| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 215 } |
| 216 | 216 |
| 217 return sk_gr_allocate_texture(ctx, cache, params, bm, desc, bytes, 0); | 217 return sk_gr_allocate_texture(ctx, cache, params, bm, desc, bytes, 0); |
| 218 } | 218 } |
| 219 #endif // SK_IGNORE_ETC1_SUPPORT | 219 #endif // SK_IGNORE_ETC1_SUPPORT |
| 220 | 220 |
| 221 static GrTexture *load_yuv_texture(GrContext* ctx, bool cache, const GrTexturePa
rams* params, | 221 static GrTexture *load_yuv_texture(GrContext* ctx, bool cache, const GrTexturePa
rams* params, |
| 222 const SkBitmap& bm, const GrTextureDesc& desc
) { | 222 const SkBitmap& bm, const GrTextureDesc& desc
) { |
| 223 SkPixelRef* pixelRef = bm.pixelRef(); | 223 SkPixelRef* pixelRef = bm.pixelRef(); |
| 224 SkISize yuvSizes[3]; | 224 SkISize yuvSizes[3]; |
| 225 if ((NULL == pixelRef) || !pixelRef->getYUV8Planes(yuvSizes, NULL, NULL)) { | 225 if ((NULL == pixelRef) || !pixelRef->getYUV8Planes(yuvSizes, NULL, NULL, NUL
L)) { |
| 226 return NULL; | 226 return NULL; |
| 227 } | 227 } |
| 228 | 228 |
| 229 // Allocate the memory for YUV | 229 // Allocate the memory for YUV |
| 230 size_t totalSize(0); | 230 size_t totalSize(0); |
| 231 size_t sizes[3], rowBytes[3]; | 231 size_t sizes[3], rowBytes[3]; |
| 232 for (int i = 0; i < 3; ++i) { | 232 for (int i = 0; i < 3; ++i) { |
| 233 rowBytes[i] = yuvSizes[i].fWidth; | 233 rowBytes[i] = yuvSizes[i].fWidth; |
| 234 totalSize += sizes[i] = rowBytes[i] * yuvSizes[i].fHeight; | 234 totalSize += sizes[i] = rowBytes[i] * yuvSizes[i].fHeight; |
| 235 } | 235 } |
| 236 SkAutoMalloc storage(totalSize); | 236 SkAutoMalloc storage(totalSize); |
| 237 void* planes[3]; | 237 void* planes[3]; |
| 238 planes[0] = storage.get(); | 238 planes[0] = storage.get(); |
| 239 planes[1] = (uint8_t*)planes[0] + sizes[0]; | 239 planes[1] = (uint8_t*)planes[0] + sizes[0]; |
| 240 planes[2] = (uint8_t*)planes[1] + sizes[1]; | 240 planes[2] = (uint8_t*)planes[1] + sizes[1]; |
| 241 | 241 |
| 242 SkYUVColorSpace colorSpace; |
| 243 |
| 242 // Get the YUV planes | 244 // Get the YUV planes |
| 243 if (!pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes)) { | 245 if (!pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes, &colorSpace)) { |
| 244 return NULL; | 246 return NULL; |
| 245 } | 247 } |
| 246 | 248 |
| 247 GrTextureDesc yuvDesc; | 249 GrTextureDesc yuvDesc; |
| 248 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; | 250 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 249 GrAutoScratchTexture yuvTextures[3]; | 251 GrAutoScratchTexture yuvTextures[3]; |
| 250 for (int i = 0; i < 3; ++i) { | 252 for (int i = 0; i < 3; ++i) { |
| 251 yuvDesc.fWidth = yuvSizes[i].fWidth; | 253 yuvDesc.fWidth = yuvSizes[i].fWidth; |
| 252 yuvDesc.fHeight = yuvSizes[i].fHeight; | 254 yuvDesc.fHeight = yuvSizes[i].fHeight; |
| 253 yuvTextures[i].set(ctx, yuvDesc); | 255 yuvTextures[i].set(ctx, yuvDesc); |
| 254 if ((NULL == yuvTextures[i].texture()) || | 256 if ((NULL == yuvTextures[i].texture()) || |
| 255 !ctx->writeTexturePixels(yuvTextures[i].texture(), | 257 !ctx->writeTexturePixels(yuvTextures[i].texture(), |
| 256 0, 0, yuvDesc.fWidth, yuvDesc.fHeight, | 258 0, 0, yuvDesc.fWidth, yuvDesc.fHeight, |
| 257 yuvDesc.fConfig, planes[i], rowBytes[i])) { | 259 yuvDesc.fConfig, planes[i], rowBytes[i])) { |
| 258 return NULL; | 260 return NULL; |
| 259 } | 261 } |
| 260 } | 262 } |
| 261 | 263 |
| 262 GrTextureDesc rtDesc = desc; | 264 GrTextureDesc rtDesc = desc; |
| 263 rtDesc.fFlags = rtDesc.fFlags | | 265 rtDesc.fFlags = rtDesc.fFlags | |
| 264 kRenderTarget_GrTextureFlagBit | | 266 kRenderTarget_GrTextureFlagBit | |
| 265 kNoStencil_GrTextureFlagBit; | 267 kNoStencil_GrTextureFlagBit; |
| 266 | 268 |
| 267 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); |
| 268 | 270 |
| 269 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; | 271 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; |
| 270 if (renderTarget) { | 272 if (renderTarget) { |
| 271 SkAutoTUnref<GrEffect> yuvToRgbEffect(GrYUVtoRGBEffect::Create( | 273 SkAutoTUnref<GrEffect> yuvToRgbEffect(GrYUVtoRGBEffect::Create( |
| 272 yuvTextures[0].texture(), yuvTextures[1].texture(), yuvTextures[2].t
exture())); | 274 yuvTextures[0].texture(), yuvTextures[1].texture(), yuvTextures[2].t
exture(), |
| 275 colorSpace)); |
| 273 GrPaint paint; | 276 GrPaint paint; |
| 274 paint.addColorEffect(yuvToRgbEffect); | 277 paint.addColorEffect(yuvToRgbEffect); |
| 275 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth), | 278 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth), |
| 276 SkIntToScalar(yuvSizes[0].fHeight)); | 279 SkIntToScalar(yuvSizes[0].fHeight)); |
| 277 GrContext::AutoRenderTarget autoRT(ctx, renderTarget); | 280 GrContext::AutoRenderTarget autoRT(ctx, renderTarget); |
| 278 GrContext::AutoMatrix am; | 281 GrContext::AutoMatrix am; |
| 279 am.setIdentity(ctx); | 282 am.setIdentity(ctx); |
| 280 GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip); | 283 GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip); |
| 281 ctx->drawRect(paint, r); | 284 ctx->drawRect(paint, r); |
| 282 } else { | 285 } else { |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 if (shader->asNewEffect(context, skPaint, NULL, &paintColor, &effect) &&
effect) { | 576 if (shader->asNewEffect(context, skPaint, NULL, &paintColor, &effect) &&
effect) { |
| 574 grPaint->addColorEffect(effect)->unref(); | 577 grPaint->addColorEffect(effect)->unref(); |
| 575 constantColor = false; | 578 constantColor = false; |
| 576 } | 579 } |
| 577 } | 580 } |
| 578 | 581 |
| 579 // The grcolor is automatically set when calling asneweffect. | 582 // The grcolor is automatically set when calling asneweffect. |
| 580 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 583 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
| 581 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 584 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
| 582 } | 585 } |
| OLD | NEW |