Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
ImageTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkData.h"
#include "include/core/SkDataTable.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageGenerator.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkM44.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPicture.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSerialProcs.h"
#include "include/core/SkSize.h"
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/core/SkYUVAInfo.h"
#include "include/core/SkYUVAPixmaps.h"
#include "include/encode/SkPngEncoder.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrTypes.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/private/SkColorData.h"
#include "include/private/base/SkCPUTypes.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/base/SkTo.h"
#include "include/private/gpu/ganesh/GrImageContext.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "modules/skcms/skcms.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "src/core/SkBitmapCache.h"
#include "src/core/SkColorSpacePriv.h"
#include "src/core/SkImagePriv.h"
#include "src/core/SkMemset.h"
#include "src/gpu/ResourceKey.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrGpu.h"
#include "src/gpu/ganesh/GrImageContextPriv.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
#include "src/gpu/ganesh/GrTextureProxy.h"
#include "src/gpu/ganesh/image/GrImageUtils.h"
#include "src/gpu/ganesh/image/SkImage_GaneshYUVA.h"
#include "src/image/SkImageGeneratorPriv.h"
#include "src/image/SkImage_Base.h"
#include "src/shaders/SkImageShader.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/gpu/FenceSync.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include "tools/gpu/ProxyUtils.h"
#include "tools/gpu/TestContext.h"
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <functional>
#include <initializer_list>
#include <memory>
#include <tuple>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

struct  RasterDataHolder
 
class  EmptyGenerator
 
struct  TextureReleaseChecker
 

Functions

SkImageInfo read_pixels_info (SkImage *image)
 
static void assert_equal (skiatest::Reporter *reporter, GrDirectContext *dContextA, SkImage *a, const SkIRect *subsetA, SkImage *b)
 
static void draw_image_test_pattern (SkCanvas *canvas)
 
static sk_sp< SkImagecreate_image ()
 
static sk_sp< SkDatacreate_image_data (SkImageInfo *info)
 
static sk_sp< SkImagecreate_data_image ()
 
static sk_sp< SkImagecreate_image_large (int maxTextureSize)
 
static sk_sp< SkImagecreate_picture_image ()
 
static sk_sp< SkImagecreate_rasterproc_image (RasterDataHolder *dataHolder)
 
static sk_sp< SkImagecreate_codec_image ()
 
static sk_sp< SkImagecreate_gpu_image (GrRecordingContext *rContext, bool withMips=false, skgpu::Budgeted budgeted=skgpu::Budgeted::kYes)
 
