OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkRegion.h" | 9 #include "SkRegion.h" |
10 | 10 |
11 bool SkBitmap::scrollRect(const SkIRect* subset, int dx, int dy, | 11 bool SkBitmap::scrollRect(const SkIRect* subset, int dx, int dy, |
12 SkRegion* inval) const | 12 SkRegion* inval) const |
13 { | 13 { |
14 if (this->isImmutable() || kUnknown_SkColorType == this->colorType()) { | 14 if (this->isImmutable() || kUnknown_SkColorType == this->colorType()) { |
15 return false; | 15 return false; |
16 } | 16 } |
17 | 17 |
18 if (NULL != subset) { | 18 if (subset) { |
19 SkBitmap tmp; | 19 SkBitmap tmp; |
20 | 20 |
21 return this->extractSubset(&tmp, *subset) && | 21 return this->extractSubset(&tmp, *subset) && |
22 // now call again with no rectangle | 22 // now call again with no rectangle |
23 tmp.scrollRect(NULL, dx, dy, inval); | 23 tmp.scrollRect(NULL, dx, dy, inval); |
24 } | 24 } |
25 | 25 |
26 int shift = this->bytesPerPixel() >> 1; | 26 int shift = this->bytesPerPixel() >> 1; |
27 int width = this->width(); | 27 int width = this->width(); |
28 int height = this->height(); | 28 int height = this->height(); |
29 | 29 |
30 // check if there's nothing to do | 30 // check if there's nothing to do |
31 if ((dx | dy) == 0 || width <= 0 || height <= 0) { | 31 if ((dx | dy) == 0 || width <= 0 || height <= 0) { |
32 if (NULL != inval) { | 32 if (inval) { |
33 inval->setEmpty(); | 33 inval->setEmpty(); |
34 } | 34 } |
35 return true; | 35 return true; |
36 } | 36 } |
37 | 37 |
38 // compute the inval region now, before we see if there are any pixels | 38 // compute the inval region now, before we see if there are any pixels |
39 if (NULL != inval) { | 39 if (inval) { |
40 SkIRect r; | 40 SkIRect r; |
41 | 41 |
42 r.set(0, 0, width, height); | 42 r.set(0, 0, width, height); |
43 // initial the region with the entire bounds | 43 // initial the region with the entire bounds |
44 inval->setRect(r); | 44 inval->setRect(r); |
45 // do the "scroll" | 45 // do the "scroll" |
46 r.offset(dx, dy); | 46 r.offset(dx, dy); |
47 | 47 |
48 // check if we scrolled completely away | 48 // check if we scrolled completely away |
49 if (!SkIRect::Intersects(r, inval->getBounds())) { | 49 if (!SkIRect::Intersects(r, inval->getBounds())) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 width <<= shift; // now width is the number of bytes to move per line | 96 width <<= shift; // now width is the number of bytes to move per line |
97 while (--height >= 0) { | 97 while (--height >= 0) { |
98 memmove(dst, src, width); | 98 memmove(dst, src, width); |
99 dst += rowBytes; | 99 dst += rowBytes; |
100 src += rowBytes; | 100 src += rowBytes; |
101 } | 101 } |
102 | 102 |
103 this->notifyPixelsChanged(); | 103 this->notifyPixelsChanged(); |
104 return true; | 104 return true; |
105 } | 105 } |
OLD | NEW |