34const SkISize kSurfaceSize = { 16, 16 };
52 int count = builder.countLevels();
56 for (
int i = 0; i <
count; ++i) {
58 pm.
erase(mipLevelColors[i]);
61 return builder.attachTo(img);
78 if (mipmapped == Mipmapped::kYes) {
79 img = create_and_attach_mipmaps(std::move(img));
87 return create_raster(Mipmapped::kNo);
92 return create_raster(Mipmapped::kYes);
111 paint.setColor(kBaseImageColor);
131 BitmapBackedGenerator()
141 const Options&)
override {
154 return bm.
readPixels(dstInfo, pixels, rowBytes, 0, 0);
158 std::unique_ptr<SkImageGenerator>
gen(
new BitmapBackedGenerator());
168 const char* testcase,
187 canvas->
clear(kBackgroundColor);
197 if (!
surface->readPixels(pm, 0, 0)) {
203 auto error = std::function<ComparePixmapsErrorReporter>(
204 [&](
int x,
int y,
const float diffs[4]) {
206 "case %s %s: expected (%.1f %.1f %.1f %.1f) got (%.1f, %.1f, %.1f, %.1f)",
208 (mipmapped == Mipmapped::kYes) ?
"w/ mipmaps" :
"w/o mipmaps",
209 expectedColor.fR, expectedColor.fG, expectedColor.fB, expectedColor.fA,
210 expectedColor.fR-diffs[0], expectedColor.fG-diffs[1],
211 expectedColor.fB-diffs[2], expectedColor.fA-diffs[3]);
213 static constexpr float kTol[] = {0, 0, 0, 0};
222 const char* fTestCase;
232 for (
auto t : testcases) {
233 for (
auto mm : { Mipmapped::kNo, Mipmapped::kYes }) {
237 t.fTestCase, t.fExpectedColors[
static_cast<int>(mm)]);
278 {
"0", create_raster_backed_image_no_mipmaps, { kBackgroundColor, kBackgroundColor } },
279 {
"1", create_raster_backed_image_with_mipmaps, { kBackgroundColor, kBackgroundColor } },
280 {
"2", create_gpu_backed_image_no_mipmaps, { kBaseImageColor, kBaseImageColor } },
281 {
"3", create_gpu_backed_image_with_mipmaps, { kBaseImageColor, kFirstMipLevelColor } },
282 {
"4", create_picture_backed_image, { kBackgroundColor, kBackgroundColor } },
283 {
"5", create_bitmap_generator_backed_image, { kBackgroundColor, kBackgroundColor } },
286 std::unique_ptr<Recorder> recorder = context->makeRecorder();
319 static const TestCase testcases[] = {
320 {
"0", create_raster_backed_image_no_mipmaps, { kBaseImageColor, kBaseImageColor } },
321 {
"1", create_raster_backed_image_with_mipmaps, { kBaseImageColor, kFirstMipLevelColor } },
322 {
"2", create_gpu_backed_image_no_mipmaps, { kBaseImageColor, kBaseImageColor } },
323 {
"3", create_gpu_backed_image_with_mipmaps, { kBaseImageColor, kFirstMipLevelColor } },
324 {
"4", create_picture_backed_image, { kBaseImageColor, kBaseImageColor } },
325 {
"5", create_bitmap_generator_backed_image, { kBaseImageColor, kBaseImageColor } },
329 std::unique_ptr<skgpu::graphite::Recorder> recorder = context->makeRecorder(
options);
338 static const struct {
342 {
"raster_no_mips", create_raster_backed_image_no_mipmaps },
343 {
"raster_with_mips", create_raster_backed_image_with_mipmaps },
344 {
"texture_no_mips", create_gpu_backed_image_no_mipmaps },
345 {
"texture_with_mips", create_gpu_backed_image_with_mipmaps },
346 {
"picture_backed", create_picture_backed_image },
347 {
"image_generator", create_bitmap_generator_backed_image },
353 std::unique_ptr<Recorder> recorderUP = context->makeRecorder();
354 auto recorder = recorderUP.get();
356 for (
const auto&
test : testcases) {
359 for (
bool mipmapped : {
false,
true}) {
366 bool mipmapOptAllowed = orig->hasMipmaps() && !mipmapped;
371 (i->hasMipmaps() == mipmapped) || (i->hasMipmaps() && mipmapOptAllowed));
376 i = orig->makeSubset(recorder, kTrueSubset, {mipmapped});
378 "orig texture status %d != subset texture status %d",
379 orig->isTextureBacked(), i->isTextureBacked());
380 if (i->isTextureBacked()) {
385 i = orig->makeSubset(recorder, kFakeSubset, {mipmapped});
387 "orig texture status %d != subset texture status %d",
388 orig->isTextureBacked(), i->isTextureBacked());
389 if (i->isTextureBacked()) {
393 i->hasMipmaps() == mipmapped || (i->hasMipmaps() && mipmapOptAllowed));
402 if (!orig->isTextureBacked()) {
407 i = orig->makeSubset(
nullptr, kTrueSubset, {mipmapped});
412 i = orig->makeSubset(
nullptr, kFakeSubset, {mipmapped});
424 auto mm = mipmapped ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo;
427 if (
info.isValid()) {
433 if (
info.isValid()) {
448 static const struct {
453 {
"raster_no_mips", create_raster_backed_image_no_mipmaps,
false },
454 {
"raster_with_mips", create_raster_backed_image_with_mipmaps,
false },
455 {
"texture_no_mips", create_gpu_backed_image_no_mipmaps,
true },
456 {
"texture_with_mips", create_gpu_backed_image_with_mipmaps,
true },
457 {
"picture_backed", create_picture_backed_image,
false },
458 {
"image_generator", create_bitmap_generator_backed_image,
false },
463 std::unique_ptr<Recorder> recorder = context->makeRecorder();
465 const Caps* caps = recorder->priv().caps();
467 for (
const auto& testcase : testcases) {
475 for (
bool mipmapped : {
false,
true}) {
483 if (testcase.fTextureBacked) {
489 SkColorType altCT = pick_colortype(caps, mipmapped);
490 i = orig->makeColorTypeAndColorSpace(recorder.get(), altCT,
spin, {mipmapped});
496 if (testcase.fTextureBacked) {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
#define SkAssertResult(cond)
#define SkASSERT_RELEASE(cond)
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kUnknown_SkColorType
uninitialized
SK_API SkString static SkString SkStringPrintf()
constexpr int SkToInt(S x)
bool CheckSolidPixels(const SkColor4f &col, const SkPixmap &pixmap, const float tolRGBA[4], std::function< ComparePixmapsErrorReporter > &error)
#define REPORTER_ASSERT(r, cond,...)
#define DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS(name, reporter, graphite_context, ctsEnforcement)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
void eraseColor(SkColor4f) const
void drawIRect(const SkIRect &rect, const SkPaint &paint)
void clear(SkColor color)
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
static sk_sp< SkColorSpace > MakeSRGB()
sk_sp< SkColorSpace > makeColorSpin() const
virtual bool onGetPixels(const SkImageInfo &, void *, size_t, const Options &)
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
bool erase(SkColor color, const SkIRect &subset) const
virtual TextureInfo getDefaultSampledTextureInfo(SkColorType, Mipmapped mipmapped, Protected, Renderable) const =0
const uint8_t uint32_t uint32_t GError ** error
static const int kImageSize
constexpr SkColor4f kMagenta
constexpr SkColor4f kGreen
constexpr SkColor4f kWhite
constexpr SkColor4f kCyan
constexpr SkColor4f kBlue
constexpr SkColor4f kYellow
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 > DeferredFromGenerator(std::unique_ptr< SkImageGenerator > imageGenerator)
SK_API sk_sp< SkImage > TextureFromImage(GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)
SK_API sk_sp< SkImage > SubsetTextureFrom(GrDirectContext *context, const SkImage *img, const SkIRect &subset)
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
@ kU8
uses 8-bit unsigned int per color component
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)
void run_test(skiatest::Reporter *reporter, Context *context, SkISize surfaceSize, SkISize recordingSize, SkISize replayOffset, DrawCallback draw, const std::vector< Expectation > &expectations)
constexpr SkISize size() const
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
SkIRect makeInset(int32_t dx, int32_t dy) const
constexpr int32_t width() const
constexpr int32_t height() const
SkISize dimensions() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static SkRect Make(const SkISize &size)
static constexpr SkRect MakeWH(float w, float h)
static sk_sp< SkColorFilter > spin(sk_sp< SkColorFilter > cf)