#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "gpu/command_buffer/client/gl_helper.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <string>
#include <utility>
#include "base/bits.h"
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/queue.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/lazy_instance.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/context_support.h"
#include "gpu/command_buffer/client/gl_helper_scaling.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
namespace gpu {
GLES2Interface;
namespace {
class ScopedFlush { … };
class TextureHolder { … };
class I420ConverterImpl : public I420Converter { … };
}
class GLHelper::CopyTextureToImpl final { … };
std::unique_ptr<GLHelper::ScalerInterface> GLHelper::CreateScaler(
ScalerQuality quality,
const gfx::Vector2d& scale_from,
const gfx::Vector2d& scale_to,
bool flipped_source,
bool flip_output,
bool swizzle) { … }
void GLHelper::CopyTextureToImpl::ReadbackAsync(
const gfx::Point& src_starting_point,
const gfx::Size& dst_size,
size_t bytes_per_row,
size_t row_stride_bytes,
unsigned char* out,
GLenum format,
GLenum type,
size_t bytes_per_pixel,
bool flip_y,
base::OnceCallback<void(bool)> callback) { … }
void GLHelper::CopyTextureToImpl::ReadbackTextureAsync(
GLuint texture,
GLenum texture_target,
const gfx::Point& src_starting_point,
const gfx::Size& dst_size,
unsigned char* out,
size_t row_stride_bytes,
bool flip_y,
GLenum format,
base::OnceCallback<void(bool)> callback) { … }
void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request) { … }
void GLHelper::CopyTextureToImpl::FinishRequest(
Request* request,
bool result,
FinishRequestHelper* finish_request_helper) { … }
void GLHelper::CopyTextureToImpl::CancelRequests() { … }
bool GLHelper::CopyTextureToImpl::IsBGRAReadbackSupported() { … }
GLHelper::GLHelper(GLES2Interface* gl, ContextSupport* context_support)
: … { … }
GLHelper::~GLHelper() { … }
void GLHelper::ReadbackTextureAsync(GLuint texture,
GLenum texture_target,
const gfx::Point& src_starting_point,
const gfx::Size& dst_size,
unsigned char* out,
size_t row_stride_bytes,
bool flip_y,
GLenum format,
base::OnceCallback<void(bool)> callback) { … }
void GLHelper::InitCopyTextToImpl() { … }
void GLHelper::InitScalerImpl() { … }
GLint GLHelper::MaxDrawBuffers() { … }
void GLHelper::CopyTextureToImpl::ReadbackPlane(
const gfx::Size& texture_size,
int row_stride_bytes,
unsigned char* data,
int size_shift,
const gfx::Rect& paste_rect,
ReadbackSwizzle swizzle,
base::OnceCallback<void(bool)> callback) { … }
I420Converter::I420Converter() = default;
I420Converter::~I420Converter() = default;
gfx::Size I420Converter::GetYPlaneTextureSize(const gfx::Size& output_size) { … }
gfx::Size I420Converter::GetChromaPlaneTextureSize(
const gfx::Size& output_size) { … }
namespace {
I420ConverterImpl::I420ConverterImpl(GLES2Interface* gl,
GLHelperScaling* scaler_impl,
bool flipped_source,
bool flip_output,
bool swizzle,
bool use_mrt)
: … { … }
I420ConverterImpl::~I420ConverterImpl() = default;
void I420ConverterImpl::Convert(GLuint src_texture,
const gfx::Size& src_texture_size,
const gfx::Vector2dF& src_offset,
GLHelper::ScalerInterface* optional_scaler,
const gfx::Rect& output_rect,
GLuint y_plane_texture,
GLuint u_plane_texture,
GLuint v_plane_texture) { … }
bool I420ConverterImpl::IsSamplingFlippedSource() const { … }
bool I420ConverterImpl::IsFlippingOutput() const { … }
GLenum I420ConverterImpl::GetReadbackFormat() const { … }
void I420ConverterImpl::EnsureTexturesSizedFor(
const gfx::Size& scaler_output_size,
const gfx::Size& y_texture_size,
const gfx::Size& chroma_texture_size,
GLuint y_plane_texture,
GLuint u_plane_texture,
GLuint v_plane_texture) { … }
}
GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUVImpl(
GLES2Interface* gl,
CopyTextureToImpl* copy_impl,
GLHelperScaling* scaler_impl,
bool flip_vertically,
ReadbackSwizzle swizzle,
bool use_mrt)
: … { … }
GLHelper::CopyTextureToImpl::ReadbackYUVImpl::~ReadbackYUVImpl() = default;
void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::SetScaler(
std::unique_ptr<GLHelper::ScalerInterface> scaler) { … }
GLHelper::ScalerInterface*
GLHelper::CopyTextureToImpl::ReadbackYUVImpl::scaler() const { … }
bool GLHelper::CopyTextureToImpl::ReadbackYUVImpl::IsFlippingOutput() const { … }
void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV(
GLuint texture,
const gfx::Size& src_texture_size,
const gfx::Rect& output_rect,
int y_plane_row_stride_bytes,
unsigned char* y_plane_data,
int u_plane_row_stride_bytes,
unsigned char* u_plane_data,
int v_plane_row_stride_bytes,
unsigned char* v_plane_data,
const gfx::Point& paste_location,
base::OnceCallback<void(bool)> callback) { … }
std::unique_ptr<I420Converter> GLHelper::CreateI420Converter(
bool flipped_source,
bool flip_output,
bool swizzle,
bool use_mrt) { … }
std::unique_ptr<ReadbackYUVInterface>
GLHelper::CopyTextureToImpl::CreateReadbackPipelineYUV(bool flip_vertically,
bool use_mrt) { … }
std::unique_ptr<ReadbackYUVInterface> GLHelper::CreateReadbackPipelineYUV(
bool flip_vertically,
bool use_mrt) { … }
ReadbackYUVInterface* GLHelper::GetReadbackPipelineYUV(
bool vertically_flip_texture) { … }
}