static void test_encode (skiatest::Reporter *reporter, GrDirectContext *dContext, SkImage *image)
 
 DEF_TEST (ImageEncode, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ImageEncode_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_TEST (Image_MakeFromRasterBitmap, reporter)
 
 DEF_TEST (Image_Serialize_Encoding_Failure, reporter)
 
 DEF_TEST (Image_RetainSnapshot, reporter)
 
static void make_bitmap_mutable (SkBitmap *bm)
 
static void make_bitmap_immutable (SkBitmap *bm)
 
 DEF_TEST (image_newfrombitmap, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkImage_Ganesh2Cpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkImage_makeTextureImage, reporter, contextInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkImage_makeNonTextureImage, reporter, contextInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (GrContext_colorTypeSupportedAsImage, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (UnpremulTextureImage, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST (AbandonedContextImage, reporter, options, CtsEnforcement::kApiLevel_T)
 
 DEF_TEST (ImageEmpty, reporter)
 
 DEF_TEST (ImageDataRef, reporter)
 
static bool has_pixels (const SkPMColor pixels[], int count, SkPMColor expected)
 
static void image_test_read_pixels (GrDirectContext *dContext, skiatest::Reporter *reporter, SkImage *image)
 
 DEF_TEST (ImageReadPixels, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ImageReadPixels_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void check_legacy_bitmap (skiatest::Reporter *reporter, GrDirectContext *dContext, const SkImage *image, const SkBitmap &bitmap)
 
static void test_legacy_bitmap (skiatest::Reporter *reporter, GrDirectContext *dContext, const SkImage *image)
 
 DEF_TEST (ImageLegacyBitmap, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ImageLegacyBitmap_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void test_peek (skiatest::Reporter *reporter, SkImage *image, bool expectPeekSuccess)
 
 DEF_TEST (ImagePeek, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ImagePeek_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_GL_CONTEXT (SkImage_NewFromTextureRelease, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void test_cross_context_image (skiatest::Reporter *reporter, const GrContextOptions &options, const char *testName, std::function< sk_sp< SkImage >(GrDirectContext *)> imageMaker)
 
 DEF_GANESH_TEST (SkImage_MakeCrossContextFromPixmapRelease, reporter, options, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST (SkImage_CrossContextGrayAlphaConfigs, reporter, options, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_GL_CONTEXT (makeBackendTexture, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ImageBackendAccessAbandoned_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static sk_sp< SkImagecreate_picture_image (sk_sp< SkColorSpace > space)
 
 DEF_TEST (Image_ColorSpace, r)
 
 DEF_TEST (Image_makeColorSpace, r)
 
static void make_all_premul (SkBitmap *bm)
 
static bool equal (const SkBitmap &a, const SkBitmap &b)
 
 DEF_TEST (image_roundtrip_encode, reporter)
 
 DEF_TEST (image_roundtrip_premul, reporter)
 
 DEF_TEST (image_from_encoded_alphatype_override, reporter)
 
static void check_scaled_pixels (skiatest::Reporter *reporter, SkPixmap *pmap, uint32_t expected)
 
static void test_scale_pixels (skiatest::Reporter *reporter, const SkImage *image, uint32_t expected)
 
 DEF_TEST (ImageScalePixels, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ImageScalePixels_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static sk_sp< SkImageany_image_will_do ()
 
 DEF_TEST (Image_nonfinite_dst, reporter)
 
static sk_sp< SkImagemake_yuva_image (GrDirectContext *dContext)
 
 DEF_GANESH_TEST_FOR_ALL_CONTEXTS (ImageFlush, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
constexpr SkM44 gCentripetalCatmulRom (0.0f/2, -1.0f/2, 2.0f/2, -1.0f/2, 2.0f/2, 0.0f/2, -5.0f/2, 3.0f/2, 0.0f/2, 1.0f/2, 4.0f/2, -3.0f/2, 0.0f/2, 0.0f/2, -1.0f/2, 1.0f/2)
 
constexpr SkM44 gMitchellNetravali (1.0f/18, -9.0f/18, 15.0f/18, -7.0f/18, 16.0f/18, 0.0f/18, -36.0f/18, 21.0f/18, 1.0f/18, 9.0f/18, 27.0f/18, -21.0f/18, 0.0f/18, 0.0f/18, -6.0f/18, 7.0f/18)
 
 DEF_TEST (image_cubicresampler, reporter)
 
 DEF_TEST (image_subset_encode_skbug_7752, reporter)
 

Function Documentation

◆ any_image_will_do()

static sk_sp< SkImage > any_image_will_do ( )
static

Definition at line 1511 of file ImageTest.cpp.

1511 {
1512 return GetResourceAsImage("images/mandrill_32.png");
1513}
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: Resources.h:39

◆ assert_equal()

static void assert_equal ( skiatest::Reporter reporter,
GrDirectContext dContextA,
SkImage a,
const SkIRect subsetA,
SkImage b 
)
static

Definition at line 106 of file ImageTest.cpp.

107 {
108 const int widthA = subsetA ? subsetA->width() : a->width();
109 const int heightA = subsetA ? subsetA->height() : a->height();
110
111 REPORTER_ASSERT(reporter, widthA == b->width());
112 REPORTER_ASSERT(reporter, heightA == b->height());
113
114 // see https://bug.skia.org/3965
115 //REPORTER_ASSERT(reporter, a->isOpaque() == b->isOpaque());
116
117 SkAutoPixmapStorage pmapA, pmapB;
118 pmapA.alloc(read_pixels_info(a));
119 pmapB.alloc(read_pixels_info(b));
120
121 const int srcX = subsetA ? subsetA->x() : 0;
122 const int srcY = subsetA ? subsetA->y() : 0;
123
124 REPORTER_ASSERT(reporter, a->readPixels(dContextA, pmapA, srcX, srcY));
125 REPORTER_ASSERT(reporter, b->readPixels(nullptr, pmapB, 0, 0));
126
127 const size_t widthBytes = widthA * 4;
128 for (int y = 0; y < heightA; ++y) {
129 REPORTER_ASSERT(reporter, !memcmp(pmapA.addr32(0, y), pmapB.addr32(0, y), widthBytes));
130 }
131}
reporter
Definition: FontMgrTest.cpp:37
SkImageInfo read_pixels_info(SkImage *image)
Definition: ImageTest.cpp:97
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:281
void alloc(const SkImageInfo &)
const uint32_t * addr32() const
Definition: SkPixmap.h:352
static bool b
struct MyStruct a[10]
double y
constexpr int32_t x() const
Definition: SkRect.h:141
constexpr int32_t y() const
Definition: SkRect.h:148
constexpr int32_t height() const
Definition: SkRect.h:165
constexpr int32_t width() const
Definition: SkRect.h:158

◆ check_legacy_bitmap()

static void check_legacy_bitmap ( skiatest::Reporter reporter,
GrDirectContext dContext,
const SkImage image,
const SkBitmap bitmap 
)
static

Definition at line 813 of file ImageTest.cpp.

814 {
815 REPORTER_ASSERT(reporter, image->width() == bitmap.width());
816 REPORTER_ASSERT(reporter, image->height() == bitmap.height());
817 REPORTER_ASSERT(reporter, image->alphaType() == bitmap.alphaType());
818
819 REPORTER_ASSERT(reporter, bitmap.isImmutable());
820
821 REPORTER_ASSERT(reporter, bitmap.getPixels());
822
823 const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType());
824 SkPMColor imageColor;
825 REPORTER_ASSERT(reporter, image->readPixels(dContext, info, &imageColor, sizeof(SkPMColor),
826 0, 0));
827 REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0));
828}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:233
uint32_t SkPMColor
Definition: SkColor.h:205
bool readPixels(GrDirectContext *context, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
Definition: SkImage.cpp:42
SkAlphaType alphaType() const
Definition: SkImage.cpp:145
int width() const
Definition: SkImage.h:283
int height() const
Definition: SkImage.h:289
sk_sp< SkImage > image
Definition: examples.cpp:13
Definition: bitmap.py:1
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)

◆ check_scaled_pixels()

static void check_scaled_pixels ( skiatest::Reporter reporter,
SkPixmap pmap,
uint32_t  expected 
)
static

Definition at line 1448 of file ImageTest.cpp.

1448 {
1449 // Verify that all pixels contain the original test color
1450 for (auto y = 0; y < pmap->height(); ++y) {
1451 for (auto x = 0; x < pmap->width(); ++x) {
1452 uint32_t pixel = *pmap->addr32(x, y);
1453 if (pixel != expected) {
1454 ERRORF(reporter, "Expected scaled pixels to be the same. At %d,%d 0x%08x != 0x%08x",
1455 x, y, pixel, expected);
1456 return;
1457 }
1458 }
1459 }
1460}
#define ERRORF(r,...)
Definition: Test.h:288
int width() const
Definition: SkPixmap.h:160
int height() const
Definition: SkPixmap.h:166
double x

◆ create_codec_image()

static sk_sp< SkImage > create_codec_image ( )
static

Definition at line 200 of file ImageTest.cpp.

200 {
204 bitmap.installPixels(info, data->writable_data(), info.minRowBytes());
206 SkASSERT_RELEASE(SkPngEncoder::Encode(&stream, bitmap.pixmap(), {}));
207 return SkImages::DeferredFromEncodedData(stream.detachAsData());
208}
static sk_sp< SkData > create_image_data(SkImageInfo *info)
Definition: ImageTest.cpp:144
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:84
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition: switches.h:41

◆ create_data_image()

static sk_sp< SkImage > create_data_image ( )
static

Definition at line 156 of file ImageTest.cpp.

156 {
159 return SkImages::RasterFromData(info, std::move(data), info.minRowBytes());
160}
SK_API sk_sp< SkImage > RasterFromData(const SkImageInfo &info, sk_sp< SkData > pixels, size_t rowBytes)

◆ create_gpu_image()

static sk_sp< SkImage > create_gpu_image ( GrRecordingContext rContext,
bool  withMips = false,
skgpu::Budgeted  budgeted = skgpu::Budgeted::kYes 
)
static

Definition at line 209 of file ImageTest.cpp.

211 {
214 rContext, budgeted, info, 0, kBottomLeft_GrSurfaceOrigin, nullptr, withMips);
215 draw_image_test_pattern(surface->getCanvas());
216 return surface->makeImageSnapshot();
217}
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:158
static void draw_image_test_pattern(SkCanvas *canvas)
Definition: ImageTest.cpp:132
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
VkSurfaceKHR surface
Definition: main.cc:48
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)

◆ create_image()

static sk_sp< SkImage > create_image ( )
static

Definition at line 138 of file ImageTest.cpp.

138 {
141 draw_image_test_pattern(surface->getCanvas());
142 return surface->makeImageSnapshot();
143}
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)

◆ create_image_data()

static sk_sp< SkData > create_image_data ( SkImageInfo info)
static

Definition at line 144 of file ImageTest.cpp.

144 {
146 const size_t rowBytes = info->minRowBytes();
147 sk_sp<SkData> data(SkData::MakeUninitialized(rowBytes * info->height()));
148 {
149 SkBitmap bm;
150 bm.installPixels(*info, data->writable_data(), rowBytes);
151 SkCanvas canvas(bm);
153 }
154 return data;
155}
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, void(*releaseProc)(void *addr, void *context), void *context)
Definition: SkBitmap.cpp:317
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116

◆ create_image_large()

static sk_sp< SkImage > create_image_large ( int  maxTextureSize)
static

Definition at line 161 of file ImageTest.cpp.

161 {
162 const SkImageInfo info = SkImageInfo::MakeN32(maxTextureSize + 1, 32, kOpaque_SkAlphaType);
164 surface->getCanvas()->clear(SK_ColorWHITE);
167 surface->getCanvas()->drawRect(SkRect::MakeXYWH(4000, 2, 28000, 30), paint);
168 return surface->makeImageSnapshot();
169}
static SkPaint paint(SkColor color, float strokeWidth=-1.f, SkPaint::Join join=SkPaint::kMiter_Join)
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void setColor(SkColor color)
Definition: SkPaint.cpp:119
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ create_picture_image() [1/2]

static sk_sp< SkImage > create_picture_image ( )
static

Definition at line 170 of file ImageTest.cpp.

170 {
171 SkPictureRecorder recorder;
172 SkCanvas* canvas = recorder.beginRecording(10, 10);
173 canvas->clear(SK_ColorCYAN);
175 SkISize::Make(10, 10),
176 nullptr,
177 nullptr,
180}
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
void clear(SkColor color)
Definition: SkCanvas.h:1147
static sk_sp< SkColorSpace > MakeSRGB()
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
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)
@ kU8
uses 8-bit unsigned int per color component
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:19

◆ create_picture_image() [2/2]

static sk_sp< SkImage > create_picture_image ( sk_sp< SkColorSpace space)
static

Definition at line 1290 of file ImageTest.cpp.

1290 {
1291 SkPictureRecorder recorder;
1292 SkCanvas* canvas = recorder.beginRecording(10, 10);
1293 canvas->clear(SK_ColorCYAN);
1295 SkISize::Make(10, 10),
1296 nullptr,
1297 nullptr,
1299 std::move(space));
1300}

◆ create_rasterproc_image()

static sk_sp< SkImage > create_rasterproc_image ( RasterDataHolder dataHolder)
static

Definition at line 192 of file ImageTest.cpp.

192 {
193 SkASSERT(dataHolder);
195 dataHolder->fData = create_image_data(&info);
196 return SkImages::RasterFromPixmap(SkPixmap(info, dataHolder->fData->data(), info.minRowBytes()),
198 dataHolder);
199}
#define SkASSERT(cond)
Definition: SkAssert.h:100
const void * data() const
Definition: SkData.h:37
SK_API sk_sp< SkImage > RasterFromPixmap(const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
sk_sp< SkData > fData
Definition: ImageTest.cpp:184
static void Release(const void *pixels, void *context)
Definition: ImageTest.cpp:186

◆ DEF_GANESH_TEST() [1/3]

DEF_GANESH_TEST ( AbandonedContextImage  ,
reporter  ,
options  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 661 of file ImageTest.cpp.

661 {
662 using Factory = sk_gpu_test::GrContextFactory;
663 for (int ct = 0; ct < skgpu::kContextTypeCount; ++ct) {
664 auto type = static_cast<Factory::ContextType>(ct);
665 std::unique_ptr<Factory> factory(new Factory);
666 if (!factory->get(type)) {
667 continue;
668 }
669
670 sk_sp<SkImage> img;
671 auto gsurf = SkSurfaces::RenderTarget(
672 factory->get(type),
675 1,
676 nullptr);
677 if (!gsurf) {
678 continue;
679 }
680 img = gsurf->makeImageSnapshot();
681 gsurf.reset();
682
683 auto rsurf = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(100, 100));
684
685 REPORTER_ASSERT(reporter, img->isValid(factory->get(type)));
686 REPORTER_ASSERT(reporter, img->isValid(rsurf->getCanvas()->recordingContext()));
687
688 factory->get(type)->abandonContext();
689 REPORTER_ASSERT(reporter, !img->isValid(factory->get(type)));
690 REPORTER_ASSERT(reporter, !img->isValid(rsurf->getCanvas()->recordingContext()));
691 // This shouldn't crash.
692 rsurf->getCanvas()->drawImage(img, 0, 0);
693
694 // Give up all other refs on the context.
695 factory.reset(nullptr);
696 REPORTER_ASSERT(reporter, !img->isValid(rsurf->getCanvas()->recordingContext()));
697 // This shouldn't crash.
698 rsurf->getCanvas()->drawImage(img, 0, 0);
699 }
700}
@ 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
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
enum flutter::testing::@2643::KeyboardChange::Type type
static const int kContextTypeCount
Definition: ContextType.h:43
static SkImageInfo MakeN32Premul(int width, int height)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ DEF_GANESH_TEST() [2/3]

DEF_GANESH_TEST ( SkImage_CrossContextGrayAlphaConfigs  ,
reporter  ,
options  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 1162 of file ImageTest.cpp.

1165 {
1167 SkAutoPixmapStorage pixmap;
1168 pixmap.alloc(SkImageInfo::Make(4, 4, ct, kPremul_SkAlphaType));
1169
1170 for (int i = 0; i < skgpu::kContextTypeCount; ++i) {
1171 GrContextFactory testFactory(options);
1172 skgpu::ContextType ctxType = static_cast<skgpu::ContextType>(i);
1173 ContextInfo ctxInfo = testFactory.getContextInfo(ctxType);
1174 auto dContext = ctxInfo.directContext();
1175 if (!dContext || !dContext->priv().caps()->crossContextTextureSupport()) {
1176 continue;
1177 }
1178
1181
1182 auto [view, viewCT] = skgpu::ganesh::AsView(dContext, image, skgpu::Mipmapped::kNo);
1185
1186 bool expectAlpha = kAlpha_8_SkColorType == ct;
1188 REPORTER_ASSERT(reporter, expectAlpha == GrColorTypeIsAlphaOnly(grCT));
1189 }
1190 }
1191}
const char * options
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct)
Definition: GrTypesPriv.h:593
static constexpr bool GrColorTypeIsAlphaOnly(GrColorType ct)
Definition: GrTypesPriv.h:887
GrColorType
Definition: GrTypesPriv.h:545
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
Definition: GrTypesPriv.h:632
SkColorType
Definition: SkColorType.h:19
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition: SkColorType.h:21
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition: SkColorType.h:34
SkColorType colorType() const
Definition: SkImage.cpp:143
GrDirectContext * directContext() const
SK_API sk_sp< SkImage > CrossContextTextureFromPixmap(GrDirectContext *context, const SkPixmap &pixmap, bool buildMips, bool limitToMaxTextureSize=false)
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)
ContextType
Definition: ContextType.h:19

◆ DEF_GANESH_TEST() [3/3]

DEF_GANESH_TEST ( SkImage_MakeCrossContextFromPixmapRelease  ,
reporter  ,
options  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 1143 of file ImageTest.cpp.

1146 {
1148 SkPixmap pixmap;
1149 if (!GetResourceAsBitmap("images/mandrill_128.png", &bitmap) || !bitmap.peekPixels(&pixmap)) {
1150 ERRORF(reporter, "missing resource");
1151 return;
1152 }
1154 options,
1155 "SkImage_MakeCrossContextFromPixmapRelease",
1156 [&pixmap](GrDirectContext* dContext) {
1158 dContext, pixmap, false);
1159 });
1160}
static void test_cross_context_image(skiatest::Reporter *reporter, const GrContextOptions &options, const char *testName, std::function< sk_sp< SkImage >(GrDirectContext *)> imageMaker)
Definition: ImageTest.cpp:982
bool GetResourceAsBitmap(const char *resource, SkBitmap *dst)
Definition: Resources.h:35

◆ DEF_GANESH_TEST_FOR_ALL_CONTEXTS()

DEF_GANESH_TEST_FOR_ALL_CONTEXTS ( ImageFlush  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 1551 of file ImageTest.cpp.

1551 {
1552 auto dContext = ctxInfo.directContext();
1554 auto s = SkSurfaces::RenderTarget(dContext, skgpu::Budgeted::kYes, ii, 1, nullptr);
1555
1556 s->getCanvas()->clear(SK_ColorRED);
1557 auto i0 = s->makeImageSnapshot();
1558 s->getCanvas()->clear(SK_ColorBLUE);
1559 auto i1 = s->makeImageSnapshot();
1560 s->getCanvas()->clear(SK_ColorGREEN);
1561 // Make a YUVA image.
1562 auto i2 = make_yuva_image(dContext);
1563
1564 // Flush all the setup work we did above and then make little lambda that reports the flush
1565 // count delta since the last time it was called.
1566 dContext->flushAndSubmit();
1567 auto numSubmits =
1568 [dContext,
1569 submitCnt = dContext->priv().getGpu()->stats()->numSubmitToGpus()]() mutable {
1570 int curr = dContext->priv().getGpu()->stats()->numSubmitToGpus();
1571 int n = curr - submitCnt;
1572 submitCnt = curr;
1573 return n;
1574 };
1575
1576 // Images aren't used therefore flush is ignored, but submit is still called.
1577 dContext->flushAndSubmit(i0);
1578 dContext->flushAndSubmit(i1);
1579 dContext->flushAndSubmit(i2);
1580 REPORTER_ASSERT(reporter, numSubmits() == 3);
1581
1582 // Syncing forces the flush to happen even if the images aren't used.
1583 dContext->flush(i0);
1584 dContext->submit(GrSyncCpu::kYes);
1585 REPORTER_ASSERT(reporter, numSubmits() == 1);
1586 dContext->flush(i1);
1587 dContext->submit(GrSyncCpu::kYes);
1588 REPORTER_ASSERT(reporter, numSubmits() == 1);
1589 dContext->flush(i2);
1590 dContext->submit(GrSyncCpu::kYes);
1591 REPORTER_ASSERT(reporter, numSubmits() == 1);
1592
1593 // Use image 1
1594 s->getCanvas()->drawImage(i1, 0, 0);
1595 // Flushing image 0 should do nothing, but submit is still called.
1596 dContext->flushAndSubmit(i0);
1597 REPORTER_ASSERT(reporter, numSubmits() == 1);
1598 // Flushing image 1 should flush.
1599 dContext->flushAndSubmit(i1);
1600 REPORTER_ASSERT(reporter, numSubmits() == 1);
1601 // Flushing image 2 should do nothing, but submit is still called.
1602 dContext->flushAndSubmit(i2);
1603 REPORTER_ASSERT(reporter, numSubmits() == 1);
1604
1605 // Use image 2
1606 s->getCanvas()->drawImage(i2, 0, 0);
1607 // Flushing image 0 should do nothing, but submit is still called.
1608 dContext->flushAndSubmit(i0);
1609 REPORTER_ASSERT(reporter, numSubmits() == 1);
1610 // Flushing image 1 do nothing, but submit is still called.
1611 dContext->flushAndSubmit(i1);
1612 REPORTER_ASSERT(reporter, numSubmits() == 1);
1613 // Flushing image 2 should flush.
1614 dContext->flushAndSubmit(i2);
1615 REPORTER_ASSERT(reporter, numSubmits() == 1);
1616 REPORTER_ASSERT(reporter, static_cast<SkImage_GaneshYUVA*>(as_IB(i2.get()))->isTextureBacked());
1617 s->getCanvas()->drawImage(i2, 0, 0);
1618 // Flushing image 0 should do nothing, but submit is still called.
1619 dContext->flushAndSubmit(i0);
1620 REPORTER_ASSERT(reporter, numSubmits() == 1);
1621 // Flushing image 1 do nothing, but submit is still called.
1622 dContext->flushAndSubmit(i1);
1623 REPORTER_ASSERT(reporter, numSubmits() == 1);
1624 // Flushing image 2 should flush.
1625 dContext->flushAndSubmit(i2);
1626 REPORTER_ASSERT(reporter, numSubmits() == 1);
1627}
static sk_sp< SkImage > make_yuva_image(GrDirectContext *dContext)
Definition: ImageTest.cpp:1538
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 SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:193
bool isTextureBacked() const override
Definition: SkImage_Base.h:161
struct MyStruct s

◆ DEF_GANESH_TEST_FOR_GL_CONTEXT() [1/2]

DEF_GANESH_TEST_FOR_GL_CONTEXT ( makeBackendTexture  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 1193 of file ImageTest.cpp.

1193 {
1194 auto context = ctxInfo.directContext();
1195 sk_gpu_test::TestContext* testContext = ctxInfo.testContext();
1196 sk_sp<GrContextThreadSafeProxy> proxy = context->threadSafeProxy();
1197
1198 GrContextFactory otherFactory;
1199 ContextInfo otherContextInfo = otherFactory.getContextInfo(ctxInfo.type());
1200
1201 testContext->makeCurrent();
1202 REPORTER_ASSERT(reporter, proxy);
1203 auto createLarge = [context] {
1204 return create_image_large(context->priv().caps()->maxTextureSize());
1205 };
1206 struct TestCase {
1207 std::function<sk_sp<SkImage>()> fImageFactory;
1208 bool fExpectation;
1209 bool fCanTakeDirectly;
1210 };
1211 TestCase testCases[] = {
1212 { create_image, true, false },
1213 { create_codec_image, true, false },
1214 { create_data_image, true, false },
1215 { create_picture_image, true, false },
1216 { [context] { return create_gpu_image(context); }, true, true },
1217 // Create a texture image in a another context.
1218 { [otherContextInfo] {
1219 auto restore = otherContextInfo.testContext()->makeCurrentAndAutoRestore();
1220 sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo.directContext());
1221 otherContextInfo.directContext()->flushAndSubmit();
1222 return otherContextImage;
1223 }, false, false },
1224 // Create an image that is too large to be texture backed.
1225 { createLarge, false, false }
1226 };
1227
1228 for (const TestCase& testCase : testCases) {
1229 sk_sp<SkImage> image(testCase.fImageFactory());
1230 if (!image) {
1231 ERRORF(reporter, "Failed to create image!");
1232 continue;
1233 }
1234
1235 GrBackendTexture origBackend;
1236 SkImages::GetBackendTextureFromImage(image, &origBackend, true);
1237 if (testCase.fCanTakeDirectly) {
1238 SkASSERT(origBackend.isValid());
1239 }
1240
1241 GrBackendTexture newBackend;
1244 context, std::move(image), &newBackend, &proc);
1245 if (result != testCase.fExpectation) {
1246 static const char *const kFS[] = { "fail", "succeed" };
1247 ERRORF(reporter, "This image was expected to %s but did not.",
1248 kFS[testCase.fExpectation]);
1249 }
1250
1251 if (result) {
1252 SkASSERT(newBackend.isValid());
1253 }
1254
1255 bool tookDirectly = result && GrBackendTexture::TestingOnly_Equals(origBackend, newBackend);
1256 if (testCase.fCanTakeDirectly != tookDirectly) {
1257 static const char *const kExpectedState[] = { "not expected", "expected" };
1258 ERRORF(reporter, "This backend texture was %s to be taken directly.",
1259 kExpectedState[testCase.fCanTakeDirectly]);
1260 }
1261
1262 context->flushAndSubmit();
1263 }
1264}
static sk_sp< SkImage > create_data_image()
Definition: ImageTest.cpp:156
static sk_sp< SkImage > create_codec_image()
Definition: ImageTest.cpp:200
static sk_sp< SkImage > create_gpu_image(GrRecordingContext *rContext, bool withMips=false, skgpu::Budgeted budgeted=skgpu::Budgeted::kYes)
Definition: ImageTest.cpp:209
static sk_sp< SkImage > create_picture_image()
Definition: ImageTest.cpp:170
static sk_sp< SkImage > create_image()
Definition: ImageTest.cpp:138
static sk_sp< SkImage > create_image_large(int maxTextureSize)
Definition: ImageTest.cpp:161
bool isValid() const
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
TestContext * testContext() const
ContextInfo getContextInfo(ContextType type, ContextOverrides=ContextOverrides::kNone)
SkScopeExit makeCurrentAndAutoRestore() const
Definition: TestContext.cpp:31
GAsyncResult * result
std::function< void(GrBackendTexture)> BackendTextureReleaseProc
Definition: SkImageGanesh.h:43
SK_API bool GetBackendTextureFromImage(const SkImage *img, GrBackendTexture *outTexture, bool flushPendingGrContextIO, GrSurfaceOrigin *origin=nullptr)
SK_API bool MakeBackendTextureFromImage(GrDirectContext *context, sk_sp< SkImage > image, GrBackendTexture *backendTexture, BackendTextureReleaseProc *backendTextureReleaseProc)

◆ DEF_GANESH_TEST_FOR_GL_CONTEXT() [2/2]

DEF_GANESH_TEST_FOR_GL_CONTEXT ( SkImage_NewFromTextureRelease  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 927 of file ImageTest.cpp.

930 {
931 const int kWidth = 10;
932 const int kHeight = 10;
933
934 auto dContext = ctxInfo.directContext();
935
936 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext,
937 kWidth,
938 kHeight,
940 skgpu::Mipmapped::kNo,
941 GrRenderable::kNo,
942 GrProtected::kNo);
943 if (!mbet) {
944 ERRORF(reporter, "couldn't create backend texture\n");
945 return;
946 }
947
948 TextureReleaseChecker releaseChecker;
951 dContext,
952 mbet->texture(),
953 texOrigin,
956 /*color space*/ nullptr,
957 sk_gpu_test::ManagedBackendTexture::ReleaseProc,
958 mbet->releaseContext(TextureReleaseChecker::Release, &releaseChecker));
959
960 GrSurfaceOrigin readBackOrigin;
961 GrBackendTexture readBackBackendTex;
964 refImg, &readBackBackendTex, false, &readBackOrigin),
965 "Did not get backend texture");
966 if (!GrBackendTexture::TestingOnly_Equals(readBackBackendTex, mbet->texture())) {
967 ERRORF(reporter, "backend mismatch\n");
968 }
970 GrBackendTexture::TestingOnly_Equals(readBackBackendTex, mbet->texture()));
971 if (readBackOrigin != texOrigin) {
972 ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, texOrigin);
973 }
974 REPORTER_ASSERT(reporter, readBackOrigin == texOrigin);
975
976 // Now exercise the release proc
977 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount);
978 refImg.reset(nullptr); // force a release of the image
979 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount);
980}
GrSurfaceOrigin
Definition: GrTypes.h:156
static const int kHeight
static const int kWidth
SK_API sk_sp< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
static void Release(void *self)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [1/11]

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

