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

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: fix build + feedback Created 4 years, 4 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/offscreencanvas/OffscreenCanvas.h" 32 #include "core/offscreencanvas/OffscreenCanvas.h"
33 #include "third_party/skia/include/core/SkColorSpace.h"
32 #include "wtf/HashSet.h" 34 #include "wtf/HashSet.h"
33 #include "wtf/Noncopyable.h" 35 #include "wtf/Noncopyable.h"
34 #include "wtf/text/StringHash.h" 36 #include "wtf/text/StringHash.h"
35 37
36 class SkCanvas; 38 class SkCanvas;
37 39
38 namespace blink { class WebLayer; }
39
40 namespace blink { 40 namespace blink {
41 41
42 class CanvasImageSource; 42 class CanvasImageSource;
43 class HTMLCanvasElement; 43 class HTMLCanvasElement;
44 class ImageData; 44 class ImageData;
45 class ImageBitmap; 45 class ImageBitmap;
46 class WebLayer;
47
48 enum CanvasColorSpace {
49 kLegacyCanvasColorSpace,
50 kSRGBCanvasColorSpace,
51 kLinearRGBCanvasColorSpace,
52 };
46 53
47 class CORE_EXPORT CanvasRenderingContext : public GarbageCollectedFinalized<Canv asRenderingContext>, public ScriptWrappable { 54 class CORE_EXPORT CanvasRenderingContext : public GarbageCollectedFinalized<Canv asRenderingContext>, public ScriptWrappable {
48 WTF_MAKE_NONCOPYABLE(CanvasRenderingContext); 55 WTF_MAKE_NONCOPYABLE(CanvasRenderingContext);
49 USING_PRE_FINALIZER(CanvasRenderingContext, dispose); 56 USING_PRE_FINALIZER(CanvasRenderingContext, dispose);
50 public: 57 public:
51 virtual ~CanvasRenderingContext() { } 58 virtual ~CanvasRenderingContext() { }
52 59
53 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2 D canvas and the existing 60 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2 D canvas and the existing
54 // context is already 2D, just return that. If the existing context is WebGL , then destroy it 61 // context is already 2D, just return that. If the existing context is WebGL , then destroy it
55 // before creating a new 2D context. Vice versa when requesting a WebGL canv as. Requesting a 62 // before creating a new 2D context. Vice versa when requesting a WebGL canv as. Requesting a
56 // context with any other type string will destroy any existing context. 63 // context with any other type string will destroy any existing context.
57 enum ContextType { 64 enum ContextType {
58 // Do not change assigned numbers of existing items: add new features to the end of the list. 65 // Do not change assigned numbers of existing items: add new features to the end of the list.
59 Context2d = 0, 66 Context2d = 0,
60 ContextExperimentalWebgl = 2, 67 ContextExperimentalWebgl = 2,
61 ContextWebgl = 3, 68 ContextWebgl = 3,
62 ContextWebgl2 = 4, 69 ContextWebgl2 = 4,
63 ContextImageBitmap = 5, 70 ContextImageBitmap = 5,
64 ContextTypeCount, 71 ContextTypeCount,
65 }; 72 };
66 73
67 static ContextType contextTypeFromId(const String& id); 74 static ContextType contextTypeFromId(const String& id);
68 static ContextType resolveContextTypeAliases(ContextType); 75 static ContextType resolveContextTypeAliases(ContextType);
69 76
70 HTMLCanvasElement* canvas() const { return m_canvas; } 77 HTMLCanvasElement* canvas() const { return m_canvas; }
71 78
79 CanvasColorSpace colorSpace() const { return m_colorSpace; };
80 WTF::String colorSpaceAsString() const;
81 sk_sp<SkColorSpace> skColorSpace() const;
82
72 virtual ContextType getContextType() const = 0; 83 virtual ContextType getContextType() const = 0;
73 virtual bool isAccelerated() const { return false; } 84 virtual bool isAccelerated() const { return false; }
74 virtual bool shouldAntialias() const { return false; } 85 virtual bool shouldAntialias() const { return false; }
75 virtual bool hasAlpha() const { return true; }
76 virtual void setIsHidden(bool) = 0; 86 virtual void setIsHidden(bool) = 0;
77 virtual bool isContextLost() const { return true; } 87 virtual bool isContextLost() const { return true; }
78 virtual void setCanvasGetContextResult(RenderingContext&) { NOTREACHED(); }; 88 virtual void setCanvasGetContextResult(RenderingContext&) { NOTREACHED(); };
79 virtual void setOffscreenCanvasGetContextResult(OffscreenRenderingContext&) { NOTREACHED(); } 89 virtual void setOffscreenCanvasGetContextResult(OffscreenRenderingContext&) { NOTREACHED(); }
80 90
81 // Return true if the content is updated. 91 // Return true if the content is updated.
82 virtual bool paintRenderingResultsToCanvas(SourceDrawingBuffer) { return fal se; } 92 virtual bool paintRenderingResultsToCanvas(SourceDrawingBuffer) { return fal se; }
83 93
84 virtual WebLayer* platformLayer() const { return nullptr; } 94 virtual WebLayer* platformLayer() const { return nullptr; }
85 95
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 136
127 bool wouldTaintOrigin(CanvasImageSource*, SecurityOrigin* = nullptr); 137 bool wouldTaintOrigin(CanvasImageSource*, SecurityOrigin* = nullptr);
128 void didMoveToNewDocument(Document*); 138 void didMoveToNewDocument(Document*);
129 139
130 // OffscreenCanvas-specific methods 140 // OffscreenCanvas-specific methods
131 OffscreenCanvas* getOffscreenCanvas() const { return m_offscreenCanvas; } 141 OffscreenCanvas* getOffscreenCanvas() const { return m_offscreenCanvas; }
132 virtual ImageBitmap* transferToImageBitmap(ExceptionState&) { return nullptr ; } 142 virtual ImageBitmap* transferToImageBitmap(ExceptionState&) { return nullptr ; }
133 143
134 void detachCanvas() { m_canvas = nullptr; } 144 void detachCanvas() { m_canvas = nullptr; }
135 145
146 const CanvasContextCreationAttributes& creationAttributes() const { return m _creationAttributes; }
147
136 protected: 148 protected:
137 CanvasRenderingContext(HTMLCanvasElement* = nullptr, OffscreenCanvas* = null ptr); 149 CanvasRenderingContext(HTMLCanvasElement*, OffscreenCanvas*, const CanvasCon textCreationAttributes&);
138 DECLARE_VIRTUAL_TRACE(); 150 DECLARE_VIRTUAL_TRACE();
139 virtual void stop() = 0; 151 virtual void stop() = 0;
140 152
141 private: 153 private:
142 void dispose(); 154 void dispose();
143 155
144 Member<HTMLCanvasElement> m_canvas; 156 Member<HTMLCanvasElement> m_canvas;
145 Member<OffscreenCanvas> m_offscreenCanvas; 157 Member<OffscreenCanvas> m_offscreenCanvas;
146 HashSet<String> m_cleanURLs; 158 HashSet<String> m_cleanURLs;
147 HashSet<String> m_dirtyURLs; 159 HashSet<String> m_dirtyURLs;
160 CanvasColorSpace m_colorSpace;
161 CanvasContextCreationAttributes m_creationAttributes;
148 }; 162 };
149 163
150 } // namespace blink 164 } // namespace blink
151 165
152 #endif 166 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698