blob: e84615d73f5bcf032c77b7863e670abac6bdffa2 [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
Ben Wagnerb607a8f2018-03-12 13:46:21 -04008#include "SkTypes.h"
Ben Wagner501c17c2018-03-12 20:04:31 +00009#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
Ben Wagnerb607a8f2018-03-12 13:46:21 -040010#include "CanvasStateHelpers.h"
scroggo24519372014-07-22 12:38:55 -070011#include "SkCanvas.h"
12#include "SkCanvasStateUtils.h"
Ben Wagnerb607a8f2018-03-12 13:46:21 -040013#include "SkClipOp.h"
14#include "SkColor.h"
scroggo24519372014-07-22 12:38:55 -070015#include "SkPaint.h"
16#include "SkRect.h"
17#include "SkRegion.h"
Ben Wagnerb607a8f2018-03-12 13:46:21 -040018#include "SkScalar.h"
19
20#include <memory>
scroggo24519372014-07-22 12:38:55 -070021
22void complex_layers_draw(SkCanvas* canvas, float left, float top,
23 float right, float bottom, int32_t spacer) {
24 SkPaint bluePaint;
25 bluePaint.setColor(SK_ColorBLUE);
26 bluePaint.setStyle(SkPaint::kFill_Style);
27
28 SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
29 canvas->drawRect(rect, bluePaint);
30 canvas->translate(0, rect.height() + spacer);
31 canvas->drawRect(rect, bluePaint);
32}
33
34extern "C" bool complex_layers_draw_from_canvas_state(SkCanvasState* state,
35 float left, float top, float right, float bottom, int32_t spacer) {
Mike Reed5df49342016-11-12 08:06:55 -060036 std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state);
scroggo24519372014-07-22 12:38:55 -070037 if (!canvas) {
38 return false;
39 }
Mike Reed5df49342016-11-12 08:06:55 -060040 complex_layers_draw(canvas.get(), left, top, right, bottom, spacer);
scroggo24519372014-07-22 12:38:55 -070041 return true;
42}
43
44void complex_clips_draw(SkCanvas* canvas, int32_t left, int32_t top,
45 int32_t right, int32_t bottom, int32_t clipOp, const SkRegion& localRegion) {
46 canvas->save();
47 SkRect clipRect = SkRect::MakeLTRB(SkIntToScalar(left), SkIntToScalar(top),
48 SkIntToScalar(right), SkIntToScalar(bottom));
49 canvas->clipRect(clipRect, (SkRegion::Op) clipOp);
50 canvas->drawColor(SK_ColorBLUE);
51 canvas->restore();
52
Mike Reedc1f77742016-12-09 09:00:50 -050053 canvas->clipRegion(localRegion, (SkClipOp) clipOp);
scroggo24519372014-07-22 12:38:55 -070054 canvas->drawColor(SK_ColorBLUE);
55}
56
57extern "C" bool complex_clips_draw_from_canvas_state(SkCanvasState* state,
58 int32_t left, int32_t top, int32_t right, int32_t bottom, int32_t clipOp,
59 int32_t regionRects, int32_t* rectCoords) {
Mike Reed5df49342016-11-12 08:06:55 -060060 std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state);
scroggo24519372014-07-22 12:38:55 -070061 if (!canvas) {
62 return false;
63 }
64
65 SkRegion localRegion;
66 for (int32_t i = 0; i < regionRects; ++i) {
67 localRegion.op(rectCoords[0], rectCoords[1], rectCoords[2], rectCoords[3],
68 SkRegion::kUnion_Op);
69 rectCoords += 4;
70 }
71
Mike Reed5df49342016-11-12 08:06:55 -060072 complex_clips_draw(canvas.get(), left, top, right, bottom, clipOp, localRegion);
scroggo24519372014-07-22 12:38:55 -070073 return true;
74}
75#endif // SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG