1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/test/mock_quad_culler.h"
7 #include "cc/base/math_util.h"
8 #include "cc/quads/draw_quad.h"
12 MockQuadCuller::MockQuadCuller() {
13 render_pass_storage_
= RenderPass::Create();
14 active_render_pass_
= render_pass_storage_
.get();
17 MockQuadCuller::MockQuadCuller(RenderPass
* external_render_pass
)
18 : active_render_pass_(external_render_pass
) {
21 MockQuadCuller::~MockQuadCuller() {}
23 SharedQuadState
* MockQuadCuller::CreateSharedQuadState() {
24 return active_render_pass_
->CreateAndAppendSharedQuadState();
27 gfx::Rect
MockQuadCuller::UnoccludedContentRect(
28 const gfx::Rect
& content_rect
,
29 const gfx::Transform
& draw_transform
) {
30 DCHECK(draw_transform
.IsIdentityOrIntegerTranslation() ||
31 occluded_target_rect_
.IsEmpty());
32 gfx::Rect target_rect
=
33 MathUtil::MapEnclosingClippedRect(draw_transform
, content_rect
);
34 target_rect
.Subtract(occluded_target_rect_
);
35 gfx::Transform
inverse_draw_transform(gfx::Transform::kSkipInitialization
);
36 if (!draw_transform
.GetInverse(&inverse_draw_transform
))
38 gfx::Rect result
= MathUtil::ProjectEnclosingClippedRect(
39 inverse_draw_transform
, target_rect
);
43 gfx::Rect
MockQuadCuller::UnoccludedContributingSurfaceContentRect(
44 const gfx::Rect
& content_rect
,
45 const gfx::Transform
& draw_transform
) {
46 DCHECK(draw_transform
.IsIdentityOrIntegerTranslation() ||
47 occluded_target_rect_for_contributing_surface_
.IsEmpty());
48 gfx::Rect target_rect
=
49 MathUtil::MapEnclosingClippedRect(draw_transform
, content_rect
);
50 target_rect
.Subtract(occluded_target_rect_for_contributing_surface_
);
51 gfx::Transform
inverse_draw_transform(gfx::Transform::kSkipInitialization
);
52 if (!draw_transform
.GetInverse(&inverse_draw_transform
))
54 gfx::Rect result
= MathUtil::ProjectEnclosingClippedRect(
55 inverse_draw_transform
, target_rect
);
59 void MockQuadCuller::Append(scoped_ptr
<DrawQuad
> draw_quad
) {
60 DCHECK(!draw_quad
->rect
.IsEmpty());
61 DCHECK(!draw_quad
->visible_rect
.IsEmpty());
62 active_render_pass_
->quad_list
.push_back(draw_quad
.Pass());