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

Side by Side Diff: cc/gl_renderer.cc

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

Powered by Google App Engine
This is Rietveld 408576698