| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "Benchmark.h" | 8 #include "Benchmark.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 {{50,125},{150,125},{250,125},{350,125},{450,125}}, | 89 {{50,125},{150,125},{250,125},{350,125},{450,125}}, |
| 90 {{50,175},{150,175},{220,225},{350,175},{470,225}}, | 90 {{50,175},{150,175},{220,225},{350,175},{470,225}}, |
| 91 {{50,225},{150,225},{220,175},{350,225},{470,155}}, | 91 {{50,225},{150,225},{220,175},{350,225},{470,155}}, |
| 92 {{50,275},{150,275},{250,275},{350,275},{400,305}}, | 92 {{50,275},{150,275},{250,275},{350,275},{400,305}}, |
| 93 {{50,325},{150,325},{250,325},{350,325},{450,325}} | 93 {{50,325},{150,325},{250,325},{350,325},{450,325}} |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 static const int kRows = 3; | 96 static const int kRows = 3; |
| 97 static const int kCols = 4; | 97 static const int kCols = 4; |
| 98 | 98 |
| 99 fGrid.reset(kRows, kCols, SkPatchGrid::kColors_VertexType, NULL); | 99 fGrid.reset(kRows, kCols, SkPatchGrid::kColors_VertexType, nullptr); |
| 100 for (int i = 0; i < kRows; i++) { | 100 for (int i = 0; i < kRows; i++) { |
| 101 for (int j = 0; j < kCols; j++) { | 101 for (int j = 0; j < kCols; j++) { |
| 102 SkPoint points[12]; | 102 SkPoint points[12]; |
| 103 | 103 |
| 104 //set corners | 104 //set corners |
| 105 points[SkPatchUtils::kTopP0_CubicCtrlPts] = vertices[i][j]; | 105 points[SkPatchUtils::kTopP0_CubicCtrlPts] = vertices[i][j]; |
| 106 points[SkPatchUtils::kTopP3_CubicCtrlPts] = vertices[i][j + 1]; | 106 points[SkPatchUtils::kTopP3_CubicCtrlPts] = vertices[i][j + 1]; |
| 107 points[SkPatchUtils::kBottomP0_CubicCtrlPts] = vertices[i + 1][j
]; | 107 points[SkPatchUtils::kBottomP0_CubicCtrlPts] = vertices[i + 1][j
]; |
| 108 points[SkPatchUtils::kBottomP3_CubicCtrlPts] = vertices[i + 1][j
+ 1]; | 108 points[SkPatchUtils::kBottomP3_CubicCtrlPts] = vertices[i + 1][j
+ 1]; |
| 109 | 109 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 124 colors[2] = cornerColors[i + 1][j + 1]; | 124 colors[2] = cornerColors[i + 1][j + 1]; |
| 125 | 125 |
| 126 SkPoint texs[4]; | 126 SkPoint texs[4]; |
| 127 texs[0] = texCoords[i][j]; | 127 texs[0] = texCoords[i][j]; |
| 128 texs[1] = texCoords[i][j + 1]; | 128 texs[1] = texCoords[i][j + 1]; |
| 129 texs[3] = texCoords[i + 1][j]; | 129 texs[3] = texCoords[i + 1][j]; |
| 130 texs[2] = texCoords[i + 1][j + 1]; | 130 texs[2] = texCoords[i + 1][j + 1]; |
| 131 | 131 |
| 132 switch (fVertexMode) { | 132 switch (fVertexMode) { |
| 133 case kNone_VertexMode: | 133 case kNone_VertexMode: |
| 134 fGrid.setPatch(j, i, points, NULL, NULL); | 134 fGrid.setPatch(j, i, points, nullptr, nullptr); |
| 135 break; | 135 break; |
| 136 case kColors_VertexMode: | 136 case kColors_VertexMode: |
| 137 fGrid.setPatch(j, i, points, colors, NULL); | 137 fGrid.setPatch(j, i, points, colors, nullptr); |
| 138 break; | 138 break; |
| 139 case kTexCoords_VertexMode: | 139 case kTexCoords_VertexMode: |
| 140 fGrid.setPatch(j, i, points, NULL, texs); | 140 fGrid.setPatch(j, i, points, nullptr, texs); |
| 141 break; | 141 break; |
| 142 case kBoth_VertexMode: | 142 case kBoth_VertexMode: |
| 143 fGrid.setPatch(j, i, points, colors, texs); | 143 fGrid.setPatch(j, i, points, colors, texs); |
| 144 break; | 144 break; |
| 145 default: | 145 default: |
| 146 break; | 146 break; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 // override this method to change the shader | 152 // override this method to change the shader |
| 153 SkShader* createShader() { | 153 SkShader* createShader() { |
| 154 const SkColor colors[] = { | 154 const SkColor colors[] = { |
| 155 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, | 155 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, |
| 156 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW, | 156 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW, |
| 157 }; | 157 }; |
| 158 const SkPoint pts[] = { { 200.f / 4.f, 0.f }, { 3.f * 200.f / 4, 200.f }
}; | 158 const SkPoint pts[] = { { 200.f / 4.f, 0.f }, { 3.f * 200.f / 4, 200.f }
}; |
| 159 | 159 |
| 160 return SkGradientShader::CreateLinear(pts, colors, NULL, | 160 return SkGradientShader::CreateLinear(pts, colors, nullptr, |
| 161 SK_ARRAY_COUNT(colors), | 161 SK_ARRAY_COUNT(colors), |
| 162 SkShader::kMirror_TileMode); | 162 SkShader::kMirror_TileMode); |
| 163 } | 163 } |
| 164 | 164 |
| 165 protected: | 165 protected: |
| 166 const char* onGetName() override { | 166 const char* onGetName() override { |
| 167 SkString vertexMode; | 167 SkString vertexMode; |
| 168 switch (fVertexMode) { | 168 switch (fVertexMode) { |
| 169 case kNone_VertexMode: | 169 case kNone_VertexMode: |
| 170 vertexMode.set("meshlines"); | 170 vertexMode.set("meshlines"); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 201 } | 201 } |
| 202 | 202 |
| 203 void onPreDraw() override { | 203 void onPreDraw() override { |
| 204 this->setGrid(); | 204 this->setGrid(); |
| 205 switch (fVertexMode) { | 205 switch (fVertexMode) { |
| 206 case kTexCoords_VertexMode: | 206 case kTexCoords_VertexMode: |
| 207 case kBoth_VertexMode: | 207 case kBoth_VertexMode: |
| 208 fPaint.setShader(createShader())->unref(); | 208 fPaint.setShader(createShader())->unref(); |
| 209 break; | 209 break; |
| 210 default: | 210 default: |
| 211 fPaint.setShader(NULL); | 211 fPaint.setShader(nullptr); |
| 212 break; | 212 break; |
| 213 } | 213 } |
| 214 this->setupPaint(&fPaint); | 214 this->setupPaint(&fPaint); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void onDraw(const int loops, SkCanvas* canvas) override { | 217 void onDraw(const int loops, SkCanvas* canvas) override { |
| 218 this->setScale(canvas); | 218 this->setScale(canvas); |
| 219 for (int i = 0; i < loops; i++) { | 219 for (int i = 0; i < loops; i++) { |
| 220 fGrid.draw(canvas, fPaint); | 220 fGrid.draw(canvas, fPaint); |
| 221 } | 221 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 250 DEF_BENCH( return new PatchGridBench(PatchGridBench::kMedium_Size, | 250 DEF_BENCH( return new PatchGridBench(PatchGridBench::kMedium_Size, |
| 251 PatchGridBench::kBoth_VertexMode); ) | 251 PatchGridBench::kBoth_VertexMode); ) |
| 252 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, | 252 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, |
| 253 PatchGridBench::kNone_VertexMode); ) | 253 PatchGridBench::kNone_VertexMode); ) |
| 254 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, | 254 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, |
| 255 PatchGridBench::kColors_VertexMode); ) | 255 PatchGridBench::kColors_VertexMode); ) |
| 256 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, | 256 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, |
| 257 PatchGridBench::kTexCoords_VertexMode); ) | 257 PatchGridBench::kTexCoords_VertexMode); ) |
| 258 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, | 258 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, |
| 259 PatchGridBench::kBoth_VertexMode); ) | 259 PatchGridBench::kBoth_VertexMode); ) |
| OLD | NEW |