Flutter Engine
The Flutter Engine
Typedefs | Functions
ImageProviderTest.cpp File Reference
#include "tests/Test.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkImageGenerator.h"
#include "include/core/SkPicture.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkSpan.h"
#include "include/gpu/graphite/Context.h"
#include "include/gpu/graphite/Image.h"
#include "include/gpu/graphite/Recording.h"
#include "include/gpu/graphite/Surface.h"
#include "include/private/base/SkTo.h"
#include "src/core/SkMipmapBuilder.h"
#include "src/gpu/graphite/Caps.h"
#include "src/gpu/graphite/RecorderPriv.h"
#include "src/gpu/graphite/Surface_Graphite.h"
#include "tests/TestUtils.h"
#include "tools/GpuToolUtils.h"
#include "tools/ToolUtils.h"

Go to the source code of this file.

Typedefs

using Mipmapped = skgpu::Mipmapped
 

Functions

 DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS (ImageProviderTest_Graphite_Default, reporter, context, CtsEnforcement::kNextRelease)
 
 DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS (ImageProviderTest_Graphite_Testing, reporter, context, CtsEnforcement::kNextRelease)
 
 DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS (Make_TextureImage_Subset_Test, reporter, context, CtsEnforcement::kNextRelease)
 
 DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS (MakeColorSpace_Test, reporter, context, CtsEnforcement::kNextRelease)
 

Typedef Documentation

◆ Mipmapped

Definition at line 30 of file ImageProviderTest.cpp.

Function Documentation

◆ DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS() [1/4]

DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS ( ImageProviderTest_Graphite_Default  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 275 of file ImageProviderTest.cpp.

276 {
277 TestCase testcases[] = {
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 } },
284 };
285
286 std::unique_ptr<Recorder> recorder = context->makeRecorder();
287
288 run_test(reporter, context, recorder.get(), testcases);
289}
static void run_test(GrDirectContext *dContext, skiatest::Reporter *reporter, BulkRectTest test)
reporter
Definition: FontMgrTest.cpp:39

◆ DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS() [2/4]

DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS ( ImageProviderTest_Graphite_Testing  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 317 of file ImageProviderTest.cpp.

318 {
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 } },
326 };
327
328 RecorderOptions options = ToolUtils::CreateTestingRecorderOptions();
329 std::unique_ptr<skgpu::graphite::Recorder> recorder = context->makeRecorder(options);
330
331 run_test(reporter, context, recorder.get(), testcases);
332}
const char * options

◆ DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS() [3/4]

DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS ( Make_TextureImage_Subset_Test  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 336 of file ImageProviderTest.cpp.

337 {
338 static const struct {
339 std::string name;
340 FactoryT fFactory;
341 } testcases[] = {
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 },
348 };
349
350 const SkIRect kFakeSubset = SkIRect::MakeWH(kImageSize.width(), kImageSize.height());
351 const SkIRect kTrueSubset = kFakeSubset.makeInset(4, 4);
352
353 std::unique_ptr<Recorder> recorderUP = context->makeRecorder();
354 auto recorder = recorderUP.get();
355
356 for (const auto& test : testcases) {
357 sk_sp<SkImage> orig = test.fFactory(recorder);
359 for (bool mipmapped : {false, true}) {
361 SkStringPrintf("mipmaps: %d", (int)mipmapped));
362 sk_sp<SkImage> i = SkImages::TextureFromImage(recorder, orig, {mipmapped});
363
364 // makeTextureImage has an optimization which allows Mipmaps on an Image if it
365 // would take extra work to remove them.
366 bool mipmapOptAllowed = orig->hasMipmaps() && !mipmapped;
367
368 REPORTER_ASSERT(reporter, i->isTextureBacked());
370 reporter,
371 (i->hasMipmaps() == mipmapped) || (i->hasMipmaps() && mipmapOptAllowed));
372
373 // SkImage::makeSubset should "leave an image where it is", that is, return a
374 // texture backed image iff the original image was texture backed. Otherwise,
375 // it will return a raster image.
376 i = orig->makeSubset(recorder, kTrueSubset, {mipmapped});
377 REPORTER_ASSERT(reporter, orig->isTextureBacked() == i->isTextureBacked(),
378 "orig texture status %d != subset texture status %d",
379 orig->isTextureBacked(), i->isTextureBacked());
380 if (i->isTextureBacked()) {
381 REPORTER_ASSERT(reporter, i->dimensions() == kTrueSubset.size());
382 REPORTER_ASSERT(reporter, i->hasMipmaps() == mipmapped);
383 }
384
385 i = orig->makeSubset(recorder, kFakeSubset, {mipmapped});
386 REPORTER_ASSERT(reporter, orig->isTextureBacked() == i->isTextureBacked(),
387 "orig texture status %d != subset texture status %d",
388 orig->isTextureBacked(), i->isTextureBacked());
389 if (i->isTextureBacked()) {
390 REPORTER_ASSERT(reporter, i->dimensions() == kFakeSubset.size());
392 reporter,
393 i->hasMipmaps() == mipmapped || (i->hasMipmaps() && mipmapOptAllowed));
394 }
395
396 // SubsetTextureFrom should always return a texture-backed image
397 i = SkImages::SubsetTextureFrom(recorder, orig.get(), kTrueSubset, {mipmapped});
398 REPORTER_ASSERT(reporter, i->isTextureBacked());
399 REPORTER_ASSERT(reporter, i->dimensions() == kTrueSubset.size());
400 REPORTER_ASSERT(reporter, i->hasMipmaps() == mipmapped);
401
402 if (!orig->isTextureBacked()) {
403 i = SkImages::TextureFromImage(nullptr, orig, {mipmapped});
405
406 // Make sure makeSubset w/o a recorder works as expected
407 i = orig->makeSubset(nullptr, kTrueSubset, {mipmapped});
408 REPORTER_ASSERT(reporter, !i->isTextureBacked());
409 REPORTER_ASSERT(reporter, i->dimensions() == kTrueSubset.size());
410 REPORTER_ASSERT(reporter, i->hasMipmaps() == mipmapped);
411
412 i = orig->makeSubset(nullptr, kFakeSubset, {mipmapped});
413 REPORTER_ASSERT(reporter, !i->isTextureBacked());
414 REPORTER_ASSERT(reporter, i->dimensions() == kFakeSubset.size());
415 REPORTER_ASSERT(reporter, i->hasMipmaps() == mipmapped);
416 }
417 }
418 }
419}
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
virtual bool isTextureBacked() const =0
bool hasMipmaps() const
Definition: SkImage.cpp:292
virtual sk_sp< SkImage > makeSubset(GrDirectContext *direct, const SkIRect &subset) const =0
T * get() const
Definition: SkRefCnt.h:303
static const int kImageSize
Definition: flippity.cpp:44
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)
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
Definition: SkRect.h:32
constexpr SkISize size() const
Definition: SkRect.h:172
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
SkIRect makeInset(int32_t dx, int32_t dy) const
Definition: SkRect.h:332

