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.
6 #include "web/tests/sim/SimCanvas.h"
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"
15 static int s_depth
= 0;
19 DrawScope() { ++s_depth
; }
20 ~DrawScope() { --s_depth
; }
23 SimCanvas::SimCanvas(int width
, int height
)
24 : SkCanvas(width
, height
)
28 void SimCanvas::addCommand(CommandType type
, RGBA32 color
)
32 Command command
= {type
, color
};
33 m_commands
.append(command
);
36 void SimCanvas::onDrawRect(const SkRect
& rect
, const SkPaint
& paint
)
39 addCommand(CommandType::Rect
, paint
.getColor());
40 SkCanvas::onDrawRect(rect
, paint
);
43 void SimCanvas::onDrawOval(const SkRect
& oval
, const SkPaint
& paint
)
46 addCommand(CommandType::Shape
, paint
.getColor());
47 SkCanvas::onDrawOval(oval
, paint
);
50 void SimCanvas::onDrawRRect(const SkRRect
& rrect
, const SkPaint
& paint
)
53 addCommand(CommandType::Shape
, paint
.getColor());
54 SkCanvas::onDrawRRect(rrect
, paint
);
57 void SimCanvas::onDrawPath(const SkPath
& path
, const SkPaint
& paint
)
60 addCommand(CommandType::Shape
, paint
.getColor());
61 SkCanvas::onDrawPath(path
, paint
);
64 void SimCanvas::onDrawImage(const SkImage
* image
, SkScalar left
, SkScalar top
, const SkPaint
* paint
)
67 addCommand(CommandType::Image
);
68 SkCanvas::onDrawImage(image
, left
, top
, paint
);
71 void SimCanvas::onDrawImageRect(const SkImage
* image
, const SkRect
* src
, const SkRect
& dst
, const SkPaint
* paint
, SrcRectConstraint constraint
)
74 addCommand(CommandType::Image
);
75 SkCanvas::onDrawImageRect(image
, src
, dst
, paint
, constraint
);
78 void SimCanvas::onDrawText(const void* text
, size_t byteLength
, SkScalar x
, SkScalar y
, const SkPaint
& paint
)
81 addCommand(CommandType::Text
, paint
.getColor());
82 SkCanvas::onDrawText(text
, byteLength
, x
, y
, paint
);
85 void SimCanvas::onDrawPosText(const void* text
, size_t byteLength
, const SkPoint pos
[], const SkPaint
& paint
)
88 addCommand(CommandType::Text
, paint
.getColor());
89 SkCanvas::onDrawPosText(text
, byteLength
, pos
, paint
);
92 void SimCanvas::onDrawPosTextH(const void* text
, size_t byteLength
, const SkScalar xpos
[], SkScalar constY
, const SkPaint
& paint
)
95 addCommand(CommandType::Text
, paint
.getColor());
96 SkCanvas::onDrawPosTextH(text
, byteLength
, xpos
, constY
, paint
);
99 void SimCanvas::onDrawTextOnPath(const void* text
, size_t byteLength
, const SkPath
& path
, const SkMatrix
* matrix
, const SkPaint
& paint
)
102 addCommand(CommandType::Text
, paint
.getColor());
103 SkCanvas::onDrawTextOnPath(text
, byteLength
, path
, matrix
, paint
);
106 void SimCanvas::onDrawTextBlob(const SkTextBlob
* blob
, SkScalar x
, SkScalar y
, const SkPaint
& paint
)
109 addCommand(CommandType::Text
, paint
.getColor());
110 SkCanvas::onDrawTextBlob(blob
, x
, y
, paint
);