OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "Test.h" | 8 #include "Test.h" |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // Create our test texture | 112 // Create our test texture |
113 GrSurfaceDesc desc; | 113 GrSurfaceDesc desc; |
114 desc.fFlags = kNone_GrSurfaceFlags; | 114 desc.fFlags = kNone_GrSurfaceFlags; |
115 desc.fConfig = kSkiaGamma8888_GrPixelConfig; | 115 desc.fConfig = kSkiaGamma8888_GrPixelConfig; |
116 desc.fWidth = texS; | 116 desc.fWidth = texS; |
117 desc.fHeight = texS; | 117 desc.fHeight = texS; |
118 | 118 |
119 GrTextureProvider* texProvider = context->textureProvider(); | 119 GrTextureProvider* texProvider = context->textureProvider(); |
120 SkAutoTUnref<GrTexture> texture(texProvider->createTexture(desc, SkBudgeted:
:kNo, texData, 0)); | 120 SkAutoTUnref<GrTexture> texture(texProvider->createTexture(desc, SkBudgeted:
:kNo, texData, 0)); |
121 | 121 |
122 // Create two surfaces (L32 and S32) | 122 // Create two draw contexts (L32 and S32) |
123 GrSurfaceDesc l32Desc; | |
124 l32Desc.fFlags = kRenderTarget_GrSurfaceFlag; | |
125 l32Desc.fConfig = kSkia8888_GrPixelConfig; | |
126 l32Desc.fWidth = rtS; | |
127 l32Desc.fHeight = rtS; | |
128 | |
129 GrSurfaceDesc s32Desc = l32Desc; | |
130 s32Desc.fConfig = kSkiaGamma8888_GrPixelConfig; | |
131 | |
132 SkAutoTUnref<GrTexture> l32Texture(texProvider->createTexture(l32Desc, SkBud
geted::kNo)); | |
133 SkAutoTUnref<GrTexture> s32Texture(texProvider->createTexture(s32Desc, SkBud
geted::kNo)); | |
134 | |
135 SkSurfaceProps l32Props(SkSurfaceProps::kLegacyFontHost_InitType); | 123 SkSurfaceProps l32Props(SkSurfaceProps::kLegacyFontHost_InitType); |
136 SkSurfaceProps s32Props(SkSurfaceProps::kGammaCorrect_Flag, | 124 SkSurfaceProps s32Props(SkSurfaceProps::kGammaCorrect_Flag, |
137 SkSurfaceProps::kLegacyFontHost_InitType); | 125 SkSurfaceProps::kLegacyFontHost_InitType); |
138 | 126 sk_sp<GrDrawContext> l32DrawContext = context->newDrawContext(SkBackingFit::
kExact, rtS, rtS, |
139 sk_sp<GrDrawContext> l32DrawContext( | 127 kSkia8888_GrPi
xelConfig, 0, |
140 context->drawContext(sk_ref_sp(l32Texture->asRenderTarget()), &l32Props)
); | 128 kDefault_GrSur
faceOrigin, |
141 sk_sp<GrDrawContext> s32DrawContext( | 129 &l32Props); |
142 context->drawContext(sk_ref_sp(s32Texture->asRenderTarget()), &s32Props)
); | 130 sk_sp<GrDrawContext> s32DrawContext = context->newDrawContext(SkBackingFit::
kExact, rtS, rtS, |
| 131 kSkiaGamma8888
_GrPixelConfig, 0, |
| 132 kDefault_GrSur
faceOrigin, |
| 133 &s32Props); |
143 | 134 |
144 SkRect rect = SkRect::MakeWH(SkIntToScalar(rtS), SkIntToScalar(rtS)); | 135 SkRect rect = SkRect::MakeWH(SkIntToScalar(rtS), SkIntToScalar(rtS)); |
145 GrNoClip noClip; | 136 GrNoClip noClip; |
146 GrPaint paint; | 137 GrPaint paint; |
147 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 138 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
148 GrTextureParams mipMapParams(SkShader::kRepeat_TileMode, GrTextureParams::kM
ipMap_FilterMode); | 139 GrTextureParams mipMapParams(SkShader::kRepeat_TileMode, GrTextureParams::kM
ipMap_FilterMode); |
149 paint.addColorTextureProcessor(texture, nullptr, SkMatrix::MakeScale(0.5f),
mipMapParams); | 140 paint.addColorTextureProcessor(texture, nullptr, SkMatrix::MakeScale(0.5f),
mipMapParams); |
150 | 141 |
151 // 1) Draw texture to S32 surface (should generate/use sRGB mips) | 142 // 1) Draw texture to S32 surface (should generate/use sRGB mips) |
152 paint.setGammaCorrect(true); | 143 paint.setGammaCorrect(true); |
153 s32DrawContext->drawRect(noClip, paint, SkMatrix::I(), rect); | 144 s32DrawContext->drawRect(noClip, paint, SkMatrix::I(), rect); |
154 read_and_check_pixels(reporter, s32Texture, expectedSRGB, error, "first rend
er of sRGB"); | 145 read_and_check_pixels(reporter, s32DrawContext->asTexture().get(), expectedS
RGB, error, |
| 146 "first render of sRGB"); |
155 | 147 |
156 // 2) Draw texture to L32 surface (should generate/use linear mips) | 148 // 2) Draw texture to L32 surface (should generate/use linear mips) |
157 paint.setGammaCorrect(false); | 149 paint.setGammaCorrect(false); |
158 l32DrawContext->drawRect(noClip, paint, SkMatrix::I(), rect); | 150 l32DrawContext->drawRect(noClip, paint, SkMatrix::I(), rect); |
159 read_and_check_pixels(reporter, l32Texture, expectedLinear, error, "re-rende
r as linear"); | 151 read_and_check_pixels(reporter, l32DrawContext->asTexture().get(), expectedL
inear, error, |
| 152 "re-render as linear"); |
160 | 153 |
161 // 3) Go back to sRGB | 154 // 3) Go back to sRGB |
162 paint.setGammaCorrect(true); | 155 paint.setGammaCorrect(true); |
163 s32DrawContext->drawRect(noClip, paint, SkMatrix::I(), rect); | 156 s32DrawContext->drawRect(noClip, paint, SkMatrix::I(), rect); |
164 read_and_check_pixels(reporter, s32Texture, expectedSRGB, error, "re-render
as sRGB"); | 157 read_and_check_pixels(reporter, s32DrawContext->asTexture().get(), expectedS
RGB, error, |
| 158 "re-render as sRGB"); |
165 } | 159 } |
166 #endif | 160 #endif |
OLD | NEW |