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

Side by Side Diff: tools/viewer/sk_app/WindowContext.cpp

Issue 2165703002: Make sk_app::WindowContext directly create a SkSurface without an intermediate GrRenderTarget (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "SkSurface.h" 10 #include "SkSurface.h"
11 #include "WindowContext.h" 11 #include "WindowContext.h"
12 12
13 #include "gl/GrGLDefines.h" 13 #include "gl/GrGLDefines.h"
14 14
15 #include "gl/GrGLUtil.h" 15 #include "gl/GrGLUtil.h"
16 #include "GrRenderTarget.h" 16 #include "GrRenderTarget.h"
17 #include "GrContext.h" 17 #include "GrContext.h"
18 18
19 #include "SkCanvas.h" 19 #include "SkCanvas.h"
20 #include "SkImage_Base.h" 20 #include "SkImage_Base.h"
21 21
22 namespace sk_app { 22 namespace sk_app {
23 23
24 sk_sp<SkSurface> WindowContext::createOffscreenSurface(bool forceSRGB) { 24 sk_sp<SkSurface> WindowContext::createOffscreenSurface(bool forceSRGB) {
25 return createSurface(nullptr, 0, true, forceSRGB); 25 return createSurface(nullptr, 0, true, forceSRGB);
26 } 26 }
27 27
28 sk_sp<SkSurface> WindowContext::createRenderSurface(sk_sp<GrRenderTarget> rt, in t colorBits) { 28 sk_sp<SkSurface> WindowContext::createRenderSurface(GrBackendRenderTargetDesc de sc, int colorBits) {
29 return createSurface(rt, colorBits, false, false); 29 return createSurface(&desc, colorBits, false, false);
30 } 30 }
31 31
32 sk_sp<SkSurface> WindowContext::createSurface( 32 sk_sp<SkSurface> WindowContext::createSurface(
33 sk_sp<GrRenderTarget> rt, int colorBits, bool offscreen, bool forceSRGB) { 33 GrBackendRenderTargetDesc* rtDesc, int colorBits, bool offscreen, bool f orceSRGB) {
34 auto flags = (fSurfaceProps.flags() & ~SkSurfaceProps::kGammaCorrect_Flag) | 34 auto flags = (fSurfaceProps.flags() & ~SkSurfaceProps::kGammaCorrect_Flag) |
35 (GrPixelConfigIsSRGB(fPixelConfig) || forceSRGB ? 35 (GrPixelConfigIsSRGB(fPixelConfig) || forceSRGB ?
36 SkSurfaceProps::kGammaCorrect_Flag : 0); 36 SkSurfaceProps::kGammaCorrect_Flag : 0);
37 SkSurfaceProps props(flags, fSurfaceProps.pixelGeometry()); 37 SkSurfaceProps props(flags, fSurfaceProps.pixelGeometry());
38 38
39 if (!this->isGpuContext() || colorBits > 24 || offscreen || 39 if (!this->isGpuContext() || colorBits > 24 || offscreen ||
40 kRGBA_F16_SkColorType == fDisplayParams.fColorType) { 40 kRGBA_F16_SkColorType == fDisplayParams.fColorType) {
41 // If we're rendering to F16, we need an off-screen surface - the curren t render 41 // If we're rendering to F16, we need an off-screen surface - the curren t render
42 // target is most likely the wrong format. 42 // target is most likely the wrong format.
43 // 43 //
44 // If we're rendering raster data or using a deep (10-bit or higher) sur face, we probably 44 // If we're rendering raster data or using a deep (10-bit or higher) sur face, we probably
45 // need an off-screen surface. 10-bit, in particular, has strange gamma behavior. 45 // need an off-screen surface. 10-bit, in particular, has strange gamma behavior.
46 SkImageInfo info = SkImageInfo::Make( 46 SkImageInfo info = SkImageInfo::Make(
47 fWidth, fHeight, 47 fWidth, fHeight,
48 fDisplayParams.fColorType, 48 fDisplayParams.fColorType,
49 kPremul_SkAlphaType, 49 kPremul_SkAlphaType,
50 forceSRGB ? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) 50 forceSRGB ? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)
51 : fDisplayParams.fColorSpace 51 : fDisplayParams.fColorSpace
52 ); 52 );
53 if (this->isGpuContext()) { 53 if (this->isGpuContext()) {
54 return SkSurface::MakeRenderTarget(fContext, SkBudgeted::kNo, info, 54 return SkSurface::MakeRenderTarget(fContext, SkBudgeted::kNo, info,
55 fDisplayParams.fMSAASampleCount, &props); 55 fDisplayParams.fMSAASampleCount, &props);
56 } else { 56 } else {
57 return SkSurface::MakeRaster(info, &props); 57 return SkSurface::MakeRaster(info, &props);
58 } 58 }
59 } else { 59 } else {
60 return SkSurface::MakeRenderTargetDirect(rt.get(), &props); 60 return SkSurface::MakeFromBackendRenderTarget(fContext, *rtDesc, &props) ;
61 } 61 }
62 } 62 }
63 63
64 void WindowContext::presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<G rRenderTarget> rt, 64 void WindowContext::presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<G rRenderTarget> rt,
65 int colorBits) { 65 int colorBits) {
66 if (!this->isGpuContext() || colorBits > 24 || 66 if (!this->isGpuContext() || colorBits > 24 ||
67 kRGBA_F16_SkColorType == fDisplayParams.fColorType) { 67 kRGBA_F16_SkColorType == fDisplayParams.fColorType) {
68 // We made/have an off-screen surface. Get the contents as an SkImage: 68 // We made/have an off-screen surface. Get the contents as an SkImage:
69 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, 69 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight,
70 fDisplayParams.fColorType, 70 fDisplayParams.fColorType,
(...skipping 11 matching lines...) Expand all
82 82
83 // With ten-bit output, we need to manually apply the gamma of the outpu t device 83 // With ten-bit output, we need to manually apply the gamma of the outpu t device
84 // (unless we're in non-gamma correct mode, in which case our data is al ready 84 // (unless we're in non-gamma correct mode, in which case our data is al ready
85 // fake-sRGB, like we're expected to put in the 10-bit buffer): 85 // fake-sRGB, like we're expected to put in the 10-bit buffer):
86 bool doGamma = (colorBits == 30) && SkImageInfoIsGammaCorrect(info); 86 bool doGamma = (colorBits == 30) && SkImageInfoIsGammaCorrect(info);
87 fContext->applyGamma(rt.get(), texture, doGamma ? 1.0f / 2.2f : 1.0f); 87 fContext->applyGamma(rt.get(), texture, doGamma ? 1.0f / 2.2f : 1.0f);
88 } 88 }
89 } 89 }
90 90
91 } //namespace sk_app 91 } //namespace sk_app
OLDNEW
« tools/viewer/sk_app/WindowContext.h ('K') | « tools/viewer/sk_app/WindowContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698