scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkTypes.h" |
Michael Ludwig | 3021795 | 2020-12-04 12:58:35 -0500 | [diff] [blame] | 9 | |
| 10 | #if !defined(SK_TEST_CANVAS_STATE_CROSS_LIBRARY) |
| 11 | |
| 12 | #include "tests/CanvasStateHelpers.h" |
| 13 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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" |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 22 | |
| 23 | #include <memory> |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 24 | |
| 25 | void 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 | |
| 37 | extern "C" bool complex_layers_draw_from_canvas_state(SkCanvasState* state, |
| 38 | float left, float top, float right, float bottom, int32_t spacer) { |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 39 | std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 40 | if (!canvas) { |
| 41 | return false; |
| 42 | } |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 43 | complex_layers_draw(canvas.get(), left, top, right, bottom, spacer); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 44 | return true; |
| 45 | } |
| 46 | |
| 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) { |
| 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 Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 56 | canvas->clipRegion(localRegion, (SkClipOp) clipOp); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 57 | canvas->drawColor(SK_ColorBLUE); |
| 58 | } |
| 59 | |
| 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) { |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 63 | std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 64 | if (!canvas) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | SkRegion localRegion; |
| 69 | for (int32_t i = 0; i < regionRects; ++i) { |
Ravi Mistry | 6d50818 | 2019-08-30 09:17:46 -0400 | [diff] [blame] | 70 | localRegion.op({rectCoords[0], rectCoords[1], rectCoords[2], rectCoords[3]}, |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 71 | SkRegion::kUnion_Op); |
| 72 | rectCoords += 4; |
| 73 | } |
| 74 | |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 75 | complex_clips_draw(canvas.get(), left, top, right, bottom, clipOp, localRegion); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 76 | return true; |
| 77 | } |
Michael Ludwig | 3021795 | 2020-12-04 12:58:35 -0500 | [diff] [blame] | 78 | |
| 79 | #endif // SK_TEST_CANVAS_STATE_CROSS_LIBRARY |