 Chromium Code Reviews
 Chromium Code Reviews Issue 2401513002:
  DrawingBuffer cleanup: Merge structures  (Closed)
    
  
    Issue 2401513002:
  DrawingBuffer cleanup: Merge structures  (Closed) 
  | 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 m_wantStencil(wantStencil), | 175 m_wantStencil(wantStencil), | 
| 176 m_chromiumImageUsage(chromiumImageUsage) { | 176 m_chromiumImageUsage(chromiumImageUsage) { | 
| 177 memset(m_colorMask, 0, 4 * sizeof(GLboolean)); | 177 memset(m_colorMask, 0, 4 * sizeof(GLboolean)); | 
| 178 memset(m_clearColor, 0, 4 * sizeof(GLfloat)); | 178 memset(m_clearColor, 0, 4 * sizeof(GLfloat)); | 
| 179 // Used by browser tests to detect the use of a DrawingBuffer. | 179 // Used by browser tests to detect the use of a DrawingBuffer. | 
| 180 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", | 180 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", | 
| 181 TRACE_EVENT_SCOPE_GLOBAL); | 181 TRACE_EVENT_SCOPE_GLOBAL); | 
| 182 } | 182 } | 
| 183 | 183 | 
| 184 DrawingBuffer::~DrawingBuffer() { | 184 DrawingBuffer::~DrawingBuffer() { | 
| 185 ASSERT(m_destructionInProgress); | 185 DCHECK(m_destructionInProgress); | 
| 186 ASSERT(m_textureMailboxes.isEmpty()); | |
| 187 m_layer.reset(); | 186 m_layer.reset(); | 
| 188 m_contextProvider.reset(); | 187 m_contextProvider.reset(); | 
| 189 } | 188 } | 
| 190 | 189 | 
| 191 void DrawingBuffer::markContentsChanged() { | 190 void DrawingBuffer::markContentsChanged() { | 
| 192 m_contentsChanged = true; | 191 m_contentsChanged = true; | 
| 193 m_contentsChangeCommitted = false; | 192 m_contentsChangeCommitted = false; | 
| 194 } | 193 } | 
| 195 | 194 | 
| 196 bool DrawingBuffer::bufferClearNeeded() const { | 195 bool DrawingBuffer::bufferClearNeeded() const { | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 210 } | 209 } | 
| 211 | 210 | 
| 212 WebGraphicsContext3DProvider* DrawingBuffer::contextProvider() { | 211 WebGraphicsContext3DProvider* DrawingBuffer::contextProvider() { | 
| 213 return m_contextProvider.get(); | 212 return m_contextProvider.get(); | 
| 214 } | 213 } | 
| 215 | 214 | 
| 216 void DrawingBuffer::setIsHidden(bool hidden) { | 215 void DrawingBuffer::setIsHidden(bool hidden) { | 
| 217 if (m_isHidden == hidden) | 216 if (m_isHidden == hidden) | 
| 218 return; | 217 return; | 
| 219 m_isHidden = hidden; | 218 m_isHidden = hidden; | 
| 220 if (m_isHidden) | 219 if (m_isHidden) { | 
| 221 freeRecycledMailboxes(); | 220 m_recycledMailboxQueue.clear(); | 
| 221 m_frontColorBuffer = nullptr; | |
| 
ccameron
2016/10/06 09:24:53
m_frontColorBuffer remained populated, but its bac
 
erikchen
2016/10/06 23:32:51
This induces a behavior change, specifically with
 
ccameron
2016/10/07 00:46:51
Previously, this sequence would result in solid bl
 | |
| 222 } | |
| 222 } | 223 } | 
| 223 | 224 | 
| 224 void DrawingBuffer::setFilterQuality(SkFilterQuality filterQuality) { | 225 void DrawingBuffer::setFilterQuality(SkFilterQuality filterQuality) { | 
| 225 if (m_filterQuality != filterQuality) { | 226 if (m_filterQuality != filterQuality) { | 
| 226 m_filterQuality = filterQuality; | 227 m_filterQuality = filterQuality; | 
| 227 if (m_layer) | 228 if (m_layer) | 
| 228 m_layer->setNearestNeighbor(filterQuality == kNone_SkFilterQuality); | 229 m_layer->setNearestNeighbor(filterQuality == kNone_SkFilterQuality); | 
| 229 } | 230 } | 
| 230 } | 231 } | 
| 231 | 232 | 
| 232 bool DrawingBuffer::requiresAlphaChannelToBePreserved() { | 233 bool DrawingBuffer::requiresAlphaChannelToBePreserved() { | 
| 233 return !m_drawFramebufferBinding && | 234 return !m_drawFramebufferBinding && | 
| 234 defaultBufferRequiresAlphaChannelToBePreserved(); | 235 defaultBufferRequiresAlphaChannelToBePreserved(); | 
| 235 } | 236 } | 
| 236 | 237 | 
| 237 bool DrawingBuffer::defaultBufferRequiresAlphaChannelToBePreserved() { | 238 bool DrawingBuffer::defaultBufferRequiresAlphaChannelToBePreserved() { | 
| 238 if (wantExplicitResolve()) { | 239 if (wantExplicitResolve()) { | 
| 239 return !m_wantAlphaChannel && | 240 return !m_wantAlphaChannel && | 
| 240 getMultisampledRenderbufferFormat() == GL_RGBA8_OES; | 241 getMultisampledRenderbufferFormat() == GL_RGBA8_OES; | 
| 241 } | 242 } | 
| 242 | 243 | 
| 243 bool rgbEmulation = | 244 bool rgbEmulation = | 
| 244 contextProvider()->getCapabilities().emulate_rgb_buffer_with_rgba || | 245 contextProvider()->getCapabilities().emulate_rgb_buffer_with_rgba || | 
| 245 (shouldUseChromiumImage() && | 246 (shouldUseChromiumImage() && | 
| 246 contextProvider()->getCapabilities().chromium_image_rgb_emulation); | 247 contextProvider()->getCapabilities().chromium_image_rgb_emulation); | 
| 247 return !m_wantAlphaChannel && rgbEmulation; | 248 return !m_wantAlphaChannel && rgbEmulation; | 
| 248 } | 249 } | 
| 249 | 250 | 
| 250 void DrawingBuffer::freeRecycledMailboxes() { | |
| 251 while (!m_recycledMailboxQueue.isEmpty()) { | |
| 252 RefPtr<RecycledMailbox> recycled = m_recycledMailboxQueue.takeLast(); | |
| 253 deleteMailbox(recycled->mailbox, recycled->syncToken); | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 std::unique_ptr<cc::SharedBitmap> DrawingBuffer::createOrRecycleBitmap() { | 251 std::unique_ptr<cc::SharedBitmap> DrawingBuffer::createOrRecycleBitmap() { | 
| 258 auto it = std::remove_if( | 252 auto it = std::remove_if( | 
| 259 m_recycledBitmaps.begin(), m_recycledBitmaps.end(), | 253 m_recycledBitmaps.begin(), m_recycledBitmaps.end(), | 
| 260 [this](const RecycledBitmap& bitmap) { return bitmap.size != m_size; }); | 254 [this](const RecycledBitmap& bitmap) { return bitmap.size != m_size; }); | 
| 261 m_recycledBitmaps.shrink(it - m_recycledBitmaps.begin()); | 255 m_recycledBitmaps.shrink(it - m_recycledBitmaps.begin()); | 
| 262 | 256 | 
| 263 if (!m_recycledBitmaps.isEmpty()) { | 257 if (!m_recycledBitmaps.isEmpty()) { | 
| 264 RecycledBitmap recycled = std::move(m_recycledBitmaps.last()); | 258 RecycledBitmap recycled = std::move(m_recycledBitmaps.last()); | 
| 265 m_recycledBitmaps.removeLast(); | 259 m_recycledBitmaps.removeLast(); | 
| 266 DCHECK(recycled.size == m_size); | 260 DCHECK(recycled.size == m_size); | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 // software frames, until we get a new context, since the compositor will | 292 // software frames, until we get a new context, since the compositor will | 
| 299 // be trying to get a new context and may change modes. | 293 // be trying to get a new context and may change modes. | 
| 300 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) | 294 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) | 
| 301 return false; | 295 return false; | 
| 302 | 296 | 
| 303 TRACE_EVENT0("blink,rail", "DrawingBuffer::prepareMailbox"); | 297 TRACE_EVENT0("blink,rail", "DrawingBuffer::prepareMailbox"); | 
| 304 | 298 | 
| 305 if (m_newMailboxCallback) | 299 if (m_newMailboxCallback) | 
| 306 (*m_newMailboxCallback)(); | 300 (*m_newMailboxCallback)(); | 
| 307 | 301 | 
| 308 // Resolve the multisampled buffer into m_colorBuffer texture. | 302 // Resolve the multisampled buffer into m_backColorBuffer texture. | 
| 309 if (m_antiAliasingMode != None) | 303 if (m_antiAliasingMode != None) | 
| 310 commit(); | 304 commit(); | 
| 311 | 305 | 
| 312 if (m_softwareRendering && !forceGpuResult) { | 306 if (m_softwareRendering && !forceGpuResult) { | 
| 313 std::unique_ptr<cc::SharedBitmap> bitmap = createOrRecycleBitmap(); | 307 std::unique_ptr<cc::SharedBitmap> bitmap = createOrRecycleBitmap(); | 
| 314 if (!bitmap) | 308 if (!bitmap) | 
| 315 return false; | 309 return false; | 
| 316 unsigned char* pixels = bitmap->pixels(); | 310 unsigned char* pixels = bitmap->pixels(); | 
| 317 DCHECK(pixels); | 311 DCHECK(pixels); | 
| 318 | 312 | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 339 if (m_webGLVersion > WebGL1) { | 333 if (m_webGLVersion > WebGL1) { | 
| 340 m_gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | 334 m_gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | 
| 341 } | 335 } | 
| 342 | 336 | 
| 343 // We must restore the texture binding since creating new textures, | 337 // We must restore the texture binding since creating new textures, | 
| 344 // consuming and producing mailboxes changes it. | 338 // consuming and producing mailboxes changes it. | 
| 345 ScopedTextureUnit0BindingRestorer restorer(m_gl, m_activeTextureUnit, | 339 ScopedTextureUnit0BindingRestorer restorer(m_gl, m_activeTextureUnit, | 
| 346 m_texture2DBinding); | 340 m_texture2DBinding); | 
| 347 | 341 | 
| 348 // First try to recycle an old buffer. | 342 // First try to recycle an old buffer. | 
| 349 RefPtr<MailboxInfo> mailboxInfo = takeRecycledMailbox(); | 343 RefPtr<ColorBuffer> colorBufferForMailbox = takeRecycledMailbox(); | 
| 350 | 344 | 
| 351 // No buffer available to recycle, create a new one. | 345 // No buffer available to recycle, create a new one. | 
| 352 if (!mailboxInfo) | 346 if (!colorBufferForMailbox) | 
| 353 mailboxInfo = createNewMailbox(createTextureAndAllocateMemory(m_size)); | 347 colorBufferForMailbox = createTextureAndAllocateMemory(m_size); | 
| 354 | 348 | 
| 355 if (m_preserveDrawingBuffer == Discard) { | 349 if (m_preserveDrawingBuffer == Discard) { | 
| 356 std::swap(mailboxInfo->textureInfo, m_colorBuffer); | 350 std::swap(colorBufferForMailbox, m_backColorBuffer); | 
| 357 attachColorBufferToReadFramebuffer(); | 351 attachColorBufferToReadFramebuffer(); | 
| 358 | 352 | 
| 359 if (m_discardFramebufferSupported) { | 353 if (m_discardFramebufferSupported) { | 
| 360 // Explicitly discard the framebuffer to save GPU memory bandwidth for | 354 // Explicitly discard the framebuffer to save GPU memory bandwidth for | 
| 361 // tile-based GPU arch. | 355 // tile-based GPU arch. | 
| 362 const GLenum attachments[3] = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, | 356 const GLenum attachments[3] = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, | 
| 363 GL_STENCIL_ATTACHMENT}; | 357 GL_STENCIL_ATTACHMENT}; | 
| 364 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 358 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 
| 365 m_gl->DiscardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments); | 359 m_gl->DiscardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments); | 
| 366 } | 360 } | 
| 367 } else { | 361 } else { | 
| 368 m_gl->CopySubTextureCHROMIUM( | 362 m_gl->CopySubTextureCHROMIUM( | 
| 369 m_colorBuffer.textureId, mailboxInfo->textureInfo.textureId, 0, 0, 0, 0, | 363 m_backColorBuffer->textureId, colorBufferForMailbox->textureId, 0, 0, 0, | 
| 370 m_size.width(), m_size.height(), GL_FALSE, GL_FALSE, GL_FALSE); | 364 0, m_size.width(), m_size.height(), GL_FALSE, GL_FALSE, GL_FALSE); | 
| 371 } | 365 } | 
| 372 | 366 | 
| 373 restoreFramebufferBindings(); | 367 restoreFramebufferBindings(); | 
| 374 restorePixelUnpackBufferBindings(); | 368 restorePixelUnpackBufferBindings(); | 
| 375 m_contentsChanged = false; | 369 m_contentsChanged = false; | 
| 376 | 370 | 
| 377 m_gl->ProduceTextureDirectCHROMIUM(mailboxInfo->textureInfo.textureId, | 371 m_gl->ProduceTextureDirectCHROMIUM(colorBufferForMailbox->textureId, | 
| 378 mailboxInfo->textureInfo.parameters.target, | 372 colorBufferForMailbox->parameters.target, | 
| 379 mailboxInfo->mailbox.name); | 373 colorBufferForMailbox->mailbox.name); | 
| 380 const GLuint64 fenceSync = m_gl->InsertFenceSyncCHROMIUM(); | 374 const GLuint64 fenceSync = m_gl->InsertFenceSyncCHROMIUM(); | 
| 381 #if OS(MACOSX) | 375 #if OS(MACOSX) | 
| 382 m_gl->DescheduleUntilFinishedCHROMIUM(); | 376 m_gl->DescheduleUntilFinishedCHROMIUM(); | 
| 383 #endif | 377 #endif | 
| 384 m_gl->Flush(); | 378 m_gl->Flush(); | 
| 385 gpu::SyncToken syncToken; | 379 gpu::SyncToken syncToken; | 
| 386 m_gl->GenSyncTokenCHROMIUM(fenceSync, syncToken.GetData()); | 380 m_gl->GenSyncTokenCHROMIUM(fenceSync, syncToken.GetData()); | 
| 387 | 381 | 
| 388 bool isOverlayCandidate = mailboxInfo->textureInfo.imageId != 0; | 382 bool isOverlayCandidate = colorBufferForMailbox->imageId != 0; | 
| 389 bool secureOutputOnly = false; | 383 bool secureOutputOnly = false; | 
| 390 *outMailbox = cc::TextureMailbox(mailboxInfo->mailbox, syncToken, | 384 *outMailbox = cc::TextureMailbox(colorBufferForMailbox->mailbox, syncToken, | 
| 391 mailboxInfo->textureInfo.parameters.target, | 385 colorBufferForMailbox->parameters.target, | 
| 392 gfx::Size(m_size.width(), m_size.height()), | 386 gfx::Size(m_size.width(), m_size.height()), | 
| 393 isOverlayCandidate, secureOutputOnly); | 387 isOverlayCandidate, secureOutputOnly); | 
| 394 | 388 | 
| 395 // This holds a ref on the DrawingBuffer that will keep it alive until the | 389 // This holds a ref on the DrawingBuffer that will keep it alive until the | 
| 396 // mailbox is released (and while the release callback is running). | 390 // mailbox is released (and while the release callback is running). | 
| 397 auto func = WTF::bind(&DrawingBuffer::gpuMailboxReleased, | 391 auto func = WTF::bind(&DrawingBuffer::gpuMailboxReleased, | 
| 398 RefPtr<DrawingBuffer>(this), mailboxInfo->mailbox); | 392 RefPtr<DrawingBuffer>(this), colorBufferForMailbox); | 
| 399 *outReleaseCallback = | 393 *outReleaseCallback = | 
| 400 cc::SingleReleaseCallback::Create(convertToBaseCallback(std::move(func))); | 394 cc::SingleReleaseCallback::Create(convertToBaseCallback(std::move(func))); | 
| 401 | 395 | 
| 402 m_frontColorBuffer = {mailboxInfo->mailbox, syncToken, | 396 // Point |m_frontColorBuffer| to the buffer that we are presenting, and | 
| 403 mailboxInfo->textureInfo}; | 397 // update its sync token. | 
| 398 colorBufferForMailbox->produceSyncToken = syncToken; | |
| 399 m_frontColorBuffer = colorBufferForMailbox; | |
| 404 setBufferClearNeeded(true); | 400 setBufferClearNeeded(true); | 
| 405 return true; | 401 return true; | 
| 406 } | 402 } | 
| 407 | 403 | 
| 408 void DrawingBuffer::gpuMailboxReleased(const gpu::Mailbox& mailbox, | 404 void DrawingBuffer::gpuMailboxReleased(RefPtr<ColorBuffer> colorBuffer, | 
| 409 const gpu::SyncToken& syncToken, | 405 const gpu::SyncToken& syncToken, | 
| 410 bool lostResource) { | 406 bool lostResource) { | 
| 411 if (m_destructionInProgress || | 407 // Update the SyncToken to ensure that we will wait for it even if we | 
| 408 // immediately destroy this buffer. | |
| 409 colorBuffer->receiveSyncToken = syncToken; | |
| 410 | |
| 411 if (m_destructionInProgress || colorBuffer->size != m_size || | |
| 412 m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR || lostResource || | 412 m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR || lostResource || | 
| 413 m_isHidden) { | 413 m_isHidden) { | 
| 414 deleteMailbox(mailbox, syncToken); | |
| 415 return; | 414 return; | 
| 416 } | 415 } | 
| 417 | 416 | 
| 418 // Creation of image backed mailboxes is very expensive, so be less | 417 // Creation of image backed mailboxes is very expensive, so be less | 
| 419 // aggressive about pruning them. Pruning is done in FIFO order. | 418 // aggressive about pruning them. Pruning is done in FIFO order. | 
| 420 size_t cacheLimit = 1; | 419 size_t cacheLimit = 1; | 
| 421 if (shouldUseChromiumImage()) | 420 if (shouldUseChromiumImage()) | 
| 422 cacheLimit = 4; | 421 cacheLimit = 4; | 
| 423 while (m_recycledMailboxQueue.size() >= cacheLimit) { | 422 while (m_recycledMailboxQueue.size() >= cacheLimit) | 
| 424 RefPtr<RecycledMailbox> recycled = m_recycledMailboxQueue.takeLast(); | 423 m_recycledMailboxQueue.takeLast(); | 
| 425 deleteMailbox(recycled->mailbox, recycled->syncToken); | |
| 426 } | |
| 427 | 424 | 
| 428 RefPtr<MailboxInfo> mailboxInfo; | 425 m_recycledMailboxQueue.prepend(colorBuffer); | 
| 
ccameron
2016/10/06 09:24:53
This block is looking up the MailboxInfo from its
 | |
| 429 for (size_t i = 0; i < m_textureMailboxes.size(); i++) { | |
| 430 if (m_textureMailboxes[i]->mailbox == mailbox) { | |
| 431 mailboxInfo = m_textureMailboxes[i]; | |
| 432 break; | |
| 433 } | |
| 434 } | |
| 435 DCHECK(mailboxInfo); | |
| 436 if (mailboxInfo->size != m_size) { | |
| 437 deleteMailbox(mailbox, syncToken); | |
| 438 return; | |
| 439 } | |
| 440 | |
| 441 m_recycledMailboxQueue.prepend( | |
| 442 adoptRef(new RecycledMailbox(mailbox, syncToken))); | |
| 443 } | 426 } | 
| 444 | 427 | 
| 445 void DrawingBuffer::softwareMailboxReleased( | 428 void DrawingBuffer::softwareMailboxReleased( | 
| 446 std::unique_ptr<cc::SharedBitmap> bitmap, | 429 std::unique_ptr<cc::SharedBitmap> bitmap, | 
| 447 const IntSize& size, | 430 const IntSize& size, | 
| 448 const gpu::SyncToken& syncToken, | 431 const gpu::SyncToken& syncToken, | 
| 449 bool lostResource) { | 432 bool lostResource) { | 
| 450 DCHECK(!syncToken.HasData()); // No sync tokens for software resources. | 433 DCHECK(!syncToken.HasData()); // No sync tokens for software resources. | 
| 451 if (m_destructionInProgress || lostResource || m_isHidden || size != m_size) | 434 if (m_destructionInProgress || lostResource || m_isHidden || size != m_size) | 
| 452 return; // Just delete the bitmap. | 435 return; // Just delete the bitmap. | 
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 } else { | 558 } else { | 
| 576 GLenum format = | 559 GLenum format = | 
| 577 defaultBufferRequiresAlphaChannelToBePreserved() ? GL_RGBA : GL_RGB; | 560 defaultBufferRequiresAlphaChannelToBePreserved() ? GL_RGBA : GL_RGB; | 
| 578 parameters.creationInternalColorFormat = format; | 561 parameters.creationInternalColorFormat = format; | 
| 579 parameters.internalColorFormat = format; | 562 parameters.internalColorFormat = format; | 
| 580 parameters.colorFormat = format; | 563 parameters.colorFormat = format; | 
| 581 } | 564 } | 
| 582 return parameters; | 565 return parameters; | 
| 583 } | 566 } | 
| 584 | 567 | 
| 585 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::takeRecycledMailbox() { | 568 PassRefPtr<DrawingBuffer::ColorBuffer> DrawingBuffer::takeRecycledMailbox() { | 
| 586 if (m_recycledMailboxQueue.isEmpty()) | 569 if (m_recycledMailboxQueue.isEmpty()) | 
| 587 return nullptr; | 570 return nullptr; | 
| 588 | 571 | 
| 589 RefPtr<RecycledMailbox> recycled = m_recycledMailboxQueue.takeLast(); | 572 RefPtr<ColorBuffer> recycled = m_recycledMailboxQueue.takeLast(); | 
| 590 if (recycled->syncToken.HasData()) | 573 if (recycled->receiveSyncToken.HasData()) | 
| 591 m_gl->WaitSyncTokenCHROMIUM(recycled->syncToken.GetData()); | 574 m_gl->WaitSyncTokenCHROMIUM(recycled->receiveSyncToken.GetData()); | 
| 592 | 575 return recycled; | 
| 593 RefPtr<MailboxInfo> mailboxInfo; | |
| 594 for (size_t i = 0; i < m_textureMailboxes.size(); i++) { | |
| 595 if (m_textureMailboxes[i]->mailbox == recycled->mailbox) { | |
| 596 mailboxInfo = m_textureMailboxes[i]; | |
| 597 break; | |
| 598 } | |
| 599 } | |
| 600 DCHECK(mailboxInfo); | |
| 601 DCHECK(mailboxInfo->size == m_size); | |
| 
erikchen
2016/10/06 23:32:51
why get rid of this DCHECK? seems like a good sani
 
ccameron
2016/10/07 00:46:51
Yes, this is needed! Was a bit too aggressive with
 | |
| 602 return mailboxInfo.release(); | |
| 603 } | 576 } | 
| 604 | 577 | 
| 605 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox( | 578 DrawingBuffer::ColorBuffer::ColorBuffer(DrawingBuffer* drawingBuffer, | 
| 606 const TextureInfo& info) { | 579 const TextureParameters& parameters, | 
| 607 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo); | 580 const IntSize& size) | 
| 608 m_gl->GenMailboxCHROMIUM(returnMailbox->mailbox.name); | 581 : drawingBuffer(drawingBuffer), parameters(parameters), size(size) { | 
| 609 returnMailbox->textureInfo = info; | 582 drawingBuffer->contextGL()->GenMailboxCHROMIUM(mailbox.name); | 
| 610 returnMailbox->size = m_size; | |
| 611 m_textureMailboxes.append(returnMailbox); | |
| 612 return returnMailbox.release(); | |
| 613 } | 583 } | 
| 614 | 584 | 
| 615 void DrawingBuffer::deleteMailbox(const gpu::Mailbox& mailbox, | 585 DrawingBuffer::ColorBuffer::~ColorBuffer() { | 
| 616 const gpu::SyncToken& syncToken) { | 586 gpu::gles2::GLES2Interface* gl = drawingBuffer->contextGL(); | 
| 617 if (syncToken.HasData()) | 587 if (receiveSyncToken.HasData()) | 
| 618 m_gl->WaitSyncTokenCHROMIUM(syncToken.GetConstData()); | 588 gl->WaitSyncTokenCHROMIUM(receiveSyncToken.GetConstData()); | 
| 619 for (size_t i = 0; i < m_textureMailboxes.size(); i++) { | 589 if (imageId) { | 
| 620 if (m_textureMailboxes[i]->mailbox == mailbox) { | 590 gl->BindTexture(parameters.target, textureId); | 
| 621 deleteChromiumImageForTexture(&m_textureMailboxes[i]->textureInfo); | 591 gl->ReleaseTexImage2DCHROMIUM(parameters.target, imageId); | 
| 622 m_gl->DeleteTextures(1, &m_textureMailboxes[i]->textureInfo.textureId); | 592 gl->DestroyImageCHROMIUM(imageId); | 
| 623 m_textureMailboxes.remove(i); | |
| 624 return; | |
| 625 } | |
| 626 } | 593 } | 
| 627 ASSERT_NOT_REACHED(); | 594 gl->DeleteTextures(1, &textureId); | 
| 628 } | 595 } | 
| 629 | 596 | 
| 630 bool DrawingBuffer::initialize(const IntSize& size, bool useMultisampling) { | 597 bool DrawingBuffer::initialize(const IntSize& size, bool useMultisampling) { | 
| 631 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { | 598 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { | 
| 632 // Need to try to restore the context again later. | 599 // Need to try to restore the context again later. | 
| 633 return false; | 600 return false; | 
| 634 } | 601 } | 
| 635 | 602 | 
| 636 m_gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); | 603 m_gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); | 
| 637 | 604 | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 m_gl->Flush(); | 666 m_gl->Flush(); | 
| 700 } | 667 } | 
| 701 | 668 | 
| 702 // Assume that the destination target is GL_TEXTURE_2D. | 669 // Assume that the destination target is GL_TEXTURE_2D. | 
| 703 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM( | 670 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM( | 
| 704 GL_TEXTURE_2D, internalFormat, destType, level)) | 671 GL_TEXTURE_2D, internalFormat, destType, level)) | 
| 705 return false; | 672 return false; | 
| 706 | 673 | 
| 707 // Contexts may be in a different share group. We must transfer the texture | 674 // Contexts may be in a different share group. We must transfer the texture | 
| 708 // through a mailbox first. | 675 // through a mailbox first. | 
| 709 GLint textureId = 0; | |
| 710 GLenum target = 0; | 676 GLenum target = 0; | 
| 711 gpu::Mailbox mailbox; | 677 gpu::Mailbox mailbox; | 
| 712 gpu::SyncToken produceSyncToken; | 678 gpu::SyncToken produceSyncToken; | 
| 713 if (sourceBuffer == FrontBuffer && m_frontColorBuffer.texInfo.textureId) { | 679 if (sourceBuffer == FrontBuffer && m_frontColorBuffer) { | 
| 714 textureId = m_frontColorBuffer.texInfo.textureId; | 680 target = m_frontColorBuffer->parameters.target; | 
| 715 target = m_frontColorBuffer.texInfo.parameters.target; | 681 mailbox = m_frontColorBuffer->mailbox; | 
| 716 mailbox = m_frontColorBuffer.mailbox; | 682 produceSyncToken = m_frontColorBuffer->produceSyncToken; | 
| 717 produceSyncToken = m_frontColorBuffer.produceSyncToken; | |
| 718 } else { | 683 } else { | 
| 719 textureId = m_colorBuffer.textureId; | 684 target = m_backColorBuffer->parameters.target; | 
| 720 target = m_colorBuffer.parameters.target; | |
| 721 m_gl->GenMailboxCHROMIUM(mailbox.name); | 685 m_gl->GenMailboxCHROMIUM(mailbox.name); | 
| 722 m_gl->ProduceTextureDirectCHROMIUM(textureId, target, mailbox.name); | 686 m_gl->ProduceTextureDirectCHROMIUM(m_backColorBuffer->textureId, target, | 
| 687 mailbox.name); | |
| 723 const GLuint64 fenceSync = m_gl->InsertFenceSyncCHROMIUM(); | 688 const GLuint64 fenceSync = m_gl->InsertFenceSyncCHROMIUM(); | 
| 724 m_gl->Flush(); | 689 m_gl->Flush(); | 
| 725 m_gl->GenSyncTokenCHROMIUM(fenceSync, produceSyncToken.GetData()); | 690 m_gl->GenSyncTokenCHROMIUM(fenceSync, produceSyncToken.GetData()); | 
| 726 } | 691 } | 
| 727 | 692 | 
| 728 DCHECK(produceSyncToken.HasData()); | 693 DCHECK(produceSyncToken.HasData()); | 
| 729 gl->WaitSyncTokenCHROMIUM(produceSyncToken.GetConstData()); | 694 gl->WaitSyncTokenCHROMIUM(produceSyncToken.GetConstData()); | 
| 730 GLuint sourceTexture = | 695 GLuint sourceTexture = | 
| 731 gl->CreateAndConsumeTextureCHROMIUM(target, mailbox.name); | 696 gl->CreateAndConsumeTextureCHROMIUM(target, mailbox.name); | 
| 732 | 697 | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 m_layer->clearTexture(); | 743 m_layer->clearTexture(); | 
| 779 | 744 | 
| 780 m_gl->Flush(); | 745 m_gl->Flush(); | 
| 781 } | 746 } | 
| 782 | 747 | 
| 783 void DrawingBuffer::beginDestruction() { | 748 void DrawingBuffer::beginDestruction() { | 
| 784 ASSERT(!m_destructionInProgress); | 749 ASSERT(!m_destructionInProgress); | 
| 785 m_destructionInProgress = true; | 750 m_destructionInProgress = true; | 
| 786 | 751 | 
| 787 clearPlatformLayer(); | 752 clearPlatformLayer(); | 
| 788 freeRecycledMailboxes(); | 753 m_recycledMailboxQueue.clear(); | 
| 789 | 754 | 
| 790 if (m_multisampleFBO) | 755 if (m_multisampleFBO) | 
| 791 m_gl->DeleteFramebuffers(1, &m_multisampleFBO); | 756 m_gl->DeleteFramebuffers(1, &m_multisampleFBO); | 
| 792 | 757 | 
| 793 if (m_fbo) | 758 if (m_fbo) | 
| 794 m_gl->DeleteFramebuffers(1, &m_fbo); | 759 m_gl->DeleteFramebuffers(1, &m_fbo); | 
| 795 | 760 | 
| 796 if (m_multisampleRenderbuffer) | 761 if (m_multisampleRenderbuffer) | 
| 797 m_gl->DeleteRenderbuffers(1, &m_multisampleRenderbuffer); | 762 m_gl->DeleteRenderbuffers(1, &m_multisampleRenderbuffer); | 
| 798 | 763 | 
| 799 if (m_depthStencilBuffer) | 764 if (m_depthStencilBuffer) | 
| 800 m_gl->DeleteRenderbuffers(1, &m_depthStencilBuffer); | 765 m_gl->DeleteRenderbuffers(1, &m_depthStencilBuffer); | 
| 801 | 766 | 
| 802 if (m_colorBuffer.textureId) { | |
| 803 deleteChromiumImageForTexture(&m_colorBuffer); | |
| 804 m_gl->DeleteTextures(1, &m_colorBuffer.textureId); | |
| 805 } | |
| 806 | |
| 807 m_size = IntSize(); | 767 m_size = IntSize(); | 
| 808 | 768 | 
| 809 m_colorBuffer = TextureInfo(); | 769 m_backColorBuffer = nullptr; | 
| 810 m_frontColorBuffer = FrontBufferInfo(); | 770 m_frontColorBuffer = nullptr; | 
| 811 m_multisampleRenderbuffer = 0; | 771 m_multisampleRenderbuffer = 0; | 
| 812 m_depthStencilBuffer = 0; | 772 m_depthStencilBuffer = 0; | 
| 813 m_multisampleFBO = 0; | 773 m_multisampleFBO = 0; | 
| 814 m_fbo = 0; | 774 m_fbo = 0; | 
| 815 | 775 | 
| 816 if (m_layer) | 776 if (m_layer) | 
| 817 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 777 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 
| 818 } | 778 } | 
| 819 | 779 | 
| 820 GLuint DrawingBuffer::createColorTexture(const TextureParameters& parameters) { | 780 GLuint DrawingBuffer::createColorTexture(const TextureParameters& parameters) { | 
| 821 GLuint offscreenColorTexture; | 781 GLuint offscreenColorTexture; | 
| 822 m_gl->GenTextures(1, &offscreenColorTexture); | 782 m_gl->GenTextures(1, &offscreenColorTexture); | 
| 823 m_gl->BindTexture(parameters.target, offscreenColorTexture); | 783 m_gl->BindTexture(parameters.target, offscreenColorTexture); | 
| 824 m_gl->TexParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 784 m_gl->TexParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 
| 825 m_gl->TexParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 785 m_gl->TexParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 
| 826 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 786 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 
| 827 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 787 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 
| 828 return offscreenColorTexture; | 788 return offscreenColorTexture; | 
| 829 } | 789 } | 
| 830 | 790 | 
| 831 bool DrawingBuffer::resizeDefaultFramebuffer(const IntSize& size) { | 791 bool DrawingBuffer::resizeDefaultFramebuffer(const IntSize& size) { | 
| 832 // Resize or create m_colorBuffer. | 792 // Recreate m_backColorBuffer. | 
| 833 if (m_colorBuffer.textureId) { | 793 m_backColorBuffer = createTextureAndAllocateMemory(size); | 
| 834 deleteChromiumImageForTexture(&m_colorBuffer); | |
| 835 m_gl->DeleteTextures(1, &m_colorBuffer.textureId); | |
| 836 } | |
| 837 m_colorBuffer = createTextureAndAllocateMemory(size); | |
| 838 | 794 | 
| 839 attachColorBufferToReadFramebuffer(); | 795 attachColorBufferToReadFramebuffer(); | 
| 840 | 796 | 
| 841 if (wantExplicitResolve()) { | 797 if (wantExplicitResolve()) { | 
| 842 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); | 798 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); | 
| 843 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_multisampleRenderbuffer); | 799 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_multisampleRenderbuffer); | 
| 844 m_gl->RenderbufferStorageMultisampleCHROMIUM( | 800 m_gl->RenderbufferStorageMultisampleCHROMIUM( | 
| 845 GL_RENDERBUFFER, m_sampleCount, getMultisampledRenderbufferFormat(), | 801 GL_RENDERBUFFER, m_sampleCount, getMultisampledRenderbufferFormat(), | 
| 846 size.width(), size.height()); | 802 size.width(), size.height()); | 
| 847 | 803 | 
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 950 clearMask |= GL_DEPTH_BUFFER_BIT; | 906 clearMask |= GL_DEPTH_BUFFER_BIT; | 
| 951 m_gl->DepthMask(true); | 907 m_gl->DepthMask(true); | 
| 952 } | 908 } | 
| 953 if (!!m_depthStencilBuffer) { | 909 if (!!m_depthStencilBuffer) { | 
| 954 m_gl->ClearStencil(0); | 910 m_gl->ClearStencil(0); | 
| 955 clearMask |= GL_STENCIL_BUFFER_BIT; | 911 clearMask |= GL_STENCIL_BUFFER_BIT; | 
| 956 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); | 912 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); | 
| 957 } | 913 } | 
| 958 | 914 | 
| 959 clearFramebuffers(clearMask); | 915 clearFramebuffers(clearMask); | 
| 960 freeRecycledMailboxes(); | 916 m_recycledMailboxQueue.clear(); | 
| 917 m_recycledBitmaps.clear(); | |
| 961 return true; | 918 return true; | 
| 962 } | 919 } | 
| 963 | 920 | 
| 964 void DrawingBuffer::commit() { | 921 void DrawingBuffer::commit() { | 
| 965 if (wantExplicitResolve() && !m_contentsChangeCommitted) { | 922 if (wantExplicitResolve() && !m_contentsChangeCommitted) { | 
| 966 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); | 923 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); | 
| 967 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); | 924 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); | 
| 968 | 925 | 
| 969 if (m_scissorEnabled) | 926 if (m_scissorEnabled) | 
| 970 m_gl->Disable(GL_SCISSOR_TEST); | 927 m_gl->Disable(GL_SCISSOR_TEST); | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1060 dataSize *= width; | 1017 dataSize *= width; | 
| 1061 dataSize *= height; | 1018 dataSize *= height; | 
| 1062 if (!dataSize.IsValid()) | 1019 if (!dataSize.IsValid()) | 
| 1063 return false; | 1020 return false; | 
| 1064 | 1021 | 
| 1065 WTF::ArrayBufferContents pixels(width * height, 4, | 1022 WTF::ArrayBufferContents pixels(width * height, 4, | 
| 1066 WTF::ArrayBufferContents::NotShared, | 1023 WTF::ArrayBufferContents::NotShared, | 
| 1067 WTF::ArrayBufferContents::DontInitialize); | 1024 WTF::ArrayBufferContents::DontInitialize); | 
| 1068 | 1025 | 
| 1069 GLuint fbo = 0; | 1026 GLuint fbo = 0; | 
| 1070 if (sourceBuffer == FrontBuffer && m_frontColorBuffer.texInfo.textureId) { | 1027 if (sourceBuffer == FrontBuffer && m_frontColorBuffer) { | 
| 1071 m_gl->GenFramebuffers(1, &fbo); | 1028 m_gl->GenFramebuffers(1, &fbo); | 
| 1072 m_gl->BindFramebuffer(GL_FRAMEBUFFER, fbo); | 1029 m_gl->BindFramebuffer(GL_FRAMEBUFFER, fbo); | 
| 1073 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 1030 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 
| 1074 m_frontColorBuffer.texInfo.parameters.target, | 1031 m_frontColorBuffer->parameters.target, | 
| 1075 m_frontColorBuffer.texInfo.textureId, 0); | 1032 m_frontColorBuffer->textureId, 0); | 
| 1076 } else { | 1033 } else { | 
| 1077 m_gl->BindFramebuffer(GL_FRAMEBUFFER, framebuffer()); | 1034 m_gl->BindFramebuffer(GL_FRAMEBUFFER, framebuffer()); | 
| 1078 } | 1035 } | 
| 1079 | 1036 | 
| 1080 readBackFramebuffer(static_cast<unsigned char*>(pixels.data()), width, height, | 1037 readBackFramebuffer(static_cast<unsigned char*>(pixels.data()), width, height, | 
| 1081 ReadbackRGBA, WebGLImageConversion::AlphaDoNothing); | 1038 ReadbackRGBA, WebGLImageConversion::AlphaDoNothing); | 
| 1082 flipVertically(static_cast<uint8_t*>(pixels.data()), width, height); | 1039 flipVertically(static_cast<uint8_t*>(pixels.data()), width, height); | 
| 1083 | 1040 | 
| 1084 if (fbo) { | 1041 if (fbo) { | 
| 1085 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 1042 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 
| 1086 m_frontColorBuffer.texInfo.parameters.target, 0, | 1043 m_frontColorBuffer->parameters.target, 0, 0); | 
| 1087 0); | |
| 1088 m_gl->DeleteFramebuffers(1, &fbo); | 1044 m_gl->DeleteFramebuffers(1, &fbo); | 
| 1089 } | 1045 } | 
| 1090 | 1046 | 
| 1091 restoreFramebufferBindings(); | 1047 restoreFramebufferBindings(); | 
| 1092 | 1048 | 
| 1093 pixels.transfer(contents); | 1049 pixels.transfer(contents); | 
| 1094 return true; | 1050 return true; | 
| 1095 } | 1051 } | 
| 1096 | 1052 | 
| 1097 void DrawingBuffer::readBackFramebuffer(unsigned char* pixels, | 1053 void DrawingBuffer::readBackFramebuffer(unsigned char* pixels, | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1161 NOTREACHED(); | 1117 NOTREACHED(); | 
| 1162 } | 1118 } | 
| 1163 m_gl->TexStorage2DEXT(GL_TEXTURE_2D, 1, internalStorageFormat, width, | 1119 m_gl->TexStorage2DEXT(GL_TEXTURE_2D, 1, internalStorageFormat, width, | 
| 1164 height); | 1120 height); | 
| 1165 return; | 1121 return; | 
| 1166 } | 1122 } | 
| 1167 m_gl->TexImage2D(target, 0, internalformat, width, height, border, format, | 1123 m_gl->TexImage2D(target, 0, internalformat, width, height, border, format, | 
| 1168 type, 0); | 1124 type, 0); | 
| 1169 } | 1125 } | 
| 1170 | 1126 | 
| 1171 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) { | 1127 void DrawingBuffer::clearChromiumImageAlpha(const ColorBuffer& info) { | 
| 1172 if (info->imageId) { | |
| 1173 m_gl->BindTexture(info->parameters.target, info->textureId); | |
| 1174 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId); | |
| 1175 m_gl->DestroyImageCHROMIUM(info->imageId); | |
| 1176 info->imageId = 0; | |
| 1177 } | |
| 1178 } | |
| 1179 | |
| 1180 void DrawingBuffer::clearChromiumImageAlpha(const TextureInfo& info) { | |
| 1181 if (m_wantAlphaChannel) | 1128 if (m_wantAlphaChannel) | 
| 1182 return; | 1129 return; | 
| 1183 if (!contextProvider()->getCapabilities().chromium_image_rgb_emulation) | 1130 if (!contextProvider()->getCapabilities().chromium_image_rgb_emulation) | 
| 1184 return; | 1131 return; | 
| 1185 | 1132 | 
| 1186 GLuint fbo = 0; | 1133 GLuint fbo = 0; | 
| 1187 m_gl->GenFramebuffers(1, &fbo); | 1134 m_gl->GenFramebuffers(1, &fbo); | 
| 1188 m_gl->BindFramebuffer(GL_FRAMEBUFFER, fbo); | 1135 m_gl->BindFramebuffer(GL_FRAMEBUFFER, fbo); | 
| 1189 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 1136 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 
| 1190 info.parameters.target, info.textureId, 0); | 1137 info.parameters.target, info.textureId, 0); | 
| 1191 m_gl->ClearColor(0, 0, 0, 1); | 1138 m_gl->ClearColor(0, 0, 0, 1); | 
| 1192 m_gl->ColorMask(false, false, false, true); | 1139 m_gl->ColorMask(false, false, false, true); | 
| 1193 m_gl->Clear(GL_COLOR_BUFFER_BIT); | 1140 m_gl->Clear(GL_COLOR_BUFFER_BIT); | 
| 1194 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 1141 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 
| 1195 info.parameters.target, 0, 0); | 1142 info.parameters.target, 0, 0); | 
| 1196 m_gl->DeleteFramebuffers(1, &fbo); | 1143 m_gl->DeleteFramebuffers(1, &fbo); | 
| 1197 restoreFramebufferBindings(); | 1144 restoreFramebufferBindings(); | 
| 1198 m_gl->ClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2], | 1145 m_gl->ClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2], | 
| 1199 m_clearColor[3]); | 1146 m_clearColor[3]); | 
| 1200 m_gl->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], | 1147 m_gl->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], | 
| 1201 m_colorMask[3]); | 1148 m_colorMask[3]); | 
| 1202 } | 1149 } | 
| 1203 | 1150 | 
| 1204 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory( | 1151 RefPtr<DrawingBuffer::ColorBuffer> | 
| 1205 const IntSize& size) { | 1152 DrawingBuffer::createTextureAndAllocateMemory(const IntSize& size) { | 
| 1206 if (!shouldUseChromiumImage()) | 1153 if (!shouldUseChromiumImage()) | 
| 1207 return createDefaultTextureAndAllocateMemory(size); | 1154 return createDefaultTextureAndAllocateMemory(size); | 
| 1208 | 1155 | 
| 1209 TextureParameters parameters = chromiumImageTextureParameters(); | 1156 TextureParameters parameters = chromiumImageTextureParameters(); | 
| 1210 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM( | 1157 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM( | 
| 1211 size.width(), size.height(), parameters.creationInternalColorFormat, | 1158 size.width(), size.height(), parameters.creationInternalColorFormat, | 
| 1212 GC3D_SCANOUT_CHROMIUM); | 1159 GC3D_SCANOUT_CHROMIUM); | 
| 1213 GLuint textureId = createColorTexture(parameters); | 1160 GLuint textureId = createColorTexture(parameters); | 
| 1214 if (imageId) { | 1161 if (imageId) { | 
| 1215 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId); | 1162 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId); | 
| 1216 } | 1163 } | 
| 1217 | 1164 | 
| 1218 TextureInfo info; | 1165 RefPtr<ColorBuffer> info(adoptRef(new ColorBuffer(this, parameters, size))); | 
| 1219 info.textureId = textureId; | 1166 info->textureId = textureId; | 
| 1220 info.imageId = imageId; | 1167 info->imageId = imageId; | 
| 1221 info.parameters = parameters; | 1168 clearChromiumImageAlpha(*info); | 
| 1222 clearChromiumImageAlpha(info); | |
| 1223 return info; | 1169 return info; | 
| 1224 } | 1170 } | 
| 1225 | 1171 | 
| 1226 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( | 1172 RefPtr<DrawingBuffer::ColorBuffer> | 
| 1227 const IntSize& size) { | 1173 DrawingBuffer::createDefaultTextureAndAllocateMemory(const IntSize& size) { | 
| 1228 DrawingBuffer::TextureInfo info; | |
| 1229 TextureParameters parameters = defaultTextureParameters(); | 1174 TextureParameters parameters = defaultTextureParameters(); | 
| 1230 info.parameters = parameters; | 1175 RefPtr<ColorBuffer> info(adoptRef(new ColorBuffer(this, parameters, size))); | 
| 1231 info.textureId = createColorTexture(parameters); | 1176 info->textureId = createColorTexture(parameters); | 
| 1232 allocateConditionallyImmutableTexture( | 1177 allocateConditionallyImmutableTexture( | 
| 1233 parameters.target, parameters.creationInternalColorFormat, size.width(), | 1178 parameters.target, parameters.creationInternalColorFormat, size.width(), | 
| 1234 size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); | 1179 size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); | 
| 1235 return info; | 1180 return info; | 
| 1236 } | 1181 } | 
| 1237 | 1182 | 
| 1238 void DrawingBuffer::attachColorBufferToReadFramebuffer() { | 1183 void DrawingBuffer::attachColorBufferToReadFramebuffer() { | 
| 1239 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 1184 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 
| 1240 | 1185 | 
| 1241 GLenum target = m_colorBuffer.parameters.target; | 1186 GLenum target = m_backColorBuffer->parameters.target; | 
| 1242 GLenum id = m_colorBuffer.textureId; | 1187 GLenum id = m_backColorBuffer->textureId; | 
| 1243 | 1188 | 
| 1244 m_gl->BindTexture(target, id); | 1189 m_gl->BindTexture(target, id); | 
| 1245 | 1190 | 
| 1246 if (m_antiAliasingMode == MSAAImplicitResolve) | 1191 if (m_antiAliasingMode == MSAAImplicitResolve) | 
| 1247 m_gl->FramebufferTexture2DMultisampleEXT( | 1192 m_gl->FramebufferTexture2DMultisampleEXT( | 
| 1248 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, id, 0, m_sampleCount); | 1193 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, id, 0, m_sampleCount); | 
| 1249 else | 1194 else | 
| 1250 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, id, | 1195 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, id, | 
| 1251 0); | 1196 0); | 
| 1252 | 1197 | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1282 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE. | 1227 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE. | 
| 1283 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 1228 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 
| 1284 } | 1229 } | 
| 1285 | 1230 | 
| 1286 bool DrawingBuffer::shouldUseChromiumImage() { | 1231 bool DrawingBuffer::shouldUseChromiumImage() { | 
| 1287 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && | 1232 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && | 
| 1288 m_chromiumImageUsage == AllowChromiumImage; | 1233 m_chromiumImageUsage == AllowChromiumImage; | 
| 1289 } | 1234 } | 
| 1290 | 1235 | 
| 1291 } // namespace blink | 1236 } // namespace blink | 
| OLD | NEW |