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

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 and tests 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
83 virtual bool hasAlpha() const { return creationAttributes().alpha(); }
Stephen White 2016/08/12 19:48:31 As discussed, let's see if we can get rid of this
Justin Novosad 2016/08/12 20:08:49 Done.
72 virtual ContextType getContextType() const = 0; 84 virtual ContextType getContextType() const = 0;
73 virtual bool isAccelerated() const { return false; } 85 virtual bool isAccelerated() const { return false; }
74 virtual bool shouldAntialias() const { return false; } 86 virtual bool shouldAntialias() const { return false; }
75 virtual bool hasAlpha() const { return true; }
76 virtual void setIsHidden(bool) = 0; 87 virtual void setIsHidden(bool) = 0;
77 virtual bool isContextLost() const { return true; } 88 virtual bool isContextLost() const { return true; }
78 virtual void setCanvasGetContextResult(RenderingContext&) { NOTREACHED(); }; 89 virtual void setCanvasGetContextResult(RenderingContext&) { NOTREACHED(); };
79 virtual void setOffscreenCanvasGetContextResult(OffscreenRenderingContext&) { NOTREACHED(); } 90 virtual void setOffscreenCanvasGetContextResult(OffscreenRenderingContext&) { NOTREACHED(); }
80 91
81 // Return true if the content is updated. 92 // Return true if the content is updated.
82 virtual bool paintRenderingResultsToCanvas(SourceDrawingBuffer) { return fal se; } 93 virtual bool paintRenderingResultsToCanvas(SourceDrawingBuffer) { return fal se; }
83 94
84 virtual WebLayer* platformLayer() const { return nullptr; } 95 virtual WebLayer* platformLayer() const { return nullptr; }
85 96
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 137
127 bool wouldTaintOrigin(CanvasImageSource*, SecurityOrigin* = nullptr); 138 bool wouldTaintOrigin(CanvasImageSource*, SecurityOrigin* = nullptr);
128 void didMoveToNewDocument(Document*); 139 void didMoveToNewDocument(Document*);
129 140
130 // OffscreenCanvas-specific methods 141 // OffscreenCanvas-specific methods
131 OffscreenCanvas* getOffscreenCanvas() const { return m_offscreenCanvas; } 142 OffscreenCanvas* getOffscreenCanvas() const { return m_offscreenCanvas; }
132 virtual ImageBitmap* transferToImageBitmap(ExceptionState&) { return nullptr ; } 143 virtual ImageBitmap* transferToImageBitmap(ExceptionState&) { return nullptr ; }
133 144
134 void detachCanvas() { m_canvas = nullptr; } 145 void detachCanvas() { m_canvas = nullptr; }
135 146
147 const CanvasContextCreationAttributes& creationAttributes() const { return m _creationAttributes; }
148
136 protected: 149 protected:
137 CanvasRenderingContext(HTMLCanvasElement* = nullptr, OffscreenCanvas* = null ptr); 150 CanvasRenderingContext(HTMLCanvasElement*, OffscreenCanvas*, const CanvasCon textCreationAttributes&);
138 DECLARE_VIRTUAL_TRACE(); 151 DECLARE_VIRTUAL_TRACE();
139 virtual void stop() = 0; 152 virtual void stop() = 0;
140 153
141 private: 154 private:
142 void dispose(); 155 void dispose();
143 156
144 Member<HTMLCanvasElement> m_canvas; 157 Member<HTMLCanvasElement> m_canvas;
145 Member<OffscreenCanvas> m_offscreenCanvas; 158 Member<OffscreenCanvas> m_offscreenCanvas;
146 HashSet<String> m_cleanURLs; 159 HashSet<String> m_cleanURLs;
147 HashSet<String> m_dirtyURLs; 160 HashSet<String> m_dirtyURLs;
161 CanvasColorSpace m_colorSpace;
162 CanvasContextCreationAttributes m_creationAttributes;
148 }; 163 };
149 164
150 } // namespace blink 165 } // namespace blink
151 166
152 #endif 167 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698