Skip to content

Commit

Permalink
Re-land: ui: Move GLImage::BindTexImage fallback from GLImage impleme…
Browse files Browse the repository at this point in the history
…ntations to GLES2CmdDecoder.

This allows the GPU service to properly track the memory usage
image backed textures.

It also reduces the complexity of GLImage implementations
significantly and makes it easier to support format and
buffer types that require a copy or conversion of data to
be used for sampling.

This change also includes a few minor GLImage cleanups such
as removing gfx:: namespace prefix in places where it's not
needed and making the CopyTexImage GLImage test not part of
the core GLImage tests as it's optional to support that
function.

BUG=526298
TEST=gl_tests --gtest_filter=GpuMemoryBuffer*, gpu_unittests, gl_unittests --gtest_filter=GLImage*

Review URL: https://codereview.chromium.org/1401423003

Cr-Commit-Position: refs/heads/master@{#354972}
  • Loading branch information
reveman-chromium authored and Commit bot committed Oct 20, 2015
1 parent 4dffdd8 commit 779bd95
Show file tree
Hide file tree
Showing 41 changed files with 546 additions and 867 deletions.
11 changes: 6 additions & 5 deletions components/mus/gles2/command_buffer_local.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "components/mus/gles2/command_buffer_local.h"

#include "base/bind.h"
#include "base/memory/shared_memory.h"
#include "components/mus/gles2/command_buffer_local_client.h"
#include "components/mus/gles2/gpu_memory_tracker.h"
#include "components/mus/gles2/mojo_gpu_memory_buffer.h"
Expand All @@ -19,7 +20,7 @@
#include "gpu/command_buffer/service/valuebuffer_manager.h"
#include "ui/gfx/vsync_provider.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_image_memory.h"
#include "ui/gl/gl_image_shared_memory.h"
#include "ui/gl/gl_surface.h"

namespace mus {
Expand Down Expand Up @@ -135,12 +136,12 @@ int32_t CommandBufferLocal::CreateImage(ClientBuffer buffer,
MojoGpuMemoryBufferImpl* gpu_memory_buffer =
MojoGpuMemoryBufferImpl::FromClientBuffer(buffer);

scoped_refptr<gfx::GLImageMemory> image(new gfx::GLImageMemory(
gfx::GpuMemoryBufferHandle handle = gpu_memory_buffer->GetHandle();
scoped_refptr<gfx::GLImageSharedMemory> image(new gfx::GLImageSharedMemory(
gfx::Size(static_cast<int>(width), static_cast<int>(height)),
internalformat));
if (!image->Initialize(
static_cast<const unsigned char*>(gpu_memory_buffer->GetMemory()),
gpu_memory_buffer->GetFormat())) {
if (!image->Initialize(base::SharedMemory::DuplicateHandle(handle.handle),
handle.id, gpu_memory_buffer->GetFormat())) {
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void AndroidDeferredRenderingBackingStrategy::SetImageForPicture(
}

texture_manager->SetLevelImage(texture_ref, GetTextureTarget(), 0,
image.get());
image.get(), gpu::gles2::Texture::UNBOUND);
}

void AndroidDeferredRenderingBackingStrategy::UseCodecBufferForPictureBuffer(
Expand Down
50 changes: 27 additions & 23 deletions content/common/gpu/media/avda_codec_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "content/common/gpu/media/avda_codec_image.h"

#include "content/common/gpu/media/avda_shared_state.h"
#include "gpu/command_buffer/service/context_group.h"
#include "gpu/command_buffer/service/context_state.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include "gpu/command_buffer/service/texture_manager.h"
Expand Down Expand Up @@ -50,18 +51,12 @@ unsigned AVDACodecImage::GetInternalFormat() {
}

bool AVDACodecImage::BindTexImage(unsigned target) {
return true;
return false;
}

void AVDACodecImage::ReleaseTexImage(unsigned target) {}

bool AVDACodecImage::CopyTexSubImage(unsigned target,
const gfx::Point& offset,
const gfx::Rect& rect) {
return false;
}

void AVDACodecImage::WillUseTexImage() {
bool AVDACodecImage::CopyTexImage(unsigned target) {
// Have we bound the SurfaceTexture's texture handle to the active
// texture unit yet?
bool bound_texture = false;
Expand All @@ -75,29 +70,38 @@ void AVDACodecImage::WillUseTexImage() {
// Make sure that we have the right image in the front buffer.
bound_texture |= UpdateSurfaceTexture();

// TODO(liberato): Handle the texture matrix properly.
// Either we can update the shader with it or we can move all of the logic
// to updateTexImage() to the right place in the cc to send it to the shader.
// For now, we just skip it. crbug.com/530681

// Sneakily bind the ST texture handle in the real GL context.
// If we called UpdateTexImage() to update the ST front buffer, then we can
// skip this. Since one draw/frame is the common case, we optimize for it.
if (!bound_texture)
glBindTexture(GL_TEXTURE_EXTERNAL_OES,
shared_state_->surface_texture_service_id());

// TODO(liberato): Handle the texture matrix properly.
// Either we can update the shader with it or we can move all of the logic
// to updateTexImage() to the right place in the cc to send it to the shader.
// For now, we just skip it. crbug.com/530681

gpu::gles2::TextureManager* texture_manager =
decoder_->GetContextGroup()->texture_manager();
gpu::gles2::Texture* texture =
texture_manager->GetTextureForServiceId(
shared_state_->surface_texture_service_id());
if (texture) {
// By setting image state to UNBOUND instead of COPIED we ensure that
// CopyTexImage() is called each time the surface texture is used for
// drawing.
texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this,
gpu::gles2::Texture::UNBOUND);
}

return true;
}

void AVDACodecImage::DidUseTexImage() {
// Unbind the ST's service_id in the real GL context in favor of whatever
// the decoder thinks is bound there.
const gpu::gles2::ContextState* state = decoder_->GetContextState();
const gpu::gles2::TextureUnit& active_unit =
state->texture_units[state->active_texture_unit];
glBindTexture(GL_TEXTURE_EXTERNAL_OES,
active_unit.bound_texture_external_oes.get()
? active_unit.bound_texture_external_oes->service_id()
: 0);
bool AVDACodecImage::CopyTexSubImage(unsigned target,
const gfx::Point& offset,
const gfx::Rect& rect) {
return false;
}

bool AVDACodecImage::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
Expand Down
5 changes: 1 addition & 4 deletions content/common/gpu/media/avda_codec_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ class AVDACodecImage : public gfx::GLImage {
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override;
bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const gfx::Point& offset,
const gfx::Rect& rect) override;
void WillUseTexImage() override;
void DidUseTexImage() override;
void WillModifyTexImage() override {}
void DidModifyTexImage() override {}
bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
gfx::OverlayTransform transform,
Expand Down
6 changes: 4 additions & 2 deletions content/common/gpu/media/gpu_video_decode_accelerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ void GpuVideoDecodeAccelerator::BindImage(uint32 client_texture_id,
gpu::gles2::TextureManager* texture_manager =
command_decoder->GetContextGroup()->texture_manager();
gpu::gles2::TextureRef* ref = texture_manager->GetTexture(client_texture_id);
if (ref)
texture_manager->SetLevelImage(ref, texture_target, 0, image.get());
if (ref) {
texture_manager->SetLevelImage(ref, texture_target, 0, image.get(),
gpu::gles2::Texture::BOUND);
}
}

scoped_ptr<media::VideoDecodeAccelerator>
Expand Down
26 changes: 22 additions & 4 deletions content/common/gpu/stream_texture_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ bool StreamTexture::Create(
texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA,
size.width(), size.height(), 1, 0, GL_RGBA,
GL_UNSIGNED_BYTE, gfx::Rect(size));
texture_manager->SetLevelImage(
texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get());
texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0,
gl_image.get(),
gpu::gles2::Texture::UNBOUND);
return true;
}

Expand All @@ -63,6 +64,7 @@ StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub,
owner_stub_(owner_stub),
route_id_(route_id),
has_listener_(false),
texture_id_(texture_id),
weak_factory_(this) {
owner_stub->AddDestructionObserver(this);
memset(current_matrix_, 0, sizeof(current_matrix_));
Expand Down Expand Up @@ -92,9 +94,11 @@ void StreamTexture::Destroy(bool have_context) {
NOTREACHED();
}

void StreamTexture::WillUseTexImage() {
bool StreamTexture::CopyTexImage(unsigned target) {
DCHECK_EQ(target, static_cast<unsigned>(GL_TEXTURE_EXTERNAL_OES));

if (!owner_stub_ || !surface_texture_.get())
return;
return true;

if (has_pending_frame_) {
scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current;
Expand Down Expand Up @@ -128,6 +132,18 @@ void StreamTexture::WillUseTexImage() {
? active_unit.bound_texture_external_oes->service_id()
: 0);
}

TextureManager* texture_manager =
owner_stub_->decoder()->GetContextGroup()->texture_manager();
gpu::gles2::Texture* texture =
texture_manager->GetTextureForServiceId(texture_id_);
if (texture) {
// By setting image state to UNBOUND instead of COPIED we ensure that
// CopyTexImage() is called each time the surface texture is used for
// drawing.
texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this,
gpu::gles2::Texture::UNBOUND);
}
}

if (has_listener_ && has_valid_frame_) {
Expand All @@ -144,6 +160,8 @@ void StreamTexture::WillUseTexImage() {
new GpuStreamTextureMsg_MatrixChanged(route_id_, params));
}
}

return true;
}

void StreamTexture::OnFrameAvailable() {
Expand Down
6 changes: 2 additions & 4 deletions content/common/gpu/stream_texture_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,10 @@ class StreamTexture : public gfx::GLImage,
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override;
bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const gfx::Point& offset,
const gfx::Rect& rect) override;
void WillUseTexImage() override;
void DidUseTexImage() override {}
void WillModifyTexImage() override {}
void DidModifyTexImage() override {}
bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
gfx::OverlayTransform transform,
Expand Down Expand Up @@ -85,6 +82,7 @@ class StreamTexture : public gfx::GLImage,
GpuCommandBufferStub* owner_stub_;
int32 route_id_;
bool has_listener_;
uint32 texture_id_;

base::WeakPtrFactory<StreamTexture> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(StreamTexture);
Expand Down
47 changes: 0 additions & 47 deletions gpu/command_buffer/service/framebuffer_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ class RenderbufferAttachment
renderbuffer_->AddToSignature(signature);
}

void OnWillRenderTo() const override {}
void OnDidRenderTo() const override {}
bool FormsFeedbackLoop(TextureRef* /* texture */,
GLint /*level */) const override {
return false;
Expand Down Expand Up @@ -179,7 +177,6 @@ class TextureAttachment

void DetachFromFramebuffer(Framebuffer* framebuffer) const override {
texture_ref_->texture()->DetachFromFramebuffer();
framebuffer->OnTextureRefDetached(texture_ref_.get());
}

bool ValidForAttachmentType(GLenum attachment_type,
Expand Down Expand Up @@ -214,14 +211,6 @@ class TextureAttachment
texture_ref_.get(), target_, level_, signature);
}

void OnWillRenderTo() const override {
texture_ref_->texture()->OnWillModifyPixels();
}

void OnDidRenderTo() const override {
texture_ref_->texture()->OnDidModifyPixels();
}

bool FormsFeedbackLoop(TextureRef* texture, GLint level) const override {
return texture == texture_ref_.get() && level == level_;
}
Expand All @@ -238,10 +227,6 @@ class TextureAttachment
DISALLOW_COPY_AND_ASSIGN(TextureAttachment);
};

FramebufferManager::TextureDetachObserver::TextureDetachObserver() {}

FramebufferManager::TextureDetachObserver::~TextureDetachObserver() {}

FramebufferManager::FramebufferManager(
uint32 max_draw_buffers,
uint32 max_color_attachments,
Expand Down Expand Up @@ -713,28 +698,6 @@ const Framebuffer::Attachment* Framebuffer::GetReadBufferAttachment() const {
return GetAttachment(read_buffer_);
}

void Framebuffer::OnTextureRefDetached(TextureRef* texture) {
manager_->OnTextureRefDetached(texture);
}

void Framebuffer::OnWillRenderTo(GLenum attachment) const {
for (AttachmentMap::const_iterator it = attachments_.begin();
it != attachments_.end(); ++it) {
if (attachment == 0 || attachment == it->first) {
it->second->OnWillRenderTo();
}
}
}

void Framebuffer::OnDidRenderTo(GLenum attachment) const {
for (AttachmentMap::const_iterator it = attachments_.begin();
it != attachments_.end(); ++it) {
if (attachment == 0 || attachment == it->first) {
it->second->OnDidRenderTo();
}
}
}

bool FramebufferManager::GetClientId(
GLuint service_id, GLuint* client_id) const {
// This doesn't need to be fast. It's only used during slow queries.
Expand Down Expand Up @@ -772,15 +735,5 @@ bool FramebufferManager::IsComplete(
framebuffer_state_change_count_;
}

void FramebufferManager::OnTextureRefDetached(TextureRef* texture) {
for (TextureDetachObserverVector::iterator it =
texture_detach_observers_.begin();
it != texture_detach_observers_.end();
++it) {
TextureDetachObserver* observer = *it;
observer->OnTextureRefDetachedFromFramebuffer(texture);
}
}

} // namespace gles2
} // namespace gpu
Loading

0 comments on commit 779bd95

Please sign in to comment.