| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 case kText_ShapeType: { | 87 case kText_ShapeType: { |
| 88 const char* text = "Hello!"; | 88 const char* text = "Hello!"; |
| 89 paint->setTextSize(30); | 89 paint->setTextSize(30); |
| 90 canvas->drawText(text, strlen(text), 0, 0, *paint); | 90 canvas->drawText(text, strlen(text), 0, 0, *paint); |
| 91 } | 91 } |
| 92 default: | 92 default: |
| 93 break; | 93 break; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 static SkColor GetColor(SkRandom* random, int i) { | 97 static SkColor GetColor(SkRandom* random, int i, int nextColor) { |
| 98 static SkColor colors[] = { SK_ColorRED, |
| 99 0xFFFF7F00, // Orange |
| 100 SK_ColorYELLOW, |
| 101 SK_ColorGREEN, |
| 102 SK_ColorBLUE, |
| 103 0xFF4B0082, // indigo |
| 104 0xFF7F00FF }; // violet |
| 98 SkColor color; | 105 SkColor color; |
| 106 int index = nextColor % SK_ARRAY_COUNT(colors); |
| 99 switch (i) { | 107 switch (i) { |
| 100 case 0: | 108 case 0: |
| 101 color = SK_ColorTRANSPARENT; | 109 color = SK_ColorTRANSPARENT; |
| 102 break; | 110 break; |
| 103 case 1: | 111 case 1: |
| 104 color = SkColorSetARGB(0xff, | 112 color = SkColorSetARGB(0xff, |
| 105 random->nextULessThan(256), | 113 SkColorGetR(colors[index]), |
| 106 random->nextULessThan(256), | 114 SkColorGetG(colors[index]), |
| 107 random->nextULessThan(256)); | 115 SkColorGetB(colors[index])); |
| 108 break; | 116 break; |
| 109 default: | 117 default: |
| 110 uint8_t alpha = random->nextULessThan(256); | 118 uint8_t alpha = 0x80; |
| 111 color = SkColorSetARGB(alpha, | 119 color = SkColorSetARGB(alpha, |
| 112 random->nextRangeU(0, alpha), | 120 SkColorGetR(colors[index]), |
| 113 random->nextRangeU(0, alpha), | 121 SkColorGetG(colors[index]), |
| 114 random->nextRangeU(0, alpha)); | 122 SkColorGetB(colors[index])); |
| 115 break; | 123 break; |
| 116 } | 124 } |
| 117 return color; | 125 return color; |
| 118 } | 126 } |
| 119 | 127 |
| 120 static void SetStyle(SkPaint* p, int style, int width) { | 128 static void SetStyle(SkPaint* p, int style, int width) { |
| 121 switch (style) { | 129 switch (style) { |
| 122 case 0: | 130 case 0: |
| 123 p->setStyle(SkPaint::kStroke_Style); | 131 p->setStyle(SkPaint::kStroke_Style); |
| 124 p->setStrokeWidth((SkScalar)width); | 132 p->setStrokeWidth((SkScalar)width); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 136 void onDraw(SkCanvas* canvas) override { | 144 void onDraw(SkCanvas* canvas) override { |
| 137 SkRandom random; | 145 SkRandom random; |
| 138 SkScalar y = 100; | 146 SkScalar y = 100; |
| 139 for (int i = 0; i < kNumShapeTypes; i++) { | 147 for (int i = 0; i < kNumShapeTypes; i++) { |
| 140 ShapeType shapeType = static_cast<ShapeType>(i); | 148 ShapeType shapeType = static_cast<ShapeType>(i); |
| 141 SkScalar x = 25; | 149 SkScalar x = 25; |
| 142 for (int style = 0; style < 3; style++) { | 150 for (int style = 0; style < 3; style++) { |
| 143 for (int width = 0; width <= 1; width++) { | 151 for (int width = 0; width <= 1; width++) { |
| 144 for (int alpha = 0; alpha <= 2; alpha++) { | 152 for (int alpha = 0; alpha <= 2; alpha++) { |
| 145 for (int r = 0; r <= 5; r++) { | 153 for (int r = 0; r <= 5; r++) { |
| 146 SkColor color = GetColor(&random, alpha); | 154 SkColor color = GetColor(&random, alpha, style + wid
th + alpha + r); |
| 147 | 155 |
| 148 SkPaint p; | 156 SkPaint p; |
| 149 p.setAntiAlias(true); | 157 p.setAntiAlias(true); |
| 150 p.setColor(color); | 158 p.setColor(color); |
| 151 p.setXfermodeMode(r % 3 == 0 ? SkXfermode::kHardLigh
t_Mode : | 159 // In order to get some batching on the GPU backend
we do 2 src over for |
| 160 // each xfer mode which requires a dst read |
| 161 p.setXfermodeMode(r % 3 == 0 ? SkXfermode::kLighten_
Mode : |
| 152 SkXfermode::kSrcOver_
Mode); | 162 SkXfermode::kSrcOver_
Mode); |
| 153 SetStyle(&p, style, width); | 163 SetStyle(&p, style, width); |
| 154 canvas->save(); | 164 canvas->save(); |
| 155 canvas->translate(x, y); | 165 canvas->translate(x, y); |
| 156 canvas->rotate((SkScalar)(r < 3 ? 10 : 0)); | 166 canvas->rotate((SkScalar)(r < 3 ? 10 : 0)); |
| 157 this->drawShape(canvas, &p, shapeType); | 167 this->drawShape(canvas, &p, shapeType); |
| 158 canvas->restore(); | 168 canvas->restore(); |
| 159 x += 8; | 169 x += 8; |
| 160 } | 170 } |
| 161 } | 171 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 176 static const int kHeight = 400; | 186 static const int kHeight = 400; |
| 177 typedef GM INHERITED; | 187 typedef GM INHERITED; |
| 178 }; | 188 }; |
| 179 | 189 |
| 180 ////////////////////////////////////////////////////////////////////////////// | 190 ////////////////////////////////////////////////////////////////////////////// |
| 181 | 191 |
| 182 static GM* MyFactory(void*) { return new DstReadShuffle; } | 192 static GM* MyFactory(void*) { return new DstReadShuffle; } |
| 183 static GMRegistry reg(MyFactory); | 193 static GMRegistry reg(MyFactory); |
| 184 | 194 |
| 185 } | 195 } |
| OLD | NEW |