Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
PinnedImageTest.cpp File Reference
#include "include/android/SkImageAndroid.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/gpu/mock/GrMockTypes.h"
#include "src/gpu/ganesh/GrFragmentProcessor.h"
#include "src/gpu/ganesh/SkGr.h"
#include "src/gpu/ganesh/image/GrImageUtils.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/gpu/ContextType.h"
#include "tools/gpu/FenceSync.h"
#include <string>

Go to the source code of this file.

Functions

static bool surface_is_expected_color (SkSurface *surf, const SkImageInfo &ii, SkColor color)
 
static void basic_test (skiatest::Reporter *reporter, GrRecordingContext *rContext)
 
static void cleanup_test (skiatest::Reporter *reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (PinnedImageTest, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (PinnedImageTest_AsGaneshView, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (PinnedImageTest_AsFragmentProcessor, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 

Function Documentation

◆ basic_test()

static void basic_test ( skiatest::Reporter reporter,
GrRecordingContext rContext 
)
static

Definition at line 59 of file PinnedImageTest.cpp.

59 {
60 skiatest::ReporterContext subtest(reporter, "basic_test");
61 const SkImageInfo ii = SkImageInfo::Make(64, 64, kN32_SkColorType, kPremul_SkAlphaType);
62
63 SkBitmap bm;
64 bm.allocPixels(ii);
65
66 SkCanvas bmCanvas(bm);
67 bmCanvas.clear(SK_ColorRED);
68
69 // We start off with the raster image being all red.
71 REPORTER_ASSERT(reporter, img, "PinnableImageFromBitmap returned null");
72
74 SkCanvas* canvas = gpuSurface->getCanvas();
75
76 // w/o pinning - the gpu draw always reflects the current state of the underlying bitmap
77 {
78 canvas->drawImage(img, 0, 0);
80
81 bmCanvas.clear(SK_ColorGREEN);
82
83 canvas->drawImage(img, 0, 0);
85 }
86
87 // w/ pinning - the gpu draw is stuck at the pinned state
88 {
89 bool ok = skgpu::ganesh::PinAsTexture(rContext, img.get()); // pin at blue
90 REPORTER_ASSERT(reporter, ok, "PinAsTexture did not succeed");
91
92 canvas->drawImage(img, 0, 0);
94
95 bmCanvas.clear(SK_ColorBLUE);
96
97 canvas->drawImage(img, 0, 0);
99
100 skgpu::ganesh::UnpinTexture(rContext, img.get());
101 }
102
103 // once unpinned local changes will be picked up
104 {
105 canvas->drawImage(img, 0, 0);
107 }
108}
reporter
static bool surface_is_expected_color(SkSurface *surf, const SkImageInfo &ii, SkColor color)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
static bool ok(int result)
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
T * get() const
Definition SkRefCnt.h:303
SK_API sk_sp< SkImage > PinnableRasterFromBitmap(const SkBitmap &)
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)
bool PinAsTexture(GrRecordingContext *, SkImage *)
void UnpinTexture(GrRecordingContext *, SkImage *)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ cleanup_test()

static void cleanup_test ( skiatest::Reporter reporter)
static

Definition at line 111 of file PinnedImageTest.cpp.

111 {
112 skiatest::ReporterContext subtest(reporter, "cleanup_test");
113 const SkImageInfo ii = SkImageInfo::Make(64, 64, kN32_SkColorType, kPremul_SkAlphaType);
114
115 SkBitmap bm;
116 bm.allocPixels(ii);
117
118 SkCanvas bmCanvas(bm);
119 bmCanvas.clear(SK_ColorRED);
120
123
124 for (int i = 0; i < skgpu::kContextTypeCount; ++i) {
125 auto ctxType = static_cast<skgpu::ContextType>(i);
126
127 {
128 sk_sp<SkImage> img;
129 GrDirectContext* dContext = nullptr;
130
131 {
132 GrContextFactory testFactory;
133 ContextInfo info = testFactory.getContextInfo(ctxType);
134 dContext = info.directContext();
135 if (!dContext) {
136 continue;
137 }
138
140 if (!skgpu::ganesh::PinAsTexture(dContext, img.get())) {
141 continue;
142 }
143 // Pinning on a second context should be blocked.
145 img.get()));
146 }
147
148 // The context used to pin the image is gone at this point!
149 // "context" isn't technically used in this call but it can't be null!
150 // We don't really want to support this use case but it currently happens.
151 skgpu::ganesh::UnpinTexture(dContext, img.get());
152 }
153 }
154}
const char * options
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static sk_sp< GrDirectContext > MakeMock(const GrMockOptions *, const GrContextOptions &)
ContextInfo getContextInfo(ContextType type, ContextOverrides=ContextOverrides::kNone)
static const int kContextTypeCount
Definition ContextType.h:42

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [1/3]

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

Definition at line 156 of file PinnedImageTest.cpp.

159 {
160
161 basic_test(reporter, ctxInfo.directContext());
163}
static void basic_test(skiatest::Reporter *reporter, GrRecordingContext *rContext)
static void cleanup_test(skiatest::Reporter *reporter)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [2/3]

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

Definition at line 196 of file PinnedImageTest.cpp.

199 {
200 GrRecordingContext* rContext = ctxInfo.directContext();
201 const SkImageInfo ii = SkImageInfo::Make(64, 64, kN32_SkColorType, kPremul_SkAlphaType);
202
203 SkBitmap bm;
204 bm.allocPixels(ii);
205
206 SkCanvas bmCanvas(bm);
207 bmCanvas.clear(SK_ColorMAGENTA); // arbitrary color
208
210 REPORTER_ASSERT(reporter, img, "PinnableImageFromBitmap returned null");
211
213
215 rContext, img.get(), SkSamplingOptions({1/3, 1/3}), tm,
216 SkMatrix::I(), nullptr, nullptr);
217 REPORTER_ASSERT(reporter, fp, "AsFragmentProcessor returned falsey processor");
218}
constexpr SkColor SK_ColorMAGENTA
Definition SkColor.h:147
SkTileMode
Definition SkTileMode.h:13
static const SkMatrix & I()
const uint32_t fp
std::unique_ptr< GrFragmentProcessor > AsFragmentProcessor(GrRecordingContext *rContext, const SkImage *img, SkSamplingOptions sampling, const SkTileMode tileModes[2], const SkMatrix &m, const SkRect *subset, const SkRect *domain)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [3/3]

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

