Add remoting and PPAPI tests to GN build
[chromium-blink-merge.git] / content / browser / android / content_view_render_view.cc
blobeb6a695d1213fca825625f12973276c65a83ebee
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 "jni/ContentViewRenderView_jni.h"
19 #include "ui/gfx/android/java_bitmap.h"
20 #include "ui/gfx/geometry/size.h"
22 #include <android/bitmap.h>
23 #include <android/native_window_jni.h>
25 using base::android::ScopedJavaLocalRef;
27 namespace content {
29 // static
30 bool ContentViewRenderView::RegisterContentViewRenderView(JNIEnv* env) {
31 return RegisterNativesImpl(env);
34 ContentViewRenderView::ContentViewRenderView(JNIEnv* env,
35 jobject obj,
36 gfx::NativeWindow root_window)
37 : root_window_(root_window), current_surface_format_(0) {
38 java_obj_.Reset(env, obj);
41 ContentViewRenderView::~ContentViewRenderView() {
44 // static
45 static jlong Init(JNIEnv* env,
46 jobject obj,
47 jlong native_root_window) {
48 gfx::NativeWindow root_window =
49 reinterpret_cast<gfx::NativeWindow>(native_root_window);
50 ContentViewRenderView* content_view_render_view =
51 new ContentViewRenderView(env, obj, root_window);
52 return reinterpret_cast<intptr_t>(content_view_render_view);
55 void ContentViewRenderView::Destroy(JNIEnv* env, jobject obj) {
56 delete this;
59 void ContentViewRenderView::SetCurrentContentViewCore(
60 JNIEnv* env, jobject obj, jlong native_content_view_core) {
61 InitCompositor();
62 ContentViewCoreImpl* content_view_core =
63 reinterpret_cast<ContentViewCoreImpl*>(native_content_view_core);
64 compositor_->SetRootLayer(content_view_core ? content_view_core->GetLayer()
65 : scoped_refptr<cc::Layer>());
68 void ContentViewRenderView::SurfaceCreated(
69 JNIEnv* env, jobject obj) {
70 current_surface_format_ = 0;
71 InitCompositor();
74 void ContentViewRenderView::SurfaceDestroyed(JNIEnv* env, jobject obj) {
75 compositor_->SetSurface(NULL);
76 current_surface_format_ = 0;
79 void ContentViewRenderView::SurfaceChanged(JNIEnv* env, jobject obj,
80 jint format, jint width, jint height, jobject surface) {
81 if (current_surface_format_ != format) {
82 current_surface_format_ = format;
83 compositor_->SetSurface(surface);
85 compositor_->SetWindowBounds(gfx::Size(width, height));
88 void ContentViewRenderView::SetOverlayVideoMode(
89 JNIEnv* env, jobject obj, bool enabled) {
90 compositor_->SetHasTransparentBackground(enabled);
91 SetNeedsComposite(env, obj);
94 void ContentViewRenderView::SetNeedsComposite(JNIEnv* env, jobject obj) {
95 if (compositor_)
96 compositor_->SetNeedsComposite();
99 void ContentViewRenderView::Layout() {
100 JNIEnv* env = base::android::AttachCurrentThread();
101 Java_ContentViewRenderView_onCompositorLayout(env, java_obj_.obj());
104 void ContentViewRenderView::OnSwapBuffersCompleted(int pending_swap_buffers) {
105 JNIEnv* env = base::android::AttachCurrentThread();
106 Java_ContentViewRenderView_onSwapBuffersCompleted(env, java_obj_.obj());
109 void ContentViewRenderView::InitCompositor() {
110 if (!compositor_)
111 compositor_.reset(Compositor::Create(this, root_window_));
114 jlong ContentViewRenderView::GetUIResourceProvider(JNIEnv* env,
115 jobject obj) {
116 if (!compositor_)
117 return 0;
118 return reinterpret_cast<intptr_t>(&compositor_->GetUIResourceProvider());
120 } // namespace content