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 | |
| 8 | #include "CanvasStateHelpers.h" |
| 9 | #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkCanvasStateUtils.h" |
| 12 | #include "SkPaint.h" |
| 13 | #include "SkRect.h" |
| 14 | #include "SkRegion.h" |
| 15 | |
| 16 | void complex_layers_draw(SkCanvas* canvas, float left, float top, |
| 17 | float right, float bottom, int32_t spacer) { |
| 18 | SkPaint bluePaint; |
| 19 | bluePaint.setColor(SK_ColorBLUE); |
| 20 | bluePaint.setStyle(SkPaint::kFill_Style); |
| 21 | |
| 22 | SkRect rect = SkRect::MakeLTRB(left, top, right, bottom); |
| 23 | canvas->drawRect(rect, bluePaint); |
| 24 | canvas->translate(0, rect.height() + spacer); |
| 25 | canvas->drawRect(rect, bluePaint); |
| 26 | } |
| 27 | |
| 28 | extern "C" bool complex_layers_draw_from_canvas_state(SkCanvasState* state, |
| 29 | float left, float top, float right, float bottom, int32_t spacer) { |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame^] | 30 | std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 31 | if (!canvas) { |
| 32 | return false; |
| 33 | } |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame^] | 34 | complex_layers_draw(canvas.get(), left, top, right, bottom, spacer); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 35 | return true; |
| 36 | } |
| 37 | |
| 38 | void complex_clips_draw(SkCanvas* canvas, int32_t left, int32_t top, |
| 39 | int32_t right, int32_t bottom, int32_t clipOp, const SkRegion& localRegion) { |
| 40 | canvas->save(); |
| 41 | SkRect clipRect = SkRect::MakeLTRB(SkIntToScalar(left), SkIntToScalar(top), |
| 42 | SkIntToScalar(right), SkIntToScalar(bottom)); |
| 43 | canvas->clipRect(clipRect, (SkRegion::Op) clipOp); |
| 44 | canvas->drawColor(SK_ColorBLUE); |
| 45 | canvas->restore(); |
| 46 | |
Mike Reed | 1cd88c4 | 2016-09-23 10:05:05 -0400 | [diff] [blame] | 47 | canvas->clipRegion(localRegion, (SkCanvas::ClipOp) clipOp); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 48 | canvas->drawColor(SK_ColorBLUE); |
| 49 | } |
| 50 | |
| 51 | extern "C" bool complex_clips_draw_from_canvas_state(SkCanvasState* state, |
| 52 | int32_t left, int32_t top, int32_t right, int32_t bottom, int32_t clipOp, |
| 53 | int32_t regionRects, int32_t* rectCoords) { |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame^] | 54 | std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 55 | if (!canvas) { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | SkRegion localRegion; |
| 60 | for (int32_t i = 0; i < regionRects; ++i) { |
| 61 | localRegion.op(rectCoords[0], rectCoords[1], rectCoords[2], rectCoords[3], |
| 62 | SkRegion::kUnion_Op); |
| 63 | rectCoords += 4; |
| 64 | } |
| 65 | |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame^] | 66 | complex_clips_draw(canvas.get(), left, top, right, bottom, clipOp, localRegion); |
scroggo | 2451937 | 2014-07-22 12:38:55 -0700 | [diff] [blame] | 67 | return true; |
| 68 | } |
| 69 | #endif // SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |