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

Side by Side Diff: gm/surface.cpp

Issue 1845283003: Gamma-correctness pushed into Skia, top-down. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 8 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 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) { 25 int disallowAA, int disallowDither, bool al lowSRGBInputs) {
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) {
34 flags |= SkSurfaceProps::kAllowSRGBInputs_Flag;
35 }
33 36
34 SkSurfaceProps props(flags, geo); 37 SkSurfaceProps props(flags, geo);
35 if (ctx) { 38 if (ctx) {
36 return SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props ); 39 return SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props );
37 } else { 40 } else {
38 return SkSurface::MakeRaster(info, &props); 41 return SkSurface::MakeRaster(info, &props);
39 } 42 }
40 } 43 }
41 44
42 static void test_draw(SkCanvas* canvas, const char label[]) { 45 static void test_draw(SkCanvas* canvas, const char label[]) {
(...skipping 24 matching lines...) Expand all
67 } 70 }
68 71
69 SkISize onISize() override { 72 SkISize onISize() override {
70 return SkISize::Make(W * 4, H * 5); 73 return SkISize::Make(W * 4, H * 5);
71 } 74 }
72 75
73 void onDraw(SkCanvas* canvas) override { 76 void onDraw(SkCanvas* canvas) override {
74 GrContext* ctx = canvas->getGrContext(); 77 GrContext* ctx = canvas->getGrContext();
75 78
76 // must be opaque to have a hope of testing LCD text 79 // must be opaque to have a hope of testing LCD text
77 const SkImageInfo info = SkImageInfo::MakeN32(W, H, kOpaque_SkAlphaType) ; 80 const SkImageInfo info = SkImageInfo::MakeN32(W, H, kOpaque_SkAlphaType,
81 canvas->imageInfo().profil eType());
82 SkSurfaceProps canvasProps(SkSurfaceProps::kLegacyFontHost_InitType);
83 bool allowSRGBInputs = canvas->getProps(&canvasProps) && canvasProps.all owSRGBInputs();
78 84
79 const struct { 85 const struct {
80 SkPixelGeometry fGeo; 86 SkPixelGeometry fGeo;
81 const char* fLabel; 87 const char* fLabel;
82 } rec[] = { 88 } rec[] = {
83 { kUnknown_SkPixelGeometry, "Unknown" }, 89 { kUnknown_SkPixelGeometry, "Unknown" },
84 { kRGB_H_SkPixelGeometry, "RGB_H" }, 90 { kRGB_H_SkPixelGeometry, "RGB_H" },
85 { kBGR_H_SkPixelGeometry, "BGR_H" }, 91 { kBGR_H_SkPixelGeometry, "BGR_H" },
86 { kRGB_V_SkPixelGeometry, "RGB_V" }, 92 { kRGB_V_SkPixelGeometry, "RGB_V" },
87 { kBGR_V_SkPixelGeometry, "BGR_V" }, 93 { kBGR_V_SkPixelGeometry, "BGR_V" },
88 }; 94 };
89 95
90 SkScalar x = 0; 96 SkScalar x = 0;
91 for (int disallowAA = 0; disallowAA <= 1; ++disallowAA) { 97 for (int disallowAA = 0; disallowAA <= 1; ++disallowAA) {
92 for (int disallowDither = 0; disallowDither <= 1; ++disallowDither) { 98 for (int disallowDither = 0; disallowDither <= 1; ++disallowDither) {
93 SkScalar y = 0; 99 SkScalar y = 0;
94 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { 100 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
95 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));
96 test_draw(surface->getCanvas(), rec[i].fLabel); 103 test_draw(surface->getCanvas(), rec[i].fLabel);
97 surface->draw(canvas, x, y, nullptr); 104 surface->draw(canvas, x, y, nullptr);
98 y += H; 105 y += H;
99 } 106 }
100 x += W; 107 x += W;
101 } 108 }
102 } 109 }
103 } 110 }
104 111
105 private: 112 private:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 SkASSERT(equal(surf->props(), surf2->props())); 156 SkASSERT(equal(surf->props(), surf2->props()));
150 157
151 sk_sp<SkImage> image2(surf2->makeImageSnapshot()); 158 sk_sp<SkImage> image2(surf2->makeImageSnapshot());
152 canvas->drawImage(image2.get(), 10 + SkIntToScalar(image->width()) + 10, 10, nullptr); 159 canvas->drawImage(image2.get(), 10 + SkIntToScalar(image->width()) + 10, 10, nullptr);
153 } 160 }
154 161
155 private: 162 private:
156 typedef GM INHERITED; 163 typedef GM INHERITED;
157 }; 164 };
158 DEF_GM( return new NewSurfaceGM ) 165 DEF_GM( return new NewSurfaceGM )
OLDNEW
« no previous file with comments | « gm/dftext.cpp ('k') | gm/textblobgeometrychange.cpp » ('j') | src/effects/SkImageSource.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698