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

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

Issue 196323003: Revert of 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;
236 virtual bool isDrawingToLayer() const SK_OVERRIDE; 232 virtual bool isDrawingToLayer() const SK_OVERRIDE;
237 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; 233 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
238 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; 234 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
239 virtual bool rotate(SkScalar degrees) SK_OVERRIDE; 235 virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
240 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE; 236 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
241 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE; 237 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
242 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; 238 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
243 virtual void clear(SkColor) SK_OVERRIDE; 239 virtual void clear(SkColor) SK_OVERRIDE;
244 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; 240 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
245 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], 241 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; 276 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
281 virtual void endCommentGroup() SK_OVERRIDE; 277 virtual void endCommentGroup() SK_OVERRIDE;
282 278
283 /** 279 /**
284 * Flatten an SkBitmap to send to the reader, where it will be referenced 280 * Flatten an SkBitmap to send to the reader, where it will be referenced
285 * according to slot. 281 * according to slot.
286 */ 282 */
287 bool shuttleBitmap(const SkBitmap&, int32_t slot); 283 bool shuttleBitmap(const SkBitmap&, int32_t slot);
288 284
289 protected: 285 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 int SkGPipeCanvas::save(SaveFlags flags) { 517 void SkGPipeCanvas::onSave(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 return this->INHERITED::save(flags); 522
523 this->INHERITED::onSave(flags);
523 } 524 }
524 525
525 int SkGPipeCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, 526 bool SkGPipeCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
526 SaveFlags saveFlags) { 527 SaveFlags saveFlags) {
527 NOTIFY_SETUP(this); 528 NOTIFY_SETUP(this);
528 size_t size = 0; 529 size_t size = 0;
529 unsigned opFlags = 0; 530 unsigned opFlags = 0;
530 531
531 if (bounds) { 532 if (bounds) {
532 opFlags |= kSaveLayer_HasBounds_DrawOpFlag; 533 opFlags |= kSaveLayer_HasBounds_DrawOpFlag;
533 size += sizeof(SkRect); 534 size += sizeof(SkRect);
534 } 535 }
535 if (paint) { 536 if (paint) {
536 opFlags |= kSaveLayer_HasPaint_DrawOpFlag; 537 opFlags |= kSaveLayer_HasPaint_DrawOpFlag;
537 this->writePaint(*paint); 538 this->writePaint(*paint);
538 } 539 }
539 540
540 if (this->needOpBytes(size)) { 541 if (this->needOpBytes(size)) {
541 this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags); 542 this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags);
542 if (bounds) { 543 if (bounds) {
543 fWriter.writeRect(*bounds); 544 fWriter.writeRect(*bounds);
544 } 545 }
545 } 546 }
546 547
547 if (kNoSaveLayer == fFirstSaveLayerStackLevel){ 548 if (kNoSaveLayer == fFirstSaveLayerStackLevel){
548 fFirstSaveLayerStackLevel = this->getSaveCount(); 549 fFirstSaveLayerStackLevel = this->getSaveCount();
549 } 550 }
550 // we just pass on the save, so we don't create a layer 551
551 return this->INHERITED::save(saveFlags); 552 this->INHERITED::onSaveLayer(bounds, paint, saveFlags);
553 // we don't create a layer
554 return false;
552 } 555 }
553 556
554 void SkGPipeCanvas::restore() { 557 void SkGPipeCanvas::onRestore() {
555 NOTIFY_SETUP(this); 558 NOTIFY_SETUP(this);
556 if (this->needOpBytes()) { 559 if (this->needOpBytes()) {
557 this->writeOp(kRestore_DrawOp); 560 this->writeOp(kRestore_DrawOp);
558 } 561 }
559 562
560 this->INHERITED::restore(); 563 if (this->getSaveCount() - 1 == fFirstSaveLayerStackLevel){
561
562 if (this->getSaveCount() == fFirstSaveLayerStackLevel){
563 fFirstSaveLayerStackLevel = kNoSaveLayer; 564 fFirstSaveLayerStackLevel = kNoSaveLayer;
564 } 565 }
566
567 this->INHERITED::onRestore();
565 } 568 }
566 569
567 bool SkGPipeCanvas::isDrawingToLayer() const { 570 bool SkGPipeCanvas::isDrawingToLayer() const {
568 return kNoSaveLayer != fFirstSaveLayerStackLevel; 571 return kNoSaveLayer != fFirstSaveLayerStackLevel;
569 } 572 }
570 573
571 bool SkGPipeCanvas::translate(SkScalar dx, SkScalar dy) { 574 bool SkGPipeCanvas::translate(SkScalar dx, SkScalar dy) {
572 if (dx || dy) { 575 if (dx || dy) {
573 NOTIFY_SETUP(this); 576 NOTIFY_SETUP(this);
574 if (this->needOpBytes(2 * sizeof(SkScalar))) { 577 if (this->needOpBytes(2 * sizeof(SkScalar))) {
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 return fCanvas->shuttleBitmap(bitmap, slot); 1257 return fCanvas->shuttleBitmap(bitmap, slot);
1255 } 1258 }
1256 1259
1257 void BitmapShuttle::removeCanvas() { 1260 void BitmapShuttle::removeCanvas() {
1258 if (NULL == fCanvas) { 1261 if (NULL == fCanvas) {
1259 return; 1262 return;
1260 } 1263 }
1261 fCanvas->unref(); 1264 fCanvas->unref();
1262 fCanvas = NULL; 1265 fCanvas = NULL;
1263 } 1266 }
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