skia2/tools/viewer/sk_app/WindowContext.cpp
Greg Daniel 1f05f44e8f Various fixes in VulkanWindowContext
BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4066

Change-Id: Ib42dbe70e868c83bdf06e370388e0cc7639a0992
Reviewed-on: https://skia-review.googlesource.com/4066
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2016-10-28 21:14:17 +00:00

64 lines
2.2 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrContext.h"
#include "SkSurface.h"
#include "WindowContext.h"
#include "gl/GrGLDefines.h"
#include "gl/GrGLUtil.h"
#include "GrRenderTarget.h"
#include "GrContext.h"
#include "SkCanvas.h"
#include "SkImage_Base.h"
namespace sk_app {
sk_sp<SkSurface> WindowContext::createOffscreenSurface(bool forceSRGB) {
return createSurface(nullptr, 0, true, forceSRGB);
}
sk_sp<SkSurface> WindowContext::createRenderSurface(const GrBackendRenderTargetDesc& desc,
int colorBits) {
return createSurface(&desc, colorBits, false, false);
}
sk_sp<SkSurface> WindowContext::createSurface(
const GrBackendRenderTargetDesc* rtDesc, int colorBits, bool offscreen, bool forceSRGB) {
if (!this->isGpuContext() || colorBits > 24 || offscreen ||
kRGBA_F16_SkColorType == fDisplayParams.fColorType) {
// If we're rendering to F16, we need an off-screen surface - the current render
// target is most likely the wrong format.
//
// If we're rendering raster data or using a deep (10-bit or higher) surface, we probably
// need an off-screen surface. 10-bit, in particular, has strange gamma behavior.
SkImageInfo info = SkImageInfo::Make(
fWidth, fHeight,
fDisplayParams.fColorType,
kPremul_SkAlphaType,
forceSRGB ? SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named)
: fDisplayParams.fColorSpace
);
if (this->isGpuContext()) {
return SkSurface::MakeRenderTarget(fContext, SkBudgeted::kNo, info,
fDisplayParams.fMSAASampleCount, &fSurfaceProps);
} else {
return SkSurface::MakeRaster(info, &fSurfaceProps);
}
} else {
sk_sp<SkColorSpace> colorSpace = GrPixelConfigIsSRGB(rtDesc->fConfig)
? SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named) : nullptr;
return SkSurface::MakeFromBackendRenderTarget(fContext, *rtDesc, colorSpace,
&fSurfaceProps);
}
}
} //namespace sk_app