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 "mojo/services/native_viewport/native_viewport_impl.h" | 5 #include "mojo/services/native_viewport/native_viewport_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // TODO(jamesr): Should be mojo_gpu_service | 34 // TODO(jamesr): Should be mojo_gpu_service |
35 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); | 35 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); |
36 } | 36 } |
37 | 37 |
38 NativeViewportImpl::~NativeViewportImpl() { | 38 NativeViewportImpl::~NativeViewportImpl() { |
39 // Destroy the NativeViewport early on as it may call us back during | 39 // Destroy the NativeViewport early on as it may call us back during |
40 // destruction and we want to be in a known state. | 40 // destruction and we want to be in a known state. |
41 platform_viewport_.reset(); | 41 platform_viewport_.reset(); |
42 } | 42 } |
43 | 43 |
44 void NativeViewportImpl::Create(RectPtr bounds) { | 44 void NativeViewportImpl::Create(SizePtr bounds) { |
45 platform_viewport_ = PlatformViewport::Create(this); | 45 platform_viewport_ = PlatformViewport::Create(this); |
46 platform_viewport_->Init(bounds.To<gfx::Rect>()); | 46 gfx::Rect rect = gfx::Rect(bounds.To<gfx::Size>()); |
47 OnBoundsChanged(bounds.To<gfx::Rect>()); | 47 platform_viewport_->Init(rect); |
| 48 OnBoundsChanged(rect); |
48 } | 49 } |
49 | 50 |
50 void NativeViewportImpl::Show() { | 51 void NativeViewportImpl::Show() { |
51 platform_viewport_->Show(); | 52 platform_viewport_->Show(); |
52 } | 53 } |
53 | 54 |
54 void NativeViewportImpl::Hide() { | 55 void NativeViewportImpl::Hide() { |
55 platform_viewport_->Hide(); | 56 platform_viewport_->Hide(); |
56 } | 57 } |
57 | 58 |
58 void NativeViewportImpl::Close() { | 59 void NativeViewportImpl::Close() { |
59 DCHECK(platform_viewport_); | 60 DCHECK(platform_viewport_); |
60 platform_viewport_->Close(); | 61 platform_viewport_->Close(); |
61 } | 62 } |
62 | 63 |
63 void NativeViewportImpl::SetBounds(RectPtr bounds) { | 64 void NativeViewportImpl::SetBounds(SizePtr bounds) { |
64 platform_viewport_->SetBounds(bounds.To<gfx::Rect>()); | 65 platform_viewport_->SetBounds(gfx::Rect(bounds.To<gfx::Size>())); |
65 } | 66 } |
66 | 67 |
67 void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr child_surface_id) { | 68 void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr child_surface_id) { |
68 if (child_surface_id_.is_null()) { | 69 if (child_surface_id_.is_null()) { |
69 // If this is the first indication that the client will use surfaces, | 70 // If this is the first indication that the client will use surfaces, |
70 // initialize that system. | 71 // initialize that system. |
71 // TODO(jamesr): When everything is converted to surfaces initialize this | 72 // TODO(jamesr): When everything is converted to surfaces initialize this |
72 // eagerly. | 73 // eagerly. |
73 viewport_surface_.reset( | 74 viewport_surface_.reset( |
74 new ViewportSurface(surfaces_service_.get(), | 75 new ViewportSurface(surfaces_service_.get(), |
75 gpu_service_.get(), | 76 gpu_service_.get(), |
76 bounds_, | 77 bounds_.size(), |
77 child_surface_id.To<cc::SurfaceId>())); | 78 child_surface_id.To<cc::SurfaceId>())); |
78 if (widget_id_) | 79 if (widget_id_) |
79 viewport_surface_->SetWidgetId(widget_id_); | 80 viewport_surface_->SetWidgetId(widget_id_); |
80 } | 81 } |
81 child_surface_id_ = child_surface_id.To<cc::SurfaceId>(); | 82 child_surface_id_ = child_surface_id.To<cc::SurfaceId>(); |
82 if (viewport_surface_) | 83 if (viewport_surface_) |
83 viewport_surface_->SetChildId(child_surface_id_); | 84 viewport_surface_->SetChildId(child_surface_id_); |
84 } | 85 } |
85 | 86 |
86 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { | 87 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { |
87 bounds_ = bounds; | 88 bounds_ = bounds; |
88 client()->OnBoundsChanged(Rect::From(bounds)); | 89 client()->OnBoundsChanged(Size::From(bounds.size())); |
89 if (viewport_surface_) | 90 if (viewport_surface_) |
90 viewport_surface_->SetBounds(bounds); | 91 viewport_surface_->SetSize(bounds.size()); |
91 } | 92 } |
92 | 93 |
93 void NativeViewportImpl::OnAcceleratedWidgetAvailable( | 94 void NativeViewportImpl::OnAcceleratedWidgetAvailable( |
94 gfx::AcceleratedWidget widget) { | 95 gfx::AcceleratedWidget widget) { |
95 widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget)); | 96 widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget)); |
96 // TODO(jamesr): Remove once everything is converted to surfaces. | 97 // TODO(jamesr): Remove once everything is converted to surfaces. |
97 client()->OnCreated(widget_id_); | 98 client()->OnCreated(widget_id_); |
98 if (viewport_surface_) | 99 if (viewport_surface_) |
99 viewport_surface_->SetWidgetId(widget_id_); | 100 viewport_surface_->SetWidgetId(widget_id_); |
100 } | 101 } |
(...skipping 26 matching lines...) Expand all Loading... |
127 void NativeViewportImpl::OnDestroyed() { | 128 void NativeViewportImpl::OnDestroyed() { |
128 client()->OnDestroyed(); | 129 client()->OnDestroyed(); |
129 } | 130 } |
130 | 131 |
131 void NativeViewportImpl::AckEvent() { | 132 void NativeViewportImpl::AckEvent() { |
132 waiting_for_event_ack_ = false; | 133 waiting_for_event_ack_ = false; |
133 } | 134 } |
134 | 135 |
135 } // namespace mojo | 136 } // namespace mojo |
136 | 137 |
OLD | NEW |