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

Side by Side Diff: gm/offsetimagefilter.cpp

Issue 186643003: Apply the CTM to the offset in the slow SkOffsetImageFilter path. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: SK_Scalar1 is my friend Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | src/effects/SkOffsetImageFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkOffsetImageFilter.h" 9 #include "SkOffsetImageFilter.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
11 11
12 #define WIDTH 400 12 #define WIDTH 600
13 #define HEIGHT 100 13 #define HEIGHT 100
14 #define MARGIN 12 14 #define MARGIN 12
15 15
16 namespace skiagm { 16 namespace skiagm {
17 17
18 class OffsetImageFilterGM : public GM { 18 class OffsetImageFilterGM : public GM {
19 public: 19 public:
20 OffsetImageFilterGM() : fInitialized(false) { 20 OffsetImageFilterGM() : fInitialized(false) {
21 this->setBGColor(0xFF000000); 21 this->setBGColor(0xFF000000);
22 } 22 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); 56 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
57 canvas.restore(); 57 canvas.restore();
58 } 58 }
59 } 59 }
60 } 60 }
61 61
62 virtual SkISize onISize() { 62 virtual SkISize onISize() {
63 return make_isize(WIDTH, HEIGHT); 63 return make_isize(WIDTH, HEIGHT);
64 } 64 }
65 65
66 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai nt& paint, 66 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai nt& paint, SkScalar scale, const SkIRect& cropRect) {
67 SkScalar x, SkScalar y) {
68 canvas->save(); 67 canvas->save();
69 canvas->translate(x, y); 68 SkRect clipRect = SkRect::MakeWH(
70 canvas->clipRect(SkRect::MakeXYWH(0, 0, 69 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()));
71 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); 70 canvas->clipRect(clipRect);
71 canvas->scale(scale, scale);
72 canvas->drawBitmap(bitmap, 0, 0, &paint); 72 canvas->drawBitmap(bitmap, 0, 0, &paint);
73 canvas->restore(); 73 canvas->restore();
74 SkPaint strokePaint;
75 strokePaint.setStyle(SkPaint::kStroke_Style);
76 strokePaint.setColor(SK_ColorRED);
77
78 // Draw a boundary rect around the intersection of the clip rect
79 // and crop rect.
80 SkMatrix scaleMatrix;
81 scaleMatrix.setScale(scale, scale);
82 SkRect cropRectFloat;
83 scaleMatrix.mapRect(&cropRectFloat, SkRect::Make(cropRect));
84 clipRect.intersect(cropRectFloat);
85 canvas->drawRect(clipRect, strokePaint);
74 } 86 }
75 87
76 virtual void onDraw(SkCanvas* canvas) { 88 virtual void onDraw(SkCanvas* canvas) {
77 if (!fInitialized) { 89 if (!fInitialized) {
78 make_bitmap(); 90 make_bitmap();
79 make_checkerboard(); 91 make_checkerboard();
80 fInitialized = true; 92 fInitialized = true;
81 } 93 }
82 canvas->clear(0x00000000); 94 canvas->clear(0x00000000);
83 SkPaint paint; 95 SkPaint paint;
84 96
85 int x = 0, y = 0;
86 for (int i = 0; i < 4; i++) { 97 for (int i = 0; i < 4; i++) {
87 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; 98 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
88 SkIRect cropRect = SkIRect::MakeXYWH(i * 12, 99 SkIRect cropRect = SkIRect::MakeXYWH(i * 12,
89 i * 8, 100 i * 8,
90 bitmap->width() - i * 8, 101 bitmap->width() - i * 8,
91 bitmap->height() - i * 12); 102 bitmap->height() - i * 12);
92 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); 103 SkImageFilter::CropRect rect(SkRect::Make(cropRect));
93 SkAutoTUnref<SkImageFilter> tileInput(SkNEW_ARGS(SkBitmapSource, (*b itmap))); 104 SkAutoTUnref<SkImageFilter> tileInput(SkNEW_ARGS(SkBitmapSource, (*b itmap)));
94 SkScalar dx = SkIntToScalar(i*5); 105 SkScalar dx = SkIntToScalar(i*5);
95 SkScalar dy = SkIntToScalar(i*10); 106 SkScalar dy = SkIntToScalar(i*10);
96 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( 107 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(
97 SkOffsetImageFilter, (dx, dy, tileInput, &rect))); 108 SkOffsetImageFilter, (dx, dy, tileInput, &rect)));
98 paint.setImageFilter(filter); 109 paint.setImageFilter(filter);
99 drawClippedBitmap(canvas, *bitmap, paint, SkIntToScalar(x), SkIntToS calar(y)); 110 drawClippedBitmap(canvas, *bitmap, paint, SK_Scalar1, cropRect);
100 x += bitmap->width() + MARGIN; 111 canvas->translate(SkIntToScalar(bitmap->width() + MARGIN), 0);
101 if (x + bitmap->width() > WIDTH) {
102 x = 0;
103 y += bitmap->height() + MARGIN;
104 }
105 } 112 }
113
114 SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100);
115 SkImageFilter::CropRect rect(SkRect::Make(cropRect));
116 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(
117 SkOffsetImageFilter, (SkIntToScalar(-5), SkIntToScalar(-10), NULL, & rect)));
118 paint.setImageFilter(filter);
119 drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(2), cropRect);
106 } 120 }
107 private: 121 private:
108 typedef GM INHERITED; 122 typedef GM INHERITED;
109 SkBitmap fBitmap, fCheckerboard; 123 SkBitmap fBitmap, fCheckerboard;
110 bool fInitialized; 124 bool fInitialized;
111 }; 125 };
112 126
113 ////////////////////////////////////////////////////////////////////////////// 127 //////////////////////////////////////////////////////////////////////////////
114 128
115 static GM* MyFactory(void*) { return new OffsetImageFilterGM; } 129 static GM* MyFactory(void*) { return new OffsetImageFilterGM; }
116 static GMRegistry reg(MyFactory); 130 static GMRegistry reg(MyFactory);
117 131
118 } 132 }
OLDNEW
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | src/effects/SkOffsetImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698