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/gpu/SkGr.cpp

Issue 374743003: Skia side RGB to YUV gpu conversion (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixing Windows build Created 6 years, 5 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/core/SkPixelRef.cpp ('k') | src/lazy/SkDiscardablePixelRef.h » ('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 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"
11 #include "SkData.h" 11 #include "SkData.h"
12 #include "SkMessageBus.h" 12 #include "SkMessageBus.h"
13 #include "SkPixelRef.h" 13 #include "SkPixelRef.h"
14 #include "GrResourceCache.h" 14 #include "GrResourceCache.h"
15 #include "GrGpu.h" 15 #include "GrGpu.h"
16 #include "effects/GrDitherEffect.h" 16 #include "effects/GrDitherEffect.h"
17 #include "GrDrawTargetCaps.h" 17 #include "GrDrawTargetCaps.h"
18 #include "effects/GrYUVtoRGBEffect.h"
18 19
19 #ifndef SK_IGNORE_ETC1_SUPPORT 20 #ifndef SK_IGNORE_ETC1_SUPPORT
20 # include "ktx.h" 21 # include "ktx.h"
21 # include "etc1.h" 22 # include "etc1.h"
22 #endif 23 #endif
23 24
24 /* Fill out buffer with the compressed format Ganesh expects from a colortable 25 /* Fill out buffer with the compressed format Ganesh expects from a colortable
25 based bitmap. [palette (colortable) + indices]. 26 based bitmap. [palette (colortable) + indices].
26 27
27 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others 28 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 187
187 GrResourceKey key; 188 GrResourceKey key;
188 GrTexture* result = ctx->createTexture(params, desc, cacheID, bytes, 0, &key ); 189 GrTexture* result = ctx->createTexture(params, desc, cacheID, bytes, 0, &key );
189 if (NULL != result) { 190 if (NULL != result) {
190 add_genID_listener(key, bm.pixelRef()); 191 add_genID_listener(key, bm.pixelRef());
191 } 192 }
192 return result; 193 return result;
193 } 194 }
194 #endif // SK_IGNORE_ETC1_SUPPORT 195 #endif // SK_IGNORE_ETC1_SUPPORT
195 196
197 static GrTexture *load_yuv_texture(GrContext* ctx, const GrTextureParams* params ,
198 const SkBitmap& bm, const GrTextureDesc& desc ) {
199 GrTexture* result = NULL;
200
201 SkPixelRef* pixelRef = bm.pixelRef();
202 SkISize yuvSizes[3];
203 if ((NULL == pixelRef) || !pixelRef->getYUV8Planes(yuvSizes, NULL, NULL)) {
204 return NULL;
205 }
206
207 // Allocate the memory for YUV
208 size_t totalSize(0);
209 size_t sizes[3], rowBytes[3];
210 for (int i = 0; i < 3; ++i) {
211 rowBytes[i] = yuvSizes[i].fWidth;
212 totalSize += sizes[i] = rowBytes[i] * yuvSizes[i].fHeight;
213 }
214 SkAutoMalloc storage(totalSize);
215 void* planes[3];
216 planes[0] = storage.get();
217 planes[1] = (uint8_t*)planes[0] + sizes[0];
218 planes[2] = (uint8_t*)planes[1] + sizes[1];
219
220 // Get the YUV planes
221 if (!pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes)) {
222 return NULL;
223 }
224
225 GrTextureDesc yuvDesc;
226 yuvDesc.fConfig = kAlpha_8_GrPixelConfig;
227 GrAutoScratchTexture yuvTextures[3];
228 for (int i = 0; i < 3; ++i) {
229 yuvDesc.fWidth = yuvSizes[i].fWidth;
230 yuvDesc.fHeight = yuvSizes[i].fHeight;
231 yuvTextures[i].set(ctx, yuvDesc);
232 if ((NULL == yuvTextures[i].texture()) ||
233 !ctx->writeTexturePixels(yuvTextures[i].texture(),
234 0, 0, yuvDesc.fWidth, yuvDesc.fHeight,
235 yuvDesc.fConfig, planes[i], rowBytes[i])) {
236 return NULL;
237 }
238 }
239
240 GrTextureDesc rtDesc = desc;
241 rtDesc.fFlags = rtDesc.fFlags |
242 kRenderTarget_GrTextureFlagBit |
243 kNoStencil_GrTextureFlagBit;
244
245 // This texture is likely to be used again so leave it in the cache
246 GrCacheID cacheID;
247 generate_bitmap_cache_id(bm, &cacheID);
248
249 GrResourceKey key;
250 result = ctx->createTexture(params, rtDesc, cacheID, NULL, 0, &key);
251 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL;
252 if (NULL != renderTarget) {
253 add_genID_listener(key, bm.pixelRef());
254 SkAutoTUnref<GrEffect> yuvToRgbEffect(GrYUVtoRGBEffect::Create(
255 yuvTextures[0].texture(), yuvTextures[1].texture(), yuvTextures[2].t exture()));
256 GrPaint paint;
257 paint.addColorEffect(yuvToRgbEffect);
258 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth),
259 SkIntToScalar(yuvSizes[0].fHeight));
260 GrContext::AutoRenderTarget autoRT(ctx, renderTarget);
261 GrContext::AutoMatrix am;
262 am.setIdentity(ctx);
263 GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip);
264 ctx->drawRect(paint, r);
265 } else {
266 SkSafeSetNull(result);
267 }
268
269 return result;
270 }
271
196 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, 272 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx,
197 bool cache, 273 bool cache,
198 const GrTextureParams* params, 274 const GrTextureParams* params,
199 const SkBitmap& origBitmap) { 275 const SkBitmap& origBitmap) {
200 SkBitmap tmpBitmap; 276 SkBitmap tmpBitmap;
201 277
202 const SkBitmap* bitmap = &origBitmap; 278 const SkBitmap* bitmap = &origBitmap;
203 279
204 GrTextureDesc desc; 280 GrTextureDesc desc;
205 generate_bitmap_texture_desc(*bitmap, &desc); 281 generate_bitmap_texture_desc(*bitmap, &desc);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // the bitmap has available pixels, then they might not be what the deco mpressed 333 // the bitmap has available pixels, then they might not be what the deco mpressed
258 // data is. 334 // data is.
259 && !(bitmap->readyToDraw())) { 335 && !(bitmap->readyToDraw())) {
260 GrTexture *texture = load_etc1_texture(ctx, params, *bitmap, desc); 336 GrTexture *texture = load_etc1_texture(ctx, params, *bitmap, desc);
261 if (NULL != texture) { 337 if (NULL != texture) {
262 return texture; 338 return texture;
263 } 339 }
264 } 340 }
265 #endif // SK_IGNORE_ETC1_SUPPORT 341 #endif // SK_IGNORE_ETC1_SUPPORT
266 342
343 else {
344 GrTexture *texture = load_yuv_texture(ctx, params, *bitmap, desc);
345 if (NULL != texture) {
346 return texture;
347 }
348 }
267 SkAutoLockPixels alp(*bitmap); 349 SkAutoLockPixels alp(*bitmap);
268 if (!bitmap->readyToDraw()) { 350 if (!bitmap->readyToDraw()) {
269 return NULL; 351 return NULL;
270 } 352 }
271 if (cache) { 353 if (cache) {
272 // This texture is likely to be used again so leave it in the cache 354 // This texture is likely to be used again so leave it in the cache
273 GrCacheID cacheID; 355 GrCacheID cacheID;
274 generate_bitmap_cache_id(origBitmap, &cacheID); 356 generate_bitmap_cache_id(origBitmap, &cacheID);
275 357
276 GrResourceKey key; 358 GrResourceKey key;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 if (shader->asNewEffect(context, skPaint, NULL, &paintColor, &effect) && NULL != effect) { 616 if (shader->asNewEffect(context, skPaint, NULL, &paintColor, &effect) && NULL != effect) {
535 grPaint->addColorEffect(effect)->unref(); 617 grPaint->addColorEffect(effect)->unref();
536 constantColor = false; 618 constantColor = false;
537 } 619 }
538 } 620 }
539 621
540 // The grcolor is automatically set when calling asneweffect. 622 // The grcolor is automatically set when calling asneweffect.
541 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. 623 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint.
542 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); 624 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint );
543 } 625 }
OLDNEW
« no previous file with comments | « src/core/SkPixelRef.cpp ('k') | src/lazy/SkDiscardablePixelRef.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698