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

Side by Side Diff: tests/ShaderOpacityTest.cpp

Issue 1793303002: Reland of "more shader-->sp conversions (patchset #5 id:80001 of https://codereview.chromium… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make pictureRef a value, so its clearer what's going on Created 4 years, 9 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 | « tests/RecorderTest.cpp ('k') | no next file » | 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 "SkColorShader.h" 8 #include "SkColorShader.h"
9 #include "SkGradientShader.h" 9 #include "SkGradientShader.h"
10 #include "SkShader.h" 10 #include "SkShader.h"
11 #include "Test.h" 11 #include "Test.h"
12 12
13 static void test_bitmap(skiatest::Reporter* reporter) { 13 static void test_bitmap(skiatest::Reporter* reporter) {
14 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); 14 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
15 15
16 SkBitmap bmp; 16 SkBitmap bmp;
17 bmp.setInfo(info); 17 bmp.setInfo(info);
18 18
19 // test 1: bitmap without pixel data 19 // test 1: bitmap without pixel data
20 SkShader* shader = SkShader::CreateBitmapShader(bmp, 20 auto shader = SkShader::MakeBitmapShader(bmp,
21 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); 21 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
22 REPORTER_ASSERT(reporter, shader); 22 REPORTER_ASSERT(reporter, shader);
23 REPORTER_ASSERT(reporter, !shader->isOpaque()); 23 REPORTER_ASSERT(reporter, !shader->isOpaque());
24 shader->unref();
25 24
26 // From this point on, we have pixels 25 // From this point on, we have pixels
27 bmp.allocPixels(info); 26 bmp.allocPixels(info);
28 27
29 // test 2: not opaque by default 28 // test 2: not opaque by default
30 shader = SkShader::CreateBitmapShader(bmp, 29 shader = SkShader::MakeBitmapShader(bmp,
31 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); 30 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
32 REPORTER_ASSERT(reporter, shader); 31 REPORTER_ASSERT(reporter, shader);
33 REPORTER_ASSERT(reporter, !shader->isOpaque()); 32 REPORTER_ASSERT(reporter, !shader->isOpaque());
34 shader->unref();
35 33
36 // test 3: explicitly opaque 34 // test 3: explicitly opaque
37 bmp.setAlphaType(kOpaque_SkAlphaType); 35 bmp.setAlphaType(kOpaque_SkAlphaType);
38 shader = SkShader::CreateBitmapShader(bmp, 36 shader = SkShader::MakeBitmapShader(bmp,
39 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); 37 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
40 REPORTER_ASSERT(reporter, shader); 38 REPORTER_ASSERT(reporter, shader);
41 REPORTER_ASSERT(reporter, shader->isOpaque()); 39 REPORTER_ASSERT(reporter, shader->isOpaque());
42 shader->unref();
43 40
44 // test 4: explicitly not opaque 41 // test 4: explicitly not opaque
45 bmp.setAlphaType(kPremul_SkAlphaType); 42 bmp.setAlphaType(kPremul_SkAlphaType);
46 shader = SkShader::CreateBitmapShader(bmp, 43 shader = SkShader::MakeBitmapShader(bmp,
47 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); 44 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
48 REPORTER_ASSERT(reporter, shader); 45 REPORTER_ASSERT(reporter, shader);
49 REPORTER_ASSERT(reporter, !shader->isOpaque()); 46 REPORTER_ASSERT(reporter, !shader->isOpaque());
50 shader->unref();
51
52 } 47 }
53 48
54 static void test_gradient(skiatest::Reporter* reporter) 49 static void test_gradient(skiatest::Reporter* reporter) {
55 {
56 SkPoint pts[2]; 50 SkPoint pts[2];
57 pts[0].iset(0, 0); 51 pts[0].iset(0, 0);
58 pts[1].iset(1, 0); 52 pts[1].iset(1, 0);
59 SkColor colors[2]; 53 SkColor colors[2];
60 SkScalar pos[2] = {SkIntToScalar(0), SkIntToScalar(1)}; 54 SkScalar pos[2] = {SkIntToScalar(0), SkIntToScalar(1)};
61 int count = 2; 55 int count = 2;
62 SkShader::TileMode mode = SkShader::kClamp_TileMode; 56 SkShader::TileMode mode = SkShader::kClamp_TileMode;
63 57
64 // test 1: all opaque 58 // test 1: all opaque
65 colors[0] = SkColorSetARGB(0xFF, 0, 0, 0); 59 colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
66 colors[1] = SkColorSetARGB(0xFF, 0, 0, 0); 60 colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
67 SkShader* grad = SkGradientShader::CreateLinear(pts, colors, pos, count, 61 auto grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
68 mode);
69 REPORTER_ASSERT(reporter, grad); 62 REPORTER_ASSERT(reporter, grad);
70 REPORTER_ASSERT(reporter, grad->isOpaque()); 63 REPORTER_ASSERT(reporter, grad->isOpaque());
71 grad->unref();
72 64
73 // test 2: all 0 alpha 65 // test 2: all 0 alpha
74 colors[0] = SkColorSetARGB(0, 0, 0, 0); 66 colors[0] = SkColorSetARGB(0, 0, 0, 0);
75 colors[1] = SkColorSetARGB(0, 0, 0, 0); 67 colors[1] = SkColorSetARGB(0, 0, 0, 0);
76 grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode); 68 grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
77 REPORTER_ASSERT(reporter, grad); 69 REPORTER_ASSERT(reporter, grad);
78 REPORTER_ASSERT(reporter, !grad->isOpaque()); 70 REPORTER_ASSERT(reporter, !grad->isOpaque());
79 grad->unref();
80 71
81 // test 3: one opaque, one transparent 72 // test 3: one opaque, one transparent
82 colors[0] = SkColorSetARGB(0xFF, 0, 0, 0); 73 colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
83 colors[1] = SkColorSetARGB(0x40, 0, 0, 0); 74 colors[1] = SkColorSetARGB(0x40, 0, 0, 0);
84 grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode); 75 grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
85 REPORTER_ASSERT(reporter, grad); 76 REPORTER_ASSERT(reporter, grad);
86 REPORTER_ASSERT(reporter, !grad->isOpaque()); 77 REPORTER_ASSERT(reporter, !grad->isOpaque());
87 grad->unref();
88 78
89 // test 4: test 3, swapped 79 // test 4: test 3, swapped
90 colors[0] = SkColorSetARGB(0x40, 0, 0, 0); 80 colors[0] = SkColorSetARGB(0x40, 0, 0, 0);
91 colors[1] = SkColorSetARGB(0xFF, 0, 0, 0); 81 colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
92 grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode); 82 grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
93 REPORTER_ASSERT(reporter, grad); 83 REPORTER_ASSERT(reporter, grad);
94 REPORTER_ASSERT(reporter, !grad->isOpaque()); 84 REPORTER_ASSERT(reporter, !grad->isOpaque());
95 grad->unref();
96 } 85 }
97 86
98 static void test_color(skiatest::Reporter* reporter) 87 static void test_color(skiatest::Reporter* reporter) {
99 {
100 SkColorShader colorShader1(SkColorSetARGB(0,0,0,0)); 88 SkColorShader colorShader1(SkColorSetARGB(0,0,0,0));
101 REPORTER_ASSERT(reporter, !colorShader1.isOpaque()); 89 REPORTER_ASSERT(reporter, !colorShader1.isOpaque());
102 SkColorShader colorShader2(SkColorSetARGB(0xFF,0,0,0)); 90 SkColorShader colorShader2(SkColorSetARGB(0xFF,0,0,0));
103 REPORTER_ASSERT(reporter, colorShader2.isOpaque()); 91 REPORTER_ASSERT(reporter, colorShader2.isOpaque());
104 SkColorShader colorShader3(SkColorSetARGB(0x7F,0,0,0)); 92 SkColorShader colorShader3(SkColorSetARGB(0x7F,0,0,0));
105 REPORTER_ASSERT(reporter, !colorShader3.isOpaque()); 93 REPORTER_ASSERT(reporter, !colorShader3.isOpaque());
106 } 94 }
107 95
108 DEF_TEST(ShaderOpacity, reporter) { 96 DEF_TEST(ShaderOpacity, reporter) {
109 test_gradient(reporter); 97 test_gradient(reporter);
110 test_color(reporter); 98 test_color(reporter);
111 test_bitmap(reporter); 99 test_bitmap(reporter);
112 } 100 }
OLDNEW
« no previous file with comments | « tests/RecorderTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698