OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 static void not_supported() { | 39 static void not_supported() { |
40 SkDEBUGFAIL("this method should never be called"); | 40 SkDEBUGFAIL("this method should never be called"); |
41 } | 41 } |
42 | 42 |
43 static void nothing_to_do() {} | 43 static void nothing_to_do() {} |
44 | 44 |
45 /** | 45 /** |
46 * This device will route all bitmaps (primitives and in shaders) to its PRSet. | 46 * This device will route all bitmaps (primitives and in shaders) to its PRSet. |
47 * It should never actually draw anything, so there need not be any pixels | 47 * It should never actually draw anything, so there need not be any pixels |
48 * behind its device-bitmap. | 48 * behind its device-bitmap. |
49 * FIXME: Derive from SkBaseDevice. | 49 * FIXME: Derive from SkBaseDevice. |
scroggo
2013/11/12 18:37:31
I guess you just rebased and got this, but it's no
reed1
2013/11/12 21:21:25
Done.
| |
50 */ | 50 */ |
51 class GatherPixelRefDevice : public SkBitmapDevice { | 51 class GatherPixelRefDevice : public SkBaseDevice { |
52 private: | 52 private: |
53 PixelRefSet* fPRSet; | 53 PixelRefSet* fPRSet; |
54 | 54 |
55 void addBitmap(const SkBitmap& bm) { | 55 void addBitmap(const SkBitmap& bm) { |
56 fPRSet->add(bm.pixelRef()); | 56 fPRSet->add(bm.pixelRef()); |
57 } | 57 } |
58 | 58 |
59 void addBitmapFromPaint(const SkPaint& paint) { | 59 void addBitmapFromPaint(const SkPaint& paint) { |
60 SkShader* shader = paint.getShader(); | 60 SkShader* shader = paint.getShader(); |
61 if (shader) { | 61 if (shader) { |
62 SkBitmap bm; | 62 SkBitmap bm; |
63 // Check whether the shader is a gradient in order to short-circuit | 63 // Check whether the shader is a gradient in order to short-circuit |
64 // call to asABitmap to prevent generation of bitmaps from | 64 // call to asABitmap to prevent generation of bitmaps from |
65 // gradient shaders, which implement asABitmap. | 65 // gradient shaders, which implement asABitmap. |
66 if (SkShader::kNone_GradientType == shader->asAGradient(NULL) && | 66 if (SkShader::kNone_GradientType == shader->asAGradient(NULL) && |
67 shader->asABitmap(&bm, NULL, NULL)) { | 67 shader->asABitmap(&bm, NULL, NULL)) { |
68 fPRSet->add(bm.pixelRef()); | 68 fPRSet->add(bm.pixelRef()); |
69 } | 69 } |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 public: | 73 public: |
74 GatherPixelRefDevice(const SkBitmap& bm, PixelRefSet* prset) : SkBitmapDevic e(bm) { | 74 GatherPixelRefDevice(int width, int height, PixelRefSet* prset) { |
75 fSize.set(width, height); | |
76 fEmptyBitmap.setConfig(SkBitmap::kNo_Config, width, height); | |
75 fPRSet = prset; | 77 fPRSet = prset; |
76 } | 78 } |
77 | 79 |
80 virtual uint32_t getDeviceCapabilities() SK_OVERRIDE { return 0; } | |
81 virtual int width() const SK_OVERRIDE { return fSize.width(); } | |
82 virtual int height() const SK_OVERRIDE { return fSize.height(); } | |
83 virtual bool isOpaque() const SK_OVERRIDE { return false; } | |
84 virtual SkBitmap::Config config() const SK_OVERRIDE { | |
85 return SkBitmap::kNo_Config; | |
86 } | |
87 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE { return NULL; } | |
88 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE { | |
89 return true; | |
90 } | |
91 // TODO: allow this call to return failure, or move to SkBitmapDevice only. | |
92 virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE { | |
93 return fEmptyBitmap; | |
94 } | |
95 virtual void lockPixels() SK_OVERRIDE { nothing_to_do(); } | |
96 virtual void unlockPixels() SK_OVERRIDE { nothing_to_do(); } | |
97 virtual bool allowImageFilter(SkImageFilter*) SK_OVERRIDE { return false; } | |
98 virtual bool canHandleImageFilter(SkImageFilter*) SK_OVERRIDE { return false ; } | |
99 virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&, | |
100 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE { | |
101 return false; | |
102 } | |
103 | |
78 virtual void clear(SkColor color) SK_OVERRIDE { | 104 virtual void clear(SkColor color) SK_OVERRIDE { |
79 nothing_to_do(); | 105 nothing_to_do(); |
80 } | 106 } |
81 virtual void writePixels(const SkBitmap& bitmap, int x, int y, | 107 virtual void writePixels(const SkBitmap& bitmap, int x, int y, |
82 SkCanvas::Config8888 config8888) SK_OVERRIDE { | 108 SkCanvas::Config8888 config8888) SK_OVERRIDE { |
83 not_supported(); | 109 not_supported(); |
84 } | 110 } |
85 | 111 |
86 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE { | 112 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE { |
87 this->addBitmapFromPaint(paint); | 113 this->addBitmapFromPaint(paint); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 } | 175 } |
150 | 176 |
151 protected: | 177 protected: |
152 virtual bool onReadPixels(const SkBitmap& bitmap, | 178 virtual bool onReadPixels(const SkBitmap& bitmap, |
153 int x, int y, | 179 int x, int y, |
154 SkCanvas::Config8888 config8888) SK_OVERRIDE { | 180 SkCanvas::Config8888 config8888) SK_OVERRIDE { |
155 not_supported(); | 181 not_supported(); |
156 return false; | 182 return false; |
157 } | 183 } |
158 | 184 |
185 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRI DE { | |
186 not_supported(); | |
187 } | |
188 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config, | |
189 int width, int height, | |
190 bool isOpaque, | |
191 Usage usage) SK_OVERRIDE { | |
192 return NULL; | |
193 } | |
194 virtual void flush() SK_OVERRIDE {} | |
195 | |
159 private: | 196 private: |
160 typedef SkBitmapDevice INHERITED; | 197 SkBitmap fEmptyBitmap; // legacy -- need to remove the need for this guy |
198 SkISize fSize; | |
199 typedef SkBaseDevice INHERITED; | |
161 }; | 200 }; |
162 | 201 |
163 class NoSaveLayerCanvas : public SkCanvas { | 202 class NoSaveLayerCanvas : public SkCanvas { |
164 public: | 203 public: |
165 NoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {} | 204 NoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {} |
166 | 205 |
167 // turn saveLayer() into save() for speed, should not affect correctness. | 206 // turn saveLayer() into save() for speed, should not affect correctness. |
168 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, | 207 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, |
169 SaveFlags flags) SK_OVERRIDE { | 208 SaveFlags flags) SK_OVERRIDE { |
170 | 209 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 // this test also handles if either area or pict's width/height are empty | 246 // this test also handles if either area or pict's width/height are empty |
208 if (!SkRect::Intersects(area, | 247 if (!SkRect::Intersects(area, |
209 SkRect::MakeWH(SkIntToScalar(pict->width()), | 248 SkRect::MakeWH(SkIntToScalar(pict->width()), |
210 SkIntToScalar(pict->height())))) { | 249 SkIntToScalar(pict->height())))) { |
211 return NULL; | 250 return NULL; |
212 } | 251 } |
213 | 252 |
214 SkTDArray<SkPixelRef*> array; | 253 SkTDArray<SkPixelRef*> array; |
215 PixelRefSet prset(&array); | 254 PixelRefSet prset(&array); |
216 | 255 |
217 SkBitmap emptyBitmap; | 256 SkBitmap emptyBitmap; |
scroggo
2013/11/12 18:37:31
emptyBitmap is no longer used
reed1
2013/11/12 21:21:25
Done.
| |
218 emptyBitmap.setConfig(SkBitmap::kARGB_8888_Config, pict->width(), pict->heig ht()); | 257 emptyBitmap.setConfig(SkBitmap::kARGB_8888_Config, pict->width(), pict->heig ht()); |
219 // note: we do not set any pixels (shouldn't need to) | 258 // note: we do not set any pixels (shouldn't need to) |
220 | 259 |
221 GatherPixelRefDevice device(emptyBitmap, &prset); | 260 GatherPixelRefDevice device(pict->width(), pict->height(), &prset); |
222 NoSaveLayerCanvas canvas(&device); | 261 NoSaveLayerCanvas canvas(&device); |
223 | 262 |
224 canvas.clipRect(area, SkRegion::kIntersect_Op, false); | 263 canvas.clipRect(area, SkRegion::kIntersect_Op, false); |
225 canvas.drawPicture(*pict); | 264 canvas.drawPicture(*pict); |
226 | 265 |
227 SkData* data = NULL; | 266 SkData* data = NULL; |
228 int count = array.count(); | 267 int count = array.count(); |
229 if (count > 0) { | 268 if (count > 0) { |
230 data = SkData::NewFromMalloc(array.detach(), count * sizeof(SkPixelRef*) ); | 269 data = SkData::NewFromMalloc(array.detach(), count * sizeof(SkPixelRef*) ); |
231 } | 270 } |
232 return data; | 271 return data; |
233 } | 272 } |
OLD | NEW |