Remove GrContext::applyGamma
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2191323002 Review-Url: https://codereview.chromium.org/2191323002
This commit is contained in:
parent
e0d362929d
commit
1e8761809d
@ -294,15 +294,6 @@ public:
|
||||
size_t rowBytes,
|
||||
uint32_t pixelOpsFlags = 0);
|
||||
|
||||
/**
|
||||
* Copies contents of src to dst, while applying a gamma curve. Fails if the two surfaces
|
||||
* are not identically sized.
|
||||
* @param dst the surface to copy to.
|
||||
* @param src the texture to copy from.
|
||||
* @param gamma the gamma value to apply.
|
||||
*/
|
||||
bool applyGamma(GrRenderTarget* dst, GrTexture* src, SkScalar gamma);
|
||||
|
||||
/**
|
||||
* Copies a rectangle of texels from src to dst.
|
||||
* @param dst the surface to copy to.
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "SkCommandLineFlags.h"
|
||||
#include "SkData.h"
|
||||
#include "SkDocument.h"
|
||||
#include "SkGammaColorFilter.h"
|
||||
#include "SkGraphics.h"
|
||||
#include "SkImage_Base.h"
|
||||
#include "SkImageEncoder.h"
|
||||
@ -36,8 +37,6 @@
|
||||
#if SK_SUPPORT_GPU
|
||||
# include "gl/GrGLInterface.h"
|
||||
# include "gl/GrGLUtil.h"
|
||||
# include "GrDrawContext.h"
|
||||
# include "GrRenderTarget.h"
|
||||
# include "GrContext.h"
|
||||
# include "SkGr.h"
|
||||
# if SK_ANGLE
|
||||
@ -314,39 +313,37 @@ public:
|
||||
}
|
||||
|
||||
void publishCanvas(SampleWindow::DeviceType dType,
|
||||
SkCanvas* canvas, SampleWindow* win) override {
|
||||
SkCanvas* renderingCanvas, SampleWindow* win) override {
|
||||
#if SK_SUPPORT_GPU
|
||||
if (fCurContext) {
|
||||
// in case we have queued drawing calls
|
||||
fCurContext->flush();
|
||||
}
|
||||
|
||||
if (!IsGpuDeviceType(dType) ||
|
||||
kRGBA_F16_SkColorType == win->info().colorType() ||
|
||||
fActualColorBits > 24) {
|
||||
// We made/have an off-screen surface. Get the contents as an SkImage:
|
||||
SkBitmap bm;
|
||||
bm.allocPixels(win->info());
|
||||
canvas->readPixels(&bm, 0, 0);
|
||||
renderingCanvas->readPixels(&bm, 0, 0);
|
||||
SkPixmap pm;
|
||||
bm.peekPixels(&pm);
|
||||
sk_sp<SkImage> image(SkImage::MakeTextureFromPixmap(fCurContext, pm,
|
||||
SkBudgeted::kNo));
|
||||
|
||||
SkCanvas* canvas = fGpuSurface->getCanvas();
|
||||
|
||||
// Temporary code until applyGamma is replaced
|
||||
GrDrawContext* dc = canvas->internal_private_accessTopLayerDrawContext();
|
||||
GrRenderTarget* rt = dc->accessRenderTarget();
|
||||
GrTexture* texture = image->getTexture();
|
||||
SkASSERT(texture);
|
||||
SkCanvas* gpuCanvas = fGpuSurface->getCanvas();
|
||||
|
||||
// With ten-bit output, we need to manually apply the gamma of the output device
|
||||
// (unless we're in non-gamma correct mode, in which case our data is already
|
||||
// fake-sRGB, like we're expected to put in the 10-bit buffer):
|
||||
bool doGamma = (fActualColorBits == 30) && SkImageInfoIsGammaCorrect(win->info());
|
||||
fCurContext->applyGamma(rt, texture, doGamma ? 1.0f / 2.2f : 1.0f);
|
||||
|
||||
SkPaint gammaPaint;
|
||||
gammaPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
||||
if (doGamma) {
|
||||
gammaPaint.setColorFilter(SkGammaColorFilter::Make(1.0f / 2.2f));
|
||||
}
|
||||
|
||||
gpuCanvas->drawImage(image, 0, 0, &gammaPaint);
|
||||
}
|
||||
|
||||
fGpuSurface->prepareForExternalIO();
|
||||
#endif
|
||||
|
||||
win->present();
|
||||
|
@ -527,40 +527,6 @@ bool GrContext::readSurfacePixels(GrSurface* src,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GrContext::applyGamma(GrRenderTarget* dst, GrTexture* src, SkScalar gamma){
|
||||
ASSERT_SINGLE_OWNER
|
||||
RETURN_FALSE_IF_ABANDONED
|
||||
ASSERT_OWNED_RESOURCE(dst);
|
||||
ASSERT_OWNED_RESOURCE(src);
|
||||
GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma");
|
||||
|
||||
// Dimensions must match exactly.
|
||||
if (dst->width() != src->width() || dst->height() != src->height()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Supply color space?
|
||||
sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(dst), nullptr));
|
||||
if (!drawContext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GrPaint paint;
|
||||
paint.addColorTextureProcessor(src, nullptr, GrCoordTransform::MakeDivByTextureWHMatrix(src));
|
||||
if (!SkScalarNearlyEqual(gamma, 1.0f)) {
|
||||
paint.addColorFragmentProcessor(GrGammaEffect::Make(gamma));
|
||||
}
|
||||
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
|
||||
paint.setGammaCorrect(true);
|
||||
|
||||
SkRect rect;
|
||||
src->getBoundsRect(&rect);
|
||||
drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect);
|
||||
|
||||
this->flushSurfaceWrites(dst);
|
||||
return true;
|
||||
}
|
||||
|
||||
void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
RETURN_IF_ABANDONED
|
||||
|
@ -10,11 +10,9 @@
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContext.h"
|
||||
#include "GrDrawContext.h"
|
||||
#include "GrTexture.h"
|
||||
#include "GrTextureProvider.h"
|
||||
|
||||
#include "SkCanvas.h"
|
||||
#include "SkGammaColorFilter.h"
|
||||
#include "SkPixmap.h"
|
||||
#include "SkSurface.h"
|
||||
#include "SkUtils.h"
|
||||
@ -113,20 +111,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ApplyGamma, reporter, ctxInfo) {
|
||||
dstCanvas->clear(SK_ColorRED);
|
||||
dstCanvas->flush();
|
||||
|
||||
// Temporary code until applyGamma is replaced
|
||||
GrDrawContext* dc = dstCanvas->internal_private_accessTopLayerDrawContext();
|
||||
GrRenderTarget* rt = dc->accessRenderTarget();
|
||||
GrTexture* texture = src->getTexture();
|
||||
SkASSERT(texture);
|
||||
SkPaint gammaPaint;
|
||||
gammaPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
||||
gammaPaint.setColorFilter(SkGammaColorFilter::Make(gamma));
|
||||
|
||||
bool result = context->applyGamma(rt, texture, gamma);
|
||||
|
||||
// To make the copied src rect correct we would apply any dst clipping
|
||||
// back to the src rect, but we don't use it again so don't bother.
|
||||
if (!result) {
|
||||
ERRORF(reporter, "Unexpected failure from applyGamma.");
|
||||
continue;
|
||||
}
|
||||
dstCanvas->drawImage(src, 0, 0, &gammaPaint);
|
||||
dstCanvas->flush();
|
||||
|
||||
sk_memset32(read.get(), 0, kW * kH);
|
||||
if (!dstCanvas->readPixels(ii, read.get(), kRowBytes, 0, 0)) {
|
||||
|
Loading…
Reference in New Issue
Block a user