diff options
-rw-r--r-- | gm/colorwheel.cpp | 17 | ||||
-rw-r--r-- | gm/grayscalejpg.cpp | 8 | ||||
-rw-r--r-- | tools/Resources.cpp | 7 | ||||
-rw-r--r-- | tools/Resources.h | 2 |
4 files changed, 22 insertions, 12 deletions
diff --git a/gm/colorwheel.cpp b/gm/colorwheel.cpp index 9af52f2484..dfa81ead70 100644 --- a/gm/colorwheel.cpp +++ b/gm/colorwheel.cpp @@ -7,13 +7,14 @@ #include "Resources.h" #include "SkData.h" +#include "SkImage.h" #include "gm.h" #include "sk_tool_utils.h" -static void draw_bitmap(SkCanvas* canvas, const char* resource, int x, int y) { - SkBitmap bitmap; - if (GetResourceAsBitmap(resource, &bitmap)) { - canvas->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y)); +static void draw_image(SkCanvas* canvas, const char* resource, int x, int y) { + SkAutoTUnref<SkImage> image(GetResourceAsImage(resource)); + if (image) { + canvas->drawImage(image, SkIntToScalar(x), SkIntToScalar(y)); } else { SkDebugf("\nCould not decode file '%s'. Did you forget" " to set the resourcePath?\n", resource); @@ -31,10 +32,10 @@ static void draw_bitmap(SkCanvas* canvas, const char* resource, int x, int y) { */ DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) { sk_tool_utils::draw_checkerboard(canvas); - draw_bitmap(canvas, "color_wheel.png", 0, 0); // top left - draw_bitmap(canvas, "color_wheel.gif", 128, 0); // top right - draw_bitmap(canvas, "color_wheel.webp", 0, 128); // bottom left - draw_bitmap(canvas, "color_wheel.jpg", 128, 128); // bottom right + draw_image(canvas, "color_wheel.png", 0, 0); // top left + draw_image(canvas, "color_wheel.gif", 128, 0); // top right + draw_image(canvas, "color_wheel.webp", 0, 128); // bottom left + draw_image(canvas, "color_wheel.jpg", 128, 128); // bottom right } DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) { diff --git a/gm/grayscalejpg.cpp b/gm/grayscalejpg.cpp index 0c617bf2eb..70ea72e9bd 100644 --- a/gm/grayscalejpg.cpp +++ b/gm/grayscalejpg.cpp @@ -6,7 +6,7 @@ */ #include "Resources.h" -#include "SkCanvas.h" +#include "SkImage.h" #include "gm.h" /* @@ -15,9 +15,9 @@ */ DEF_SIMPLE_GM(grayscalejpg, canvas, 128, 128) { const char kResource[] = "grayscale.jpg"; - SkBitmap bitmap; - if (GetResourceAsBitmap(kResource, &bitmap)) { - canvas->drawBitmap(bitmap, 0.0f, 0.0f); + SkAutoTUnref<SkImage> image(GetResourceAsImage(kResource)); + if (image) { + canvas->drawImage(image, 0.0f, 0.0f); } else { SkDebugf("\nCould not decode file '%s'. Did you forget" " to set the resourcePath?\n", kResource); diff --git a/tools/Resources.cpp b/tools/Resources.cpp index 608b03cff6..75625b40a6 100644 --- a/tools/Resources.cpp +++ b/tools/Resources.cpp @@ -9,6 +9,7 @@ #include "SkBitmap.h" #include "SkCommandLineFlags.h" #include "SkData.h" +#include "SkImage.h" #include "SkImageGenerator.h" #include "SkOSFile.h" #include "SkStream.h" @@ -30,6 +31,12 @@ bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) { return resourceData && SkInstallDiscardablePixelRef(resourceData, dst); } +SkImage* GetResourceAsImage(const char* resource) { + SkString path = GetResourcePath(resource); + SkAutoTUnref<SkData> resourceData(SkData::NewFromFileName(path.c_str())); + return SkImage::NewFromEncoded(resourceData); +} + SkStreamAsset* GetResourceAsStream(const char* resource) { SkString resourcePath = GetResourcePath(resource); SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(resourcePath.c_str())); diff --git a/tools/Resources.h b/tools/Resources.h index c9785a574c..5e76eb3ae8 100644 --- a/tools/Resources.h +++ b/tools/Resources.h @@ -11,6 +11,7 @@ #include "SkString.h" class SkBitmap; +class SkImage; class SkStreamAsset; class SkTypeface; @@ -18,6 +19,7 @@ SkString GetResourcePath(const char* resource = ""); void SetResourcePath(const char* ); bool GetResourceAsBitmap(const char* resource, SkBitmap* dst); +SkImage* GetResourceAsImage(const char* resource); SkStreamAsset* GetResourceAsStream(const char* resource); SkTypeface* GetResourceAsTypeface(const char* resource); |