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 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 #include "SkSurface.h" | 10 #include "SkSurface.h" |
11 #include "SkSurfaceProps.h" | 11 #include "SkSurfaceProps.h" |
12 | 12 |
13 #define W 200 | 13 #define W 200 |
14 #define H 100 | 14 #define H 100 |
15 | 15 |
16 static sk_sp<SkShader> make_shader() { | 16 static sk_sp<SkShader> make_shader() { |
17 int a = 0x99; | 17 int a = 0x99; |
18 int b = 0xBB; | 18 int b = 0xBB; |
19 SkPoint pts[] = { { 0, 0 }, { W, H } }; | 19 SkPoint pts[] = { { 0, 0 }, { W, H } }; |
20 SkColor colors[] = { SkColorSetRGB(a, a, a), SkColorSetRGB(b, b, b) }; | 20 SkColor colors[] = { SkColorSetRGB(a, a, a), SkColorSetRGB(b, b, b) }; |
21 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam
p_TileMode); | 21 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam
p_TileMode); |
22 } | 22 } |
23 | 23 |
24 static sk_sp<SkSurface> make_surface(GrContext* ctx, const SkImageInfo& info, Sk
PixelGeometry geo, | 24 static sk_sp<SkSurface> make_surface(GrContext* ctx, const SkImageInfo& info, Sk
PixelGeometry geo, |
25 int disallowAA, int disallowDither, bool al
lowSRGBInputs) { | 25 int disallowAA, int disallowDither, bool ga
mmaCorrect) { |
26 uint32_t flags = 0; | 26 uint32_t flags = 0; |
27 if (disallowAA) { | 27 if (disallowAA) { |
28 flags |= SkSurfaceProps::kDisallowAntiAlias_Flag; | 28 flags |= SkSurfaceProps::kDisallowAntiAlias_Flag; |
29 } | 29 } |
30 if (disallowDither) { | 30 if (disallowDither) { |
31 flags |= SkSurfaceProps::kDisallowDither_Flag; | 31 flags |= SkSurfaceProps::kDisallowDither_Flag; |
32 } | 32 } |
33 if (allowSRGBInputs) { | 33 if (gammaCorrect) { |
34 flags |= SkSurfaceProps::kAllowSRGBInputs_Flag; | 34 flags |= SkSurfaceProps::kGammaCorrect_Flag; |
35 } | 35 } |
36 | 36 |
37 SkSurfaceProps props(flags, geo); | 37 SkSurfaceProps props(flags, geo); |
38 if (ctx) { | 38 if (ctx) { |
39 return SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props
); | 39 return SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props
); |
40 } else { | 40 } else { |
41 return SkSurface::MakeRaster(info, &props); | 41 return SkSurface::MakeRaster(info, &props); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
(...skipping 28 matching lines...) Expand all Loading... |
73 return SkISize::Make(W * 4, H * 5); | 73 return SkISize::Make(W * 4, H * 5); |
74 } | 74 } |
75 | 75 |
76 void onDraw(SkCanvas* canvas) override { | 76 void onDraw(SkCanvas* canvas) override { |
77 GrContext* ctx = canvas->getGrContext(); | 77 GrContext* ctx = canvas->getGrContext(); |
78 | 78 |
79 // must be opaque to have a hope of testing LCD text | 79 // must be opaque to have a hope of testing LCD text |
80 const SkImageInfo info = SkImageInfo::MakeN32(W, H, kOpaque_SkAlphaType, | 80 const SkImageInfo info = SkImageInfo::MakeN32(W, H, kOpaque_SkAlphaType, |
81 canvas->imageInfo().profil
eType()); | 81 canvas->imageInfo().profil
eType()); |
82 SkSurfaceProps canvasProps(SkSurfaceProps::kLegacyFontHost_InitType); | 82 SkSurfaceProps canvasProps(SkSurfaceProps::kLegacyFontHost_InitType); |
83 bool allowSRGBInputs = canvas->getProps(&canvasProps) && canvasProps.all
owSRGBInputs(); | 83 bool gammaCorrrect = canvas->getProps(&canvasProps) && canvasProps.isGam
maCorrect(); |
84 | 84 |
85 const struct { | 85 const struct { |
86 SkPixelGeometry fGeo; | 86 SkPixelGeometry fGeo; |
87 const char* fLabel; | 87 const char* fLabel; |
88 } rec[] = { | 88 } rec[] = { |
89 { kUnknown_SkPixelGeometry, "Unknown" }, | 89 { kUnknown_SkPixelGeometry, "Unknown" }, |
90 { kRGB_H_SkPixelGeometry, "RGB_H" }, | 90 { kRGB_H_SkPixelGeometry, "RGB_H" }, |
91 { kBGR_H_SkPixelGeometry, "BGR_H" }, | 91 { kBGR_H_SkPixelGeometry, "BGR_H" }, |
92 { kRGB_V_SkPixelGeometry, "RGB_V" }, | 92 { kRGB_V_SkPixelGeometry, "RGB_V" }, |
93 { kBGR_V_SkPixelGeometry, "BGR_V" }, | 93 { kBGR_V_SkPixelGeometry, "BGR_V" }, |
94 }; | 94 }; |
95 | 95 |
96 SkScalar x = 0; | 96 SkScalar x = 0; |
97 for (int disallowAA = 0; disallowAA <= 1; ++disallowAA) { | 97 for (int disallowAA = 0; disallowAA <= 1; ++disallowAA) { |
98 for (int disallowDither = 0; disallowDither <= 1; ++disallowDither)
{ | 98 for (int disallowDither = 0; disallowDither <= 1; ++disallowDither)
{ |
99 SkScalar y = 0; | 99 SkScalar y = 0; |
100 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { | 100 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { |
101 auto surface(make_surface(ctx, info, rec[i].fGeo, disallowAA
, disallowDither, | 101 auto surface(make_surface(ctx, info, rec[i].fGeo, disallowAA
, disallowDither, |
102 allowSRGBInputs)); | 102 gammaCorrrect)); |
103 test_draw(surface->getCanvas(), rec[i].fLabel); | 103 test_draw(surface->getCanvas(), rec[i].fLabel); |
104 surface->draw(canvas, x, y, nullptr); | 104 surface->draw(canvas, x, y, nullptr); |
105 y += H; | 105 y += H; |
106 } | 106 } |
107 x += W; | 107 x += W; |
108 } | 108 } |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 private: | 112 private: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 SkASSERT(equal(surf->props(), surf2->props())); | 156 SkASSERT(equal(surf->props(), surf2->props())); |
157 | 157 |
158 sk_sp<SkImage> image2(surf2->makeImageSnapshot()); | 158 sk_sp<SkImage> image2(surf2->makeImageSnapshot()); |
159 canvas->drawImage(image2.get(), 10 + SkIntToScalar(image->width()) + 10,
10, nullptr); | 159 canvas->drawImage(image2.get(), 10 + SkIntToScalar(image->width()) + 10,
10, nullptr); |
160 } | 160 } |
161 | 161 |
162 private: | 162 private: |
163 typedef GM INHERITED; | 163 typedef GM INHERITED; |
164 }; | 164 }; |
165 DEF_GM( return new NewSurfaceGM ) | 165 DEF_GM( return new NewSurfaceGM ) |
OLD | NEW |