Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: src/image/SkSurface_Gpu.cpp

Issue 925343002: Swap render target instead of creating a new gpu device for surface copy-on-write (Closed) Base URL: https://skia.googlesource.com/skia.git@skimage-filters-02-use-sksurface-constructor-skgpudevice
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_Gpu.h" 8 #include "SkSurface_Gpu.h"
9 9
10 #include "GrGpuResourcePriv.h"
11 #include "SkCanvas.h" 10 #include "SkCanvas.h"
12 #include "SkGpuDevice.h" 11 #include "SkGpuDevice.h"
13 #include "SkImage_Base.h" 12 #include "SkImage_Base.h"
14 #include "SkImagePriv.h" 13 #include "SkImagePriv.h"
15 #include "SkSurface_Base.h" 14 #include "SkSurface_Base.h"
16 15
17 #if SK_SUPPORT_GPU 16 #if SK_SUPPORT_GPU
18 17
19 /////////////////////////////////////////////////////////////////////////////// 18 ///////////////////////////////////////////////////////////////////////////////
20 19
21 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) 20 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device)
22 : INHERITED(device->width(), device->height(), &device->surfaceProps()) 21 : INHERITED(device->width(), device->height(), &device->surfaceProps())
23 , fDevice(SkRef(device)) { 22 , fDevice(SkRef(device)) {
24 } 23 }
25 24
26 SkSurface_Gpu::~SkSurface_Gpu() { 25 SkSurface_Gpu::~SkSurface_Gpu() {
27 SkSafeUnref(fDevice); 26 fDevice->unref();
28 } 27 }
29 28
30 SkCanvas* SkSurface_Gpu::onNewCanvas() { 29 SkCanvas* SkSurface_Gpu::onNewCanvas() {
31 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; 30 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags;
32 // When we think this works... 31 // When we think this works...
33 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; 32 // flags |= SkCanvas::kConservativeRasterClip_InitFlag;
34 33
35 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags)); 34 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags));
36 } 35 }
37 36
(...skipping 14 matching lines...) Expand all
52 as_IB(image)->initWithProps(this->props()); 51 as_IB(image)->initWithProps(this->props());
53 } 52 }
54 return image; 53 return image;
55 } 54 }
56 55
57 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 56 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
58 const SkPaint* paint) { 57 const SkPaint* paint) {
59 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); 58 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint);
60 } 59 }
61 60
62 // Create a new SkGpuDevice and, if necessary, copy the contents of the old 61 // Create a new render target and, if necessary, copy the contents of the old
63 // device into it. Note that this flushes the SkGpuDevice but 62 // render target into it. Note that this flushes the SkGpuDevice but
64 // doesn't force an OpenGL flush. 63 // doesn't force an OpenGL flush.
65 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { 64 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) {
66 GrRenderTarget* rt = fDevice->accessRenderTarget(); 65 GrRenderTarget* rt = fDevice->accessRenderTarget();
67 // are we sharing our render target with the image? Note this call should ne ver create a new 66 // are we sharing our render target with the image? Note this call should ne ver create a new
68 // image because onCopyOnWrite is only called when there is a cached image. 67 // image because onCopyOnWrite is only called when there is a cached image.
69 SkImage* image = this->getCachedImage(kNo_Budgeted); 68 SkImage* image = this->getCachedImage(kNo_Budgeted);
70 SkASSERT(image); 69 SkASSERT(image);
71 if (rt->asTexture() == SkTextureImageGetTexture(image)) { 70 if (rt->asTexture() == SkTextureImageGetTexture(image)) {
72 GrRenderTarget* oldRT = this->fDevice->accessRenderTarget(); 71 this->fDevice->replaceRenderTarget(SkSurface::kRetain_ContentChangeMode == mode);
73 SkSurface::Budgeted budgeted = oldRT->resourcePriv().isBudgeted() ? kYes _Budgeted :
74 kNo_ Budgeted;
75 SkAutoTUnref<SkGpuDevice> newDevice(
76 SkGpuDevice::Create(oldRT->getContext(), budgeted, fDevice->imageInf o(),
77 oldRT->numSamples(), &this->props(), 0));
78 if (kRetain_ContentChangeMode == mode && !oldRT->wasDestroyed() && newDe vice) {
79 oldRT->getContext()->copySurface(newDevice->accessRenderTarget(), ol dRT);
80 }
81
82 SkASSERT(this->getCachedCanvas());
83 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice);
84
85 this->getCachedCanvas()->setRootDevice(newDevice);
86 SkRefCnt_SafeAssign(fDevice, newDevice.get());
87
88 SkTextureImageApplyBudgetedDecision(image); 72 SkTextureImageApplyBudgetedDecision(image);
89 } else if (kDiscard_ContentChangeMode == mode) { 73 } else if (kDiscard_ContentChangeMode == mode) {
90 this->SkSurface_Gpu::onDiscard(); 74 this->SkSurface_Gpu::onDiscard();
91 } 75 }
92 } 76 }
93 77
94 void SkSurface_Gpu::onDiscard() { 78 void SkSurface_Gpu::onDiscard() {
95 fDevice->accessRenderTarget()->discard(); 79 fDevice->accessRenderTarget()->discard();
96 } 80 }
97 81
(...skipping 11 matching lines...) Expand all
109 int sampleCount, const SkSurfaceProps* pro ps) { 93 int sampleCount, const SkSurfaceProps* pro ps) {
110 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(ctx, budgeted, info, sa mpleCount, props, 94 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(ctx, budgeted, info, sa mpleCount, props,
111 SkGpuDevice::kNeedClear _Flag)); 95 SkGpuDevice::kNeedClear _Flag));
112 if (!device) { 96 if (!device) {
113 return NULL; 97 return NULL;
114 } 98 }
115 return SkNEW_ARGS(SkSurface_Gpu, (device)); 99 return SkNEW_ARGS(SkSurface_Gpu, (device));
116 } 100 }
117 101
118 #endif 102 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698