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

Side by Side Diff: tests/PictureTest.cpp

Issue 162643002: replace setConfig+allocPixels with single call (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/PathUtilsTest.cpp ('k') | tests/PipeTest.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 2012 Google Inc. 2 * Copyright 2012 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"
11 #include "SkData.h" 11 #include "SkData.h"
12 #include "SkDecodingImageGenerator.h" 12 #include "SkDecodingImageGenerator.h"
13 #include "SkError.h" 13 #include "SkError.h"
14 #include "SkImageEncoder.h" 14 #include "SkImageEncoder.h"
15 #include "SkImageGenerator.h" 15 #include "SkImageGenerator.h"
16 #include "SkPaint.h" 16 #include "SkPaint.h"
17 #include "SkPicture.h" 17 #include "SkPicture.h"
18 #include "SkPictureUtils.h" 18 #include "SkPictureUtils.h"
19 #include "SkRRect.h" 19 #include "SkRRect.h"
20 #include "SkRandom.h" 20 #include "SkRandom.h"
21 #include "SkShader.h" 21 #include "SkShader.h"
22 #include "SkStream.h" 22 #include "SkStream.h"
23 #include "Test.h" 23 #include "Test.h"
24 24
25 static const int gColorScale = 30; 25 static const int gColorScale = 30;
26 static const int gColorOffset = 60; 26 static const int gColorOffset = 60;
27 27
28 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { 28 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) {
29 bm->setConfig(SkBitmap::kARGB_8888_Config, w, h); 29 bm->allocN32Pixels(w, h);
30 bm->allocPixels();
31 bm->eraseColor(color); 30 bm->eraseColor(color);
32 if (immutable) { 31 if (immutable) {
33 bm->setImmutable(); 32 bm->setImmutable();
34 } 33 }
35 } 34 }
36 35
37 static void make_checkerboard(SkBitmap* bm, int w, int h, bool immutable) { 36 static void make_checkerboard(SkBitmap* bm, int w, int h, bool immutable) {
38 SkASSERT(w % 2 == 0); 37 SkASSERT(w % 2 == 0);
39 SkASSERT(h % 2 == 0); 38 SkASSERT(h % 2 == 0);
40 bm->setConfig(SkBitmap::kA8_Config, w, h); 39 bm->allocPixels(SkImageInfo::Make(w, h, kAlpha_8_SkColorType,
41 bm->allocPixels(); 40 kPremul_SkAlphaType));
42 SkAutoLockPixels lock(*bm); 41 SkAutoLockPixels lock(*bm);
43 for (int y = 0; y < h; y += 2) { 42 for (int y = 0; y < h; y += 2) {
44 uint8_t* s = bm->getAddr8(0, y); 43 uint8_t* s = bm->getAddr8(0, y);
45 for (int x = 0; x < w; x += 2) { 44 for (int x = 0; x < w; x += 2) {
46 *s++ = 0xFF; 45 *s++ = 0xFF;
47 *s++ = 0x00; 46 *s++ = 0x00;
48 } 47 }
49 s = bm->getAddr8(0, y + 1); 48 s = bm->getAddr8(0, y + 1);
50 for (int x = 0; x < w; x += 2) { 49 for (int x = 0; x < w; x += 2) {
51 *s++ = 0x00; 50 *s++ = 0x00;
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 } 713 }
715 } 714 }
716 715
717 #ifndef SK_DEBUG 716 #ifndef SK_DEBUG
718 // Only test this is in release mode. We deliberately crash in debug mode, since a valid caller 717 // Only test this is in release mode. We deliberately crash in debug mode, since a valid caller
719 // should never do this. 718 // should never do this.
720 static void test_bad_bitmap() { 719 static void test_bad_bitmap() {
721 // This bitmap has a width and height but no pixels. As a result, attempting to record it will 720 // This bitmap has a width and height but no pixels. As a result, attempting to record it will
722 // fail. 721 // fail.
723 SkBitmap bm; 722 SkBitmap bm;
724 bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 723 bm.setConfig(SkImageInfo::MakeN32Premul(100, 100));
725 SkPicture picture; 724 SkPicture picture;
726 SkCanvas* recordingCanvas = picture.beginRecording(100, 100); 725 SkCanvas* recordingCanvas = picture.beginRecording(100, 100);
727 recordingCanvas->drawBitmap(bm, 0, 0); 726 recordingCanvas->drawBitmap(bm, 0, 0);
728 picture.endRecording(); 727 picture.endRecording();
729 728
730 SkCanvas canvas; 729 SkCanvas canvas;
731 canvas.drawPicture(picture); 730 canvas.drawPicture(picture);
732 } 731 }
733 #endif 732 #endif
734 733
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint); 1040 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint);
1042 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag); 1041 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag);
1043 canvas->drawBitmapMatrix(bitmap, SkMatrix::I(), &paint); 1042 canvas->drawBitmapMatrix(bitmap, SkMatrix::I(), &paint);
1044 canvas->drawBitmapNine(bitmap, irect, rect, &paint); 1043 canvas->drawBitmapNine(bitmap, irect, rect, &paint);
1045 canvas->drawSprite(bitmap, 1, 1); 1044 canvas->drawSprite(bitmap, 1, 1);
1046 } 1045 }
1047 1046
1048 static void test_draw_bitmaps(SkCanvas* canvas) { 1047 static void test_draw_bitmaps(SkCanvas* canvas) {
1049 SkBitmap empty; 1048 SkBitmap empty;
1050 draw_bitmaps(empty, canvas); 1049 draw_bitmaps(empty, canvas);
1051 empty.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); 1050 empty.setConfig(SkImageInfo::MakeN32Premul(10, 10));
1052 draw_bitmaps(empty, canvas); 1051 draw_bitmaps(empty, canvas);
1053 } 1052 }
1054 1053
1055 DEF_TEST(Picture_EmptyBitmap, r) { 1054 DEF_TEST(Picture_EmptyBitmap, r) {
1056 SkPicture picture; 1055 SkPicture picture;
1057 test_draw_bitmaps(picture.beginRecording(10, 10)); 1056 test_draw_bitmaps(picture.beginRecording(10, 10));
1058 picture.endRecording(); 1057 picture.endRecording();
1059 } 1058 }
1060 1059
1061 DEF_TEST(Canvas_EmptyBitmap, r) { 1060 DEF_TEST(Canvas_EmptyBitmap, r) {
1062 SkBitmap dst; 1061 SkBitmap dst;
1063 dst.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); 1062 dst.allocN32Pixels(10, 10);
1064 dst.allocPixels();
1065 SkCanvas canvas(dst); 1063 SkCanvas canvas(dst);
1066 1064
1067 test_draw_bitmaps(&canvas); 1065 test_draw_bitmaps(&canvas);
1068 } 1066 }
OLDNEW
« no previous file with comments | « tests/PathUtilsTest.cpp ('k') | tests/PipeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698