Flutter Engine
The Flutter Engine
Classes | Macros | Functions
SurfaceTest.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/SkColorFilter.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkOverdrawCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRRect.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkRegion.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkColorMatrix.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/SkDebug.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkTo.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "src/core/SkCanvasPriv.h"
#include "src/gpu/ganesh/Device.h"
#include "src/gpu/ganesh/GrCanvas.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrColorInfo.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrGpu.h"
#include "src/gpu/ganesh/GrRenderTarget.h"
#include "src/gpu/ganesh/GrRenderTargetProxy.h"
#include "src/gpu/ganesh/GrResourceProvider.h"
#include "src/gpu/ganesh/GrTextureProxy.h"
#include "src/gpu/ganesh/SurfaceContext.h"
#include "src/gpu/ganesh/SurfaceFillContext.h"
#include "src/gpu/ganesh/image/GrImageUtils.h"
#include "src/gpu/ganesh/surface/SkSurface_Ganesh.h"
#include "src/image/SkImage_Base.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tests/TestHarness.h"
#include "tools/RuntimeBlendUtils.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/gpu/BackendSurfaceFactory.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include "tools/gpu/ProxyUtils.h"
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <limits>
#include <memory>
#include <utility>

Go to the source code of this file.

Classes

struct  ReleaseChecker
 

Macros

#define EXPECT_COPY_ON_WRITE(command)
 

Functions

static void release_direct_surface_storage (void *pixels, void *context)
 
