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

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

Issue 2448593002: Remove SkAutoTUnref and SkAutoTDelete from public includes. (Closed)
Patch Set: And Vulcan. Created 4 years, 1 month 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/SkSurface_Gpu.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 <cstddef> 8 #include <cstddef>
9 #include <cstring> 9 #include <cstring>
10 #include <type_traits> 10 #include <type_traits>
11 11
12 #include "SkAutoPixmapStorage.h" 12 #include "SkAutoPixmapStorage.h"
13 #include "GrCaps.h" 13 #include "GrCaps.h"
14 #include "GrContext.h" 14 #include "GrContext.h"
15 #include "GrDrawContext.h" 15 #include "GrDrawContext.h"
16 #include "GrImageIDTextureAdjuster.h" 16 #include "GrImageIDTextureAdjuster.h"
17 #include "GrTexturePriv.h" 17 #include "GrTexturePriv.h"
18 #include "effects/GrYUVEffect.h" 18 #include "effects/GrYUVEffect.h"
19 #include "SkCanvas.h" 19 #include "SkCanvas.h"
20 #include "SkBitmapCache.h" 20 #include "SkBitmapCache.h"
21 #include "SkGrPriv.h" 21 #include "SkGrPriv.h"
22 #include "SkImage_Gpu.h" 22 #include "SkImage_Gpu.h"
23 #include "SkMipMap.h" 23 #include "SkMipMap.h"
24 #include "SkPixelRef.h" 24 #include "SkPixelRef.h"
25 25
26 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText ure* tex, 26 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, sk_sp< GrTexture> tex,
27 sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted) 27 sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted)
28 : INHERITED(w, h, uniqueID) 28 : INHERITED(w, h, uniqueID)
29 , fTexture(SkRef(tex)) 29 , fTexture(std::move(tex))
30 , fAlphaType(at) 30 , fAlphaType(at)
31 , fBudgeted(budgeted) 31 , fBudgeted(budgeted)
32 , fColorSpace(std::move(colorSpace)) 32 , fColorSpace(std::move(colorSpace))
33 , fAddedRasterVersionToCache(false) 33 , fAddedRasterVersionToCache(false)
34 { 34 {
35 SkASSERT(tex->width() == w); 35 SkASSERT(fTexture->width() == w);
36 SkASSERT(tex->height() == h); 36 SkASSERT(fTexture->height() == h);
37 } 37 }
38 38
39 SkImage_Gpu::~SkImage_Gpu() { 39 SkImage_Gpu::~SkImage_Gpu() {
40 if (fAddedRasterVersionToCache.load()) { 40 if (fAddedRasterVersionToCache.load()) {
41 SkNotifyBitmapGenIDIsStale(this->uniqueID()); 41 SkNotifyBitmapGenIDIsStale(this->uniqueID());
42 } 42 }
43 } 43 }
44 44
45 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { 45 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) {
46 if (image->isTextureBacked()) { 46 if (image->isTextureBacked()) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const { 142 sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const {
143 GrContext* ctx = fTexture->getContext(); 143 GrContext* ctx = fTexture->getContext();
144 GrSurfaceDesc desc = fTexture->desc(); 144 GrSurfaceDesc desc = fTexture->desc();
145 desc.fWidth = subset.width(); 145 desc.fWidth = subset.width();
146 desc.fHeight = subset.height(); 146 desc.fHeight = subset.height();
147 147
148 sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, fBudgeted )); 148 sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, fBudgeted ));
149 if (!subTx) { 149 if (!subTx) {
150 return nullptr; 150 return nullptr;
151 } 151 }
152 ctx->copySurface(subTx.get(), fTexture, subset, SkIPoint::Make(0, 0)); 152 ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0, 0));
153 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID, 153 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID,
154 fAlphaType, subTx.get(), fColorSpace, fBudget ed); 154 fAlphaType, std::move(subTx), fColorSpace, fB udgeted);
155 } 155 }
156 156
157 //////////////////////////////////////////////////////////////////////////////// /////////////////// 157 //////////////////////////////////////////////////////////////////////////////// ///////////////////
158 158
159 static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend TextureDesc& desc, 159 static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend TextureDesc& desc,
160 SkAlphaType at, sk_sp<SkColorSp ace> colorSpace, 160 SkAlphaType at, sk_sp<SkColorSp ace> colorSpace,
161 GrWrapOwnership ownership, 161 GrWrapOwnership ownership,
162 SkImage::TextureReleaseProc rel easeProc, 162 SkImage::TextureReleaseProc rel easeProc,
163 SkImage::ReleaseContext release Ctx) { 163 SkImage::ReleaseContext release Ctx) {
164 if (desc.fWidth <= 0 || desc.fHeight <= 0) { 164 if (desc.fWidth <= 0 || desc.fHeight <= 0) {
165 return nullptr; 165 return nullptr;
166 } 166 }
167 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc, ownership)); 167 sk_sp<GrTexture> tex = ctx->textureProvider()->wrapBackendTexture(desc, owne rship);
168 if (!tex) { 168 if (!tex) {
169 return nullptr; 169 return nullptr;
170 } 170 }
171 if (releaseProc) { 171 if (releaseProc) {
172 tex->setRelease(releaseProc, releaseCtx); 172 tex->setRelease(releaseProc, releaseCtx);
173 } 173 }
174 174
175 const SkBudgeted budgeted = SkBudgeted::kNo; 175 const SkBudgeted budgeted = SkBudgeted::kNo;
176 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID, 176 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID,
177 at, tex, colorSpace, budgeted); 177 at, std::move(tex), std::move(colorSpace), bu dgeted);
178 } 178 }
179 179
180 sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDe sc& desc, 180 sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDe sc& desc,
181 SkAlphaType at, sk_sp<SkColorSpace> cs, 181 SkAlphaType at, sk_sp<SkColorSpace> cs,
182 TextureReleaseProc releaseP, ReleaseCont ext releaseC) { 182 TextureReleaseProc releaseP, ReleaseCont ext releaseC) {
183 return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kBorrow_GrWr apOwnership, 183 return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kBorrow_GrWr apOwnership,
184 releaseP, releaseC); 184 releaseP, releaseC);
185 } 185 }
186 186
187 sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTe xtureDesc& desc, 187 sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTe xtureDesc& desc,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 GrPaint paint; 264 GrPaint paint;
265 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 265 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
266 paint.addColorFragmentProcessor( 266 paint.addColorFragmentProcessor(
267 GrYUVEffect::MakeYUVToRGB(yTex.get(), uTex.get(), vTex.get(), yuvSizes, colorSpace, nv12)); 267 GrYUVEffect::MakeYUVToRGB(yTex.get(), uTex.get(), vTex.get(), yuvSizes, colorSpace, nv12));
268 268
269 const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh t)); 269 const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh t));
270 270
271 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect); 271 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect);
272 ctx->flushSurfaceWrites(drawContext->accessRenderTarget()); 272 ctx->flushSurfaceWrites(drawContext->accessRenderTarget());
273 return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID, 273 return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID,
274 kOpaque_SkAlphaType, drawContext->asTexture() .get(), 274 kOpaque_SkAlphaType, drawContext->asTexture() ,
275 sk_ref_sp(drawContext->getColorSpace()), budg eted); 275 sk_ref_sp(drawContext->getColorSpace()), budg eted);
276 } 276 }
277 277
278 sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, 278 sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace,
279 const GrBackendObject yuvTexture Handles[3], 279 const GrBackendObject yuvTexture Handles[3],
280 const SkISize yuvSizes[3], GrSur faceOrigin origin, 280 const SkISize yuvSizes[3], GrSur faceOrigin origin,
281 sk_sp<SkColorSpace> imageColorSp ace) { 281 sk_sp<SkColorSpace> imageColorSp ace) {
282 return make_from_yuv_textures_copy(ctx, colorSpace, false, yuvTextureHandles , yuvSizes, origin, 282 return make_from_yuv_textures_copy(ctx, colorSpace, false, yuvTextureHandles , yuvSizes, origin,
283 std::move(imageColorSpace)); 283 std::move(imageColorSpace));
284 } 284 }
285 285
286 sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, 286 sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace,
287 const GrBackendObject yuvTextur eHandles[2], 287 const GrBackendObject yuvTextur eHandles[2],
288 const SkISize yuvSizes[2], 288 const SkISize yuvSizes[2],
289 GrSurfaceOrigin origin, 289 GrSurfaceOrigin origin,
290 sk_sp<SkColorSpace> imageColorS pace) { 290 sk_sp<SkColorSpace> imageColorS pace) {
291 return make_from_yuv_textures_copy(ctx, colorSpace, true, yuvTextureHandles, yuvSizes, origin, 291 return make_from_yuv_textures_copy(ctx, colorSpace, true, yuvTextureHandles, yuvSizes, origin,
292 std::move(imageColorSpace)); 292 std::move(imageColorSpace));
293 } 293 }
294 294
295 static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) { 295 static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
296 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams:: ClampNoFilter(), 296 sk_sp<GrTexture> texture(maker->refTextureForParams(GrTextureParams::ClampNo Filter(),
297 SkSourceGammaTrea tment::kRespect)); 297 SkSourceGammaTreatment:: kRespect));
298 if (!texture) { 298 if (!texture) {
299 return nullptr; 299 return nullptr;
300 } 300 }
301 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, texture, 301 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, std::move(texture),
302 sk_ref_sp(maker->getColorSpace()), SkBudgeted ::kNo); 302 sk_ref_sp(maker->getColorSpace()), SkBudgeted ::kNo);
303 } 303 }
304 304
305 sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const { 305 sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const {
306 if (!context) { 306 if (!context) {
307 return nullptr; 307 return nullptr;
308 } 308 }
309 if (GrTexture* peek = as_IB(this)->peekTexture()) { 309 if (GrTexture* peek = as_IB(this)->peekTexture()) {
310 return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(th is)) : nullptr; 310 return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(th is)) : nullptr;
311 } 311 }
(...skipping 26 matching lines...) Expand all
338 return nullptr; 338 return nullptr;
339 } 339 }
340 return MakeRasterData(info, data, rowBytes); 340 return MakeRasterData(info, data, rowBytes);
341 } 341 }
342 342
343 sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pi xmap, 343 sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pi xmap,
344 SkBudgeted budgeted) { 344 SkBudgeted budgeted) {
345 if (!ctx) { 345 if (!ctx) {
346 return nullptr; 346 return nullptr;
347 } 347 }
348 SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap, budgete d)); 348 sk_sp<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap, budgeted));
349 if (!texture) { 349 if (!texture) {
350 return nullptr; 350 return nullptr;
351 } 351 }
352 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID, 352 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID,
353 pixmap.alphaType(), texture, 353 pixmap.alphaType(), std::move(texture),
354 sk_ref_sp(pixmap.info().colorSpace()), budget ed); 354 sk_ref_sp(pixmap.info().colorSpace()), budget ed);
355 } 355 }
356 356
357 //////////////////////////////////////////////////////////////////////////////// /////////////////// 357 //////////////////////////////////////////////////////////////////////////////// ///////////////////
358 358
359 namespace { 359 namespace {
360 struct MipMapLevelData { 360 struct MipMapLevelData {
361 void* fPixelData; 361 void* fPixelData;
362 size_t fRowBytes; 362 size_t fRowBytes;
363 }; 363 };
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 695
696 //////////////////////////////////////////////////////////////////////////////// /////////////////// 696 //////////////////////////////////////////////////////////////////////////////// ///////////////////
697 697
698 sk_sp<SkImage> SkImage::MakeTextureFromMipMap(GrContext* ctx, const SkImageInfo& info, 698 sk_sp<SkImage> SkImage::MakeTextureFromMipMap(GrContext* ctx, const SkImageInfo& info,
699 const GrMipLevel* texels, int mipL evelCount, 699 const GrMipLevel* texels, int mipL evelCount,
700 SkBudgeted budgeted, 700 SkBudgeted budgeted,
701 SkSourceGammaTreatment gammaTreatm ent) { 701 SkSourceGammaTreatment gammaTreatm ent) {
702 if (!ctx) { 702 if (!ctx) {
703 return nullptr; 703 return nullptr;
704 } 704 }
705 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m ipLevelCount)); 705 sk_sp<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, mipLevel Count));
706 if (!texture) { 706 if (!texture) {
707 return nullptr; 707 return nullptr;
708 } 708 }
709 texture->texturePriv().setGammaTreatment(gammaTreatment); 709 texture->texturePriv().setGammaTreatment(gammaTreatment);
710 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID, 710 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID,
711 info.alphaType(), texture, sk_ref_sp(info.col orSpace()), 711 info.alphaType(), std::move(texture),
712 budgeted); 712 sk_ref_sp(info.colorSpace()), budgeted);
713 } 713 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.h ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698