Index: cc/output/output_surface_unittest.cc |
diff --git a/cc/output/output_surface_unittest.cc b/cc/output/output_surface_unittest.cc |
index 4f9e370e1f05d86070520ea9e809acd5ee706df2..42cbc14eb85d97873bc77f2feff9dc851a4747b1 100644 |
--- a/cc/output/output_surface_unittest.cc |
+++ b/cc/output/output_surface_unittest.cc |
@@ -5,6 +5,7 @@ |
#include "cc/output/output_surface.h" |
#include "base/test/test_simple_task_runner.h" |
+#include "cc/debug/test_context_provider.h" |
#include "cc/debug/test_web_graphics_context_3d.h" |
#include "cc/output/managed_memory_policy.h" |
#include "cc/output/output_surface_client.h" |
@@ -14,38 +15,31 @@ |
#include "cc/test/scheduler_test_common.h" |
#include "gpu/GLES2/gl2extchromium.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-#include "third_party/WebKit/public/platform/WebGraphicsMemoryAllocation.h" |
- |
-using WebKit::WebGraphicsMemoryAllocation; |
namespace cc { |
namespace { |
class TestOutputSurface : public OutputSurface { |
public: |
- explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d) |
- : OutputSurface(context3d.Pass()) {} |
+ explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider) |
+ : OutputSurface(context_provider) {} |
explicit TestOutputSurface( |
scoped_ptr<cc::SoftwareOutputDevice> software_device) |
: OutputSurface(software_device.Pass()) {} |
- TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
+ TestOutputSurface(scoped_refptr<ContextProvider> context_provider, |
scoped_ptr<cc::SoftwareOutputDevice> software_device) |
- : OutputSurface(context3d.Pass(), software_device.Pass()) {} |
+ : OutputSurface(context_provider, software_device.Pass()) {} |
- bool InitializeNewContext3D( |
- scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) { |
- return InitializeAndSetContext3D(new_context3d.Pass(), |
+ bool InitializeNewContext3d( |
+ scoped_refptr<ContextProvider> new_context_provider) { |
+ return InitializeAndSetContext3d(new_context_provider, |
scoped_refptr<ContextProvider>()); |
} |
using OutputSurface::ReleaseGL; |
- bool HasClientForTesting() { |
- return HasClient(); |
- } |
- |
void OnVSyncParametersChangedForTesting(base::TimeTicks timebase, |
base::TimeDelta interval) { |
OnVSyncParametersChanged(timebase, interval); |
@@ -85,108 +79,98 @@ class TestOutputSurface : public OutputSurface { |
}; |
TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { |
- scoped_ptr<TestWebGraphicsContext3D> context3d = |
- TestWebGraphicsContext3D::Create(); |
- |
- TestOutputSurface output_surface( |
- context3d.PassAs<WebKit::WebGraphicsContext3D>()); |
- EXPECT_FALSE(output_surface.HasClientForTesting()); |
+ TestOutputSurface output_surface(TestContextProvider::Create()); |
+ EXPECT_FALSE(output_surface.HasClient()); |
FakeOutputSurfaceClient client; |
EXPECT_TRUE(output_surface.BindToClient(&client)); |
- EXPECT_TRUE(output_surface.HasClientForTesting()); |
+ EXPECT_TRUE(output_surface.HasClient()); |
EXPECT_FALSE(client.deferred_initialize_called()); |
// Verify DidLoseOutputSurface callback is hooked up correctly. |
EXPECT_FALSE(client.did_lose_output_surface_called()); |
- output_surface.context3d()->loseContextCHROMIUM( |
+ output_surface.context_provider()->Context3d()->loseContextCHROMIUM( |
GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
EXPECT_TRUE(client.did_lose_output_surface_called()); |
} |
TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) { |
- scoped_ptr<TestWebGraphicsContext3D> context3d = |
- TestWebGraphicsContext3D::Create(); |
+ scoped_refptr<TestContextProvider> context_provider = |
+ TestContextProvider::Create(); |
// Lose the context so BindToClient fails. |
- context3d->set_times_make_current_succeeds(0); |
+ context_provider->TestContext3d()->set_times_make_current_succeeds(0); |
- TestOutputSurface output_surface( |
- context3d.PassAs<WebKit::WebGraphicsContext3D>()); |
- EXPECT_FALSE(output_surface.HasClientForTesting()); |
+ TestOutputSurface output_surface(context_provider); |
+ EXPECT_FALSE(output_surface.HasClient()); |
FakeOutputSurfaceClient client; |
EXPECT_FALSE(output_surface.BindToClient(&client)); |
- EXPECT_FALSE(output_surface.HasClientForTesting()); |
+ EXPECT_FALSE(output_surface.HasClient()); |
} |
-class InitializeNewContext3D : public ::testing::Test { |
+class OutputSurfaceTestInitializeNewContext3d : public ::testing::Test { |
public: |
- InitializeNewContext3D() |
- : context3d_(TestWebGraphicsContext3D::Create()), |
+ OutputSurfaceTestInitializeNewContext3d() |
+ : context_provider_(TestContextProvider::Create()), |
output_surface_( |
scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)) {} |
protected: |
void BindOutputSurface() { |
EXPECT_TRUE(output_surface_.BindToClient(&client_)); |
- EXPECT_TRUE(output_surface_.HasClientForTesting()); |
+ EXPECT_TRUE(output_surface_.HasClient()); |
} |
void InitializeNewContextExpectFail() { |
- EXPECT_FALSE(output_surface_.InitializeNewContext3D( |
- context3d_.PassAs<WebKit::WebGraphicsContext3D>())); |
- EXPECT_TRUE(output_surface_.HasClientForTesting()); |
+ EXPECT_FALSE(output_surface_.InitializeNewContext3d(context_provider_)); |
+ EXPECT_TRUE(output_surface_.HasClient()); |
- EXPECT_FALSE(output_surface_.context3d()); |
+ EXPECT_FALSE(output_surface_.context_provider()); |
EXPECT_TRUE(output_surface_.software_device()); |
} |
- scoped_ptr<TestWebGraphicsContext3D> context3d_; |
+ scoped_refptr<TestContextProvider> context_provider_; |
TestOutputSurface output_surface_; |
FakeOutputSurfaceClient client_; |
}; |
-TEST_F(InitializeNewContext3D, Success) { |
+TEST_F(OutputSurfaceTestInitializeNewContext3d, Success) { |
BindOutputSurface(); |
EXPECT_FALSE(client_.deferred_initialize_called()); |
- EXPECT_TRUE(output_surface_.InitializeNewContext3D( |
- context3d_.PassAs<WebKit::WebGraphicsContext3D>())); |
+ EXPECT_TRUE(output_surface_.InitializeNewContext3d(context_provider_)); |
EXPECT_TRUE(client_.deferred_initialize_called()); |
+ EXPECT_EQ(context_provider_, output_surface_.context_provider()); |
EXPECT_FALSE(client_.did_lose_output_surface_called()); |
- output_surface_.context3d()->loseContextCHROMIUM( |
+ context_provider_->Context3d()->loseContextCHROMIUM( |
GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
EXPECT_TRUE(client_.did_lose_output_surface_called()); |
output_surface_.ReleaseGL(); |
- EXPECT_FALSE(output_surface_.context3d()); |
+ EXPECT_FALSE(output_surface_.context_provider()); |
} |
-TEST_F(InitializeNewContext3D, Context3dMakeCurrentFails) { |
+TEST_F(OutputSurfaceTestInitializeNewContext3d, Context3dMakeCurrentFails) { |
BindOutputSurface(); |
- context3d_->set_times_make_current_succeeds(0); |
+ context_provider_->TestContext3d()->set_times_make_current_succeeds(0); |
InitializeNewContextExpectFail(); |
} |
-TEST_F(InitializeNewContext3D, ClientDeferredInitializeFails) { |
+TEST_F(OutputSurfaceTestInitializeNewContext3d, ClientDeferredInitializeFails) { |
BindOutputSurface(); |
client_.set_deferred_initialize_result(false); |
InitializeNewContextExpectFail(); |
} |
TEST(OutputSurfaceTest, BeginFrameEmulation) { |
- scoped_ptr<TestWebGraphicsContext3D> context3d = |
- TestWebGraphicsContext3D::Create(); |
- |
- TestOutputSurface output_surface( |
- context3d.PassAs<WebKit::WebGraphicsContext3D>()); |
- EXPECT_FALSE(output_surface.HasClientForTesting()); |
+ TestOutputSurface output_surface(TestContextProvider::Create()); |
+ EXPECT_FALSE(output_surface.HasClient()); |
FakeOutputSurfaceClient client; |
EXPECT_TRUE(output_surface.BindToClient(&client)); |
- EXPECT_TRUE(output_surface.HasClientForTesting()); |
+ EXPECT_TRUE(output_surface.HasClient()); |
EXPECT_FALSE(client.deferred_initialize_called()); |
// Initialize BeginFrame emulation |
@@ -264,16 +248,12 @@ TEST(OutputSurfaceTest, BeginFrameEmulation) { |
} |
TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { |
- scoped_ptr<TestWebGraphicsContext3D> context3d = |
- TestWebGraphicsContext3D::Create(); |
- |
- TestOutputSurface output_surface( |
- context3d.PassAs<WebKit::WebGraphicsContext3D>()); |
- EXPECT_FALSE(output_surface.HasClientForTesting()); |
+ TestOutputSurface output_surface(TestContextProvider::Create()); |
+ EXPECT_FALSE(output_surface.HasClient()); |
FakeOutputSurfaceClient client; |
EXPECT_TRUE(output_surface.BindToClient(&client)); |
- EXPECT_TRUE(output_surface.HasClientForTesting()); |
+ EXPECT_TRUE(output_surface.HasClient()); |
EXPECT_FALSE(client.deferred_initialize_called()); |
output_surface.SetMaxFramesPending(2); |
@@ -318,16 +298,15 @@ TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { |
} |
TEST(OutputSurfaceTest, RetroactiveBeginFrameDoesNotDoubleTickWhenEmulating) { |
- scoped_ptr<TestWebGraphicsContext3D> context3d = |
- TestWebGraphicsContext3D::Create(); |
+ scoped_refptr<TestContextProvider> context_provider = |
+ TestContextProvider::Create(); |
- TestOutputSurface output_surface( |
- context3d.PassAs<WebKit::WebGraphicsContext3D>()); |
- EXPECT_FALSE(output_surface.HasClientForTesting()); |
+ TestOutputSurface output_surface(context_provider); |
+ EXPECT_FALSE(output_surface.HasClient()); |
FakeOutputSurfaceClient client; |
EXPECT_TRUE(output_surface.BindToClient(&client)); |
- EXPECT_TRUE(output_surface.HasClientForTesting()); |
+ EXPECT_TRUE(output_surface.HasClient()); |
EXPECT_FALSE(client.deferred_initialize_called()); |
base::TimeDelta big_interval = base::TimeDelta::FromSeconds(1000); |
@@ -375,27 +354,26 @@ TEST(OutputSurfaceTest, RetroactiveBeginFrameDoesNotDoubleTickWhenEmulating) { |
} |
TEST(OutputSurfaceTest, MemoryAllocation) { |
- scoped_ptr<TestWebGraphicsContext3D> scoped_context = |
- TestWebGraphicsContext3D::Create(); |
- TestWebGraphicsContext3D* context = scoped_context.get(); |
+ scoped_refptr<TestContextProvider> context_provider = |
+ TestContextProvider::Create(); |
- TestOutputSurface output_surface( |
- scoped_context.PassAs<WebKit::WebGraphicsContext3D>()); |
+ TestOutputSurface output_surface(context_provider); |
FakeOutputSurfaceClient client; |
EXPECT_TRUE(output_surface.BindToClient(&client)); |
- WebGraphicsMemoryAllocation allocation; |
- allocation.suggestHaveBackbuffer = true; |
- allocation.bytesLimitWhenVisible = 1234; |
- allocation.priorityCutoffWhenVisible = |
- WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleOnly; |
- allocation.bytesLimitWhenNotVisible = 4567; |
- allocation.priorityCutoffWhenNotVisible = |
- WebGraphicsMemoryAllocation::PriorityCutoffAllowNothing; |
+ ManagedMemoryPolicy policy(0); |
+ policy.bytes_limit_when_visible = 1234; |
+ policy.priority_cutoff_when_visible = |
+ ManagedMemoryPolicy::CUTOFF_ALLOW_REQUIRED_ONLY; |
+ policy.bytes_limit_when_not_visible = 4567; |
+ policy.priority_cutoff_when_not_visible = |
+ ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING; |
- context->SetMemoryAllocation(allocation); |
+ bool discard_backbuffer_when_not_visible = false; |
+ context_provider->SetMemoryAllocation(policy, |
+ discard_backbuffer_when_not_visible); |
EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); |
EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_REQUIRED_ONLY, |
client.memory_policy().priority_cutoff_when_visible); |
@@ -404,23 +382,26 @@ TEST(OutputSurfaceTest, MemoryAllocation) { |
client.memory_policy().priority_cutoff_when_not_visible); |
EXPECT_FALSE(client.discard_backbuffer_when_not_visible()); |
- allocation.suggestHaveBackbuffer = false; |
- context->SetMemoryAllocation(allocation); |
+ discard_backbuffer_when_not_visible = true; |
+ context_provider->SetMemoryAllocation(policy, |
+ discard_backbuffer_when_not_visible); |
EXPECT_TRUE(client.discard_backbuffer_when_not_visible()); |
- allocation.priorityCutoffWhenVisible = |
- WebGraphicsMemoryAllocation::PriorityCutoffAllowEverything; |
- allocation.priorityCutoffWhenNotVisible = |
- WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearby; |
- context->SetMemoryAllocation(allocation); |
+ policy.priority_cutoff_when_visible = |
+ ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING; |
+ policy.priority_cutoff_when_not_visible = |
+ ManagedMemoryPolicy::CUTOFF_ALLOW_NICE_TO_HAVE; |
+ context_provider->SetMemoryAllocation(policy, |
+ discard_backbuffer_when_not_visible); |
EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING, |
client.memory_policy().priority_cutoff_when_visible); |
EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_NICE_TO_HAVE, |
client.memory_policy().priority_cutoff_when_not_visible); |
// 0 bytes limit should be ignored. |
- allocation.bytesLimitWhenVisible = 0; |
- context->SetMemoryAllocation(allocation); |
+ policy.bytes_limit_when_visible = 0; |
+ context_provider->SetMemoryAllocation(policy, |
+ discard_backbuffer_when_not_visible); |
EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); |
} |