OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 #include "config.h" |
| 5 |
| 6 #include "web/tests/sim/SimCanvas.h" |
| 7 |
| 8 #include "third_party/skia/include/core/SkPaint.h" |
| 9 #include "third_party/skia/include/core/SkPath.h" |
| 10 #include "third_party/skia/include/core/SkRRect.h" |
| 11 #include "third_party/skia/include/core/SkRect.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 static int s_depth = 0; |
| 16 |
| 17 class DrawScope { |
| 18 public: |
| 19 DrawScope() { ++s_depth; } |
| 20 ~DrawScope() { --s_depth; } |
| 21 }; |
| 22 |
| 23 SimCanvas::SimCanvas(int width, int height) |
| 24 : SkCanvas(width, height) |
| 25 { |
| 26 } |
| 27 |
| 28 void SimCanvas::addCommand(CommandType type, RGBA32 color) |
| 29 { |
| 30 if (s_depth > 1) |
| 31 return; |
| 32 Command command = {type, color}; |
| 33 m_commands.append(command); |
| 34 } |
| 35 |
| 36 void SimCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) |
| 37 { |
| 38 DrawScope scope; |
| 39 addCommand(CommandType::Rect, paint.getColor()); |
| 40 SkCanvas::onDrawRect(rect, paint); |
| 41 } |
| 42 |
| 43 void SimCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) |
| 44 { |
| 45 DrawScope scope; |
| 46 addCommand(CommandType::Shape, paint.getColor()); |
| 47 SkCanvas::onDrawOval(oval, paint); |
| 48 } |
| 49 |
| 50 void SimCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) |
| 51 { |
| 52 DrawScope scope; |
| 53 addCommand(CommandType::Shape, paint.getColor()); |
| 54 SkCanvas::onDrawRRect(rrect, paint); |
| 55 } |
| 56 |
| 57 void SimCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) |
| 58 { |
| 59 DrawScope scope; |
| 60 addCommand(CommandType::Shape, paint.getColor()); |
| 61 SkCanvas::onDrawPath(path, paint); |
| 62 } |
| 63 |
| 64 void SimCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top, c
onst SkPaint* paint) |
| 65 { |
| 66 DrawScope scope; |
| 67 addCommand(CommandType::Image); |
| 68 SkCanvas::onDrawImage(image, left, top, paint); |
| 69 } |
| 70 |
| 71 void SimCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const S
kRect& dst, const SkPaint* paint, SrcRectConstraint constraint) |
| 72 { |
| 73 DrawScope scope; |
| 74 addCommand(CommandType::Image); |
| 75 SkCanvas::onDrawImageRect(image, src, dst, paint, constraint); |
| 76 } |
| 77 |
| 78 void SimCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkSc
alar y, const SkPaint& paint) |
| 79 { |
| 80 DrawScope scope; |
| 81 addCommand(CommandType::Text, paint.getColor()); |
| 82 SkCanvas::onDrawText(text, byteLength, x, y, paint); |
| 83 } |
| 84 |
| 85 void SimCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint
pos[], const SkPaint& paint) |
| 86 { |
| 87 DrawScope scope; |
| 88 addCommand(CommandType::Text, paint.getColor()); |
| 89 SkCanvas::onDrawPosText(text, byteLength, pos, paint); |
| 90 } |
| 91 |
| 92 void SimCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScal
ar xpos[], SkScalar constY, const SkPaint& paint) |
| 93 { |
| 94 DrawScope scope; |
| 95 addCommand(CommandType::Text, paint.getColor()); |
| 96 SkCanvas::onDrawPosTextH(text, byteLength, xpos, constY, paint); |
| 97 } |
| 98 |
| 99 void SimCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPa
th& path, const SkMatrix* matrix, const SkPaint& paint) |
| 100 { |
| 101 DrawScope scope; |
| 102 addCommand(CommandType::Text, paint.getColor()); |
| 103 SkCanvas::onDrawTextOnPath(text, byteLength, path, matrix, paint); |
| 104 } |
| 105 |
| 106 void SimCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, c
onst SkPaint& paint) |
| 107 { |
| 108 DrawScope scope; |
| 109 addCommand(CommandType::Text, paint.getColor()); |
| 110 SkCanvas::onDrawTextBlob(blob, x, y, paint); |
| 111 } |
| 112 |
| 113 } // namespace blink |
OLD | NEW |