Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / android / compositor / scene_layer / scene_layer.cc
blob5995e97dbb1f4ae8e9c140b0556916364603e5fb
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"
11 namespace chrome {
12 namespace android {
14 // static
15 SceneLayer* SceneLayer::FromJavaObject(JNIEnv* env, jobject jobj) {
16 if (jobj == nullptr)
17 return nullptr;
18 return reinterpret_cast<SceneLayer*>(Java_SceneLayer_getNativePtr(env, jobj));
21 SceneLayer::SceneLayer(JNIEnv* env, jobject jobj)
22 : SceneLayer(env,
23 jobj,
24 cc::Layer::Create(content::Compositor::LayerSettings())) {
27 SceneLayer::SceneLayer(JNIEnv* env,
28 jobject jobj,
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);
37 if (jobj.is_null())
38 return;
40 Java_SceneLayer_setNativePtr(
41 env, jobj.obj(),
42 reinterpret_cast<intptr_t>(static_cast<SceneLayer*>(NULL)));
45 void SceneLayer::OnDetach() {
46 layer()->RemoveFromParent();
49 void SceneLayer::Destroy(JNIEnv* env, jobject jobj) {
50 delete this;
53 bool SceneLayer::ShouldShowBackground() {
54 return false;
57 SkColor SceneLayer::GetBackgroundColor() {
58 return SK_ColorWHITE;
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
72 } // namespace chrome