Commit d041a28b authored by dongseong.hwang's avatar dongseong.hwang Committed by Commit bot

zero-copy: Clarify to allocate/destroy GpuMemoryBuffer on any thread and use...

zero-copy: Clarify to allocate/destroy GpuMemoryBuffer on any thread and use it on the main thread only

Add many thread check to clarify it.

BUG=473125

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

Cr-Commit-Position: refs/heads/master@{#324382}
parent 9bf2589b
...@@ -59,6 +59,8 @@ class GpuChannelManagerMessageFilter : public IPC::MessageFilter { ...@@ -59,6 +59,8 @@ class GpuChannelManagerMessageFilter : public IPC::MessageFilter {
protected: protected:
~GpuChannelManagerMessageFilter() override {} ~GpuChannelManagerMessageFilter() override {}
// GPU IO thread bounces off GpuMsg_CreateGpuMemoryBuffer message, because
// the UI thread in the browser process must remain fast at all times.
void OnCreateGpuMemoryBuffer( void OnCreateGpuMemoryBuffer(
const GpuMsg_CreateGpuMemoryBuffer_Params& params) { const GpuMsg_CreateGpuMemoryBuffer_Params& params) {
TRACE_EVENT2("gpu", TRACE_EVENT2("gpu",
......
...@@ -31,7 +31,6 @@ class CONTENT_EXPORT GpuMemoryBufferFactory { ...@@ -31,7 +31,6 @@ class CONTENT_EXPORT GpuMemoryBufferFactory {
gfx::GpuMemoryBuffer::Usage usage; gfx::GpuMemoryBuffer::Usage usage;
}; };
GpuMemoryBufferFactory() {}
virtual ~GpuMemoryBufferFactory() {} virtual ~GpuMemoryBufferFactory() {}
// Gets system supported GPU memory buffer factory types. Preferred type at // Gets system supported GPU memory buffer factory types. Preferred type at
...@@ -47,7 +46,7 @@ class CONTENT_EXPORT GpuMemoryBufferFactory { ...@@ -47,7 +46,7 @@ class CONTENT_EXPORT GpuMemoryBufferFactory {
std::vector<Configuration>* configurations) = 0; std::vector<Configuration>* configurations) = 0;
// Creates a new GPU memory buffer instance. A valid handle is returned on // Creates a new GPU memory buffer instance. A valid handle is returned on
// success. // success. It can be called on any thread.
virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(
gfx::GpuMemoryBufferId id, gfx::GpuMemoryBufferId id,
const gfx::Size& size, const gfx::Size& size,
...@@ -57,12 +56,16 @@ class CONTENT_EXPORT GpuMemoryBufferFactory { ...@@ -57,12 +56,16 @@ class CONTENT_EXPORT GpuMemoryBufferFactory {
gfx::PluginWindowHandle surface_handle) = 0; gfx::PluginWindowHandle surface_handle) = 0;
// Destroys GPU memory buffer identified by |id|. // Destroys GPU memory buffer identified by |id|.
// It can be called on any thread.
virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
int client_id) = 0; int client_id) = 0;
// Type-checking downcast routine. // Type-checking downcast routine.
virtual gpu::ImageFactory* AsImageFactory() = 0; virtual gpu::ImageFactory* AsImageFactory() = 0;
protected:
GpuMemoryBufferFactory() {}
private: private:
DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferFactory); DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferFactory);
}; };
......
...@@ -14,12 +14,14 @@ GLImageEGL::GLImageEGL(const gfx::Size& size) ...@@ -14,12 +14,14 @@ GLImageEGL::GLImageEGL(const gfx::Size& size)
} }
GLImageEGL::~GLImageEGL() { GLImageEGL::~GLImageEGL() {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
} }
bool GLImageEGL::Initialize(EGLenum target, bool GLImageEGL::Initialize(EGLenum target,
EGLClientBuffer buffer, EGLClientBuffer buffer,
const EGLint* attrs) { const EGLint* attrs) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
EGL_NO_CONTEXT, EGL_NO_CONTEXT,
...@@ -35,6 +37,7 @@ bool GLImageEGL::Initialize(EGLenum target, ...@@ -35,6 +37,7 @@ bool GLImageEGL::Initialize(EGLenum target,
} }
void GLImageEGL::Destroy(bool have_context) { void GLImageEGL::Destroy(bool have_context) {
DCHECK(thread_checker_.CalledOnValidThread());
if (egl_image_ != EGL_NO_IMAGE_KHR) { if (egl_image_ != EGL_NO_IMAGE_KHR) {
EGLBoolean result = EGLBoolean result =
eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
...@@ -49,6 +52,7 @@ void GLImageEGL::Destroy(bool have_context) { ...@@ -49,6 +52,7 @@ void GLImageEGL::Destroy(bool have_context) {
gfx::Size GLImageEGL::GetSize() { return size_; } gfx::Size GLImageEGL::GetSize() { return size_; }
bool GLImageEGL::BindTexImage(unsigned target) { bool GLImageEGL::BindTexImage(unsigned target) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
glEGLImageTargetTexture2DOES(target, egl_image_); glEGLImageTargetTexture2DOES(target, egl_image_);
DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef UI_GL_GL_IMAGE_EGL_H_ #ifndef UI_GL_GL_IMAGE_EGL_H_
#define UI_GL_GL_IMAGE_EGL_H_ #define UI_GL_GL_IMAGE_EGL_H_
#include "base/threading/thread_checker.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image.h" #include "ui/gl/gl_image.h"
...@@ -37,6 +38,7 @@ class GL_EXPORT GLImageEGL : public GLImage { ...@@ -37,6 +38,7 @@ class GL_EXPORT GLImageEGL : public GLImage {
EGLImageKHR egl_image_; EGLImageKHR egl_image_;
const gfx::Size size_; const gfx::Size size_;
base::ThreadChecker thread_checker_;
private: private:
DISALLOW_COPY_AND_ASSIGN(GLImageEGL); DISALLOW_COPY_AND_ASSIGN(GLImageEGL);
......
...@@ -16,22 +16,26 @@ GLImageIOSurface::GLImageIOSurface(const gfx::Size& size) : size_(size) { ...@@ -16,22 +16,26 @@ GLImageIOSurface::GLImageIOSurface(const gfx::Size& size) : size_(size) {
} }
GLImageIOSurface::~GLImageIOSurface() { GLImageIOSurface::~GLImageIOSurface() {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!io_surface_); DCHECK(!io_surface_);
} }
bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface) { bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!io_surface_); DCHECK(!io_surface_);
io_surface_.reset(io_surface); io_surface_.reset(io_surface);
return true; return true;
} }
void GLImageIOSurface::Destroy(bool have_context) { void GLImageIOSurface::Destroy(bool have_context) {
DCHECK(thread_checker_.CalledOnValidThread());
io_surface_.reset(); io_surface_.reset();
} }
gfx::Size GLImageIOSurface::GetSize() { return size_; } gfx::Size GLImageIOSurface::GetSize() { return size_; }
bool GLImageIOSurface::BindTexImage(unsigned target) { bool GLImageIOSurface::BindTexImage(unsigned target) {
DCHECK(thread_checker_.CalledOnValidThread());
if (target != GL_TEXTURE_RECTANGLE_ARB) { if (target != GL_TEXTURE_RECTANGLE_ARB) {
// This might be supported in the future. For now, perform strict // This might be supported in the future. For now, perform strict
// validation so we know what's going on. // validation so we know what's going on.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <IOSurface/IOSurfaceAPI.h> #include <IOSurface/IOSurfaceAPI.h>
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "base/threading/thread_checker.h"
#include "ui/gfx/gpu_memory_buffer.h" #include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gl/gl_image.h" #include "ui/gl/gl_image.h"
...@@ -41,6 +42,7 @@ class GL_EXPORT GLImageIOSurface : public GLImage { ...@@ -41,6 +42,7 @@ class GL_EXPORT GLImageIOSurface : public GLImage {
private: private:
base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; base::ScopedCFTypeRef<IOSurfaceRef> io_surface_;
const gfx::Size size_; const gfx::Size size_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(GLImageIOSurface); DISALLOW_COPY_AND_ASSIGN(GLImageIOSurface);
}; };
......
...@@ -14,17 +14,20 @@ GLImageSurfaceTexture::GLImageSurfaceTexture(const gfx::Size& size) ...@@ -14,17 +14,20 @@ GLImageSurfaceTexture::GLImageSurfaceTexture(const gfx::Size& size)
} }
GLImageSurfaceTexture::~GLImageSurfaceTexture() { GLImageSurfaceTexture::~GLImageSurfaceTexture() {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!surface_texture_.get()); DCHECK(!surface_texture_.get());
DCHECK_EQ(0, texture_id_); DCHECK_EQ(0, texture_id_);
} }
bool GLImageSurfaceTexture::Initialize(SurfaceTexture* surface_texture) { bool GLImageSurfaceTexture::Initialize(SurfaceTexture* surface_texture) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!surface_texture_.get()); DCHECK(!surface_texture_.get());
surface_texture_ = surface_texture; surface_texture_ = surface_texture;
return true; return true;
} }
void GLImageSurfaceTexture::Destroy(bool have_context) { void GLImageSurfaceTexture::Destroy(bool have_context) {
DCHECK(thread_checker_.CalledOnValidThread());
surface_texture_ = NULL; surface_texture_ = NULL;
texture_id_ = 0; texture_id_ = 0;
} }
...@@ -33,6 +36,7 @@ gfx::Size GLImageSurfaceTexture::GetSize() { return size_; } ...@@ -33,6 +36,7 @@ gfx::Size GLImageSurfaceTexture::GetSize() { return size_; }
bool GLImageSurfaceTexture::BindTexImage(unsigned target) { bool GLImageSurfaceTexture::BindTexImage(unsigned target) {
TRACE_EVENT0("gpu", "GLImageSurfaceTexture::BindTexImage"); TRACE_EVENT0("gpu", "GLImageSurfaceTexture::BindTexImage");
DCHECK(thread_checker_.CalledOnValidThread());
if (target != GL_TEXTURE_EXTERNAL_OES) { if (target != GL_TEXTURE_EXTERNAL_OES) {
LOG(ERROR) LOG(ERROR)
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define UI_GL_GL_IMAGE_SURFACE_TEXTURE_H_ #define UI_GL_GL_IMAGE_SURFACE_TEXTURE_H_
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/threading/thread_checker.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image.h" #include "ui/gl/gl_image.h"
...@@ -41,6 +42,7 @@ class GL_EXPORT GLImageSurfaceTexture : public GLImage { ...@@ -41,6 +42,7 @@ class GL_EXPORT GLImageSurfaceTexture : public GLImage {
scoped_refptr<SurfaceTexture> surface_texture_; scoped_refptr<SurfaceTexture> surface_texture_;
const gfx::Size size_; const gfx::Size size_;
GLint texture_id_; GLint texture_id_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(GLImageSurfaceTexture); DISALLOW_COPY_AND_ASSIGN(GLImageSurfaceTexture);
}; };
......
...@@ -31,6 +31,7 @@ class OZONE_GPU_EXPORT GpuMemoryBufferFactoryOzoneNativeBuffer { ...@@ -31,6 +31,7 @@ class OZONE_GPU_EXPORT GpuMemoryBufferFactoryOzoneNativeBuffer {
virtual ~GpuMemoryBufferFactoryOzoneNativeBuffer(); virtual ~GpuMemoryBufferFactoryOzoneNativeBuffer();
// Creates a GPU memory buffer identified by |id|. // Creates a GPU memory buffer identified by |id|.
// It can be called on any thread.
bool CreateGpuMemoryBuffer(gfx::GpuMemoryBufferId id, bool CreateGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
const gfx::Size& size, const gfx::Size& size,
gfx::GpuMemoryBuffer::Format format, gfx::GpuMemoryBuffer::Format format,
...@@ -39,6 +40,7 @@ class OZONE_GPU_EXPORT GpuMemoryBufferFactoryOzoneNativeBuffer { ...@@ -39,6 +40,7 @@ class OZONE_GPU_EXPORT GpuMemoryBufferFactoryOzoneNativeBuffer {
gfx::PluginWindowHandle surface_handle); gfx::PluginWindowHandle surface_handle);
// Destroys GPU memory buffer identified by |id|. // Destroys GPU memory buffer identified by |id|.
// It can be called on any thread.
void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id); void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id);
// Creates a GLImage instance for GPU memory buffer identified by |id|. // Creates a GLImage instance for GPU memory buffer identified by |id|.
......
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