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

Unified Diff: tests/WritePixelsTest.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/ReadPixelsTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/WritePixelsTest.cpp
diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp
index 43d17e7cb5c14e2dc6cbcdda00f0965935245515..e2e4a0c802952f9e6f09cfe6ec772c387e645f7c 100644
--- a/tests/WritePixelsTest.cpp
+++ b/tests/WritePixelsTest.cpp
@@ -136,8 +136,7 @@ static uint32_t getBitmapColor(int x, int y, int w, SkCanvas::Config8888 config8
static void fillCanvas(SkCanvas* canvas) {
static SkBitmap bmp;
if (bmp.isNull()) {
- bmp.setConfig(SkBitmap::kARGB_8888_Config, DEV_W, DEV_H);
- SkDEBUGCODE(bool alloc = ) bmp.allocPixels();
+ SkDEBUGCODE(bool alloc = ) bmp.allocN32Pixels(DEV_W, DEV_H);
SkASSERT(alloc);
SkAutoLockPixels alp(bmp);
intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
@@ -304,13 +303,28 @@ static const CanvasConfig gCanvasConfigs[] = {
#endif
};
+#include "SkMallocPixelRef.h"
+
+// This is a tricky pattern, because we have to setConfig+rowBytes AND specify
+// a custom pixelRef (which also has to specify its rowBytes), so we have to be
+// sure that the two rowBytes match (and the infos match).
+//
+static bool allocRowBytes(SkBitmap* bm, const SkImageInfo& info, size_t rowBytes) {
+ if (!bm->setConfig(info, rowBytes)) {
+ return false;
+ }
+ SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, rowBytes, NULL);
+ bm->setPixelRef(pr)->unref();
+ return true;
+}
+
static SkBaseDevice* createDevice(const CanvasConfig& c, GrContext* grCtx) {
switch (c.fDevType) {
case kRaster_DevType: {
SkBitmap bmp;
size_t rowBytes = c.fTightRowBytes ? 0 : 4 * DEV_W + 100;
- bmp.setConfig(SkBitmap::kARGB_8888_Config, DEV_W, DEV_H, rowBytes);
- if (!bmp.allocPixels()) {
+ SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
+ if (!allocRowBytes(&bmp, info, rowBytes)) {
sk_throw();
return NULL;
}
@@ -344,8 +358,8 @@ static bool setupBitmap(SkBitmap* bitmap,
int w, int h,
bool tightRowBytes) {
size_t rowBytes = tightRowBytes ? 0 : 4 * w + 60;
- bitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h, rowBytes);
- if (!bitmap->allocPixels()) {
+ SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
+ if (!allocRowBytes(bitmap, info, rowBytes)) {
return false;
}
SkAutoLockPixels alp(*bitmap);
« no previous file with comments | « tests/ReadPixelsTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698