Support passthrough for shared image AHardwarebuffer backing
Bug: 1156801 Change-Id: Ib163666ea9d4a940e3da6e23037422bef814573b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580167 Commit-Queue: Peng Huang <penghuang@chromium.org> Reviewed-by: vikas soni <vikassoni@chromium.org> Cr-Commit-Position: refs/heads/master@{#835654}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
3247437d31
commit
9ae347729c
@ -443,6 +443,8 @@ target(link_target_type, "gles2_sources") {
|
||||
"shared_image_batch_access_manager.h",
|
||||
"shared_image_representation_gl_texture_android.cc",
|
||||
"shared_image_representation_gl_texture_android.h",
|
||||
"shared_image_representation_gl_texture_passthrough_android.cc",
|
||||
"shared_image_representation_gl_texture_passthrough_android.h",
|
||||
"shared_image_representation_skia_vk_android.cc",
|
||||
"shared_image_representation_skia_vk_android.h",
|
||||
"shared_image_video.cc",
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "gpu/command_buffer/service/shared_image_backing_android.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation_gl_texture_android.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation_gl_texture_passthrough_android.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation_skia_gl.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation_skia_vk_android.h"
|
||||
#include "gpu/command_buffer/service/skia_utils.h"
|
||||
@ -161,6 +162,10 @@ class SharedImageBackingAHB : public SharedImageBackingAndroid {
|
||||
SharedImageManager* manager,
|
||||
MemoryTypeTracker* tracker) override;
|
||||
|
||||
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
|
||||
ProduceGLTexturePassthrough(SharedImageManager* manager,
|
||||
MemoryTypeTracker* tracker) override;
|
||||
|
||||
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
|
||||
SharedImageManager* manager,
|
||||
MemoryTypeTracker* tracker,
|
||||
@ -361,6 +366,28 @@ SharedImageBackingAHB::ProduceGLTexture(SharedImageManager* manager,
|
||||
manager, this, tracker, std::move(texture));
|
||||
}
|
||||
|
||||
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
|
||||
SharedImageBackingAHB::ProduceGLTexturePassthrough(SharedImageManager* manager,
|
||||
MemoryTypeTracker* tracker) {
|
||||
// Use same texture for all the texture representations generated from same
|
||||
// backing.
|
||||
DCHECK(hardware_buffer_handle_.is_valid());
|
||||
|
||||
// Note that we are not using GL_TEXTURE_EXTERNAL_OES target(here and all
|
||||
// other places in this file) since sksurface
|
||||
// doesn't supports it. As per the egl documentation -
|
||||
// https://www.khronos.org/registry/OpenGL/extensions/OES/OES_EGL_image_external.txt
|
||||
// if GL_OES_EGL_image is supported then <target> may also be TEXTURE_2D.
|
||||
auto texture = GenGLTexturePassthrough(hardware_buffer_handle_.get(),
|
||||
GL_TEXTURE_2D, color_space(), size(),
|
||||
estimated_size(), ClearedRect());
|
||||
if (!texture)
|
||||
return nullptr;
|
||||
|
||||
return std::make_unique<SharedImageRepresentationGLTexturePassthroughAndroid>(
|
||||
manager, this, tracker, std::move(texture));
|
||||
}
|
||||
|
||||
std::unique_ptr<SharedImageRepresentationSkia>
|
||||
SharedImageBackingAHB::ProduceSkia(
|
||||
SharedImageManager* manager,
|
||||
|
82
gpu/command_buffer/service/shared_image_representation_gl_texture_passthrough_android.cc
Normal file
82
gpu/command_buffer/service/shared_image_representation_gl_texture_passthrough_android.cc
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright 2020 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 "shared_image_representation_gl_texture_passthrough_android.h"
|
||||
|
||||
#include "gpu/command_buffer/service/texture_manager.h"
|
||||
#include "gpu/ipc/common/android/android_image_reader_utils.h"
|
||||
|
||||
namespace gpu {
|
||||
|
||||
SharedImageRepresentationGLTexturePassthroughAndroid::
|
||||
SharedImageRepresentationGLTexturePassthroughAndroid(
|
||||
SharedImageManager* manager,
|
||||
SharedImageBackingAndroid* backing,
|
||||
MemoryTypeTracker* tracker,
|
||||
scoped_refptr<gles2::TexturePassthrough> texture)
|
||||
: SharedImageRepresentationGLTexturePassthrough(manager, backing, tracker),
|
||||
texture_(std::move(texture)) {
|
||||
DCHECK(texture_);
|
||||
}
|
||||
|
||||
SharedImageRepresentationGLTexturePassthroughAndroid::
|
||||
~SharedImageRepresentationGLTexturePassthroughAndroid() {
|
||||
EndAccess();
|
||||
if (!has_context())
|
||||
texture_->MarkContextLost();
|
||||
}
|
||||
|
||||
const scoped_refptr<gles2::TexturePassthrough>&
|
||||
SharedImageRepresentationGLTexturePassthroughAndroid::GetTexturePassthrough() {
|
||||
return texture_;
|
||||
}
|
||||
|
||||
bool SharedImageRepresentationGLTexturePassthroughAndroid::BeginAccess(
|
||||
GLenum mode) {
|
||||
bool read_only_mode = (mode == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM) ||
|
||||
(mode == GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM);
|
||||
bool read_write_mode =
|
||||
(mode == GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM);
|
||||
DCHECK(read_only_mode || read_write_mode);
|
||||
|
||||
if (read_only_mode) {
|
||||
base::ScopedFD write_sync_fd;
|
||||
if (!android_backing()->BeginRead(this, &write_sync_fd))
|
||||
return false;
|
||||
if (!InsertEglFenceAndWait(std::move(write_sync_fd)))
|
||||
return false;
|
||||
} else {
|
||||
base::ScopedFD sync_fd;
|
||||
if (!android_backing()->BeginWrite(&sync_fd))
|
||||
return false;
|
||||
|
||||
if (!InsertEglFenceAndWait(std::move(sync_fd)))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (read_only_mode)
|
||||
mode_ = RepresentationAccessMode::kRead;
|
||||
else
|
||||
mode_ = RepresentationAccessMode::kWrite;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SharedImageRepresentationGLTexturePassthroughAndroid::EndAccess() {
|
||||
if (mode_ == RepresentationAccessMode::kNone)
|
||||
return;
|
||||
|
||||
base::ScopedFD sync_fd = CreateEglFenceAndExportFd();
|
||||
|
||||
// Pass this fd to its backing.
|
||||
if (mode_ == RepresentationAccessMode::kRead) {
|
||||
android_backing()->EndRead(this, std::move(sync_fd));
|
||||
} else if (mode_ == RepresentationAccessMode::kWrite) {
|
||||
android_backing()->EndWrite(std::move(sync_fd));
|
||||
}
|
||||
|
||||
mode_ = RepresentationAccessMode::kNone;
|
||||
}
|
||||
|
||||
} // namespace gpu
|
46
gpu/command_buffer/service/shared_image_representation_gl_texture_passthrough_android.h
Normal file
46
gpu/command_buffer/service/shared_image_representation_gl_texture_passthrough_android.h
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright 2020 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.
|
||||
|
||||
#ifndef GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_REPRESENTATION_GL_TEXTURE_PASSTHROUGH_ANDROID_H_
|
||||
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_REPRESENTATION_GL_TEXTURE_PASSTHROUGH_ANDROID_H_
|
||||
|
||||
#include "gpu/command_buffer/service/shared_image_backing_android.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation.h"
|
||||
|
||||
namespace gpu {
|
||||
class SharedImageBackingAndroid;
|
||||
|
||||
class SharedImageRepresentationGLTexturePassthroughAndroid
|
||||
: public SharedImageRepresentationGLTexturePassthrough {
|
||||
public:
|
||||
SharedImageRepresentationGLTexturePassthroughAndroid(
|
||||
SharedImageManager* manager,
|
||||
SharedImageBackingAndroid* backing,
|
||||
MemoryTypeTracker* tracker,
|
||||
scoped_refptr<gles2::TexturePassthrough> texture);
|
||||
~SharedImageRepresentationGLTexturePassthroughAndroid() override;
|
||||
|
||||
const scoped_refptr<gles2::TexturePassthrough>& GetTexturePassthrough()
|
||||
override;
|
||||
|
||||
bool BeginAccess(GLenum mode) override;
|
||||
void EndAccess() override;
|
||||
|
||||
private:
|
||||
SharedImageBackingAndroid* android_backing() {
|
||||
return static_cast<SharedImageBackingAndroid*>(backing());
|
||||
}
|
||||
|
||||
scoped_refptr<gles2::TexturePassthrough> texture_;
|
||||
RepresentationAccessMode mode_ = RepresentationAccessMode::kNone;
|
||||
|
||||
SharedImageRepresentationGLTexturePassthroughAndroid(
|
||||
const SharedImageRepresentationGLTexturePassthroughAndroid&) = delete;
|
||||
SharedImageRepresentationGLTexturePassthroughAndroid& operator=(
|
||||
const SharedImageRepresentationGLTexturePassthroughAndroid&) = delete;
|
||||
};
|
||||
|
||||
} // namespace gpu
|
||||
|
||||
#endif // GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_REPRESENTATION_GL_TEXTURE_PASSTHROUGH_ANDROID_H_
|
Reference in New Issue
Block a user