| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/frame_host/render_widget_host_view_child_frame.h" | 5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "content/common/view_messages.h" | 26 #include "content/common/view_messages.h" |
| 27 #include "content/public/browser/render_widget_host_view.h" | 27 #include "content/public/browser/render_widget_host_view.h" |
| 28 #include "content/public/test/mock_render_process_host.h" | 28 #include "content/public/test/mock_render_process_host.h" |
| 29 #include "content/public/test/test_browser_context.h" | 29 #include "content/public/test/test_browser_context.h" |
| 30 #include "content/test/test_render_view_host.h" | 30 #include "content/test/test_render_view_host.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "ui/compositor/compositor.h" | 32 #include "ui/compositor/compositor.h" |
| 33 | 33 |
| 34 namespace content { | 34 namespace content { |
| 35 namespace { | 35 namespace { |
| 36 |
| 37 const cc::LocalSurfaceId kArbitraryLocalSurfaceId( |
| 38 1, |
| 39 base::UnguessableToken::Deserialize(2, 3)); |
| 40 |
| 36 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { | 41 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { |
| 37 public: | 42 public: |
| 38 MockRenderWidgetHostDelegate() {} | 43 MockRenderWidgetHostDelegate() {} |
| 39 ~MockRenderWidgetHostDelegate() override {} | 44 ~MockRenderWidgetHostDelegate() override {} |
| 40 private: | 45 private: |
| 41 void Cut() override {} | 46 void Cut() override {} |
| 42 void Copy() override {} | 47 void Copy() override {} |
| 43 void Paste() override {} | 48 void Paste() override {} |
| 44 void SelectAll() override {} | 49 void SelectAll() override {} |
| 45 }; | 50 }; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 base::RunLoop().RunUntilIdle(); | 105 base::RunLoop().RunUntilIdle(); |
| 101 #if !defined(OS_ANDROID) | 106 #if !defined(OS_ANDROID) |
| 102 ImageTransportFactory::Terminate(); | 107 ImageTransportFactory::Terminate(); |
| 103 #endif | 108 #endif |
| 104 } | 109 } |
| 105 | 110 |
| 106 cc::SurfaceId GetSurfaceId() const { | 111 cc::SurfaceId GetSurfaceId() const { |
| 107 return cc::SurfaceId(view_->frame_sink_id_, view_->local_surface_id_); | 112 return cc::SurfaceId(view_->frame_sink_id_, view_->local_surface_id_); |
| 108 } | 113 } |
| 109 | 114 |
| 115 cc::LocalSurfaceId GetLocalSurfaceId() const { |
| 116 return view_->local_surface_id_; |
| 117 } |
| 118 |
| 110 void ClearCompositorSurfaceIfNecessary() { | 119 void ClearCompositorSurfaceIfNecessary() { |
| 111 view_->ClearCompositorSurfaceIfNecessary(); | 120 view_->ClearCompositorSurfaceIfNecessary(); |
| 112 } | 121 } |
| 113 | 122 |
| 114 protected: | 123 protected: |
| 115 base::MessageLoopForUI message_loop_; | 124 base::MessageLoopForUI message_loop_; |
| 116 std::unique_ptr<BrowserContext> browser_context_; | 125 std::unique_ptr<BrowserContext> browser_context_; |
| 117 MockRenderWidgetHostDelegate delegate_; | 126 MockRenderWidgetHostDelegate delegate_; |
| 118 | 127 |
| 119 // Tests should set these to NULL if they've already triggered their | 128 // Tests should set these to NULL if they've already triggered their |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 view_->Hide(); | 163 view_->Hide(); |
| 155 ASSERT_FALSE(view_->IsShowing()); | 164 ASSERT_FALSE(view_->IsShowing()); |
| 156 } | 165 } |
| 157 | 166 |
| 158 // Verify that OnSwapCompositorFrame behavior is correct when a delegated | 167 // Verify that OnSwapCompositorFrame behavior is correct when a delegated |
| 159 // frame is received from a renderer process. | 168 // frame is received from a renderer process. |
| 160 TEST_F(RenderWidgetHostViewChildFrameTest, MAYBE_SwapCompositorFrame) { | 169 TEST_F(RenderWidgetHostViewChildFrameTest, MAYBE_SwapCompositorFrame) { |
| 161 gfx::Size view_size(100, 100); | 170 gfx::Size view_size(100, 100); |
| 162 gfx::Rect view_rect(view_size); | 171 gfx::Rect view_rect(view_size); |
| 163 float scale_factor = 1.f; | 172 float scale_factor = 1.f; |
| 173 cc::LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); |
| 164 | 174 |
| 165 view_->SetSize(view_size); | 175 view_->SetSize(view_size); |
| 166 view_->Show(); | 176 view_->Show(); |
| 167 | 177 |
| 168 view_->OnSwapCompositorFrame( | 178 view_->OnSwapCompositorFrame( |
| 169 0, CreateDelegatedFrame(scale_factor, view_size, view_rect)); | 179 0, local_surface_id, |
| 180 CreateDelegatedFrame(scale_factor, view_size, view_rect)); |
| 170 | 181 |
| 171 cc::SurfaceId id = GetSurfaceId(); | 182 cc::SurfaceId id = GetSurfaceId(); |
| 172 if (id.is_valid()) { | 183 if (id.is_valid()) { |
| 173 #if !defined(OS_ANDROID) | 184 #if !defined(OS_ANDROID) |
| 174 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 185 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 175 cc::SurfaceManager* manager = | 186 cc::SurfaceManager* manager = |
| 176 factory->GetContextFactoryPrivate()->GetSurfaceManager(); | 187 factory->GetContextFactoryPrivate()->GetSurfaceManager(); |
| 177 cc::Surface* surface = manager->GetSurfaceForId(id); | 188 cc::Surface* surface = manager->GetSurfaceForId(id); |
| 178 EXPECT_TRUE(surface); | 189 EXPECT_TRUE(surface); |
| 179 // There should be a SurfaceSequence created by the RWHVChildFrame. | 190 // There should be a SurfaceSequence created by the RWHVChildFrame. |
| 180 EXPECT_EQ(1u, surface->GetDestructionDependencyCount()); | 191 EXPECT_EQ(1u, surface->GetDestructionDependencyCount()); |
| 181 #endif | 192 #endif |
| 182 | 193 |
| 183 // Surface ID should have been passed to CrossProcessFrameConnector to | 194 // Surface ID should have been passed to CrossProcessFrameConnector to |
| 184 // be sent to the embedding renderer. | 195 // be sent to the embedding renderer. |
| 185 EXPECT_EQ(cc::SurfaceInfo(id, scale_factor, view_size), | 196 EXPECT_EQ(cc::SurfaceInfo(id, scale_factor, view_size), |
| 186 test_frame_connector_->last_surface_info_); | 197 test_frame_connector_->last_surface_info_); |
| 187 } | 198 } |
| 188 } | 199 } |
| 189 | 200 |
| 190 // Check that frame eviction does not trigger allocation of a new local surface | 201 // Check that the same local surface id can be used after frame eviction. |
| 191 // id. | 202 TEST_F(RenderWidgetHostViewChildFrameTest, FrameEviction) { |
| 192 TEST_F(RenderWidgetHostViewChildFrameTest, FrameEvictionKeepsLocalSurfaceId) { | |
| 193 gfx::Size view_size(100, 100); | 203 gfx::Size view_size(100, 100); |
| 194 gfx::Rect view_rect(view_size); | 204 gfx::Rect view_rect(view_size); |
| 195 float scale_factor = 1.f; | 205 float scale_factor = 1.f; |
| 196 | 206 |
| 197 view_->SetSize(view_size); | 207 view_->SetSize(view_size); |
| 198 view_->Show(); | 208 view_->Show(); |
| 199 | 209 |
| 200 // Submit a frame. Remember the local surface id and check that has_frame() | 210 // Submit a frame. |
| 201 // returns true. | |
| 202 view_->OnSwapCompositorFrame( | 211 view_->OnSwapCompositorFrame( |
| 203 0, CreateDelegatedFrame(scale_factor, view_size, view_rect)); | 212 0, kArbitraryLocalSurfaceId, |
| 213 CreateDelegatedFrame(scale_factor, view_size, view_rect)); |
| 204 | 214 |
| 205 cc::SurfaceId surface_id = GetSurfaceId(); | 215 EXPECT_EQ(kArbitraryLocalSurfaceId, GetLocalSurfaceId()); |
| 206 EXPECT_TRUE(surface_id.is_valid()); | |
| 207 EXPECT_TRUE(view_->has_frame()); | 216 EXPECT_TRUE(view_->has_frame()); |
| 208 | 217 |
| 209 // Evict the frame. The surface id must remain the same but has_frame() should | 218 // Evict the frame. has_frame() should return false. |
| 210 // return false. | |
| 211 ClearCompositorSurfaceIfNecessary(); | 219 ClearCompositorSurfaceIfNecessary(); |
| 212 EXPECT_EQ(surface_id, GetSurfaceId()); | 220 EXPECT_EQ(kArbitraryLocalSurfaceId, GetLocalSurfaceId()); |
| 213 EXPECT_FALSE(view_->has_frame()); | 221 EXPECT_FALSE(view_->has_frame()); |
| 214 | 222 |
| 215 // Submit another frame. Since it has the same size and scale as the first | 223 // Submit another frame with the same local surface id. The same id should be |
| 216 // one, the same surface id must be used. has_frame() must return true. | 224 // usable. |
| 217 view_->OnSwapCompositorFrame( | 225 view_->OnSwapCompositorFrame( |
| 218 0, CreateDelegatedFrame(scale_factor, view_size, view_rect)); | 226 0, kArbitraryLocalSurfaceId, |
| 219 EXPECT_EQ(surface_id, GetSurfaceId()); | 227 CreateDelegatedFrame(scale_factor, view_size, view_rect)); |
| 228 EXPECT_EQ(kArbitraryLocalSurfaceId, GetLocalSurfaceId()); |
| 220 EXPECT_TRUE(view_->has_frame()); | 229 EXPECT_TRUE(view_->has_frame()); |
| 221 } | 230 } |
| 222 | 231 |
| 223 } // namespace content | 232 } // namespace content |
| OLD | NEW |