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

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

Issue 1789443002: Revert "Revert of add Make variations to return SkImage by sk_sp (patchset #5 id:80001 of https://c… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use get, not release, when calling legacy function that wants ptr Created 4 years, 9 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/SkImage_Gpu.h ('k') | src/image/SkImage_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 "GrCaps.h" 8 #include "GrCaps.h"
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "GrDrawContext.h" 10 #include "GrDrawContext.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // all other combos need to change. 127 // all other combos need to change.
128 // 128 //
129 // Should this be handled by Ganesh? todo:? 129 // Should this be handled by Ganesh? todo:?
130 // 130 //
131 if (kPremul_SkAlphaType == info.alphaType() && kUnpremul_SkAlphaType == fAlp haType) { 131 if (kPremul_SkAlphaType == info.alphaType() && kUnpremul_SkAlphaType == fAlp haType) {
132 apply_premul(info, pixels, rowBytes); 132 apply_premul(info, pixels, rowBytes);
133 } 133 }
134 return true; 134 return true;
135 } 135 }
136 136
137 SkImage* SkImage_Gpu::onNewSubset(const SkIRect& subset) const { 137 sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const {
138 GrContext* ctx = fTexture->getContext(); 138 GrContext* ctx = fTexture->getContext();
139 GrSurfaceDesc desc = fTexture->desc(); 139 GrSurfaceDesc desc = fTexture->desc();
140 desc.fWidth = subset.width(); 140 desc.fWidth = subset.width();
141 desc.fHeight = subset.height(); 141 desc.fHeight = subset.height();
142 142
143 GrTexture* subTx = ctx->textureProvider()->createTexture(desc, fBudgeted); 143 GrTexture* subTx = ctx->textureProvider()->createTexture(desc, fBudgeted);
144 if (!subTx) { 144 if (!subTx) {
145 return nullptr; 145 return nullptr;
146 } 146 }
147 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); 147 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0));
148 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAl phaType, subTx, 148 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID,
149 fBudgeted); 149 fAlphaType, subTx, fBudgeted);
150 } 150 }
151 151
152 //////////////////////////////////////////////////////////////////////////////// /////////////////// 152 //////////////////////////////////////////////////////////////////////////////// ///////////////////
153 153
154 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur eDesc& desc, 154 static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend TextureDesc& desc,
155 SkAlphaType at, GrWrapOwnership owner ship, 155 SkAlphaType at, GrWrapOwnership ownership,
156 SkImage::TextureReleaseProc releasePr oc, 156 SkImage::TextureReleaseProc rel easeProc,
157 SkImage::ReleaseContext releaseCtx) { 157 SkImage::ReleaseContext release Ctx) {
158 if (desc.fWidth <= 0 || desc.fHeight <= 0) { 158 if (desc.fWidth <= 0 || desc.fHeight <= 0) {
159 return nullptr; 159 return nullptr;
160 } 160 }
161 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc, ownership)); 161 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc, ownership));
162 if (!tex) { 162 if (!tex) {
163 return nullptr; 163 return nullptr;
164 } 164 }
165 if (releaseProc) { 165 if (releaseProc) {
166 tex->setRelease(releaseProc, releaseCtx); 166 tex->setRelease(releaseProc, releaseCtx);
167 } 167 }
168 168
169 const SkBudgeted budgeted = SkBudgeted::kNo; 169 const SkBudgeted budgeted = SkBudgeted::kNo;
170 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, tex, budgeted); 170 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID,
171 at, tex, budgeted);
171 } 172 }
172 173
173 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des c, SkAlphaType at, 174 sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDe sc& desc,
174 TextureReleaseProc releaseP, ReleaseContext rel easeC) { 175 SkAlphaType at, TextureReleaseProc relea seP,
176 ReleaseContext releaseC) {
175 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re leaseP, releaseC); 177 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re leaseP, releaseC);
176 } 178 }
177 179
178 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe sc& desc, 180 sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTe xtureDesc& desc,
179 SkAlphaType at) { 181 SkAlphaType at) {
180 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nul lptr, nullptr); 182 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nul lptr, nullptr);
181 } 183 }
182 184
183 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc, 185 sk_sp<SkImage> SkImage::MakeFromTextureCopy(GrContext* ctx, const GrBackendTextu reDesc& desc,
184 SkAlphaType at) { 186 SkAlphaType at) {
185 if (desc.fWidth <= 0 || desc.fHeight <= 0) { 187 if (desc.fWidth <= 0 || desc.fHeight <= 0) {
186 return nullptr; 188 return nullptr;
187 } 189 }
188 190
189 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture( 191 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture(
190 desc, kBorrow_GrWrapOwnership)); 192 desc, kBorrow_GrWrapOwnership));
191 if (!src) { 193 if (!src) {
192 return nullptr; 194 return nullptr;
193 } 195 }
194 196
195 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, SkBudgeted::kYes)); 197 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, SkBudgeted::kYes));
196 if (!dst) { 198 if (!dst) {
197 return nullptr; 199 return nullptr;
198 } 200 }
199 201
200 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst, 202 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID, at, dst,
201 SkBudgeted::kYes); 203 SkBudgeted::kYes);
202 } 204 }
203 205
204 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS pace, 206 sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorSpace,
205 const GrBackendObject yuvTextureHandles [3], 207 const GrBackendObject yuvTexture Handles[3],
206 const SkISize yuvSizes[3], 208 const SkISize yuvSizes[3],
207 GrSurfaceOrigin origin) { 209 GrSurfaceOrigin origin) {
208 const SkBudgeted budgeted = SkBudgeted::kYes; 210 const SkBudgeted budgeted = SkBudgeted::kYes;
209 211
210 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || 212 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 ||
211 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 || 213 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 ||
212 yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0) { 214 yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0) {
213 return nullptr; 215 return nullptr;
214 } 216 }
215 static const GrPixelConfig kConfig = kAlpha_8_GrPixelConfig; 217 static const GrPixelConfig kConfig = kAlpha_8_GrPixelConfig;
216 GrBackendTextureDesc yDesc; 218 GrBackendTextureDesc yDesc;
217 yDesc.fConfig = kConfig; 219 yDesc.fConfig = kConfig;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 270
269 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), 271 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth),
270 SkIntToScalar(dstDesc.fHeight)); 272 SkIntToScalar(dstDesc.fHeight));
271 SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(dst->asRenderTarget ())); 273 SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(dst->asRenderTarget ()));
272 if (!drawContext) { 274 if (!drawContext) {
273 return nullptr; 275 return nullptr;
274 } 276 }
275 277
276 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect); 278 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect);
277 ctx->flushSurfaceWrites(dst); 279 ctx->flushSurfaceWrites(dst);
278 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI D, 280 return sk_make_sp<SkImage_Gpu>(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImag eUniqueID,
279 kOpaque_SkAlphaType, dst, budgeted); 281 kOpaque_SkAlphaType, dst, budgeted);
280 } 282 }
281 283
282 static SkImage* create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, u int32_t id) { 284 static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
283 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams:: ClampNoFilter())); 285 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams:: ClampNoFilter()));
284 if (!texture) { 286 if (!texture) {
285 return nullptr; 287 return nullptr;
286 } 288 }
287 return new SkImage_Gpu(texture->width(), texture->height(), id, at, texture, 289 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, texture,
288 SkBudgeted::kNo); 290 SkBudgeted::kNo);
289 } 291 }
290 292
291 SkImage* SkImage::newTextureImage(GrContext *context) const { 293 sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const {
292 if (!context) { 294 if (!context) {
293 return nullptr; 295 return nullptr;
294 } 296 }
295 if (GrTexture* peek = as_IB(this)->peekTexture()) { 297 if (GrTexture* peek = as_IB(this)->peekTexture()) {
296 return peek->getContext() == context ? SkRef(const_cast<SkImage*>(this)) : nullptr; 298 return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(th is)) : nullptr;
297 } 299 }
298 // No way to check whether a image is premul or not? 300 // No way to check whether a image is premul or not?
299 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e; 301 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e;
300 302
301 if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) { 303 if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) {
302 GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint); 304 GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint);
303 return create_image_from_maker(&maker, at, this->uniqueID()); 305 return create_image_from_maker(&maker, at, this->uniqueID());
304 } 306 }
305 SkBitmap bmp; 307 SkBitmap bmp;
306 if (!this->asLegacyBitmap(&bmp, kRO_LegacyBitmapMode)) { 308 if (!this->asLegacyBitmap(&bmp, kRO_LegacyBitmapMode)) {
307 return nullptr; 309 return nullptr;
308 } 310 }
309 GrBitmapTextureMaker maker(context, bmp); 311 GrBitmapTextureMaker maker(context, bmp);
310 return create_image_from_maker(&maker, at, this->uniqueID()); 312 return create_image_from_maker(&maker, at, this->uniqueID());
311 } 313 }
312 314
313 SkImage* SkImage::NewTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap, 315 sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pi xmap,
314 SkBudgeted budgeted) { 316 SkBudgeted budgeted) {
315 if (!ctx) { 317 if (!ctx) {
316 return nullptr; 318 return nullptr;
317 } 319 }
318 SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap)); 320 SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap));
319 if (!texture) { 321 if (!texture) {
320 return nullptr; 322 return nullptr;
321 } 323 }
322 return new SkImage_Gpu(texture->width(), texture->height(), kNeedNewImageUni queID, 324 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID,
323 pixmap.alphaType(), texture, budgeted); 325 pixmap.alphaType(), texture, budgeted);
324 } 326 }
325 327
326 //////////////////////////////////////////////////////////////////////////////// /////////////////// 328 //////////////////////////////////////////////////////////////////////////////// ///////////////////
327 329
328 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) { 330 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) {
329 GrContext* ctx = src->getContext(); 331 GrContext* ctx = src->getContext();
330 332
331 GrSurfaceDesc desc = src->desc(); 333 GrSurfaceDesc desc = src->desc();
332 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0); 334 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0);
333 if (!dst) { 335 if (!dst) {
334 return nullptr; 336 return nullptr;
335 } 337 }
336 338
337 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 339 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
338 const SkIPoint dstP = SkIPoint::Make(0, 0); 340 const SkIPoint dstP = SkIPoint::Make(0, 0);
339 ctx->copySurface(dst, src, srcR, dstP); 341 ctx->copySurface(dst, src, srcR, dstP);
340 ctx->flushSurfaceWrites(dst); 342 ctx->flushSurfaceWrites(dst);
341 return dst; 343 return dst;
342 } 344 }
343 345
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.h ('k') | src/image/SkImage_Raster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698