52#if defined(SK_TEST_CANVAS_STATE_CROSS_LIBRARY)
55 "Support library to use for CanvasState test. Must be provided when"
56 " SK_TEST_CANVAS_STATE_CROSS_LIBRARY to specify the dynamically loaded library"
57 " that receives the captured canvas state. Functions from the library will be"
58 " called to test SkCanvasState. The library is built from the canvas_state_lib"
67 if (FLAGS_library.count() == 1) {
82 void* procAddress(
const char* funcName) {
104 SkDebugf(
"---- counter %d\n", counter);
108 name.printf(
"capture_%d.png", counter);
120 if (memcmp(pm[0].addr(0, 0), pm[1].addr(0, 0), pm[0].computeByteSize()) != 0) {
126 const int WIDTH = 400;
128 const int SPACER = 10;
138 const int layerAlpha[] = { 255, 255, 0 };
141 float r,
float b, int32_t
s);
143#if defined(SK_TEST_CANVAS_STATE_CROSS_LIBRARY)
144 OpenLibResult openLibResult(
reporter);
145 *(
void**) (&drawFn) = openLibResult.procAddress(
"complex_layers_draw_from_canvas_state");
155 for (
size_t i = 0; i < std::size(colorTypes); ++i) {
157 for (
int j = 0; j < 2; ++j) {
160 SkCanvas* canvas = surf->getCanvas();
164 for (
size_t k = 0; k < std::size(layerAlpha); ++k) {
166 if (layerAlpha[k] != 0xFF) {
167 paint.init()->setAlpha(layerAlpha[k]);
180 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, SPACER);
188 rect.fRight, rect.fBottom, SPACER);
194 canvas->
translate(0, 2*(rect.height() + SPACER));
196 images[j] = surf->makeImageSnapshot();
206 const int WIDTH = 400;
208 const int SPACER = 10;
211 layerRect.
inset(2*SPACER, 2*SPACER);
214 clipRect.fRight = clipRect.fLeft + (clipRect.width() / 2) - (2*SPACER);
215 clipRect.outset(SPACER, SPACER);
217 SkIRect regionBounds = clipRect;
218 regionBounds.
offset(clipRect.width() + (2*SPACER), 0);
220 SkIRect regionInterior = regionBounds;
221 regionInterior.
inset(SPACER*3, SPACER*3);
224 clipRegion.
setRect(regionBounds);
234 int32_t r, int32_t
b, int32_t clipOp,
235 int32_t regionRects, int32_t* rectCoords);
237#if defined(SK_TEST_CANVAS_STATE_CROSS_LIBRARY)
238 OpenLibResult openLibResult(
reporter);
239 *(
void**) (&drawFn) = openLibResult.procAddress(
"complex_clips_draw_from_canvas_state");
250 for (
int i = 0; i < 2; ++i) {
252 SkCanvas* canvas = surf->getCanvas();
260 for (
size_t j = 0; j < std::size(clipOps); ++j) {
272 *rectCoords.
append() = rect.fLeft;
273 *rectCoords.
append() = rect.fTop;
274 *rectCoords.
append() = rect.fRight;
275 *rectCoords.
append() = rect.fBottom;
277 bool success = drawFn(
state, clipRect.fLeft, clipRect.fTop,
278 clipRect.fRight, clipRect.fBottom, clipOps[j],
279 rectCoords.
size() / 4, rectCoords.
begin());
285 clipRect.fRight, clipRect.fBottom, clipOps[j],
295 images[i] = surf->makeImageSnapshot();
305 bitmap.allocN32Pixels(10, 10);
318 const int WIDTH = 100;
320 const int LAYER_WIDTH = 50;
321 const int LAYER_HEIGHT = 50;
bool complex_layers_draw_from_canvas_state(SkCanvasState *state, float left, float top, float right, float bottom, int32_t spacer)
void complex_layers_draw(SkCanvas *canvas, float left, float top, float right, float bottom, int32_t spacer)
bool complex_clips_draw_from_canvas_state(SkCanvasState *state, int32_t left, int32_t top, int32_t right, int32_t bottom, int32_t clipOp, int32_t regionRects, int32_t *rectCoords)
void complex_clips_draw(SkCanvas *canvas, int32_t left, int32_t top, int32_t right, int32_t bottom, int32_t clipOp, const SkRegion &localRegion)
static void write_image(const SkImage *img, const char path[])
static void compare(skiatest::Reporter *reporter, SkImage *img0, SkImage *img1)
#define DEFINE_string(name, defaultValue, helpString)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
constexpr SkColor SK_ColorRED
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
void * SkGetProcedureAddress(void *library, const char *functionName)
void * SkLoadDynamicLibrary(const char *libraryName)
bool SkFreeDynamicLibrary(void *library)
#define DEF_TEST(name, reporter)
#define REPORTER_ASSERT(r, cond,...)
static SkCanvasState * CaptureCanvasState(SkCanvas *canvas)
static void ReleaseCanvasState(SkCanvasState *state)
int saveLayer(const SkRect *bounds, const SkPaint *paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void translate(SkScalar dx, SkScalar dy)
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
virtual bool isClipRect() const
SkIRect getDeviceClipBounds() const
void clipRRect(const SkRRect &rrect, SkClipOp op, bool doAntiAlias)
bool write(const void *buffer, size_t size) override
bool peekPixels(SkPixmap *pixmap) const
void setOval(const SkRect &oval)
const SkIRect & rect() const
void translate(int dx, int dy)
@ kIntersect_Op
target intersected with operand
@ kDifference_Op
target minus operand
bool op(const SkIRect &rect, Op op)
bool setRect(const SkIRect &rect)
void printf(const char format[],...) SK_PRINTF_LIKE(2
std::array< MockImage, 3 > images
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
void inset(int32_t dx, int32_t dy)
constexpr int32_t height() const
constexpr int32_t width() const
void offset(int32_t dx, int32_t dy)
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
static SkImageInfo MakeN32Premul(int width, int height)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static SkRect Make(const SkISize &size)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
static constexpr SkRect MakeWH(float w, float h)