1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
// Copyright (c) 2012 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 "content/browser/android/content_view_render_view.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "cc/layers/layer.h"
#include "content/browser/android/content_view_core_impl.h"
#include "content/public/browser/android/compositor.h"
#include "content/public/browser/android/content_view_layer_renderer.h"
#include "jni/ContentViewRenderView_jni.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/geometry/size.h"
#include <android/bitmap.h>
#include <android/native_window_jni.h>
using base::android::ScopedJavaLocalRef;
namespace content {
// static
bool ContentViewRenderView::RegisterContentViewRenderView(JNIEnv* env) {
return RegisterNativesImpl(env);
}
ContentViewRenderView::ContentViewRenderView(JNIEnv* env,
jobject obj,
gfx::NativeWindow root_window)
: root_window_(root_window), current_surface_format_(0) {
java_obj_.Reset(env, obj);
}
ContentViewRenderView::~ContentViewRenderView() {
}
// static
static jlong Init(JNIEnv* env,
jobject obj,
jlong native_root_window) {
gfx::NativeWindow root_window =
reinterpret_cast<gfx::NativeWindow>(native_root_window);
ContentViewRenderView* content_view_render_view =
new ContentViewRenderView(env, obj, root_window);
return reinterpret_cast<intptr_t>(content_view_render_view);
}
void ContentViewRenderView::Destroy(JNIEnv* env, jobject obj) {
delete this;
}
void ContentViewRenderView::SetCurrentContentViewCore(
JNIEnv* env, jobject obj, jlong native_content_view_core) {
InitCompositor();
ContentViewCoreImpl* content_view_core =
reinterpret_cast<ContentViewCoreImpl*>(native_content_view_core);
compositor_->SetRootLayer(content_view_core ? content_view_core->GetLayer()
: scoped_refptr<cc::Layer>());
}
void ContentViewRenderView::SurfaceCreated(
JNIEnv* env, jobject obj) {
current_surface_format_ = 0;
InitCompositor();
}
void ContentViewRenderView::SurfaceDestroyed(JNIEnv* env, jobject obj) {
compositor_->SetSurface(NULL);
current_surface_format_ = 0;
}
void ContentViewRenderView::SurfaceChanged(JNIEnv* env, jobject obj,
jint format, jint width, jint height, jobject surface) {
if (current_surface_format_ != format) {
current_surface_format_ = format;
compositor_->SetSurface(surface);
}
compositor_->SetWindowBounds(gfx::Size(width, height));
}
void ContentViewRenderView::SetOverlayVideoMode(
JNIEnv* env, jobject obj, bool enabled) {
compositor_->SetHasTransparentBackground(enabled);
SetNeedsComposite(env, obj);
}
void ContentViewRenderView::SetNeedsComposite(JNIEnv* env, jobject obj) {
if (compositor_)
compositor_->SetNeedsComposite();
}
void ContentViewRenderView::Layout() {
JNIEnv* env = base::android::AttachCurrentThread();
Java_ContentViewRenderView_onCompositorLayout(env, java_obj_.obj());
}
void ContentViewRenderView::OnSwapBuffersCompleted(int pending_swap_buffers) {
JNIEnv* env = base::android::AttachCurrentThread();
Java_ContentViewRenderView_onSwapBuffersCompleted(env, java_obj_.obj());
}
void ContentViewRenderView::InitCompositor() {
if (!compositor_)
compositor_.reset(Compositor::Create(this, root_window_));
}
jlong ContentViewRenderView::GetUIResourceProvider(JNIEnv* env,
jobject obj) {
if (!compositor_)
return 0;
return reinterpret_cast<intptr_t>(&compositor_->GetUIResourceProvider());
}
} // namespace content
|