OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 #include "gm.h" | 8 #include "gm.h" |
10 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
11 #include "SkPatchUtils.h" | 10 #include "SkPatchUtils.h" |
12 | 11 |
13 static sk_sp<SkShader> make_shader() { | 12 static sk_sp<SkShader> make_shader() { |
14 const SkColor colors[] = { | 13 const SkColor colors[] = { |
15 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, SK_ColorMAGENTA
, SK_ColorBLUE, | 14 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, SK_ColorMAGENTA
, SK_ColorBLUE, |
16 SK_ColorYELLOW, | 15 SK_ColorYELLOW, |
17 }; | 16 }; |
18 const SkPoint pts[] = { { 100.f / 4.f, 0.f }, { 3.f * 100.f / 4.f, 100.f } }
; | 17 const SkPoint pts[] = { { 100.f / 4.f, 0.f }, { 3.f * 100.f / 4.f, 100.f } }
; |
19 | 18 |
20 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col
ors), | 19 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col
ors), |
21 SkShader::kMirror_TileMode); | 20 SkShader::kMirror_TileMode); |
22 } | 21 } |
23 | 22 |
24 static void draw_control_points(SkCanvas* canvas, const SkPoint cubics[12]) { | 23 static void draw_control_points(SkCanvas* canvas, const SkPoint cubics[12]) { |
25 //draw control points | 24 //draw control points |
26 SkPaint paint; | 25 SkPaint paint; |
27 SkPoint bottom[SkPatchUtils::kNumPtsCubic]; | 26 SkPoint bottom[SkPatchUtils::kNumPtsCubic]; |
28 SkPatchUtils::getBottomCubic(cubics, bottom); | 27 SkPatchUtils::getBottomCubic(cubics, bottom); |
29 SkPoint top[SkPatchUtils::kNumPtsCubic]; | 28 SkPoint top[SkPatchUtils::kNumPtsCubic]; |
(...skipping 29 matching lines...) Expand all Loading... |
59 | 58 |
60 paint.setColor(SK_ColorYELLOW); | 59 paint.setColor(SK_ColorYELLOW); |
61 canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, left + 1, paint); | 60 canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, left + 1, paint); |
62 | 61 |
63 paint.setColor(SK_ColorGREEN); | 62 paint.setColor(SK_ColorGREEN); |
64 canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, right + 1, paint); | 63 canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, right + 1, paint); |
65 } | 64 } |
66 | 65 |
67 DEF_SIMPLE_GM(patch_primitive, canvas, 800, 800) { | 66 DEF_SIMPLE_GM(patch_primitive, canvas, 800, 800) { |
68 SkPaint paint; | 67 SkPaint paint; |
69 | 68 |
70 // The order of the colors and points is clockwise starting at upper-lef
t corner. | 69 // The order of the colors and points is clockwise starting at upper-lef
t corner. |
71 const SkPoint cubics[SkPatchUtils::kNumCtrlPts] = { | 70 const SkPoint cubics[SkPatchUtils::kNumCtrlPts] = { |
72 //top points | 71 //top points |
73 {100,100},{150,50},{250,150}, {300,100}, | 72 {100,100},{150,50},{250,150}, {300,100}, |
74 //right points | 73 //right points |
75 {250, 150},{350,250}, | 74 {250, 150},{350,250}, |
76 //bottom points | 75 //bottom points |
77 {300,300},{250,250},{150,350},{100,300}, | 76 {300,300},{250,250},{150,350},{100,300}, |
78 //left points | 77 //left points |
79 {50,250},{150,150} | 78 {50,250},{150,150} |
80 }; | 79 }; |
81 | 80 |
82 const SkColor colors[SkPatchUtils::kNumCorners] = { | 81 const SkColor colors[SkPatchUtils::kNumCorners] = { |
83 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorCYAN | 82 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorCYAN |
84 }; | 83 }; |
85 const SkPoint texCoords[SkPatchUtils::kNumCorners] = { | 84 const SkPoint texCoords[SkPatchUtils::kNumCorners] = { |
86 {0.0f, 0.0f}, {100.0f, 0.0f}, {100.0f,100.0f}, {0.0f, 100.0f}} | 85 {0.0f, 0.0f}, {100.0f, 0.0f}, {100.0f,100.0f}, {0.0f, 100.0f}} |
87 ; | 86 ; |
88 | 87 |
89 const SkXfermode::Mode modes[] = { | 88 const SkXfermode::Mode modes[] = { |
90 SkXfermode::kSrc_Mode, | 89 SkXfermode::kSrc_Mode, |
91 SkXfermode::kDst_Mode, | 90 SkXfermode::kDst_Mode, |
92 SkXfermode::kModulate_Mode, | 91 SkXfermode::kModulate_Mode, |
93 }; | 92 }; |
94 | 93 |
95 sk_sp<SkShader> shader(make_shader()); | 94 sk_sp<SkShader> shader(make_shader()); |
96 | 95 |
97 canvas->save(); | 96 canvas->save(); |
98 for (int y = 0; y < 3; y++) { | 97 for (int y = 0; y < 3; y++) { |
99 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(modes[y])); | 98 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(modes[y])); |
100 | 99 |
101 for (int x = 0; x < 4; x++) { | 100 for (int x = 0; x < 4; x++) { |
102 canvas->save(); | 101 canvas->save(); |
103 canvas->translate(x * 350.0f, y * 350.0f); | 102 canvas->translate(x * 350.0f, y * 350.0f); |
104 switch (x) { | 103 switch (x) { |
105 case 0: | 104 case 0: |
106 canvas->drawPatch(cubics, nullptr, nullptr, xfer, paint)
; | 105 canvas->drawPatch(cubics, nullptr, nullptr, xfer, paint)
; |
107 break; | 106 break; |
108 case 1: | 107 case 1: |
109 canvas->drawPatch(cubics, colors, nullptr, xfer, paint); | 108 canvas->drawPatch(cubics, colors, nullptr, xfer, paint); |
110 break; | 109 break; |
111 case 2: | 110 case 2: |
112 paint.setShader(shader); | 111 paint.setShader(shader); |
113 canvas->drawPatch(cubics, nullptr, texCoords, xfer, pain
t); | 112 canvas->drawPatch(cubics, nullptr, texCoords, xfer, pain
t); |
114 paint.setShader(nullptr); | 113 paint.setShader(nullptr); |
115 break; | 114 break; |
116 case 3: | 115 case 3: |
117 paint.setShader(shader); | 116 paint.setShader(shader); |
118 canvas->drawPatch(cubics, colors, texCoords, xfer, paint
); | 117 canvas->drawPatch(cubics, colors, texCoords, xfer, paint
); |
119 paint.setShader(nullptr); | 118 paint.setShader(nullptr); |
120 break; | 119 break; |
121 default: | 120 default: |
122 break; | 121 break; |
123 } | 122 } |
124 | 123 |
125 draw_control_points(canvas, cubics); | 124 draw_control_points(canvas, cubics); |
126 canvas->restore(); | 125 canvas->restore(); |
127 } | 126 } |
128 } | 127 } |
129 canvas->restore(); | 128 canvas->restore(); |
130 } | 129 } |
OLD | NEW |