| 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 #include "SkSurface_Base.h" | 8 #include "SkSurface_Base.h" |
| 9 #include "SkImagePriv.h" | 9 #include "SkImagePriv.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 | 63 |
| 64 SkSurface_Base::SkSurface_Base(const SkImageInfo& info, const SkSurfaceProps* pr
ops) | 64 SkSurface_Base::SkSurface_Base(const SkImageInfo& info, const SkSurfaceProps* pr
ops) |
| 65 : INHERITED(info, props) | 65 : INHERITED(info, props) |
| 66 { | 66 { |
| 67 fCachedCanvas = NULL; | 67 fCachedCanvas = NULL; |
| 68 fCachedImage = NULL; | 68 fCachedImage = NULL; |
| 69 } | 69 } |
| 70 | 70 |
| 71 SkSurface_Base::~SkSurface_Base() { | 71 SkSurface_Base::~SkSurface_Base() { |
| 72 // in case the canvas outsurvives us, we null the callback | |
| 73 if (fCachedCanvas) { | |
| 74 fCachedCanvas->setSurfaceBase(NULL); | |
| 75 } | |
| 76 | |
| 77 SkSafeUnref(fCachedImage); | 72 SkSafeUnref(fCachedImage); |
| 78 SkSafeUnref(fCachedCanvas); | 73 SkSafeUnref(fCachedCanvas); |
| 79 } | 74 } |
| 80 | 75 |
| 81 void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa
int* paint) { | 76 void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa
int* paint) { |
| 82 SkImage* image = this->newImageSnapshot(kYes_Budgeted); | 77 SkImage* image = this->newImageSnapshot(kYes_Budgeted); |
| 83 if (image) { | 78 if (image) { |
| 84 canvas->drawImage(image, x, y, paint); | 79 canvas->drawImage(image, x, y, paint); |
| 85 image->unref(); | 80 image->unref(); |
| 86 } | 81 } |
| 87 } | 82 } |
| 88 | 83 |
| 89 void SkSurface_Base::aboutToDraw(ContentChangeMode mode) { | 84 void SkSurface_Base::aboutToDraw(ContentChangeMode mode) { |
| 90 this->dirtyGenerationID(); | 85 this->dirtyGenerationID(); |
| 91 | 86 |
| 92 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); | |
| 93 | |
| 94 if (fCachedImage) { | 87 if (fCachedImage) { |
| 95 // the surface may need to fork its backend, if its sharing it with | 88 // the surface may need to fork its backend, if its sharing it with |
| 96 // the cached image. Note: we only call if there is an outstanding owner | 89 // the cached image. Note: we only call if there is an outstanding owner |
| 97 // on the image (besides us). | 90 // on the image (besides us). |
| 98 if (!fCachedImage->unique()) { | 91 if (!fCachedImage->unique()) { |
| 99 this->onCopyOnWrite(mode); | 92 this->onCopyOnWrite(mode); |
| 100 } | 93 } |
| 101 | 94 |
| 102 // regardless of copy-on-write, we must drop our cached image now, so | 95 // regardless of copy-on-write, we must drop our cached image now, so |
| 103 // that the next request will get our new contents. | 96 // that the next request will get our new contents. |
| 104 fCachedImage->unref(); | 97 fCachedImage->unref(); |
| 105 fCachedImage = NULL; | 98 fCachedImage = NULL; |
| 106 } else if (kDiscard_ContentChangeMode == mode) { | 99 } else if (kDiscard_ContentChangeMode == mode) { |
| 107 this->onDiscard(); | 100 this->onDiscard(); |
| 108 } | 101 } |
| 109 } | 102 } |
| 110 | 103 |
| 111 uint32_t SkSurface_Base::newGenerationID() { | 104 uint32_t SkSurface_Base::newGenerationID() { |
| 112 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); | |
| 113 static int32_t gID; | 105 static int32_t gID; |
| 114 return sk_atomic_inc(&gID) + 1; | 106 return sk_atomic_inc(&gID) + 1; |
| 115 } | 107 } |
| 116 | 108 |
| 117 static SkSurface_Base* asSB(SkSurface* surface) { | 109 static SkSurface_Base* asSB(SkSurface* surface) { |
| 118 return static_cast<SkSurface_Base*>(surface); | 110 return static_cast<SkSurface_Base*>(surface); |
| 119 } | 111 } |
| 120 | 112 |
| 121 /////////////////////////////////////////////////////////////////////////////// | 113 /////////////////////////////////////////////////////////////////////////////// |
| 122 | 114 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 return NULL; | 175 return NULL; |
| 184 } | 176 } |
| 185 | 177 |
| 186 SkSurface* SkSurface::NewRenderTarget(GrContext*, Budgeted, const SkImageInfo&,
int, | 178 SkSurface* SkSurface::NewRenderTarget(GrContext*, Budgeted, const SkImageInfo&,
int, |
| 187 const SkSurfaceProps*) { | 179 const SkSurfaceProps*) { |
| 188 return NULL; | 180 return NULL; |
| 189 } | 181 } |
| 190 | 182 |
| 191 | 183 |
| 192 #endif | 184 #endif |
| OLD | NEW |