summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorweiliangc@chromium.org <weiliangc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 14:54:02 +0000
committerweiliangc@chromium.org <weiliangc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 14:54:02 +0000
commitce4738ef468d259f614599dbfaee33662681f250 (patch)
tree0efa673335f073f382318c6a4bd330e71bcb00eb /cc
parentc5c89d0418fa2386b3b5da8232252ba4770dc06c (diff)
downloadchromium_src-ce4738ef468d259f614599dbfaee33662681f250.zip
chromium_src-ce4738ef468d259f614599dbfaee33662681f250.tar.gz
chromium_src-ce4738ef468d259f614599dbfaee33662681f250.tar.bz2
Create MockOcclusionTracker for testing
This CL is part of effort to replace QuadSink/QuadCuller with just RenderPass and OcclusionTracker since QuadSink provide no stand-alone functionality other than passing onto RP and OT. MockOcclusionTracker is created because current TestOT is still based a well constructed OT. For unittests, only minimum set up is provided and only minimun functionality is needed, in which case TestOT is overcomplicated. Next step would be let individual test create RP and OT, so MockQuadCuller only needs to take in pointers. After MockQuadCuller and QuadCuller can be collapsed, and eventually QuadSink removed. BUG=344962 TEST=cc_unittests Review URL: https://codereview.chromium.org/302603006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277017 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/cc_tests.gyp1
-rw-r--r--cc/test/mock_occlusion_tracker.h41
-rw-r--r--cc/test/mock_quad_culler.cc47
-rw-r--r--cc/test/mock_quad_culler.h15
-rw-r--r--cc/trees/occlusion_tracker.cc25
-rw-r--r--cc/trees/occlusion_tracker.h4
-rw-r--r--cc/trees/occlusion_tracker_perftest.cc12
-rw-r--r--cc/trees/occlusion_tracker_unittest.cc18
-rw-r--r--cc/trees/quad_culler.cc5
9 files changed, 95 insertions, 73 deletions
diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp
index 4e92c65..af16085 100644
--- a/cc/cc_tests.gyp
+++ b/cc/cc_tests.gyp
@@ -194,6 +194,7 @@
'test/layer_tree_pixel_test.h',
'test/layer_tree_test.cc',
'test/layer_tree_test.h',
+ 'test/mock_occlusion_tracker.h',
'test/mock_quad_culler.cc',
'test/mock_quad_culler.h',
'test/ordered_simple_task_runner.cc',
diff --git a/cc/test/mock_occlusion_tracker.h b/cc/test/mock_occlusion_tracker.h
new file mode 100644
index 0000000..69e2e5a
--- /dev/null
+++ b/cc/test/mock_occlusion_tracker.h
@@ -0,0 +1,41 @@
+// Copyright 2014 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_TEST_MOCK_OCCLUSION_TRACKER_H_
+#define CC_TEST_MOCK_OCCLUSION_TRACKER_H_
+
+#include "cc/trees/occlusion_tracker.h"
+
+namespace cc {
+
+template <typename LayerType>
+class MockOcclusionTracker : public OcclusionTracker<LayerType> {
+ // This class is used for testing only. It fakes just enough information to
+ // calculate unoccluded content rect and unoccluded contributing surface
+ // content rect. It calls the helper function of occlusion tracker to avoid
+ // DCHECKs since testing environment won't be set up properly to pass those.
+ public:
+ explicit MockOcclusionTracker(const gfx::Rect& screen_scissor_rect)
+ : OcclusionTracker<LayerType>(screen_scissor_rect) {
+ typename OcclusionTracker<LayerType>::StackObject stack_obj;
+ OcclusionTracker<LayerType>::stack_.push_back(stack_obj);
+ OcclusionTracker<LayerType>::stack_.push_back(stack_obj);
+ }
+
+ void set_occluded_target_rect(const gfx::Rect& occluded) {
+ OcclusionTracker<LayerType>::stack_.back().occlusion_from_inside_target =
+ occluded;
+ }
+
+ void set_occluded_target_rect_for_contributing_surface(
+ const gfx::Rect& occluded) {
+ OcclusionTracker<
+ LayerType>::stack_[OcclusionTracker<LayerType>::stack_.size() - 2]
+ .occlusion_from_inside_target = occluded;
+ }
+};
+
+} // namespace cc
+
+#endif // CC_TEST_MOCK_OCCLUSION_TRACKER_H_
diff --git a/cc/test/mock_quad_culler.cc b/cc/test/mock_quad_culler.cc
index ddb5913..71f1eb8 100644
--- a/cc/test/mock_quad_culler.cc
+++ b/cc/test/mock_quad_culler.cc
@@ -5,6 +5,7 @@
#include "cc/test/mock_quad_culler.h"
#include "cc/base/math_util.h"
+#include "cc/layers/layer_impl.h"
#include "cc/quads/draw_quad.h"
namespace cc {
@@ -12,10 +13,30 @@ namespace cc {
MockQuadCuller::MockQuadCuller() {
render_pass_storage_ = RenderPass::Create();
active_render_pass_ = render_pass_storage_.get();
+ occlusion_tracker_storage_ = make_scoped_ptr(
+ new MockOcclusionTracker<LayerImpl>(gfx::Rect(0, 0, 1000, 1000)));
+ occlusion_tracker_ = occlusion_tracker_storage_.get();
}
MockQuadCuller::MockQuadCuller(RenderPass* external_render_pass)
: active_render_pass_(external_render_pass) {
+ occlusion_tracker_storage_ = make_scoped_ptr(
+ new MockOcclusionTracker<LayerImpl>(gfx::Rect(0, 0, 1000, 1000)));
+ occlusion_tracker_ = occlusion_tracker_storage_.get();
+}
+
+MockQuadCuller::MockQuadCuller(
+ MockOcclusionTracker<LayerImpl>* occlusion_tracker)
+ : occlusion_tracker_(occlusion_tracker) {
+ render_pass_storage_ = RenderPass::Create();
+ active_render_pass_ = render_pass_storage_.get();
+}
+
+MockQuadCuller::MockQuadCuller(
+ RenderPass* external_render_pass,
+ MockOcclusionTracker<LayerImpl>* occlusion_tracker)
+ : active_render_pass_(external_render_pass),
+ occlusion_tracker_(occlusion_tracker) {
}
MockQuadCuller::~MockQuadCuller() {}
@@ -27,33 +48,15 @@ SharedQuadState* MockQuadCuller::CreateSharedQuadState() {
gfx::Rect MockQuadCuller::UnoccludedContentRect(
const gfx::Rect& content_rect,
const gfx::Transform& draw_transform) {
- DCHECK(draw_transform.IsIdentityOrIntegerTranslation() ||
- occluded_target_rect_.IsEmpty());
- gfx::Rect target_rect =
- MathUtil::MapEnclosingClippedRect(draw_transform, content_rect);
- target_rect.Subtract(occluded_target_rect_);
- gfx::Transform inverse_draw_transform(gfx::Transform::kSkipInitialization);
- if (!draw_transform.GetInverse(&inverse_draw_transform))
- NOTREACHED();
- gfx::Rect result = MathUtil::ProjectEnclosingClippedRect(
- inverse_draw_transform, target_rect);
- return result;
+ return occlusion_tracker_->UnoccludedContentRect(content_rect,
+ draw_transform);
}
gfx::Rect MockQuadCuller::UnoccludedContributingSurfaceContentRect(
const gfx::Rect& content_rect,
const gfx::Transform& draw_transform) {
- DCHECK(draw_transform.IsIdentityOrIntegerTranslation() ||
- occluded_target_rect_for_contributing_surface_.IsEmpty());
- gfx::Rect target_rect =
- MathUtil::MapEnclosingClippedRect(draw_transform, content_rect);
- target_rect.Subtract(occluded_target_rect_for_contributing_surface_);
- gfx::Transform inverse_draw_transform(gfx::Transform::kSkipInitialization);
- if (!draw_transform.GetInverse(&inverse_draw_transform))
- NOTREACHED();
- gfx::Rect result = MathUtil::ProjectEnclosingClippedRect(
- inverse_draw_transform, target_rect);
- return result;
+ return occlusion_tracker_->UnoccludedContributingSurfaceContentRect(
+ content_rect, draw_transform);
}
void MockQuadCuller::Append(scoped_ptr<DrawQuad> draw_quad) {
diff --git a/cc/test/mock_quad_culler.h b/cc/test/mock_quad_culler.h
index 195eb5b..3140c4e 100644
--- a/cc/test/mock_quad_culler.h
+++ b/cc/test/mock_quad_culler.h
@@ -9,15 +9,20 @@
#include "cc/layers/quad_sink.h"
#include "cc/quads/draw_quad.h"
#include "cc/quads/render_pass.h"
+#include "cc/test/mock_occlusion_tracker.h"
namespace cc {
+class LayerImpl;
class MockQuadCuller : public QuadSink {
public:
- MockQuadCuller();
virtual ~MockQuadCuller();
explicit MockQuadCuller(RenderPass* external_render_pass);
+ explicit MockQuadCuller(MockOcclusionTracker<LayerImpl>* occlusion_tracker);
+ MockQuadCuller(RenderPass* external_render_pass,
+ MockOcclusionTracker<LayerImpl>* occlusion_tracker);
+ MockQuadCuller();
// QuadSink interface.
virtual SharedQuadState* CreateSharedQuadState() OVERRIDE;
@@ -35,12 +40,13 @@ class MockQuadCuller : public QuadSink {
}
void set_occluded_target_rect(const gfx::Rect& occluded) {
- occluded_target_rect_ = occluded;
+ occlusion_tracker_->set_occluded_target_rect(occluded);
}
void set_occluded_target_rect_for_contributing_surface(
const gfx::Rect& occluded) {
- occluded_target_rect_for_contributing_surface_ = occluded;
+ occlusion_tracker_->set_occluded_target_rect_for_contributing_surface(
+ occluded);
}
void clear_lists() {
@@ -51,6 +57,9 @@ class MockQuadCuller : public QuadSink {
private:
scoped_ptr<RenderPass> render_pass_storage_;
RenderPass* active_render_pass_;
+ scoped_ptr<MockOcclusionTracker<LayerImpl> > occlusion_tracker_storage_;
+ MockOcclusionTracker<LayerImpl>* occlusion_tracker_;
+
gfx::Rect occluded_target_rect_;
gfx::Rect occluded_target_rect_for_contributing_surface_;
};
diff --git a/cc/trees/occlusion_tracker.cc b/cc/trees/occlusion_tracker.cc
index ceb2d14..b549f89 100644
--- a/cc/trees/occlusion_tracker.cc
+++ b/cc/trees/occlusion_tracker.cc
@@ -335,10 +335,9 @@ void OcclusionTracker<LayerType>::LeaveToRenderTarget(
gfx::Rect unoccluded_replica_rect;
if (old_target->background_filters().HasFilterThatMovesPixels()) {
unoccluded_surface_rect = UnoccludedContributingSurfaceContentRect(
- old_target, old_surface->content_rect(), old_surface->draw_transform());
+ old_surface->content_rect(), old_surface->draw_transform());
if (old_target->has_replica()) {
unoccluded_replica_rect = UnoccludedContributingSurfaceContentRect(
- old_target,
old_surface->content_rect(),
old_surface->replica_draw_transform());
}
@@ -543,23 +542,13 @@ bool OcclusionTracker<LayerType>::Occluded(
template <typename LayerType>
gfx::Rect OcclusionTracker<LayerType>::UnoccludedContentRect(
- const LayerType* render_target,
const gfx::Rect& content_rect,
const gfx::Transform& draw_transform) const {
- DCHECK(!stack_.empty());
if (stack_.empty())
return content_rect;
if (content_rect.IsEmpty())
return content_rect;
- // For tests with no render target.
- if (!render_target)
- return content_rect;
-
- DCHECK_EQ(render_target->render_target(), render_target);
- DCHECK(render_target->render_surface());
- DCHECK_EQ(render_target, stack_.back().target);
-
if (stack_.back().occlusion_from_inside_target.IsEmpty() &&
stack_.back().occlusion_from_outside_target.IsEmpty()) {
return content_rect;
@@ -589,20 +578,8 @@ gfx::Rect OcclusionTracker<LayerType>::UnoccludedContentRect(
template <typename LayerType>
gfx::Rect OcclusionTracker<LayerType>::UnoccludedContributingSurfaceContentRect(
- const LayerType* layer,
const gfx::Rect& content_rect,
const gfx::Transform& draw_transform) const {
- DCHECK(!stack_.empty());
- // The layer is a contributing render_target so it should have a surface.
- DCHECK(layer->render_surface());
- // The layer is a contributing render_target so its target should be itself.
- DCHECK_EQ(layer->render_target(), layer);
- // The layer should not be the root, else what is is contributing to?
- DCHECK(layer->parent());
- // This should be called while the layer is still considered the current
- // target in the occlusion tracker.
- DCHECK_EQ(layer, stack_.back().target);
-
if (content_rect.IsEmpty())
return content_rect;
diff --git a/cc/trees/occlusion_tracker.h b/cc/trees/occlusion_tracker.h
index e4567af..78b992c 100644
--- a/cc/trees/occlusion_tracker.h
+++ b/cc/trees/occlusion_tracker.h
@@ -53,15 +53,13 @@ class CC_EXPORT OcclusionTracker {
// layer. Used when considering occlusion for a layer that paints/draws
// something. |render_target| is the contributing layer's render target, and
// |draw_transform| and |impl_draw_transform_is_unknown| are relative to that.
- gfx::Rect UnoccludedContentRect(const LayerType* render_target,
- const gfx::Rect& content_rect,
+ gfx::Rect UnoccludedContentRect(const gfx::Rect& content_rect,
const gfx::Transform& draw_transform) const;
// Gives an unoccluded sub-rect of |content_rect| in the content space of the
// render_target owned by the layer. Used when considering occlusion for a
// contributing surface that is rendering into another target.
gfx::Rect UnoccludedContributingSurfaceContentRect(
- const LayerType* layer,
const gfx::Rect& content_rect,
const gfx::Transform& draw_transform) const;
diff --git a/cc/trees/occlusion_tracker_perftest.cc b/cc/trees/occlusion_tracker_perftest.cc
index 1506b2f..d913074 100644
--- a/cc/trees/occlusion_tracker_perftest.cc
+++ b/cc/trees/occlusion_tracker_perftest.cc
@@ -109,10 +109,8 @@ TEST_F(OcclusionTrackerPerfTest, UnoccludedContentRect_FullyOccluded) {
for (int x = 0; x < viewport_rect.width(); x += 256) {
for (int y = 0; y < viewport_rect.height(); y += 256) {
gfx::Rect query_content_rect(x, y, 256, 256);
- gfx::Rect unoccluded =
- tracker.UnoccludedContentRect(pos.target_render_surface_layer,
- query_content_rect,
- transform_to_target);
+ gfx::Rect unoccluded = tracker.UnoccludedContentRect(
+ query_content_rect, transform_to_target);
// Sanity test that we're not hitting early outs.
bool expect_empty =
query_content_rect.right() <= viewport_rect.width() &&
@@ -186,10 +184,8 @@ TEST_F(OcclusionTrackerPerfTest, UnoccludedContentRect_10OpaqueLayers) {
for (int x = 0; x < viewport_rect.width(); x += 256) {
for (int y = 0; y < viewport_rect.height(); y += 256) {
gfx::Rect query_content_rect(x, y, 256, 256);
- gfx::Rect unoccluded =
- tracker.UnoccludedContentRect(pos.target_render_surface_layer,
- query_content_rect,
- transform_to_target);
+ gfx::Rect unoccluded = tracker.UnoccludedContentRect(
+ query_content_rect, transform_to_target);
}
}
diff --git a/cc/trees/occlusion_tracker_unittest.cc b/cc/trees/occlusion_tracker_unittest.cc
index 6ce2781..89165b8 100644
--- a/cc/trees/occlusion_tracker_unittest.cc
+++ b/cc/trees/occlusion_tracker_unittest.cc
@@ -90,8 +90,7 @@ class TestOcclusionTrackerWithClip : public TestOcclusionTracker<LayerType> {
gfx::Rect UnoccludedLayerContentRect(const LayerType* layer,
const gfx::Rect& content_rect) const {
DCHECK(layer->visible_content_rect().Contains(content_rect));
- return this->UnoccludedContentRect(
- layer->render_target(), content_rect, layer->draw_transform());
+ return this->UnoccludedContentRect(content_rect, layer->draw_transform());
}
gfx::Rect UnoccludedSurfaceContentRect(const LayerType* layer,
@@ -101,8 +100,8 @@ class TestOcclusionTrackerWithClip : public TestOcclusionTracker<LayerType> {
gfx::Transform draw_transform = for_replica
? surface->replica_draw_transform()
: surface->draw_transform();
- return this->UnoccludedContributingSurfaceContentRect(
- layer, content_rect, draw_transform);
+ return this->UnoccludedContributingSurfaceContentRect(content_rect,
+ draw_transform);
}
};
@@ -611,15 +610,14 @@ class OcclusionTrackerTestQuadsMismatchLayer
gfx::Transform quad_transform;
quad_transform.Translate(30.0, 30.0);
- EXPECT_TRUE(occlusion.UnoccludedContentRect(parent,
- gfx::Rect(0, 0, 10, 10),
+ EXPECT_TRUE(occlusion.UnoccludedContentRect(gfx::Rect(0, 0, 10, 10),
quad_transform).IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(40, 40, 10, 10),
- occlusion.UnoccludedContentRect(
- parent, gfx::Rect(40, 40, 10, 10), quad_transform));
+ occlusion.UnoccludedContentRect(gfx::Rect(40, 40, 10, 10),
+ quad_transform));
EXPECT_RECT_EQ(gfx::Rect(40, 30, 5, 10),
- occlusion.UnoccludedContentRect(
- parent, gfx::Rect(35, 30, 10, 10), quad_transform));
+ occlusion.UnoccludedContentRect(gfx::Rect(35, 30, 10, 10),
+ quad_transform));
}
};
diff --git a/cc/trees/quad_culler.cc b/cc/trees/quad_culler.cc
index 419a3dd..db59fa5 100644
--- a/cc/trees/quad_culler.cc
+++ b/cc/trees/quad_culler.cc
@@ -33,15 +33,14 @@ SharedQuadState* QuadCuller::CreateSharedQuadState() {
gfx::Rect QuadCuller::UnoccludedContentRect(
const gfx::Rect& content_rect,
const gfx::Transform& draw_transform) {
- return occlusion_tracker_.UnoccludedContentRect(
- layer_->render_target(), content_rect, draw_transform);
+ return occlusion_tracker_.UnoccludedContentRect(content_rect, draw_transform);
}
gfx::Rect QuadCuller::UnoccludedContributingSurfaceContentRect(
const gfx::Rect& content_rect,
const gfx::Transform& draw_transform) {
return occlusion_tracker_.UnoccludedContributingSurfaceContentRect(
- layer_, content_rect, draw_transform);
+ content_rect, draw_transform);
}
void QuadCuller::Append(scoped_ptr<DrawQuad> draw_quad) {