| Index: components/view_manager/native_viewport/native_viewport.cc
|
| diff --git a/components/view_manager/native_viewport/native_viewport.cc b/components/view_manager/native_viewport/native_viewport.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..06d0869b10bed5d58f182af8f5f3be6af7444f2a
|
| --- /dev/null
|
| +++ b/components/view_manager/native_viewport/native_viewport.cc
|
| @@ -0,0 +1,92 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/view_manager/native_viewport/native_viewport.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "components/view_manager/gles2/gpu_state.h"
|
| +#include "components/view_manager/native_viewport/platform_viewport_headless.h"
|
| +#include "ui/gfx/geometry/size.h"
|
| +
|
| +namespace view_manager {
|
| +
|
| +NativeViewport::NativeViewport(
|
| + Delegate* delegate,
|
| + const gfx::Size& size,
|
| + bool is_headless,
|
| + const scoped_refptr<gles2::GpuState>& gpu_state)
|
| + : delegate_(delegate),
|
| + context_provider_(
|
| + new native_viewport::OnscreenContextProvider(gpu_state)),
|
| + size_(size) {
|
| + platform_viewport_ =
|
| + native_viewport::PlatformViewport::Create(this, is_headless);
|
| + platform_viewport_->Init(gfx::Rect(size));
|
| +}
|
| +
|
| +NativeViewport::~NativeViewport() {
|
| + // Destroy before |platform_viewport_| because this will destroy
|
| + // CommandBufferDriver objects that contain child windows. Otherwise if this
|
| + // class destroys its window first, X errors will occur.
|
| + context_provider_.reset();
|
| +
|
| + // Destroy the NativeViewport early on as it may call us back during
|
| + // destruction and we want to be in a known state.
|
| + platform_viewport_.reset();
|
| +}
|
| +
|
| +void NativeViewport::Show() {
|
| + platform_viewport_->Show();
|
| +}
|
| +
|
| +void NativeViewport::Hide() {
|
| + platform_viewport_->Hide();
|
| +}
|
| +
|
| +void NativeViewport::Close() {
|
| + DCHECK(platform_viewport_);
|
| + platform_viewport_->Close();
|
| +}
|
| +
|
| +void NativeViewport::SetSize(const gfx::Size& size) {
|
| + platform_viewport_->SetBounds(gfx::Rect(size));
|
| +}
|
| +
|
| +void NativeViewport::GetContextProvider(
|
| + mojo::InterfaceRequest<mojo::ContextProvider> request) {
|
| + context_provider_->Bind(request.Pass());
|
| +}
|
| +
|
| +void NativeViewport::OnMetricsChanged(const gfx::Size& size,
|
| + float device_scale_factor) {
|
| + if (delegate_)
|
| + delegate_->OnMetricsChanged(size, device_scale_factor);
|
| +}
|
| +
|
| +void NativeViewport::OnAcceleratedWidgetAvailable(
|
| + gfx::AcceleratedWidget widget,
|
| + float device_pixel_ratio) {
|
| + context_provider_->SetAcceleratedWidget(widget);
|
| + // TODO: The metrics here might not match the actual window size on android
|
| + // where we don't know the actual size until the first OnMetricsChanged call.
|
| + OnMetricsChanged(size_, device_pixel_ratio);
|
| +}
|
| +
|
| +void NativeViewport::OnAcceleratedWidgetDestroyed() {
|
| + context_provider_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
|
| +}
|
| +
|
| +bool NativeViewport::OnEvent(mojo::EventPtr event) {
|
| + if (delegate_)
|
| + return delegate_->OnEvent(event.Pass());
|
| +
|
| + return false;
|
| +}
|
| +
|
| +void NativeViewport::OnDestroyed() {
|
| + if (delegate_)
|
| + delegate_->OnViewDestroyed();
|
| +}
|
| +
|
| +} // namespace view_manager
|
|
|