Commit 4d47e6c7 authored by posciak@chromium.org's avatar posciak@chromium.org

Extract Scoped{FrameBuffer,Texture}Binder and clean up TFP in VAVDA.

Clean up TFP in VAVDA:
- properly restore currently bound texture after binding our own
- use the extracted Binders for the above
- use glXDestroyPixmap instead of glXDestroyPixmapGLX
- do not bind texture twice

Also modify TextureImageTransportSurface to use the extracted Binders.

BUG=
TEST=manual runs of VAVDA


Review URL: https://chromiumcodereview.appspot.com/10827052

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148827 0039d316-1c4b-4281-b951-d872f2087c98
parent 06ac889f
// Copyright (c) 2012 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 "content/common/gpu/gl_scoped_binders.h"
#include "ui/gl/gl_bindings.h"
namespace content {
ScopedFrameBufferBinder::ScopedFrameBufferBinder(unsigned int fbo) {
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo_);
glBindFramebufferEXT(GL_FRAMEBUFFER, fbo);
}
ScopedFrameBufferBinder::~ScopedFrameBufferBinder() {
glBindFramebufferEXT(GL_FRAMEBUFFER, old_fbo_);
}
ScopedTextureBinder::ScopedTextureBinder(unsigned int id) {
glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_id_);
glBindTexture(GL_TEXTURE_2D, id);
}
ScopedTextureBinder::~ScopedTextureBinder() {
glBindTexture(GL_TEXTURE_2D, old_id_);
}
} // namespace content
// Copyright (c) 2012 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 CONTENT_COMMON_GPU_GL_SCOPED_BINDERS_H_
#define CONTENT_COMMON_GPU_GL_SCOPED_BINDERS_H_
namespace content {
class ScopedFrameBufferBinder {
public:
explicit ScopedFrameBufferBinder(unsigned int fbo);
~ScopedFrameBufferBinder();
private:
int old_fbo_;
};
class ScopedTextureBinder {
public:
explicit ScopedTextureBinder(unsigned int id);
~ScopedTextureBinder();
private:
int old_id_;
};
} // namespace content
#endif // CONTENT_COMMON_GPU_GL_SCOPED_BINDERS_H_
......@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/stl_util.h"
#include "content/common/gpu/gl_scoped_binders.h"
#include "content/common/gpu/media/vaapi_h264_decoder.h"
#include "third_party/libva/va/va.h"
#include "third_party/libva/va/va_x11.h"
......@@ -255,14 +256,14 @@ VaapiH264Decoder::DecodeSurface::DecodeSurface(
if (!make_context_current_.Run())
return;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture_id_);
content::ScopedTextureBinder texture_binder(texture_id_);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
XWindowAttributes win_attr;
int screen = DefaultScreen(x_display_);
XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr);
//TODO(posciak): pass the depth required by libva, not the RootWindow's depth
x_pixmap_ = XCreatePixmap(x_display_, RootWindow(x_display_, screen),
width_, height_, win_attr.depth);
if (!x_pixmap_) {
......@@ -283,7 +284,6 @@ VaapiH264Decoder::DecodeSurface::DecodeSurface(
return;
}
glBindTexture(GL_TEXTURE_2D, texture_id_);
glXBindTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL);
available_ = true;
......@@ -293,7 +293,7 @@ VaapiH264Decoder::DecodeSurface::~DecodeSurface() {
// Unbind surface from texture and deallocate resources.
if (glx_pixmap_ && make_context_current_.Run()) {
glXReleaseTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT);
glXDestroyGLXPixmap(x_display_, glx_pixmap_);
glXDestroyPixmap(x_display_, glx_pixmap_);
}
if (x_pixmap_)
......
......@@ -8,6 +8,7 @@
#include <vector>
#include "base/command_line.h"
#include "content/common/gpu/gl_scoped_binders.h"
#include "content/common/gpu/gpu_channel.h"
#include "content/common/gpu/gpu_channel_manager.h"
#include "content/common/gpu/gpu_messages.h"
......@@ -21,40 +22,6 @@ using gpu::gles2::ContextGroup;
using gpu::gles2::TextureManager;
typedef TextureManager::TextureInfo TextureInfo;
namespace {
class ScopedFrameBufferBinder {
public:
explicit ScopedFrameBufferBinder(unsigned int fbo) {
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo_);
glBindFramebufferEXT(GL_FRAMEBUFFER, fbo);
}
~ScopedFrameBufferBinder() {
glBindFramebufferEXT(GL_FRAMEBUFFER, old_fbo_);
}
private:
int old_fbo_;
};
class ScopedTextureBinder {
public:
explicit ScopedTextureBinder(unsigned int id) {
glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_id_);
glBindTexture(GL_TEXTURE_2D, id);
}
~ScopedTextureBinder() {
glBindTexture(GL_TEXTURE_2D, old_id_);
}
private:
int old_id_;
};
} // anonymous namespace
TextureImageTransportSurface::Texture::Texture()
: client_id(0),
sent_to_client(false) {
......@@ -310,13 +277,13 @@ bool TextureImageTransportSurface::PostSubBuffer(
std::vector<gfx::Rect> regions_to_copy;
GetRegionsToCopy(previous_damage_rect_, new_damage_rect, &regions_to_copy);
ScopedFrameBufferBinder fbo_binder(fbo_id_);
content::ScopedFrameBufferBinder fbo_binder(fbo_id_);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
front_texture_service_id,
0);
ScopedTextureBinder texture_binder(back_texture_service_id);
content::ScopedTextureBinder texture_binder(back_texture_service_id);
for (size_t i = 0; i < regions_to_copy.size(); ++i) {
const gfx::Rect& region_to_copy = regions_to_copy[i];
......@@ -442,7 +409,7 @@ void TextureImageTransportSurface::ReleaseTexture(int id) {
info->SetServiceId(0);
{
ScopedFrameBufferBinder fbo_binder(fbo_id_);
content::ScopedFrameBufferBinder fbo_binder(fbo_id_);
glDeleteTextures(1, &service_id);
}
glFlush();
......@@ -485,7 +452,7 @@ void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) {
}
{
ScopedTextureBinder texture_binder(service_id);
content::ScopedTextureBinder texture_binder(service_id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
......@@ -512,7 +479,7 @@ void TextureImageTransportSurface::AttachBackTextureToFBO() {
TextureInfo* info = textures_[back()].info;
DCHECK(info);
ScopedFrameBufferBinder fbo_binder(fbo_id_);
content::ScopedFrameBufferBinder fbo_binder(fbo_id_);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
......
......@@ -196,6 +196,8 @@
'common/gpu/client/gpu_video_decode_accelerator_host.h',
'common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc',
'common/gpu/client/webgraphicscontext3d_command_buffer_impl.h',
'common/gpu/gl_scoped_binders.cc',
'common/gpu/gl_scoped_binders.h',
'common/gpu/gpu_channel.cc',
'common/gpu/gpu_channel.h',
'common/gpu/gpu_channel_manager.cc',
......
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