Chromium Code Reviews| Index: media/base/android/dialog_surface.cc |
| diff --git a/media/base/android/dialog_surface.cc b/media/base/android/dialog_surface.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8393e16c9e73d1316a9c985d77bdab74f2e88912 |
| --- /dev/null |
| +++ b/media/base/android/dialog_surface.cc |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/base/android/dialog_surface.h" |
| + |
| +#include <algorithm> |
| +#include <limits> |
| +#include <map> |
| +#include <memory> |
| +#include <utility> |
| + |
| +#include "base/android/build_info.h" |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_array.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/logging.h" |
| +#include "base/numerics/safe_conversions.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "jni/DialogSurfaceWrapper_jni.h" |
|
boliu
2017/01/04 01:48:43
there is somewhat of a tradition to call the nativ
liberato (no reviews please)
2017/01/11 22:17:56
i'll put out a separate PS with the renaming per o
|
| +#include "media/base/android/dialog_surface_callback.h" |
| +#include "media/base/android/dialog_surface_manager.h" |
| +#include "media/base/bind_to_current_loop.h" |
| +#include "media/base/bit_reader.h" |
| +#include "media/base/decrypt_config.h" |
| + |
| +using base::android::AttachCurrentThread; |
| +using base::android::JavaRef; |
| +using base::android::ScopedJavaLocalRef; |
| + |
| +namespace media { |
| + |
| +DialogSurface::DialogSurface( |
| + const JavaRef<jobject>& unwrapped_holder, |
| + std::unique_ptr<DialogSurfaceCallback> wrapped_callback) |
| + : wrapped_callback_(std::move(wrapped_callback)) { |
| + JNIEnv* env = AttachCurrentThread(); |
| + CHECK(env); |
|
boliu
2017/01/04 01:48:43
there aren't a lot of CHECK(env), or even DCHECKs
liberato (no reviews please)
2017/01/11 22:17:56
Done, and elsewhere.
|
| + |
| + // Set the callback that we'll use to get the java surface. |
| + wrapped_callback_->SetAndroidSurfaceCB( |
| + base::Bind(&DialogSurface::OnAndroidSurface, base::Unretained(this))); |
| + |
| + j_wrapped_surface_.Reset( |
| + env, Java_DialogSurfaceWrapper_wrap(env, unwrapped_holder.obj()).obj()); |
|
boliu
2017/01/04 01:48:43
are either .obj() here necessary? I'd hope everyth
liberato (no reviews please)
2017/01/11 22:17:56
turns out that the outer one is required, but the
|
| +} |
| + |
| +DialogSurface::~DialogSurface() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + |
| + wrapped_callback_->SetAndroidSurfaceCB( |
| + DialogSurfaceCallback::AndroidSurfaceCB()); |
| + |
| + JNIEnv* env = AttachCurrentThread(); |
| + CHECK(env); |
| + if (j_wrapped_surface_.obj()) |
| + Java_DialogSurfaceWrapper_release(env, j_wrapped_surface_.obj()); |
| +} |
| + |
| +void DialogSurface::ScheduleLayout(const Config& config) { |
| + DCHECK(CalledOnValidThread()); |
| + JNIEnv* env = AttachCurrentThread(); |
| + CHECK(env); |
| + Java_DialogSurfaceWrapper_scheduleLayoutSurface( |
| + env, j_wrapped_surface_.obj(), config.rect.x(), config.rect.y(), |
| + config.rect.width(), config.rect.height()); |
| +} |
| + |
| +bool DialogSurface::CalledOnValidThread() const { |
| + return thread_checker_.CalledOnValidThread(); |
| +} |
| + |
| +void DialogSurface::OnAndroidSurface( |
| + const base::android::JavaRef<jobject>& jsurface) { |
| + android_surface_ = |
|
boliu
2017/01/04 01:48:43
thread check here?
liberato (no reviews please)
2017/01/11 22:17:56
Done.
|
| + gl::ScopedJavaSurface::AcquireExternalSurface(jsurface.obj()); |
| +} |
| + |
| +gl::ScopedJavaSurface& DialogSurface::GetAndroidSurface() { |
| + return android_surface_; |
| +} |
| + |
| +} // namespace media |