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

Side by Side Diff: src/pipe/SkGPipeWrite.cpp

Issue 194923008: Revert "De-virtualize SkCanvas save/restore." (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 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/core/SkPictureRecord.cpp ('k') | src/utils/SkDeferredCanvas.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 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 "SkAnnotation.h" 9 #include "SkAnnotation.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 222 }
223 223
224 void flushRecording(bool detachCurrentBlock); 224 void flushRecording(bool detachCurrentBlock);
225 size_t freeMemoryIfPossible(size_t bytesToFree); 225 size_t freeMemoryIfPossible(size_t bytesToFree);
226 226
227 size_t storageAllocatedForRecording() { 227 size_t storageAllocatedForRecording() {
228 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->bytesAllocated(); 228 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->bytesAllocated();
229 } 229 }
230 230
231 // overrides from SkCanvas 231 // overrides from SkCanvas
232 virtual int save(SaveFlags) SK_OVERRIDE;
233 virtual int saveLayer(const SkRect* bounds, const SkPaint*,
234 SaveFlags) SK_OVERRIDE;
235 virtual void restore() SK_OVERRIDE;
232 virtual bool isDrawingToLayer() const SK_OVERRIDE; 236 virtual bool isDrawingToLayer() const SK_OVERRIDE;
233 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; 237 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
234 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; 238 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
235 virtual bool rotate(SkScalar degrees) SK_OVERRIDE; 239 virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
236 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE; 240 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
237 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE; 241 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
238 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; 242 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
239 virtual void clear(SkColor) SK_OVERRIDE; 243 virtual void clear(SkColor) SK_OVERRIDE;
240 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; 244 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
241 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], 245 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; 280 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
277 virtual void endCommentGroup() SK_OVERRIDE; 281 virtual void endCommentGroup() SK_OVERRIDE;
278 282
279 /** 283 /**
280 * Flatten an SkBitmap to send to the reader, where it will be referenced 284 * Flatten an SkBitmap to send to the reader, where it will be referenced
281 * according to slot. 285 * according to slot.
282 */ 286 */
283 bool shuttleBitmap(const SkBitmap&, int32_t slot); 287 bool shuttleBitmap(const SkBitmap&, int32_t slot);
284 288
285 protected: 289 protected:
286 virtual void onSave(SaveFlags) SK_OVERRIDE;
287 virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRI DE;
288 virtual void onRestore() SK_OVERRIDE;
289
290 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK _OVERRIDE; 290 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK _OVERRIDE;
291 291
292 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERR IDE; 292 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERR IDE;
293 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVE RRIDE; 293 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVE RRIDE;
294 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERR IDE; 294 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERR IDE;
295 virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; 295 virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE;
296 296
297 private: 297 private:
298 enum { 298 enum {
299 kNoSaveLayer = -1, 299 kNoSaveLayer = -1,
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 } 507 }
508 } 508 }
509 return id; 509 return id;
510 } 510 }
511 511
512 /////////////////////////////////////////////////////////////////////////////// 512 ///////////////////////////////////////////////////////////////////////////////
513 513
514 #define NOTIFY_SETUP(canvas) \ 514 #define NOTIFY_SETUP(canvas) \
515 AutoPipeNotify apn(canvas) 515 AutoPipeNotify apn(canvas)
516 516
517 void SkGPipeCanvas::onSave(SaveFlags flags) { 517 int SkGPipeCanvas::save(SaveFlags flags) {
518 NOTIFY_SETUP(this); 518 NOTIFY_SETUP(this);
519 if (this->needOpBytes()) { 519 if (this->needOpBytes()) {
520 this->writeOp(kSave_DrawOp, 0, flags); 520 this->writeOp(kSave_DrawOp, 0, flags);
521 } 521 }
522 522 return this->INHERITED::save(flags);
523 this->INHERITED::onSave(flags);
524 } 523 }
525 524
526 bool SkGPipeCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint, 525 int SkGPipeCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
527 SaveFlags saveFlags) { 526 SaveFlags saveFlags) {
528 NOTIFY_SETUP(this); 527 NOTIFY_SETUP(this);
529 size_t size = 0; 528 size_t size = 0;
530 unsigned opFlags = 0; 529 unsigned opFlags = 0;
531 530
532 if (bounds) { 531 if (bounds) {
533 opFlags |= kSaveLayer_HasBounds_DrawOpFlag; 532 opFlags |= kSaveLayer_HasBounds_DrawOpFlag;
534 size += sizeof(SkRect); 533 size += sizeof(SkRect);
535 } 534 }
536 if (paint) { 535 if (paint) {
537 opFlags |= kSaveLayer_HasPaint_DrawOpFlag; 536 opFlags |= kSaveLayer_HasPaint_DrawOpFlag;
538 this->writePaint(*paint); 537 this->writePaint(*paint);
539 } 538 }
540 539
541 if (this->needOpBytes(size)) { 540 if (this->needOpBytes(size)) {
542 this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags); 541 this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags);
543 if (bounds) { 542 if (bounds) {
544 fWriter.writeRect(*bounds); 543 fWriter.writeRect(*bounds);
545 } 544 }
546 } 545 }
547 546
548 if (kNoSaveLayer == fFirstSaveLayerStackLevel){ 547 if (kNoSaveLayer == fFirstSaveLayerStackLevel){
549 fFirstSaveLayerStackLevel = this->getSaveCount(); 548 fFirstSaveLayerStackLevel = this->getSaveCount();
550 } 549 }
551 550 // we just pass on the save, so we don't create a layer
552 this->INHERITED::onSaveLayer(bounds, paint, saveFlags); 551 return this->INHERITED::save(saveFlags);
553 // we don't create a layer
554 return false;
555 } 552 }
556 553
557 void SkGPipeCanvas::onRestore() { 554 void SkGPipeCanvas::restore() {
558 NOTIFY_SETUP(this); 555 NOTIFY_SETUP(this);
559 if (this->needOpBytes()) { 556 if (this->needOpBytes()) {
560 this->writeOp(kRestore_DrawOp); 557 this->writeOp(kRestore_DrawOp);
561 } 558 }
562 559
563 if (this->getSaveCount() - 1 == fFirstSaveLayerStackLevel){ 560 this->INHERITED::restore();
561
562 if (this->getSaveCount() == fFirstSaveLayerStackLevel){
564 fFirstSaveLayerStackLevel = kNoSaveLayer; 563 fFirstSaveLayerStackLevel = kNoSaveLayer;
565 } 564 }
566
567 this->INHERITED::onRestore();
568 } 565 }
569 566
570 bool SkGPipeCanvas::isDrawingToLayer() const { 567 bool SkGPipeCanvas::isDrawingToLayer() const {
571 return kNoSaveLayer != fFirstSaveLayerStackLevel; 568 return kNoSaveLayer != fFirstSaveLayerStackLevel;
572 } 569 }
573 570
574 bool SkGPipeCanvas::translate(SkScalar dx, SkScalar dy) { 571 bool SkGPipeCanvas::translate(SkScalar dx, SkScalar dy) {
575 if (dx || dy) { 572 if (dx || dy) {
576 NOTIFY_SETUP(this); 573 NOTIFY_SETUP(this);
577 if (this->needOpBytes(2 * sizeof(SkScalar))) { 574 if (this->needOpBytes(2 * sizeof(SkScalar))) {
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 return fCanvas->shuttleBitmap(bitmap, slot); 1254 return fCanvas->shuttleBitmap(bitmap, slot);
1258 } 1255 }
1259 1256
1260 void BitmapShuttle::removeCanvas() { 1257 void BitmapShuttle::removeCanvas() {
1261 if (NULL == fCanvas) { 1258 if (NULL == fCanvas) {
1262 return; 1259 return;
1263 } 1260 }
1264 fCanvas->unref(); 1261 fCanvas->unref();
1265 fCanvas = NULL; 1262 fCanvas = NULL;
1266 } 1263 }
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.cpp ('k') | src/utils/SkDeferredCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698