diff options
author | sky <sky@chromium.org> | 2015-04-20 21:03:22 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-21 04:03:44 +0000 |
commit | a57fb11d71d161f41e1da8071c6883579246c155 (patch) | |
tree | 25dc34051bb84d644476f78e2ea8c5ea1d0ed446 /mojo | |
parent | 9d6f4e94b65973751f11d2d304b1fcff2a5fa013 (diff) | |
download | chromium_src-a57fb11d71d161f41e1da8071c6883579246c155.zip chromium_src-a57fb11d71d161f41e1da8071c6883579246c155.tar.gz chromium_src-a57fb11d71d161f41e1da8071c6883579246c155.tar.bz2 |
Moves mojo/services/* to components/* part 4
native_viewport and surfaces (which should be renamed to something
more specific).
R=ben@chromium.org
TBR=ben@chromium.org
BUG=none
TEST=none
Review URL: https://codereview.chromium.org/1093983004
Cr-Commit-Position: refs/heads/master@{#325980}
Diffstat (limited to 'mojo')
37 files changed, 9 insertions, 2515 deletions
diff --git a/mojo/services/BUILD.gn b/mojo/services/BUILD.gn index ecddb11..304ef92 100644 --- a/mojo/services/BUILD.gn +++ b/mojo/services/BUILD.gn @@ -21,12 +21,12 @@ group("services") { deps += [ "//components/clipboard", "//components/kiosk_wm:window_manager", + "//components/native_viewport", + "//components/surfaces", "//components/view_manager", "//components/window_manager:lib", "//mojo/services/html_viewer", - "//mojo/services/native_viewport", "//mojo/services/network", - "//mojo/services/surfaces", "//mojo/services/tracing", ] @@ -34,10 +34,10 @@ group("services") { if (is_mac) { deps -= [ "//components/kiosk_wm:window_manager", + "//components/native_viewport", "//components/view_manager", "//components/window_manager:lib", "//mojo/services/html_viewer", - "//mojo/services/native_viewport", ] } } diff --git a/mojo/services/native_viewport/BUILD.gn b/mojo/services/native_viewport/BUILD.gn deleted file mode 100644 index 39dee00..0000000 --- a/mojo/services/native_viewport/BUILD.gn +++ /dev/null @@ -1,110 +0,0 @@ -# Copyright 2014 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. - -import("//build/config/ui.gni") -import("//third_party/mojo/src/mojo/public/mojo_application.gni") - -if (is_android) { - import("//build/config/android/config.gni") - import("//build/config/android/rules.gni") - - group("native_viewport") { - deps = [ - ":lib", - ":native_viewport_java", - ":jni_headers", - ] - } - - android_library("native_viewport_java") { - java_files = - [ "android/src/org/chromium/mojo/PlatformViewportAndroid.java" ] - - deps = [ - "//base:base_java", - ] - } - - generate_jni("jni_headers") { - sources = [ - "android/src/org/chromium/mojo/PlatformViewportAndroid.java", - ] - - jni_package = "mojo" - } -} else { - mojo_native_application("native_viewport") { - output_name = "native_viewport_service" - sources = [ - "main.cc", - ] - deps = [ - ":lib", - "//base", - "//components/gles2", - "//mojo/application", - "//mojo/common:tracing_impl", - "//third_party/mojo/src/mojo/public/cpp/bindings:bindings", - "//third_party/mojo_services/src/native_viewport/public/interfaces", - "//third_party/mojo_services/src/native_viewport/public/cpp:args", - "//ui/events", - "//ui/events/platform", - "//ui/gl", - ] - } -} - -source_set("lib") { - sources = [ - "native_viewport_impl.cc", - "native_viewport_impl.h", - "onscreen_context_provider.cc", - "onscreen_context_provider.h", - "platform_viewport.h", - "platform_viewport_android.cc", - "platform_viewport_android.h", - "platform_viewport_headless.cc", - "platform_viewport_headless.h", - "platform_viewport_stub.cc", - "platform_viewport_win.cc", - "platform_viewport_x11.cc", - ] - - if (!is_ios) { - sources -= [ "platform_viewport_stub.cc" ] - } - - deps = [ - "//base", - "//components/gles2", - "//gpu/command_buffer/service", - "//mojo/application", - "//mojo/common", - "//mojo/converters/geometry", - "//mojo/converters/input_events", - "//mojo/environment:chromium", - "//third_party/mojo_services/src/geometry/public/interfaces", - "//third_party/mojo_services/src/native_viewport/public/interfaces", - "//ui/events", - "//ui/events/platform", - "//ui/gfx", - "//ui/gfx/geometry", - "//ui/gl", - "//ui/platform_window", - ] - - if (is_android) { - deps += [ ":jni_headers" ] - } - - if (use_x11) { - deps += [ "//ui/platform_window/x11" ] - } else { - sources -= [ "platform_viewport_x11.cc" ] - } - - if (is_win) { - deps += [ "//ui/platform_window/win:win_window" ] - } -} diff --git a/mojo/services/native_viewport/DEPS b/mojo/services/native_viewport/DEPS deleted file mode 100644 index cfb361f..0000000 --- a/mojo/services/native_viewport/DEPS +++ /dev/null @@ -1,7 +0,0 @@ -include_rules = [ - "+components/gles2", - "+mojo/application", - "+mojo/converters", - "+third_party/mojo_services", - "+ui", -] diff --git a/mojo/services/native_viewport/android/src/org/chromium/mojo/PlatformViewportAndroid.java b/mojo/services/native_viewport/android/src/org/chromium/mojo/PlatformViewportAndroid.java deleted file mode 100644 index 189bc07..0000000 --- a/mojo/services/native_viewport/android/src/org/chromium/mojo/PlatformViewportAndroid.java +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright 2013 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. - -package org.chromium.mojo; - -import android.app.Activity; -import android.content.Context; -import android.view.KeyEvent; -import android.view.MotionEvent; -import android.view.Surface; -import android.view.SurfaceHolder; -import android.view.SurfaceView; -import android.view.View; - -import org.chromium.base.CalledByNative; -import org.chromium.base.JNINamespace; - -/** - * Exposes SurfaceView to native code. - */ -@JNINamespace("native_viewport") -public class PlatformViewportAndroid extends SurfaceView { - - private long mNativeMojoViewport; - private final SurfaceHolder.Callback mSurfaceCallback; - - @CalledByNative - public static PlatformViewportAndroid createForActivity( - Activity activity, long nativeViewport) { - PlatformViewportAndroid rv = new PlatformViewportAndroid(activity, nativeViewport); - activity.setContentView(rv); - return rv; - } - - public PlatformViewportAndroid(Context context, long nativeViewport) { - super(context); - - setFocusable(true); - setFocusableInTouchMode(true); - - mNativeMojoViewport = nativeViewport; - assert mNativeMojoViewport != 0; - - final float density = context.getResources().getDisplayMetrics().density; - - mSurfaceCallback = new SurfaceHolder.Callback() { - @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - assert mNativeMojoViewport != 0; - nativeSurfaceSetSize(mNativeMojoViewport, width, height, density); - } - - @Override - public void surfaceCreated(SurfaceHolder holder) { - assert mNativeMojoViewport != 0; - nativeSurfaceCreated(mNativeMojoViewport, holder.getSurface()); - } - - @Override - public void surfaceDestroyed(SurfaceHolder holder) { - assert mNativeMojoViewport != 0; - nativeSurfaceDestroyed(mNativeMojoViewport); - } - }; - getHolder().addCallback(mSurfaceCallback); - - } - - @CalledByNative - public void detach() { - getHolder().removeCallback(mSurfaceCallback); - mNativeMojoViewport = 0; - } - - @Override - protected void onWindowVisibilityChanged(int visibility) { - super.onWindowVisibilityChanged(visibility); - if (visibility == View.VISIBLE) { - requestFocusFromTouch(); - requestFocus(); - } - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - final int actionMasked = event.getActionMasked(); - if (actionMasked == MotionEvent.ACTION_POINTER_DOWN - || actionMasked == MotionEvent.ACTION_POINTER_UP) { - // Up/down events identify a single point. - return notifyTouchEventAtIndex(event, event.getActionIndex()); - } - assert event.getPointerCount() != 0; - // All other types can have more than one point. - boolean result = false; - for (int i = 0, count = event.getPointerCount(); i < count; i++) { - final boolean sub_result = notifyTouchEventAtIndex(event, i); - result |= sub_result; - } - return result; - } - - @Override - public boolean dispatchKeyEvent(KeyEvent event) { - if (privateDispatchKeyEvent(event)) { - return true; - } - return super.dispatchKeyEvent(event); - } - - @Override - public boolean dispatchKeyEventPreIme(KeyEvent event) { - if (privateDispatchKeyEvent(event)) { - return true; - } - return super.dispatchKeyEventPreIme(event); - } - - @Override - public boolean dispatchKeyShortcutEvent(KeyEvent event) { - if (privateDispatchKeyEvent(event)) { - return true; - } - return super.dispatchKeyShortcutEvent(event); - } - - private boolean notifyTouchEventAtIndex(MotionEvent event, int index) { - return nativeTouchEvent(mNativeMojoViewport, event.getEventTime(), event.getActionMasked(), - event.getPointerId(index), event.getX(index), event.getY(index), - event.getPressure(index), event.getTouchMajor(index), event.getTouchMinor(index), - event.getOrientation(index), event.getAxisValue(MotionEvent.AXIS_HSCROLL, index), - event.getAxisValue(MotionEvent.AXIS_VSCROLL, index)); - } - - private boolean privateDispatchKeyEvent(KeyEvent event) { - if (event.getAction() == KeyEvent.ACTION_MULTIPLE) { - boolean result = false; - if (event.getKeyCode() == KeyEvent.KEYCODE_UNKNOWN && event.getCharacters() != null) { - String characters = event.getCharacters(); - for (int i = 0; i < characters.length(); ++i) { - char c = characters.charAt(i); - int codepoint = c; - if (codepoint >= Character.MIN_SURROGATE - && codepoint < (Character.MAX_SURROGATE + 1)) { - i++; - char c2 = characters.charAt(i); - codepoint = Character.toCodePoint(c, c2); - } - result |= nativeKeyEvent(mNativeMojoViewport, true, 0, codepoint); - result |= nativeKeyEvent(mNativeMojoViewport, false, 0, codepoint); - } - } else { - for (int i = 0; i < event.getRepeatCount(); ++i) { - result |= nativeKeyEvent( - mNativeMojoViewport, true, event.getKeyCode(), event.getUnicodeChar()); - result |= nativeKeyEvent( - mNativeMojoViewport, false, event.getKeyCode(), event.getUnicodeChar()); - } - } - return result; - } else { - return nativeKeyEvent(mNativeMojoViewport, event.getAction() == KeyEvent.ACTION_DOWN, - event.getKeyCode(), event.getUnicodeChar()); - } - } - - private static native void nativeDestroy(long nativePlatformViewportAndroid); - - private static native void nativeSurfaceCreated( - long nativePlatformViewportAndroid, Surface surface); - - private static native void nativeSurfaceDestroyed( - long nativePlatformViewportAndroid); - - private static native void nativeSurfaceSetSize( - long nativePlatformViewportAndroid, int width, int height, float density); - - private static native boolean nativeTouchEvent(long nativePlatformViewportAndroid, long timeMs, - int maskedAction, int pointerId, float x, float y, float pressure, float touchMajor, - float touchMinor, float orientation, float hWheel, float vWheel); - - private static native boolean nativeKeyEvent( - long nativePlatformViewportAndroid, boolean pressed, int keyCode, int unicodeCharacter); -} diff --git a/mojo/services/native_viewport/main.cc b/mojo/services/native_viewport/main.cc deleted file mode 100644 index 35f6bd2..0000000 --- a/mojo/services/native_viewport/main.cc +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2014 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 <algorithm> - -#include "base/command_line.h" -#include "base/macros.h" -#include "base/message_loop/message_loop.h" -#include "components/gles2/gpu_impl.h" -#include "mojo/application/application_runner_chromium.h" -#include "mojo/common/tracing_impl.h" -#include "mojo/public/c/system/main.h" -#include "mojo/public/cpp/application/application_connection.h" -#include "mojo/public/cpp/application/application_delegate.h" -#include "mojo/public/cpp/application/application_impl.h" -#include "mojo/public/cpp/application/interface_factory_impl.h" -#include "mojo/services/native_viewport/native_viewport_impl.h" -#include "third_party/mojo_services/src/native_viewport/public/cpp/args.h" -#include "ui/events/event_switches.h" -#include "ui/gl/gl_surface.h" - -using mojo::ApplicationConnection; -using mojo::Gpu; -using mojo::NativeViewport; - -namespace native_viewport { - -class NativeViewportAppDelegate : public mojo::ApplicationDelegate, - public mojo::InterfaceFactory<NativeViewport>, - public mojo::InterfaceFactory<Gpu> { - public: - NativeViewportAppDelegate() : is_headless_(false) {} - ~NativeViewportAppDelegate() override {} - - private: - // mojo::ApplicationDelegate implementation. - void Initialize(mojo::ApplicationImpl* application) override { - tracing_.Initialize(application); - -#if defined(OS_LINUX) - // Apply the switch for kTouchEvents to CommandLine (if set). This allows - // redirecting the mouse to a touch device on X for testing. - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - const std::string touch_event_string("--" + - std::string(switches::kTouchDevices)); - auto touch_iter = std::find(application->args().begin(), - application->args().end(), - touch_event_string); - if (touch_iter != application->args().end() && - ++touch_iter != application->args().end()) { - command_line->AppendSwitchASCII(touch_event_string, *touch_iter); - } -#endif - - if (application->HasArg(mojo::kUseTestConfig)) - gfx::GLSurface::InitializeOneOffForTests(); - else - gfx::GLSurface::InitializeOneOff(); - - is_headless_ = application->HasArg(mojo::kUseHeadlessConfig); - } - - bool ConfigureIncomingConnection(ApplicationConnection* connection) override { - connection->AddService<NativeViewport>(this); - connection->AddService<Gpu>(this); - return true; - } - - // mojo::InterfaceFactory<NativeViewport> implementation. - void Create(ApplicationConnection* connection, - mojo::InterfaceRequest<NativeViewport> request) override { - if (!gpu_state_.get()) - gpu_state_ = new gles2::GpuState; - new NativeViewportImpl(is_headless_, gpu_state_, request.Pass()); - } - - // mojo::InterfaceFactory<Gpu> implementation. - void Create(ApplicationConnection* connection, - mojo::InterfaceRequest<Gpu> request) override { - if (!gpu_state_.get()) - gpu_state_ = new gles2::GpuState; - new gles2::GpuImpl(request.Pass(), gpu_state_); - } - - scoped_refptr<gles2::GpuState> gpu_state_; - bool is_headless_; - mojo::TracingImpl tracing_; - - DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); -}; -} - -MojoResult MojoMain(MojoHandle shell_handle) { - mojo::ApplicationRunnerChromium runner( - new native_viewport::NativeViewportAppDelegate); - runner.set_message_loop_type(base::MessageLoop::TYPE_UI); - return runner.Run(shell_handle); -} diff --git a/mojo/services/native_viewport/native_viewport_impl.cc b/mojo/services/native_viewport/native_viewport_impl.cc deleted file mode 100644 index 6450d78..0000000 --- a/mojo/services/native_viewport/native_viewport_impl.cc +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2014 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 "mojo/services/native_viewport/native_viewport_impl.h" - -#include "base/auto_reset.h" -#include "base/bind.h" -#include "base/macros.h" -#include "base/message_loop/message_loop.h" -#include "base/time/time.h" -#include "components/gles2/gpu_state.h" -#include "mojo/converters/geometry/geometry_type_converters.h" -#include "mojo/public/cpp/application/interface_factory.h" -#include "mojo/services/native_viewport/platform_viewport_headless.h" -#include "ui/events/event.h" - -namespace native_viewport { - -NativeViewportImpl::NativeViewportImpl( - bool is_headless, - const scoped_refptr<gles2::GpuState>& gpu_state, - mojo::InterfaceRequest<mojo::NativeViewport> request) - : is_headless_(is_headless), - context_provider_(gpu_state), - sent_metrics_(false), - metrics_(mojo::ViewportMetrics::New()), - binding_(this, request.Pass()), - weak_factory_(this) { - binding_.set_error_handler(this); -} - -NativeViewportImpl::~NativeViewportImpl() { - // 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 NativeViewportImpl::Create(mojo::SizePtr size, - const CreateCallback& callback) { - create_callback_ = callback; - metrics_->size = size.Clone(); - if (is_headless_) - platform_viewport_ = PlatformViewportHeadless::Create(this); - else - platform_viewport_ = PlatformViewport::Create(this); - platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>())); -} - -void NativeViewportImpl::RequestMetrics( - const RequestMetricsCallback& callback) { - if (!sent_metrics_) { - callback.Run(metrics_.Clone()); - sent_metrics_ = true; - return; - } - metrics_callback_ = callback; -} - -void NativeViewportImpl::Show() { - platform_viewport_->Show(); -} - -void NativeViewportImpl::Hide() { - platform_viewport_->Hide(); -} - -void NativeViewportImpl::Close() { - DCHECK(platform_viewport_); - platform_viewport_->Close(); -} - -void NativeViewportImpl::SetSize(mojo::SizePtr size) { - platform_viewport_->SetBounds(gfx::Rect(size.To<gfx::Size>())); -} - -void NativeViewportImpl::GetContextProvider( - mojo::InterfaceRequest<mojo::ContextProvider> request) { - context_provider_.Bind(request.Pass()); -} - -void NativeViewportImpl::SetEventDispatcher( - mojo::NativeViewportEventDispatcherPtr dispatcher) { - event_dispatcher_ = dispatcher.Pass(); -} - -void NativeViewportImpl::OnMetricsChanged(mojo::ViewportMetricsPtr metrics) { - if (metrics_->Equals(*metrics)) - return; - - metrics_ = metrics.Pass(); - sent_metrics_ = false; - - if (!metrics_callback_.is_null()) { - metrics_callback_.Run(metrics_.Clone()); - metrics_callback_.reset(); - sent_metrics_ = true; - } -} - -void NativeViewportImpl::OnAcceleratedWidgetAvailable( - gfx::AcceleratedWidget widget) { - 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. - create_callback_.Run(metrics_.Clone()); - sent_metrics_ = true; - create_callback_.reset(); -} - -void NativeViewportImpl::OnAcceleratedWidgetDestroyed() { - context_provider_.SetAcceleratedWidget(gfx::kNullAcceleratedWidget); -} - -bool NativeViewportImpl::OnEvent(mojo::EventPtr event) { - if (event.is_null() || !event_dispatcher_.get()) - return false; - - mojo::NativeViewportEventDispatcher::OnEventCallback callback; - switch (event->action) { - case mojo::EVENT_TYPE_POINTER_MOVE: { - // TODO(sky): add logic to remember last event location and not send if - // the same. - if (pointers_waiting_on_ack_.count(event->pointer_data->pointer_id)) - return false; - - pointers_waiting_on_ack_.insert(event->pointer_data->pointer_id); - callback = - base::Bind(&NativeViewportImpl::AckEvent, weak_factory_.GetWeakPtr(), - event->pointer_data->pointer_id); - break; - } - - case mojo::EVENT_TYPE_POINTER_CANCEL: - pointers_waiting_on_ack_.clear(); - break; - - case mojo::EVENT_TYPE_POINTER_UP: - pointers_waiting_on_ack_.erase(event->pointer_data->pointer_id); - break; - - default: - break; - } - - event_dispatcher_->OnEvent(event.Pass(), callback); - return false; -} - -void NativeViewportImpl::OnDestroyed() { - // This will signal a connection error and cause us to delete |this|. - binding_.Close(); -} - -void NativeViewportImpl::OnConnectionError() { - binding_.set_error_handler(nullptr); - delete this; -} - -void NativeViewportImpl::AckEvent(int32 pointer_id) { - pointers_waiting_on_ack_.erase(pointer_id); -} - -} // namespace native_viewport diff --git a/mojo/services/native_viewport/native_viewport_impl.h b/mojo/services/native_viewport/native_viewport_impl.h deleted file mode 100644 index 3c2344a..0000000 --- a/mojo/services/native_viewport/native_viewport_impl.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2014 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. - -#ifndef SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ -#define SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ - -#include <set> - -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "mojo/public/cpp/bindings/strong_binding.h" -#include "mojo/services/native_viewport/onscreen_context_provider.h" -#include "mojo/services/native_viewport/platform_viewport.h" -#include "third_party/mojo_services/src/gpu/public/interfaces/gpu.mojom.h" -#include "third_party/mojo_services/src/native_viewport/public/interfaces/native_viewport.mojom.h" -#include "ui/gfx/geometry/rect.h" - -namespace gles2 { -class GpuState; -} - -namespace ui { -class Event; -} - -namespace native_viewport { - -// A NativeViewportImpl is bound to a message pipe and to a PlatformViewport. -// The NativeViewportImpl's lifetime ends when either the message pipe is closed -// or the PlatformViewport informs the NativeViewportImpl that it has been -// destroyed. -class NativeViewportImpl : public mojo::NativeViewport, - public PlatformViewport::Delegate, - public mojo::ErrorHandler { - public: - NativeViewportImpl(bool is_headless, - const scoped_refptr<gles2::GpuState>& gpu_state, - mojo::InterfaceRequest<mojo::NativeViewport> request); - ~NativeViewportImpl() override; - - // NativeViewport implementation. - void Create(mojo::SizePtr size, const CreateCallback& callback) override; - void RequestMetrics(const RequestMetricsCallback& callback) override; - void Show() override; - void Hide() override; - void Close() override; - void SetSize(mojo::SizePtr size) override; - void GetContextProvider( - mojo::InterfaceRequest<mojo::ContextProvider> request) override; - void SetEventDispatcher( - mojo::NativeViewportEventDispatcherPtr dispatcher) override; - - // PlatformViewport::Delegate implementation. - void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override; - void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override; - void OnAcceleratedWidgetDestroyed() override; - bool OnEvent(mojo::EventPtr event) override; - void OnDestroyed() override; - - // mojo::ErrorHandler implementation. - void OnConnectionError() override; - - private: - // Callback when the dispatcher has processed a message we're waiting on - // an ack from. |pointer_id| identifies the pointer the message was associated - // with. - void AckEvent(int32 pointer_id); - - bool is_headless_; - scoped_ptr<PlatformViewport> platform_viewport_; - OnscreenContextProvider context_provider_; - bool sent_metrics_; - mojo::ViewportMetricsPtr metrics_; - CreateCallback create_callback_; - RequestMetricsCallback metrics_callback_; - mojo::NativeViewportEventDispatcherPtr event_dispatcher_; - mojo::Binding<mojo::NativeViewport> binding_; - - // Set of pointer_ids we've sent a move to and are waiting on an ack. - std::set<int32> pointers_waiting_on_ack_; - - base::WeakPtrFactory<NativeViewportImpl> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(NativeViewportImpl); -}; - -} // namespace native_viewport - -#endif // SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ diff --git a/mojo/services/native_viewport/onscreen_context_provider.cc b/mojo/services/native_viewport/onscreen_context_provider.cc deleted file mode 100644 index da72837..0000000 --- a/mojo/services/native_viewport/onscreen_context_provider.cc +++ /dev/null @@ -1,58 +0,0 @@ -// 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 "mojo/services/native_viewport/onscreen_context_provider.h" - -#include "components/gles2/command_buffer_driver.h" -#include "components/gles2/command_buffer_impl.h" -#include "components/gles2/gpu_state.h" - -namespace native_viewport { - -OnscreenContextProvider::OnscreenContextProvider( - const scoped_refptr<gles2::GpuState>& state) - : state_(state), widget_(gfx::kNullAcceleratedWidget), binding_(this) { -} - -OnscreenContextProvider::~OnscreenContextProvider() { -} - -void OnscreenContextProvider::Bind( - mojo::InterfaceRequest<mojo::ContextProvider> request) { - binding_.Bind(request.Pass()); -} - -void OnscreenContextProvider::SetAcceleratedWidget( - gfx::AcceleratedWidget widget) { - widget_ = widget; - if (widget_ != gfx::kNullAcceleratedWidget && - !pending_create_callback_.is_null()) - CreateAndReturnCommandBuffer(); -} - -void OnscreenContextProvider::Create( - mojo::ViewportParameterListenerPtr viewport_parameter_listener, - const CreateCallback& callback) { - if (!pending_create_callback_.is_null()) - pending_create_callback_.Run(nullptr); - pending_listener_ = viewport_parameter_listener.Pass(); - pending_create_callback_ = callback; - - if (widget_ != gfx::kNullAcceleratedWidget) - CreateAndReturnCommandBuffer(); -} - -void OnscreenContextProvider::CreateAndReturnCommandBuffer() { - mojo::CommandBufferPtr cb; - new gles2::CommandBufferImpl( - GetProxy(&cb), pending_listener_.Pass(), state_->control_task_runner(), - state_->sync_point_manager(), - make_scoped_ptr(new gles2::CommandBufferDriver( - widget_, state_->share_group(), state_->mailbox_manager(), - state_->sync_point_manager()))); - pending_create_callback_.Run(cb.Pass()); - pending_create_callback_.reset(); -} - -} // namespace mojo diff --git a/mojo/services/native_viewport/onscreen_context_provider.h b/mojo/services/native_viewport/onscreen_context_provider.h deleted file mode 100644 index e8a05d5..0000000 --- a/mojo/services/native_viewport/onscreen_context_provider.h +++ /dev/null @@ -1,46 +0,0 @@ -// 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. - -#ifndef SERVICES_NATIVE_VIEWPORT_ONSCREEN_CONTEXT_PROVIDER_H_ -#define SERVICES_NATIVE_VIEWPORT_ONSCREEN_CONTEXT_PROVIDER_H_ - -#include "base/memory/ref_counted.h" -#include "third_party/mojo_services/src/gpu/public/interfaces/context_provider.mojom.h" -#include "third_party/mojo_services/src/gpu/public/interfaces/viewport_parameter_listener.mojom.h" -#include "ui/gfx/native_widget_types.h" - -namespace gles2 { -class GpuState; -} - -namespace native_viewport { - -class OnscreenContextProvider : public mojo::ContextProvider { - public: - explicit OnscreenContextProvider(const scoped_refptr<gles2::GpuState>& state); - ~OnscreenContextProvider() override; - - void Bind(mojo::InterfaceRequest<mojo::ContextProvider> request); - - void SetAcceleratedWidget(gfx::AcceleratedWidget widget); - - private: - // mojo::ContextProvider implementation: - void Create(mojo::ViewportParameterListenerPtr viewport_parameter_listener, - const CreateCallback& callback) override; - - void CreateAndReturnCommandBuffer(); - - scoped_refptr<gles2::GpuState> state_; - gfx::AcceleratedWidget widget_; - mojo::ViewportParameterListenerPtr pending_listener_; - CreateCallback pending_create_callback_; - mojo::Binding<mojo::ContextProvider> binding_; - - DISALLOW_COPY_AND_ASSIGN(OnscreenContextProvider); -}; - -} // namespace mojo - -#endif // SERVICES_NATIVE_VIEWPORT_ONSCREEN_CONTEXT_PROVIDER_H_ diff --git a/mojo/services/native_viewport/platform_viewport.h b/mojo/services/native_viewport/platform_viewport.h deleted file mode 100644 index 62594b0..0000000 --- a/mojo/services/native_viewport/platform_viewport.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2013 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. - -#ifndef SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_H_ -#define SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_H_ - -#include "base/memory/scoped_ptr.h" -#include "third_party/mojo_services/src/input_events/public/interfaces/input_events.mojom.h" -#include "third_party/mojo_services/src/native_viewport/public/interfaces/native_viewport.mojom.h" -#include "ui/gfx/geometry/size.h" -#include "ui/gfx/native_widget_types.h" - -namespace gfx { -class Rect; -} - -namespace native_viewport { - -// Encapsulation of platform-specific Viewport. -class PlatformViewport { - public: - class Delegate { - public: - virtual ~Delegate() {} - - virtual void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) = 0; - virtual void OnAcceleratedWidgetAvailable( - gfx::AcceleratedWidget widget) = 0; - virtual void OnAcceleratedWidgetDestroyed() = 0; - virtual bool OnEvent(mojo::EventPtr event) = 0; - virtual void OnDestroyed() = 0; - }; - - virtual ~PlatformViewport() {} - - virtual void Init(const gfx::Rect& bounds) = 0; - virtual void Show() = 0; - virtual void Hide() = 0; - virtual void Close() = 0; - virtual gfx::Size GetSize() = 0; - virtual void SetBounds(const gfx::Rect& bounds) = 0; - - static scoped_ptr<PlatformViewport> Create(Delegate* delegate); -}; - -} // namespace native_viewport - -#endif // SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_H_ diff --git a/mojo/services/native_viewport/platform_viewport_android.cc b/mojo/services/native_viewport/platform_viewport_android.cc deleted file mode 100644 index 124919a..0000000 --- a/mojo/services/native_viewport/platform_viewport_android.cc +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright 2013 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 "mojo/services/native_viewport/platform_viewport_android.h" - -#include <android/input.h> -#include <android/native_window_jni.h> - -#include "base/android/jni_android.h" -#include "jni/PlatformViewportAndroid_jni.h" -#include "mojo/converters/geometry/geometry_type_converters.h" -#include "mojo/converters/input_events/input_events_type_converters.h" -#include "ui/events/event.h" -#include "ui/events/keycodes/keyboard_code_conversion_android.h" -#include "ui/gfx/geometry/point.h" - -namespace native_viewport { -namespace { - -mojo::EventType MotionEventActionToEventType(jint action) { - switch (action) { - case AMOTION_EVENT_ACTION_DOWN: - case AMOTION_EVENT_ACTION_POINTER_DOWN: - return mojo::EVENT_TYPE_POINTER_DOWN; - case AMOTION_EVENT_ACTION_UP: - case AMOTION_EVENT_ACTION_POINTER_UP: - return mojo::EVENT_TYPE_POINTER_UP; - case AMOTION_EVENT_ACTION_MOVE: - return mojo::EVENT_TYPE_POINTER_MOVE; - case AMOTION_EVENT_ACTION_CANCEL: - return mojo::EVENT_TYPE_POINTER_CANCEL; - case AMOTION_EVENT_ACTION_OUTSIDE: - case AMOTION_EVENT_ACTION_HOVER_MOVE: - case AMOTION_EVENT_ACTION_SCROLL: - case AMOTION_EVENT_ACTION_HOVER_ENTER: - case AMOTION_EVENT_ACTION_HOVER_EXIT: - default: - NOTIMPLEMENTED() << "Unimplemented motion action: " << action; - } - return mojo::EVENT_TYPE_UNKNOWN; -} - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// -// PlatformViewportAndroid, public: - -// static -bool PlatformViewportAndroid::Register(JNIEnv* env) { - return RegisterNativesImpl(env); -} - -PlatformViewportAndroid::PlatformViewportAndroid(Delegate* delegate) - : delegate_(delegate), - window_(NULL), - id_generator_(0), - weak_factory_(this) { -} - -PlatformViewportAndroid::~PlatformViewportAndroid() { - if (window_) - ReleaseWindow(); - if (!java_platform_viewport_android_.is_empty()) { - JNIEnv* env = base::android::AttachCurrentThread(); - Java_PlatformViewportAndroid_detach( - env, java_platform_viewport_android_.get(env).obj()); - } -} - -void PlatformViewportAndroid::Destroy(JNIEnv* env, jobject obj) { - delegate_->OnDestroyed(); -} - -void PlatformViewportAndroid::SurfaceCreated(JNIEnv* env, - jobject obj, - jobject jsurface) { - base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); - // Note: This ensures that any local references used by - // ANativeWindow_fromSurface are released immediately. This is needed as a - // workaround for https://code.google.com/p/android/issues/detail?id=68174 - { - base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); - window_ = ANativeWindow_fromSurface(env, jsurface); - } - delegate_->OnAcceleratedWidgetAvailable(window_); -} - -void PlatformViewportAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) { - DCHECK(window_); - delegate_->OnAcceleratedWidgetDestroyed(); - ReleaseWindow(); -} - -void PlatformViewportAndroid::SurfaceSetSize(JNIEnv* env, - jobject obj, - jint width, - jint height, - jfloat density) { - metrics_ = mojo::ViewportMetrics::New(); - metrics_->size = mojo::Size::New(); - metrics_->size->width = static_cast<int>(width); - metrics_->size->height = static_cast<int>(height); - metrics_->device_pixel_ratio = density; - delegate_->OnMetricsChanged(metrics_.Clone()); -} - -bool PlatformViewportAndroid::TouchEvent(JNIEnv* env, - jobject obj, - jlong time_ms, - jint masked_action, - jint pointer_id, - jfloat x, - jfloat y, - jfloat pressure, - jfloat touch_major, - jfloat touch_minor, - jfloat orientation, - jfloat h_wheel, - jfloat v_wheel) { - mojo::EventPtr event(mojo::Event::New()); - event->time_stamp = - (base::TimeTicks() + base::TimeDelta::FromMilliseconds(time_ms)) - .ToInternalValue(); - event->action = MotionEventActionToEventType(masked_action); - if (event->action == mojo::EVENT_TYPE_UNKNOWN) - return false; - - event->pointer_data = mojo::PointerData::New(); - event->pointer_data->pointer_id = pointer_id; - event->pointer_data->x = x; - event->pointer_data->y = y; - event->pointer_data->screen_x = x; - event->pointer_data->screen_y = y; - event->pointer_data->pressure = pressure; - event->pointer_data->radius_major = touch_major; - event->pointer_data->radius_minor = touch_minor; - event->pointer_data->orientation = orientation; - event->pointer_data->horizontal_wheel = h_wheel; - event->pointer_data->vertical_wheel = v_wheel; - delegate_->OnEvent(event.Pass()); - - return true; -} - -bool PlatformViewportAndroid::KeyEvent(JNIEnv* env, - jobject obj, - bool pressed, - jint key_code, - jint unicode_character) { - ui::KeyEvent event(pressed ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, - ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); - event.set_platform_keycode(key_code); - delegate_->OnEvent(mojo::Event::From(event)); - if (pressed && unicode_character) { - ui::KeyEvent char_event(unicode_character, - ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); - char_event.set_platform_keycode(key_code); - delegate_->OnEvent(mojo::Event::From(char_event)); - } - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -// PlatformViewportAndroid, PlatformViewport implementation: - -void PlatformViewportAndroid::Init(const gfx::Rect& bounds) { - JNIEnv* env = base::android::AttachCurrentThread(); - java_platform_viewport_android_ = JavaObjectWeakGlobalRef( - env, Java_PlatformViewportAndroid_createForActivity( - env, base::android::GetApplicationContext(), - reinterpret_cast<jlong>(this)).obj()); -} - -void PlatformViewportAndroid::Show() { - // Nothing to do. View is created visible. -} - -void PlatformViewportAndroid::Hide() { - // Nothing to do. View is always visible. -} - -void PlatformViewportAndroid::Close() { - // TODO(beng): close activity containing MojoView? - - // TODO(beng): perform this in response to view destruction. - delegate_->OnDestroyed(); -} - -gfx::Size PlatformViewportAndroid::GetSize() { - return metrics_->size.To<gfx::Size>(); -} - -void PlatformViewportAndroid::SetBounds(const gfx::Rect& bounds) { - NOTIMPLEMENTED(); -} - -//////////////////////////////////////////////////////////////////////////////// -// PlatformViewportAndroid, private: - -void PlatformViewportAndroid::ReleaseWindow() { - ANativeWindow_release(window_); - window_ = NULL; -} - -//////////////////////////////////////////////////////////////////////////////// -// PlatformViewport, public: - -// static -scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { - return scoped_ptr<PlatformViewport>( - new PlatformViewportAndroid(delegate)).Pass(); -} - -} // namespace native_viewport diff --git a/mojo/services/native_viewport/platform_viewport_android.h b/mojo/services/native_viewport/platform_viewport_android.h deleted file mode 100644 index b3a0b86..0000000 --- a/mojo/services/native_viewport/platform_viewport_android.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2013 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. - -#ifndef SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_ANDROID_H_ -#define SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_ANDROID_H_ - -#include "base/android/jni_weak_ref.h" -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "mojo/services/native_viewport/platform_viewport.h" -#include "ui/events/event_constants.h" -#include "ui/gfx/geometry/rect.h" -#include "ui/gfx/geometry/size.h" -#include "ui/gfx/sequential_id_generator.h" - -namespace gpu { -class GLInProcessContext; -} - -struct ANativeWindow; - -namespace native_viewport { - -class PlatformViewportAndroid : public PlatformViewport { - public: - static bool Register(JNIEnv* env); - - explicit PlatformViewportAndroid(Delegate* delegate); - virtual ~PlatformViewportAndroid(); - - void Destroy(JNIEnv* env, jobject obj); - void SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface); - void SurfaceDestroyed(JNIEnv* env, jobject obj); - void SurfaceSetSize(JNIEnv* env, - jobject obj, - jint width, - jint height, - jfloat density); - bool TouchEvent(JNIEnv* env, - jobject obj, - jlong time_ms, - jint masked_action, - jint pointer_id, - jfloat x, - jfloat y, - jfloat pressure, - jfloat touch_major, - jfloat touch_minor, - jfloat orientation, - jfloat h_wheel, - jfloat v_wheel); - bool KeyEvent(JNIEnv* env, - jobject obj, - bool pressed, - jint key_code, - jint unicode_character); - - private: - // Overridden from PlatformViewport: - virtual void Init(const gfx::Rect& bounds) override; - virtual void Show() override; - virtual void Hide() override; - virtual void Close() override; - virtual gfx::Size GetSize() override; - virtual void SetBounds(const gfx::Rect& bounds) override; - - void ReleaseWindow(); - - Delegate* const delegate_; - JavaObjectWeakGlobalRef java_platform_viewport_android_; - ANativeWindow* window_; - mojo::ViewportMetricsPtr metrics_; - ui::SequentialIDGenerator id_generator_; - - base::WeakPtrFactory<PlatformViewportAndroid> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(PlatformViewportAndroid); -}; - -} // namespace native_viewport - -#endif // SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_ANDROID_H_ diff --git a/mojo/services/native_viewport/platform_viewport_headless.cc b/mojo/services/native_viewport/platform_viewport_headless.cc deleted file mode 100644 index af3cec7..0000000 --- a/mojo/services/native_viewport/platform_viewport_headless.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2013 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 "mojo/services/native_viewport/platform_viewport_headless.h" - -#include "mojo/converters/geometry/geometry_type_converters.h" - -namespace native_viewport { - -PlatformViewportHeadless::PlatformViewportHeadless(Delegate* delegate) - : delegate_(delegate) { -} - -PlatformViewportHeadless::~PlatformViewportHeadless() { -} - -void PlatformViewportHeadless::Init(const gfx::Rect& bounds) { - metrics_ = mojo::ViewportMetrics::New(); - metrics_->size = mojo::Size::From(bounds.size()); -} - -void PlatformViewportHeadless::Show() { -} - -void PlatformViewportHeadless::Hide() { -} - -void PlatformViewportHeadless::Close() { - delegate_->OnDestroyed(); -} - -gfx::Size PlatformViewportHeadless::GetSize() { - return metrics_->size.To<gfx::Size>(); -} - -void PlatformViewportHeadless::SetBounds(const gfx::Rect& bounds) { - metrics_->size = mojo::Size::From(bounds.size()); - delegate_->OnMetricsChanged(metrics_->Clone()); -} - -// static -scoped_ptr<PlatformViewport> PlatformViewportHeadless::Create( - Delegate* delegate) { - return scoped_ptr<PlatformViewport>( - new PlatformViewportHeadless(delegate)).Pass(); -} - -} // namespace native_viewport diff --git a/mojo/services/native_viewport/platform_viewport_headless.h b/mojo/services/native_viewport/platform_viewport_headless.h deleted file mode 100644 index fe7d148..0000000 --- a/mojo/services/native_viewport/platform_viewport_headless.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2013 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. - -#ifndef SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_HEADLESS_H_ -#define SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_HEADLESS_H_ - -#include "base/macros.h" -#include "mojo/services/native_viewport/platform_viewport.h" -#include "ui/gfx/geometry/rect.h" - -namespace native_viewport { - -class PlatformViewportHeadless : public PlatformViewport { - public: - ~PlatformViewportHeadless() override; - - static scoped_ptr<PlatformViewport> Create(Delegate* delegate); - - private: - explicit PlatformViewportHeadless(Delegate* delegate); - - // Overridden from PlatformViewport: - void Init(const gfx::Rect& bounds) override; - void Show() override; - void Hide() override; - void Close() override; - gfx::Size GetSize() override; - void SetBounds(const gfx::Rect& bounds) override; - - Delegate* delegate_; - mojo::ViewportMetricsPtr metrics_; - - DISALLOW_COPY_AND_ASSIGN(PlatformViewportHeadless); -}; - -} // namespace native_viewport - -#endif // SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_HEADLESS_H_ diff --git a/mojo/services/native_viewport/platform_viewport_stub.cc b/mojo/services/native_viewport/platform_viewport_stub.cc deleted file mode 100644 index 80a7e94..0000000 --- a/mojo/services/native_viewport/platform_viewport_stub.cc +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2014 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 "mojo/services/native_viewport/platform_viewport_headless.h" - -namespace mojo { - -// static -scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { - return PlatformViewportHeadless::Create(delegate); -} - -} // namespace mojo diff --git a/mojo/services/native_viewport/platform_viewport_win.cc b/mojo/services/native_viewport/platform_viewport_win.cc deleted file mode 100644 index 8dcd589..0000000 --- a/mojo/services/native_viewport/platform_viewport_win.cc +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2013 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 "mojo/services/native_viewport/platform_viewport.h" - -#include "base/memory/scoped_ptr.h" -#include "mojo/converters/geometry/geometry_type_converters.h" -#include "mojo/converters/input_events/input_events_type_converters.h" -#include "ui/events/event.h" -#include "ui/gfx/geometry/rect.h" -#include "ui/platform_window/platform_window_delegate.h" -#include "ui/platform_window/win/win_window.h" - -namespace native_viewport { -namespace { -float ConvertUIWheelValueToMojoValue(int offset) { - // Mojo's event type takes a value between -1 and 1. Normalize by allowing - // up to 20 of ui's offset. This is a bit arbitrary. - return std::max( - -1.0f, std::min(1.0f, static_cast<float>(offset) / - (20 * static_cast<float>( - ui::MouseWheelEvent::kWheelDelta)))); -} -} // namespace - -class PlatformViewportWin : public PlatformViewport, - public ui::PlatformWindowDelegate { - public: - explicit PlatformViewportWin(Delegate* delegate) - : delegate_(delegate) { - } - - ~PlatformViewportWin() { - // Destroy the platform-window while |this| is still alive. - platform_window_.reset(); - } - - private: - // Overridden from PlatformViewport: - void Init(const gfx::Rect& bounds) override { - metrics_ = mojo::ViewportMetrics::New(); - metrics_->size = mojo::Size::From(bounds.size()); - platform_window_.reset(new ui::WinWindow(this, bounds)); - } - - void Show() override { - platform_window_->Show(); - } - - void Hide() override { - platform_window_->Hide(); - } - - void Close() override { - platform_window_->Close(); - } - - gfx::Size GetSize() override { return metrics_->size.To<gfx::Size>(); } - - void SetBounds(const gfx::Rect& bounds) override { - platform_window_->SetBounds(bounds); - } - - // ui::PlatformWindowDelegate: - void OnBoundsChanged(const gfx::Rect& new_bounds) override { - metrics_->size = mojo::Size::From(new_bounds.size()); - delegate_->OnMetricsChanged(metrics_.Clone()); - } - - void OnDamageRect(const gfx::Rect& damaged_region) override { - } - - void DispatchEvent(ui::Event* event) override { - // TODO(jam): this code is copied from the X11 version. - mojo::EventPtr mojo_event(mojo::Event::From(*event)); - if (event->IsMouseWheelEvent()) { - // Mojo's event type has a different meaning for wheel events. Convert - // between the two. - ui::MouseWheelEvent* wheel_event = - static_cast<ui::MouseWheelEvent*>(event); - DCHECK(mojo_event->pointer_data); - mojo_event->pointer_data->horizontal_wheel = - ConvertUIWheelValueToMojoValue(wheel_event->x_offset()); - mojo_event->pointer_data->horizontal_wheel = - ConvertUIWheelValueToMojoValue(wheel_event->y_offset()); - } - delegate_->OnEvent(mojo_event.Pass()); - - switch (event->type()) { - case ui::ET_MOUSE_PRESSED: - case ui::ET_TOUCH_PRESSED: - platform_window_->SetCapture(); - break; - case ui::ET_MOUSE_RELEASED: - case ui::ET_TOUCH_RELEASED: - platform_window_->ReleaseCapture(); - break; - default: - break; - } - } - - void OnCloseRequest() override { - platform_window_->Close(); - } - - void OnClosed() override { - delegate_->OnDestroyed(); - } - - void OnWindowStateChanged(ui::PlatformWindowState state) override { - } - - void OnLostCapture() override { - } - - void OnAcceleratedWidgetAvailable( - gfx::AcceleratedWidget widget) override { - delegate_->OnAcceleratedWidgetAvailable(widget); - } - - void OnActivationChanged(bool active) override {} - - scoped_ptr<ui::PlatformWindow> platform_window_; - Delegate* delegate_; - mojo::ViewportMetricsPtr metrics_; - - DISALLOW_COPY_AND_ASSIGN(PlatformViewportWin); -}; - -// static -scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { - return scoped_ptr<PlatformViewport>(new PlatformViewportWin(delegate)).Pass(); -} - -} // namespace native_viewport diff --git a/mojo/services/native_viewport/platform_viewport_x11.cc b/mojo/services/native_viewport/platform_viewport_x11.cc deleted file mode 100644 index a3cff26..0000000 --- a/mojo/services/native_viewport/platform_viewport_x11.cc +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright 2013 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 "mojo/services/native_viewport/platform_viewport.h" - -#include "base/command_line.h" -#include "base/message_loop/message_loop.h" -#include "mojo/converters/geometry/geometry_type_converters.h" -#include "mojo/converters/input_events/input_events_type_converters.h" -#include "mojo/converters/input_events/mojo_extended_key_event_data.h" -#include "ui/events/event.h" -#include "ui/events/event_utils.h" -#include "ui/events/platform/platform_event_dispatcher.h" -#include "ui/events/platform/platform_event_source.h" -#include "ui/gfx/geometry/rect.h" -#include "ui/platform_window/platform_window.h" -#include "ui/platform_window/platform_window_delegate.h" -#include "ui/platform_window/x11/x11_window.h" - -namespace native_viewport { -namespace { - -float ConvertUIWheelValueToMojoValue(int offset) { - // Mojo's event type takes a value between -1 and 1. Normalize by allowing - // up to 20 of ui's offset. This is a bit arbitrary. - return std::max( - -1.0f, std::min(1.0f, static_cast<float>(offset) / - (20 * static_cast<float>( - ui::MouseWheelEvent::kWheelDelta)))); -} -} // namespace - -class PlatformViewportX11 : public PlatformViewport, - public ui::PlatformWindowDelegate { - public: - explicit PlatformViewportX11(Delegate* delegate) : delegate_(delegate) { - } - - ~PlatformViewportX11() override { - // Destroy the platform-window while |this| is still alive. - platform_window_.reset(); - } - - private: - // Overridden from PlatformViewport: - void Init(const gfx::Rect& bounds) override { - CHECK(!event_source_); - CHECK(!platform_window_); - - event_source_ = ui::PlatformEventSource::CreateDefault(); - - metrics_ = mojo::ViewportMetrics::New(); - metrics_->size = mojo::Size::From(bounds.size()); - - platform_window_.reset(new ui::X11Window(this)); - platform_window_->SetBounds(bounds); - } - - void Show() override { platform_window_->Show(); } - - void Hide() override { platform_window_->Hide(); } - - void Close() override { platform_window_->Close(); } - - gfx::Size GetSize() override { return metrics_->size.To<gfx::Size>(); } - - void SetBounds(const gfx::Rect& bounds) override { - platform_window_->SetBounds(bounds); - } - - // ui::PlatformWindowDelegate: - void OnBoundsChanged(const gfx::Rect& new_bounds) override { - metrics_->size = mojo::Size::From(new_bounds.size()); - delegate_->OnMetricsChanged(metrics_.Clone()); - } - - void OnDamageRect(const gfx::Rect& damaged_region) override {} - - void DispatchEvent(ui::Event* event) override { - mojo::EventPtr mojo_event(mojo::Event::From(*event)); - if (event->IsMouseWheelEvent()) { - // Mojo's event type has a different meaning for wheel events. Convert - // between the two. - ui::MouseWheelEvent* wheel_event = - static_cast<ui::MouseWheelEvent*>(event); - DCHECK(mojo_event->pointer_data); - mojo_event->pointer_data->horizontal_wheel = - ConvertUIWheelValueToMojoValue(wheel_event->x_offset()); - mojo_event->pointer_data->horizontal_wheel = - ConvertUIWheelValueToMojoValue(wheel_event->y_offset()); - } - delegate_->OnEvent(mojo_event.Pass()); - - switch (event->type()) { - case ui::ET_MOUSE_PRESSED: - case ui::ET_TOUCH_PRESSED: - platform_window_->SetCapture(); - break; - case ui::ET_MOUSE_RELEASED: - case ui::ET_TOUCH_RELEASED: - platform_window_->ReleaseCapture(); - break; - default: - break; - } - - // We want to emulate the WM_CHAR generation behaviour of Windows. - // - // On Linux, we've previously inserted characters by having - // InputMethodAuraLinux take all key down events and send a character event - // to the TextInputClient. This causes a mismatch in code that has to be - // shared between Windows and Linux, including blink code. Now that we're - // trying to have one way of doing things, we need to standardize on and - // emulate Windows character events. - // - // This is equivalent to what we're doing in the current Linux port, but - // done once instead of done multiple times in different places. - if (event->type() == ui::ET_KEY_PRESSED) { - ui::KeyEvent* key_press_event = static_cast<ui::KeyEvent*>(event); - ui::KeyEvent char_event(key_press_event->GetCharacter(), - key_press_event->key_code(), - key_press_event->flags()); - - DCHECK_EQ(key_press_event->GetCharacter(), char_event.GetCharacter()); - DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); - DCHECK_EQ(key_press_event->flags(), char_event.flags()); - - char_event.SetExtendedKeyEventData( - make_scoped_ptr(new mojo::MojoExtendedKeyEventData( - key_press_event->GetLocatedWindowsKeyboardCode(), - key_press_event->GetText(), - key_press_event->GetUnmodifiedText()))); - char_event.set_platform_keycode(key_press_event->platform_keycode()); - - delegate_->OnEvent(mojo::Event::From(char_event)); - } - } - - void OnCloseRequest() override { platform_window_->Close(); } - - void OnClosed() override { delegate_->OnDestroyed(); } - - void OnWindowStateChanged(ui::PlatformWindowState state) override {} - - void OnLostCapture() override {} - - void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override { - delegate_->OnAcceleratedWidgetAvailable(widget); - } - - void OnActivationChanged(bool active) override {} - - scoped_ptr<ui::PlatformEventSource> event_source_; - scoped_ptr<ui::PlatformWindow> platform_window_; - Delegate* delegate_; - mojo::ViewportMetricsPtr metrics_; - - DISALLOW_COPY_AND_ASSIGN(PlatformViewportX11); -}; - -// static -scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { - return make_scoped_ptr(new PlatformViewportX11(delegate)); -} - -} // namespace native_viewport diff --git a/mojo/services/surfaces/BUILD.gn b/mojo/services/surfaces/BUILD.gn deleted file mode 100644 index c1f8d2e..0000000 --- a/mojo/services/surfaces/BUILD.gn +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2014 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. - -import("//third_party/mojo/src/mojo/public/mojo_application.gni") - -mojo_native_application("surfaces") { - output_name = "surfaces_service" - sources = [ - "context_provider_mojo.cc", - "context_provider_mojo.h", - "display_factory_impl.cc", - "display_factory_impl.h", - "display_impl.cc", - "display_impl.h", - "surfaces_impl.cc", - "surfaces_impl.h", - "surfaces_output_surface.cc", - "surfaces_output_surface.h", - "surfaces_scheduler.cc", - "surfaces_scheduler.h", - "surfaces_service_application.cc", - "surfaces_service_application.h", - ] - - deps = [ - "//base", - "//cc", - "//cc/surfaces", - "//cc/surfaces:surface_id", - "//gpu/command_buffer/client:gles2_interface", - "//mojo/application", - "//mojo/common", - "//mojo/common:tracing_impl", - "//mojo/converters/geometry", - "//mojo/converters/surfaces", - "//mojo/environment:chromium", - "//third_party/mojo/src/mojo/public/c/gles2", - "//third_party/mojo/src/mojo/public/cpp/bindings", - "//third_party/mojo/src/mojo/public/cpp/environment", - "//third_party/mojo/src/mojo/public/cpp/system", - "//third_party/mojo_services/src/geometry/public/interfaces", - "//third_party/mojo_services/src/gpu/public/interfaces", - "//third_party/mojo_services/src/surfaces/public/interfaces", - "//ui/gfx/geometry", - ] -} diff --git a/mojo/services/surfaces/DEPS b/mojo/services/surfaces/DEPS deleted file mode 100644 index 3b182bf..0000000 --- a/mojo/services/surfaces/DEPS +++ /dev/null @@ -1,7 +0,0 @@ -include_rules = [ - "+cc", - "+gpu", - "+mojo/application", - "+mojo/converters", - "+third_party/mojo_services", -] diff --git a/mojo/services/surfaces/context_provider_mojo.cc b/mojo/services/surfaces/context_provider_mojo.cc deleted file mode 100644 index 2874794..0000000 --- a/mojo/services/surfaces/context_provider_mojo.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2014 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 "mojo/services/surfaces/context_provider_mojo.h" - -#include "base/logging.h" -#include "mojo/public/cpp/environment/environment.h" - -namespace mojo { - -ContextProviderMojo::ContextProviderMojo( - ScopedMessagePipeHandle command_buffer_handle) - : command_buffer_handle_(command_buffer_handle.Pass()), - context_(nullptr), - context_lost_(false) { -} - -bool ContextProviderMojo::BindToCurrentThread() { - DCHECK(command_buffer_handle_.is_valid()); - context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(), - &ContextLostThunk, this, - Environment::GetDefaultAsyncWaiter()); - DCHECK(context_); - return !!context_; -} - -gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() { - if (!context_) - return nullptr; - return static_cast<gpu::gles2::GLES2Interface*>( - MojoGLES2GetGLES2Interface(context_)); -} - -gpu::ContextSupport* ContextProviderMojo::ContextSupport() { - if (!context_) - return nullptr; - return static_cast<gpu::ContextSupport*>( - MojoGLES2GetContextSupport(context_)); -} - -class GrContext* ContextProviderMojo::GrContext() { - return NULL; -} - -cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() { - return capabilities_; -} - -void ContextProviderMojo::SetupLock() { -} - -base::Lock* ContextProviderMojo::GetLock() { - return &context_lock_; -} - -bool ContextProviderMojo::IsContextLost() { - return context_lost_; -} -bool ContextProviderMojo::DestroyedOnMainThread() { - return !context_; -} - -void ContextProviderMojo::SetLostContextCallback( - const LostContextCallback& lost_context_callback) { - lost_context_callback_ = lost_context_callback; -} - -ContextProviderMojo::~ContextProviderMojo() { - if (context_) - MojoGLES2DestroyContext(context_); -} - -void ContextProviderMojo::ContextLost() { - context_lost_ = true; - if (!lost_context_callback_.is_null()) - lost_context_callback_.Run(); -} - -} // namespace mojo diff --git a/mojo/services/surfaces/context_provider_mojo.h b/mojo/services/surfaces/context_provider_mojo.h deleted file mode 100644 index 48d12f2..0000000 --- a/mojo/services/surfaces/context_provider_mojo.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2014 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. - -#ifndef SERVICES_SURFACES_CONTEXT_PROVIDER_MOJO_H_ -#define SERVICES_SURFACES_CONTEXT_PROVIDER_MOJO_H_ - -#include "base/macros.h" -#include "base/synchronization/lock.h" -#include "cc/output/context_provider.h" -#include "mojo/public/c/gles2/gles2.h" -#include "mojo/public/cpp/system/core.h" - -namespace mojo { - -class ContextProviderMojo : public cc::ContextProvider { - public: - explicit ContextProviderMojo(ScopedMessagePipeHandle command_buffer_handle); - - // cc::ContextProvider implementation. - bool BindToCurrentThread() override; - gpu::gles2::GLES2Interface* ContextGL() override; - gpu::ContextSupport* ContextSupport() override; - class GrContext* GrContext() override; - Capabilities ContextCapabilities() override; - bool IsContextLost() override; - void VerifyContexts() override {} - void DeleteCachedResources() override {} - bool DestroyedOnMainThread() override; - void SetLostContextCallback( - const LostContextCallback& lost_context_callback) override; - void SetMemoryPolicyChangedCallback( - const MemoryPolicyChangedCallback& memory_policy_changed_callback) - override {} - void SetupLock() override; - base::Lock* GetLock() override; - - protected: - friend class base::RefCountedThreadSafe<ContextProviderMojo>; - ~ContextProviderMojo() override; - - private: - static void ContextLostThunk(void* closure) { - static_cast<ContextProviderMojo*>(closure)->ContextLost(); - } - void ContextLost(); - - cc::ContextProvider::Capabilities capabilities_; - ScopedMessagePipeHandle command_buffer_handle_; - MojoGLES2Context context_; - bool context_lost_; - LostContextCallback lost_context_callback_; - - base::Lock context_lock_; - - DISALLOW_COPY_AND_ASSIGN(ContextProviderMojo); -}; - -} // namespace mojo - -#endif // SERVICES_SURFACES_CONTEXT_PROVIDER_MOJO_H_ diff --git a/mojo/services/surfaces/display_factory_impl.cc b/mojo/services/surfaces/display_factory_impl.cc deleted file mode 100644 index 11e9bf2..0000000 --- a/mojo/services/surfaces/display_factory_impl.cc +++ /dev/null @@ -1,36 +0,0 @@ -// 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 "mojo/services/surfaces/display_factory_impl.h" - -#include "cc/surfaces/surface_id.h" - -namespace surfaces { - -DisplayFactoryImpl::DisplayFactoryImpl( - cc::SurfaceManager* manager, - uint32_t id_namespace, - SurfacesScheduler* scheduler, - mojo::InterfaceRequest<mojo::DisplayFactory> request) - : id_namespace_(id_namespace), - next_local_id_(1u), - scheduler_(scheduler), - manager_(manager), - binding_(this, request.Pass()) { -} - -DisplayFactoryImpl::~DisplayFactoryImpl() { -} - -void DisplayFactoryImpl::Create( - mojo::ContextProviderPtr context_provider, - mojo::ResourceReturnerPtr returner, - mojo::InterfaceRequest<mojo::Display> display_request) { - cc::SurfaceId cc_id(static_cast<uint64_t>(id_namespace_) << 32 | - next_local_id_++); - new DisplayImpl(manager_, cc_id, scheduler_, context_provider.Pass(), - returner.Pass(), display_request.Pass()); -} - -} // namespace surfaces diff --git a/mojo/services/surfaces/display_factory_impl.h b/mojo/services/surfaces/display_factory_impl.h deleted file mode 100644 index 7a21c43..0000000 --- a/mojo/services/surfaces/display_factory_impl.h +++ /dev/null @@ -1,44 +0,0 @@ -// 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. - -#ifndef SERVICES_SURFACES_DISPLAY_FACTORY_IMPL_H_ -#define SERVICES_SURFACES_DISPLAY_FACTORY_IMPL_H_ - -#include "mojo/public/cpp/bindings/strong_binding.h" -#include "mojo/services/surfaces/display_impl.h" -#include "third_party/mojo_services/src/surfaces/public/interfaces/display.mojom.h" - -namespace cc { -class SurfaceManager; -} - -namespace surfaces { -class SurfacesScheduler; - -class DisplayFactoryImpl : public mojo::DisplayFactory { - public: - DisplayFactoryImpl(cc::SurfaceManager* manager, - uint32_t id_namespace, - SurfacesScheduler* scheduler, - mojo::InterfaceRequest<mojo::DisplayFactory> request); - ~DisplayFactoryImpl() override; - - private: - // mojo::DisplayFactory implementation. - void Create(mojo::ContextProviderPtr context_provider, - mojo::ResourceReturnerPtr returner, - mojo::InterfaceRequest<mojo::Display> display_request) override; - - // We use one ID namespace for all DisplayImpls since the ID is used only by - // cc and not exposed through mojom. - uint32_t id_namespace_; - uint32_t next_local_id_; - SurfacesScheduler* scheduler_; - cc::SurfaceManager* manager_; - mojo::StrongBinding<mojo::DisplayFactory> binding_; -}; - -} // namespace surfaces - -#endif // SERVICES_SURFACES_DISPLAY_FACTORY_IMPL_H_ diff --git a/mojo/services/surfaces/display_impl.cc b/mojo/services/surfaces/display_impl.cc deleted file mode 100644 index 3fff760..0000000 --- a/mojo/services/surfaces/display_impl.cc +++ /dev/null @@ -1,137 +0,0 @@ -// 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 "mojo/services/surfaces/display_impl.h" - -#include "cc/output/compositor_frame.h" -#include "cc/surfaces/display.h" -#include "mojo/converters/geometry/geometry_type_converters.h" -#include "mojo/converters/surfaces/surfaces_type_converters.h" -#include "mojo/services/surfaces/context_provider_mojo.h" -#include "mojo/services/surfaces/surfaces_output_surface.h" -#include "mojo/services/surfaces/surfaces_scheduler.h" - -namespace surfaces { -namespace { -void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) { - callback.Run(); -} -} - -DisplayImpl::DisplayImpl(cc::SurfaceManager* manager, - cc::SurfaceId cc_id, - SurfacesScheduler* scheduler, - mojo::ContextProviderPtr context_provider, - mojo::ResourceReturnerPtr returner, - mojo::InterfaceRequest<mojo::Display> display_request) - : manager_(manager), - factory_(manager, this), - cc_id_(cc_id), - scheduler_(scheduler), - context_provider_(context_provider.Pass()), - returner_(returner.Pass()), - viewport_param_binding_(this), - display_binding_(this, display_request.Pass()) { - mojo::ViewportParameterListenerPtr viewport_parameter_listener; - viewport_param_binding_.Bind(GetProxy(&viewport_parameter_listener)); - context_provider_->Create( - viewport_parameter_listener.Pass(), - base::Bind(&DisplayImpl::OnContextCreated, base::Unretained(this))); -} - -void DisplayImpl::OnContextCreated(mojo::CommandBufferPtr gles2_client) { - DCHECK(!display_); - - cc::RendererSettings settings; - display_.reset(new cc::Display(this, manager_, nullptr, nullptr, settings)); - scheduler_->AddDisplay(display_.get()); - display_->Initialize(make_scoped_ptr(new mojo::DirectOutputSurface( - new mojo::ContextProviderMojo(gles2_client.PassMessagePipe())))); - - factory_.Create(cc_id_); - display_->SetSurfaceId(cc_id_, 1.f); - if (pending_frame_) - Draw(); -} - -DisplayImpl::~DisplayImpl() { - if (display_) { - factory_.Destroy(cc_id_); - scheduler_->RemoveDisplay(display_.get()); - } -} - -void DisplayImpl::SubmitFrame(mojo::FramePtr frame, - const SubmitFrameCallback& callback) { - DCHECK(pending_callback_.is_null()); - pending_frame_ = frame.Pass(); - pending_callback_ = callback; - if (display_) - Draw(); -} - -void DisplayImpl::Draw() { - gfx::Size frame_size = - pending_frame_->passes[0]->output_rect.To<gfx::Rect>().size(); - display_->Resize(frame_size); - factory_.SubmitFrame(cc_id_, - pending_frame_.To<scoped_ptr<cc::CompositorFrame>>(), - base::Bind(&CallCallback, pending_callback_)); - scheduler_->SetNeedsDraw(); - pending_callback_.reset(); -} - -void DisplayImpl::DisplayDamaged() { -} - -void DisplayImpl::DidSwapBuffers() { -} - -void DisplayImpl::DidSwapBuffersComplete() { -} - -void DisplayImpl::CommitVSyncParameters(base::TimeTicks timebase, - base::TimeDelta interval) { -} - -void DisplayImpl::OutputSurfaceLost() { - // If our OutputSurface is lost we can't draw until we get a new one. For now, - // destroy the display and create a new one when our ContextProvider provides - // a new one. - // TODO: This is more violent than necessary - we could simply remove this - // display from the scheduler's set and pass a new context in to the - // OutputSurface. It should be able to reinitialize properly. - scheduler_->RemoveDisplay(display_.get()); - display_.reset(); - factory_.Destroy(cc_id_); - viewport_param_binding_.Close(); - mojo::ViewportParameterListenerPtr viewport_parameter_listener; - viewport_param_binding_.Bind(GetProxy(&viewport_parameter_listener)); - context_provider_->Create( - viewport_parameter_listener.Pass(), - base::Bind(&DisplayImpl::OnContextCreated, base::Unretained(this))); -} - -void DisplayImpl::SetMemoryPolicy(const cc::ManagedMemoryPolicy& policy) { -} - -void DisplayImpl::OnVSyncParametersUpdated(int64_t timebase, int64_t interval) { - scheduler_->OnVSyncParametersUpdated( - base::TimeTicks::FromInternalValue(timebase), - base::TimeDelta::FromInternalValue(interval)); -} - -void DisplayImpl::ReturnResources(const cc::ReturnedResourceArray& resources) { - if (resources.empty()) - return; - DCHECK(returner_); - - mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size()); - for (size_t i = 0; i < resources.size(); ++i) { - ret[i] = mojo::ReturnedResource::From(resources[i]); - } - returner_->ReturnResources(ret.Pass()); -} - -} // namespace surfaces diff --git a/mojo/services/surfaces/display_impl.h b/mojo/services/surfaces/display_impl.h deleted file mode 100644 index 19d11e3..0000000 --- a/mojo/services/surfaces/display_impl.h +++ /dev/null @@ -1,80 +0,0 @@ -// 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. - -#ifndef SERVICES_SURFACES_DISPLAY_IMPL_H_ -#define SERVICES_SURFACES_DISPLAY_IMPL_H_ - -#include "base/memory/scoped_ptr.h" -#include "cc/surfaces/display_client.h" -#include "cc/surfaces/surface_factory.h" -#include "cc/surfaces/surface_factory_client.h" -#include "mojo/public/cpp/bindings/strong_binding.h" -#include "third_party/mojo_services/src/surfaces/public/interfaces/display.mojom.h" - -namespace cc { -class Display; -class SurfaceFactory; -} - -namespace surfaces { -class SurfacesScheduler; - -class DisplayImpl : public mojo::Display, - public mojo::ViewportParameterListener, - public cc::DisplayClient, - public cc::SurfaceFactoryClient { - public: - DisplayImpl(cc::SurfaceManager* manager, - cc::SurfaceId cc_id, - SurfacesScheduler* scheduler, - mojo::ContextProviderPtr context_provider, - mojo::ResourceReturnerPtr returner, - mojo::InterfaceRequest<mojo::Display> display_request); - ~DisplayImpl() override; - - private: - void OnContextCreated(mojo::CommandBufferPtr gles2_client); - - // mojo::Display implementation: - void SubmitFrame(mojo::FramePtr frame, - const SubmitFrameCallback& callback) override; - - // DisplayClient implementation. - void DisplayDamaged() override; - void DidSwapBuffers() override; - void DidSwapBuffersComplete() override; - void CommitVSyncParameters(base::TimeTicks timebase, - base::TimeDelta interval) override; - void OutputSurfaceLost() override; - void SetMemoryPolicy(const cc::ManagedMemoryPolicy& policy) override; - - // ViewportParameterListener - void OnVSyncParametersUpdated(int64_t timebase, int64_t interval) override; - - // SurfaceFactoryClient implementation. - void ReturnResources(const cc::ReturnedResourceArray& resources) override; - - void Draw(); - - cc::SurfaceManager* manager_; - cc::SurfaceFactory factory_; - cc::SurfaceId cc_id_; - SurfacesScheduler* scheduler_; - mojo::ContextProviderPtr context_provider_; - mojo::ResourceReturnerPtr returner_; - - mojo::FramePtr pending_frame_; - SubmitFrameCallback pending_callback_; - - scoped_ptr<cc::Display> display_; - - mojo::Binding<mojo::ViewportParameterListener> viewport_param_binding_; - mojo::StrongBinding<mojo::Display> display_binding_; - - DISALLOW_COPY_AND_ASSIGN(DisplayImpl); -}; - -} // namespace surfaces - -#endif // SERVICES_SURFACES_DISPLAY_IMPL_H_ diff --git a/mojo/services/surfaces/surfaces_impl.cc b/mojo/services/surfaces/surfaces_impl.cc deleted file mode 100644 index 577b6c1..0000000 --- a/mojo/services/surfaces/surfaces_impl.cc +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2014 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 "mojo/services/surfaces/surfaces_impl.h" - -#include "base/trace_event/trace_event.h" -#include "cc/output/compositor_frame.h" -#include "cc/resources/returned_resource.h" -#include "cc/surfaces/surface_id_allocator.h" -#include "mojo/converters/geometry/geometry_type_converters.h" -#include "mojo/converters/surfaces/surfaces_type_converters.h" -#include "mojo/services/surfaces/surfaces_scheduler.h" - -using mojo::SurfaceIdPtr; - -namespace surfaces { - -namespace { -void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) { - callback.Run(); -} -} - -SurfacesImpl::SurfacesImpl(cc::SurfaceManager* manager, - uint32_t id_namespace, - SurfacesScheduler* scheduler, - mojo::InterfaceRequest<mojo::Surface> request) - : manager_(manager), - factory_(manager, this), - id_namespace_(id_namespace), - scheduler_(scheduler), - binding_(this, request.Pass()) { -} - -SurfacesImpl::~SurfacesImpl() { - factory_.DestroyAll(); -} - -void SurfacesImpl::GetIdNamespace( - const Surface::GetIdNamespaceCallback& callback) { - callback.Run(id_namespace_); -} - -void SurfacesImpl::SetResourceReturner(mojo::ResourceReturnerPtr returner) { - returner_ = returner.Pass(); -} - -void SurfacesImpl::CreateSurface(uint32_t local_id) { - factory_.Create(QualifyIdentifier(local_id)); -} - -void SurfacesImpl::SubmitFrame(uint32_t local_id, - mojo::FramePtr frame, - const mojo::Closure& callback) { - TRACE_EVENT0("mojo", "SurfacesImpl::SubmitFrame"); - factory_.SubmitFrame(QualifyIdentifier(local_id), - frame.To<scoped_ptr<cc::CompositorFrame>>(), - base::Bind(&CallCallback, callback)); - scheduler_->SetNeedsDraw(); -} - -void SurfacesImpl::DestroySurface(uint32_t local_id) { - factory_.Destroy(QualifyIdentifier(local_id)); -} - -void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) { - if (resources.empty() || !returner_) - return; - mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size()); - for (size_t i = 0; i < resources.size(); ++i) { - ret[i] = mojo::ReturnedResource::From(resources[i]); - } - returner_->ReturnResources(ret.Pass()); -} - -cc::SurfaceId SurfacesImpl::QualifyIdentifier(uint32_t local_id) { - return cc::SurfaceId(static_cast<uint64_t>(id_namespace_) << 32 | local_id); -} - -} // namespace mojo diff --git a/mojo/services/surfaces/surfaces_impl.h b/mojo/services/surfaces/surfaces_impl.h deleted file mode 100644 index 10c6b7b..0000000 --- a/mojo/services/surfaces/surfaces_impl.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2014 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. - -#ifndef SERVICES_SURFACES_SURFACES_IMPL_H_ -#define SERVICES_SURFACES_SURFACES_IMPL_H_ - -#include "cc/surfaces/display_client.h" -#include "cc/surfaces/surface_factory.h" -#include "cc/surfaces/surface_factory_client.h" -#include "mojo/common/weak_binding_set.h" -#include "mojo/public/cpp/application/application_connection.h" -#include "mojo/public/cpp/bindings/strong_binding.h" -#include "third_party/mojo_services/src/gpu/public/interfaces/command_buffer.mojom.h" -#include "third_party/mojo_services/src/gpu/public/interfaces/viewport_parameter_listener.mojom.h" -#include "third_party/mojo_services/src/surfaces/public/interfaces/surfaces.mojom.h" - -namespace cc { -class Display; -} - -namespace mojo { -class ApplicationManager; -} - -namespace surfaces { -class SurfacesScheduler; - -class SurfacesImpl : public mojo::Surface, public cc::SurfaceFactoryClient { - public: - SurfacesImpl(cc::SurfaceManager* manager, - uint32_t id_namespace, - SurfacesScheduler* scheduler, - mojo::InterfaceRequest<mojo::Surface> request); - - ~SurfacesImpl() override; - - // Surface implementation. - void GetIdNamespace(const Surface::GetIdNamespaceCallback& callback) override; - void SetResourceReturner(mojo::ResourceReturnerPtr returner) override; - void CreateSurface(uint32_t local_id) override; - void SubmitFrame(uint32_t local_id, - mojo::FramePtr frame, - const mojo::Closure& callback) override; - void DestroySurface(uint32_t local_id) override; - - // SurfaceFactoryClient implementation. - void ReturnResources(const cc::ReturnedResourceArray& resources) override; - - cc::SurfaceFactory* factory() { return &factory_; } - - private: - cc::SurfaceId QualifyIdentifier(uint32_t local_id); - - cc::SurfaceManager* manager_; - cc::SurfaceFactory factory_; - const uint32_t id_namespace_; - SurfacesScheduler* scheduler_; - mojo::ScopedMessagePipeHandle command_buffer_handle_; - mojo::ResourceReturnerPtr returner_; - mojo::StrongBinding<Surface> binding_; - - DISALLOW_COPY_AND_ASSIGN(SurfacesImpl); -}; - -} // namespace surfaces - -#endif // SERVICES_SURFACES_SURFACES_IMPL_H_ diff --git a/mojo/services/surfaces/surfaces_output_surface.cc b/mojo/services/surfaces/surfaces_output_surface.cc deleted file mode 100644 index 891ef13..0000000 --- a/mojo/services/surfaces/surfaces_output_surface.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2014 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 "mojo/services/surfaces/surfaces_output_surface.h" - -#include "base/bind.h" -#include "cc/output/compositor_frame.h" -#include "cc/output/context_provider.h" -#include "cc/output/output_surface_client.h" -#include "gpu/command_buffer/client/context_support.h" -#include "gpu/command_buffer/client/gles2_interface.h" - -namespace mojo { - -DirectOutputSurface::DirectOutputSurface( - const scoped_refptr<cc::ContextProvider>& context_provider) - : cc::OutputSurface(context_provider), weak_ptr_factory_(this) { -} - -DirectOutputSurface::~DirectOutputSurface() { -} - -void DirectOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { - DCHECK(context_provider_.get()); - DCHECK(frame->gl_frame_data); - if (frame->gl_frame_data->sub_buffer_rect == - gfx::Rect(frame->gl_frame_data->size)) { - context_provider_->ContextSupport()->Swap(); - } else { - context_provider_->ContextSupport()->PartialSwapBuffers( - frame->gl_frame_data->sub_buffer_rect); - } - uint32_t sync_point = - context_provider_->ContextGL()->InsertSyncPointCHROMIUM(); - context_provider_->ContextSupport()->SignalSyncPoint( - sync_point, base::Bind(&OutputSurface::OnSwapBuffersComplete, - weak_ptr_factory_.GetWeakPtr())); - client_->DidSwapBuffers(); -} - -} // namespace mojo diff --git a/mojo/services/surfaces/surfaces_output_surface.h b/mojo/services/surfaces/surfaces_output_surface.h deleted file mode 100644 index a2e61d0..0000000 --- a/mojo/services/surfaces/surfaces_output_surface.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2014 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. - -#ifndef SERVICES_SURFACES_SURFACES_OUTPUT_SURFACE_H_ -#define SERVICES_SURFACES_SURFACES_OUTPUT_SURFACE_H_ - -#include "cc/output/output_surface.h" - -namespace mojo { - -// An OutputSurface implementation that directly draws and -// swaps to an actual GL surface. -class DirectOutputSurface : public cc::OutputSurface { - public: - explicit DirectOutputSurface( - const scoped_refptr<cc::ContextProvider>& context_provider); - ~DirectOutputSurface() override; - - // cc::OutputSurface implementation - void SwapBuffers(cc::CompositorFrame* frame) override; - - private: - base::WeakPtrFactory<DirectOutputSurface> weak_ptr_factory_; -}; - -} // namespace mojo - -#endif // SERVICES_SURFACES_SURFACES_OUTPUT_SURFACE_H_ diff --git a/mojo/services/surfaces/surfaces_scheduler.cc b/mojo/services/surfaces/surfaces_scheduler.cc deleted file mode 100644 index e20015b..0000000 --- a/mojo/services/surfaces/surfaces_scheduler.cc +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2014 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 "mojo/services/surfaces/surfaces_scheduler.h" - -#include "cc/surfaces/display.h" - -namespace surfaces { - -SurfacesScheduler::SurfacesScheduler() { - cc::SchedulerSettings settings; - scheduler_ = cc::Scheduler::Create( - this, settings, 0, base::MessageLoop::current()->task_runner(), nullptr); - scheduler_->SetCanStart(); - scheduler_->SetVisible(true); - scheduler_->SetCanDraw(true); - scheduler_->SetNeedsCommit(); -} - -SurfacesScheduler::~SurfacesScheduler() { -} - -void SurfacesScheduler::SetNeedsDraw() { - // Don't tell the scheduler we need to draw if we have no active displays - // which can happen if we haven't initialized displays yet or if all active - // displays have lost their context. - if (!displays_.empty()) - scheduler_->SetNeedsRedraw(); -} - -void SurfacesScheduler::OnVSyncParametersUpdated(base::TimeTicks timebase, - base::TimeDelta interval) { - scheduler_->CommitVSyncParameters(timebase, interval); -} - -void SurfacesScheduler::AddDisplay(cc::Display* display) { - DCHECK(displays_.find(display) == displays_.end()); - displays_.insert(display); -} - -void SurfacesScheduler::RemoveDisplay(cc::Display* display) { - auto it = displays_.find(display); - DCHECK(it != displays_.end()); - displays_.erase(it); -} - -void SurfacesScheduler::WillBeginImplFrame(const cc::BeginFrameArgs& args) { -} - -void SurfacesScheduler::ScheduledActionSendBeginMainFrame() { - scheduler_->NotifyBeginMainFrameStarted(); - scheduler_->NotifyReadyToCommit(); -} - -cc::DrawResult SurfacesScheduler::ScheduledActionDrawAndSwapIfPossible() { - base::TimeTicks start = base::TimeTicks::Now(); - for (const auto& it : displays_) { - it->Draw(); - } - base::TimeDelta duration = base::TimeTicks::Now() - start; - - draw_estimate_ = (duration + draw_estimate_) / 2; - return cc::DRAW_SUCCESS; -} - -cc::DrawResult SurfacesScheduler::ScheduledActionDrawAndSwapForced() { - NOTREACHED() << "ScheduledActionDrawAndSwapIfPossible always succeeds."; - return cc::DRAW_SUCCESS; -} - -void SurfacesScheduler::ScheduledActionAnimate() { -} - -void SurfacesScheduler::ScheduledActionCommit() { -} - -void SurfacesScheduler::ScheduledActionActivateSyncTree() { -} - -void SurfacesScheduler::ScheduledActionBeginOutputSurfaceCreation() { - scheduler_->DidCreateAndInitializeOutputSurface(); -} - -void SurfacesScheduler::ScheduledActionPrepareTiles() { -} - -void SurfacesScheduler::ScheduledActionInvalidateOutputSurface() { -} - -void SurfacesScheduler::DidAnticipatedDrawTimeChange(base::TimeTicks time) { -} - -base::TimeDelta SurfacesScheduler::DrawDurationEstimate() { - return draw_estimate_; -} - -base::TimeDelta SurfacesScheduler::BeginMainFrameToCommitDurationEstimate() { - return base::TimeDelta(); -} - -base::TimeDelta SurfacesScheduler::CommitToActivateDurationEstimate() { - return base::TimeDelta(); -} - -void SurfacesScheduler::DidBeginImplFrameDeadline() { -} - -void SurfacesScheduler::SendBeginFramesToChildren( - const cc::BeginFrameArgs& args) { -} - -void SurfacesScheduler::SendBeginMainFrameNotExpectedSoon() { -} - -} // namespace mojo diff --git a/mojo/services/surfaces/surfaces_scheduler.h b/mojo/services/surfaces/surfaces_scheduler.h deleted file mode 100644 index b35d216..0000000 --- a/mojo/services/surfaces/surfaces_scheduler.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2014 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. - -#ifndef MOJO_SERVICES_SURFACES_SURFACES_SCHEDULER_H_ -#define MOJO_SERVICES_SURFACES_SURFACES_SCHEDULER_H_ - -#include <set> - -#include "cc/scheduler/scheduler.h" - -namespace cc { -class Display; -} - -namespace surfaces { - -class SurfacesScheduler : public cc::SchedulerClient { - public: - SurfacesScheduler(); - ~SurfacesScheduler() override; - - void SetNeedsDraw(); - - void OnVSyncParametersUpdated(base::TimeTicks timebase, - base::TimeDelta interval); - - void AddDisplay(cc::Display* display); - void RemoveDisplay(cc::Display* display); - - private: - void WillBeginImplFrame(const cc::BeginFrameArgs& args) override; - void ScheduledActionSendBeginMainFrame() override; - cc::DrawResult ScheduledActionDrawAndSwapIfPossible() override; - cc::DrawResult ScheduledActionDrawAndSwapForced() override; - void ScheduledActionAnimate() override; - void ScheduledActionCommit() override; - void ScheduledActionActivateSyncTree() override; - void ScheduledActionBeginOutputSurfaceCreation() override; - void ScheduledActionPrepareTiles() override; - void ScheduledActionInvalidateOutputSurface() override; - void DidAnticipatedDrawTimeChange(base::TimeTicks time) override; - base::TimeDelta DrawDurationEstimate() override; - base::TimeDelta BeginMainFrameToCommitDurationEstimate() override; - base::TimeDelta CommitToActivateDurationEstimate() override; - void DidBeginImplFrameDeadline() override; - void SendBeginFramesToChildren(const cc::BeginFrameArgs& args) override; - void SendBeginMainFrameNotExpectedSoon() override; - - std::set<cc::Display*> displays_; - scoped_ptr<cc::Scheduler> scheduler_; - base::TimeDelta draw_estimate_; - - DISALLOW_COPY_AND_ASSIGN(SurfacesScheduler); -}; - -} // namespace mojo - -#endif // MOJO_SERVICES_SURFACES_SURFACES_SCHEDULER_H_ diff --git a/mojo/services/surfaces/surfaces_service_application.cc b/mojo/services/surfaces/surfaces_service_application.cc deleted file mode 100644 index 7d3e370..0000000 --- a/mojo/services/surfaces/surfaces_service_application.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2014 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 "mojo/services/surfaces/surfaces_service_application.h" - -#include "mojo/application/application_runner_chromium.h" -#include "mojo/public/c/system/main.h" -#include "mojo/services/surfaces/display_factory_impl.h" -#include "mojo/services/surfaces/surfaces_impl.h" -#include "mojo/services/surfaces/surfaces_scheduler.h" - -namespace surfaces { - -SurfacesServiceApplication::SurfacesServiceApplication() - : next_id_namespace_(1u) { -} - -SurfacesServiceApplication::~SurfacesServiceApplication() { -} - -void SurfacesServiceApplication::Initialize(mojo::ApplicationImpl* app) { - tracing_.Initialize(app); - scheduler_.reset(new SurfacesScheduler); -} - -bool SurfacesServiceApplication::ConfigureIncomingConnection( - mojo::ApplicationConnection* connection) { - connection->AddService<mojo::DisplayFactory>(this); - connection->AddService<mojo::Surface>(this); - return true; -} - -void SurfacesServiceApplication::Create( - mojo::ApplicationConnection* connection, - mojo::InterfaceRequest<mojo::DisplayFactory> request) { - new DisplayFactoryImpl(&manager_, next_id_namespace_++, scheduler_.get(), - request.Pass()); -} - -void SurfacesServiceApplication::Create( - mojo::ApplicationConnection* connection, - mojo::InterfaceRequest<mojo::Surface> request) { - new SurfacesImpl(&manager_, next_id_namespace_++, scheduler_.get(), - request.Pass()); -} - -} // namespace surfaces - -MojoResult MojoMain(MojoHandle shell_handle) { - mojo::ApplicationRunnerChromium runner( - new surfaces::SurfacesServiceApplication); - return runner.Run(shell_handle); -} diff --git a/mojo/services/surfaces/surfaces_service_application.h b/mojo/services/surfaces/surfaces_service_application.h deleted file mode 100644 index cae7b35..0000000 --- a/mojo/services/surfaces/surfaces_service_application.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2014 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. - -#ifndef SERVICES_SURFACES_SURFACES_SERVICE_APPLICATION_H_ -#define SERVICES_SURFACES_SURFACES_SERVICE_APPLICATION_H_ - -#include "base/macros.h" -#include "cc/surfaces/surface_manager.h" -#include "mojo/common/tracing_impl.h" -#include "mojo/public/cpp/application/application_delegate.h" -#include "mojo/public/cpp/application/interface_factory.h" -#include "third_party/mojo_services/src/surfaces/public/interfaces/display.mojom.h" -#include "third_party/mojo_services/src/surfaces/public/interfaces/surfaces.mojom.h" - -namespace mojo { -class ApplicationConnection; -} - -namespace surfaces { -class SurfacesScheduler; - -class SurfacesServiceApplication - : public mojo::ApplicationDelegate, - public mojo::InterfaceFactory<mojo::DisplayFactory>, - public mojo::InterfaceFactory<mojo::Surface> { - public: - SurfacesServiceApplication(); - ~SurfacesServiceApplication() override; - - // ApplicationDelegate implementation. - void Initialize(mojo::ApplicationImpl* app) override; - bool ConfigureIncomingConnection( - mojo::ApplicationConnection* connection) override; - - // InterfaceFactory<DisplayFactory> implementation. - void Create(mojo::ApplicationConnection* connection, - mojo::InterfaceRequest<mojo::DisplayFactory> request) override; - - // InterfaceFactory<Surface> implementation. - void Create(mojo::ApplicationConnection* connection, - mojo::InterfaceRequest<mojo::Surface> request) override; - - private: - cc::SurfaceManager manager_; - uint32_t next_id_namespace_; - scoped_ptr<SurfacesScheduler> scheduler_; - mojo::TracingImpl tracing_; - - DISALLOW_COPY_AND_ASSIGN(SurfacesServiceApplication); -}; - -} // namespace surfaces - -#endif // SERVICES_SURFACES_SURFACES_SERVICE_APPLICATION_H_ diff --git a/mojo/shell/BUILD.gn b/mojo/shell/BUILD.gn index 3620709..512c455 100644 --- a/mojo/shell/BUILD.gn +++ b/mojo/shell/BUILD.gn @@ -72,7 +72,7 @@ executable("mojo_shell") { deps += [ ":jni_headers", - "//mojo/services/native_viewport:lib", + "//components/native_viewport:lib", "//mojo/shell/application_manager", "//ui/gl", ] @@ -166,8 +166,8 @@ source_set("lib") { ":jni_headers", ":run_android_application_function", "//components/gles2", + "//components/native_viewport:lib", "//mojo/application:content_handler", - "//mojo/services/native_viewport:lib", ] } @@ -324,7 +324,7 @@ if (is_android) { ":java", ":resources", "//base:base_java", - "//mojo/services/native_viewport:native_viewport_java", + "//components/native_viewport:native_viewport_java", "//third_party/android_tools:google_play_services_default_resources", ] } diff --git a/mojo/shell/DEPS b/mojo/shell/DEPS index 6c6ed51..0a011fa 100644 --- a/mojo/shell/DEPS +++ b/mojo/shell/DEPS @@ -1,5 +1,6 @@ include_rules = [ "+components/gles2", + "+components/native_viewport", "+crypto", "+jni", "+third_party/mojo_services", diff --git a/mojo/shell/android/library_loader.cc b/mojo/shell/android/library_loader.cc index 3a1faa4..c43a4b5 100644 --- a/mojo/shell/android/library_loader.cc +++ b/mojo/shell/android/library_loader.cc @@ -7,7 +7,7 @@ #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" #include "base/bind.h" -#include "mojo/services/native_viewport/platform_viewport_android.h" +#include "components/native_viewport/platform_viewport_android.h" #include "mojo/shell/android/android_handler.h" #include "mojo/shell/android/main.h" diff --git a/mojo/shell/android/native_viewport_application_loader.cc b/mojo/shell/android/native_viewport_application_loader.cc index bc52947..3822980 100644 --- a/mojo/shell/android/native_viewport_application_loader.cc +++ b/mojo/shell/android/native_viewport_application_loader.cc @@ -5,8 +5,8 @@ #include "mojo/shell/android/native_viewport_application_loader.h" #include "components/gles2/gpu_state.h" +#include "components/native_viewport/native_viewport_impl.h" #include "mojo/public/cpp/application/application_impl.h" -#include "mojo/services/native_viewport/native_viewport_impl.h" namespace mojo { namespace shell { |