On gpu, use max(r,g,b) for coverage alpha in LCD and update lcd blend gm.

BUG=skia:

Review URL: https://codereview.chromium.org/1339213004
This commit is contained in:
egdaniel 2015-09-15 13:13:50 -07:00 committed by Commit bot
parent fb1e2fc8aa
commit 27b6335c71
4 changed files with 45 additions and 14 deletions

View File

@ -13,6 +13,7 @@
#include "gm.h"
#include "SkCanvas.h"
#include "SkGradientShader.h"
#include "SkSurface.h"
namespace skiagm {
@ -43,21 +44,44 @@ public:
protected:
SkString onShortName() override {
SkString name("lcdblendmodes");
name.append(sk_tool_utils::major_platform_os_name());
return name;
return SkString("lcdblendmodes");
}
void onOnceBeforeDraw() override {
fCheckerboard.reset(sk_tool_utils::create_checkerboard_shader(SK_ColorBLACK,
SK_ColorWHITE,
4));
}
SkISize onISize() override { return SkISize::Make(kWidth, kHeight); }
void onDraw(SkCanvas* canvas) override {
this->drawColumn(canvas, SK_ColorBLACK, SK_ColorWHITE, false);
canvas->translate(SkIntToScalar(kColWidth), 0);
this->drawColumn(canvas, SK_ColorWHITE, SK_ColorBLACK, false);
canvas->translate(SkIntToScalar(kColWidth), 0);
this->drawColumn(canvas, SK_ColorGREEN, SK_ColorMAGENTA, false);
canvas->translate(SkIntToScalar(kColWidth), 0);
this->drawColumn(canvas, SK_ColorCYAN, SK_ColorMAGENTA, true);
SkPaint p;
p.setAntiAlias(false);
p.setStyle(SkPaint::kFill_Style);
p.setShader(fCheckerboard);
SkRect r = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight));
canvas->drawRect(r, p);
SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
if (nullptr == surface) {
surface.reset(SkSurface::NewRaster(info));
}
SkCanvas* surfCanvas = surface->getCanvas();
this->drawColumn(surfCanvas, SK_ColorBLACK, SK_ColorWHITE, false);
surfCanvas->translate(SkIntToScalar(kColWidth), 0);
this->drawColumn(surfCanvas, SK_ColorWHITE, SK_ColorBLACK, false);
surfCanvas->translate(SkIntToScalar(kColWidth), 0);
this->drawColumn(surfCanvas, SK_ColorGREEN, SK_ColorMAGENTA, false);
surfCanvas->translate(SkIntToScalar(kColWidth), 0);
this->drawColumn(surfCanvas, SK_ColorCYAN, SK_ColorMAGENTA, true);
SkPaint surfPaint;
SkAutoTUnref<SkXfermode> xfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
surfPaint.setXfermode(xfermode);
surface->draw(canvas, 0, 0, &surfPaint);
}
void drawColumn(SkCanvas* canvas, SkColor backgroundColor, SkColor textColor, bool useGrad) {
@ -124,6 +148,7 @@ protected:
private:
SkScalar fTextHeight;
SkAutoTUnref<SkShader> fCheckerboard;
typedef skiagm::GM INHERITED;
};

View File

@ -79,11 +79,9 @@ void GrTextContext::drawPosText(GrDrawContext* dc, GrRenderTarget* rt,
}
bool GrTextContext::ShouldDisableLCD(const SkPaint& paint) {
if (paint.getShader() ||
!SkXfermode::AsMode(paint.getXfermode(), nullptr) ||
if (!SkXfermode::AsMode(paint.getXfermode(), nullptr) ||
paint.getMaskFilter() ||
paint.getRasterizer() ||
paint.getColorFilter() ||
paint.getPathEffect() ||
paint.isFakeBoldText() ||
paint.getStyle() != SkPaint::kFill_Style)

View File

@ -69,6 +69,12 @@ public:
fsBuilder->codeAppendf("%s = ", args.fOutputCoverage);
fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLType);
fsBuilder->codeAppend(";");
if (cte.maskFormat() == kA565_GrMaskFormat) {
// set alpha to be max of rgb coverage
fsBuilder->codeAppendf("%s.a = max(max(%s.r, %s.g), %s.b);",
args.fOutputCoverage, args.fOutputCoverage,
args.fOutputCoverage, args.fOutputCoverage);
}
}
}

View File

@ -633,8 +633,10 @@ public:
fsBuilder->codeAppend(
"vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), distance), 1.0);");
// set alpha to be max of rgb coverage
fsBuilder->codeAppend("val.a = max(max(val.r, val.g), val.b);");
fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage);
fsBuilder->codeAppendf("%s = val;", args.fOutputCoverage);
}
void setData(const GrGLProgramDataManager& pdman,