Draw Alpha8 + color filter correctly in software

This makes the behavior match our gpu backend.

BUG=android:31019366

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

Change-Id: I941623d0bdf54f61aafb1383de46bbedceb7578d
Reviewed-on: https://skia-review.googlesource.com/3979
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Matt Sarett <msarett@google.com>
This commit is contained in:
Matt Sarett 2016-10-28 13:25:40 -04:00 committed by Skia Commit-Bot
parent cd5e7d75e9
commit a9fd106d0c
3 changed files with 51 additions and 1 deletions

48
gm/colorfilteralpha8.cpp Normal file
View File

@ -0,0 +1,48 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "SkBitmap.h"
#include "SkColorFilter.h"
class ColorFilterAlpha8 : public skiagm::GM {
public:
ColorFilterAlpha8() {}
protected:
SkString onShortName() override {
return SkString("colorfilteralpha8");
}
SkISize onISize() override {
return SkISize::Make(400, 400);
}
void onDraw(SkCanvas* canvas) override {
canvas->clear(SK_ColorRED);
SkBitmap bitmap;
SkImageInfo info = SkImageInfo::MakeA8(200, 200);
bitmap.allocPixels(info);
bitmap.eraseColor(0x88FFFFFF);
SkPaint paint;
float opaqueGrayMatrix[20] = {
0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 255.0f
};
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(opaqueGrayMatrix));
canvas->drawBitmap(bitmap, 100.0f, 100.0f, &paint);
}
private:
typedef skiagm::GM INHERITED;
};
DEF_GM( return new ColorFilterAlpha8; )

View File

@ -59,6 +59,7 @@ gm_sources = [
"$_gm/color4f.cpp",
"$_gm/colorcube.cpp",
"$_gm/coloremoji.cpp",
"$_gm/colorfilteralpha8.cpp",
"$_gm/colorfilterimagefilter.cpp",
"$_gm/colorfilters.cpp",
"$_gm/colormatrix.cpp",

View File

@ -1342,7 +1342,8 @@ void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix,
SkDraw draw(*this);
draw.fMatrix = &matrix;
if (bitmap.colorType() == kAlpha_8_SkColorType) {
if (bitmap.colorType() == kAlpha_8_SkColorType && !paint->getColorFilter() &&
!paint->getShader()) {
draw.drawBitmapAsMask(bitmap, *paint);
} else {
SkAutoBitmapShaderInstall install(bitmap, *paint);