Chromium Code Reviews| Index: src/image/SkSurface_Gpu.cpp |
| =================================================================== |
| --- src/image/SkSurface_Gpu.cpp (revision 8402) |
| +++ src/image/SkSurface_Gpu.cpp (working copy) |
| @@ -23,7 +23,7 @@ |
| virtual SkImage* onNewImageShapshot() SK_OVERRIDE; |
| virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, |
| const SkPaint*) SK_OVERRIDE; |
| - virtual void onCopyOnWrite(SkImage*, SkCanvas*) SK_OVERRIDE; |
| + virtual void onCopyOnWrite(SkImage*, SkCanvas*, bool overwrite) SK_OVERRIDE; |
| private: |
| SkGpuDevice* fDevice; |
| @@ -83,31 +83,26 @@ |
| canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); |
| } |
| -// Copy the contents of the SkGpuDevice into a new texture and give that |
| -// texture to the SkImage. Note that this flushes the SkGpuDevice but |
| +// Create a new SkGpuDevice and, if necessary, copy the contents of the old |
| +// device into it. Note that this flushes the SkGpuDevice but |
| // doesn't force an OpenGL flush. |
| -void SkSurface_Gpu::onCopyOnWrite(SkImage* image, SkCanvas*) { |
| +void SkSurface_Gpu::onCopyOnWrite(SkImage* image, SkCanvas* canvas, bool overwrite) { |
| GrRenderTarget* rt = (GrRenderTarget*) fDevice->accessRenderTarget(); |
| // are we sharing our render target with the image? |
| if (rt->asTexture() == SkTextureImageGetTexture(image)) { |
| - GrTextureDesc desc; |
| - // copyTexture requires a render target as the destination |
| - desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| - desc.fWidth = fDevice->width(); |
| - desc.fHeight = fDevice->height(); |
| - desc.fConfig = SkBitmapConfig2GrPixelConfig(fDevice->config()); |
| - desc.fSampleCnt = 0; |
| - |
| - SkAutoTUnref<GrTexture> tex(fDevice->context()->createUncachedTexture(desc, NULL, 0)); |
| - if (NULL == tex) { |
| - SkTextureImageSetTexture(image, NULL); |
| - return; |
| + SkGpuDevice* newDevice = static_cast<SkGpuDevice*>( |
|
Stephen White
2013/03/26 20:51:44
Kind of a style thing, but you could use SkAutoTUn
|
| + fDevice->createCompatibleDevice(fDevice->config(), fDevice->width(), |
| + fDevice->height(), fDevice->isOpaque())); |
| + if (!overwrite) { |
| + fDevice->context()->copyTexture(rt->asTexture(), |
| + (GrRenderTarget*)newDevice->accessRenderTarget()); |
| } |
| - |
| - fDevice->context()->copyTexture(rt->asTexture(), tex->asRenderTarget()); |
| - |
| - SkTextureImageSetTexture(image, tex); |
| + SkASSERT(NULL != canvas); |
| + SkASSERT(canvas->getDevice() == fDevice); |
| + canvas->setDevice(newDevice); |
| + SkSafeUnref(fDevice); |
| + fDevice = newDevice; |
|
Stephen White
2013/03/26 20:51:44
... and SkRefCnt_SafeAssign() here.
|
| } |
| } |