Skip to content

Commit

Permalink
Fold AbstractTextureImpl to AbstractTextureAndroid
Browse files Browse the repository at this point in the history
Subclasses don't really have enough differences.

Change-Id: Ibd8fd38d17f7d40cac394e04963b58badfe43435
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4220012
Commit-Queue: vikas soni <vikassoni@chromium.org>
Reviewed-by: vikas soni <vikassoni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1104530}
  • Loading branch information
vasilyt authored and Chromium LUCI CQ committed Feb 13, 2023
1 parent 017932f commit cfc2c3b
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 259 deletions.
5 changes: 1 addition & 4 deletions gpu/command_buffer/service/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,8 @@ target(link_target_type, "gles2_sources") {
]
} else {
sources += [
"abstract_texture_android.cc",
"abstract_texture_android.h",
"abstract_texture_impl_android.cc",
"abstract_texture_impl_android.h",
]
}

Expand Down Expand Up @@ -604,8 +603,6 @@ if (is_android) {
static_library("android_texture_owner_test_support") {
testonly = true
sources = [
"mock_abstract_texture.cc",
"mock_abstract_texture.h",
"mock_texture_owner.cc",
"mock_texture_owner.h",
"ref_counted_lock_for_test.cc",
Expand Down
110 changes: 110 additions & 0 deletions gpu/command_buffer/service/abstract_texture_android.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright 2023 The Chromium Authors
// 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/abstract_texture_android.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/scoped_binders.h"
#include "ui/gl/scoped_make_current.h"

namespace gpu {
namespace {
GLuint CreateTextureWithLinearFilter() {
const auto target = GL_TEXTURE_EXTERNAL_OES;
GLuint service_id = 0;
auto* api = gl::g_current_gl_context;
api->glGenTexturesFn(1, &service_id);
gl::ScopedTextureBinder binder(target, service_id);
api->glTexParameteriFn(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
return service_id;
}
} // namespace

std::unique_ptr<AbstractTextureAndroid>
AbstractTextureAndroid::CreateForValidating(gfx::Size size) {
GLuint service_id = CreateTextureWithLinearFilter();

auto* texture = gpu::gles2::CreateGLES2TextureWithLightRef(
service_id, GL_TEXTURE_EXTERNAL_OES);
gfx::Rect cleared_rect;
texture->SetLevelInfo(GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, size.width(),
size.height(), 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
cleared_rect);
texture->SetImmutable(true, false);

return std::make_unique<AbstractTextureAndroid>(texture);
}

std::unique_ptr<AbstractTextureAndroid>
AbstractTextureAndroid::CreateForPassthrough(gfx::Size size) {
GLuint service_id = CreateTextureWithLinearFilter();
auto texture = base::MakeRefCounted<gles2::TexturePassthrough>(
service_id, GL_TEXTURE_EXTERNAL_OES, GL_RGBA, size.width(), size.height(),
1, 0, GL_RGBA, GL_UNSIGNED_BYTE);

return std::make_unique<AbstractTextureAndroid>(std::move(texture));
}

std::unique_ptr<AbstractTextureAndroid>
AbstractTextureAndroid::CreateForTesting(GLuint texture_id) {
auto texture = std::make_unique<gpu::TextureBase>(texture_id);
return std::make_unique<AbstractTextureAndroid>(std::move(texture));
}

AbstractTextureAndroid::AbstractTextureAndroid(
std::unique_ptr<gpu::TextureBase> texture)
: texture_for_testing_(std::move(texture)) {}
AbstractTextureAndroid::AbstractTextureAndroid(gles2::Texture* texture)
: texture_(texture), api_(gl::g_current_gl_context) {}
AbstractTextureAndroid::AbstractTextureAndroid(
scoped_refptr<gles2::TexturePassthrough> texture)
: texture_passthrough_(std::move(texture)),
api_(gl::g_current_gl_context) {}

AbstractTextureAndroid::~AbstractTextureAndroid() {
// If context is not lost, then the texture should be destroyed on same
// context it was create on.
if ((texture_ || texture_passthrough_) && have_context_) {
DCHECK_EQ(api_, gl::g_current_gl_context);
}

if (texture_) {
texture_->RemoveLightweightRef(have_context_);
}
}

void AbstractTextureAndroid::NotifyOnContextLost() {
if (texture_passthrough_) {
texture_passthrough_->MarkContextLost();
}
have_context_ = false;
}

void AbstractTextureAndroid::BindToServiceId(GLuint service_id) {
if (texture_) {
texture_->BindToServiceId(service_id);
texture_->SetLevelCleared(texture_->target(), /*level=*/0, true);
} else if (texture_passthrough_) {
texture_passthrough_->BindToServiceId(service_id);
}
}

TextureBase* AbstractTextureAndroid::GetTextureBase() const {
if (texture_) {
return texture_;
}
if (texture_passthrough_) {
return texture_passthrough_.get();
}
if (texture_for_testing_) {
return texture_for_testing_.get();
}
return nullptr;
}

} // namespace gpu
49 changes: 40 additions & 9 deletions gpu/command_buffer/service/abstract_texture_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,75 @@
#ifndef GPU_COMMAND_BUFFER_SERVICE_ABSTRACT_TEXTURE_ANDROID_H_
#define GPU_COMMAND_BUFFER_SERVICE_ABSTRACT_TEXTURE_ANDROID_H_

#include "base/memory/weak_ptr.h"
#include "build/build_config.h"
#include "gpu/command_buffer/service/texture_base.h"
#include "gpu/gpu_gles2_export.h"
#include "ui/gfx/geometry/size.h"

// Forwardly declare a few GL types to avoid including GL header files.
typedef unsigned GLenum;
typedef int GLsizei;
typedef int GLint;
typedef unsigned int GLuint;

namespace gl {
class GLApi;
} // namespace gl

namespace gpu {
namespace gles2 {
class Texture;
class TexturePassthrough;
} // namespace gles2

// An AbstractTexture enables access to GL textures from the GPU process, for
// things that set up textures using some client's decoder. Creating an
// AbstractTexture is similar to "glGenTexture", and deleting it is similar to
// calling "glDeleteTextures".
class GPU_GLES2_EXPORT AbstractTextureAndroid {
// An AbstractTextureAndroid enables access to GL textures from the GPU process,
// for things that set up textures using some client's decoder. Creating an
// AbstractTextureAndroid is similar to "glGenTexture", and deleting it is
// similar to calling "glDeleteTextures".
class GPU_GLES2_EXPORT AbstractTextureAndroid
: public base::SupportsWeakPtr<AbstractTextureAndroid> {
public:
static std::unique_ptr<AbstractTextureAndroid> CreateForValidating(
gfx::Size size);
static std::unique_ptr<AbstractTextureAndroid> CreateForPassthrough(
gfx::Size size);
static std::unique_ptr<AbstractTextureAndroid> CreateForTesting(
GLuint texture_id);

explicit AbstractTextureAndroid(std::unique_ptr<TextureBase> texture);
explicit AbstractTextureAndroid(gles2::Texture* texture);
explicit AbstractTextureAndroid(
scoped_refptr<gles2::TexturePassthrough> texture);

// The texture is guaranteed to be around while |this| exists, as long as
// the decoder isn't destroyed / context isn't lost.
virtual ~AbstractTextureAndroid() = default;
~AbstractTextureAndroid();

// Return our TextureBase, useful mostly for creating a mailbox. This may
// return null if the texture has been destroyed.
virtual TextureBase* GetTextureBase() const = 0;
TextureBase* GetTextureBase() const;

// Binds the texture to |service_id|. This will do nothing if the texture has
// been destroyed.
//
// It is not required to SetCleared() if one calls this method.
//
// The context must be current.
virtual void BindToServiceId(GLuint service_id) = 0;
void BindToServiceId(GLuint service_id);

// Used to notify the AbstractTexture if the context is lost.
virtual void NotifyOnContextLost() = 0;
void NotifyOnContextLost();

unsigned int service_id() const { return GetTextureBase()->service_id(); }

private:
bool have_context_ = true;

std::unique_ptr<TextureBase> texture_for_testing_;
raw_ptr<gles2::Texture, DanglingUntriaged> texture_;
scoped_refptr<gles2::TexturePassthrough> texture_passthrough_;
raw_ptr<gl::GLApi, DanglingUntriaged> api_ = nullptr;
};

} // namespace gpu
Expand Down
107 changes: 0 additions & 107 deletions gpu/command_buffer/service/abstract_texture_impl_android.cc

This file was deleted.

64 changes: 0 additions & 64 deletions gpu/command_buffer/service/abstract_texture_impl_android.h

This file was deleted.

0 comments on commit cfc2c3b

Please sign in to comment.