Commit acd0a968 authored by Vikas Soni's avatar Vikas Soni Committed by Commit Bot

Relocate AndroidImageReader class and a media flag.

Move AndroidImageReader class out from media/gpu/android to
a more generic location base/android as this helper class will also be
used outside of the media/gpu/android.
Also make the media flag kAImageReaderVideoOutput static member of
this class since this flag is only used inside this class.

Bug: 838725
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: Ie4da6bd555db3c3ebfa3f0f01b4009010d53e704
Reviewed-on: https://chromium-review.googlesource.com/1135812Reviewed-by: default avatarFrank Liberato <liberato@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Commit-Queue: vikas soni <vikassoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575823}
parent 36970fe8
......@@ -165,6 +165,9 @@ jumbo_component("base") {
"android/android_hardware_buffer_abi.h",
"android/android_hardware_buffer_compat.cc",
"android/android_hardware_buffer_compat.h",
"android/android_image_reader_abi.h",
"android/android_image_reader_compat.cc",
"android/android_image_reader_compat.h",
"android/animation_frame_time_histogram.cc",
"android/apk_assets.cc",
"android/apk_assets.h",
......@@ -2178,6 +2181,7 @@ test("base_unittests") {
"allocator/allocator_interception_mac_unittest.mm",
"allocator/malloc_zone_functions_mac_unittest.cc",
"allocator/tcmalloc_unittest.cc",
"android/android_image_reader_compat_unittest.cc",
"android/application_status_listener_unittest.cc",
"android/content_uri_utils_unittest.cc",
"android/jni_android_unittest.cc",
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_GPU_ANDROID_ANDROID_IMAGE_READER_ABI_H_
#define MEDIA_GPU_ANDROID_ANDROID_IMAGE_READER_ABI_H_
#ifndef BASE_ANDROID_ANDROID_IMAGE_READER_ABI_H_
#define BASE_ANDROID_ANDROID_IMAGE_READER_ABI_H_
// Minimal binary interface definitions for AImage,AImageReader
// and ANativeWindow based on include/media/NdkImage.h,
......@@ -94,4 +94,4 @@ using pANativeWindow_toSurface = jobject (*)(JNIEnv* env,
} // extern "C"
#endif // MEDIA_GPU_ANDROID_ANDROID_IMAGE_READER_ABI_H_
#endif // BASE_ANDROID_ANDROID_IMAGE_READER_ABI_H_
......@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/gpu/android/android_image_reader_compat.h"
#include "base/android/android_image_reader_compat.h"
#include <dlfcn.h>
#include "base/android/build_info.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "media/base/media_switches.h"
#define LOAD_FUNCTION(lib, func) \
do { \
......@@ -20,7 +19,8 @@
} \
} while (0)
namespace media {
namespace base {
namespace android {
AndroidImageReader& AndroidImageReader::GetInstance() {
// C++11 static local variable initialization is
......@@ -34,9 +34,7 @@ bool AndroidImageReader::IsSupported() {
}
AndroidImageReader::AndroidImageReader() {
is_supported_ =
base::FeatureList::IsEnabled(media::kAImageReaderVideoOutput) &&
LoadFunctions();
is_supported_ = LoadFunctions();
}
bool AndroidImageReader::LoadFunctions() {
......@@ -140,4 +138,5 @@ jobject AndroidImageReader::ANativeWindow_toSurface(JNIEnv* env,
return ANativeWindow_toSurface_(env, window);
}
} // namespace media
} // namespace android
} // namespace base
......@@ -2,21 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_GPU_ANDROID_ANDROID_IMAGE_READER_COMPAT_H_
#define MEDIA_GPU_ANDROID_ANDROID_IMAGE_READER_COMPAT_H_
#ifndef BASE_ANDROID_ANDROID_IMAGE_READER_COMPAT_H_
#define BASE_ANDROID_ANDROID_IMAGE_READER_COMPAT_H_
#include "base/android/android_image_reader_abi.h"
#include "base/base_export.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "media/gpu/android/android_image_reader_abi.h"
#include "media/gpu/media_gpu_export.h"
namespace media {
namespace base {
namespace android {
// This class provides runtime support for working with AImage, AImageReader and
// ANativeWindow objects on Android O systems without requiring building for the
// Android O NDK level. Don't call GetInstance() unless IsSupported() returns
// true.
class MEDIA_GPU_EXPORT AndroidImageReader {
class BASE_EXPORT AndroidImageReader {
public:
// Thread safe GetInstance.
static AndroidImageReader& GetInstance();
......@@ -72,6 +73,7 @@ class MEDIA_GPU_EXPORT AndroidImageReader {
DISALLOW_COPY_AND_ASSIGN(AndroidImageReader);
};
} // namespace media
} // namespace android
} // namespace base
#endif // MEDIA_GPU_ANDROID_ANDROID_IMAGE_READER_COMPAT_H_
#endif // BASE_ANDROID_ANDROID_IMAGE_READER_COMPAT_H_
......@@ -2,27 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/gpu/android/android_image_reader_compat.h"
#include "base/android/android_image_reader_compat.h"
#include <stdint.h>
#include <memory>
#include "base/android/build_info.h"
#include "base/test/scoped_feature_list.h"
#include "media/base/media_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
namespace base {
namespace android {
class AndroidImageReaderTest : public testing::Test {
public:
AndroidImageReaderTest() {
scoped_feature_list_.InitAndEnableFeature(media::kAImageReaderVideoOutput);
}
AndroidImageReaderTest() = default;
~AndroidImageReaderTest() override = default;
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// Getting instance of AndroidImageReader will invoke AndroidImageReader
......@@ -44,4 +39,5 @@ TEST_F(AndroidImageReaderTest, CompareImageReaderInstance) {
ASSERT_EQ(&a1, &a2);
}
} // namespace media
} // namespace android
} // namespace base
......@@ -149,9 +149,6 @@ component("gpu") {
if (is_android) {
sources += [
"android/android_image_reader_abi.h",
"android/android_image_reader_compat.cc",
"android/android_image_reader_compat.h",
"android/android_video_decode_accelerator.cc",
"android/android_video_decode_accelerator.h",
"android/android_video_encode_accelerator.cc",
......@@ -429,7 +426,6 @@ source_set("android_video_decode_accelerator_unittests") {
if (is_android) {
testonly = true
sources = [
"android/android_image_reader_compat_unittest.cc",
"android/android_video_decode_accelerator_unittest.cc",
"android/android_video_surface_chooser_impl_unittest.cc",
"android/avda_codec_allocator_unittest.cc",
......
......@@ -47,7 +47,7 @@ struct FrameAvailableEvent_ImageReader
ImageReaderGLOwner::ImageReaderGLOwner(GLuint texture_id)
: current_image_(nullptr),
texture_id_(texture_id),
loader_(AndroidImageReader::GetInstance()),
loader_(base::android::AndroidImageReader::GetInstance()),
context_(gl::GLContext::GetCurrent()),
surface_(gl::GLSurface::GetCurrent()),
frame_available_event_(new FrameAvailableEvent_ImageReader()) {
......
......@@ -7,7 +7,7 @@
#include <memory>
#include "media/gpu/android/android_image_reader_compat.h"
#include "base/android/android_image_reader_compat.h"
#include "media/gpu/android/texture_owner.h"
#include "ui/gl/gl_fence_egl.h"
#include "ui/gl/gl_image_ahardwarebuffer.h"
......@@ -53,7 +53,7 @@ class MEDIA_GPU_EXPORT ImageReaderGLOwner : public TextureOwner {
// reference to the class instance which is used to dynamically
// load the functions in android libraries at runtime.
AndroidImageReader& loader_;
base::android::AndroidImageReader& loader_;
// The context and surface that were used to create |texture_id_|.
scoped_refptr<gl::GLContext> context_;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/gpu/android/image_reader_gl_owner.h"
#include "media/gpu/android/texture_owner.h"
#include <stdint.h>
#include <memory>
......@@ -36,7 +36,7 @@ class ImageReaderGLOwnerTest : public testing::Test {
context_->Initialize(surface_.get(), gl::GLContextAttribs());
ASSERT_TRUE(context_->MakeCurrent(surface_.get()));
image_reader_ = ImageReaderGLOwner::Create();
image_reader_ = TextureOwner::Create();
}
void TearDown() override {
......
......@@ -4,8 +4,10 @@
#include "media/gpu/android/texture_owner.h"
#include "base/android/android_image_reader_compat.h"
#include "base/feature_list.h"
#include "base/threading/thread_task_runner_handle.h"
#include "media/gpu/android/android_image_reader_compat.h"
#include "media/base/media_switches.h"
#include "media/gpu/android/image_reader_gl_owner.h"
#include "media/gpu/android/surface_texture_gl_owner.h"
#include "ui/gl/scoped_binders.h"
......@@ -34,8 +36,9 @@ scoped_refptr<TextureOwner> TextureOwner::Create() {
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
if (AndroidImageReader::GetInstance().IsSupported()) {
// If image reader is supported, use it.
// If AImageReader is supported and is enabled by media flag, use it.
if (base::FeatureList::IsEnabled(media::kAImageReaderVideoOutput) &&
base::android::AndroidImageReader::GetInstance().IsSupported()) {
return new ImageReaderGLOwner(texture_id);
}
......
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