OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "SkGr.h" | 8 #include "SkGr.h" |
9 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
10 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 result = ctx->createTexture(params, desc, cacheID, pixels, rowBytes, &ke
y); | 152 result = ctx->createTexture(params, desc, cacheID, pixels, rowBytes, &ke
y); |
153 if (result) { | 153 if (result) { |
154 add_genID_listener(key, bm.pixelRef()); | 154 add_genID_listener(key, bm.pixelRef()); |
155 } | 155 } |
156 } else { | 156 } else { |
157 // This texture is unlikely to be used again (in its present form) so | 157 // This texture is unlikely to be used again (in its present form) so |
158 // just use a scratch texture. This will remove the texture from the | 158 // just use a scratch texture. This will remove the texture from the |
159 // cache so no one else can find it. Additionally, once unlocked, the | 159 // cache so no one else can find it. Additionally, once unlocked, the |
160 // scratch texture will go to the end of the list for purging so will | 160 // scratch texture will go to the end of the list for purging so will |
161 // likely be available for this volatile bitmap the next time around. | 161 // likely be available for this volatile bitmap the next time around. |
162 result = ctx->lockAndRefScratchTexture(desc, GrContext::kExact_ScratchTe
xMatch); | 162 result = ctx->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch)
; |
163 if (pixels) { | 163 if (pixels) { |
164 result->writePixels(0, 0, bm.width(), bm.height(), desc.fConfig, pix
els, rowBytes); | 164 result->writePixels(0, 0, bm.width(), bm.height(), desc.fConfig, pix
els, rowBytes); |
165 } | 165 } |
166 } | 166 } |
167 return result; | 167 return result; |
168 } | 168 } |
169 | 169 |
170 #ifndef SK_IGNORE_ETC1_SUPPORT | 170 #ifndef SK_IGNORE_ETC1_SUPPORT |
171 static GrTexture *load_etc1_texture(GrContext* ctx, bool cache, | 171 static GrTexture *load_etc1_texture(GrContext* ctx, bool cache, |
172 const GrTextureParams* params, | 172 const GrTextureParams* params, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 241 |
242 SkYUVColorSpace colorSpace; | 242 SkYUVColorSpace colorSpace; |
243 | 243 |
244 // Get the YUV planes | 244 // Get the YUV planes |
245 if (!pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes, &colorSpace)) { | 245 if (!pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes, &colorSpace)) { |
246 return NULL; | 246 return NULL; |
247 } | 247 } |
248 | 248 |
249 GrTextureDesc yuvDesc; | 249 GrTextureDesc yuvDesc; |
250 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; | 250 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; |
251 GrAutoScratchTexture yuvTextures[3]; | 251 SkAutoTUnref<GrTexture> yuvTextures[3]; |
252 for (int i = 0; i < 3; ++i) { | 252 for (int i = 0; i < 3; ++i) { |
253 yuvDesc.fWidth = yuvSizes[i].fWidth; | 253 yuvDesc.fWidth = yuvSizes[i].fWidth; |
254 yuvDesc.fHeight = yuvSizes[i].fHeight; | 254 yuvDesc.fHeight = yuvSizes[i].fHeight; |
255 yuvTextures[i].set(ctx, yuvDesc); | 255 yuvTextures[i].reset( |
256 if ((NULL == yuvTextures[i].texture()) || | 256 ctx->refScratchTexture(yuvDesc, GrContext::kApprox_ScratchTexMatch))
; |
257 !yuvTextures[i].texture()->writePixels(0, 0, yuvDesc.fWidth, yuvDesc
.fHeight, | 257 if (!yuvTextures[i] || |
258 yuvDesc.fConfig, planes[i], r
owBytes[i])) { | 258 !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, |
| 259 yuvDesc.fConfig, planes[i], rowBytes[i]
)) { |
259 return NULL; | 260 return NULL; |
260 } | 261 } |
261 } | 262 } |
262 | 263 |
263 GrTextureDesc rtDesc = desc; | 264 GrTextureDesc rtDesc = desc; |
264 rtDesc.fFlags = rtDesc.fFlags | | 265 rtDesc.fFlags = rtDesc.fFlags | |
265 kRenderTarget_GrTextureFlagBit | | 266 kRenderTarget_GrTextureFlagBit | |
266 kNoStencil_GrTextureFlagBit; | 267 kNoStencil_GrTextureFlagBit; |
267 | 268 |
268 GrTexture* result = sk_gr_allocate_texture(ctx, cache, params, bm, rtDesc, N
ULL, 0); | 269 GrTexture* result = sk_gr_allocate_texture(ctx, cache, params, bm, rtDesc, N
ULL, 0); |
269 | 270 |
270 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; | 271 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; |
271 if (renderTarget) { | 272 if (renderTarget) { |
272 SkAutoTUnref<GrFragmentProcessor> yuvToRgbProcessor(GrYUVtoRGBEffect::Cr
eate( | 273 SkAutoTUnref<GrFragmentProcessor> yuvToRgbProcessor( |
273 yuvTextures[0].texture(), yuvTextures[1].texture(), yuvTextures[2].t
exture(), | 274 GrYUVtoRGBEffect::Create(yuvTextures[0], yuvTextures[1], yuvTextures
[2], colorSpace)); |
274 colorSpace)); | |
275 GrPaint paint; | 275 GrPaint paint; |
276 paint.addColorProcessor(yuvToRgbProcessor); | 276 paint.addColorProcessor(yuvToRgbProcessor); |
277 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth), | 277 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth), |
278 SkIntToScalar(yuvSizes[0].fHeight)); | 278 SkIntToScalar(yuvSizes[0].fHeight)); |
279 GrContext::AutoRenderTarget autoRT(ctx, renderTarget); | 279 GrContext::AutoRenderTarget autoRT(ctx, renderTarget); |
280 GrContext::AutoMatrix am; | 280 GrContext::AutoMatrix am; |
281 am.setIdentity(ctx); | 281 am.setIdentity(ctx); |
282 GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip); | 282 GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip); |
283 ctx->drawRect(paint, r); | 283 ctx->drawRect(paint, r); |
284 } else { | 284 } else { |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { | 569 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { |
570 grPaint->addColorProcessor(fp)->unref(); | 570 grPaint->addColorProcessor(fp)->unref(); |
571 constantColor = false; | 571 constantColor = false; |
572 } | 572 } |
573 } | 573 } |
574 | 574 |
575 // The grcolor is automatically set when calling asFragmentProcessor. | 575 // The grcolor is automatically set when calling asFragmentProcessor. |
576 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 576 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
577 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 577 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
578 } | 578 } |
OLD | NEW |