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

Unified Diff: gm/tiledscaledbitmap.cpp

Issue 675823002: Fix the way we patch up the matrix for scaled images that aren't (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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 | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/tiledscaledbitmap.cpp
diff --git a/gm/tiledscaledbitmap.cpp b/gm/tiledscaledbitmap.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..78f2d389d1054467e7fd68417aba965d1f2b2440
--- /dev/null
+++ b/gm/tiledscaledbitmap.cpp
@@ -0,0 +1,93 @@
+
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "gm.h"
+
+#include "Resources.h"
+#include "SkBitmap.h"
+#include "SkImageDecoder.h"
+#include "SkPaint.h"
+#include "SkShader.h"
+#include "SkStream.h"
+
+
+ /***
+ *
+ * This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly
+ * when fractional image scaling was ignored by the high quality bitmap scaler.
+ *
+ ***/
+
+namespace skiagm {
+
+class TiledScaledBitmapGM : public GM {
+public:
+
+ TiledScaledBitmapGM(const char filename[])
+ : fFilename(filename) {
+ }
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("tiledscaledbitmap");
+ }
+
+ virtual SkISize onISize() {
+ return SkISize::Make(1016, 616);
+ }
+
+ virtual void onOnceBeforeDraw() SK_OVERRIDE {
+ SkImageDecoder* codec = NULL;
+ SkString resourcePath = GetResourcePath(fFilename.c_str());
reed1 2014/10/24 14:27:38 I think it is just as easy (and slightly more port
+ SkFILEStream stream(resourcePath.c_str());
+ if (stream.isValid()) {
+ codec = SkImageDecoder::Factory(&stream);
+ }
+ if (codec) {
+ stream.rewind();
+ codec->decode(&stream, &fBitmap, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
+ SkDELETE(codec);
+ } else {
+ fBitmap.allocN32Pixels(360,288);
+ for (int row = 0 ; row < 288 ; row++) {
+ for (int col = 0 ; col < 360 ; col++ ) {
+ *(fBitmap.getAddr32(row,col)) = 0xFF0000FF; // red == bad
+ }
+ }
+ }
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ SkPaint paint;
+
+ paint.setAntiAlias(true);
+ paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
+
+ SkMatrix mat;
+ mat.setScale(121.f/360.f, 93.f/288.f);
+ mat.postTranslate(-72, -72);
+
+ SkShader *shader = SkShader::CreateBitmapShader(fBitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &mat);
+ paint.setShader(shader);
+
+ SkSafeUnref(shader);
+ canvas->drawRectCoords(8,8,1008, 608, paint);
+ }
+
+private:
+ SkBitmap fBitmap;
+ SkString fFilename;
+
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new TiledScaledBitmapGM("circle.png"); }
reed1 2014/10/24 14:27:38 nit: DEF_GM( return SkNEW_ARGS(TiledScaledBitmapGM
humper 2014/10/24 15:10:01 Done.
+static GMRegistry reg(MyFactory);
+
+}
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698