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 static bool scroll_pixels(const SkPixmap& pmap, int dx, int dy) { |
12 SkRegion* inval) const | 12 const int shift = pmap.info().bytesPerPixel() >> 1; |
13 { | 13 char* dst = (char*)pmap.writable_addr(); |
14 const char* src = dst; | |
15 int rowBytes = (int)pmap.rowBytes(); // need rowBytes to be signe d | |
16 int width = pmap.width(); | |
17 int height = pmap.height(); | |
18 | |
19 if (dy <= 0) { | |
20 src -= dy * rowBytes; | |
21 height += dy; | |
22 } else { | |
23 dst += dy * rowBytes; | |
24 height -= dy; | |
25 // now jump src/dst to the last scanline | |
26 src += (height - 1) * rowBytes; | |
27 dst += (height - 1) * rowBytes; | |
28 // now invert rowbytes so we copy backwards in the loop | |
29 rowBytes = -rowBytes; | |
30 } | |
31 | |
32 if (dx <= 0) { | |
33 src -= dx << shift; | |
34 width += dx; | |
35 } else { | |
36 dst += dx << shift; | |
37 width -= dx; | |
38 } | |
39 | |
40 // If the X-translation would push it completely beyond the region, | |
41 // then there's nothing to draw. | |
42 if (width <= 0) { | |
43 return false; | |
44 } | |
45 | |
46 width <<= shift; // now width is the number of bytes to move per line | |
47 while (--height >= 0) { | |
48 memmove(dst, src, width); | |
49 dst += rowBytes; | |
50 src += rowBytes; | |
51 } | |
52 return true; | |
53 } | |
54 | |
55 bool SkBitmap::scrollRect(const SkIRect* subset, int dx, int dy, SkRegion* inval ) const { | |
scroggo
2015/05/19 20:11:42
It appears that neither Android nor Chromium use t
reed1
2015/05/21 20:59:35
I'll try that in an (earlier?) CL.
| |
14 if (this->isImmutable() || kUnknown_SkColorType == this->colorType()) { | 56 if (this->isImmutable() || kUnknown_SkColorType == this->colorType()) { |
15 return false; | 57 return false; |
16 } | 58 } |
17 | 59 |
18 if (subset) { | 60 if (subset) { |
19 SkBitmap tmp; | 61 SkBitmap tmp; |
20 | 62 |
21 return this->extractSubset(&tmp, *subset) && | 63 return this->extractSubset(&tmp, *subset) && |
22 // now call again with no rectangle | 64 // now call again with no rectangle |
23 tmp.scrollRect(NULL, dx, dy, inval); | 65 tmp.scrollRect(NULL, dx, dy, inval); |
24 } | 66 } |
25 | 67 |
26 int shift = this->bytesPerPixel() >> 1; | |
27 int width = this->width(); | 68 int width = this->width(); |
28 int height = this->height(); | 69 int height = this->height(); |
29 | 70 |
30 // check if there's nothing to do | 71 // check if there's nothing to do |
31 if ((dx | dy) == 0 || width <= 0 || height <= 0) { | 72 if ((dx | dy) == 0 || width <= 0 || height <= 0) { |
32 if (inval) { | 73 if (inval) { |
33 inval->setEmpty(); | 74 inval->setEmpty(); |
34 } | 75 } |
35 return true; | 76 return true; |
36 } | 77 } |
(...skipping 11 matching lines...) Expand all Loading... | |
48 // check if we scrolled completely away | 89 // check if we scrolled completely away |
49 if (!SkIRect::Intersects(r, inval->getBounds())) { | 90 if (!SkIRect::Intersects(r, inval->getBounds())) { |
50 // inval has already been updated... | 91 // inval has already been updated... |
51 return true; | 92 return true; |
52 } | 93 } |
53 | 94 |
54 // compute the dirty area | 95 // compute the dirty area |
55 inval->op(r, SkRegion::kDifference_Op); | 96 inval->op(r, SkRegion::kDifference_Op); |
56 } | 97 } |
57 | 98 |
58 SkAutoLockPixels alp(*this); | 99 SkAutoBitmapLockResult result; |
59 // if we have no pixels, just return (inval is already updated) | 100 if (!this->requestLock(&result)) { |
60 // don't call readyToDraw(), since we don't require a colortable per se | |
61 if (this->getPixels() == NULL) { | |
62 return true; | 101 return true; |
63 } | 102 } |
64 | 103 if (scroll_pixels(result.pixmap(), dx, dy)) { |
65 char* dst = (char*)this->getPixels(); | 104 this->notifyPixelsChanged(); |
66 const char* src = dst; | |
67 int rowBytes = (int)this->rowBytes(); // need rowBytes to be sign ed | |
68 | |
69 if (dy <= 0) { | |
70 src -= dy * rowBytes; | |
71 height += dy; | |
72 } else { | |
73 dst += dy * rowBytes; | |
74 height -= dy; | |
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 | |
79 rowBytes = -rowBytes; | |
80 } | 105 } |
81 | |
82 if (dx <= 0) { | |
83 src -= dx << shift; | |
84 width += dx; | |
85 } else { | |
86 dst += dx << shift; | |
87 width -= dx; | |
88 } | |
89 | |
90 // If the X-translation would push it completely beyond the region, | |
91 // then there's nothing to draw. | |
92 if (width <= 0) { | |
93 return true; | |
94 } | |
95 | |
96 width <<= shift; // now width is the number of bytes to move per line | |
97 while (--height >= 0) { | |
98 memmove(dst, src, width); | |
99 dst += rowBytes; | |
100 src += rowBytes; | |
101 } | |
102 | |
103 this->notifyPixelsChanged(); | |
104 return true; | 106 return true; |
105 } | 107 } |
OLD | NEW |