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 "jni/SceneLayer_jni.h"
14 SceneLayer
* SceneLayer::FromJavaObject(JNIEnv
* env
, jobject jobj
) {
17 return reinterpret_cast<SceneLayer
*>(Java_SceneLayer_getNativePtr(env
, jobj
));
20 SceneLayer::SceneLayer(JNIEnv
* env
, jobject jobj
)
21 : SceneLayer(env
, jobj
, cc::Layer::Create()) {
24 SceneLayer::SceneLayer(JNIEnv
* env
,
26 scoped_refptr
<cc::Layer
> layer
)
27 : weak_java_scene_layer_(env
, jobj
), layer_(layer
) {
28 Java_SceneLayer_setNativePtr(env
, jobj
, reinterpret_cast<intptr_t>(this));
31 SceneLayer::~SceneLayer() {
32 JNIEnv
* env
= base::android::AttachCurrentThread();
33 ScopedJavaLocalRef
<jobject
> jobj
= weak_java_scene_layer_
.get(env
);
37 Java_SceneLayer_setNativePtr(
39 reinterpret_cast<intptr_t>(static_cast<SceneLayer
*>(NULL
)));
42 void SceneLayer::OnDetach() {
43 layer()->RemoveFromParent();
46 void SceneLayer::Destroy(JNIEnv
* env
, jobject jobj
) {
50 bool SceneLayer::ShouldShowBackground() {
54 SkColor
SceneLayer::GetBackgroundColor() {
58 static jlong
Init(JNIEnv
* env
, jobject jobj
) {
59 // This will automatically bind to the Java object and pass ownership there.
60 SceneLayer
* tree_provider
= new SceneLayer(env
, jobj
);
61 return reinterpret_cast<intptr_t>(tree_provider
);
64 bool RegisterSceneLayer(JNIEnv
* env
) {
65 return RegisterNativesImpl(env
);
68 } // namespace android