1// Copyright (c) 2012 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
5#ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIEW_RENDER_VIEW_H_
6#define CONTENT_BROWSER_ANDROID_CONTENT_VIEW_RENDER_VIEW_H_
7
8#include "base/android/jni_weak_ref.h"
9#include "base/logging.h"
10#include "base/memory/scoped_ptr.h"
11#include "base/memory/weak_ptr.h"
12#include "content/public/browser/android/compositor_client.h"
13#include "ui/gfx/native_widget_types.h"
14
15namespace cc {
16class Layer;
17}
18
19namespace content {
20class Compositor;
21class LayerTreeBuildHelper;
22class UIResourceProvider;
23
24class ContentViewRenderView : public CompositorClient {
25 public:
26  // Registers the JNI methods for ContentViewRender.
27  static bool RegisterContentViewRenderView(JNIEnv* env);
28
29  ContentViewRenderView(JNIEnv* env,
30                        jobject obj,
31                        gfx::NativeWindow root_window);
32
33  // Methods called from Java via JNI -----------------------------------------
34  void Destroy(JNIEnv* env, jobject obj);
35  void SetCurrentContentViewCore(JNIEnv* env, jobject obj,
36                                 jlong native_content_view_core);
37  void SetLayerTreeBuildHelper(
38      JNIEnv* env, jobject obj, jlong native_build_helper);
39  void SurfaceCreated(JNIEnv* env, jobject obj);
40  void SurfaceDestroyed(JNIEnv* env, jobject obj);
41  void SurfaceChanged(JNIEnv* env, jobject obj,
42                      jint format, jint width, jint height, jobject surface);
43  jboolean Composite(JNIEnv* env, jobject obj);
44  void SetOverlayVideoMode(JNIEnv* env, jobject obj, bool enabled);
45  void SetNeedsComposite(JNIEnv* env, jobject obj);
46
47  // TODO(yusufo): Remove this once the compositor code is
48  // refactored to use a unified system.
49  jlong GetUIResourceProvider(JNIEnv* env, jobject obj);
50
51  // CompositorClient implementation
52  virtual void Layout() OVERRIDE;
53  virtual void OnSwapBuffersCompleted(int pending_swap_buffers) OVERRIDE;
54
55 private:
56  virtual ~ContentViewRenderView();
57
58  void InitCompositor();
59
60  base::android::ScopedJavaGlobalRef<jobject> java_obj_;
61  scoped_ptr<LayerTreeBuildHelper> layer_tree_build_helper_;
62
63  scoped_ptr<content::Compositor> compositor_;
64
65  gfx::NativeWindow root_window_;
66  int current_surface_format_;
67
68  DISALLOW_COPY_AND_ASSIGN(ContentViewRenderView);
69};
70
71
72
73}
74
75#endif  // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_RENDER_VIEW_H_
76