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

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

Issue 1728093005: Move Budgeted enum out of SkSurface, use in GrTextureProvider (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add aliases for Chrome Created 4 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/SkImage_Gpu.h ('k') | src/image/SkSurface.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"
11 #include "GrImageIDTextureAdjuster.h" 11 #include "GrImageIDTextureAdjuster.h"
12 #include "effects/GrYUVEffect.h" 12 #include "effects/GrYUVEffect.h"
13 #include "SkCanvas.h" 13 #include "SkCanvas.h"
14 #include "SkBitmapCache.h" 14 #include "SkBitmapCache.h"
15 #include "SkGpuDevice.h" 15 #include "SkGpuDevice.h"
16 #include "SkGrPixelRef.h" 16 #include "SkGrPixelRef.h"
17 #include "SkGrPriv.h" 17 #include "SkGrPriv.h"
18 #include "SkImageFilter.h" 18 #include "SkImageFilter.h"
19 #include "SkImage_Gpu.h" 19 #include "SkImage_Gpu.h"
20 #include "SkPixelRef.h" 20 #include "SkPixelRef.h"
21 21
22 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText ure* tex, 22 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText ure* tex,
23 SkSurface::Budgeted budgeted) 23 SkBudgeted budgeted)
24 : INHERITED(w, h, uniqueID) 24 : INHERITED(w, h, uniqueID)
25 , fTexture(SkRef(tex)) 25 , fTexture(SkRef(tex))
26 , fAlphaType(at) 26 , fAlphaType(at)
27 , fBudgeted(budgeted) 27 , fBudgeted(budgeted)
28 , fAddedRasterVersionToCache(false) 28 , fAddedRasterVersionToCache(false)
29 { 29 {
30 SkASSERT(tex->width() == w); 30 SkASSERT(tex->width() == w);
31 SkASSERT(tex->height() == h); 31 SkASSERT(tex->height() == h);
32 } 32 }
33 33
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 133 }
134 return true; 134 return true;
135 } 135 }
136 136
137 SkImage* SkImage_Gpu::onNewSubset(const SkIRect& subset) const { 137 SkImage* SkImage_Gpu::onNewSubset(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, 143 GrTexture* subTx = ctx->textureProvider()->createTexture(desc, fBudgeted);
144 SkSurface::kYes_Bud geted == fBudgeted);
145 if (!subTx) { 144 if (!subTx) {
146 return nullptr; 145 return nullptr;
147 } 146 }
148 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); 147 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0));
149 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAl phaType, subTx, 148 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAl phaType, subTx,
150 fBudgeted); 149 fBudgeted);
151 } 150 }
152 151
153 //////////////////////////////////////////////////////////////////////////////// /////////////////// 152 //////////////////////////////////////////////////////////////////////////////// ///////////////////
154 153
155 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur eDesc& desc, 154 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur eDesc& desc,
156 SkAlphaType at, GrWrapOwnership owner ship, 155 SkAlphaType at, GrWrapOwnership owner ship,
157 SkImage::TextureReleaseProc releasePr oc, 156 SkImage::TextureReleaseProc releasePr oc,
158 SkImage::ReleaseContext releaseCtx) { 157 SkImage::ReleaseContext releaseCtx) {
159 if (desc.fWidth <= 0 || desc.fHeight <= 0) { 158 if (desc.fWidth <= 0 || desc.fHeight <= 0) {
160 return nullptr; 159 return nullptr;
161 } 160 }
162 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc, ownership)); 161 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc, ownership));
163 if (!tex) { 162 if (!tex) {
164 return nullptr; 163 return nullptr;
165 } 164 }
166 if (releaseProc) { 165 if (releaseProc) {
167 tex->setRelease(releaseProc, releaseCtx); 166 tex->setRelease(releaseProc, releaseCtx);
168 } 167 }
169 168
170 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; 169 const SkBudgeted budgeted = SkBudgeted::kNo;
171 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, tex, budgeted); 170 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, tex, budgeted);
172 } 171 }
173 172
174 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des c, SkAlphaType at, 173 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des c, SkAlphaType at,
175 TextureReleaseProc releaseP, ReleaseContext rel easeC) { 174 TextureReleaseProc releaseP, ReleaseContext rel easeC) {
176 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re leaseP, releaseC); 175 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re leaseP, releaseC);
177 } 176 }
178 177
179 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe sc& desc, 178 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe sc& desc,
180 SkAlphaType at) { 179 SkAlphaType at) {
181 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nul lptr, nullptr); 180 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nul lptr, nullptr);
182 } 181 }
183 182
184 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc, 183 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc,
185 SkAlphaType at) { 184 SkAlphaType at) {
186 if (desc.fWidth <= 0 || desc.fHeight <= 0) { 185 if (desc.fWidth <= 0 || desc.fHeight <= 0) {
187 return nullptr; 186 return nullptr;
188 } 187 }
189 188
190 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture( 189 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture(
191 desc, kBorrow_GrWrapOwnership)); 190 desc, kBorrow_GrWrapOwnership));
192 if (!src) { 191 if (!src) {
193 return nullptr; 192 return nullptr;
194 } 193 }
195 194
196 const bool isBudgeted = true; 195 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, SkBudgeted::kYes));
197 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, isBudgeted));
198 if (!dst) { 196 if (!dst) {
199 return nullptr; 197 return nullptr;
200 } 198 }
201 199
202 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted;
203 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst, 200 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst,
204 budgeted); 201 SkBudgeted::kYes);
205 } 202 }
206 203
207 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS pace, 204 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS pace,
208 const GrBackendObject yuvTextureHandles [3], 205 const GrBackendObject yuvTextureHandles [3],
209 const SkISize yuvSizes[3], 206 const SkISize yuvSizes[3],
210 GrSurfaceOrigin origin) { 207 GrSurfaceOrigin origin) {
211 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; 208 const SkBudgeted budgeted = SkBudgeted::kYes;
212 209
213 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || 210 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 ||
214 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 || 211 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 ||
215 yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0) { 212 yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0) {
216 return nullptr; 213 return nullptr;
217 } 214 }
218 static const GrPixelConfig kConfig = kAlpha_8_GrPixelConfig; 215 static const GrPixelConfig kConfig = kAlpha_8_GrPixelConfig;
219 GrBackendTextureDesc yDesc; 216 GrBackendTextureDesc yDesc;
220 yDesc.fConfig = kConfig; 217 yDesc.fConfig = kConfig;
221 yDesc.fOrigin = origin; 218 yDesc.fOrigin = origin;
(...skipping 30 matching lines...) Expand all
252 249
253 GrSurfaceDesc dstDesc; 250 GrSurfaceDesc dstDesc;
254 // Needs to be a render target in order to draw to it for the yuv->rgb conve rsion. 251 // Needs to be a render target in order to draw to it for the yuv->rgb conve rsion.
255 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; 252 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag;
256 dstDesc.fOrigin = origin; 253 dstDesc.fOrigin = origin;
257 dstDesc.fWidth = yuvSizes[0].fWidth; 254 dstDesc.fWidth = yuvSizes[0].fWidth;
258 dstDesc.fHeight = yuvSizes[0].fHeight; 255 dstDesc.fHeight = yuvSizes[0].fHeight;
259 dstDesc.fConfig = kRGBA_8888_GrPixelConfig; 256 dstDesc.fConfig = kRGBA_8888_GrPixelConfig;
260 dstDesc.fSampleCnt = 0; 257 dstDesc.fSampleCnt = 0;
261 258
262 SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, t rue)); 259 SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, S kBudgeted::kYes));
263 if (!dst) { 260 if (!dst) {
264 return nullptr; 261 return nullptr;
265 } 262 }
266 263
267 GrPaint paint; 264 GrPaint paint;
268 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 265 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
269 paint.addColorFragmentProcessor(GrYUVEffect::CreateYUVToRGB(yTex, uTex, vTex , yuvSizes, 266 paint.addColorFragmentProcessor(GrYUVEffect::CreateYUVToRGB(yTex, uTex, vTex , yuvSizes,
270 colorSpace))->un ref(); 267 colorSpace))->un ref();
271 268
272 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), 269 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth),
273 SkIntToScalar(dstDesc.fHeight)); 270 SkIntToScalar(dstDesc.fHeight));
274 SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(dst->asRenderTarget ())); 271 SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(dst->asRenderTarget ()));
275 if (!drawContext) { 272 if (!drawContext) {
276 return nullptr; 273 return nullptr;
277 } 274 }
278 275
279 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect); 276 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect);
280 ctx->flushSurfaceWrites(dst); 277 ctx->flushSurfaceWrites(dst);
281 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI D, 278 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI D,
282 kOpaque_SkAlphaType, dst, budgeted); 279 kOpaque_SkAlphaType, dst, budgeted);
283 } 280 }
284 281
285 static SkImage* create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, u int32_t id) { 282 static SkImage* create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, u int32_t id) {
286 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams:: ClampNoFilter())); 283 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams:: ClampNoFilter()));
287 if (!texture) { 284 if (!texture) {
288 return nullptr; 285 return nullptr;
289 } 286 }
290 return new SkImage_Gpu(texture->width(), texture->height(), id, at, texture, 287 return new SkImage_Gpu(texture->width(), texture->height(), id, at, texture,
291 SkSurface::kNo_Budgeted); 288 SkBudgeted::kNo);
292 } 289 }
293 290
294 SkImage* SkImage::newTextureImage(GrContext *context) const { 291 SkImage* SkImage::newTextureImage(GrContext *context) const {
295 if (!context) { 292 if (!context) {
296 return nullptr; 293 return nullptr;
297 } 294 }
298 if (GrTexture* peek = as_IB(this)->peekTexture()) { 295 if (GrTexture* peek = as_IB(this)->peekTexture()) {
299 return peek->getContext() == context ? SkRef(const_cast<SkImage*>(this)) : nullptr; 296 return peek->getContext() == context ? SkRef(const_cast<SkImage*>(this)) : nullptr;
300 } 297 }
301 // No way to check whether a image is premul or not? 298 // No way to check whether a image is premul or not?
302 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e; 299 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e;
303 300
304 if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) { 301 if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) {
305 GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint); 302 GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint);
306 return create_image_from_maker(&maker, at, this->uniqueID()); 303 return create_image_from_maker(&maker, at, this->uniqueID());
307 } 304 }
308 SkBitmap bmp; 305 SkBitmap bmp;
309 if (!this->asLegacyBitmap(&bmp, kRO_LegacyBitmapMode)) { 306 if (!this->asLegacyBitmap(&bmp, kRO_LegacyBitmapMode)) {
310 return nullptr; 307 return nullptr;
311 } 308 }
312 GrBitmapTextureMaker maker(context, bmp); 309 GrBitmapTextureMaker maker(context, bmp);
313 return create_image_from_maker(&maker, at, this->uniqueID()); 310 return create_image_from_maker(&maker, at, this->uniqueID());
314 } 311 }
315 312
316 //////////////////////////////////////////////////////////////////////////////// /////////////////// 313 //////////////////////////////////////////////////////////////////////////////// ///////////////////
317 314
318 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) { 315 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) {
319 GrContext* ctx = src->getContext(); 316 GrContext* ctx = src->getContext();
320 317
321 GrSurfaceDesc desc = src->desc(); 318 GrSurfaceDesc desc = src->desc();
322 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0); 319 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0);
323 if (!dst) { 320 if (!dst) {
324 return nullptr; 321 return nullptr;
325 } 322 }
326 323
327 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 324 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
328 const SkIPoint dstP = SkIPoint::Make(0, 0); 325 const SkIPoint dstP = SkIPoint::Make(0, 0);
329 ctx->copySurface(dst, src, srcR, dstP); 326 ctx->copySurface(dst, src, srcR, dstP);
330 ctx->flushSurfaceWrites(dst); 327 ctx->flushSurfaceWrites(dst);
331 return dst; 328 return dst;
332 } 329 }
333 330
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.h ('k') | src/image/SkSurface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698