Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
CanvasStateHelpers.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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
9
10#if !defined(SK_TEST_CANVAS_STATE_CROSS_LIBRARY)
11
13
17#include "include/core/SkRect.h"
21
22#include <memory>
23
24enum class SkClipOp;
25
26void complex_layers_draw(SkCanvas* canvas, float left, float top,
27 float right, float bottom, int32_t spacer) {
28 SkPaint bluePaint;
29 bluePaint.setColor(SK_ColorBLUE);
31
32 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
33 canvas->drawRect(rect, bluePaint);
34 canvas->translate(0, rect.height() + spacer);
35 canvas->drawRect(rect, bluePaint);
36}
37
39 float left, float top, float right, float bottom, int32_t spacer) {
40 std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state);
41 if (!canvas) {
42 return false;
43 }
44 complex_layers_draw(canvas.get(), left, top, right, bottom, spacer);
45 return true;
46}
47
48void complex_clips_draw(SkCanvas* canvas, int32_t left, int32_t top,
49 int32_t right, int32_t bottom, int32_t clipOp, const SkRegion& localRegion) {
50 canvas->save();
53 canvas->clipRect(clipRect, (SkRegion::Op) clipOp);
54 canvas->drawColor(SK_ColorBLUE);
55 canvas->restore();
56
57 canvas->clipRegion(localRegion, (SkClipOp) clipOp);
58 canvas->drawColor(SK_ColorBLUE);
59}
60
62 int32_t left, int32_t top, int32_t right, int32_t bottom, int32_t clipOp,
63 int32_t regionRects, int32_t* rectCoords) {
64 std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state);
65 if (!canvas) {
66 return false;
67 }
68
69 SkRegion localRegion;
70 for (int32_t i = 0; i < regionRects; ++i) {
71 localRegion.op({rectCoords[0], rectCoords[1], rectCoords[2], rectCoords[3]},
73 rectCoords += 4;
74 }
75
76 complex_clips_draw(canvas.get(), left, top, right, bottom, clipOp, localRegion);
77 return true;
78}
79
80#endif // SK_TEST_CANVAS_STATE_CROSS_LIBRARY
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)
SkClipOp
Definition SkClipOp.h:13
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
#define SkIntToScalar(x)
Definition SkScalar.h:57
static std::unique_ptr< SkCanvas > MakeFromCanvasState(const SkCanvasState *state)
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition SkCanvas.h:1182
void clipRegion(const SkRegion &deviceRgn, SkClipOp op=SkClipOp::kIntersect)
int save()
Definition SkCanvas.cpp:451
void setStyle(Style style)
Definition SkPaint.cpp:105
void setColor(SkColor color)
Definition SkPaint.cpp:119
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
@ kUnion_Op
target unioned with operand
Definition SkRegion.h:369
bool op(const SkIRect &rect, Op op)
Definition SkRegion.h:384
AtkStateType state
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646