| 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 "SkPatchGrid.h" |    9 #include "SkPatchGrid.h" | 
|   11  |   10  | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   50  |   49  | 
|   51     paint.setColor(SK_ColorGREEN); |   50     paint.setColor(SK_ColorGREEN); | 
|   52     canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, right+1, paint); |   51     canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, right+1, paint); | 
|   53 } |   52 } | 
|   54  |   53  | 
|   55 namespace skiagm { |   54 namespace skiagm { | 
|   56 /** |   55 /** | 
|   57  * This GM draws a grid of patches, it only uses colors so it could be considere
     d a mesh gradient. |   56  * This GM draws a grid of patches, it only uses colors so it could be considere
     d a mesh gradient. | 
|   58  */ |   57  */ | 
|   59 class SkPatchGridGM : public GM { |   58 class SkPatchGridGM : public GM { | 
|   60      |   59  | 
|   61 public: |   60 public: | 
|   62     SkPatchGridGM() { |   61     SkPatchGridGM() { | 
|   63         this->setBGColor(0xFFFFFFFF); |   62         this->setBGColor(0xFFFFFFFF); | 
|   64     } |   63     } | 
|   65  |   64  | 
|   66 protected: |   65 protected: | 
|   67     SkString onShortName() override { |   66     SkString onShortName() override { | 
|   68         return SkString("patch_grid"); |   67         return SkString("patch_grid"); | 
|   69     } |   68     } | 
|   70  |   69  | 
|   71     SkISize onISize() override { |   70     SkISize onISize() override { | 
|   72         return SkISize::Make(800, 800); |   71         return SkISize::Make(800, 800); | 
|   73     } |   72     } | 
|   74  |   73  | 
|   75     void onDraw(SkCanvas* canvas) override { |   74     void onDraw(SkCanvas* canvas) override { | 
|   76  |   75  | 
|   77         SkPaint paint; |   76         SkPaint paint; | 
|   78          |   77  | 
|   79         SkPoint vertices[4][5] = { |   78         SkPoint vertices[4][5] = { | 
|   80             {{50,50}, {150,50}, {250,50},{350,50},{450,50}}, |   79             {{50,50}, {150,50}, {250,50},{350,50},{450,50}}, | 
|   81             {{50,150}, {120,120}, {250,150},{350,150},{450,150}}, |   80             {{50,150}, {120,120}, {250,150},{350,150},{450,150}}, | 
|   82             {{50,250}, {150,250}, {250,250},{350,250},{450,250}}, |   81             {{50,250}, {150,250}, {250,250},{350,250},{450,250}}, | 
|   83             {{100,300}, {150,350}, {250,350},{350,350},{450,350}} |   82             {{100,300}, {150,350}, {250,350},{350,350},{450,350}} | 
|   84         }; |   83         }; | 
|   85          |   84  | 
|   86         SkColor cornerColors[4][5] = { |   85         SkColor cornerColors[4][5] = { | 
|   87             {SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE}
     , |   86             {SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE}
     , | 
|   88             {SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED}, |   87             {SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED}, | 
|   89             {SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE}
     , |   88             {SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE}
     , | 
|   90             {SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED}, |   89             {SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED}, | 
|   91         }; |   90         }; | 
|   92          |   91  | 
|   93         SkPoint hrzCtrl[4][8] = { |   92         SkPoint hrzCtrl[4][8] = { | 
|   94             {{75,30},{125,45},{175,70},{225,20},{275,50},{325,50},{375,5},{425,9
     0}}, |   93             {{75,30},{125,45},{175,70},{225,20},{275,50},{325,50},{375,5},{425,9
     0}}, | 
|   95             {{75,150},{125,150},{175,150},{225,150},{275,150},{325,150},{375,150
     },{425,150}}, |   94             {{75,150},{125,150},{175,150},{225,150},{275,150},{325,150},{375,150
     },{425,150}}, | 
|   96             {{75,250},{125,250},{175,250},{225,250},{275,200},{325,150},{375,250
     },{425,250}}, |   95             {{75,250},{125,250},{175,250},{225,250},{275,200},{325,150},{375,250
     },{425,250}}, | 
|   97             {{75,350},{125,350},{175,350},{225,350},{275,350},{325,350},{375,350
     },{425,350}} |   96             {{75,350},{125,350},{175,350},{225,350},{275,350},{325,350},{375,350
     },{425,350}} | 
|   98         }; |   97         }; | 
|   99          |   98  | 
|  100         SkPoint vrtCtrl[6][5] = { |   99         SkPoint vrtCtrl[6][5] = { | 
|  101             {{50,75},{150,75},{250,75},{350,75},{450,75}}, |  100             {{50,75},{150,75},{250,75},{350,75},{450,75}}, | 
|  102             {{50,125},{150,125},{250,125},{350,125},{450,125}}, |  101             {{50,125},{150,125},{250,125},{350,125},{450,125}}, | 
|  103             {{50,175},{150,175},{220,225},{350,175},{470,225}}, |  102             {{50,175},{150,175},{220,225},{350,175},{470,225}}, | 
|  104             {{50,225},{150,225},{220,175},{350,225},{470,155}}, |  103             {{50,225},{150,225},{220,175},{350,225},{470,155}}, | 
|  105             {{50,275},{150,275},{250,275},{350,275},{400,305}}, |  104             {{50,275},{150,275},{250,275},{350,275},{400,305}}, | 
|  106             {{50,325},{150,325},{250,325},{350,325},{450,325}} |  105             {{50,325},{150,325},{250,325},{350,325},{450,325}} | 
|  107         }; |  106         }; | 
|  108          |  107  | 
|  109         static const int kRows = 3; |  108         static const int kRows = 3; | 
|  110         static const int kCols = 4; |  109         static const int kCols = 4; | 
|  111          |  110  | 
|  112         canvas->scale(3, 3); |  111         canvas->scale(3, 3); | 
|  113         SkPatchGrid grid(kRows, kCols, SkPatchGrid::kColors_VertexType, nullptr)
     ; |  112         SkPatchGrid grid(kRows, kCols, SkPatchGrid::kColors_VertexType, nullptr)
     ; | 
|  114         for (int i = 0; i < kRows; i++) { |  113         for (int i = 0; i < kRows; i++) { | 
|  115             for (int j = 0; j < kCols; j++) { |  114             for (int j = 0; j < kCols; j++) { | 
|  116                 SkPoint points[12]; |  115                 SkPoint points[12]; | 
|  117                  |  116  | 
|  118                 //set corners |  117                 //set corners | 
|  119                 points[SkPatchUtils::kTopP0_CubicCtrlPts] = vertices[i][j]; |  118                 points[SkPatchUtils::kTopP0_CubicCtrlPts] = vertices[i][j]; | 
|  120                 points[SkPatchUtils::kTopP3_CubicCtrlPts] = vertices[i][j + 1]; |  119                 points[SkPatchUtils::kTopP3_CubicCtrlPts] = vertices[i][j + 1]; | 
|  121                 points[SkPatchUtils::kBottomP0_CubicCtrlPts] = vertices[i + 1][j
     ]; |  120                 points[SkPatchUtils::kBottomP0_CubicCtrlPts] = vertices[i + 1][j
     ]; | 
|  122                 points[SkPatchUtils::kBottomP3_CubicCtrlPts] = vertices[i + 1][j
      + 1]; |  121                 points[SkPatchUtils::kBottomP3_CubicCtrlPts] = vertices[i + 1][j
      + 1]; | 
|  123                  |  122  | 
|  124                 points[SkPatchUtils::kTopP1_CubicCtrlPts] = hrzCtrl[i][j * 2]; |  123                 points[SkPatchUtils::kTopP1_CubicCtrlPts] = hrzCtrl[i][j * 2]; | 
|  125                 points[SkPatchUtils::kTopP2_CubicCtrlPts] = hrzCtrl[i][j * 2 + 1
     ]; |  124                 points[SkPatchUtils::kTopP2_CubicCtrlPts] = hrzCtrl[i][j * 2 + 1
     ]; | 
|  126                 points[SkPatchUtils::kBottomP1_CubicCtrlPts] = hrzCtrl[i + 1][j 
     * 2]; |  125                 points[SkPatchUtils::kBottomP1_CubicCtrlPts] = hrzCtrl[i + 1][j 
     * 2]; | 
|  127                 points[SkPatchUtils::kBottomP2_CubicCtrlPts] = hrzCtrl[i + 1][j 
     * 2 + 1]; |  126                 points[SkPatchUtils::kBottomP2_CubicCtrlPts] = hrzCtrl[i + 1][j 
     * 2 + 1]; | 
|  128                  |  127  | 
|  129                 points[SkPatchUtils::kLeftP1_CubicCtrlPts] = vrtCtrl[i * 2][j]; |  128                 points[SkPatchUtils::kLeftP1_CubicCtrlPts] = vrtCtrl[i * 2][j]; | 
|  130                 points[SkPatchUtils::kLeftP2_CubicCtrlPts] = vrtCtrl[i * 2 + 1][
     j]; |  129                 points[SkPatchUtils::kLeftP2_CubicCtrlPts] = vrtCtrl[i * 2 + 1][
     j]; | 
|  131                 points[SkPatchUtils::kRightP1_CubicCtrlPts] = vrtCtrl[i * 2][j +
      1]; |  130                 points[SkPatchUtils::kRightP1_CubicCtrlPts] = vrtCtrl[i * 2][j +
      1]; | 
|  132                 points[SkPatchUtils::kRightP2_CubicCtrlPts] = vrtCtrl[i * 2 + 1]
     [j + 1]; |  131                 points[SkPatchUtils::kRightP2_CubicCtrlPts] = vrtCtrl[i * 2 + 1]
     [j + 1]; | 
|  133                  |  132  | 
|  134                 SkColor colors[4]; |  133                 SkColor colors[4]; | 
|  135                 colors[0] = cornerColors[i][j]; |  134                 colors[0] = cornerColors[i][j]; | 
|  136                 colors[1] = cornerColors[i][j + 1]; |  135                 colors[1] = cornerColors[i][j + 1]; | 
|  137                 colors[3] = cornerColors[i + 1][j]; |  136                 colors[3] = cornerColors[i + 1][j]; | 
|  138                 colors[2] = cornerColors[i + 1][j + 1]; |  137                 colors[2] = cornerColors[i + 1][j + 1]; | 
|  139                  |  138  | 
|  140                 grid.setPatch(j, i, points, colors, nullptr); |  139                 grid.setPatch(j, i, points, colors, nullptr); | 
|  141             } |  140             } | 
|  142         } |  141         } | 
|  143          |  142  | 
|  144         grid.draw(canvas, paint); |  143         grid.draw(canvas, paint); | 
|  145         SkISize dims = grid.getDimensions(); |  144         SkISize dims = grid.getDimensions(); | 
|  146         for (int y = 0; y < dims.height(); y++) { |  145         for (int y = 0; y < dims.height(); y++) { | 
|  147             for (int x = 0; x < dims.width(); x++) { |  146             for (int x = 0; x < dims.width(); x++) { | 
|  148                 SkPoint cubics[12]; |  147                 SkPoint cubics[12]; | 
|  149                 grid.getPatch(x, y, cubics, nullptr, nullptr); |  148                 grid.getPatch(x, y, cubics, nullptr, nullptr); | 
|  150                 draw_control_points(canvas, cubics); |  149                 draw_control_points(canvas, cubics); | 
|  151             } |  150             } | 
|  152         } |  151         } | 
|  153     } |  152     } | 
|  154  |  153  | 
|  155 private: |  154 private: | 
|  156     typedef GM INHERITED; |  155     typedef GM INHERITED; | 
|  157 }; |  156 }; | 
|  158  |  157  | 
|  159 DEF_GM(return new SkPatchGridGM;) |  158 DEF_GM(return new SkPatchGridGM;) | 
|  160 } |  159 } | 
| OLD | NEW |