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

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

Issue 22978012: Split SkDevice into SkBaseDevice and SkBitmapDevice (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Updating to ToT (10994) Created 7 years, 3 months 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/utils/SkDeferredCanvas.cpp ('k') | tests/CanvasTest.cpp » ('j') | 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 "SkPictureUtils.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkData.h" 10 #include "SkData.h"
11 #include "SkDevice.h" 11 #include "SkPictureUtils.h"
12 #include "SkPixelRef.h" 12 #include "SkPixelRef.h"
13 #include "SkRRect.h"
13 #include "SkShader.h" 14 #include "SkShader.h"
14 #include "SkRRect.h"
15 15
16 class PixelRefSet { 16 class PixelRefSet {
17 public: 17 public:
18 PixelRefSet(SkTDArray<SkPixelRef*>* array) : fArray(array) {} 18 PixelRefSet(SkTDArray<SkPixelRef*>* array) : fArray(array) {}
19 19
20 // This does a linear search on existing pixelrefs, so if this list gets big 20 // This does a linear search on existing pixelrefs, so if this list gets big
21 // we should use a more complex sorted/hashy thing. 21 // we should use a more complex sorted/hashy thing.
22 // 22 //
23 void add(SkPixelRef* pr) { 23 void add(SkPixelRef* pr) {
24 uint32_t genID = pr->getGenerationID(); 24 uint32_t genID = pr->getGenerationID();
(...skipping 15 matching lines...) Expand all
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 */ 49 */
50 class GatherPixelRefDevice : public SkDevice { 50 class GatherPixelRefDevice : public SkBitmapDevice {
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) : SkBitmapDevic 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 const SkPaint& paint) SK_OVERRIDE { 131 const SkPaint& paint) SK_OVERRIDE {
132 this->addBitmapFromPaint(paint); 132 this->addBitmapFromPaint(paint);
133 } 133 }
134 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCou nt, 134 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCou nt,
135 const SkPoint verts[], const SkPoint texs[], 135 const SkPoint verts[], const SkPoint texs[],
136 const SkColor colors[], SkXfermode* xmode, 136 const SkColor colors[], SkXfermode* xmode,
137 const uint16_t indices[], int indexCount, 137 const uint16_t indices[], int indexCount,
138 const SkPaint& paint) SK_OVERRIDE { 138 const SkPaint& paint) SK_OVERRIDE {
139 this->addBitmapFromPaint(paint); 139 this->addBitmapFromPaint(paint);
140 } 140 }
141 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, 141 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
142 const SkPaint&) SK_OVERRIDE { 142 const SkPaint&) SK_OVERRIDE {
143 nothing_to_do(); 143 nothing_to_do();
144 } 144 }
145 145
146 protected: 146 protected:
147 virtual bool onReadPixels(const SkBitmap& bitmap, 147 virtual bool onReadPixels(const SkBitmap& bitmap,
148 int x, int y, 148 int x, int y,
149 SkCanvas::Config8888 config8888) SK_OVERRIDE { 149 SkCanvas::Config8888 config8888) SK_OVERRIDE {
150 not_supported(); 150 not_supported();
151 return false; 151 return false;
152 } 152 }
153
154 private:
155 typedef SkBitmapDevice INHERITED;
153 }; 156 };
154 157
155 class NoSaveLayerCanvas : public SkCanvas { 158 class NoSaveLayerCanvas : public SkCanvas {
156 public: 159 public:
157 NoSaveLayerCanvas(SkDevice* device) : INHERITED(device) {} 160 NoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {}
158 161
159 // turn saveLayer() into save() for speed, should not affect correctness. 162 // turn saveLayer() into save() for speed, should not affect correctness.
160 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, 163 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
161 SaveFlags flags) SK_OVERRIDE { 164 SaveFlags flags) SK_OVERRIDE {
162 165
163 // Like SkPictureRecord, we don't want to create layers, but we do need 166 // Like SkPictureRecord, we don't want to create layers, but we do need
164 // to respect the save and (possibly) its rect-clip. 167 // to respect the save and (possibly) its rect-clip.
165 168
166 int count = this->INHERITED::save(flags); 169 int count = this->INHERITED::save(flags);
167 if (bounds) { 170 if (bounds) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 canvas.clipRect(area, SkRegion::kIntersect_Op, false); 219 canvas.clipRect(area, SkRegion::kIntersect_Op, false);
217 canvas.drawPicture(*pict); 220 canvas.drawPicture(*pict);
218 221
219 SkData* data = NULL; 222 SkData* data = NULL;
220 int count = array.count(); 223 int count = array.count();
221 if (count > 0) { 224 if (count > 0) {
222 data = SkData::NewFromMalloc(array.detach(), count * sizeof(SkPixelRef*) ); 225 data = SkData::NewFromMalloc(array.detach(), count * sizeof(SkPixelRef*) );
223 } 226 }
224 return data; 227 return data;
225 } 228 }
OLDNEW
« no previous file with comments | « src/utils/SkDeferredCanvas.cpp ('k') | tests/CanvasTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698