diff options
author | 2015-02-22 22:53:44 -0800 | |
---|---|---|
committer | 2015-02-22 22:53:44 -0800 | |
commit | abcfab4d68d53900ef33320bb2622696c14d14b0 (patch) | |
tree | 8ea70d5b22a26ba36811f51bb97361c9bb1e96d6 /src/image/SkSurface_Gpu.cpp | |
parent | 54bf133ca445011e54cd4a98f9be14681869991f (diff) |
Swap render target instead of creating a new gpu device for surface copy-on-write
Swap render target of the gpu device instead of creating a new gpu
device when making a copy-on-write upon surface modification.
This removes the SkCanvas::setRootDevice which contains problematic code
when trying to increase the use of SkImages internally in Skia.
BUG=skia:3388
Review URL: https://codereview.chromium.org/925343002
Diffstat (limited to 'src/image/SkSurface_Gpu.cpp')
-rw-r--r-- | src/image/SkSurface_Gpu.cpp | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index a1c31f3137..b94e4e30bd 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -7,7 +7,6 @@ #include "SkSurface_Gpu.h" -#include "GrGpuResourcePriv.h" #include "SkCanvas.h" #include "SkGpuDevice.h" #include "SkImage_Base.h" @@ -24,7 +23,7 @@ SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) } SkSurface_Gpu::~SkSurface_Gpu() { - SkSafeUnref(fDevice); + fDevice->unref(); } SkCanvas* SkSurface_Gpu::onNewCanvas() { @@ -59,8 +58,8 @@ void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); } -// Create a new SkGpuDevice and, if necessary, copy the contents of the old -// device into it. Note that this flushes the SkGpuDevice but +// Create a new render target and, if necessary, copy the contents of the old +// render target into it. Note that this flushes the SkGpuDevice but // doesn't force an OpenGL flush. void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { GrRenderTarget* rt = fDevice->accessRenderTarget(); @@ -69,22 +68,7 @@ void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { SkImage* image = this->getCachedImage(kNo_Budgeted); SkASSERT(image); if (rt->asTexture() == SkTextureImageGetTexture(image)) { - GrRenderTarget* oldRT = this->fDevice->accessRenderTarget(); - SkSurface::Budgeted budgeted = oldRT->resourcePriv().isBudgeted() ? kYes_Budgeted : - kNo_Budgeted; - SkAutoTUnref<SkGpuDevice> newDevice( - SkGpuDevice::Create(oldRT->getContext(), budgeted, fDevice->imageInfo(), - oldRT->numSamples(), &this->props(), 0)); - if (kRetain_ContentChangeMode == mode && !oldRT->wasDestroyed() && newDevice) { - oldRT->getContext()->copySurface(newDevice->accessRenderTarget(), oldRT); - } - - SkASSERT(this->getCachedCanvas()); - SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); - - this->getCachedCanvas()->setRootDevice(newDevice); - SkRefCnt_SafeAssign(fDevice, newDevice.get()); - + this->fDevice->replaceRenderTarget(SkSurface::kRetain_ContentChangeMode == mode); SkTextureImageApplyBudgetedDecision(image); } else if (kDiscard_ContentChangeMode == mode) { this->SkSurface_Gpu::onDiscard(); |