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

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

Issue 926843003: Move canvas->surface association to the device subclasses (Closed) Base URL: https://skia.googlesource.com/skia.git@skimage-filters-03-sksurface-set-root-device-simple
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/image/SkSurface_Base.h ('k') | src/image/SkSurface_Raster.cpp » ('j') | 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)) {
23 fDevice->setSurface(this);
24 } 24 }
25 25
26 SkSurface_Gpu::~SkSurface_Gpu() { 26 SkSurface_Gpu::~SkSurface_Gpu() {
27 // In case the device outlives this instance, make sure device does not try to access this.
28 fDevice->setSurface(NULL);
27 fDevice->unref(); 29 fDevice->unref();
28 } 30 }
29 31
30 SkCanvas* SkSurface_Gpu::onNewCanvas() { 32 SkCanvas* SkSurface_Gpu::onNewCanvas() {
31 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; 33 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags;
32 // When we think this works... 34 // When we think this works...
33 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; 35 // flags |= SkCanvas::kConservativeRasterClip_InitFlag;
34 36
35 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags)); 37 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags));
36 } 38 }
(...skipping 25 matching lines...) Expand all
62 // Create a new render target and, if necessary, copy the contents of the old 64 // Create a new render target and, if necessary, copy the contents of the old
63 // render target into it. Note that this flushes the SkGpuDevice but 65 // render target into it. Note that this flushes the SkGpuDevice but
64 // doesn't force an OpenGL flush. 66 // doesn't force an OpenGL flush.
65 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { 67 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) {
66 GrRenderTarget* rt = fDevice->accessRenderTarget(); 68 GrRenderTarget* rt = fDevice->accessRenderTarget();
67 // are we sharing our render target with the image? Note this call should ne ver create a new 69 // 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. 70 // image because onCopyOnWrite is only called when there is a cached image.
69 SkImage* image = this->getCachedImage(kNo_Budgeted); 71 SkImage* image = this->getCachedImage(kNo_Budgeted);
70 SkASSERT(image); 72 SkASSERT(image);
71 if (rt->asTexture() == SkTextureImageGetTexture(image)) { 73 if (rt->asTexture() == SkTextureImageGetTexture(image)) {
72 GrRenderTarget* oldRT = this->fDevice->accessRenderTarget(); 74 fDevice->detachBackendRenderTarget(kRetain_ContentChangeMode == mode);
73 SkSurface::Budgeted budgeted = oldRT->resourcePriv().isBudgeted() ? kYes _Budgeted :
74 kNo_Budgeted;
75 SkAutoTUnref<GrRenderTarget> newRT(
76 SkGpuDevice::CreateRenderTarget(oldRT->getContext(), budgeted, fDevi ce->imageInfo(),
77 oldRT->numSamples()));
78
79 if (kRetain_ContentChangeMode == mode && !oldRT->wasDestroyed() && newRT ) {
80 oldRT->getContext()->copySurface(newRT, oldRT);
81 }
82
83 SkASSERT(this->getCachedCanvas());
84 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice);
85
86 this->fDevice->swapRenderTarget(newRT);
87
88 SkTextureImageApplyBudgetedDecision(image); 75 SkTextureImageApplyBudgetedDecision(image);
89 } else if (kDiscard_ContentChangeMode == mode) { 76 } else if (kDiscard_ContentChangeMode == mode) {
90 this->SkSurface_Gpu::onDiscard(); 77 this->SkSurface_Gpu::onDiscard();
91 } 78 }
92 } 79 }
93 80
94 void SkSurface_Gpu::onDiscard() { 81 void SkSurface_Gpu::onDiscard() {
95 fDevice->accessRenderTarget()->discard(); 82 fDevice->accessRenderTarget()->discard();
96 } 83 }
97 84
(...skipping 16 matching lines...) Expand all
114 return NULL; 101 return NULL;
115 } 102 }
116 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, SkGpuDevice: :kNeedClear_Flag)); 103 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, SkGpuDevice: :kNeedClear_Flag));
117 if (NULL == device) { 104 if (NULL == device) {
118 return NULL; 105 return NULL;
119 } 106 }
120 return SkNEW_ARGS(SkSurface_Gpu, (device)); 107 return SkNEW_ARGS(SkSurface_Gpu, (device));
121 } 108 }
122 109
123 #endif 110 #endif
OLDNEW
« no previous file with comments | « src/image/SkSurface_Base.h ('k') | src/image/SkSurface_Raster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698