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

Side by Side Diff: tests/ReadPixelsTest.cpp

Issue 164203003: replace setConfig+allocPixels with alloc-or-install-pixels (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 | « tests/DrawPathTest.cpp ('k') | tests/WritePixelsTest.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 2011 Google Inc. 2 * Copyright 2011 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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 r = SkMulDiv255Ceiling(r, a); 100 r = SkMulDiv255Ceiling(r, a);
101 g = SkMulDiv255Ceiling(g, a); 101 g = SkMulDiv255Ceiling(g, a);
102 b = SkMulDiv255Ceiling(b, a); 102 b = SkMulDiv255Ceiling(b, a);
103 } 103 }
104 return SkPackARGB32(a, r, g, b); 104 return SkPackARGB32(a, r, g, b);
105 } 105 }
106 106
107 static void fillCanvas(SkCanvas* canvas) { 107 static void fillCanvas(SkCanvas* canvas) {
108 static SkBitmap bmp; 108 static SkBitmap bmp;
109 if (bmp.isNull()) { 109 if (bmp.isNull()) {
110 bmp.setConfig(SkBitmap::kARGB_8888_Config, DEV_W, DEV_H); 110 SkDEBUGCODE(bool alloc =) bmp.allocN32Pixels(DEV_W, DEV_H);
111 SkDEBUGCODE(bool alloc =) bmp.allocPixels();
112 SkASSERT(alloc); 111 SkASSERT(alloc);
113 SkAutoLockPixels alp(bmp); 112 SkAutoLockPixels alp(bmp);
114 intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels()); 113 intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
115 for (int y = 0; y < DEV_H; ++y) { 114 for (int y = 0; y < DEV_H; ++y) {
116 for (int x = 0; x < DEV_W; ++x) { 115 for (int x = 0; x < DEV_W; ++x) {
117 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp .rowBytes() + x * bmp.bytesPerPixel()); 116 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp .rowBytes() + x * bmp.bytesPerPixel());
118 *pixel = getCanvasColor(x, y); 117 *pixel = getCanvasColor(x, y);
119 } 118 }
120 } 119 }
121 } 120 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 222
224 kBitmapInitCnt 223 kBitmapInitCnt
225 }; 224 };
226 225
227 static BitmapInit nextBMI(BitmapInit bmi) { 226 static BitmapInit nextBMI(BitmapInit bmi) {
228 int x = bmi; 227 int x = bmi;
229 return static_cast<BitmapInit>(++x); 228 return static_cast<BitmapInit>(++x);
230 } 229 }
231 230
232 static void init_bitmap(SkBitmap* bitmap, const SkIRect& rect, BitmapInit init) { 231 static void init_bitmap(SkBitmap* bitmap, const SkIRect& rect, BitmapInit init) {
233 int w = rect.width(); 232 SkImageInfo info = SkImageInfo::MakeN32Premul(rect.width(), rect.height());
234 int h = rect.height(); 233 size_t rowBytes = 0;
235 int rowBytes = 0;
236 bool alloc = true; 234 bool alloc = true;
237 switch (init) { 235 switch (init) {
238 case kNoPixels_BitmapInit: 236 case kNoPixels_BitmapInit:
239 alloc = false; 237 alloc = false;
240 case kTight_BitmapInit: 238 case kTight_BitmapInit:
241 break; 239 break;
242 case kRowBytes_BitmapInit: 240 case kRowBytes_BitmapInit:
243 rowBytes = w * sizeof(SkPMColor) + 16 * sizeof(SkPMColor); 241 rowBytes = (info.width() + 16) * sizeof(SkPMColor);
244 break; 242 break;
245 default: 243 default:
246 SkASSERT(0); 244 SkASSERT(0);
247 break; 245 break;
248 } 246 }
249 bitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h, rowBytes); 247
250 if (alloc) { 248 if (alloc) {
251 bitmap->allocPixels(); 249 bitmap->allocPixels(info);
250 } else {
251 bitmap->setConfig(info, rowBytes);
252 } 252 }
253 } 253 }
254 254
255 DEF_GPUTEST(ReadPixels, reporter, factory) { 255 DEF_GPUTEST(ReadPixels, reporter, factory) {
256 const SkIRect testRects[] = { 256 const SkIRect testRects[] = {
257 // entire thing 257 // entire thing
258 DEV_RECT, 258 DEV_RECT,
259 // larger on all sides 259 // larger on all sides
260 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H + 10), 260 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H + 10),
261 // fully contained 261 // fully contained
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 clippedRect.fTop, true, false, 400 clippedRect.fTop, true, false,
401 SkCanvas::kNative_Premul_Config8888); 401 SkCanvas::kNative_Premul_Config8888);
402 } else { 402 } else {
403 REPORTER_ASSERT(reporter, !success); 403 REPORTER_ASSERT(reporter, !success);
404 } 404 }
405 } 405 }
406 } 406 }
407 } 407 }
408 } 408 }
409 } 409 }
OLDNEW
« no previous file with comments | « tests/DrawPathTest.cpp ('k') | tests/WritePixelsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698