2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "include/core/SkTypes.h"
10 #if !defined(SK_TEST_CANVAS_STATE_CROSS_LIBRARY)
12 #include "tests/CanvasStateHelpers.h"
14 #include "include/core/SkCanvas.h"
15 #include "include/core/SkClipOp.h"
16 #include "include/core/SkColor.h"
17 #include "include/core/SkPaint.h"
18 #include "include/core/SkRect.h"
19 #include "include/core/SkRegion.h"
20 #include "include/core/SkScalar.h"
21 #include "include/utils/SkCanvasStateUtils.h"
25 void complex_layers_draw(SkCanvas* canvas, float left, float top,
26 float right, float bottom, int32_t spacer) {
28 bluePaint.setColor(SK_ColorBLUE);
29 bluePaint.setStyle(SkPaint::kFill_Style);
31 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
32 canvas->drawRect(rect, bluePaint);
33 canvas->translate(0, rect.height() + spacer);
34 canvas->drawRect(rect, bluePaint);
37 extern "C" bool complex_layers_draw_from_canvas_state(SkCanvasState* state,
38 float left, float top, float right, float bottom, int32_t spacer) {
39 std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state);
43 complex_layers_draw(canvas.get(), left, top, right, bottom, spacer);
47 void complex_clips_draw(SkCanvas* canvas, int32_t left, int32_t top,
48 int32_t right, int32_t bottom, int32_t clipOp, const SkRegion& localRegion) {
50 SkRect clipRect = SkRect::MakeLTRB(SkIntToScalar(left), SkIntToScalar(top),
51 SkIntToScalar(right), SkIntToScalar(bottom));
52 canvas->clipRect(clipRect, (SkRegion::Op) clipOp);
53 canvas->drawColor(SK_ColorBLUE);
56 canvas->clipRegion(localRegion, (SkClipOp) clipOp);
57 canvas->drawColor(SK_ColorBLUE);
60 extern "C" bool complex_clips_draw_from_canvas_state(SkCanvasState* state,
61 int32_t left, int32_t top, int32_t right, int32_t bottom, int32_t clipOp,
62 int32_t regionRects, int32_t* rectCoords) {
63 std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state);
69 for (int32_t i = 0; i < regionRects; ++i) {
70 localRegion.op({rectCoords[0], rectCoords[1], rectCoords[2], rectCoords[3]},
75 complex_clips_draw(canvas.get(), left, top, right, bottom, clipOp, localRegion);
79 #endif // SK_TEST_CANVAS_STATE_CROSS_LIBRARY