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 | |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 8 | #include "SkTypes.h" |
Ben Wagner | 501c17c | 2018-03-12 20:04:31 +0000 | [diff] [blame] | 9 | #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 10 | #include "CanvasStateHelpers.h" |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 11 | #include "SkCanvas.h" |
| 12 | #include "SkCanvasStateUtils.h" |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 13 | #include "SkClipOp.h" |
| 14 | #include "SkColor.h" |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 15 | #include "SkPaint.h" |
| 16 | #include "SkRect.h" |
| 17 | #include "SkRegion.h" |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 18 | #include "SkScalar.h" |
| 19 | |
| 20 | #include <memory> |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 21 | |
| 22 | void 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 | |
| 34 | extern "C" bool complex_layers_draw_from_canvas_state(SkCanvasState* state, |
| 35 | float left, float top, float right, float bottom, int32_t spacer) { |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 36 | std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 37 | if (!canvas) { |
| 38 | return false; |
| 39 | } |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 40 | complex_layers_draw(canvas.get(), left, top, right, bottom, spacer); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 41 | return true; |
| 42 | } |
| 43 | |
| 44 | void 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 Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 53 | canvas->clipRegion(localRegion, (SkClipOp) clipOp); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 54 | canvas->drawColor(SK_ColorBLUE); |
| 55 | } |
| 56 | |
| 57 | extern "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 Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 60 | std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 61 | 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 Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 72 | complex_clips_draw(canvas.get(), left, top, right, bottom, clipOp, localRegion); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 73 | return true; |
| 74 | } |
| 75 | #endif // SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |