78#include <initializer_list>
94 *requestedInfo =
info;
102 *requestedInfo =
info;
104 const size_t rowBytes =
info.minRowBytes();
113 *requestedInfo =
info;
122 *requestedInfo =
info;
146 using namespace skgpu;
148 auto context = ctxInfo.directContext();
150 Protected isProtected =
Protected(context->priv().caps()->supportsProtectedContent());
153 static constexpr int kSize = 10;
159 bool can = context->colorTypeSupportedAsSurface(
colorType);
177 if (context->colorTypeSupportedAsSurface(
colorType)) {
178 static constexpr int kSampleCnt = 2;
180 bool can = context->maxSurfaceSampleCountForColorType(
colorType) >= kSampleCnt;
182 context, Budgeted::kYes,
info, kSampleCnt,
nullptr);
190 "colorTypeSupportedAsSurface:%d, surf:%d, ct:%d", can,
SkToBool(surf),
195 int storedCnt = rtp->numSamples();
198 context->priv().caps()->getRenderTargetSampleCount(storedCnt,
format);
200 "Should store an allowed sample count (%d vs %d)", allowedCnt,
205 for (
int sampleCnt : {1, 2}) {
213 bool can = context->colorTypeSupportedAsSurface(
colorType) &&
214 context->maxSurfaceSampleCountForColorType(
colorType) >= sampleCnt;
230 int storedCnt = rtp->numSamples();
232 int allowedCnt = context->priv().caps()->getRenderTargetSampleCount(storedCnt,
235 "Should store an allowed sample count (%d vs %d)", allowedCnt,
246 using namespace skgpu;
248 auto context = ctxInfo.directContext();
250 Protected isProtected =
Protected(context->priv().caps()->supportsProtectedContent());
252 static constexpr int kSize = 10;
257 int maxSampleCnt = context->maxSurfaceSampleCountForColorType(
colorType);
261 if (!context->colorTypeSupportedAsSurface(
colorType)) {
272 int sampleCnt = ((
SkSurface_Ganesh*)(surf.get()))->getDevice()->targetProxy()->numSamples();
274 maxSampleCnt, sampleCnt);
281 bool expectPeekSuccess) {
287 bool success =
surface->getCanvas()->peekPixels(&pmap);
291 const void* addr2 =
surface->peekPixels(&pmap2) ? pmap2.
addr() :
nullptr;
337 auto surface(surface_func(at,
nullptr));
349 auto surface(surface_func(ctxInfo.directContext(), at,
nullptr));
391 for (
auto& accessMode : accessModes) {
404template <
typename Type, Type (*func)(SkSurface*, SkSurface::BackendHandleAccess)>
436 test_backend_unique_id<GrBackendTexture, &SkSurfaces::GetBackendTexture>(
reporter,
441 test_backend_unique_id<GrBackendRenderTarget, &SkSurfaces::GetBackendRenderTarget>(
452 auto direct = ctxInfo.directContext();
459 direct->abandonContext();
470 auto dContext = ctxInfo.directContext();
483 dContext->flush(
surface.get());
484 dContext->abandonContext();
512 const SkColor testColor = 0x01020304;
514 const SkPoint testPoints[3] = {
519 const size_t testPointCount = 3;
530#define EXPECT_COPY_ON_WRITE(command) \
532 sk_sp<SkImage> imageBefore = surface->makeImageSnapshot(); \
533 sk_sp<SkImage> aur_before(imageBefore); \
535 sk_sp<SkImage> imageAfter = surface->makeImageSnapshot(); \
536 sk_sp<SkImage> aur_after(imageAfter); \
537 REPORTER_ASSERT(reporter, imageBefore != imageAfter); \
727 for (
auto&
mode : modes) {
740 for (
auto&
mode : modes) {
791 for (
int j = 0; j < pixmap.
info().
height(); ++j) {
825 surf->getCanvas()->clear(
color);
831 GrRenderTarget* rt = surfaceGpu->getDevice()->targetProxy()->peekRenderTarget();
859 uint32_t expectedValue) {
860 int w = surfaceContext->
width();
861 int h = surfaceContext->
height();
870 for (
int y = 0;
y <
h; ++
y) {
871 for (
int x = 0;
x <
w; ++
x) {
873 if (pixel != expectedValue) {
876 msg =
"SkSurface should have left render target unmodified";
878 msg =
"SkSurface should have cleared the render target";
881 "%s but read 0x%08X (instead of 0x%08X) at %d,%d", msg.
c_str(), pixel,
882 expectedValue,
x,
y);
890 auto dContext = ctxInfo.directContext();
895 GrColorInfo colorInfo(ct,
i->alphaType(),
i->refColorSpace());
896 return dContext->priv().makeSC(view, std::move(colorInfo));
908 ERRORF(
reporter,
"Could access surface context of GPU SkSurface.");
912 auto imageSurfaceCtx = makeImageSurfaceContext(
surface.get());
917 const SkColor4f kOrigColor{.67f, .67f, .67f, 1};
918 for (
auto& surfaceFunc :
920 auto surface = surfaceFunc(dContext, 1, kOrigColor);
927 ERRORF(
reporter,
"Could access surface context of GPU SkSurface.");
931 auto imageSurfaceCtx = makeImageSurfaceContext(
surface.get());
933 kOrigColor.toSkColor());
942 const SkColor kRectColor = ~origColor | 0xFF000000;
943 paint.setColor(kRectColor);
966 for (
int y = 0;
y <
kH/2 && !stop; ++
y) {
967 for (
int x = 0;
x <
kW && !stop; ++
x) {
970 SkDebugf(
"--- got [%x] expected [%x], x = %d, y = %d\n",
977 for (
int y =
kH/2;
y <
kH && !stop; ++
y) {
978 for (
int x = 0;
x <
kW && !stop; ++
x) {
981 SkDebugf(
"--- got [%x] expected [%x], x = %d, y = %d\n",
993 auto context = ctxInfo.directContext();
995 static const SkColor4f kOrigColor { 0.667f, 0.733f, 0.8f, 1 };
997 for (
auto& surfaceFunc :
1002 auto surface = surfaceFunc(context, 1, kOrigColor);
1024 auto ctx = ctxInfo.directContext();
1025 GrGpu* gpu = ctx->priv().getGpu();
1027 for (
bool useTexture : {
false,
true}) {
1038 mbet = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
1052 sk_gpu_test::ManagedBackendTexture::ReleaseProc,
1055 backendRT = gpu->createTestingOnlyBackendRenderTarget({
kWidth,
kHeight},
1084 gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
1093 auto context = ctxInfo.directContext();
1094 const GrCaps* caps = context->priv().caps();
1100 static const SkColor4f kOrigColor { 0.667f, 0.733f, 0.8f, 1 };
1102 auto resourceProvider = context->priv().resourceProvider();
1104 for (
auto& surfaceFunc :
1106 for (
int sampleCnt : {1, 4, 8}) {
1107 auto surface = surfaceFunc(context, sampleCnt, kOrigColor);
1109 if (!
surface && sampleCnt > 1) {
1119 resourceProvider->attachStencilAttachment(rt, rt->
numSamples() > 1));
1128 auto context = ctxInfo.directContext();
1130 for (
int sampleCnt : {1, 2}) {
1132 auto mbet1 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
1137 auto mbet2 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
1143 auto ii2 = ii.makeWH(8, 8);
1144 auto mbet3 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
1164 surf->getCanvas()->translate(5, 5);
1165 surf->getCanvas()->saveLayer(
nullptr,
nullptr);
1173 surf->getCanvas()->restore();
1178 bool bad = !surf->readPixels(pm, 0, 0);
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;
1184 if (found != expected) {
1186 ERRORF(
reporter,
"Expected color 0x%08x, found color 0x%08x at %d, %d.",
1187 expected, found,
x,
y);
1203 bad = !surf->readPixels(pm, 0, 0);
1205 for (
int y = 0;
y < ii.height() && !bad; ++
y) {
1206 for (
int x = 0;
x < ii.width() && !bad; ++
x) {
1207 auto expected = 0xFFFF0000;
1209 if (found != expected) {
1211 ERRORF(
reporter,
"Expected color 0x%08x, found color 0x%08x at %d, %d.",
1212 expected, found,
x,
y);
1242 for (
int y = 0;
y < 10;
y++) {
1243 for (
int x = 0;
x < 10;
x++) {
1258 auto context = ctxInfo.directContext();
1269 auto canvas = surf->getCanvas();
1279 size_t rowBytes =
info.minRowBytes();
1282 auto img = surf->makeImageSnapshot();
1285 SkDebugf(
"image failed: [%08X %08X] %14s %s\n",
1286 (uint32_t)
info.width(),
1287 (uint32_t)
info.height(),
1302 const int32_t sizes[] = { -1, 0, 1, 1 << 18 };
1307 for (int32_t
size : sizes) {
static void readback(const SkBitmap &src, int *result, int resultCount)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kBottomLeft_GrSurfaceOrigin
@ kTopLeft_GrSurfaceOrigin
skgpu::Protected Protected
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kLastEnum_SkAlphaType
last valid value
static uint32_t SkPackARGB_as_RGBA(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
#define SkGetPackedA32(packed)
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kLastEnum_SkColorType
last valid value
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
#define SkColorGetR(color)
#define SkColorGetG(color)
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
constexpr SkColor SK_ColorBLUE
constexpr SkColor SK_ColorRED
#define SkColorGetA(color)
#define SkColorGetB(color)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static bool ok(int result)
static SkImage_Base * as_IB(SkImage *image)
SK_API void sk_free(void *)
static void * sk_malloc_throw(size_t size)
static constexpr bool SkToBool(const T &x)
static void test_backend_rendertarget_access_copy_on_write(skiatest::Reporter *reporter, SkSurface *surface, SkSurface::BackendHandleAccess access)
static void check_rowbytes_remain_consistent(SkSurface *surface, skiatest::Reporter *reporter)
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
static skgpu::Budgeted is_budgeted(const sk_sp< SkSurface > &surf)
DEF_TEST(SurfaceEmpty, reporter)
static void test_surface_draw_partially(skiatest::Reporter *reporter, sk_sp< SkSurface > surface, SkColor origColor)
static void test_surface_context_clear(skiatest::Reporter *reporter, GrDirectContext *dContext, skgpu::ganesh::SurfaceContext *surfaceContext, uint32_t expectedValue)
static void test_overdraw_surface(skiatest::Reporter *r, SkSurface *surface)
static void test_copy_on_write(skiatest::Reporter *reporter, SkSurface *surface)
static void test_backend_texture_access_copy_on_write(skiatest::Reporter *reporter, SkSurface *surface, SkSurface::BackendHandleAccess access)
static void test_writable_after_snapshot_release(skiatest::Reporter *reporter, SkSurface *surface)
DEF_GANESH_TEST_FOR_GL_CONTEXT(SurfaceClear_Gpu, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
static void test_canvas_peek(skiatest::Reporter *reporter, sk_sp< SkSurface > &surface, const SkImageInfo &requestInfo, bool expectPeekSuccess)
static sk_sp< SkSurface > create_gpu_surface_backend_texture(GrDirectContext *dContext, int sampleCnt, const SkColor4f &color)
static sk_sp< SkSurface > create_surface(SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
#define EXPECT_COPY_ON_WRITE(command)
static sk_sp< SkSurface > create_gpu_surface_backend_render_target(GrDirectContext *dContext, int sampleCnt, const SkColor4f &color)
static bool supports_readpixels(const GrCaps *caps, SkSurface *surface)
static sk_sp< SkSurface > create_direct_surface(SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
static void test_no_canvas2(skiatest::Reporter *reporter, SkSurface *surface, SkSurface::ContentChangeMode mode)
static void test_backend_unique_id(skiatest::Reporter *reporter, SkSurface *surface)
static sk_sp< SkSurface > create_gpu_surface(GrRecordingContext *rContext, SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
static void test_snapshot_alphatype(skiatest::Reporter *reporter, const sk_sp< SkSurface > &surface, SkAlphaType expectedAlphaType)
static sk_sp< SkSurface > create_gpu_scratch_surface(GrRecordingContext *rContext, SkAlphaType at=kPremul_SkAlphaType, SkImageInfo *requestedInfo=nullptr)
static void test_no_canvas1(skiatest::Reporter *reporter, SkSurface *surface, SkSurface::ContentChangeMode mode)
static void test_crbug263329(skiatest::Reporter *reporter, SkSurface *surface1, SkSurface *surface2)
static void release_direct_surface_storage(void *pixels, void *context)
bool CurrentTestHarnessIsSkQP()
#define REPORTER_ASSERT(r, cond,...)
virtual SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface *) const =0
bool avoidStencilBuffers() const
skgpu::Budgeted isBudgeted() const
void alloc(const SkImageInfo &)
sk_sp< SkImage > asImage() const
void allocN32Pixels(int width, int height, bool isOpaque=false)
void eraseColor(SkColor4f) const
void drawPaint(const SkPaint &paint)
void clear(SkColor color)
@ kPoints_PointMode
draw each point separately
uint32_t uniqueID() const
SkAlphaType alphaType() const
bool peekPixels(SkPixmap *pixmap) const
bool asLegacyBitmap(SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
const uint32_t * addr32() const
const SkImageInfo & info() const
const void * addr() const
void setRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
bool setRect(const SkIRect &rect)
const char * c_str() const
skgpu::ganesh::Device * getDevice()
@ kDiscard_ContentChangeMode
discards surface on change
@ kRetain_ContentChangeMode
preserves surface on change
GrRecordingContext * recordingContext() const
sk_sp< SkImage > makeImageSnapshot()
@ kFlushRead
back-end object is readable
@ kFlushWrite
back-end object is writable
@ kDiscardWrite
back-end object must be overwritten
GrRenderTargetProxy * targetProxy()
bool readPixels(GrDirectContext *dContext, GrPixmap dst, SkIPoint srcPt)
uint32_t uint32_t * format
static SkScalar drawString(SkCanvas *canvas, const SkString &text, SkScalar x, SkScalar y, const SkFont &font)
static float max(float r, float g, float b)
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)
SK_API sk_sp< SkImage > RasterFromPixmap(const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
SK_API bool GetBackendTextureFromImage(const SkImage *img, GrBackendTexture *outTexture, bool flushPendingGrContextIO, GrSurfaceOrigin *origin=nullptr)
sk_sp< const SkImage > image
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
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)
SK_API GrBackendTexture GetBackendTexture(SkSurface *, BackendHandleAccess)
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)
SK_API GrBackendRenderTarget GetBackendRenderTarget(SkSurface *, BackendHandleAccess)
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)
SK_API sk_sp< SkSurface > Null(int width, int height)
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
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
const myers::Point & get(const myers::Segment &)
sk_sp< SkSurface > MakeBackendRenderTargetSurface(GrDirectContext *dContext, const SkImageInfo &ii, GrSurfaceOrigin origin, int sampleCnt, GrProtected isProtected, const SkSurfaceProps *props)
GrTextureProxy * GetTextureImageProxy(SkImage *image, GrRecordingContext *rContext)
sk_sp< SkSurface > MakeBackendTextureSurface(GrDirectContext *dContext, const SkImageInfo &ii, GrSurfaceOrigin origin, int sampleCnt, skgpu::Mipmapped mipmapped, GrProtected isProtected, const SkSurfaceProps *props)
SurfaceFillContext * TopDeviceSurfaceFillContext(const SkCanvas *canvas)
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)
GrRenderTargetProxy * TopDeviceTargetProxy(const SkCanvas *canvas)
static void Release(void *self)
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
static SkImageInfo MakeN32Premul(int width, int height)
size_t minRowBytes() const
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static SkRect MakeIWH(int w, int h)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
static constexpr SkRect MakeWH(float w, float h)