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 "SkPictureUtils.h" | 8 #include "SkPictureUtils.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 SkASSERT(!"this method should never be called"); | 40 SkASSERT(!"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 */ | 49 */ |
50 class GatherPixelRefDevice : public SkDevice { | 50 class GatherPixelRefDevice : public SkRasterDevice { |
51 private: | 51 private: |
52 PixelRefSet* fPRSet; | 52 PixelRefSet* fPRSet; |
53 | 53 |
54 void addBitmap(const SkBitmap& bm) { | 54 void addBitmap(const SkBitmap& bm) { |
55 fPRSet->add(bm.pixelRef()); | 55 fPRSet->add(bm.pixelRef()); |
56 } | 56 } |
57 | 57 |
58 void addBitmapFromPaint(const SkPaint& paint) { | 58 void addBitmapFromPaint(const SkPaint& paint) { |
59 SkShader* shader = paint.getShader(); | 59 SkShader* shader = paint.getShader(); |
60 if (shader) { | 60 if (shader) { |
61 SkBitmap bm; | 61 SkBitmap bm; |
62 // Check whether the shader is a gradient in order to short-circuit | 62 // Check whether the shader is a gradient in order to short-circuit |
63 // call to asABitmap to prevent generation of bitmaps from | 63 // call to asABitmap to prevent generation of bitmaps from |
64 // gradient shaders, which implement asABitmap. | 64 // gradient shaders, which implement asABitmap. |
65 if (SkShader::kNone_GradientType == shader->asAGradient(NULL) && | 65 if (SkShader::kNone_GradientType == shader->asAGradient(NULL) && |
66 shader->asABitmap(&bm, NULL, NULL)) { | 66 shader->asABitmap(&bm, NULL, NULL)) { |
67 fPRSet->add(bm.pixelRef()); | 67 fPRSet->add(bm.pixelRef()); |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 public: | 72 public: |
73 GatherPixelRefDevice(const SkBitmap& bm, PixelRefSet* prset) : SkDevice(bm)
{ | 73 GatherPixelRefDevice(const SkBitmap& bm, PixelRefSet* prset) : SkRasterDevic
e(bm) { |
74 fPRSet = prset; | 74 fPRSet = prset; |
75 } | 75 } |
76 | 76 |
77 virtual void clear(SkColor color) SK_OVERRIDE { | 77 virtual void clear(SkColor color) SK_OVERRIDE { |
78 nothing_to_do(); | 78 nothing_to_do(); |
79 } | 79 } |
80 virtual void writePixels(const SkBitmap& bitmap, int x, int y, | 80 virtual void writePixels(const SkBitmap& bitmap, int x, int y, |
81 SkCanvas::Config8888 config8888) SK_OVERRIDE { | 81 SkCanvas::Config8888 config8888) SK_OVERRIDE { |
82 not_supported(); | 82 not_supported(); |
83 } | 83 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 nothing_to_do(); | 142 nothing_to_do(); |
143 } | 143 } |
144 | 144 |
145 protected: | 145 protected: |
146 virtual bool onReadPixels(const SkBitmap& bitmap, | 146 virtual bool onReadPixels(const SkBitmap& bitmap, |
147 int x, int y, | 147 int x, int y, |
148 SkCanvas::Config8888 config8888) SK_OVERRIDE { | 148 SkCanvas::Config8888 config8888) SK_OVERRIDE { |
149 not_supported(); | 149 not_supported(); |
150 return false; | 150 return false; |
151 } | 151 } |
| 152 |
| 153 private: |
| 154 typedef SkRasterDevice INHERITED; |
152 }; | 155 }; |
153 | 156 |
154 class NoSaveLayerCanvas : public SkCanvas { | 157 class NoSaveLayerCanvas : public SkCanvas { |
155 public: | 158 public: |
156 NoSaveLayerCanvas(SkDevice* device) : INHERITED(device) {} | 159 NoSaveLayerCanvas(SkDevice* device) : INHERITED(device) {} |
157 | 160 |
158 // turn saveLayer() into save() for speed, should not affect correctness. | 161 // turn saveLayer() into save() for speed, should not affect correctness. |
159 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, | 162 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, |
160 SaveFlags flags) SK_OVERRIDE { | 163 SaveFlags flags) SK_OVERRIDE { |
161 | 164 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 canvas.clipRect(area, SkRegion::kIntersect_Op, false); | 218 canvas.clipRect(area, SkRegion::kIntersect_Op, false); |
216 canvas.drawPicture(*pict); | 219 canvas.drawPicture(*pict); |
217 | 220 |
218 SkData* data = NULL; | 221 SkData* data = NULL; |
219 int count = array.count(); | 222 int count = array.count(); |
220 if (count > 0) { | 223 if (count > 0) { |
221 data = SkData::NewFromMalloc(array.detach(), count * sizeof(SkPixelRef*)
); | 224 data = SkData::NewFromMalloc(array.detach(), count * sizeof(SkPixelRef*)
); |
222 } | 225 } |
223 return data; | 226 return data; |
224 } | 227 } |
OLD | NEW |