Definition at line 165 of file PinnedImageTest.cpp.

168 {
169 GrRecordingContext* rContext = ctxInfo.directContext();
170 const SkImageInfo ii = SkImageInfo::Make(64, 64, kN32_SkColorType, kPremul_SkAlphaType);
171
172 SkBitmap bm;
173 bm.allocPixels(ii);
174
175 SkCanvas bmCanvas(bm);
176 bmCanvas.clear(SK_ColorMAGENTA); // arbitrary color
177
179 REPORTER_ASSERT(reporter, img, "PinnableImageFromBitmap returned null");
180
181 {
182 skiatest::ReporterContext subtest(reporter, "cached path");
183 auto [view, colortype] = skgpu::ganesh::AsView(rContext, img, skgpu::Mipmapped::kNo,
185 REPORTER_ASSERT(reporter, view, "AsView returned falsey view");
186 }
187
188 {
189 skiatest::ReporterContext subtest(reporter, "unncached path");
190 auto [view, colortype] = skgpu::ganesh::AsView(rContext, img, skgpu::Mipmapped::kNo,
192 REPORTER_ASSERT(reporter, view, "AsView returned falsey view");
193 }
194}
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)

◆ surface_is_expected_color()

static bool surface_is_expected_color ( SkSurface surf,
const SkImageInfo ii,
SkColor  color 
)
static

Definition at line 42 of file PinnedImageTest.cpp.

42 {
43 SkBitmap bm;
44 bm.allocPixels(ii);
45
46 surf->readPixels(bm, 0, 0);
47
48 for (int y = 0; y < bm.height(); ++y) {
49 for (int x = 0; x < bm.width(); ++x) {
50 if (bm.getColor(x, y) != color) {
51 return false;
52 }
53 }
54 }
55
56 return true;
57}
SkColor4f color
SkColor getColor(int x, int y) const
Definition SkBitmap.h:874
int width() const
Definition SkBitmap.h:149
int height() const
Definition SkBitmap.h:158
bool readPixels(const SkPixmap &dst, int srcX, int srcY)
double y
double x