aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image/SkSurface_Gpu.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-22 14:28:01 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-22 14:28:01 +0000
commitc4c9870953037be94da00ac9db887d171f6e479c (patch)
tree3b23c2fd0a4de6ebb38d48b9371a76b9a50296d8 /src/image/SkSurface_Gpu.cpp
parent73c0abc2affdd5703f66c777e1cb3199179f3a09 (diff)
Adding optimization to avoid image copy in SkSurface copy on write when content is discardable
This patch also adds code to SkDeferredCanvas to trigger the optimization. TEST=DeferredSurfaceCopy bench, Surface unit test R=reed@google.com Author: junov@chromium.org Review URL: https://chromiumcodereview.appspot.com/14063015 git-svn-id: http://skia.googlecode.com/svn/trunk@8797 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/image/SkSurface_Gpu.cpp')
-rw-r--r--src/image/SkSurface_Gpu.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 098c92b1b1..687ca6c5ba 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -23,7 +23,7 @@ public:
virtual SkImage* onNewImageSnapshot() SK_OVERRIDE;
virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
const SkPaint*) SK_OVERRIDE;
- virtual void onCopyOnWrite() SK_OVERRIDE;
+ virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE;
private:
SkGpuDevice* fDevice;
@@ -86,9 +86,8 @@ void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
// 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() {
+void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) {
GrRenderTarget* rt = (GrRenderTarget*) fDevice->accessRenderTarget();
-
// are we sharing our render target with the image?
SkASSERT(NULL != this->getCachedImage());
if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) {
@@ -96,8 +95,10 @@ void SkSurface_Gpu::onCopyOnWrite() {
fDevice->createCompatibleDevice(fDevice->config(), fDevice->width(),
fDevice->height(), fDevice->isOpaque()));
SkAutoTUnref<SkGpuDevice> aurd(newDevice);
- fDevice->context()->copyTexture(rt->asTexture(),
- (GrRenderTarget*)newDevice->accessRenderTarget());
+ if (kRetain_ContentChangeMode == mode) {
+ fDevice->context()->copyTexture(rt->asTexture(),
+ reinterpret_cast<GrRenderTarget*>(newDevice->accessRenderTarget()));
+ }
SkASSERT(NULL != this->getCachedCanvas());
SkASSERT(this->getCachedCanvas()->getDevice() == fDevice);
this->getCachedCanvas()->setDevice(newDevice);