Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ImageIsOpaqueTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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
14#include "include/core/SkPicture.h" // IWYU pragma: keep
23#include "tests/Test.h"
24#include "tools/DecodeUtils.h"
25#include "tools/Resources.h"
26
27#include <cstdint>
28#include <initializer_list>
29
30struct GrContextOptions;
31
33 bool expectedOpaque) {
34 sk_sp<SkImage> image(surface->makeImageSnapshot());
35 REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque);
36}
37
38DEF_TEST(ImageIsOpaqueTest, reporter) {
39 SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
40 auto surfaceTransparent(SkSurfaces::Raster(infoTransparent));
41 check_isopaque(reporter, surfaceTransparent, false);
42
44 auto surfaceOpaque(SkSurfaces::Raster(infoOpaque));
45 check_isopaque(reporter, surfaceOpaque, true);
46}
47
50 ctxInfo,
52 auto context = ctxInfo.directContext();
53 SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
54 auto surfaceTransparent(
55 SkSurfaces::RenderTarget(context, skgpu::Budgeted::kNo, infoTransparent));
56 check_isopaque(reporter, surfaceTransparent, false);
57
59 auto surfaceOpaque(SkSurfaces::RenderTarget(context, skgpu::Budgeted::kNo, infoOpaque));
60
61 check_isopaque(reporter, surfaceOpaque, true);
62}
63
64///////////////////////////////////////////////////////////////////////////////////////////////////
66
68 SkPictureRecorder recorder;
69 SkCanvas* canvas = recorder.beginRecording({ 0, 0, 10, 10 });
70 canvas->drawColor(SK_ColorRED);
71 return recorder.finishRecordingAsPicture();
72}
73
74DEF_TEST(Image_isAlphaOnly, reporter) {
75 SkPMColor pmColors = 0;
76 SkPixmap pmap = {
78 &pmColors,
79 sizeof(pmColors)
80 };
81 for (auto& image : {
83 ToolUtils::GetResourceAsImage("images/mandrill_128.png"),
84 ToolUtils::GetResourceAsImage("images/color_wheel.jpg"),
86 {10, 10},
87 nullptr,
88 nullptr,
91 }) {
93 }
94
97 SkImages::RasterFromPixmapCopy({SkImageInfo::MakeA8(1, 1), (uint8_t*)&pmColors, 1})
98 ->isAlphaOnly() == true);
99}
reporter
static sk_sp< SkPicture > make_picture()
static void check_isopaque(skiatest::Reporter *reporter, const sk_sp< SkSurface > &surface, bool expectedOpaque)
@ kOpaque_SkAlphaType
pixel is opaque
Definition SkAlphaType.h:28
uint32_t SkPMColor
Definition SkColor.h:205
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
Definition Test.h:434
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition SkCanvas.h:1182
static sk_sp< SkColorSpace > MakeSRGB()
bool isAlphaOnly() const
Definition SkImage.cpp:239
bool isOpaque() const
Definition SkImage.h:375
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkImage > image
Definition examples.cpp:29
SK_API sk_sp< SkImage > DeferredFromPicture(sk_sp< SkPicture > picture, const SkISize &dimensions, const SkMatrix *matrix, const SkPaint *paint, BitDepth bitDepth, sk_sp< SkColorSpace > colorSpace, SkSurfaceProps props)
SK_API sk_sp< SkImage > RasterFromPixmapCopy(const SkPixmap &pixmap)
@ kU8
uses 8-bit unsigned int per color component
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
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)
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition DecodeUtils.h:25
static SkImageInfo MakeN32Premul(int width, int height)
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)
static SkImageInfo MakeA8(int width, int height)