Flutter Engine
The Flutter Engine
Functions
ImageIsOpaqueTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPicture.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"
#include <cstdint>
#include <initializer_list>
#include "include/core/SkPictureRecorder.h"

Go to the source code of this file.

Functions

static void check_isopaque (skiatest::Reporter *reporter, const sk_sp< SkSurface > &surface, bool expectedOpaque)
 
 DEF_TEST (ImageIsOpaqueTest, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ImageIsOpaqueTest_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static sk_sp< SkPicturemake_picture ()
 
 DEF_TEST (Image_isAlphaOnly, reporter)
 

Function Documentation

◆ check_isopaque()

static void check_isopaque ( skiatest::Reporter reporter,
const sk_sp< SkSurface > &  surface,
bool  expectedOpaque 
)
static

Definition at line 32 of file ImageIsOpaqueTest.cpp.

33 {
34 sk_sp<SkImage> image(surface->makeImageSnapshot());
35 REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque);
36}
reporter
Definition: FontMgrTest.cpp:39
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
bool isOpaque() const
Definition: SkImage.h:375
VkSurfaceKHR surface
Definition: main.cc:49
sk_sp< const SkImage > image
Definition: SkRecords.h:269

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( ImageIsOpaqueTest_Gpu  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 48 of file ImageIsOpaqueTest.cpp.

51 {
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}
static void check_isopaque(skiatest::Reporter *reporter, const sk_sp< SkSurface > &surface, bool expectedOpaque)
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
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 MakeN32Premul(int width, int height)
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)

◆ DEF_TEST() [1/2]

DEF_TEST ( Image_isAlphaOnly  ,
reporter   
)

Definition at line 74 of file ImageIsOpaqueTest.cpp.

74 {
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}
static sk_sp< SkPicture > make_picture()
uint32_t SkPMColor
Definition: SkColor.h:205
static sk_sp< SkColorSpace > MakeSRGB()
bool isAlphaOnly() const
Definition: SkImage.cpp:239
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_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
static SkImageInfo MakeA8(int width, int height)

◆ DEF_TEST() [2/2]

DEF_TEST ( ImageIsOpaqueTest  ,
reporter   
)

Definition at line 38 of file ImageIsOpaqueTest.cpp.

38 {
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}
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)

◆ make_picture()

static sk_sp< SkPicture > make_picture ( )
static

Definition at line 67 of file ImageIsOpaqueTest.cpp.

67 {
68 SkPictureRecorder recorder;
69 SkCanvas* canvas = recorder.beginRecording({ 0, 0, 10, 10 });
70 canvas->drawColor(SK_ColorRED);
71 return recorder.finishRecordingAsPicture();
72}
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()