GMs: change some GMs to use SkImage over SkBitmap
Also, add GetResourceAsImage() to Resources.h Motivation: test drawImage() as much as we test drawBitmap() Review URL: https://codereview.chromium.org/1306133003
This commit is contained in:
parent
b30e9d3960
commit
2f0a728e5a
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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()));
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user