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

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: minor corrections 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 11 matching lines...) Expand all
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/offscreencanvas/OffscreenCanvas.h" 31 #include "core/offscreencanvas/OffscreenCanvas.h"
32 #include "third_party/skia/include/core/SkColorSpace.h"
32 #include "wtf/HashSet.h" 33 #include "wtf/HashSet.h"
33 #include "wtf/Noncopyable.h" 34 #include "wtf/Noncopyable.h"
34 #include "wtf/text/StringHash.h" 35 #include "wtf/text/StringHash.h"
35 36
36 class SkCanvas; 37 class SkCanvas;
37 38
38 namespace blink { class WebLayer; }
39
40 namespace blink { 39 namespace blink {
41 40
42 class CanvasImageSource; 41 class CanvasImageSource;
43 class HTMLCanvasElement; 42 class HTMLCanvasElement;
44 class ImageData; 43 class ImageData;
45 class ImageBitmap; 44 class ImageBitmap;
45 class WebLayer;
46
47 enum CanvasColorSpace {
48 kLegacyCanvasColorSpace,
49 kSRGBCanvasColorSpace,
50 kLinearRGBCanvasColorSpace,
51 };
46 52
47 class CORE_EXPORT CanvasRenderingContext : public GarbageCollectedFinalized<Canv asRenderingContext>, public ScriptWrappable { 53 class CORE_EXPORT CanvasRenderingContext : public GarbageCollectedFinalized<Canv asRenderingContext>, public ScriptWrappable {
48 WTF_MAKE_NONCOPYABLE(CanvasRenderingContext); 54 WTF_MAKE_NONCOPYABLE(CanvasRenderingContext);
49 USING_PRE_FINALIZER(CanvasRenderingContext, dispose); 55 USING_PRE_FINALIZER(CanvasRenderingContext, dispose);
50 public: 56 public:
51 virtual ~CanvasRenderingContext() { } 57 virtual ~CanvasRenderingContext() { }
52 58
53 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2 D canvas and the existing 59 // 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 60 // 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 61 // 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. 62 // context with any other type string will destroy any existing context.
57 enum ContextType { 63 enum ContextType {
58 // Do not change assigned numbers of existing items: add new features to the end of the list. 64 // Do not change assigned numbers of existing items: add new features to the end of the list.
59 Context2d = 0, 65 Context2d = 0,
60 ContextExperimentalWebgl = 2, 66 ContextExperimentalWebgl = 2,
61 ContextWebgl = 3, 67 ContextWebgl = 3,
62 ContextWebgl2 = 4, 68 ContextWebgl2 = 4,
63 ContextImageBitmap = 5, 69 ContextImageBitmap = 5,
64 ContextTypeCount, 70 ContextTypeCount,
65 }; 71 };
66 72
67 static ContextType contextTypeFromId(const String& id); 73 static ContextType contextTypeFromId(const String& id);
68 static ContextType resolveContextTypeAliases(ContextType); 74 static ContextType resolveContextTypeAliases(ContextType);
69 75
70 HTMLCanvasElement* canvas() const { return m_canvas; } 76 HTMLCanvasElement* canvas() const { return m_canvas; }
71 77
78 CanvasColorSpace colorSpace() const { return m_colorSpace; };
79 WTF::String colorSpaceAsString() const;
80 sk_sp<SkColorSpace> skColorSpace() const;
81
72 virtual ContextType getContextType() const = 0; 82 virtual ContextType getContextType() const = 0;
73 virtual bool isAccelerated() const { return false; } 83 virtual bool isAccelerated() const { return false; }
74 virtual bool shouldAntialias() const { return false; } 84 virtual bool shouldAntialias() const { return false; }
75 virtual bool hasAlpha() const { return true; } 85 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.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
136 protected: 146 protected:
137 CanvasRenderingContext(HTMLCanvasElement* = nullptr, OffscreenCanvas* = null ptr); 147 CanvasRenderingContext(HTMLCanvasElement*, OffscreenCanvas*, const String& c olorSpace);
Stephen White 2016/08/11 20:41:27 As discussed, I think we should pass in (a ref to)
Justin Novosad 2016/08/12 17:40:18 Done. This was a bit more complicated than antici
138 DECLARE_VIRTUAL_TRACE(); 148 DECLARE_VIRTUAL_TRACE();
139 virtual void stop() = 0; 149 virtual void stop() = 0;
140 150
141 private: 151 private:
142 void dispose(); 152 void dispose();
143 153
144 Member<HTMLCanvasElement> m_canvas; 154 Member<HTMLCanvasElement> m_canvas;
145 Member<OffscreenCanvas> m_offscreenCanvas; 155 Member<OffscreenCanvas> m_offscreenCanvas;
146 HashSet<String> m_cleanURLs; 156 HashSet<String> m_cleanURLs;
147 HashSet<String> m_dirtyURLs; 157 HashSet<String> m_dirtyURLs;
158 CanvasColorSpace m_colorSpace;
148 }; 159 };
149 160
150 } // namespace blink 161 } // namespace blink
151 162
152 #endif 163 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698