Commit 54796409 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

Release ScopedJavaSurface on overwrite

Also ensure members are initialized so the move constructor doesn't use
uninitialized values.

Bug: 871604
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I9ab800fec100ccf7ec4de3dd63dfcd28b1e5c5df
Reviewed-on: https://chromium-review.googlesource.com/1178302Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584623}
parent 666489e8
...@@ -16,18 +16,13 @@ ScopedJavaSurface::ScopedJavaSurface() { ...@@ -16,18 +16,13 @@ ScopedJavaSurface::ScopedJavaSurface() {
} }
ScopedJavaSurface::ScopedJavaSurface( ScopedJavaSurface::ScopedJavaSurface(
const base::android::JavaRef<jobject>& surface) const base::android::JavaRef<jobject>& surface) {
: auto_release_(true),
is_protected_(false) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
DCHECK(env->IsInstanceOf(surface.obj(), android_view_Surface_clazz(env))); DCHECK(env->IsInstanceOf(surface.obj(), android_view_Surface_clazz(env)));
j_surface_.Reset(surface); j_surface_.Reset(surface);
} }
ScopedJavaSurface::ScopedJavaSurface( ScopedJavaSurface::ScopedJavaSurface(const SurfaceTexture* surface_texture) {
const SurfaceTexture* surface_texture)
: auto_release_(true),
is_protected_(false) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jobject> tmp(JNI_Surface::Java_Surface_Constructor( ScopedJavaLocalRef<jobject> tmp(JNI_Surface::Java_Surface_Constructor(
env, surface_texture->j_surface_texture())); env, surface_texture->j_surface_texture()));
...@@ -45,6 +40,10 @@ ScopedJavaSurface& ScopedJavaSurface::operator=(ScopedJavaSurface&& rhs) { ...@@ -45,6 +40,10 @@ ScopedJavaSurface& ScopedJavaSurface::operator=(ScopedJavaSurface&& rhs) {
} }
ScopedJavaSurface::~ScopedJavaSurface() { ScopedJavaSurface::~ScopedJavaSurface() {
ReleaseSurfaceIfNeeded();
}
void ScopedJavaSurface::ReleaseSurfaceIfNeeded() {
if (auto_release_ && !j_surface_.is_null()) { if (auto_release_ && !j_surface_.is_null()) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
JNI_Surface::Java_Surface_release(env, j_surface_); JNI_Surface::Java_Surface_release(env, j_surface_);
...@@ -52,6 +51,7 @@ ScopedJavaSurface::~ScopedJavaSurface() { ...@@ -52,6 +51,7 @@ ScopedJavaSurface::~ScopedJavaSurface() {
} }
void ScopedJavaSurface::MoveFrom(ScopedJavaSurface& other) { void ScopedJavaSurface::MoveFrom(ScopedJavaSurface& other) {
ReleaseSurfaceIfNeeded();
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
j_surface_.Reset(env, other.j_surface_.Release()); j_surface_.Reset(env, other.j_surface_.Release());
auto_release_ = other.auto_release_; auto_release_ = other.auto_release_;
......
...@@ -57,9 +57,10 @@ class GL_EXPORT ScopedJavaSurface { ...@@ -57,9 +57,10 @@ class GL_EXPORT ScopedJavaSurface {
private: private:
// Performs destructive move from |other| to this. // Performs destructive move from |other| to this.
void MoveFrom(ScopedJavaSurface& other); void MoveFrom(ScopedJavaSurface& other);
void ReleaseSurfaceIfNeeded();
bool auto_release_; bool auto_release_ = true;
bool is_protected_; bool is_protected_ = false;
base::android::ScopedJavaGlobalRef<jobject> j_surface_; base::android::ScopedJavaGlobalRef<jobject> j_surface_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment