| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/ipc/service/direct_composition_surface_win.h" | 5 #include "gpu/ipc/service/direct_composition_surface_win.h" |
| 6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/synchronization/waitable_event.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/base/win/hidden_window.h" | 10 #include "ui/base/win/hidden_window.h" |
| 10 #include "ui/gl/gl_angle_util_win.h" | 11 #include "ui/gl/gl_angle_util_win.h" |
| 11 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
| 12 #include "ui/gl/init/gl_factory.h" | 13 #include "ui/gl/init/gl_factory.h" |
| 13 | 14 |
| 14 namespace gpu { | 15 namespace gpu { |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 class TestImageTransportSurfaceDelegate | 18 class TestImageTransportSurfaceDelegate |
| 18 : public ImageTransportSurfaceDelegate, | 19 : public ImageTransportSurfaceDelegate, |
| 19 public base::SupportsWeakPtr<TestImageTransportSurfaceDelegate> { | 20 public base::SupportsWeakPtr<TestImageTransportSurfaceDelegate> { |
| 20 public: | 21 public: |
| 21 ~TestImageTransportSurfaceDelegate() override {} | 22 ~TestImageTransportSurfaceDelegate() override {} |
| 22 | 23 |
| 23 // ImageTransportSurfaceDelegate implementation. | 24 // ImageTransportSurfaceDelegate implementation. |
| 24 void DidCreateAcceleratedSurfaceChildWindow( | 25 void DidCreateAcceleratedSurfaceChildWindow( |
| 25 SurfaceHandle parent_window, | 26 SurfaceHandle parent_window, |
| 26 SurfaceHandle child_window) override {} | 27 SurfaceHandle child_window) override {} |
| 27 void DidSwapBuffersComplete(SwapBuffersCompleteParams params) override {} | 28 void DidSwapBuffersComplete(SwapBuffersCompleteParams params) override {} |
| 28 const gles2::FeatureInfo* GetFeatureInfo() const override { return nullptr; } | 29 const gles2::FeatureInfo* GetFeatureInfo() const override { return nullptr; } |
| 29 void SetLatencyInfoCallback(const LatencyInfoCallback& callback) override {} | 30 void SetLatencyInfoCallback(const LatencyInfoCallback& callback) override {} |
| 30 void UpdateVSyncParameters(base::TimeTicks timebase, | 31 void UpdateVSyncParameters(base::TimeTicks timebase, |
| 31 base::TimeDelta interval) override {} | 32 base::TimeDelta interval) override {} |
| 32 void AddFilter(IPC::MessageFilter* message_filter) override {} | 33 void AddFilter(IPC::MessageFilter* message_filter) override {} |
| 33 int32_t GetRouteID() const override { return 0; } | 34 int32_t GetRouteID() const override { return 0; } |
| 34 }; | 35 }; |
| 35 | 36 |
| 37 void RunPendingTasks(scoped_refptr<base::TaskRunner> task_runner) { |
| 38 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 39 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 40 task_runner->PostTask(FROM_HERE, |
| 41 Bind(&base::WaitableEvent::Signal, Unretained(&done))); |
| 42 done.Wait(); |
| 43 } |
| 44 |
| 36 TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { | 45 TEST(DirectCompositionSurfaceTest, TestMakeCurrent) { |
| 37 if (!gl::QueryDirectCompositionDevice( | 46 if (!gl::QueryDirectCompositionDevice( |
| 38 gl::QueryD3D11DeviceObjectFromANGLE())) { | 47 gl::QueryD3D11DeviceObjectFromANGLE())) { |
| 39 LOG(WARNING) | 48 LOG(WARNING) |
| 40 << "GL implementation not using DirectComposition, skipping test."; | 49 << "GL implementation not using DirectComposition, skipping test."; |
| 41 return; | 50 return; |
| 42 } | 51 } |
| 43 | 52 |
| 44 TestImageTransportSurfaceDelegate delegate; | 53 TestImageTransportSurfaceDelegate delegate; |
| 45 | 54 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 EXPECT_TRUE(context2->MakeCurrent(surface2.get())); | 92 EXPECT_TRUE(context2->MakeCurrent(surface2.get())); |
| 84 EXPECT_TRUE(surface2->Resize(gfx::Size(100, 100), 1.0, true)); | 93 EXPECT_TRUE(surface2->Resize(gfx::Size(100, 100), 1.0, true)); |
| 85 // The previous IDCompositionSurface should be suspended when another | 94 // The previous IDCompositionSurface should be suspended when another |
| 86 // surface is being drawn to. | 95 // surface is being drawn to. |
| 87 EXPECT_TRUE(surface2->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); | 96 EXPECT_TRUE(surface2->SetDrawRectangle(gfx::Rect(0, 0, 100, 100))); |
| 88 EXPECT_TRUE(context2->IsCurrent(surface2.get())); | 97 EXPECT_TRUE(context2->IsCurrent(surface2.get())); |
| 89 | 98 |
| 90 // It should be possible to switch back to the previous surface and | 99 // It should be possible to switch back to the previous surface and |
| 91 // unsuspend it. | 100 // unsuspend it. |
| 92 EXPECT_TRUE(context->MakeCurrent(surface.get())); | 101 EXPECT_TRUE(context->MakeCurrent(surface.get())); |
| 102 scoped_refptr<base::TaskRunner> task_runner1 = |
| 103 surface->GetWindowTaskRunnerForTesting(); |
| 104 scoped_refptr<base::TaskRunner> task_runner2 = |
| 105 surface2->GetWindowTaskRunnerForTesting(); |
| 93 | 106 |
| 94 context2 = nullptr; | 107 context2 = nullptr; |
| 95 surface2 = nullptr; | 108 surface2 = nullptr; |
| 96 context = nullptr; | 109 context = nullptr; |
| 97 surface = nullptr; | 110 surface = nullptr; |
| 111 |
| 112 // Ensure that the ChildWindowWin posts the task to delete the thread to the |
| 113 // main loop before doing RunUntilIdle. Otherwise the child threads could |
| 114 // outlive the main thread. |
| 115 RunPendingTasks(task_runner1); |
| 116 RunPendingTasks(task_runner2); |
| 117 |
| 98 base::RunLoop().RunUntilIdle(); | 118 base::RunLoop().RunUntilIdle(); |
| 99 } | 119 } |
| 100 | 120 |
| 101 } // namespace | 121 } // namespace |
| 102 } // namespace gpu | 122 } // namespace gpu |
| OLD | NEW |