OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/gl_renderer.h" | 5 #include "cc/gl_renderer.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 paint.setImageFilter(filter); | 431 paint.setImageFilter(filter); |
432 canvas.clear(0x0); | 432 canvas.clear(0x0); |
433 canvas.drawSprite(source, 0, 0, &paint); | 433 canvas.drawSprite(source, 0, 0, &paint); |
434 canvas.flush(); | 434 canvas.flush(); |
435 context3d->flush(); | 435 context3d->flush(); |
436 return device.accessBitmap(false); | 436 return device.accessBitmap(false); |
437 } | 437 } |
438 | 438 |
439 scoped_ptr<ScopedResource> GLRenderer::drawBackgroundFilters( | 439 scoped_ptr<ScopedResource> GLRenderer::drawBackgroundFilters( |
440 DrawingFrame& frame, const RenderPassDrawQuad* quad, | 440 DrawingFrame& frame, const RenderPassDrawQuad* quad, |
441 const WebKit::WebFilterOperations& filters, | |
442 const gfx::Transform& contentsDeviceTransform, | 441 const gfx::Transform& contentsDeviceTransform, |
443 const gfx::Transform& contentsDeviceTransformInverse) | 442 const gfx::Transform& contentsDeviceTransformInverse) |
444 { | 443 { |
445 // This method draws a background filter, which applies a filter to any pixe
ls behind the quad and seen through its background. | 444 // This method draws a background filter, which applies a filter to any pixe
ls behind the quad and seen through its background. |
446 // The algorithm works as follows: | 445 // The algorithm works as follows: |
447 // 1. Compute a bounding box around the pixels that will be visible through
the quad. | 446 // 1. Compute a bounding box around the pixels that will be visible through
the quad. |
448 // 2. Read the pixels in the bounding box into a buffer R. | 447 // 2. Read the pixels in the bounding box into a buffer R. |
449 // 3. Apply the background filter to R, so that it is applied in the pixels'
coordinate space. | 448 // 3. Apply the background filter to R, so that it is applied in the pixels'
coordinate space. |
450 // 4. Apply the quad's inverse transform to map the pixels in R into the qua
d's content space. This implicitly | 449 // 4. Apply the quad's inverse transform to map the pixels in R into the qua
d's content space. This implicitly |
451 // clips R by the content bounds of the quad since the destination texture h
as bounds matching the quad's content. | 450 // clips R by the content bounds of the quad since the destination texture h
as bounds matching the quad's content. |
452 // 5. Draw the background texture for the contents using the same transform
as used to draw the contents itself. This is done | 451 // 5. Draw the background texture for the contents using the same transform
as used to draw the contents itself. This is done |
453 // without blending to replace the current background pixels with the new fi
ltered background. | 452 // without blending to replace the current background pixels with the new fi
ltered background. |
454 // 6. Draw the contents of the quad over drop of the new background with ble
nding, as per usual. The filtered background | 453 // 6. Draw the contents of the quad over drop of the new background with ble
nding, as per usual. The filtered background |
455 // pixels will show through any non-opaque pixels in this draws. | 454 // pixels will show through any non-opaque pixels in this draws. |
456 // | 455 // |
457 // Pixel copies in this algorithm occur at steps 2, 3, 4, and 5. | 456 // Pixel copies in this algorithm occur at steps 2, 3, 4, and 5. |
458 | 457 |
459 // FIXME: When this algorithm changes, update LayerTreeHost::prioritizeTextu
res() accordingly. | 458 // FIXME: When this algorithm changes, update LayerTreeHost::prioritizeTextu
res() accordingly. |
460 | 459 |
| 460 const WebKit::WebFilterOperations& filters = quad->background_filters; |
461 if (filters.isEmpty()) | 461 if (filters.isEmpty()) |
462 return scoped_ptr<ScopedResource>(); | 462 return scoped_ptr<ScopedResource>(); |
463 | 463 |
464 // FIXME: We only allow background filters on an opaque render surface becau
se other surfaces may contain | 464 // FIXME: We only allow background filters on an opaque render surface becau
se other surfaces may contain |
465 // translucent pixels, and the contents behind those translucent pixels woul
dn't have the filter applied. | 465 // translucent pixels, and the contents behind those translucent pixels woul
dn't have the filter applied. |
466 if (frame.currentRenderPass->has_transparent_background) | 466 if (frame.currentRenderPass->has_transparent_background) |
467 return scoped_ptr<ScopedResource>(); | 467 return scoped_ptr<ScopedResource>(); |
468 DCHECK(!frame.currentTexture); | 468 DCHECK(!frame.currentTexture); |
469 | 469 |
470 // FIXME: Do a single readback for both the surface and replica and cache th
e filtered results (once filter textures are not reused). | 470 // FIXME: Do a single readback for both the surface and replica and cache th
e filtered results (once filter textures are not reused). |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 return scoped_ptr<ScopedResource>(); | 509 return scoped_ptr<ScopedResource>(); |
510 return backgroundTexture.Pass(); | 510 return backgroundTexture.Pass(); |
511 } | 511 } |
512 | 512 |
513 void GLRenderer::drawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQua
d* quad) | 513 void GLRenderer::drawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQua
d* quad) |
514 { | 514 { |
515 CachedResource* contentsTexture = m_renderPassTextures.get(quad->render_pass
_id); | 515 CachedResource* contentsTexture = m_renderPassTextures.get(quad->render_pass
_id); |
516 if (!contentsTexture || !contentsTexture->id()) | 516 if (!contentsTexture || !contentsTexture->id()) |
517 return; | 517 return; |
518 | 518 |
519 const RenderPass* renderPass = frame.renderPassesById->get(quad->render_pass
_id); | |
520 DCHECK(renderPass); | |
521 if (!renderPass) | |
522 return; | |
523 | |
524 gfx::Transform quadRectMatrix; | 519 gfx::Transform quadRectMatrix; |
525 quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->rect); | 520 quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->rect); |
526 gfx::Transform contentsDeviceTransform = MathUtil::to2dTransform(frame.windo
wMatrix * frame.projectionMatrix * quadRectMatrix); | 521 gfx::Transform contentsDeviceTransform = MathUtil::to2dTransform(frame.windo
wMatrix * frame.projectionMatrix * quadRectMatrix); |
527 | 522 |
528 // Can only draw surface if device matrix is invertible. | 523 // Can only draw surface if device matrix is invertible. |
529 if (!contentsDeviceTransform.IsInvertible()) | 524 if (!contentsDeviceTransform.IsInvertible()) |
530 return; | 525 return; |
531 | 526 |
532 gfx::Transform contentsDeviceTransformInverse = MathUtil::inverse(contentsDe
viceTransform); | 527 gfx::Transform contentsDeviceTransformInverse = MathUtil::inverse(contentsDe
viceTransform); |
533 scoped_ptr<ScopedResource> backgroundTexture = drawBackgroundFilters( | 528 scoped_ptr<ScopedResource> backgroundTexture = drawBackgroundFilters( |
534 frame, quad, renderPass->background_filters, | 529 frame, quad, contentsDeviceTransform, contentsDeviceTransformInverse); |
535 contentsDeviceTransform, contentsDeviceTransformInverse); | |
536 | 530 |
537 // FIXME: Cache this value so that we don't have to do it for both the surfa
ce and its replica. | 531 // FIXME: Cache this value so that we don't have to do it for both the surfa
ce and its replica. |
538 // Apply filters to the contents texture. | 532 // Apply filters to the contents texture. |
539 SkBitmap filterBitmap; | 533 SkBitmap filterBitmap; |
540 if (renderPass->filter) { | 534 if (quad->filter) { |
541 filterBitmap = applyImageFilter(this, renderPass->filter.get(), contents
Texture, m_client->hasImplThread()); | 535 filterBitmap = applyImageFilter(this, quad->filter.get(), contentsTextur
e, m_client->hasImplThread()); |
542 } else { | 536 } else { |
543 filterBitmap = applyFilters(this, renderPass->filters, contentsTexture,
m_client->hasImplThread()); | 537 filterBitmap = applyFilters(this, quad->filters, contentsTexture, m_clie
nt->hasImplThread()); |
544 } | 538 } |
545 | 539 |
546 // Draw the background texture if there is one. | 540 // Draw the background texture if there is one. |
547 if (backgroundTexture) { | 541 if (backgroundTexture) { |
548 DCHECK(backgroundTexture->size() == quad->rect.size()); | 542 DCHECK(backgroundTexture->size() == quad->rect.size()); |
549 ResourceProvider::ScopedReadLockGL lock(m_resourceProvider, backgroundTe
xture->id()); | 543 ResourceProvider::ScopedReadLockGL lock(m_resourceProvider, backgroundTe
xture->id()); |
550 copyTextureToFramebuffer(frame, lock.textureId(), quad->rect, quad->quad
Transform()); | 544 copyTextureToFramebuffer(frame, lock.textureId(), quad->rect, quad->quad
Transform()); |
551 } | 545 } |
552 | 546 |
553 bool clipped = false; | 547 bool clipped = false; |
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 | 1790 |
1797 releaseRenderPassTextures(); | 1791 releaseRenderPassTextures(); |
1798 } | 1792 } |
1799 | 1793 |
1800 bool GLRenderer::isContextLost() | 1794 bool GLRenderer::isContextLost() |
1801 { | 1795 { |
1802 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1796 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
1803 } | 1797 } |
1804 | 1798 |
1805 } // namespace cc | 1799 } // namespace cc |
OLD | NEW |