OLD | NEW |
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 m_context->bindTexture(GL_TEXTURE_2D, m_oldTextureUnitZeroId); | 70 m_context->bindTexture(GL_TEXTURE_2D, m_oldTextureUnitZeroId); |
71 m_context->activeTexture(m_oldActiveTextureUnit); | 71 m_context->activeTexture(m_oldActiveTextureUnit); |
72 } | 72 } |
73 | 73 |
74 private: | 74 private: |
75 blink::WebGraphicsContext3D* m_context; | 75 blink::WebGraphicsContext3D* m_context; |
76 GLenum m_oldActiveTextureUnit; | 76 GLenum m_oldActiveTextureUnit; |
77 Platform3DObject m_oldTextureUnitZeroId; | 77 Platform3DObject m_oldTextureUnitZeroId; |
78 }; | 78 }; |
79 | 79 |
80 PassRefPtr<DrawingBuffer> DrawingBuffer::create(blink::WebGraphicsContext3D* con
text, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvi
ctionManager> contextEvictionManager) | 80 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<blink::WebGraphicsCon
text3D> context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr
<ContextEvictionManager> contextEvictionManager) |
81 { | 81 { |
82 Extensions3DUtil extensionsUtil(context); | 82 ASSERT(context); |
| 83 Extensions3DUtil extensionsUtil(context.get()); |
83 bool multisampleSupported = extensionsUtil.supportsExtension("GL_CHROMIUM_fr
amebuffer_multisample") | 84 bool multisampleSupported = extensionsUtil.supportsExtension("GL_CHROMIUM_fr
amebuffer_multisample") |
84 && extensionsUtil.supportsExtension("GL_OES_rgb8_rgba8"); | 85 && extensionsUtil.supportsExtension("GL_OES_rgb8_rgba8"); |
85 if (multisampleSupported) { | 86 if (multisampleSupported) { |
86 extensionsUtil.ensureExtensionEnabled("GL_CHROMIUM_framebuffer_multisamp
le"); | 87 extensionsUtil.ensureExtensionEnabled("GL_CHROMIUM_framebuffer_multisamp
le"); |
87 extensionsUtil.ensureExtensionEnabled("GL_OES_rgb8_rgba8"); | 88 extensionsUtil.ensureExtensionEnabled("GL_OES_rgb8_rgba8"); |
88 } | 89 } |
89 bool packedDepthStencilSupported = extensionsUtil.supportsExtension("GL_OES_
packed_depth_stencil"); | 90 bool packedDepthStencilSupported = extensionsUtil.supportsExtension("GL_OES_
packed_depth_stencil"); |
90 if (packedDepthStencilSupported) | 91 if (packedDepthStencilSupported) |
91 extensionsUtil.ensureExtensionEnabled("GL_OES_packed_depth_stencil"); | 92 extensionsUtil.ensureExtensionEnabled("GL_OES_packed_depth_stencil"); |
92 | 93 |
93 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, si
ze, multisampleSupported, packedDepthStencilSupported, preserve, contextEviction
Manager)); | 94 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, mu
ltisampleSupported, packedDepthStencilSupported, preserve, contextEvictionManage
r)); |
| 95 if (!drawingBuffer->initialize(size)) |
| 96 return PassRefPtr<DrawingBuffer>(); |
94 return drawingBuffer.release(); | 97 return drawingBuffer.release(); |
95 } | 98 } |
96 | 99 |
97 DrawingBuffer::DrawingBuffer(blink::WebGraphicsContext3D* context, | 100 DrawingBuffer::DrawingBuffer(PassOwnPtr<blink::WebGraphicsContext3D> context, |
98 const IntSize& size, | |
99 bool multisampleExtensionSupported, | 101 bool multisampleExtensionSupported, |
100 bool packedDepthStencilExtensionSupported, | 102 bool packedDepthStencilExtensionSupported, |
101 PreserveDrawingBuffer preserve, | 103 PreserveDrawingBuffer preserve, |
102 PassRefPtr<ContextEvictionManager> contextEvictionManager) | 104 PassRefPtr<ContextEvictionManager> contextEvictionManager) |
103 : m_preserveDrawingBuffer(preserve) | 105 : m_preserveDrawingBuffer(preserve) |
104 , m_scissorEnabled(false) | 106 , m_scissorEnabled(false) |
105 , m_texture2DBinding(0) | 107 , m_texture2DBinding(0) |
106 , m_framebufferBinding(0) | 108 , m_framebufferBinding(0) |
107 , m_activeTextureUnit(GL_TEXTURE0) | 109 , m_activeTextureUnit(GL_TEXTURE0) |
108 , m_context(context) | 110 , m_context(context) |
109 , m_size(-1, -1) | 111 , m_size(-1, -1) |
110 , m_multisampleExtensionSupported(multisampleExtensionSupported) | 112 , m_multisampleExtensionSupported(multisampleExtensionSupported) |
111 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte
d) | 113 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte
d) |
112 , m_fbo(0) | 114 , m_fbo(0) |
113 , m_colorBuffer(0) | 115 , m_colorBuffer(0) |
114 , m_frontColorBuffer(0) | 116 , m_frontColorBuffer(0) |
115 , m_depthStencilBuffer(0) | 117 , m_depthStencilBuffer(0) |
116 , m_depthBuffer(0) | 118 , m_depthBuffer(0) |
117 , m_stencilBuffer(0) | 119 , m_stencilBuffer(0) |
118 , m_multisampleFBO(0) | 120 , m_multisampleFBO(0) |
119 , m_multisampleColorBuffer(0) | 121 , m_multisampleColorBuffer(0) |
120 , m_contentsChanged(true) | 122 , m_contentsChanged(true) |
121 , m_contentsChangeCommitted(false) | 123 , m_contentsChangeCommitted(false) |
122 , m_layerComposited(false) | 124 , m_layerComposited(false) |
123 , m_internalColorFormat(0) | 125 , m_internalColorFormat(0) |
124 , m_colorFormat(0) | 126 , m_colorFormat(0) |
125 , m_internalRenderbufferFormat(0) | 127 , m_internalRenderbufferFormat(0) |
126 , m_maxTextureSize(0) | 128 , m_maxTextureSize(0) |
| 129 , m_sampleCount(4) |
127 , m_packAlignment(4) | 130 , m_packAlignment(4) |
128 , m_contextEvictionManager(contextEvictionManager) | 131 , m_contextEvictionManager(contextEvictionManager) |
129 { | 132 { |
130 // Used by browser tests to detect the use of a DrawingBuffer. | 133 // Used by browser tests to detect the use of a DrawingBuffer. |
131 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation"); | 134 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation"); |
132 initialize(size); | |
133 } | 135 } |
134 | 136 |
135 DrawingBuffer::~DrawingBuffer() | 137 DrawingBuffer::~DrawingBuffer() |
136 { | 138 { |
137 releaseResources(); | 139 releaseResources(); |
138 } | 140 } |
139 | 141 |
140 void DrawingBuffer::markContentsChanged() | 142 void DrawingBuffer::markContentsChanged() |
141 { | 143 { |
142 m_contentsChanged = true; | 144 m_contentsChanged = true; |
143 m_contentsChangeCommitted = false; | 145 m_contentsChangeCommitted = false; |
144 m_layerComposited = false; | 146 m_layerComposited = false; |
145 } | 147 } |
146 | 148 |
147 bool DrawingBuffer::layerComposited() const | 149 bool DrawingBuffer::layerComposited() const |
148 { | 150 { |
149 return m_layerComposited; | 151 return m_layerComposited; |
150 } | 152 } |
151 | 153 |
152 void DrawingBuffer::markLayerComposited() | 154 void DrawingBuffer::markLayerComposited() |
153 { | 155 { |
154 m_layerComposited = true; | 156 m_layerComposited = true; |
155 } | 157 } |
156 | 158 |
157 blink::WebGraphicsContext3D* DrawingBuffer::context() | 159 blink::WebGraphicsContext3D* DrawingBuffer::context() |
158 { | 160 { |
159 return m_context; | 161 return m_context.get(); |
160 } | 162 } |
161 | 163 |
162 bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox,
blink::WebExternalBitmap* bitmap) | 164 bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox,
blink::WebExternalBitmap* bitmap) |
163 { | 165 { |
164 if (!m_context || !m_contentsChanged) | 166 if (!m_contentsChanged) |
165 return false; | 167 return false; |
166 | 168 |
167 m_context->makeContextCurrent(); | 169 m_context->makeContextCurrent(); |
168 | 170 |
169 // Resolve the multisampled buffer into m_colorBuffer texture. | 171 // Resolve the multisampled buffer into m_colorBuffer texture. |
170 if (multisample()) | 172 if (multisample()) |
171 commit(); | 173 commit(); |
172 | 174 |
173 if (bitmap) { | 175 if (bitmap) { |
174 bitmap->setSize(size()); | 176 bitmap->setSize(size()); |
175 | 177 |
176 unsigned char* pixels = bitmap->pixels(); | 178 unsigned char* pixels = bitmap->pixels(); |
177 bool needPremultiply = m_attributes.alpha && !m_attributes.premultiplied
Alpha; | 179 bool needPremultiply = m_attributes.alpha && !m_attributes.premultiplied
Alpha; |
178 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; | 180 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; |
179 if (pixels) | 181 if (pixels) |
180 readBackFramebuffer(pixels, size().width(), size().height(), Readbac
kSkia, op); | 182 readBackFramebuffer(pixels, size().width(), size().height(), Readbac
kSkia, op); |
181 } | 183 } |
182 | 184 |
183 // We must restore the texture binding since creating new textures, | 185 // We must restore the texture binding since creating new textures, |
184 // consuming and producing mailboxes changes it. | 186 // consuming and producing mailboxes changes it. |
185 ScopedTextureUnit0BindingRestorer restorer(m_context, m_activeTextureUnit, m
_texture2DBinding); | 187 ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureU
nit, m_texture2DBinding); |
186 | 188 |
187 // First try to recycle an old buffer. | 189 // First try to recycle an old buffer. |
188 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); | 190 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); |
189 | 191 |
190 // No buffer available to recycle, create a new one. | 192 // No buffer available to recycle, create a new one. |
191 if (!frontColorBufferMailbox) { | 193 if (!frontColorBufferMailbox) { |
192 unsigned newColorBuffer = createColorTexture(m_size); | 194 unsigned newColorBuffer = createColorTexture(m_size); |
193 // Bad things happened, abandon ship. | 195 // Bad things happened, abandon ship. |
194 if (!newColorBuffer) | 196 if (!newColorBuffer) |
195 return false; | 197 return false; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 mailboxInfo->mailbox.syncPoint = mailbox.syncPoint; | 237 mailboxInfo->mailbox.syncPoint = mailbox.syncPoint; |
236 m_recycledMailboxes.prepend(mailboxInfo.release()); | 238 m_recycledMailboxes.prepend(mailboxInfo.release()); |
237 return; | 239 return; |
238 } | 240 } |
239 } | 241 } |
240 ASSERT_NOT_REACHED(); | 242 ASSERT_NOT_REACHED(); |
241 } | 243 } |
242 | 244 |
243 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() | 245 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() |
244 { | 246 { |
245 if (!m_context || m_recycledMailboxes.isEmpty()) | 247 if (m_recycledMailboxes.isEmpty()) |
246 return PassRefPtr<MailboxInfo>(); | 248 return PassRefPtr<MailboxInfo>(); |
247 | 249 |
248 RefPtr<MailboxInfo> mailboxInfo = m_recycledMailboxes.last().release(); | 250 RefPtr<MailboxInfo> mailboxInfo = m_recycledMailboxes.last().release(); |
249 m_recycledMailboxes.removeLast(); | 251 m_recycledMailboxes.removeLast(); |
250 | 252 |
251 if (mailboxInfo->mailbox.syncPoint) { | 253 if (mailboxInfo->mailbox.syncPoint) { |
252 m_context->waitSyncPoint(mailboxInfo->mailbox.syncPoint); | 254 m_context->waitSyncPoint(mailboxInfo->mailbox.syncPoint); |
253 mailboxInfo->mailbox.syncPoint = 0; | 255 mailboxInfo->mailbox.syncPoint = 0; |
254 } | 256 } |
255 | 257 |
256 if (mailboxInfo->size != m_size) { | 258 if (mailboxInfo->size != m_size) { |
257 m_context->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId); | 259 m_context->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId); |
258 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.w
idth(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); | 260 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.w
idth(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
259 mailboxInfo->size = m_size; | 261 mailboxInfo->size = m_size; |
260 } | 262 } |
261 | 263 |
262 return mailboxInfo.release(); | 264 return mailboxInfo.release(); |
263 } | 265 } |
264 | 266 |
265 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(unsigned
textureId) | 267 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(unsigned
textureId) |
266 { | 268 { |
267 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); | 269 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); |
268 m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); | 270 m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); |
269 returnMailbox->textureId = textureId; | 271 returnMailbox->textureId = textureId; |
270 returnMailbox->size = m_size; | 272 returnMailbox->size = m_size; |
271 m_textureMailboxes.append(returnMailbox); | 273 m_textureMailboxes.append(returnMailbox); |
272 return returnMailbox.release(); | 274 return returnMailbox.release(); |
273 } | 275 } |
274 | 276 |
275 void DrawingBuffer::initialize(const IntSize& size) | 277 bool DrawingBuffer::initialize(const IntSize& size) |
276 { | 278 { |
277 ASSERT(m_context); | |
278 m_attributes = m_context->getContextAttributes(); | 279 m_attributes = m_context->getContextAttributes(); |
279 | 280 |
280 if (m_attributes.alpha) { | 281 if (m_attributes.alpha) { |
281 m_internalColorFormat = GL_RGBA; | 282 m_internalColorFormat = GL_RGBA; |
282 m_colorFormat = GL_RGBA; | 283 m_colorFormat = GL_RGBA; |
283 m_internalRenderbufferFormat = GL_RGBA8_OES; | 284 m_internalRenderbufferFormat = GL_RGBA8_OES; |
284 } else { | 285 } else { |
285 m_internalColorFormat = GL_RGB; | 286 m_internalColorFormat = GL_RGB; |
286 m_colorFormat = GL_RGB; | 287 m_colorFormat = GL_RGB; |
287 m_internalRenderbufferFormat = GL_RGB8_OES; | 288 m_internalRenderbufferFormat = GL_RGB8_OES; |
288 } | 289 } |
289 | 290 |
290 m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); | 291 m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); |
291 | 292 |
292 int maxSampleCount = 0; | 293 int maxSampleCount = 0; |
293 if (multisample()) | 294 if (multisample()) |
294 m_context->getIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); | 295 m_context->getIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); |
295 m_sampleCount = std::min(4, maxSampleCount); | 296 m_sampleCount = std::min(4, maxSampleCount); |
296 | 297 |
297 m_fbo = m_context->createFramebuffer(); | 298 m_fbo = m_context->createFramebuffer(); |
298 | 299 |
299 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 300 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
300 m_colorBuffer = createColorTexture(); | 301 m_colorBuffer = createColorTexture(); |
301 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEX
TURE_2D, m_colorBuffer, 0); | 302 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEX
TURE_2D, m_colorBuffer, 0); |
302 createSecondaryBuffers(); | 303 createSecondaryBuffers(); |
303 reset(size); | 304 return reset(size); |
304 } | 305 } |
305 | 306 |
306 bool DrawingBuffer::copyToPlatformTexture(blink::WebGraphicsContext3D* context,
Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, b
ool premultiplyAlpha, bool flipY) | 307 bool DrawingBuffer::copyToPlatformTexture(blink::WebGraphicsContext3D* context,
Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, b
ool premultiplyAlpha, bool flipY) |
307 { | 308 { |
308 if (!m_context || !m_context->makeContextCurrent()) | 309 if (!m_context->makeContextCurrent()) |
309 return false; | 310 return false; |
310 if (m_contentsChanged) { | 311 if (m_contentsChanged) { |
311 if (multisample()) { | 312 if (multisample()) { |
312 commit(); | 313 commit(); |
313 if (!m_framebufferBinding) | 314 if (!m_framebufferBinding) |
314 bind(); | 315 bind(); |
315 else | 316 else |
316 restoreFramebufferBinding(); | 317 restoreFramebufferBinding(); |
317 } | 318 } |
318 m_context->flush(); | 319 m_context->flush(); |
(...skipping 25 matching lines...) Expand all Loading... |
344 return true; | 345 return true; |
345 } | 346 } |
346 | 347 |
347 Platform3DObject DrawingBuffer::framebuffer() const | 348 Platform3DObject DrawingBuffer::framebuffer() const |
348 { | 349 { |
349 return m_fbo; | 350 return m_fbo; |
350 } | 351 } |
351 | 352 |
352 blink::WebLayer* DrawingBuffer::platformLayer() | 353 blink::WebLayer* DrawingBuffer::platformLayer() |
353 { | 354 { |
354 if (!m_context) | |
355 return 0; | |
356 | |
357 if (!m_layer) { | 355 if (!m_layer) { |
358 m_layer = adoptPtr(blink::Platform::current()->compositorSupport()->crea
teExternalTextureLayer(this)); | 356 m_layer = adoptPtr(blink::Platform::current()->compositorSupport()->crea
teExternalTextureLayer(this)); |
359 | 357 |
360 m_layer->setOpaque(!m_attributes.alpha); | 358 m_layer->setOpaque(!m_attributes.alpha); |
361 m_layer->setBlendBackgroundColor(m_attributes.alpha); | 359 m_layer->setBlendBackgroundColor(m_attributes.alpha); |
362 m_layer->setPremultipliedAlpha(m_attributes.premultipliedAlpha); | 360 m_layer->setPremultipliedAlpha(m_attributes.premultipliedAlpha); |
363 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 361 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
364 } | 362 } |
365 | 363 |
366 return m_layer->layer(); | 364 return m_layer->layer(); |
367 } | 365 } |
368 | 366 |
369 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) | 367 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) |
370 { | 368 { |
371 if (!m_context || !m_context->makeContextCurrent() || m_context->getGraphics
ResetStatusARB() != GL_NO_ERROR) | 369 if (!m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB
() != GL_NO_ERROR) |
372 return; | 370 return; |
373 | 371 |
374 if (!imageBuffer) | 372 if (!imageBuffer) |
375 return; | 373 return; |
376 Platform3DObject tex = imageBuffer->getBackingTexture(); | 374 Platform3DObject tex = imageBuffer->getBackingTexture(); |
377 if (tex) { | 375 if (tex) { |
378 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer, | 376 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer, |
379 tex, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 377 tex, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
380 return; | 378 return; |
381 } | 379 } |
(...skipping 20 matching lines...) Expand all Loading... |
402 m_context->deleteTexture(sourceTexture); | 400 m_context->deleteTexture(sourceTexture); |
403 | 401 |
404 m_context->bindFramebuffer(GL_FRAMEBUFFER, previousFramebuffer); | 402 m_context->bindFramebuffer(GL_FRAMEBUFFER, previousFramebuffer); |
405 } | 403 } |
406 | 404 |
407 void DrawingBuffer::clearPlatformLayer() | 405 void DrawingBuffer::clearPlatformLayer() |
408 { | 406 { |
409 if (m_layer) | 407 if (m_layer) |
410 m_layer->clearTexture(); | 408 m_layer->clearTexture(); |
411 | 409 |
412 if (m_context) | 410 m_context->flush(); |
413 m_context->flush(); | |
414 } | 411 } |
415 | 412 |
416 void DrawingBuffer::releaseResources() | 413 void DrawingBuffer::releaseResources() |
417 { | 414 { |
418 if (m_context) { | 415 m_context->makeContextCurrent(); |
419 m_context->makeContextCurrent(); | |
420 | 416 |
421 clearPlatformLayer(); | 417 clearPlatformLayer(); |
422 | 418 |
423 for (size_t i = 0; i < m_textureMailboxes.size(); i++) | 419 for (size_t i = 0; i < m_textureMailboxes.size(); i++) |
424 m_context->deleteTexture(m_textureMailboxes[i]->textureId); | 420 m_context->deleteTexture(m_textureMailboxes[i]->textureId); |
425 | 421 |
426 if (m_multisampleColorBuffer) | 422 if (m_multisampleColorBuffer) |
427 m_context->deleteRenderbuffer(m_multisampleColorBuffer); | 423 m_context->deleteRenderbuffer(m_multisampleColorBuffer); |
428 | 424 |
429 if (m_depthStencilBuffer) | 425 if (m_depthStencilBuffer) |
430 m_context->deleteRenderbuffer(m_depthStencilBuffer); | 426 m_context->deleteRenderbuffer(m_depthStencilBuffer); |
431 | 427 |
432 if (m_depthBuffer) | 428 if (m_depthBuffer) |
433 m_context->deleteRenderbuffer(m_depthBuffer); | 429 m_context->deleteRenderbuffer(m_depthBuffer); |
434 | 430 |
435 if (m_stencilBuffer) | 431 if (m_stencilBuffer) |
436 m_context->deleteRenderbuffer(m_stencilBuffer); | 432 m_context->deleteRenderbuffer(m_stencilBuffer); |
437 | 433 |
438 if (m_multisampleFBO) | 434 if (m_multisampleFBO) |
439 m_context->deleteFramebuffer(m_multisampleFBO); | 435 m_context->deleteFramebuffer(m_multisampleFBO); |
440 | 436 |
441 if (m_fbo) | 437 if (m_fbo) |
442 m_context->deleteFramebuffer(m_fbo); | 438 m_context->deleteFramebuffer(m_fbo); |
443 | 439 |
444 m_context = 0; | 440 m_context.clear(); |
445 } | |
446 | 441 |
447 setSize(IntSize()); | 442 setSize(IntSize()); |
448 | 443 |
449 m_colorBuffer = 0; | 444 m_colorBuffer = 0; |
450 m_frontColorBuffer = 0; | 445 m_frontColorBuffer = 0; |
451 m_multisampleColorBuffer = 0; | 446 m_multisampleColorBuffer = 0; |
452 m_depthStencilBuffer = 0; | 447 m_depthStencilBuffer = 0; |
453 m_depthBuffer = 0; | 448 m_depthBuffer = 0; |
454 m_stencilBuffer = 0; | 449 m_stencilBuffer = 0; |
455 m_multisampleFBO = 0; | 450 m_multisampleFBO = 0; |
456 m_fbo = 0; | 451 m_fbo = 0; |
457 m_contextEvictionManager.clear(); | 452 m_contextEvictionManager.clear(); |
458 | 453 |
459 m_recycledMailboxes.clear(); | 454 m_recycledMailboxes.clear(); |
460 m_textureMailboxes.clear(); | 455 m_textureMailboxes.clear(); |
461 | 456 |
462 if (m_layer) { | 457 if (m_layer) { |
463 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 458 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |
464 m_layer.clear(); | 459 m_layer.clear(); |
465 } | 460 } |
466 } | 461 } |
467 | 462 |
468 unsigned DrawingBuffer::createColorTexture(const IntSize& size) | 463 unsigned DrawingBuffer::createColorTexture(const IntSize& size) |
469 { | 464 { |
470 if (!m_context) | |
471 return 0; | |
472 | |
473 unsigned offscreenColorTexture = m_context->createTexture(); | 465 unsigned offscreenColorTexture = m_context->createTexture(); |
474 if (!offscreenColorTexture) | 466 if (!offscreenColorTexture) |
475 return 0; | 467 return 0; |
476 | 468 |
477 m_context->bindTexture(GL_TEXTURE_2D, offscreenColorTexture); | 469 m_context->bindTexture(GL_TEXTURE_2D, offscreenColorTexture); |
478 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 470 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
479 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 471 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
480 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
; | 472 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
; |
481 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
; | 473 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
; |
482 if (!size.isEmpty()) | 474 if (!size.isEmpty()) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACH
MENT, GL_RENDERBUFFER, m_stencilBuffer); | 562 m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACH
MENT, GL_RENDERBUFFER, m_stencilBuffer); |
571 } | 563 } |
572 } | 564 } |
573 m_context->bindRenderbuffer(GL_RENDERBUFFER, 0); | 565 m_context->bindRenderbuffer(GL_RENDERBUFFER, 0); |
574 } | 566 } |
575 | 567 |
576 | 568 |
577 | 569 |
578 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) | 570 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) |
579 { | 571 { |
580 if (!m_context) | |
581 return; | |
582 | |
583 // We will clear the multisample FBO, but we also need to clear the non-mult
isampled buffer too. | 572 // We will clear the multisample FBO, but we also need to clear the non-mult
isampled buffer too. |
584 if (m_multisampleFBO) { | 573 if (m_multisampleFBO) { |
585 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 574 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
586 m_context->clear(GL_COLOR_BUFFER_BIT); | 575 m_context->clear(GL_COLOR_BUFFER_BIT); |
587 } | 576 } |
588 | 577 |
589 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); | 578 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); |
590 m_context->clear(clearMask); | 579 m_context->clear(clearMask); |
591 } | 580 } |
592 | 581 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 int pixelDelta = oldestSize.width() * oldestSize.height(); | 629 int pixelDelta = oldestSize.width() * oldestSize.height(); |
641 | 630 |
642 s_currentResourceUsePixels -= pixelDelta; | 631 s_currentResourceUsePixels -= pixelDelta; |
643 adjustedSize = adjustSize(size); | 632 adjustedSize = adjustSize(size); |
644 s_currentResourceUsePixels += pixelDelta; | 633 s_currentResourceUsePixels += pixelDelta; |
645 | 634 |
646 evictContext = !adjustedSize.isEmpty(); | 635 evictContext = !adjustedSize.isEmpty(); |
647 return adjustedSize; | 636 return adjustedSize; |
648 } | 637 } |
649 | 638 |
650 void DrawingBuffer::reset(const IntSize& newSize) | 639 bool DrawingBuffer::reset(const IntSize& newSize) |
651 { | 640 { |
652 if (!m_context) | 641 ASSERT(!newSize.isEmpty()); |
653 return; | |
654 | |
655 IntSize adjustedSize; | 642 IntSize adjustedSize; |
656 bool evictContext = false; | 643 bool evictContext = false; |
657 bool isNewContext = m_size.isEmpty(); | 644 bool isNewContext = m_size.isEmpty(); |
658 if (s_allowContextEvictionOnCreate && isNewContext) | 645 if (s_allowContextEvictionOnCreate && isNewContext) |
659 adjustedSize = adjustSizeWithContextEviction(newSize, evictContext); | 646 adjustedSize = adjustSizeWithContextEviction(newSize, evictContext); |
660 else | 647 else |
661 adjustedSize = adjustSize(newSize); | 648 adjustedSize = adjustSize(newSize); |
662 | 649 |
663 if (adjustedSize.isEmpty()) | 650 if (adjustedSize.isEmpty()) |
664 return; | 651 return false; |
665 | 652 |
666 if (evictContext) | 653 if (evictContext) |
667 m_contextEvictionManager->forciblyLoseOldestContext("WARNING: WebGL cont
exts have exceeded the maximum allowed backbuffer area. Oldest context will be l
ost."); | 654 m_contextEvictionManager->forciblyLoseOldestContext("WARNING: WebGL cont
exts have exceeded the maximum allowed backbuffer area. Oldest context will be l
ost."); |
668 | 655 |
669 if (adjustedSize != m_size) { | 656 if (adjustedSize != m_size) { |
670 do { | 657 do { |
671 // resize multisample FBO | 658 // resize multisample FBO |
672 if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffe
r(adjustedSize)) { | 659 if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffe
r(adjustedSize)) { |
673 adjustedSize.scale(s_resourceAdjustedRatio); | 660 adjustedSize.scale(s_resourceAdjustedRatio); |
674 continue; | 661 continue; |
675 } | 662 } |
676 break; | 663 break; |
677 } while (!adjustedSize.isEmpty()); | 664 } while (!adjustedSize.isEmpty()); |
678 | 665 |
679 setSize(adjustedSize); | 666 setSize(adjustedSize); |
680 | 667 |
681 if (adjustedSize.isEmpty()) | 668 if (adjustedSize.isEmpty()) |
682 return; | 669 return false; |
683 } | 670 } |
684 | 671 |
685 m_context->disable(GL_SCISSOR_TEST); | 672 m_context->disable(GL_SCISSOR_TEST); |
686 m_context->clearColor(0, 0, 0, 0); | 673 m_context->clearColor(0, 0, 0, 0); |
687 m_context->colorMask(true, true, true, true); | 674 m_context->colorMask(true, true, true, true); |
688 | 675 |
689 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; | 676 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; |
690 if (m_attributes.depth) { | 677 if (m_attributes.depth) { |
691 m_context->clearDepth(1.0f); | 678 m_context->clearDepth(1.0f); |
692 clearMask |= GL_DEPTH_BUFFER_BIT; | 679 clearMask |= GL_DEPTH_BUFFER_BIT; |
693 m_context->depthMask(true); | 680 m_context->depthMask(true); |
694 } | 681 } |
695 if (m_attributes.stencil) { | 682 if (m_attributes.stencil) { |
696 m_context->clearStencil(0); | 683 m_context->clearStencil(0); |
697 clearMask |= GL_STENCIL_BUFFER_BIT; | 684 clearMask |= GL_STENCIL_BUFFER_BIT; |
698 m_context->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); | 685 m_context->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); |
699 } | 686 } |
700 | 687 |
701 clearFramebuffers(clearMask); | 688 clearFramebuffers(clearMask); |
| 689 return true; |
702 } | 690 } |
703 | 691 |
704 void DrawingBuffer::commit(long x, long y, long width, long height) | 692 void DrawingBuffer::commit(long x, long y, long width, long height) |
705 { | 693 { |
706 if (!m_context) | |
707 return; | |
708 | |
709 if (width < 0) | 694 if (width < 0) |
710 width = m_size.width(); | 695 width = m_size.width(); |
711 if (height < 0) | 696 if (height < 0) |
712 height = m_size.height(); | 697 height = m_size.height(); |
713 | 698 |
714 m_context->makeContextCurrent(); | 699 m_context->makeContextCurrent(); |
715 | 700 |
716 if (m_multisampleFBO && !m_contentsChangeCommitted) { | 701 if (m_multisampleFBO && !m_contentsChangeCommitted) { |
717 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); | 702 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); |
718 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); | 703 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); |
719 | 704 |
720 if (m_scissorEnabled) | 705 if (m_scissorEnabled) |
721 m_context->disable(GL_SCISSOR_TEST); | 706 m_context->disable(GL_SCISSOR_TEST); |
722 | 707 |
723 // Use NEAREST, because there is no scale performed during the blit. | 708 // Use NEAREST, because there is no scale performed during the blit. |
724 m_context->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, hei
ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); | 709 m_context->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, hei
ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
725 | 710 |
726 if (m_scissorEnabled) | 711 if (m_scissorEnabled) |
727 m_context->enable(GL_SCISSOR_TEST); | 712 m_context->enable(GL_SCISSOR_TEST); |
728 } | 713 } |
729 | 714 |
730 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 715 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
731 m_contentsChangeCommitted = true; | 716 m_contentsChangeCommitted = true; |
732 } | 717 } |
733 | 718 |
734 void DrawingBuffer::restoreFramebufferBinding() | 719 void DrawingBuffer::restoreFramebufferBinding() |
735 { | 720 { |
736 if (!m_context || !m_framebufferBinding) | 721 if (!m_framebufferBinding) |
737 return; | 722 return; |
738 | 723 |
739 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding); | 724 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding); |
740 } | 725 } |
741 | 726 |
742 bool DrawingBuffer::multisample() const | 727 bool DrawingBuffer::multisample() const |
743 { | 728 { |
744 return m_attributes.antialias && m_multisampleExtensionSupported; | 729 return m_attributes.antialias && m_multisampleExtensionSupported; |
745 } | 730 } |
746 | 731 |
747 void DrawingBuffer::bind() | 732 void DrawingBuffer::bind() |
748 { | 733 { |
749 if (!m_context) | |
750 return; | |
751 | |
752 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); | 734 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); |
753 } | 735 } |
754 | 736 |
755 void DrawingBuffer::setPackAlignment(GLint param) | 737 void DrawingBuffer::setPackAlignment(GLint param) |
756 { | 738 { |
757 m_packAlignment = param; | 739 m_packAlignment = param; |
758 } | 740 } |
759 | 741 |
760 void DrawingBuffer::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer) | 742 void DrawingBuffer::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer) |
761 { | 743 { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 } | 855 } |
874 } | 856 } |
875 | 857 |
876 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
type, GLint unpackAlignment) | 858 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
type, GLint unpackAlignment) |
877 { | 859 { |
878 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); | 860 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); |
879 m_context->texImage2D(target, level, internalformat, width, height, border,
format, type, 0); | 861 m_context->texImage2D(target, level, internalformat, width, height, border,
format, type, 0); |
880 } | 862 } |
881 | 863 |
882 } // namespace WebCore | 864 } // namespace WebCore |
OLD | NEW |