Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
SpecialImageTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkSurface.h"
#include "include/core/SkSurfaceProps.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "src/core/SkSpecialImage.h"
#include "src/gpu/ganesh/GrColorInfo.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
#include "src/gpu/ganesh/SkGr.h"
#include "src/gpu/ganesh/image/SkSpecialImage_Ganesh.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include <utility>

Go to the source code of this file.

Functions

static SkBitmap create_bm ()
 
static void test_image (const sk_sp< SkSpecialImage > &img, skiatest::Reporter *reporter, GrRecordingContext *rContext, bool isGPUBacked)
 
 DEF_TEST (SpecialImage_Raster, reporter)
 
static void test_specialimage_image (skiatest::Reporter *reporter)
 
 DEF_TEST (SpecialImage_Image_Legacy, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SpecialImage_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 

Variables

static const int kSmallerSize = 10
 
static const int kPad = 3
 
static const int kFullSize = kSmallerSize + 2 * kPad
 

Function Documentation

◆ create_bm()

static SkBitmap create_bm ( )
static

Definition at line 50 of file SpecialImageTest.cpp.

50 {
53
54 SkBitmap bm;
55 bm.allocPixels(ii);
56
57 SkCanvas temp(bm);
58
59 temp.clear(SK_ColorGREEN);
60 SkPaint p;
61 p.setColor(SK_ColorRED);
62 p.setAntiAlias(false);
63
66 p);
67
68 bm.setImmutable();
69 return bm;
70}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
#define SkIntToScalar(x)
Definition SkScalar.h:57
static const int kFullSize
static const int kSmallerSize
static const int kPad
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
void setImmutable()
Definition SkBitmap.cpp:400
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

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

Definition at line 181 of file SpecialImageTest.cpp.

