#include "cc/layers/delegated_renderer_layer_impl.h"
#include "cc/base/scoped_ptr_vector.h"
-#include "cc/layers/append_quads_data.h"
-#include "cc/layers/quad_sink.h"
#include "cc/layers/solid_color_layer_impl.h"
#include "cc/quads/render_pass_draw_quad.h"
#include "cc/quads/solid_color_draw_quad.h"
#include "cc/test/fake_proxy.h"
#include "cc/test/fake_rendering_stats_instrumentation.h"
#include "cc/test/geometry_test_utils.h"
-#include "cc/test/mock_quad_culler.h"
+#include "cc/test/layer_test_common.h"
#include "cc/test/render_pass_test_common.h"
#include "cc/test/render_pass_test_utils.h"
+#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
LayerTreeSettings settings;
settings.minimum_occlusion_tracking_size = gfx::Size();
- host_impl_.reset(new FakeLayerTreeHostImpl(settings, &proxy_));
+ host_impl_.reset(
+ new FakeLayerTreeHostImpl(settings, &proxy_, &shared_bitmap_manager_));
host_impl_->InitializeRenderer(
FakeOutputSurface::Create3d().PassAs<OutputSurface>());
host_impl_->SetViewportSize(gfx::Size(10, 10));
FakeProxy proxy_;
DebugScopedSetImplThreadAndMainThreadBlocked
always_impl_thread_and_main_thread_blocked_;
+ TestSharedBitmapManager shared_bitmap_manager_;
scoped_ptr<LayerTreeHostImpl> host_impl_;
};
transform.Translate(1.0, 1.0);
delegated_renderer_layer->SetTransform(transform);
- ScopedPtrVector<RenderPass> delegated_render_passes;
+ RenderPassList delegated_render_passes;
TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
- RenderPass::Id(9, 6),
+ RenderPassId(9, 6),
gfx::Rect(6, 6, 6, 6),
gfx::Transform(1, 0, 0, 1, 5, 6));
AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
TestRenderPass* pass2 = AddRenderPass(&delegated_render_passes,
- RenderPass::Id(9, 7),
+ RenderPassId(9, 7),
gfx::Rect(7, 7, 7, 7),
gfx::Transform(1, 0, 0, 1, 7, 8));
AddQuad(pass2, gfx::Rect(0, 0, 7, 7), 22u);
AddRenderPassQuad(pass2, pass1);
TestRenderPass* pass3 = AddRenderPass(&delegated_render_passes,
- RenderPass::Id(9, 8),
+ RenderPassId(9, 8),
gfx::Rect(0, 0, 8, 8),
gfx::Transform(1, 0, 0, 1, 9, 10));
AddRenderPassQuad(pass3, pass2);
delegated_renderer_layer->SetFrameDataForRenderPasses(
- &delegated_render_passes);
+ 1.f, &delegated_render_passes);
// The RenderPasses should be taken by the layer.
EXPECT_EQ(0u, delegated_render_passes.size());
TEST_F(DelegatedRendererLayerImplTestSimple, AddsContributingRenderPasses) {
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes.
TEST_F(DelegatedRendererLayerImplTestSimple,
AddsQuadsToContributingRenderPasses) {
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes.
// contributing RenderPasses.
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
- frame.render_passes[1]->quad_list[0]->rect.ToString());
+ frame.render_passes[1]->quad_list.front()->rect.ToString());
// Verify it added the right quads.
ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
- frame.render_passes[2]->quad_list[0]->rect.ToString());
+ frame.render_passes[2]->quad_list.front()->rect.ToString());
EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
- frame.render_passes[2]->quad_list[1]->rect.ToString());
+ frame.render_passes[2]->quad_list.ElementAt(1)->rect.ToString());
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
- frame.render_passes[1]->quad_list[0]->rect.ToString());
+ frame.render_passes[1]->quad_list.front()->rect.ToString());
host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
host_impl_->DidDrawAllLayers(frame);
TEST_F(DelegatedRendererLayerImplTestSimple, AddsQuadsToTargetRenderPass) {
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes.
ASSERT_EQ(5u, frame.render_passes.size());
// The layer's target is the RenderPass from layer_after_.
- EXPECT_EQ(RenderPass::Id(3, 0), frame.render_passes[3]->id);
+ EXPECT_EQ(RenderPassId(3, 0), frame.render_passes[3]->id);
// The DelegatedRendererLayer should have added copies of quads in its root
// RenderPass to its target RenderPass. The layer_after_ also adds one quad.
// Verify it added the right quads.
EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
- frame.render_passes[3]->quad_list[0]->rect.ToString());
+ frame.render_passes[3]->quad_list.front()->rect.ToString());
// Its target layer should have a quad as well.
EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
- frame.render_passes[3]->quad_list[1]->rect.ToString());
+ frame.render_passes[3]->quad_list.ElementAt(1)->rect.ToString());
host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
host_impl_->DidDrawAllLayers(frame);
TEST_F(DelegatedRendererLayerImplTestSimple,
QuadsFromRootRenderPassAreModifiedForTheTarget) {
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes.
// The DelegatedRendererLayer is at position 3,3 compared to its target, and
// has a translation transform of 1,1. So its root RenderPass' quads should
// all be transformed by that combined amount.
- // The DelegatedRendererLayer has a size of 10x10, but the root delegated
- // RenderPass has a size of 8x8, so any quads should be scaled by 10/8.
gfx::Transform transform;
transform.Translate(4.0, 4.0);
- transform.Scale(10.0 / 8.0, 10.0 / 8.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
- transform, frame.render_passes[3]->quad_list[0]->quadTransform());
+ transform, frame.render_passes[3]->quad_list.front()->quadTransform());
// Quads from non-root RenderPasses should not be shifted though.
ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
+
EXPECT_TRANSFORMATION_MATRIX_EQ(
- gfx::Transform(), frame.render_passes[2]->quad_list[0]->quadTransform());
+ gfx::Transform(),
+ frame.render_passes[2]->quad_list.front()->quadTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
- gfx::Transform(), frame.render_passes[2]->quad_list[1]->quadTransform());
+ gfx::Transform(),
+ frame.render_passes[2]->quad_list.ElementAt(1)->quadTransform());
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_TRANSFORMATION_MATRIX_EQ(
- gfx::Transform(), frame.render_passes[1]->quad_list[0]->quadTransform());
+ gfx::Transform(),
+ frame.render_passes[1]->quad_list.front()->quadTransform());
host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
host_impl_->DidDrawAllLayers(frame);
TEST_F(DelegatedRendererLayerImplTestSimple, RenderPassTransformIsModified) {
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// The delegated layer has a surface between it and the root.
EXPECT_TRUE(delegated_renderer_layer_->render_target()->parent());
// The DelegatedRendererLayer is at position 9,9 compared to the root, so all
// render pass' transforms to the root should be shifted by this amount.
- // The DelegatedRendererLayer has a size of 10x10, but the root delegated
- // RenderPass has a size of 8x8, so any render passes should be scaled by
- // 10/8.
gfx::Transform transform;
transform.Translate(9.0, 9.0);
- transform.Scale(10.0 / 8.0, 10.0 / 8.0);
// The first contributing surface has a translation of 5, 6.
gfx::Transform five_six(1, 0, 0, 1, 5, 6);
TEST_F(DelegatedRendererLayerImplTestSimple, DoesNotOwnARenderSurface) {
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// If the DelegatedRendererLayer is axis aligned and has opacity 1, then it
// has no need to be a RenderSurface for the quads it carries.
delegated_renderer_layer_->SetOpacity(0.5f);
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(
+ host_impl_->active_tree()->root_layer());
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// This test case has quads from multiple layers in the delegated renderer, so
// if the DelegatedRendererLayer has opacity < 1, it should end up with a
delegated_renderer_layer_->SetTransform(rotation);
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(
+ host_impl_->active_tree()->root_layer());
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// This test case has quads from multiple layers in the delegated renderer, so
// if the DelegatedRendererLayer has opacity < 1, it should end up with a
TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsRenderPasses) {
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes and its owned surface
TEST_F(DelegatedRendererLayerImplTestOwnSurface,
AddsQuadsToContributingRenderPasses) {
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes and its owned surface
// contributing RenderPasses.
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
- frame.render_passes[1]->quad_list[0]->rect.ToString());
+ frame.render_passes[1]->quad_list.front()->rect.ToString());
// Verify it added the right quads.
ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
+
EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
- frame.render_passes[2]->quad_list[0]->rect.ToString());
+ frame.render_passes[2]->quad_list.front()->rect.ToString());
EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
- frame.render_passes[2]->quad_list[1]->rect.ToString());
+ frame.render_passes[2]->quad_list.ElementAt(1)->rect.ToString());
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
- frame.render_passes[1]->quad_list[0]->rect.ToString());
+ frame.render_passes[1]->quad_list.front()->rect.ToString());
host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
host_impl_->DidDrawAllLayers(frame);
TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsQuadsToTargetRenderPass) {
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes and its owned surface
ASSERT_EQ(6u, frame.render_passes.size());
// The layer's target is the RenderPass owned by itself.
- EXPECT_EQ(RenderPass::Id(4, 0), frame.render_passes[3]->id);
+ EXPECT_EQ(RenderPassId(4, 0), frame.render_passes[3]->id);
// The DelegatedRendererLayer should have added copies of quads in its root
// RenderPass to its target RenderPass.
// Verify it added the right quads.
EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
- frame.render_passes[3]->quad_list[0]->rect.ToString());
+ frame.render_passes[3]->quad_list.front()->rect.ToString());
host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
host_impl_->DidDrawAllLayers(frame);
TEST_F(DelegatedRendererLayerImplTestOwnSurface,
QuadsFromRootRenderPassAreNotModifiedForTheTarget) {
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes and its owned surface
ASSERT_EQ(6u, frame.render_passes.size());
// Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
- // RenderPass' quads do not need to be translated at all. However, they are
- // scaled from the frame's size (8x8) to the layer's bounds (10x10).
- gfx::Transform transform;
- transform.Scale(10.0 / 8.0, 10.0 / 8.0);
+ // RenderPass' quads do not need to be translated at all.
EXPECT_TRANSFORMATION_MATRIX_EQ(
- transform, frame.render_passes[3]->quad_list[0]->quadTransform());
+ gfx::Transform(),
+ frame.render_passes[3]->quad_list.front()->quadTransform());
// Quads from non-root RenderPasses should not be shifted either.
ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
+
EXPECT_TRANSFORMATION_MATRIX_EQ(
- gfx::Transform(), frame.render_passes[2]->quad_list[0]->quadTransform());
+ gfx::Transform(),
+ frame.render_passes[2]->quad_list.front()->quadTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
- gfx::Transform(), frame.render_passes[2]->quad_list[1]->quadTransform());
+ gfx::Transform(),
+ frame.render_passes[2]->quad_list.ElementAt(1)->quadTransform());
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_TRANSFORMATION_MATRIX_EQ(
- gfx::Transform(), frame.render_passes[1]->quad_list[0]->quadTransform());
+ gfx::Transform(),
+ frame.render_passes[1]->quad_list.front()->quadTransform());
host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
host_impl_->DidDrawAllLayers(frame);
class DelegatedRendererLayerImplTestTransform
: public DelegatedRendererLayerImplTest {
public:
+ DelegatedRendererLayerImplTestTransform()
+ : root_delegated_render_pass_is_clipped_(false),
+ delegated_device_scale_factor_(2.f) {}
+
void SetUpTest() {
host_impl_->SetDeviceScaleFactor(2.f);
transform.Translate(8.0, 8.0);
delegated_renderer_layer->SetTransform(transform);
- ScopedPtrVector<RenderPass> delegated_render_passes;
+ RenderPassList delegated_render_passes;
gfx::Size child_pass_content_bounds(7, 7);
gfx::Rect child_pass_rect(20, 20, 7, 7);
bool child_pass_clipped = false;
{
- TestRenderPass* pass = AddRenderPass(
- &delegated_render_passes,
- RenderPass::Id(10, 7),
- child_pass_rect,
- gfx::Transform());
- MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
- AppendQuadsData data(pass->id);
- SharedQuadState* shared_quad_state = quad_sink.UseSharedQuadState(
- SharedQuadState::Create());
+ TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
+ RenderPassId(10, 7),
+ child_pass_rect,
+ gfx::Transform());
+ SharedQuadState* shared_quad_state =
+ pass->CreateAndAppendSharedQuadState();
shared_quad_state->SetAll(child_pass_transform,
child_pass_content_bounds,
child_pass_rect,
child_pass_clip_rect,
child_pass_clipped,
1.f,
- SkXfermode::kSrcOver_Mode);
-
- scoped_ptr<SolidColorDrawQuad> color_quad;
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(20, 20, 3, 7), 1u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
-
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(23, 20, 4, 7), 1u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
+ SkXfermode::kSrcOver_Mode,
+ 0);
+
+ SolidColorDrawQuad* color_quad;
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(20, 20, 3, 7),
+ gfx::Rect(20, 20, 3, 7),
+ 1u,
+ false);
+
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(23, 20, 4, 7),
+ gfx::Rect(23, 20, 4, 7),
+ 1u,
+ false);
}
gfx::Size root_pass_content_bounds(100, 100);
gfx::Rect root_pass_clip_rect(10, 10, 35, 35);
bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
- TestRenderPass* pass = AddRenderPass(
- &delegated_render_passes,
- RenderPass::Id(9, 6),
- root_pass_rect,
- gfx::Transform());
- MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
- AppendQuadsData data(pass->id);
- SharedQuadState* shared_quad_state =
- quad_sink.UseSharedQuadState(SharedQuadState::Create());
+ TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
+ RenderPassId(9, 6),
+ root_pass_rect,
+ gfx::Transform());
+ SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
shared_quad_state->SetAll(root_pass_transform,
root_pass_content_bounds,
root_pass_rect,
root_pass_clip_rect,
root_pass_clipped,
1.f,
- SkXfermode::kSrcOver_Mode);
-
- scoped_ptr<RenderPassDrawQuad> render_pass_quad =
- RenderPassDrawQuad::Create();
- render_pass_quad->SetNew(
- shared_quad_state,
- gfx::Rect(5, 5, 7, 7), // rect
- RenderPass::Id(10, 7), // render_pass_id
- false, // is_replica
- 0, // mask_resource_id
- child_pass_rect, // contents_changed_since_last_frame
- gfx::RectF(), // mask_uv_rect
- FilterOperations(), // filters
- FilterOperations()); // background_filters
- quad_sink.Append(render_pass_quad.PassAs<DrawQuad>(), &data);
-
- scoped_ptr<SolidColorDrawQuad> color_quad;
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(0, 0, 10, 10), 1u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
-
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(0, 10, 10, 10), 2u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
-
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(10, 0, 10, 10), 3u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
-
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(10, 10, 10, 10), 4u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
+ SkXfermode::kSrcOver_Mode,
+ 0);
+
+ RenderPassDrawQuad* render_pass_quad =
+ pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
+ render_pass_quad->SetNew(shared_quad_state,
+ gfx::Rect(5, 5, 7, 7), // quad_rect
+ gfx::Rect(5, 5, 7, 7), // visible_rect
+ RenderPassId(10, 7), // render_pass_id
+ 0, // mask_resource_id
+ gfx::RectF(), // mask_uv_rect
+ FilterOperations(), // filters
+ gfx::Vector2dF(), // filters_scale
+ FilterOperations()); // background_filters
+
+ SolidColorDrawQuad* color_quad;
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(0, 0, 10, 10),
+ gfx::Rect(0, 0, 10, 10),
+ 1u,
+ false);
+
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(0, 10, 10, 10),
+ gfx::Rect(0, 10, 10, 10),
+ 2u,
+ false);
+
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(10, 0, 10, 10),
+ gfx::Rect(10, 0, 10, 10),
+ 3u,
+ false);
+
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(10, 10, 10, 10),
+ gfx::Rect(10, 10, 10, 10),
+ 4u,
+ false);
delegated_renderer_layer->SetFrameDataForRenderPasses(
- &delegated_render_passes);
+ delegated_device_scale_factor_, &delegated_render_passes);
// The RenderPasses should be taken by the layer.
EXPECT_EQ(0u, delegated_render_passes.size());
// All quads in a render pass should share the same state.
*contrib_delegated_shared_quad_state =
- contrib_delegated_quad_list[0]->shared_quad_state;
+ contrib_delegated_quad_list.front()->shared_quad_state;
EXPECT_EQ(*contrib_delegated_shared_quad_state,
- contrib_delegated_quad_list[1]->shared_quad_state);
+ contrib_delegated_quad_list.ElementAt(1)->shared_quad_state);
*root_delegated_shared_quad_state =
- root_delegated_quad_list[0]->shared_quad_state;
+ root_delegated_quad_list.front()->shared_quad_state;
EXPECT_EQ(*root_delegated_shared_quad_state,
- root_delegated_quad_list[1]->shared_quad_state);
+ root_delegated_quad_list.ElementAt(1)->shared_quad_state);
EXPECT_EQ(*root_delegated_shared_quad_state,
- root_delegated_quad_list[2]->shared_quad_state);
+ root_delegated_quad_list.ElementAt(2)->shared_quad_state);
EXPECT_EQ(*root_delegated_shared_quad_state,
- root_delegated_quad_list[3]->shared_quad_state);
+ root_delegated_quad_list.ElementAt(3)->shared_quad_state);
EXPECT_EQ(*root_delegated_shared_quad_state,
- root_delegated_quad_list[4]->shared_quad_state);
+ root_delegated_quad_list.ElementAt(4)->shared_quad_state);
EXPECT_NE(*contrib_delegated_shared_quad_state,
*root_delegated_shared_quad_state);
LayerImpl* root_layer_;
DelegatedRendererLayerImpl* delegated_renderer_layer_;
bool root_delegated_render_pass_is_clipped_;
+ float delegated_device_scale_factor_;
};
TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_NoSurface) {
SetUpTest();
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
const SharedQuadState* root_delegated_shared_quad_state = NULL;
const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
gfx::Transform expected;
- // Device scale factor is 2.
+ // Device scale factor.
expected.Scale(2.0, 2.0);
// This is the transform from the layer's space to its target.
- // The position (20) - the width / scale (75 / 2) = 20 - 37.5 = -17.5
- expected.Translate(-17.5, -17.5);
+ expected.Translate(20, 20);
expected.Scale(2.0, 2.0);
expected.Translate(8.0, 8.0);
- // The frame has size 100x100 but the layer's bounds are 75x75.
- expected.Scale(75.0 / 100.0, 75.0 / 100.0);
// This is the transform within the source frame.
+ // Inverse device scale factor to go from physical space to layer space.
+ expected.Scale(0.5, 0.5);
expected.Scale(1.5, 1.5);
expected.Translate(7.0, 7.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
SetUpTest();
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
const SharedQuadState* root_delegated_shared_quad_state = NULL;
const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
// Since the quads have a clip_rect it should be modified by delegated
// renderer layer's draw_transform.
// The position of the resulting clip_rect is:
- // (clip rect position (10) * scale to layer (75/100) + translate (8)) *
- // layer scale (2) + layer position (20) = 51
- // But the layer is centered, so: 51 - (75 / 2) = 51 - 75 / 2 = 13.5
- // The device scale is 2, so everything gets doubled, giving 27.
+ // (clip rect position (10) * inverse dsf (1/2) + translate (8)) *
+ // layer scale (2) + layer position (20) = 46
+ // The device scale is 2, so everything gets doubled, giving 92.
//
- // The size is 35x35 scaled to fit inside the layer's bounds at 75x75 from
- // a frame at 100x100: 35 * 2 (device scale) * 75 / 100 = 52.5. The device
- // scale doubles this to 105.
- EXPECT_EQ(gfx::Rect(27, 27, 105, 105).ToString(),
+ // The size is 35x35 scaled by the device scale.
+ EXPECT_EQ(gfx::Rect(92, 92, 70, 70).ToString(),
root_delegated_shared_quad_state->clip_rect.ToString());
// The quads had a clip and it should be preserved.
EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
gfx::Transform expected;
- // Device scale factor is 2.
+ // Device scale factor.
expected.Scale(2.0, 2.0);
// This is the transform from the layer's space to its target.
- // The position (20) - the width / scale (75 / 2) = 20 - 37.5 = -17.5
- expected.Translate(-17.5, -17.5);
+ expected.Translate(20, 20);
expected.Scale(2.0, 2.0);
expected.Translate(8.0, 8.0);
- // The frame has size 100x100 but the layer's bounds are 75x75.
- expected.Scale(75.0 / 100.0, 75.0 / 100.0);
// This is the transform within the source frame.
+ // Inverse device scale factor to go from physical space to layer space.
+ expected.Scale(0.5, 0.5);
expected.Scale(1.5, 1.5);
expected.Translate(7.0, 7.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
delegated_renderer_layer_->SetForceRenderSurface(true);
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
const SharedQuadState* root_delegated_shared_quad_state = NULL;
const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
// When the layer owns a surface, then its position and translation are not
// a part of its draw transform.
- // The position of the resulting clip_rect is:
- // (clip rect position (10) * scale to layer (75/100)) * device scale (2) = 15
- // The size is 35x35 scaled to fit inside the layer's bounds at 75x75 from
- // a frame at 100x100: 35 * 2 (device scale) * 75 / 100 = 52.5.
- EXPECT_EQ(gfx::Rect(15, 15, 53, 53).ToString(),
+ EXPECT_EQ(gfx::Rect(10, 10, 35, 35).ToString(),
root_delegated_shared_quad_state->clip_rect.ToString());
// Since the layer owns a surface it doesn't need to clip its quads, so
EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
gfx::Transform expected;
- // Device scale factor is 2.
- expected.Scale(2.0, 2.0);
- // The frame has size 100x100 but the layer's bounds are 75x75.
- expected.Scale(75.0 / 100.0, 75.0 / 100.0);
// This is the transform within the source frame.
expected.Scale(1.5, 1.5);
expected.Translate(7.0, 7.0);
delegated_renderer_layer_->SetForceRenderSurface(true);
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
const SharedQuadState* root_delegated_shared_quad_state = NULL;
const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
&contrib_delegated_shared_quad_state);
// When the layer owns a surface, then its position and translation are not
- // a part of its draw transform.
- // The position of the resulting clip_rect is:
- // (clip rect position (10) * scale to layer (75/100)) * device scale (2) = 15
- // The size is 35x35 scaled to fit inside the layer's bounds at 75x75 from
- // a frame at 100x100: 35 * 2 (device scale) * 75 / 100 = 52.5.
- EXPECT_EQ(gfx::Rect(15, 15, 53, 53).ToString(),
+ // a part of its draw transform. The clip_rect should be preserved.
+ EXPECT_EQ(gfx::Rect(10, 10, 35, 35).ToString(),
root_delegated_shared_quad_state->clip_rect.ToString());
// The quads had a clip and it should be preserved.
EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
gfx::Transform expected;
- // Device scale factor is 2.
- expected.Scale(2.0, 2.0);
- // The frame has size 100x100 but the layer's bounds are 75x75.
- expected.Scale(75.0 / 100.0, 75.0 / 100.0);
// This is the transform within the source frame.
expected.Scale(1.5, 1.5);
expected.Translate(7.0, 7.0);
host_impl_->DidDrawAllLayers(frame);
}
+TEST_F(DelegatedRendererLayerImplTestTransform, MismatchedDeviceScaleFactor) {
+ root_delegated_render_pass_is_clipped_ = true;
+ delegated_device_scale_factor_ = 1.3f;
+
+ SetUpTest();
+
+ LayerTreeHostImpl::FrameData frame;
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
+
+ const SharedQuadState* root_delegated_shared_quad_state = NULL;
+ const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
+ VerifyRenderPasses(frame,
+ 2,
+ &root_delegated_shared_quad_state,
+ &contrib_delegated_shared_quad_state);
+
+ // The parent tree's device scale factor is 2.0, but the child has submitted a
+ // frame with a device scale factor of 1.3. Absent any better option, the
+ // only thing we can do is scale from 1.3 -> 2.0.
+
+ gfx::Transform expected;
+ // Device scale factor (from parent).
+ expected.Scale(2.0, 2.0);
+ // This is the transform from the layer's space to its target.
+ expected.Translate(20, 20);
+ expected.Scale(2.0, 2.0);
+ expected.Translate(8.0, 8.0);
+ // This is the transform within the source frame.
+ // Inverse device scale factor (from child).
+ expected.Scale(1.0f / 1.3f, 1.0f / 1.3f);
+ expected.Scale(1.5, 1.5);
+ expected.Translate(7.0, 7.0);
+ EXPECT_TRANSFORMATION_MATRIX_EQ(
+ expected, root_delegated_shared_quad_state->content_to_target_transform);
+
+ host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
+ host_impl_->DidDrawAllLayers(frame);
+}
+
class DelegatedRendererLayerImplTestClip
: public DelegatedRendererLayerImplTest {
public:
delegated_renderer_layer->SetContentBounds(gfx::Size(50, 50));
delegated_renderer_layer->SetDrawsContent(true);
- ScopedPtrVector<RenderPass> delegated_render_passes;
+ RenderPassList delegated_render_passes;
gfx::Size child_pass_content_bounds(7, 7);
gfx::Rect child_pass_rect(20, 20, 7, 7);
bool child_pass_clipped = false;
{
- TestRenderPass* pass = AddRenderPass(
- &delegated_render_passes,
- RenderPass::Id(10, 7),
- child_pass_rect,
- gfx::Transform());
- MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
- AppendQuadsData data(pass->id);
+ TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
+ RenderPassId(10, 7),
+ child_pass_rect,
+ gfx::Transform());
SharedQuadState* shared_quad_state =
- quad_sink.UseSharedQuadState(SharedQuadState::Create());
+ pass->CreateAndAppendSharedQuadState();
shared_quad_state->SetAll(child_pass_transform,
child_pass_content_bounds,
child_pass_rect,
child_pass_clip_rect,
child_pass_clipped,
1.f,
- SkXfermode::kSrcOver_Mode);
-
- scoped_ptr<SolidColorDrawQuad> color_quad;
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(20, 20, 3, 7), 1u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
-
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(23, 20, 4, 7), 1u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
+ SkXfermode::kSrcOver_Mode,
+ 0);
+
+ SolidColorDrawQuad* color_quad;
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(20, 20, 3, 7),
+ gfx::Rect(20, 20, 3, 7),
+ 1u,
+ false);
+
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(23, 20, 4, 7),
+ gfx::Rect(23, 20, 4, 7),
+ 1u,
+ false);
}
gfx::Size root_pass_content_bounds(50, 50);
gfx::Rect root_pass_clip_rect(5, 5, 40, 40);
bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
- TestRenderPass* pass = AddRenderPass(
- &delegated_render_passes,
- RenderPass::Id(9, 6),
- root_pass_rect,
- gfx::Transform());
- MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
- AppendQuadsData data(pass->id);
- SharedQuadState* shared_quad_state =
- quad_sink.UseSharedQuadState(SharedQuadState::Create());
+ TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
+ RenderPassId(9, 6),
+ root_pass_rect,
+ gfx::Transform());
+ SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
shared_quad_state->SetAll(root_pass_transform,
root_pass_content_bounds,
root_pass_rect,
root_pass_clip_rect,
root_pass_clipped,
1.f,
- SkXfermode::kSrcOver_Mode);
-
- scoped_ptr<RenderPassDrawQuad> render_pass_quad =
- RenderPassDrawQuad::Create();
- render_pass_quad->SetNew(
- shared_quad_state,
- gfx::Rect(5, 5, 7, 7), // rect
- RenderPass::Id(10, 7), // render_pass_id
- false, // is_replica
- 0, // mask_resource_id
- child_pass_rect, // contents_changed_since_last_frame
- gfx::RectF(), // mask_uv_rect
- FilterOperations(), // filters
- FilterOperations()); // background_filters
- quad_sink.Append(render_pass_quad.PassAs<DrawQuad>(), &data);
-
- scoped_ptr<SolidColorDrawQuad> color_quad;
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(0, 0, 10, 10), 1u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
-
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(0, 10, 10, 10), 2u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
-
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(10, 0, 10, 10), 3u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
-
- color_quad = SolidColorDrawQuad::Create();
- color_quad->SetNew(shared_quad_state, gfx::Rect(10, 10, 10, 10), 4u, false);
- quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
+ SkXfermode::kSrcOver_Mode,
+ 0);
+
+ RenderPassDrawQuad* render_pass_quad =
+ pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
+ render_pass_quad->SetNew(shared_quad_state,
+ gfx::Rect(5, 5, 7, 7), // quad_rect
+ gfx::Rect(5, 5, 7, 7), // visible_quad_rect
+ RenderPassId(10, 7), // render_pass_id
+ 0, // mask_resource_id
+ gfx::RectF(), // mask_uv_rect
+ FilterOperations(), // filters
+ gfx::Vector2dF(), // filters_scale
+ FilterOperations()); // background_filters
+
+ SolidColorDrawQuad* color_quad;
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(0, 0, 10, 10),
+ gfx::Rect(0, 0, 10, 10),
+ 1u,
+ false);
+
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(0, 10, 10, 10),
+ gfx::Rect(0, 10, 10, 10),
+ 2u,
+ false);
+
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(10, 0, 10, 10),
+ gfx::Rect(10, 0, 10, 10),
+ 3u,
+ false);
+
+ color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ color_quad->SetNew(shared_quad_state,
+ gfx::Rect(10, 10, 10, 10),
+ gfx::Rect(10, 10, 10, 10),
+ 4u,
+ false);
delegated_renderer_layer->SetFrameDataForRenderPasses(
- &delegated_render_passes);
+ 1.f, &delegated_render_passes);
// The RenderPasses should be taken by the layer.
EXPECT_EQ(0u, delegated_render_passes.size());
SetUpTest();
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
ASSERT_EQ(2u, frame.render_passes.size());
const QuadList& contrib_delegated_quad_list =
const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
ASSERT_EQ(5u, root_delegated_quad_list.size());
const SharedQuadState* root_delegated_shared_quad_state =
- root_delegated_quad_list[0]->shared_quad_state;
+ root_delegated_quad_list.front()->shared_quad_state;
// When the quads don't have a clip of their own, the clip rect is set to
// the drawable_content_rect of the delegated renderer layer.
SetUpTest();
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
ASSERT_EQ(2u, frame.render_passes.size());
const QuadList& contrib_delegated_quad_list =
frame.render_passes[1]->quad_list;
ASSERT_EQ(5u, root_delegated_quad_list.size());
const SharedQuadState* root_delegated_shared_quad_state =
- root_delegated_quad_list[0]->shared_quad_state;
+ root_delegated_quad_list.front()->shared_quad_state;
// When the quads have a clip of their own, it is used.
EXPECT_EQ(gfx::Rect(25, 25, 40, 40).ToString(),
SetUpTest();
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
ASSERT_EQ(2u, frame.render_passes.size());
const QuadList& contrib_delegated_quad_list =
const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
ASSERT_EQ(5u, root_delegated_quad_list.size());
const SharedQuadState* root_delegated_shared_quad_state =
- root_delegated_quad_list[0]->shared_quad_state;
+ root_delegated_quad_list.front()->shared_quad_state;
// When the quads don't have a clip of their own, the clip rect is set to
// the drawable_content_rect of the delegated renderer layer. When the layer
SetUpTest();
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
ASSERT_EQ(2u, frame.render_passes.size());
const QuadList& contrib_delegated_quad_list =
const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
ASSERT_EQ(5u, root_delegated_quad_list.size());
const SharedQuadState* root_delegated_shared_quad_state =
- root_delegated_quad_list[0]->shared_quad_state;
+ root_delegated_quad_list.front()->shared_quad_state;
// When the quads have a clip of their own, it is used, but it is
// combined with the clip rect of the delegated renderer layer.
delegated_renderer_layer_->SetForceRenderSurface(true);
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
ASSERT_EQ(3u, frame.render_passes.size());
const QuadList& contrib_delegated_quad_list =
const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
ASSERT_EQ(5u, root_delegated_quad_list.size());
const SharedQuadState* root_delegated_shared_quad_state =
- root_delegated_quad_list[0]->shared_quad_state;
+ root_delegated_quad_list.front()->shared_quad_state;
// When the layer owns a surface, the quads don't need to be clipped
// further than they already specify. If they aren't clipped, then their
delegated_renderer_layer_->SetForceRenderSurface(true);
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
ASSERT_EQ(3u, frame.render_passes.size());
const QuadList& contrib_delegated_quad_list =
const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
ASSERT_EQ(5u, root_delegated_quad_list.size());
const SharedQuadState* root_delegated_shared_quad_state =
- root_delegated_quad_list[0]->shared_quad_state;
+ root_delegated_quad_list.front()->shared_quad_state;
// When the quads have a clip of their own, it is used.
EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
delegated_renderer_layer_->SetForceRenderSurface(true);
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
ASSERT_EQ(3u, frame.render_passes.size());
const QuadList& contrib_delegated_quad_list =
const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
ASSERT_EQ(5u, root_delegated_quad_list.size());
const SharedQuadState* root_delegated_shared_quad_state =
- root_delegated_quad_list[0]->shared_quad_state;
+ root_delegated_quad_list.front()->shared_quad_state;
// When the layer owns a surface, the quads don't need to be clipped
// further than they already specify. If they aren't clipped, then their
delegated_renderer_layer_->SetForceRenderSurface(true);
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
ASSERT_EQ(3u, frame.render_passes.size());
const QuadList& contrib_delegated_quad_list =
const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
ASSERT_EQ(5u, root_delegated_quad_list.size());
const SharedQuadState* root_delegated_shared_quad_state =
- root_delegated_quad_list[0]->shared_quad_state;
+ root_delegated_quad_list.front()->shared_quad_state;
// When the quads have a clip of their own, it is used, but it is
// combined with the clip rect of the delegated renderer layer. If the
delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
delegated_renderer_layer->SetDrawsContent(true);
- ScopedPtrVector<RenderPass> delegated_render_passes;
- TestRenderPass* pass1 = AddRenderPass(
- &delegated_render_passes,
- RenderPass::Id(9, 6),
- gfx::Rect(0, 0, 10, 10),
- gfx::Transform());
+ RenderPassList delegated_render_passes;
+ TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
+ RenderPassId(9, 6),
+ gfx::Rect(0, 0, 10, 10),
+ gfx::Transform());
AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
// This render pass isn't part of the frame.
scoped_ptr<TestRenderPass> missing_pass(TestRenderPass::Create());
- missing_pass->SetNew(RenderPass::Id(9, 7),
+ missing_pass->SetNew(RenderPassId(9, 7),
gfx::Rect(7, 7, 7, 7),
gfx::Rect(7, 7, 7, 7),
gfx::Transform());
AddRenderPassQuad(pass1, missing_pass.get());
delegated_renderer_layer->SetFrameDataForRenderPasses(
- &delegated_render_passes);
+ 1.f, &delegated_render_passes);
// The RenderPasses should be taken by the layer.
EXPECT_EQ(0u, delegated_render_passes.size());
host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
LayerTreeHostImpl::FrameData frame;
- EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS,
- host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// The DelegatedRendererLayerImpl should drop the bad RenderPassDrawQuad.
ASSERT_EQ(1u, frame.render_passes.size());
ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
EXPECT_EQ(DrawQuad::SOLID_COLOR,
- frame.render_passes[0]->quad_list[0]->material);
+ frame.render_passes[0]->quad_list.front()->material);
host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
host_impl_->DidDrawAllLayers(frame);
}
+TEST_F(DelegatedRendererLayerImplTest, Occlusion) {
+ gfx::Size layer_size(1000, 1000);
+ gfx::Size viewport_size(1000, 1000);
+ gfx::Rect quad_screen_rect(211, 300, 400, 500);
+
+ gfx::Transform transform;
+ transform.Translate(211.0, 300.0);
+
+ LayerTestCommon::LayerImplTest impl;
+
+ FakeDelegatedRendererLayerImpl* delegated_renderer_layer_impl =
+ impl.AddChildToRoot<FakeDelegatedRendererLayerImpl>();
+ delegated_renderer_layer_impl->SetBounds(layer_size);
+ delegated_renderer_layer_impl->SetContentBounds(layer_size);
+ delegated_renderer_layer_impl->SetDrawsContent(true);
+
+ // Contributing render pass is offset by a transform and holds a quad that
+ // covers it entirely.
+ RenderPassList delegated_render_passes;
+ // pass2 is just the size of the quad. It contributes to |pass1| with a
+ // translation of (211,300).
+ RenderPassId pass2_id =
+ delegated_renderer_layer_impl->FirstContributingRenderPassId();
+ TestRenderPass* pass2 = AddRenderPass(&delegated_render_passes,
+ pass2_id,
+ gfx::Rect(quad_screen_rect.size()),
+ transform);
+ AddQuad(pass2, gfx::Rect(quad_screen_rect.size()), SK_ColorRED);
+ // |pass1| covers the whole layer.
+ RenderPassId pass1_id = RenderPassId(impl.root_layer()->id(), 0);
+ TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
+ pass1_id,
+ gfx::Rect(layer_size),
+ gfx::Transform());
+ AddRenderPassQuad(pass1, pass2, 0, FilterOperations(), transform);
+ delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
+ 1.f, &delegated_render_passes);
+
+ impl.CalcDrawProps(viewport_size);
+
+ {
+ SCOPED_TRACE("No occlusion");
+ gfx::Rect occluded;
+
+ {
+ SCOPED_TRACE("Root render pass");
+ impl.AppendQuadsForPassWithOcclusion(
+ delegated_renderer_layer_impl, pass1_id, occluded);
+ LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
+ quad_screen_rect);
+ ASSERT_EQ(1u, impl.quad_list().size());
+ EXPECT_EQ(DrawQuad::RENDER_PASS, impl.quad_list().front()->material);
+ }
+ {
+ SCOPED_TRACE("Contributing render pass");
+ impl.AppendQuadsForPassWithOcclusion(
+ delegated_renderer_layer_impl, pass2_id, occluded);
+ LayerTestCommon::VerifyQuadsExactlyCoverRect(
+ impl.quad_list(), gfx::Rect(quad_screen_rect.size()));
+ ASSERT_EQ(1u, impl.quad_list().size());
+ EXPECT_EQ(DrawQuad::SOLID_COLOR, impl.quad_list().front()->material);
+ }
+ }
+
+ {
+ SCOPED_TRACE("Full occlusion");
+ {
+ gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect());
+
+ SCOPED_TRACE("Root render pass");
+ impl.AppendQuadsForPassWithOcclusion(
+ delegated_renderer_layer_impl, pass1_id, occluded);
+ LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
+ gfx::Rect());
+ EXPECT_EQ(impl.quad_list().size(), 0u);
+ }
+ {
+ gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect());
+
+ SCOPED_TRACE("Contributing render pass");
+ impl.AppendQuadsForPassWithOcclusion(
+ delegated_renderer_layer_impl, pass2_id, occluded);
+ LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
+ gfx::Rect());
+ EXPECT_EQ(impl.quad_list().size(), 0u);
+ }
+ }
+
+ {
+ SCOPED_TRACE("Partial occlusion");
+ {
+ gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
+
+ SCOPED_TRACE("Root render pass");
+ impl.AppendQuadsForPassWithOcclusion(
+ delegated_renderer_layer_impl, pass1_id, occlusion_in_root_target);
+ size_t partially_occluded_count = 0;
+ LayerTestCommon::VerifyQuadsAreOccluded(impl.quad_list(),
+ occlusion_in_root_target,
+ &partially_occluded_count);
+ // The layer outputs one quad, which is partially occluded.
+ EXPECT_EQ(1u, impl.quad_list().size());
+ EXPECT_EQ(1u, partially_occluded_count);
+ }
+ {
+ gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
+ // Move the occlusion to where it is in the contributing surface.
+ gfx::Rect occlusion_in_target_of_delegated_quad =
+ occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin();
+
+ SCOPED_TRACE("Contributing render pass");
+ impl.AppendQuadsForPassWithOcclusion(
+ delegated_renderer_layer_impl, pass2_id, occlusion_in_root_target);
+ size_t partially_occluded_count = 0;
+ LayerTestCommon::VerifyQuadsAreOccluded(
+ impl.quad_list(),
+ occlusion_in_target_of_delegated_quad,
+ &partially_occluded_count);
+ // The layer outputs one quad, which is partially occluded.
+ EXPECT_EQ(1u, impl.quad_list().size());
+ EXPECT_EQ(1u, partially_occluded_count);
+ // The quad in the contributing surface is at (211,300) in the root.
+ // The occlusion extends to 500 in the x-axis, pushing the left of the
+ // visible part of the quad to 500 - 211 = 300 - 11 inside the quad.
+ EXPECT_EQ(gfx::Rect(300 - 11, 0, 100 + 11, 500).ToString(),
+ impl.quad_list().front()->visible_rect.ToString());
+ }
+ {
+ gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
+ // Move the occlusion to where it is in the contributing surface.
+ gfx::Rect occlusion_in_target_of_delegated_quad =
+ occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin();
+
+ SCOPED_TRACE("Contributing render pass with transformed root");
+
+ gfx::Transform layer_transform;
+ layer_transform.Translate(11.0, 0.0);
+ delegated_renderer_layer_impl->SetTransform(layer_transform);
+
+ occlusion_in_target_of_delegated_quad += gfx::Vector2d(11, 0);
+
+ impl.CalcDrawProps(viewport_size);
+
+ impl.AppendQuadsForPassWithOcclusion(
+ delegated_renderer_layer_impl, pass2_id, occlusion_in_root_target);
+ size_t partially_occluded_count = 0;
+ LayerTestCommon::VerifyQuadsAreOccluded(
+ impl.quad_list(),
+ occlusion_in_target_of_delegated_quad,
+ &partially_occluded_count);
+ // The layer outputs one quad, which is partially occluded.
+ EXPECT_EQ(1u, impl.quad_list().size());
+ EXPECT_EQ(1u, partially_occluded_count);
+ // The quad in the contributing surface is at (222,300) in the transformed
+ // root. The occlusion extends to 500 in the x-axis, pushing the left of
+ // the visible part of the quad to 500 - 222 = 300 - 22 inside the quad.
+ EXPECT_EQ(gfx::Rect(300 - 22, 0, 100 + 22, 500).ToString(),
+ impl.quad_list().front()->visible_rect.ToString());
+ }
+ }
+}
+
+TEST_F(DelegatedRendererLayerImplTest, PushPropertiesTo) {
+ gfx::Size layer_size(1000, 1000);
+
+ scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer_impl =
+ FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 5);
+ delegated_renderer_layer_impl->SetBounds(layer_size);
+ delegated_renderer_layer_impl->SetContentBounds(layer_size);
+ delegated_renderer_layer_impl->SetDrawsContent(true);
+
+ RenderPassList delegated_render_passes;
+ // |pass1| covers the whole layer.
+ RenderPassId pass1_id = RenderPassId(5, 0);
+ AddRenderPass(&delegated_render_passes,
+ pass1_id,
+ gfx::Rect(layer_size),
+ gfx::Transform());
+ delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
+ 2.f, &delegated_render_passes);
+ EXPECT_EQ(0.5f, delegated_renderer_layer_impl->inverse_device_scale_factor());
+
+ scoped_ptr<DelegatedRendererLayerImpl> other_layer =
+ DelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 6);
+
+ delegated_renderer_layer_impl->PushPropertiesTo(other_layer.get());
+
+ EXPECT_EQ(0.5f, other_layer->inverse_device_scale_factor());
+}
+
} // namespace
} // namespace cc