static sk_sp< SkSurfacecreate_surface (SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
 
static sk_sp< SkSurfacecreate_direct_surface (SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
 
static sk_sp< SkSurfacecreate_gpu_surface (GrRecordingContext *rContext, SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
 
static sk_sp< SkSurfacecreate_gpu_scratch_surface (GrRecordingContext *rContext, SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
 
 DEF_TEST (SurfaceEmpty, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceEmpty_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (GrContext_colorTypeSupportedAsSurface, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (GrContext_maxSurfaceSamplesForColorType, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void test_canvas_peek (skiatest::Reporter *reporter, sk_sp< SkSurface > &surface, const SkImageInfo &requestInfo, bool expectPeekSuccess)
 
 DEF_TEST (SurfaceCanvasPeek, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceCanvasPeek_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void test_snapshot_alphatype (skiatest::Reporter *reporter, const sk_sp< SkSurface > &surface, SkAlphaType expectedAlphaType)
 
 DEF_TEST (SurfaceSnapshotAlphaType, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceSnapshotAlphaType_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void test_backend_texture_access_copy_on_write (skiatest::Reporter *reporter, SkSurface *surface, SkSurface::BackendHandleAccess access)
 
static void test_backend_rendertarget_access_copy_on_write (skiatest::Reporter *reporter, SkSurface *surface, SkSurface::BackendHandleAccess access)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceBackendSurfaceAccessCopyOnWrite_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
template<typename Type , Type(*)(SkSurface *, SkSurface::BackendHandleAccess) func>
static void test_backend_unique_id (skiatest::Reporter *reporter, SkSurface *surface)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceBackendHandleAccessIDs_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceAbandonPostFlush_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceBackendAccessAbandoned_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void test_copy_on_write (skiatest::Reporter *reporter, SkSurface *surface)
 
 DEF_TEST (SurfaceCopyOnWrite, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceCopyOnWrite_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void test_writable_after_snapshot_release (skiatest::Reporter *reporter, SkSurface *surface)
 
 DEF_TEST (SurfaceWriteableAfterSnapshotRelease, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceWriteableAfterSnapshotRelease_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void test_crbug263329 (skiatest::Reporter *reporter, SkSurface *surface1, SkSurface *surface2)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceCRBug263329_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_TEST (SurfaceGetTexture, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfacepeekTexture_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static skgpu::Budgeted is_budgeted (const sk_sp< SkSurface > &surf)
 
static skgpu::Budgeted is_budgeted (SkImage *image, GrRecordingContext *rc)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceBudget, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void test_no_canvas1 (skiatest::Reporter *reporter, SkSurface *surface, SkSurface::ContentChangeMode mode)
 
static void test_no_canvas2 (skiatest::Reporter *reporter, SkSurface *surface, SkSurface::ContentChangeMode mode)
 
 DEF_TEST (SurfaceNoCanvas, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceNoCanvas_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void check_rowbytes_remain_consistent (SkSurface *surface, skiatest::Reporter *reporter)
 
 DEF_TEST (surface_rowbytes, reporter)
 
 DEF_TEST (surface_raster_zeroinitialized, reporter)
 
static sk_sp< SkSurfacecreate_gpu_surface_backend_texture (GrDirectContext *dContext, int sampleCnt, const SkColor4f &color)
 
static bool supports_readpixels (const GrCaps *caps, SkSurface *surface)
 
static sk_sp< SkSurfacecreate_gpu_surface_backend_render_target (GrDirectContext *dContext, int sampleCnt, const SkColor4f &color)
 
static void test_surface_context_clear (skiatest::Reporter *reporter, GrDirectContext *dContext, skgpu::ganesh::SurfaceContext *surfaceContext, uint32_t expectedValue)
 
 DEF_GANESH_TEST_FOR_GL_CONTEXT (SurfaceClear_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void test_surface_draw_partially (skiatest::Reporter *reporter, sk_sp< SkSurface > surface, SkColor origColor)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfacePartialDraw_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SurfaceWrappedWithRelease_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_GL_CONTEXT (SurfaceAttachStencil_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ReplaceSurfaceBackendTexture, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void test_overdraw_surface (skiatest::Reporter *r, SkSurface *surface)
 
 DEF_TEST (OverdrawSurface_Raster, r)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (OverdrawSurface_Gpu, r, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_TEST (Surface_null, r)
 
 DEF_TEST (surface_image_unity, reporter)
 

Macro Definition Documentation

◆ EXPECT_COPY_ON_WRITE

#define EXPECT_COPY_ON_WRITE (   command)
Value:
{ \
sk_sp<SkImage> imageBefore = surface->makeImageSnapshot(); \
sk_sp<SkImage> aur_before(imageBefore); /*NOLINT*/ \
canvas-> command ; \
sk_sp<SkImage> imageAfter = surface->makeImageSnapshot(); \
sk_sp<SkImage> aur_after(imageAfter); /*NOLINT*/ \
REPORTER_ASSERT(reporter, imageBefore != imageAfter); \
}
reporter
Definition: FontMgrTest.cpp:39
VkSurfaceKHR surface
Definition: main.cc:49
list command
Definition: valgrind.py:24

Function Documentation

◆ check_rowbytes_remain_consistent()

static void check_rowbytes_remain_consistent ( SkSurface surface,
skiatest::Reporter reporter 
)
static

Definition at line 748 of file SurfaceTest.cpp.

748 {
749 SkPixmap surfacePM;
750 REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM));
751
752 sk_sp<SkImage> image(surface->makeImageSnapshot());
753 SkPixmap pm;
755
756 REPORTER_ASSERT(reporter, surfacePM.rowBytes() == pm.rowBytes());
757
758 // trigger a copy-on-write
759 surface->getCanvas()->drawPaint(SkPaint());
760 sk_sp<SkImage> image2(surface->makeImageSnapshot());
761 REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID());
762
763 SkPixmap pm2;
764 REPORTER_ASSERT(reporter, image2->peekPixels(&pm2));
766}
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
uint32_t uniqueID() const
Definition: SkImage.h:311
bool peekPixels(SkPixmap *pixmap) const
Definition: SkImage.cpp:34
size_t rowBytes() const
Definition: SkPixmap.h:145
sk_sp< const SkImage > image
Definition: SkRecords.h:269

◆ create_direct_surface()

static sk_sp< SkSurface > create_direct_surface ( SkAlphaType  at = kPremul_SkAlphaType,
SkImageInfo requestedInfo = nullptr 
)
static

Definition at line 98 of file SurfaceTest.cpp.

99 {
100 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
101 if (requestedInfo) {
102 *requestedInfo = info;
103 }
104 const size_t rowBytes = info.minRowBytes();
105 void* storage = sk_malloc_throw(info.computeByteSize(rowBytes));
106 return SkSurfaces::WrapPixels(info, storage, rowBytes, release_direct_surface_storage, storage);
107}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static void * sk_malloc_throw(size_t size)
Definition: SkMalloc.h:67
static void release_direct_surface_storage(void *pixels, void *context)
Definition: SurfaceTest.cpp:86
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)

◆ create_gpu_scratch_surface()

static sk_sp< SkSurface > create_gpu_scratch_surface ( GrRecordingContext rContext,
SkAlphaType  at = kPremul_SkAlphaType,
SkImageInfo requestedInfo = nullptr 
)
static

Definition at line 117 of file SurfaceTest.cpp.

119 {
120 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
121 if (requestedInfo) {
122 *requestedInfo = info;
123 }
125}
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_gpu_surface()

static sk_sp< SkSurface > create_gpu_surface ( GrRecordingContext rContext,
SkAlphaType  at = kPremul_SkAlphaType,
SkImageInfo requestedInfo = nullptr 
)
static

Definition at line 108 of file SurfaceTest.cpp.

110 {
111 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
112 if (requestedInfo) {
113 *requestedInfo = info;
114 }
116}

◆ create_gpu_surface_backend_render_target()

static sk_sp< SkSurface > create_gpu_surface_backend_render_target ( GrDirectContext dContext,
int  sampleCnt,
const SkColor4f color 
)
static

Definition at line 838 of file SurfaceTest.cpp.

840 {
841 const int kWidth = 10;
842 const int kHeight = 10;
843
845 {kWidth, kHeight},
847 sampleCnt,
849 if (!surf) {
850 return nullptr;
851 }
852 surf->getCanvas()->clear(color);
853 return surf;
854}
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
void clear(SkColor color)
Definition: SkCanvas.h:1199
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
DlColor color
sk_sp< SkSurface > MakeBackendRenderTargetSurface(GrDirectContext *dContext, const SkImageInfo &ii, GrSurfaceOrigin origin, int sampleCnt, GrProtected isProtected, const SkSurfaceProps *props)
constexpr size_t kHeight
constexpr size_t kWidth

◆ create_gpu_surface_backend_texture()

static sk_sp< SkSurface > create_gpu_surface_backend_texture ( GrDirectContext dContext,
int  sampleCnt,
const SkColor4f color 
)
static

Definition at line 797 of file SurfaceTest.cpp.

799 {
800 // On Pixel and Pixel2XL's with Adreno 530 and 540s, setting width and height to 10s reliably
801 // triggers what appears to be a driver race condition where the 10x10 surface from the
802 // OverdrawSurface_gpu test is reused(?) for this surface created by the SurfacePartialDraw_gpu
803 // test.
804 //
805 // Immediately after creation of this surface, readback shows the correct initial solid color.
806 // However, sometime before content is rendered into the upper half of the surface, the driver
807 // presumably cleans up the OverdrawSurface_gpu's memory which corrupts this color buffer. The
808 // top half of the surface is fine after the partially-covering rectangle is drawn, but the
809 // untouched bottom half contains random pixel values that trigger asserts in the
810 // SurfacePartialDraw_gpu test for no longer matching the initial color. Running the
811 // SurfacePartialDraw_gpu test without the OverdrawSurface_gpu test completes successfully.
812 //
813 // Requesting a much larger backend texture size seems to prevent it from reusing the same
814 // memory and avoids the issue.
815 const SkISize kSize = CurrentTestHarnessIsSkQP() ? SkISize{10, 10} : SkISize{100, 100};
816
817 auto surf = sk_gpu_test::MakeBackendTextureSurface(dContext,
818 kSize,
820 sampleCnt,
822 if (!surf) {
823 return nullptr;
824 }
825 surf->getCanvas()->clear(color);
826 return surf;
827}
bool CurrentTestHarnessIsSkQP()
Definition: TestHarness.cpp:10
constexpr int kSize
sk_sp< SkSurface > MakeBackendTextureSurface(GrDirectContext *dContext, const SkImageInfo &ii, GrSurfaceOrigin origin, int sampleCnt, skgpu::Mipmapped mipmapped, GrProtected isProtected, const SkSurfaceProps *props)
Definition: SkSize.h:16

◆ create_surface()

static sk_sp< SkSurface > create_surface ( SkAlphaType  at = kPremul_SkAlphaType,
SkImageInfo requestedInfo = nullptr 
)
static

Definition at line 90 of file SurfaceTest.cpp.

91 {
92 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
93 if (requestedInfo) {
94 *requestedInfo = info;
95 }
97}
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)

◆ DEF_GANESH_TEST_FOR_GL_CONTEXT() [1/2]

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

Definition at line 1089 of file SurfaceTest.cpp.

1092 {
1093 auto context = ctxInfo.directContext();
1094 const GrCaps* caps = context->priv().caps();
1095
1096 if (caps->avoidStencilBuffers()) {
1097 return;
1098 }
1099
1100 static const SkColor4f kOrigColor { 0.667f, 0.733f, 0.8f, 1 };
1101
1102 auto resourceProvider = context->priv().resourceProvider();
1103
1104 for (auto& surfaceFunc :
1106 for (int sampleCnt : {1, 4, 8}) {
1107 auto surface = surfaceFunc(context, sampleCnt, kOrigColor);
1108
1109 if (!surface && sampleCnt > 1) {
1110 // Certain platforms don't support MSAA, skip these.
1111 continue;
1112 }
1113
1114 // Validate that we can attach a stencil buffer to an SkSurface created by either of
1115 // our surface functions.
1116 auto rtp = skgpu::ganesh::TopDeviceTargetProxy(surface->getCanvas());
1117 GrRenderTarget* rt = rtp->peekRenderTarget();
1119 resourceProvider->attachStencilAttachment(rt, rt->numSamples() > 1));
1120 }
1121 }
1122}
static sk_sp< SkSurface > create_gpu_surface_backend_texture(GrDirectContext *dContext, int sampleCnt, const SkColor4f &color)
static sk_sp< SkSurface > create_gpu_surface_backend_render_target(GrDirectContext *dContext, int sampleCnt, const SkColor4f &color)
Definition: GrCaps.h:57
bool avoidStencilBuffers() const
Definition: GrCaps.h:139
int numSamples() const
GrRenderTargetProxy * TopDeviceTargetProxy(const SkCanvas *canvas)
Definition: GrCanvas.cpp:34

◆ DEF_GANESH_TEST_FOR_GL_CONTEXT() [2/2]

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

Definition at line 889 of file SurfaceTest.cpp.

889 {
890 auto dContext = ctxInfo.directContext();
891 // Snaps an image from a surface and then makes a SurfaceContext from the image's texture.
892 auto makeImageSurfaceContext = [dContext](SkSurface* surface) {
893 sk_sp<SkImage> i(surface->makeImageSnapshot());
894 auto [view, ct] = skgpu::ganesh::AsView(dContext, i, skgpu::Mipmapped::kNo);
895 GrColorInfo colorInfo(ct, i->alphaType(), i->refColorSpace());
896 return dContext->priv().makeSC(view, std::move(colorInfo));
897 };
898
899 // Test that non-wrapped RTs are created clear.
900 for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surface}) {
901 auto surface = surface_func(dContext, kPremul_SkAlphaType, nullptr);
902 if (!surface) {
903 ERRORF(reporter, "Could not create GPU SkSurface.");
904 return;
905 }
907 if (!sfc) {
908 ERRORF(reporter, "Could access surface context of GPU SkSurface.");
909 return;
910 }
911 test_surface_context_clear(reporter, dContext, sfc, 0x0);
912 auto imageSurfaceCtx = makeImageSurfaceContext(surface.get());
913 test_surface_context_clear(reporter, dContext, imageSurfaceCtx.get(), 0x0);
914 }
915
916 // Wrapped RTs are *not* supposed to clear (to allow client to partially update a surface).
917 const SkColor4f kOrigColor{.67f, .67f, .67f, 1};
918 for (auto& surfaceFunc :
920 auto surface = surfaceFunc(dContext, 1, kOrigColor);
921 if (!surface) {
922 ERRORF(reporter, "Could not create GPU SkSurface.");
923 return;
924 }
926 if (!sfc) {
927 ERRORF(reporter, "Could access surface context of GPU SkSurface.");
928 return;
929 }
930 test_surface_context_clear(reporter, dContext, sfc, kOrigColor.toSkColor());
931 auto imageSurfaceCtx = makeImageSurfaceContext(surface.get());
932 test_surface_context_clear(reporter, dContext, imageSurfaceCtx.get(),
933 kOrigColor.toSkColor());
934 }
935}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
static void test_surface_context_clear(skiatest::Reporter *reporter, GrDirectContext *dContext, skgpu::ganesh::SurfaceContext *surfaceContext, uint32_t expectedValue)
static sk_sp< SkSurface > create_gpu_surface(GrRecordingContext *rContext, SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
static sk_sp< SkSurface > create_gpu_scratch_surface(GrRecordingContext *rContext, SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
#define ERRORF(r,...)
Definition: Test.h:293
SurfaceFillContext * TopDeviceSurfaceFillContext(const SkCanvas *canvas)
Definition: GrCanvas.cpp:27
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [1/19]

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

Definition at line 142 of file SurfaceTest.cpp.

145 {
146 using namespace skgpu;
147
148 auto context = ctxInfo.directContext();
149
150 Protected isProtected = Protected(context->priv().caps()->supportsProtectedContent());
151
152 for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) {
153 static constexpr int kSize = 10;
154
155 SkColorType colorType = static_cast<SkColorType>(ct);
157
158 {
159 bool can = context->colorTypeSupportedAsSurface(colorType);
160 auto surf = SkSurfaces::RenderTarget(context, Budgeted::kYes, info, 1, nullptr);
161 REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
162 colorType, can, SkToBool(surf));
163
165 {kSize, kSize},
167 /*sample cnt*/ 1,
168 colorType,
169 /* colorSpace= */ nullptr,
171 isProtected);
172 REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
173 colorType, can, SkToBool(surf));
174 }
175
176 // The MSAA test only makes sense if the colorType is renderable to begin with.
177 if (context->colorTypeSupportedAsSurface(colorType)) {
178 static constexpr int kSampleCnt = 2;
179
180 bool can = context->maxSurfaceSampleCountForColorType(colorType) >= kSampleCnt;
181 auto surf = SkSurfaces::RenderTarget(
182 context, Budgeted::kYes, info, kSampleCnt, nullptr);
183 REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
184 colorType, can, SkToBool(surf));
185
187 context, {kSize, kSize}, kTopLeft_GrSurfaceOrigin, kSampleCnt, colorType,
188 /* colorSpace= */ nullptr, Mipmapped::kNo, isProtected);
189 REPORTER_ASSERT(reporter, can == SkToBool(surf),
190 "colorTypeSupportedAsSurface:%d, surf:%d, ct:%d", can, SkToBool(surf),
191 colorType);
192 // Ensure that the sample count stored on the resulting SkSurface is a valid value.
193 if (surf) {
194 auto rtp = skgpu::ganesh::TopDeviceTargetProxy(surf->getCanvas());
195 int storedCnt = rtp->numSamples();
196 const GrBackendFormat& format = rtp->backendFormat();
197 int allowedCnt =
198 context->priv().caps()->getRenderTargetSampleCount(storedCnt, format);
199 REPORTER_ASSERT(reporter, storedCnt == allowedCnt,
200 "Should store an allowed sample count (%d vs %d)", allowedCnt,
201 storedCnt);
202 }
203 }
204
205 for (int sampleCnt : {1, 2}) {
207 {16, 16},
209 sampleCnt,
210 colorType,
211 /* colorSpace= */ nullptr,
212 isProtected);
213 bool can = context->colorTypeSupportedAsSurface(colorType) &&
214 context->maxSurfaceSampleCountForColorType(colorType) >= sampleCnt;
215 if (!surf && can && colorType == kBGRA_8888_SkColorType && sampleCnt > 1 &&
216 context->backend() == GrBackendApi::kOpenGL) {
217 // This is an execeptional case. On iOS GLES we support MSAA BGRA for internally-
218 // created render targets by using a MSAA RGBA8 renderbuffer that resolves to a
219 // BGRA8 texture. However, the GL_APPLE_texture_format_BGRA8888 extension does not
220 // allow creation of BGRA8 renderbuffers and we don't support multisampled textures.
221 // So this is expected to fail. As of 10/5/2020 it actually seems to work to create
222 // a MSAA BGRA8 renderbuffer (at least in the simulator) but we don't want to rely
223 // on this undocumented behavior.
224 continue;
225 }
226 REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, sc: %d, can: %d, surf: %d",
227 colorType, sampleCnt, can, SkToBool(surf));
228 if (surf) {
229 auto rtp = skgpu::ganesh::TopDeviceTargetProxy(surf->getCanvas());
230 int storedCnt = rtp->numSamples();
231 const GrBackendFormat& backendFormat = rtp->backendFormat();
232 int allowedCnt = context->priv().caps()->getRenderTargetSampleCount(storedCnt,
233 backendFormat);
234 REPORTER_ASSERT(reporter, storedCnt == allowedCnt,
235 "Should store an allowed sample count (%d vs %d)", allowedCnt,
236 storedCnt);
237 }
238 }
239 }
240}
skgpu::Protected Protected
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
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
@ kLastEnum_SkColorType
last valid value
Definition: SkColorType.h:56
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
uint32_t uint32_t * format
Definition: GpuTools.h:21
Protected
Definition: GpuTypes.h:61
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [2/19]

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

Definition at line 242 of file SurfaceTest.cpp.

245 {
246 using namespace skgpu;
247
248 auto context = ctxInfo.directContext();
249
250 Protected isProtected = Protected(context->priv().caps()->supportsProtectedContent());
251
252 static constexpr int kSize = 10;
253
254 for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) {
255
256 SkColorType colorType = static_cast<SkColorType>(ct);
257 int maxSampleCnt = context->maxSurfaceSampleCountForColorType(colorType);
258 if (!maxSampleCnt) {
259 continue;
260 }
261 if (!context->colorTypeSupportedAsSurface(colorType)) {
262 continue;
263 }
264
267 context, info, kTopLeft_GrSurfaceOrigin, maxSampleCnt, Mipmapped::kNo, isProtected);
268 if (!surf) {
269 ERRORF(reporter, "Could not make surface of color type %d.", colorType);
270 continue;
271 }
272 int sampleCnt = ((SkSurface_Ganesh*)(surf.get()))->getDevice()->targetProxy()->numSamples();
273 REPORTER_ASSERT(reporter, sampleCnt == maxSampleCnt, "Exected: %d, actual: %d",
274 maxSampleCnt, sampleCnt);
275 }
276}

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [3/19]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( OverdrawSurface_Gpu  ,
,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 1254 of file SurfaceTest.cpp.

1257 {
1258 auto context = ctxInfo.directContext();
1261}
static void test_overdraw_surface(skiatest::Reporter *r, SkSurface *surface)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [4/19]

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

Definition at line 1124 of file SurfaceTest.cpp.

1127 {
1128 auto context = ctxInfo.directContext();
1129
1130 for (int sampleCnt : {1, 2}) {
1132 auto mbet1 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
1134 if (!mbet1) {
1135 continue;
1136 }
1137 auto mbet2 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
1139 if (!mbet2) {
1140 ERRORF(reporter, "Expected to be able to make second texture");
1141 continue;
1142 }
1143 auto ii2 = ii.makeWH(8, 8);
1144 auto mbet3 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
1146 GrBackendTexture backendTexture3;
1147 if (!mbet3) {
1148 ERRORF(reporter, "Couldn't create different sized texture.");
1149 continue;
1150 }
1151
1152 auto surf = SkSurfaces::WrapBackendTexture(context,
1153 mbet1->texture(),
1155 sampleCnt,
1157 ii.refColorSpace(),
1158 nullptr);
1159 if (!surf) {
1160 continue;
1161 }
1162 surf->getCanvas()->clear(SK_ColorBLUE);
1163 // Change matrix, layer, and clip state before swapping out the backing texture.
1164 surf->getCanvas()->translate(5, 5);
1165 surf->getCanvas()->saveLayer(nullptr, nullptr);
1166 surf->getCanvas()->clipRect(SkRect::MakeXYWH(0, 0, 1, 1));
1167 // switch origin while we're at it.
1168 bool replaced = surf->replaceBackendTexture(mbet2->texture(), kBottomLeft_GrSurfaceOrigin);
1169 REPORTER_ASSERT(reporter, replaced);
1170 SkPaint paint;
1171 paint.setColor(SK_ColorRED);
1172 surf->getCanvas()->drawRect(SkRect::MakeWH(5, 5), paint);
1173 surf->getCanvas()->restore();
1174
1175 // Check that the replacement texture got the right color values.
1177 pm.alloc(ii);
1178 bool bad = !surf->readPixels(pm, 0, 0);
1179 REPORTER_ASSERT(reporter, !bad, "Could not read surface.");
1180 for (int y = 0; y < ii.height() && !bad; ++y) {
1181 for (int x = 0; x < ii.width() && !bad; ++x) {
1182 auto expected = (x == 5 && y == 5) ? 0xFF0000FF : 0xFFFF0000;
1183 auto found = *pm.addr32(x, y);
1184 if (found != expected) {
1185 bad = true;
1186 ERRORF(reporter, "Expected color 0x%08x, found color 0x%08x at %d, %d.",
1187 expected, found, x, y);
1188 }
1189 }
1190 }
1191 // The original texture should still be all blue.
1192 surf = SkSurfaces::WrapBackendTexture(context,
1193 mbet1->texture(),
1195 sampleCnt,
1197 ii.refColorSpace(),
1198 nullptr);
1199 if (!surf) {
1200 ERRORF(reporter, "Could not create second surface.");
1201 continue;
1202 }
1203 bad = !surf->readPixels(pm, 0, 0);
1204 REPORTER_ASSERT(reporter, !bad, "Could not read second surface.");
1205 for (int y = 0; y < ii.height() && !bad; ++y) {
1206 for (int x = 0; x < ii.width() && !bad; ++x) {
1207 auto expected = 0xFFFF0000;
1208 auto found = *pm.addr32(x, y);
1209 if (found != expected) {
1210 bad = true;
1211 ERRORF(reporter, "Expected color 0x%08x, found color 0x%08x at %d, %d.",
1212 expected, found, x, y);
1213 }
1214 }
1215 }
1216
1217 // Can't replace with the same texture
1219 !surf->replaceBackendTexture(mbet1->texture(), kTopLeft_GrSurfaceOrigin));
1220 // Can't replace with invalid texture
1221 REPORTER_ASSERT(reporter, !surf->replaceBackendTexture({}, kTopLeft_GrSurfaceOrigin));
1222 // Can't replace with different size texture.
1224 !surf->replaceBackendTexture(mbet3->texture(), kTopLeft_GrSurfaceOrigin));
1225 // Can't replace texture of non-wrapped SkSurface.
1226 surf = SkSurfaces::RenderTarget(context, skgpu::Budgeted::kYes, ii, sampleCnt, nullptr);
1228 if (surf) {
1229 REPORTER_ASSERT(reporter, !surf->replaceBackendTexture(mbet1->texture(),
1231 }
1232 }
1233}
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
void alloc(const SkImageInfo &)
const uint32_t * addr32() const
Definition: SkPixmap.h:352
const Paint & paint
Definition: color_source.cc:38
double y
double x
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [5/19]

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

Definition at line 448 of file SurfaceTest.cpp.

451 {
452 auto direct = ctxInfo.directContext();
454 if (!surface) {
455 return;
456 }
457 // This flush can put command buffer refs on the GrGpuResource for the surface.
458 direct->flush(surface.get());
459 direct->abandonContext();
460 // We pass the test if we don't hit any asserts or crashes when the ref on the surface goes away
461 // after we abanonded the context. One thing specifically this checks is to make sure we're
462 // correctly handling the mix of normal refs and command buffer refs, and correctly deleting
463 // the object at the right time.
464}

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [6/19]

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

Definition at line 466 of file SurfaceTest.cpp.

469 {
470 auto dContext = ctxInfo.directContext();
472 if (!surface) {
473 return;
474 }
475
482
483 dContext->flush(surface.get());
484 dContext->abandonContext();
485
486 // After abandoning the context none of the backend surfaces should be valid.
493}
bool isValid() const
@ kFlushRead
back-end object is readable
SK_API GrBackendTexture GetBackendTexture(SkSurface *, BackendHandleAccess)
SK_API GrBackendRenderTarget GetBackendRenderTarget(SkSurface *, BackendHandleAccess)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [7/19]

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

Definition at line 429 of file SurfaceTest.cpp.

432 {
433 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
434 {
435 auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
436 test_backend_unique_id<GrBackendTexture, &SkSurfaces::GetBackendTexture>(reporter,
437 surface.get());
438 }
439 {
440 auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
441 test_backend_unique_id<GrBackendRenderTarget, &SkSurfaces::GetBackendRenderTarget>(
442 reporter, surface.get());
443 }
444 }
445}

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [8/19]

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

Definition at line 380 of file SurfaceTest.cpp.

383 {
384 const SkSurfaces::BackendHandleAccess accessModes[] = {
388 };
389
390 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
391 for (auto& accessMode : accessModes) {
392 {
393 auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
395 }
396 {
397 auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
399 }
400 }
401 }
402}
static void test_backend_rendertarget_access_copy_on_write(skiatest::Reporter *reporter, SkSurface *surface, SkSurface::BackendHandleAccess access)
static void test_backend_texture_access_copy_on_write(skiatest::Reporter *reporter, SkSurface *surface, SkSurface::BackendHandleAccess access)
BackendHandleAccess
Definition: SkSurface.h:229
@ kFlushWrite
back-end object is writable
@ kDiscardWrite
back-end object must be overwritten

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [9/19]

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

