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

Side by Side Diff: gm/showmiplevels.cpp

Issue 1598803002: use pixmaps in mipmap api (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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 | src/core/SkBitmapController.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 2016 Google Inc. 2 * Copyright 2016 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 9
10 #include "Resources.h" 10 #include "Resources.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 SkPixmap prevPM; 144 SkPixmap prevPM;
145 baseBM.lockPixels(); 145 baseBM.lockPixels();
146 baseBM.peekPixels(&prevPM); 146 baseBM.peekPixels(&prevPM);
147 147
148 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(baseBM, nullptr)); 148 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(baseBM, nullptr));
149 149
150 int index = 0; 150 int index = 0;
151 SkMipMap::Level level; 151 SkMipMap::Level level;
152 SkScalar scale = 0.5f; 152 SkScalar scale = 0.5f;
153 while (mm->extractLevel(scale, &level)) { 153 while (mm->extractLevel(scale, &level)) {
154 SkImageInfo info = SkImageInfo::Make(level.fWidth, level.fHeight, 154 SkBitmap bm = func(prevPM, level.fPixmap);
155 baseBM.colorType(), baseBM.alph aType());
156 SkPixmap levelPM{ info, level.fPixels, level.fRowBytes };
157
158 SkBitmap bm = func(prevPM, levelPM);
159 DrawAndFrame(canvas, bm, x, y); 155 DrawAndFrame(canvas, bm, x, y);
160 156
161 if (info.width() <= 2 || info.height() <= 2) { 157 if (level.fPixmap.width() <= 2 || level.fPixmap.height() <= 2) {
162 break; 158 break;
163 } 159 }
164 if (index & 1) { 160 if (index & 1) {
165 x += info.width() + 4; 161 x += level.fPixmap.width() + 4;
166 } else { 162 } else {
167 y += info.height() + 4; 163 y += level.fPixmap.height() + 4;
168 } 164 }
169 scale /= 2; 165 scale /= 2;
170 prevPM = levelPM; 166 prevPM = level.fPixmap;
171 index += 1; 167 index += 1;
172 } 168 }
173 } 169 }
174 170
175 void drawSet(SkCanvas* canvas, const SkBitmap& orig) { 171 void drawSet(SkCanvas* canvas, const SkBitmap& orig) {
176 SkAutoCanvasRestore acr(canvas, true); 172 SkAutoCanvasRestore acr(canvas, true);
177 173
178 drawLevels(canvas, orig, [](const SkPixmap& prev, const SkPixmap& curr) { 174 drawLevels(canvas, orig, [](const SkPixmap& prev, const SkPixmap& curr) {
179 SkBitmap bm; 175 SkBitmap bm;
180 bm.installPixels(curr); 176 bm.installPixels(curr);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 void drawLevels(SkCanvas* canvas, const SkBitmap& baseBM) { 252 void drawLevels(SkCanvas* canvas, const SkBitmap& baseBM) {
257 SkScalar x = 4; 253 SkScalar x = 4;
258 SkScalar y = 4; 254 SkScalar y = 4;
259 255
260 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(baseBM, nullptr)); 256 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(baseBM, nullptr));
261 257
262 int index = 0; 258 int index = 0;
263 SkMipMap::Level level; 259 SkMipMap::Level level;
264 SkScalar scale = 0.5f; 260 SkScalar scale = 0.5f;
265 while (mm->extractLevel(scale, &level)) { 261 while (mm->extractLevel(scale, &level)) {
266 SkImageInfo info = SkImageInfo::Make(level.fWidth, level.fHeight,
267 baseBM.colorType(), baseBM.alph aType());
268
269 SkBitmap bm; 262 SkBitmap bm;
270 bm.installPixels(info, level.fPixels, level.fRowBytes); 263 bm.installPixels(level.fPixmap);
271 DrawAndFrame(canvas, bm, x, y); 264 DrawAndFrame(canvas, bm, x, y);
272 265
273 if (info.width() <= 2 || info.height() <= 2) { 266 if (level.fPixmap.width() <= 2 || level.fPixmap.height() <= 2) {
274 break; 267 break;
275 } 268 }
276 if (index & 1) { 269 if (index & 1) {
277 x += info.width() + 4; 270 x += level.fPixmap.width() + 4;
278 } else { 271 } else {
279 y += info.height() + 4; 272 y += level.fPixmap.height() + 4;
280 } 273 }
281 scale /= 2; 274 scale /= 2;
282 index += 1; 275 index += 1;
283 } 276 }
284 } 277 }
285 278
286 void drawSet(SkCanvas* canvas, const SkBitmap& orig) { 279 void drawSet(SkCanvas* canvas, const SkBitmap& orig) {
287 const SkColorType ctypes[] = { 280 const SkColorType ctypes[] = {
288 kN32_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kGra y_8_SkColorType 281 kN32_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kGra y_8_SkColorType
289 }; 282 };
(...skipping 19 matching lines...) Expand all
309 } 302 }
310 } 303 }
311 304
312 private: 305 private:
313 typedef skiagm::GM INHERITED; 306 typedef skiagm::GM INHERITED;
314 }; 307 };
315 DEF_GM( return new ShowMipLevels2(255, 255); ) 308 DEF_GM( return new ShowMipLevels2(255, 255); )
316 DEF_GM( return new ShowMipLevels2(256, 255); ) 309 DEF_GM( return new ShowMipLevels2(256, 255); )
317 DEF_GM( return new ShowMipLevels2(255, 256); ) 310 DEF_GM( return new ShowMipLevels2(255, 256); )
318 DEF_GM( return new ShowMipLevels2(256, 256); ) 311 DEF_GM( return new ShowMipLevels2(256, 256); )
OLDNEW
« no previous file with comments | « no previous file | src/core/SkBitmapController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698