| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "gm.h" | 8 #include "gm.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 SK_ColorTRANSPARENT, | 53 SK_ColorTRANSPARENT, |
| 54 SK_ColorBLUE, | 54 SK_ColorBLUE, |
| 55 0x80808000 | 55 0x80808000 |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 static const SkColor kBmpAlphas[] = { | 58 static const SkColor kBmpAlphas[] = { |
| 59 0xff, | 59 0xff, |
| 60 0x80, | 60 0x80, |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 SkAutoTUnref<SkSurface> tempSurface(this->possiblyCreateTempSurface(canv
as, kSize, kSize)); | 63 auto tempSurface(this->possiblyCreateTempSurface(canvas, kSize, kSize)); |
| 64 | 64 |
| 65 int test = 0; | 65 int test = 0; |
| 66 int x = 0, y = 0; | 66 int x = 0, y = 0; |
| 67 static const struct { SkPaint::Style fStyle; SkScalar fWidth; } kStrokes
[] = { | 67 static const struct { SkPaint::Style fStyle; SkScalar fWidth; } kStrokes
[] = { |
| 68 {SkPaint::kFill_Style, 0}, | 68 {SkPaint::kFill_Style, 0}, |
| 69 {SkPaint::kStroke_Style, SkIntToScalar(kSize) / 2}, | 69 {SkPaint::kStroke_Style, SkIntToScalar(kSize) / 2}, |
| 70 }; | 70 }; |
| 71 for (size_t s = 0; s < SK_ARRAY_COUNT(kStrokes); ++s) { | 71 for (size_t s = 0; s < SK_ARRAY_COUNT(kStrokes); ++s) { |
| 72 for (size_t m = 0; m <= SkXfermode::kLastMode; ++m) { | 72 for (size_t m = 0; m <= SkXfermode::kLastMode; ++m) { |
| 73 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(m); | 73 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(m); |
| 74 canvas->drawText(SkXfermode::ModeName(mode), | 74 canvas->drawText(SkXfermode::ModeName(mode), |
| 75 strlen(SkXfermode::ModeName(mode)), | 75 strlen(SkXfermode::ModeName(mode)), |
| 76 SkIntToScalar(x), | 76 SkIntToScalar(x), |
| 77 SkIntToScalar(y + kSize + 3) + labelP.getTextSi
ze(), | 77 SkIntToScalar(y + kSize + 3) + labelP.getTextSi
ze(), |
| 78 labelP); | 78 labelP); |
| 79 for (size_t c = 0; c < SK_ARRAY_COUNT(kSolidColors); ++c) { | 79 for (size_t c = 0; c < SK_ARRAY_COUNT(kSolidColors); ++c) { |
| 80 SkPaint modePaint; | 80 SkPaint modePaint; |
| 81 modePaint.setXfermodeMode(mode); | 81 modePaint.setXfermodeMode(mode); |
| 82 modePaint.setColor(kSolidColors[c]); | 82 modePaint.setColor(kSolidColors[c]); |
| 83 modePaint.setStyle(kStrokes[s].fStyle); | 83 modePaint.setStyle(kStrokes[s].fStyle); |
| 84 modePaint.setStrokeWidth(kStrokes[s].fWidth); | 84 modePaint.setStrokeWidth(kStrokes[s].fWidth); |
| 85 | 85 |
| 86 this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSu
rface); | 86 this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSu
rface.get()); |
| 87 | 87 |
| 88 ++test; | 88 ++test; |
| 89 x += kSize + 10; | 89 x += kSize + 10; |
| 90 if (!(test % kTestsPerRow)) { | 90 if (!(test % kTestsPerRow)) { |
| 91 x = 0; | 91 x = 0; |
| 92 y += kSize + 30; | 92 y += kSize + 30; |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 for (size_t a = 0; a < SK_ARRAY_COUNT(kBmpAlphas); ++a) { | 95 for (size_t a = 0; a < SK_ARRAY_COUNT(kBmpAlphas); ++a) { |
| 96 SkPaint modePaint; | 96 SkPaint modePaint; |
| 97 modePaint.setXfermodeMode(mode); | 97 modePaint.setXfermodeMode(mode); |
| 98 modePaint.setAlpha(kBmpAlphas[a]); | 98 modePaint.setAlpha(kBmpAlphas[a]); |
| 99 modePaint.setShader(fBmpShader); | 99 modePaint.setShader(fBmpShader); |
| 100 modePaint.setStyle(kStrokes[s].fStyle); | 100 modePaint.setStyle(kStrokes[s].fStyle); |
| 101 modePaint.setStrokeWidth(kStrokes[s].fWidth); | 101 modePaint.setStrokeWidth(kStrokes[s].fWidth); |
| 102 | 102 |
| 103 this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSu
rface); | 103 this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSu
rface.get()); |
| 104 | 104 |
| 105 ++test; | 105 ++test; |
| 106 x += kSize + 10; | 106 x += kSize + 10; |
| 107 if (!(test % kTestsPerRow)) { | 107 if (!(test % kTestsPerRow)) { |
| 108 x = 0; | 108 x = 0; |
| 109 y += kSize + 30; | 109 y += kSize + 30; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 /** | 117 /** |
| 118 * GrContext has optimizations around full rendertarget draws that can be re
placed with clears. | 118 * GrContext has optimizations around full rendertarget draws that can be re
placed with clears. |
| 119 * We are trying to test those. We could use saveLayer() to create small SkG
puDevices but | 119 * We are trying to test those. We could use saveLayer() to create small SkG
puDevices but |
| 120 * saveLayer() uses the texture cache. This means that the actual render tar
get may be larger | 120 * saveLayer() uses the texture cache. This means that the actual render tar
get may be larger |
| 121 * than the layer. Because the clip will contain the layer's bounds, no draw
s will be full-RT. | 121 * than the layer. Because the clip will contain the layer's bounds, no draw
s will be full-RT. |
| 122 * So when running on a GPU canvas we explicitly create a temporary canvas u
sing a texture with | 122 * So when running on a GPU canvas we explicitly create a temporary canvas u
sing a texture with |
| 123 * dimensions exactly matching the layer size. | 123 * dimensions exactly matching the layer size. |
| 124 */ | 124 */ |
| 125 SkSurface* possiblyCreateTempSurface(SkCanvas* baseCanvas, int w, int h) { | 125 sk_sp<SkSurface> possiblyCreateTempSurface(SkCanvas* baseCanvas, int w, int
h) { |
| 126 #if SK_SUPPORT_GPU | 126 #if SK_SUPPORT_GPU |
| 127 GrContext* context = baseCanvas->getGrContext(); | 127 GrContext* context = baseCanvas->getGrContext(); |
| 128 SkImageInfo baseInfo = baseCanvas->imageInfo(); | 128 SkImageInfo baseInfo = baseCanvas->imageInfo(); |
| 129 SkImageInfo info = SkImageInfo::Make(w, h, baseInfo.colorType(), baseInf
o.alphaType(), | 129 SkImageInfo info = SkImageInfo::Make(w, h, baseInfo.colorType(), baseInf
o.alphaType(), |
| 130 baseInfo.profileType()); | 130 baseInfo.profileType()); |
| 131 return SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0, nul
lptr); | 131 return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nu
llptr); |
| 132 #else | 132 #else |
| 133 return nullptr; | 133 return nullptr; |
| 134 #endif | 134 #endif |
| 135 } | 135 } |
| 136 | 136 |
| 137 void drawMode(SkCanvas* canvas, | 137 void drawMode(SkCanvas* canvas, |
| 138 int x, int y, int w, int h, | 138 int x, int y, int w, int h, |
| 139 const SkPaint& modePaint, SkSurface* surface) { | 139 const SkPaint& modePaint, SkSurface* surface) { |
| 140 canvas->save(); | 140 canvas->save(); |
| 141 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 141 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 sk_sp<SkShader> fBmpShader; | 220 sk_sp<SkShader> fBmpShader; |
| 221 | 221 |
| 222 typedef GM INHERITED; | 222 typedef GM INHERITED; |
| 223 }; | 223 }; |
| 224 | 224 |
| 225 ////////////////////////////////////////////////////////////////////////////// | 225 ////////////////////////////////////////////////////////////////////////////// |
| 226 | 226 |
| 227 DEF_GM(return new Xfermodes3GM;) | 227 DEF_GM(return new Xfermodes3GM;) |
| 228 | 228 |
| 229 } | 229 } |
| OLD | NEW |