Definition at line 678 of file SurfaceTest.cpp.

681 {
683 GrDirectContext* dContext = ctxInfo.directContext();
684 for (auto budgeted : {skgpu::Budgeted::kNo, skgpu::Budgeted::kYes}) {
685 auto surface(SkSurfaces::RenderTarget(dContext, budgeted, info));
688
689 sk_sp<SkImage> image(surface->makeImageSnapshot());
690
691 // Initially the image shares a texture with the surface, and the
692 // the budgets should always match.
694 REPORTER_ASSERT(reporter, budgeted == is_budgeted(image.get(), dContext));
695
696 // Now trigger copy-on-write
697 surface->getCanvas()->clear(SK_ColorBLUE);
698
699 // They don't share a texture anymore but the budgets should still match.
701 REPORTER_ASSERT(reporter, budgeted == is_budgeted(image.get(), dContext));
702 }
703}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static skgpu::Budgeted is_budgeted(const sk_sp< SkSurface > &surf)
T * get() const
Definition: SkRefCnt.h:303
static SkImageInfo MakeN32Premul(int width, int height)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [10/19]

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

Definition at line 312 of file SurfaceTest.cpp.

315 {
316 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
317 SkImageInfo requestInfo;
318 auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, &requestInfo));
319 test_canvas_peek(reporter, surface, requestInfo, false);
320 }
321}
static void test_canvas_peek(skiatest::Reporter *reporter, sk_sp< SkSurface > &surface, const SkImageInfo &requestInfo, bool expectPeekSuccess)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [11/19]

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

