| 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 #include "gm.h" | 7 #include "gm.h" |
| 8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
| 10 #include "SkShader.h" | 10 #include "SkShader.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 textP.setAntiAlias(true); | 114 textP.setAntiAlias(true); |
| 115 textP.setTypeface(fColorType); | 115 textP.setTypeface(fColorType); |
| 116 textP.setTextSize(SkIntToScalar(70)); | 116 textP.setTextSize(SkIntToScalar(70)); |
| 117 | 117 |
| 118 const int W = 5; | 118 const int W = 5; |
| 119 | 119 |
| 120 SkScalar x0 = 0; | 120 SkScalar x0 = 0; |
| 121 SkScalar y0 = 0; | 121 SkScalar y0 = 0; |
| 122 SkScalar x = x0, y = y0; | 122 SkScalar x = x0, y = y0; |
| 123 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { | 123 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { |
| 124 SkXfermode* mode = SkXfermode::Create(gModes[i].fMode); | |
| 125 SkAutoUnref aur(mode); | |
| 126 SkRect r; | 124 SkRect r; |
| 127 r.set(x, y, x+w, y+h); | 125 r.set(x, y, x+w, y+h); |
| 128 | 126 |
| 129 SkPaint p; | 127 SkPaint p; |
| 130 p.setStyle(SkPaint::kFill_Style); | 128 p.setStyle(SkPaint::kFill_Style); |
| 131 p.setShader(s); | 129 p.setShader(s); |
| 132 canvas->drawRect(r, p); | 130 canvas->drawRect(r, p); |
| 133 | 131 |
| 134 r.inset(-SK_ScalarHalf, -SK_ScalarHalf); | 132 r.inset(-SK_ScalarHalf, -SK_ScalarHalf); |
| 135 p.setStyle(SkPaint::kStroke_Style); | 133 p.setStyle(SkPaint::kStroke_Style); |
| 136 p.setShader(nullptr); | 134 p.setShader(nullptr); |
| 137 canvas->drawRect(r, p); | 135 canvas->drawRect(r, p); |
| 138 | 136 |
| 139 textP.setXfermode(mode); | 137 textP.setXfermode(SkXfermode::Make(gModes[i].fMode)); |
| 140 canvas->drawText("H", 1, x+ w/10.f, y + 7.f*h/8.f, textP); | 138 canvas->drawText("H", 1, x+ w/10.f, y + 7.f*h/8.f, textP); |
| 141 #if 1 | 139 #if 1 |
| 142 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel), | 140 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel), |
| 143 x + w/2, y - labelP.getTextSize()/2, labelP); | 141 x + w/2, y - labelP.getTextSize()/2, labelP); |
| 144 #endif | 142 #endif |
| 145 x += w + SkIntToScalar(10); | 143 x += w + SkIntToScalar(10); |
| 146 if ((i % W) == W - 1) { | 144 if ((i % W) == W - 1) { |
| 147 x = x0; | 145 x = x0; |
| 148 y += h + SkIntToScalar(30); | 146 y += h + SkIntToScalar(30); |
| 149 } | 147 } |
| 150 } | 148 } |
| 151 } | 149 } |
| 152 | 150 |
| 153 private: | 151 private: |
| 154 SkBitmap fBG; | 152 SkBitmap fBG; |
| 155 SkTypeface* fColorType; | 153 SkTypeface* fColorType; |
| 156 | 154 |
| 157 typedef GM INHERITED; | 155 typedef GM INHERITED; |
| 158 }; | 156 }; |
| 159 | 157 |
| 160 ////////////////////////////////////////////////////////////////////////////// | 158 ////////////////////////////////////////////////////////////////////////////// |
| 161 | 159 |
| 162 static GM* MyFactory(void*) { return new ColorTypeXfermodeGM; } | 160 static GM* MyFactory(void*) { return new ColorTypeXfermodeGM; } |
| 163 static GMRegistry reg(MyFactory); | 161 static GMRegistry reg(MyFactory); |
| 164 | 162 |
| 165 } | 163 } |
| OLD | NEW |