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

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

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