OLD | NEW |
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 #include "gm.h" | 7 #include "gm.h" |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
10 #include "SkBlurDrawLooper.h" | 10 #include "SkBlurDrawLooper.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 canvas->drawText(header.c_str(), header.size(), 0, height, paint); | 118 canvas->drawText(header.c_str(), header.size(), 0, height, paint); |
119 | 119 |
120 // Now draw the image itself. | 120 // Now draw the image itself. |
121 canvas->translate(height * 2, height * 2); | 121 canvas->translate(height * 2, height * 2); |
122 if (!fPremul) { | 122 if (!fPremul) { |
123 // A premultiplied bitmap cannot currently be drawn. | 123 // A premultiplied bitmap cannot currently be drawn. |
124 SkAutoLockPixels alp(fBitmap); | 124 SkAutoLockPixels alp(fBitmap); |
125 // Copy it to a bitmap which can be drawn, converting | 125 // Copy it to a bitmap which can be drawn, converting |
126 // to premultiplied: | 126 // to premultiplied: |
127 SkBitmap bm; | 127 SkBitmap bm; |
128 bm.setConfig(SkBitmap::kARGB_8888_Config, fBitmap.width(), | 128 if (!bm.allocN32Pixels(fBitmap.width(), fBitmap.height())) { |
129 fBitmap.height()); | |
130 SkASSERT(fBitmap.config() == SkBitmap::kARGB_8888_Config); | |
131 if (!bm.allocPixels()) { | |
132 SkString errMsg("allocPixels failed"); | 129 SkString errMsg("allocPixels failed"); |
133 canvas->drawText(errMsg.c_str(), errMsg.size(), 0, height, paint
); | 130 canvas->drawText(errMsg.c_str(), errMsg.size(), 0, height, paint
); |
134 return; | 131 return; |
135 } | 132 } |
136 for (int i = 0; i < fBitmap.width(); ++i) { | 133 for (int i = 0; i < fBitmap.width(); ++i) { |
137 for (int j = 0; j < fBitmap.height(); ++j) { | 134 for (int j = 0; j < fBitmap.height(); ++j) { |
138 *bm.getAddr32(i, j) = premultiply_unpmcolor(*fBitmap.getAddr
32(i, j)); | 135 *bm.getAddr32(i, j) = premultiply_unpmcolor(*fBitmap.getAddr
32(i, j)); |
139 } | 136 } |
140 } | 137 } |
141 canvas->drawBitmap(bm, 0, 0); | 138 canvas->drawBitmap(bm, 0, 0); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 195 |
199 typedef SampleView INHERITED; | 196 typedef SampleView INHERITED; |
200 }; | 197 }; |
201 | 198 |
202 ////////////////////////////////////////////////////////////////////////////// | 199 ////////////////////////////////////////////////////////////////////////////// |
203 | 200 |
204 static SkView* MyFactory() { | 201 static SkView* MyFactory() { |
205 return new UnpremulView(skiagm::GM::GetResourcePath()); | 202 return new UnpremulView(skiagm::GM::GetResourcePath()); |
206 } | 203 } |
207 static SkViewRegister reg(MyFactory); | 204 static SkViewRegister reg(MyFactory); |
OLD | NEW |