Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: gm/colortypexfermode.cpp

Issue 1933393002: Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "SkXfermode.h" 11 #include "SkXfermode.h"
12 #include "../src/fonts/SkGScalerContext.h" 12 #include "../src/fonts/SkGScalerContext.h"
13 13
14 namespace skiagm { 14 namespace skiagm {
15 15
16 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; 16 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
17 17
18 class ColorTypeXfermodeGM : public GM { 18 class ColorTypeXfermodeGM : public GM {
19 public: 19 public:
20 const static int W = 64; 20 const static int W = 64;
21 const static int H = 64; 21 const static int H = 64;
22 ColorTypeXfermodeGM() 22 ColorTypeXfermodeGM() {}
23 : fColorType(nullptr) {
24 }
25
26 virtual ~ColorTypeXfermodeGM() {
27 SkSafeUnref(fColorType);
28 }
29 23
30 protected: 24 protected:
31 void onOnceBeforeDraw() override { 25 void onOnceBeforeDraw() override {
32 const SkColor colors[] = { 26 const SkColor colors[] = {
33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, 27 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
34 SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW 28 SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW
35 }; 29 };
36 SkMatrix local; 30 SkMatrix local;
37 local.setRotate(180); 31 local.setRotate(180);
38 SkPaint paint; 32 SkPaint paint;
39 paint.setAntiAlias(true); 33 paint.setAntiAlias(true);
40 paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_AR RAY_COUNT(colors), 34 paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_AR RAY_COUNT(colors),
41 0, &local)); 35 0, &local));
42 36
43 SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", SkTy peface::kBold); 37 auto orig = sk_tool_utils::create_portable_typeface("serif", SkTypeface: :kBold);
f(malita) 2016/05/02 13:46:35 Nit: ditto
bungeman-skia 2016/05/02 20:24:54 Done.
44 if (nullptr == orig) { 38 if (nullptr == orig) {
45 orig = SkTypeface::RefDefault(); 39 orig = SkTypeface::MakeDefault();
46 } 40 }
47 fColorType = new SkGTypeface(orig, paint); 41 fColorType = sk_make_sp<SkGTypeface>(orig, paint);
48 orig->unref();
49 42
50 fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, 43 fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType,
51 kOpaque_SkAlphaType), gData, 4); 44 kOpaque_SkAlphaType), gData, 4);
52 } 45 }
53 46
54 virtual SkString onShortName() override { 47 virtual SkString onShortName() override {
55 return SkString("colortype_xfermodes"); 48 return SkString("colortype_xfermodes");
56 } 49 }
57 50
58 virtual SkISize onISize() override { 51 virtual SkISize onISize() override {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 #endif 135 #endif
143 x += w + SkIntToScalar(10); 136 x += w + SkIntToScalar(10);
144 if ((i % W) == W - 1) { 137 if ((i % W) == W - 1) {
145 x = x0; 138 x = x0;
146 y += h + SkIntToScalar(30); 139 y += h + SkIntToScalar(30);
147 } 140 }
148 } 141 }
149 } 142 }
150 143
151 private: 144 private:
152 SkBitmap fBG; 145 SkBitmap fBG;
153 SkTypeface* fColorType; 146 sk_sp<SkTypeface> fColorType;
154 147
155 typedef GM INHERITED; 148 typedef GM INHERITED;
156 }; 149 };
157 150
158 ////////////////////////////////////////////////////////////////////////////// 151 //////////////////////////////////////////////////////////////////////////////
159 152
160 static GM* MyFactory(void*) { return new ColorTypeXfermodeGM; } 153 static GM* MyFactory(void*) { return new ColorTypeXfermodeGM; }
161 static GMRegistry reg(MyFactory); 154 static GMRegistry reg(MyFactory);
162 155
163 } 156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698