blob: ea558cf444538b50ae4ac8076e0829ae8e7371fb [file] [log] [blame]
* Copyright 2019 Google Inc.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
#include "include/core/SkCanvas.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkPaint.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkColorMatrix.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "tests/Test.h"
#include "tests/TestUtils.h"
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(MatrixColorFilter_TransparentBlack, reporter, info) {
auto* context = info.grContext();
// Make a transparent black image rather than use a paint color to avoid an optimization that
// applies the color filter on the CPU to paint colors.
auto imgSurf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
SkImageInfo::MakeN32(5, 5, kPremul_SkAlphaType));
auto shader = imgSurf->makeImageSnapshot()->makeShader(SkTileMode::kClamp, SkTileMode::kClamp);
SkColorMatrix m;
m.setScale(0, 0, 0, 127.f);
SkPaint p;
auto surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
SkImageInfo::MakeN32(5, 5, kPremul_SkAlphaType));
// Seed the output surface with red so we would notice if we failed to draw at all.
SkAutoPixmapStorage pixels;
surf->readPixels(pixels, 0, 0);
auto error = std::function<ComparePixmapsErrorReporter>(
[reporter](int x, int y, const float diffs[4]) {
ERRORF(reporter, "Expected transparent black, instead got (%f, %f, %f, %f)",
diffs[0], diffs[1], diffs[2], diffs[3]);
static constexpr float kTol[] = {0, 0, 0, 0};
CheckSolidPixels({0, 0, 0, 0}, pixels, kTol, error);