From 22ddc4a8f76077593fba14c8cafffc74f9170dab Mon Sep 17 00:00:00 2001 From: John Reck Date: Tue, 10 Jul 2012 10:10:18 -0700 Subject: Build a clipping tree in RecordingContext Change-Id: I967c8e2ea209c848e6a09b44390ab2228b213ca5 --- .../graphics/android/context/GraphicsOperation.h | 160 +++++++++++++-------- .../context/GraphicsOperationCollection.cpp | 33 ++++- .../android/context/GraphicsOperationCollection.h | 10 +- .../android/context/PlatformGraphicsContext.h | 12 +- .../context/PlatformGraphicsContextRecording.cpp | 54 ++++--- .../context/PlatformGraphicsContextRecording.h | 17 +-- .../context/PlatformGraphicsContextSkia.cpp | 26 ++-- .../android/context/PlatformGraphicsContextSkia.h | 12 +- 8 files changed, 200 insertions(+), 124 deletions(-) diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h b/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h index 942d9a6..ae52b2b 100644 --- a/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h +++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h @@ -26,11 +26,10 @@ #ifndef GraphicsOperation_h #define GraphicsOperation_h -#if USE(ACCELERATED_COMPOSITING) - #include "Color.h" #include "FloatRect.h" #include "GlyphBuffer.h" +#include "GraphicsOperationCollection.h" #include "Font.h" #include "IntRect.h" #include "PlatformGraphicsContext.h" @@ -101,7 +100,7 @@ public: , DrawTextOperation } OperationType; - virtual void apply(PlatformGraphicsContext* context) = 0; + virtual bool apply(PlatformGraphicsContext* context) = 0; virtual ~Operation() {} virtual OperationType type() { return UndefinedOperation; } virtual String parameters() { return ""; } @@ -169,7 +168,10 @@ public: class BeginTransparencyLayer : public Operation { public: BeginTransparencyLayer(const float opacity) : m_opacity(opacity) {} - virtual void apply(PlatformGraphicsContext* context) { context->beginTransparencyLayer(m_opacity); } + virtual bool apply(PlatformGraphicsContext* context) { + context->beginTransparencyLayer(m_opacity); + return true; + } virtual OperationType type() { return BeginTransparencyLayerOperation; } private: float m_opacity; @@ -177,18 +179,24 @@ private: class EndTransparencyLayer : public Operation { public: EndTransparencyLayer() {} - virtual void apply(PlatformGraphicsContext* context) { context->endTransparencyLayer(); } + virtual bool apply(PlatformGraphicsContext* context) { + context->endTransparencyLayer(); + return true; + } virtual OperationType type() { return EndTransparencyLayerOperation; } }; class Save : public Operation { public: - virtual void apply(PlatformGraphicsContext* context) { context->save(); } + virtual bool apply(PlatformGraphicsContext* context) { + context->save(); + m_operations.apply(context); + context->restore(); + return true; + } virtual OperationType type() { return SaveOperation; } -}; -class Restore : public Operation { -public: - virtual void apply(PlatformGraphicsContext* context) { context->restore(); } - virtual OperationType type() { return RestoreOperation; } + GraphicsOperationCollection* operations() { return &m_operations; } +private: + GraphicsOperationCollection m_operations; }; //************************************** @@ -198,7 +206,10 @@ public: class SetAlpha : public Operation { public: SetAlpha(const float alpha) : m_alpha(alpha) {} - virtual void apply(PlatformGraphicsContext* context) { context->setAlpha(m_alpha); } + virtual bool apply(PlatformGraphicsContext* context) { + context->setAlpha(m_alpha); + return true; + } virtual OperationType type() { return SetAlphaOperation; } private: float m_alpha; @@ -207,8 +218,9 @@ private: class SetCompositeOperation : public Operation { public: SetCompositeOperation(CompositeOperator op) : m_operator(op) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setCompositeOperation(m_operator); + return true; } virtual OperationType type() { return SetCompositeOpOperation; } private: @@ -218,8 +230,9 @@ private: class SetFillColor : public Operation { public: SetFillColor(Color color) : m_color(color) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setFillColor(m_color); + return true; } virtual OperationType type() { return SetFillColorOperation; } virtual String parameters() { @@ -239,8 +252,9 @@ public: SkSafeRef(m_shader); } ~SetFillShader() { SkSafeUnref(m_shader); } - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setFillShader(m_shader); + return true; } virtual OperationType type() { return SetFillShaderOperation; } private: @@ -250,8 +264,9 @@ private: class SetLineCap : public Operation { public: SetLineCap(LineCap cap) : m_cap(cap) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setLineCap(m_cap); + return true; } virtual OperationType type() { return SetLineCapOperation; } private: @@ -262,8 +277,9 @@ class SetLineDash : public Operation { public: SetLineDash(const DashArray& dashes, float dashOffset) : m_dashes(dashes), m_dashOffset(dashOffset) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setLineDash(m_dashes, m_dashOffset); + return true; } virtual OperationType type() { return SetLineDashOperation; } private: @@ -274,8 +290,9 @@ private: class SetLineJoin : public Operation { public: SetLineJoin(LineJoin join) : m_join(join) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setLineJoin(m_join); + return true; } virtual OperationType type() { return SetLineJoinOperation; } private: @@ -285,8 +302,9 @@ private: class SetMiterLimit : public Operation { public: SetMiterLimit(float limit) : m_limit(limit) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setMiterLimit(m_limit); + return true; } virtual OperationType type() { return SetMiterLimitOperation; } private: @@ -297,8 +315,9 @@ class SetShadow : public Operation { public: SetShadow(int radius, int dx, int dy, SkColor c) : m_radius(radius), m_dx(dx), m_dy(dy), m_color(c) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setShadow(m_radius, m_dx, m_dy, m_color); + return true; } virtual OperationType type() { return SetShadowOperation; } private: @@ -311,8 +330,9 @@ private: class SetShouldAntialias : public Operation { public: SetShouldAntialias(bool useAA) : m_useAA(useAA) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setShouldAntialias(m_useAA); + return true; } virtual OperationType type() { return SetShouldAntialiasOperation; } private: @@ -322,8 +342,9 @@ private: class SetStrokeColor : public Operation { public: SetStrokeColor(const Color& c) : m_color(c) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setStrokeColor(m_color); + return true; } virtual OperationType type() { return SetStrokeColorOperation; } private: @@ -336,8 +357,9 @@ public: SkSafeRef(m_shader); } ~SetStrokeShader() { SkSafeUnref(m_shader); } - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setStrokeShader(m_shader); + return true; } virtual OperationType type() { return SetStrokeShaderOperation; } private: @@ -347,8 +369,9 @@ private: class SetStrokeStyle : public Operation { public: SetStrokeStyle(StrokeStyle style) : m_style(style) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setStrokeStyle(m_style); + return true; } virtual OperationType type() { return SetStrokeStyleOperation; } private: @@ -358,8 +381,9 @@ private: class SetStrokeThickness : public Operation { public: SetStrokeThickness(float thickness) : m_thickness(thickness) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->setStrokeThickness(m_thickness); + return true; } virtual OperationType type() { return SetStrokeThicknessOperation; } private: @@ -373,8 +397,9 @@ private: class ConcatCTM : public Operation { public: ConcatCTM(const AffineTransform& affine) : m_matrix(affine) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->concatCTM(m_matrix); + return true; } virtual OperationType type() { return ConcatCTMOperation; } private: @@ -384,8 +409,9 @@ private: class Rotate : public Operation { public: Rotate(float angleInRadians) : m_angle(angleInRadians) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->rotate(m_angle); + return true; } virtual OperationType type() { return RotateOperation; } private: @@ -395,8 +421,9 @@ private: class Scale : public Operation { public: Scale(const FloatSize& size) : m_scale(size) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->scale(m_scale); + return true; } virtual OperationType type() { return ScaleOperation; } private: @@ -406,8 +433,9 @@ private: class Translate : public Operation { public: Translate(float x, float y) : m_x(x), m_y(y) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->translate(m_x, m_y); + return true; } virtual OperationType type() { return TranslateOperation; } private: @@ -423,8 +451,9 @@ class InnerRoundedRectClip : public Operation { public: InnerRoundedRectClip(const IntRect& rect, int thickness) : m_rect(rect), m_thickness(thickness) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->addInnerRoundedRectClip(m_rect, m_thickness); + return true; } virtual OperationType type() { return InnerRoundedRectClipOperation; } private: @@ -435,8 +464,8 @@ private: class Clip : public Operation { public: Clip(const FloatRect& rect) : m_rect(rect) {} - virtual void apply(PlatformGraphicsContext* context) { - context->clip(m_rect); + virtual bool apply(PlatformGraphicsContext* context) { + return context->clip(m_rect); } virtual OperationType type() { return ClipOperation; } private: @@ -448,15 +477,14 @@ public: ClipPath(const Path& path, bool clipout = false) : m_path(path), m_clipOut(clipout), m_hasWindRule(false) {} void setWindRule(WindRule rule) { m_windRule = rule; m_hasWindRule = true; } - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { if (m_hasWindRule) { - context->clipPath(m_path, m_windRule); - return; + return context->clipPath(m_path, m_windRule); } if (m_clipOut) - context->clipOut(m_path); + return context->clipOut(m_path); else - context->clip(m_path); + return context->clip(m_path); } virtual OperationType type() { return ClipPathOperation; } private: @@ -469,8 +497,8 @@ private: class ClipOut : public Operation { public: ClipOut(const IntRect& rect) : m_rect(rect) {} - virtual void apply(PlatformGraphicsContext* context) { - context->clipOut(m_rect); + virtual bool apply(PlatformGraphicsContext* context) { + return context->clipOut(m_rect); } virtual OperationType type() { return ClipOutOperation; } private: @@ -480,8 +508,9 @@ private: class ClearRect : public Operation { public: ClearRect(const FloatRect& rect) : m_rect(rect) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->clearRect(m_rect); + return true; } virtual OperationType type() { return ClearRectOperation; } private: @@ -497,8 +526,9 @@ public: DrawBitmapPattern(const SkBitmap& bitmap, const SkMatrix& matrix, CompositeOperator op, const FloatRect& destRect) : m_bitmap(bitmap), m_matrix(matrix), m_operator(op), m_destRect(destRect) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->drawBitmapPattern(m_bitmap, m_matrix, m_operator, m_destRect); + return true; } virtual OperationType type() { return DrawBitmapPatternOperation; } private: @@ -514,8 +544,9 @@ public: DrawBitmapRect(const SkBitmap& bitmap, const SkIRect& srcR, const SkRect& dstR, CompositeOperator op) : m_bitmap(bitmap), m_srcR(srcR), m_dstR(dstR), m_operator(op) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->drawBitmapRect(m_bitmap, &m_srcR, m_dstR, m_operator); + return true; } virtual OperationType type() { return DrawBitmapRectOperation; } virtual String parameters() { @@ -533,8 +564,9 @@ private: class DrawEllipse : public Operation { public: DrawEllipse(const IntRect& rect) : m_rect(rect) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->drawEllipse(m_rect); + return true; } virtual OperationType type() { return DrawEllipseOperation; } private: @@ -545,8 +577,9 @@ class DrawLine : public Operation { public: DrawLine(const IntPoint& point1, const IntPoint& point2) : m_point1(point1), m_point2(point2) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->drawLine(m_point1, m_point2); + return true; } virtual OperationType type() { return DrawLineOperation; } private: @@ -558,8 +591,9 @@ class DrawLineForText : public Operation { public: DrawLineForText(const FloatPoint& pt, float width) : m_point(pt), m_width(width) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->drawLineForText(m_point, m_width); + return true; } virtual OperationType type() { return DrawLineForTextOperation; } private: @@ -572,8 +606,9 @@ public: DrawLineForTextChecking(const FloatPoint& pt, float width, GraphicsContext::TextCheckingLineStyle lineStyle) : m_point(pt), m_width(width), m_lineStyle(lineStyle) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->drawLineForTextChecking(m_point, m_width, m_lineStyle); + return true; } virtual OperationType type() { return DrawLineForTextCheckingOperation; } private: @@ -585,8 +620,9 @@ private: class DrawRect : public Operation { public: DrawRect(const IntRect& rect) : m_rect(rect) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->drawRect(m_rect); + return true; } virtual OperationType type() { return DrawRectOperation; } private: @@ -597,8 +633,9 @@ class FillPath : public Operation { public: FillPath(const Path& pathToFill, WindRule fillRule) : m_path(pathToFill), m_fillRule(fillRule) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->fillPath(m_path, m_fillRule); + return true; } virtual OperationType type() { return FillPathOperation; } private: @@ -610,11 +647,12 @@ class FillRect : public Operation { public: FillRect(const FloatRect& rect) : m_rect(rect), m_hasColor(false) {} void setColor(Color c) { m_color = c; m_hasColor = true; } - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { if (m_hasColor) context->fillRect(m_rect, m_color); else context->fillRect(m_rect); + return true; } virtual OperationType type() { return FillRectOperation; } private: @@ -638,10 +676,11 @@ public: , m_bottomRight(bottomRight) , m_color(color) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->fillRoundedRect(m_rect, m_topLeft, m_topRight, m_bottomLeft, m_bottomRight, m_color); + return true; } virtual OperationType type() { return FillRoundedRectOperation; } private: @@ -660,8 +699,9 @@ public: , m_startAngle(startAngle) , m_angleSpan(angleSpan) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->strokeArc(m_rect, m_startAngle, m_angleSpan); + return true; } virtual OperationType type() { return StrokeArcOperation; } private: @@ -673,8 +713,9 @@ private: class StrokePath : public Operation { public: StrokePath(const Path& path) : m_path(path) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->strokePath(m_path); + return true; } virtual OperationType type() { return StrokePathOperation; } private: @@ -686,8 +727,9 @@ class StrokeRect : public Operation { public: StrokeRect(const FloatRect& rect, float lineWidth) : m_rect(rect), m_lineWidth(lineWidth) {} - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { context->strokeRect(m_rect, m_lineWidth); + return true; } virtual OperationType type() { return StrokeRectOperation; } private: @@ -705,10 +747,11 @@ public: SkSafeRef(m_picture); } ~DrawComplexText() { SkSafeUnref(m_picture); } - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { if (!context->getCanvas()) - return; + return true; context->getCanvas()->drawPicture(*m_picture); + return true; } virtual OperationType type() { return DrawComplexTextOperation; } private: @@ -733,10 +776,11 @@ public: m_picture = picture; } ~DrawText() { SkSafeUnref(m_picture); } - virtual void apply(PlatformGraphicsContext* context) { + virtual bool apply(PlatformGraphicsContext* context) { if (!context->getCanvas()) - return; + return true; context->getCanvas()->drawPicture(*m_picture); + return true; } virtual OperationType type() { return DrawTextOperation; } private: @@ -753,6 +797,4 @@ private: } -#endif // USE(ACCELERATED_COMPOSITING) - #endif // GraphicsOperation_h diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp index 1ebb369..a24f829 100644 --- a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp +++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.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 "GraphicsOperationCollection" #define LOG_NDEBUG 1 @@ -6,11 +31,10 @@ #include "AndroidLog.h" #include "GraphicsContext.h" +#include "GraphicsOperation.h" #include "PlatformGraphicsContext.h" #include "PlatformGraphicsContextRecording.h" -#if USE(ACCELERATED_COMPOSITING) - namespace WebCore { GraphicsOperationCollection::GraphicsOperationCollection() @@ -26,7 +50,8 @@ void GraphicsOperationCollection::apply(PlatformGraphicsContext* context) const { size_t size = m_operations.size(); for (size_t i = 0; i < size; i++) - m_operations[i]->apply(context); + if (!m_operations[i]->apply(context)) + return; } void GraphicsOperationCollection::adoptAndAppend(GraphicsOperation::Operation* operation) @@ -57,5 +82,3 @@ void GraphicsOperationCollection::clear() } } // namespace WebCore - -#endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h index 713d06e..d2c18ab 100644 --- a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h +++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h @@ -26,13 +26,15 @@ #ifndef GraphicsOperationCollection_h #define GraphicsOperationCollection_h -#if USE(ACCELERATED_COMPOSITING) - -#include "GraphicsOperation.h" #include "SkRefCnt.h" +#include "wtf/Vector.h" namespace WebCore { +namespace GraphicsOperation { +class Operation; +} + class PlatformGraphicsContext; class GraphicsOperationCollection : public SkRefCnt { @@ -56,6 +58,4 @@ private: } -#endif // USE(ACCELERATED_COMPOSITING) - #endif // GraphicsOperationCollection_h diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h index 69ccdaf..d30bac3 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h @@ -92,12 +92,12 @@ public: // Clipping virtual void addInnerRoundedRectClip(const IntRect& rect, int thickness) = 0; virtual void canvasClip(const Path& path) = 0; - virtual void clip(const FloatRect& rect) = 0; - virtual void clip(const Path& path) = 0; - virtual void clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias) = 0; - virtual void clipOut(const IntRect& r) = 0; - virtual void clipOut(const Path& p) = 0; - virtual void clipPath(const Path& pathToClip, WindRule clipRule) = 0; + virtual bool clip(const FloatRect& rect) = 0; + virtual bool clip(const Path& path) = 0; + virtual bool clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias) = 0; + virtual bool clipOut(const IntRect& r) = 0; + virtual bool clipOut(const Path& p) = 0; + virtual bool clipPath(const Path& pathToClip, WindRule clipRule) = 0; // Drawing virtual void clearRect(const FloatRect& rect) = 0; diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp index 3b60ec0..6bbffcd 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp @@ -19,13 +19,15 @@ namespace WebCore { PlatformGraphicsContextRecording::PlatformGraphicsContextRecording(GraphicsOperationCollection* picture) : PlatformGraphicsContext() , mPicture(0) - , mGraphicsOperationCollection(picture) + , mPendingOperation(0) { + if (picture) + mGraphicsOperationStack.append(picture); } bool PlatformGraphicsContextRecording::isPaintingDisabled() { - return !mGraphicsOperationCollection; + return !mGraphicsOperationStack.size(); } SkCanvas* PlatformGraphicsContextRecording::recordingCanvas() @@ -64,17 +66,17 @@ void PlatformGraphicsContextRecording::save() { PlatformGraphicsContext::save(); flushPendingOperations(); - mPendingOperations.adoptAndAppend(new GraphicsOperation::Save()); + mPendingOperation = new GraphicsOperation::Save(); } void PlatformGraphicsContextRecording::restore() { PlatformGraphicsContext::restore(); - // If we have pending operations then the save/restore pair is empty and a no-op, discard it - if (mPendingOperations.isEmpty()) - mGraphicsOperationCollection->adoptAndAppend(new GraphicsOperation::Restore()); - else - mPendingOperations.clear(); + if (mPendingOperation) { + delete mPendingOperation; + mPendingOperation = 0; + } else + mGraphicsOperationStack.removeLast(); } //************************************** @@ -227,37 +229,43 @@ void PlatformGraphicsContextRecording::canvasClip(const Path& path) clip(path); } -void PlatformGraphicsContextRecording::clip(const FloatRect& rect) +bool PlatformGraphicsContextRecording::clip(const FloatRect& rect) { appendStateOperation(new GraphicsOperation::Clip(rect)); + return true; } -void PlatformGraphicsContextRecording::clip(const Path& path) +bool PlatformGraphicsContextRecording::clip(const Path& path) { appendStateOperation(new GraphicsOperation::ClipPath(path)); + return true; } -void PlatformGraphicsContextRecording::clipConvexPolygon(size_t numPoints, +bool PlatformGraphicsContextRecording::clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias) { // TODO + return true; } -void PlatformGraphicsContextRecording::clipOut(const IntRect& r) +bool PlatformGraphicsContextRecording::clipOut(const IntRect& r) { appendStateOperation(new GraphicsOperation::ClipOut(r)); + return true; } -void PlatformGraphicsContextRecording::clipOut(const Path& path) +bool PlatformGraphicsContextRecording::clipOut(const Path& path) { appendStateOperation(new GraphicsOperation::ClipPath(path, true)); + return true; } -void PlatformGraphicsContextRecording::clipPath(const Path& pathToClip, WindRule clipRule) +bool PlatformGraphicsContextRecording::clipPath(const Path& pathToClip, WindRule clipRule) { GraphicsOperation::ClipPath* operation = new GraphicsOperation::ClipPath(pathToClip); operation->setWindRule(clipRule); appendStateOperation(operation); + return true; } void PlatformGraphicsContextRecording::clearRect(const FloatRect& rect) @@ -389,24 +397,24 @@ void PlatformGraphicsContextRecording::strokeRect(const FloatRect& rect, float l void PlatformGraphicsContextRecording::appendDrawingOperation(GraphicsOperation::Operation* operation) { flushPendingOperations(); - mGraphicsOperationCollection->adoptAndAppend(operation); + mGraphicsOperationStack.last()->adoptAndAppend(operation); } void PlatformGraphicsContextRecording::appendStateOperation(GraphicsOperation::Operation* operation) { - // If we have pending operations, we are in a save/restore pair that we are not - // sure whether or not it does any drawing in which case we add this operation to - // the pending operations - if (mPendingOperations.isEmpty()) - mGraphicsOperationCollection->adoptAndAppend(operation); + if (mPendingOperation) + mPendingOperation->operations()->adoptAndAppend(operation); else - mPendingOperations.adoptAndAppend(operation); + mGraphicsOperationStack.last()->adoptAndAppend(operation); } void PlatformGraphicsContextRecording::flushPendingOperations() { - if (!mPendingOperations.isEmpty()) - mGraphicsOperationCollection->transferFrom(mPendingOperations); + if (mPendingOperation) { + mGraphicsOperationStack.last()->adoptAndAppend(mPendingOperation); + mGraphicsOperationStack.append(mPendingOperation->operations()); + mPendingOperation = 0; + } } } // WebCore diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h index 1cce5a6..4a202f9 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h @@ -33,6 +33,7 @@ namespace WebCore { namespace GraphicsOperation { class Operation; +class Save; } class PlatformGraphicsContextRecording : public PlatformGraphicsContext { @@ -79,12 +80,12 @@ public: // Clipping virtual void addInnerRoundedRectClip(const IntRect& rect, int thickness); virtual void canvasClip(const Path& path); - virtual void clip(const FloatRect& rect); - virtual void clip(const Path& path); - virtual void clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias); - virtual void clipOut(const IntRect& r); - virtual void clipOut(const Path& p); - virtual void clipPath(const Path& pathToClip, WindRule clipRule); + virtual bool clip(const FloatRect& rect); + virtual bool clip(const Path& path); + virtual bool clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias); + virtual bool clipOut(const IntRect& r); + virtual bool clipOut(const Path& p); + virtual bool clipPath(const Path& pathToClip, WindRule clipRule); // Drawing virtual void clearRect(const FloatRect& rect); @@ -129,8 +130,8 @@ private: SkPicture* mPicture; SkMatrix mCurrentMatrix; - GraphicsOperationCollection* mGraphicsOperationCollection; - GraphicsOperationCollection mPendingOperations; + Vector mGraphicsOperationStack; + GraphicsOperation::Save* mPendingOperation; }; } diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.cpp b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.cpp index f00bb02..2fa3805 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.cpp +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.cpp @@ -174,43 +174,45 @@ void PlatformGraphicsContextSkia::canvasClip(const Path& path) clip(path); } -void PlatformGraphicsContextSkia::clip(const FloatRect& rect) +bool PlatformGraphicsContextSkia::clip(const FloatRect& rect) { - mCanvas->clipRect(rect); + return mCanvas->clipRect(rect); } -void PlatformGraphicsContextSkia::clip(const Path& path) +bool PlatformGraphicsContextSkia::clip(const Path& path) { - mCanvas->clipPath(*path.platformPath(), SkRegion::kIntersect_Op, true); + return mCanvas->clipPath(*path.platformPath(), SkRegion::kIntersect_Op, true); } -void PlatformGraphicsContextSkia::clipConvexPolygon(size_t numPoints, +bool PlatformGraphicsContextSkia::clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias) { if (numPoints <= 1) - return; + return true; // This is only used if HAVE_PATH_BASED_BORDER_RADIUS_DRAWING is defined // in RenderObject.h which it isn't for us. TODO: Support that :) + return true; } -void PlatformGraphicsContextSkia::clipOut(const IntRect& r) +bool PlatformGraphicsContextSkia::clipOut(const IntRect& r) { - mCanvas->clipRect(r, SkRegion::kDifference_Op); + return mCanvas->clipRect(r, SkRegion::kDifference_Op); } -void PlatformGraphicsContextSkia::clipOut(const Path& path) +bool PlatformGraphicsContextSkia::clipOut(const Path& path) { - mCanvas->clipPath(*path.platformPath(), SkRegion::kDifference_Op); + return mCanvas->clipPath(*path.platformPath(), SkRegion::kDifference_Op); } -void PlatformGraphicsContextSkia::clipPath(const Path& pathToClip, WindRule clipRule) +bool PlatformGraphicsContextSkia::clipPath(const Path& pathToClip, WindRule clipRule) { SkPath path = *pathToClip.platformPath(); path.setFillType(clipRule == RULE_EVENODD ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType); - mCanvas->clipPath(path); + return mCanvas->clipPath(path); } + void PlatformGraphicsContextSkia::clearRect(const FloatRect& rect) { SkPaint paint; diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.h b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.h index 724e20b..7bb12ae 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.h +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.h @@ -62,12 +62,12 @@ public: // Clipping virtual void addInnerRoundedRectClip(const IntRect& rect, int thickness); virtual void canvasClip(const Path& path); - virtual void clip(const FloatRect& rect); - virtual void clip(const Path& path); - virtual void clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias); - virtual void clipOut(const IntRect& r); - virtual void clipOut(const Path& p); - virtual void clipPath(const Path& pathToClip, WindRule clipRule); + virtual bool clip(const FloatRect& rect); + virtual bool clip(const Path& path); + virtual bool clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias); + virtual bool clipOut(const IntRect& r); + virtual bool clipOut(const Path& p); + virtual bool clipPath(const Path& pathToClip, WindRule clipRule); // Drawing virtual void clearRect(const FloatRect& rect); -- cgit v1.1