Chromium Code Reviews| OLD | NEW |
|---|---|
| 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::createRenderSurface(sk_sp<GrRenderTarget> rt, in t colorBits) { | 24 sk_sp<SkSurface> WindowContext::createRenderSurface( |
| 25 sk_sp<GrRenderTarget> rt, int colorBits, bool offscreen, bool sRGB) { | |
| 25 auto flags = (fSurfaceProps.flags() & ~SkSurfaceProps::kGammaCorrect_Flag) | | 26 auto flags = (fSurfaceProps.flags() & ~SkSurfaceProps::kGammaCorrect_Flag) | |
| 26 (GrPixelConfigIsSRGB(fPixelConfig) ? SkSurfaceProps::kGammaCorr ect_Flag : 0); | 27 (GrPixelConfigIsSRGB(fPixelConfig) ? SkSurfaceProps::kGammaCorr ect_Flag : 0); |
|
Brian Osman
2016/06/15 13:41:59
Need to also set this flag if sRGB is true:
((GrP
liyuqian
2016/06/15 14:09:15
Done.
| |
| 27 SkSurfaceProps props(flags, fSurfaceProps.pixelGeometry()); | 28 SkSurfaceProps props(flags, fSurfaceProps.pixelGeometry()); |
| 28 | 29 |
| 29 if (!this->isGpuContext() || colorBits > 24 || | 30 if (!this->isGpuContext() || colorBits > 24 || offscreen || |
| 30 kRGBA_F16_SkColorType == fDisplayParams.fColorType) { | 31 kRGBA_F16_SkColorType == fDisplayParams.fColorType) { |
| 31 // If we're rendering to F16, we need an off-screen surface - the curren t render | 32 // If we're rendering to F16, we need an off-screen surface - the curren t render |
| 32 // target is most likely the wrong format. | 33 // target is most likely the wrong format. |
| 33 // | 34 // |
| 34 // If we're rendering raster data or using a deep (10-bit or higher) sur face, we probably | 35 // If we're rendering raster data or using a deep (10-bit or higher) sur face, we probably |
| 35 // need an off-screen surface. 10-bit, in particular, has strange gamma behavior. | 36 // need an off-screen surface. 10-bit, in particular, has strange gamma behavior. |
| 36 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, | 37 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, |
| 37 fDisplayParams.fColorType, | 38 fDisplayParams.fColorType, |
| 38 kUnknown_SkAlphaType, | 39 // kUnknown_SkAlphaType won't pass |
|
msarett
2016/06/15 13:48:10
Sorry I don't understand what you're saying here?
liyuqian
2016/06/15 14:09:15
I was referring to the previous implementation bef
msarett
2016/06/15 14:20:40
Depends on whether what you are drawing is opaque
| |
| 39 fDisplayParams.fProfileType); | 40 // CheckAlphaTypeAndGetFlags |
| 40 return SkSurface::MakeRenderTarget(fContext, SkBudgeted::kNo, info, | 41 kOpaque_SkAlphaType, |
| 41 fDisplayParams.fMSAASampleCount, &pro ps); | 42 sRGB ? kSRGB_SkColorProfileType |
|
msarett
2016/06/15 13:48:10
Please use a SkColorSpace object here instead of t
liyuqian
2016/06/15 14:09:15
The difficulty here is that DisplayParams maintain
msarett
2016/06/15 14:20:40
SGTM.
I still think it's possible to use SkColorS
liyuqian
2016/06/15 16:43:12
Done. I've adopted your approach.
| |
| 43 : fDisplayParams.fProfileType) ; | |
| 44 if (this->isGpuContext()) { | |
| 45 return SkSurface::MakeRenderTarget(fContext, SkBudgeted::kNo, info, | |
| 46 fDisplayParams.fMSAASampleCount, &props); | |
| 47 } else { | |
| 48 return SkSurface::MakeRaster(info, &props); | |
| 49 } | |
| 42 } else { | 50 } else { |
| 43 return SkSurface::MakeRenderTargetDirect(rt.get(), &props); | 51 return SkSurface::MakeRenderTargetDirect(rt.get(), &props); |
| 44 } | 52 } |
| 45 } | 53 } |
| 46 | 54 |
| 47 void WindowContext::presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<G rRenderTarget> rt, | 55 void WindowContext::presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<G rRenderTarget> rt, |
| 48 int colorBits) { | 56 int colorBits) { |
| 49 if (!this->isGpuContext() || colorBits > 24 || | 57 if (!this->isGpuContext() || colorBits > 24 || |
| 50 kRGBA_F16_SkColorType == fDisplayParams.fColorType) { | 58 kRGBA_F16_SkColorType == fDisplayParams.fColorType) { |
| 51 // We made/have an off-screen surface. Get the contents as an SkImage: | 59 // We made/have an off-screen surface. Get the contents as an SkImage: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 65 | 73 |
| 66 // With ten-bit output, we need to manually apply the gamma of the outpu t device | 74 // With ten-bit output, we need to manually apply the gamma of the outpu t device |
| 67 // (unless we're in non-gamma correct mode, in which case our data is al ready | 75 // (unless we're in non-gamma correct mode, in which case our data is al ready |
| 68 // fake-sRGB, like we're expected to put in the 10-bit buffer): | 76 // fake-sRGB, like we're expected to put in the 10-bit buffer): |
| 69 bool doGamma = (colorBits == 30) && SkImageInfoIsGammaCorrect(info); | 77 bool doGamma = (colorBits == 30) && SkImageInfoIsGammaCorrect(info); |
| 70 fContext->applyGamma(rt.get(), texture, doGamma ? 1.0f / 2.2f : 1.0f); | 78 fContext->applyGamma(rt.get(), texture, doGamma ? 1.0f / 2.2f : 1.0f); |
| 71 } | 79 } |
| 72 } | 80 } |
| 73 | 81 |
| 74 } //namespace sk_app | 82 } //namespace sk_app |
| OLD | NEW |