Definition at line 555 of file SurfaceTest.cpp.

558 {
559 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
560 auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
562 }
563}
static void test_copy_on_write(skiatest::Reporter *reporter, SkSurface *surface)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [12/19]

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

Definition at line 627 of file SurfaceTest.cpp.

630 {
631 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
632 auto surface1(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
633 auto surface2(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
634 test_crbug263329(reporter, surface1.get(), surface2.get());
635 }
636}
static void test_crbug263329(skiatest::Reporter *reporter, SkSurface *surface1, SkSurface *surface2)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [13/19]

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

Definition at line 132 of file SurfaceTest.cpp.

135 {
136 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
138 nullptr == SkSurfaces::RenderTarget(
139 ctxInfo.directContext(), skgpu::Budgeted::kNo, info));
140}

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [14/19]

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

Definition at line 732 of file SurfaceTest.cpp.

735 {
738 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
739 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
740 for (auto& mode : modes) {
741 auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
742 test_func(reporter, surface.get(), mode);
743 }
744 }
745 }
746}
static void test_no_canvas2(skiatest::Reporter *reporter, SkSurface *surface, SkSurface::ContentChangeMode mode)
static void test_no_canvas1(skiatest::Reporter *reporter, SkSurface *surface, SkSurface::ContentChangeMode mode)
ContentChangeMode
Definition: SkSurface.h:203
@ kDiscard_ContentChangeMode
discards surface on change
Definition: SkSurface.h:204
@ kRetain_ContentChangeMode
preserves surface on change
Definition: SkSurface.h:205
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 mode
Definition: switches.h:228

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [15/19]

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

