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

Side by Side Diff: tests/ShaderOpacityTest.cpp

Issue 1790353002: Revert of more shader-->sp conversions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 auto shader = SkShader::MakeBitmapShader(bmp, 20 SkShader* shader = SkShader::CreateBitmapShader(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();
24 25
25 // From this point on, we have pixels 26 // From this point on, we have pixels
26 bmp.allocPixels(info); 27 bmp.allocPixels(info);
27 28
28 // test 2: not opaque by default 29 // test 2: not opaque by default
29 shader = SkShader::MakeBitmapShader(bmp, 30 shader = SkShader::CreateBitmapShader(bmp,
30 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); 31 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
31 REPORTER_ASSERT(reporter, shader); 32 REPORTER_ASSERT(reporter, shader);
32 REPORTER_ASSERT(reporter, !shader->isOpaque()); 33 REPORTER_ASSERT(reporter, !shader->isOpaque());
34 shader->unref();
33 35
34 // test 3: explicitly opaque 36 // test 3: explicitly opaque
35 bmp.setAlphaType(kOpaque_SkAlphaType); 37 bmp.setAlphaType(kOpaque_SkAlphaType);
36 shader = SkShader::MakeBitmapShader(bmp, 38 shader = SkShader::CreateBitmapShader(bmp,
37 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); 39 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
38 REPORTER_ASSERT(reporter, shader); 40 REPORTER_ASSERT(reporter, shader);
39 REPORTER_ASSERT(reporter, shader->isOpaque()); 41 REPORTER_ASSERT(reporter, shader->isOpaque());
42 shader->unref();
40 43
41 // test 4: explicitly not opaque 44 // test 4: explicitly not opaque
42 bmp.setAlphaType(kPremul_SkAlphaType); 45 bmp.setAlphaType(kPremul_SkAlphaType);
43 shader = SkShader::MakeBitmapShader(bmp, 46 shader = SkShader::CreateBitmapShader(bmp,
44 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); 47 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
45 REPORTER_ASSERT(reporter, shader); 48 REPORTER_ASSERT(reporter, shader);
46 REPORTER_ASSERT(reporter, !shader->isOpaque()); 49 REPORTER_ASSERT(reporter, !shader->isOpaque());
50 shader->unref();
51
47 } 52 }
48 53
49 static void test_gradient(skiatest::Reporter* reporter) { 54 static void test_gradient(skiatest::Reporter* reporter)
55 {
50 SkPoint pts[2]; 56 SkPoint pts[2];
51 pts[0].iset(0, 0); 57 pts[0].iset(0, 0);
52 pts[1].iset(1, 0); 58 pts[1].iset(1, 0);
53 SkColor colors[2]; 59 SkColor colors[2];
54 SkScalar pos[2] = {SkIntToScalar(0), SkIntToScalar(1)}; 60 SkScalar pos[2] = {SkIntToScalar(0), SkIntToScalar(1)};
55 int count = 2; 61 int count = 2;
56 SkShader::TileMode mode = SkShader::kClamp_TileMode; 62 SkShader::TileMode mode = SkShader::kClamp_TileMode;
57 63
58 // test 1: all opaque 64 // test 1: all opaque
59 colors[0] = SkColorSetARGB(0xFF, 0, 0, 0); 65 colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
60 colors[1] = SkColorSetARGB(0xFF, 0, 0, 0); 66 colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
61 auto grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode); 67 SkShader* grad = SkGradientShader::CreateLinear(pts, colors, pos, count,
68 mode);
62 REPORTER_ASSERT(reporter, grad); 69 REPORTER_ASSERT(reporter, grad);
63 REPORTER_ASSERT(reporter, grad->isOpaque()); 70 REPORTER_ASSERT(reporter, grad->isOpaque());
71 grad->unref();
64 72
65 // test 2: all 0 alpha 73 // test 2: all 0 alpha
66 colors[0] = SkColorSetARGB(0, 0, 0, 0); 74 colors[0] = SkColorSetARGB(0, 0, 0, 0);
67 colors[1] = SkColorSetARGB(0, 0, 0, 0); 75 colors[1] = SkColorSetARGB(0, 0, 0, 0);
68 grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode); 76 grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
69 REPORTER_ASSERT(reporter, grad); 77 REPORTER_ASSERT(reporter, grad);
70 REPORTER_ASSERT(reporter, !grad->isOpaque()); 78 REPORTER_ASSERT(reporter, !grad->isOpaque());
79 grad->unref();
71 80
72 // test 3: one opaque, one transparent 81 // test 3: one opaque, one transparent
73 colors[0] = SkColorSetARGB(0xFF, 0, 0, 0); 82 colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
74 colors[1] = SkColorSetARGB(0x40, 0, 0, 0); 83 colors[1] = SkColorSetARGB(0x40, 0, 0, 0);
75 grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode); 84 grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
76 REPORTER_ASSERT(reporter, grad); 85 REPORTER_ASSERT(reporter, grad);
77 REPORTER_ASSERT(reporter, !grad->isOpaque()); 86 REPORTER_ASSERT(reporter, !grad->isOpaque());
87 grad->unref();
78 88
79 // test 4: test 3, swapped 89 // test 4: test 3, swapped
80 colors[0] = SkColorSetARGB(0x40, 0, 0, 0); 90 colors[0] = SkColorSetARGB(0x40, 0, 0, 0);
81 colors[1] = SkColorSetARGB(0xFF, 0, 0, 0); 91 colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
82 grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode); 92 grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
83 REPORTER_ASSERT(reporter, grad); 93 REPORTER_ASSERT(reporter, grad);
84 REPORTER_ASSERT(reporter, !grad->isOpaque()); 94 REPORTER_ASSERT(reporter, !grad->isOpaque());
95 grad->unref();
85 } 96 }
86 97
87 static void test_color(skiatest::Reporter* reporter) { 98 static void test_color(skiatest::Reporter* reporter)
99 {
88 SkColorShader colorShader1(SkColorSetARGB(0,0,0,0)); 100 SkColorShader colorShader1(SkColorSetARGB(0,0,0,0));
89 REPORTER_ASSERT(reporter, !colorShader1.isOpaque()); 101 REPORTER_ASSERT(reporter, !colorShader1.isOpaque());
90 SkColorShader colorShader2(SkColorSetARGB(0xFF,0,0,0)); 102 SkColorShader colorShader2(SkColorSetARGB(0xFF,0,0,0));
91 REPORTER_ASSERT(reporter, colorShader2.isOpaque()); 103 REPORTER_ASSERT(reporter, colorShader2.isOpaque());
92 SkColorShader colorShader3(SkColorSetARGB(0x7F,0,0,0)); 104 SkColorShader colorShader3(SkColorSetARGB(0x7F,0,0,0));
93 REPORTER_ASSERT(reporter, !colorShader3.isOpaque()); 105 REPORTER_ASSERT(reporter, !colorShader3.isOpaque());
94 } 106 }
95 107
96 DEF_TEST(ShaderOpacity, reporter) { 108 DEF_TEST(ShaderOpacity, reporter) {
97 test_gradient(reporter); 109 test_gradient(reporter);
98 test_color(reporter); 110 test_color(reporter);
99 test_bitmap(reporter); 111 test_bitmap(reporter);
100 } 112 }
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