1 // Copyright 2015 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 "chrome/browser/android/compositor/scene_layer/scene_layer.h"
7 #include "cc/layers/layer.h"
8 #include "content/public/browser/android/compositor.h"
9 #include "jni/SceneLayer_jni.h"
15 SceneLayer
* SceneLayer::FromJavaObject(JNIEnv
* env
, jobject jobj
) {
18 return reinterpret_cast<SceneLayer
*>(Java_SceneLayer_getNativePtr(env
, jobj
));
21 SceneLayer::SceneLayer(JNIEnv
* env
, jobject jobj
)
24 cc::Layer::Create(content::Compositor::LayerSettings())) {
27 SceneLayer::SceneLayer(JNIEnv
* env
,
29 scoped_refptr
<cc::Layer
> layer
)
30 : weak_java_scene_layer_(env
, jobj
), layer_(layer
) {
31 Java_SceneLayer_setNativePtr(env
, jobj
, reinterpret_cast<intptr_t>(this));
34 SceneLayer::~SceneLayer() {
35 JNIEnv
* env
= base::android::AttachCurrentThread();
36 ScopedJavaLocalRef
<jobject
> jobj
= weak_java_scene_layer_
.get(env
);
40 Java_SceneLayer_setNativePtr(
42 reinterpret_cast<intptr_t>(static_cast<SceneLayer
*>(NULL
)));
45 void SceneLayer::OnDetach() {
46 layer()->RemoveFromParent();
49 void SceneLayer::Destroy(JNIEnv
* env
, jobject jobj
) {
53 bool SceneLayer::ShouldShowBackground() {
57 SkColor
SceneLayer::GetBackgroundColor() {
61 static jlong
Init(JNIEnv
* env
, const JavaParamRef
<jobject
>& jobj
) {
62 // This will automatically bind to the Java object and pass ownership there.
63 SceneLayer
* tree_provider
= new SceneLayer(env
, jobj
);
64 return reinterpret_cast<intptr_t>(tree_provider
);
67 bool RegisterSceneLayer(JNIEnv
* env
) {
68 return RegisterNativesImpl(env
);
71 } // namespace android