Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / tests / sim / SimCanvas.cpp
blob40ca1f80716ac6c46b70f142d612ed6c7b485e26
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"
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"
13 namespace blink {
15 static int s_depth = 0;
17 class DrawScope {
18 public:
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)
30 if (s_depth > 1)
31 return;
32 Command command = {type, color};
33 m_commands.append(command);
36 void SimCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint)
38 DrawScope scope;
39 addCommand(CommandType::Rect, paint.getColor());
40 SkCanvas::onDrawRect(rect, paint);
43 void SimCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint)
45 DrawScope scope;
46 addCommand(CommandType::Shape, paint.getColor());
47 SkCanvas::onDrawOval(oval, paint);
50 void SimCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint)
52 DrawScope scope;
53 addCommand(CommandType::Shape, paint.getColor());
54 SkCanvas::onDrawRRect(rrect, paint);
57 void SimCanvas::onDrawPath(const SkPath& path, const SkPaint& paint)
59 DrawScope scope;
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)
66 DrawScope scope;
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)
73 DrawScope scope;
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)
80 DrawScope scope;
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)
87 DrawScope scope;
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)
94 DrawScope scope;
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)
101 DrawScope scope;
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)
108 DrawScope scope;
109 addCommand(CommandType::Text, paint.getColor());
110 SkCanvas::onDrawTextBlob(blob, x, y, paint);
113 } // namespace blink