blob: bfafc6ef2a94d2800beb453f3f29fb4dffe95fd2 [file] [log] [blame]
scroggo24519372014-07-22 12:38:55 -07001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkTypes.h"
Michael Ludwig30217952020-12-04 12:58:35 -05009
10#if !defined(SK_TEST_CANVAS_STATE_CROSS_LIBRARY)
11
12#include "tests/CanvasStateHelpers.h"
13
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#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"
Ben Wagnerb607a8f2018-03-12 13:46:21 -040022
23#include <memory>
scroggo24519372014-07-22 12:38:55 -070024
25void complex_layers_draw(SkCanvas* canvas, float left, float top,
26 float right, float bottom, int32_t spacer) {
27 SkPaint bluePaint;
28 bluePaint.setColor(SK_ColorBLUE);
29 bluePaint.setStyle(SkPaint::kFill_Style);
30
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);
35}
36
37extern "C" bool complex_layers_draw_from_canvas_state(SkCanvasState* state,
38 float left, float top, float right, float bottom, int32_t spacer) {
Mike Reed5df49342016-11-12 08:06:55 -060039 std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state);
scroggo24519372014-07-22 12:38:55 -070040 if (!canvas) {
41 return false;
42 }
Mike Reed5df49342016-11-12 08:06:55 -060043 complex_layers_draw(canvas.get(), left, top, right, bottom, spacer);
scroggo24519372014-07-22 12:38:55 -070044 return true;
45}
46
47void complex_clips_draw(SkCanvas* canvas, int32_t left, int32_t top,
48 int32_t right, int32_t bottom, int32_t clipOp, const SkRegion& localRegion) {
49 canvas->save();
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);
54 canvas->restore();
55
Mike Reedc1f77742016-12-09 09:00:50 -050056 canvas->clipRegion(localRegion, (SkClipOp) clipOp);
scroggo24519372014-07-22 12:38:55 -070057 canvas->drawColor(SK_ColorBLUE);
58}
59
60extern "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) {
Mike Reed5df49342016-11-12 08:06:55 -060063 std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state);
scroggo24519372014-07-22 12:38:55 -070064 if (!canvas) {
65 return false;
66 }
67
68 SkRegion localRegion;
69 for (int32_t i = 0; i < regionRects; ++i) {
Ravi Mistry6d508182019-08-30 09:17:46 -040070 localRegion.op({rectCoords[0], rectCoords[1], rectCoords[2], rectCoords[3]},
scroggo24519372014-07-22 12:38:55 -070071 SkRegion::kUnion_Op);
72 rectCoords += 4;
73 }
74
Mike Reed5df49342016-11-12 08:06:55 -060075 complex_clips_draw(canvas.get(), left, top, right, bottom, clipOp, localRegion);
scroggo24519372014-07-22 12:38:55 -070076 return true;
77}
Michael Ludwig30217952020-12-04 12:58:35 -050078
79#endif // SK_TEST_CANVAS_STATE_CROSS_LIBRARY