Definition at line 989 of file SurfaceTest.cpp.

992 {
993 auto context = ctxInfo.directContext();
994
995 static const SkColor4f kOrigColor { 0.667f, 0.733f, 0.8f, 1 };
996
997 for (auto& surfaceFunc :
999 // Validate that we can draw to the canvas and that the original texture color is
1000 // preserved in pixels that aren't rendered to via the surface.
1001 // This works only for non-multisampled case.
1002 auto surface = surfaceFunc(context, 1, kOrigColor);
1003 if (surface && supports_readpixels(context->priv().caps(), surface.get())) {
1004 test_surface_draw_partially(reporter, surface, kOrigColor.toSkColor());
1005 }
1006 }
1007}
static void test_surface_draw_partially(skiatest::Reporter *reporter, sk_sp< SkSurface > surface, SkColor origColor)
static bool supports_readpixels(const GrCaps *caps, SkSurface *surface)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [16/19]

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

Definition at line 645 of file SurfaceTest.cpp.

648 {
649 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
650 auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
651 sk_sp<SkImage> image(surface->makeImageSnapshot());
652
653 REPORTER_ASSERT(reporter, as_IB(image)->isTextureBacked());
654 GrBackendTexture backendTex;
655 bool ok = SkImages::GetBackendTextureFromImage(image, &backendTex, false);
657 REPORTER_ASSERT(reporter, backendTex.isValid());
658 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
659 REPORTER_ASSERT(reporter, as_IB(image)->isTextureBacked());
660 GrBackendTexture backendTex2;
661 ok = SkImages::GetBackendTextureFromImage(image, &backendTex2, false);
663 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex, backendTex2));
664 }
665}
static bool ok(int result)
static SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:201
SK_API bool GetBackendTextureFromImage(const SkImage *img, GrBackendTexture *outTexture, bool flushPendingGrContextIO, GrSurfaceOrigin *origin=nullptr)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [17/19]

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

Definition at line 342 of file SurfaceTest.cpp.

345 {
346 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
347 // GPU doesn't support creating unpremul surfaces, so only test opaque + premul
348 for (auto& at : { kOpaque_SkAlphaType, kPremul_SkAlphaType }) {
349 auto surface(surface_func(ctxInfo.directContext(), at, nullptr));
351 }
352 }
353}
static void test_snapshot_alphatype(skiatest::Reporter *reporter, const sk_sp< SkSurface > &surface, SkAlphaType expectedAlphaType)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [18/19]

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

Definition at line 1017 of file SurfaceTest.cpp.

1020 {
1021 const int kWidth = 10;
1022 const int kHeight = 10;
1023
1024 auto ctx = ctxInfo.directContext();
1025 GrGpu* gpu = ctx->priv().getGpu();
1026
1027 for (bool useTexture : {false, true}) {
1029 GrBackendRenderTarget backendRT;
1031
1032 ReleaseChecker releaseChecker;
1034
1035 if (useTexture) {
1038 mbet = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
1040 if (!mbet) {
1041 continue;
1042 }
1043
1045 ctx,
1046 mbet->texture(),
1047 texOrigin,
1048 /*sample count*/ 1,
1050 /*color space*/ nullptr,
1051 /*surface props*/ nullptr,
1052 sk_gpu_test::ManagedBackendTexture::ReleaseProc,
1053 mbet->releaseContext(ReleaseChecker::Release, &releaseChecker));
1054 } else {
1055 backendRT = gpu->createTestingOnlyBackendRenderTarget({kWidth, kHeight},
1057 if (!backendRT.isValid()) {
1058 continue;
1059 }
1061 backendRT,
1062 texOrigin,
1064 nullptr,
1065 nullptr,
1067 &releaseChecker);
1068 }
1069 if (!surface) {
1070 ERRORF(reporter, "Failed to create surface");
1071 continue;
1072 }
1073
1074 surface->getCanvas()->clear(SK_ColorRED);
1075 ctx->flush(surface.get());
1076 ctx->submit(GrSyncCpu::kYes);
1077
1078 // Now exercise the release proc
1079 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount);
1080 surface.reset(nullptr); // force a release of the surface
1081 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount);
1082
1083 if (!useTexture) {
1084 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
1085 }
1086 }
1087}
GrSurfaceOrigin
Definition: GrTypes.h:147
Definition: GrGpu.h:62
SK_API sk_sp< SkSurface > WrapBackendRenderTarget(GrRecordingContext *context, const GrBackendRenderTarget &backendRenderTarget, GrSurfaceOrigin origin, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, RenderTargetReleaseProc releaseProc=nullptr, ReleaseContext releaseContext=nullptr)
static void Release(void *self)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [19/19]

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

Definition at line 578 of file SurfaceTest.cpp.

581 {
582 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
583 auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
585 }
586}
static void test_writable_after_snapshot_release(skiatest::Reporter *reporter, SkSurface *surface)

◆ DEF_TEST() [1/12]

DEF_TEST ( OverdrawSurface_Raster  ,
 
)

Definition at line 1249 of file SurfaceTest.cpp.

