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

Side by Side Diff: Source/platform/graphics/gpu/DrawingBuffer.h

Issue 127493002: Removed most calls to GraphicsContext3D from DrawingBuffer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Moved texImage2DSafe to DrawingBuffer, it's only caller. Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010, Google Inc. All rights reserved. 2 * Copyright (c) 2010, Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 20 matching lines...) Expand all
31 #ifndef DrawingBuffer_h 31 #ifndef DrawingBuffer_h
32 #define DrawingBuffer_h 32 #define DrawingBuffer_h
33 33
34 #include "platform/PlatformExport.h" 34 #include "platform/PlatformExport.h"
35 #include "platform/geometry/IntSize.h" 35 #include "platform/geometry/IntSize.h"
36 #include "platform/graphics/GraphicsContext3D.h" 36 #include "platform/graphics/GraphicsContext3D.h"
37 #include "platform/graphics/GraphicsTypes3D.h" 37 #include "platform/graphics/GraphicsTypes3D.h"
38 38
39 #include "public/platform/WebExternalTextureLayerClient.h" 39 #include "public/platform/WebExternalTextureLayerClient.h"
40 #include "public/platform/WebExternalTextureMailbox.h" 40 #include "public/platform/WebExternalTextureMailbox.h"
41 #include "public/platform/WebGraphicsContext3D.h"
42 #include "third_party/skia/include/core/SkBitmap.h"
41 #include "wtf/Noncopyable.h" 43 #include "wtf/Noncopyable.h"
42 #include "wtf/OwnPtr.h" 44 #include "wtf/OwnPtr.h"
43 #include "wtf/PassOwnPtr.h" 45 #include "wtf/PassOwnPtr.h"
44 46
45 namespace blink { 47 namespace blink {
46 class WebExternalBitmap; 48 class WebExternalBitmap;
47 class WebExternalTextureLayer; 49 class WebExternalTextureLayer;
48 class WebGraphicsContext3D; 50 class WebGraphicsContext3D;
49 class WebLayer; 51 class WebLayer;
50 } 52 }
(...skipping 18 matching lines...) Expand all
69 blink::WebExternalTextureMailbox mailbox; 71 blink::WebExternalTextureMailbox mailbox;
70 unsigned textureId; 72 unsigned textureId;
71 IntSize size; 73 IntSize size;
72 }; 74 };
73 public: 75 public:
74 enum PreserveDrawingBuffer { 76 enum PreserveDrawingBuffer {
75 Preserve, 77 Preserve,
76 Discard 78 Discard
77 }; 79 };
78 80
79 static PassRefPtr<DrawingBuffer> create(GraphicsContext3D*, const IntSize&, PreserveDrawingBuffer, PassRefPtr<ContextEvictionManager>); 81 static PassRefPtr<DrawingBuffer> create(blink::WebGraphicsContext3D*, const IntSize&, PreserveDrawingBuffer, PassRefPtr<ContextEvictionManager>);
80 82
81 ~DrawingBuffer(); 83 ~DrawingBuffer();
82 84
83 // Clear all resources from this object, as well as context. Called when con text is destroyed 85 // Clear all resources from this object, as well as context. Called when con text is destroyed
84 // to prevent invalid accesses to the resources. 86 // to prevent invalid accesses to the resources.
85 void releaseResources(); 87 void releaseResources();
86 88
87 // Issues a glClear() on all framebuffers associated with this DrawingBuffer . The caller is responsible for 89 // Issues a glClear() on all framebuffers associated with this DrawingBuffer . The caller is responsible for
88 // making the context current and setting the clear values and masks. Modifi es the framebuffer binding. 90 // making the context current and setting the clear values and masks. Modifi es the framebuffer binding.
89 void clearFramebuffers(GLbitfield clearMask); 91 void clearFramebuffers(GLbitfield clearMask);
(...skipping 23 matching lines...) Expand all
113 115
114 // Track the currently active texture unit. Texture unit 0 is used as host f or a scratch 116 // Track the currently active texture unit. Texture unit 0 is used as host f or a scratch
115 // texture. 117 // texture.
116 void setActiveTextureUnit(GLint textureUnit) { m_activeTextureUnit = texture Unit; } 118 void setActiveTextureUnit(GLint textureUnit) { m_activeTextureUnit = texture Unit; }
117 119
118 bool multisample() const; 120 bool multisample() const;
119 121
120 Platform3DObject framebuffer() const; 122 Platform3DObject framebuffer() const;
121 123
122 void markContentsChanged(); 124 void markContentsChanged();
125 void markLayerComposited();
126 bool layerComposited() const;
123 127
124 blink::WebLayer* platformLayer(); 128 blink::WebLayer* platformLayer();
125 void paintCompositedResultsToCanvas(ImageBuffer*); 129 void paintCompositedResultsToCanvas(ImageBuffer*);
126 130
127 // WebExternalTextureLayerClient implementation. 131 // WebExternalTextureLayerClient implementation.
128 virtual blink::WebGraphicsContext3D* context() OVERRIDE; 132 virtual blink::WebGraphicsContext3D* context() OVERRIDE;
129 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExt ernalBitmap*) OVERRIDE; 133 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExt ernalBitmap*) OVERRIDE;
130 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&) OVERRI DE; 134 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&) OVERRI DE;
131 135
132 bool copyToPlatformTexture(GraphicsContext3D&, Platform3DObject texture, GLe num internalFormat, 136 bool copyToPlatformTexture(GraphicsContext3D&, Platform3DObject texture, GLe num internalFormat,
133 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY); 137 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY);
134 138
139 void setPackAlignment(GLint param);
140
141 void paintRenderingResultsToCanvas(ImageBuffer*);
142 PassRefPtr<Uint8ClampedArray> paintRenderingResultsToImageData(int&, int&);
143
135 private: 144 private:
136 DrawingBuffer(GraphicsContext3D*, const IntSize&, bool multisampleExtensionS upported, 145 DrawingBuffer(blink::WebGraphicsContext3D*, GraphicsContext3D*, const IntSiz e&, bool multisampleExtensionSupported,
137 bool packedDepthStencilExtensionSupported, PreserveDrawingBuff er, PassRefPtr<ContextEvictionManager>); 146 bool packedDepthStencilExtensionSupported, PreserveDrawingBuff er, PassRefPtr<ContextEvictionManager>);
138 147
139 void initialize(const IntSize&); 148 void initialize(const IntSize&);
140 149
141 unsigned createColorTexture(const IntSize& size = IntSize()); 150 unsigned createColorTexture(const IntSize& size = IntSize());
142 // Create the depth/stencil and multisample buffers, if needed. 151 // Create the depth/stencil and multisample buffers, if needed.
143 void createSecondaryBuffers(); 152 void createSecondaryBuffers();
144 bool resizeFramebuffer(const IntSize&); 153 bool resizeFramebuffer(const IntSize&);
145 bool resizeMultisampleFramebuffer(const IntSize&); 154 bool resizeMultisampleFramebuffer(const IntSize&);
146 void resizeDepthStencil(const IntSize&); 155 void resizeDepthStencil(const IntSize&);
147 156
148 // Bind to the m_framebufferBinding if it's not 0. 157 // Bind to the m_framebufferBinding if it's not 0.
149 void restoreFramebufferBinding(); 158 void restoreFramebufferBinding();
150 159
151 void clearPlatformLayer(); 160 void clearPlatformLayer();
152 161
153 PassRefPtr<MailboxInfo> recycledMailbox(); 162 PassRefPtr<MailboxInfo> recycledMailbox();
154 PassRefPtr<MailboxInfo> createNewMailbox(unsigned); 163 PassRefPtr<MailboxInfo> createNewMailbox(unsigned);
155 164
156 // Updates the current size of the buffer, ensuring that s_currentResourceUs ePixels is updated. 165 // Updates the current size of the buffer, ensuring that s_currentResourceUs ePixels is updated.
157 void setSize(const IntSize& size); 166 void setSize(const IntSize& size);
158 167
159 // Calculates the difference in pixels between the current buffer size and t he proposed size. 168 // Calculates the difference in pixels between the current buffer size and t he proposed size.
160 int pixelDelta(const IntSize& size); 169 int pixelDelta(const IntSize& size);
161 170
162 // Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget 171 // Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget
163 // Returns true if the buffer will only fit if the oldest WebGL context is f orcibly lost 172 // Returns true if the buffer will only fit if the oldest WebGL context is f orcibly lost
164 IntSize adjustSizeWithContextEviction(const IntSize&, bool& evictContext); 173 IntSize adjustSizeWithContextEviction(const IntSize&, bool& evictContext);
165 174
175 void paintFramebufferToCanvas(int framebuffer, int width, int height, bool p remultiplyAlpha, ImageBuffer*);
176
177 // This is the order of bytes to use when doing a readback.
178 enum ReadbackOrder {
179 ReadbackRGBA,
180 ReadbackSkia
181 };
182
183 // Helper function which does a readback from the currently-bound
184 // framebuffer into a buffer of a certain size with 4-byte pixels.
185 void readBackFramebuffer(unsigned char* pixels, int width, int height, Readb ackOrder, GraphicsContext3D::AlphaOp);
186
187 // Helper function to flip a bitmap vertically.
188 void flipVertically(uint8_t* data, int width, int height);
189
190 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
191 // By default, alignment is 4, the OpenGL default setting.
192 void texImage2DResourceSafe(GLenum target, GLint level, GLenum internalforma t, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLin t alignment = 4);
193
166 PreserveDrawingBuffer m_preserveDrawingBuffer; 194 PreserveDrawingBuffer m_preserveDrawingBuffer;
167 bool m_scissorEnabled; 195 bool m_scissorEnabled;
168 Platform3DObject m_texture2DBinding; 196 Platform3DObject m_texture2DBinding;
169 Platform3DObject m_framebufferBinding; 197 Platform3DObject m_framebufferBinding;
170 GLenum m_activeTextureUnit; 198 GLenum m_activeTextureUnit;
171 199
172 RefPtr<GraphicsContext3D> m_context; 200 blink::WebGraphicsContext3D* m_context;
201 RefPtr<GraphicsContext3D> m_contextSupport;
173 IntSize m_size; 202 IntSize m_size;
174 bool m_multisampleExtensionSupported; 203 bool m_multisampleExtensionSupported;
175 bool m_packedDepthStencilExtensionSupported; 204 bool m_packedDepthStencilExtensionSupported;
176 Platform3DObject m_fbo; 205 Platform3DObject m_fbo;
177 // DrawingBuffer's output is double-buffered. m_colorBuffer is the back buff er. 206 // DrawingBuffer's output is double-buffered. m_colorBuffer is the back buff er.
178 Platform3DObject m_colorBuffer; 207 Platform3DObject m_colorBuffer;
179 Platform3DObject m_frontColorBuffer; 208 Platform3DObject m_frontColorBuffer;
180 209
181 // This is used when we have OES_packed_depth_stencil. 210 // This is used when we have OES_packed_depth_stencil.
182 Platform3DObject m_depthStencilBuffer; 211 Platform3DObject m_depthStencilBuffer;
183 212
184 // These are used when we don't. 213 // These are used when we don't.
185 Platform3DObject m_depthBuffer; 214 Platform3DObject m_depthBuffer;
186 Platform3DObject m_stencilBuffer; 215 Platform3DObject m_stencilBuffer;
187 216
188 // For multisampling. 217 // For multisampling.
189 Platform3DObject m_multisampleFBO; 218 Platform3DObject m_multisampleFBO;
190 Platform3DObject m_multisampleColorBuffer; 219 Platform3DObject m_multisampleColorBuffer;
191 220
192 // True if our contents have been modified since the last presentation of th is buffer. 221 // True if our contents have been modified since the last presentation of th is buffer.
193 bool m_contentsChanged; 222 bool m_contentsChanged;
194 223
195 // True if commit() has been called since the last time markContentsChanged( ) had been called. 224 // True if commit() has been called since the last time markContentsChanged( ) had been called.
196 bool m_contentsChangeCommitted; 225 bool m_contentsChangeCommitted;
226 bool m_layerComposited;
197 227
198 GraphicsContext3D::Attributes m_attributes; 228 blink::WebGraphicsContext3D::Attributes m_attributes;
199 unsigned m_internalColorFormat; 229 unsigned m_internalColorFormat;
200 unsigned m_colorFormat; 230 unsigned m_colorFormat;
201 unsigned m_internalRenderbufferFormat; 231 unsigned m_internalRenderbufferFormat;
202 int m_maxTextureSize; 232 int m_maxTextureSize;
203 int m_sampleCount; 233 int m_sampleCount;
234 int m_packAlignment;
204 235
205 OwnPtr<blink::WebExternalTextureLayer> m_layer; 236 OwnPtr<blink::WebExternalTextureLayer> m_layer;
206 237
207 // All of the mailboxes that this DrawingBuffer has ever created. 238 // All of the mailboxes that this DrawingBuffer has ever created.
208 Vector<RefPtr<MailboxInfo> > m_textureMailboxes; 239 Vector<RefPtr<MailboxInfo> > m_textureMailboxes;
209 // Mailboxes that were released by the compositor and can be used again by t his DrawingBuffer. 240 // Mailboxes that were released by the compositor and can be used again by t his DrawingBuffer.
210 Vector<RefPtr<MailboxInfo> > m_recycledMailboxes; 241 Vector<RefPtr<MailboxInfo> > m_recycledMailboxes;
211 242
212 RefPtr<ContextEvictionManager> m_contextEvictionManager; 243 RefPtr<ContextEvictionManager> m_contextEvictionManager;
244
245 // If the width and height of the Canvas's backing store don't
246 // match those that we were given in the most recent call to
247 // reshape(), then we need an intermediate bitmap to read back the
248 // frame buffer into. This seems to happen when CSS styles are
249 // used to resize the Canvas.
250 SkBitmap m_resizingBitmap;
251
252 // Used to flip a bitmap vertically.
253 Vector<uint8_t> m_scanline;
213 }; 254 };
214 255
215 } // namespace WebCore 256 } // namespace WebCore
216 257
217 #endif // DrawingBuffer_h 258 #endif // DrawingBuffer_h
OLDNEW
« no previous file with comments | « Source/platform/graphics/GraphicsContext3D.cpp ('k') | Source/platform/graphics/gpu/DrawingBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698