Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: components/view_manager/native_viewport/native_viewport.cc

Issue 1149083010: Mandoline: Remove native_viewport.mojom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplified headless logic Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/view_manager/native_viewport/native_viewport.h"
6
7 #include "base/bind.h"
8 #include "components/view_manager/gles2/gpu_state.h"
9 #include "components/view_manager/native_viewport/platform_viewport_headless.h"
10 #include "ui/gfx/geometry/size.h"
11
12 namespace view_manager {
13
14 NativeViewport::NativeViewport(
15 Delegate* delegate,
16 const gfx::Size& size,
17 bool is_headless,
18 const scoped_refptr<gles2::GpuState>& gpu_state)
19 : delegate_(delegate),
20 context_provider_(
21 new native_viewport::OnscreenContextProvider(gpu_state)),
22 size_(size) {
23 platform_viewport_ =
24 native_viewport::PlatformViewport::Create(this, is_headless);
25 platform_viewport_->Init(gfx::Rect(size));
26 }
27
28 NativeViewport::~NativeViewport() {
29 // Destroy before |platform_viewport_| because this will destroy
30 // CommandBufferDriver objects that contain child windows. Otherwise if this
31 // class destroys its window first, X errors will occur.
32 context_provider_.reset();
33
34 // Destroy the NativeViewport early on as it may call us back during
35 // destruction and we want to be in a known state.
36 platform_viewport_.reset();
37 }
38
39 void NativeViewport::Show() {
40 platform_viewport_->Show();
41 }
42
43 void NativeViewport::Hide() {
44 platform_viewport_->Hide();
45 }
46
47 void NativeViewport::Close() {
48 DCHECK(platform_viewport_);
49 platform_viewport_->Close();
50 }
51
52 void NativeViewport::SetSize(const gfx::Size& size) {
53 platform_viewport_->SetBounds(gfx::Rect(size));
54 }
55
56 void NativeViewport::GetContextProvider(
57 mojo::InterfaceRequest<mojo::ContextProvider> request) {
58 context_provider_->Bind(request.Pass());
59 }
60
61 void NativeViewport::OnMetricsChanged(const gfx::Size& size,
62 float device_scale_factor) {
63 if (delegate_)
64 delegate_->OnMetricsChanged(size, device_scale_factor);
65 }
66
67 void NativeViewport::OnAcceleratedWidgetAvailable(
68 gfx::AcceleratedWidget widget,
69 float device_pixel_ratio) {
70 context_provider_->SetAcceleratedWidget(widget);
71 // TODO: The metrics here might not match the actual window size on android
72 // where we don't know the actual size until the first OnMetricsChanged call.
73 OnMetricsChanged(size_, device_pixel_ratio);
74 }
75
76 void NativeViewport::OnAcceleratedWidgetDestroyed() {
77 context_provider_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
78 }
79
80 bool NativeViewport::OnEvent(mojo::EventPtr event) {
81 if (delegate_)
82 return delegate_->OnEvent(event.Pass());
83
84 return false;
85 }
86
87 void NativeViewport::OnDestroyed() {
88 if (delegate_)
89 delegate_->OnViewDestroyed();
90 }
91
92 } // namespace view_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698