| Index: src/gpu/SkGr.cpp
|
| diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
|
| index 540edb6a38e728c6a5e1f018a2dc3840fda965a8..0cbf4a80acbd9b1c1069db1fd3d55013a7a0d2b7 100644
|
| --- a/src/gpu/SkGr.cpp
|
| +++ b/src/gpu/SkGr.cpp
|
| @@ -10,6 +10,7 @@
|
|
|
| #include "GrCaps.h"
|
| #include "GrContext.h"
|
| +#include "GrDrawContext.h"
|
| #include "GrTextureParamsAdjuster.h"
|
| #include "GrGpuResourcePriv.h"
|
| #include "GrImageIDTextureAdjuster.h"
|
| @@ -33,6 +34,7 @@
|
| #include "effects/GrPorterDuffXferProcessor.h"
|
| #include "effects/GrXfermodeFragmentProcessor.h"
|
| #include "effects/GrYUVtoRGBEffect.h"
|
| +#include "effects/GrIndex8toRGBEffect.h"
|
|
|
| #ifndef SK_IGNORE_ETC1_SUPPORT
|
| # include "ktx.h"
|
| @@ -215,6 +217,79 @@ static GrTexture* load_etc1_texture(GrContext* ctx, const SkBitmap &bm, GrSurfac
|
| return ctx->textureProvider()->createTexture(desc, true, startOfTexData, 0);
|
| }
|
|
|
| +static GrTexture* create_texture_from_index8(GrContext* ctx, const SkBitmap& bm,
|
| + const GrSurfaceDesc& desc) {
|
| + SkAutoLockPixels alp(bm);
|
| + if (!bm.readyToDraw()) {
|
| + return nullptr;
|
| + }
|
| +
|
| + GrSurfaceDesc indicesDesc = desc;
|
| + indicesDesc.fConfig = kAlpha_8_GrPixelConfig;
|
| + SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->
|
| + createTexture(indicesDesc, true, bm.getPixels(), bm.rowBytes()));
|
| +
|
| + SkAutoTUnref<GrTexture> colorTableTexture;
|
| + const SkImageInfo info = SkImageInfo::Make(256, 1, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
| + GrSurfaceDesc colorTableDesc = GrImageInfoToSurfaceDesc(info);
|
| + SkColorTable* ctable = bm.getColorTable();
|
| + const int count = ctable->count();
|
| + if (count != 256 || kN32_SkColorType != kRGBA_8888_SkColorType) {
|
| + // Allocate 256 color array for palette and fill it with converted N32->RGBA colors.
|
| + SkPMColor fullTable[256] = { 0 };
|
| + SkDstPixelInfo dstPI;
|
| + dstPI.fColorType = kRGBA_8888_SkColorType;
|
| + dstPI.fAlphaType = kPremul_SkAlphaType;
|
| + dstPI.fPixels = fullTable;
|
| + dstPI.fRowBytes = count * sizeof(SkPMColor);
|
| +
|
| + SkSrcPixelInfo srcPI;
|
| + srcPI.fColorType = kN32_SkColorType;
|
| + srcPI.fAlphaType = kPremul_SkAlphaType;
|
| + srcPI.fPixels = ctable->readColors();
|
| + srcPI.fRowBytes = count * sizeof(SkPMColor);
|
| +
|
| + srcPI.convertPixelsTo(&dstPI, count, 1);
|
| +
|
| + colorTableTexture.reset(ctx->textureProvider()->
|
| + createTexture(colorTableDesc, true, fullTable, sizeof(SkPMColor) * 256));
|
| + } else {
|
| + colorTableTexture.reset(ctx->textureProvider()->
|
| + createTexture(colorTableDesc, true, ctable->readColors(), sizeof(SkPMColor) * 256));
|
| + }
|
| +
|
| +
|
| + GrSurfaceDesc rDesc = desc;
|
| + rDesc.fFlags = rDesc.fFlags | kRenderTarget_GrSurfaceFlag;
|
| + rDesc.fConfig = kRGBA_8888_GrPixelConfig;
|
| +
|
| + SkAutoTUnref<GrTexture> result(ctx->textureProvider()->createTexture(rDesc, true, nullptr, 0));
|
| + if (!result) {
|
| + return nullptr;
|
| + }
|
| +
|
| + GrRenderTarget* renderTarget = result->asRenderTarget();
|
| + SkASSERT(renderTarget);
|
| +
|
| + GrPaint paint;
|
| + SkMatrix textureMatrix;
|
| + textureMatrix.setTranslate(0, 0);
|
| + textureMatrix.postIDiv(bm.width(), bm.height());
|
| + SkAutoTUnref<GrFragmentProcessor> index8ToRgbProcessor(
|
| + GrIndex8toRGBEffect::Create(tex, colorTableTexture, textureMatrix));
|
| + paint.addColorFragmentProcessor(index8ToRgbProcessor);
|
| + const SkRect r = SkRect::MakeIWH(desc.fWidth, desc.fHeight);
|
| +
|
| + SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget));
|
| + if (!drawContext) {
|
| + return nullptr;
|
| + }
|
| +
|
| + drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), r);
|
| +
|
| + return result.detach();
|
| +}
|
| +
|
| GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bmp) {
|
| SkASSERT(!bmp.getTexture());
|
|
|
| @@ -236,6 +311,8 @@ GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bmp) {
|
| return ctx->textureProvider()->createTexture(desc, true, storage.get(),
|
| bitmap->width());
|
| } else {
|
| + if (GrTexture* tex = create_texture_from_index8(ctx, bmp, desc))
|
| + return tex;
|
| bmp.copyTo(&tmpBitmap, kN32_SkColorType);
|
| // now bitmap points to our temp, which has been promoted to 32bits
|
| bitmap = &tmpBitmap;
|
|
|