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

Side by Side Diff: src/gpu/SkGr.cpp

Issue 1495693003: Index8 GPU and CPU raster support. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years 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/SkImageGenerator.cpp ('k') | src/gpu/effects/GrIndex8toRGBEffect.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 8
9 #include "SkGr.h" 9 #include "SkGr.h"
10 10
11 #include "GrCaps.h" 11 #include "GrCaps.h"
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrDrawContext.h"
13 #include "GrTextureParamsAdjuster.h" 14 #include "GrTextureParamsAdjuster.h"
14 #include "GrGpuResourcePriv.h" 15 #include "GrGpuResourcePriv.h"
15 #include "GrImageIDTextureAdjuster.h" 16 #include "GrImageIDTextureAdjuster.h"
16 #include "GrXferProcessor.h" 17 #include "GrXferProcessor.h"
17 #include "GrYUVProvider.h" 18 #include "GrYUVProvider.h"
18 19
19 #include "SkColorFilter.h" 20 #include "SkColorFilter.h"
20 #include "SkConfig8888.h" 21 #include "SkConfig8888.h"
21 #include "SkCanvas.h" 22 #include "SkCanvas.h"
22 #include "SkData.h" 23 #include "SkData.h"
23 #include "SkErrorInternals.h" 24 #include "SkErrorInternals.h"
24 #include "SkGrPixelRef.h" 25 #include "SkGrPixelRef.h"
25 #include "SkMessageBus.h" 26 #include "SkMessageBus.h"
26 #include "SkPixelRef.h" 27 #include "SkPixelRef.h"
27 #include "SkResourceCache.h" 28 #include "SkResourceCache.h"
28 #include "SkTextureCompressor.h" 29 #include "SkTextureCompressor.h"
29 #include "SkYUVPlanesCache.h" 30 #include "SkYUVPlanesCache.h"
30 #include "effects/GrBicubicEffect.h" 31 #include "effects/GrBicubicEffect.h"
31 #include "effects/GrConstColorProcessor.h" 32 #include "effects/GrConstColorProcessor.h"
32 #include "effects/GrDitherEffect.h" 33 #include "effects/GrDitherEffect.h"
33 #include "effects/GrPorterDuffXferProcessor.h" 34 #include "effects/GrPorterDuffXferProcessor.h"
34 #include "effects/GrXfermodeFragmentProcessor.h" 35 #include "effects/GrXfermodeFragmentProcessor.h"
35 #include "effects/GrYUVtoRGBEffect.h" 36 #include "effects/GrYUVtoRGBEffect.h"
37 #include "effects/GrIndex8toRGBEffect.h"
36 38
37 #ifndef SK_IGNORE_ETC1_SUPPORT 39 #ifndef SK_IGNORE_ETC1_SUPPORT
38 # include "ktx.h" 40 # include "ktx.h"
39 # include "etc1.h" 41 # include "etc1.h"
40 #endif 42 #endif
41 43
42 GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo& info) { 44 GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo& info) {
43 GrSurfaceDesc desc; 45 GrSurfaceDesc desc;
44 desc.fFlags = kNone_GrSurfaceFlags; 46 desc.fFlags = kNone_GrSurfaceFlags;
45 desc.fWidth = info.width(); 47 desc.fWidth = info.width();
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 const void* startOfTexData; 210 const void* startOfTexData;
209 desc.fConfig = GrIsCompressedTextureDataSupported(ctx, data, bm.width(), bm. height(), 211 desc.fConfig = GrIsCompressedTextureDataSupported(ctx, data, bm.width(), bm. height(),
210 &startOfTexData); 212 &startOfTexData);
211 if (kUnknown_GrPixelConfig == desc.fConfig) { 213 if (kUnknown_GrPixelConfig == desc.fConfig) {
212 return nullptr; 214 return nullptr;
213 } 215 }
214 216
215 return ctx->textureProvider()->createTexture(desc, true, startOfTexData, 0); 217 return ctx->textureProvider()->createTexture(desc, true, startOfTexData, 0);
216 } 218 }
217 219
220 static GrTexture* create_texture_from_index8(GrContext* ctx, const SkBitmap& bm,
221 const GrSurfaceDesc& desc) {
222 SkAutoLockPixels alp(bm);
223 if (!bm.readyToDraw()) {
224 return nullptr;
225 }
226
227 GrSurfaceDesc indicesDesc = desc;
228 indicesDesc.fConfig = kAlpha_8_GrPixelConfig;
229 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->
230 createTexture(indicesDesc, true, bm.getPixels(), bm.rowBytes()));
231
232 SkAutoTUnref<GrTexture> colorTableTexture;
233 const SkImageInfo info = SkImageInfo::Make(256, 1, kRGBA_8888_SkColorType, k Premul_SkAlphaType);
234 GrSurfaceDesc colorTableDesc = GrImageInfoToSurfaceDesc(info);
235 SkColorTable* ctable = bm.getColorTable();
236 const int count = ctable->count();
237 if (count != 256 || kN32_SkColorType != kRGBA_8888_SkColorType) {
aleksandar.stojiljkovic 2015/12/03 13:30:49 Not happy with this one - might make sense to use
238 // Allocate 256 color array for palette and fill it with converted N32-> RGBA colors.
239 SkPMColor fullTable[256] = { 0 };
240 SkDstPixelInfo dstPI;
241 dstPI.fColorType = kRGBA_8888_SkColorType;
242 dstPI.fAlphaType = kPremul_SkAlphaType;
243 dstPI.fPixels = fullTable;
244 dstPI.fRowBytes = count * sizeof(SkPMColor);
245
246 SkSrcPixelInfo srcPI;
247 srcPI.fColorType = kN32_SkColorType;
248 srcPI.fAlphaType = kPremul_SkAlphaType;
249 srcPI.fPixels = ctable->readColors();
250 srcPI.fRowBytes = count * sizeof(SkPMColor);
251
252 srcPI.convertPixelsTo(&dstPI, count, 1);
253
254 colorTableTexture.reset(ctx->textureProvider()->
255 createTexture(colorTableDesc, true, fullTable, sizeof(SkPMColor) * 2 56));
256 } else {
257 colorTableTexture.reset(ctx->textureProvider()->
258 createTexture(colorTableDesc, true, ctable->readColors(), sizeof(SkP MColor) * 256));
259 }
260
261
262 GrSurfaceDesc rDesc = desc;
263 rDesc.fFlags = rDesc.fFlags | kRenderTarget_GrSurfaceFlag;
264 rDesc.fConfig = kRGBA_8888_GrPixelConfig;
265
266 SkAutoTUnref<GrTexture> result(ctx->textureProvider()->createTexture(rDesc, true, nullptr, 0));
267 if (!result) {
268 return nullptr;
269 }
270
271 GrRenderTarget* renderTarget = result->asRenderTarget();
272 SkASSERT(renderTarget);
273
274 GrPaint paint;
275 SkMatrix textureMatrix;
276 textureMatrix.setTranslate(0, 0);
277 textureMatrix.postIDiv(bm.width(), bm.height());
278 SkAutoTUnref<GrFragmentProcessor> index8ToRgbProcessor(
279 GrIndex8toRGBEffect::Create(tex, colorTableTexture, textureMatrix));
280 paint.addColorFragmentProcessor(index8ToRgbProcessor);
281 const SkRect r = SkRect::MakeIWH(desc.fWidth, desc.fHeight);
282
283 SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget));
284 if (!drawContext) {
285 return nullptr;
286 }
287
288 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), r);
289
290 return result.detach();
291 }
292
218 GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bmp) { 293 GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bmp) {
219 SkASSERT(!bmp.getTexture()); 294 SkASSERT(!bmp.getTexture());
220 295
221 SkBitmap tmpBitmap; 296 SkBitmap tmpBitmap;
222 const SkBitmap* bitmap = &bmp; 297 const SkBitmap* bitmap = &bmp;
223 298
224 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap->info()); 299 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap->info());
225 const GrCaps* caps = ctx->caps(); 300 const GrCaps* caps = ctx->caps();
226 301
227 if (kIndex_8_SkColorType == bitmap->colorType()) { 302 if (kIndex_8_SkColorType == bitmap->colorType()) {
228 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) { 303 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) {
aleksandar.stojiljkovic 2015/12/03 13:30:49 Based on my previous finding with Mali and Adrenos
229 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig , 304 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig ,
230 bitmap->width(), bitma p->height()); 305 bitmap->width(), bitma p->height());
231 SkAutoMalloc storage(imageSize); 306 SkAutoMalloc storage(imageSize);
232 build_index8_data(storage.get(), bmp); 307 build_index8_data(storage.get(), bmp);
233 308
234 // our compressed data will be trimmed, so pass width() for its 309 // our compressed data will be trimmed, so pass width() for its
235 // "rowBytes", since they are the same now. 310 // "rowBytes", since they are the same now.
236 return ctx->textureProvider()->createTexture(desc, true, storage.get (), 311 return ctx->textureProvider()->createTexture(desc, true, storage.get (),
237 bitmap->width()); 312 bitmap->width());
238 } else { 313 } else {
314 if (GrTexture* tex = create_texture_from_index8(ctx, bmp, desc))
315 return tex;
239 bmp.copyTo(&tmpBitmap, kN32_SkColorType); 316 bmp.copyTo(&tmpBitmap, kN32_SkColorType);
240 // now bitmap points to our temp, which has been promoted to 32bits 317 // now bitmap points to our temp, which has been promoted to 32bits
241 bitmap = &tmpBitmap; 318 bitmap = &tmpBitmap;
242 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); 319 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info());
243 } 320 }
244 } else if (!bitmap->readyToDraw()) { 321 } else if (!bitmap->readyToDraw()) {
245 // If the bitmap had compressed data and was then uncompressed, it'll st ill return 322 // If the bitmap had compressed data and was then uncompressed, it'll st ill return
246 // compressed data on 'refEncodedData' and upload it. Probably not good, since if 323 // compressed data on 'refEncodedData' and upload it. Probably not good, since if
247 // the bitmap has available pixels, then they might not be what the deco mpressed 324 // the bitmap has available pixels, then they might not be what the deco mpressed
248 // data is. 325 // data is.
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 SkErrorInternals::SetError( kInvalidPaint_SkError, 732 SkErrorInternals::SetError( kInvalidPaint_SkError,
656 "Sorry, I don't understand the filtering " 733 "Sorry, I don't understand the filtering "
657 "mode you asked for. Falling back to " 734 "mode you asked for. Falling back to "
658 "MIPMaps."); 735 "MIPMaps.");
659 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 736 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
660 break; 737 break;
661 738
662 } 739 }
663 return textureFilterMode; 740 return textureFilterMode;
664 } 741 }
OLDNEW
« no previous file with comments | « src/core/SkImageGenerator.cpp ('k') | src/gpu/effects/GrIndex8toRGBEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698