aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2014-08-26 07:56:44 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-26 07:56:44 -0700
commitb7425173f96e93b090787e2386ba5f022b6c2869 (patch)
treeb73511cfeb4373c7a46a2507ada4274ca4b099e8 /src/utils
parent3d2e50d1aa56d7f65a4c52fa03af4413fa4c616a (diff)
SkTextBlob plumbing
Add SkTextBlob serialization + drawTextBlob() overrides. R=mtklein@google.com, reed@google.com, robertphillips@google.com BUG=269080 Author: fmalita@chromium.org Review URL: https://codereview.chromium.org/499413002
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/SkDeferredCanvas.cpp7
-rw-r--r--src/utils/SkDumpCanvas.cpp9
-rw-r--r--src/utils/SkLua.cpp7
-rw-r--r--src/utils/SkLuaCanvas.cpp9
-rw-r--r--src/utils/SkNWayCanvas.cpp8
-rw-r--r--src/utils/SkProxyCanvas.cpp5
-rw-r--r--src/utils/debugger/SkDebugCanvas.cpp5
-rw-r--r--src/utils/debugger/SkDebugCanvas.h2
-rw-r--r--src/utils/debugger/SkDrawCommand.cpp22
-rw-r--r--src/utils/debugger/SkDrawCommand.h15
10 files changed, 89 insertions, 0 deletions
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index de3958adbc..cb69b4e282 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -901,6 +901,13 @@ void SkDeferredCanvas::onDrawTextOnPath(const void* text, size_t byteLength, con
this->recordedDrawCommand();
}
+void SkDeferredCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
+ const SkPaint& paint) {
+ AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
+ this->drawingCanvas()->drawTextBlob(blob, x, y, paint);
+ this->recordedDrawCommand();
+}
+
void SkDeferredCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
const SkPaint* paint) {
this->drawingCanvas()->drawPicture(picture, matrix, paint);
diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp
index 661f0d8860..5e3d1535d9 100644
--- a/src/utils/SkDumpCanvas.cpp
+++ b/src/utils/SkDumpCanvas.cpp
@@ -14,6 +14,7 @@
#include "SkPixelRef.h"
#include "SkRRect.h"
#include "SkString.h"
+#include "SkTextBlob.h"
#include <stdarg.h>
#include <stdio.h>
@@ -423,6 +424,14 @@ void SkDumpCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const S
str.c_str(), byteLength);
}
+void SkDumpCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
+ const SkPaint& paint) {
+ SkString str;
+ toString(blob->bounds(), &str);
+ this->dump(kDrawText_Verb, &paint, "drawTextBlob(%p) [%s]", blob, str.c_str());
+ // FIXME: dump the actual blob content?
+}
+
void SkDumpCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
const SkPaint* paint) {
this->dump(kDrawPicture_Verb, NULL, "drawPicture(%p) %d:%d", picture,
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 9e9477596a..773af54dfd 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -21,6 +21,7 @@
#include "SkPixelRef.h"
#include "SkRRect.h"
#include "SkString.h"
+#include "SkTextBlob.h"
#include "SkTypeface.h"
extern "C" {
@@ -45,6 +46,7 @@ DEF_MTNAME(SkPath)
DEF_MTNAME(SkPaint)
DEF_MTNAME(SkPathEffect)
DEF_MTNAME(SkShader)
+DEF_MTNAME(SkTextBlob)
DEF_MTNAME(SkTypeface)
template <typename T> T* push_new(lua_State* L) {
@@ -273,6 +275,11 @@ void SkLua::pushCanvas(SkCanvas* canvas, const char key[]) {
CHECK_SETFIELD(key);
}
+void SkLua::pushTextBlob(const SkTextBlob* blob, const char key[]) {
+ push_ref(fL, const_cast<SkTextBlob*>(blob));
+ CHECK_SETFIELD(key);
+}
+
static const char* element_type(SkClipStack::Element::Type type) {
switch (type) {
case SkClipStack::Element::kEmpty_Type:
diff --git a/src/utils/SkLuaCanvas.cpp b/src/utils/SkLuaCanvas.cpp
index 0903ee8c89..8fe1aa2bbf 100644
--- a/src/utils/SkLuaCanvas.cpp
+++ b/src/utils/SkLuaCanvas.cpp
@@ -268,6 +268,15 @@ void SkLuaCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const Sk
lua.pushPaint(paint, "paint");
}
+void SkLuaCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y,
+ const SkPaint &paint) {
+ AUTO_LUA("drawTextBlob");
+ lua.pushTextBlob(blob, "blob");
+ lua.pushScalar(x, "x");
+ lua.pushScalar(y, "y");
+ lua.pushPaint(paint, "paint");
+}
+
void SkLuaCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
const SkPaint* paint) {
AUTO_LUA("drawPicture");
diff --git a/src/utils/SkNWayCanvas.cpp b/src/utils/SkNWayCanvas.cpp
index d436bd4a6b..90fd017e1c 100644
--- a/src/utils/SkNWayCanvas.cpp
+++ b/src/utils/SkNWayCanvas.cpp
@@ -265,6 +265,14 @@ void SkNWayCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const S
}
}
+void SkNWayCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
+ const SkPaint &paint) {
+ Iter iter(fList);
+ while (iter.next()) {
+ iter->drawTextBlob(blob, x, y, paint);
+ }
+}
+
void SkNWayCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
const SkPaint* paint) {
Iter iter(fList);
diff --git a/src/utils/SkProxyCanvas.cpp b/src/utils/SkProxyCanvas.cpp
index c15acaa78f..1677dafde2 100644
--- a/src/utils/SkProxyCanvas.cpp
+++ b/src/utils/SkProxyCanvas.cpp
@@ -136,6 +136,11 @@ void SkProxyCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const
fProxy->drawTextOnPath(text, byteLength, path, matrix, paint);
}
+void SkProxyCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
+ const SkPaint& paint) {
+ fProxy->drawTextBlob(blob, x, y, paint);
+}
+
void SkProxyCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
const SkPaint* paint) {
fProxy->drawPicture(picture, matrix, paint);
diff --git a/src/utils/debugger/SkDebugCanvas.cpp b/src/utils/debugger/SkDebugCanvas.cpp
index 228f25f737..2b0eab7f32 100644
--- a/src/utils/debugger/SkDebugCanvas.cpp
+++ b/src/utils/debugger/SkDebugCanvas.cpp
@@ -571,6 +571,11 @@ void SkDebugCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const
new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint));
}
+void SkDebugCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
+ const SkPaint& paint) {
+ this->addDrawCommand(new SkDrawTextBlobCommand(blob, x, y, paint));
+}
+
void SkDebugCanvas::drawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
SkXfermode*, const uint16_t indices[], int indexCount,
diff --git a/src/utils/debugger/SkDebugCanvas.h b/src/utils/debugger/SkDebugCanvas.h
index e4fb0d9588..94ad4263e5 100644
--- a/src/utils/debugger/SkDebugCanvas.h
+++ b/src/utils/debugger/SkDebugCanvas.h
@@ -242,6 +242,8 @@ protected:
SkScalar constY, const SkPaint&) SK_OVERRIDE;
virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE;
+ virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
+ const SkPaint& paint) SK_OVERRIDE;
virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
virtual void onPopCull() SK_OVERRIDE;
diff --git a/src/utils/debugger/SkDrawCommand.cpp b/src/utils/debugger/SkDrawCommand.cpp
index 26d2a85a8a..3cebca2c64 100644
--- a/src/utils/debugger/SkDrawCommand.cpp
+++ b/src/utils/debugger/SkDrawCommand.cpp
@@ -10,6 +10,8 @@
#include "SkDrawCommand.h"
#include "SkObjectParser.h"
+#include "SkTextBlob.h"
+
// TODO(chudy): Refactor into non subclass model.
SkDrawCommand::SkDrawCommand(DrawType type)
@@ -643,6 +645,26 @@ void SkDrawPosTextHCommand::execute(SkCanvas* canvas) {
canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
}
+SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
+ const SkPaint& paint)
+ : INHERITED(DRAW_TEXT_BLOB)
+ , fBlob(blob)
+ , fXPos(x)
+ , fYPos(y)
+ , fPaint(paint) {
+
+ blob->ref();
+
+ // FIXME: push blob info
+ fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
+ fInfo.push(SkObjectParser::ScalarToString(x, "YPOS: "));
+ fInfo.push(SkObjectParser::PaintToString(paint));
+}
+
+void SkDrawTextBlobCommand::execute(SkCanvas* canvas) {
+ canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
+}
+
SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
: INHERITED(DRAW_RECT) {
fRect = rect;
diff --git a/src/utils/debugger/SkDrawCommand.h b/src/utils/debugger/SkDrawCommand.h
index ce7b1f5f76..f3c8cca9de 100644
--- a/src/utils/debugger/SkDrawCommand.h
+++ b/src/utils/debugger/SkDrawCommand.h
@@ -436,6 +436,21 @@ private:
typedef SkDrawCommand INHERITED;
};
+class SkDrawTextBlobCommand : public SkDrawCommand {
+public:
+ SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint);
+
+ virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
+
+private:
+ SkAutoTUnref<const SkTextBlob> fBlob;
+ SkScalar fXPos;
+ SkScalar fYPos;
+ SkPaint fPaint;
+
+ typedef SkDrawCommand INHERITED;
+};
+
class SkDrawRectCommand : public SkDrawCommand {
public:
SkDrawRectCommand(const SkRect& rect, const SkPaint& paint);