Definition at line 561 of file ImageTest.cpp.

564 {
565 auto dContext = ctxInfo.directContext();
566
567 static constexpr int kSize = 10;
568
569 for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) {
570 SkColorType colorType = static_cast<SkColorType>(ct);
571 bool can = dContext->colorTypeSupportedAsImage(colorType);
572
573 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
574 dContext, kSize, kSize, colorType, skgpu::Mipmapped::kNo, GrRenderable::kNo);
575 sk_sp<SkImage> img;
576 if (mbet) {
577 img = SkImages::BorrowTextureFrom(dContext,
578 mbet->texture(),
580 colorType,
582 nullptr);
583 }
584 REPORTER_ASSERT(reporter, can == SkToBool(img),
585 "colorTypeSupportedAsImage:%d, actual:%d, ct:%d", can, SkToBool(img),
586 colorType);
587 }
588}
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:157
@ kLastEnum_SkColorType
last valid value
Definition: SkColorType.h:55
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
static constexpr int kSize

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [2/11]

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

Definition at line 1266 of file ImageTest.cpp.

1269 {
1270 auto dContext = ctxInfo.directContext();
1271 sk_sp<SkImage> image(create_gpu_image(ctxInfo.directContext()));
1272 if (!image) {
1273 return;
1274 }
1275
1276 GrBackendTexture beTex;
1277 bool ok = SkImages::GetBackendTextureFromImage(image, &beTex, true);
1280
1281 dContext->abandonContext();
1282
1283 // After abandoning the context the backend texture should not be valid.
1286}
static bool ok(int result)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [3/11]

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

