From: reed Date: Wed, 16 Sep 2015 17:09:24 +0000 (-0700) Subject: share code between SkGr and Cacherator X-Git-Tag: submit/tizen/20180928.044319~839 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3322a8137d12255258a937897389ea90ca1ee6fa;p=platform%2Fupstream%2FlibSkiaSharp.git share code between SkGr and Cacherator BUG=skia: Review URL: https://codereview.chromium.org/1351533004 --- diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h index 99a361bca1..2d1b95df85 100644 --- a/include/gpu/SkGr.h +++ b/include/gpu/SkGr.h @@ -78,6 +78,8 @@ static inline GrColor SkPMColorToGrColor(SkPMColor c) { SkGetPackedA32(c)); } +GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&); + //////////////////////////////////////////////////////////////////////////////// /** diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index dcc5c676f6..f5ec5e3477 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -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 data(this->refEncoded()); if (data) { diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index bba352569a..d897f3ce88 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -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; } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index ee06f3eef6..9ab2f6393a 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -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()) {