Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
WritePixelsTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
17#include "include/core/SkRect.h"
19#include "include/core/SkSize.h"
25#include "include/gpu/GrTypes.h"
26#if defined(SK_GRAPHITE)
29#endif
37#include "src/base/SkMathPriv.h"
45#include "tests/Test.h"
47
48#include <array>
49#include <cstdint>
50#include <cstring>
51#include <initializer_list>
52#include <memory>
53#include <utility>
54
56class SkImage;
57struct GrContextOptions;
58
59static const int DEV_W = 100, DEV_H = 100;
61static const U8CPU DEV_PAD = 0xee;
62
63static SkPMColor get_canvas_color(int x, int y) {
64 SkASSERT(x >= 0 && x < DEV_W);
65 SkASSERT(y >= 0 && y < DEV_H);
66
67 U8CPU r = x;
68 U8CPU g = y;
69 U8CPU b = 0xc;
70
71 U8CPU a = 0x0;
72 switch ((x+y) % 5) {
73 case 0:
74 a = 0xff;
75 break;
76 case 1:
77 a = 0x80;
78 break;
79 case 2:
80 a = 0xCC;
81 break;
82 case 3:
83 a = 0x00;
84 break;
85 case 4:
86 a = 0x01;
87 break;
88 }
89 return SkPremultiplyARGBInline(a, r, g, b);
90}
91
92// assumes any premu/.unpremul has been applied
93static uint32_t pack_color_type(SkColorType ct, U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
94 uint32_t r32;
95 uint8_t* result = reinterpret_cast<uint8_t*>(&r32);
96 switch (ct) {
98 result[0] = b;
99 result[1] = g;
100 result[2] = r;
101 result[3] = a;
102 break;
103 case kRGBA_8888_SkColorType: // fallthrough
105 result[0] = r;
106 result[1] = g;
107 result[2] = b;
108 result[3] = a;
109 break;
110 default:
111 SkASSERT(0);
112 return 0;
113 }
114 return r32;
115}
116
117static uint32_t get_bitmap_color(int x, int y, int w, SkColorType ct, SkAlphaType at) {
118 int n = y * w + x;
119 U8CPU b = n & 0xff;
120 U8CPU g = (n >> 8) & 0xff;
121 U8CPU r = (n >> 16) & 0xff;
122 U8CPU a = 0;
123 switch ((x+y) % 5) {
124 case 4:
125 a = 0xff;
126 break;
127 case 3:
128 a = 0x80;
129 break;
130 case 2:
131 a = 0xCC;
132 break;
133 case 1:
134 a = 0x01;
135 break;
136 case 0:
137 a = 0x00;
138 break;
139 }
140 if (kPremul_SkAlphaType == at) {
141 r = SkMulDiv255Ceiling(r, a);
142 g = SkMulDiv255Ceiling(g, a);
144 }
145 return pack_color_type(ct, a, r, g , b);
146}
147
149 SkBitmap bmp;
151 for (int y = 0; y < DEV_H; ++y) {
152 for (int x = 0; x < DEV_W; ++x) {
153 *bmp.getAddr32(x, y) = get_canvas_color(x, y);
154 }
155 }
156 surface->writePixels(bmp, 0, 0);
157}
158
159/**
160 * Lucky for us, alpha is always in the same spot (SK_A32_SHIFT), for both RGBA and BGRA.
161 * Thus this routine doesn't need to know the exact colortype
162 */
163static uint32_t premul(uint32_t color) {
164 unsigned a = SkGetPackedA32(color);
165 // these next three are not necessarily r,g,b in that order, but they are r,g,b in some order.
166 unsigned c0 = SkGetPackedR32(color);
167 unsigned c1 = SkGetPackedG32(color);
168 unsigned c2 = SkGetPackedB32(color);
169 c0 = SkMulDiv255Ceiling(c0, a);
170 c1 = SkMulDiv255Ceiling(c1, a);
171 c2 = SkMulDiv255Ceiling(c2, a);
172 return SkPackARGB32NoCheck(a, c0, c1, c2);
173}
174
176 if (kUnpremul_SkAlphaType == at) {
177 color = premul(color);
178 }
179 switch (ct) {
180 case kRGBA_8888_SkColorType: // fallthrough
183 break;
186 break;
187 default:
188 SkASSERT(0);
189 break;
190 }
191 return color;
192}
193
194static bool check_pixel(SkPMColor a, SkPMColor b, bool didPremulConversion) {
195 if (!didPremulConversion) {
196 return a == b;
197 }
198 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a));
199 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a));
200 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a));
201 int32_t aB = SkGetPackedB32(a);
202
203 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b));
204 int32_t bR = static_cast<int32_t>(SkGetPackedR32(b));
205 int32_t bG = static_cast<int32_t>(SkGetPackedG32(b));
206 int32_t bB = static_cast<int32_t>(SkGetPackedB32(b));
207
208 return aA == bA &&
209 SkAbs32(aR - bR) <= 1 &&
210 SkAbs32(aG - bG) <= 1 &&
211 SkAbs32(aB - bB) <= 1;
212}
213
214bool write_should_succeed(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo, bool isGPU) {
215 if (!SkImageInfoValidConversion(dstInfo, srcInfo)) {
216 return false;
217 }
218 if (!isGPU) {
219 return true;
220 }
221 // The GPU backend supports writing unpremul data to a premul dst but not vice versa.
222 if (srcInfo.alphaType() == kPremul_SkAlphaType &&
223 dstInfo.alphaType() == kUnpremul_SkAlphaType) {
224 return false;
225 }
226 if (!SkColorTypeIsAlwaysOpaque(srcInfo.colorType()) &&
228 return false;
229 }
230 // The source has no alpha value and the dst is only alpha
231 if (SkColorTypeIsAlwaysOpaque(srcInfo.colorType()) &&
233 return false;
234 }
235 return true;
236}
237
238static bool check_write(skiatest::Reporter* reporter, SkSurface* surf, SkAlphaType surfaceAlphaType,
239 const SkBitmap& bitmap, int writeX, int writeY) {
240 size_t canvasRowBytes;
241 const uint32_t* canvasPixels;
242
243 // Can't use canvas->peekPixels(), as we are trying to look at GPU pixels sometimes as well.
244 // At some point this will be unsupported, as we won't allow accessBitmap() to magically call
245 // readPixels for the client.
246 SkBitmap secretDevBitmap;
247 secretDevBitmap.allocN32Pixels(surf->width(), surf->height());
248 if (!surf->readPixels(secretDevBitmap, 0, 0)) {
249 return false;
250 }
251
252 canvasRowBytes = secretDevBitmap.rowBytes();
253 canvasPixels = static_cast<const uint32_t*>(secretDevBitmap.getPixels());
254
255 if (nullptr == canvasPixels) {
256 return false;
257 }
258
259 if (surf->width() != DEV_W || surf->height() != DEV_H) {
260 return false;
261 }
262
263 const SkImageInfo& bmInfo = bitmap.info();
264
265 SkIRect writeRect = SkIRect::MakeXYWH(writeX, writeY, bitmap.width(), bitmap.height());
266 for (int cy = 0; cy < DEV_H; ++cy) {
267 for (int cx = 0; cx < DEV_W; ++cx) {
268 SkPMColor canvasPixel = canvasPixels[cx];
269 if (writeRect.contains(cx, cy)) {
270 int bx = cx - writeX;
271 int by = cy - writeY;
272 uint32_t bmpColor8888 = get_bitmap_color(bx, by, bitmap.width(),
273 bmInfo.colorType(), bmInfo.alphaType());
274 bool mul = (kUnpremul_SkAlphaType == bmInfo.alphaType());
275 SkPMColor bmpPMColor = convert_to_PMColor(bmInfo.colorType(), bmInfo.alphaType(),
276 bmpColor8888);
277 if (bmInfo.alphaType() == kOpaque_SkAlphaType ||
278 surfaceAlphaType == kOpaque_SkAlphaType) {
279 bmpPMColor |= 0xFF000000;
280 }
281 if (!check_pixel(bmpPMColor, canvasPixel, mul)) {
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);
284 return false;
285 }
286 } else {
287 SkPMColor testColor = get_canvas_color(cx, cy);
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);
291 return false;
292 }
293 }
294 }
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) {
298 bool check;
299 REPORTER_ASSERT(reporter, check = (pad[px] == static_cast<char>(DEV_PAD)));
300 if (!check) {
301 return false;
302 }
303 }
304 }
305 canvasPixels += canvasRowBytes/4;
306 }
307
308 return true;
309}
310
311// This is a tricky pattern, because we have to setConfig+rowBytes AND specify
312// a custom pixelRef (which also has to specify its rowBytes), so we have to be
313// sure that the two rowBytes match (and the infos match).
314//
315static bool alloc_row_bytes(SkBitmap* bm, const SkImageInfo& info, size_t rowBytes) {
316 if (!bm->setInfo(info, rowBytes)) {
317 return false;
318 }
320 bm->setPixelRef(std::move(pr), 0, 0);
321 return true;
322}
323
324static bool setup_bitmap(SkBitmap* bm, SkColorType ct, SkAlphaType at, int w, int h, int tightRB) {
325 size_t rowBytes = tightRB ? 0 : 4 * w + 60;
327 if (!alloc_row_bytes(bm, info, rowBytes)) {
328 return false;
329 }
330 for (int y = 0; y < h; ++y) {
331 for (int x = 0; x < w; ++x) {
332 *bm->getAddr32(x, y) = get_bitmap_color(x, y, w, ct, at);
333 }
334 }
335 return true;
336}
337
340 SkPMColor pixel = 0;
341 surface->writePixels({info, &pixel, sizeof(SkPMColor)}, 0, 0);
342}
343
344DEF_TEST(WritePixelsSurfaceGenID, reporter) {
347 uint32_t genID1 = surface->generationID();
349 uint32_t genID2 = surface->generationID();
350 REPORTER_ASSERT(reporter, genID1 != genID2);
351}
352
354 const SkImageInfo& surfaceInfo) {
355 const SkIRect testRects[] = {
356 // entire thing
357 DEV_RECT,
358 // larger on all sides
359 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H + 10),
360 // fully contained
361 SkIRect::MakeLTRB(DEV_W / 4, DEV_H / 4, 3 * DEV_W / 4, 3 * DEV_H / 4),
362 // outside top left
363 SkIRect::MakeLTRB(-10, -10, -1, -1),
364 // touching top left corner
365 SkIRect::MakeLTRB(-10, -10, 0, 0),
366 // overlapping top left corner
367 SkIRect::MakeLTRB(-10, -10, DEV_W / 4, DEV_H / 4),
368 // overlapping top left and top right corners
369 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H / 4),
370 // touching entire top edge
371 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, 0),
372 // overlapping top right corner
373 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H / 4),
374 // contained in x, overlapping top edge
375 SkIRect::MakeLTRB(DEV_W / 4, -10, 3 * DEV_W / 4, DEV_H / 4),
376 // outside top right corner
377 SkIRect::MakeLTRB(DEV_W + 1, -10, DEV_W + 10, -1),
378 // touching top right corner
379 SkIRect::MakeLTRB(DEV_W, -10, DEV_W + 10, 0),
380 // overlapping top left and bottom left corners
381 SkIRect::MakeLTRB(-10, -10, DEV_W / 4, DEV_H + 10),
382 // touching entire left edge
383 SkIRect::MakeLTRB(-10, -10, 0, DEV_H + 10),
384 // overlapping bottom left corner
385 SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W / 4, DEV_H + 10),
386 // contained in y, overlapping left edge
387 SkIRect::MakeLTRB(-10, DEV_H / 4, DEV_W / 4, 3 * DEV_H / 4),
388 // outside bottom left corner
389 SkIRect::MakeLTRB(-10, DEV_H + 1, -1, DEV_H + 10),
390 // touching bottom left corner
391 SkIRect::MakeLTRB(-10, DEV_H, 0, DEV_H + 10),
392 // overlapping bottom left and bottom right corners
393 SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10),
394 // touching entire left edge
396 // overlapping bottom right corner
397 SkIRect::MakeLTRB(3 * DEV_W / 4, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10),
398 // overlapping top right and bottom right corners
399 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10),
400 };
401
402 SkCanvas* canvas = surface->getCanvas();
403
404 static const struct {
406 SkAlphaType fAlphaType;
407 } gSrcConfigs[] = {
413 };
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) {
418 const SkColorType ct = gSrcConfigs[c].fColorType;
419 const SkAlphaType at = gSrcConfigs[c].fAlphaType;
420
421 bool isGPU = SkToBool(surface->getCanvas()->recordingContext()) ||
422 SkToBool(surface->getCanvas()->recorder());
424 SkBitmap bmp;
425 REPORTER_ASSERT(reporter, setup_bitmap(&bmp, ct, at, rect.width(),
426 rect.height(), SkToBool(tightBmp)));
427 uint32_t idBefore = surface->generationID();
428
429 surface->writePixels(bmp, rect.fLeft, rect.fTop);
430
431 uint32_t idAfter = surface->generationID();
433 bmp, rect.fLeft, rect.fTop));
434
435 // we should change the genID iff pixels were actually written.
436 SkIRect canvasRect = SkIRect::MakeSize(canvas->getBaseLayerSize());
437 SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.fTop,
438 bmp.width(), bmp.height());
439 bool expectSuccess = SkIRect::Intersects(canvasRect, writeRect) &&
440 write_should_succeed(surfaceInfo, bmp.info(), isGPU);
441 REPORTER_ASSERT(reporter, expectSuccess == (idBefore != idAfter));
442 }
443 }
444 }
445}
446
447static void free_pixels(void* pixels, void* ctx) { sk_free(pixels); }
448
449DEF_TEST(WritePixels, reporter) {
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);
454 void* pixels = sk_malloc_throw(size);
455 // if rowBytes isn't tight then set the padding to a known value
456 if (!tightRowBytes) {
457 memset(pixels, DEV_PAD, size);
458 }
459 auto surface(SkSurfaces::WrapPixels(info, pixels, rowBytes, free_pixels, nullptr));
461 }
462}
463
465 GrRecordingContext* rContext,
466 int sampleCnt) {
468 for (auto& origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
470 rContext, skgpu::Budgeted::kNo, ii, sampleCnt, origin, nullptr));
471 if (surface) {
473 }
474 }
475}
476
478 reporter,
479 ctxInfo,
481 test_write_pixels(reporter, ctxInfo.directContext(), 1);
482}
483
485 reporter,
486 ctxInfo,
488 test_write_pixels(reporter, ctxInfo.directContext(), 1);
489}
490
491#if defined(SK_GRAPHITE)
494 int sampleCnt) {
497 if (surface) {
499 }
500}
501
503 reporter,
504 context,
506 std::unique_ptr<skgpu::graphite::Recorder> recorder = context->makeRecorder();
507 test_write_pixels(reporter, recorder.get(), 1);
508}
509#endif
510
512 GrDirectContext* dContext,
513 int sampleCnt) {
515 SkColorType colorType = kN32_SkColorType;
517 {DEV_W, DEV_H},
518 origin,
519 sampleCnt,
520 colorType);
521 if (surface) {
524 }
525 }
526}
527
529 reporter,
530 ctxInfo,
532 test_write_pixels_non_texture(reporter, ctxInfo.directContext(), 1);
533}
534
535DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(WritePixelsNonTextureMSAA_Gpu,
536 reporter,
537 ctxInfo,
539 test_write_pixels_non_texture(reporter, ctxInfo.directContext(), 4);
540}
541
550
553 SkBitmap bm;
554 bm.allocPixels(smII);
555 bm.eraseColor(color);
556
557 surf->writePixels(bm, 0, 0);
558
559 return surf->makeImageSnapshot();
560}
561
562// This is tests whether the first writePixels is completed before the
563// second writePixels takes effect (i.e., that writePixels correctly flushes
564// in between uses of the shared backing resource).
565// The unit test fails on Nexus 6P/Android M with driver 129.0 without the
566// "DisallowTexSubImageForUnormConfigTexturesEverBoundToFBO" workaround enabled.
567// skbug.com/11834
569 reporter,
570 ctxInfo,
572 auto context = ctxInfo.directContext();
573 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
574 const GrCaps* caps = context->priv().caps();
575
576 static const int kFullSize = 62;
577 static const int kHalfSize = 31;
578
579 static const uint32_t kLeftColor = 0xFF222222;
580 static const uint32_t kRightColor = 0xFFAAAAAA;
581
584 const SkImageInfo halfII = SkImageInfo::Make(kHalfSize, kFullSize,
586
588
589 {
590 // Seed the resource cached with a scratch texture that will be reused by writePixels
591 static constexpr SkISize kDims = {32, 64};
592
594 GrRenderable::kNo);
595
596 sk_sp<GrTextureProxy> temp = proxyProvider->createProxy(format,
597 kDims,
598 GrRenderable::kNo,
599 1,
600 skgpu::Mipmapped::kNo,
603 GrProtected::kNo,
604 /*label=*/"WritePixelsTest");
605 temp->instantiate(context->priv().resourceProvider());
606 }
607
608 // Create the surfaces and flush them to ensure there is no lingering pendingIO
609 sk_sp<SkSurface> leftSurf = create_surf(context, kHalfSize, kFullSize);
610 sk_sp<SkSurface> rightSurf = create_surf(context, kHalfSize, kFullSize);
611
612 sk_sp<SkImage> leftImg = upload(std::move(leftSurf), kLeftColor);
613 dest->getCanvas()->drawImage(std::move(leftImg), 0, 0);
614
615 sk_sp<SkImage> rightImg = upload(std::move(rightSurf), kRightColor);
616 dest->getCanvas()->drawImage(std::move(rightImg), kHalfSize, 0);
617
618 SkBitmap bm;
619 bm.allocPixels(fullII);
620 SkAssertResult(dest->readPixels(bm, 0, 0));
621
622 bool isCorrect = true;
623 for (int y = 0; isCorrect && y < 16; ++y) {
624 const uint32_t* sl = bm.getAddr32(0, y);
625
626 for (int x = 0; x < 16; ++x) {
627 if (kLeftColor != sl[x]) {
628 isCorrect = false;
629 break;
630 }
631 }
632 for (int x = kHalfSize; x < kHalfSize+16; ++x) {
633 if (kRightColor != sl[x]) {
634 isCorrect = false;
635 break;
636 }
637 }
638 }
639
640 REPORTER_ASSERT(reporter, isCorrect);
641}
642
643DEF_TEST(WritePixels_InvalidRowBytes, reporter) {
645 auto surf = SkSurfaces::Raster(dstII);
646 for (int ct = 0; ct < kLastEnum_SkColorType + 1; ++ct) {
647 auto colorType = static_cast<SkColorType>(ct);
648
650 if (bpp <= 1) {
651 continue;
652 }
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());
657 // SkSurface::writePixels doesn't report bool, SkCanvas's does.
659 !surf->getCanvas()->writePixels(srcII, storage.get(), badRowBytes, 0, 0));
660 }
661}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
reporter
@ kBottomLeft_GrSurfaceOrigin
Definition GrTypes.h:149
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
static const int kFullSize
SkColor4f color
SkColorType fColorType
kUnpremul_SkAlphaType
#define check(reporter, ref, unref, make, kill)
SkAlphaType
Definition SkAlphaType.h:26
@ kOpaque_SkAlphaType
pixel is opaque
Definition SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkAssertResult(cond)
Definition SkAssert.h:123
#define SkASSERT(cond)
Definition SkAssert.h:116
unsigned U8CPU
Definition SkCPUTypes.h:18
static SkPMColor SkSwizzle_RGBA_to_PMColor(uint32_t c)
Definition SkColorData.h:83
static SkPMColor SkSwizzle_BGRA_to_PMColor(uint32_t c)
Definition SkColorData.h:91
#define SkGetPackedB32(packed)
Definition SkColorPriv.h:95
#define SkGetPackedR32(packed)
Definition SkColorPriv.h:93
static SkPMColor SkPremultiplyARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
#define SkGetPackedA32(packed)
Definition SkColorPriv.h:92
#define SkGetPackedG32(packed)
Definition SkColorPriv.h:94
static SkPMColor SkPackARGB32NoCheck(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
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
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition SkColorType.h:25
uint32_t SkColor
Definition SkColor.h:37
uint32_t SkPMColor
Definition SkColor.h:205
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)
Definition SkMalloc.h:67
static U8CPU SkMulDiv255Ceiling(U8CPU a, U8CPU b)
Definition SkMathPriv.h:102
static int32_t SkAbs32(int32_t value)
Definition SkSafe32.h:41
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS(name, reporter, graphite_context, ctsEnforcement)
Definition Test.h:377
#define ERRORF(r,...)
Definition Test.h:293
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
Definition Test.h:434
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 const int DEV_H
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 const int DEV_W
static uint32_t premul(uint32_t color)
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition GrCaps.cpp:400
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)
Definition SkBitmap.cpp:258
int width() const
Definition SkBitmap.h:149
size_t rowBytes() const
Definition SkBitmap.h:238
void * getPixels() const
Definition SkBitmap.h:283
const SkImageInfo & info() const
Definition SkBitmap.h:139
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Definition SkBitmap.cpp:114
int height() const
Definition SkBitmap.h:158
uint32_t * getAddr32(int x, int y) const
Definition SkBitmap.h:1260
void setPixelRef(sk_sp< SkPixelRef > pixelRef, int dx, int dy)
Definition SkBitmap.cpp:182
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
virtual SkISize getBaseLayerSize() const
Definition SkCanvas.cpp:373
int width() const
Definition SkSurface.h:178
int height() const
Definition SkSurface.h:184
bool readPixels(const SkPixmap &dst, int srcX, int srcY)
VkSurfaceKHR surface
Definition main.cc:49
static bool b
struct MyStruct a[10]
GAsyncResult * result
uint32_t uint32_t * format
double y
double x
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 >)
SkScalar w
SkScalar h
int32_t height
int32_t width
static bool Intersects(const SkIRect &a, const SkIRect &b)
Definition SkRect.h:535
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition SkRect.h:91
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104
bool contains(int32_t x, int32_t y) const
Definition SkRect.h:463
static SkImageInfo MakeN32Premul(int width, int height)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkAlphaType alphaType() const
SkColorType colorType() const