| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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(GrBackendRenderTargetDesc de
sc, int colorBits) { | 28 sk_sp<SkSurface> WindowContext::createRenderSurface(GrBackendRenderTargetDesc de
sc, int colorBits) { |
| 29 return createSurface(&desc, 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 GrBackendRenderTargetDesc* rtDesc, int colorBits, bool offscreen, bool f
orceSRGB) { | 33 GrBackendRenderTargetDesc* rtDesc, int colorBits, bool offscreen, bool f
orceSRGB) { |
| 34 auto flags = (fSurfaceProps.flags() & ~SkSurfaceProps::kGammaCorrect_Flag) | | |
| 35 (GrPixelConfigIsSRGB(fPixelConfig) || forceSRGB ? | |
| 36 SkSurfaceProps::kGammaCorrect_Flag : 0); | |
| 37 SkSurfaceProps props(flags, fSurfaceProps.pixelGeometry()); | |
| 38 | |
| 39 if (!this->isGpuContext() || colorBits > 24 || offscreen || | 34 if (!this->isGpuContext() || colorBits > 24 || offscreen || |
| 40 kRGBA_F16_SkColorType == fDisplayParams.fColorType) { | 35 kRGBA_F16_SkColorType == fDisplayParams.fColorType) { |
| 41 // If we're rendering to F16, we need an off-screen surface - the curren
t render | 36 // If we're rendering to F16, we need an off-screen surface - the curren
t render |
| 42 // target is most likely the wrong format. | 37 // target is most likely the wrong format. |
| 43 // | 38 // |
| 44 // If we're rendering raster data or using a deep (10-bit or higher) sur
face, we probably | 39 // 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. | 40 // need an off-screen surface. 10-bit, in particular, has strange gamma
behavior. |
| 46 SkImageInfo info = SkImageInfo::Make( | 41 SkImageInfo info = SkImageInfo::Make( |
| 47 fWidth, fHeight, | 42 fWidth, fHeight, |
| 48 fDisplayParams.fColorType, | 43 fDisplayParams.fColorType, |
| 49 kPremul_SkAlphaType, | 44 kPremul_SkAlphaType, |
| 50 forceSRGB ? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) | 45 forceSRGB ? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) |
| 51 : fDisplayParams.fColorSpace | 46 : fDisplayParams.fColorSpace |
| 52 ); | 47 ); |
| 53 if (this->isGpuContext()) { | 48 if (this->isGpuContext()) { |
| 54 return SkSurface::MakeRenderTarget(fContext, SkBudgeted::kNo, info, | 49 return SkSurface::MakeRenderTarget(fContext, SkBudgeted::kNo, info, |
| 55 fDisplayParams.fMSAASampleCount,
&props); | 50 fDisplayParams.fMSAASampleCount,
&fSurfaceProps); |
| 56 } else { | 51 } else { |
| 57 return SkSurface::MakeRaster(info, &props); | 52 return SkSurface::MakeRaster(info, &fSurfaceProps); |
| 58 } | 53 } |
| 59 } else { | 54 } else { |
| 60 return SkSurface::MakeFromBackendRenderTarget(fContext, *rtDesc, &props)
; | 55 return SkSurface::MakeFromBackendRenderTarget(fContext, *rtDesc, &fSurfa
ceProps); |
| 61 } | 56 } |
| 62 } | 57 } |
| 63 | 58 |
| 64 void WindowContext::presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<G
rRenderTarget> rt, | 59 void WindowContext::presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<G
rRenderTarget> rt, |
| 65 int colorBits) { | 60 int colorBits) { |
| 66 if (!this->isGpuContext() || colorBits > 24 || | 61 if (!this->isGpuContext() || colorBits > 24 || |
| 67 kRGBA_F16_SkColorType == fDisplayParams.fColorType) { | 62 kRGBA_F16_SkColorType == fDisplayParams.fColorType) { |
| 68 // We made/have an off-screen surface. Get the contents as an SkImage: | 63 // We made/have an off-screen surface. Get the contents as an SkImage: |
| 69 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, | 64 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, |
| 70 fDisplayParams.fColorType, | 65 fDisplayParams.fColorType, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 82 | 77 |
| 83 // With ten-bit output, we need to manually apply the gamma of the outpu
t device | 78 // 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 | 79 // (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): | 80 // fake-sRGB, like we're expected to put in the 10-bit buffer): |
| 86 bool doGamma = (colorBits == 30) && SkImageInfoIsGammaCorrect(info); | 81 bool doGamma = (colorBits == 30) && SkImageInfoIsGammaCorrect(info); |
| 87 fContext->applyGamma(rt.get(), texture, doGamma ? 1.0f / 2.2f : 1.0f); | 82 fContext->applyGamma(rt.get(), texture, doGamma ? 1.0f / 2.2f : 1.0f); |
| 88 } | 83 } |
| 89 } | 84 } |
| 90 | 85 |
| 91 } //namespace sk_app | 86 } //namespace sk_app |
| OLD | NEW |