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