| 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 25 matching lines...) Expand all Loading... |
| 36 SkImage* image = this->newImageSnapshot(); | 36 SkImage* image = this->newImageSnapshot(); |
| 37 if (image) { | 37 if (image) { |
| 38 image->draw(canvas, x, y, paint); | 38 image->draw(canvas, x, y, paint); |
| 39 image->unref(); | 39 image->unref(); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 void SkSurface_Base::aboutToDraw(ContentChangeMode mode) { | 43 void SkSurface_Base::aboutToDraw(ContentChangeMode mode) { |
| 44 this->dirtyGenerationID(); | 44 this->dirtyGenerationID(); |
| 45 | 45 |
| 46 if (NULL != fCachedCanvas) { | 46 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); |
| 47 SkASSERT(fCachedCanvas->getSurfaceBase() == this || \ | |
| 48 NULL == fCachedCanvas->getSurfaceBase()); | |
| 49 fCachedCanvas->setSurfaceBase(NULL); | |
| 50 } | |
| 51 | 47 |
| 52 if (NULL != fCachedImage) { | 48 if (NULL != fCachedImage) { |
| 53 // the surface may need to fork its backend, if its sharing it with | 49 // the surface may need to fork its backend, if its sharing it with |
| 54 // the cached image. Note: we only call if there is an outstanding owner | 50 // the cached image. Note: we only call if there is an outstanding owner |
| 55 // on the image (besides us). | 51 // on the image (besides us). |
| 56 if (!fCachedImage->unique()) { | 52 if (!fCachedImage->unique()) { |
| 57 this->onCopyOnWrite(mode); | 53 this->onCopyOnWrite(mode); |
| 58 } | 54 } |
| 59 | 55 |
| 60 // regardless of copy-on-write, we must drop our cached image now, so | 56 // regardless of copy-on-write, we must drop our cached image now, so |
| 61 // that the next request will get our new contents. | 57 // that the next request will get our new contents. |
| 62 fCachedImage->unref(); | 58 fCachedImage->unref(); |
| 63 fCachedImage = NULL; | 59 fCachedImage = NULL; |
| 60 } else if (kDiscard_ContentChangeMode == mode) { |
| 61 this->onDiscard(); |
| 64 } | 62 } |
| 65 } | 63 } |
| 66 | 64 |
| 67 uint32_t SkSurface_Base::newGenerationID() { | 65 uint32_t SkSurface_Base::newGenerationID() { |
| 68 this->installIntoCanvasForDirtyNotification(); | 66 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); |
| 69 | |
| 70 static int32_t gID; | 67 static int32_t gID; |
| 71 return sk_atomic_inc(&gID) + 1; | 68 return sk_atomic_inc(&gID) + 1; |
| 72 } | 69 } |
| 73 | 70 |
| 74 static SkSurface_Base* asSB(SkSurface* surface) { | 71 static SkSurface_Base* asSB(SkSurface* surface) { |
| 75 return static_cast<SkSurface_Base*>(surface); | 72 return static_cast<SkSurface_Base*>(surface); |
| 76 } | 73 } |
| 77 | 74 |
| 78 /////////////////////////////////////////////////////////////////////////////// | 75 /////////////////////////////////////////////////////////////////////////////// |
| 79 | 76 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 115 } |
| 119 | 116 |
| 120 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, | 117 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, |
| 121 const SkPaint* paint) { | 118 const SkPaint* paint) { |
| 122 return asSB(this)->onDraw(canvas, x, y, paint); | 119 return asSB(this)->onDraw(canvas, x, y, paint); |
| 123 } | 120 } |
| 124 | 121 |
| 125 const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) { | 122 const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) { |
| 126 return this->getCanvas()->peekPixels(info, rowBytes); | 123 return this->getCanvas()->peekPixels(info, rowBytes); |
| 127 } | 124 } |
| OLD | NEW |