share code between SkGr and Cacherator

BUG=skia:

Review URL: https://codereview.chromium.org/1351533004
This commit is contained in:
reed 2015-09-16 10:09:24 -07:00 committed by Commit bot
parent 5d08d44c68
commit 3322a8137d
4 changed files with 22 additions and 23 deletions

View File

@ -78,6 +78,8 @@ static inline GrColor SkPMColorToGrColor(SkPMColor c) {
SkGetPackedA32(c));
}
GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&);
////////////////////////////////////////////////////////////////////////////////
/**

View File

@ -162,13 +162,6 @@ bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap) {
//////////////////////////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
static void make_texture_desc(const SkImageInfo& info, GrSurfaceDesc* desc) {
desc->fFlags = kNone_GrSurfaceFlags;
desc->fWidth = info.width();
desc->fHeight = info.height();
desc->fConfig = SkImageInfo2GrPixelConfig(info);
desc->fSampleCnt = 0;
}
static GrTexture* load_compressed_into_texture(GrContext* ctx, SkData* data, GrSurfaceDesc desc) {
const void* rawStart;
@ -229,9 +222,6 @@ GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa
GrMakeKeyFromImageID(&key, fUniqueID, SkIRect::MakeWH(fInfo.width(), fInfo.height()),
*ctx->caps(), usage);
GrSurfaceDesc desc;
make_texture_desc(fInfo, &desc);
// 1. Check the cache for a pre-existing one
if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) {
return tex;
@ -246,6 +236,8 @@ GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa
}
}
const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(fInfo);
// 3. Ask the generator to return a compressed form that the GPU might support
SkAutoTUnref<SkData> data(this->refEncoded());
if (data) {

View File

@ -1042,6 +1042,13 @@ static void draw_aa_bitmap(GrDrawContext* drawContext, GrContext* context,
drawContext->drawBatch(renderTarget, clip, grPaint, batch);
}
static bool can_ignore_strict_subset_constraint(const SkBitmap& bitmap, const SkRect& subset) {
GrTexture* tex = bitmap.getTexture();
int width = tex ? tex->width() : bitmap.width();
int height = tex ? tex->height() : bitmap.height();
return subset.contains(SkRect::MakeIWH(width, height));
}
void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
const SkBitmap& bitmap,
const SkRect* srcRectPtr,
@ -1065,11 +1072,8 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
srcRect = *srcRectPtr;
dstSize = *dstSizePtr;
}
GrTexture* tex = bitmap.getTexture();
int width = tex ? tex->width() : bitmap.width();
int height = tex ? tex->height() : bitmap.height();
if (srcRect.fLeft <= 0 && srcRect.fTop <= 0 &&
srcRect.fRight >= width && srcRect.fBottom >= height) {
if (can_ignore_strict_subset_constraint(bitmap, srcRect)) {
constraint = SkCanvas::kFast_SrcRectConstraint;
}

View File

@ -205,12 +205,14 @@ static void make_image_keys(uint32_t imageID, const SkIRect& subset, const Stret
}
}
static void generate_bitmap_texture_desc(const SkBitmap& bitmap, GrSurfaceDesc* desc) {
desc->fFlags = kNone_GrSurfaceFlags;
desc->fWidth = bitmap.width();
desc->fHeight = bitmap.height();
desc->fConfig = SkImageInfo2GrPixelConfig(bitmap.info());
desc->fSampleCnt = 0;
GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo& info) {
GrSurfaceDesc desc;
desc.fFlags = kNone_GrSurfaceFlags;
desc.fWidth = info.width();
desc.fHeight = info.height();
desc.fConfig = SkImageInfo2GrPixelConfig(info);
desc.fSampleCnt = 0;
return desc;
}
namespace {
@ -433,8 +435,7 @@ static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx,
const SkBitmap* bitmap = &origBitmap;
GrSurfaceDesc desc;
generate_bitmap_texture_desc(*bitmap, &desc);
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap->info());
const GrCaps* caps = ctx->caps();
if (kIndex_8_SkColorType == bitmap->colorType()) {