OLD | NEW |
(Empty) | |
| 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) { |
| 30 SkCanvas* canvas = SkCanvasStateUtils::CreateFromCanvasState(state); |
| 31 if (!canvas) { |
| 32 return false; |
| 33 } |
| 34 complex_layers_draw(canvas, left, top, right, bottom, spacer); |
| 35 canvas->unref(); |
| 36 return true; |
| 37 } |
| 38 |
| 39 void complex_clips_draw(SkCanvas* canvas, int32_t left, int32_t top, |
| 40 int32_t right, int32_t bottom, int32_t clipOp, const SkRegion& localRegi
on) { |
| 41 canvas->save(); |
| 42 SkRect clipRect = SkRect::MakeLTRB(SkIntToScalar(left), SkIntToScalar(top), |
| 43 SkIntToScalar(right), SkIntToScalar(botto
m)); |
| 44 canvas->clipRect(clipRect, (SkRegion::Op) clipOp); |
| 45 canvas->drawColor(SK_ColorBLUE); |
| 46 canvas->restore(); |
| 47 |
| 48 canvas->clipRegion(localRegion, (SkRegion::Op) clipOp); |
| 49 canvas->drawColor(SK_ColorBLUE); |
| 50 } |
| 51 |
| 52 extern "C" bool complex_clips_draw_from_canvas_state(SkCanvasState* state, |
| 53 int32_t left, int32_t top, int32_t right, int32_t bottom, int32_t clipOp
, |
| 54 int32_t regionRects, int32_t* rectCoords) { |
| 55 SkCanvas* canvas = SkCanvasStateUtils::CreateFromCanvasState(state); |
| 56 if (!canvas) { |
| 57 return false; |
| 58 } |
| 59 |
| 60 SkRegion localRegion; |
| 61 for (int32_t i = 0; i < regionRects; ++i) { |
| 62 localRegion.op(rectCoords[0], rectCoords[1], rectCoords[2], rectCoords[3
], |
| 63 SkRegion::kUnion_Op); |
| 64 rectCoords += 4; |
| 65 } |
| 66 |
| 67 complex_clips_draw(canvas, left, top, right, bottom, clipOp, localRegion); |
| 68 canvas->unref(); |
| 69 return true; |
| 70 } |
| 71 #endif // SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
OLD | NEW |