diff options
Diffstat (limited to 'cc/output')
-rw-r--r-- | cc/output/bsp_tree.cc | 3 | ||||
-rw-r--r-- | cc/output/bsp_walk_action.cc | 26 | ||||
-rw-r--r-- | cc/output/bsp_walk_action.h | 16 | ||||
-rw-r--r-- | cc/output/direct_renderer.cc | 105 | ||||
-rw-r--r-- | cc/output/direct_renderer.h | 24 | ||||
-rw-r--r-- | cc/output/dynamic_geometry_binding.cc | 70 | ||||
-rw-r--r-- | cc/output/dynamic_geometry_binding.h | 30 | ||||
-rw-r--r-- | cc/output/geometry_binding.cc | 92 | ||||
-rw-r--r-- | cc/output/geometry_binding.h | 49 | ||||
-rw-r--r-- | cc/output/gl_renderer.cc | 513 | ||||
-rw-r--r-- | cc/output/gl_renderer.h | 78 | ||||
-rw-r--r-- | cc/output/overlay_unittest.cc | 11 | ||||
-rw-r--r-- | cc/output/renderer_pixeltest.cc | 812 | ||||
-rw-r--r-- | cc/output/software_renderer.cc | 36 | ||||
-rw-r--r-- | cc/output/software_renderer.h | 5 | ||||
-rw-r--r-- | cc/output/static_geometry_binding.cc | 74 | ||||
-rw-r--r-- | cc/output/static_geometry_binding.h | 33 |
17 files changed, 1497 insertions, 480 deletions
diff --git a/cc/output/bsp_tree.cc b/cc/output/bsp_tree.cc index f2318ce..4eb87cb 100644 --- a/cc/output/bsp_tree.cc +++ b/cc/output/bsp_tree.cc @@ -62,10 +62,9 @@ void BspTree::BuildTree(BspNode* node, scoped_ptr<DrawPolygon> polygon; scoped_ptr<DrawPolygon> new_front; scoped_ptr<DrawPolygon> new_back; - bool split_result = false; // Time to split this geometry, *it needs to be split by node_data. polygon = polygon_list->take_front(); - split_result = + bool split_result = polygon->Split(*(node->node_data), &new_front, &new_back); DCHECK(split_result); if (!split_result) { diff --git a/cc/output/bsp_walk_action.cc b/cc/output/bsp_walk_action.cc index da5ada5..9ffc299 100644 --- a/cc/output/bsp_walk_action.cc +++ b/cc/output/bsp_walk_action.cc @@ -9,15 +9,37 @@ #include "base/memory/scoped_ptr.h" #include "cc/output/direct_renderer.h" #include "cc/quads/draw_polygon.h" +#include "cc/quads/draw_quad.h" namespace cc { -void BspWalkActionToVector::operator()(DrawPolygon* item) { - list_->push_back(item); +BspWalkActionDrawPolygon::BspWalkActionDrawPolygon( + DirectRenderer* renderer, + DirectRenderer::DrawingFrame* frame, + const gfx::Rect& render_pass_scissor, + bool using_scissor_as_optimization) + : renderer_(renderer), + frame_(frame), + render_pass_scissor_(render_pass_scissor), + using_scissor_as_optimization_(using_scissor_as_optimization) { +} + +void BspWalkActionDrawPolygon::operator()(DrawPolygon* item) { + gfx::Transform inverse_transform; + bool invertible = + item->original_ref()->quadTransform().GetInverse(&inverse_transform); + DCHECK(invertible); + item->TransformToLayerSpace(inverse_transform); + renderer_->DoDrawPolygon(*item, frame_, render_pass_scissor_, + using_scissor_as_optimization_); } BspWalkActionToVector::BspWalkActionToVector(std::vector<DrawPolygon*>* in_list) : list_(in_list) { } +void BspWalkActionToVector::operator()(DrawPolygon* item) { + list_->push_back(item); +} + } // namespace cc diff --git a/cc/output/bsp_walk_action.h b/cc/output/bsp_walk_action.h index ac8fa41..a89d8ea 100644 --- a/cc/output/bsp_walk_action.h +++ b/cc/output/bsp_walk_action.h @@ -20,6 +20,22 @@ class CC_EXPORT BspWalkAction { // The BspTree class takes ownership of all the DrawPolygons returned in list_ // so the BspTree must be preserved while elements in that vector are in use. +class CC_EXPORT BspWalkActionDrawPolygon : public BspWalkAction { + public: + void operator()(DrawPolygon* item) override; + + BspWalkActionDrawPolygon(DirectRenderer* renderer, + DirectRenderer::DrawingFrame* frame, + const gfx::Rect& render_pass_scissor, + bool using_scissor_as_optimization); + + private: + DirectRenderer* renderer_; + DirectRenderer::DrawingFrame* frame_; + const gfx::Rect& render_pass_scissor_; + bool using_scissor_as_optimization_; +}; + class CC_EXPORT BspWalkActionToVector : public BspWalkAction { public: explicit BspWalkActionToVector(std::vector<DrawPolygon*>* in_list); diff --git a/cc/output/direct_renderer.cc b/cc/output/direct_renderer.cc index 5867fce..0ae4179 100644 --- a/cc/output/direct_renderer.cc +++ b/cc/output/direct_renderer.cc @@ -12,6 +12,8 @@ #include "base/metrics/histogram.h" #include "base/trace_event/trace_event.h" #include "cc/base/math_util.h" +#include "cc/output/bsp_tree.h" +#include "cc/output/bsp_walk_action.h" #include "cc/output/copy_output_request.h" #include "cc/quads/draw_quad.h" #include "ui/gfx/geometry/rect_conversions.h" @@ -299,22 +301,27 @@ void DirectRenderer::SetScissorStateForQuad(const DrawingFrame* frame, EnsureScissorTestDisabled(); } +bool DirectRenderer::ShouldSkipQuad(const DrawQuad& quad, + const gfx::Rect& render_pass_scissor) { + if (render_pass_scissor.IsEmpty()) + return true; + + if (quad.isClipped()) { + gfx::Rect r = quad.clipRect(); + r.Intersect(render_pass_scissor); + return r.IsEmpty(); + } + + return false; +} + void DirectRenderer::SetScissorStateForQuadWithRenderPassScissor( const DrawingFrame* frame, const DrawQuad& quad, - const gfx::Rect& render_pass_scissor, - bool* should_skip_quad) { + const gfx::Rect& render_pass_scissor) { gfx::Rect quad_scissor_rect = render_pass_scissor; - if (quad.isClipped()) quad_scissor_rect.Intersect(quad.clipRect()); - - if (quad_scissor_rect.IsEmpty()) { - *should_skip_quad = true; - return; - } - - *should_skip_quad = false; SetScissorTestRectInDrawSpace(frame, quad_scissor_rect); } @@ -330,6 +337,46 @@ void DirectRenderer::SetScissorTestRectInDrawSpace( void DirectRenderer::FinishDrawingQuadList() {} +void DirectRenderer::DoDrawPolygon(const DrawPolygon& poly, + DrawingFrame* frame, + const gfx::Rect& render_pass_scissor, + bool using_scissor_as_optimization) { + if (using_scissor_as_optimization) { + SetScissorStateForQuadWithRenderPassScissor(frame, *poly.original_ref(), + render_pass_scissor); + } else { + SetScissorStateForQuad(frame, *poly.original_ref()); + } + + // If the poly has not been split, then it is just a normal DrawQuad, + // and we should save any extra processing that would have to be done. + if (!poly.is_split()) { + DoDrawQuad(frame, poly.original_ref(), NULL); + return; + } + + std::vector<gfx::QuadF> quads; + poly.ToQuads2D(&quads); + for (size_t i = 0; i < quads.size(); ++i) { + DoDrawQuad(frame, poly.original_ref(), &quads[i]); + } +} + +void DirectRenderer::FlushPolygons(ScopedPtrDeque<DrawPolygon>* poly_list, + DrawingFrame* frame, + const gfx::Rect& render_pass_scissor, + bool using_scissor_as_optimization) { + if (poly_list->empty()) { + return; + } + + BspTree bsp_tree(poly_list); + BspWalkActionDrawPolygon action_handler(this, frame, render_pass_scissor, + using_scissor_as_optimization); + bsp_tree.TraverseWithActionHandler(&action_handler); + DCHECK(poly_list->empty()); +} + void DirectRenderer::DrawRenderPass(DrawingFrame* frame, const RenderPass* render_pass) { TRACE_EVENT0("cc", "DirectRenderer::DrawRenderPass"); @@ -369,21 +416,49 @@ void DirectRenderer::DrawRenderPass(DrawingFrame* frame, } const QuadList& quad_list = render_pass->quad_list; + ScopedPtrDeque<DrawPolygon> poly_list; + + int next_polygon_id = 0; + int last_sorting_context_id = 0; for (auto it = quad_list.BackToFrontBegin(); it != quad_list.BackToFrontEnd(); ++it) { const DrawQuad& quad = **it; - bool should_skip_quad = false; + gfx::QuadF send_quad(quad.visible_rect); + + if (using_scissor_as_optimization && + ShouldSkipQuad(quad, render_pass_scissor)) { + continue; + } + + if (last_sorting_context_id != quad.shared_quad_state->sorting_context_id) { + last_sorting_context_id = quad.shared_quad_state->sorting_context_id; + FlushPolygons(&poly_list, frame, render_pass_scissor, + using_scissor_as_optimization); + } + + // This layer is in a 3D sorting context so we add it to the list of + // polygons to go into the BSP tree. + if (quad.shared_quad_state->sorting_context_id != 0) { + scoped_ptr<DrawPolygon> new_polygon(new DrawPolygon( + *it, quad.visible_rect, quad.quadTransform(), next_polygon_id++)); + if (new_polygon->points().size() > 2u) { + poly_list.push_back(new_polygon.Pass()); + } + continue; + } + // We are not in a 3d sorting context, so we should draw the quad normally. if (using_scissor_as_optimization) { - SetScissorStateForQuadWithRenderPassScissor( - frame, quad, render_pass_scissor, &should_skip_quad); + SetScissorStateForQuadWithRenderPassScissor(frame, quad, + render_pass_scissor); } else { SetScissorStateForQuad(frame, quad); } - if (!should_skip_quad) - DoDrawQuad(frame, &quad); + DoDrawQuad(frame, &quad, nullptr); } + FlushPolygons(&poly_list, frame, render_pass_scissor, + using_scissor_as_optimization); FinishDrawingQuadList(); } diff --git a/cc/output/direct_renderer.h b/cc/output/direct_renderer.h index e07cb93..3399491 100644 --- a/cc/output/direct_renderer.h +++ b/cc/output/direct_renderer.h @@ -9,13 +9,17 @@ #include "base/callback.h" #include "base/containers/scoped_ptr_hash_map.h" #include "cc/base/cc_export.h" +#include "cc/base/scoped_ptr_deque.h" #include "cc/output/overlay_processor.h" #include "cc/output/renderer.h" #include "cc/resources/resource_provider.h" #include "cc/resources/scoped_resource.h" +#include "cc/resources/task_graph_runner.h" +#include "ui/gfx/geometry/quad_f.h" namespace cc { +class DrawPolygon; class ResourceProvider; // This is the base class for code shared between the GL and software @@ -56,6 +60,10 @@ class CC_EXPORT DirectRenderer : public Renderer { }; void SetEnlargePassTextureAmountForTesting(const gfx::Vector2d& amount); + void DoDrawPolygon(const DrawPolygon& poly, + DrawingFrame* frame, + const gfx::Rect& render_pass_scissor, + bool using_scissor_as_optimization); protected: DirectRenderer(RendererClient* client, @@ -78,16 +86,21 @@ class CC_EXPORT DirectRenderer : public Renderer { gfx::Rect DeviceClipRectInWindowSpace(const DrawingFrame* frame) const; static gfx::Rect ComputeScissorRectForRenderPass(const DrawingFrame* frame); void SetScissorStateForQuad(const DrawingFrame* frame, const DrawQuad& quad); + bool ShouldSkipQuad(const DrawQuad& quad, + const gfx::Rect& render_pass_scissor); void SetScissorStateForQuadWithRenderPassScissor( const DrawingFrame* frame, const DrawQuad& quad, - const gfx::Rect& render_pass_scissor, - bool* should_skip_quad); + const gfx::Rect& render_pass_scissor); void SetScissorTestRectInDrawSpace(const DrawingFrame* frame, const gfx::Rect& draw_space_rect); static gfx::Size RenderPassTextureSize(const RenderPass* render_pass); + void FlushPolygons(ScopedPtrDeque<DrawPolygon>* poly_list, + DrawingFrame* frame, + const gfx::Rect& render_pass_scissor, + bool using_scissor_as_optimization); void DrawRenderPass(DrawingFrame* frame, const RenderPass* render_pass); bool UseRenderPass(DrawingFrame* frame, const RenderPass* render_pass); @@ -101,7 +114,12 @@ class CC_EXPORT DirectRenderer : public Renderer { bool draw_rect_covers_full_surface) = 0; virtual void ClearFramebuffer(DrawingFrame* frame, bool has_external_stencil_test) = 0; - virtual void DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) = 0; + // clip_region is a (possibly null) pointer to a quad in the same + // space as the quad. When non-null only the area of the quad that overlaps + // with clip_region will be drawn. + virtual void DoDrawQuad(DrawingFrame* frame, + const DrawQuad* quad, + const gfx::QuadF* clip_region) = 0; virtual void BeginDrawingFrame(DrawingFrame* frame) = 0; virtual void FinishDrawingFrame(DrawingFrame* frame) = 0; virtual void FinishDrawingQuadList(); diff --git a/cc/output/dynamic_geometry_binding.cc b/cc/output/dynamic_geometry_binding.cc new file mode 100644 index 0000000..8eeff0c --- /dev/null +++ b/cc/output/dynamic_geometry_binding.cc @@ -0,0 +1,70 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cc/output/dynamic_geometry_binding.h" + +#include "cc/output/gl_renderer.h" // For the GLC() macro. +#include "gpu/command_buffer/client/gles2_interface.h" +#include "ui/gfx/geometry/rect_f.h" + +namespace cc { + +DynamicGeometryBinding::DynamicGeometryBinding(gpu::gles2::GLES2Interface* gl) + : gl_(gl), quad_vertices_vbo_(0), quad_elements_vbo_(0) { + GeometryBindingQuad quads[8]; + GeometryBindingQuadIndex quad_indices[8]; + + static_assert(sizeof(GeometryBindingQuad) == 24 * sizeof(float), + "struct Quad should be densely packed"); + static_assert(sizeof(GeometryBindingQuadIndex) == 6 * sizeof(uint16_t), + "struct QuadIndex should be densely packed"); + + GLC(gl_, gl_->GenBuffers(1, &quad_vertices_vbo_)); + GLC(gl_, gl_->GenBuffers(1, &quad_elements_vbo_)); + + GLC(gl_, gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); + GLC(gl_, gl_->BufferData(GL_ARRAY_BUFFER, sizeof(GeometryBindingQuad) * 1, + quads, GL_DYNAMIC_DRAW)); + + GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_)); + GLC(gl_, gl_->BufferData(GL_ELEMENT_ARRAY_BUFFER, + sizeof(GeometryBindingQuadIndex) * 1, &quad_indices, + GL_DYNAMIC_DRAW)); +} + +void DynamicGeometryBinding::InitializeCustomQuad(const gfx::QuadF& quad) { + float uv[] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}; + InitializeCustomQuadWithUVs(quad, uv); +} + +void DynamicGeometryBinding::InitializeCustomQuadWithUVs(const gfx::QuadF& quad, + const float uv[8]) { + GeometryBindingVertex v0 = { + {quad.p1().x(), quad.p1().y(), 0.0f}, {uv[0], uv[1]}, 0.0f}; + GeometryBindingVertex v1 = { + {quad.p2().x(), quad.p2().y(), 0.0f}, {uv[2], uv[3]}, 1.0f}; + GeometryBindingVertex v2 = { + {quad.p3().x(), quad.p3().y(), 0.0f}, {uv[4], uv[5]}, 2.0f}; + GeometryBindingVertex v3 = { + {quad.p4().x(), quad.p4().y(), 0.0f}, {uv[6], uv[7]}, 3.0f}; + + GeometryBindingQuad local_quad = {v0, v1, v2, v3}; + GeometryBindingQuadIndex quad_index = {{static_cast<uint16>(0), + static_cast<uint16>(1), + static_cast<uint16>(2), + static_cast<uint16>(3), + static_cast<uint16>(0), + static_cast<uint16>(2)}}; + + GLC(gl_, gl_->BufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GeometryBindingQuad), + &local_quad)); + GLC(gl_, gl_->BufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, + sizeof(GeometryBindingQuadIndex), &quad_index)); +} + +void DynamicGeometryBinding::PrepareForDraw() { + SetupGLContext(gl_, quad_elements_vbo_, quad_vertices_vbo_); +} + +} // namespace cc diff --git a/cc/output/dynamic_geometry_binding.h b/cc/output/dynamic_geometry_binding.h new file mode 100644 index 0000000..4e4ea3d --- /dev/null +++ b/cc/output/dynamic_geometry_binding.h @@ -0,0 +1,30 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CC_OUTPUT_DYNAMIC_GEOMETRY_BINDING_H_ +#define CC_OUTPUT_DYNAMIC_GEOMETRY_BINDING_H_ + +#include "cc/output/geometry_binding.h" + +namespace cc { + +class DynamicGeometryBinding { + public: + explicit DynamicGeometryBinding(gpu::gles2::GLES2Interface* gl); + void PrepareForDraw(); + void InitializeCustomQuad(const gfx::QuadF& quad); + void InitializeCustomQuadWithUVs(const gfx::QuadF& quad, const float uv[8]); + + private: + gpu::gles2::GLES2Interface* gl_; + + GLuint quad_vertices_vbo_; + GLuint quad_elements_vbo_; + + DISALLOW_COPY_AND_ASSIGN(DynamicGeometryBinding); +}; + +} // namespace cc + +#endif // CC_OUTPUT_DYNAMIC_GEOMETRY_BINDING_H_ diff --git a/cc/output/geometry_binding.cc b/cc/output/geometry_binding.cc index eda2a5c..c3cdf73 100644 --- a/cc/output/geometry_binding.cc +++ b/cc/output/geometry_binding.cc @@ -10,70 +10,12 @@ namespace cc { -GeometryBinding::GeometryBinding(gpu::gles2::GLES2Interface* gl, - const gfx::RectF& quad_vertex_rect) - : gl_(gl), quad_vertices_vbo_(0), quad_elements_vbo_(0) { - struct Vertex { - float a_position[3]; - float a_texCoord[2]; - // Index of the vertex, divide by 4 to have the matrix for this quad. - float a_index; - }; - struct Quad { - Vertex v0, v1, v2, v3; - }; - struct QuadIndex { - uint16 data[6]; - }; - - static_assert(sizeof(Quad) == 24 * sizeof(float), - "struct Quad should be densely packed"); - static_assert(sizeof(QuadIndex) == 6 * sizeof(uint16_t), - "struct QuadIndex should be densely packed"); - - Quad quad_list[8]; - QuadIndex quad_index_list[8]; - for (int i = 0; i < 8; i++) { - Vertex v0 = {{quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f, }, - {0.0f, 1.0f, }, i * 4.0f + 0.0f}; - Vertex v1 = {{quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f, }, - {0.0f, 0.0f, }, i * 4.0f + 1.0f}; - Vertex v2 = {{quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f, }, - {1.0f, .0f, }, i * 4.0f + 2.0f}; - Vertex v3 = {{quad_vertex_rect.right(), quad_vertex_rect.bottom(), 0.0f, }, - {1.0f, 1.0f, }, i * 4.0f + 3.0f}; - Quad x = {v0, v1, v2, v3}; - quad_list[i] = x; - QuadIndex y = { - {static_cast<uint16>(0 + 4 * i), static_cast<uint16>(1 + 4 * i), - static_cast<uint16>(2 + 4 * i), static_cast<uint16>(3 + 4 * i), - static_cast<uint16>(0 + 4 * i), static_cast<uint16>(2 + 4 * i)}}; - quad_index_list[i] = y; - } - - gl_->GenBuffers(1, &quad_vertices_vbo_); - gl_->GenBuffers(1, &quad_elements_vbo_); - GLC(gl_, gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); - GLC(gl_, - gl_->BufferData( - GL_ARRAY_BUFFER, sizeof(quad_list), quad_list, GL_STATIC_DRAW)); - GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_)); - GLC(gl_, - gl_->BufferData(GL_ELEMENT_ARRAY_BUFFER, - sizeof(quad_index_list), - quad_index_list, - GL_STATIC_DRAW)); -} - -GeometryBinding::~GeometryBinding() { - gl_->DeleteBuffers(1, &quad_vertices_vbo_); - gl_->DeleteBuffers(1, &quad_elements_vbo_); -} - -void GeometryBinding::PrepareForDraw() { - GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_)); +void SetupGLContext(gpu::gles2::GLES2Interface* gl, + GLuint quad_elements_vbo, + GLuint quad_vertices_vbo) { + GLC(gl, gl->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo)); - GLC(gl_, gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); + GLC(gl, gl->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo)); // OpenGL defines the last parameter to VertexAttribPointer as type // "const GLvoid*" even though it is actually an offset into the buffer // object's data store and not a pointer to the client's address space. @@ -83,15 +25,21 @@ void GeometryBinding::PrepareForDraw() { reinterpret_cast<const void*>(5 * sizeof(float)), }; - GLC(gl_, gl_->VertexAttribPointer(PositionAttribLocation(), 3, GL_FLOAT, - false, 6 * sizeof(float), offsets[0])); - GLC(gl_, gl_->VertexAttribPointer(TexCoordAttribLocation(), 2, GL_FLOAT, - false, 6 * sizeof(float), offsets[1])); - GLC(gl_, gl_->VertexAttribPointer(TriangleIndexAttribLocation(), 1, GL_FLOAT, - false, 6 * sizeof(float), offsets[2])); - GLC(gl_, gl_->EnableVertexAttribArray(PositionAttribLocation())); - GLC(gl_, gl_->EnableVertexAttribArray(TexCoordAttribLocation())); - GLC(gl_, gl_->EnableVertexAttribArray(TriangleIndexAttribLocation())); + GLC(gl, + gl->VertexAttribPointer(GeometryBinding::PositionAttribLocation(), 3, + GL_FLOAT, false, 6 * sizeof(float), offsets[0])); + GLC(gl, + gl->VertexAttribPointer(GeometryBinding::TexCoordAttribLocation(), 2, + GL_FLOAT, false, 6 * sizeof(float), offsets[1])); + GLC(gl, + gl->VertexAttribPointer(GeometryBinding::TriangleIndexAttribLocation(), 1, + GL_FLOAT, false, 6 * sizeof(float), offsets[2])); + GLC(gl, + gl->EnableVertexAttribArray(GeometryBinding::PositionAttribLocation())); + GLC(gl, + gl->EnableVertexAttribArray(GeometryBinding::TexCoordAttribLocation())); + GLC(gl, gl->EnableVertexAttribArray( + GeometryBinding::TriangleIndexAttribLocation())); } } // namespace cc diff --git a/cc/output/geometry_binding.h b/cc/output/geometry_binding.h index cfa21ef..ef08b7d 100644 --- a/cc/output/geometry_binding.h +++ b/cc/output/geometry_binding.h @@ -6,43 +6,52 @@ #define CC_OUTPUT_GEOMETRY_BINDING_H_ #include "base/basictypes.h" +#include "cc/output/gl_renderer.h" // For the GLC() macro. +#include "gpu/command_buffer/client/gles2_interface.h" #include "third_party/khronos/GLES2/gl2.h" +#include "third_party/khronos/GLES2/gl2ext.h" +#include "ui/gfx/geometry/rect_f.h" namespace gfx { -class RectF; -} -namespace gpu { -namespace gles2 { -class GLES2Interface; -} +class QuadF; +class Quad; +class QuadIndex; +class PointF; } namespace cc { -class GeometryBinding { - public: - GeometryBinding(gpu::gles2::GLES2Interface* gl, - const gfx::RectF& quad_vertex_rect); - ~GeometryBinding(); +struct GeometryBindingVertex { + float a_position[3]; + float a_texCoord[2]; + // Index of the vertex, divide by 4 to have the matrix for this quad. + float a_index; +}; + +struct GeometryBindingQuad { + GeometryBindingVertex v0, v1, v2, v3; +}; - void PrepareForDraw(); +struct GeometryBindingQuadIndex { + uint16 data[6]; +}; +class DrawQuad; +class DrawPolygon; + +struct GeometryBinding { // All layer shaders share the same attribute locations for the vertex // positions and texture coordinates. This allows switching shaders without // rebinding attribute arrays. static int PositionAttribLocation() { return 0; } static int TexCoordAttribLocation() { return 1; } static int TriangleIndexAttribLocation() { return 2; } - - private: - gpu::gles2::GLES2Interface* gl_; - - GLuint quad_vertices_vbo_; - GLuint quad_elements_vbo_; - - DISALLOW_COPY_AND_ASSIGN(GeometryBinding); }; +void SetupGLContext(gpu::gles2::GLES2Interface* gl, + GLuint quad_elements_vbo, + GLuint quad_vertices_vbo); + } // namespace cc #endif // CC_OUTPUT_GEOMETRY_BINDING_H_ diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc index 6142d96..c340da9 100644 --- a/cc/output/gl_renderer.cc +++ b/cc/output/gl_renderer.cc @@ -11,6 +11,11 @@ #include <vector> #include "base/logging.h" +#include "base/memory/scoped_ptr.h" +#include "base/strings/string_split.h" +#include "base/strings/string_util.h" +#include "base/strings/stringprintf.h" +#include "build/build_config.h" #include "base/trace_event/trace_event.h" #include "cc/base/math_util.h" #include "cc/layers/video_layer_impl.h" @@ -18,10 +23,12 @@ #include "cc/output/compositor_frame_metadata.h" #include "cc/output/context_provider.h" #include "cc/output/copy_output_request.h" -#include "cc/output/geometry_binding.h" +#include "cc/output/dynamic_geometry_binding.h" #include "cc/output/gl_frame_data.h" #include "cc/output/output_surface.h" #include "cc/output/render_surface_filters.h" +#include "cc/output/static_geometry_binding.h" +#include "cc/quads/draw_polygon.h" #include "cc/quads/picture_draw_quad.h" #include "cc/quads/render_pass.h" #include "cc/quads/stream_video_draw_quad.h" @@ -324,7 +331,8 @@ GLRenderer::GLRenderer(RendererClient* client, highp_threshold_min_(highp_threshold_min), highp_threshold_cache_(0), use_sync_query_(false), - on_demand_tile_raster_resource_id_(0) { + on_demand_tile_raster_resource_id_(0), + bound_geometry_(NO_BINDING) { DCHECK(gl_); DCHECK(context_support_); @@ -494,10 +502,12 @@ void GLRenderer::DoNoOp() { GLC(gl_, gl_->Flush()); } -void GLRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { +void GLRenderer::DoDrawQuad(DrawingFrame* frame, + const DrawQuad* quad, + const gfx::QuadF* clip_region) { DCHECK(quad->rect.Contains(quad->visible_rect)); if (quad->material != DrawQuad::TEXTURE_CONTENT) { - FlushTextureQuadCache(); + FlushTextureQuadCache(SHARED_BINDING); } switch (quad->material) { @@ -505,26 +515,31 @@ void GLRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { NOTREACHED(); break; case DrawQuad::CHECKERBOARD: - DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); + DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad), + clip_region); break; case DrawQuad::DEBUG_BORDER: DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); break; case DrawQuad::IO_SURFACE_CONTENT: - DrawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad)); + DrawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad), + clip_region); break; case DrawQuad::PICTURE_CONTENT: // PictureDrawQuad should only be used for resourceless software draws. NOTREACHED(); break; case DrawQuad::RENDER_PASS: - DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); + DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad), + clip_region); break; case DrawQuad::SOLID_COLOR: - DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad)); + DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad), + clip_region); break; case DrawQuad::STREAM_VIDEO_CONTENT: - DrawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad)); + DrawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad), + clip_region); break; case DrawQuad::SURFACE_CONTENT: // Surface content should be fully resolved to other quad types before @@ -532,19 +547,28 @@ void GLRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { NOTREACHED(); break; case DrawQuad::TEXTURE_CONTENT: - EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); + EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad), + clip_region); break; case DrawQuad::TILED_CONTENT: - DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); + DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region); break; case DrawQuad::YUV_VIDEO_CONTENT: - DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); + DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad), + clip_region); break; } } void GLRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, - const CheckerboardDrawQuad* quad) { + const CheckerboardDrawQuad* quad, + const gfx::QuadF* clip_region) { + // TODO(enne) For now since checkerboards shouldn't be part of a 3D + // context, clipping regions aren't supported so we skip drawing them + // if this becomes the case. + if (clip_region) { + return; + } SetBlendEnabled(quad->ShouldDrawWithBlending()); const TileCheckerboardProgram* program = GetTileCheckerboardProgram(); @@ -586,6 +610,9 @@ void GLRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, program->vertex_shader().matrix_location()); } +// This function does not handle 3D sorting right now, since the debug border +// quads are just drawn as their original quads and not in split pieces. This +// results in some debug border quads drawing over foreground quads. void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, const DebugBorderDrawQuad* quad) { SetBlendEnabled(quad->ShouldDrawWithBlending()); @@ -817,13 +844,56 @@ bool GLRenderer::ShouldApplyBackgroundFilters(DrawingFrame* frame, return true; } +// This takes a gfx::Rect and a clip region quad in the same space, +// and returns a quad with the same proportions in the space -0.5->0.5. +bool GetScaledRegion(const gfx::Rect& rect, + const gfx::QuadF* clip, + gfx::QuadF* scaled_region) { + if (!clip) + return false; + + gfx::PointF p1(((clip->p1().x() - rect.x()) / rect.width()) - 0.5f, + ((clip->p1().y() - rect.y()) / rect.height()) - 0.5f); + gfx::PointF p2(((clip->p2().x() - rect.x()) / rect.width()) - 0.5f, + ((clip->p2().y() - rect.y()) / rect.height()) - 0.5f); + gfx::PointF p3(((clip->p3().x() - rect.x()) / rect.width()) - 0.5f, + ((clip->p3().y() - rect.y()) / rect.height()) - 0.5f); + gfx::PointF p4(((clip->p4().x() - rect.x()) / rect.width()) - 0.5f, + ((clip->p4().y() - rect.y()) / rect.height()) - 0.5f); + *scaled_region = gfx::QuadF(p1, p2, p3, p4); + return true; +} + +// This takes a gfx::Rect and a clip region quad in the same space, +// and returns the proportional uv's in the space 0->1. +bool GetScaledUVs(const gfx::Rect& rect, const gfx::QuadF* clip, float uvs[8]) { + if (!clip) + return false; + + uvs[0] = ((clip->p1().x() - rect.x()) / rect.width()); + uvs[1] = ((clip->p1().y() - rect.y()) / rect.height()); + uvs[2] = ((clip->p2().x() - rect.x()) / rect.width()); + uvs[3] = ((clip->p2().y() - rect.y()) / rect.height()); + uvs[4] = ((clip->p3().x() - rect.x()) / rect.width()); + uvs[5] = ((clip->p3().y() - rect.y()) / rect.height()); + uvs[6] = ((clip->p4().x() - rect.x()) / rect.width()); + uvs[7] = ((clip->p4().y() - rect.y()) / rect.height()); + return true; +} + gfx::Rect GLRenderer::GetBackdropBoundingBoxForRenderPassQuad( DrawingFrame* frame, const RenderPassDrawQuad* quad, const gfx::Transform& contents_device_transform, + const gfx::QuadF* clip_region, bool use_aa) { + gfx::QuadF scaled_region; + if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { + scaled_region = SharedGeometryQuad().BoundingBox(); + } + gfx::Rect backdrop_rect = gfx::ToEnclosingRect(MathUtil::MapClippedRect( - contents_device_transform, SharedGeometryQuad().BoundingBox())); + contents_device_transform, scaled_region.BoundingBox())); if (ShouldApplyBackgroundFilters(frame, quad)) { int top, right, bottom, left; @@ -872,7 +942,8 @@ skia::RefPtr<SkImage> GLRenderer::ApplyBackgroundFilters( } void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, - const RenderPassDrawQuad* quad) { + const RenderPassDrawQuad* quad, + const gfx::QuadF* clip_region) { ScopedResource* contents_texture = render_pass_textures_.get(quad->render_pass_id); if (!contents_texture || !contents_texture->id()) @@ -894,10 +965,8 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, ShouldAntialiasQuad(contents_device_transform, quad, settings_->force_antialiasing); - if (use_aa) - SetupQuadForAntialiasing(contents_device_transform, quad, - &surface_quad, edge); - + SetupQuadForClippingAndAntialiasing(contents_device_transform, quad, use_aa, + clip_region, &surface_quad, edge); SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode; bool use_shaders_for_blending = !CanApplyBlendModeUsingBlendFunc(blend_mode) || @@ -911,7 +980,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame, // Compute a bounding box around the pixels that will be visible through // the quad. background_rect = GetBackdropBoundingBoxForRenderPassQuad( - frame, quad, contents_device_transform, use_aa); + frame, quad, contents_device_transform, clip_region, use_aa); if (!background_rect.IsEmpty()) { // The pixels from the filtered background should completely replace the @@ -1334,15 +1403,78 @@ static void SolidColorUniformLocation(T program, uniforms->color_location = program->fragment_shader().color_location(); } +namespace { +// These functions determine if a quad, clipped by a clip_region contains +// the entire {top|bottom|left|right} edge. +bool is_top(const gfx::QuadF* clip_region, const DrawQuad* quad) { + if (!quad->IsTopEdge()) + return false; + if (!clip_region) + return true; + + return std::abs(clip_region->p1().y()) < kAntiAliasingEpsilon && + std::abs(clip_region->p2().y()) < kAntiAliasingEpsilon; +} + +bool is_bottom(const gfx::QuadF* clip_region, const DrawQuad* quad) { + if (!quad->IsBottomEdge()) + return false; + if (!clip_region) + return true; + + return std::abs(clip_region->p3().y() - + quad->shared_quad_state->content_bounds.height()) < + kAntiAliasingEpsilon && + std::abs(clip_region->p4().y() - + quad->shared_quad_state->content_bounds.height()) < + kAntiAliasingEpsilon; +} + +bool is_left(const gfx::QuadF* clip_region, const DrawQuad* quad) { + if (!quad->IsLeftEdge()) + return false; + if (!clip_region) + return true; + + return std::abs(clip_region->p1().x()) < kAntiAliasingEpsilon && + std::abs(clip_region->p4().x()) < kAntiAliasingEpsilon; +} + +bool is_right(const gfx::QuadF* clip_region, const DrawQuad* quad) { + if (!quad->IsRightEdge()) + return false; + if (!clip_region) + return true; + + return std::abs(clip_region->p2().x() - + quad->shared_quad_state->content_bounds.width()) < + kAntiAliasingEpsilon && + std::abs(clip_region->p3().x() - + quad->shared_quad_state->content_bounds.width()) < + kAntiAliasingEpsilon; +} +} // anonymous namespace + static gfx::QuadF GetDeviceQuadWithAntialiasingOnExteriorEdges( const LayerQuad& device_layer_edges, const gfx::Transform& device_transform, + const gfx::QuadF* clip_region, const DrawQuad* quad) { - gfx::Rect tile_rect = quad->visible_rect; - gfx::PointF bottom_right = tile_rect.bottom_right(); - gfx::PointF bottom_left = tile_rect.bottom_left(); - gfx::PointF top_left = tile_rect.origin(); - gfx::PointF top_right = tile_rect.top_right(); + gfx::RectF tile_rect = quad->visible_rect; + gfx::QuadF tile_quad(tile_rect); + + if (clip_region) { + if (quad->material != DrawQuad::RENDER_PASS) { + tile_quad = *clip_region; + } else { + GetScaledRegion(quad->rect, clip_region, &tile_quad); + } + } + + gfx::PointF bottom_right = tile_quad.p3(); + gfx::PointF bottom_left = tile_quad.p4(); + gfx::PointF top_left = tile_quad.p1(); + gfx::PointF top_right = tile_quad.p2(); bool clipped = false; // Map points to device space. We ignore |clipped|, since the result of @@ -1359,16 +1491,26 @@ static gfx::QuadF GetDeviceQuadWithAntialiasingOnExteriorEdges( LayerQuad::Edge right_edge(top_right, bottom_right); // Only apply anti-aliasing to edges not clipped by culling or scissoring. - if (quad->IsTopEdge() && tile_rect.y() == quad->rect.y()) + // If an edge is degenerate we do not want to replace it with a "proper" edge + // as that will cause the quad to possibly expand is strange ways. + if (!top_edge.degenerate() && is_top(clip_region, quad) && + tile_rect.y() == quad->rect.y()) { top_edge = device_layer_edges.top(); - if (quad->IsLeftEdge() && tile_rect.x() == quad->rect.x()) + } + if (!left_edge.degenerate() && is_left(clip_region, quad) && + tile_rect.x() == quad->rect.x()) { left_edge = device_layer_edges.left(); - if (quad->IsRightEdge() && tile_rect.right() == quad->rect.right()) + } + if (!right_edge.degenerate() && is_right(clip_region, quad) && + tile_rect.right() == quad->rect.right()) { right_edge = device_layer_edges.right(); - if (quad->IsBottomEdge() && tile_rect.bottom() == quad->rect.bottom()) + } + if (!bottom_edge.degenerate() && is_bottom(clip_region, quad) && + tile_rect.bottom() == quad->rect.bottom()) { bottom_edge = device_layer_edges.bottom(); + } - float sign = gfx::QuadF(tile_rect).IsCounterClockwise() ? -1 : 1; + float sign = tile_quad.IsCounterClockwise() ? -1 : 1; bottom_edge.scale(sign); left_edge.scale(sign); top_edge.scale(sign); @@ -1378,6 +1520,32 @@ static gfx::QuadF GetDeviceQuadWithAntialiasingOnExteriorEdges( return LayerQuad(left_edge, top_edge, right_edge, bottom_edge).ToQuadF(); } +float GetTotalQuadError(const gfx::QuadF* clipped_quad, + const gfx::QuadF* ideal_rect) { + return (clipped_quad->p1() - ideal_rect->p1()).LengthSquared() + + (clipped_quad->p2() - ideal_rect->p2()).LengthSquared() + + (clipped_quad->p3() - ideal_rect->p3()).LengthSquared() + + (clipped_quad->p4() - ideal_rect->p4()).LengthSquared(); +} + +// Attempt to rotate the clipped quad until it lines up the most +// correctly. This is necessary because we check the edges of this +// quad against the expected left/right/top/bottom for anti-aliasing. +void AlignQuadToBoundingBox(gfx::QuadF* clipped_quad) { + gfx::QuadF bounding_quad = gfx::QuadF(clipped_quad->BoundingBox()); + gfx::QuadF best_rotation = *clipped_quad; + float least_error_amount = GetTotalQuadError(clipped_quad, &bounding_quad); + for (size_t i = 1; i < 4; ++i) { + clipped_quad->Realign(1); + float new_error = GetTotalQuadError(clipped_quad, &bounding_quad); + if (new_error < least_error_amount) { + least_error_amount = new_error; + best_rotation = *clipped_quad; + } + } + *clipped_quad = best_rotation; +} + // static bool GLRenderer::ShouldAntialiasQuad(const gfx::Transform& device_transform, const DrawQuad* quad, @@ -1409,18 +1577,39 @@ bool GLRenderer::ShouldAntialiasQuad(const gfx::Transform& device_transform, } // static -void GLRenderer::SetupQuadForAntialiasing( +void GLRenderer::SetupQuadForClippingAndAntialiasing( const gfx::Transform& device_transform, const DrawQuad* quad, + bool use_aa, + const gfx::QuadF* clip_region, gfx::QuadF* local_quad, float edge[24]) { bool is_render_pass_quad = (quad->material == DrawQuad::RENDER_PASS); - gfx::RectF content_rect = - is_render_pass_quad ? QuadVertexRect() : quad->visibleContentRect(); - + gfx::QuadF rotated_clip; + const gfx::QuadF* local_clip_region = clip_region; + if (local_clip_region) { + rotated_clip = *clip_region; + AlignQuadToBoundingBox(&rotated_clip); + local_clip_region = &rotated_clip; + } + + gfx::QuadF content_rect = is_render_pass_quad + ? gfx::QuadF(QuadVertexRect()) + : gfx::QuadF(quad->visibleContentRect()); + if (!use_aa) { + if (local_clip_region) { + if (!is_render_pass_quad) { + content_rect = *local_clip_region; + } else { + GetScaledRegion(quad->rect, local_clip_region, &content_rect); + } + *local_quad = content_rect; + } + return; + } bool clipped = false; gfx::QuadF device_layer_quad = - MathUtil::MapQuad(device_transform, gfx::QuadF(content_rect), &clipped); + MathUtil::MapQuad(device_transform, content_rect, &clipped); LayerQuad device_layer_bounds(gfx::QuadF(device_layer_quad.BoundingBox())); device_layer_bounds.InflateAntiAliasingDistance(); @@ -1431,16 +1620,25 @@ void GLRenderer::SetupQuadForAntialiasing( device_layer_edges.ToFloatArray(edge); device_layer_bounds.ToFloatArray(&edge[12]); + // If we have a clip region then we are split, and therefore + // by necessity, at least one of our edges is not an external + // one. + bool is_full_rect = quad->visible_rect == quad->rect; + + bool region_contains_all_outside_edges = + is_full_rect && + (is_top(local_clip_region, quad) && is_left(local_clip_region, quad) && + is_bottom(local_clip_region, quad) && is_right(local_clip_region, quad)); + bool use_aa_on_all_four_edges = - is_render_pass_quad || - (quad->IsTopEdge() && quad->IsLeftEdge() && quad->IsBottomEdge() && - quad->IsRightEdge() && quad->visible_rect == quad->rect); + !local_clip_region && + (is_render_pass_quad || region_contains_all_outside_edges); gfx::QuadF device_quad = use_aa_on_all_four_edges ? device_layer_edges.ToQuadF() : GetDeviceQuadWithAntialiasingOnExteriorEdges( - device_layer_edges, device_transform, quad); + device_layer_edges, device_transform, local_clip_region, quad); // Map device space quad to local space. device_transform has no 3d // component since it was flattened, so we don't need to project. We should @@ -1456,7 +1654,8 @@ void GLRenderer::SetupQuadForAntialiasing( } void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame, - const SolidColorDrawQuad* quad) { + const SolidColorDrawQuad* quad, + const gfx::QuadF* clip_region) { gfx::Rect tile_rect = quad->visible_rect; SkColor color = quad->color; @@ -1480,10 +1679,11 @@ void GLRenderer::DrawSolidColorQuad(const DrawingFrame* frame, bool use_aa = settings_->allow_antialiasing && !quad->force_anti_aliasing_off && ShouldAntialiasQuad(device_transform, quad, force_aa); + SetupQuadForClippingAndAntialiasing(device_transform, quad, use_aa, + clip_region, &local_quad, edge); SolidColorProgramUniforms uniforms; if (use_aa) { - SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge); SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms); } else { SolidColorUniformLocation(GetSolidColorProgram(), &uniforms); @@ -1554,13 +1754,15 @@ static void TileUniformLocation(T program, TileProgramUniforms* uniforms) { } void GLRenderer::DrawTileQuad(const DrawingFrame* frame, - const TileDrawQuad* quad) { - DrawContentQuad(frame, quad, quad->resource_id); + const TileDrawQuad* quad, + const gfx::QuadF* clip_region) { + DrawContentQuad(frame, quad, quad->resource_id, clip_region); } void GLRenderer::DrawContentQuad(const DrawingFrame* frame, const ContentDrawQuadBase* quad, - ResourceProvider::ResourceId resource_id) { + ResourceProvider::ResourceId resource_id, + const gfx::QuadF* clip_region) { gfx::Transform device_transform = frame->window_matrix * frame->projection_matrix * quad->quadTransform(); device_transform.FlattenTo2d(); @@ -1572,15 +1774,16 @@ void GLRenderer::DrawContentQuad(const DrawingFrame* frame, // similar to the way DrawContentQuadNoAA works and then consider // combining DrawContentQuadAA and DrawContentQuadNoAA into one method. if (use_aa) - DrawContentQuadAA(frame, quad, resource_id, device_transform); + DrawContentQuadAA(frame, quad, resource_id, device_transform, clip_region); else - DrawContentQuadNoAA(frame, quad, resource_id); + DrawContentQuadNoAA(frame, quad, resource_id, clip_region); } void GLRenderer::DrawContentQuadAA(const DrawingFrame* frame, const ContentDrawQuadBase* quad, ResourceProvider::ResourceId resource_id, - const gfx::Transform& device_transform) { + const gfx::Transform& device_transform, + const gfx::QuadF* clip_region) { if (!device_transform.IsInvertible()) return; @@ -1625,8 +1828,8 @@ void GLRenderer::DrawContentQuadAA(const DrawingFrame* frame, gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); float edge[24]; - SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge); - + SetupQuadForClippingAndAntialiasing(device_transform, quad, true, clip_region, + &local_quad, edge); ResourceProvider::ScopedSamplerGL quad_resource_lock( resource_provider_, resource_id, quad->nearest_neighbor ? GL_NEAREST : GL_LINEAR); @@ -1704,7 +1907,8 @@ void GLRenderer::DrawContentQuadAA(const DrawingFrame* frame, void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame, const ContentDrawQuadBase* quad, - ResourceProvider::ResourceId resource_id) { + ResourceProvider::ResourceId resource_id, + const gfx::QuadF* clip_region) { gfx::RectF tex_coord_rect = MathUtil::ScaleRectProportional( quad->tex_coord_rect, quad->rect, quad->visible_rect); float tex_to_geom_scale_x = quad->rect.width() / quad->tex_coord_rect.width(); @@ -1778,17 +1982,37 @@ void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame, // does, then vertices will match the texture mapping in the vertex buffer. // The method SetShaderQuadF() changes the order of vertices and so it's // not used here. - - gfx::RectF tile_rect = quad->visible_rect; + gfx::QuadF tile_rect(quad->visible_rect); + float width = quad->visible_rect.width(); + float height = quad->visible_rect.height(); + gfx::PointF top_left = quad->visible_rect.origin(); + if (clip_region) { + tile_rect = *clip_region; + float gl_uv[8] = { + (tile_rect.p4().x() - top_left.x()) / width, + (tile_rect.p4().y() - top_left.y()) / height, + (tile_rect.p1().x() - top_left.x()) / width, + (tile_rect.p1().y() - top_left.y()) / height, + (tile_rect.p2().x() - top_left.x()) / width, + (tile_rect.p2().y() - top_left.y()) / height, + (tile_rect.p3().x() - top_left.x()) / width, + (tile_rect.p3().y() - top_left.y()) / height, + }; + PrepareGeometry(CLIPPED_BINDING); + clipped_geometry_->InitializeCustomQuadWithUVs( + gfx::QuadF(quad->visible_rect), gl_uv); + } else { + PrepareGeometry(SHARED_BINDING); + } float gl_quad[8] = { - tile_rect.x(), - tile_rect.bottom(), - tile_rect.x(), - tile_rect.y(), - tile_rect.right(), - tile_rect.y(), - tile_rect.right(), - tile_rect.bottom(), + tile_rect.p4().x(), + tile_rect.p4().y(), + tile_rect.p1().x(), + tile_rect.p1().y(), + tile_rect.p2().x(), + tile_rect.p2().y(), + tile_rect.p3().x(), + tile_rect.p3().y(), }; GLC(gl_, gl_->Uniform2fv(uniforms.quad_location, 4, gl_quad)); @@ -1801,7 +2025,8 @@ void GLRenderer::DrawContentQuadNoAA(const DrawingFrame* frame, } void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, - const YUVVideoDrawQuad* quad) { + const YUVVideoDrawQuad* quad, + const gfx::QuadF* clip_region) { SetBlendEnabled(quad->ShouldDrawWithBlending()); TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( @@ -1941,15 +2166,31 @@ void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, break; } + // The transform and vertex data are used to figure out the extents that the + // un-antialiased quad should have and which vertex this is and the float + // quad passed in via uniform is the actual geometry that gets used to draw + // it. This is why this centered rect is used and not the original quad_rect. + gfx::RectF tile_rect = quad->visible_rect; GLC(gl_, gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb)); GLC(gl_, gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust)); SetShaderOpacity(quad->opacity(), alpha_location); - DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, matrix_location); + if (!clip_region) { + DrawQuadGeometry(frame, quad->quadTransform(), tile_rect, matrix_location); + } else { + float uvs[8] = {0}; + GetScaledUVs(quad->visible_rect, clip_region, uvs); + gfx::QuadF region_quad = *clip_region; + region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); + region_quad -= gfx::Vector2dF(0.5f, 0.5f); + DrawQuadGeometryClippedByQuadF(frame, quad->quadTransform(), tile_rect, + region_quad, matrix_location, uvs); + } } void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, - const StreamVideoDrawQuad* quad) { + const StreamVideoDrawQuad* quad, + const gfx::QuadF* clip_region) { SetBlendEnabled(quad->ShouldDrawWithBlending()); static float gl_matrix[16]; @@ -1980,10 +2221,19 @@ void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, SetShaderOpacity(quad->opacity(), program->fragment_shader().alpha_location()); - DrawQuadGeometry(frame, - quad->quadTransform(), - quad->rect, - program->vertex_shader().matrix_location()); + if (!clip_region) { + DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, + program->vertex_shader().matrix_location()); + } else { + gfx::QuadF region_quad(*clip_region); + region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); + region_quad -= gfx::Vector2dF(0.5f, 0.5f); + float uvs[8] = {0}; + GetScaledUVs(quad->visible_rect, clip_region, uvs); + DrawQuadGeometryClippedByQuadF( + frame, quad->quadTransform(), quad->rect, region_quad, + program->vertex_shader().matrix_location(), uvs); + } } struct TextureProgramBinding { @@ -1999,6 +2249,7 @@ struct TextureProgramBinding { int program_id; int sampler_location; int matrix_location; + int transform_location; int background_color_location; }; @@ -2014,11 +2265,13 @@ struct TexTransformTextureProgramBinding : TextureProgramBinding { int vertex_opacity_location; }; -void GLRenderer::FlushTextureQuadCache() { +void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { // Check to see if we have anything to draw. if (draw_cache_.program_id == -1) return; + PrepareGeometry(flush_binding); + // Set the correct blending mode. SetBlendEnabled(draw_cache_.needs_blending); @@ -2079,10 +2332,26 @@ void GLRenderer::FlushTextureQuadCache() { draw_cache_.uv_xform_data.resize(0); draw_cache_.vertex_opacity_data.resize(0); draw_cache_.matrix_data.resize(0); + + // If we had a clipped binding, prepare the shared binding for the + // next inserts. + if (flush_binding == CLIPPED_BINDING) { + PrepareGeometry(SHARED_BINDING); + } } void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, - const TextureDrawQuad* quad) { + const TextureDrawQuad* quad, + const gfx::QuadF* clip_region) { + // If we have a clip_region then we have to render the next quad + // with dynamic geometry, therefore we must flush all pending + // texture quads. + if (clip_region) { + // We send in false here because we want to flush what's currently in the + // queue using the shared_geometry and not clipped_geometry + FlushTextureQuadCache(SHARED_BINDING); + } + TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( gl_, &highp_threshold_cache_, @@ -2114,7 +2383,7 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, draw_cache_.nearest_neighbor != quad->nearest_neighbor || draw_cache_.background_color != quad->background_color || draw_cache_.matrix_data.size() >= 8) { - FlushTextureQuadCache(); + FlushTextureQuadCache(SHARED_BINDING); draw_cache_.program_id = binding.program_id; draw_cache_.resource_id = resource_id; draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); @@ -2129,7 +2398,12 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, } // Generate the uv-transform - draw_cache_.uv_xform_data.push_back(UVTransform(quad)); + if (!clip_region) { + draw_cache_.uv_xform_data.push_back(UVTransform(quad)); + } else { + Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; + draw_cache_.uv_xform_data.push_back(uv_transform); + } // Generate the vertex opacity const float opacity = quad->opacity(); @@ -2146,10 +2420,32 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, Float16 m; quad_rect_matrix.matrix().asColMajorf(m.data); draw_cache_.matrix_data.push_back(m); + + if (clip_region) { + gfx::QuadF scaled_region; + if (!GetScaledRegion(quad->rect, clip_region, &scaled_region)) { + scaled_region = SharedGeometryQuad().BoundingBox(); + } + // Both the scaled region and the SharedGeomtryQuad are in the space + // -0.5->0.5. We need to move that to the space 0->1. + float uv[8]; + uv[0] = scaled_region.p1().x() + 0.5f; + uv[1] = scaled_region.p1().y() + 0.5f; + uv[2] = scaled_region.p2().x() + 0.5f; + uv[3] = scaled_region.p2().y() + 0.5f; + uv[4] = scaled_region.p3().x() + 0.5f; + uv[5] = scaled_region.p3().y() + 0.5f; + uv[6] = scaled_region.p4().x() + 0.5f; + uv[7] = scaled_region.p4().y() + 0.5f; + PrepareGeometry(CLIPPED_BINDING); + clipped_geometry_->InitializeCustomQuadWithUVs(scaled_region, uv); + FlushTextureQuadCache(CLIPPED_BINDING); + } } void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, - const IOSurfaceDrawQuad* quad) { + const IOSurfaceDrawQuad* quad, + const gfx::QuadF* clip_region) { SetBlendEnabled(quad->ShouldDrawWithBlending()); TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( @@ -2188,8 +2484,15 @@ void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id())); - DrawQuadGeometry( - frame, quad->quadTransform(), quad->rect, binding.matrix_location); + if (!clip_region) { + DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, + binding.matrix_location); + } else { + float uvs[8] = {0}; + GetScaledUVs(quad->visible_rect, clip_region, uvs); + DrawQuadGeometryClippedByQuadF(frame, quad->quadTransform(), quad->rect, + *clip_region, binding.matrix_location, uvs); + } GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); } @@ -2210,7 +2513,9 @@ void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { ScheduleOverlays(frame); } -void GLRenderer::FinishDrawingQuadList() { FlushTextureQuadCache(); } +void GLRenderer::FinishDrawingQuadList() { + FlushTextureQuadCache(SHARED_BINDING); +} bool GLRenderer::FlippedFramebuffer(const DrawingFrame* frame) const { if (frame->current_render_pass != frame->root_render_pass) @@ -2227,7 +2532,7 @@ void GLRenderer::EnsureScissorTestEnabled() { if (is_scissor_enabled_) return; - FlushTextureQuadCache(); + FlushTextureQuadCache(SHARED_BINDING); GLC(gl_, gl_->Enable(GL_SCISSOR_TEST)); is_scissor_enabled_ = true; } @@ -2236,7 +2541,7 @@ void GLRenderer::EnsureScissorTestDisabled() { if (!is_scissor_enabled_) return; - FlushTextureQuadCache(); + FlushTextureQuadCache(SHARED_BINDING); GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); is_scissor_enabled_ = false; } @@ -2305,10 +2610,34 @@ void GLRenderer::SetUseProgram(unsigned program) { program_shadow_ = program; } +void GLRenderer::DrawQuadGeometryClippedByQuadF( + const DrawingFrame* frame, + const gfx::Transform& draw_transform, + const gfx::RectF& quad_rect, + const gfx::QuadF& clipping_region_quad, + int matrix_location, + const float* uvs) { + PrepareGeometry(CLIPPED_BINDING); + if (uvs) { + clipped_geometry_->InitializeCustomQuadWithUVs(clipping_region_quad, uvs); + } else { + clipped_geometry_->InitializeCustomQuad(clipping_region_quad); + } + gfx::Transform quad_rect_matrix; + QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); + static float gl_matrix[16]; + ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); + GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); + + GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, + reinterpret_cast<const void*>(0))); +} + void GLRenderer::DrawQuadGeometry(const DrawingFrame* frame, const gfx::Transform& draw_transform, const gfx::RectF& quad_rect, int matrix_location) { + PrepareGeometry(SHARED_BINDING); gfx::Transform quad_rect_matrix; QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); static float gl_matrix[16]; @@ -2371,6 +2700,7 @@ void GLRenderer::EnforceMemoryPolicy() { output_surface_->context_provider()->DeleteCachedResources(); GLC(gl_, gl_->Flush()); } + PrepareGeometry(NO_BINDING); } void GLRenderer::DiscardBackbuffer() { @@ -2702,7 +3032,7 @@ void GLRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { return; scissor_rect_ = scissor_rect; - FlushTextureQuadCache(); + FlushTextureQuadCache(SHARED_BINDING); GLC(gl_, gl_->Scissor(scissor_rect.x(), scissor_rect.y(), @@ -2727,8 +3057,27 @@ void GLRenderer::InitializeSharedObjects() { // Create an FBO for doing offscreen rendering. GLC(gl_, gl_->GenFramebuffers(1, &offscreen_framebuffer_id_)); - shared_geometry_ = make_scoped_ptr( - new GeometryBinding(gl_, QuadVertexRect())); + shared_geometry_ = + make_scoped_ptr(new StaticGeometryBinding(gl_, QuadVertexRect())); + clipped_geometry_ = make_scoped_ptr(new DynamicGeometryBinding(gl_)); +} + +void GLRenderer::PrepareGeometry(BoundGeometry binding) { + if (binding == bound_geometry_) { + return; + } + + switch (binding) { + case SHARED_BINDING: + shared_geometry_->PrepareForDraw(); + break; + case CLIPPED_BINDING: + clipped_geometry_->PrepareForDraw(); + break; + case NO_BINDING: + break; + } + bound_geometry_ = binding; } const GLRenderer::TileCheckerboardProgram* @@ -3193,8 +3542,8 @@ void GLRenderer::ReinitializeGLState() { void GLRenderer::RestoreGLState() { // This restores the current GLRenderer state to the GL context. - - shared_geometry_->PrepareForDraw(); + bound_geometry_ = NO_BINDING; + PrepareGeometry(SHARED_BINDING); GLC(gl_, gl_->Disable(GL_DEPTH_TEST)); GLC(gl_, gl_->Disable(GL_CULL_FACE)); diff --git a/cc/output/gl_renderer.h b/cc/output/gl_renderer.h index 25c7096..31d4939 100644 --- a/cc/output/gl_renderer.h +++ b/cc/output/gl_renderer.h @@ -39,7 +39,8 @@ class ScopedResource; class StreamVideoDrawQuad; class TextureDrawQuad; class TextureMailboxDeleter; -class GeometryBinding; +class StaticGeometryBinding; +class DynamicGeometryBinding; class ScopedEnsureFramebufferAllocation; // Class that handles drawing of composited render layers using GL. @@ -85,7 +86,7 @@ class CC_EXPORT GLRenderer : public DirectRenderer { bool IsBackbufferDiscarded() const { return is_backbuffer_discarded_; } const gfx::QuadF& SharedGeometryQuad() const { return shared_geometry_quad_; } - const GeometryBinding* SharedGeometry() const { + const StaticGeometryBinding* SharedGeometry() const { return shared_geometry_.get(); } @@ -96,7 +97,8 @@ class CC_EXPORT GLRenderer : public DirectRenderer { ResourceFormat texture_format, const gfx::Rect& device_rect); void ReleaseRenderPassTextures(); - + enum BoundGeometry { NO_BINDING, SHARED_BINDING, CLIPPED_BINDING }; + void PrepareGeometry(BoundGeometry geometry_to_bind); void SetStencilEnabled(bool enabled); bool stencil_enabled() const { return stencil_shadow_; } void SetBlendEnabled(bool enabled); @@ -112,7 +114,9 @@ class CC_EXPORT GLRenderer : public DirectRenderer { bool draw_rect_covers_full_surface) override; void ClearFramebuffer(DrawingFrame* frame, bool has_external_stencil_test) override; - void DoDrawQuad(DrawingFrame* frame, const class DrawQuad*) override; + void DoDrawQuad(DrawingFrame* frame, + const class DrawQuad*, + const gfx::QuadF* draw_region) override; void BeginDrawingFrame(DrawingFrame* frame) override; void FinishDrawingFrame(DrawingFrame* frame) override; bool FlippedFramebuffer(const DrawingFrame* frame) const override; @@ -132,10 +136,13 @@ class CC_EXPORT GLRenderer : public DirectRenderer { // Inflate the quad and fill edge array for fragment shader. // |local_quad| is set to inflated quad. |edge| array is filled with // inflated quad's edge data. - static void SetupQuadForAntialiasing(const gfx::Transform& device_transform, - const DrawQuad* quad, - gfx::QuadF* local_quad, - float edge[24]); + static void SetupQuadForClippingAndAntialiasing( + const gfx::Transform& device_transform, + const DrawQuad* quad, + bool use_aa, + const gfx::QuadF* clip_region, + gfx::QuadF* local_quad, + float edge[24]); private: friend class GLRendererShaderPixelTest; @@ -144,7 +151,8 @@ class CC_EXPORT GLRenderer : public DirectRenderer { static void ToGLMatrix(float* gl_matrix, const gfx::Transform& transform); void DrawCheckerboardQuad(const DrawingFrame* frame, - const CheckerboardDrawQuad* quad); + const CheckerboardDrawQuad* quad, + const gfx::QuadF* clip_region); void DrawDebugBorderQuad(const DrawingFrame* frame, const DebugBorderDrawQuad* quad); static bool IsDefaultBlendMode(SkXfermode::Mode blend_mode) { @@ -158,6 +166,7 @@ class CC_EXPORT GLRenderer : public DirectRenderer { DrawingFrame* frame, const RenderPassDrawQuad* quad, const gfx::Transform& contents_device_transform, + const gfx::QuadF* clip_region, bool use_aa); scoped_ptr<ScopedResource> GetBackdropTexture(const gfx::Rect& bounding_rect); @@ -168,34 +177,56 @@ class CC_EXPORT GLRenderer : public DirectRenderer { const RenderPassDrawQuad* quad, ScopedResource* background_texture); - void DrawRenderPassQuad(DrawingFrame* frame, const RenderPassDrawQuad* quad); + void DrawRenderPassQuad(DrawingFrame* frame, + const RenderPassDrawQuad* quadi, + const gfx::QuadF* clip_region); void DrawSolidColorQuad(const DrawingFrame* frame, - const SolidColorDrawQuad* quad); + const SolidColorDrawQuad* quad, + const gfx::QuadF* clip_region); void DrawStreamVideoQuad(const DrawingFrame* frame, - const StreamVideoDrawQuad* quad); + const StreamVideoDrawQuad* quad, + const gfx::QuadF* clip_region); + void DrawTextureQuad(const DrawingFrame* frame, + const TextureDrawQuad* quad, + const gfx::QuadF* clip_region); void EnqueueTextureQuad(const DrawingFrame* frame, - const TextureDrawQuad* quad); - void FlushTextureQuadCache(); + const TextureDrawQuad* quad, + const gfx::QuadF* clip_region); + void FlushTextureQuadCache(BoundGeometry flush_binding); void DrawIOSurfaceQuad(const DrawingFrame* frame, - const IOSurfaceDrawQuad* quad); - void DrawTileQuad(const DrawingFrame* frame, const TileDrawQuad* quad); + const IOSurfaceDrawQuad* quad, + const gfx::QuadF* clip_region); + void DrawTileQuad(const DrawingFrame* frame, + const TileDrawQuad* quad, + const gfx::QuadF* clip_region); void DrawContentQuad(const DrawingFrame* frame, const ContentDrawQuadBase* quad, - ResourceProvider::ResourceId resource_id); + ResourceProvider::ResourceId resource_id, + const gfx::QuadF* clip_region); void DrawContentQuadAA(const DrawingFrame* frame, const ContentDrawQuadBase* quad, ResourceProvider::ResourceId resource_id, - const gfx::Transform& device_transform); + const gfx::Transform& device_transform, + const gfx::QuadF* clip_region); void DrawContentQuadNoAA(const DrawingFrame* frame, const ContentDrawQuadBase* quad, - ResourceProvider::ResourceId resource_id); + ResourceProvider::ResourceId resource_id, + const gfx::QuadF* clip_region); void DrawYUVVideoQuad(const DrawingFrame* frame, - const YUVVideoDrawQuad* quad); + const YUVVideoDrawQuad* quad, + const gfx::QuadF* clip_region); void DrawPictureQuad(const DrawingFrame* frame, - const PictureDrawQuad* quad); + const PictureDrawQuad* quad, + const gfx::QuadF* clip_region); void SetShaderOpacity(float opacity, int alpha_location); void SetShaderQuadF(const gfx::QuadF& quad, int quad_location); + void DrawQuadGeometryClippedByQuadF(const DrawingFrame* frame, + const gfx::Transform& draw_transform, + const gfx::RectF& quad_rect, + const gfx::QuadF& clipping_region_quad, + int matrix_location, + const float uv[8]); void DrawQuadGeometry(const DrawingFrame* frame, const gfx::Transform& draw_transform, const gfx::RectF& quad_rect, @@ -237,7 +268,8 @@ class CC_EXPORT GLRenderer : public DirectRenderer { unsigned offscreen_framebuffer_id_; - scoped_ptr<GeometryBinding> shared_geometry_; + scoped_ptr<StaticGeometryBinding> shared_geometry_; + scoped_ptr<DynamicGeometryBinding> clipped_geometry_; gfx::QuadF shared_geometry_quad_; // This block of bindings defines all of the programs used by the compositor @@ -471,7 +503,7 @@ class CC_EXPORT GLRenderer : public DirectRenderer { SkBitmap on_demand_tile_raster_bitmap_; ResourceProvider::ResourceId on_demand_tile_raster_resource_id_; - + BoundGeometry bound_geometry_; DISALLOW_COPY_AND_ASSIGN(GLRenderer); }; diff --git a/cc/output/overlay_unittest.cc b/cc/output/overlay_unittest.cc index 6ee388a..47e2b9c 100644 --- a/cc/output/overlay_unittest.cc +++ b/cc/output/overlay_unittest.cc @@ -775,7 +775,10 @@ class OverlayInfoRendererGL : public GLRenderer { 0), expect_overlays_(false) {} - MOCK_METHOD2(DoDrawQuad, void(DrawingFrame* frame, const DrawQuad* quad)); + MOCK_METHOD3(DoDrawQuad, + void(DrawingFrame* frame, + const DrawQuad* quad, + const gfx::QuadF* draw_region)); using GLRenderer::BeginDrawingFrame; @@ -875,7 +878,7 @@ TEST_F(GLRendererWithOverlaysTest, OverlayQuadNotDrawn) { // Candidate pass was taken out and extra skipped pass added, // so only draw 2 quads. - EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(2); + EXPECT_CALL(*renderer_, DoDrawQuad(_, _, _)).Times(2); EXPECT_CALL(scheduler_, Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, @@ -913,7 +916,7 @@ TEST_F(GLRendererWithOverlaysTest, OccludedQuadDrawn) { pass_list.push_back(pass.Pass()); // 3 quads in the pass, all should draw. - EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(3); + EXPECT_CALL(*renderer_, DoDrawQuad(_, _, _)).Times(3); EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0); renderer_->DrawFrame(&pass_list, 1.f, viewport_rect, viewport_rect, false); @@ -946,7 +949,7 @@ TEST_F(GLRendererWithOverlaysTest, NoValidatorNoOverlay) { pass_list.push_back(pass.Pass()); // Should see no overlays. - EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(3); + EXPECT_CALL(*renderer_, DoDrawQuad(_, _, _)).Times(3); EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0); renderer_->DrawFrame(&pass_list, 1.f, viewport_rect, viewport_rect, false); diff --git a/cc/output/renderer_pixeltest.cc b/cc/output/renderer_pixeltest.cc index 743e1cf..006c574 100644 --- a/cc/output/renderer_pixeltest.cc +++ b/cc/output/renderer_pixeltest.cc @@ -111,6 +111,52 @@ void CreateTestRenderPassDrawQuad(const SharedQuadState* shared_state, FilterOperations()); // background filters } +void CreateTestTwoColoredTextureDrawQuad(const gfx::Rect& rect, + SkColor texel_color, + SkColor texel_stripe_color, + SkColor background_color, + bool premultiplied_alpha, + const SharedQuadState* shared_state, + ResourceProvider* resource_provider, + RenderPass* render_pass) { + SkPMColor pixel_color = premultiplied_alpha + ? SkPreMultiplyColor(texel_color) + : SkPackARGB32NoCheck(SkColorGetA(texel_color), + SkColorGetR(texel_color), + SkColorGetG(texel_color), + SkColorGetB(texel_color)); + SkPMColor pixel_stripe_color = + premultiplied_alpha + ? SkPreMultiplyColor(texel_stripe_color) + : SkPackARGB32NoCheck(SkColorGetA(texel_stripe_color), + SkColorGetR(texel_stripe_color), + SkColorGetG(texel_stripe_color), + SkColorGetB(texel_stripe_color)); + std::vector<uint32_t> pixels(rect.size().GetArea(), pixel_color); + for (int i = rect.height() / 4; i < (rect.height() * 3 / 4); ++i) { + for (int k = rect.width() / 4; k < (rect.width() * 3 / 4); ++k) { + pixels[i * rect.width() + k] = pixel_stripe_color; + } + } + ResourceProvider::ResourceId resource = resource_provider->CreateResource( + rect.size(), GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, + RGBA_8888); + resource_provider->SetPixels(resource, + reinterpret_cast<uint8_t*>(&pixels.front()), + rect, rect, gfx::Vector2d()); + + float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + const gfx::PointF uv_top_left(0.0f, 0.0f); + const gfx::PointF uv_bottom_right(1.0f, 1.0f); + const bool flipped = false; + const bool nearest_neighbor = false; + TextureDrawQuad* quad = + render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); + quad->SetNew(shared_state, rect, gfx::Rect(), rect, resource, + premultiplied_alpha, uv_top_left, uv_bottom_right, + background_color, vertex_opacity, flipped, nearest_neighbor); +} + void CreateTestTextureDrawQuad(const gfx::Rect& rect, SkColor texel_color, SkColor background_color, @@ -135,20 +181,216 @@ void CreateTestTextureDrawQuad(const gfx::Rect& rect, float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + const gfx::PointF uv_top_left(0.0f, 0.0f); + const gfx::PointF uv_bottom_right(1.0f, 1.0f); + const bool flipped = false; + const bool nearest_neighbor = false; TextureDrawQuad* quad = render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); - quad->SetNew(shared_state, - rect, - gfx::Rect(), - rect, - resource, - premultiplied_alpha, - gfx::PointF(0.0f, 0.0f), // uv_top_left - gfx::PointF(1.0f, 1.0f), // uv_bottom_right - background_color, - vertex_opacity, - false, // flipped - false); // nearest_neighbor + quad->SetNew(shared_state, rect, gfx::Rect(), rect, resource, + premultiplied_alpha, uv_top_left, uv_bottom_right, + background_color, vertex_opacity, flipped, nearest_neighbor); +} + +void CreateTestYUVVideoDrawQuad_FromVideoFrame( + const SharedQuadState* shared_state, + scoped_refptr<media::VideoFrame> video_frame, + uint8 alpha_value, + const gfx::RectF& tex_coord_rect, + RenderPass* render_pass, + VideoResourceUpdater* video_resource_updater, + const gfx::Rect& rect, + ResourceProvider* resource_provider) { + const bool with_alpha = (video_frame->format() == media::VideoFrame::YV12A); + const YUVVideoDrawQuad::ColorSpace color_space = + (video_frame->format() == media::VideoFrame::YV12J + ? YUVVideoDrawQuad::JPEG + : YUVVideoDrawQuad::REC_601); + const gfx::Rect opaque_rect(0, 0, 0, 0); + + if (with_alpha) { + memset(video_frame->data(media::VideoFrame::kAPlane), alpha_value, + video_frame->stride(media::VideoFrame::kAPlane) * + video_frame->rows(media::VideoFrame::kAPlane)); + } + + VideoFrameExternalResources resources = + video_resource_updater->CreateExternalResourcesFromVideoFrame( + video_frame); + + EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); + EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame->format()), + resources.mailboxes.size()); + EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame->format()), + resources.release_callbacks.size()); + + ResourceProvider::ResourceId y_resource = + resource_provider->CreateResourceFromTextureMailbox( + resources.mailboxes[media::VideoFrame::kYPlane], + SingleReleaseCallbackImpl::Create( + resources.release_callbacks[media::VideoFrame::kYPlane])); + ResourceProvider::ResourceId u_resource = + resource_provider->CreateResourceFromTextureMailbox( + resources.mailboxes[media::VideoFrame::kUPlane], + SingleReleaseCallbackImpl::Create( + resources.release_callbacks[media::VideoFrame::kUPlane])); + ResourceProvider::ResourceId v_resource = + resource_provider->CreateResourceFromTextureMailbox( + resources.mailboxes[media::VideoFrame::kVPlane], + SingleReleaseCallbackImpl::Create( + resources.release_callbacks[media::VideoFrame::kVPlane])); + ResourceProvider::ResourceId a_resource = 0; + if (with_alpha) { + a_resource = resource_provider->CreateResourceFromTextureMailbox( + resources.mailboxes[media::VideoFrame::kAPlane], + SingleReleaseCallbackImpl::Create( + resources.release_callbacks[media::VideoFrame::kAPlane])); + } + + YUVVideoDrawQuad* yuv_quad = + render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); + yuv_quad->SetNew(shared_state, rect, opaque_rect, rect, tex_coord_rect, + video_frame->coded_size(), y_resource, u_resource, + v_resource, a_resource, color_space); +} + +void CreateTestYUVVideoDrawQuad_Striped( + const SharedQuadState* shared_state, + media::VideoFrame::Format format, + bool is_transparent, + const gfx::RectF& tex_coord_rect, + RenderPass* render_pass, + VideoResourceUpdater* video_resource_updater, + const gfx::Rect& rect, + ResourceProvider* resource_provider) { + scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame( + format, rect.size(), rect, rect.size(), base::TimeDelta()); + + // YUV values representing a striped pattern, for validating texture + // coordinates for sampling. + uint8_t y_value = 0; + uint8_t u_value = 0; + uint8_t v_value = 0; + for (int i = 0; i < video_frame->rows(media::VideoFrame::kYPlane); ++i) { + uint8_t* y_row = video_frame->data(media::VideoFrame::kYPlane) + + video_frame->stride(media::VideoFrame::kYPlane) * i; + for (int j = 0; j < video_frame->row_bytes(media::VideoFrame::kYPlane); + ++j) { + y_row[j] = (y_value += 1); + } + } + for (int i = 0; i < video_frame->rows(media::VideoFrame::kUPlane); ++i) { + uint8_t* u_row = video_frame->data(media::VideoFrame::kUPlane) + + video_frame->stride(media::VideoFrame::kUPlane) * i; + uint8_t* v_row = video_frame->data(media::VideoFrame::kVPlane) + + video_frame->stride(media::VideoFrame::kVPlane) * i; + for (int j = 0; j < video_frame->row_bytes(media::VideoFrame::kUPlane); + ++j) { + u_row[j] = (u_value += 3); + v_row[j] = (v_value += 5); + } + } + uint8 alpha_value = is_transparent ? 0 : 128; + CreateTestYUVVideoDrawQuad_FromVideoFrame( + shared_state, video_frame, alpha_value, tex_coord_rect, render_pass, + video_resource_updater, rect, resource_provider); +} + +// Creates a video frame of size background_size filled with yuv_background, +// and then draws a foreground rectangle in a different color on top of +// that. The foreground rectangle must have coordinates that are divisible +// by 2 because YUV is a block format. +void CreateTestYUVVideoDrawQuad_TwoColor( + const SharedQuadState* shared_state, + media::VideoFrame::Format format, + bool is_transparent, + const gfx::RectF& tex_coord_rect, + const gfx::Size& background_size, + uint8 y_background, + uint8 u_background, + uint8 v_background, + const gfx::Rect& foreground_rect, + uint8 y_foreground, + uint8 u_foreground, + uint8 v_foreground, + RenderPass* render_pass, + VideoResourceUpdater* video_resource_updater, + ResourceProvider* resource_provider) { + const gfx::Rect rect(background_size); + + scoped_refptr<media::VideoFrame> video_frame = + media::VideoFrame::CreateFrame(format, background_size, foreground_rect, + foreground_rect.size(), base::TimeDelta()); + + int planes[] = {media::VideoFrame::kYPlane, + media::VideoFrame::kUPlane, + media::VideoFrame::kVPlane}; + uint8 yuv_background[] = {y_background, u_background, v_background}; + uint8 yuv_foreground[] = {y_foreground, u_foreground, v_foreground}; + int sample_size[] = {1, 2, 2}; + + for (int i = 0; i < 3; ++i) { + memset(video_frame->data(planes[i]), yuv_background[i], + video_frame->stride(planes[i]) * video_frame->rows(planes[i])); + } + + for (int i = 0; i < 3; ++i) { + // Since yuv encoding uses block encoding, widths have to be divisible + // by the sample size in order for this function to behave properly. + DCHECK_EQ(foreground_rect.x() % sample_size[i], 0); + DCHECK_EQ(foreground_rect.y() % sample_size[i], 0); + DCHECK_EQ(foreground_rect.width() % sample_size[i], 0); + DCHECK_EQ(foreground_rect.height() % sample_size[i], 0); + + gfx::Rect sample_rect(foreground_rect.x() / sample_size[i], + foreground_rect.y() / sample_size[i], + foreground_rect.width() / sample_size[i], + foreground_rect.height() / sample_size[i]); + for (int y = sample_rect.y(); y < sample_rect.bottom(); ++y) { + for (int x = sample_rect.x(); x < sample_rect.right(); ++x) { + size_t offset = y * video_frame->stride(planes[i]) + x; + video_frame->data(planes[i])[offset] = yuv_foreground[i]; + } + } + } + + uint8 alpha_value = 255; + CreateTestYUVVideoDrawQuad_FromVideoFrame( + shared_state, video_frame, alpha_value, tex_coord_rect, render_pass, + video_resource_updater, rect, resource_provider); +} + +void CreateTestYUVVideoDrawQuad_Solid( + const SharedQuadState* shared_state, + media::VideoFrame::Format format, + bool is_transparent, + const gfx::RectF& tex_coord_rect, + uint8 y, + uint8 u, + uint8 v, + RenderPass* render_pass, + VideoResourceUpdater* video_resource_updater, + const gfx::Rect& rect, + ResourceProvider* resource_provider) { + scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame( + format, rect.size(), rect, rect.size(), base::TimeDelta()); + + // YUV values of a solid, constant, color. Useful for testing that color + // space/color range are being handled properly. + memset(video_frame->data(media::VideoFrame::kYPlane), y, + video_frame->stride(media::VideoFrame::kYPlane) * + video_frame->rows(media::VideoFrame::kYPlane)); + memset(video_frame->data(media::VideoFrame::kUPlane), u, + video_frame->stride(media::VideoFrame::kUPlane) * + video_frame->rows(media::VideoFrame::kUPlane)); + memset(video_frame->data(media::VideoFrame::kVPlane), v, + video_frame->stride(media::VideoFrame::kVPlane) * + video_frame->rows(media::VideoFrame::kVPlane)); + + uint8 alpha_value = is_transparent ? 0 : 128; + CreateTestYUVVideoDrawQuad_FromVideoFrame( + shared_state, video_frame, alpha_value, tex_coord_rect, render_pass, + video_resource_updater, rect, resource_provider); } typedef ::testing::Types<GLRenderer, @@ -323,6 +565,278 @@ TYPED_TEST(RendererPixelTest, PremultipliedTextureWithBackground) { FuzzyPixelOffByOneComparator(true))); } +template <typename QuadType> +static const base::FilePath::CharType* IntersectingQuadImage() { + return FILE_PATH_LITERAL("intersecting_blue_green_squares.png"); +} +template <> +const base::FilePath::CharType* IntersectingQuadImage<SolidColorDrawQuad>() { + return FILE_PATH_LITERAL("intersecting_blue_green.png"); +} +template <> +const base::FilePath::CharType* IntersectingQuadImage<YUVVideoDrawQuad>() { + return FILE_PATH_LITERAL("intersecting_blue_green_squares_video.png"); +} + +template <typename TypeParam> +class IntersectingQuadPixelTest : public RendererPixelTest<TypeParam> { + protected: + void SetupQuadStateAndRenderPass() { + // This sets up a pair of draw quads. They are both rotated + // relative to the root plane, they are also rotated relative to each other. + // The intersect in the middle at a non-perpendicular angle so that any + // errors are hopefully magnified. + // The quads should intersect correctly, as in the front quad should only + // be partially in front of the back quad, and partially behind. + + viewport_rect_ = gfx::Rect(this->device_viewport_size_); + quad_rect_ = gfx::Rect(0, 0, this->device_viewport_size_.width(), + this->device_viewport_size_.height() / 2.0); + + RenderPassId id(1, 1); + render_pass_ = CreateTestRootRenderPass(id, viewport_rect_); + + // Create the front quad rotated on the Z and Y axis. + gfx::Transform trans; + trans.Translate3d(0, 0, 0.707 * this->device_viewport_size_.width() / 2.0); + trans.RotateAboutZAxis(45.0); + trans.RotateAboutYAxis(45.0); + front_quad_state_ = + CreateTestSharedQuadState(trans, viewport_rect_, render_pass_.get()); + front_quad_state_->clip_rect = quad_rect_; + // Make sure they end up in a 3d sorting context. + front_quad_state_->sorting_context_id = 1; + + // Create the back quad, and rotate on just the y axis. This will intersect + // the first quad partially. + trans = gfx::Transform(); + trans.Translate3d(0, 0, -0.707 * this->device_viewport_size_.width() / 2.0); + trans.RotateAboutYAxis(-45.0); + back_quad_state_ = + CreateTestSharedQuadState(trans, viewport_rect_, render_pass_.get()); + back_quad_state_->sorting_context_id = 1; + back_quad_state_->clip_rect = quad_rect_; + } + template <typename T> + void AppendBackgroundAndRunTest(const PixelComparator& comparator) { + SharedQuadState* background_quad_state = CreateTestSharedQuadState( + gfx::Transform(), viewport_rect_, render_pass_.get()); + SolidColorDrawQuad* background_quad = + render_pass_->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); + background_quad->SetNew(background_quad_state, viewport_rect_, + viewport_rect_, SK_ColorWHITE, false); + pass_list_.push_back(render_pass_.Pass()); + const base::FilePath::CharType* fileName = IntersectingQuadImage<T>(); + EXPECT_TRUE( + this->RunPixelTest(&pass_list_, base::FilePath(fileName), comparator)); + } + template <typename T> + T* CreateAndAppendDrawQuad() { + return render_pass_->CreateAndAppendDrawQuad<T>(); + } + + scoped_ptr<RenderPass> render_pass_; + gfx::Rect viewport_rect_; + SharedQuadState* front_quad_state_; + SharedQuadState* back_quad_state_; + gfx::Rect quad_rect_; + RenderPassList pass_list_; +}; + +template <typename TypeParam> +class IntersectingQuadGLPixelTest + : public IntersectingQuadPixelTest<TypeParam> { + public: + void SetUp() override { + IntersectingQuadPixelTest<TypeParam>::SetUp(); + video_resource_updater_.reset( + new VideoResourceUpdater(this->output_surface_->context_provider(), + this->resource_provider_.get())); + video_resource_updater2_.reset( + new VideoResourceUpdater(this->output_surface_->context_provider(), + this->resource_provider_.get())); + } + + protected: + scoped_ptr<VideoResourceUpdater> video_resource_updater_; + scoped_ptr<VideoResourceUpdater> video_resource_updater2_; +}; + +template <typename TypeParam> +class IntersectingQuadSoftwareTest + : public IntersectingQuadPixelTest<TypeParam> {}; + +typedef ::testing::Types<SoftwareRenderer, SoftwareRendererWithExpandedViewport> + SoftwareRendererTypes; +typedef ::testing::Types<GLRenderer, GLRendererWithExpandedViewport> + GLRendererTypes; + +TYPED_TEST_CASE(IntersectingQuadPixelTest, RendererTypes); +TYPED_TEST_CASE(IntersectingQuadGLPixelTest, GLRendererTypes); +TYPED_TEST_CASE(IntersectingQuadSoftwareTest, SoftwareRendererTypes); + +TYPED_TEST(IntersectingQuadPixelTest, SolidColorQuads) { + this->SetupQuadStateAndRenderPass(); + + SolidColorDrawQuad* quad = + this->template CreateAndAppendDrawQuad<SolidColorDrawQuad>(); + SolidColorDrawQuad* quad2 = + this->template CreateAndAppendDrawQuad<SolidColorDrawQuad>(); + + quad->SetNew(this->front_quad_state_, this->quad_rect_, this->quad_rect_, + SK_ColorBLUE, false); + quad2->SetNew(this->back_quad_state_, this->quad_rect_, this->quad_rect_, + SK_ColorGREEN, false); + SCOPED_TRACE("IntersectingSolidColorQuads"); + this->template AppendBackgroundAndRunTest<SolidColorDrawQuad>( + FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f)); +} + +template <typename TypeParam> +SkColor GetColor(const SkColor& color) { + return color; +} + +template <> +SkColor GetColor<GLRenderer>(const SkColor& color) { + return SkColorSetARGB(SkColorGetA(color), SkColorGetB(color), + SkColorGetG(color), SkColorGetR(color)); +} +template <> +SkColor GetColor<GLRendererWithExpandedViewport>(const SkColor& color) { + return GetColor<GLRenderer>(color); +} + +TYPED_TEST(IntersectingQuadPixelTest, TexturedQuads) { + this->SetupQuadStateAndRenderPass(); + CreateTestTwoColoredTextureDrawQuad( + this->quad_rect_, GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 0)), + GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 255)), SK_ColorTRANSPARENT, + true, this->front_quad_state_, this->resource_provider_.get(), + this->render_pass_.get()); + CreateTestTwoColoredTextureDrawQuad( + this->quad_rect_, GetColor<TypeParam>(SkColorSetARGB(255, 0, 255, 0)), + GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 0)), SK_ColorTRANSPARENT, + true, this->back_quad_state_, this->resource_provider_.get(), + this->render_pass_.get()); + + SCOPED_TRACE("IntersectingTexturedQuads"); + this->template AppendBackgroundAndRunTest<TextureDrawQuad>( + FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f)); +} + +TYPED_TEST(IntersectingQuadSoftwareTest, PictureQuads) { + this->SetupQuadStateAndRenderPass(); + gfx::RectF outer_rect(this->quad_rect_); + gfx::RectF inner_rect(this->quad_rect_.x() + (this->quad_rect_.width() / 4), + this->quad_rect_.y() + (this->quad_rect_.height() / 4), + this->quad_rect_.width() / 2, + this->quad_rect_.height() / 2); + + SkPaint black_paint; + black_paint.setColor(SK_ColorBLACK); + SkPaint blue_paint; + blue_paint.setColor(SK_ColorBLUE); + SkPaint green_paint; + green_paint.setColor(SK_ColorGREEN); + + scoped_ptr<FakePicturePile> blue_recording = + FakePicturePile::CreateFilledPile(gfx::Size(1000, 1000), + this->quad_rect_.size()); + blue_recording->add_draw_rect_with_paint(outer_rect, black_paint); + blue_recording->add_draw_rect_with_paint(inner_rect, blue_paint); + blue_recording->RerecordPile(); + scoped_refptr<FakePicturePileImpl> blue_pile = + FakePicturePileImpl::CreateFromPile(blue_recording.get(), nullptr); + + PictureDrawQuad* blue_quad = + this->render_pass_->template CreateAndAppendDrawQuad<PictureDrawQuad>(); + + blue_quad->SetNew(this->front_quad_state_, this->quad_rect_, gfx::Rect(), + this->quad_rect_, this->quad_rect_, this->quad_rect_.size(), + false, RGBA_8888, this->quad_rect_, 1.f, blue_pile); + + scoped_ptr<FakePicturePile> green_recording = + FakePicturePile::CreateFilledPile(this->quad_rect_.size(), + this->quad_rect_.size()); + green_recording->add_draw_rect_with_paint(outer_rect, green_paint); + green_recording->add_draw_rect_with_paint(inner_rect, black_paint); + green_recording->RerecordPile(); + scoped_refptr<FakePicturePileImpl> green_pile = + FakePicturePileImpl::CreateFromPile(green_recording.get(), nullptr); + + PictureDrawQuad* green_quad = + this->render_pass_->template CreateAndAppendDrawQuad<PictureDrawQuad>(); + green_quad->SetNew(this->back_quad_state_, this->quad_rect_, gfx::Rect(), + this->quad_rect_, this->quad_rect_, + this->quad_rect_.size(), false, RGBA_8888, + this->quad_rect_, 1.f, green_pile); + SCOPED_TRACE("IntersectingPictureQuadsPass"); + this->template AppendBackgroundAndRunTest<PictureDrawQuad>( + FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f)); +} + +TYPED_TEST(IntersectingQuadPixelTest, RenderPassQuads) { + this->SetupQuadStateAndRenderPass(); + RenderPassId child_pass_id1(2, 2); + RenderPassId child_pass_id2(2, 3); + scoped_ptr<RenderPass> child_pass1 = + CreateTestRenderPass(child_pass_id1, this->quad_rect_, gfx::Transform()); + SharedQuadState* child1_quad_state = CreateTestSharedQuadState( + gfx::Transform(), this->quad_rect_, child_pass1.get()); + scoped_ptr<RenderPass> child_pass2 = + CreateTestRenderPass(child_pass_id2, this->quad_rect_, gfx::Transform()); + SharedQuadState* child2_quad_state = CreateTestSharedQuadState( + gfx::Transform(), this->quad_rect_, child_pass2.get()); + + CreateTestTwoColoredTextureDrawQuad( + this->quad_rect_, GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 0)), + GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 255)), SK_ColorTRANSPARENT, + true, child1_quad_state, this->resource_provider_.get(), + child_pass1.get()); + CreateTestTwoColoredTextureDrawQuad( + this->quad_rect_, GetColor<TypeParam>(SkColorSetARGB(255, 0, 255, 0)), + GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 0)), SK_ColorTRANSPARENT, + true, child2_quad_state, this->resource_provider_.get(), + child_pass2.get()); + + CreateTestRenderPassDrawQuad(this->front_quad_state_, this->quad_rect_, + child_pass_id1, this->render_pass_.get()); + CreateTestRenderPassDrawQuad(this->back_quad_state_, this->quad_rect_, + child_pass_id2, this->render_pass_.get()); + + this->pass_list_.push_back(child_pass1.Pass()); + this->pass_list_.push_back(child_pass2.Pass()); + SCOPED_TRACE("IntersectingRenderQuadsPass"); + this->template AppendBackgroundAndRunTest<RenderPassDrawQuad>( + FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f)); +} + +TYPED_TEST(IntersectingQuadGLPixelTest, YUVVideoQuads) { + this->SetupQuadStateAndRenderPass(); + gfx::Rect inner_rect( + (this->quad_rect_.x() + (this->quad_rect_.width() / 4) & ~0xF), + (this->quad_rect_.y() + (this->quad_rect_.height() / 4) & ~0xF), + (this->quad_rect_.width() / 2) & ~0xF, + (this->quad_rect_.height() / 2) & ~0xF); + + CreateTestYUVVideoDrawQuad_TwoColor( + this->front_quad_state_, media::VideoFrame::YV12J, false, + gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), this->quad_rect_.size(), 0, 128, 128, + inner_rect, 29, 255, 107, this->render_pass_.get(), + this->video_resource_updater_.get(), this->resource_provider_.get()); + + CreateTestYUVVideoDrawQuad_TwoColor( + this->back_quad_state_, media::VideoFrame::YV12J, false, + gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), this->quad_rect_.size(), 149, 43, 21, + inner_rect, 0, 128, 128, this->render_pass_.get(), + this->video_resource_updater2_.get(), this->resource_provider_.get()); + + SCOPED_TRACE("IntersectingVideoQuads"); + this->template AppendBackgroundAndRunTest<YUVVideoDrawQuad>( + FuzzyPixelOffByOneComparator(false)); +} + // TODO(skaslev): The software renderer does not support non-premultplied alpha. TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithoutBackground) { gfx::Rect rect(this->device_viewport_size_); @@ -390,80 +904,6 @@ TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithBackground) { class VideoGLRendererPixelTest : public GLRendererPixelTest { protected: - void CreateTestYUVVideoDrawQuad_Striped(const SharedQuadState* shared_state, - media::VideoFrame::Format format, - bool is_transparent, - const gfx::RectF& tex_coord_rect, - RenderPass* render_pass) { - const gfx::Rect rect(this->device_viewport_size_); - - scoped_refptr<media::VideoFrame> video_frame = - media::VideoFrame::CreateFrame( - format, rect.size(), rect, rect.size(), base::TimeDelta()); - - // YUV values representing a striped pattern, for validating texture - // coordinates for sampling. - uint8_t y_value = 0; - uint8_t u_value = 0; - uint8_t v_value = 0; - for (int i = 0; i < video_frame->rows(media::VideoFrame::kYPlane); ++i) { - uint8_t* y_row = video_frame->data(media::VideoFrame::kYPlane) + - video_frame->stride(media::VideoFrame::kYPlane) * i; - for (int j = 0; j < video_frame->row_bytes(media::VideoFrame::kYPlane); - ++j) { - y_row[j] = (y_value += 1); - } - } - for (int i = 0; i < video_frame->rows(media::VideoFrame::kUPlane); ++i) { - uint8_t* u_row = video_frame->data(media::VideoFrame::kUPlane) + - video_frame->stride(media::VideoFrame::kUPlane) * i; - uint8_t* v_row = video_frame->data(media::VideoFrame::kVPlane) + - video_frame->stride(media::VideoFrame::kVPlane) * i; - for (int j = 0; j < video_frame->row_bytes(media::VideoFrame::kUPlane); - ++j) { - u_row[j] = (u_value += 3); - v_row[j] = (v_value += 5); - } - } - uint8 alpha_value = is_transparent ? 0 : 128; - CreateTestYUVVideoDrawQuad_FromVideoFrame( - shared_state, video_frame, alpha_value, tex_coord_rect, render_pass); - } - - void CreateTestYUVVideoDrawQuad_Solid(const SharedQuadState* shared_state, - media::VideoFrame::Format format, - bool is_transparent, - const gfx::RectF& tex_coord_rect, - uint8 y, - uint8 u, - uint8 v, - RenderPass* render_pass) { - const gfx::Rect rect(this->device_viewport_size_); - - scoped_refptr<media::VideoFrame> video_frame = - media::VideoFrame::CreateFrame( - format, rect.size(), rect, rect.size(), base::TimeDelta()); - - // YUV values of a solid, constant, color. Useful for testing that color - // space/color range are being handled properly. - memset(video_frame->data(media::VideoFrame::kYPlane), - y, - video_frame->stride(media::VideoFrame::kYPlane) * - video_frame->rows(media::VideoFrame::kYPlane)); - memset(video_frame->data(media::VideoFrame::kUPlane), - u, - video_frame->stride(media::VideoFrame::kUPlane) * - video_frame->rows(media::VideoFrame::kUPlane)); - memset(video_frame->data(media::VideoFrame::kVPlane), - v, - video_frame->stride(media::VideoFrame::kVPlane) * - video_frame->rows(media::VideoFrame::kVPlane)); - - uint8 alpha_value = is_transparent ? 0 : 128; - CreateTestYUVVideoDrawQuad_FromVideoFrame( - shared_state, video_frame, alpha_value, tex_coord_rect, render_pass); - } - void CreateEdgeBleedPass(media::VideoFrame::Format format, RenderPassList* pass_list) { gfx::Rect rect(200, 200); @@ -492,139 +932,19 @@ class VideoGLRendererPixelTest : public GLRendererPixelTest { // green sub-rectangle that should be the only thing displayed in // the final image. Bleeding will appear on all four sides of the video // if the tex coords are not clamped. - CreateTestYUVVideoDrawQuad_TwoColor(shared_state, format, false, - tex_coord_rect, background_size, 0, 0, - 0, green_rect, 149, 43, 21, pass.get()); + CreateTestYUVVideoDrawQuad_TwoColor( + shared_state, format, false, tex_coord_rect, background_size, 0, 0, 0, + green_rect, 149, 43, 21, pass.get(), video_resource_updater_.get(), + resource_provider_.get()); pass_list->push_back(pass.Pass()); } - // Creates a video frame of size background_size filled with yuv_background, - // and then draws a foreground rectangle in a different color on top of - // that. The foreground rectangle must have coordinates that are divisible - // by 2 because YUV is a block format. - void CreateTestYUVVideoDrawQuad_TwoColor(const SharedQuadState* shared_state, - media::VideoFrame::Format format, - bool is_transparent, - const gfx::RectF& tex_coord_rect, - const gfx::Size& background_size, - uint8 y_background, - uint8 u_background, - uint8 v_background, - const gfx::Rect& foreground_rect, - uint8 y_foreground, - uint8 u_foreground, - uint8 v_foreground, - RenderPass* render_pass) { - const gfx::Rect rect(background_size); - - scoped_refptr<media::VideoFrame> video_frame = - media::VideoFrame::CreateFrame(format, background_size, foreground_rect, - foreground_rect.size(), - base::TimeDelta()); - - int planes[] = {media::VideoFrame::kYPlane, - media::VideoFrame::kUPlane, - media::VideoFrame::kVPlane}; - uint8 yuv_background[] = {y_background, u_background, v_background}; - uint8 yuv_foreground[] = {y_foreground, u_foreground, v_foreground}; - int sample_size[] = {1, 2, 2}; - - for (int i = 0; i < 3; ++i) { - memset(video_frame->data(planes[i]), yuv_background[i], - video_frame->stride(planes[i]) * video_frame->rows(planes[i])); - } - - for (int i = 0; i < 3; ++i) { - // Since yuv encoding uses block encoding, widths have to be divisible - // by the sample size in order for this function to behave properly. - DCHECK_EQ(foreground_rect.x() % sample_size[i], 0); - DCHECK_EQ(foreground_rect.y() % sample_size[i], 0); - DCHECK_EQ(foreground_rect.width() % sample_size[i], 0); - DCHECK_EQ(foreground_rect.height() % sample_size[i], 0); - - gfx::Rect sample_rect(foreground_rect.x() / sample_size[i], - foreground_rect.y() / sample_size[i], - foreground_rect.width() / sample_size[i], - foreground_rect.height() / sample_size[i]); - for (int y = sample_rect.y(); y < sample_rect.bottom(); ++y) { - for (int x = sample_rect.x(); x < sample_rect.right(); ++x) { - size_t offset = y * video_frame->stride(planes[i]) + x; - video_frame->data(planes[i])[offset] = yuv_foreground[i]; - } - } - } - - uint8 alpha_value = 255; - CreateTestYUVVideoDrawQuad_FromVideoFrame( - shared_state, video_frame, alpha_value, tex_coord_rect, render_pass); - } - - void CreateTestYUVVideoDrawQuad_FromVideoFrame( - const SharedQuadState* shared_state, - scoped_refptr<media::VideoFrame> video_frame, - uint8 alpha_value, - const gfx::RectF& tex_coord_rect, - RenderPass* render_pass) { - const bool with_alpha = (video_frame->format() == media::VideoFrame::YV12A); - const YUVVideoDrawQuad::ColorSpace color_space = - (video_frame->format() == media::VideoFrame::YV12J - ? YUVVideoDrawQuad::JPEG - : YUVVideoDrawQuad::REC_601); - const gfx::Rect rect(shared_state->content_bounds); - const gfx::Rect opaque_rect(0, 0, 0, 0); - - if (with_alpha) - memset(video_frame->data(media::VideoFrame::kAPlane), alpha_value, - video_frame->stride(media::VideoFrame::kAPlane) * - video_frame->rows(media::VideoFrame::kAPlane)); - - VideoFrameExternalResources resources = - video_resource_updater_->CreateExternalResourcesFromVideoFrame( - video_frame); - - EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); - EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame->format()), - resources.mailboxes.size()); - EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame->format()), - resources.release_callbacks.size()); - - ResourceProvider::ResourceId y_resource = - resource_provider_->CreateResourceFromTextureMailbox( - resources.mailboxes[media::VideoFrame::kYPlane], - SingleReleaseCallbackImpl::Create( - resources.release_callbacks[media::VideoFrame::kYPlane])); - ResourceProvider::ResourceId u_resource = - resource_provider_->CreateResourceFromTextureMailbox( - resources.mailboxes[media::VideoFrame::kUPlane], - SingleReleaseCallbackImpl::Create( - resources.release_callbacks[media::VideoFrame::kUPlane])); - ResourceProvider::ResourceId v_resource = - resource_provider_->CreateResourceFromTextureMailbox( - resources.mailboxes[media::VideoFrame::kVPlane], - SingleReleaseCallbackImpl::Create( - resources.release_callbacks[media::VideoFrame::kVPlane])); - ResourceProvider::ResourceId a_resource = 0; - if (with_alpha) { - a_resource = resource_provider_->CreateResourceFromTextureMailbox( - resources.mailboxes[media::VideoFrame::kAPlane], - SingleReleaseCallbackImpl::Create( - resources.release_callbacks[media::VideoFrame::kAPlane])); - } - - YUVVideoDrawQuad* yuv_quad = - render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); - yuv_quad->SetNew(shared_state, rect, opaque_rect, rect, tex_coord_rect, - video_frame->coded_size(), y_resource, u_resource, - v_resource, a_resource, color_space); - } - void SetUp() override { GLRendererPixelTest::SetUp(); video_resource_updater_.reset(new VideoResourceUpdater( output_surface_->context_provider(), resource_provider_.get())); } - private: scoped_ptr<VideoResourceUpdater> video_resource_updater_; }; @@ -637,11 +957,10 @@ TEST_F(VideoGLRendererPixelTest, SimpleYUVRect) { SharedQuadState* shared_state = CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); - CreateTestYUVVideoDrawQuad_Striped(shared_state, - media::VideoFrame::YV12, - false, - gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), - pass.get()); + CreateTestYUVVideoDrawQuad_Striped(shared_state, media::VideoFrame::YV12, + false, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), + pass.get(), video_resource_updater_.get(), + rect, resource_provider_.get()); RenderPassList pass_list; pass_list.push_back(pass.Pass()); @@ -662,11 +981,10 @@ TEST_F(VideoGLRendererPixelTest, OffsetYUVRect) { CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); // Intentionally sets frame format to I420 for testing coverage. - CreateTestYUVVideoDrawQuad_Striped(shared_state, - media::VideoFrame::I420, - false, - gfx::RectF(0.125f, 0.25f, 0.75f, 0.5f), - pass.get()); + CreateTestYUVVideoDrawQuad_Striped( + shared_state, media::VideoFrame::I420, false, + gfx::RectF(0.125f, 0.25f, 0.75f, 0.5f), pass.get(), + video_resource_updater_.get(), rect, resource_provider_.get()); RenderPassList pass_list; pass_list.push_back(pass.Pass()); @@ -687,14 +1005,10 @@ TEST_F(VideoGLRendererPixelTest, SimpleYUVRectBlack) { CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); // In MPEG color range YUV values of (15,128,128) should produce black. - CreateTestYUVVideoDrawQuad_Solid(shared_state, - media::VideoFrame::YV12, - false, - gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), - 15, - 128, - 128, - pass.get()); + CreateTestYUVVideoDrawQuad_Solid( + shared_state, media::VideoFrame::YV12, false, + gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 15, 128, 128, pass.get(), + video_resource_updater_.get(), rect, resource_provider_.get()); RenderPassList pass_list; pass_list.push_back(pass.Pass()); @@ -716,14 +1030,10 @@ TEST_F(VideoGLRendererPixelTest, SimpleYUVJRect) { CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); // YUV of (149,43,21) should be green (0,255,0) in RGB. - CreateTestYUVVideoDrawQuad_Solid(shared_state, - media::VideoFrame::YV12J, - false, - gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), - 149, - 43, - 21, - pass.get()); + CreateTestYUVVideoDrawQuad_Solid( + shared_state, media::VideoFrame::YV12J, false, + gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 149, 43, 21, pass.get(), + video_resource_updater_.get(), rect, resource_provider_.get()); RenderPassList pass_list; pass_list.push_back(pass.Pass()); @@ -761,14 +1071,10 @@ TEST_F(VideoGLRendererPixelTest, SimpleYUVJRectGrey) { CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); // Dark grey in JPEG color range (in MPEG, this is black). - CreateTestYUVVideoDrawQuad_Solid(shared_state, - media::VideoFrame::YV12J, - false, - gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), - 15, - 128, - 128, - pass.get()); + CreateTestYUVVideoDrawQuad_Solid( + shared_state, media::VideoFrame::YV12J, false, + gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 15, 128, 128, pass.get(), + video_resource_updater_.get(), rect, resource_provider_.get()); RenderPassList pass_list; pass_list.push_back(pass.Pass()); @@ -788,11 +1094,10 @@ TEST_F(VideoGLRendererPixelTest, SimpleYUVARect) { SharedQuadState* shared_state = CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); - CreateTestYUVVideoDrawQuad_Striped(shared_state, - media::VideoFrame::YV12A, - false, - gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), - pass.get()); + CreateTestYUVVideoDrawQuad_Striped(shared_state, media::VideoFrame::YV12A, + false, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), + pass.get(), video_resource_updater_.get(), + rect, resource_provider_.get()); SolidColorDrawQuad* color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); @@ -816,11 +1121,10 @@ TEST_F(VideoGLRendererPixelTest, FullyTransparentYUVARect) { SharedQuadState* shared_state = CreateTestSharedQuadState(gfx::Transform(), rect, pass.get()); - CreateTestYUVVideoDrawQuad_Striped(shared_state, - media::VideoFrame::YV12A, - true, - gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), - pass.get()); + CreateTestYUVVideoDrawQuad_Striped(shared_state, media::VideoFrame::YV12A, + true, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), + pass.get(), video_resource_updater_.get(), + rect, resource_provider_.get()); SolidColorDrawQuad* color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); diff --git a/cc/output/software_renderer.cc b/cc/output/software_renderer.cc index 5360d59..5726fd7 100644 --- a/cc/output/software_renderer.cc +++ b/cc/output/software_renderer.cc @@ -25,6 +25,7 @@ #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkImageFilter.h" #include "third_party/skia/include/core/SkMatrix.h" +#include "third_party/skia/include/core/SkPoint.h" #include "third_party/skia/include/core/SkShader.h" #include "third_party/skia/include/effects/SkLayerRasterizer.h" #include "ui/gfx/geometry/rect_conversions.h" @@ -235,7 +236,13 @@ bool SoftwareRenderer::IsSoftwareResource( return false; } -void SoftwareRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { +void SoftwareRenderer::DoDrawQuad(DrawingFrame* frame, + const DrawQuad* quad, + const gfx::QuadF* draw_region) { + if (draw_region) { + current_canvas_->save(); + } + TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad"); gfx::Transform quad_rect_matrix; QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); @@ -270,9 +277,31 @@ void SoftwareRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { current_paint_.setXfermodeMode(SkXfermode::kSrc_Mode); } + if (draw_region) { + gfx::QuadF local_draw_region(*draw_region); + SkPath draw_region_clip_path; + local_draw_region -= + gfx::Vector2dF(quad->visible_rect.x(), quad->visible_rect.y()); + local_draw_region.Scale(1.0f / quad->visible_rect.width(), + 1.0f / quad->visible_rect.height()); + local_draw_region -= gfx::Vector2dF(0.5f, 0.5f); + + SkPoint clip_points[4]; + QuadFToSkPoints(local_draw_region, clip_points); + draw_region_clip_path.addPoly(clip_points, 4, true); + + current_canvas_->clipPath(draw_region_clip_path, SkRegion::kIntersect_Op, + false); + } + switch (quad->material) { case DrawQuad::CHECKERBOARD: - DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); + // TODO(enne) For now since checkerboards shouldn't be part of a 3D + // context, clipping regions aren't supported so we skip drawing them + // if this becomes the case. + if (!draw_region) { + DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); + } break; case DrawQuad::DEBUG_BORDER: DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); @@ -307,6 +336,9 @@ void SoftwareRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { } current_canvas_->resetMatrix(); + if (draw_region) { + current_canvas_->restore(); + } } void SoftwareRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, diff --git a/cc/output/software_renderer.h b/cc/output/software_renderer.h index 99868c3..dc8e2fb 100644 --- a/cc/output/software_renderer.h +++ b/cc/output/software_renderer.h @@ -52,7 +52,10 @@ class CC_EXPORT SoftwareRenderer : public DirectRenderer { bool draw_rect_covers_full_surface) override; void ClearFramebuffer(DrawingFrame* frame, bool has_external_stencil_test) override; - void DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) override; + + void DoDrawQuad(DrawingFrame* frame, + const DrawQuad* quad, + const gfx::QuadF* draw_region) override; void BeginDrawingFrame(DrawingFrame* frame) override; void FinishDrawingFrame(DrawingFrame* frame) override; bool FlippedFramebuffer(const DrawingFrame* frame) const override; diff --git a/cc/output/static_geometry_binding.cc b/cc/output/static_geometry_binding.cc new file mode 100644 index 0000000..2a41faf --- /dev/null +++ b/cc/output/static_geometry_binding.cc @@ -0,0 +1,74 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cc/output/static_geometry_binding.h" + +#include "cc/output/gl_renderer.h" // For the GLC() macro. +#include "gpu/command_buffer/client/gles2_interface.h" +#include "ui/gfx/geometry/rect_f.h" + +namespace cc { + +StaticGeometryBinding::StaticGeometryBinding(gpu::gles2::GLES2Interface* gl, + const gfx::RectF& quad_vertex_rect) + : gl_(gl), quad_vertices_vbo_(0), quad_elements_vbo_(0) { + GeometryBindingQuad quads[8]; + GeometryBindingQuadIndex quad_indices[8]; + + static_assert(sizeof(GeometryBindingQuad) == 24 * sizeof(float), + "struct Quad should be densely packed"); + static_assert(sizeof(GeometryBindingQuadIndex) == 6 * sizeof(uint16_t), + "struct QuadIndex should be densely packed"); + + for (size_t i = 0; i < 8; i++) { + GeometryBindingVertex v0 = { + {quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f}, + {0.0f, 1.0f}, + i * 4.0f + 0.0f}; + GeometryBindingVertex v1 = { + {quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f}, + {0.0f, 0.0f}, + i * 4.0f + 1.0f}; + GeometryBindingVertex v2 = { + {quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f}, + {1.0f, 0.0f}, + i * 4.0f + 2.0f}; + GeometryBindingVertex v3 = { + {quad_vertex_rect.right(), quad_vertex_rect.bottom(), 0.0f}, + {1.0f, 1.0f}, + i * 4.0f + 3.0f}; + GeometryBindingQuad x = {v0, v1, v2, v3}; + quads[i] = x; + GeometryBindingQuadIndex y = {{static_cast<uint16>(0 + 4 * i), + static_cast<uint16>(1 + 4 * i), + static_cast<uint16>(2 + 4 * i), + static_cast<uint16>(3 + 4 * i), + static_cast<uint16>(0 + 4 * i), + static_cast<uint16>(2 + 4 * i)}}; + quad_indices[i] = y; + } + + GLC(gl_, gl_->GenBuffers(1, &quad_vertices_vbo_)); + GLC(gl_, gl_->GenBuffers(1, &quad_elements_vbo_)); + + GLC(gl_, gl_->BindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); + GLC(gl_, gl_->BufferData(GL_ARRAY_BUFFER, sizeof(GeometryBindingQuad) * 8, + quads, GL_STATIC_DRAW)); + + GLC(gl_, gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_)); + GLC(gl_, gl_->BufferData(GL_ELEMENT_ARRAY_BUFFER, + sizeof(GeometryBindingQuadIndex) * 8, &quad_indices, + GL_STATIC_DRAW)); +} + +StaticGeometryBinding::~StaticGeometryBinding() { + gl_->DeleteBuffers(1, &quad_vertices_vbo_); + gl_->DeleteBuffers(1, &quad_elements_vbo_); +} + +void StaticGeometryBinding::PrepareForDraw() { + SetupGLContext(gl_, quad_elements_vbo_, quad_vertices_vbo_); +} + +} // namespace cc diff --git a/cc/output/static_geometry_binding.h b/cc/output/static_geometry_binding.h new file mode 100644 index 0000000..bd6bfcc --- /dev/null +++ b/cc/output/static_geometry_binding.h @@ -0,0 +1,33 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CC_OUTPUT_STATIC_GEOMETRY_BINDING_H_ +#define CC_OUTPUT_STATIC_GEOMETRY_BINDING_H_ + +#include "cc/output/geometry_binding.h" + +using gpu::gles2::GLES2Interface; + +namespace cc { + +class StaticGeometryBinding { + public: + StaticGeometryBinding(gpu::gles2::GLES2Interface* gl, + const gfx::RectF& quad_vertex_rect); + ~StaticGeometryBinding(); + + void PrepareForDraw(); + + private: + gpu::gles2::GLES2Interface* gl_; + + GLuint quad_vertices_vbo_; + GLuint quad_elements_vbo_; + + DISALLOW_COPY_AND_ASSIGN(StaticGeometryBinding); +}; + +} // namespace cc + +#endif // CC_OUTPUT_STATIC_GEOMETRY_BINDING_H_ |