Definition at line 244 of file ImageTest.cpp.

247 {
248 auto dContext = ctxInfo.directContext();
249 test_encode(reporter, dContext, create_gpu_image(dContext).get());
250}
static void test_encode(skiatest::Reporter *reporter, GrDirectContext *dContext, SkImage *image)
Definition: ImageTest.cpp:219
def get(pkg)
Definition: go.py:42

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [4/11]

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

Definition at line 867 of file ImageTest.cpp.

870 {
871 auto dContext = ctxInfo.directContext();
873 test_legacy_bitmap(reporter, dContext, image.get());
874}
static void test_legacy_bitmap(skiatest::Reporter *reporter, GrDirectContext *dContext, const SkImage *image)
Definition: ImageTest.cpp:830
T * get() const
Definition: SkRefCnt.h:303

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [5/11]

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

Definition at line 911 of file ImageTest.cpp.

914 {
915 sk_sp<SkImage> image(create_gpu_image(ctxInfo.directContext()));
916 test_peek(reporter, image.get(), false);
917}
static void test_peek(skiatest::Reporter *reporter, SkImage *image, bool expectPeekSuccess)
Definition: ImageTest.cpp:876

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [6/11]

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

Definition at line 805 of file ImageTest.cpp.

808 {
809 auto dContext = ctxInfo.directContext();
810 image_test_read_pixels(dContext, reporter, create_gpu_image(dContext).get());
811}
static void image_test_read_pixels(GrDirectContext *dContext, skiatest::Reporter *reporter, SkImage *image)
Definition: ImageTest.cpp:738

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [7/11]

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

Definition at line 1496 of file ImageTest.cpp.

1499 {
1500 const SkPMColor pmRed = SkPackARGB32(0xFF, 0xFF, 0, 0);
1501 const SkColor red = SK_ColorRED;
1502
1505 SkSurfaces::RenderTarget(ctxInfo.directContext(), skgpu::Budgeted::kNo, info);
1506 surface->getCanvas()->clear(red);
1507 sk_sp<SkImage> gpuImage = surface->makeImageSnapshot();
1508 test_scale_pixels(reporter, gpuImage.get(), pmRed);
1509}
static void test_scale_pixels(skiatest::Reporter *reporter, const SkImage *image, uint32_t expected)
Definition: ImageTest.cpp:1462
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColorPriv.h:106
uint32_t SkColor
Definition: SkColor.h:37

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [8/11]

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

Definition at line 401 of file ImageTest.cpp.

404 {
406 sk_sp<SkImage> image(create_gpu_image(ctxInfo.directContext()));
407 const auto desc = SkBitmapCacheDesc::Make(image.get());
408
410
411 // now we can test drawing a gpu-backed image into a cpu-backed surface
412
413 {
414 SkBitmap cachedBitmap;
415 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(desc, &cachedBitmap));
416 }
417
418 surface->getCanvas()->drawImage(image, 0, 0);
419 {
420 SkBitmap cachedBitmap;
421 if (SkBitmapCache::Find(desc, &cachedBitmap)) {
422 REPORTER_ASSERT(reporter, cachedBitmap.isImmutable());
423 REPORTER_ASSERT(reporter, cachedBitmap.getPixels());
424 } else {
425 // unexpected, but not really a bug, since the cache is global and this test may be
426 // run w/ other threads competing for its budget.
427 SkDebugf("SkImage_Ganesh2Cpu : cachedBitmap was already purged\n");
428 }
429 }
430
431 image.reset(nullptr);
432 {
433 SkBitmap cachedBitmap;
434 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(desc, &cachedBitmap));
435 }
436}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static bool Find(const SkBitmapCacheDesc &, SkBitmap *result)
bool isImmutable() const
Definition: SkBitmap.cpp:390
void * getPixels() const
Definition: SkBitmap.h:273
static SkBitmapCacheDesc Make(const SkImage *)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [9/11]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkImage_makeNonTextureImage  ,
reporter  ,
contextInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 531 of file ImageTest.cpp.

534 {
535 auto dContext = contextInfo.directContext();
536
537 std::function<sk_sp<SkImage>()> imageFactories[] = {
542 [dContext] { return create_gpu_image(dContext); },
543 };
544 for (const auto& factory : imageFactories) {
545 sk_sp<SkImage> image = factory();
546 if (!image->isTextureBacked()) {
548 if (!(image = SkImages::TextureFromImage(dContext, image))) {
549 continue;
550 }
551 }
552 auto rasterImage = image->makeNonTextureImage();
553 if (!rasterImage) {
554 ERRORF(reporter, "makeNonTextureImage failed for texture-backed image.");
555 }
556 REPORTER_ASSERT(reporter, !rasterImage->isTextureBacked());
557 assert_equal(reporter, dContext, image.get(), nullptr, rasterImage.get());
558 }
559}
static void assert_equal(skiatest::Reporter *reporter, GrDirectContext *dContextA, SkImage *a, const SkIRect *subsetA, SkImage *b)
Definition: ImageTest.cpp:106
sk_sp< SkImage > makeNonTextureImage(GrDirectContext *=nullptr) const
Definition: SkImage.cpp:251
virtual bool isTextureBacked() const =0
SK_API sk_sp< SkImage > TextureFromImage(GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [10/11]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkImage_makeTextureImage  ,
reporter  ,
contextInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 438 of file ImageTest.cpp.

441 {
442 auto dContext = contextInfo.directContext();
443 sk_gpu_test::TestContext* testContext = contextInfo.testContext();
444 GrContextFactory otherFactory;
445 ContextInfo otherContextInfo = otherFactory.getContextInfo(contextInfo.type());
446 testContext->makeCurrent();
447 std::function<sk_sp<SkImage>()> imageFactories[] = {
451 // Create an image from a picture.
453 // Create a texture image.
454 [dContext] { return create_gpu_image(dContext, true, skgpu::Budgeted::kYes); },
455 [dContext] { return create_gpu_image(dContext, false, skgpu::Budgeted::kNo); },
456 // Create a texture image in a another context.
457 [otherContextInfo] {
458 auto restore = otherContextInfo.testContext()->makeCurrentAndAutoRestore();
459 auto otherContextImage = create_gpu_image(otherContextInfo.directContext());
460 otherContextInfo.directContext()->flushAndSubmit();
461 return otherContextImage;
462 }};
463 for (auto mipmapped : {skgpu::Mipmapped::kNo, skgpu::Mipmapped::kYes}) {
464 for (const auto& factory : imageFactories) {
465 sk_sp<SkImage> image(factory());
466 if (!image) {
467 ERRORF(reporter, "Error creating image.");
468 continue;
469 }
470 GrTextureProxy* origProxy = nullptr;
471 bool origIsMippedTexture = false;
472
473 if ((origProxy = sk_gpu_test::GetTextureImageProxy(image.get(), dContext))) {
475 reporter,
476 (origProxy->mipmapped() == skgpu::Mipmapped::kYes) == image->hasMipmaps());
477 origIsMippedTexture = image->hasMipmaps();
478 }
479 for (auto budgeted : {skgpu::Budgeted::kNo, skgpu::Budgeted::kYes}) {
480 auto texImage = SkImages::TextureFromImage(dContext, image, mipmapped, budgeted);
481 if (!texImage) {
482 auto imageContext = as_IB(image)->context();
483 // We expect to fail if image comes from a different context
484 if (!image->isTextureBacked() || imageContext->priv().matches(dContext)) {
485 ERRORF(reporter, "makeTextureImage failed.");
486 }
487 continue;
488 }
489 if (!texImage->isTextureBacked()) {
490 ERRORF(reporter, "makeTextureImage returned non-texture image.");
491 continue;
492 }
493
494 GrTextureProxy* copyProxy = sk_gpu_test::GetTextureImageProxy(texImage.get(),
495 dContext);
496 SkASSERT(copyProxy);
497 // Did we ask for MIPs on a context that supports them?
498 bool validRequestForMips = (mipmapped == skgpu::Mipmapped::kYes &&
499 dContext->priv().caps()->mipmapSupport());
500 // Do we expect the "copy" to have MIPs?
501 bool shouldBeMipped = origIsMippedTexture || validRequestForMips;
502 REPORTER_ASSERT(reporter, shouldBeMipped == texImage->hasMipmaps());
504 reporter,
505 shouldBeMipped == (copyProxy->mipmapped() == skgpu::Mipmapped::kYes));
506
507 // We should only make a copy of an already texture-backed image if it didn't
508 // already have MIPs but we asked for MIPs and the context supports it.
509 if (image->isTextureBacked() && (!validRequestForMips || origIsMippedTexture)) {
510 if (origProxy->underlyingUniqueID() != copyProxy->underlyingUniqueID()) {
511 ERRORF(reporter, "makeTextureImage made unnecessary texture copy.");
512 }
513 } else {
514 GrTextureProxy* texProxy = sk_gpu_test::GetTextureImageProxy(texImage.get(),
515 dContext);
517 REPORTER_ASSERT(reporter, texProxy->isBudgeted() == budgeted);
518 }
519 if (image->width() != texImage->width() || image->height() != texImage->height()) {
520 ERRORF(reporter, "makeTextureImage changed the image size.");
521 }
522 if (image->alphaType() != texImage->alphaType()) {
523 ERRORF(reporter, "makeTextureImage changed image alpha type.");
524 }
525 }
526 }
527 }
528 dContext->flushAndSubmit();
529}
UniqueID underlyingUniqueID() const
skgpu::Budgeted isBudgeted() const
const skgpu::UniqueKey & getUniqueKey() const override
skgpu::Mipmapped mipmapped() const
virtual GrImageContext * context() const
Definition: SkImage_Base.h:105
bool hasMipmaps() const
Definition: SkImage.cpp:283
bool isValid() const
Definition: ResourceKey.h:51
GrTextureProxy * GetTextureImageProxy(SkImage *image, GrRecordingContext *rContext)
Definition: ProxyUtils.cpp:32

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [11/11]

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

Definition at line 590 of file ImageTest.cpp.

