| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gl/android/scoped_java_surface.h" | 5 #include "ui/gl/android/scoped_java_surface.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "jni/Surface_jni.h" | 8 #include "jni/Surface_jni.h" |
| 9 #include "ui/gl/android/surface_texture.h" | 9 #include "ui/gl/android/surface_texture.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 DCHECK(env->IsInstanceOf(surface.obj(), Surface_clazz(env))); | 23 DCHECK(env->IsInstanceOf(surface.obj(), Surface_clazz(env))); |
| 24 j_surface_.Reset(surface); | 24 j_surface_.Reset(surface); |
| 25 } | 25 } |
| 26 | 26 |
| 27 ScopedJavaSurface::ScopedJavaSurface( | 27 ScopedJavaSurface::ScopedJavaSurface( |
| 28 const SurfaceTexture* surface_texture) | 28 const SurfaceTexture* surface_texture) |
| 29 : auto_release_(true), | 29 : auto_release_(true), |
| 30 is_protected_(false) { | 30 is_protected_(false) { |
| 31 JNIEnv* env = base::android::AttachCurrentThread(); | 31 JNIEnv* env = base::android::AttachCurrentThread(); |
| 32 ScopedJavaLocalRef<jobject> tmp(JNI_Surface::Java_Surface_Constructor( | 32 ScopedJavaLocalRef<jobject> tmp(JNI_Surface::Java_Surface_Constructor( |
| 33 env, surface_texture->j_surface_texture().obj())); | 33 env, surface_texture->j_surface_texture())); |
| 34 DCHECK(!tmp.is_null()); | 34 DCHECK(!tmp.is_null()); |
| 35 j_surface_.Reset(tmp); | 35 j_surface_.Reset(tmp); |
| 36 } | 36 } |
| 37 | 37 |
| 38 ScopedJavaSurface::ScopedJavaSurface(ScopedJavaSurface&& rvalue) { | 38 ScopedJavaSurface::ScopedJavaSurface(ScopedJavaSurface&& rvalue) { |
| 39 MoveFrom(rvalue); | 39 MoveFrom(rvalue); |
| 40 } | 40 } |
| 41 | 41 |
| 42 ScopedJavaSurface& ScopedJavaSurface::operator=(ScopedJavaSurface&& rhs) { | 42 ScopedJavaSurface& ScopedJavaSurface::operator=(ScopedJavaSurface&& rhs) { |
| 43 MoveFrom(rhs); | 43 MoveFrom(rhs); |
| 44 return *this; | 44 return *this; |
| 45 } | 45 } |
| 46 | 46 |
| 47 ScopedJavaSurface::~ScopedJavaSurface() { | 47 ScopedJavaSurface::~ScopedJavaSurface() { |
| 48 if (auto_release_ && !j_surface_.is_null()) { | 48 if (auto_release_ && !j_surface_.is_null()) { |
| 49 JNIEnv* env = base::android::AttachCurrentThread(); | 49 JNIEnv* env = base::android::AttachCurrentThread(); |
| 50 JNI_Surface::Java_Surface_release(env, j_surface_.obj()); | 50 JNI_Surface::Java_Surface_release(env, j_surface_); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ScopedJavaSurface::MoveFrom(ScopedJavaSurface& other) { | 54 void ScopedJavaSurface::MoveFrom(ScopedJavaSurface& other) { |
| 55 JNIEnv* env = base::android::AttachCurrentThread(); | 55 JNIEnv* env = base::android::AttachCurrentThread(); |
| 56 j_surface_.Reset(env, other.j_surface_.Release()); | 56 j_surface_.Reset(env, other.j_surface_.Release()); |
| 57 auto_release_ = other.auto_release_; | 57 auto_release_ = other.auto_release_; |
| 58 is_protected_ = other.is_protected_; | 58 is_protected_ = other.is_protected_; |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool ScopedJavaSurface::IsEmpty() const { | 61 bool ScopedJavaSurface::IsEmpty() const { |
| 62 return j_surface_.is_null(); | 62 return j_surface_.is_null(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // static | 65 // static |
| 66 ScopedJavaSurface ScopedJavaSurface::AcquireExternalSurface(jobject surface) { | 66 ScopedJavaSurface ScopedJavaSurface::AcquireExternalSurface(jobject surface) { |
| 67 JNIEnv* env = base::android::AttachCurrentThread(); | 67 JNIEnv* env = base::android::AttachCurrentThread(); |
| 68 ScopedJavaLocalRef<jobject> surface_ref; | 68 ScopedJavaLocalRef<jobject> surface_ref; |
| 69 surface_ref.Reset(env, surface); | 69 surface_ref.Reset(env, surface); |
| 70 ScopedJavaSurface scoped_surface(surface_ref); | 70 ScopedJavaSurface scoped_surface(surface_ref); |
| 71 scoped_surface.auto_release_ = false; | 71 scoped_surface.auto_release_ = false; |
| 72 scoped_surface.is_protected_ = true; | 72 scoped_surface.is_protected_ = true; |
| 73 return scoped_surface; | 73 return scoped_surface; |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace gl | 76 } // namespace gl |
| OLD | NEW |