1249 {
1252}
static sk_sp< SkSurface > create_surface(SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
Definition: SurfaceTest.cpp:90

◆ DEF_TEST() [2/12]

DEF_TEST ( surface_image_unity  ,
reporter   
)

Definition at line 1277 of file SurfaceTest.cpp.

1277 {
1278 auto do_test = [reporter](const SkImageInfo& info) {
1279 size_t rowBytes = info.minRowBytes();
1280 auto surf = SkSurfaces::Raster(info, rowBytes, nullptr);
1281 if (surf) {
1282 auto img = surf->makeImageSnapshot();
1283 if ((false)) { // change to true to document the differences
1284 if (!img) {
1285 SkDebugf("image failed: [%08X %08X] %14s %s\n",
1286 (uint32_t)info.width(),
1287 (uint32_t)info.height(),
1288 ToolUtils::colortype_name(info.colorType()),
1289 ToolUtils::alphatype_name(info.alphaType()));
1290 return;
1291 }
1292 }
1293 REPORTER_ASSERT(reporter, img != nullptr);
1294
1295 char tempPixel = 0; // just need a valid address (not a valid size)
1296 SkPixmap pmap = { info, &tempPixel, rowBytes };
1297 img = SkImages::RasterFromPixmap(pmap, nullptr, nullptr);
1298 REPORTER_ASSERT(reporter, img != nullptr);
1299 }
1300 };
1301
1302 const int32_t sizes[] = { -1, 0, 1, 1 << 18 };
1303 for (int cti = 0; cti <= kLastEnum_SkColorType; ++cti) {
1304 SkColorType ct = static_cast<SkColorType>(cti);
1305 for (int ati = 0; ati <= kLastEnum_SkAlphaType; ++ati) {
1306 SkAlphaType at = static_cast<SkAlphaType>(ati);
1307 for (int32_t size : sizes) {
1308 do_test(SkImageInfo::Make(1, size, ct, at));
1309 do_test(SkImageInfo::Make(size, 1, ct, at));
1310 }
1311 }
1312 }
1313}
SkAlphaType
Definition: SkAlphaType.h:26
@ kLastEnum_SkAlphaType
last valid value
Definition: SkAlphaType.h:31
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
SK_API sk_sp< SkImage > RasterFromPixmap(const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
const char * colortype_name(SkColorType ct)
Definition: ToolUtils.cpp:65
const char * alphatype_name(SkAlphaType at)
Definition: ToolUtils.cpp:55
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() [3/12]

DEF_TEST ( Surface_null  ,
 
)

Definition at line 1263 of file SurfaceTest.cpp.

1263 {
1264 REPORTER_ASSERT(r, SkSurfaces::Null(0, 0) == nullptr);
1265
1266 const int w = 37;
1267 const int h = 1000;
1268 auto surf = SkSurfaces::Null(w, h);
1269 auto canvas = surf->getCanvas();
1270
1271 canvas->drawPaint(SkPaint()); // should not crash, but don't expect anything to draw
1272 REPORTER_ASSERT(r, surf->makeImageSnapshot() == nullptr);
1273}
SK_API sk_sp< SkSurface > Null(int width, int height)
SkScalar w
SkScalar h

◆ DEF_TEST() [4/12]

DEF_TEST ( surface_raster_zeroinitialized  ,
reporter   
)

Definition at line 785 of file SurfaceTest.cpp.

785 {
787 SkPixmap pixmap;
788 REPORTER_ASSERT(reporter, s->peekPixels(&pixmap));
789
790 for (int i = 0; i < pixmap.info().width(); ++i) {
791 for (int j = 0; j < pixmap.info().height(); ++j) {
792 REPORTER_ASSERT(reporter, *pixmap.addr32(i, j) == 0);
793 }
794 }
795}
const SkImageInfo & info() const
Definition: SkPixmap.h:135
struct MyStruct s
int32_t height
int32_t width

◆ DEF_TEST() [5/12]

DEF_TEST ( surface_rowbytes  ,
reporter   
)

Definition at line 768 of file SurfaceTest.cpp.

768 {
770
771 auto surf0(SkSurfaces::Raster(info));
773
774 // specify a larger rowbytes
775 auto surf1(SkSurfaces::Raster(info, 500, nullptr));
777
778 // Try some illegal rowByte values
779 auto s = SkSurfaces::Raster(info, 396, nullptr); // needs to be at least 400
780 REPORTER_ASSERT(reporter, nullptr == s);
782 REPORTER_ASSERT(reporter, nullptr == s);
783}
static void check_rowbytes_remain_consistent(SkSurface *surface, skiatest::Reporter *reporter)
static float max(float r, float g, float b)
Definition: hsl.cpp:49

◆ DEF_TEST() [6/12]

DEF_TEST ( SurfaceCanvasPeek  ,
reporter   
)

Definition at line 305 of file SurfaceTest.cpp.

305 {
306 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
307 SkImageInfo requestInfo;
308 auto surface(surface_func(kPremul_SkAlphaType, &requestInfo));
309 test_canvas_peek(reporter, surface, requestInfo, true);
310 }
311}
static sk_sp< SkSurface > create_direct_surface(SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
Definition: SurfaceTest.cpp:98

◆ DEF_TEST() [7/12]

DEF_TEST ( SurfaceCopyOnWrite  ,
reporter   
)

Definition at line 552 of file SurfaceTest.cpp.

552 {
554}
const myers::Point & get(const myers::Segment &)

◆ DEF_TEST() [8/12]

DEF_TEST ( SurfaceEmpty  ,
reporter   
)

Definition at line 127 of file SurfaceTest.cpp.

127 {
128 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
130 REPORTER_ASSERT(reporter, nullptr == SkSurfaces::WrapPixels(info, nullptr, 0));
131}

◆ DEF_TEST() [9/12]

DEF_TEST ( SurfaceGetTexture  ,
reporter   
)

Definition at line 638 of file SurfaceTest.cpp.

638 {
639 auto surface(create_surface());
640 sk_sp<SkImage> image(surface->makeImageSnapshot());
641 REPORTER_ASSERT(reporter, !as_IB(image)->isTextureBacked());
642 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
643 REPORTER_ASSERT(reporter, !as_IB(image)->isTextureBacked());
644}

◆ DEF_TEST() [10/12]

DEF_TEST ( SurfaceNoCanvas  ,
reporter   
)

Definition at line 723 of file SurfaceTest.cpp.

723 {
726 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
727 for (auto& mode : modes) {
728 test_func(reporter, create_surface().get(), mode);
729 }
730 }
731}

◆ DEF_TEST() [11/12]

DEF_TEST ( SurfaceSnapshotAlphaType  ,
reporter   
)

Definition at line 334 of file SurfaceTest.cpp.

334 {
335 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
337 auto surface(surface_func(at, nullptr));
339 }
340 }
341}
kUnpremul_SkAlphaType

◆ DEF_TEST() [12/12]

DEF_TEST ( SurfaceWriteableAfterSnapshotRelease  ,
reporter   
)

Definition at line 575 of file SurfaceTest.cpp.

◆ is_budgeted() [1/2]

static skgpu::Budgeted is_budgeted ( const sk_sp< SkSurface > &  surf)
static

Definition at line 667 of file SurfaceTest.cpp.

667 {
668 SkSurface_Ganesh* gsurf = (SkSurface_Ganesh*)surf.get();
669
670 GrRenderTargetProxy* proxy = gsurf->getDevice()->targetProxy();
671 return proxy->isBudgeted();
672}
skgpu::Budgeted isBudgeted() const
skgpu::ganesh::Device * getDevice()
GrRenderTargetProxy * targetProxy()
Definition: Device.cpp:1287

◆ is_budgeted() [2/2]

static skgpu::Budgeted is_budgeted ( SkImage image,
GrRecordingContext rc 
)
static

Definition at line 674 of file SurfaceTest.cpp.

674 {
676}
GrTextureProxy * GetTextureImageProxy(SkImage *image, GrRecordingContext *rContext)
Definition: ProxyUtils.cpp:32

◆ release_direct_surface_storage()

static void release_direct_surface_storage ( void *  pixels,
void *  context 
)
static

Definition at line 86 of file SurfaceTest.cpp.

86 {
87 SkASSERT(pixels == context);
88 sk_free(pixels);
89}
SK_API void sk_free(void *)

◆ supports_readpixels()

static bool supports_readpixels ( const GrCaps caps,
SkSurface surface 
)
static

Definition at line 829 of file SurfaceTest.cpp.

829 {
830 auto surfaceGpu = static_cast<SkSurface_Ganesh*>(surface);
831 GrRenderTarget* rt = surfaceGpu->getDevice()->targetProxy()->peekRenderTarget();
832 if (!rt) {
833 return false;
834 }
836}
virtual SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface *) const =0

◆ test_backend_rendertarget_access_copy_on_write()

static void test_backend_rendertarget_access_copy_on_write ( skiatest::Reporter reporter,
SkSurface surface,
SkSurface::BackendHandleAccess  access 
)
static

Definition at line 367 of file SurfaceTest.cpp.

368 {
370 sk_sp<SkImage> snap1(surface->makeImageSnapshot());
371
373 sk_sp<SkImage> snap2(surface->makeImageSnapshot());
374
375 // If the access mode triggers CoW, then the backend objects should reflect it.
376 REPORTER_ASSERT(reporter, GrBackendRenderTarget::TestingOnly_Equals(rt1, rt2) ==
377 (snap1 == snap2));
378}