◆ DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS() [4/4]

DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS ( MakeColorSpace_Test  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 446 of file ImageProviderTest.cpp.

447 {
448 static const struct {
449 std::string name;
450 FactoryT fFactory;
451 bool fTextureBacked;
452 } testcases[] = {
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 },
459 };
460
462
463 std::unique_ptr<Recorder> recorder = context->makeRecorder();
464
465 const Caps* caps = recorder->priv().caps();
466
467 for (const auto& testcase : testcases) {
468 skiatest::ReporterContext subtest(reporter, testcase.name);
469 sk_sp<SkImage> orig = testcase.fFactory(recorder.get());
470
473 SkASSERT(!orig->colorSpace() || orig->colorSpace() == SkColorSpace::MakeSRGB().get());
474
475 for (bool mipmapped : {false, true}) {
477 SkStringPrintf("mipmaps: %d", (int)mipmapped));
478 sk_sp<SkImage> i = orig->makeColorSpace(recorder.get(), spin, {mipmapped});
479
480 REPORTER_ASSERT(reporter, i != nullptr);
481 REPORTER_ASSERT(reporter, i->isTextureBacked() == testcase.fTextureBacked);
482 REPORTER_ASSERT(reporter, i->colorSpace() == spin.get());
483 if (testcase.fTextureBacked) {
484 REPORTER_ASSERT(reporter, i->hasMipmaps() == mipmapped);
485 } else {
486 REPORTER_ASSERT(reporter, !i->hasMipmaps());
487 }
488
489 SkColorType altCT = pick_colortype(caps, mipmapped);
490 i = orig->makeColorTypeAndColorSpace(recorder.get(), altCT, spin, {mipmapped});
491
492 REPORTER_ASSERT(reporter, i != nullptr);
493 REPORTER_ASSERT(reporter, i->isTextureBacked() == testcase.fTextureBacked);
494 REPORTER_ASSERT(reporter, i->colorType() == altCT);
495 REPORTER_ASSERT(reporter, i->colorSpace() == spin.get());
496 if (testcase.fTextureBacked) {
497 REPORTER_ASSERT(reporter, i->hasMipmaps() == mipmapped);
498 } else {
499 REPORTER_ASSERT(reporter, !i->hasMipmaps());
500 }
501 }
502 }
503}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkColorType
Definition: SkColorType.h:19
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
static sk_sp< SkColorSpace > MakeSRGB()
sk_sp< SkColorSpace > makeColorSpin() const
virtual sk_sp< SkImage > makeColorSpace(GrDirectContext *direct, sk_sp< SkColorSpace > target) const =0
SkColorSpace * colorSpace() const
Definition: SkImage.cpp:156
SkColorType colorType() const
Definition: SkImage.cpp:152
virtual sk_sp< SkImage > makeColorTypeAndColorSpace(GrDirectContext *direct, SkColorType targetColorType, sk_sp< SkColorSpace > targetCS) const =0
static sk_sp< SkColorFilter > spin(sk_sp< SkColorFilter > cf)