| OLD | NEW |
| 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 #ifndef SkSurface_Base_DEFINED | 8 #ifndef SkSurface_Base_DEFINED |
| 9 #define SkSurface_Base_DEFINED | 9 #define SkSurface_Base_DEFINED |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 * | 40 * |
| 41 * image = this->newImageSnapshot(); | 41 * image = this->newImageSnapshot(); |
| 42 * if (image) { | 42 * if (image) { |
| 43 * image->draw(canvas, ...); | 43 * image->draw(canvas, ...); |
| 44 * image->unref(); | 44 * image->unref(); |
| 45 * } | 45 * } |
| 46 */ | 46 */ |
| 47 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*); | 47 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*); |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Called as a performance hint when the Surface is allowed to make it's con
tents |
| 51 * undefined. |
| 52 */ |
| 53 virtual void onDiscard() {} |
| 54 |
| 55 /** |
| 50 * If the surface is about to change, we call this so that our subclass | 56 * If the surface is about to change, we call this so that our subclass |
| 51 * can optionally fork their backend (copy-on-write) in case it was | 57 * can optionally fork their backend (copy-on-write) in case it was |
| 52 * being shared with the cachedImage. | 58 * being shared with the cachedImage. |
| 53 */ | 59 */ |
| 54 virtual void onCopyOnWrite(ContentChangeMode) = 0; | 60 virtual void onCopyOnWrite(ContentChangeMode) = 0; |
| 55 | 61 |
| 56 inline SkCanvas* getCachedCanvas(); | 62 inline SkCanvas* getCachedCanvas(); |
| 57 inline SkImage* getCachedImage(); | 63 inline SkImage* getCachedImage(); |
| 58 | 64 |
| 59 // called by SkSurface to compute a new genID | 65 // called by SkSurface to compute a new genID |
| 60 uint32_t newGenerationID(); | 66 uint32_t newGenerationID(); |
| 61 | 67 |
| 62 private: | 68 private: |
| 63 SkCanvas* fCachedCanvas; | 69 SkCanvas* fCachedCanvas; |
| 64 SkImage* fCachedImage; | 70 SkImage* fCachedImage; |
| 65 | 71 |
| 66 void aboutToDraw(ContentChangeMode mode); | 72 void aboutToDraw(ContentChangeMode mode); |
| 67 friend class SkCanvas; | 73 friend class SkCanvas; |
| 68 friend class SkSurface; | 74 friend class SkSurface; |
| 69 | 75 |
| 70 inline void installIntoCanvasForDirtyNotification(); | |
| 71 | |
| 72 typedef SkSurface INHERITED; | 76 typedef SkSurface INHERITED; |
| 73 }; | 77 }; |
| 74 | 78 |
| 75 SkCanvas* SkSurface_Base::getCachedCanvas() { | 79 SkCanvas* SkSurface_Base::getCachedCanvas() { |
| 76 if (NULL == fCachedCanvas) { | 80 if (NULL == fCachedCanvas) { |
| 77 fCachedCanvas = this->onNewCanvas(); | 81 fCachedCanvas = this->onNewCanvas(); |
| 78 this->installIntoCanvasForDirtyNotification(); | 82 if (NULL != fCachedCanvas) { |
| 83 fCachedCanvas->setSurfaceBase(this); |
| 84 } |
| 79 } | 85 } |
| 80 return fCachedCanvas; | 86 return fCachedCanvas; |
| 81 } | 87 } |
| 82 | 88 |
| 83 SkImage* SkSurface_Base::getCachedImage() { | 89 SkImage* SkSurface_Base::getCachedImage() { |
| 84 if (NULL == fCachedImage) { | 90 if (NULL == fCachedImage) { |
| 85 fCachedImage = this->onNewImageSnapshot(); | 91 fCachedImage = this->onNewImageSnapshot(); |
| 86 this->installIntoCanvasForDirtyNotification(); | 92 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); |
| 87 } | 93 } |
| 88 return fCachedImage; | 94 return fCachedImage; |
| 89 } | 95 } |
| 90 | 96 |
| 91 void SkSurface_Base::installIntoCanvasForDirtyNotification() { | |
| 92 if (NULL != fCachedCanvas) { | |
| 93 fCachedCanvas->setSurfaceBase(this); | |
| 94 } | |
| 95 } | |
| 96 | |
| 97 #endif | 97 #endif |
| OLD | NEW |