From 81233b6df93975e5c606ac9f228d29f00561d4a4 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 19 Mar 2015 16:00:21 -0700 Subject: [PATCH] Add a basic custom painting facility to Sky This CL adds just enough custom painting to Sky to make sky/examples/painting/circle.sky draw a circle. Over time, we should be able to elaborate this system into something interesting and to make it actually work in a reasonable way. R=ojan@chromium.org Review URL: https://codereview.chromium.org/1017593005 --- .../scripts/dart_callback_interface.py | 5 ++ engine/bindings/scripts/dart_types.py | 2 +- .../callback_interface_dart.template | 2 +- engine/core/core.gni | 3 + engine/core/dom/Element.cpp | 36 +++++++++ engine/core/dom/Element.h | 3 + engine/core/dom/Element.idl | 2 + engine/core/painting/Paint.h | 2 +- engine/core/painting/PaintingCallback.cpp | 14 ++++ engine/core/painting/PaintingCallback.h | 19 +++++ engine/core/painting/PaintingCallback.idl | 7 ++ engine/core/painting/PaintingContext.cpp | 13 +++- engine/core/painting/PaintingContext.h | 22 +++++- engine/core/painting/PaintingContext.idl | 1 - engine/core/rendering/RenderBox.cpp | 6 ++ engine/core/rendering/RenderBox.h | 3 + engine/platform/graphics/DisplayList.cpp | 8 +- engine/platform/graphics/DisplayList.h | 5 +- engine/platform/graphics/GraphicsContext.cpp | 77 ++---------------- engine/platform/graphics/GraphicsContext.h | 14 +--- .../platform/graphics/GraphicsContextTest.cpp | 78 ------------------- .../graphics/filters/SourceGraphic.cpp | 10 +-- .../platform/graphics/filters/SourceGraphic.h | 5 +- examples/painting/circle.sky | 24 ++++++ 24 files changed, 164 insertions(+), 197 deletions(-) create mode 100644 engine/core/painting/PaintingCallback.cpp create mode 100644 engine/core/painting/PaintingCallback.h create mode 100644 engine/core/painting/PaintingCallback.idl create mode 100644 examples/painting/circle.sky diff --git a/engine/bindings/scripts/dart_callback_interface.py b/engine/bindings/scripts/dart_callback_interface.py index 8ec81032a..99f2ad625 100644 --- a/engine/bindings/scripts/dart_callback_interface.py +++ b/engine/bindings/scripts/dart_callback_interface.py @@ -124,7 +124,12 @@ def generate_arguments_contents(arguments, call_with_this_handle): for argument in arguments] if call_with_this_handle: argument_declarations.insert(0, 'ScriptValue thisValue') + + dart_argument_declarations = [ + '%s %s' % (dart_types.idl_type_to_dart_type(argument.idl_type), argument.name) + for argument in arguments] return { 'argument_declarations': argument_declarations, + 'dart_argument_declarations': dart_argument_declarations, 'arguments': [generate_argument(argument) for argument in arguments], } diff --git a/engine/bindings/scripts/dart_types.py b/engine/bindings/scripts/dart_types.py index c58ad59e6..83335aa40 100644 --- a/engine/bindings/scripts/dart_types.py +++ b/engine/bindings/scripts/dart_types.py @@ -718,7 +718,7 @@ CPP_VALUE_TO_DART_VALUE = { 'DartValue': 'DartConverter::ToDart({cpp_value})', # General 'array': 'VectorToDart({cpp_value})', - 'DOMWrapper': 'Dart{idl_type}::toDart({cpp_value})', + 'DOMWrapper': 'DartConverter<{idl_type}*>::ToDart({cpp_value})', } diff --git a/engine/bindings/scripts/templates/callback_interface_dart.template b/engine/bindings/scripts/templates/callback_interface_dart.template index dab95f7ef..4e122bdfb 100644 --- a/engine/bindings/scripts/templates/callback_interface_dart.template +++ b/engine/bindings/scripts/templates/callback_interface_dart.template @@ -5,4 +5,4 @@ // WARNING: Do not edit - generated code. part of dart.sky; -typedef void {{cpp_class}}({{methods[0].argument_declarations | join(', ')}}); \ No newline at end of file +typedef void {{cpp_class}}({{methods[0].dart_argument_declarations | join(', ')}}); \ No newline at end of file diff --git a/engine/core/core.gni b/engine/core/core.gni index b3bf1edfd..97fa2f969 100644 --- a/engine/core/core.gni +++ b/engine/core/core.gni @@ -942,6 +942,8 @@ sky_core_files = [ "page/SpellCheckerClient.h", "painting/Paint.cpp", "painting/Paint.h", + "painting/PaintingCallback.cpp", + "painting/PaintingCallback.h", "painting/PaintingContext.cpp", "painting/PaintingContext.h", "rendering/BidiRun.h", @@ -1239,6 +1241,7 @@ core_idl_files = get_path_info([ "html/TextMetrics.idl", "html/VoidCallback.idl", "painting/Paint.idl", + "painting/PaintingCallback.idl", "painting/PaintingContext.idl", ], "abspath") diff --git a/engine/core/dom/Element.cpp b/engine/core/dom/Element.cpp index 78d958c9d..7f5c889f4 100644 --- a/engine/core/dom/Element.cpp +++ b/engine/core/dom/Element.cpp @@ -26,6 +26,7 @@ #include "sky/engine/config.h" #include "sky/engine/core/dom/Element.h" +#include "base/bind.h" #include "gen/sky/core/CSSValueKeywords.h" #include "gen/sky/core/HTMLNames.h" #include "gen/sky/platform/RuntimeEnabledFeatures.h" @@ -49,6 +50,7 @@ #include "sky/engine/core/dom/ElementRareData.h" #include "sky/engine/core/dom/ElementTraversal.h" #include "sky/engine/core/dom/ExceptionCode.h" +#include "sky/engine/core/dom/Microtask.h" #include "sky/engine/core/dom/MutationObserverInterestGroup.h" #include "sky/engine/core/dom/MutationRecord.h" #include "sky/engine/core/dom/NodeRenderStyle.h" @@ -75,6 +77,8 @@ #include "sky/engine/core/page/ChromeClient.h" #include "sky/engine/core/page/FocusController.h" #include "sky/engine/core/page/Page.h" +#include "sky/engine/core/painting/PaintingContext.h" +#include "sky/engine/core/painting/PaintingCallback.h" #include "sky/engine/core/rendering/RenderLayer.h" #include "sky/engine/core/rendering/RenderView.h" #include "sky/engine/platform/EventDispatchForbiddenScope.h" @@ -413,6 +417,38 @@ PassRefPtr Element::getBoundingClientRect() return ClientRect::create(result); } +// TODO(abarth): We should schedule this work at a more reasonable time. +static void handlePaintingCommit(RefPtr element, RefPtr context) +{ + if (!element->document().isActive()) + return; + element->document().updateLayout(); + RenderObject* renderer = element->renderer(); + if (!renderer || !renderer->isBox()) + return; + toRenderBox(renderer)->setCustomPainting(context->takeDisplayList()); + element->document().scheduleVisualUpdate(); +} + +// TODO(abarth): We should schedule this work at a more reasonable time. +static void runPaintingCallback(RefPtr element, PassOwnPtr callback) +{ + if (!element->document().isActive()) + return; + element->document().updateLayout(); + RenderObject* renderer = element->renderer(); + if (!renderer || !renderer->isBox()) + return; + RefPtr context = PaintingContext::create( + toRenderBox(renderer)->size(), base::Bind(&handlePaintingCommit, element)); + callback->handleEvent(context.get()); +} + +void Element::requestPaint(PassOwnPtr callback) +{ + Microtask::enqueueMicrotask(base::Bind(&runPaintingCallback, this, callback)); +} + void Element::setAttribute(const AtomicString& localName, const AtomicString& value, ExceptionState& exceptionState) { if (!Document::isValidName(localName)) { diff --git a/engine/core/dom/Element.h b/engine/core/dom/Element.h index 06fb806f0..5772343bd 100644 --- a/engine/core/dom/Element.h +++ b/engine/core/dom/Element.h @@ -51,6 +51,7 @@ class ExceptionState; class Image; class IntSize; class MutableStylePropertySet; +class PaintingCallback; class PropertySetCSSStyleDeclaration; class PseudoElement; class ShadowRoot; @@ -126,6 +127,8 @@ public: PassRefPtr getClientRects(); PassRefPtr getBoundingClientRect(); + void requestPaint(PassOwnPtr); + virtual void didMoveToNewDocument(Document&) override; CSSStyleDeclaration* style(); diff --git a/engine/core/dom/Element.idl b/engine/core/dom/Element.idl index 9bf63f373..26f30ee88 100644 --- a/engine/core/dom/Element.idl +++ b/engine/core/dom/Element.idl @@ -16,6 +16,8 @@ readonly attribute ShadowRoot shadowRoot; + void requestPaint(PaintingCallback callback); + // TODO(abarth): Move to Node. readonly attribute CSSStyleDeclaration style; diff --git a/engine/core/painting/Paint.h b/engine/core/painting/Paint.h index 58794fcb2..a592623c0 100644 --- a/engine/core/painting/Paint.h +++ b/engine/core/painting/Paint.h @@ -29,7 +29,7 @@ public: void setARGB(unsigned a, unsigned r, unsigned g, unsigned b) { - m_paint.setARGB(r, g, b, a); + m_paint.setARGB(a, r, g, b); } const SkPaint& paint() const { return m_paint; } diff --git a/engine/core/painting/PaintingCallback.cpp b/engine/core/painting/PaintingCallback.cpp new file mode 100644 index 000000000..ef8da9ac8 --- /dev/null +++ b/engine/core/painting/PaintingCallback.cpp @@ -0,0 +1,14 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sky/engine/config.h" +#include "sky/engine/core/painting/PaintingCallback.h" + +namespace blink { + +PaintingCallback::~PaintingCallback() +{ +} + +} // namespace blink diff --git a/engine/core/painting/PaintingCallback.h b/engine/core/painting/PaintingCallback.h new file mode 100644 index 000000000..7a5d77f55 --- /dev/null +++ b/engine/core/painting/PaintingCallback.h @@ -0,0 +1,19 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SKY_ENGINE_CORE_PAINTING_PAINTINGCALLBACK_H_ +#define SKY_ENGINE_CORE_PAINTING_PAINTINGCALLBACK_H_ + +namespace blink { +class PaintingContext; + +class PaintingCallback { +public: + virtual ~PaintingCallback(); + virtual void handleEvent(PaintingContext* context) = 0; +}; + +} // namespace blink + +#endif // SKY_ENGINE_CORE_PAINTING_PAINTINGCALLBACK_H_ diff --git a/engine/core/painting/PaintingCallback.idl b/engine/core/painting/PaintingCallback.idl new file mode 100644 index 000000000..7bc7c20b1 --- /dev/null +++ b/engine/core/painting/PaintingCallback.idl @@ -0,0 +1,7 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +callback interface PaintingCallback { + void handleEvent(PaintingContext context); +}; diff --git a/engine/core/painting/PaintingContext.cpp b/engine/core/painting/PaintingContext.cpp index ccd785a8b..f31484580 100644 --- a/engine/core/painting/PaintingContext.cpp +++ b/engine/core/painting/PaintingContext.cpp @@ -5,15 +5,19 @@ #include "sky/engine/config.h" #include "sky/engine/core/painting/PaintingContext.h" +#include "base/bind.h" +#include "sky/engine/core/dom/Microtask.h" #include "sky/engine/platform/geometry/IntRect.h" #include "third_party/skia/include/core/SkCanvas.h" namespace blink { -PaintingContext::PaintingContext(const FloatRect& bounds) +PaintingContext::PaintingContext(const FloatSize& size, const CommitCallback& commitCallback) + : m_size(size) + , m_commitCallback(commitCallback) { - m_displayList = adoptRef(new DisplayList(bounds)); - m_canvas = m_displayList->beginRecording(enclosingIntRect(bounds).size()); + m_displayList = adoptRef(new DisplayList); + m_canvas = m_displayList->beginRecording(expandedIntSize(size)); } PaintingContext::~PaintingContext() @@ -31,8 +35,11 @@ void PaintingContext::drawCircle(double x, double y, double radius, Paint* paint void PaintingContext::commit() { + if (!m_canvas) + return; m_displayList->endRecording(); m_canvas = nullptr; + Microtask::enqueueMicrotask(base::Bind(m_commitCallback, this)); } } // namespace blink diff --git a/engine/core/painting/PaintingContext.h b/engine/core/painting/PaintingContext.h index 6d33eab1c..084724e53 100644 --- a/engine/core/painting/PaintingContext.h +++ b/engine/core/painting/PaintingContext.h @@ -5,6 +5,7 @@ #ifndef SKY_ENGINE_CORE_PAINTING_PAINTINGCONTEXT_H_ #define SKY_ENGINE_CORE_PAINTING_PAINTINGCONTEXT_H_ +#include "base/callback.h" #include "sky/engine/core/painting/Paint.h" #include "sky/engine/platform/graphics/DisplayList.h" #include "sky/engine/tonic/dart_wrappable.h" @@ -16,18 +17,31 @@ namespace blink { class PaintingContext : public RefCounted, public DartWrappable { DEFINE_WRAPPERTYPEINFO(); public: + typedef base::Callback)> CommitCallback; + ~PaintingContext() override; - PassRefPtr create(const FloatRect& bounds) { return adoptRef(new PaintingContext(bounds)); } + static PassRefPtr create(const FloatSize& size, const CommitCallback& commitCallback) + { + return adoptRef(new PaintingContext(size, commitCallback)); + } - double height() const { return m_displayList->bounds().height(); } - double width() const { return m_displayList->bounds().width(); } + double height() const { return m_size.height(); } + double width() const { return m_size.width(); } void drawCircle(double x, double y, double radius, Paint* paint); void commit(); + PassRefPtr takeDisplayList() + { + ASSERT(!m_canvas); + return m_displayList.release(); + } + private: - PaintingContext(const FloatRect& bounds); + PaintingContext(const FloatSize& size, const CommitCallback& commitCallback); + FloatSize m_size; + CommitCallback m_commitCallback; RefPtr m_displayList; SkCanvas* m_canvas; }; diff --git a/engine/core/painting/PaintingContext.idl b/engine/core/painting/PaintingContext.idl index 586850069..8eec203b5 100644 --- a/engine/core/painting/PaintingContext.idl +++ b/engine/core/painting/PaintingContext.idl @@ -7,6 +7,5 @@ interface PaintingContext { readonly attribute double width; void drawCircle(double x, double y, double radius, Paint paint); - void commit(); }; diff --git a/engine/core/rendering/RenderBox.cpp b/engine/core/rendering/RenderBox.cpp index c0ab2dc08..c98659947 100644 --- a/engine/core/rendering/RenderBox.cpp +++ b/engine/core/rendering/RenderBox.cpp @@ -989,6 +989,12 @@ void RenderBox::paintBoxDecorationBackground(PaintInfo& paintInfo, const LayoutP LayoutRect paintRect = borderBoxRect(); paintRect.moveBy(paintOffset); paintBoxDecorationBackgroundWithRect(paintInfo, paintOffset, paintRect); + // TODO(abarth): Currently we only draw m_customPainting if we happen to + // have a box decoration or a background. Instead, we should probably have + // another function like paintBoxDecorationBackground that subclasses can + // call to draw m_customPainting. + if (m_customPainting) + paintInfo.context->drawDisplayList(m_customPainting.get(), paintRect.location()); } void RenderBox::paintBoxDecorationBackgroundWithRect(PaintInfo& paintInfo, const LayoutPoint& paintOffset, const LayoutRect& paintRect) diff --git a/engine/core/rendering/RenderBox.h b/engine/core/rendering/RenderBox.h index f83578c03..164571212 100644 --- a/engine/core/rendering/RenderBox.h +++ b/engine/core/rendering/RenderBox.h @@ -450,6 +450,8 @@ public: bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); } + void setCustomPainting(PassRefPtr customPainting) { m_customPainting = customPainting; } + protected: virtual void willBeDestroyed() override; @@ -569,6 +571,7 @@ protected: OwnPtr m_transform; private: + RefPtr m_customPainting; OwnPtr m_layer; OwnPtr m_rareData; }; diff --git a/engine/platform/graphics/DisplayList.cpp b/engine/platform/graphics/DisplayList.cpp index 360939662..87f6b1dc3 100644 --- a/engine/platform/graphics/DisplayList.cpp +++ b/engine/platform/graphics/DisplayList.cpp @@ -38,8 +38,7 @@ namespace blink { -DisplayList::DisplayList(const FloatRect& bounds) - : m_bounds(bounds) +DisplayList::DisplayList() { } @@ -47,11 +46,6 @@ DisplayList::~DisplayList() { } -const FloatRect& DisplayList::bounds() const -{ - return m_bounds; -} - SkPicture* DisplayList::picture() const { return m_picture.get(); diff --git a/engine/platform/graphics/DisplayList.h b/engine/platform/graphics/DisplayList.h index 4161a3e6b..fcf13ff0e 100644 --- a/engine/platform/graphics/DisplayList.h +++ b/engine/platform/graphics/DisplayList.h @@ -49,11 +49,9 @@ class PLATFORM_EXPORT DisplayList final : public WTF::RefCounted { WTF_MAKE_FAST_ALLOCATED; WTF_MAKE_NONCOPYABLE(DisplayList); public: - DisplayList(const FloatRect&); + DisplayList(); ~DisplayList(); - const FloatRect& bounds() const; - // This entry point will return 0 when the DisplayList is in the // midst of recording (i.e., between a beginRecording/endRecording pair) // and if no recording has ever been completed. Otherwise it will return @@ -65,7 +63,6 @@ public: void endRecording(); private: - FloatRect m_bounds; RefPtr m_picture; OwnPtr m_recorder; }; diff --git a/engine/platform/graphics/GraphicsContext.cpp b/engine/platform/graphics/GraphicsContext.cpp index 6765a71c9..92d3f5c03 100644 --- a/engine/platform/graphics/GraphicsContext.cpp +++ b/engine/platform/graphics/GraphicsContext.cpp @@ -98,19 +98,6 @@ struct GraphicsContext::CanvasSaveState { int m_restoreCount; }; -struct GraphicsContext::RecordingState { - RecordingState(SkCanvas* currentCanvas, const SkMatrix& currentMatrix, PassRefPtr displayList) - : m_savedCanvas(currentCanvas) - , m_displayList(displayList) - , m_savedMatrix(currentMatrix) - { - } - - SkCanvas* m_savedCanvas; - RefPtr m_displayList; - const SkMatrix m_savedMatrix; -}; - GraphicsContext::GraphicsContext(SkCanvas* canvas, DisabledMode disableContextOrPainting) : m_canvas(canvas) , m_paintStateStack() @@ -144,7 +131,6 @@ GraphicsContext::~GraphicsContext() ASSERT(!m_paintStateIndex); ASSERT(!m_paintState->saveCount()); ASSERT(!m_layerCount); - ASSERT(m_recordingStateStack.isEmpty()); ASSERT(m_canvasStateStack.isEmpty()); } #endif @@ -332,14 +318,7 @@ SkMatrix GraphicsContext::getTotalMatrix() const if (contextDisabled()) return SkMatrix::I(); - if (!isRecording()) - return m_canvas->getTotalMatrix(); - - const RecordingState& recordingState = m_recordingStateStack.last(); - SkMatrix totalMatrix = recordingState.m_savedMatrix; - totalMatrix.preConcat(m_canvas->getTotalMatrix()); - - return totalMatrix; + return m_canvas->getTotalMatrix(); } void GraphicsContext::adjustTextRenderMode(SkPaint* paint) @@ -447,64 +426,18 @@ void GraphicsContext::endLayer() #endif } -void GraphicsContext::beginRecording(const FloatRect& bounds) -{ - RefPtr displayList = adoptRef(new DisplayList(bounds)); - - SkCanvas* savedCanvas = m_canvas; - SkMatrix savedMatrix = getTotalMatrix(); - - if (!contextDisabled()) { - IntRect recordingRect = enclosingIntRect(bounds); - m_canvas = displayList->beginRecording(recordingRect.size()); - - // We want the bounds offset mapped to (0, 0), such that the display list content - // is fully contained within the SkPictureRecord's bounds. - if (!toFloatSize(bounds.location()).isZero()) { - m_canvas->translate(-bounds.x(), -bounds.y()); - // To avoid applying the offset repeatedly in getTotalMatrix(), we pre-apply it here. - savedMatrix.preTranslate(bounds.x(), bounds.y()); - } - } - - m_recordingStateStack.append(RecordingState(savedCanvas, savedMatrix, displayList)); -} - -PassRefPtr GraphicsContext::endRecording() -{ - ASSERT(!m_recordingStateStack.isEmpty()); - - RecordingState recording = m_recordingStateStack.last(); - if (!contextDisabled()) { - ASSERT(recording.m_displayList->isRecording()); - recording.m_displayList->endRecording(); - } - - m_recordingStateStack.removeLast(); - m_canvas = recording.m_savedCanvas; - - return recording.m_displayList.release(); -} - -bool GraphicsContext::isRecording() const -{ - return !m_recordingStateStack.isEmpty(); -} - -void GraphicsContext::drawDisplayList(DisplayList* displayList) +void GraphicsContext::drawDisplayList(DisplayList* displayList, const FloatPoint& point) { ASSERT(displayList); - ASSERT(!displayList->isRecording()); - if (contextDisabled() || displayList->bounds().isEmpty()) + if (contextDisabled()) return; realizeCanvasSave(); - const FloatRect& bounds = displayList->bounds(); - if (bounds.x() || bounds.y()) { + if (point.x() || point.y()) { SkMatrix m; - m.setTranslate(bounds.x(), bounds.y()); + m.setTranslate(point.x(), point.y()); m_canvas->drawPicture(displayList->picture(), &m, 0); } else { m_canvas->drawPicture(displayList->picture()); diff --git a/engine/platform/graphics/GraphicsContext.h b/engine/platform/graphics/GraphicsContext.h index 8afe366c1..5f1d5a864 100644 --- a/engine/platform/graphics/GraphicsContext.h +++ b/engine/platform/graphics/GraphicsContext.h @@ -155,7 +155,7 @@ public: // rotations of thin ("hairline") images. // Note: This will only be reliable when the device pixel scale/ratio is // fixed (e.g. when drawing to context backed by an ImageBuffer). - void disableAntialiasingOptimizationForHairlineImages() { ASSERT(!isRecording()); m_antialiasHairlineImages = true; } + void disableAntialiasingOptimizationForHairlineImages() { m_antialiasHairlineImages = true; } bool shouldAntialiasHairlineImages() const { return m_antialiasHairlineImages; } void setShouldClampToSourceRect(bool clampToSourceRect) { mutableState()->setShouldClampToSourceRect(clampToSourceRect); } @@ -258,7 +258,7 @@ public: const IntRect&, const IntSize& innerTopLeft, const IntSize& innerTopRight, const IntSize& innerBottomLeft, const IntSize& innerBottomRight, const Color&); void fillBetweenRoundedRects(const RoundedRect&, const RoundedRect&, const Color&); - void drawDisplayList(DisplayList*); + void drawDisplayList(DisplayList*, const FloatPoint&); void drawImage(Image*, const IntPoint&, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation); void drawImage(Image*, const IntRect&, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation); @@ -319,11 +319,6 @@ public: void beginLayer(float opacity, CompositeOperator, const FloatRect* = 0, ColorFilter = ColorFilterNone, ImageFilter* = 0); void endLayer(); - // Instead of being dispatched to the active canvas, draw commands following beginRecording() - // are stored in a display list that can be replayed at a later time. - void beginRecording(const FloatRect& bounds); - PassRefPtr endRecording(); - bool hasShadow() const; void setShadow(const FloatSize& offset, float blur, const Color&, DrawLooperBuilder::ShadowTransformMode = DrawLooperBuilder::ShadowRespectsTransforms, @@ -466,8 +461,6 @@ private: void fillRectWithRoundedHole(const IntRect&, const RoundedRect& roundedHoleRect, const Color&); - bool isRecording() const; - // null indicates painting is contextDisabled. Never delete this object. SkCanvas* m_canvas; @@ -487,9 +480,6 @@ private: Vector m_canvasStateStack; bool m_pendingCanvasSave; - struct RecordingState; - Vector m_recordingStateStack; - #if ENABLE(ASSERT) unsigned m_layerCount; bool m_disableDestructionChecks; diff --git a/engine/platform/graphics/GraphicsContextTest.cpp b/engine/platform/graphics/GraphicsContextTest.cpp index f8f6c2580..0d99ea3cb 100644 --- a/engine/platform/graphics/GraphicsContextTest.cpp +++ b/engine/platform/graphics/GraphicsContextTest.cpp @@ -1117,82 +1117,4 @@ TEST(GraphicsContextTest, OpaqueRegionForLayerWithRectDeviceClip) EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); } -#define DISPATCH1(c1, c2, op, param1) do { c1.op(param1); c2.op(param1); } while (0); -#define DISPATCH2(c1, c2, op, param1, param2) do { c1.op(param1, param2); c2.op(param1, param2); } while (0); - -TEST(GraphicsContextTest, RecordingTotalMatrix) -{ - SkBitmap bitmap; - bitmap.allocN32Pixels(400, 400); - bitmap.eraseColor(0); - SkCanvas canvas(bitmap); - GraphicsContext context(&canvas); - - SkCanvas controlCanvas(400, 400); - GraphicsContext controlContext(&controlCanvas); - - EXPECT_EQ(context.getCTM(), controlContext.getCTM()); - DISPATCH2(context, controlContext, scale, 2, 2); - EXPECT_EQ(context.getCTM(), controlContext.getCTM()); - - controlContext.save(); - context.beginRecording(FloatRect(0, 0, 200, 200)); - DISPATCH2(context, controlContext, translate, 10, 10); - EXPECT_EQ(context.getCTM(), controlContext.getCTM()); - - controlContext.save(); - context.beginRecording(FloatRect(10, 10, 100, 100)); - DISPATCH1(context, controlContext, rotate, 45); - EXPECT_EQ(context.getCTM(), controlContext.getCTM()); - - controlContext.restore(); - context.endRecording(); - EXPECT_EQ(context.getCTM(), controlContext.getCTM()); - - controlContext.restore(); - context.endRecording(); - EXPECT_EQ(context.getCTM(), controlContext.getCTM()); -} - -TEST(GraphicsContextTest, DisplayList) -{ - FloatRect rect(0, 0, 1, 1); - RefPtr dl = adoptRef(new DisplayList(rect)); - - // picture() returns 0 initially - SkPicture* pic = dl->picture(); - EXPECT_FALSE(pic); - - // endRecording without a beginRecording does nothing - dl->endRecording(); - pic = dl->picture(); - EXPECT_FALSE(pic); - - // Two beginRecordings in a row generate two canvases. - // Unfortunately the new one could be allocated in the same - // spot as the old one so ref the first one to prolong its life. - IntSize size(1, 1); - SkCanvas* canvas1 = dl->beginRecording(size); - EXPECT_TRUE(canvas1); - canvas1->ref(); - SkCanvas* canvas2 = dl->beginRecording(size); - EXPECT_TRUE(canvas2); - - EXPECT_NE(canvas1, canvas2); - EXPECT_TRUE(canvas1->unique()); - canvas1->unref(); - - EXPECT_TRUE(dl->isRecording()); - - // picture() returns 0 during recording - pic = dl->picture(); - EXPECT_FALSE(pic); - - // endRecording finally makes the picture accessible - dl->endRecording(); - pic = dl->picture(); - EXPECT_TRUE(pic); - EXPECT_TRUE(pic->unique()); -} - } // namespace diff --git a/engine/platform/graphics/filters/SourceGraphic.cpp b/engine/platform/graphics/filters/SourceGraphic.cpp index de895463d..ff6dc9f16 100644 --- a/engine/platform/graphics/filters/SourceGraphic.cpp +++ b/engine/platform/graphics/filters/SourceGraphic.cpp @@ -63,17 +63,9 @@ void SourceGraphic::applySoftware() } } -void SourceGraphic::setDisplayList(PassRefPtr displayList) -{ - m_displayList = displayList; -} - PassRefPtr SourceGraphic::createImageFilter(SkiaImageFilterBuilder*) { - if (!m_displayList) - return nullptr; - - return adoptRef(SkPictureImageFilter::Create(m_displayList->picture(), m_displayList->bounds())); + return nullptr; } TextStream& SourceGraphic::externalRepresentation(TextStream& ts, int indent) const diff --git a/engine/platform/graphics/filters/SourceGraphic.h b/engine/platform/graphics/filters/SourceGraphic.h index e68b26d25..b60e326c4 100644 --- a/engine/platform/graphics/filters/SourceGraphic.h +++ b/engine/platform/graphics/filters/SourceGraphic.h @@ -41,9 +41,6 @@ public: virtual TextStream& externalRepresentation(TextStream&, int indention) const override; PassRefPtr createImageFilter(SkiaImageFilterBuilder*) override; - void setDisplayList(PassRefPtr); - - private: SourceGraphic(Filter* filter) : FilterEffect(filter) @@ -52,7 +49,7 @@ private: } virtual void applySoftware() override; - RefPtr m_displayList; + // TODO(sky): This class appears to be broken... }; } //namespace blink diff --git a/examples/painting/circle.sky b/examples/painting/circle.sky new file mode 100644 index 000000000..224e2d925 --- /dev/null +++ b/examples/painting/circle.sky @@ -0,0 +1,24 @@ + + +
+ + -- GitLab