Commit b7d33d6a authored by Brian Ho's avatar Brian Ho Committed by Commit Bot

gpu: Add a GL representation for Ozone SharedImage

This CL creates a SharedImageRepresentationGLTexture for Ozone-based
SharedImages. The representation creates a GLImage from the pixmap
via GLImageNativePixmap::Initialize and then binds it to a GL texture.

Like in the case of the Pixmap Dawn representation, synchronization
will be added in a future CL.

Also, updates SharedImageBackingOzone to properly track the cleared
rect now that it is being used on SIRGLTexture::BeginAccess as per
chromium-review.googlesource.com/1990195.

Bug: 1023997,996470
Change-Id: Icacf20bc0f754fbc8acb37693618f2aca64568e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1913085
Commit-Queue: Brian Ho <hob@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738665}
parent ea7d2f0f
......@@ -347,6 +347,8 @@ target(link_target_type, "gles2_sources") {
sources += [
"shared_image_backing_ozone.cc",
"shared_image_backing_ozone.h",
"shared_image_representation_gl_ozone.cc",
"shared_image_representation_gl_ozone.h",
]
}
......
......@@ -23,6 +23,7 @@
#include "gpu/command_buffer/service/shared_context_state.h"
#include "gpu/command_buffer/service/shared_image_manager.h"
#include "gpu/command_buffer/service/shared_image_representation.h"
#include "gpu/command_buffer/service/shared_image_representation_gl_ozone.h"
#include "gpu/vulkan/vulkan_device_queue.h"
#include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/buffer_types.h"
......@@ -95,15 +96,6 @@ std::unique_ptr<SharedImageBackingOzone> SharedImageBackingOzone::Create(
SharedImageBackingOzone::~SharedImageBackingOzone() = default;
gfx::Rect SharedImageBackingOzone::ClearedRect() const {
NOTIMPLEMENTED_LOG_ONCE();
return gfx::Rect();
}
void SharedImageBackingOzone::SetClearedRect(const gfx::Rect& cleared_rect) {
NOTIMPLEMENTED_LOG_ONCE();
}
void SharedImageBackingOzone::Update(std::unique_ptr<gfx::GpuFence> in_fence) {
NOTIMPLEMENTED_LOG_ONCE();
return;
......@@ -134,8 +126,8 @@ SharedImageBackingOzone::ProduceDawn(SharedImageManager* manager,
std::unique_ptr<SharedImageRepresentationGLTexture>
SharedImageBackingOzone::ProduceGLTexture(SharedImageManager* manager,
MemoryTypeTracker* tracker) {
NOTIMPLEMENTED_LOG_ONCE();
return nullptr;
return SharedImageRepresentationGLOzone::Create(manager, this, tracker,
pixmap_, format());
}
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
......@@ -171,7 +163,7 @@ SharedImageBackingOzone::SharedImageBackingOzone(
SharedContextState* context_state,
scoped_refptr<gfx::NativePixmap> pixmap,
scoped_refptr<base::RefCountedData<DawnProcTable>> dawn_procs)
: SharedImageBacking(mailbox,
: ClearTrackingSharedImageBacking(mailbox,
format,
size,
color_space,
......
......@@ -30,7 +30,7 @@ namespace gpu {
// Implementation of SharedImageBacking that uses a NativePixmap created via
// an Ozone surface factory. The memory associated with the pixmap can be
// aliased by both GL and Vulkan for use in rendering or compositing.
class SharedImageBackingOzone final : public SharedImageBacking {
class SharedImageBackingOzone final : public ClearTrackingSharedImageBacking {
public:
static std::unique_ptr<SharedImageBackingOzone> Create(
scoped_refptr<base::RefCountedData<DawnProcTable>> dawn_procs,
......@@ -43,8 +43,6 @@ class SharedImageBackingOzone final : public SharedImageBacking {
~SharedImageBackingOzone() override;
// gpu::SharedImageBacking:
gfx::Rect ClearedRect() const override;
void SetClearedRect(const gfx::Rect& cleared_rect) override;
void Update(std::unique_ptr<gfx::GpuFence> in_fence) override;
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) override;
......
// 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 "gpu/command_buffer/service/shared_image_representation_gl_ozone.h"
#include "base/memory/scoped_refptr.h"
#include "components/viz/common/resources/resource_format.h"
#include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/shared_image_backing.h"
#include "gpu/command_buffer/service/shared_image_manager.h"
#include "gpu/command_buffer/service/shared_image_representation.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "ui/gfx/native_pixmap.h"
#include "ui/gl/buffer_format_utils.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_fence.h"
#include "ui/gl/gl_gl_api_implementation.h"
#include "ui/gl/gl_image_native_pixmap.h"
#include "ui/gl/gl_image_shared_memory.h"
#include "ui/gl/gl_version_info.h"
#include "ui/gl/scoped_binders.h"
#include "ui/gl/trace_util.h"
namespace gpu {
// static
std::unique_ptr<SharedImageRepresentationGLOzone>
SharedImageRepresentationGLOzone::Create(
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
scoped_refptr<gfx::NativePixmap> pixmap,
viz::ResourceFormat format) {
gl::GLApi* api = gl::g_current_gl_context;
DCHECK(api);
GLuint internal_format = viz::TextureStorageFormat(format);
GLuint gl_texture_service_id;
api->glGenTexturesFn(1, &gl_texture_service_id);
gl::ScopedTextureBinder binder(GL_TEXTURE_2D, gl_texture_service_id);
gfx::BufferFormat buffer_format = viz::BufferFormat(format);
auto image = base::MakeRefCounted<gl::GLImageNativePixmap>(
pixmap->GetBufferSize(), buffer_format);
if (!image->Initialize(pixmap)) {
DLOG(ERROR) << "Unable to initialize EGL image from pixmap";
return nullptr;
}
api->glTexParameteriFn(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
api->glTexParameteriFn(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
api->glTexParameteriFn(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
api->glTexParameteriFn(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (!image->BindTexImage(GL_TEXTURE_2D)) {
DLOG(ERROR) << "Unable to bind EGL image to GL_TEXTURE_2D";
return nullptr;
}
gles2::Texture* texture = new gles2::Texture(gl_texture_service_id);
texture->SetLightweightRef();
texture->SetTarget(GL_TEXTURE_2D, 1 /*max_levels=*/);
texture->sampler_state_.min_filter = GL_LINEAR;
texture->sampler_state_.mag_filter = GL_LINEAR;
texture->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE;
texture->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE;
GLenum gl_format = viz::GLDataFormat(format);
GLenum gl_type = viz::GLDataType(format);
texture->SetLevelImage(GL_TEXTURE_2D, 0, image.get(), gles2::Texture::BOUND);
texture->SetLevelInfo(GL_TEXTURE_2D, 0, internal_format,
pixmap->GetBufferSize().width(),
pixmap->GetBufferSize().height(), 1, 0, gl_format,
gl_type, backing->ClearedRect());
texture->SetImmutable(true, true);
return base::WrapUnique<SharedImageRepresentationGLOzone>(
new SharedImageRepresentationGLOzone(manager, backing, tracker, texture));
}
SharedImageRepresentationGLOzone::SharedImageRepresentationGLOzone(
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
gles2::Texture* texture)
: SharedImageRepresentationGLTexture(manager, backing, tracker),
texture_(texture) {}
SharedImageRepresentationGLOzone::~SharedImageRepresentationGLOzone() {
texture_->RemoveLightweightRef(has_context());
}
gles2::Texture* SharedImageRepresentationGLOzone::GetTexture() {
return texture_;
}
bool SharedImageRepresentationGLOzone::BeginAccess(GLenum mode) {
// TODO(hob): Synchronize access to the dma-buf by waiting on all semaphores
// tracked by SharedImageBackingOzone.
return true;
}
void SharedImageRepresentationGLOzone::EndAccess() {
// TODO(hob): Synchronize access to the dma-buf by signaling completion via
// glSignalSemaphoreEXT.
}
} // namespace gpu
// 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_OZONE_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_REPRESENTATION_GL_OZONE_H_
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "components/viz/common/resources/resource_format.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/shared_image_backing.h"
#include "gpu/command_buffer/service/shared_image_manager.h"
#include "gpu/command_buffer/service/shared_image_representation.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "ui/gfx/native_pixmap.h"
namespace gpu {
// Representation of an Ozone-backed SharedImage that can be accessed as a
// GL texture.
class SharedImageRepresentationGLOzone
: public SharedImageRepresentationGLTexture {
public:
// Creates and initializes a SharedImageRepresentationGLOzone. On failure,
// returns nullptr.
static std::unique_ptr<SharedImageRepresentationGLOzone> Create(
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
scoped_refptr<gfx::NativePixmap> pixmap,
viz::ResourceFormat format);
~SharedImageRepresentationGLOzone() override;
// SharedImageRepresentationGLTexture implementation.
gles2::Texture* GetTexture() override;
bool BeginAccess(GLenum mode) override;
void EndAccess() override;
private:
SharedImageRepresentationGLOzone(SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
gles2::Texture* texture);
gles2::Texture* texture_;
DISALLOW_COPY_AND_ASSIGN(SharedImageRepresentationGLOzone);
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_REPRESENTATION_GL_OZONE_H_
......@@ -49,6 +49,7 @@ class SharedImageRepresentationSkiaGLAHB;
class SharedImageBackingIOSurface;
class SharedImageRepresentationGLTextureIOSurface;
class SharedImageRepresentationSkiaIOSurface;
class SharedImageRepresentationGLOzone;
class SharedImageBackingD3D;
class SharedImageVideo;
class StreamTexture;
......@@ -448,6 +449,7 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
friend class gpu::SharedImageBackingFactoryD3D;
friend class gpu::SharedImageRepresentationGLTextureIOSurface;
friend class gpu::SharedImageRepresentationSkiaIOSurface;
friend class gpu::SharedImageRepresentationGLOzone;
friend class gpu::StreamTexture;
friend class gpu::TestSharedImageBacking;
friend class AbstractTextureImplOnSharedContext;
......
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