184 {
185 auto context = ctxInfo.directContext();
186 SkBitmap bm = create_bm();
187 auto [view, ct] = GrMakeUncachedBitmapProxyView(context, bm);
188 if (!view) {
189 return;
190 }
191
192 sk_sp<SkSpecialImage> fullSImg =
193 SkSpecialImages::MakeDeferredFromGpu(context,
196 view,
197 {ct, kPremul_SkAlphaType, nullptr},
199
201
202 {
203 sk_sp<SkSpecialImage> subSImg1 =
204 SkSpecialImages::MakeDeferredFromGpu(context,
205 subset,
207 std::move(view),
208 {ct, kPremul_SkAlphaType, nullptr},
210 test_image(subSImg1, reporter, context, true);
211 }
212
213 {
214 sk_sp<SkSpecialImage> subSImg2 = fullSImg->makeSubset(subset);
215 test_image(subSImg2, reporter, context, true);
216 }
217}
reporter
std::tuple< GrSurfaceProxyView, GrColorType > GrMakeUncachedBitmapProxyView(GrRecordingContext *rContext, const SkBitmap &bitmap, skgpu::Mipmapped mipmapped, SkBackingFit fit, skgpu::Budgeted budgeted)
Definition SkGr.cpp:253
@ kNeedNewImageUniqueID_SpecialImage
static SkBitmap create_bm()
static void test_image(const sk_sp< SkSpecialImage > &img, skiatest::Reporter *reporter, GrRecordingContext *rContext, bool isGPUBacked)
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104

◆ DEF_TEST() [1/2]

DEF_TEST ( SpecialImage_Image_Legacy  ,
reporter   
)

Definition at line 177 of file SpecialImageTest.cpp.

177 {
179}
static void test_specialimage_image(skiatest::Reporter *reporter)

◆ DEF_TEST() [2/2]

DEF_TEST ( SpecialImage_Raster  ,
reporter   
)

Definition at line 135 of file SpecialImageTest.cpp.

135 {
136 SkBitmap bm = create_bm();
137
138 sk_sp<SkSpecialImage> fullSImage(SkSpecialImages::MakeFromRaster(
140
142
143 {
144 sk_sp<SkSpecialImage> subSImg1(
145 SkSpecialImages::MakeFromRaster(subset, bm, SkSurfaceProps()));
146 test_image(subSImg1, reporter, nullptr, false);
147 }
148
149 {
150 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset));
151 test_image(subSImg2, reporter, nullptr, false);
152 }
153}

◆ test_image()

static void test_image ( const sk_sp< SkSpecialImage > &  img,
skiatest::Reporter reporter,
GrRecordingContext rContext,
bool  isGPUBacked 
)
static

Definition at line 73 of file SpecialImageTest.cpp.

74 {
75 const SkIRect subset = img->subset();
76 REPORTER_ASSERT(reporter, kPad == subset.left());
77 REPORTER_ASSERT(reporter, kPad == subset.top());
80
81 //--------------
82 // Test that isTextureBacked reports the correct backing type
83 REPORTER_ASSERT(reporter, isGPUBacked == img->isGaneshBacked());
85
86 //--------------
87 // Test view - only succeeds if it's Ganesh backed
88 if (rContext) {
89 GrSurfaceProxyView view = SkSpecialImages::AsView(rContext, img);
90 REPORTER_ASSERT(reporter, SkToBool(view.asTextureProxy()) == isGPUBacked);
91 }
92
93 //--------------
94 // Test AsBitmap - this only works for raster-backed special images
95 if (!img->isGaneshBacked() && !img->isGraphiteBacked()) {
97 REPORTER_ASSERT(reporter, SkSpecialImages::AsBitmap(img.get(), &bitmap));
100 } else {
102 REPORTER_ASSERT(reporter, !SkSpecialImages::AsBitmap(img.get(), &bitmap));
103 }
104
105 //--------------
106 // Test that draw restricts itself to the subset
108 kN32_SkColorType,
110 sk_ref_sp(img->getColorSpace()));
111 sk_sp<SkSurface> surf = isGPUBacked
112 ? SkSurfaces::RenderTarget(rContext, skgpu::Budgeted::kNo, imageInfo)
113 : SkSurfaces::Raster(imageInfo, {});
114
115 SkCanvas* canvas = surf->getCanvas();
116
117 canvas->clear(SK_ColorBLUE);
118 img->draw(canvas, SkIntToScalar(kPad), SkIntToScalar(kPad));
119
120 SkBitmap bm;
122
123 bool result = canvas->readPixels(bm.info(), bm.getPixels(), bm.rowBytes(), 0, 0);
125
126 // Only the center (red) portion should've been drawn into the canvas
130 kSmallerSize+kPad-1));
133}
#define SkASSERT_RELEASE(cond)
Definition SkAssert.h:100
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
GrTextureProxy * asTextureProxy() const
SkColor getColor(int x, int y) const
Definition SkBitmap.h:874
size_t rowBytes() const
Definition SkBitmap.h:238
void * getPixels() const
Definition SkBitmap.h:283
const SkImageInfo & info() const
Definition SkBitmap.h:139
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
void draw(SkCanvas *canvas, SkScalar x, SkScalar y, const SkSamplingOptions &sampling, const SkPaint *paint, bool strict=true) const
virtual bool isGaneshBacked() const
SkColorSpace * getColorSpace() const
const SkIRect & subset() const
virtual bool isGraphiteBacked() const
T * get() const
Definition SkRefCnt.h:303
GAsyncResult * result
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)
constexpr int32_t top() const
Definition SkRect.h:120
constexpr int32_t height() const
Definition SkRect.h:165
constexpr int32_t width() const
Definition SkRect.h:158
constexpr int32_t left() const
Definition SkRect.h:113
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20

◆ test_specialimage_image()

static void test_specialimage_image ( skiatest::Reporter reporter)
static

Definition at line 155 of file SpecialImageTest.cpp.

155 {
156 SkBitmap bm = create_bm();
157
158 sk_sp<SkImage> fullImage(bm.asImage());
159
160 sk_sp<SkSpecialImage> fullSImage(SkSpecialImages::MakeFromRaster(
162
164
165 {
166 sk_sp<SkSpecialImage> subSImg1(
167 SkSpecialImages::MakeFromRaster(subset, fullImage, SkSurfaceProps()));
168 test_image(subSImg1, reporter, nullptr, false);
169 }
170
171 {
172 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset));
173 test_image(subSImg2, reporter, nullptr, false);
174 }
175}
sk_sp< SkImage > asImage() const
Definition SkBitmap.cpp:645

Variable Documentation

◆ kFullSize

const int kFullSize = kSmallerSize + 2 * kPad
static

Definition at line 47 of file SpecialImageTest.cpp.

◆ kPad

const int kPad = 3
static

Definition at line 46 of file SpecialImageTest.cpp.

◆ kSmallerSize

const int kSmallerSize = 10
static

Definition at line 45 of file SpecialImageTest.cpp.