Cleanup: Update the path to gfx size headers.
[chromium-blink-merge.git] / content / browser / android / content_view_render_view.cc
blobe6580416a87c627da89bc5b8b0be1850c72dc7bb
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.
5 #include "content/browser/android/content_view_render_view.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "base/bind.h"
11 #include "base/lazy_instance.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h"
14 #include "cc/layers/layer.h"
15 #include "content/browser/android/content_view_core_impl.h"
16 #include "content/public/browser/android/compositor.h"
17 #include "content/public/browser/android/content_view_layer_renderer.h"
18 #include "content/public/browser/android/layer_tree_build_helper.h"
19 #include "jni/ContentViewRenderView_jni.h"
20 #include "ui/gfx/android/java_bitmap.h"
21 #include "ui/gfx/geometry/size.h"
23 #include <android/bitmap.h>
24 #include <android/native_window_jni.h>
26 using base::android::ScopedJavaLocalRef;
28 namespace content {
30 namespace {
32 class LayerTreeBuildHelperImpl : public LayerTreeBuildHelper {
33 public:
34 LayerTreeBuildHelperImpl() {}
35 virtual ~LayerTreeBuildHelperImpl() {}
37 virtual scoped_refptr<cc::Layer> GetLayerTree(
38 scoped_refptr<cc::Layer> content_root_layer) override {
39 return content_root_layer;
42 private:
43 DISALLOW_COPY_AND_ASSIGN(LayerTreeBuildHelperImpl);
46 } // anonymous namespace
48 // static
49 bool ContentViewRenderView::RegisterContentViewRenderView(JNIEnv* env) {
50 return RegisterNativesImpl(env);
53 ContentViewRenderView::ContentViewRenderView(JNIEnv* env,
54 jobject obj,
55 gfx::NativeWindow root_window)
56 : layer_tree_build_helper_(new LayerTreeBuildHelperImpl()),
57 root_window_(root_window),
58 current_surface_format_(0) {
59 java_obj_.Reset(env, obj);
62 ContentViewRenderView::~ContentViewRenderView() {
65 void ContentViewRenderView::SetLayerTreeBuildHelper(JNIEnv* env,
66 jobject obj,
67 jlong native_build_helper) {
68 CHECK(native_build_helper);
70 LayerTreeBuildHelper* build_helper =
71 reinterpret_cast<LayerTreeBuildHelper*>(native_build_helper);
72 layer_tree_build_helper_.reset(build_helper);
73 InitCompositor();
75 // static
76 static jlong Init(JNIEnv* env,
77 jobject obj,
78 jlong native_root_window) {
79 gfx::NativeWindow root_window =
80 reinterpret_cast<gfx::NativeWindow>(native_root_window);
81 ContentViewRenderView* content_view_render_view =
82 new ContentViewRenderView(env, obj, root_window);
83 return reinterpret_cast<intptr_t>(content_view_render_view);
86 void ContentViewRenderView::Destroy(JNIEnv* env, jobject obj) {
87 delete this;
90 void ContentViewRenderView::SetCurrentContentViewCore(
91 JNIEnv* env, jobject obj, jlong native_content_view_core) {
92 InitCompositor();
93 ContentViewCoreImpl* content_view_core =
94 reinterpret_cast<ContentViewCoreImpl*>(native_content_view_core);
95 compositor_->SetRootLayer(content_view_core
96 ? layer_tree_build_helper_->GetLayerTree(
97 content_view_core->GetLayer())
98 : scoped_refptr<cc::Layer>());
101 void ContentViewRenderView::SurfaceCreated(
102 JNIEnv* env, jobject obj) {
103 current_surface_format_ = 0;
104 InitCompositor();
107 void ContentViewRenderView::SurfaceDestroyed(JNIEnv* env, jobject obj) {
108 compositor_->SetSurface(NULL);
109 current_surface_format_ = 0;
112 void ContentViewRenderView::SurfaceChanged(JNIEnv* env, jobject obj,
113 jint format, jint width, jint height, jobject surface) {
114 if (current_surface_format_ != format) {
115 current_surface_format_ = format;
116 compositor_->SetSurface(surface);
118 compositor_->SetWindowBounds(gfx::Size(width, height));
121 void ContentViewRenderView::SetOverlayVideoMode(
122 JNIEnv* env, jobject obj, bool enabled) {
123 compositor_->SetHasTransparentBackground(enabled);
124 SetNeedsComposite(env, obj);
127 void ContentViewRenderView::SetNeedsComposite(JNIEnv* env, jobject obj) {
128 if (compositor_)
129 compositor_->SetNeedsComposite();
132 void ContentViewRenderView::Layout() {
133 JNIEnv* env = base::android::AttachCurrentThread();
134 Java_ContentViewRenderView_onCompositorLayout(env, java_obj_.obj());
137 void ContentViewRenderView::OnSwapBuffersCompleted(int pending_swap_buffers) {
138 JNIEnv* env = base::android::AttachCurrentThread();
139 Java_ContentViewRenderView_onSwapBuffersCompleted(env, java_obj_.obj());
142 void ContentViewRenderView::InitCompositor() {
143 if (!compositor_)
144 compositor_.reset(Compositor::Create(this, root_window_));
147 jlong ContentViewRenderView::GetUIResourceProvider(JNIEnv* env,
148 jobject obj) {
149 if (!compositor_)
150 return 0;
151 return reinterpret_cast<intptr_t>(&compositor_->GetUIResourceProvider());
153 } // namespace content