From b9f38925d3cdae56548c3c18300c2964d207ed4e Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 27 Jul 2012 17:36:43 -0700 Subject: Don't use SkPicture for DrawText recording Change-Id: I5b6872bc37eefded7decae767fc39f1cef858dac --- Source/WebCore/Android.mk | 1 + .../graphics/android/context/GraphicsOperation.h | 66 ++++--------- .../android/context/PlatformGraphicsContext.h | 1 - .../context/PlatformGraphicsContextRecording.cpp | 84 ++++++++++++++--- .../context/PlatformGraphicsContextRecording.h | 8 +- .../android/context/PlatformGraphicsContextSkia.h | 1 - .../context/RecordingContextCanvasProxy.cpp | 68 ++++++++++++++ .../android/context/RecordingContextCanvasProxy.h | 102 +++++++++++++++++++++ .../graphics/android/fonts/FontAndroid.cpp | 69 ++------------ 9 files changed, 276 insertions(+), 124 deletions(-) create mode 100644 Source/WebCore/platform/graphics/android/context/RecordingContextCanvasProxy.cpp create mode 100644 Source/WebCore/platform/graphics/android/context/RecordingContextCanvasProxy.h diff --git a/Source/WebCore/Android.mk b/Source/WebCore/Android.mk index dcef645..cd5764f 100644 --- a/Source/WebCore/Android.mk +++ b/Source/WebCore/Android.mk @@ -645,6 +645,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ platform/graphics/android/context/PlatformGraphicsContext.cpp \ platform/graphics/android/context/PlatformGraphicsContextRecording.cpp \ platform/graphics/android/context/PlatformGraphicsContextSkia.cpp \ + platform/graphics/android/context/RecordingContextCanvasProxy.cpp \ platform/graphics/android/context/RTree.cpp \ \ platform/graphics/android/fonts/FontAndroid.cpp \ diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h b/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h index 2a7369c..604206b 100644 --- a/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h +++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h @@ -79,8 +79,7 @@ public: , StrokePathOperation , StrokeRectOperation // Text - , DrawComplexTextOperation - , DrawTextOperation + , DrawPosTextOperation } OperationType; Operation() @@ -137,8 +136,7 @@ public: TYPE_CASE(StrokePathOperation) TYPE_CASE(StrokeRectOperation) // Text - TYPE_CASE(DrawComplexTextOperation) - TYPE_CASE(DrawTextOperation) + TYPE_CASE(DrawPosTextOperation) } return "Undefined"; } @@ -536,56 +534,32 @@ private: // Text //************************************** -class DrawComplexText : public Operation { +class DrawPosText : public Operation { public: - DrawComplexText(SkPicture* picture) : m_picture(picture) { - SkSafeRef(m_picture); - } - ~DrawComplexText() { SkSafeUnref(m_picture); } - virtual bool applyImpl(PlatformGraphicsContext* context) { - if (!context->getCanvas()) - return true; - context->getCanvas()->drawPicture(*m_picture); - return true; - } - virtual OperationType type() { return DrawComplexTextOperation; } -private: - SkPicture* m_picture; -}; - -class DrawText : public Operation { -public: - DrawText(const Font* font, const SimpleFontData* simpleFont, - const GlyphBuffer& glyphBuffer, - int from, int numGlyphs, const FloatPoint& point) - : m_font(font), m_simpleFont(simpleFont) - , m_glyphBuffer(glyphBuffer), m_from(from) - , m_numGlyphs(numGlyphs), m_point(point) { - SkPicture* picture = new SkPicture(); - SkCanvas* canvas = picture->beginRecording(0, 0, 0); - PlatformGraphicsContextSkia platformContext(canvas); - GraphicsContext graphicsContext(&platformContext); - m_font->drawGlyphs(&graphicsContext, m_simpleFont, - m_glyphBuffer, m_from, m_numGlyphs, m_point); - picture->endRecording(); - m_picture = picture; + DrawPosText(const void* text, size_t byteLength, + const SkPoint pos[], const SkPaint& paint) + : m_byteLength(byteLength) + , m_paint(paint) + { + size_t points = paint.countText(text, byteLength); + m_pos = new SkPoint[points]; + memcpy(m_pos, pos, sizeof(SkPoint) * points); + m_text = malloc(byteLength); + memcpy(m_text, text, byteLength); } - ~DrawText() { SkSafeUnref(m_picture); } + ~DrawPosText() { delete m_pos; free(m_text); } virtual bool applyImpl(PlatformGraphicsContext* context) { if (!context->getCanvas()) return true; - context->getCanvas()->drawPicture(*m_picture); + context->getCanvas()->drawPosText(m_text, m_byteLength, m_pos, m_paint); return true; } - virtual OperationType type() { return DrawTextOperation; } + virtual OperationType type() { return DrawPosTextOperation; } private: - SkPicture* m_picture; - const Font* m_font; - const SimpleFontData* m_simpleFont; - const GlyphBuffer m_glyphBuffer; - int m_from; - int m_numGlyphs; - const FloatPoint m_point; + void* m_text; + size_t m_byteLength; + SkPoint* m_pos; + SkPaint m_paint; }; } diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h index 3056523..595d2ab 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h @@ -141,7 +141,6 @@ public: virtual void strokeRect(const FloatRect& rect, float lineWidth) = 0; virtual SkCanvas* recordingCanvas() = 0; - virtual void endRecording(const SkRect& bounds) = 0; void setRawState(State* state) { m_state = state; } diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp index 1e5aada..a2163ce 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp @@ -1,3 +1,28 @@ +/* + * Copyright 2012, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #define LOG_TAG "PlatformGraphicsContextRecording" #define LOG_NDEBUG 1 @@ -19,6 +44,39 @@ namespace WebCore { +static FloatRect approximateTextBounds(size_t numGlyphs, + const SkPoint pos[], const SkPaint& paint) +{ + if (!numGlyphs || !pos) { + return FloatRect(); + } + + // get glyph position bounds + SkScalar minX = pos[0].x(); + SkScalar maxX = minX; + SkScalar minY = pos[0].y(); + SkScalar maxY = minY; + for (size_t i = 1; i < numGlyphs; ++i) { + SkScalar x = pos[i].x(); + SkScalar y = pos[i].y(); + minX = std::min(minX, x); + maxX = std::max(maxX, x); + minY = std::min(minY, y); + maxY = std::max(maxY, y); + } + + // build final rect + SkPaint::FontMetrics metrics; + SkScalar bufY = paint.getFontMetrics(&metrics); + SkScalar bufX = bufY * 2; + SkScalar adjY = metrics.fAscent / 2; + minY += adjY; + maxY += adjY; + SkRect rect; + rect.set(minX - bufX, minY - bufY, maxX + bufX, maxY + bufY); + return rect; +} + class StateHash { public: static unsigned hash(PlatformGraphicsContext::State* const& state) @@ -274,6 +332,7 @@ PlatformGraphicsContextRecording::PlatformGraphicsContextRecording(Recording* re , mOperationState(0) , m_hasText(false) , m_isEmpty(true) + , m_canvasProxy(this) { if (mRecording) mRecording->setRecording(new RecordingImpl()); @@ -289,21 +348,8 @@ bool PlatformGraphicsContextRecording::isPaintingDisabled() SkCanvas* PlatformGraphicsContextRecording::recordingCanvas() { - SkSafeUnref(mPicture); - mPicture = new SkPicture(); - return mPicture->beginRecording(0, 0, 0); -} - -void PlatformGraphicsContextRecording::endRecording(const SkRect& bounds) -{ - if (!mPicture) - return; - mPicture->endRecording(); - GraphicsOperation::DrawComplexText* text = new GraphicsOperation::DrawComplexText(mPicture); - appendDrawingOperation(text, bounds); - mPicture = 0; - m_hasText = true; + return &m_canvasProxy; } //************************************** @@ -677,6 +723,16 @@ void PlatformGraphicsContextRecording::strokeRect(const FloatRect& rect, float l appendDrawingOperation(new GraphicsOperation::StrokeRect(rect, lineWidth), bounds); } +void PlatformGraphicsContextRecording::drawPosText(const void* text, size_t byteLength, + const SkPoint pos[], const SkPaint& paint) +{ + if (paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding) { + ALOGE("Unsupported text encoding! %d", paint.getTextEncoding()); + } + FloatRect bounds = approximateTextBounds(byteLength / sizeof(uint16_t), pos, paint); + appendDrawingOperation(new GraphicsOperation::DrawPosText(text, byteLength, pos, paint), bounds); +} + void PlatformGraphicsContextRecording::clipState(const FloatRect& clip) { if (mRecordingStateStack.size()) { diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h index c06c9bc..3af1e2f 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h @@ -28,10 +28,9 @@ #include "PlatformGraphicsContext.h" +#include "RecordingContextCanvasProxy.h" #include "SkRefCnt.h" -class SkCanvas; - namespace WebCore { namespace GraphicsOperation { class Operation; @@ -62,7 +61,6 @@ public: virtual SkCanvas* getCanvas() { return 0; } virtual SkCanvas* recordingCanvas(); - virtual void endRecording(const SkRect& bounds); virtual ContextType type() { return RecordingContext; } @@ -135,6 +133,9 @@ public: virtual void strokePath(const Path& pathToStroke); virtual void strokeRect(const FloatRect& rect, float lineWidth); + void drawPosText(const void* text, size_t byteLength, + const SkPoint pos[], const SkPaint& paint); + bool hasText() { return m_hasText; } bool isEmpty() { return m_isEmpty; } private: @@ -192,6 +193,7 @@ private: bool m_hasText; bool m_isEmpty; + RecordingContextCanvasProxy m_canvasProxy; }; } diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.h b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.h index 3c5e347..32249c3 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.h +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.h @@ -39,7 +39,6 @@ public: virtual ContextType type() { return PaintingContext; } virtual SkCanvas* recordingCanvas() { return mCanvas; } - virtual void endRecording(const SkRect& bounds) {} // FIXME: This is used by ImageBufferAndroid, which should really be // managing the canvas lifecycle itself diff --git a/Source/WebCore/platform/graphics/android/context/RecordingContextCanvasProxy.cpp b/Source/WebCore/platform/graphics/android/context/RecordingContextCanvasProxy.cpp new file mode 100644 index 0000000..ea3b1a2 --- /dev/null +++ b/Source/WebCore/platform/graphics/android/context/RecordingContextCanvasProxy.cpp @@ -0,0 +1,68 @@ +/* + * Copyright 2012, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "RecordingContextCanvasProxy.h" + +#include "PlatformGraphicsContextRecording.h" + +namespace WebCore { + +// Return value is unused by FontAndroid +int RecordingContextCanvasProxy::save(SaveFlags) +{ + m_pgc->save(); + return -1; +} + +void RecordingContextCanvasProxy::restore() +{ + m_pgc->restore(); +} + +void RecordingContextCanvasProxy::drawPosText(const void* text, + size_t byteLength, + const SkPoint pos[], + const SkPaint& paint) +{ + m_pgc->drawPosText(text, byteLength, pos, paint); +} + +void RecordingContextCanvasProxy::drawBitmapRect(const SkBitmap& bitmap, + const SkIRect* src, + const SkRect& dst, + const SkPaint*) +{ + m_pgc->drawBitmapRect(bitmap, src, dst, CompositeSourceOver); +} + +// Return value is unused by FontAndroid +bool RecordingContextCanvasProxy::rotate(SkScalar degrees) +{ + m_pgc->rotate(degrees / (180.0f / 3.14159265f)); + return true; +} + +} // WebCore diff --git a/Source/WebCore/platform/graphics/android/context/RecordingContextCanvasProxy.h b/Source/WebCore/platform/graphics/android/context/RecordingContextCanvasProxy.h new file mode 100644 index 0000000..4daf5e7 --- /dev/null +++ b/Source/WebCore/platform/graphics/android/context/RecordingContextCanvasProxy.h @@ -0,0 +1,102 @@ +/* + * Copyright 2012, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RecordingContextCanvasProxy_h +#define RecordingContextCanvasProxy_h + +#include "SkCanvas.h" + +namespace WebCore { + +class PlatformGraphicsContextRecording; + +class RecordingContextCanvasProxy : public SkCanvas { +public: + RecordingContextCanvasProxy(PlatformGraphicsContextRecording* pgc) + : m_pgc(pgc) + {} + + // Used by FontAndroid + + // Return value is unused by FontAndroid + virtual int save(SaveFlags); + virtual void restore(); + virtual void drawPosText(const void* text, size_t byteLength, + const SkPoint pos[], const SkPaint& paint); + virtual bool rotate(SkScalar degrees); + + // Used by EmojiFont + + virtual void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src, + const SkRect& dst, const SkPaint*); + + // These aren't used by anyone + + virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) { /* NOT IMPLEMENTED*/ CRASH(); return -1; } + virtual bool translate(SkScalar dx, SkScalar dy) { /* NOT IMPLEMENTED*/ CRASH(); return -1; } + virtual bool scale(SkScalar sx, SkScalar sy) { /* NOT IMPLEMENTED*/ CRASH(); return -1; } + virtual bool skew(SkScalar sx, SkScalar sy) { /* NOT IMPLEMENTED*/ CRASH(); return -1; } + virtual bool concat(const SkMatrix& matrix) { /* NOT IMPLEMENTED*/ CRASH(); return -1; } + virtual void setMatrix(const SkMatrix& matrix) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual bool clipRect(const SkRect&, SkRegion::Op, bool) { /* NOT IMPLEMENTED*/ CRASH(); return -1; } + virtual bool clipPath(const SkPath&, SkRegion::Op, bool) { /* NOT IMPLEMENTED*/ CRASH(); return -1; } + virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) { /* NOT IMPLEMENTED*/ CRASH(); return -1; } + virtual void clear(SkColor) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawPaint(const SkPaint& paint) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], + const SkPaint&) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawRect(const SkRect& rect, const SkPaint&) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawPath(const SkPath& path, const SkPaint&) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, + const SkPaint*) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, + const SkPaint*) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, + const SkRect& dst, const SkPaint*) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawSprite(const SkBitmap&, int left, int top, + const SkPaint*) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawText(const void* text, size_t byteLength, SkScalar x, + SkScalar y, const SkPaint&) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawPosTextH(const void* text, size_t byteLength, + const SkScalar xpos[], SkScalar constY, const SkPaint&) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawTextOnPath(const void* text, size_t byteLength, + const SkPath& path, const SkMatrix* matrix, + const SkPaint&) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawPicture(SkPicture& picture) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawVertices(VertexMode, int vertexCount, + const SkPoint vertices[], const SkPoint texs[], + const SkColor colors[], SkXfermode*, + const uint16_t indices[], int indexCount, + const SkPaint&) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual void drawData(const void*, size_t) { /* NOT IMPLEMENTED*/ CRASH(); } + virtual bool isDrawingToLayer() const { /* NOT IMPLEMENTED*/ CRASH(); return -1; } + +private: + PlatformGraphicsContextRecording* m_pgc; +}; + +} // namespace WebCore + +#endif // RecordingContextCanvasProxy_h diff --git a/Source/WebCore/platform/graphics/android/fonts/FontAndroid.cpp b/Source/WebCore/platform/graphics/android/fonts/FontAndroid.cpp index 6388325..fcb78ed 100644 --- a/Source/WebCore/platform/graphics/android/fonts/FontAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/fonts/FontAndroid.cpp @@ -177,48 +177,6 @@ static bool setupForText(SkPaint* paint, GraphicsContext* gc, return true; } -static void approximateTextBounds(SkRect& rect, size_t numGlyphs, - const SkPoint pos[], const SkPaint& paint) -{ - if (!numGlyphs || !pos) { - return; - } - - // get glyph position bounds - SkScalar minX = pos[0].x(); - SkScalar maxX = minX; - SkScalar minY = pos[0].y(); - SkScalar maxY = minY; - for (size_t i = 1; i < numGlyphs; ++i) { - SkScalar x = pos[i].x(); - SkScalar y = pos[i].y(); - minX = std::min(minX, x); - maxX = std::max(maxX, x); - minY = std::min(minY, y); - maxY = std::max(maxY, y); - } - - // build final rect - SkPaint::FontMetrics metrics; - SkScalar bufY = paint.getFontMetrics(&metrics); - SkScalar bufX = bufY * 2; - SkScalar adjY = metrics.fAscent / 2; - minY += adjY; - maxY += adjY; - rect.set(minX - bufX, minY - bufY, maxX + bufX, maxY + bufY); -} - -static SkRect drawPosText(SkCanvas* canvas, const void* text, - size_t byteLength, const SkPoint pos[], const SkPaint& paint) -{ - canvas->drawPosText(text, byteLength, pos, paint); - SkRect textBounds; - approximateTextBounds(textBounds, byteLength / sizeof(uint16_t), pos, - paint); - canvas->getTotalMatrix().mapRect(&textBounds); - return textBounds; -} - bool Font::canReturnFallbackFontsForComplexText() { return false; @@ -263,7 +221,6 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, if (font->platformData().orientation() == Vertical) y += SkFloatToScalar(font->fontMetrics().floatAscent(IdeographicBaseline) - font->fontMetrics().floatAscent()); - FloatRect textBounds; if (EmojiFont::IsAvailable()) { // set filtering, to make scaled images look nice(r) paint.setFilterBitmap(true); @@ -273,14 +230,11 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, for (int i = 0; i < numGlyphs; i++) { if (EmojiFont::IsEmojiGlyph(glyphs[i])) { if (localCount) { - textBounds.unite(drawPosText(canvas, &glyphs[localIndex], + canvas->drawPosText(&glyphs[localIndex], localCount * sizeof(uint16_t), - &pos[localIndex], paint)); + &pos[localIndex], paint); } EmojiFont::Draw(canvas, glyphs[i], x, y, paint); - float size = paint.getTextSize(); - FloatRect emojiBounds(x, y - size + 0.2f, size, size); - textBounds.unite(emojiBounds); // reset local index/count track for "real" glyphs localCount = 0; localIndex = i + 1; @@ -293,9 +247,9 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, } // draw the last run of glyphs (if any) if (localCount) { - textBounds.unite(drawPosText(canvas, &glyphs[localIndex], + canvas->drawPosText(&glyphs[localIndex], localCount * sizeof(uint16_t), - &pos[localIndex], paint)); + &pos[localIndex], paint); } } else { for (int i = 0; i < numGlyphs; i++) { @@ -312,13 +266,12 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, rotator.setRotate(90); rotator.mapPoints(pos, numGlyphs); } - textBounds.unite(drawPosText(canvas, glyphs, - numGlyphs * sizeof(uint16_t), pos, paint)); + canvas->drawPosText(glyphs, + numGlyphs * sizeof(uint16_t), pos, paint); if (font->platformData().orientation() == Vertical) canvas->restore(); } - gc->platformContext()->endRecording(textBounds); } void Font::drawEmphasisMarksForComplexText(WebCore::GraphicsContext*, WebCore::TextRun const&, WTF::AtomicString const&, WebCore::FloatPoint const&, int, int) const @@ -1082,23 +1035,21 @@ void Font::drawComplexText(GraphicsContext* gc, TextRun const& run, walker.setWordAndLetterSpacing(wordSpacing(), letterSpacing()); walker.setPadding(run.expansion()); - FloatRect textBounds; while (walker.nextScriptRun()) { if (fill) { walker.fontPlatformDataForScriptRun()->setupPaint(&fillPaint); adjustTextRenderMode(&fillPaint, haveMultipleLayers); - textBounds.unite(drawPosText(canvas, walker.glyphs(), - walker.length() << 1, walker.positions(), fillPaint)); + canvas->drawPosText(walker.glyphs(), + walker.length() << 1, walker.positions(), fillPaint); } if (stroke) { walker.fontPlatformDataForScriptRun()->setupPaint(&strokePaint); adjustTextRenderMode(&strokePaint, haveMultipleLayers); - textBounds.unite(drawPosText(canvas, walker.glyphs(), - walker.length() << 1, walker.positions(), strokePaint)); + canvas->drawPosText(walker.glyphs(), + walker.length() << 1, walker.positions(), strokePaint); } } - gc->platformContext()->endRecording(textBounds); } float Font::floatWidthForComplexText(const TextRun& run, -- cgit v1.1