Flutter Engine
The Flutter Engine
Functions
ImageWrapTextureMipmapsTest.cpp File Reference
#include "tests/Test.h"
#include "include/core/SkCanvas.h"
#include "include/gpu/graphite/BackendTexture.h"
#include "include/gpu/graphite/Context.h"
#include "include/gpu/graphite/Image.h"
#include "include/gpu/graphite/Recorder.h"
#include "include/gpu/graphite/Surface.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "src/gpu/graphite/Caps.h"
#include "src/gpu/graphite/ContextPriv.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include "tools/graphite/GraphiteTestContext.h"

Go to the source code of this file.

Functions

 DEF_CONDITIONAL_GRAPHITE_TEST_FOR_ALL_CONTEXTS (ImageWrapTextureMipmapsTest, reporter, context, testContext, true, CtsEnforcement::kNextRelease)
 

Function Documentation

◆ DEF_CONDITIONAL_GRAPHITE_TEST_FOR_ALL_CONTEXTS()

DEF_CONDITIONAL_GRAPHITE_TEST_FOR_ALL_CONTEXTS ( ImageWrapTextureMipmapsTest  ,
reporter  ,
context  ,
testContext  ,
true  ,
CtsEnforcement::kNextRelease   
)

Definition at line 25 of file ImageWrapTextureMipmapsTest.cpp.

30 {
31 auto recorder = context->makeRecorder();
32 if (!recorder) {
33 ERRORF(reporter, "Could not make recorder");
34 return;
35 }
36
37 skgpu::Protected isProtected = skgpu::Protected(context->priv().caps()->protectedSupport());
38
40 SkAutoPixmapStorage basePM, topPM;
41 basePM.alloc(info);
42 basePM.erase(SK_ColorGREEN);
43 topPM.alloc(info.makeDimensions({1, 1}));
44 topPM.erase(SK_ColorBLUE);
45
46 SkPixmap levelPMs[]{basePM, topPM};
47 auto mbet = sk_gpu_test::ManagedGraphiteTexture::MakeMipmappedFromPixmaps(recorder.get(),
48 levelPMs,
50 isProtected);
51
52 if (!mbet) {
53 ERRORF(reporter, "Could not make backend texture");
54 return;
55 }
56
57 std::unique_ptr<Recording> recording = recorder->snap();
58
59 auto recordingFinishProc = [](void* context, CallbackResult) {
60 std::unique_ptr<Recording>(static_cast<Recording*>(context));
61 };
62
64 recordingInfo.fFinishedProc = recordingFinishProc;
65 recordingInfo.fRecording = recording.get();
66 recordingInfo.fFinishedContext = recording.release();
67 if (!context->insertRecording(recordingInfo)) {
68 ERRORF(reporter, "Could not insert recording");
69 return;
70 }
71
72 static constexpr struct TestCase {
74 SkColor expectedColor;
75 } kTestCases[]{{SkImages::GenerateMipmapsFromBase::kNo , 0xFFFF0000},
77
78 for (const auto& testCase : kTestCases) {
79 recorder = context->makeRecorder();
80 if (!recorder) {
81 ERRORF(reporter, "Could not make recorder");
82 return;
83 }
84
85 auto image = SkImages::WrapTexture(recorder.get(),
86 mbet->texture(),
87 info.colorType(),
88 info.alphaType(),
89 info.refColorSpace(),
90 Origin::kTopLeft,
91 testCase.genMipmaps,
92 sk_gpu_test::ManagedGraphiteTexture::ImageReleaseProc,
93 mbet->releaseContext());
94 if (!recorder) {
95 ERRORF(reporter, "Could not make image");
96 return;
97 }
98
99 // We determe the contents of the image's top level by doing a downsampling draw to a
100 // surface and then reading the surface's contents.
101 auto surface = SkSurfaces::RenderTarget(recorder.get(), info.makeDimensions({1, 1}));
102 if (!recorder) {
103 ERRORF(reporter, "Could not make surface");
104 return;
105 }
106
107 auto shader = image->makeShader(
111
112 surface->getCanvas()->scale(0.05f, 0.05f);
114 paint.setShader(std::move(shader));
115 surface->getCanvas()->drawPaint(paint);
116
117 recording = recorder->snap();
118 recordingInfo.fRecording = recording.get();
119 recordingInfo.fFinishedContext = recording.release();
120 if (!context->insertRecording(recordingInfo)) {
121 ERRORF(reporter, "Could not insert recording");
122 return;
123 }
124
125 struct ReadContext {
126 bool called = false;
127 bool success = false;
128 uint32_t color;
129 };
130 auto readPixelsCallback = [](SkImage::ReadPixelsContext context,
131 std::unique_ptr<const SkImage::AsyncReadResult> result) {
132 auto& readContext = *static_cast<ReadContext*>(context);
133 readContext.called = true;
134 if (result) {
135 readContext.success = true;
136 readContext.color = *static_cast<const uint32_t*>(result->data(0));
137 }
138 };
139 ReadContext readContext;
140 context->asyncRescaleAndReadPixels(surface.get(),
141 surface->imageInfo(),
142 SkIRect::MakeSize(surface->imageInfo().dimensions()),
145 readPixelsCallback,
146 &readContext);
147 context->submit();
148 while (!readContext.called) {
149 testContext->tick();
150 context->checkAsyncWorkCompletion();
151 }
152
153 if (!readContext.success) {
154 ERRORF(reporter, "Read pixels failed");
155 return;
156 }
157
158 REPORTER_ASSERT(reporter, readContext.color == testCase.expectedColor);
159 }
160}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
reporter
Definition: FontMgrTest.cpp:39
@ 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
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define ERRORF(r,...)
Definition: Test.h:293
void alloc(const SkImageInfo &)
void * ReadPixelsContext
Definition: SkImage.h:578
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
const Paint & paint
Definition: color_source.cc:38
DlColor color
VkSurfaceKHR surface
Definition: main.cc:49
GAsyncResult * result
SK_API sk_sp< SkImage > WrapTexture(skgpu::graphite::Recorder *, const skgpu::graphite::BackendTexture &, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, skgpu::Origin origin, GenerateMipmapsFromBase generateMipmapsFromBase, TextureReleaseProc=nullptr, ReleaseContext=nullptr, std::string_view label={})
GenerateMipmapsFromBase
Definition: Image.h:33
sk_sp< const SkImage > image
Definition: SkRecords.h:269
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)
CallbackResult
Definition: GpuTypes.h:45
Protected
Definition: GpuTypes.h:61
SkSamplingOptions(SkFilterMode::kLinear))
static constexpr SkIRect MakeSize(const SkISize &size)
Definition: SkRect.h:66
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)