| Index: mojo/services/native_viewport/native_viewport_impl.cc
|
| diff --git a/mojo/services/native_viewport/native_viewport_impl.cc b/mojo/services/native_viewport/native_viewport_impl.cc
|
| index e662a6d38a045d6c6b8adcccc1d79da60f26543c..8755dfd1c74b8f2dc5274e50698b51d89dfff11b 100644
|
| --- a/mojo/services/native_viewport/native_viewport_impl.cc
|
| +++ b/mojo/services/native_viewport/native_viewport_impl.cc
|
| @@ -4,7 +4,6 @@
|
|
|
| #include "mojo/services/native_viewport/native_viewport_impl.h"
|
|
|
| -#include "base/bind.h"
|
| #include "base/macros.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/time/time.h"
|
| @@ -39,6 +38,7 @@
|
| void NativeViewportImpl::Create(RectPtr bounds) {
|
| platform_viewport_ = PlatformViewport::Create(this);
|
| platform_viewport_->Init(bounds.To<gfx::Rect>());
|
| + client()->OnCreated();
|
| OnBoundsChanged(bounds.To<gfx::Rect>());
|
| }
|
|
|
| @@ -51,6 +51,7 @@
|
| }
|
|
|
| void NativeViewportImpl::Close() {
|
| + command_buffer_.reset();
|
| DCHECK(platform_viewport_);
|
| platform_viewport_->Close();
|
| }
|
| @@ -59,14 +60,25 @@
|
| platform_viewport_->SetBounds(bounds.To<gfx::Rect>());
|
| }
|
|
|
| +void NativeViewportImpl::CreateGLES2Context(
|
| + InterfaceRequest<CommandBuffer> command_buffer_request) {
|
| + if (command_buffer_ || command_buffer_request_.is_pending()) {
|
| + LOG(ERROR) << "Can't create multiple contexts on a NativeViewport";
|
| + return;
|
| + }
|
| + command_buffer_request_ = command_buffer_request.Pass();
|
| + CreateCommandBufferIfNeeded();
|
| +}
|
| +
|
| void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) {
|
| + CreateCommandBufferIfNeeded();
|
| client()->OnBoundsChanged(Rect::From(bounds));
|
| }
|
|
|
| void NativeViewportImpl::OnAcceleratedWidgetAvailable(
|
| gfx::AcceleratedWidget widget) {
|
| widget_ = widget;
|
| - client()->OnCreated(reinterpret_cast<uint64_t>(widget));
|
| + CreateCommandBufferIfNeeded();
|
| }
|
|
|
| bool NativeViewportImpl::OnEvent(ui::Event* ui_event) {
|
| @@ -96,12 +108,31 @@
|
| }
|
|
|
| void NativeViewportImpl::OnDestroyed() {
|
| - client()->OnDestroyed();
|
| + client()->OnDestroyed(base::Bind(&NativeViewportImpl::AckDestroyed,
|
| + base::Unretained(this)));
|
| }
|
|
|
| void NativeViewportImpl::AckEvent() {
|
| waiting_for_event_ack_ = false;
|
| }
|
|
|
| +void NativeViewportImpl::CreateCommandBufferIfNeeded() {
|
| + if (!command_buffer_request_.is_pending())
|
| + return;
|
| + DCHECK(!command_buffer_.get());
|
| + if (widget_ == gfx::kNullAcceleratedWidget)
|
| + return;
|
| + gfx::Size size = platform_viewport_->GetSize();
|
| + if (size.IsEmpty())
|
| + return;
|
| + command_buffer_.reset(
|
| + new CommandBufferImpl(widget_, platform_viewport_->GetSize()));
|
| + WeakBindToRequest(command_buffer_.get(), &command_buffer_request_);
|
| +}
|
| +
|
| +void NativeViewportImpl::AckDestroyed() {
|
| + command_buffer_.reset();
|
| +}
|
| +
|
| } // namespace mojo
|
|
|
|
|