◆ test_backend_texture_access_copy_on_write()

static void test_backend_texture_access_copy_on_write ( skiatest::Reporter reporter,
SkSurface surface,
SkSurface::BackendHandleAccess  access 
)
static

Definition at line 355 of file SurfaceTest.cpp.

356 {
358 sk_sp<SkImage> snap1(surface->makeImageSnapshot());
359
361 sk_sp<SkImage> snap2(surface->makeImageSnapshot());
362
363 // If the access mode triggers CoW, then the backend objects should reflect it.
364 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(tex1, tex2) == (snap1 == snap2));
365}

◆ test_backend_unique_id()

template<typename Type , Type(*)(SkSurface *, SkSurface::BackendHandleAccess) func>
static void test_backend_unique_id ( skiatest::Reporter reporter,
SkSurface surface 
)
static

Definition at line 405 of file SurfaceTest.cpp.

405 {
406 sk_sp<SkImage> image0(surface->makeImageSnapshot());
407
409 REPORTER_ASSERT(reporter, obj.isValid());
410 sk_sp<SkImage> image1(surface->makeImageSnapshot());
411 // just read access should not affect the snapshot
412 REPORTER_ASSERT(reporter, image0->uniqueID() == image1->uniqueID());
413
415 REPORTER_ASSERT(reporter, obj.isValid());
416 sk_sp<SkImage> image2(surface->makeImageSnapshot());
417 // expect a new image, since we claimed we would write
418 REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID());
419
421 REPORTER_ASSERT(reporter, obj.isValid());
422 sk_sp<SkImage> image3(surface->makeImageSnapshot());
423 // expect a new(er) image, since we claimed we would write
424 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID());
425 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID());
426}

◆ test_canvas_peek()

static void test_canvas_peek ( skiatest::Reporter reporter,
sk_sp< SkSurface > &  surface,
const SkImageInfo requestInfo,
bool  expectPeekSuccess 
)
static

Definition at line 278 of file SurfaceTest.cpp.

281 {
282 const SkColor color = SK_ColorRED;
283 const SkPMColor pmcolor = SkPreMultiplyColor(color);
284 surface->getCanvas()->clear(color);
285
286 SkPixmap pmap;
287 bool success = surface->getCanvas()->peekPixels(&pmap);
288 REPORTER_ASSERT(reporter, expectPeekSuccess == success);
289
290 SkPixmap pmap2;
291 const void* addr2 = surface->peekPixels(&pmap2) ? pmap2.addr() : nullptr;
292
293 if (success) {
294 REPORTER_ASSERT(reporter, requestInfo == pmap.info());
295 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= pmap.rowBytes());
296 REPORTER_ASSERT(reporter, pmcolor == *pmap.addr32());
297
298 REPORTER_ASSERT(reporter, pmap.addr() == pmap2.addr());
299 REPORTER_ASSERT(reporter, pmap.info() == pmap2.info());
300 REPORTER_ASSERT(reporter, pmap.rowBytes() == pmap2.rowBytes());
301 } else {
302 REPORTER_ASSERT(reporter, nullptr == addr2);
303 }
304}
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
Definition: SkColor.cpp:21
uint32_t SkColor
Definition: SkColor.h:37
uint32_t SkPMColor
Definition: SkColor.h:205
const void * addr() const
Definition: SkPixmap.h:153
size_t minRowBytes() const
Definition: SkImageInfo.h:517

◆ test_copy_on_write()

static void test_copy_on_write ( skiatest::Reporter reporter,
SkSurface surface 
)
static

Definition at line 496 of file SurfaceTest.cpp.

496 {
497 SkCanvas* canvas = surface->getCanvas();
498
499 const SkRect testRect =
502 SkPath testPath;
505
506 const SkIRect testIRect = SkIRect::MakeXYWH(0, 0, 2, 1);
507
508 SkRegion testRegion;
509 testRegion.setRect(testIRect);
510
511
512 const SkColor testColor = 0x01020304;
513 const SkPaint testPaint;
514 const SkPoint testPoints[3] = {
518 };
519 const size_t testPointCount = 3;
520
521 SkBitmap testBitmap;
522 testBitmap.allocN32Pixels(10, 10);
523 testBitmap.eraseColor(0);
524
525 SkRRect testRRect;
526 testRRect.setRectXY(testRect, SK_Scalar1, SK_Scalar1);
527
528 SkString testText("Hello World");
529
530#define EXPECT_COPY_ON_WRITE(command) \
531 { \
532 sk_sp<SkImage> imageBefore = surface->makeImageSnapshot(); \
533 sk_sp<SkImage> aur_before(imageBefore); /*NOLINT*/ \
534 canvas-> command ; \
535 sk_sp<SkImage> imageAfter = surface->makeImageSnapshot(); \
536 sk_sp<SkImage> aur_after(imageAfter); /*NOLINT*/ \
537 REPORTER_ASSERT(reporter, imageBefore != imageAfter); \
538 }
539
540 EXPECT_COPY_ON_WRITE(clear(testColor))
541 EXPECT_COPY_ON_WRITE(drawPaint(testPaint))
542 EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \
543 testPaint))
544 EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint))
545 EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint))
546 EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint))
547 EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint))
548 EXPECT_COPY_ON_WRITE(drawImage(testBitmap.asImage(), 0, 0))
549 EXPECT_COPY_ON_WRITE(drawImageRect(testBitmap.asImage(), testRect, SkSamplingOptions()))
550 EXPECT_COPY_ON_WRITE(drawString(testText, 0, 1, ToolUtils::DefaultPortableFont(), testPaint))
551}
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define EXPECT_COPY_ON_WRITE(command)
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
@ kPoints_PointMode
draw each point separately
Definition: SkCanvas.h:1241
Definition: SkPath.h:59
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
Definition: SkPath.cpp:864
void setRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.cpp:52
bool setRect(const SkIRect &rect)
Definition: SkRegion.cpp:192
static SkScalar drawString(SkCanvas *canvas, const SkString &text, SkScalar x, SkScalar y, const SkFont &font)
Definition: fontmgr.cpp:39
static void drawPath(SkPath &path, SkCanvas *canvas, SkColor color, const SkRect &clip, SkPaint::Cap cap, SkPaint::Join join, SkPaint::Style style, SkPathFillType fill, SkScalar strokeWidth)
Definition: linepaths.cpp:22
SkFont DefaultPortableFont()
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_crbug263329()

static void test_crbug263329 ( skiatest::Reporter reporter,
SkSurface surface1,
SkSurface surface2 
)
static

Definition at line 588 of file SurfaceTest.cpp.

590 {
591 // This is a regression test for crbug.com/263329
592 // Bug was caused by onCopyOnWrite releasing the old surface texture
593 // back to the scratch texture pool even though the texture is used
594 // by and active SkImage_Ganesh.
595 SkCanvas* canvas1 = surface1->getCanvas();
596 SkCanvas* canvas2 = surface2->getCanvas();
597 canvas1->clear(1);
598 sk_sp<SkImage> image1(surface1->makeImageSnapshot());
599 // Trigger copy on write, new backing is a scratch texture
600 canvas1->clear(2);
601 sk_sp<SkImage> image2(surface1->makeImageSnapshot());
602 // Trigger copy on write, old backing should not be returned to scratch
603 // pool because it is held by image2
604 canvas1->clear(3);
605
606 canvas2->clear(4);
607 sk_sp<SkImage> image3(surface2->makeImageSnapshot());
608 // Trigger copy on write on surface2. The new backing store should not
609 // be recycling a texture that is held by an existing image.
610 canvas2->clear(5);
611 sk_sp<SkImage> image4(surface2->makeImageSnapshot());
612
613 auto imageProxy = [ctx = surface1->recordingContext()](SkImage* img) {
615 SkASSERT(proxy);
616 return proxy;
617 };
618
619 REPORTER_ASSERT(reporter, imageProxy(image4.get()) != imageProxy(image3.get()));
620 // The following assertion checks crbug.com/263329
621 REPORTER_ASSERT(reporter, imageProxy(image4.get()) != imageProxy(image2.get()));
622 REPORTER_ASSERT(reporter, imageProxy(image4.get()) != imageProxy(image1.get()));
623 REPORTER_ASSERT(reporter, imageProxy(image3.get()) != imageProxy(image2.get()));
624 REPORTER_ASSERT(reporter, imageProxy(image3.get()) != imageProxy(image1.get()));
625 REPORTER_ASSERT(reporter, imageProxy(image2.get()) != imageProxy(image1.get()));
626}
GrRecordingContext * recordingContext() const
Definition: SkSurface.cpp:228
sk_sp< SkImage > makeImageSnapshot()
Definition: SkSurface.cpp:90

