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

Side by Side Diff: cc/gl_renderer.cc

Issue 11411050: cc: Make the DrawQuad subclasses into struct-like classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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/heads_up_display_layer_impl.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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
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:
271 drawIOSurfaceQuad(frame, IOSurfaceDrawQuad::materialCast(quad)); 271 drawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad));
272 break; 272 break;
273 case DrawQuad::RENDER_PASS: 273 case DrawQuad::RENDER_PASS:
274 drawRenderPassQuad(frame, RenderPassDrawQuad::materialCast(quad)); 274 drawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad));
275 break; 275 break;
276 case DrawQuad::SOLID_COLOR: 276 case DrawQuad::SOLID_COLOR:
277 drawSolidColorQuad(frame, SolidColorDrawQuad::materialCast(quad)); 277 drawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad));
278 break; 278 break;
279 case DrawQuad::STREAM_VIDEO_CONTENT: 279 case DrawQuad::STREAM_VIDEO_CONTENT:
280 drawStreamVideoQuad(frame, StreamVideoDrawQuad::materialCast(quad)); 280 drawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad));
281 break; 281 break;
282 case DrawQuad::TEXTURE_CONTENT: 282 case DrawQuad::TEXTURE_CONTENT:
283 drawTextureQuad(frame, TextureDrawQuad::materialCast(quad)); 283 drawTextureQuad(frame, TextureDrawQuad::MaterialCast(quad));
284 break; 284 break;
285 case DrawQuad::TILED_CONTENT: 285 case DrawQuad::TILED_CONTENT:
286 drawTileQuad(frame, TileDrawQuad::materialCast(quad)); 286 drawTileQuad(frame, TileDrawQuad::MaterialCast(quad));
287 break; 287 break;
288 case DrawQuad::YUV_VIDEO_CONTENT: 288 case DrawQuad::YUV_VIDEO_CONTENT:
289 drawYUVVideoQuad(frame, YUVVideoDrawQuad::materialCast(quad)); 289 drawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad));
290 break; 290 break;
291 } 291 }
292 } 292 }
293 293
294 void GLRenderer::drawCheckerboardQuad(const DrawingFrame& frame, const Checkerbo ardDrawQuad* quad) 294 void GLRenderer::drawCheckerboardQuad(const DrawingFrame& frame, const Checkerbo ardDrawQuad* quad)
295 { 295 {
296 const TileCheckerboardProgram* program = tileCheckerboardProgram(); 296 const TileCheckerboardProgram* program = tileCheckerboardProgram();
297 DCHECK(program && (program->initialized() || isContextLost())); 297 DCHECK(program && (program->initialized() || isContextLost()));
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();
(...skipping 13 matching lines...) Expand all
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));
338 338
339 GLC(context(), context()->lineWidth(quad->width())); 339 GLC(context(), context()->lineWidth(quad->width));
340 340
341 // The indices for the line are stored in the same array as the triangle ind ices. 341 // The indices for the line are stored in the same array as the triangle ind ices.
342 GLC(context(), context()->drawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 6 * sizeof(unsigned short))); 342 GLC(context(), context()->drawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 6 * sizeof(unsigned short)));
343 } 343 }
344 344
345 static WebGraphicsContext3D* getFilterContext(bool hasImplThread) 345 static WebGraphicsContext3D* getFilterContext(bool hasImplThread)
346 { 346 {
347 if (hasImplThread) 347 if (hasImplThread)
348 return WebSharedGraphicsContext3D::compositorThreadContext(); 348 return WebSharedGraphicsContext3D::compositorThreadContext();
349 else 349 else
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->render_pass _id);
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->render_pass _id);
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())
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
562 if (useAA) { 562 if (useAA) {
563 deviceLayerBounds.inflateAntiAliasingDistance(); 563 deviceLayerBounds.inflateAntiAliasingDistance();
564 deviceLayerEdges.inflateAntiAliasingDistance(); 564 deviceLayerEdges.inflateAntiAliasingDistance();
565 } 565 }
566 566
567 scoped_ptr<ResourceProvider::ScopedReadLockGL> maskResourceLock; 567 scoped_ptr<ResourceProvider::ScopedReadLockGL> maskResourceLock;
568 unsigned maskTextureId = 0; 568 unsigned maskTextureId = 0;
569 if (quad->maskResourceId()) { 569 if (quad->mask_resource_id) {
570 maskResourceLock.reset(new ResourceProvider::ScopedReadLockGL(m_resource Provider, quad->maskResourceId())); 570 maskResourceLock.reset(new ResourceProvider::ScopedReadLockGL(m_resource Provider, quad->mask_resource_id));
571 maskTextureId = maskResourceLock->textureId(); 571 maskTextureId = maskResourceLock->textureId();
572 } 572 }
573 573
574 // FIXME: use the backgroundTexture and blend the background in with this dr aw instead of having a separate copy of the background texture. 574 // FIXME: use the backgroundTexture and blend the background in with this dr aw instead of having a separate copy of the background texture.
575 575
576 context()->bindTexture(GL_TEXTURE_2D, contentsTextureId); 576 context()->bindTexture(GL_TEXTURE_2D, contentsTextureId);
577 577
578 int shaderQuadLocation = -1; 578 int shaderQuadLocation = -1;
579 int shaderEdgeLocation = -1; 579 int shaderEdgeLocation = -1;
580 int shaderMaskSamplerLocation = -1; 580 int shaderMaskSamplerLocation = -1;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 620
621 shaderMatrixLocation = program->vertexShader().matrixLocation(); 621 shaderMatrixLocation = program->vertexShader().matrixLocation();
622 shaderAlphaLocation = program->fragmentShader().alphaLocation(); 622 shaderAlphaLocation = program->fragmentShader().alphaLocation();
623 } 623 }
624 624
625 if (shaderMaskSamplerLocation != -1) { 625 if (shaderMaskSamplerLocation != -1) {
626 DCHECK(shaderMaskTexCoordScaleLocation != 1); 626 DCHECK(shaderMaskTexCoordScaleLocation != 1);
627 DCHECK(shaderMaskTexCoordOffsetLocation != 1); 627 DCHECK(shaderMaskTexCoordOffsetLocation != 1);
628 GLC(context(), context()->activeTexture(GL_TEXTURE1)); 628 GLC(context(), context()->activeTexture(GL_TEXTURE1));
629 GLC(context(), context()->uniform1i(shaderMaskSamplerLocation, 1)); 629 GLC(context(), context()->uniform1i(shaderMaskSamplerLocation, 1));
630 GLC(context(), context()->uniform2f(shaderMaskTexCoordScaleLocation, qua d->maskTexCoordScaleX(), quad->maskTexCoordScaleY())); 630 GLC(context(), context()->uniform2f(shaderMaskTexCoordScaleLocation, qua d->mask_tex_coord_scale_x, quad->mask_tex_coord_scale_y));
631 GLC(context(), context()->uniform2f(shaderMaskTexCoordOffsetLocation, qu ad->maskTexCoordOffsetX(), quad->maskTexCoordOffsetY())); 631 GLC(context(), context()->uniform2f(shaderMaskTexCoordOffsetLocation, qu ad->mask_tex_coord_offset_x, quad->mask_tex_coord_offset_y));
632 context()->bindTexture(GL_TEXTURE_2D, maskTextureId); 632 context()->bindTexture(GL_TEXTURE_2D, maskTextureId);
633 GLC(context(), context()->activeTexture(GL_TEXTURE0)); 633 GLC(context(), context()->activeTexture(GL_TEXTURE0));
634 } 634 }
635 635
636 if (shaderEdgeLocation != -1) { 636 if (shaderEdgeLocation != -1) {
637 float edge[24]; 637 float edge[24];
638 deviceLayerEdges.toFloatArray(edge); 638 deviceLayerEdges.toFloatArray(edge);
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 }
(...skipping 10 matching lines...) Expand all
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->vertexSh ader().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;
(...skipping 17 matching lines...) Expand all
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 texCoordRect = quad->texCoordRect(); 700 gfx::RectF texCoordRect = quad->tex_coord_rect;
701 float texToGeomScaleX = quad->rect.width() / texCoordRect.width(); 701 float texToGeomScaleX = quad->rect.width() / texCoordRect.width();
702 float texToGeomScaleY = quad->rect.height() / texCoordRect.height(); 702 float texToGeomScaleY = quad->rect.height() / texCoordRect.height();
703 703
704 // texCoordRect corresponds to quadRect, but quadVisibleRect may be 704 // texCoordRect corresponds to quadRect, but quadVisibleRect may be
705 // smaller than quadRect due to occlusion or clipping. Adjust 705 // smaller than quadRect due to occlusion or clipping. Adjust
706 // texCoordRect to match. 706 // texCoordRect to match.
707 gfx::Vector2d topLeftDiff = tileRect.origin() - quad->rect.origin(); 707 gfx::Vector2d topLeftDiff = tileRect.origin() - quad->rect.origin();
708 gfx::Vector2d bottomRightDiff = 708 gfx::Vector2d bottomRightDiff =
709 tileRect.bottom_right() - quad->rect.bottom_right(); 709 tileRect.bottom_right() - quad->rect.bottom_right();
710 texCoordRect.Inset(topLeftDiff.x() / texToGeomScaleX, 710 texCoordRect.Inset(topLeftDiff.x() / texToGeomScaleX,
(...skipping 19 matching lines...) Expand all
730 clampGeomRect.Inset(geomClampX, geomClampY, geomClampX, geomClampY); 730 clampGeomRect.Inset(geomClampX, geomClampY, geomClampX, geomClampY);
731 clampTexRect.Inset(texClampX, texClampY, texClampX, texClampY); 731 clampTexRect.Inset(texClampX, texClampY, texClampX, texClampY);
732 732
733 // Map clamping rectangle to unit square. 733 // Map clamping rectangle to unit square.
734 float vertexTexTranslateX = -clampGeomRect.x() / clampGeomRect.width(); 734 float vertexTexTranslateX = -clampGeomRect.x() / clampGeomRect.width();
735 float vertexTexTranslateY = -clampGeomRect.y() / clampGeomRect.height(); 735 float vertexTexTranslateY = -clampGeomRect.y() / clampGeomRect.height();
736 float vertexTexScaleX = tileRect.width() / clampGeomRect.width(); 736 float vertexTexScaleX = tileRect.width() / clampGeomRect.width();
737 float vertexTexScaleY = tileRect.height() / clampGeomRect.height(); 737 float vertexTexScaleY = tileRect.height() / clampGeomRect.height();
738 738
739 // Map to normalized texture coordinates. 739 // Map to normalized texture coordinates.
740 const gfx::Size& textureSize = quad->textureSize(); 740 const gfx::Size& textureSize = quad->texture_size;
741 float fragmentTexTranslateX = clampTexRect.x() / textureSize.width(); 741 float fragmentTexTranslateX = clampTexRect.x() / textureSize.width();
742 float fragmentTexTranslateY = clampTexRect.y() / textureSize.height(); 742 float fragmentTexTranslateY = clampTexRect.y() / textureSize.height();
743 float fragmentTexScaleX = clampTexRect.width() / textureSize.width(); 743 float fragmentTexScaleX = clampTexRect.width() / textureSize.width();
744 float fragmentTexScaleY = clampTexRect.height() / textureSize.height(); 744 float fragmentTexScaleY = clampTexRect.height() / textureSize.height();
745 745
746 746
747 gfx::QuadF localQuad; 747 gfx::QuadF localQuad;
748 WebTransformationMatrix deviceTransform = WebTransformationMatrix(frame.wind owMatrix * frame.projectionMatrix * quad->quadTransform()).to2dTransform(); 748 WebTransformationMatrix deviceTransform = WebTransformationMatrix(frame.wind owMatrix * frame.projectionMatrix * quad->quadTransform()).to2dTransform();
749 if (!deviceTransform.isInvertible()) 749 if (!deviceTransform.isInvertible())
750 return; 750 return;
751 751
752 bool clipped = false; 752 bool clipped = false;
753 gfx::QuadF deviceLayerQuad = MathUtil::mapQuad(deviceTransform, gfx::QuadF(q uad->visibleContentRect()), clipped); 753 gfx::QuadF deviceLayerQuad = MathUtil::mapQuad(deviceTransform, gfx::QuadF(q uad->visibleContentRect()), clipped);
754 DCHECK(!clipped); 754 DCHECK(!clipped);
755 755
756 TileProgramUniforms uniforms; 756 TileProgramUniforms uniforms;
757 // For now, we simply skip anti-aliasing with the quad is clipped. This only happens 757 // For now, we simply skip anti-aliasing with the quad is clipped. This only happens
758 // on perspective transformed layers that go partially behind the camera. 758 // on perspective transformed layers that go partially behind the camera.
759 if (quad->isAntialiased() && !clipped) { 759 if (quad->IsAntialiased() && !clipped) {
760 if (quad->swizzleContents()) 760 if (quad->swizzle_contents)
761 tileUniformLocation(tileProgramSwizzleAA(), uniforms); 761 tileUniformLocation(tileProgramSwizzleAA(), uniforms);
762 else 762 else
763 tileUniformLocation(tileProgramAA(), uniforms); 763 tileUniformLocation(tileProgramAA(), uniforms);
764 } else { 764 } else {
765 if (quad->ShouldDrawWithBlending()) { 765 if (quad->ShouldDrawWithBlending()) {
766 if (quad->swizzleContents()) 766 if (quad->swizzle_contents)
767 tileUniformLocation(tileProgramSwizzle(), uniforms); 767 tileUniformLocation(tileProgramSwizzle(), uniforms);
768 else 768 else
769 tileUniformLocation(tileProgram(), uniforms); 769 tileUniformLocation(tileProgram(), uniforms);
770 } else { 770 } else {
771 if (quad->swizzleContents()) 771 if (quad->swizzle_contents)
772 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); 772 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms);
773 else 773 else
774 tileUniformLocation(tileProgramOpaque(), uniforms); 774 tileUniformLocation(tileProgramOpaque(), uniforms);
775 } 775 }
776 } 776 }
777 777
778 GLC(context(), context()->useProgram(uniforms.program)); 778 GLC(context(), context()->useProgram(uniforms.program));
779 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); 779 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0));
780 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resourceId()); 780 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resource_id);
781 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId())); 781 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId()));
782 782
783 bool useAA = !clipped && quad->isAntialiased(); 783 bool useAA = !clipped && quad->IsAntialiased();
784 if (useAA) { 784 if (useAA) {
785 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox())); 785 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox()));
786 deviceLayerBounds.inflateAntiAliasingDistance(); 786 deviceLayerBounds.inflateAntiAliasingDistance();
787 787
788 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad); 788 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad);
789 deviceLayerEdges.inflateAntiAliasingDistance(); 789 deviceLayerEdges.inflateAntiAliasingDistance();
790 790
791 float edge[24]; 791 float edge[24];
792 deviceLayerEdges.toFloatArray(edge); 792 deviceLayerEdges.toFloatArray(edge);
793 deviceLayerBounds.toFloatArray(&edge[12]); 793 deviceLayerBounds.toFloatArray(&edge[12]);
(...skipping 16 matching lines...) Expand all
810 DCHECK(!clipped); 810 DCHECK(!clipped);
811 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped); 811 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped);
812 DCHECK(!clipped); 812 DCHECK(!clipped);
813 813
814 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft); 814 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft);
815 LayerQuad::Edge leftEdge(bottomLeft, topLeft); 815 LayerQuad::Edge leftEdge(bottomLeft, topLeft);
816 LayerQuad::Edge topEdge(topLeft, topRight); 816 LayerQuad::Edge topEdge(topLeft, topRight);
817 LayerQuad::Edge rightEdge(topRight, bottomRight); 817 LayerQuad::Edge rightEdge(topRight, bottomRight);
818 818
819 // Only apply anti-aliasing to edges not clipped by culling or scissorin g. 819 // Only apply anti-aliasing to edges not clipped by culling or scissorin g.
820 if (quad->topEdgeAA() && tileRect.y() == quad->rect.y()) 820 if (quad->top_edge_aa && tileRect.y() == quad->rect.y())
821 topEdge = deviceLayerEdges.top(); 821 topEdge = deviceLayerEdges.top();
822 if (quad->leftEdgeAA() && tileRect.x() == quad->rect.x()) 822 if (quad->left_edge_aa && tileRect.x() == quad->rect.x())
823 leftEdge = deviceLayerEdges.left(); 823 leftEdge = deviceLayerEdges.left();
824 if (quad->rightEdgeAA() && tileRect.right() == quad->rect.right()) 824 if (quad->right_edge_aa && tileRect.right() == quad->rect.right())
825 rightEdge = deviceLayerEdges.right(); 825 rightEdge = deviceLayerEdges.right();
826 if (quad->bottomEdgeAA() && tileRect.bottom() == quad->rect.bottom()) 826 if (quad->bottom_edge_aa && tileRect.bottom() == quad->rect.bottom())
827 bottomEdge = deviceLayerEdges.bottom(); 827 bottomEdge = deviceLayerEdges.bottom();
828 828
829 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1; 829 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1;
830 bottomEdge.scale(sign); 830 bottomEdge.scale(sign);
831 leftEdge.scale(sign); 831 leftEdge.scale(sign);
832 topEdge.scale(sign); 832 topEdge.scale(sign);
833 rightEdge.scale(sign); 833 rightEdge.scale(sign);
834 834
835 // Create device space quad. 835 // Create device space quad.
836 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); 836 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 // it. This is why this centered rect is used and not the original quadRect. 871 // it. This is why this centered rect is used and not the original quadRect.
872 gfx::RectF centeredRect(gfx::PointF(-0.5 * tileRect.width(), -0.5 * tileRect .height()), tileRect.size()); 872 gfx::RectF centeredRect(gfx::PointF(-0.5 * tileRect.width(), -0.5 * tileRect .height()), tileRect.size());
873 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix Location); 873 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix Location);
874 } 874 }
875 875
876 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ uad* quad) 876 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ uad* quad)
877 { 877 {
878 const VideoYUVProgram* program = videoYUVProgram(); 878 const VideoYUVProgram* program = videoYUVProgram();
879 DCHECK(program && (program->initialized() || isContextLost())); 879 DCHECK(program && (program->initialized() || isContextLost()));
880 880
881 const VideoLayerImpl::FramePlane& yPlane = quad->yPlane(); 881 const VideoLayerImpl::FramePlane& yPlane = quad->y_plane;
882 const VideoLayerImpl::FramePlane& uPlane = quad->uPlane(); 882 const VideoLayerImpl::FramePlane& uPlane = quad->u_plane;
883 const VideoLayerImpl::FramePlane& vPlane = quad->vPlane(); 883 const VideoLayerImpl::FramePlane& vPlane = quad->v_plane;
884 884
885 ResourceProvider::ScopedReadLockGL yPlaneLock(m_resourceProvider, yPlane.res ourceId); 885 ResourceProvider::ScopedReadLockGL yPlaneLock(m_resourceProvider, yPlane.res ourceId);
886 ResourceProvider::ScopedReadLockGL uPlaneLock(m_resourceProvider, uPlane.res ourceId); 886 ResourceProvider::ScopedReadLockGL uPlaneLock(m_resourceProvider, uPlane.res ourceId);
887 ResourceProvider::ScopedReadLockGL vPlaneLock(m_resourceProvider, vPlane.res ourceId); 887 ResourceProvider::ScopedReadLockGL vPlaneLock(m_resourceProvider, vPlane.res ourceId);
888 GLC(context(), context()->activeTexture(GL_TEXTURE1)); 888 GLC(context(), context()->activeTexture(GL_TEXTURE1));
889 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, yPlaneLock.textureId()) ); 889 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, yPlaneLock.textureId()) );
890 GLC(context(), context()->activeTexture(GL_TEXTURE2)); 890 GLC(context(), context()->activeTexture(GL_TEXTURE2));
891 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, uPlaneLock.textureId()) ); 891 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, uPlaneLock.textureId()) );
892 GLC(context(), context()->activeTexture(GL_TEXTURE3)); 892 GLC(context(), context()->activeTexture(GL_TEXTURE3));
893 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, vPlaneLock.textureId()) ); 893 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, vPlaneLock.textureId()) );
894 894
895 GLC(context(), context()->useProgram(program->program())); 895 GLC(context(), context()->useProgram(program->program()));
896 896
897 GLC(context(), context()->uniform2f(program->vertexShader().texScaleLocation (), quad->texScale().width(), quad->texScale().height())); 897 GLC(context(), context()->uniform2f(program->vertexShader().texScaleLocation (), quad->tex_scale.width(), quad->tex_scale.height()));
898 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati on(), 1)); 898 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati on(), 1));
899 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati on(), 2)); 899 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati on(), 2));
900 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati on(), 3)); 900 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati on(), 3));
901 901
902 // These values are magic numbers that are used in the transformation from Y UV to RGB color values. 902 // These values are magic numbers that are used in the transformation from Y UV to RGB color values.
903 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb .php 903 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb .php
904 float yuv2RGB[9] = { 904 float yuv2RGB[9] = {
905 1.164f, 1.164f, 1.164f, 905 1.164f, 1.164f, 1.164f,
906 0.f, -.391f, 2.018f, 906 0.f, -.391f, 2.018f,
907 1.596f, -.813f, 0.f, 907 1.596f, -.813f, 0.f,
(...skipping 22 matching lines...) Expand all
930 930
931 void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide oDrawQuad* quad) 931 void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide oDrawQuad* quad)
932 { 932 {
933 static float glMatrix[16]; 933 static float glMatrix[16];
934 934
935 DCHECK(m_capabilities.usingEglImage); 935 DCHECK(m_capabilities.usingEglImage);
936 936
937 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); 937 const VideoStreamTextureProgram* program = videoStreamTextureProgram();
938 GLC(context(), context()->useProgram(program->program())); 938 GLC(context(), context()->useProgram(program->program()));
939 939
940 toGLMatrix(&glMatrix[0], quad->matrix()); 940 toGLMatrix(&glMatrix[0], quad->matrix);
941 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix Location(), 1, false, glMatrix)); 941 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix Location(), 1, false, glMatrix));
942 942
943 GLC(context(), context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture Id())); 943 GLC(context(), context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture _id));
944 944
945 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0)); 945 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0));
946 946
947 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; 947 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ;
948 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); 948 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation());
949 } 949 }
950 950
951 struct TextureProgramBinding { 951 struct TextureProgramBinding {
952 template<class Program> void set( 952 template<class Program> void set(
953 Program* program, WebKit::WebGraphicsContext3D* context) 953 Program* program, WebKit::WebGraphicsContext3D* context)
(...skipping 16 matching lines...) Expand all
970 { 970 {
971 TextureProgramBinding::set(program, context); 971 TextureProgramBinding::set(program, context);
972 texTransformLocation = program->vertexShader().texTransformLocation(); 972 texTransformLocation = program->vertexShader().texTransformLocation();
973 } 973 }
974 int texTransformLocation; 974 int texTransformLocation;
975 }; 975 };
976 976
977 void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua d* quad) 977 void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua d* quad)
978 { 978 {
979 TexTransformTextureProgramBinding binding; 979 TexTransformTextureProgramBinding binding;
980 if (quad->flipped()) 980 if (quad->flipped)
981 binding.set(textureProgramFlip(), context()); 981 binding.set(textureProgramFlip(), context());
982 else 982 else
983 binding.set(textureProgram(), context()); 983 binding.set(textureProgram(), context());
984 GLC(context(), context()->useProgram(binding.programId)); 984 GLC(context(), context()->useProgram(binding.programId));
985 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); 985 GLC(context(), context()->uniform1i(binding.samplerLocation, 0));
986 const gfx::RectF& uvRect = quad->uvRect(); 986 const gfx::RectF& uvRect = quad->uv_rect;
987 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x() , uvRect.y(), uvRect.width(), uvRect.height())); 987 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x() , uvRect.y(), uvRect.width(), uvRect.height()));
988 988
989 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resourceId()); 989 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resource_id);
990 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId())); 990 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId()));
991 991
992 if (!quad->premultipliedAlpha()) { 992 if (!quad->premultiplied_alpha) {
993 // As it turns out, the premultiplied alpha blending function (ONE, ONE_ MINUS_SRC_ALPHA) 993 // As it turns out, the premultiplied alpha blending function (ONE, ONE_ MINUS_SRC_ALPHA)
994 // will never cause the alpha channel to be set to anything less than 1. 0 if it is 994 // will never cause the alpha channel to be set to anything less than 1. 0 if it is
995 // initialized to that value! Therefore, premultipliedAlpha being false is the first 995 // initialized to that value! Therefore, premultipliedAlpha being false is the first
996 // situation we can generally see an alpha channel less than 1.0 coming out of the 996 // situation we can generally see an alpha channel less than 1.0 coming out of the
997 // compositor. This is causing platform differences in some layout tests (see 997 // compositor. This is causing platform differences in some layout tests (see
998 // https://bugs.webkit.org/show_bug.cgi?id=82412), so in this situation, use a separate 998 // https://bugs.webkit.org/show_bug.cgi?id=82412), so in this situation, use a separate
999 // blend function for the alpha channel to avoid modifying it. Don't use colorMask for this 999 // blend function for the alpha channel to avoid modifying it. Don't use colorMask for this
1000 // as it has performance implications on some platforms. 1000 // as it has performance implications on some platforms.
1001 GLC(context(), context()->blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_S RC_ALPHA, GL_ZERO, GL_ONE)); 1001 GLC(context(), context()->blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_S RC_ALPHA, GL_ZERO, GL_ONE));
1002 } 1002 }
1003 1003
1004 setShaderOpacity(quad->opacity(), binding.alphaLocation); 1004 setShaderOpacity(quad->opacity(), binding.alphaLocation);
1005 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLoc ation); 1005 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLoc ation);
1006 1006
1007 if (!quad->premultipliedAlpha()) 1007 if (!quad->premultiplied_alpha)
1008 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); 1008 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
1009 } 1009 }
1010 1010
1011 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra wQuad* quad) 1011 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra wQuad* quad)
1012 { 1012 {
1013 TexTransformTextureProgramBinding binding; 1013 TexTransformTextureProgramBinding binding;
1014 binding.set(textureIOSurfaceProgram(), context()); 1014 binding.set(textureIOSurfaceProgram(), context());
1015 1015
1016 GLC(context(), context()->useProgram(binding.programId)); 1016 GLC(context(), context()->useProgram(binding.programId));
1017 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); 1017 GLC(context(), context()->uniform1i(binding.samplerLocation, 0));
1018 if (quad->orientation() == IOSurfaceDrawQuad::Flipped) 1018 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED)
1019 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua d->ioSurfaceSize().height(), quad->ioSurfaceSize().width(), quad->ioSurfaceSize( ).height() * -1.0)); 1019 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua d->io_surface_size.height(), quad->io_surface_size.width(), quad->io_surface_siz e.height() * -1.0));
1020 else 1020 else
1021 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0, quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height())); 1021 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0, quad->io_surface_size.width(), quad->io_surface_size.height()));
1022 1022
1023 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->ioSurf aceTextureId())); 1023 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->io_sur face_texture_id));
1024 1024
1025 setShaderOpacity(quad->opacity(), binding.alphaLocation); 1025 setShaderOpacity(quad->opacity(), binding.alphaLocation);
1026 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLoc ation); 1026 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLoc ation);
1027 1027
1028 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); 1028 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, 0));
1029 } 1029 }
1030 1030
1031 void GLRenderer::finishDrawingFrame(DrawingFrame& frame) 1031 void GLRenderer::finishDrawingFrame(DrawingFrame& frame)
1032 { 1032 {
1033 m_currentFramebufferLock.reset(); 1033 m_currentFramebufferLock.reset();
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 1611
1612 releaseRenderPassTextures(); 1612 releaseRenderPassTextures();
1613 } 1613 }
1614 1614
1615 bool GLRenderer::isContextLost() 1615 bool GLRenderer::isContextLost()
1616 { 1616 {
1617 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); 1617 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR);
1618 } 1618 }
1619 1619
1620 } // namespace cc 1620 } // namespace cc
OLDNEW
« no previous file with comments | « cc/draw_quad_unittest.cc ('k') | cc/heads_up_display_layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698