593 {
594 SkBitmap bmp;
595 bmp.allocPixels(
597 for (int y = 0; y < 256; ++y) {
598 for (int x = 0; x < 256; ++x) {
599 *bmp.getAddr32(x, y) =
600 SkColorSetARGB((U8CPU)y, 255 - (U8CPU)y, (U8CPU)x, 255 - (U8CPU)x);
601 }
602 }
603 auto dContext = ctxInfo.directContext();
604 auto texImage = SkImages::TextureFromImage(dContext, bmp.asImage());
605 if (!texImage || texImage->alphaType() != kUnpremul_SkAlphaType) {
606 ERRORF(reporter, "Failed to make unpremul texture image.");
607 return;
608 }
609 SkBitmap unpremul;
611 kUnpremul_SkAlphaType, nullptr));
612 if (!texImage->readPixels(dContext, unpremul.info(), unpremul.getPixels(), unpremul.rowBytes(),
613 0, 0)) {
614 ERRORF(reporter, "Unpremul readback failed.");
615 return;
616 }
617 for (int y = 0; y < 256; ++y) {
618 for (int x = 0; x < 256; ++x) {
619 if (*bmp.getAddr32(x, y) != *unpremul.getAddr32(x, y)) {
620 ERRORF(reporter, "unpremul(0x%08x)->unpremul(0x%08x) at %d, %d.",
621 *bmp.getAddr32(x, y), *unpremul.getAddr32(x, y), x, y);
622 return;
623 }
624 }
625 }
627 premul.allocPixels(
629 if (!texImage->readPixels(dContext, premul.info(), premul.getPixels(), premul.rowBytes(),
630 0, 0)) {
631 ERRORF(reporter, "Unpremul readback failed.");
632 return;
633 }
634 for (int y = 0; y < 256; ++y) {
635 for (int x = 0; x < 256; ++x) {
636 uint32_t origColor = *bmp.getAddr32(x, y);
637 int32_t origA = (origColor >> 24) & 0xff;
638 float a = origA / 255.f;
639 int32_t origB = sk_float_round2int(((origColor >> 16) & 0xff) * a);
640 int32_t origG = sk_float_round2int(((origColor >> 8) & 0xff) * a);
641 int32_t origR = sk_float_round2int(((origColor >> 0) & 0xff) * a);
642
643 uint32_t read = *premul.getAddr32(x, y);
644 int32_t readA = (read >> 24) & 0xff;
645 int32_t readB = (read >> 16) & 0xff;
646 int32_t readG = (read >> 8) & 0xff;
647 int32_t readR = (read >> 0) & 0xff;
648 // We expect that alpha=1 and alpha=0 should come out exact. Otherwise allow a little
649 // bit of tolerance for GPU vs CPU premul math.
650 int32_t tol = (origA == 0 || origA == 255) ? 0 : 1;
651 if (origA != readA || SkTAbs(readB - origB) > tol || SkTAbs(readG - origG) > tol ||
652 SkTAbs(readR - origR) > tol) {
653 ERRORF(reporter, "unpremul(0x%08x)->premul(0x%08x) expected(0x%08x) at %d, %d.",
654 *bmp.getAddr32(x, y), *premul.getAddr32(x, y), origColor, x, y);
655 return;
656 }
657 }
658 }
659}
kUnpremul_SkAlphaType
unsigned U8CPU
Definition: SkCPUTypes.h:18
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
#define sk_float_round2int(x)
static bool read(SkStream *stream, void *buffer, size_t amount)
static T SkTAbs(T value)
Definition: SkTemplates.h:43
static uint32_t premul(uint32_t color)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:252
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:639
size_t rowBytes() const
Definition: SkBitmap.h:238
const SkImageInfo & info() const
Definition: SkBitmap.h:139
uint32_t * getAddr32(int x, int y) const
Definition: SkBitmap.h:1250

◆ DEF_TEST() [1/19]

DEF_TEST ( Image_ColorSpace  ,
 
)

Definition at line 1302 of file ImageTest.cpp.

1302 {
1304 sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_512_q075.jpg");
1305 REPORTER_ASSERT(r, srgb.get() == image->colorSpace());
1306
1307 image = GetResourceAsImage("images/webp-color-profile-lossy.webp");
1309 bool success = image->colorSpace()->isNumericalTransferFn(&fn);
1310 REPORTER_ASSERT(r, success);
1312
1317
1320 bitmap.allocPixels(info);
1321 image = bitmap.asImage();
1323
1326 image = surface->makeImageSnapshot();
1327 REPORTER_ASSERT(r, nullptr == image->colorSpace());
1328
1330 image = surface->makeImageSnapshot();
1332}
static sk_sp< SkColorSpace > rec2020()
static bool color_space_almost_equal(float a, float b)
bool isNumericalTransferFn(skcms_TransferFunction *fn) const
static bool Equals(const SkColorSpace *, const SkColorSpace *)
static sk_sp< SkColorSpace > MakeRGB(const skcms_TransferFunction &transferFn, const skcms_Matrix3x3 &toXYZ)
SkColorSpace * colorSpace() const
Definition: SkImage.cpp:147
static constexpr skcms_Matrix3x3 kRec2020
Definition: SkColorSpace.h:93
static constexpr skcms_TransferFunction kSRGB
Definition: SkColorSpace.h:45

◆ DEF_TEST() [2/19]

DEF_TEST ( image_cubicresampler  ,
reporter   
)

Definition at line 1641 of file ImageTest.cpp.

1641 {
1642 auto diff = [reporter](const SkM44& a, const SkM44& b) {
1643 const float tolerance = 0.000001f;
1644 for (int r = 0; r < 4; ++r) {
1645 for (int c = 0; c < 4; ++c) {
1646 float d = std::abs(a.rc(r, c) - b.rc(r, c));
1647 REPORTER_ASSERT(reporter, d <= tolerance);
1648 }
1649 }
1650 };
1651
1653
1655}
constexpr SkM44 gCentripetalCatmulRom(0.0f/2, -1.0f/2, 2.0f/2, -1.0f/2, 2.0f/2, 0.0f/2, -5.0f/2, 3.0f/2, 0.0f/2, 1.0f/2, 4.0f/2, -3.0f/2, 0.0f/2, 0.0f/2, -1.0f/2, 1.0f/2)
constexpr SkM44 gMitchellNetravali(1.0f/18, -9.0f/18, 15.0f/18, -7.0f/18, 16.0f/18, 0.0f/18, -36.0f/18, 21.0f/18, 1.0f/18, 9.0f/18, 27.0f/18, -21.0f/18, 0.0f/18, 0.0f/18, -6.0f/18, 7.0f/18)
static SkM44 CubicResamplerMatrix(float B, float C)
Definition: SkM44.h:146
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19

◆ DEF_TEST() [3/19]

DEF_TEST ( image_from_encoded_alphatype_override  ,
reporter   
)

Definition at line 1431 of file ImageTest.cpp.

1431 {
1432 sk_sp<SkData> data = GetResourceAsData("images/mandrill_32.png");
1433
1434 // Ensure that we can decode the image when we specifically request premul or unpremul, but
1435 // not when we request kOpaque
1439
1440 // Same tests as above, but using SkImageGenerators::MakeFromEncoded
1444}
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition: Resources.cpp:53
std::unique_ptr< SkImageGenerator > MakeFromEncoded(sk_sp< SkData > data, std::optional< SkAlphaType > at)

◆ DEF_TEST() [4/19]

DEF_TEST ( Image_makeColorSpace  ,
 
)

Definition at line 1334 of file ImageTest.cpp.

1334 {
1337 fn.a = 1.f; fn.b = 0.f; fn.c = 0.f; fn.d = 0.f; fn.e = 0.f; fn.f = 0.f; fn.g = 1.8f;
1339
1340 SkBitmap srgbBitmap;
1342 *srgbBitmap.getAddr32(0, 0) = SkSwizzle_RGBA_to_PMColor(0xFF604020);
1343 srgbBitmap.setImmutable();
1344 sk_sp<SkImage> srgbImage = srgbBitmap.asImage();
1345 sk_sp<SkImage> p3Image = srgbImage->makeColorSpace(nullptr, p3);
1346 SkBitmap p3Bitmap;
1347 bool success = p3Image->asLegacyBitmap(&p3Bitmap);
1348
1349 auto almost_equal = [](int a, int b) { return SkTAbs(a - b) <= 2; };
1350
1351 REPORTER_ASSERT(r, success);
1352 REPORTER_ASSERT(r, almost_equal(0x28, SkGetPackedR32(*p3Bitmap.getAddr32(0, 0))));
1353 REPORTER_ASSERT(r, almost_equal(0x40, SkGetPackedG32(*p3Bitmap.getAddr32(0, 0))));
1354 REPORTER_ASSERT(r, almost_equal(0x5E, SkGetPackedB32(*p3Bitmap.getAddr32(0, 0))));
1355
1356 sk_sp<SkImage> adobeImage = srgbImage->makeColorSpace(nullptr, adobeGamut);
1357 SkBitmap adobeBitmap;
1358 success = adobeImage->asLegacyBitmap(&adobeBitmap);
1359 REPORTER_ASSERT(r, success);
1360 REPORTER_ASSERT(r, almost_equal(0x21, SkGetPackedR32(*adobeBitmap.getAddr32(0, 0))));
1361 REPORTER_ASSERT(r, almost_equal(0x31, SkGetPackedG32(*adobeBitmap.getAddr32(0, 0))));
1362 REPORTER_ASSERT(r, almost_equal(0x4C, SkGetPackedB32(*adobeBitmap.getAddr32(0, 0))));
1363
1364 srgbImage = GetResourceAsImage("images/1x1.png");
1365 p3Image = srgbImage->makeColorSpace(nullptr, p3);
1366 success = p3Image->asLegacyBitmap(&p3Bitmap);
1367 REPORTER_ASSERT(r, success);
1368 REPORTER_ASSERT(r, almost_equal(0x8B, SkGetPackedR32(*p3Bitmap.getAddr32(0, 0))));
1369 REPORTER_ASSERT(r, almost_equal(0x82, SkGetPackedG32(*p3Bitmap.getAddr32(0, 0))));
1370 REPORTER_ASSERT(r, almost_equal(0x77, SkGetPackedB32(*p3Bitmap.getAddr32(0, 0))));
1371}
static bool almost_equal(float a, float b)
static SkPMColor SkSwizzle_RGBA_to_PMColor(uint32_t c)
Definition: SkColorData.h:83
#define SkGetPackedB32(packed)
Definition: SkColorPriv.h:95
#define SkGetPackedR32(packed)
Definition: SkColorPriv.h:93
#define SkGetPackedG32(packed)
Definition: SkColorPriv.h:94
void setImmutable()
Definition: SkBitmap.cpp:394
static constexpr skcms_Matrix3x3 kAdobeRGB
Definition: SkColorSpace.h:77
static constexpr skcms_Matrix3x3 kDisplayP3
Definition: SkColorSpace.h:87
static SkImageInfo MakeS32(int width, int height, SkAlphaType at)

◆ DEF_TEST() [5/19]

DEF_TEST ( Image_MakeFromRasterBitmap  ,
reporter   
)

Definition at line 252 of file ImageTest.cpp.

