Skip to content

Commit

Permalink
Unify TextureOwner and StreamTexture.
Browse files Browse the repository at this point in the history
1. Move media::TextureOwner to gpu::TextureOwner by relocating
   files from media/gpu/android/ to gpu/ipc/common/android/.

2. Move TextureOwner unit-tests and relevant mock files to
   gpu/ipc/common/android/.

3. Unify SurfaceOwner and TextureOwner into TextureOwner.
   This removes/deletes SurfaceOwner.

4. Update several BUILD files due to above refactoring.

Bug: 989344
Change-Id: I446ccdd2d68bd7cf9a7d515a7fe446899e1af589
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1745626
Reviewed-by: Frank Liberato <liberato@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Eric Karl <ericrk@chromium.org>
Commit-Queue: vikas soni <vikassoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#687817}
  • Loading branch information
vikaschromie authored and Commit Bot committed Aug 16, 2019
1 parent d8f9ea5 commit aa04e98
Show file tree
Hide file tree
Showing 48 changed files with 342 additions and 574 deletions.
4 changes: 2 additions & 2 deletions content/app/android/content_child_process_service_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class ChildProcessSurfaceManager : public gpu::ScopedSurfaceRequestConduit,
// Overriden from ScopedSurfaceRequestConduit:
void ForwardSurfaceOwnerForSurfaceRequest(
const base::UnguessableToken& request_token,
const gpu::SurfaceOwner* surface_owner) override {
const gpu::TextureOwner* texture_owner) override {
JNIEnv* env = base::android::AttachCurrentThread();

content::
Java_ContentChildProcessServiceDelegate_forwardSurfaceForSurfaceRequest(
env, service_impl_,
base::android::UnguessableTokenAndroid::Create(env, request_token),
surface_owner->CreateJavaSurface().j_surface());
texture_owner->CreateJavaSurface().j_surface());
}

