summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-19 05:17:18 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-19 05:17:18 +0000
commit5f07afcd9dc529b87cfa860ba8cbb526af214dec (patch)
tree5ae9ed998300679338518998b64b8972ab951350 /cc
parentd12ffd8adf17f6442ed60900d14eaa84d0b4f027 (diff)
downloadchromium_src-5f07afcd9dc529b87cfa860ba8cbb526af214dec.zip
chromium_src-5f07afcd9dc529b87cfa860ba8cbb526af214dec.tar.gz
chromium_src-5f07afcd9dc529b87cfa860ba8cbb526af214dec.tar.bz2
Adds a new callback as this signal is required to pass up to the application
independent of whether the compositor is generating frames BUG=232944 Review URL: https://chromiumcodereview.appspot.com/16958012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212526 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/output/output_surface_client.h7
-rw-r--r--cc/test/fake_output_surface.cc18
-rw-r--r--cc/test/fake_output_surface.h6
-rw-r--r--cc/test/fake_output_surface_client.h1
-rw-r--r--cc/test/layer_tree_test.h1
-rw-r--r--cc/test/pixel_test.cc1
-rw-r--r--cc/trees/layer_tree_host_impl.cc9
-rw-r--r--cc/trees/layer_tree_host_impl.h5
-rw-r--r--cc/trees/layer_tree_host_unittest.cc69
9 files changed, 117 insertions, 0 deletions
diff --git a/cc/output/output_surface_client.h b/cc/output/output_surface_client.h
index 516f075..e6f296b 100644
--- a/cc/output/output_surface_client.h
+++ b/cc/output/output_surface_client.h
@@ -5,6 +5,7 @@
#ifndef CC_OUTPUT_OUTPUT_SURFACE_CLIENT_H_
#define CC_OUTPUT_OUTPUT_SURFACE_CLIENT_H_
+#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "cc/base/cc_export.h"
@@ -37,6 +38,12 @@ class CC_EXPORT OutputSurfaceClient {
gfx::Rect viewport) = 0;
virtual void SetMemoryPolicy(const ManagedMemoryPolicy& policy,
bool discard_backbuffer_when_not_visible) = 0;
+ // If set, |callback| will be called subsequent to each new tree activation,
+ // regardless of the compositor visibility or damage. |callback| must remain
+ // valid for the lifetime of the OutputSurfaceClient or until unregisted --
+ // use SetTreeActivationCallback(base::Closure()) to unregister it.
+ virtual void SetTreeActivationCallback(const base::Closure& callback) = 0;
+
protected:
virtual ~OutputSurfaceClient() {}
diff --git a/cc/test/fake_output_surface.cc b/cc/test/fake_output_surface.cc
index 6694b06..09af44c 100644
--- a/cc/test/fake_output_surface.cc
+++ b/cc/test/fake_output_surface.cc
@@ -16,6 +16,7 @@ FakeOutputSurface::FakeOutputSurface(
scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
bool delegated_rendering)
: OutputSurface(context3d.Pass()),
+ client_(NULL),
num_sent_frames_(0),
needs_begin_frame_(false),
forced_draw_to_software_device_(false),
@@ -29,6 +30,7 @@ FakeOutputSurface::FakeOutputSurface(
FakeOutputSurface::FakeOutputSurface(
scoped_ptr<SoftwareOutputDevice> software_device, bool delegated_rendering)
: OutputSurface(software_device.Pass()),
+ client_(NULL),
num_sent_frames_(0),
forced_draw_to_software_device_(false),
fake_weak_ptr_factory_(this) {
@@ -43,6 +45,7 @@ FakeOutputSurface::FakeOutputSurface(
scoped_ptr<SoftwareOutputDevice> software_device,
bool delegated_rendering)
: OutputSurface(context3d.Pass(), software_device.Pass()),
+ client_(NULL),
num_sent_frames_(0),
forced_draw_to_software_device_(false),
fake_weak_ptr_factory_(this) {
@@ -91,6 +94,15 @@ bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const {
return forced_draw_to_software_device_;
}
+bool FakeOutputSurface::BindToClient(OutputSurfaceClient* client) {
+ if (OutputSurface::BindToClient(client)) {
+ client_ = client;
+ return true;
+ } else {
+ return false;
+ }
+}
+
bool FakeOutputSurface::SetAndInitializeContext3D(
scoped_ptr<WebKit::WebGraphicsContext3D> context3d) {
context3d_.reset();
@@ -98,4 +110,10 @@ bool FakeOutputSurface::SetAndInitializeContext3D(
scoped_refptr<ContextProvider>());
}
+void FakeOutputSurface::SetTreeActivationCallback(
+ const base::Closure& callback) {
+ DCHECK(client_);
+ client_->SetTreeActivationCallback(callback);
+}
+
} // namespace cc
diff --git a/cc/test/fake_output_surface.h b/cc/test/fake_output_surface.h
index ad81d84..18759ec 100644
--- a/cc/test/fake_output_surface.h
+++ b/cc/test/fake_output_surface.h
@@ -5,6 +5,7 @@
#ifndef CC_TEST_FAKE_OUTPUT_SURFACE_H_
#define CC_TEST_FAKE_OUTPUT_SURFACE_H_
+#include "base/callback.h"
#include "base/time/time.h"
#include "cc/output/begin_frame_args.h"
#include "cc/output/compositor_frame.h"
@@ -78,11 +79,15 @@ class FakeOutputSurface : public OutputSurface {
}
virtual bool ForcedDrawToSoftwareDevice() const OVERRIDE;
+ virtual bool BindToClient(OutputSurfaceClient* client) OVERRIDE;
+
bool SetAndInitializeContext3D(
scoped_ptr<WebKit::WebGraphicsContext3D> context3d);
using OutputSurface::ReleaseGL;
+ void SetTreeActivationCallback(const base::Closure& callback);
+
protected:
FakeOutputSurface(
scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
@@ -99,6 +104,7 @@ class FakeOutputSurface : public OutputSurface {
void OnBeginFrame();
+ OutputSurfaceClient* client_;
CompositorFrame last_sent_frame_;
size_t num_sent_frames_;
bool needs_begin_frame_;
diff --git a/cc/test/fake_output_surface_client.h b/cc/test/fake_output_surface_client.h
index b948958..830dcad 100644
--- a/cc/test/fake_output_surface_client.h
+++ b/cc/test/fake_output_surface_client.h
@@ -32,6 +32,7 @@ class FakeOutputSurfaceClient : public OutputSurfaceClient {
virtual void SetMemoryPolicy(
const ManagedMemoryPolicy& policy,
bool discard_backbuffer_when_not_visible) OVERRIDE;
+ virtual void SetTreeActivationCallback(const base::Closure&) OVERRIDE {}
int begin_frame_count() {
return begin_frame_count_;
diff --git a/cc/test/layer_tree_test.h b/cc/test/layer_tree_test.h
index 4e4f951..556378b 100644
--- a/cc/test/layer_tree_test.h
+++ b/cc/test/layer_tree_test.h
@@ -151,6 +151,7 @@ class LayerTreeTest : public testing::Test, public TestHooks {
LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); }
bool delegating_renderer() const { return delegating_renderer_; }
+ FakeOutputSurface* output_surface() { return output_surface_; }
virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE;
virtual scoped_refptr<cc::ContextProvider>
diff --git a/cc/test/pixel_test.cc b/cc/test/pixel_test.cc
index ae4e102..23a1a4f 100644
--- a/cc/test/pixel_test.cc
+++ b/cc/test/pixel_test.cc
@@ -67,6 +67,7 @@ class PixelTest::PixelTestRendererClient
}
virtual void SetMemoryPolicy(
const ManagedMemoryPolicy& policy, bool discard) OVERRIDE {}
+ virtual void SetTreeActivationCallback(const base::Closure&) OVERRIDE {}
private:
gfx::Rect device_viewport_;
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index f88cf8a..459ec40 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -1064,6 +1064,13 @@ void LayerTreeHostImpl::SetMemoryPolicy(
discard_backbuffer_when_not_visible);
}
+void LayerTreeHostImpl::SetTreeActivationCallback(
+ const base::Closure& callback) {
+ DCHECK(proxy_->IsImplThread());
+ DCHECK(settings_.impl_side_painting || callback.is_null());
+ tree_activiation_callback_ = callback;
+}
+
void LayerTreeHostImpl::SetManagedMemoryPolicy(
const ManagedMemoryPolicy& policy) {
if (managed_memory_policy_ == policy)
@@ -1440,6 +1447,8 @@ void LayerTreeHostImpl::ActivatePendingTree() {
}
client_->DidActivatePendingTree();
+ if (!tree_activiation_callback_.is_null())
+ tree_activiation_callback_.Run();
}
void LayerTreeHostImpl::SetVisible(bool visible) {
diff --git a/cc/trees/layer_tree_host_impl.h b/cc/trees/layer_tree_host_impl.h
index e1b2694..0db6cb7 100644
--- a/cc/trees/layer_tree_host_impl.h
+++ b/cc/trees/layer_tree_host_impl.h
@@ -207,6 +207,8 @@ class CC_EXPORT LayerTreeHostImpl
virtual void SetMemoryPolicy(
const ManagedMemoryPolicy& policy,
bool discard_backbuffer_when_not_visible) OVERRIDE;
+ virtual void SetTreeActivationCallback(const base::Closure& callback)
+ OVERRIDE;
// Called from LayerTreeImpl.
void OnCanDrawStateChangedForTree();
@@ -533,6 +535,9 @@ class CC_EXPORT LayerTreeHostImpl
bool need_check_for_completed_tile_uploads_before_draw_;
+ // Optional callback to notify of new tree activations.
+ base::Closure tree_activiation_callback_;
+
DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
};
diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc
index b341f92..3dbce1b 100644
--- a/cc/trees/layer_tree_host_unittest.cc
+++ b/cc/trees/layer_tree_host_unittest.cc
@@ -3817,5 +3817,74 @@ class LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent
MULTI_THREAD_TEST_F(
LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent);
+// This test verifies that the tree activation callback is invoked correctly.
+class LayerTreeHostTestTreeActivationCallback : public LayerTreeHostTest {
+ public:
+ LayerTreeHostTestTreeActivationCallback()
+ : num_commits_(0), callback_count_(0) {}
+
+ virtual void BeginTest() OVERRIDE {
+ EXPECT_TRUE(HasImplThread());
+ PostSetNeedsCommitToMainThread();
+ }
+
+ virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
+ LayerTreeHostImpl::FrameData* frame_data,
+ bool result) OVERRIDE {
+ ++num_commits_;
+ switch (num_commits_) {
+ case 1:
+ EXPECT_EQ(0, callback_count_);
+ callback_count_ = 0;
+ SetCallback(true);
+ PostSetNeedsCommitToMainThread();
+ break;
+ case 2:
+ EXPECT_EQ(1, callback_count_);
+ callback_count_ = 0;
+ SetCallback(false);
+ PostSetNeedsCommitToMainThread();
+ break;
+ case 3:
+ EXPECT_EQ(0, callback_count_);
+ callback_count_ = 0;
+ EndTest();
+ break;
+ default:
+ ADD_FAILURE() << num_commits_;
+ EndTest();
+ break;
+ }
+ return LayerTreeHostTest::PrepareToDrawOnThread(host_impl, frame_data,
+ result);
+ }
+
+ virtual void AfterTest() OVERRIDE {
+ EXPECT_EQ(3, num_commits_);
+ }
+
+ void SetCallback(bool enable) {
+ output_surface()->SetTreeActivationCallback(enable ?
+ base::Bind(&LayerTreeHostTestTreeActivationCallback::ActivationCallback,
+ base::Unretained(this)) :
+ base::Closure());
+ }
+
+ void ActivationCallback() {
+ ++callback_count_;
+ }
+
+ int num_commits_;
+ int callback_count_;
+};
+
+TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) {
+ RunTest(true, false, true);
+}
+
+TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) {
+ RunTest(true, true, true);
+}
+
} // namespace
} // namespace cc