Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
MatrixColorFilterTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
27#include "tests/Test.h"
28#include "tests/TestUtils.h"
29
30#include <functional>
31
32struct GrContextOptions;
33
34
35DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(MatrixColorFilter_TransparentBlack,
37 info,
39 auto context = info.directContext();
40 // Make a transparent black image rather than use a paint color to avoid an optimization that
41 // applies the color filter on the CPU to paint colors.
42 auto imgSurf = SkSurfaces::RenderTarget(
44 imgSurf->getCanvas()->drawColor(0x0000000);
45 auto shader = imgSurf->makeImageSnapshot()->makeShader(SkSamplingOptions());
47 m.setScale(0, 0, 0, 127.f);
48 SkPaint p;
49 p.setColorFilter(SkColorFilters::Matrix(m));
50 p.setShader(shader);
51 p.setBlendMode(SkBlendMode::kSrc);
52 auto surf = SkSurfaces::RenderTarget(
54 // Seed the output surface with red so we would notice if we failed to draw at all.
55 surf->getCanvas()->clear(SK_ColorRED);
56 surf->getCanvas()->drawPaint(p);
58 pixels.alloc(surf->imageInfo());
59 surf->readPixels(pixels, 0, 0);
60 auto error = std::function<ComparePixmapsErrorReporter>(
61 [reporter](int x, int y, const float diffs[4]) {
62 ERRORF(reporter, "Expected transparent black, instead got (%f, %f, %f, %f)",
63 diffs[0], diffs[1], diffs[2], diffs[3]);
64 });
65 static constexpr float kTol[] = {0, 0, 0, 0};
66 CheckSolidPixels({0, 0, 0, 0}, pixels, kTol, error);
67}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
reporter
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
bool CheckSolidPixels(const SkColor4f &col, const SkPixmap &pixmap, const float tolRGBA[4], std::function< ComparePixmapsErrorReporter > &error)
#define ERRORF(r,...)
Definition Test.h:293
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
Definition Test.h:434
void alloc(const SkImageInfo &)
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
const uint8_t uint32_t uint32_t GError ** error
double y
double x
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)