blob: 4a21c893c40e818cd70d79dde926648692cc284b [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
James Robinsonc9b163e2014-12-03 13:31:32 -08005#ifndef SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_ANDROID_H_
6#define SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_ANDROID_H_
James Robinson646469d2014-10-03 15:33:28 -07007
8#include "base/android/jni_weak_ref.h"
James Robinson646469d2014-10-03 15:33:28 -07009#include "base/macros.h"
10#include "base/memory/weak_ptr.h"
Etienne Membrives14731832015-08-11 15:42:42 +020011#include "services/native_viewport/native_viewport_support.mojom.h"
James Robinsonc9b163e2014-12-03 13:31:32 -080012#include "services/native_viewport/platform_viewport.h"
James Robinson646469d2014-10-03 15:33:28 -070013#include "ui/events/event_constants.h"
14#include "ui/gfx/rect.h"
15#include "ui/gfx/sequential_id_generator.h"
16#include "ui/gfx/size.h"
17
18namespace gpu {
19class GLInProcessContext;
20}
21
Etienne Membrivesfbd9af02015-08-07 16:26:09 +020022namespace mojo {
23class ApplicationImpl;
24}
25
James Robinson646469d2014-10-03 15:33:28 -070026struct ANativeWindow;
27
James Robinsonbd9353b2014-12-12 17:56:18 -080028namespace native_viewport {
James Robinson646469d2014-10-03 15:33:28 -070029
30class PlatformViewportAndroid : public PlatformViewport {
31 public:
32 static bool Register(JNIEnv* env);
33
Etienne Membrivesfbd9af02015-08-07 16:26:09 +020034 explicit PlatformViewportAndroid(mojo::ApplicationImpl* application,
35 Delegate* delegate);
James Robinson646469d2014-10-03 15:33:28 -070036 virtual ~PlatformViewportAndroid();
37
38 void Destroy(JNIEnv* env, jobject obj);
Etienne Membrivesfbd9af02015-08-07 16:26:09 +020039 void SurfaceAttached(JNIEnv* env, jobject obj, jobject platform_viewport);
James Robinson646469d2014-10-03 15:33:28 -070040 void SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface);
41 void SurfaceDestroyed(JNIEnv* env, jobject obj);
Adam Barth9329c442015-01-09 21:56:43 -080042 void SurfaceSetSize(JNIEnv* env,
43 jobject obj,
44 jint width,
45 jint height,
46 jfloat density);
Scott Violet6aadda52015-03-24 09:13:10 -070047 bool TouchEvent(JNIEnv* env,
48 jobject obj,
49 jlong time_ms,
50 jint masked_action,
51 jint pointer_id,
52 jfloat x,
53 jfloat y,
54 jfloat pressure,
55 jfloat touch_major,
56 jfloat touch_minor,
57 jfloat orientation,
58 jfloat h_wheel,
59 jfloat v_wheel);
James Robinson646469d2014-10-03 15:33:28 -070060
61 private:
62 // Overridden from PlatformViewport:
63 virtual void Init(const gfx::Rect& bounds) override;
64 virtual void Show() override;
65 virtual void Hide() override;
66 virtual void Close() override;
67 virtual gfx::Size GetSize() override;
68 virtual void SetBounds(const gfx::Rect& bounds) override;
James Robinson646469d2014-10-03 15:33:28 -070069
70 void ReleaseWindow();
71
Etienne Membrivesfbd9af02015-08-07 16:26:09 +020072 mojo::ApplicationImpl* application_;
Etienne Membrives14731832015-08-11 15:42:42 +020073 NativeViewportSupportServicePtr support_service_;
Viet-Trung Luudc865d42015-04-15 15:15:08 -070074 Delegate* const delegate_;
75 JavaObjectWeakGlobalRef java_platform_viewport_android_;
James Robinson646469d2014-10-03 15:33:28 -070076 ANativeWindow* window_;
Adam Barth9329c442015-01-09 21:56:43 -080077 mojo::ViewportMetricsPtr metrics_;
James Robinson646469d2014-10-03 15:33:28 -070078 ui::SequentialIDGenerator id_generator_;
79
80 base::WeakPtrFactory<PlatformViewportAndroid> weak_factory_;
81
82 DISALLOW_COPY_AND_ASSIGN(PlatformViewportAndroid);
83};
84
James Robinsonbd9353b2014-12-12 17:56:18 -080085} // namespace native_viewport
James Robinson646469d2014-10-03 15:33:28 -070086
James Robinsonc9b163e2014-12-03 13:31:32 -080087#endif // SERVICES_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_ANDROID_H_