| 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_guest.h" | 5 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/test/scoped_task_scheduler.h" | 14 #include "base/test/scoped_task_scheduler.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "cc/surfaces/surface.h" | 16 #include "cc/surfaces/surface.h" |
| 17 #include "cc/surfaces/surface_manager.h" | 17 #include "cc/surfaces/surface_manager.h" |
| 18 #include "cc/surfaces/surface_sequence.h" | 18 #include "cc/surfaces/surface_sequence.h" |
| 19 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 19 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 20 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 20 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
| 21 #include "content/browser/gpu/compositor_util.h" | 21 #include "content/browser/gpu/compositor_util.h" |
| 22 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 22 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 23 #include "content/browser/renderer_host/render_widget_host_impl.h" | 23 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 24 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
| 25 #include "content/public/browser/browser_plugin_guest_delegate.h" | 25 #include "content/public/browser/browser_plugin_guest_delegate.h" |
| 26 #include "content/public/browser/render_widget_host_view.h" | 26 #include "content/public/browser/render_widget_host_view.h" |
| 27 #include "content/public/test/mock_render_process_host.h" | 27 #include "content/public/test/mock_render_process_host.h" |
| 28 #include "content/public/test/test_browser_context.h" | 28 #include "content/public/test/test_browser_context.h" |
| 29 #include "content/test/fake_renderer_compositor_frame_sink.h" | |
| 30 #include "content/test/test_render_view_host.h" | 29 #include "content/test/test_render_view_host.h" |
| 31 #include "content/test/test_web_contents.h" | 30 #include "content/test/test_web_contents.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "ui/compositor/compositor.h" | 32 #include "ui/compositor/compositor.h" |
| 34 | 33 |
| 35 namespace content { | 34 namespace content { |
| 36 namespace { | 35 namespace { |
| 37 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { | 36 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { |
| 38 public: | 37 public: |
| 39 MockRenderWidgetHostDelegate() {} | 38 MockRenderWidgetHostDelegate() {} |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // We don't own the BPG, the WebContents does. | 161 // We don't own the BPG, the WebContents does. |
| 163 browser_plugin_guest_ = new TestBrowserPluginGuest( | 162 browser_plugin_guest_ = new TestBrowserPluginGuest( |
| 164 web_contents_.get(), &browser_plugin_guest_delegate_); | 163 web_contents_.get(), &browser_plugin_guest_delegate_); |
| 165 | 164 |
| 166 int32_t routing_id = process_host->GetNextRoutingID(); | 165 int32_t routing_id = process_host->GetNextRoutingID(); |
| 167 widget_host_ = | 166 widget_host_ = |
| 168 new RenderWidgetHostImpl(&delegate_, process_host, routing_id, false); | 167 new RenderWidgetHostImpl(&delegate_, process_host, routing_id, false); |
| 169 view_ = RenderWidgetHostViewGuest::Create( | 168 view_ = RenderWidgetHostViewGuest::Create( |
| 170 widget_host_, browser_plugin_guest_, | 169 widget_host_, browser_plugin_guest_, |
| 171 (new TestRenderWidgetHostView(widget_host_))->GetWeakPtr()); | 170 (new TestRenderWidgetHostView(widget_host_))->GetWeakPtr()); |
| 172 cc::mojom::MojoCompositorFrameSinkPtr sink; | |
| 173 cc::mojom::MojoCompositorFrameSinkRequest sink_request = | |
| 174 mojo::MakeRequest(&sink); | |
| 175 cc::mojom::MojoCompositorFrameSinkClientRequest client_request = | |
| 176 mojo::MakeRequest(&renderer_compositor_frame_sink_ptr_); | |
| 177 renderer_compositor_frame_sink_ = | |
| 178 base::MakeUnique<FakeRendererCompositorFrameSink>( | |
| 179 std::move(sink), std::move(client_request)); | |
| 180 view_->DidCreateNewRendererCompositorFrameSink( | |
| 181 renderer_compositor_frame_sink_ptr_.get()); | |
| 182 } | 171 } |
| 183 | 172 |
| 184 void TearDown() override { | 173 void TearDown() override { |
| 185 if (view_) | 174 if (view_) |
| 186 view_->Destroy(); | 175 view_->Destroy(); |
| 187 delete widget_host_; | 176 delete widget_host_; |
| 188 | 177 |
| 189 // It's important to make sure that the view finishes destructing before | 178 // It's important to make sure that the view finishes destructing before |
| 190 // we hit the destructor for the TestBrowserThreadBundle, so run the message | 179 // we hit the destructor for the TestBrowserThreadBundle, so run the message |
| 191 // loop here. | 180 // loop here. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 209 std::unique_ptr<BrowserContext> browser_context_; | 198 std::unique_ptr<BrowserContext> browser_context_; |
| 210 MockRenderWidgetHostDelegate delegate_; | 199 MockRenderWidgetHostDelegate delegate_; |
| 211 BrowserPluginGuestDelegate browser_plugin_guest_delegate_; | 200 BrowserPluginGuestDelegate browser_plugin_guest_delegate_; |
| 212 std::unique_ptr<TestWebContents> web_contents_; | 201 std::unique_ptr<TestWebContents> web_contents_; |
| 213 TestBrowserPluginGuest* browser_plugin_guest_; | 202 TestBrowserPluginGuest* browser_plugin_guest_; |
| 214 | 203 |
| 215 // Tests should set these to NULL if they've already triggered their | 204 // Tests should set these to NULL if they've already triggered their |
| 216 // destruction. | 205 // destruction. |
| 217 RenderWidgetHostImpl* widget_host_; | 206 RenderWidgetHostImpl* widget_host_; |
| 218 RenderWidgetHostViewGuest* view_; | 207 RenderWidgetHostViewGuest* view_; |
| 219 std::unique_ptr<FakeRendererCompositorFrameSink> | |
| 220 renderer_compositor_frame_sink_; | |
| 221 | 208 |
| 222 private: | 209 private: |
| 223 cc::mojom::MojoCompositorFrameSinkClientPtr | |
| 224 renderer_compositor_frame_sink_ptr_; | |
| 225 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestSurfaceTest); | 210 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestSurfaceTest); |
| 226 }; | 211 }; |
| 227 | 212 |
| 228 namespace { | 213 namespace { |
| 229 cc::CompositorFrame CreateDelegatedFrame(float scale_factor, | 214 cc::CompositorFrame CreateDelegatedFrame(float scale_factor, |
| 230 gfx::Size size, | 215 gfx::Size size, |
| 231 const gfx::Rect& damage) { | 216 const gfx::Rect& damage) { |
| 232 cc::CompositorFrame frame; | 217 cc::CompositorFrame frame; |
| 233 frame.metadata.device_scale_factor = scale_factor; | 218 frame.metadata.device_scale_factor = scale_factor; |
| 234 frame.metadata.begin_frame_ack = cc::BeginFrameAck(0, 1, 1, true); | 219 frame.metadata.begin_frame_ack = cc::BeginFrameAck(0, 1, 1, true); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 | 287 |
| 303 view_->SubmitCompositorFrame( | 288 view_->SubmitCompositorFrame( |
| 304 local_surface_id, | 289 local_surface_id, |
| 305 CreateDelegatedFrame(scale_factor, view_size, view_rect)); | 290 CreateDelegatedFrame(scale_factor, view_size, view_rect)); |
| 306 // Since guest is not attached, the CompositorFrame must be processed but the | 291 // Since guest is not attached, the CompositorFrame must be processed but the |
| 307 // frame must be evicted to return the resources immediately. | 292 // frame must be evicted to return the resources immediately. |
| 308 EXPECT_FALSE(view_->has_frame()); | 293 EXPECT_FALSE(view_->has_frame()); |
| 309 } | 294 } |
| 310 | 295 |
| 311 } // namespace content | 296 } // namespace content |
| OLD | NEW |