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

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

Issue 167003002: Revert "Revert of have DeferredDevice inherit from SkBaseDevice (https://codereview.chromium.org/16… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 | « no previous file | 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 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 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 8
9 #include "SkDeferredCanvas.h" 9 #include "SkDeferredCanvas.h"
10 10
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 fBlock = NULL; 130 fBlock = NULL;
131 } 131 }
132 132
133 // Release all allocated blocks 133 // Release all allocated blocks
134 fAllocator.reset(); 134 fAllocator.reset();
135 } 135 }
136 136
137 //----------------------------------------------------------------------------- 137 //-----------------------------------------------------------------------------
138 // DeferredDevice 138 // DeferredDevice
139 //----------------------------------------------------------------------------- 139 //-----------------------------------------------------------------------------
140 // FIXME: Derive from SkBaseDevice. 140 class DeferredDevice : public SkBaseDevice {
141 class DeferredDevice : public SkBitmapDevice {
142 public: 141 public:
143 explicit DeferredDevice(SkSurface* surface); 142 explicit DeferredDevice(SkSurface* surface);
144 ~DeferredDevice(); 143 ~DeferredDevice();
145 144
146 void setNotificationClient(SkDeferredCanvas::NotificationClient* notificatio nClient); 145 void setNotificationClient(SkDeferredCanvas::NotificationClient* notificatio nClient);
147 SkCanvas* recordingCanvas(); 146 SkCanvas* recordingCanvas();
148 SkCanvas* immediateCanvas() const {return fImmediateCanvas;} 147 SkCanvas* immediateCanvas() const {return fImmediateCanvas;}
149 SkBaseDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice ();} 148 SkBaseDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice ();}
150 SkImage* newImageSnapshot(); 149 SkImage* newImageSnapshot();
151 void setSurface(SkSurface* surface); 150 void setSurface(SkSurface* surface);
152 bool isFreshFrame(); 151 bool isFreshFrame();
153 bool hasPendingCommands(); 152 bool hasPendingCommands();
154 size_t storageAllocatedForRecording() const; 153 size_t storageAllocatedForRecording() const;
155 size_t freeMemoryIfPossible(size_t bytesToFree); 154 size_t freeMemoryIfPossible(size_t bytesToFree);
156 size_t getBitmapSizeThreshold() const; 155 size_t getBitmapSizeThreshold() const;
157 void setBitmapSizeThreshold(size_t sizeThreshold); 156 void setBitmapSizeThreshold(size_t sizeThreshold);
158 void flushPendingCommands(PlaybackMode); 157 void flushPendingCommands(PlaybackMode);
159 void skipPendingCommands(); 158 void skipPendingCommands();
160 void setMaxRecordingStorage(size_t); 159 void setMaxRecordingStorage(size_t);
161 void recordedDrawCommand(); 160 void recordedDrawCommand();
162 161
163 virtual uint32_t getDeviceCapabilities() SK_OVERRIDE; 162 virtual uint32_t getDeviceCapabilities() SK_OVERRIDE;
164 virtual int width() const SK_OVERRIDE; 163 virtual int width() const SK_OVERRIDE;
165 virtual int height() const SK_OVERRIDE; 164 virtual int height() const SK_OVERRIDE;
165 virtual SkBitmap::Config config() const SK_OVERRIDE;
166 virtual bool isOpaque() const SK_OVERRIDE;
167 virtual SkImageInfo imageInfo() const SK_OVERRIDE;
168
166 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE; 169 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE;
167 170
168 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config, 171 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
169 int width, int height, 172 int width, int height,
170 bool isOpaque, 173 bool isOpaque,
171 Usage usage) SK_OVERRIDE; 174 Usage usage) SK_OVERRIDE;
172 175
173 virtual void writePixels(const SkBitmap& bitmap, int x, int y, 176 virtual void writePixels(const SkBitmap& bitmap, int x, int y,
174 SkCanvas::Config8888 config8888) SK_OVERRIDE; 177 SkCanvas::Config8888 config8888) SK_OVERRIDE;
175 178
(...skipping 16 matching lines...) Expand all
192 {SkASSERT(0);} 195 {SkASSERT(0);}
193 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE 196 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE
194 {SkASSERT(0);} 197 {SkASSERT(0);}
195 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, 198 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode,
196 size_t count, const SkPoint[], 199 size_t count, const SkPoint[],
197 const SkPaint& paint) SK_OVERRIDE 200 const SkPaint& paint) SK_OVERRIDE
198 {SkASSERT(0);} 201 {SkASSERT(0);}
199 virtual void drawRect(const SkDraw&, const SkRect& r, 202 virtual void drawRect(const SkDraw&, const SkRect& r,
200 const SkPaint& paint) SK_OVERRIDE 203 const SkPaint& paint) SK_OVERRIDE
201 {SkASSERT(0);} 204 {SkASSERT(0);}
205 virtual void drawOval(const SkDraw&, const SkRect&, const SkPaint&) SK_OVERR IDE
206 {SkASSERT(0);}
202 virtual void drawRRect(const SkDraw&, const SkRRect& rr, 207 virtual void drawRRect(const SkDraw&, const SkRRect& rr,
203 const SkPaint& paint) SK_OVERRIDE 208 const SkPaint& paint) SK_OVERRIDE
204 {SkASSERT(0);} 209 {SkASSERT(0);}
205 virtual void drawPath(const SkDraw&, const SkPath& path, 210 virtual void drawPath(const SkDraw&, const SkPath& path,
206 const SkPaint& paint, 211 const SkPaint& paint,
207 const SkMatrix* prePathMatrix = NULL, 212 const SkMatrix* prePathMatrix = NULL,
208 bool pathIsMutable = false) SK_OVERRIDE 213 bool pathIsMutable = false) SK_OVERRIDE
209 {SkASSERT(0);} 214 {SkASSERT(0);}
210 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, 215 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
211 const SkMatrix& matrix, const SkPaint& paint) SK_OVE RRIDE 216 const SkMatrix& matrix, const SkPaint& paint) SK_OVE RRIDE
212 {SkASSERT(0);} 217 {SkASSERT(0);}
218 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect*,
219 const SkRect&, const SkPaint&,
220 SkCanvas::DrawBitmapRectFlags) SK_OVERRIDE
221 {SkASSERT(0);}
213 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, 222 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
214 int x, int y, const SkPaint& paint) SK_OVERRIDE 223 int x, int y, const SkPaint& paint) SK_OVERRIDE
215 {SkASSERT(0);} 224 {SkASSERT(0);}
216 virtual void drawText(const SkDraw&, const void* text, size_t len, 225 virtual void drawText(const SkDraw&, const void* text, size_t len,
217 SkScalar x, SkScalar y, const SkPaint& paint) SK_OVE RRIDE 226 SkScalar x, SkScalar y, const SkPaint& paint) SK_OVE RRIDE
218 {SkASSERT(0);} 227 {SkASSERT(0);}
219 virtual void drawPosText(const SkDraw&, const void* text, size_t len, 228 virtual void drawPosText(const SkDraw&, const void* text, size_t len,
220 const SkScalar pos[], SkScalar constY, 229 const SkScalar pos[], SkScalar constY,
221 int scalarsPerPos, const SkPaint& paint) SK_OVER RIDE 230 int scalarsPerPos, const SkPaint& paint) SK_OVER RIDE
222 {SkASSERT(0);} 231 {SkASSERT(0);}
223 virtual void drawTextOnPath(const SkDraw&, const void* text, 232 virtual void drawTextOnPath(const SkDraw&, const void* text,
224 size_t len, const SkPath& path, 233 size_t len, const SkPath& path,
225 const SkMatrix* matrix, 234 const SkMatrix* matrix,
226 const SkPaint& paint) SK_OVERRIDE 235 const SkPaint& paint) SK_OVERRIDE
227 {SkASSERT(0);} 236 {SkASSERT(0);}
228 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, 237 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode,
229 int vertexCount, const SkPoint verts[], 238 int vertexCount, const SkPoint verts[],
230 const SkPoint texs[], const SkColor colors[], 239 const SkPoint texs[], const SkColor colors[],
231 SkXfermode* xmode, const uint16_t indices[], 240 SkXfermode* xmode, const uint16_t indices[],
232 int indexCount, const SkPaint& paint) SK_OVERRID E 241 int indexCount, const SkPaint& paint) SK_OVERRID E
233 {SkASSERT(0);} 242 {SkASSERT(0);}
234 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, 243 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
235 const SkPaint&) SK_OVERRIDE 244 const SkPaint&) SK_OVERRIDE
236 {SkASSERT(0);} 245 {SkASSERT(0);}
246
247 virtual void lockPixels() SK_OVERRIDE {}
248 virtual void unlockPixels() SK_OVERRIDE {}
249
250 virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE {
251 return false;
252 }
253 virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE {
254 return false;
255 }
256 virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
257 const SkMatrix&, SkBitmap*, SkIPoint*) SK_OVERRIDE {
258 return false;
259 }
260
237 private: 261 private:
238 virtual void flush() SK_OVERRIDE; 262 virtual void flush() SK_OVERRIDE;
263 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRI DE {}
239 264
240 void beginRecording(); 265 void beginRecording();
241 void init(); 266 void init();
242 void aboutToDraw(); 267 void aboutToDraw();
243 void prepareForImmediatePixelWrite(); 268 void prepareForImmediatePixelWrite();
244 269
245 DeferredPipeController fPipeController; 270 DeferredPipeController fPipeController;
246 SkGPipeWriter fPipeWriter; 271 SkGPipeWriter fPipeWriter;
247 SkCanvas* fImmediateCanvas; 272 SkCanvas* fImmediateCanvas;
248 SkCanvas* fRecordingCanvas; 273 SkCanvas* fRecordingCanvas;
249 SkSurface* fSurface; 274 SkSurface* fSurface;
250 SkDeferredCanvas::NotificationClient* fNotificationClient; 275 SkDeferredCanvas::NotificationClient* fNotificationClient;
251 bool fFreshFrame; 276 bool fFreshFrame;
252 bool fCanDiscardCanvasContents; 277 bool fCanDiscardCanvasContents;
253 size_t fMaxRecordingStorageBytes; 278 size_t fMaxRecordingStorageBytes;
254 size_t fPreviousStorageAllocated; 279 size_t fPreviousStorageAllocated;
255 size_t fBitmapSizeThreshold; 280 size_t fBitmapSizeThreshold;
256 }; 281 };
257 282
258 DeferredDevice::DeferredDevice(SkSurface* surface) 283 DeferredDevice::DeferredDevice(SkSurface* surface) {
259 : SkBitmapDevice(SkBitmap::kNo_Config,
260 surface->getCanvas()->getDevice()->width(),
261 surface->getCanvas()->getDevice()->height(),
262 surface->getCanvas()->getDevice()->isOpaque(),
263 surface->getCanvas()->getDevice()->getDeviceProperties()) {
264 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; 284 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes;
265 fNotificationClient = NULL; 285 fNotificationClient = NULL;
266 fImmediateCanvas = NULL; 286 fImmediateCanvas = NULL;
267 fSurface = NULL; 287 fSurface = NULL;
268 this->setSurface(surface); 288 this->setSurface(surface);
269 this->init(); 289 this->init();
270 } 290 }
271 291
272 void DeferredDevice::setSurface(SkSurface* surface) { 292 void DeferredDevice::setSurface(SkSurface* surface) {
273 SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas()); 293 SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas());
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 440 }
421 441
422 int DeferredDevice::width() const { 442 int DeferredDevice::width() const {
423 return immediateDevice()->width(); 443 return immediateDevice()->width();
424 } 444 }
425 445
426 int DeferredDevice::height() const { 446 int DeferredDevice::height() const {
427 return immediateDevice()->height(); 447 return immediateDevice()->height();
428 } 448 }
429 449
450 SkBitmap::Config DeferredDevice::config() const {
451 return immediateDevice()->config();
452 }
453
454 bool DeferredDevice::isOpaque() const {
455 return immediateDevice()->isOpaque();
456 }
457
458 SkImageInfo DeferredDevice::imageInfo() const {
459 return immediateDevice()->imageInfo();
460 }
461
430 GrRenderTarget* DeferredDevice::accessRenderTarget() { 462 GrRenderTarget* DeferredDevice::accessRenderTarget() {
431 this->flushPendingCommands(kNormal_PlaybackMode); 463 this->flushPendingCommands(kNormal_PlaybackMode);
432 return immediateDevice()->accessRenderTarget(); 464 return immediateDevice()->accessRenderTarget();
433 } 465 }
434 466
435 void DeferredDevice::prepareForImmediatePixelWrite() { 467 void DeferredDevice::prepareForImmediatePixelWrite() {
436 // The purpose of the following code is to make sure commands are flushed, t hat 468 // The purpose of the following code is to make sure commands are flushed, t hat
437 // aboutToDraw() is called and that notifyContentWillChange is called, witho ut 469 // aboutToDraw() is called and that notifyContentWillChange is called, witho ut
438 // calling anything redundantly. 470 // calling anything redundantly.
439 if (fPipeController.hasPendingCommands()) { 471 if (fPipeController.hasPendingCommands()) {
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { 1020 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) {
989 this->drawingCanvas()->setDrawFilter(filter); 1021 this->drawingCanvas()->setDrawFilter(filter);
990 this->INHERITED::setDrawFilter(filter); 1022 this->INHERITED::setDrawFilter(filter);
991 this->recordedDrawCommand(); 1023 this->recordedDrawCommand();
992 return filter; 1024 return filter;
993 } 1025 }
994 1026
995 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { 1027 SkCanvas* SkDeferredCanvas::canvasForDrawIter() {
996 return this->drawingCanvas(); 1028 return this->drawingCanvas();
997 } 1029 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698