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

Side by Side Diff: third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext.h

Issue 2212163002: Add some plumbing for the color management of canvases (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase again Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 10 matching lines...) Expand all
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef CanvasRenderingContext_h 26 #ifndef CanvasRenderingContext_h
27 #define CanvasRenderingContext_h 27 #define CanvasRenderingContext_h
28 28
29 #include "core/CoreExport.h" 29 #include "core/CoreExport.h"
30 #include "core/html/HTMLCanvasElement.h" 30 #include "core/html/HTMLCanvasElement.h"
31 #include "core/html/canvas/CanvasContextCreationAttributes.h"
31 #include "core/layout/HitTestCanvasResult.h" 32 #include "core/layout/HitTestCanvasResult.h"
32 #include "core/offscreencanvas/OffscreenCanvas.h" 33 #include "core/offscreencanvas/OffscreenCanvas.h"
34 #include "third_party/skia/include/core/SkColorSpace.h"
33 #include "wtf/HashSet.h" 35 #include "wtf/HashSet.h"
34 #include "wtf/Noncopyable.h" 36 #include "wtf/Noncopyable.h"
35 #include "wtf/text/StringHash.h" 37 #include "wtf/text/StringHash.h"
36 38
37 class SkCanvas; 39 class SkCanvas;
38 40
39 namespace blink { class WebLayer; }
40
41 namespace blink { 41 namespace blink {
42 42
43 class CanvasImageSource; 43 class CanvasImageSource;
44 class HTMLCanvasElement; 44 class HTMLCanvasElement;
45 class ImageData; 45 class ImageData;
46 class ImageBitmap; 46 class ImageBitmap;
47 class WebLayer;
48
49 enum CanvasColorSpace {
50 kLegacyCanvasColorSpace,
51 kSRGBCanvasColorSpace,
52 kLinearRGBCanvasColorSpace,
53 };
47 54
48 class CORE_EXPORT CanvasRenderingContext : public GarbageCollectedFinalized<Canv asRenderingContext>, public ScriptWrappable { 55 class CORE_EXPORT CanvasRenderingContext : public GarbageCollectedFinalized<Canv asRenderingContext>, public ScriptWrappable {
49 WTF_MAKE_NONCOPYABLE(CanvasRenderingContext); 56 WTF_MAKE_NONCOPYABLE(CanvasRenderingContext);
50 USING_PRE_FINALIZER(CanvasRenderingContext, dispose); 57 USING_PRE_FINALIZER(CanvasRenderingContext, dispose);
51 public: 58 public:
52 virtual ~CanvasRenderingContext() { } 59 virtual ~CanvasRenderingContext() { }
53 60
54 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2 D canvas and the existing 61 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2 D canvas and the existing
55 // context is already 2D, just return that. If the existing context is WebGL , then destroy it 62 // context is already 2D, just return that. If the existing context is WebGL , then destroy it
56 // before creating a new 2D context. Vice versa when requesting a WebGL canv as. Requesting a 63 // before creating a new 2D context. Vice versa when requesting a WebGL canv as. Requesting a
57 // context with any other type string will destroy any existing context. 64 // context with any other type string will destroy any existing context.
58 enum ContextType { 65 enum ContextType {
59 // Do not change assigned numbers of existing items: add new features to the end of the list. 66 // Do not change assigned numbers of existing items: add new features to the end of the list.
60 Context2d = 0, 67 Context2d = 0,
61 ContextExperimentalWebgl = 2, 68 ContextExperimentalWebgl = 2,
62 ContextWebgl = 3, 69 ContextWebgl = 3,
63 ContextWebgl2 = 4, 70 ContextWebgl2 = 4,
64 ContextImageBitmap = 5, 71 ContextImageBitmap = 5,
65 ContextTypeCount, 72 ContextTypeCount,
66 }; 73 };
67 74
68 static ContextType contextTypeFromId(const String& id); 75 static ContextType contextTypeFromId(const String& id);
69 static ContextType resolveContextTypeAliases(ContextType); 76 static ContextType resolveContextTypeAliases(ContextType);
70 77
71 HTMLCanvasElement* canvas() const { return m_canvas; } 78 HTMLCanvasElement* canvas() const { return m_canvas; }
72 79
80 CanvasColorSpace colorSpace() const { return m_colorSpace; };
81 WTF::String colorSpaceAsString() const;
82 sk_sp<SkColorSpace> skColorSpace() const;
83
73 virtual ContextType getContextType() const = 0; 84 virtual ContextType getContextType() const = 0;
74 virtual bool isAccelerated() const { return false; } 85 virtual bool isAccelerated() const { return false; }
75 virtual bool shouldAntialias() const { return false; } 86 virtual bool shouldAntialias() const { return false; }
76 virtual bool hasAlpha() const { return true; }
77 virtual void setIsHidden(bool) = 0; 87 virtual void setIsHidden(bool) = 0;
78 virtual bool isContextLost() const { return true; } 88 virtual bool isContextLost() const { return true; }
79 virtual void setCanvasGetContextResult(RenderingContext&) { NOTREACHED(); }; 89 virtual void setCanvasGetContextResult(RenderingContext&) { NOTREACHED(); };
80 virtual void setOffscreenCanvasGetContextResult(OffscreenRenderingContext&) { NOTREACHED(); } 90 virtual void setOffscreenCanvasGetContextResult(OffscreenRenderingContext&) { NOTREACHED(); }
81 91
82 // Return true if the content is updated. 92 // Return true if the content is updated.
83 virtual bool paintRenderingResultsToCanvas(SourceDrawingBuffer) { return fal se; } 93 virtual bool paintRenderingResultsToCanvas(SourceDrawingBuffer) { return fal se; }
84 94
85 // Note: this function is strictly for OffscreenCanvas only. 95 // Note: this function is strictly for OffscreenCanvas only.
86 virtual bool isPaintable() const = 0; 96 virtual bool isPaintable() const = 0;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 141
132 bool wouldTaintOrigin(CanvasImageSource*, SecurityOrigin* = nullptr); 142 bool wouldTaintOrigin(CanvasImageSource*, SecurityOrigin* = nullptr);
133 void didMoveToNewDocument(Document*); 143 void didMoveToNewDocument(Document*);
134 144
135 // OffscreenCanvas-specific methods 145 // OffscreenCanvas-specific methods
136 OffscreenCanvas* getOffscreenCanvas() const { return m_offscreenCanvas; } 146 OffscreenCanvas* getOffscreenCanvas() const { return m_offscreenCanvas; }
137 virtual ImageBitmap* transferToImageBitmap(ExceptionState&) { return nullptr ; } 147 virtual ImageBitmap* transferToImageBitmap(ExceptionState&) { return nullptr ; }
138 148
139 void detachCanvas() { m_canvas = nullptr; } 149 void detachCanvas() { m_canvas = nullptr; }
140 150
151 const CanvasContextCreationAttributes& creationAttributes() const { return m _creationAttributes; }
152
141 protected: 153 protected:
142 CanvasRenderingContext(HTMLCanvasElement* = nullptr, OffscreenCanvas* = null ptr); 154 CanvasRenderingContext(HTMLCanvasElement*, OffscreenCanvas*, const CanvasCon textCreationAttributes&);
143 DECLARE_VIRTUAL_TRACE(); 155 DECLARE_VIRTUAL_TRACE();
144 virtual void stop() = 0; 156 virtual void stop() = 0;
145 157
146 private: 158 private:
147 void dispose(); 159 void dispose();
148 160
149 Member<HTMLCanvasElement> m_canvas; 161 Member<HTMLCanvasElement> m_canvas;
150 Member<OffscreenCanvas> m_offscreenCanvas; 162 Member<OffscreenCanvas> m_offscreenCanvas;
151 HashSet<String> m_cleanURLs; 163 HashSet<String> m_cleanURLs;
152 HashSet<String> m_dirtyURLs; 164 HashSet<String> m_dirtyURLs;
165 CanvasColorSpace m_colorSpace;
166 CanvasContextCreationAttributes m_creationAttributes;
153 }; 167 };
154 168
155 } // namespace blink 169 } // namespace blink
156 170
157 #endif 171 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698