share code between SkGr and Cacherator
authorreed <reed@google.com>
Wed, 16 Sep 2015 17:09:24 +0000 (10:09 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 16 Sep 2015 17:09:24 +0000 (10:09 -0700)
BUG=skia:

Review URL: https://codereview.chromium.org/1351533004

include/gpu/SkGr.h
src/core/SkImageCacherator.cpp
src/gpu/SkGpuDevice.cpp
src/gpu/SkGr.cpp

index 99a361bca1facb87705f1133d56fd441687a097e..2d1b95df858384c5b9fc0be9764fb76f3d4b583b 100644 (file)
@@ -78,6 +78,8 @@ static inline GrColor SkPMColorToGrColor(SkPMColor c) {
                            SkGetPackedA32(c));
 }
 
+GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&);
+
 ////////////////////////////////////////////////////////////////////////////////
 
 /**
index dcc5c676f672e546be136263c50d14b9efdaadf3..f5ec5e34771e002b3463d499a379d7d62bbfad6b 100644 (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) {
index bba352569abe80026824e8c0d4435ba2b0c16e1b..d897f3ce88ff4686c97c65b4f4edbca175c3825e 100644 (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;
     }
 
index ee06f3eef6de89787bbb747d714304bd82c2a77e..9ab2f6393aff26fa40be7b427bb693565602ee76 100644 (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()) {