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

Side by Side Diff: gm/xfermodes.cpp

Issue 92453002: [PDF] Fixes the cases where SkPDFDevice::finishContentEntry is called with empty content. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Rebase Created 7 years 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/pdf/SkPDFDevice.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkShader.h" 10 #include "SkShader.h"
11 #include "SkXfermode.h" 11 #include "SkXfermode.h"
12 12
13 namespace skiagm { 13 namespace skiagm {
14 14
15 static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst) { 15 static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst,
16 SkBitmap* transparent) {
16 src->setConfig(SkBitmap::kARGB_8888_Config, w, h); 17 src->setConfig(SkBitmap::kARGB_8888_Config, w, h);
17 src->allocPixels(); 18 src->allocPixels();
18 src->eraseColor(SK_ColorTRANSPARENT); 19 src->eraseColor(SK_ColorTRANSPARENT);
19 20
20 SkPaint p; 21 SkPaint p;
21 p.setAntiAlias(true); 22 p.setAntiAlias(true);
22 23
23 SkRect r; 24 SkRect r;
24 SkScalar ww = SkIntToScalar(w); 25 SkScalar ww = SkIntToScalar(w);
25 SkScalar hh = SkIntToScalar(h); 26 SkScalar hh = SkIntToScalar(h);
26 27
27 { 28 {
28 SkCanvas c(*src); 29 SkCanvas c(*src);
29 p.setColor(0xFFFFCC44); 30 p.setColor(0xFFFFCC44);
30 r.set(0, 0, ww*3/4, hh*3/4); 31 r.set(0, 0, ww*3/4, hh*3/4);
31 c.drawOval(r, p); 32 c.drawOval(r, p);
32 } 33 }
33 34
34 dst->setConfig(SkBitmap::kARGB_8888_Config, w, h); 35 dst->setConfig(SkBitmap::kARGB_8888_Config, w, h);
35 dst->allocPixels(); 36 dst->allocPixels();
36 dst->eraseColor(SK_ColorTRANSPARENT); 37 dst->eraseColor(SK_ColorTRANSPARENT);
37 38
38 { 39 {
39 SkCanvas c(*dst); 40 SkCanvas c(*dst);
40 p.setColor(0xFF66AAFF); 41 p.setColor(0xFF66AAFF);
41 r.set(ww/3, hh/3, ww*19/20, hh*19/20); 42 r.set(ww/3, hh/3, ww*19/20, hh*19/20);
42 c.drawRect(r, p); 43 c.drawRect(r, p);
43 } 44 }
45
46 transparent->setConfig(SkBitmap::kARGB_8888_Config, w, h);
47 transparent->allocPixels();
48 transparent->eraseColor(SK_ColorTRANSPARENT);
44 } 49 }
45 50
46 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; 51 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
47 52
48 class XfermodesGM : public GM { 53 class XfermodesGM : public GM {
49 enum SrcType { 54 enum SrcType {
50 //! A WxH image with a rectangle in the lower right. 55 //! A WxH image with a rectangle in the lower right.
51 kRectangleImage_SrcType = 0x01, 56 kRectangleImage_SrcType = 0x01,
52 //! kRectangleImage_SrcType with an alpha of 34.5%. 57 //! kRectangleImage_SrcType with an alpha of 34.5%.
53 kRectangleImageWithAlpha_SrcType = 0x02, 58 kRectangleImageWithAlpha_SrcType = 0x02,
54 //! kRectnagleImageWithAlpha_SrcType scaled down by half. 59 //! kRectnagleImageWithAlpha_SrcType scaled down by half.
55 kSmallRectangleImageWithAlpha_SrcType = 0x04, 60 kSmallRectangleImageWithAlpha_SrcType = 0x04,
56 //! kRectangleImage_SrcType drawn directly instead in an image. 61 //! kRectangleImage_SrcType drawn directly instead in an image.
57 kRectangle_SrcType = 0x08, 62 kRectangle_SrcType = 0x08,
58 //! Two rectangles, first on the right half, second on the bottom half. 63 //! Two rectangles, first on the right half, second on the bottom half.
59 kQuarterClear_SrcType = 0x10, 64 kQuarterClear_SrcType = 0x10,
60 //! kQuarterClear_SrcType in a layer. 65 //! kQuarterClear_SrcType in a layer.
61 kQuarterClearInLayer_SrcType = 0x20, 66 kQuarterClearInLayer_SrcType = 0x20,
67 //! A W/2xH/2 transparent image.
68 kSmallTransparentImage_SrcType = 0x40,
62 69
63 kAll_SrcType = 0x3F, //!< All the source types. 70 kAll_SrcType = 0x7F, //!< All the source types.
64 kBasic_SrcType = 0x03, //!< Just basic source types. 71 kBasic_SrcType = 0x03, //!< Just basic source types.
65 }; 72 };
66 73
67 SkBitmap fBG; 74 SkBitmap fBG;
68 SkBitmap fSrcB, fDstB; 75 SkBitmap fSrcB, fDstB, fTransparent;
69 76
70 /* The srcType argument indicates what to draw for the source part. Skia 77 /* The srcType argument indicates what to draw for the source part. Skia
71 * uses the implied shape of the drawing command and these modes 78 * uses the implied shape of the drawing command and these modes
72 * demonstrate that. 79 * demonstrate that.
73 */ 80 */
74 void draw_mode(SkCanvas* canvas, SkXfermode* mode, SrcType srcType, 81 void draw_mode(SkCanvas* canvas, SkXfermode* mode, SrcType srcType,
75 SkScalar x, SkScalar y) { 82 SkScalar x, SkScalar y) {
76 SkPaint p; 83 SkPaint p;
77 SkMatrix m; 84 SkMatrix m;
78 bool restoreNeeded = false; 85 bool restoreNeeded = false;
79 m.setTranslate(x, y); 86 m.setTranslate(x, y);
80 87
81 canvas->drawBitmapMatrix(fSrcB, m, &p); 88 canvas->drawBitmapMatrix(fSrcB, m, &p);
82 p.setXfermode(mode); 89 p.setXfermode(mode);
83 switch (srcType) { 90 switch (srcType) {
91 case kSmallTransparentImage_SrcType:
92 m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y);
93 canvas->drawBitmapMatrix(fTransparent, m, &p);
94 break;
84 case kQuarterClearInLayer_SrcType: { 95 case kQuarterClearInLayer_SrcType: {
85 SkRect bounds = SkRect::MakeXYWH(x, y, SkIntToScalar(W), 96 SkRect bounds = SkRect::MakeXYWH(x, y, SkIntToScalar(W),
86 SkIntToScalar(H)); 97 SkIntToScalar(H));
87 canvas->saveLayer(&bounds, &p); 98 canvas->saveLayer(&bounds, &p);
88 restoreNeeded = true; 99 restoreNeeded = true;
89 p.setXfermodeMode(SkXfermode::kSrcOver_Mode); 100 p.setXfermodeMode(SkXfermode::kSrcOver_Mode);
90 // Fall through. 101 // Fall through.
91 } 102 }
92 case kQuarterClear_SrcType: { 103 case kQuarterClear_SrcType: {
93 SkScalar halfW = SkIntToScalar(W) / 2; 104 SkScalar halfW = SkIntToScalar(W) / 2;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 136
126 if (restoreNeeded) { 137 if (restoreNeeded) {
127 canvas->restore(); 138 canvas->restore();
128 } 139 }
129 } 140 }
130 141
131 virtual void onOnceBeforeDraw() SK_OVERRIDE { 142 virtual void onOnceBeforeDraw() SK_OVERRIDE {
132 fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4, kOpaque_SkAlphaType) ; 143 fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4, kOpaque_SkAlphaType) ;
133 fBG.setPixels(gData); 144 fBG.setPixels(gData);
134 145
135 make_bitmaps(W, H, &fSrcB, &fDstB); 146 make_bitmaps(W, H, &fSrcB, &fDstB, &fTransparent);
136 } 147 }
137 148
138 public: 149 public:
139 const static int W = 64; 150 const static int W = 64;
140 const static int H = 64; 151 const static int H = 64;
141 XfermodesGM() {} 152 XfermodesGM() {}
142 153
143 protected: 154 protected:
144 virtual SkString onShortName() { 155 virtual SkString onShortName() {
145 return SkString("xfermodes"); 156 return SkString("xfermodes");
146 } 157 }
147 158
148 virtual SkISize onISize() { 159 virtual SkISize onISize() {
149 return make_isize(1590, 640); 160 return make_isize(1990, 640);
150 } 161 }
151 162
152 virtual void onDraw(SkCanvas* canvas) { 163 virtual void onDraw(SkCanvas* canvas) {
153 canvas->translate(SkIntToScalar(10), SkIntToScalar(20)); 164 canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
154 165
155 const struct { 166 const struct {
156 SkXfermode::Mode fMode; 167 SkXfermode::Mode fMode;
157 const char* fLabel; 168 const char* fLabel;
158 int fSourceTypeMask; // The source types to use this 169 int fSourceTypeMask; // The source types to use this
159 // mode with. See draw_mode for 170 // mode with. See draw_mode for
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 private: 274 private:
264 typedef GM INHERITED; 275 typedef GM INHERITED;
265 }; 276 };
266 277
267 ////////////////////////////////////////////////////////////////////////////// 278 //////////////////////////////////////////////////////////////////////////////
268 279
269 static GM* MyFactory(void*) { return new XfermodesGM; } 280 static GM* MyFactory(void*) { return new XfermodesGM; }
270 static GMRegistry reg(MyFactory); 281 static GMRegistry reg(MyFactory);
271 282
272 } 283 }
OLDNEW
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | src/pdf/SkPDFDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698