26#if defined(SK_GRAPHITE)
51#include <initializer_list>
95 uint8_t*
result =
reinterpret_cast<uint8_t*
>(&r32);
120 U8CPU g = (n >> 8) & 0xff;
121 U8CPU r = (n >> 16) & 0xff;
156 surface->writePixels(bmp, 0, 0);
195 if (!didPremulConversion) {
240 size_t canvasRowBytes;
241 const uint32_t* canvasPixels;
248 if (!surf->
readPixels(secretDevBitmap, 0, 0)) {
252 canvasRowBytes = secretDevBitmap.
rowBytes();
253 canvasPixels =
static_cast<const uint32_t*
>(secretDevBitmap.
getPixels());
255 if (
nullptr == canvasPixels) {
266 for (
int cy = 0; cy <
DEV_H; ++cy) {
267 for (
int cx = 0; cx <
DEV_W; ++cx) {
268 SkPMColor canvasPixel = canvasPixels[cx];
270 int bx = cx - writeX;
271 int by = cy - writeY;
279 bmpPMColor |= 0xFF000000;
282 ERRORF(
reporter,
"Expected canvas pixel at %d, %d to be 0x%08x, got 0x%08x. "
283 "Write performed premul: %d", cx, cy, bmpPMColor, canvasPixel, mul);
288 if (canvasPixel != testColor) {
289 ERRORF(
reporter,
"Canvas pixel outside write rect at %d, %d changed."
290 " Should be 0x%08x, got 0x%08x. ", cx, cy, testColor, canvasPixel);
295 if (cy !=
DEV_H -1) {
296 const char* pad =
reinterpret_cast<const char*
>(canvasPixels +
DEV_W);
297 for (
size_t px = 0; px < canvasRowBytes - 4 *
DEV_W; ++px) {
305 canvasPixels += canvasRowBytes/4;
325 size_t rowBytes = tightRB ? 0 : 4 *
w + 60;
330 for (
int y = 0;
y <
h; ++
y) {
331 for (
int x = 0;
x <
w; ++
x) {
347 uint32_t genID1 =
surface->generationID();
349 uint32_t genID2 =
surface->generationID();
404 static const struct {
414 for (
size_t r = 0; r < std::size(testRects); ++r) {
415 const SkIRect& rect = testRects[r];
416 for (
int tightBmp = 0; tightBmp < 2; ++tightBmp) {
417 for (
size_t c = 0; c < std::size(gSrcConfigs); ++c) {
426 rect.height(),
SkToBool(tightBmp)));
427 uint32_t idBefore =
surface->generationID();
429 surface->writePixels(bmp, rect.fLeft, rect.fTop);
431 uint32_t idAfter =
surface->generationID();
433 bmp, rect.fLeft, rect.fTop));
451 for (
auto& tightRowBytes : {
true,
false }) {
452 const size_t rowBytes = tightRowBytes ?
info.minRowBytes() : 4 *
DEV_W + 100;
453 const size_t size =
info.computeByteSize(rowBytes);
456 if (!tightRowBytes) {
491#if defined(SK_GRAPHITE)
506 std::unique_ptr<skgpu::graphite::Recorder> recorder = context->makeRecorder();
557 surf->writePixels(bm, 0, 0);
559 return surf->makeImageSnapshot();
572 auto context = ctxInfo.directContext();
574 const GrCaps* caps = context->priv().caps();
577 static const int kHalfSize = 31;
579 static const uint32_t kLeftColor = 0xFF222222;
580 static const uint32_t kRightColor = 0xFFAAAAAA;
591 static constexpr SkISize kDims = {32, 64};
600 skgpu::Mipmapped::kNo,
605 temp->instantiate(context->priv().resourceProvider());
613 dest->getCanvas()->drawImage(std::move(leftImg), 0, 0);
616 dest->getCanvas()->drawImage(std::move(rightImg), kHalfSize, 0);
622 bool isCorrect =
true;
623 for (
int y = 0; isCorrect &&
y < 16; ++
y) {
626 for (
int x = 0;
x < 16; ++
x) {
627 if (kLeftColor != sl[
x]) {
632 for (
int x = kHalfSize;
x < kHalfSize+16; ++
x) {
633 if (kRightColor != sl[
x]) {
653 auto srcII = dstII.makeColorType(
colorType);
654 size_t badRowBytes = (surf->width() + 1)*bpp - 1;
655 auto storage = std::make_unique<char[]>(badRowBytes*surf->height());
656 memset(storage.get(), 0, badRowBytes * surf->height());
659 !surf->getCanvas()->writePixels(srcII, storage.get(), badRowBytes, 0, 0));
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kBottomLeft_GrSurfaceOrigin
@ kTopLeft_GrSurfaceOrigin
static const int kFullSize
#define check(reporter, ref, unref, make, kill)
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
#define SkAssertResult(cond)
static SkPMColor SkSwizzle_RGBA_to_PMColor(uint32_t c)
static SkPMColor SkSwizzle_BGRA_to_PMColor(uint32_t c)
#define SkGetPackedB32(packed)
#define SkGetPackedR32(packed)
static SkPMColor SkPremultiplyARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
#define SkGetPackedA32(packed)
#define SkGetPackedG32(packed)
static SkPMColor SkPackARGB32NoCheck(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
@ 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
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static bool SkColorTypeIsAlphaOnly(SkColorType ct)
static bool SkImageInfoValidConversion(const SkImageInfo &dst, const SkImageInfo &src)
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
SK_API bool SkColorTypeIsAlwaysOpaque(SkColorType ct)
SK_API void sk_free(void *)
static void * sk_malloc_throw(size_t size)
static U8CPU SkMulDiv255Ceiling(U8CPU a, U8CPU b)
static int32_t SkAbs32(int32_t value)
static constexpr bool SkToBool(const T &x)
#define DEF_TEST(name, reporter)
#define REPORTER_ASSERT(r, cond,...)
#define DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS(name, reporter, graphite_context, ctsEnforcement)
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
static void test_write_pixels(skiatest::Reporter *reporter, SkSurface *surface, const SkImageInfo &surfaceInfo)
static void test_write_pixels_non_texture(skiatest::Reporter *reporter, GrDirectContext *dContext, int sampleCnt)
static bool check_pixel(SkPMColor a, SkPMColor b, bool didPremulConversion)
static bool alloc_row_bytes(SkBitmap *bm, const SkImageInfo &info, size_t rowBytes)
static SkPMColor convert_to_PMColor(SkColorType ct, SkAlphaType at, uint32_t color)
static void fill_surface(SkSurface *surface)
static uint32_t get_bitmap_color(int x, int y, int w, SkColorType ct, SkAlphaType at)
static bool check_write(skiatest::Reporter *reporter, SkSurface *surf, SkAlphaType surfaceAlphaType, const SkBitmap &bitmap, int writeX, int writeY)
static sk_sp< SkSurface > create_surf(GrRecordingContext *rContext, int width, int height)
static const U8CPU DEV_PAD
static uint32_t pack_color_type(SkColorType ct, U8CPU a, U8CPU r, U8CPU g, U8CPU b)
bool write_should_succeed(const SkImageInfo &dstInfo, const SkImageInfo &srcInfo, bool isGPU)
static void free_pixels(void *pixels, void *ctx)
static SkPMColor get_canvas_color(int x, int y)
static const SkIRect DEV_RECT
static bool setup_bitmap(SkBitmap *bm, SkColorType ct, SkAlphaType at, int w, int h, int tightRB)
static void call_writepixels(SkSurface *surface)
static uint32_t premul(uint32_t color)
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
sk_sp< GrTextureProxy > createProxy(const GrBackendFormat &, SkISize dimensions, GrRenderable, int renderTargetSampleCnt, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted, GrProtected, std::string_view label, GrInternalSurfaceFlags=GrInternalSurfaceFlags::kNone, UseAllocator useAllocator=UseAllocator::kYes)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
const SkImageInfo & info() const
void allocN32Pixels(int width, int height, bool isOpaque=false)
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
uint32_t * getAddr32(int x, int y) const
void setPixelRef(sk_sp< SkPixelRef > pixelRef, int dx, int dy)
void eraseColor(SkColor4f) const
virtual SkISize getBaseLayerSize() const
bool readPixels(const SkPixmap &dst, int srcX, int srcY)
uint32_t uint32_t * format
SK_API sk_sp< SkPixelRef > MakeAllocate(const SkImageInfo &, size_t rowBytes)
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 > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
sk_sp< SkSurface > MakeBackendRenderTargetSurface(GrDirectContext *dContext, const SkImageInfo &ii, GrSurfaceOrigin origin, int sampleCnt, GrProtected isProtected, const SkSurfaceProps *props)
SK_API void FlushAndSubmit(sk_sp< SkSurface >)
static bool Intersects(const SkIRect &a, const SkIRect &b)
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
static constexpr SkIRect MakeSize(const SkISize &size)
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
bool contains(int32_t x, int32_t y) const
static SkImageInfo MakeN32Premul(int width, int height)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkAlphaType alphaType() const
SkColorType colorType() const