// Overridden from GpuSurfaceLookup:
Expand Down
1 change: 1 addition & 0 deletions content/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,7 @@ jumbo_source_set("browser") {
"//build/config/freetype",
"//content/public/android:jni",
"//device/gamepad/public/mojom",
"//gpu/ipc/common:android_texture_owner",
"//media",
"//media/capture/content/android",
"//media/capture/video/android",
Expand Down
4 changes: 2 additions & 2 deletions content/browser/android/scoped_surface_request_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ ScopedSurfaceRequestManager::GetAndUnregisterInternal(

void ScopedSurfaceRequestManager::ForwardSurfaceOwnerForSurfaceRequest(
const base::UnguessableToken& request_token,
const gpu::SurfaceOwner* surface_owner) {
const gpu::TextureOwner* texture_owner) {
FulfillScopedSurfaceRequest(request_token,
surface_owner->CreateJavaSurface());
texture_owner->CreateJavaSurface());
}

void ScopedSurfaceRequestManager::FulfillScopedSurfaceRequest(
Expand Down
2 changes: 1 addition & 1 deletion content/browser/android/scoped_surface_request_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CONTENT_EXPORT ScopedSurfaceRequestManager
// Can be called from any thread.
void ForwardSurfaceOwnerForSurfaceRequest(
const base::UnguessableToken& request_token,
const gpu::SurfaceOwner* surface_owner) override;
const gpu::TextureOwner* texture_owner) override;

void clear_requests_for_testing() { request_callbacks_.clear(); }

Expand Down
18 changes: 10 additions & 8 deletions content/browser/android/scoped_surface_request_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "base/callback_forward.h"
#include "base/run_loop.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "gpu/ipc/common/android/surface_owner_android.h"
#include "gpu/ipc/common/android/mock_texture_owner.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/android/scoped_java_surface.h"
#include "ui/gl/android/surface_texture.h"
Expand All @@ -27,7 +27,8 @@ class ScopedSurfaceRequestManagerUnitTest : public testing::Test {
last_received_request_ = 0;
dummy_token_ = base::UnguessableToken::Deserialize(123, 456);

surface_owner = gpu::SurfaceOwner::Create(0);
mock_texture_owner = base::MakeRefCounted<NiceMock<gpu::MockTextureOwner>>(
0, nullptr, nullptr);
dummy_request_ =
base::Bind(&ScopedSurfaceRequestManagerUnitTest::DummyCallback,
base::Unretained(this));
Expand All @@ -47,7 +48,7 @@ class ScopedSurfaceRequestManagerUnitTest : public testing::Test {

ScopedSurfaceRequestManager::ScopedSurfaceRequestCB dummy_request_;
ScopedSurfaceRequestManager::ScopedSurfaceRequestCB specific_logging_request_;
std::unique_ptr<gpu::SurfaceOwner> surface_owner;
scoped_refptr<NiceMock<gpu::MockTextureOwner>> mock_texture_owner;

int last_received_request_;
const int kSpecificCallbackId = 1357;
Expand Down Expand Up @@ -140,8 +141,8 @@ TEST_F(ScopedSurfaceRequestManagerUnitTest,
FulfillUnregisteredRequest_ShouldDoNothing) {
manager_->RegisterScopedSurfaceRequest(specific_logging_request_);

manager_->FulfillScopedSurfaceRequest(dummy_token_,
surface_owner->CreateJavaSurface());
manager_->FulfillScopedSurfaceRequest(
dummy_token_, mock_texture_owner->CreateJavaSurface());

EXPECT_EQ(1, manager_->request_count_for_testing());
EXPECT_NE(kSpecificCallbackId, last_received_request_);
Expand All @@ -159,8 +160,8 @@ TEST_F(ScopedSurfaceRequestManagerUnitTest,
base::Bind(&ScopedSurfaceRequestManagerUnitTest::LoggingCallback,
base::Unretained(this), kOtherCallbackId));

manager_->FulfillScopedSurfaceRequest(specific_token,
surface_owner->CreateJavaSurface());
manager_->FulfillScopedSurfaceRequest(
specific_token, mock_texture_owner->CreateJavaSurface());

base::RunLoop().RunUntilIdle();

Expand All @@ -175,7 +176,8 @@ TEST_F(ScopedSurfaceRequestManagerUnitTest,
base::UnguessableToken token =
manager_->RegisterScopedSurfaceRequest(specific_logging_request_);

manager_->ForwardSurfaceOwnerForSurfaceRequest(token, surface_owner.get());
manager_->ForwardSurfaceOwnerForSurfaceRequest(token,
mock_texture_owner.get());

base::RunLoop().RunUntilIdle();

Expand Down
1 change: 1 addition & 0 deletions content/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,7 @@ test("content_unittests") {
"//build/config/freetype",
"//components/download/internal/common:internal_java",
"//content/public/android:content_java",
"//gpu/ipc/common:android_texture_owner_test_support",
"//media/capture/content/android",
"//media/capture/content/android:screen_capture_java",
"//third_party/blink/public/common",
Expand Down
77 changes: 72 additions & 5 deletions gpu/ipc/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,12 @@ source_set("ipc_common_sources") {

if (is_android) {
sources += [
"android/scoped_surface_request_conduit.cc",
"android/scoped_surface_request_conduit.h",
"android/surface_owner_android.cc",
"android/surface_owner_android.h",
"gpu_surface_lookup.cc",
"gpu_surface_lookup.h",
"gpu_surface_tracker.cc",
"gpu_surface_tracker.h",
]
libs = [ "android" ]
deps += [ ":android_image_reader_utils" ]
}

if (use_ozone) {
Expand All @@ -178,6 +173,78 @@ if (is_android) {
}
}

if (is_android) {
component("android_texture_owner") {
sources = [
"android/image_reader_gl_owner.cc",
"android/image_reader_gl_owner.h",
"android/scoped_surface_request_conduit.cc",
"android/scoped_surface_request_conduit.h",
"android/surface_texture_gl_owner.cc",
"android/surface_texture_gl_owner.h",
"android/texture_owner.cc",
"android/texture_owner.h",
]
configs += [ "//gpu:gpu_implementation" ]
deps = [
":android_image_reader_utils",
"//base",
"//gpu/command_buffer/service:gles2_sources",
"//gpu/command_buffer/service:service_sources",
"//ui/gl",
]
libs = [ "android" ]
visibility = [
"//gpu/*",
"//media/gpu:gpu",
"//content/browser:browser",
]
}
}

if (is_android) {
jumbo_static_library("android_texture_owner_test_support") {
testonly = true
sources = [
"android/mock_abstract_texture.cc",
"android/mock_abstract_texture.h",
"android/mock_texture_owner.cc",
"android/mock_texture_owner.h",
]
deps = [
":android_texture_owner",
"//base/test:test_support",
"//gpu:test_support",
"//testing/gmock",
"//testing/gtest",
"//ui/gl",
"//ui/gl/init",
]
}
}

if (is_android) {
source_set("android_texture_owner_unittests") {
testonly = true
sources = [
"android/image_reader_gl_owner_unittest.cc",
"android/surface_texture_gl_owner_unittest.cc",
]

deps = [
":android_texture_owner",
":android_texture_owner_test_support",
"//base/test:test_support",
"//gpu:test_support",
"//media/base:base",
"//testing/gmock",
"//testing/gtest",
"//ui/gl",
"//ui/gl/init",
]
}
}

# Depend on this to use surface_handle.h without pulling in all of gpu ipc.
source_set("surface_handle_type") {
public = [
Expand Down
1 change: 1 addition & 0 deletions gpu/ipc/common/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ include_rules = [
"+mojo",
"+ui/base",
"+ui/latency",
"+media/base/media_switches.h",
]
Original file line number Diff line number Diff line change
Expand Up @@ -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 "gpu/ipc/common/android/image_reader_gl_owner.h"

#include <android/native_window_jni.h>
#include <jni.h>
Expand All @@ -25,7 +25,7 @@
#include "ui/gl/scoped_binders.h"
#include "ui/gl/scoped_make_current.h"

namespace media {
namespace gpu {

namespace {
bool IsSurfaceControl(TextureOwner::Mode mode) {
Expand Down Expand Up @@ -76,7 +76,7 @@ class ImageReaderGLOwner::ScopedHardwareBufferImpl
};

ImageReaderGLOwner::ImageReaderGLOwner(
std::unique_ptr<gpu::gles2::AbstractTexture> texture,
std::unique_ptr<gles2::AbstractTexture> texture,
Mode mode)
: TextureOwner(false /* binds_texture_on_image_update */,
std::move(texture)),
Expand Down Expand Up @@ -117,7 +117,7 @@ ImageReaderGLOwner::ImageReaderGLOwner(
if (return_code != AMEDIA_OK) {
LOG(ERROR) << " Image reader creation failed.";
if (return_code == AMEDIA_ERROR_INVALID_PARAMETER)
LOG(ERROR) << "Either reader is NULL, or one or more of width, height, "
LOG(ERROR) << "Either reader is null, or one or more of width, height, "
"format, maxImages arguments is not supported";
else
LOG(ERROR) << "unknown error";
Expand Down Expand Up @@ -152,7 +152,7 @@ ImageReaderGLOwner::~ImageReaderGLOwner() {
DCHECK_EQ(image_refs_.size(), 0u);
}

void ImageReaderGLOwner::OnTextureDestroyed(gpu::gles2::AbstractTexture*) {
void ImageReaderGLOwner::OnTextureDestroyed(gles2::AbstractTexture*) {
// The AbstractTexture is being destroyed. This can happen if, for example,
// the video decoder's gl context is lost. Remember that the platform texture
// might not be gone; it's possible for the gl decoder (and AbstractTexture)
Expand All @@ -165,7 +165,7 @@ void ImageReaderGLOwner::OnTextureDestroyed(gpu::gles2::AbstractTexture*) {
DCHECK(image_reader_);

// Now we can stop listening to new images.
loader_.AImageReader_setImageListener(image_reader_, NULL);
loader_.AImageReader_setImageListener(image_reader_, nullptr);

// Delete all images before closing the associated image reader.
for (auto& image_ref : image_refs_)
Expand All @@ -183,6 +183,7 @@ void ImageReaderGLOwner::OnTextureDestroyed(gpu::gles2::AbstractTexture*) {

void ImageReaderGLOwner::SetFrameAvailableCallback(
const base::RepeatingClosure& frame_available_cb) {
DCHECK(!frame_available_cb_);
frame_available_cb_ = std::move(frame_available_cb);
}

Expand Down Expand Up @@ -241,7 +242,7 @@ void ImageReaderGLOwner::UpdateTexImage() {
// just return if error occurs.
switch (return_code) {
case AMEDIA_ERROR_INVALID_PARAMETER:
LOG(ERROR) << " Image is NULL";
LOG(ERROR) << " Image is null";
base::UmaHistogramSparse("Media.AImageReaderGLOwner.AcquireImageResult",
return_code);
return;
Expand Down Expand Up @@ -397,7 +398,7 @@ ImageReaderGLOwner::ScopedCurrentImageRef::~ScopedCurrentImageRef() {
// If there is no |image_reader_|, we are in tear down so no fence is
// required.
if (image_bound_ && texture_owner_->image_reader_)
release_fence = gpu::CreateEglFenceAndExportFd();
release_fence = CreateEglFenceAndExportFd();
else
release_fence = std::move(ready_fence_);
texture_owner_->ReleaseRefOnImage(image_, std::move(release_fence));
Expand All @@ -413,15 +414,15 @@ void ImageReaderGLOwner::ScopedCurrentImageRef::EnsureBound() {
return;

// Insert an EGL fence and make server wait for image to be available.
if (!gpu::InsertEglFenceAndWait(GetReadyFence()))
if (!InsertEglFenceAndWait(GetReadyFence()))
return;

// Create EGL image from the AImage and bind it to the texture.
if (!gpu::CreateAndBindEglImage(image_, texture_owner_->GetTextureId(),
&texture_owner_->loader_))
if (!CreateAndBindEglImage(image_, texture_owner_->GetTextureId(),
&texture_owner_->loader_))
return;

image_bound_ = true;
}

} // namespace media
} // namespace gpu
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_GPU_ANDROID_IMAGE_READER_GL_OWNER_H_
#define MEDIA_GPU_ANDROID_IMAGE_READER_GL_OWNER_H_
#ifndef GPU_IPC_COMMON_ANDROID_IMAGE_READER_GL_OWNER_H_
#define GPU_IPC_COMMON_ANDROID_IMAGE_READER_GL_OWNER_H_

#include <memory>

#include "base/android/android_image_reader_compat.h"
#include "base/containers/flat_map.h"
#include "media/gpu/android/texture_owner.h"
#include "gpu/ipc/common/android/texture_owner.h"
#include "ui/gl/gl_fence_egl.h"
#include "ui/gl/gl_image_ahardwarebuffer.h"

Expand All @@ -19,15 +19,15 @@ class ScopedHardwareBufferFenceSync;
} // namespace android
} // namespace base

namespace media {
namespace gpu {

// This class wraps the AImageReader usage and is used to create a GL texture
// using the current platform GL context and returns a new ImageReaderGLOwner
// attached to it. The surface handle of the AImageReader is attached to
// decoded media frames. Media frames can update the attached surface handle
// with image data and this class helps to create an eglImage using that image
// data present in the surface.
class MEDIA_GPU_EXPORT ImageReaderGLOwner : public TextureOwner {
class GPU_EXPORT ImageReaderGLOwner : public TextureOwner {
public:
gl::GLContext* GetContext() const override;
gl::GLSurface* GetSurface() const override;
Expand All @@ -45,7 +45,7 @@ class MEDIA_GPU_EXPORT ImageReaderGLOwner : public TextureOwner {
int32_t max_images_for_testing() const { return max_images_; }

protected:
void OnTextureDestroyed(gpu::gles2::AbstractTexture*) override;
void OnTextureDestroyed(gles2::AbstractTexture*) override;

private:
friend class TextureOwner;
Expand Down Expand Up @@ -74,7 +74,7 @@ class MEDIA_GPU_EXPORT ImageReaderGLOwner : public TextureOwner {
DISALLOW_COPY_AND_ASSIGN(ScopedCurrentImageRef);
};

ImageReaderGLOwner(std::unique_ptr<gpu::gles2::AbstractTexture> texture,
ImageReaderGLOwner(std::unique_ptr<gles2::AbstractTexture> texture,
Mode secure_mode);
~ImageReaderGLOwner() override;

Expand Down Expand Up @@ -130,6 +130,6 @@ class MEDIA_GPU_EXPORT ImageReaderGLOwner : public TextureOwner {
DISALLOW_COPY_AND_ASSIGN(ImageReaderGLOwner);
};

} // namespace media
} // namespace gpu

#endif // MEDIA_GPU_ANDROID_IMAGE_READER_GL_OWNER_H_
#endif // GPU_IPC_COMMON_ANDROID_IMAGE_READER_GL_OWNER_H_
Loading

0 comments on commit aa04e98

Please sign in to comment.