252 {
253 const struct {
254 SkCopyPixelsMode fCPM;
255 bool fExpectSameAsMutable;
256 bool fExpectSameAsImmutable;
257 } recs[] = {
258 { kIfMutable_SkCopyPixelsMode, false, true },
259 { kAlways_SkCopyPixelsMode, false, false },
260 { kNever_SkCopyPixelsMode, true, true },
261 };
262 for (auto rec : recs) {
263 SkPixmap pm;
264 SkBitmap bm;
265 bm.allocN32Pixels(100, 100);
266
267 auto img = SkMakeImageFromRasterBitmap(bm, rec.fCPM);
268 REPORTER_ASSERT(reporter, img->peekPixels(&pm));
269 const bool sameMutable = pm.addr32(0, 0) == bm.getAddr32(0, 0);
270 REPORTER_ASSERT(reporter, rec.fExpectSameAsMutable == sameMutable);
271 REPORTER_ASSERT(reporter, (bm.getGenerationID() == img->uniqueID()) == sameMutable);
272
273 bm.notifyPixelsChanged(); // force a new generation ID
274
275 bm.setImmutable();
276 img = SkMakeImageFromRasterBitmap(bm, rec.fCPM);
277 REPORTER_ASSERT(reporter, img->peekPixels(&pm));
278 const bool sameImmutable = pm.addr32(0, 0) == bm.getAddr32(0, 0);
279 REPORTER_ASSERT(reporter, rec.fExpectSameAsImmutable == sameImmutable);
280 REPORTER_ASSERT(reporter, (bm.getGenerationID() == img->uniqueID()) == sameImmutable);
281 }
282}
SK_SPI sk_sp< SkImage > SkMakeImageFromRasterBitmap(const SkBitmap &, SkCopyPixelsMode)
SkCopyPixelsMode
Definition: SkImagePriv.h:17
@ kNever_SkCopyPixelsMode
never copy src pixels (even if they are marked mutable)
Definition: SkImagePriv.h:20
@ kIfMutable_SkCopyPixelsMode
only copy src pixels if they are marked mutable
Definition: SkImagePriv.h:18
@ kAlways_SkCopyPixelsMode
always copy src pixels (even if they are marked immutable)
Definition: SkImagePriv.h:19
void notifyPixelsChanged() const
Definition: SkBitmap.cpp:359
uint32_t getGenerationID() const
Definition: SkBitmap.cpp:355
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:226

◆ DEF_TEST() [6/19]

DEF_TEST ( image_newfrombitmap  ,
reporter   
)

Definition at line 362 of file ImageTest.cpp.

362 {
363 const struct {
364 void (*fMakeProc)(SkBitmap*);
365 bool fExpectPeekSuccess;
366 bool fExpectSharedID;
367 bool fExpectLazy;
368 } rec[] = {
369 { make_bitmap_mutable, true, false, false },
370 { make_bitmap_immutable, true, true, false },
371 };
372
373 for (size_t i = 0; i < std::size(rec); ++i) {
374 SkBitmap bm;
375 rec[i].fMakeProc(&bm);
376
378 SkPixmap pmap;
379
380 const bool sharedID = (image->uniqueID() == bm.getGenerationID());
381 REPORTER_ASSERT(reporter, sharedID == rec[i].fExpectSharedID);
382
383 const bool peekSuccess = image->peekPixels(&pmap);
384 REPORTER_ASSERT(reporter, peekSuccess == rec[i].fExpectPeekSuccess);
385
386 const bool lazy = image->isLazyGenerated();
387 REPORTER_ASSERT(reporter, lazy == rec[i].fExpectLazy);
388 }
389}
static void make_bitmap_mutable(SkBitmap *bm)
Definition: ImageTest.cpp:353
static void make_bitmap_immutable(SkBitmap *bm)
Definition: ImageTest.cpp:357
uint32_t uniqueID() const
Definition: SkImage.h:309
virtual bool isLazyGenerated() const =0
bool peekPixels(SkPixmap *pixmap) const
Definition: SkImage.cpp:34

◆ DEF_TEST() [7/19]

DEF_TEST ( Image_nonfinite_dst  ,
reporter   
)

Definition at line 1515 of file ImageTest.cpp.

1515 {
1517 auto img = any_image_will_do();
1518
1519 for (SkScalar bad : { SK_ScalarInfinity, SK_ScalarNaN}) {
1520 for (int bits = 1; bits <= 15; ++bits) {
1521 SkRect dst = { 0, 0, 10, 10 };
1522 if (bits & 1) dst.fLeft = bad;
1523 if (bits & 2) dst.fTop = bad;
1524 if (bits & 4) dst.fRight = bad;
1525 if (bits & 8) dst.fBottom = bad;
1526
1527 surf->getCanvas()->drawImageRect(img, dst, SkSamplingOptions());
1528
1529 // we should draw nothing
1530 ToolUtils::PixelIter iter(surf.get());
1531 while (void* addr = iter.next()) {
1532 REPORTER_ASSERT(reporter, *(SkPMColor*)addr == 0);
1533 }
1534 }
1535 }
1536}
static sk_sp< SkImage > any_image_will_do()
Definition: ImageTest.cpp:1511
#define SK_ScalarNaN
Definition: SkScalar.h:26
#define SK_ScalarInfinity
Definition: SkScalar.h:24
float SkScalar
Definition: extension.cpp:12
dst
Definition: cp.py:12
uint32_t bits
Definition: skcms.cc:51

◆ DEF_TEST() [8/19]

DEF_TEST ( Image_RetainSnapshot  ,
reporter   
)

Definition at line 319 of file ImageTest.cpp.

319 {
320 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0);
321 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0);
324 surface->getCanvas()->clear(0xFF00FF00);
325
326 SkPMColor pixels[4];
327 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect
328 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2);
329 const size_t dstRowBytes = 2 * sizeof(SkPMColor);
330
331 sk_sp<SkImage> image1(surface->makeImageSnapshot());
332 REPORTER_ASSERT(reporter, image1->readPixels(nullptr, dstInfo, pixels, dstRowBytes, 0, 0));
333 for (size_t i = 0; i < std::size(pixels); ++i) {
334 REPORTER_ASSERT(reporter, pixels[i] == green);
335 }
336
340
341 surface->getCanvas()->drawRect(SkRect::MakeXYWH(1, 1, 1, 1), paint);
342
343 sk_sp<SkImage> image2(surface->makeImageSnapshot());
344 REPORTER_ASSERT(reporter, image2->readPixels(nullptr, dstInfo, pixels, dstRowBytes, 0, 0));
345 REPORTER_ASSERT(reporter, pixels[0] == green);
346 REPORTER_ASSERT(reporter, pixels[1] == green);
347 REPORTER_ASSERT(reporter, pixels[2] == green);
348 REPORTER_ASSERT(reporter, pixels[3] == red);
349}
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151

◆ DEF_TEST() [9/19]

DEF_TEST ( image_roundtrip_encode  ,
reporter   
)

Definition at line 1401 of file ImageTest.cpp.

1401 {
1402 SkBitmap bm0;
1403 make_all_premul(&bm0);
1404
1405 auto img0 = bm0.asImage();
1406 sk_sp<SkData> data = SkPngEncoder::Encode(nullptr, img0.get(), {});
1407 auto img1 = SkImages::DeferredFromEncodedData(data);
1408
1409 SkBitmap bm1;
1411 img1->readPixels(nullptr, bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0);
1412
1413 REPORTER_ASSERT(reporter, equal(bm0, bm1));
1414}
static bool equal(const SkBitmap &a, const SkBitmap &b)
Definition: ImageTest.cpp:1386
static void make_all_premul(SkBitmap *bm)
Definition: ImageTest.cpp:1375

◆ DEF_TEST() [10/19]

DEF_TEST ( image_roundtrip_premul  ,
reporter   
)

Definition at line 1416 of file ImageTest.cpp.

1416 {
1417 SkBitmap bm0;
1418 make_all_premul(&bm0);
1419
1420 SkBitmap bm1;
1422 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0);
1423
1424 SkBitmap bm2;
1426 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0);
1427
1428 REPORTER_ASSERT(reporter, equal(bm0, bm2));
1429}
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
Definition: SkBitmap.cpp:482

◆ DEF_TEST() [11/19]

DEF_TEST ( Image_Serialize_Encoding_Failure  ,
reporter   
)

Definition at line 285 of file ImageTest.cpp.

285 {
287 surface->getCanvas()->clear(SK_ColorGREEN);
288 sk_sp<SkImage> image(surface->makeImageSnapshot());
290
291 SkPictureRecorder recorder;
292 SkCanvas* canvas = recorder.beginRecording(100, 100);
293 canvas->drawImage(image.get(), 0, 0, SkSamplingOptions());
295 REPORTER_ASSERT(reporter, picture);
297
298 bool was_called = false;
299 SkSerialProcs procs;
300 procs.fImageProc = [](SkImage*, void* called) {
301 *(bool*)called = true;
302 return SkData::MakeEmpty();
303 };
304 procs.fImageCtx = &was_called;
305
306 REPORTER_ASSERT(reporter, !was_called);
307 auto data = picture->serialize(&procs);
308 REPORTER_ASSERT(reporter, was_called);
309 REPORTER_ASSERT(reporter, data && data->size() > 0);
310
311 auto deserialized = SkPicture::MakeFromData(data->data(), data->size());
312 REPORTER_ASSERT(reporter, deserialized);
313 REPORTER_ASSERT(reporter, deserialized->approximateOpCount() > 0);
314}
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1455
static sk_sp< SkData > MakeEmpty()
Definition: SkData.cpp:94
sk_sp< SkData > serialize(const SkSerialProcs *procs=nullptr) const
Definition: SkPicture.cpp:249
static sk_sp< SkPicture > MakeFromData(const SkData *data, const SkDeserialProcs *procs=nullptr)
Definition: SkPicture.cpp:160
virtual int approximateOpCount(bool nested=false) const =0
sk_sp< const SkPicture > picture
Definition: SkRecords.h:292
void * fImageCtx
Definition: SkSerialProcs.h:74
SkSerialImageProc fImageProc
Definition: SkSerialProcs.h:73

◆ DEF_TEST() [12/19]

DEF_TEST ( image_subset_encode_skbug_7752  ,
reporter   
)

Definition at line 1657 of file ImageTest.cpp.

1657 {
1658 sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_128.png");
1659 const int W = image->width();
1660 const int H = image->height();
1661
1662 auto check_roundtrip = [&](sk_sp<SkImage> img) {
1663 auto img2 = SkImages::DeferredFromEncodedData(SkPngEncoder::Encode(nullptr, img.get(), {}));
1664 REPORTER_ASSERT(reporter, ToolUtils::equal_pixels(img.get(), img2.get()));
1665 };
1666 check_roundtrip(image); // should trivially pass
1667 check_roundtrip(image->makeSubset(nullptr, {0, 0, W/2, H/2}));
1668 check_roundtrip(image->makeSubset(nullptr, {W/2, H/2, W, H}));
1669 check_roundtrip(image->makeColorSpace(nullptr, SkColorSpace::MakeSRGBLinear()));
1670}
#define W
Definition: aaa.cpp:17
static sk_sp< SkColorSpace > MakeSRGBLinear()
virtual sk_sp< SkImage > makeColorSpace(GrDirectContext *direct, sk_sp< SkColorSpace > target) const =0
virtual sk_sp< SkImage > makeSubset(GrDirectContext *direct, const SkIRect &subset) const =0
bool equal_pixels(const SkPixmap &a, const SkPixmap &b)
Definition: ToolUtils.cpp:498
Definition: SkMD5.cpp:129

