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

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

Issue 106503003: Changed GL enums from GraphicsContext3D to standard versions (Take 2) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years 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
« no previous file with comments | « Source/platform/graphics/filters/custom/FECustomFilter.cpp ('k') | Source/web/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 static const bool s_allowContextEvictionOnCreate = true; 56 static const bool s_allowContextEvictionOnCreate = true;
57 static const int s_maxScaleAttempts = 3; 57 static const int s_maxScaleAttempts = 3;
58 58
59 class ScopedTextureUnit0BindingRestorer { 59 class ScopedTextureUnit0BindingRestorer {
60 public: 60 public:
61 ScopedTextureUnit0BindingRestorer(GraphicsContext3D* context, GC3Denum activ eTextureUnit, Platform3DObject textureUnitZeroId) 61 ScopedTextureUnit0BindingRestorer(GraphicsContext3D* context, GC3Denum activ eTextureUnit, Platform3DObject textureUnitZeroId)
62 : m_context(context) 62 : m_context(context)
63 , m_oldActiveTextureUnit(activeTextureUnit) 63 , m_oldActiveTextureUnit(activeTextureUnit)
64 , m_oldTextureUnitZeroId(textureUnitZeroId) 64 , m_oldTextureUnitZeroId(textureUnitZeroId)
65 { 65 {
66 m_context->activeTexture(GraphicsContext3D::TEXTURE0); 66 m_context->activeTexture(GL_TEXTURE0);
67 } 67 }
68 ~ScopedTextureUnit0BindingRestorer() 68 ~ScopedTextureUnit0BindingRestorer()
69 { 69 {
70 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_oldTextureUnitZe roId); 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 GraphicsContext3D* m_context; 75 GraphicsContext3D* m_context;
76 GC3Denum m_oldActiveTextureUnit; 76 GC3Denum m_oldActiveTextureUnit;
77 Platform3DObject m_oldTextureUnitZeroId; 77 Platform3DObject m_oldTextureUnitZeroId;
78 }; 78 };
79 79
80 PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, cons t IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvictionManag er> contextEvictionManager) 80 PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, cons t IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvictionManag er> contextEvictionManager)
(...skipping 18 matching lines...) Expand all
99 DrawingBuffer::DrawingBuffer(GraphicsContext3D* context, 99 DrawingBuffer::DrawingBuffer(GraphicsContext3D* context,
100 const IntSize& size, 100 const IntSize& size,
101 bool multisampleExtensionSupported, 101 bool multisampleExtensionSupported,
102 bool packedDepthStencilExtensionSupported, 102 bool packedDepthStencilExtensionSupported,
103 PreserveDrawingBuffer preserve, 103 PreserveDrawingBuffer preserve,
104 PassRefPtr<ContextEvictionManager> contextEvictionM anager) 104 PassRefPtr<ContextEvictionManager> contextEvictionM anager)
105 : m_preserveDrawingBuffer(preserve) 105 : m_preserveDrawingBuffer(preserve)
106 , m_scissorEnabled(false) 106 , m_scissorEnabled(false)
107 , m_texture2DBinding(0) 107 , m_texture2DBinding(0)
108 , m_framebufferBinding(0) 108 , m_framebufferBinding(0)
109 , m_activeTextureUnit(GraphicsContext3D::TEXTURE0) 109 , m_activeTextureUnit(GL_TEXTURE0)
110 , m_context(context) 110 , m_context(context)
111 , m_size(-1, -1) 111 , m_size(-1, -1)
112 , m_multisampleExtensionSupported(multisampleExtensionSupported) 112 , m_multisampleExtensionSupported(multisampleExtensionSupported)
113 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte d) 113 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte d)
114 , m_fbo(0) 114 , m_fbo(0)
115 , m_colorBuffer(0) 115 , m_colorBuffer(0)
116 , m_frontColorBuffer(0) 116 , m_frontColorBuffer(0)
117 , m_depthStencilBuffer(0) 117 , m_depthStencilBuffer(0)
118 , m_depthBuffer(0) 118 , m_depthBuffer(0)
119 , m_stencilBuffer(0) 119 , m_stencilBuffer(0)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 nextFrontColorBuffer = createNewMailbox(newColorBuffer); 188 nextFrontColorBuffer = createNewMailbox(newColorBuffer);
189 } 189 }
190 190
191 if (m_preserveDrawingBuffer == Discard) { 191 if (m_preserveDrawingBuffer == Discard) {
192 m_colorBuffer = nextFrontColorBuffer->textureId; 192 m_colorBuffer = nextFrontColorBuffer->textureId;
193 swap(nextFrontColorBuffer, m_lastColorBuffer); 193 swap(nextFrontColorBuffer, m_lastColorBuffer);
194 // It appears safe to overwrite the context's framebuffer binding in the Discard case since there will always be a 194 // It appears safe to overwrite the context's framebuffer binding in the Discard case since there will always be a
195 // WebGLRenderingContext::clearIfComposited() call made before the next draw call which restores the framebuffer binding. 195 // WebGLRenderingContext::clearIfComposited() call made before the next draw call which restores the framebuffer binding.
196 // If this stops being true at some point, we should track the current f ramebuffer binding in the DrawingBuffer and restore 196 // If this stops being true at some point, we should track the current f ramebuffer binding in the DrawingBuffer and restore
197 // it after attaching the new back buffer here. 197 // it after attaching the new back buffer here.
198 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 198 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
199 m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, Graphics Context3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0); 199 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL _TEXTURE_2D, m_colorBuffer, 0);
200 } else { 200 } else {
201 Extensions3D* extensions = m_context->extensions(); 201 Extensions3D* extensions = m_context->extensions();
202 extensions->copyTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D, m_colorBu ffer, nextFrontColorBuffer->textureId, 0, GraphicsContext3D::RGBA, GraphicsConte xt3D::UNSIGNED_BYTE); 202 extensions->copyTextureCHROMIUM(GL_TEXTURE_2D, m_colorBuffer, nextFrontC olorBuffer->textureId, 0, GL_RGBA, GL_UNSIGNED_BYTE);
203 } 203 }
204 204
205 if (multisample() && !m_framebufferBinding) 205 if (multisample() && !m_framebufferBinding)
206 bind(); 206 bind();
207 else 207 else
208 restoreFramebufferBinding(); 208 restoreFramebufferBinding();
209 209
210 m_contentsChanged = false; 210 m_contentsChanged = false;
211 211
212 context()->bindTexture(GraphicsContext3D::TEXTURE_2D, nextFrontColorBuffer-> textureId); 212 context()->bindTexture(GL_TEXTURE_2D, nextFrontColorBuffer->textureId);
213 context()->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D, nextFrontCo lorBuffer->mailbox.name); 213 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, nextFrontColorBuffer->mailb ox.name);
214 context()->flush(); 214 context()->flush();
215 m_context->markLayerComposited(); 215 m_context->markLayerComposited();
216 216
217 *outMailbox = nextFrontColorBuffer->mailbox; 217 *outMailbox = nextFrontColorBuffer->mailbox;
218 m_frontColorBuffer = nextFrontColorBuffer->textureId; 218 m_frontColorBuffer = nextFrontColorBuffer->textureId;
219 return true; 219 return true;
220 } 220 }
221 221
222 void DrawingBuffer::mailboxReleased(const blink::WebExternalTextureMailbox& mail box) 222 void DrawingBuffer::mailboxReleased(const blink::WebExternalTextureMailbox& mail box)
223 { 223 {
(...skipping 14 matching lines...) Expand all
238 return PassRefPtr<MailboxInfo>(); 238 return PassRefPtr<MailboxInfo>();
239 239
240 RefPtr<MailboxInfo> mailboxInfo = m_recycledMailboxes.last().release(); 240 RefPtr<MailboxInfo> mailboxInfo = m_recycledMailboxes.last().release();
241 m_recycledMailboxes.removeLast(); 241 m_recycledMailboxes.removeLast();
242 242
243 if (mailboxInfo->mailbox.syncPoint) { 243 if (mailboxInfo->mailbox.syncPoint) {
244 context()->waitSyncPoint(mailboxInfo->mailbox.syncPoint); 244 context()->waitSyncPoint(mailboxInfo->mailbox.syncPoint);
245 mailboxInfo->mailbox.syncPoint = 0; 245 mailboxInfo->mailbox.syncPoint = 0;
246 } 246 }
247 247
248 context()->bindTexture(GraphicsContext3D::TEXTURE_2D, mailboxInfo->textureId ); 248 context()->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId);
249 context()->consumeTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D, mailboxInfo ->mailbox.name); 249 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailboxInfo->mailbox.name);
250 250
251 if (mailboxInfo->size != m_size) { 251 if (mailboxInfo->size != m_size) {
252 m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, m_in ternalColorFormat, m_size.width(), m_size.height(), 0, m_colorFormat, GraphicsCo ntext3D::UNSIGNED_BYTE); 252 m_context->texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorForma t, m_size.width(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE);
253 mailboxInfo->size = m_size; 253 mailboxInfo->size = m_size;
254 } 254 }
255 255
256 return mailboxInfo.release(); 256 return mailboxInfo.release();
257 } 257 }
258 258
259 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(unsigned textureId) 259 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(unsigned textureId)
260 { 260 {
261 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); 261 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo());
262 context()->genMailboxCHROMIUM(returnMailbox->mailbox.name); 262 context()->genMailboxCHROMIUM(returnMailbox->mailbox.name);
263 returnMailbox->textureId = textureId; 263 returnMailbox->textureId = textureId;
264 returnMailbox->size = m_size; 264 returnMailbox->size = m_size;
265 m_textureMailboxes.append(returnMailbox); 265 m_textureMailboxes.append(returnMailbox);
266 return returnMailbox.release(); 266 return returnMailbox.release();
267 } 267 }
268 268
269 void DrawingBuffer::initialize(const IntSize& size) 269 void DrawingBuffer::initialize(const IntSize& size)
270 { 270 {
271 ASSERT(m_context); 271 ASSERT(m_context);
272 m_attributes = m_context->getContextAttributes(); 272 m_attributes = m_context->getContextAttributes();
273 273
274 if (m_attributes.alpha) { 274 if (m_attributes.alpha) {
275 m_internalColorFormat = GraphicsContext3D::RGBA; 275 m_internalColorFormat = GL_RGBA;
276 m_colorFormat = GraphicsContext3D::RGBA; 276 m_colorFormat = GL_RGBA;
277 m_internalRenderbufferFormat = Extensions3D::RGBA8_OES; 277 m_internalRenderbufferFormat = Extensions3D::RGBA8_OES;
278 } else { 278 } else {
279 m_internalColorFormat = GraphicsContext3D::RGB; 279 m_internalColorFormat = GL_RGB;
280 m_colorFormat = GraphicsContext3D::RGB; 280 m_colorFormat = GL_RGB;
281 m_internalRenderbufferFormat = Extensions3D::RGB8_OES; 281 m_internalRenderbufferFormat = Extensions3D::RGB8_OES;
282 } 282 }
283 283
284 m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &m_maxTextureSiz e); 284 m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize);
285 285
286 m_fbo = m_context->createFramebuffer(); 286 m_fbo = m_context->createFramebuffer();
287 287
288 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 288 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
289 m_colorBuffer = createColorTexture(); 289 m_colorBuffer = createColorTexture();
290 m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsCont ext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0); 290 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEX TURE_2D, m_colorBuffer, 0);
291 createSecondaryBuffers(); 291 createSecondaryBuffers();
292 reset(size); 292 reset(size);
293 m_lastColorBuffer = createNewMailbox(m_colorBuffer); 293 m_lastColorBuffer = createNewMailbox(m_colorBuffer);
294 } 294 }
295 295
296 unsigned DrawingBuffer::frontColorBuffer() const 296 unsigned DrawingBuffer::frontColorBuffer() const
297 { 297 {
298 return m_frontColorBuffer; 298 return m_frontColorBuffer;
299 } 299 }
300 300
(...skipping 23 matching lines...) Expand all
324 bool unpackPremultiplyAlphaNeeded = false; 324 bool unpackPremultiplyAlphaNeeded = false;
325 bool unpackUnpremultiplyAlphaNeeded = false; 325 bool unpackUnpremultiplyAlphaNeeded = false;
326 if (m_attributes.alpha && m_attributes.premultipliedAlpha && !premultiplyAlp ha) 326 if (m_attributes.alpha && m_attributes.premultipliedAlpha && !premultiplyAlp ha)
327 unpackUnpremultiplyAlphaNeeded = true; 327 unpackUnpremultiplyAlphaNeeded = true;
328 else if (m_attributes.alpha && !m_attributes.premultipliedAlpha && premultip lyAlpha) 328 else if (m_attributes.alpha && !m_attributes.premultipliedAlpha && premultip lyAlpha)
329 unpackPremultiplyAlphaNeeded = true; 329 unpackPremultiplyAlphaNeeded = true;
330 330
331 context.pixelStorei(Extensions3D::UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, unpac kUnpremultiplyAlphaNeeded); 331 context.pixelStorei(Extensions3D::UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, unpac kUnpremultiplyAlphaNeeded);
332 context.pixelStorei(Extensions3D::UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, unpackP remultiplyAlphaNeeded); 332 context.pixelStorei(Extensions3D::UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, unpackP remultiplyAlphaNeeded);
333 context.pixelStorei(Extensions3D::UNPACK_FLIP_Y_CHROMIUM, flipY); 333 context.pixelStorei(Extensions3D::UNPACK_FLIP_Y_CHROMIUM, flipY);
334 extensions->copyTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D, sourceTexture , texture, level, internalFormat, destType); 334 extensions->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, texture, level , internalFormat, destType);
335 context.pixelStorei(Extensions3D::UNPACK_FLIP_Y_CHROMIUM, false); 335 context.pixelStorei(Extensions3D::UNPACK_FLIP_Y_CHROMIUM, false);
336 context.pixelStorei(Extensions3D::UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, false ); 336 context.pixelStorei(Extensions3D::UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, false );
337 context.pixelStorei(Extensions3D::UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, false); 337 context.pixelStorei(Extensions3D::UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, false);
338 context.flush(); 338 context.flush();
339 339
340 return true; 340 return true;
341 } 341 }
342 342
343 Platform3DObject DrawingBuffer::framebuffer() const 343 Platform3DObject DrawingBuffer::framebuffer() const
344 { 344 {
(...skipping 12 matching lines...) Expand all
357 m_layer->setBlendBackgroundColor(m_attributes.alpha); 357 m_layer->setBlendBackgroundColor(m_attributes.alpha);
358 m_layer->setPremultipliedAlpha(m_attributes.premultipliedAlpha); 358 m_layer->setPremultipliedAlpha(m_attributes.premultipliedAlpha);
359 GraphicsLayer::registerContentsLayer(m_layer->layer()); 359 GraphicsLayer::registerContentsLayer(m_layer->layer());
360 } 360 }
361 361
362 return m_layer->layer(); 362 return m_layer->layer();
363 } 363 }
364 364
365 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) 365 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer)
366 { 366 {
367 if (!m_context || !m_context->makeContextCurrent() || m_context->extensions( )->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR) 367 if (!m_context || !m_context->makeContextCurrent() || m_context->extensions( )->getGraphicsResetStatusARB() != GL_NO_ERROR)
368 return; 368 return;
369 369
370 Extensions3D* extensions = m_context->extensions(); 370 Extensions3D* extensions = m_context->extensions();
371 371
372 if (!imageBuffer) 372 if (!imageBuffer)
373 return; 373 return;
374 Platform3DObject tex = imageBuffer->getBackingTexture(); 374 Platform3DObject tex = imageBuffer->getBackingTexture();
375 if (tex) { 375 if (tex) {
376 extensions->copyTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D, m_frontCo lorBuffer, 376 extensions->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer,
377 tex, 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE); 377 tex, 0, GL_RGBA, GL_UNSIGNED_BYTE);
378 return; 378 return;
379 } 379 }
380 380
381 // Since the m_frontColorBuffer was produced and sent to the compositor, it cannot be bound to an fbo. 381 // Since the m_frontColorBuffer was produced and sent to the compositor, it cannot be bound to an fbo.
382 // We have to make a copy of it here and bind that copy instead. 382 // We have to make a copy of it here and bind that copy instead.
383 // FIXME: That's not true any more, provided we don't change texture 383 // FIXME: That's not true any more, provided we don't change texture
384 // parameters. 384 // parameters.
385 unsigned sourceTexture = createColorTexture(m_size); 385 unsigned sourceTexture = createColorTexture(m_size);
386 extensions->copyTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D, m_frontColorB uffer, sourceTexture, 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BY TE); 386 extensions->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer, sourceTex ture, 0, GL_RGBA, GL_UNSIGNED_BYTE);
387 387
388 // Since we're using the same context as WebGL, we have to restore any state we change (in this case, just the framebuffer binding). 388 // Since we're using the same context as WebGL, we have to restore any state we change (in this case, just the framebuffer binding).
389 // FIXME: The WebGLRenderingContext tracks the current framebuffer binding, it would be slightly more efficient to use this value 389 // FIXME: The WebGLRenderingContext tracks the current framebuffer binding, it would be slightly more efficient to use this value
390 // rather than querying it off of the context. 390 // rather than querying it off of the context.
391 GC3Dint previousFramebuffer = 0; 391 GC3Dint previousFramebuffer = 0;
392 m_context->getIntegerv(GraphicsContext3D::FRAMEBUFFER_BINDING, &previousFram ebuffer); 392 m_context->getIntegerv(GL_FRAMEBUFFER_BINDING, &previousFramebuffer);
393 393
394 Platform3DObject framebuffer = m_context->createFramebuffer(); 394 Platform3DObject framebuffer = m_context->createFramebuffer();
395 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, framebuffer); 395 m_context->bindFramebuffer(GL_FRAMEBUFFER, framebuffer);
396 m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsCont ext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, sourceTexture, 0); 396 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEX TURE_2D, sourceTexture, 0);
397 397
398 extensions->paintFramebufferToCanvas(framebuffer, size().width(), size().hei ght(), !m_attributes.premultipliedAlpha, imageBuffer); 398 extensions->paintFramebufferToCanvas(framebuffer, size().width(), size().hei ght(), !m_attributes.premultipliedAlpha, imageBuffer);
399 m_context->deleteFramebuffer(framebuffer); 399 m_context->deleteFramebuffer(framebuffer);
400 m_context->deleteTexture(sourceTexture); 400 m_context->deleteTexture(sourceTexture);
401 401
402 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, previousFramebuff er); 402 m_context->bindFramebuffer(GL_FRAMEBUFFER, previousFramebuffer);
403 } 403 }
404 404
405 void DrawingBuffer::clearPlatformLayer() 405 void DrawingBuffer::clearPlatformLayer()
406 { 406 {
407 if (m_layer) 407 if (m_layer)
408 m_layer->clearTexture(); 408 m_layer->clearTexture();
409 409
410 if (m_context) 410 if (m_context)
411 m_context->flush(); 411 m_context->flush();
412 } 412 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 466
467 unsigned DrawingBuffer::createColorTexture(const IntSize& size) 467 unsigned DrawingBuffer::createColorTexture(const IntSize& size)
468 { 468 {
469 if (!m_context) 469 if (!m_context)
470 return 0; 470 return 0;
471 471
472 unsigned offscreenColorTexture = m_context->createTexture(); 472 unsigned offscreenColorTexture = m_context->createTexture();
473 if (!offscreenColorTexture) 473 if (!offscreenColorTexture)
474 return 0; 474 return 0;
475 475
476 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, offscreenColorTexture) ; 476 m_context->bindTexture(GL_TEXTURE_2D, offscreenColorTexture);
477 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::T EXTURE_MAG_FILTER, GraphicsContext3D::LINEAR); 477 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
478 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::T EXTURE_MIN_FILTER, GraphicsContext3D::LINEAR); 478 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
479 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::T EXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); 479 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) ;
480 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::T EXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); 480 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) ;
481 if (!size.isEmpty()) 481 if (!size.isEmpty())
482 m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, m_in ternalColorFormat, size.width(), size.height(), 0, m_colorFormat, GraphicsContex t3D::UNSIGNED_BYTE); 482 m_context->texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorForma t, size.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE);
483 483
484 return offscreenColorTexture; 484 return offscreenColorTexture;
485 } 485 }
486 486
487 void DrawingBuffer::createSecondaryBuffers() 487 void DrawingBuffer::createSecondaryBuffers()
488 { 488 {
489 // create a multisample FBO 489 // create a multisample FBO
490 if (multisample()) { 490 if (multisample()) {
491 m_multisampleFBO = m_context->createFramebuffer(); 491 m_multisampleFBO = m_context->createFramebuffer();
492 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisample FBO); 492 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
493 m_multisampleColorBuffer = m_context->createRenderbuffer(); 493 m_multisampleColorBuffer = m_context->createRenderbuffer();
494 } 494 }
495 } 495 }
496 496
497 bool DrawingBuffer::resizeFramebuffer(const IntSize& size) 497 bool DrawingBuffer::resizeFramebuffer(const IntSize& size)
498 { 498 {
499 // resize regular FBO 499 // resize regular FBO
500 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 500 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
501 501
502 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer); 502 m_context->bindTexture(GL_TEXTURE_2D, m_colorBuffer);
503 m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, m_intern alColorFormat, size.width(), size.height(), 0, m_colorFormat, GraphicsContext3D: :UNSIGNED_BYTE); 503 m_context->texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, s ize.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE);
504 if (m_lastColorBuffer) 504 if (m_lastColorBuffer)
505 m_lastColorBuffer->size = size; 505 m_lastColorBuffer->size = size;
506 506
507 m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsCont ext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0); 507 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEX TURE_2D, m_colorBuffer, 0);
508 508
509 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); 509 m_context->bindTexture(GL_TEXTURE_2D, 0);
510 510
511 if (!multisample()) 511 if (!multisample())
512 resizeDepthStencil(size, 0); 512 resizeDepthStencil(size, 0);
513 if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != Gra phicsContext3D::FRAMEBUFFER_COMPLETE) 513 if (m_context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMP LETE)
514 return false; 514 return false;
515 515
516 return true; 516 return true;
517 } 517 }
518 518
519 bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size) 519 bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size)
520 { 520 {
521 if (multisample()) { 521 if (multisample()) {
522 int maxSampleCount = 0; 522 int maxSampleCount = 0;
523 523
524 m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount); 524 m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount);
525 int sampleCount = std::min(4, maxSampleCount); 525 int sampleCount = std::min(4, maxSampleCount);
526 526
527 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisample FBO); 527 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
528 528
529 m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multisamp leColorBuffer); 529 m_context->bindRenderbuffer(GL_RENDERBUFFER, m_multisampleColorBuffer);
530 m_context->extensions()->renderbufferStorageMultisample(GraphicsContext3 D::RENDERBUFFER, sampleCount, m_internalRenderbufferFormat, size.width(), size.h eight()); 530 m_context->extensions()->renderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, m_internalRenderbufferFormat, size.width(), size.height());
531 531
532 if (m_context->getError() == GraphicsContext3D::OUT_OF_MEMORY) 532 if (m_context->getError() == GL_OUT_OF_MEMORY)
533 return false; 533 return false;
534 534
535 m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, Graph icsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_multisampleC olorBuffer); 535 m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_multisampleColorBuffer);
536 resizeDepthStencil(size, sampleCount); 536 resizeDepthStencil(size, sampleCount);
537 if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) 537 if (m_context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_ COMPLETE)
538 return false; 538 return false;
539 } 539 }
540 540
541 return true; 541 return true;
542 } 542 }
543 543
544 void DrawingBuffer::resizeDepthStencil(const IntSize& size, int sampleCount) 544 void DrawingBuffer::resizeDepthStencil(const IntSize& size, int sampleCount)
545 { 545 {
546 if (m_attributes.depth && m_attributes.stencil && m_packedDepthStencilExtens ionSupported) { 546 if (m_attributes.depth && m_attributes.stencil && m_packedDepthStencilExtens ionSupported) {
547 if (!m_depthStencilBuffer) 547 if (!m_depthStencilBuffer)
548 m_depthStencilBuffer = m_context->createRenderbuffer(); 548 m_depthStencilBuffer = m_context->createRenderbuffer();
549 m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_depthSten cilBuffer); 549 m_context->bindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer);
550 if (multisample()) 550 if (multisample())
551 m_context->extensions()->renderbufferStorageMultisample(GraphicsCont ext3D::RENDERBUFFER, sampleCount, Extensions3D::DEPTH24_STENCIL8, size.width(), size.height()); 551 m_context->extensions()->renderbufferStorageMultisample(GL_RENDERBUF FER, sampleCount, Extensions3D::DEPTH24_STENCIL8, size.width(), size.height());
552 else 552 else
553 m_context->renderbufferStorage(GraphicsContext3D::RENDERBUFFER, Exte nsions3D::DEPTH24_STENCIL8, size.width(), size.height()); 553 m_context->renderbufferStorage(GL_RENDERBUFFER, Extensions3D::DEPTH2 4_STENCIL8, size.width(), size.height());
554 m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, Graph icsContext3D::STENCIL_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, m_depthStenci lBuffer); 554 m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT , GL_RENDERBUFFER, m_depthStencilBuffer);
555 m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, Graph icsContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, m_depthStencilB uffer); 555 m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
556 } else { 556 } else {
557 if (m_attributes.depth) { 557 if (m_attributes.depth) {
558 if (!m_depthBuffer) 558 if (!m_depthBuffer)
559 m_depthBuffer = m_context->createRenderbuffer(); 559 m_depthBuffer = m_context->createRenderbuffer();
560 m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_depth Buffer); 560 m_context->bindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer);
561 if (multisample()) 561 if (multisample())
562 m_context->extensions()->renderbufferStorageMultisample(Graphics Context3D::RENDERBUFFER, sampleCount, GraphicsContext3D::DEPTH_COMPONENT16, size .width(), size.height()); 562 m_context->extensions()->renderbufferStorageMultisample(GL_RENDE RBUFFER, sampleCount, GL_DEPTH_COMPONENT16, size.width(), size.height());
563 else 563 else
564 m_context->renderbufferStorage(GraphicsContext3D::RENDERBUFFER, GraphicsContext3D::DEPTH_COMPONENT16, size.width(), size.height()); 564 m_context->renderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONE NT16, size.width(), size.height());
565 m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, G raphicsContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, m_depthBuff er); 565 m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHME NT, GL_RENDERBUFFER, m_depthBuffer);
566 } 566 }
567 if (m_attributes.stencil) { 567 if (m_attributes.stencil) {
568 if (!m_stencilBuffer) 568 if (!m_stencilBuffer)
569 m_stencilBuffer = m_context->createRenderbuffer(); 569 m_stencilBuffer = m_context->createRenderbuffer();
570 m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_stenc ilBuffer); 570 m_context->bindRenderbuffer(GL_RENDERBUFFER, m_stencilBuffer);
571 if (multisample()) 571 if (multisample())
572 m_context->extensions()->renderbufferStorageMultisample(Graphics Context3D::RENDERBUFFER, sampleCount, GraphicsContext3D::STENCIL_INDEX8, size.wi dth(), size.height()); 572 m_context->extensions()->renderbufferStorageMultisample(GL_RENDE RBUFFER, sampleCount, GL_STENCIL_INDEX8, size.width(), size.height());
573 else 573 else
574 m_context->renderbufferStorage(GraphicsContext3D::RENDERBUFFER, GraphicsContext3D::STENCIL_INDEX8, size.width(), size.height()); 574 m_context->renderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX 8, size.width(), size.height());
575 m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, G raphicsContext3D::STENCIL_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, m_stencil Buffer); 575 m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACH MENT, GL_RENDERBUFFER, m_stencilBuffer);
576 } 576 }
577 } 577 }
578 m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, 0); 578 m_context->bindRenderbuffer(GL_RENDERBUFFER, 0);
579 } 579 }
580 580
581 581
582 582
583 void DrawingBuffer::clearFramebuffers(GC3Dbitfield clearMask) 583 void DrawingBuffer::clearFramebuffers(GC3Dbitfield clearMask)
584 { 584 {
585 if (!m_context) 585 if (!m_context)
586 return; 586 return;
587 587
588 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO : m_fbo); 588 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF BO : m_fbo);
589 589
590 m_context->clear(clearMask); 590 m_context->clear(clearMask);
591 591
592 // The multisample fbo was just cleared, but we also need to clear the non-m ultisampled buffer too. 592 // The multisample fbo was just cleared, but we also need to clear the non-m ultisampled buffer too.
593 if (m_multisampleFBO) { 593 if (m_multisampleFBO) {
594 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 594 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
595 m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT); 595 m_context->clear(GL_COLOR_BUFFER_BIT);
596 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisample FBO); 596 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
597 } 597 }
598 } 598 }
599 599
600 void DrawingBuffer::setSize(const IntSize& size) { 600 void DrawingBuffer::setSize(const IntSize& size) {
601 if (m_size == size) 601 if (m_size == size)
602 return; 602 return;
603 603
604 s_currentResourceUsePixels += pixelDelta(size); 604 s_currentResourceUsePixels += pixelDelta(size);
605 m_size = size; 605 m_size = size;
606 } 606 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 } 682 }
683 break; 683 break;
684 } while (!adjustedSize.isEmpty()); 684 } while (!adjustedSize.isEmpty());
685 685
686 setSize(adjustedSize); 686 setSize(adjustedSize);
687 687
688 if (adjustedSize.isEmpty()) 688 if (adjustedSize.isEmpty())
689 return; 689 return;
690 } 690 }
691 691
692 m_context->disable(GraphicsContext3D::SCISSOR_TEST); 692 m_context->disable(GL_SCISSOR_TEST);
693 m_context->clearColor(0, 0, 0, 0); 693 m_context->clearColor(0, 0, 0, 0);
694 m_context->colorMask(true, true, true, true); 694 m_context->colorMask(true, true, true, true);
695 695
696 GC3Dbitfield clearMask = GraphicsContext3D::COLOR_BUFFER_BIT; 696 GC3Dbitfield clearMask = GL_COLOR_BUFFER_BIT;
697 if (m_attributes.depth) { 697 if (m_attributes.depth) {
698 m_context->clearDepth(1.0f); 698 m_context->clearDepth(1.0f);
699 clearMask |= GraphicsContext3D::DEPTH_BUFFER_BIT; 699 clearMask |= GL_DEPTH_BUFFER_BIT;
700 m_context->depthMask(true); 700 m_context->depthMask(true);
701 } 701 }
702 if (m_attributes.stencil) { 702 if (m_attributes.stencil) {
703 m_context->clearStencil(0); 703 m_context->clearStencil(0);
704 clearMask |= GraphicsContext3D::STENCIL_BUFFER_BIT; 704 clearMask |= GL_STENCIL_BUFFER_BIT;
705 m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, 0xFFFFFFFF); 705 m_context->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF);
706 } 706 }
707 707
708 clearFramebuffers(clearMask); 708 clearFramebuffers(clearMask);
709 } 709 }
710 710
711 void DrawingBuffer::commit(long x, long y, long width, long height) 711 void DrawingBuffer::commit(long x, long y, long width, long height)
712 { 712 {
713 if (!m_context) 713 if (!m_context)
714 return; 714 return;
715 715
716 if (width < 0) 716 if (width < 0)
717 width = m_size.width(); 717 width = m_size.width();
718 if (height < 0) 718 if (height < 0)
719 height = m_size.height(); 719 height = m_size.height();
720 720
721 m_context->makeContextCurrent(); 721 m_context->makeContextCurrent();
722 722
723 if (m_multisampleFBO && !m_contentsChangeCommitted) { 723 if (m_multisampleFBO && !m_contentsChangeCommitted) {
724 m_context->bindFramebuffer(Extensions3D::READ_FRAMEBUFFER, m_multisample FBO); 724 m_context->bindFramebuffer(Extensions3D::READ_FRAMEBUFFER, m_multisample FBO);
725 m_context->bindFramebuffer(Extensions3D::DRAW_FRAMEBUFFER, m_fbo); 725 m_context->bindFramebuffer(Extensions3D::DRAW_FRAMEBUFFER, m_fbo);
726 726
727 if (m_scissorEnabled) 727 if (m_scissorEnabled)
728 m_context->disable(GraphicsContext3D::SCISSOR_TEST); 728 m_context->disable(GL_SCISSOR_TEST);
729 729
730 // Use NEAREST, because there is no scale performed during the blit. 730 // Use NEAREST, because there is no scale performed during the blit.
731 m_context->extensions()->blitFramebuffer(x, y, width, height, x, y, widt h, height, GraphicsContext3D::COLOR_BUFFER_BIT, GraphicsContext3D::NEAREST); 731 m_context->extensions()->blitFramebuffer(x, y, width, height, x, y, widt h, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
732 732
733 if (m_scissorEnabled) 733 if (m_scissorEnabled)
734 m_context->enable(GraphicsContext3D::SCISSOR_TEST); 734 m_context->enable(GL_SCISSOR_TEST);
735 } 735 }
736 736
737 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 737 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
738 m_contentsChangeCommitted = true; 738 m_contentsChangeCommitted = true;
739 } 739 }
740 740
741 void DrawingBuffer::restoreFramebufferBinding() 741 void DrawingBuffer::restoreFramebufferBinding()
742 { 742 {
743 if (!m_context || !m_framebufferBinding) 743 if (!m_context || !m_framebufferBinding)
744 return; 744 return;
745 745
746 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_framebufferBind ing); 746 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding);
747 } 747 }
748 748
749 bool DrawingBuffer::multisample() const 749 bool DrawingBuffer::multisample() const
750 { 750 {
751 return m_attributes.antialias && m_multisampleExtensionSupported; 751 return m_attributes.antialias && m_multisampleExtensionSupported;
752 } 752 }
753 753
754 void DrawingBuffer::bind() 754 void DrawingBuffer::bind()
755 { 755 {
756 if (!m_context) 756 if (!m_context)
757 return; 757 return;
758 758
759 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO : m_fbo); 759 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF BO : m_fbo);
760 } 760 }
761 761
762 } // namespace WebCore 762 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/graphics/filters/custom/FECustomFilter.cpp ('k') | Source/web/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698