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

Unified Diff: third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.h

Issue 1710633002: Pull up a subset of CanvasRenderingContext2D into BaseRenderingContext2D. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: now with moar copy detection. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.h
diff --git a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.h b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.h
similarity index 47%
copy from third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.h
copy to third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.h
index b67c24ce329e3078e987ae471f9e275cae29a656..01322b8010376c38d15f21c57ceb70e0a570eaf8 100644
--- a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.h
+++ b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.h
@@ -1,87 +1,31 @@
-/*
- * Copyright (C) 2006, 2007, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 CanvasRenderingContext2D_h
-#define CanvasRenderingContext2D_h
-
-#include "bindings/core/v8/ScriptWrappable.h"
+// Copyright 2016 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 BaseRenderingContext2D_h
+#define BaseRenderingContext2D_h
+
+#include "bindings/core/v8/UnionTypesCore.h"
#include "bindings/modules/v8/UnionTypesModules.h"
-#include "core/html/canvas/CanvasContextCreationAttributes.h"
#include "core/html/canvas/CanvasRenderingContext.h"
-#include "core/html/canvas/CanvasRenderingContextFactory.h"
-#include "core/svg/SVGResourceClient.h"
#include "modules/ModulesExport.h"
-#include "modules/canvas2d/Canvas2DContextAttributes.h"
#include "modules/canvas2d/CanvasPathMethods.h"
#include "modules/canvas2d/CanvasRenderingContext2DState.h"
-#include "platform/graphics/GraphicsTypes.h"
-#include "platform/heap/GarbageCollected.h"
-#include "public/platform/WebThread.h"
-#include "wtf/Vector.h"
-#include "wtf/text/WTFString.h"
-
-namespace blink { class WebLayer; }
namespace blink {
class CanvasImageSource;
-class Element;
-class ExceptionState;
-class FloatRect;
-class FloatSize;
-class Font;
-class FontMetrics;
-class HitRegion;
-class HitRegionOptions;
-class HitRegionManager;
-class ImageData;
+class Color;
+class Image;
+class ImageBuffer;
class Path2D;
class SVGMatrixTearOff;
-class TextMetrics;
typedef HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrImageBitmap CanvasImageSourceUnion;
-class MODULES_EXPORT CanvasRenderingContext2D final : public CanvasRenderingContext, public CanvasPathMethods, public WebThread::TaskObserver, public SVGResourceClient {
- DEFINE_WRAPPERTYPEINFO();
- USING_PRE_FINALIZER(CanvasRenderingContext2D, dispose);
+class MODULES_EXPORT BaseRenderingContext2D : public WillBeGarbageCollectedMixin, public CanvasPathMethods {
public:
- class Factory : public CanvasRenderingContextFactory {
- WTF_MAKE_NONCOPYABLE(Factory);
- public:
- Factory() {}
- ~Factory() override {}
-
- PassOwnPtrWillBeRawPtr<CanvasRenderingContext> create(HTMLCanvasElement* canvas, const CanvasContextCreationAttributes& attrs, Document& document) override
- {
- return adoptPtrWillBeNoop(new CanvasRenderingContext2D(canvas, attrs, document));
- }
- CanvasRenderingContext::ContextType contextType() const override { return CanvasRenderingContext::Context2d; }
- void onError(HTMLCanvasElement*, const String& error) override { }
- };
-
- ~CanvasRenderingContext2D() override;
+ ~BaseRenderingContext2D() override;
void strokeStyle(StringOrCanvasGradientOrCanvasPattern&) const;
void setStrokeStyle(const StringOrCanvasGradientOrCanvasPattern&);
@@ -122,11 +66,6 @@ public:
double globalAlpha() const;
void setGlobalAlpha(double);
- bool isContextLost() const override;
-
- bool shouldAntialias() const;
- void setShouldAntialias(bool) override;
-
String globalCompositeOperation() const;
void setGlobalCompositeOperation(const String&);
@@ -160,10 +99,7 @@ public:
bool isPointInStroke(const double x, const double y);
bool isPointInStroke(Path2D*, const double x, const double y);
- void scrollPathIntoView();
- void scrollPathIntoView(Path2D*);
-
- void clearRect(double x, double y, double width, double height) override;
+ void clearRect(double x, double y, double width, double height);
void fillRect(double x, double y, double width, double height);
void strokeRect(double x, double y, double width, double height);
@@ -182,83 +118,67 @@ public:
void putImageData(ImageData*, double dx, double dy, ExceptionState&);
void putImageData(ImageData*, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight, ExceptionState&);
- void reset() override;
-
- String font() const;
- void setFont(const String&) override;
-
- String textAlign() const;
- void setTextAlign(const String&);
-
- String textBaseline() const;
- void setTextBaseline(const String&);
-
- String direction() const;
- void setDirection(const String&);
-
- void fillText(const String& text, double x, double y);
- void fillText(const String& text, double x, double y, double maxWidth);
- void strokeText(const String& text, double x, double y);
- void strokeText(const String& text, double x, double y, double maxWidth);
- TextMetrics* measureText(const String& text);
-
bool imageSmoothingEnabled() const;
void setImageSmoothingEnabled(bool);
String imageSmoothingQuality() const;
void setImageSmoothingQuality(const String&);
- void getContextAttributes(Canvas2DContextAttributes&) const;
+ virtual bool originClean() const = 0;
+ virtual void setOriginTainted() = 0;
+ virtual bool wouldTaintOrigin(CanvasImageSource*) = 0;
- void drawFocusIfNeeded(Element*);
- void drawFocusIfNeeded(Path2D*, Element*);
+ virtual int width() const = 0;
+ virtual int height() const = 0;
- void addHitRegion(const HitRegionOptions&, ExceptionState&);
- void removeHitRegion(const String& id);
- void clearHitRegions();
- HitRegion* hitRegionAtPoint(const FloatPoint&);
- unsigned hitRegionsCount() const override;
+ virtual bool hasImageBuffer() const = 0;
+ virtual ImageBuffer* imageBuffer() const = 0;
- void loseContext(LostContextMode) override;
- void didSetSurfaceSize() override;
+ virtual bool parseColorOrCurrentColor(Color&, const String& colorString) const = 0;
- void restoreCanvasMatrixClipStack(SkCanvas*) const override;
+ virtual SkCanvas* drawingCanvas() const = 0;
+ virtual SkCanvas* existingDrawingCanvas() const = 0;
+ virtual void disableDeferral(DisableDeferralReason) = 0;
- // TaskObserver implementation
- void didProcessTask() override;
- void willProcessTask() override { }
+ virtual AffineTransform baseTransform() const = 0;
- void styleDidChange(const ComputedStyle* oldStyle, const ComputedStyle& newStyle) override;
+ virtual void didDraw(const SkIRect& dirtyRect) = 0;
- // SVGResourceClient implementation
- void filterNeedsInvalidation() override;
+ virtual bool stateHasFilter() = 0;
+ virtual SkImageFilter* stateGetFilter() = 0;
-private:
- friend class CanvasRenderingContext2DAutoRestoreSkCanvas;
+ virtual void validateStateStack() = 0;
- CanvasRenderingContext2D(HTMLCanvasElement*, const CanvasContextCreationAttributes& attrs, Document&);
+ virtual bool hasAlpha() const = 0;
- void dispose();
+ virtual bool isContextLost() const = 0;
- CanvasRenderingContext2DState& modifiableState();
- const CanvasRenderingContext2DState& state() const { return *m_stateStack.last(); }
+ DECLARE_VIRTUAL_TRACE();
- void setShadow(const FloatSize& offset, double blur, RGBA32 color);
+protected:
+ BaseRenderingContext2D();
- void dispatchContextLostEvent(Timer<CanvasRenderingContext2D>*);
- void dispatchContextRestoredEvent(Timer<CanvasRenderingContext2D>*);
- void tryRestoreContextEvent(Timer<CanvasRenderingContext2D>*);
+ CanvasRenderingContext2DState& modifiableState();
+ const CanvasRenderingContext2DState& state() const { return *m_stateStack.last(); }
bool computeDirtyRect(const FloatRect& localBounds, SkIRect*);
bool computeDirtyRect(const FloatRect& localBounds, const SkIRect& transformedClipBounds, SkIRect*);
- void didDraw(const SkIRect&);
- SkCanvas* drawingCanvas() const;
+ void drawForText(const Font&, const TextRunPaintInfo&, const FloatPoint& location, CanvasRenderingContext2DState::PaintType);
- void unwindStateStack();
- void realizeSaves();
+ void inflateStrokeRect(FloatRect&) const;
+
+ enum DrawType {
+ ClipFill, // Fill that is already known to cover the current clip
+ UntransformedUnclippedFill
+ };
+
+ void checkOverdraw(const SkRect&, const SkPaint*, CanvasRenderingContext2DState::ImageType, DrawType);
+
+ WillBeHeapVector<OwnPtrWillBeMember<CanvasRenderingContext2DState>> m_stateStack;
+ AntiAliasingMode m_clipAntialiasing;
- void pruneLocalFontCache(size_t targetSize);
- void schedulePruneLocalFontCacheIfNeeded();
+private:
+ void realizeSaves();
bool shouldDrawImageAntialiased(const FloatRect& destRect) const;
@@ -271,65 +191,13 @@ private:
bool isPointInPathInternal(const Path&, const double x, const double y, const String& windingRuleString);
bool isPointInStrokeInternal(const Path&, const double x, const double y);
- void scrollPathIntoViewInternal(const Path&);
-
- void drawTextInternal(const String&, double x, double y, CanvasRenderingContext2DState::PaintType, double* maxWidth = nullptr);
-
- const Font& accessFont();
- int getFontBaseline(const FontMetrics&) const;
-
- void clearCanvas();
- bool rectContainsTransformedRect(const FloatRect&, const SkIRect&) const;
-
- void inflateStrokeRect(FloatRect&) const;
-
template<typename DrawFunc>
void compositedDraw(const DrawFunc&, SkCanvas*, CanvasRenderingContext2DState::PaintType, CanvasRenderingContext2DState::ImageType);
- void drawFocusIfNeededInternal(const Path&, Element*);
- bool focusRingCallIsValid(const Path&, Element*);
- void drawFocusRing(const Path&);
- void updateElementAccessibility(const Path&, Element*);
-
- void validateStateStack();
-
- enum DrawType {
- ClipFill, // Fill that is already known to cover the current clip
- UntransformedUnclippedFill
- };
-
- void checkOverdraw(const SkRect&, const SkPaint*, CanvasRenderingContext2DState::ImageType, DrawType);
-
- CanvasRenderingContext::ContextType contextType() const override { return CanvasRenderingContext::Context2d; }
- bool is2d() const override { return true; }
- bool isAccelerated() const override;
- bool hasAlpha() const override { return m_hasAlpha; }
- void setIsHidden(bool) override;
- void stop() final;
- DECLARE_VIRTUAL_TRACE();
-
- virtual bool isTransformInvertible() const;
-
- WebLayer* platformLayer() const override;
-
- WillBeHeapVector<OwnPtrWillBeMember<CanvasRenderingContext2DState>> m_stateStack;
- PersistentWillBeMember<HitRegionManager> m_hitRegionManager;
- AntiAliasingMode m_clipAntialiasing;
- bool m_hasAlpha;
- LostContextMode m_contextLostMode;
- bool m_contextRestorable;
- unsigned m_tryRestoreContextAttemptCount;
- Timer<CanvasRenderingContext2D> m_dispatchContextLostEventTimer;
- Timer<CanvasRenderingContext2D> m_dispatchContextRestoredEventTimer;
- Timer<CanvasRenderingContext2D> m_tryRestoreContextEventTimer;
-
- HashMap<String, Font> m_fontsResolvedUsingCurrentStyle;
- bool m_pruneLocalFontCacheScheduled;
- ListHashSet<String> m_fontLRUList;
+ void clearCanvas();
+ bool rectContainsTransformedRect(const FloatRect&, const SkIRect&) const;
};
-DEFINE_TYPE_CASTS(CanvasRenderingContext2D, CanvasRenderingContext, context, context->is2d(), context.is2d());
-
} // namespace blink
-#endif // CanvasRenderingContext2D_h
+#endif // BaseRenderingContext2D_h

Powered by Google App Engine
This is Rietveld 408576698