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

Side by Side Diff: cc/gl_renderer.cc

Issue 11418047: cc: Turn DrawQuad into a struct-like class with public data members. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: no virtual for SetAll() Created 8 years, 1 month 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/draw_quad_unittest.cc ('k') | cc/io_surface_draw_quad.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 "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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 243 }
244 244
245 void GLRenderer::doNoOp() 245 void GLRenderer::doNoOp()
246 { 246 {
247 GLC(m_context, m_context->bindFramebuffer(GL_FRAMEBUFFER, 0)); 247 GLC(m_context, m_context->bindFramebuffer(GL_FRAMEBUFFER, 0));
248 GLC(m_context, m_context->flush()); 248 GLC(m_context, m_context->flush());
249 } 249 }
250 250
251 void GLRenderer::drawQuad(DrawingFrame& frame, const DrawQuad* quad) 251 void GLRenderer::drawQuad(DrawingFrame& frame, const DrawQuad* quad)
252 { 252 {
253 DCHECK(quad->rect().Contains(quad->visible_rect())); 253 DCHECK(quad->rect.Contains(quad->visible_rect));
254 254
255 if (quad->ShouldDrawWithBlending()) 255 if (quad->ShouldDrawWithBlending())
256 GLC(m_context, m_context->enable(GL_BLEND)); 256 GLC(m_context, m_context->enable(GL_BLEND));
257 else 257 else
258 GLC(m_context, m_context->disable(GL_BLEND)); 258 GLC(m_context, m_context->disable(GL_BLEND));
259 259
260 switch (quad->material()) { 260 switch (quad->material) {
261 case DrawQuad::INVALID: 261 case DrawQuad::INVALID:
262 NOTREACHED(); 262 NOTREACHED();
263 break; 263 break;
264 case DrawQuad::CHECKERBOARD: 264 case DrawQuad::CHECKERBOARD:
265 drawCheckerboardQuad(frame, CheckerboardDrawQuad::materialCast(quad)); 265 drawCheckerboardQuad(frame, CheckerboardDrawQuad::materialCast(quad));
266 break; 266 break;
267 case DrawQuad::DEBUG_BORDER: 267 case DrawQuad::DEBUG_BORDER:
268 drawDebugBorderQuad(frame, DebugBorderDrawQuad::materialCast(quad)); 268 drawDebugBorderQuad(frame, DebugBorderDrawQuad::materialCast(quad));
269 break; 269 break;
270 case DrawQuad::IO_SURFACE_CONTENT: 270 case DrawQuad::IO_SURFACE_CONTENT:
(...skipping 25 matching lines...) Expand all
296 const TileCheckerboardProgram* program = tileCheckerboardProgram(); 296 const TileCheckerboardProgram* program = tileCheckerboardProgram();
297 DCHECK(program && program->initialized()); 297 DCHECK(program && program->initialized());
298 GLC(context(), context()->useProgram(program->program())); 298 GLC(context(), context()->useProgram(program->program()));
299 299
300 SkColor color = quad->color(); 300 SkColor color = quad->color();
301 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, SkColorGetB(color) / 255.0, 1)); 301 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, SkColorGetB(color) / 255.0, 1));
302 302
303 const int checkerboardWidth = 16; 303 const int checkerboardWidth = 16;
304 float frequency = 1.0 / checkerboardWidth; 304 float frequency = 1.0 / checkerboardWidth;
305 305
306 gfx::Rect tileRect = quad->rect(); 306 gfx::Rect tileRect = quad->rect;
307 float texOffsetX = tileRect.x() % checkerboardWidth; 307 float texOffsetX = tileRect.x() % checkerboardWidth;
308 float texOffsetY = tileRect.y() % checkerboardWidth; 308 float texOffsetY = tileRect.y() % checkerboardWidth;
309 float texScaleX = tileRect.width(); 309 float texScaleX = tileRect.width();
310 float texScaleY = tileRect.height(); 310 float texScaleY = tileRect.height();
311 GLC(context(), context()->uniform4f(program->fragmentShader().texTransformLo cation(), texOffsetX, texOffsetY, texScaleX, texScaleY)); 311 GLC(context(), context()->uniform4f(program->fragmentShader().texTransformLo cation(), texOffsetX, texOffsetY, texScaleX, texScaleY));
312 312
313 GLC(context(), context()->uniform1f(program->fragmentShader().frequencyLocat ion(), frequency)); 313 GLC(context(), context()->uniform1f(program->fragmentShader().frequencyLocat ion(), frequency));
314 314
315 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; 315 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ;
316 drawQuadGeometry(frame, quad->quadTransform(), quad->rect(), program->vertex Shader().matrixLocation()); 316 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation());
317 } 317 }
318 318
319 void GLRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const DebugBorde rDrawQuad* quad) 319 void GLRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const DebugBorde rDrawQuad* quad)
320 { 320 {
321 static float glMatrix[16]; 321 static float glMatrix[16];
322 const SolidColorProgram* program = solidColorProgram(); 322 const SolidColorProgram* program = solidColorProgram();
323 DCHECK(program && program->initialized()); 323 DCHECK(program && program->initialized());
324 GLC(context(), context()->useProgram(program->program())); 324 GLC(context(), context()->useProgram(program->program()));
325 325
326 // Use the full quadRect for debug quads to not move the edges based on part ial swaps. 326 // Use the full quadRect for debug quads to not move the edges based on part ial swaps.
327 const gfx::Rect& layerRect = quad->rect(); 327 const gfx::Rect& layerRect = quad->rect;
328 WebTransformationMatrix renderMatrix = quad->quadTransform(); 328 WebTransformationMatrix renderMatrix = quad->quadTransform();
329 renderMatrix.translate(0.5 * layerRect.width() + layerRect.x(), 0.5 * layerR ect.height() + layerRect.y()); 329 renderMatrix.translate(0.5 * layerRect.width() + layerRect.x(), 0.5 * layerR ect.height() + layerRect.y());
330 renderMatrix.scaleNonUniform(layerRect.width(), layerRect.height()); 330 renderMatrix.scaleNonUniform(layerRect.width(), layerRect.height());
331 GLRenderer::toGLMatrix(&glMatrix[0], frame.projectionMatrix * renderMatrix); 331 GLRenderer::toGLMatrix(&glMatrix[0], frame.projectionMatrix * renderMatrix);
332 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().matrixLoc ation(), 1, false, &glMatrix[0])); 332 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().matrixLoc ation(), 1, false, &glMatrix[0]));
333 333
334 SkColor color = quad->color(); 334 SkColor color = quad->color();
335 float alpha = SkColorGetA(color) / 255.0; 335 float alpha = SkColorGetA(color) / 255.0;
336 336
337 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha)); 337 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha));
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 return scoped_ptr<ScopedResource>(); 473 return scoped_ptr<ScopedResource>();
474 474
475 SkBitmap filteredDeviceBackground = applyFilters(this, filters, deviceBackgr oundTexture.get(), m_client->hasImplThread()); 475 SkBitmap filteredDeviceBackground = applyFilters(this, filters, deviceBackgr oundTexture.get(), m_client->hasImplThread());
476 if (!filteredDeviceBackground.getTexture()) 476 if (!filteredDeviceBackground.getTexture())
477 return scoped_ptr<ScopedResource>(); 477 return scoped_ptr<ScopedResource>();
478 478
479 GrTexture* texture = reinterpret_cast<GrTexture*>(filteredDeviceBackground.g etTexture()); 479 GrTexture* texture = reinterpret_cast<GrTexture*>(filteredDeviceBackground.g etTexture());
480 int filteredDeviceBackgroundTextureId = texture->getTextureHandle(); 480 int filteredDeviceBackgroundTextureId = texture->getTextureHandle();
481 481
482 scoped_ptr<ScopedResource> backgroundTexture = ScopedResource::create(m_reso urceProvider); 482 scoped_ptr<ScopedResource> backgroundTexture = ScopedResource::create(m_reso urceProvider);
483 if (!backgroundTexture->Allocate(Renderer::ImplPool, quad->rect().size(), GL _RGBA, ResourceProvider::TextureUsageFramebuffer)) 483 if (!backgroundTexture->Allocate(Renderer::ImplPool, quad->rect.size(), GL_R GBA, ResourceProvider::TextureUsageFramebuffer))
484 return scoped_ptr<ScopedResource>(); 484 return scoped_ptr<ScopedResource>();
485 485
486 const RenderPass* targetRenderPass = frame.currentRenderPass; 486 const RenderPass* targetRenderPass = frame.currentRenderPass;
487 bool usingBackgroundTexture = useScopedTexture(frame, backgroundTexture.get( ), quad->rect()); 487 bool usingBackgroundTexture = useScopedTexture(frame, backgroundTexture.get( ), quad->rect);
488 488
489 if (usingBackgroundTexture) { 489 if (usingBackgroundTexture) {
490 // Copy the readback pixels from device to the background texture for th e surface. 490 // Copy the readback pixels from device to the background texture for th e surface.
491 WebTransformationMatrix deviceToFramebufferTransform; 491 WebTransformationMatrix deviceToFramebufferTransform;
492 deviceToFramebufferTransform.translate(quad->rect().width() / 2.0, quad- >rect().height() / 2.0); 492 deviceToFramebufferTransform.translate(quad->rect.width() / 2.0, quad->r ect.height() / 2.0);
493 deviceToFramebufferTransform.scale3d(quad->rect().width(), quad->rect(). height(), 1); 493 deviceToFramebufferTransform.scale3d(quad->rect.width(), quad->rect.heig ht(), 1);
494 deviceToFramebufferTransform.multiply(contentsDeviceTransformInverse); 494 deviceToFramebufferTransform.multiply(contentsDeviceTransformInverse);
495 copyTextureToFramebuffer(frame, filteredDeviceBackgroundTextureId, devic eRect, deviceToFramebufferTransform); 495 copyTextureToFramebuffer(frame, filteredDeviceBackgroundTextureId, devic eRect, deviceToFramebufferTransform);
496 } 496 }
497 497
498 useRenderPass(frame, targetRenderPass); 498 useRenderPass(frame, targetRenderPass);
499 499
500 if (!usingBackgroundTexture) 500 if (!usingBackgroundTexture)
501 return scoped_ptr<ScopedResource>(); 501 return scoped_ptr<ScopedResource>();
502 return backgroundTexture.Pass(); 502 return backgroundTexture.Pass();
503 } 503 }
504 504
505 void GLRenderer::drawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQua d* quad) 505 void GLRenderer::drawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQua d* quad)
506 { 506 {
507 CachedResource* contentsTexture = m_renderPassTextures.get(quad->renderPassI d()); 507 CachedResource* contentsTexture = m_renderPassTextures.get(quad->renderPassI d());
508 if (!contentsTexture || !contentsTexture->id()) 508 if (!contentsTexture || !contentsTexture->id())
509 return; 509 return;
510 510
511 const RenderPass* renderPass = frame.renderPassesById->get(quad->renderPassI d()); 511 const RenderPass* renderPass = frame.renderPassesById->get(quad->renderPassI d());
512 DCHECK(renderPass); 512 DCHECK(renderPass);
513 if (!renderPass) 513 if (!renderPass)
514 return; 514 return;
515 515
516 WebTransformationMatrix quadRectMatrix; 516 WebTransformationMatrix quadRectMatrix;
517 quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->rect()); 517 quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->rect);
518 WebTransformationMatrix contentsDeviceTransform = (frame.windowMatrix * fram e.projectionMatrix * quadRectMatrix).to2dTransform(); 518 WebTransformationMatrix contentsDeviceTransform = (frame.windowMatrix * fram e.projectionMatrix * quadRectMatrix).to2dTransform();
519 519
520 // Can only draw surface if device matrix is invertible. 520 // Can only draw surface if device matrix is invertible.
521 if (!contentsDeviceTransform.isInvertible()) 521 if (!contentsDeviceTransform.isInvertible())
522 return; 522 return;
523 523
524 WebTransformationMatrix contentsDeviceTransformInverse = contentsDeviceTrans form.inverse(); 524 WebTransformationMatrix contentsDeviceTransformInverse = contentsDeviceTrans form.inverse();
525 scoped_ptr<ScopedResource> backgroundTexture = drawBackgroundFilters( 525 scoped_ptr<ScopedResource> backgroundTexture = drawBackgroundFilters(
526 frame, quad, renderPass->backgroundFilters(), 526 frame, quad, renderPass->backgroundFilters(),
527 contentsDeviceTransform, contentsDeviceTransformInverse); 527 contentsDeviceTransform, contentsDeviceTransformInverse);
(...skipping 11 matching lines...) Expand all
539 if (filterBitmap.getTexture()) { 539 if (filterBitmap.getTexture()) {
540 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur e()); 540 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur e());
541 contentsTextureId = texture->getTextureHandle(); 541 contentsTextureId = texture->getTextureHandle();
542 } else { 542 } else {
543 contentsResourceLock = make_scoped_ptr(new ResourceProvider::ScopedReadL ockGL(m_resourceProvider, contentsTexture->id())); 543 contentsResourceLock = make_scoped_ptr(new ResourceProvider::ScopedReadL ockGL(m_resourceProvider, contentsTexture->id()));
544 contentsTextureId = contentsResourceLock->textureId(); 544 contentsTextureId = contentsResourceLock->textureId();
545 } 545 }
546 546
547 // Draw the background texture if there is one. 547 // Draw the background texture if there is one.
548 if (backgroundTexture) { 548 if (backgroundTexture) {
549 DCHECK(backgroundTexture->size() == quad->rect().size()); 549 DCHECK(backgroundTexture->size() == quad->rect.size());
550 ResourceProvider::ScopedReadLockGL lock(m_resourceProvider, backgroundTe xture->id()); 550 ResourceProvider::ScopedReadLockGL lock(m_resourceProvider, backgroundTe xture->id());
551 copyTextureToFramebuffer(frame, lock.textureId(), quad->rect(), quad->qu adTransform()); 551 copyTextureToFramebuffer(frame, lock.textureId(), quad->rect, quad->quad Transform());
552 } 552 }
553 553
554 bool clipped = false; 554 bool clipped = false;
555 gfx::QuadF deviceQuad = MathUtil::mapQuad(contentsDeviceTransform, sharedGeo metryQuad(), clipped); 555 gfx::QuadF deviceQuad = MathUtil::mapQuad(contentsDeviceTransform, sharedGeo metryQuad(), clipped);
556 DCHECK(!clipped); 556 DCHECK(!clipped);
557 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceQuad.BoundingBox()) ); 557 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceQuad.BoundingBox()) );
558 LayerQuad deviceLayerEdges = LayerQuad(deviceQuad); 558 LayerQuad deviceLayerEdges = LayerQuad(deviceQuad);
559 559
560 // Use anti-aliasing programs only when necessary. 560 // Use anti-aliasing programs only when necessary.
561 bool useAA = (!deviceQuad.IsRectilinear() || !deviceQuad.BoundingBox().IsExp ressibleAsRect()); 561 bool useAA = (!deviceQuad.IsRectilinear() || !deviceQuad.BoundingBox().IsExp ressibleAsRect());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 deviceLayerBounds.toFloatArray(&edge[12]); 639 deviceLayerBounds.toFloatArray(&edge[12]);
640 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge)); 640 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge));
641 } 641 }
642 642
643 // Map device space quad to surface space. contentsDeviceTransform has no 3d component since it was generated with to2dTransform() so we don't need to proje ct. 643 // Map device space quad to surface space. contentsDeviceTransform has no 3d component since it was generated with to2dTransform() so we don't need to proje ct.
644 gfx::QuadF surfaceQuad = MathUtil::mapQuad(contentsDeviceTransformInverse, d eviceLayerEdges.ToQuadF(), clipped); 644 gfx::QuadF surfaceQuad = MathUtil::mapQuad(contentsDeviceTransformInverse, d eviceLayerEdges.ToQuadF(), clipped);
645 DCHECK(!clipped); 645 DCHECK(!clipped);
646 646
647 setShaderOpacity(quad->opacity(), shaderAlphaLocation); 647 setShaderOpacity(quad->opacity(), shaderAlphaLocation);
648 setShaderQuadF(surfaceQuad, shaderQuadLocation); 648 setShaderQuadF(surfaceQuad, shaderQuadLocation);
649 drawQuadGeometry(frame, quad->quadTransform(), quad->rect(), shaderMatrixLoc ation); 649 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat ion);
650 650
651 // Flush the compositor context before the filter bitmap goes out of 651 // Flush the compositor context before the filter bitmap goes out of
652 // scope, so the draw gets processed before the filter texture gets deleted. 652 // scope, so the draw gets processed before the filter texture gets deleted.
653 if (filterBitmap.getTexture()) 653 if (filterBitmap.getTexture())
654 m_context->flush(); 654 m_context->flush();
655 } 655 }
656 656
657 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD rawQuad* quad) 657 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD rawQuad* quad)
658 { 658 {
659 const SolidColorProgram* program = solidColorProgram(); 659 const SolidColorProgram* program = solidColorProgram();
660 GLC(context(), context()->useProgram(program->program())); 660 GLC(context(), context()->useProgram(program->program()));
661 661
662 SkColor color = quad->color(); 662 SkColor color = quad->color();
663 float opacity = quad->opacity(); 663 float opacity = quad->opacity();
664 float alpha = (SkColorGetA(color) / 255.0) * opacity; 664 float alpha = (SkColorGetA(color) / 255.0) * opacity;
665 665
666 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha)); 666 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha));
667 667
668 drawQuadGeometry(frame, quad->quadTransform(), quad->rect(), program->vertex Shader().matrixLocation()); 668 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation());
669 } 669 }
670 670
671 struct TileProgramUniforms { 671 struct TileProgramUniforms {
672 unsigned program; 672 unsigned program;
673 unsigned samplerLocation; 673 unsigned samplerLocation;
674 unsigned vertexTexTransformLocation; 674 unsigned vertexTexTransformLocation;
675 unsigned fragmentTexTransformLocation; 675 unsigned fragmentTexTransformLocation;
676 unsigned edgeLocation; 676 unsigned edgeLocation;
677 unsigned matrixLocation; 677 unsigned matrixLocation;
678 unsigned alphaLocation; 678 unsigned alphaLocation;
679 unsigned pointLocation; 679 unsigned pointLocation;
680 }; 680 };
681 681
682 template<class T> 682 template<class T>
683 static void tileUniformLocation(T program, TileProgramUniforms& uniforms) 683 static void tileUniformLocation(T program, TileProgramUniforms& uniforms)
684 { 684 {
685 uniforms.program = program->program(); 685 uniforms.program = program->program();
686 uniforms.vertexTexTransformLocation = program->vertexShader().vertexTexTrans formLocation(); 686 uniforms.vertexTexTransformLocation = program->vertexShader().vertexTexTrans formLocation();
687 uniforms.matrixLocation = program->vertexShader().matrixLocation(); 687 uniforms.matrixLocation = program->vertexShader().matrixLocation();
688 uniforms.pointLocation = program->vertexShader().pointLocation(); 688 uniforms.pointLocation = program->vertexShader().pointLocation();
689 689
690 uniforms.samplerLocation = program->fragmentShader().samplerLocation(); 690 uniforms.samplerLocation = program->fragmentShader().samplerLocation();
691 uniforms.alphaLocation = program->fragmentShader().alphaLocation(); 691 uniforms.alphaLocation = program->fragmentShader().alphaLocation();
692 uniforms.fragmentTexTransformLocation = program->fragmentShader().fragmentTe xTransformLocation(); 692 uniforms.fragmentTexTransformLocation = program->fragmentShader().fragmentTe xTransformLocation();
693 uniforms.edgeLocation = program->fragmentShader().edgeLocation(); 693 uniforms.edgeLocation = program->fragmentShader().edgeLocation();
694 } 694 }
695 695
696 void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua d) 696 void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua d)
697 { 697 {
698 gfx::Rect tileRect = quad->visible_rect(); 698 gfx::Rect tileRect = quad->visible_rect;
699 699
700 gfx::RectF clampRect(tileRect); 700 gfx::RectF clampRect(tileRect);
701 // Clamp texture coordinates to avoid sampling outside the layer 701 // Clamp texture coordinates to avoid sampling outside the layer
702 // by deflating the tile region half a texel or half a texel 702 // by deflating the tile region half a texel or half a texel
703 // minus epsilon for one pixel layers. The resulting clamp region 703 // minus epsilon for one pixel layers. The resulting clamp region
704 // is mapped to the unit square by the vertex shader and mapped 704 // is mapped to the unit square by the vertex shader and mapped
705 // back to normalized texture coordinates by the fragment shader 705 // back to normalized texture coordinates by the fragment shader
706 // after being clamped to 0-1 range. 706 // after being clamped to 0-1 range.
707 const float epsilon = 1 / 1024.0f; 707 const float epsilon = 1 / 1024.0f;
708 float clampX = min(0.5, clampRect.width() / 2.0 - epsilon); 708 float clampX = min(0.5, clampRect.width() / 2.0 - epsilon);
709 float clampY = min(0.5, clampRect.height() / 2.0 - epsilon); 709 float clampY = min(0.5, clampRect.height() / 2.0 - epsilon);
710 clampRect.Inset(clampX, clampY, clampX, clampY); 710 clampRect.Inset(clampX, clampY, clampX, clampY);
711 711
712 gfx::Vector2dF textureOffset = quad->textureOffset() + (clampRect.origin() - quad->rect().origin()); 712 gfx::Vector2dF textureOffset = quad->textureOffset() + (clampRect.origin() - quad->rect.origin());
713 713
714 // Map clamping rectangle to unit square. 714 // Map clamping rectangle to unit square.
715 float vertexTexTranslateX = -clampRect.x() / clampRect.width(); 715 float vertexTexTranslateX = -clampRect.x() / clampRect.width();
716 float vertexTexTranslateY = -clampRect.y() / clampRect.height(); 716 float vertexTexTranslateY = -clampRect.y() / clampRect.height();
717 float vertexTexScaleX = tileRect.width() / clampRect.width(); 717 float vertexTexScaleX = tileRect.width() / clampRect.width();
718 float vertexTexScaleY = tileRect.height() / clampRect.height(); 718 float vertexTexScaleY = tileRect.height() / clampRect.height();
719 719
720 // Map to normalized texture coordinates. 720 // Map to normalized texture coordinates.
721 const gfx::Size& textureSize = quad->textureSize(); 721 const gfx::Size& textureSize = quad->textureSize();
722 float fragmentTexTranslateX = textureOffset.x() / textureSize.width(); 722 float fragmentTexTranslateX = textureOffset.x() / textureSize.width();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 DCHECK(!clipped); 791 DCHECK(!clipped);
792 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped); 792 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped);
793 DCHECK(!clipped); 793 DCHECK(!clipped);
794 794
795 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft); 795 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft);
796 LayerQuad::Edge leftEdge(bottomLeft, topLeft); 796 LayerQuad::Edge leftEdge(bottomLeft, topLeft);
797 LayerQuad::Edge topEdge(topLeft, topRight); 797 LayerQuad::Edge topEdge(topLeft, topRight);
798 LayerQuad::Edge rightEdge(topRight, bottomRight); 798 LayerQuad::Edge rightEdge(topRight, bottomRight);
799 799
800 // Only apply anti-aliasing to edges not clipped by culling or scissorin g. 800 // Only apply anti-aliasing to edges not clipped by culling or scissorin g.
801 if (quad->topEdgeAA() && tileRect.y() == quad->rect().y()) 801 if (quad->topEdgeAA() && tileRect.y() == quad->rect.y())
802 topEdge = deviceLayerEdges.top(); 802 topEdge = deviceLayerEdges.top();
803 if (quad->leftEdgeAA() && tileRect.x() == quad->rect().x()) 803 if (quad->leftEdgeAA() && tileRect.x() == quad->rect.x())
804 leftEdge = deviceLayerEdges.left(); 804 leftEdge = deviceLayerEdges.left();
805 if (quad->rightEdgeAA() && tileRect.right() == quad->rect().right()) 805 if (quad->rightEdgeAA() && tileRect.right() == quad->rect.right())
806 rightEdge = deviceLayerEdges.right(); 806 rightEdge = deviceLayerEdges.right();
807 if (quad->bottomEdgeAA() && tileRect.bottom() == quad->rect().bottom()) 807 if (quad->bottomEdgeAA() && tileRect.bottom() == quad->rect.bottom())
808 bottomEdge = deviceLayerEdges.bottom(); 808 bottomEdge = deviceLayerEdges.bottom();
809 809
810 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1; 810 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1;
811 bottomEdge.scale(sign); 811 bottomEdge.scale(sign);
812 leftEdge.scale(sign); 812 leftEdge.scale(sign);
813 topEdge.scale(sign); 813 topEdge.scale(sign);
814 rightEdge.scale(sign); 814 rightEdge.scale(sign);
815 815
816 // Create device space quad. 816 // Create device space quad.
817 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); 817 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 // U - 128 : Turns unsigned U into signed U [-128,127] 896 // U - 128 : Turns unsigned U into signed U [-128,127]
897 // V - 128 : Turns unsigned V into signed V [-128,127] 897 // V - 128 : Turns unsigned V into signed V [-128,127]
898 float yuvAdjust[3] = { 898 float yuvAdjust[3] = {
899 -0.0625f, 899 -0.0625f,
900 -0.5f, 900 -0.5f,
901 -0.5f, 901 -0.5f,
902 }; 902 };
903 GLC(context(), context()->uniform3fv(program->fragmentShader().yuvAdjLocatio n(), 1, yuvAdjust)); 903 GLC(context(), context()->uniform3fv(program->fragmentShader().yuvAdjLocatio n(), 1, yuvAdjust));
904 904
905 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; 905 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ;
906 drawQuadGeometry(frame, quad->quadTransform(), quad->rect(), program->vertex Shader().matrixLocation()); 906 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation());
907 907
908 // Reset active texture back to texture 0. 908 // Reset active texture back to texture 0.
909 GLC(context(), context()->activeTexture(GL_TEXTURE0)); 909 GLC(context(), context()->activeTexture(GL_TEXTURE0));
910 } 910 }
911 911
912 void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide oDrawQuad* quad) 912 void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide oDrawQuad* quad)
913 { 913 {
914 static float glMatrix[16]; 914 static float glMatrix[16];
915 915
916 DCHECK(m_capabilities.usingEglImage); 916 DCHECK(m_capabilities.usingEglImage);
917 917
918 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); 918 const VideoStreamTextureProgram* program = videoStreamTextureProgram();
919 GLC(context(), context()->useProgram(program->program())); 919 GLC(context(), context()->useProgram(program->program()));
920 920
921 toGLMatrix(&glMatrix[0], quad->matrix()); 921 toGLMatrix(&glMatrix[0], quad->matrix());
922 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix Location(), 1, false, glMatrix)); 922 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix Location(), 1, false, glMatrix));
923 923
924 GLC(context(), context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture Id())); 924 GLC(context(), context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture Id()));
925 925
926 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0)); 926 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0));
927 927
928 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; 928 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ;
929 drawQuadGeometry(frame, quad->quadTransform(), quad->rect(), program->vertex Shader().matrixLocation()); 929 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation());
930 } 930 }
931 931
932 struct TextureProgramBinding { 932 struct TextureProgramBinding {
933 template<class Program> void set(Program* program) 933 template<class Program> void set(Program* program)
934 { 934 {
935 DCHECK(program && program->initialized()); 935 DCHECK(program && program->initialized());
936 programId = program->program(); 936 programId = program->program();
937 samplerLocation = program->fragmentShader().samplerLocation(); 937 samplerLocation = program->fragmentShader().samplerLocation();
938 matrixLocation = program->vertexShader().matrixLocation(); 938 matrixLocation = program->vertexShader().matrixLocation();
939 alphaLocation = program->fragmentShader().alphaLocation(); 939 alphaLocation = program->fragmentShader().alphaLocation();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 // initialized to that value! Therefore, premultipliedAlpha being false is the first 974 // initialized to that value! Therefore, premultipliedAlpha being false is the first
975 // situation we can generally see an alpha channel less than 1.0 coming out of the 975 // situation we can generally see an alpha channel less than 1.0 coming out of the
976 // compositor. This is causing platform differences in some layout tests (see 976 // compositor. This is causing platform differences in some layout tests (see
977 // https://bugs.webkit.org/show_bug.cgi?id=82412), so in this situation, use a separate 977 // https://bugs.webkit.org/show_bug.cgi?id=82412), so in this situation, use a separate
978 // blend function for the alpha channel to avoid modifying it. Don't use colorMask for this 978 // blend function for the alpha channel to avoid modifying it. Don't use colorMask for this
979 // as it has performance implications on some platforms. 979 // as it has performance implications on some platforms.
980 GLC(context(), context()->blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_S RC_ALPHA, GL_ZERO, GL_ONE)); 980 GLC(context(), context()->blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_S RC_ALPHA, GL_ZERO, GL_ONE));
981 } 981 }
982 982
983 setShaderOpacity(quad->opacity(), binding.alphaLocation); 983 setShaderOpacity(quad->opacity(), binding.alphaLocation);
984 drawQuadGeometry(frame, quad->quadTransform(), quad->rect(), binding.matrixL ocation); 984 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLoc ation);
985 985
986 if (!quad->premultipliedAlpha()) 986 if (!quad->premultipliedAlpha())
987 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); 987 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
988 } 988 }
989 989
990 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra wQuad* quad) 990 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra wQuad* quad)
991 { 991 {
992 TexTransformTextureProgramBinding binding; 992 TexTransformTextureProgramBinding binding;
993 binding.set(textureIOSurfaceProgram()); 993 binding.set(textureIOSurfaceProgram());
994 994
995 GLC(context(), context()->useProgram(binding.programId)); 995 GLC(context(), context()->useProgram(binding.programId));
996 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); 996 GLC(context(), context()->uniform1i(binding.samplerLocation, 0));
997 if (quad->orientation() == IOSurfaceDrawQuad::Flipped) 997 if (quad->orientation() == IOSurfaceDrawQuad::Flipped)
998 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua d->ioSurfaceSize().height(), quad->ioSurfaceSize().width(), quad->ioSurfaceSize( ).height() * -1.0)); 998 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua d->ioSurfaceSize().height(), quad->ioSurfaceSize().width(), quad->ioSurfaceSize( ).height() * -1.0));
999 else 999 else
1000 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0, quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height())); 1000 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0, quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height()));
1001 1001
1002 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->ioSurf aceTextureId())); 1002 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->ioSurf aceTextureId()));
1003 1003
1004 setShaderOpacity(quad->opacity(), binding.alphaLocation); 1004 setShaderOpacity(quad->opacity(), binding.alphaLocation);
1005 drawQuadGeometry(frame, quad->quadTransform(), quad->rect(), binding.matrixL ocation); 1005 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLoc ation);
1006 1006
1007 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); 1007 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, 0));
1008 } 1008 }
1009 1009
1010 void GLRenderer::finishDrawingFrame(DrawingFrame& frame) 1010 void GLRenderer::finishDrawingFrame(DrawingFrame& frame)
1011 { 1011 {
1012 m_currentFramebufferLock.reset(); 1012 m_currentFramebufferLock.reset();
1013 m_swapBufferRect.Union(gfx::ToEnclosingRect(frame.rootDamageRect)); 1013 m_swapBufferRect.Union(gfx::ToEnclosingRect(frame.rootDamageRect));
1014 1014
1015 GLC(m_context, m_context->disable(GL_BLEND)); 1015 GLC(m_context, m_context->disable(GL_BLEND));
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 1590
1591 releaseRenderPassTextures(); 1591 releaseRenderPassTextures();
1592 } 1592 }
1593 1593
1594 bool GLRenderer::isContextLost() 1594 bool GLRenderer::isContextLost()
1595 { 1595 {
1596 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); 1596 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR);
1597 } 1597 }
1598 1598
1599 } // namespace cc 1599 } // namespace cc
OLDNEW
« no previous file with comments | « cc/draw_quad_unittest.cc ('k') | cc/io_surface_draw_quad.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698