Skip to content

Commit

Permalink
Attach YUV420 to RGB converter to GLContext
Browse files Browse the repository at this point in the history
This is less hacky than the global lookup table.

Leave the IOSurface-specific parts of the conversion inside
GLImageIOSurface. If this converter is needed on other platforms, this
will make it easier to reuse.

BUG=
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_optional_gpu_tests_rel;tryserver.chromium.mac:mac_optional_gpu_tests_rel;tryserver.chromium.win:win_optional_gpu_tests_rel

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

Cr-Commit-Position: refs/heads/master@{#387986}
  • Loading branch information
ccameron-chromium authored and Commit bot committed Apr 18, 2016
1 parent 4dc9a53 commit dde9e95
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 237 deletions.
4 changes: 4 additions & 0 deletions gpu/command_buffer/service/gl_context_virtual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ void GLContextVirtual::SetUnbindFboOnMakeCurrent() {
shared_context_->SetUnbindFboOnMakeCurrent();
}

gl::YUVToRGBConverter* GLContextVirtual::GetYUVToRGBConverter() {
return shared_context_->GetYUVToRGBConverter();
}

GLContextVirtual::~GLContextVirtual() {
Destroy();
}
Expand Down
1 change: 1 addition & 0 deletions gpu/command_buffer/service/gl_context_virtual.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class GPU_EXPORT GLContextVirtual : public gfx::GLContext {
void SetSafeToForceGpuSwitch() override;
bool WasAllocatedUsingRobustnessExtension() override;
void SetUnbindFboOnMakeCurrent() override;
gl::YUVToRGBConverter* GetYUVToRGBConverter() override;

protected:
~GLContextVirtual() override;
Expand Down
2 changes: 2 additions & 0 deletions ui/gl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ component("gl") {
"gl_image_io_surface.mm",
"scoped_cgl.cc",
"scoped_cgl.h",
"yuv_to_rgb_converter.cc",
"yuv_to_rgb_converter.h",
]

libs = [
Expand Down
2 changes: 2 additions & 0 deletions ui/gl/gl.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@
'gl_image_io_surface.h',
'scoped_cgl.cc',
'scoped_cgl.h',
'yuv_to_rgb_converter.cc',
'yuv_to_rgb_converter.h',
],
'link_settings': {
'libraries': [
Expand Down
4 changes: 4 additions & 0 deletions ui/gl/gl_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ std::string GLContext::GetGLRenderer() {
return std::string(renderer ? renderer : "");
}

gl::YUVToRGBConverter* GLContext::GetYUVToRGBConverter() {
return nullptr;
}

bool GLContext::HasExtension(const char* name) {
std::string extensions = GetExtensions();
extensions += " ";
Expand Down
8 changes: 7 additions & 1 deletion ui/gl/gl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "ui/gl/gl_state_restorer.h"
#include "ui/gl/gpu_preference.h"

namespace gl {
class YUVToRGBConverter;
} // namespace gl

namespace gpu {
class GLContextVirtual;
} // namespace gpu
Expand All @@ -29,7 +33,6 @@ class GPUTimingClient;
class VirtualGLApi;
struct GLVersionInfo;


// Encapsulates an OpenGL context, hiding platform specific management.
class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
public:
Expand Down Expand Up @@ -127,6 +130,9 @@ class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
// Returns the GL renderer string. The context must be current.
virtual std::string GetGLRenderer();

// Returns a helper structure to convert YUV textures to RGB textures.
virtual gl::YUVToRGBConverter* GetYUVToRGBConverter();

protected:
virtual ~GLContext();

Expand Down
12 changes: 12 additions & 0 deletions ui/gl/gl_context_cgl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/gpu_switching_manager.h"
#include "ui/gl/scoped_cgl.h"
#include "ui/gl/yuv_to_rgb_converter.h"

namespace gfx {

Expand Down Expand Up @@ -136,6 +138,10 @@ bool GLContextCGL::Initialize(GLSurface* compatible_surface,
}

void GLContextCGL::Destroy() {
if (yuv_to_rgb_converter_) {
gfx::ScopedCGLSetCurrentContext(static_cast<CGLContextObj>(context_));
yuv_to_rgb_converter_.reset();
}
if (discrete_pixelformat_) {
if (base::MessageLoop::current() != nullptr) {
// Delay releasing the pixel format for 10 seconds to reduce the number of
Expand Down Expand Up @@ -195,6 +201,12 @@ bool GLContextCGL::ForceGpuSwitchIfNeeded() {
return true;
}

gl::YUVToRGBConverter* GLContextCGL::GetYUVToRGBConverter() {
if (!yuv_to_rgb_converter_)
yuv_to_rgb_converter_.reset(new gl::YUVToRGBConverter);
return yuv_to_rgb_converter_.get();
}

bool GLContextCGL::MakeCurrent(GLSurface* surface) {
DCHECK(context_);

Expand Down
3 changes: 3 additions & 0 deletions ui/gl/gl_context_cgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <OpenGL/CGLTypes.h>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "ui/gl/gl_context.h"

namespace gfx {
Expand All @@ -29,6 +30,7 @@ class GLContextCGL : public GLContextReal {
void OnSetSwapInterval(int interval) override;
void SetSafeToForceGpuSwitch() override;
bool ForceGpuSwitchIfNeeded() override;
gl::YUVToRGBConverter* GetYUVToRGBConverter() override;

protected:
~GLContextCGL() override;
Expand All @@ -39,6 +41,7 @@ class GLContextCGL : public GLContextReal {

void* context_;
GpuPreference gpu_preference_;
scoped_ptr<gl::YUVToRGBConverter> yuv_to_rgb_converter_;

CGLPixelFormatObj discrete_pixelformat_;

Expand Down
4 changes: 0 additions & 4 deletions ui/gl/gl_image_io_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ class GL_EXPORT GLImageIOSurface : public GLImage {
gfx::GenericSharedMemoryId io_surface_id_;
base::ThreadChecker thread_checker_;

// GL state to support 420v IOSurface conversion to RGB. This is retained
// to avoid re-creating the necessary GL programs every frame.
scoped_refptr<RGBConverter> rgb_converter_;

DISALLOW_COPY_AND_ASSIGN(GLImageIOSurface);
};

Expand Down
Loading

0 comments on commit dde9e95

Please sign in to comment.