Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Unified Diff: sky/engine/core/painting/Canvas.cpp

Issue 1144483002: Flesh out the Painting API a bit. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: constify Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/engine/core/painting/Canvas.cpp
diff --git a/sky/engine/core/painting/Canvas.cpp b/sky/engine/core/painting/Canvas.cpp
index 5e25baf4893daf35302066caabb6bb74ca24b369..c3bde989568332920e278f6431bb33fcd1dfab88 100644
--- a/sky/engine/core/painting/Canvas.cpp
+++ b/sky/engine/core/painting/Canvas.cpp
@@ -13,6 +13,14 @@
namespace blink {
+SkRect toSkRect(const Vector<float>& rect)
+{
+ ASSERT(rect.size() == 4);
+ SkRect sk_rect;
+ sk_rect.set(rect[0], rect[1], rect[2], rect[3]);
+ return sk_rect;
+}
+
Canvas::Canvas(const FloatSize& size)
: m_size(size)
{
@@ -24,7 +32,113 @@ Canvas::~Canvas()
{
}
-void Canvas::drawCircle(double x, double y, double radius, Paint* paint)
+void Canvas::save()
+{
+ if (!m_canvas)
+ return;
+ ASSERT(m_displayList->isRecording());
+ m_canvas->save();
+}
+
+void Canvas::saveLayer(const Vector<float>& bounds, const Paint* paint)
+{
+ if (!m_canvas)
+ return;
+ ASSERT(m_displayList->isRecording());
+ SkRect sk_bounds;
+ if (!bounds.isEmpty())
+ sk_bounds = toSkRect(bounds);
+ m_canvas->saveLayer(!bounds.isEmpty() ? &sk_bounds : nullptr,
+ paint ? &paint->paint() : nullptr);
+}
+
+void Canvas::restore()
+{
+ if (!m_canvas)
+ return;
+ ASSERT(m_displayList->isRecording());
+ m_canvas->restore();
+}
+
+void Canvas::translate(float dx, float dy)
+{
+ if (!m_canvas)
+ return;
+ ASSERT(m_displayList->isRecording());
+ m_canvas->translate(dx, dy);
+}
+
+void Canvas::scale(float sx, float sy)
+{
+ if (!m_canvas)
+ return;
+ ASSERT(m_displayList->isRecording());
+ m_canvas->scale(sx, sy);
+}
+
+void Canvas::rotateDegrees(float degrees)
+{
+ if (!m_canvas)
+ return;
+ ASSERT(m_displayList->isRecording());
+ m_canvas->rotate(degrees);
+}
+
+void Canvas::skew(float sx, float sy)
+{
+ if (!m_canvas)
+ return;
+ ASSERT(m_displayList->isRecording());
+ m_canvas->skew(sx, sy);
+}
+
+void Canvas::concat(const Vector<float>& matrix)
+{
+ if (!m_canvas)
+ return;
+ ASSERT(m_displayList->isRecording());
+ ASSERT(matrix.size() == 9);
+ SkMatrix sk_matrix;
+ sk_matrix.set9(matrix.data());
+ m_canvas->concat(sk_matrix);
+}
+
+void Canvas::clipRect(const Vector<float>& rect)
+{
+ if (!m_canvas)
+ return;
+ ASSERT(m_displayList->isRecording());
+ m_canvas->clipRect(toSkRect(rect));
+}
+
+void Canvas::drawPaint(Paint* paint)
+{
+ if (!m_canvas)
+ return;
+ ASSERT(paint);
+ ASSERT(m_displayList->isRecording());
+ m_canvas->drawPaint(paint->paint());
+}
+
+void Canvas::drawRect(const Vector<float>& rect, const Paint* paint)
+{
+ if (!m_canvas)
+ return;
+ ASSERT(paint);
+ ASSERT(m_displayList->isRecording());
+ m_canvas->drawRect(toSkRect(rect), paint->paint());
+}
+
+void Canvas::drawOval(const Vector<float>& rect, const Paint* paint)
+{
+ if (!m_canvas)
+ return;
+ ASSERT(paint);
+ ASSERT(m_displayList->isRecording());
+ m_canvas->drawOval(toSkRect(rect), paint->paint());
+}
+
+void Canvas::drawCircle(float x, float y, float radius, Paint* paint)
{
if (!m_canvas)
return;

Powered by Google App Engine
This is Rietveld 408576698