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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8 #include "gm.h"
9
10 #include "Resources.h"
11 #include "SkBitmap.h"
12 #include "SkImageDecoder.h"
13 #include "SkPaint.h"
14 #include "SkShader.h"
15 #include "SkStream.h"
16
17
18 /***
19 *
20 * This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly
21 * when fractional image scaling was ignored by the high quality bitmap scaler.
22 *
23 ***/
24
25 namespace skiagm {
26
27 class TiledScaledBitmapGM : public GM {
28 public:
29
30 TiledScaledBitmapGM(const char filename[])
31 : fFilename(filename) {
32 }
33
34 protected:
35 virtual SkString onShortName() {
36 return SkString("tiledscaledbitmap");
37 }
38
39 virtual SkISize onISize() {
40 return SkISize::Make(1016, 616);
41 }
42
43 virtual void onOnceBeforeDraw() SK_OVERRIDE {
44 SkImageDecoder* codec = NULL;
45 SkString resourcePath = GetResourcePath(fFilename.c_str());
reed1 2014/10/24 14:27:38 I think it is just as easy (and slightly more port
46 SkFILEStream stream(resourcePath.c_str());
47 if (stream.isValid()) {
48 codec = SkImageDecoder::Factory(&stream);
49 }
50 if (codec) {
51 stream.rewind();
52 codec->decode(&stream, &fBitmap, kN32_SkColorType, SkImageDecoder::k DecodePixels_Mode);
53 SkDELETE(codec);
54 } else {
55 fBitmap.allocN32Pixels(360,288);
56 for (int row = 0 ; row < 288 ; row++) {
57 for (int col = 0 ; col < 360 ; col++ ) {
58 *(fBitmap.getAddr32(row,col)) = 0xFF0000FF; // red == bad
59 }
60 }
61 }
62 }
63
64 virtual void onDraw(SkCanvas* canvas) {
65 SkPaint paint;
66
67 paint.setAntiAlias(true);
68 paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
69
70 SkMatrix mat;
71 mat.setScale(121.f/360.f, 93.f/288.f);
72 mat.postTranslate(-72, -72);
73
74 SkShader *shader = SkShader::CreateBitmapShader(fBitmap, SkShader::kRepe at_TileMode, SkShader::kRepeat_TileMode, &mat);
75 paint.setShader(shader);
76
77 SkSafeUnref(shader);
78 canvas->drawRectCoords(8,8,1008, 608, paint);
79 }
80
81 private:
82 SkBitmap fBitmap;
83 SkString fFilename;
84
85 typedef GM INHERITED;
86 };
87
88 //////////////////////////////////////////////////////////////////////////////
89
90 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.
91 static GMRegistry reg(MyFactory);
92
93 }
OLDNEW
« 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