Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: gm/repeated_bitmap.cpp

Issue 1372783003: SkPDF: Implement drawImage*() properly (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-09-30 (Wednesday) 21:22:24 EDT Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dm/DM.cpp ('k') | gyp/pdf.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/repeated_bitmap.cpp
diff --git a/gm/repeated_bitmap.cpp b/gm/repeated_bitmap.cpp
index dc2a2aab0752b5b667d2050bde2b298bb71fa724..39eeb4e6e962055f22ca9f73c2256da5aab72507 100644
--- a/gm/repeated_bitmap.cpp
+++ b/gm/repeated_bitmap.cpp
@@ -5,49 +5,41 @@
* found in the LICENSE file.
*/
+#include "Resources.h"
+#include "SkImage.h"
#include "gm.h"
#include "sk_tool_utils.h"
-#include "Resources.h"
-DEF_SIMPLE_GM(repeated_bitmap, canvas, 576, 576) {
- sk_tool_utils::draw_checkerboard(canvas, sk_tool_utils::color_to_565(0xFF999999),
+static void draw_rotated_image(SkCanvas* canvas, const SkImage* image) {
+ sk_tool_utils::draw_checkerboard(canvas, SkColorSetRGB(156, 154, 156),
SK_ColorWHITE, 12);
- SkRect rect = SkRect::MakeLTRB(-4.25f, -4.25f, 4.25f, 4.25f);
+ if (!image) {
+ return;
+ }
+ SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f);
SkPaint paint;
- paint.setColor(0xFF333333);
- SkBitmap bm;
- if (GetResourceAsBitmap("randPixels.png", &bm)) {
- for (int j = 0; j < 4; ++j) {
- for (int i = 0; i < 4; ++i) {
- SkAutoCanvasRestore autoCanvasRestore(canvas, true);
- canvas->scale(12.0f, 12.0f);
- canvas->translate(6.0f + 12.0f * SkIntToScalar(i),
- 6.0f + 12.0f * SkIntToScalar(j));
- canvas->rotate(18.0f * (i + 4 * j));
- canvas->drawRect(rect, paint);
- canvas->drawBitmap(bm, -4.0f, -4.0f);
- }
+ paint.setColor(SkColorSetRGB(49, 48, 49));
+ SkScalar scale = SkTMin(128.0f / image->width(),
+ 128.0f / image->height());
+ SkScalar point[2] = {-0.5f * image->width(), -0.5f * image->height()};
+ for (int j = 0; j < 4; ++j) {
+ for (int i = 0; i < 4; ++i) {
+ SkAutoCanvasRestore autoCanvasRestore(canvas, true);
+ canvas->translate(96.0f + 192.0f * i, 96.0f + 192.0f * j);
+ canvas->rotate(18.0f * (i + 4 * j));
+ canvas->drawRect(rect, paint);
+ canvas->scale(scale, scale);
+ canvas->drawImage(image, point[0], point[1]);
}
}
}
+DEF_SIMPLE_GM(repeated_bitmap, canvas, 576, 576) {
+ SkAutoTUnref<SkImage> image(GetResourceAsImage("randPixels.png"));
+ draw_rotated_image(canvas, image);
+}
+
DEF_SIMPLE_GM(repeated_bitmap_jpg, canvas, 576, 576) {
- sk_tool_utils::draw_checkerboard(canvas, sk_tool_utils::color_to_565(0xFF999999),
- SK_ColorWHITE, 12);
- SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f);
- SkPaint paint;
- paint.setColor(0xFF333333);
- SkBitmap bm;
- if (GetResourceAsBitmap("color_wheel.jpg", &bm)) {
- for (int j = 0; j < 4; ++j) {
- for (int i = 0; i < 4; ++i) {
- SkAutoCanvasRestore autoCanvasRestore(canvas, true);
- canvas->translate(96.0f + 192.0f * SkIntToScalar(i),
- 96.0f + 192.0f * SkIntToScalar(j));
- canvas->rotate(18.0f * (i + 4 * j));
- canvas->drawRect(rect, paint);
- canvas->drawBitmap(bm, -64.0f, -64.0f);
- }
- }
- }
+ SkAutoTUnref<SkImage> image(GetResourceAsImage("color_wheel.jpg"));
+ draw_rotated_image(canvas, image);
}
« no previous file with comments | « dm/DM.cpp ('k') | gyp/pdf.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698