Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Side by Side Diff: src/utils/SkPictureUtils.cpp

Issue 58933007: Revert "switch GatherPixelRefs to use SkBaseDevice instead of SkBitmapDevice" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 38
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. 48 * behind its device-bitmap.
49 * FIXME: Derive from SkBaseDevice.
49 */ 50 */
50 class GatherPixelRefDevice : public SkBaseDevice { 51 class GatherPixelRefDevice : public SkBitmapDevice {
52 private:
53 PixelRefSet* fPRSet;
54
55 void addBitmap(const SkBitmap& bm) {
56 fPRSet->add(bm.pixelRef());
57 }
58
59 void addBitmapFromPaint(const SkPaint& paint) {
60 SkShader* shader = paint.getShader();
61 if (shader) {
62 SkBitmap bm;
63 // Check whether the shader is a gradient in order to short-circuit
64 // call to asABitmap to prevent generation of bitmaps from
65 // gradient shaders, which implement asABitmap.
66 if (SkShader::kNone_GradientType == shader->asAGradient(NULL) &&
67 shader->asABitmap(&bm, NULL, NULL)) {
68 fPRSet->add(bm.pixelRef());
69 }
70 }
71 }
72
51 public: 73 public:
52 GatherPixelRefDevice(int width, int height, PixelRefSet* prset) { 74 GatherPixelRefDevice(const SkBitmap& bm, PixelRefSet* prset) : SkBitmapDevic e(bm) {
53 fSize.set(width, height);
54 fEmptyBitmap.setConfig(SkBitmap::kNo_Config, width, height);
55 fPRSet = prset; 75 fPRSet = prset;
56 } 76 }
57 77
58 virtual uint32_t getDeviceCapabilities() SK_OVERRIDE { return 0; }
59 virtual int width() const SK_OVERRIDE { return fSize.width(); }
60 virtual int height() const SK_OVERRIDE { return fSize.height(); }
61 virtual bool isOpaque() const SK_OVERRIDE { return false; }
62 virtual SkBitmap::Config config() const SK_OVERRIDE {
63 return SkBitmap::kNo_Config;
64 }
65 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE { return NULL; }
66 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE {
67 return true;
68 }
69 // TODO: allow this call to return failure, or move to SkBitmapDevice only.
70 virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE {
71 return fEmptyBitmap;
72 }
73 virtual void lockPixels() SK_OVERRIDE { nothing_to_do(); }
74 virtual void unlockPixels() SK_OVERRIDE { nothing_to_do(); }
75 virtual bool allowImageFilter(SkImageFilter*) SK_OVERRIDE { return false; }
76 virtual bool canHandleImageFilter(SkImageFilter*) SK_OVERRIDE { return false ; }
77 virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&,
78 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE {
79 return false;
80 }
81
82 virtual void clear(SkColor color) SK_OVERRIDE { 78 virtual void clear(SkColor color) SK_OVERRIDE {
83 nothing_to_do(); 79 nothing_to_do();
84 } 80 }
85 virtual void writePixels(const SkBitmap& bitmap, int x, int y, 81 virtual void writePixels(const SkBitmap& bitmap, int x, int y,
86 SkCanvas::Config8888 config8888) SK_OVERRIDE { 82 SkCanvas::Config8888 config8888) SK_OVERRIDE {
87 not_supported(); 83 not_supported();
88 } 84 }
89 85
90 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE { 86 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE {
91 this->addBitmapFromPaint(paint); 87 this->addBitmapFromPaint(paint);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 149 }
154 150
155 protected: 151 protected:
156 virtual bool onReadPixels(const SkBitmap& bitmap, 152 virtual bool onReadPixels(const SkBitmap& bitmap,
157 int x, int y, 153 int x, int y,
158 SkCanvas::Config8888 config8888) SK_OVERRIDE { 154 SkCanvas::Config8888 config8888) SK_OVERRIDE {
159 not_supported(); 155 not_supported();
160 return false; 156 return false;
161 } 157 }
162 158
163 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRI DE {
164 not_supported();
165 }
166 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
167 int width, int height,
168 bool isOpaque,
169 Usage usage) SK_OVERRIDE {
170 // we expect to only get called via savelayer, in which case it is fine.
171 SkASSERT(kSaveLayer_Usage == usage);
172 return SkNEW_ARGS(GatherPixelRefDevice, (width, height, fPRSet));
173 }
174 virtual void flush() SK_OVERRIDE {}
175
176 private: 159 private:
177 PixelRefSet* fPRSet; 160 typedef SkBitmapDevice INHERITED;
178 SkBitmap fEmptyBitmap; // legacy -- need to remove the need for this guy
179 SkISize fSize;
180
181 void addBitmap(const SkBitmap& bm) {
182 fPRSet->add(bm.pixelRef());
183 }
184
185 void addBitmapFromPaint(const SkPaint& paint) {
186 SkShader* shader = paint.getShader();
187 if (shader) {
188 SkBitmap bm;
189 // Check whether the shader is a gradient in order to short-circuit
190 // call to asABitmap to prevent generation of bitmaps from
191 // gradient shaders, which implement asABitmap.
192 if (SkShader::kNone_GradientType == shader->asAGradient(NULL) &&
193 shader->asABitmap(&bm, NULL, NULL)) {
194 fPRSet->add(bm.pixelRef());
195 }
196 }
197 }
198
199 typedef SkBaseDevice INHERITED;
200 }; 161 };
201 162
202 class NoSaveLayerCanvas : public SkCanvas { 163 class NoSaveLayerCanvas : public SkCanvas {
203 public: 164 public:
204 NoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {} 165 NoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {}
205 166
206 // turn saveLayer() into save() for speed, should not affect correctness. 167 // turn saveLayer() into save() for speed, should not affect correctness.
207 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, 168 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
208 SaveFlags flags) SK_OVERRIDE { 169 SaveFlags flags) SK_OVERRIDE {
209 170
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // this test also handles if either area or pict's width/height are empty 207 // this test also handles if either area or pict's width/height are empty
247 if (!SkRect::Intersects(area, 208 if (!SkRect::Intersects(area,
248 SkRect::MakeWH(SkIntToScalar(pict->width()), 209 SkRect::MakeWH(SkIntToScalar(pict->width()),
249 SkIntToScalar(pict->height())))) { 210 SkIntToScalar(pict->height())))) {
250 return NULL; 211 return NULL;
251 } 212 }
252 213
253 SkTDArray<SkPixelRef*> array; 214 SkTDArray<SkPixelRef*> array;
254 PixelRefSet prset(&array); 215 PixelRefSet prset(&array);
255 216
256 GatherPixelRefDevice device(pict->width(), pict->height(), &prset); 217 SkBitmap emptyBitmap;
218 emptyBitmap.setConfig(SkBitmap::kARGB_8888_Config, pict->width(), pict->heig ht());
219 // note: we do not set any pixels (shouldn't need to)
220
221 GatherPixelRefDevice device(emptyBitmap, &prset);
257 NoSaveLayerCanvas canvas(&device); 222 NoSaveLayerCanvas canvas(&device);
258 223
259 canvas.clipRect(area, SkRegion::kIntersect_Op, false); 224 canvas.clipRect(area, SkRegion::kIntersect_Op, false);
260 canvas.drawPicture(*pict); 225 canvas.drawPicture(*pict);
261 226
262 SkData* data = NULL; 227 SkData* data = NULL;
263 int count = array.count(); 228 int count = array.count();
264 if (count > 0) { 229 if (count > 0) {
265 data = SkData::NewFromMalloc(array.detach(), count * sizeof(SkPixelRef*) ); 230 data = SkData::NewFromMalloc(array.detach(), count * sizeof(SkPixelRef*) );
266 } 231 }
267 return data; 232 return data;
268 } 233 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698