Commit 2e529d78 authored by kylechar's avatar kylechar Committed by Commit Bot

Use SharedImageInterface in GLOutputSurfaceOffscreen.

A gpu::Mailbox is needed to do something useful with the texture in
GLOutputSurfaceOffscreen. Convert it to use SharedImageInterface to
generate a gpu::Mailbox and then GL texture from that.

Bug: 601869
Change-Id: Id7da76e06bf119bc0d679132330b75bc1662836a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1585059Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Commit-Queue: kylechar <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654489}
parent 5f2d833d
......@@ -12,6 +12,8 @@
#include "components/viz/service/display/output_surface_frame.h"
#include "gpu/command_buffer/client/context_support.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "ui/gl/gl_utils.h"
......@@ -25,30 +27,36 @@ constexpr ResourceFormat kFboTextureFormat = RGBA_8888;
GLOutputSurfaceOffscreen::GLOutputSurfaceOffscreen(
scoped_refptr<VizProcessContextProvider> context_provider)
: GLOutputSurface(context_provider), weak_ptr_factory_(this) {}
: GLOutputSurface(context_provider) {}
GLOutputSurfaceOffscreen::~GLOutputSurfaceOffscreen() {}
GLOutputSurfaceOffscreen::~GLOutputSurfaceOffscreen() {
DiscardBackbuffer();
}
void GLOutputSurfaceOffscreen::EnsureBackbuffer() {
if (size_.IsEmpty())
return;
if (!texture_id_) {
gpu::SharedImageInterface* sii = context_provider_->SharedImageInterface();
gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
const int max_texture_size =
context_provider_->ContextCapabilities().max_texture_size;
int texture_width = std::min(max_texture_size, size_.width());
int texture_height = std::min(max_texture_size, size_.height());
// TODO(sgilhuly): Draw to a texture backed by a mailbox.
gl->GenTextures(1, &texture_id_);
gl->BindTexture(GL_TEXTURE_2D, texture_id_);
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gl->TexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(kFboTextureFormat),
texture_width, texture_height, 0,
GLDataFormat(kFboTextureFormat),
GLDataType(kFboTextureFormat), nullptr);
gfx::Size texture_size(std::min(size_.width(), max_texture_size),
std::min(size_.height(), max_texture_size));
const uint32_t flags = gpu::SHARED_IMAGE_USAGE_GLES2 |
gpu::SHARED_IMAGE_USAGE_GLES2_FRAMEBUFFER_HINT |
gpu::SHARED_IMAGE_USAGE_DISPLAY;
mailbox_ = sii->CreateSharedImage(kFboTextureFormat, texture_size,
color_space_, flags);
// Ensure mailbox is valid before using it.
gl->WaitSyncTokenCHROMIUM(sii->GenUnverifiedSyncToken().GetConstData());
texture_id_ = gl->CreateAndTexStorage2DSharedImageCHROMIUM(mailbox_.name);
gl->GenFramebuffers(1, &fbo_);
gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
......@@ -57,18 +65,19 @@ void GLOutputSurfaceOffscreen::EnsureBackbuffer() {
}
void GLOutputSurfaceOffscreen::DiscardBackbuffer() {
gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
if (texture_id_) {
gl->DeleteTextures(1, &texture_id_);
texture_id_ = 0;
}
if (fbo_) {
gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
gl->DeleteFramebuffers(1, &fbo_);
fbo_ = 0;
}
if (texture_id_) {
gpu::SharedImageInterface* sii = context_provider_->SharedImageInterface();
sii->DestroySharedImage(gpu::SyncToken(), mailbox_);
mailbox_.SetZero();
texture_id_ = 0;
}
}
void GLOutputSurfaceOffscreen::BindFramebuffer() {
......@@ -86,13 +95,13 @@ void GLOutputSurfaceOffscreen::Reshape(const gfx::Size& size,
bool alpha,
bool stencil) {
size_ = size;
color_space_ = color_space;
DiscardBackbuffer();
EnsureBackbuffer();
}
void GLOutputSurfaceOffscreen::SwapBuffers(OutputSurfaceFrame frame) {
gfx::Size surface_size = frame.size;
DCHECK(surface_size == size_);
DCHECK(frame.size == size_);
gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
......
......@@ -10,7 +10,8 @@
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/service/display_embedder/gl_output_surface.h"
#include "components/viz/service/display_embedder/viz_process_context_provider.h"
#include "ui/latency/latency_tracker.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "ui/gfx/color_space.h"
namespace viz {
......@@ -36,10 +37,14 @@ class GLOutputSurfaceOffscreen : public GLOutputSurface {
private:
void OnSwapBuffersComplete(std::vector<ui::LatencyInfo> latency_info);
gpu::Mailbox mailbox_;
uint32_t fbo_ = 0;
uint32_t texture_id_ = 0;
gfx::Size size_;
base::WeakPtrFactory<GLOutputSurfaceOffscreen> weak_ptr_factory_;
gfx::ColorSpace color_space_;
base::WeakPtrFactory<GLOutputSurfaceOffscreen> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(GLOutputSurfaceOffscreen);
};
......
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