◆ DEF_TEST() [13/19]

DEF_TEST ( ImageDataRef  ,
reporter   
)

Definition at line 717 of file ImageTest.cpp.

717 {
719 size_t rowBytes = info.minRowBytes();
720 size_t size = info.computeByteSize(rowBytes);
722 REPORTER_ASSERT(reporter, data->unique());
724 REPORTER_ASSERT(reporter, !data->unique());
725 image.reset();
726 REPORTER_ASSERT(reporter, data->unique());
727}
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ DEF_TEST() [14/19]

DEF_TEST ( ImageEmpty  ,
reporter   
)

Definition at line 707 of file ImageTest.cpp.

707 {
708 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
709 SkPixmap pmap(info, nullptr, 0);
711 REPORTER_ASSERT(reporter, nullptr == SkImages::RasterFromData(info, nullptr, 0));
712 REPORTER_ASSERT(reporter, nullptr == SkImages::RasterFromPixmap(pmap, nullptr, nullptr));
714 nullptr == SkImages::DeferredFromGenerator(std::make_unique<EmptyGenerator>()));
715}
SK_API sk_sp< SkImage > DeferredFromGenerator(std::unique_ptr< SkImageGenerator > imageGenerator)
SK_API sk_sp< SkImage > RasterFromPixmapCopy(const SkPixmap &pixmap)

◆ DEF_TEST() [15/19]

DEF_TEST ( ImageEncode  ,
reporter   
)

Definition at line 240 of file ImageTest.cpp.

240 {
241 test_encode(reporter, nullptr, create_image().get());
242}

◆ DEF_TEST() [16/19]

DEF_TEST ( ImageLegacyBitmap  ,
reporter   
)

Definition at line 851 of file ImageTest.cpp.

851 {
854
857
858 RasterDataHolder dataHolder;
859 image = create_rasterproc_image(&dataHolder);
861 image.reset();
862 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount);
863
866}
static sk_sp< SkImage > create_rasterproc_image(RasterDataHolder *dataHolder)
Definition: ImageTest.cpp:192

◆ DEF_TEST() [17/19]

DEF_TEST ( ImagePeek  ,
reporter   
)

Definition at line 895 of file ImageTest.cpp.

895 {
897 test_peek(reporter, image.get(), true);
898
900 test_peek(reporter, image.get(), true);
901
902 RasterDataHolder dataHolder;
903 image = create_rasterproc_image(&dataHolder);
904 test_peek(reporter, image.get(), true);
905 image.reset();
906 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount);
907
909 test_peek(reporter, image.get(), false);
910}

◆ DEF_TEST() [18/19]

DEF_TEST ( ImageReadPixels  ,
reporter   
)

Definition at line 789 of file ImageTest.cpp.

789 {
792
795
796 RasterDataHolder dataHolder;
797 image = create_rasterproc_image(&dataHolder);
799 image.reset();
800 REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount);
801
804}

◆ DEF_TEST() [19/19]

DEF_TEST ( ImageScalePixels  ,
reporter   
)

Definition at line 1479 of file ImageTest.cpp.

1479 {
1480 const SkPMColor pmRed = SkPackARGB32(0xFF, 0xFF, 0, 0);
1481 const SkColor red = SK_ColorRED;
1482
1483 // Test raster image
1486 surface->getCanvas()->clear(red);
1487 sk_sp<SkImage> rasterImage = surface->makeImageSnapshot();
1488 test_scale_pixels(reporter, rasterImage.get(), pmRed);
1489
1490 // Test encoded image
1491 sk_sp<SkData> data = SkPngEncoder::Encode(nullptr, rasterImage.get(), {});
1493 test_scale_pixels(reporter, codecImage.get(), pmRed);
1494}

◆ draw_image_test_pattern()

static void draw_image_test_pattern ( SkCanvas canvas)
static

Definition at line 132 of file ImageTest.cpp.

132 {
133 canvas->clear(SK_ColorWHITE);
136 canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint);
137}
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1635

◆ equal()

static bool equal ( const SkBitmap a,
const SkBitmap b 
)
static

Definition at line 1386 of file ImageTest.cpp.

1386 {
1387 SkASSERT(a.width() == b.width());
1388 SkASSERT(a.height() == b.height());
1389 for (int y = 0; y < a.height(); ++y) {
1390 for (int x = 0; x < a.width(); ++x) {
1391 SkPMColor pa = *a.getAddr32(x, y);
1392 SkPMColor pb = *b.getAddr32(x, y);
1393 if (pa != pb) {
1394 return false;
1395 }
1396 }
1397 }
1398 return true;
1399}

◆ gCentripetalCatmulRom()

constexpr SkM44 gCentripetalCatmulRom ( 0.0f/  2,
-1.0f/  2,
2.0f/  2,
-1.0f/  2,
2.0f/  2,
0.0f/  2,
-5.0f/  2,
3.0f/  2,
0.0f/  2,
1.0f/  2,
4.0f/  2,
-3.0f/  2,
0.0f/  2,
0.0f/  2,
-1.0f/  2,
1.0f/  2 
)
constexpr

◆ gMitchellNetravali()

constexpr SkM44 gMitchellNetravali ( 1.0f/  18,
-9.0f/  18,
15.0f/  18,
-7.0f/  18,
16.0f/  18,
0.0f/  18,
-36.0f/  18,
21.0f/  18,
1.0f/  18,
9.0f/  18,
27.0f/  18,
-21.0f/  18,
0.0f/  18,
0.0f/  18,
-6.0f/  18,
7.0f/  18 
)
constexpr

◆ has_pixels()

static bool has_pixels ( const SkPMColor  pixels[],
int  count,
SkPMColor  expected 
)
static

Definition at line 729 of file ImageTest.cpp.

729 {
730 for (int i = 0; i < count; ++i) {
731 if (pixels[i] != expected) {
732 return false;
733 }
734 }
735 return true;
736}
int count
Definition: FontMgrTest.cpp:49

◆ image_test_read_pixels()

static void image_test_read_pixels ( GrDirectContext dContext,
skiatest::Reporter reporter,
SkImage image 
)
static

Definition at line 738 of file ImageTest.cpp.

739 {
740 if (!image) {
741 ERRORF(reporter, "Failed to create image!");
742 return;
743 }
745 const SkPMColor notExpected = ~expected;
746
747 const int w = 2, h = 2;
748 const size_t rowBytes = w * sizeof(SkPMColor);
749 SkPMColor pixels[w*h];
750
752
754 REPORTER_ASSERT(reporter, !image->readPixels(dContext, info, pixels, rowBytes, 0, 0));
755
756 // out-of-bounds should fail
758 REPORTER_ASSERT(reporter, !image->readPixels(dContext, info, pixels, rowBytes, -w, 0));
759 REPORTER_ASSERT(reporter, !image->readPixels(dContext, info, pixels, rowBytes, 0, -h));
760 REPORTER_ASSERT(reporter, !image->readPixels(dContext, info, pixels, rowBytes,
761 image->width(), 0));
762 REPORTER_ASSERT(reporter, !image->readPixels(dContext, info, pixels, rowBytes,
763 0, image->height()));
764
765 // top-left should succeed
766 SkOpts::memset32(pixels, notExpected, w*h);
767 REPORTER_ASSERT(reporter, image->readPixels(dContext, info, pixels, rowBytes, 0, 0));
768 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h, expected));
769
770 // bottom-right should succeed
771 SkOpts::memset32(pixels, notExpected, w*h);
772 REPORTER_ASSERT(reporter, image->readPixels(dContext, info, pixels, rowBytes,
773 image->width() - w, image->height() - h));
774 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h, expected));
775
776 // partial top-left should succeed
777 SkOpts::memset32(pixels, notExpected, w*h);
778 REPORTER_ASSERT(reporter, image->readPixels(dContext, info, pixels, rowBytes, -1, -1));
779 REPORTER_ASSERT(reporter, pixels[3] == expected);
780 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h - 1, notExpected));
781
782 // partial bottom-right should succeed
783 SkOpts::memset32(pixels, notExpected, w*h);
784 REPORTER_ASSERT(reporter, image->readPixels(dContext, info, pixels, rowBytes,
785 image->width() - 1, image->height() - 1));
786 REPORTER_ASSERT(reporter, pixels[0] == expected);
787 REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected));
788}
static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected)
Definition: ImageTest.cpp:729
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
Definition: SkColor.cpp:21
void(* memset32)(uint32_t[], uint32_t, int)
SkScalar w
SkScalar h
static SkImageInfo MakeUnknown()
Definition: SkImageInfo.h:343

◆ make_all_premul()

static void make_all_premul ( SkBitmap bm)
static

Definition at line 1375 of file ImageTest.cpp.

1375 {
1377 for (int a = 0; a < 256; ++a) {
1378 for (int r = 0; r < 256; ++r) {
1379 // make all valid premul combinations
1380 int c = std::min(a, r);
1381 *bm->getAddr32(a, r) = SkPackARGB32(a, c, c, c);
1382 }
1383 }
1384}

◆ make_bitmap_immutable()

static void make_bitmap_immutable ( SkBitmap bm)
static

Definition at line 357 of file ImageTest.cpp.

357 {
358 bm->allocN32Pixels(10, 10);
359 bm->setImmutable();
360}

◆ make_bitmap_mutable()

static void make_bitmap_mutable ( SkBitmap bm)
static

Definition at line 353 of file ImageTest.cpp.

353 {
354 bm->allocN32Pixels(10, 10);
355}

◆ make_yuva_image()

static sk_sp< SkImage > make_yuva_image ( GrDirectContext dContext)
static

Definition at line 1538 of file ImageTest.cpp.

