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

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

Issue 169933002: WebGL: Don't destroy mailbox textures in the destructor until they're released. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase DrawingBufferTest to ToT Created 6 years, 8 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) 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 23 matching lines...) Expand all
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/GraphicsTypes3D.h" 36 #include "platform/graphics/GraphicsTypes3D.h"
37 #include "platform/graphics/gpu/WebGLImageConversion.h" 37 #include "platform/graphics/gpu/WebGLImageConversion.h"
38 #include "public/platform/WebExternalTextureLayerClient.h" 38 #include "public/platform/WebExternalTextureLayerClient.h"
39 #include "public/platform/WebExternalTextureMailbox.h" 39 #include "public/platform/WebExternalTextureMailbox.h"
40 #include "public/platform/WebGraphicsContext3D.h" 40 #include "public/platform/WebGraphicsContext3D.h"
41 #include "third_party/khronos/GLES2/gl2.h" 41 #include "third_party/khronos/GLES2/gl2.h"
42 #include "third_party/khronos/GLES2/gl2ext.h" 42 #include "third_party/khronos/GLES2/gl2ext.h"
43 #include "third_party/skia/include/core/SkBitmap.h" 43 #include "third_party/skia/include/core/SkBitmap.h"
44 #include "wtf/Deque.h"
44 #include "wtf/Noncopyable.h" 45 #include "wtf/Noncopyable.h"
45 #include "wtf/OwnPtr.h" 46 #include "wtf/OwnPtr.h"
46 #include "wtf/PassOwnPtr.h" 47 #include "wtf/PassOwnPtr.h"
47 48
48 namespace blink { 49 namespace blink {
49 class WebExternalBitmap; 50 class WebExternalBitmap;
50 class WebExternalTextureLayer; 51 class WebExternalTextureLayer;
51 class WebGraphicsContext3D; 52 class WebGraphicsContext3D;
52 class WebLayer; 53 class WebLayer;
53 } 54 }
(...skipping 12 matching lines...) Expand all
66 virtual IntSize oldestContextSize() = 0; 67 virtual IntSize oldestContextSize() = 0;
67 }; 68 };
68 69
69 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ ish its rendering 70 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ ish its rendering
70 // results to a blink::WebLayer for compositing. 71 // results to a blink::WebLayer for compositing.
71 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public b link::WebExternalTextureLayerClient { 72 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public b link::WebExternalTextureLayerClient {
72 struct MailboxInfo : public RefCounted<MailboxInfo> { 73 struct MailboxInfo : public RefCounted<MailboxInfo> {
73 blink::WebExternalTextureMailbox mailbox; 74 blink::WebExternalTextureMailbox mailbox;
74 unsigned textureId; 75 unsigned textureId;
75 IntSize size; 76 IntSize size;
77 // This keeps the parent drawing buffer alive as long as the compositor is
78 // referring to one of the mailboxes DrawingBuffer produced. The parent drawing buffer is
79 // cleared when the compositor returns the mailbox. See mailboxReleased( ).
80 RefPtr<DrawingBuffer> m_parentDrawingBuffer;
76 }; 81 };
77 public: 82 public:
78 enum PreserveDrawingBuffer { 83 enum PreserveDrawingBuffer {
79 Preserve, 84 Preserve,
80 Discard 85 Discard
81 }; 86 };
82 87
83 static PassRefPtr<DrawingBuffer> create(PassOwnPtr<blink::WebGraphicsContext 3D>, const IntSize&, PreserveDrawingBuffer, PassRefPtr<ContextEvictionManager>); 88 static PassRefPtr<DrawingBuffer> create(PassOwnPtr<blink::WebGraphicsContext 3D>, const IntSize&, PreserveDrawingBuffer, PassRefPtr<ContextEvictionManager>);
84 89
85 virtual ~DrawingBuffer(); 90 virtual ~DrawingBuffer();
86 91
92 // Destruction will be completed after all mailboxes are released.
93 void beginDestruction();
94
87 // Issues a glClear() on all framebuffers associated with this DrawingBuffer . The caller is responsible for 95 // 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. 96 // making the context current and setting the clear values and masks. Modifi es the framebuffer binding.
89 void clearFramebuffers(GLbitfield clearMask); 97 void clearFramebuffers(GLbitfield clearMask);
90 98
91 // Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget. 99 // Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget.
92 static IntSize adjustSize(const IntSize& desiredSize, const IntSize& curSize , int maxTextureSize); 100 static IntSize adjustSize(const IntSize& desiredSize, const IntSize& curSize , int maxTextureSize);
93 bool reset(const IntSize&); 101 bool reset(const IntSize&);
94 void bind(); 102 void bind();
95 IntSize size() const { return m_size; } 103 IntSize size() const { return m_size; }
96 104
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 140
133 // Destroys the TEXTURE_2D binding for the owned context 141 // Destroys the TEXTURE_2D binding for the owned context
134 bool copyToPlatformTexture(blink::WebGraphicsContext3D*, Platform3DObject te xture, GLenum internalFormat, 142 bool copyToPlatformTexture(blink::WebGraphicsContext3D*, Platform3DObject te xture, GLenum internalFormat,
135 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY); 143 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY);
136 144
137 void setPackAlignment(GLint param); 145 void setPackAlignment(GLint param);
138 146
139 void paintRenderingResultsToCanvas(ImageBuffer*); 147 void paintRenderingResultsToCanvas(ImageBuffer*);
140 PassRefPtr<Uint8ClampedArray> paintRenderingResultsToImageData(int&, int&); 148 PassRefPtr<Uint8ClampedArray> paintRenderingResultsToImageData(int&, int&);
141 149
142 private: 150 protected: // For unittests
143 DrawingBuffer( 151 DrawingBuffer(
144 PassOwnPtr<blink::WebGraphicsContext3D>, 152 PassOwnPtr<blink::WebGraphicsContext3D>,
145 PassOwnPtr<Extensions3DUtil>, 153 PassOwnPtr<Extensions3DUtil>,
146 bool multisampleExtensionSupported, 154 bool multisampleExtensionSupported,
147 bool packedDepthStencilExtensionSupported, PreserveDrawingBuffer, PassRe fPtr<ContextEvictionManager>); 155 bool packedDepthStencilExtensionSupported, PreserveDrawingBuffer, PassRe fPtr<ContextEvictionManager>);
148 156
149 bool initialize(const IntSize&); 157 bool initialize(const IntSize&);
150 void releaseResources(); 158
159 private:
160 void mailboxReleasedWhileDestructionInProgress(const blink::WebExternalTextu reMailbox&);
151 161
152 unsigned createColorTexture(const IntSize& size = IntSize()); 162 unsigned createColorTexture(const IntSize& size = IntSize());
153 // Create the depth/stencil and multisample buffers, if needed. 163 // Create the depth/stencil and multisample buffers, if needed.
154 void createSecondaryBuffers(); 164 void createSecondaryBuffers();
155 bool resizeFramebuffer(const IntSize&); 165 bool resizeFramebuffer(const IntSize&);
156 bool resizeMultisampleFramebuffer(const IntSize&); 166 bool resizeMultisampleFramebuffer(const IntSize&);
157 void resizeDepthStencil(const IntSize&); 167 void resizeDepthStencil(const IntSize&);
158 168
159 // Bind to the m_framebufferBinding if it's not 0. 169 // Bind to the m_framebufferBinding if it's not 0.
160 void restoreFramebufferBinding(); 170 void restoreFramebufferBinding();
161 171
162 void clearPlatformLayer(); 172 void clearPlatformLayer();
163 173
164 PassRefPtr<MailboxInfo> recycledMailbox(); 174 PassRefPtr<MailboxInfo> recycledMailbox();
165 PassRefPtr<MailboxInfo> createNewMailbox(unsigned); 175 PassRefPtr<MailboxInfo> createNewMailbox(unsigned);
176 void deleteMailbox(const blink::WebExternalTextureMailbox&);
166 177
167 // Updates the current size of the buffer, ensuring that s_currentResourceUs ePixels is updated. 178 // Updates the current size of the buffer, ensuring that s_currentResourceUs ePixels is updated.
168 void setSize(const IntSize& size); 179 void setSize(const IntSize& size);
169 180
170 // Calculates the difference in pixels between the current buffer size and t he proposed size. 181 // Calculates the difference in pixels between the current buffer size and t he proposed size.
171 static int pixelDelta(const IntSize& newSize, const IntSize& curSize); 182 static int pixelDelta(const IntSize& newSize, const IntSize& curSize);
172 183
173 // Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget 184 // Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget
174 // Returns true if the buffer will only fit if the oldest WebGL context is f orcibly lost 185 // Returns true if the buffer will only fit if the oldest WebGL context is f orcibly lost
175 IntSize adjustSizeWithContextEviction(const IntSize&, bool& evictContext); 186 IntSize adjustSizeWithContextEviction(const IntSize&, bool& evictContext);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 246
236 MultisampleMode m_multisampleMode; 247 MultisampleMode m_multisampleMode;
237 248
238 blink::WebGraphicsContext3D::Attributes m_attributes; 249 blink::WebGraphicsContext3D::Attributes m_attributes;
239 unsigned m_internalColorFormat; 250 unsigned m_internalColorFormat;
240 unsigned m_colorFormat; 251 unsigned m_colorFormat;
241 unsigned m_internalRenderbufferFormat; 252 unsigned m_internalRenderbufferFormat;
242 int m_maxTextureSize; 253 int m_maxTextureSize;
243 int m_sampleCount; 254 int m_sampleCount;
244 int m_packAlignment; 255 int m_packAlignment;
256 bool m_destructionInProgress;
245 257
246 OwnPtr<blink::WebExternalTextureLayer> m_layer; 258 OwnPtr<blink::WebExternalTextureLayer> m_layer;
247 259
248 // All of the mailboxes that this DrawingBuffer has ever created. 260 // All of the mailboxes that this DrawingBuffer has ever created.
249 Vector<RefPtr<MailboxInfo> > m_textureMailboxes; 261 Vector<RefPtr<MailboxInfo> > m_textureMailboxes;
250 // Mailboxes that were released by the compositor and can be used again by t his DrawingBuffer. 262 // Mailboxes that were released by the compositor can be used again by this DrawingBuffer.
251 Vector<RefPtr<MailboxInfo> > m_recycledMailboxes; 263 Deque<blink::WebExternalTextureMailbox> m_recycledMailboxQueue;
252 264
253 RefPtr<ContextEvictionManager> m_contextEvictionManager; 265 RefPtr<ContextEvictionManager> m_contextEvictionManager;
254 266
255 // If the width and height of the Canvas's backing store don't 267 // If the width and height of the Canvas's backing store don't
256 // match those that we were given in the most recent call to 268 // match those that we were given in the most recent call to
257 // reshape(), then we need an intermediate bitmap to read back the 269 // reshape(), then we need an intermediate bitmap to read back the
258 // frame buffer into. This seems to happen when CSS styles are 270 // frame buffer into. This seems to happen when CSS styles are
259 // used to resize the Canvas. 271 // used to resize the Canvas.
260 SkBitmap m_resizingBitmap; 272 SkBitmap m_resizingBitmap;
261 273
262 // Used to flip a bitmap vertically. 274 // Used to flip a bitmap vertically.
263 Vector<uint8_t> m_scanline; 275 Vector<uint8_t> m_scanline;
264 }; 276 };
265 277
266 } // namespace WebCore 278 } // namespace WebCore
267 279
268 #endif // DrawingBuffer_h 280 #endif // DrawingBuffer_h
OLDNEW
« no previous file with comments | « Source/core/html/canvas/WebGLRenderingContextBase.cpp ('k') | Source/platform/graphics/gpu/DrawingBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698