3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
11 bool SkBitmap::scrollRect(const SkIRect* subset, int dx, int dy,
12 SkRegion* inval) const
14 if (this->isImmutable() || kUnknown_SkColorType == this->colorType()) {
21 return this->extractSubset(&tmp, *subset) &&
22 // now call again with no rectangle
23 tmp.scrollRect(NULL, dx, dy, inval);
26 int shift = this->bytesPerPixel() >> 1;
27 int width = this->width();
28 int height = this->height();
30 // check if there's nothing to do
31 if ((dx | dy) == 0 || width <= 0 || height <= 0) {
38 // compute the inval region now, before we see if there are any pixels
42 r.set(0, 0, width, height);
43 // initial the region with the entire bounds
48 // check if we scrolled completely away
49 if (!SkIRect::Intersects(r, inval->getBounds())) {
50 // inval has already been updated...
54 // compute the dirty area
55 inval->op(r, SkRegion::kDifference_Op);
58 SkAutoLockPixels alp(*this);
59 // if we have no pixels, just return (inval is already updated)
60 // don't call readyToDraw(), since we don't require a colortable per se
61 if (this->getPixels() == NULL) {
65 char* dst = (char*)this->getPixels();
66 const char* src = dst;
67 int rowBytes = (int)this->rowBytes(); // need rowBytes to be signed
75 // now jump src/dst to the last scanline
76 src += (height - 1) * rowBytes;
77 dst += (height - 1) * rowBytes;
78 // now invert rowbytes so we copy backwards in the loop
90 // If the X-translation would push it completely beyond the region,
91 // then there's nothing to draw.
96 width <<= shift; // now width is the number of bytes to move per line
97 while (--height >= 0) {
98 memmove(dst, src, width);
103 this->notifyPixelsChanged();