1538 {
1541 SkYUVAInfo yuvaInfo({1, 1},
1545 const SkPixmap pmaps[] = {pm, pm, pm};
1546 auto yuvaPixmaps = SkYUVAPixmaps::FromExternalPixmaps(yuvaInfo, pmaps);
1547
1548 return SkImages::TextureFromYUVAPixmaps(dContext, yuvaPixmaps);
1549}
@ kJPEG_Full_SkYUVColorSpace
describes full range
Definition: SkImageInfo.h:69
@ kY_U_V
Plane 0: Y, Plane 1: U, Plane 2: V.
@ k444
No subsampling. UV values for each Y.
static SkYUVAPixmaps FromExternalPixmaps(const SkYUVAInfo &, const SkPixmap[kMaxPlanes])
SK_API sk_sp< SkImage > TextureFromYUVAPixmaps(GrRecordingContext *context, const SkYUVAPixmaps &pixmaps, skgpu::Mipmapped buildMips, bool limitToMaxTextureSize, sk_sp< SkColorSpace > imageColorSpace)

◆ read_pixels_info()

SkImageInfo read_pixels_info ( SkImage image)

Definition at line 97 of file ImageTest.cpp.

97 {
98 if (image->colorSpace()) {
100 }
101
103}

◆ test_cross_context_image()

static void test_cross_context_image ( skiatest::Reporter reporter,
const GrContextOptions options,
const char *  testName,
std::function< sk_sp< SkImage >(GrDirectContext *)>  imageMaker 
)
static

Definition at line 982 of file ImageTest.cpp.

984 {
985 for (int i = 0; i < skgpu::kContextTypeCount; ++i) {
986 GrContextFactory testFactory(options);
987 skgpu::ContextType ctxType = static_cast<skgpu::ContextType>(i);
988 ContextInfo ctxInfo = testFactory.getContextInfo(ctxType);
989 auto dContext = ctxInfo.directContext();
990 if (!dContext) {
991 continue;
992 }
993
994 // If we don't have proper support for this feature, the factory will fallback to returning
995 // codec-backed images. Those will "work", but some of our checks will fail because we
996 // expect the cross-context images not to work on multiple contexts at once.
997 if (!dContext->priv().caps()->crossContextTextureSupport()) {
998 continue;
999 }
1000
1001 // We test three lifetime patterns for a single context:
1002 // 1) Create image, free image
1003 // 2) Create image, draw, flush, free image
1004 // 3) Create image, draw, free image, flush
1005 // ... and then repeat the last two patterns with drawing on a second* context:
1006 // 4) Create image, draw*, flush*, free image
1007 // 5) Create image, draw*, free image, flush*
1008
1009 // Case #1: Create image, free image
1010 {
1011 sk_sp<SkImage> refImg(imageMaker(dContext));
1012 refImg.reset(nullptr); // force a release of the image
1013 }
1014
1017 if (!surface) {
1018 ERRORF(reporter, "SkSurfaces::RenderTarget failed for %s.", testName);
1019 continue;
1020 }
1021
1022 SkCanvas* canvas = surface->getCanvas();
1023
1024 // Case #2: Create image, draw, flush, free image
1025 {
1026 sk_sp<SkImage> refImg(imageMaker(dContext));
1027
1028 canvas->drawImage(refImg, 0, 0);
1029 dContext->flushAndSubmit(surface.get(), GrSyncCpu::kNo);
1030
1031 refImg.reset(nullptr); // force a release of the image
1032 }
1033
1034 // Case #3: Create image, draw, free image, flush
1035 {
1036 sk_sp<SkImage> refImg(imageMaker(dContext));
1037
1038 canvas->drawImage(refImg, 0, 0);
1039 refImg.reset(nullptr); // force a release of the image
1040
1041 dContext->flushAndSubmit(surface.get(), GrSyncCpu::kNo);
1042 }
1043
1044 // Configure second context
1045 sk_gpu_test::TestContext* testContext = ctxInfo.testContext();
1046
1047 ContextInfo otherContextInfo = testFactory.getSharedContextInfo(dContext);
1048 auto otherCtx = otherContextInfo.directContext();
1049 sk_gpu_test::TestContext* otherTestContext = otherContextInfo.testContext();
1050
1051 // Creating a context in a share group may fail
1052 if (!otherCtx) {
1053 continue;
1054 }
1055
1057 canvas = surface->getCanvas();
1058
1059 // Case #4: Create image, draw*, flush*, free image
1060 {
1061 testContext->makeCurrent();
1062 sk_sp<SkImage> refImg(imageMaker(dContext));
1063
1064 otherTestContext->makeCurrent();
1065 canvas->drawImage(refImg, 0, 0);
1066 otherCtx->flushAndSubmit(surface.get(), GrSyncCpu::kNo);
1067
1068 testContext->makeCurrent();
1069 refImg.reset(nullptr); // force a release of the image
1070 }
1071
1072 // Case #5: Create image, draw*, free image, flush*
1073 {
1074 testContext->makeCurrent();
1075 sk_sp<SkImage> refImg(imageMaker(dContext));
1076
1077 otherTestContext->makeCurrent();
1078 canvas->drawImage(refImg, 0, 0);
1079
1080 testContext->makeCurrent();
1081 refImg.reset(nullptr); // force a release of the image
1082
1083 otherTestContext->makeCurrent();
1084 // Sync is specifically here for vulkan to guarantee the command buffer will finish
1085 // which is when we call the ReleaseProc.
1086 otherCtx->flushAndSubmit(surface.get(), GrSyncCpu::kYes);
1087 }
1088
1089 // Case #6: Verify that only one context can be using the image at a time
1090 {
1091 // Suppress warnings about trying to use a texture in two contexts.
1092 GrRecordingContextPriv::AutoSuppressWarningMessages aswm(otherCtx);
1093
1094 testContext->makeCurrent();
1095 sk_sp <SkImage> refImg(imageMaker(dContext));
1096 GrSurfaceProxyView view, otherView, viewSecondRef;
1097
1098 // Any context should be able to borrow the texture at this point
1099
1100 std::tie(view, std::ignore) =
1101 skgpu::ganesh::AsView(dContext, refImg, skgpu::Mipmapped::kNo);
1103
1104 // But once it's borrowed, no other context should be able to borrow
1105 otherTestContext->makeCurrent();
1106 std::tie(otherView, std::ignore) =
1107 skgpu::ganesh::AsView(otherCtx, refImg, skgpu::Mipmapped::kNo);
1108 REPORTER_ASSERT(reporter, !otherView);
1109
1110 // Original context (that's already borrowing) should be okay
1111 testContext->makeCurrent();
1112 std::tie(viewSecondRef, std::ignore) =
1113 skgpu::ganesh::AsView(dContext, refImg, skgpu::Mipmapped::kNo);
1114 REPORTER_ASSERT(reporter, viewSecondRef);
1115
1116 // Release first ref from the original context
1117 view.reset();
1118
1119 // We released one proxy but not the other from the current borrowing context. Make sure
1120 // a new context is still not able to borrow the texture.
1121 otherTestContext->makeCurrent();
1122 std::tie(otherView, std::ignore) =
1123 skgpu::ganesh::AsView(otherCtx, refImg, skgpu::Mipmapped::kNo);
1124 REPORTER_ASSERT(reporter, !otherView);
1125
1126 // Release second ref from the original context
1127 testContext->makeCurrent();
1128 viewSecondRef.reset();
1129
1130 // Now we should be able to borrow the texture from the other context
1131 otherTestContext->makeCurrent();
1132 std::tie(otherView, std::ignore) =
1133 skgpu::ganesh::AsView(otherCtx, refImg, skgpu::Mipmapped::kNo);
1134 REPORTER_ASSERT(reporter, otherView);
1135
1136 // Release everything
1137 otherView.reset();
1138 refImg.reset(nullptr);
1139 }
1140 }
1141}

◆ test_encode()

static void test_encode ( skiatest::Reporter reporter,
GrDirectContext dContext,
SkImage image 
)
static

Definition at line 219 of file ImageTest.cpp.

219 {
220 const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10);
221 sk_sp<SkData> origEncoded = SkPngEncoder::Encode(dContext, image, {});
222 REPORTER_ASSERT(reporter, origEncoded);
223 REPORTER_ASSERT(reporter, origEncoded->size() > 0);
224
226 if (!decoded) {
227 ERRORF(reporter, "failed to decode image!");
228 return;
229 }
230 REPORTER_ASSERT(reporter, decoded);
231 assert_equal(reporter, dContext, image, nullptr, decoded.get());
232
233 // Now see if we can instantiate an image from a subset of the surface/origEncoded
234
235 decoded = SkImages::DeferredFromEncodedData(origEncoded)->makeSubset(nullptr, ir);
236 REPORTER_ASSERT(reporter, decoded);
237 assert_equal(reporter, dContext, image, &ir, decoded.get());
238}
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104

◆ test_legacy_bitmap()

static void test_legacy_bitmap ( skiatest::Reporter reporter,
GrDirectContext dContext,
const SkImage image 
)
static

Definition at line 830 of file ImageTest.cpp.

831 {
832 if (!image) {
833 ERRORF(reporter, "Failed to create image.");
834 return;
835 }
839
840 // Test subsetting to exercise the rowBytes logic.
841 SkBitmap tmp;
842 REPORTER_ASSERT(reporter, bitmap.extractSubset(&tmp, SkIRect::MakeWH(image->width() / 2,
843 image->height() / 2)));
844 sk_sp<SkImage> subsetImage(tmp.asImage());
845 REPORTER_ASSERT(reporter, subsetImage.get());
846
847 SkBitmap subsetBitmap;
848 REPORTER_ASSERT(reporter, subsetImage->asLegacyBitmap(&subsetBitmap));
849 check_legacy_bitmap(reporter, nullptr, subsetImage.get(), subsetBitmap);
850}
static void check_legacy_bitmap(skiatest::Reporter *reporter, GrDirectContext *dContext, const SkImage *image, const SkBitmap &bitmap)
Definition: ImageTest.cpp:813
bool asLegacyBitmap(SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const
Definition: SkImage.cpp:224
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56

◆ test_peek()

static void test_peek ( skiatest::Reporter reporter,
SkImage image,
bool  expectPeekSuccess 
)
static

Definition at line 876 of file ImageTest.cpp.

876 {
877 if (!image) {
878 ERRORF(reporter, "Failed to create image!");
879 return;
880 }
881 SkPixmap pm;
882 bool success = image->peekPixels(&pm);
883 REPORTER_ASSERT(reporter, expectPeekSuccess == success);
884 if (success) {
885 const SkImageInfo& info = pm.info();
886 REPORTER_ASSERT(reporter, 20 == info.width());
887 REPORTER_ASSERT(reporter, 20 == info.height());
888 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType());
890 kOpaque_SkAlphaType == info.alphaType());
891 REPORTER_ASSERT(reporter, info.minRowBytes() <= pm.rowBytes());
893 }
894}
size_t rowBytes() const
Definition: SkPixmap.h:145
const SkImageInfo & info() const
Definition: SkPixmap.h:135

◆ test_scale_pixels()

static void test_scale_pixels ( skiatest::Reporter reporter,
const SkImage image,
uint32_t  expected 
)
static

Definition at line 1462 of file ImageTest.cpp.

1463 {
1465
1466 // Make sure to test kDisallow first, so we don't just get a cache hit in that case
1468 SkAutoPixmapStorage scaled;
1469 scaled.alloc(info);
1471 ERRORF(reporter, "Failed to scale image");
1472 continue;
1473 }
1474
1475 check_scaled_pixels(reporter, &scaled, expected);
1476 }
1477}
static void check_scaled_pixels(skiatest::Reporter *reporter, SkPixmap *pmap, uint32_t expected)
Definition: ImageTest.cpp:1448
@ kDisallow_CachingHint
disallows internally caching decoded and copied pixels
Definition: SkImage.h:463
@ kAllow_CachingHint
allows internally caching decoded and copied pixels
Definition: SkImage.h:462
bool scalePixels(const SkPixmap &dst, const SkSamplingOptions &, CachingHint cachingHint=kAllow_CachingHint) const
Definition: SkImage.cpp:118