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

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

Issue 1925803004: Add sk_sp to SkSurface_Gpu and SkGpuDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address code review issues Created 4 years, 7 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_Gpu.h ('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 "GrResourceProvider.h" 10 #include "GrResourceProvider.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkGpuDevice.h" 12 #include "SkGpuDevice.h"
13 #include "SkImage_Base.h" 13 #include "SkImage_Base.h"
14 #include "SkImage_Gpu.h" 14 #include "SkImage_Gpu.h"
15 #include "SkImagePriv.h" 15 #include "SkImagePriv.h"
16 #include "SkSurface_Base.h" 16 #include "SkSurface_Base.h"
17 17
18 #if SK_SUPPORT_GPU 18 #if SK_SUPPORT_GPU
19 19
20 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) 20 SkSurface_Gpu::SkSurface_Gpu(sk_sp<SkGpuDevice> device)
21 : INHERITED(device->width(), device->height(), &device->surfaceProps()) 21 : INHERITED(device->width(), device->height(), &device->surfaceProps())
22 , fDevice(SkRef(device)) { 22 , fDevice(std::move(device)) {
23 } 23 }
24 24
25 SkSurface_Gpu::~SkSurface_Gpu() { 25 SkSurface_Gpu::~SkSurface_Gpu() {
26 fDevice->unref();
27 } 26 }
28 27
29 static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface, 28 static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface,
30 SkSurface::BackendHandleAc cess access) { 29 SkSurface::BackendHandleAc cess access) {
31 switch (access) { 30 switch (access) {
32 case SkSurface::kFlushRead_BackendHandleAccess: 31 case SkSurface::kFlushRead_BackendHandleAccess:
33 break; 32 break;
34 case SkSurface::kFlushWrite_BackendHandleAccess: 33 case SkSurface::kFlushWrite_BackendHandleAccess:
35 case SkSurface::kDiscardWrite_BackendHandleAccess: 34 case SkSurface::kDiscardWrite_BackendHandleAccess:
36 // for now we don't special-case on Discard, but we may in the futur e. 35 // for now we don't special-case on Discard, but we may in the futur e.
(...skipping 21 matching lines...) Expand all
58 bool SkSurface_Gpu::onGetRenderTargetHandle(GrBackendObject* obj, BackendHandleA ccess access) { 57 bool SkSurface_Gpu::onGetRenderTargetHandle(GrBackendObject* obj, BackendHandleA ccess access) {
59 GrRenderTarget* rt = prepare_rt_for_external_access(this, access); 58 GrRenderTarget* rt = prepare_rt_for_external_access(this, access);
60 *obj = rt->getRenderTargetHandle(); 59 *obj = rt->getRenderTargetHandle();
61 return true; 60 return true;
62 } 61 }
63 62
64 SkCanvas* SkSurface_Gpu::onNewCanvas() { 63 SkCanvas* SkSurface_Gpu::onNewCanvas() {
65 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; 64 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags;
66 flags = static_cast<SkCanvas::InitFlags>(flags | SkCanvas::kConservativeRast erClip_InitFlag); 65 flags = static_cast<SkCanvas::InitFlags>(flags | SkCanvas::kConservativeRast erClip_InitFlag);
67 66
68 return new SkCanvas(fDevice, flags); 67 return new SkCanvas(fDevice.get(), flags);
69 } 68 }
70 69
71 sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { 70 sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
72 GrRenderTarget* rt = fDevice->accessRenderTarget(); 71 GrRenderTarget* rt = fDevice->accessRenderTarget();
73 int sampleCount = rt->numColorSamples(); 72 int sampleCount = rt->numColorSamples();
74 // TODO: Make caller specify this (change virtual signature of onNewSurface) . 73 // TODO: Make caller specify this (change virtual signature of onNewSurface) .
75 static const SkBudgeted kBudgeted = SkBudgeted::kNo; 74 static const SkBudgeted kBudgeted = SkBudgeted::kNo;
76 return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, samp leCount, 75 return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, samp leCount,
77 &this->props()); 76 &this->props());
78 } 77 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 128 }
130 129
131 void SkSurface_Gpu::onPrepareForExternalIO() { 130 void SkSurface_Gpu::onPrepareForExternalIO() {
132 fDevice->accessRenderTarget()->prepareForExternalIO(); 131 fDevice->accessRenderTarget()->prepareForExternalIO();
133 } 132 }
134 133
135 /////////////////////////////////////////////////////////////////////////////// 134 ///////////////////////////////////////////////////////////////////////////////
136 135
137 sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget* target, 136 sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget* target,
138 const SkSurfaceProps* props) { 137 const SkSurfaceProps* props) {
139 SkAutoTUnref<SkGpuDevice> device( 138 sk_sp<SkGpuDevice> device(
140 SkGpuDevice::Create(target, props, SkGpuDevice::kUninit_InitContents)); 139 SkGpuDevice::Make(sk_ref_sp(target), props, SkGpuDevice::kUninit_InitCon tents));
141 if (!device) { 140 if (!device) {
142 return nullptr; 141 return nullptr;
143 } 142 }
144 return sk_make_sp<SkSurface_Gpu>(device); 143 return sk_make_sp<SkSurface_Gpu>(std::move(device));
145 } 144 }
146 145
147 sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted , 146 sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted ,
148 const SkImageInfo& info, int sample Count, 147 const SkImageInfo& info, int sample Count,
149 const SkSurfaceProps* props) { 148 const SkSurfaceProps* props) {
150 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create( 149 sk_sp<SkGpuDevice> device(SkGpuDevice::Make(
151 ctx, budgeted, info, sampleCount, props, SkGpuDevice::kClear_InitCon tents)); 150 ctx, budgeted, info, sampleCount, props, SkGpuDevice::kClear_InitCon tents));
152 if (!device) { 151 if (!device) {
153 return nullptr; 152 return nullptr;
154 } 153 }
155 return sk_make_sp<SkSurface_Gpu>(device); 154 return sk_make_sp<SkSurface_Gpu>(std::move(device));
156 } 155 }
157 156
158 sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, 157 sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context,
159 const GrBackendTextureDesc& d esc, 158 const GrBackendTextureDesc& d esc,
160 const SkSurfaceProps* props) { 159 const SkSurfaceProps* props) {
161 if (nullptr == context) { 160 if (nullptr == context) {
162 return nullptr; 161 return nullptr;
163 } 162 }
164 if (!SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) { 163 if (!SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) {
165 return nullptr; 164 return nullptr;
166 } 165 }
167 SkAutoTUnref<GrSurface> surface(context->textureProvider()->wrapBackendTextu re(desc, 166 SkAutoTUnref<GrSurface> surface(context->textureProvider()->wrapBackendTextu re(desc,
168 kBorrow_GrWrapOwnership)); 167 kBorrow_GrWrapOwnership));
169 if (!surface) { 168 if (!surface) {
170 return nullptr; 169 return nullptr;
171 } 170 }
172 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget (), props, 171 sk_sp<SkGpuDevice> device(SkGpuDevice::Make(sk_ref_sp(surface->asRenderTarge t()), props,
173 SkGpuDevice::kUninit_In itContents)); 172 SkGpuDevice::kUninit_InitContent s));
174 if (!device) { 173 if (!device) {
175 return nullptr; 174 return nullptr;
176 } 175 }
177 return sk_make_sp<SkSurface_Gpu>(device); 176 return sk_make_sp<SkSurface_Gpu>(std::move(device));
178 } 177 }
179 178
180 sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context, 179 sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
181 const GrBackendRenderTar getDesc& desc, 180 const GrBackendRenderTar getDesc& desc,
182 const SkSurfaceProps* pr ops) { 181 const SkSurfaceProps* pr ops) {
183 if (nullptr == context) { 182 if (!context) {
184 return nullptr; 183 return nullptr;
185 } 184 }
186 SkAutoTUnref<GrRenderTarget> rt(context->textureProvider()->wrapBackendRende rTarget(desc)); 185 sk_sp<GrRenderTarget> rt(context->textureProvider()->wrapBackendRenderTarget (desc));
187 if (!rt) { 186 if (!rt) {
188 return nullptr; 187 return nullptr;
189 } 188 }
190 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, 189 sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rt), props,
191 SkGpuDevice::kUninit_In itContents)); 190 SkGpuDevice::kUninit_InitContent s));
192 if (!device) { 191 if (!device) {
193 return nullptr; 192 return nullptr;
194 } 193 }
195 return sk_make_sp<SkSurface_Gpu>(device); 194 return sk_make_sp<SkSurface_Gpu>(std::move(device));
196 } 195 }
197 196
198 sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont ext, 197 sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont ext,
199 const GrBackend TextureDesc& desc, 198 const GrBackend TextureDesc& desc,
200 const SkSurface Props* props) { 199 const SkSurface Props* props) {
201 if (nullptr == context) { 200 if (!context) {
202 return nullptr; 201 return nullptr;
203 } 202 }
204 SkAutoTUnref<GrRenderTarget> rt( 203 sk_sp<GrRenderTarget> rt(context->resourceProvider()->wrapBackendTextureAsRe nderTarget(desc));
205 context->resourceProvider()->wrapBackendTextureAsRenderTarget(desc)) ;
206 if (!rt) { 204 if (!rt) {
207 return nullptr; 205 return nullptr;
208 } 206 }
209 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, 207 sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rt), props,
210 SkGpuDevice::kUninit_In itContents)); 208 SkGpuDevice::kUninit_InitContent s));
211 if (!device) { 209 if (!device) {
212 return nullptr; 210 return nullptr;
213 } 211 }
214 return sk_make_sp<SkSurface_Gpu>(device); 212 return sk_make_sp<SkSurface_Gpu>(std::move(device));
215 } 213 }
216 214
217 #endif 215 #endif
OLDNEW
« no previous file with comments | « src/image/SkSurface_Gpu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698