OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 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" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 SkPackARGB32(0xFF, 0xD6, 0xD3, 0xD6), | 92 SkPackARGB32(0xFF, 0xD6, 0xD3, 0xD6), |
93 SkPackARGB32(0xFF, 0xD6, 0xD3, 0xD6), | 93 SkPackARGB32(0xFF, 0xD6, 0xD3, 0xD6), |
94 SkPackARGB32(0xFF, 0x42, 0x41, 0x42) | 94 SkPackARGB32(0xFF, 0x42, 0x41, 0x42) |
95 }; | 95 }; |
96 SkBitmap bg; | 96 SkBitmap bg; |
97 bg.allocN32Pixels(2, 2, true); | 97 bg.allocN32Pixels(2, 2, true); |
98 memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData)); | 98 memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData)); |
99 | 99 |
100 SkMatrix lm; | 100 SkMatrix lm; |
101 lm.setScale(SkIntToScalar(16), SkIntToScalar(16)); | 101 lm.setScale(SkIntToScalar(16), SkIntToScalar(16)); |
102 fBG.reset(SkShader::CreateBitmapShader(bg, | 102 fBG = SkShader::MakeBitmapShader(bg, SkShader::kRepeat_TileMode, SkShade
r::kRepeat_TileMode, |
103 SkShader::kRepeat_TileMode, | 103 &lm); |
104 SkShader::kRepeat_TileMode, | |
105 &lm)); | |
106 | 104 |
107 SkBitmap srcBmp; | 105 SkBitmap srcBmp; |
108 srcBmp.allocN32Pixels(kSize, kSize); | 106 srcBmp.allocN32Pixels(kSize, kSize); |
109 SkPMColor* pixels = reinterpret_cast<SkPMColor*>(srcBmp.getPixels()); | 107 SkPMColor* pixels = reinterpret_cast<SkPMColor*>(srcBmp.getPixels()); |
110 | 108 |
111 for (int y = 0; y < kSize; ++y) { | 109 for (int y = 0; y < kSize; ++y) { |
112 int c = y * (1 << kShift); | 110 int c = y * (1 << kShift); |
113 SkPMColor rowColor = SkPackARGB32(c, c, 0, c/2); | 111 SkPMColor rowColor = SkPackARGB32(c, c, 0, c/2); |
114 for (int x = 0; x < kSize; ++x) { | 112 for (int x = 0; x < kSize; ++x) { |
115 pixels[kSize * y + x] = rowColor; | 113 pixels[kSize * y + x] = rowColor; |
116 } | 114 } |
117 } | 115 } |
118 fSrc.reset(SkShader::CreateBitmapShader(srcBmp, | 116 fSrc = SkShader::MakeBitmapShader(srcBmp, SkShader::kClamp_TileMode, |
119 SkShader::kClamp_TileMode, | 117 SkShader::kClamp_TileMode); |
120 SkShader::kClamp_TileMode)); | |
121 SkBitmap dstBmp; | 118 SkBitmap dstBmp; |
122 dstBmp.allocN32Pixels(kSize, kSize); | 119 dstBmp.allocN32Pixels(kSize, kSize); |
123 pixels = reinterpret_cast<SkPMColor*>(dstBmp.getPixels()); | 120 pixels = reinterpret_cast<SkPMColor*>(dstBmp.getPixels()); |
124 | 121 |
125 for (int x = 0; x < kSize; ++x) { | 122 for (int x = 0; x < kSize; ++x) { |
126 int c = x * (1 << kShift); | 123 int c = x * (1 << kShift); |
127 SkPMColor colColor = SkPackARGB32(c, 0, c, c/2); | 124 SkPMColor colColor = SkPackARGB32(c, 0, c, c/2); |
128 for (int y = 0; y < kSize; ++y) { | 125 for (int y = 0; y < kSize; ++y) { |
129 pixels[kSize * y + x] = colColor; | 126 pixels[kSize * y + x] = colColor; |
130 } | 127 } |
131 } | 128 } |
132 fDst.reset(SkShader::CreateBitmapShader(dstBmp, | 129 fDst = SkShader::MakeBitmapShader(dstBmp, SkShader::kClamp_TileMode, |
133 SkShader::kClamp_TileMode, | 130 SkShader::kClamp_TileMode); |
134 SkShader::kClamp_TileMode)); | |
135 } | 131 } |
136 | 132 |
137 enum { | 133 enum { |
138 kShift = 2, | 134 kShift = 2, |
139 kSize = 256 >> kShift, | 135 kSize = 256 >> kShift, |
140 }; | 136 }; |
141 | 137 |
142 SkAutoTUnref<SkShader> fBG; | 138 sk_sp<SkShader> fBG; |
143 SkAutoTUnref<SkShader> fSrc; | 139 sk_sp<SkShader> fSrc; |
144 SkAutoTUnref<SkShader> fDst; | 140 sk_sp<SkShader> fDst; |
145 | 141 |
146 typedef GM INHERITED; | 142 typedef GM INHERITED; |
147 }; | 143 }; |
148 | 144 |
149 ////////////////////////////////////////////////////////////////////////////// | 145 ////////////////////////////////////////////////////////////////////////////// |
150 | 146 |
151 static GM* MyFactory(void*) { return new Xfermodes2GM; } | 147 static GM* MyFactory(void*) { return new Xfermodes2GM; } |
152 static GMRegistry reg(MyFactory); | 148 static GMRegistry reg(MyFactory); |
153 | 149 |
154 } | 150 } |
OLD | NEW |