◆ test_no_canvas1()

static void test_no_canvas1 ( skiatest::Reporter reporter,
SkSurface surface,
SkSurface::ContentChangeMode  mode 
)
static

Definition at line 705 of file SurfaceTest.cpp.

707 {
708 // Test passes by not asserting
709 surface->notifyContentWillChange(mode);
710}

◆ test_no_canvas2()

static void test_no_canvas2 ( skiatest::Reporter reporter,
SkSurface surface,
SkSurface::ContentChangeMode  mode 
)
static

Definition at line 711 of file SurfaceTest.cpp.

713 {
714 // Verifies the robustness of SkSurface for handling use cases where calls
715 // are made before a canvas is created.
716 sk_sp<SkImage> image1 = surface->makeImageSnapshot();
717 sk_sp<SkImage> aur_image1(image1); // NOLINT(performance-unnecessary-copy-initialization)
718 surface->notifyContentWillChange(mode);
719 sk_sp<SkImage> image2 = surface->makeImageSnapshot();
720 sk_sp<SkImage> aur_image2(image2); // NOLINT(performance-unnecessary-copy-initialization)
721 REPORTER_ASSERT(reporter, image1 != image2);
722}

◆ test_overdraw_surface()

static void test_overdraw_surface ( skiatest::Reporter r,
SkSurface surface 
)
static

Definition at line 1235 of file SurfaceTest.cpp.

1235 {
1236 SkOverdrawCanvas canvas(surface->getCanvas());
1237 canvas.drawPaint(SkPaint());
1238 sk_sp<SkImage> image = surface->makeImageSnapshot();
1239
1242 for (int y = 0; y < 10; y++) {
1243 for (int x = 0; x < 10; x++) {
1244 REPORTER_ASSERT(r, 1 == SkGetPackedA32(*bitmap.getAddr32(x, y)));
1245 }
1246 }
1247}
#define SkGetPackedA32(packed)
Definition: SkColorPriv.h:92
bool asLegacyBitmap(SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const
Definition: SkImage.cpp:233
Definition: bitmap.py:1

◆ test_snapshot_alphatype()

static void test_snapshot_alphatype ( skiatest::Reporter reporter,
const sk_sp< SkSurface > &  surface,
SkAlphaType  expectedAlphaType 
)
static

Definition at line 323 of file SurfaceTest.cpp.

324 {
326 if (surface) {
327 sk_sp<SkImage> image(surface->makeImageSnapshot());
329 if (image) {
330 REPORTER_ASSERT(reporter, image->alphaType() == expectedAlphaType);
331 }
332 }
333}
SkAlphaType alphaType() const
Definition: SkImage.cpp:154

◆ test_surface_context_clear()

static void test_surface_context_clear ( skiatest::Reporter reporter,
GrDirectContext dContext,
skgpu::ganesh::SurfaceContext surfaceContext,
uint32_t  expectedValue 
)
static

Definition at line 856 of file SurfaceTest.cpp.

859 {
860 int w = surfaceContext->width();
861 int h = surfaceContext->height();
862
864
866 readback.alloc(ii);
867
868 readback.erase(~expectedValue);
869 surfaceContext->readPixels(dContext, readback, {0, 0});
870 for (int y = 0; y < h; ++y) {
871 for (int x = 0; x < w; ++x) {
872 uint32_t pixel = readback.addr32()[y * w + x];
873 if (pixel != expectedValue) {
874 SkString msg;
875 if (expectedValue) {
876 msg = "SkSurface should have left render target unmodified";
877 } else {
878 msg = "SkSurface should have cleared the render target";
879 }
881 "%s but read 0x%08X (instead of 0x%08X) at %d,%d", msg.c_str(), pixel,
882 expectedValue, x, y);
883 return;
884 }
885 }
886 }
887}
static void readback(const SkBitmap &src, int *result, int resultCount)
Definition: BlurTest.cpp:264
const char * c_str() const
Definition: SkString.h:133
bool readPixels(GrDirectContext *dContext, GrPixmap dst, SkIPoint srcPt)

◆ test_surface_draw_partially()

static void test_surface_draw_partially ( skiatest::Reporter reporter,
sk_sp< SkSurface surface,
SkColor  origColor 
)
static

Definition at line 937 of file SurfaceTest.cpp.

938 {
939 const int kW = surface->width();
940 const int kH = surface->height();
942 const SkColor kRectColor = ~origColor | 0xFF000000;
943 paint.setColor(kRectColor);
944 surface->getCanvas()->drawRect(SkRect::MakeIWH(kW, kH/2), paint);
945
946 // Read back RGBA to avoid format conversions that may not be supported on all platforms.
948
950 readback.alloc(readInfo);
951
952 readback.erase(~origColor);
953 REPORTER_ASSERT(reporter, surface->readPixels(readback.info(), readback.writable_addr(),
954 readback.rowBytes(), 0, 0));
955 bool stop = false;
956
957 SkPMColor origColorPM = SkPackARGB_as_RGBA(SkColorGetA(origColor),
958 SkColorGetR(origColor),
959 SkColorGetG(origColor),
960 SkColorGetB(origColor));
961 SkPMColor rectColorPM = SkPackARGB_as_RGBA(SkColorGetA(kRectColor),
962 SkColorGetR(kRectColor),
963 SkColorGetG(kRectColor),
964 SkColorGetB(kRectColor));
965
966 for (int y = 0; y < kH/2 && !stop; ++y) {
967 for (int x = 0; x < kW && !stop; ++x) {
968 REPORTER_ASSERT(reporter, rectColorPM == readback.addr32()[x + y * kW]);
969 if (rectColorPM != readback.addr32()[x + y * kW]) {
970 SkDebugf("--- got [%x] expected [%x], x = %d, y = %d\n",
971 readback.addr32()[x + y * kW], rectColorPM, x, y);
972 stop = true;
973 }
974 }
975 }
976 stop = false;
977 for (int y = kH/2; y < kH && !stop; ++y) {
978 for (int x = 0; x < kW && !stop; ++x) {
979 REPORTER_ASSERT(reporter, origColorPM == readback.addr32()[x + y * kW]);
980 if (origColorPM != readback.addr32()[x + y * kW]) {
981 SkDebugf("--- got [%x] expected [%x], x = %d, y = %d\n",
982 readback.addr32()[x + y * kW], origColorPM, x, y);
983 stop = true;
984 }
985 }
986 }
987}
static uint32_t SkPackARGB_as_RGBA(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColorData.h:65
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
#define SkColorGetA(color)
Definition: SkColor.h:61
#define SkColorGetB(color)
Definition: SkColor.h:73
constexpr int kH
constexpr int kW
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623

◆ test_writable_after_snapshot_release()

static void test_writable_after_snapshot_release ( skiatest::Reporter reporter,
SkSurface surface 
)
static

Definition at line 565 of file SurfaceTest.cpp.

566 {
567 // This test succeeds by not triggering an assertion.
568 // The test verifies that the surface remains writable (usable) after
569 // acquiring and releasing a snapshot without triggering a copy on write.
570 SkCanvas* canvas = surface->getCanvas();
571 canvas->clear(1);
572 surface->makeImageSnapshot(); // Create and destroy SkImage
573 canvas->clear(2); // Must not assert internally
574}