summaryrefslogtreecommitdiffstats
path: root/ui/gl
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gl')
-rw-r--r--ui/gl/BUILD.gn1
-rw-r--r--ui/gl/gl_image.h32
-rw-r--r--ui/gl/gl_image_egl.cc15
-rw-r--r--ui/gl/gl_image_egl.h13
-rw-r--r--ui/gl/gl_image_glx.cc52
-rw-r--r--ui/gl/gl_image_glx.h13
-rw-r--r--ui/gl/gl_image_io_surface.h23
-rw-r--r--ui/gl/gl_image_io_surface.mm28
-rw-r--r--ui/gl/gl_image_memory.cc224
-rw-r--r--ui/gl/gl_image_memory.h29
-rw-r--r--ui/gl/gl_image_ozone_native_pixmap.cc23
-rw-r--r--ui/gl/gl_image_ozone_native_pixmap.h2
-rw-r--r--ui/gl/gl_image_ref_counted_memory.cc15
-rw-r--r--ui/gl/gl_image_ref_counted_memory.h4
-rw-r--r--ui/gl/gl_image_ref_counted_memory_unittest.cc4
-rw-r--r--ui/gl/gl_image_shared_memory.cc29
-rw-r--r--ui/gl/gl_image_shared_memory.h9
-rw-r--r--ui/gl/gl_image_shared_memory_unittest.cc4
-rw-r--r--ui/gl/gl_image_stub.cc10
-rw-r--r--ui/gl/gl_image_stub.h9
-rw-r--r--ui/gl/gl_image_surface_texture.cc15
-rw-r--r--ui/gl/gl_image_surface_texture.h13
-rw-r--r--ui/gl/gl_tests.gyp1
-rw-r--r--ui/gl/test/gl_image_test_template.h62
24 files changed, 384 insertions, 246 deletions
diff --git a/ui/gl/BUILD.gn b/ui/gl/BUILD.gn
index 2e04ee0..bfd095b 100644
--- a/ui/gl/BUILD.gn
+++ b/ui/gl/BUILD.gn
@@ -356,7 +356,6 @@ test("gl_unittests") {
"//testing/gmock",
"//testing/gtest",
"//ui/gfx",
- "//ui/gfx/geometry",
]
data_deps = [
diff --git a/ui/gl/gl_image.h b/ui/gl/gl_image.h
index aba2651..a236699 100644
--- a/ui/gl/gl_image.h
+++ b/ui/gl/gl_image.h
@@ -5,8 +5,6 @@
#ifndef UI_GL_GL_IMAGE_H_
#define UI_GL_GL_IMAGE_H_
-#include <string>
-
#include "base/memory/ref_counted.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
@@ -24,8 +22,8 @@ class ProcessMemoryDump;
namespace gfx {
-// Encapsulates an image that can be bound and/or copied to a texture, hiding
-// platform specific management.
+// Encapsulates an image that can be bound to a texture, hiding platform
+// specific management.
class GL_EXPORT GLImage : public base::RefCounted<GLImage> {
public:
GLImage() {}
@@ -34,32 +32,36 @@ class GL_EXPORT GLImage : public base::RefCounted<GLImage> {
virtual void Destroy(bool have_context) = 0;
// Get the size of the image.
- virtual Size GetSize() = 0;
+ virtual gfx::Size GetSize() = 0;
// Get the internal format of the image.
virtual unsigned GetInternalFormat() = 0;
- // Bind image to texture currently bound to |target|. Returns true on success.
- // It is valid for an implementation to always return false.
+ // Bind image to texture currently bound to |target|.
virtual bool BindTexImage(unsigned target) = 0;
// Release image from texture currently bound to |target|.
virtual void ReleaseTexImage(unsigned target) = 0;
- // Define texture currently bound to |target| by copying image into it.
- // Returns true on success. It is valid for an implementation to always
- // return false.
- virtual bool CopyTexImage(unsigned target) = 0;
-
// Copy |rect| of image to |offset| in texture currently bound to |target|.
- // Returns true on success. It is valid for an implementation to always
- // return false.
virtual bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) = 0;
+ // Called before the texture is used for drawing.
+ virtual void WillUseTexImage() = 0;
+
+ // Called after the texture has been used for drawing.
+ virtual void DidUseTexImage() = 0;
+
+ // Called before the texture image data will be modified.
+ virtual void WillModifyTexImage() = 0;
+
+ // Called after the texture image data has been modified.
+ virtual void DidModifyTexImage() = 0;
+
// Schedule image as an overlay plane to be shown at swap time for |widget|.
- virtual bool ScheduleOverlayPlane(AcceleratedWidget widget,
+ virtual bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_egl.cc b/ui/gl/gl_image_egl.cc
index 6f72c4f..0ebd7cc 100644
--- a/ui/gl/gl_image_egl.cc
+++ b/ui/gl/gl_image_egl.cc
@@ -9,8 +9,9 @@
namespace gfx {
-GLImageEGL::GLImageEGL(const Size& size)
- : egl_image_(EGL_NO_IMAGE_KHR), size_(size) {}
+GLImageEGL::GLImageEGL(const gfx::Size& size)
+ : egl_image_(EGL_NO_IMAGE_KHR), size_(size) {
+}
GLImageEGL::~GLImageEGL() {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -48,9 +49,7 @@ void GLImageEGL::Destroy(bool have_context) {
}
}
-Size GLImageEGL::GetSize() {
- return size_;
-}
+gfx::Size GLImageEGL::GetSize() { return size_; }
unsigned GLImageEGL::GetInternalFormat() { return GL_RGBA; }
@@ -62,17 +61,13 @@ bool GLImageEGL::BindTexImage(unsigned target) {
return true;
}
-bool GLImageEGL::CopyTexImage(unsigned target) {
- return false;
-}
-
bool GLImageEGL::CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) {
return false;
}
-bool GLImageEGL::ScheduleOverlayPlane(AcceleratedWidget widget,
+bool GLImageEGL::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_egl.h b/ui/gl/gl_image_egl.h
index 4110fd0d..14cc40b 100644
--- a/ui/gl/gl_image_egl.h
+++ b/ui/gl/gl_image_egl.h
@@ -13,21 +13,24 @@ namespace gfx {
class GL_EXPORT GLImageEGL : public GLImage {
public:
- explicit GLImageEGL(const Size& size);
+ explicit GLImageEGL(const gfx::Size& size);
bool Initialize(EGLenum target, EGLClientBuffer buffer, const EGLint* attrs);
// Overridden from GLImage:
void Destroy(bool have_context) override;
- Size GetSize() override;
+ gfx::Size GetSize() override;
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override {}
- bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
- bool ScheduleOverlayPlane(AcceleratedWidget widget,
+ void WillUseTexImage() override {}
+ void DidUseTexImage() override {}
+ void WillModifyTexImage() override {}
+ void DidModifyTexImage() override {}
+ bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
@@ -37,7 +40,7 @@ class GL_EXPORT GLImageEGL : public GLImage {
~GLImageEGL() override;
EGLImageKHR egl_image_;
- const Size size_;
+ const gfx::Size size_;
base::ThreadChecker thread_checker_;
private:
diff --git a/ui/gl/gl_image_glx.cc b/ui/gl/gl_image_glx.cc
index f2eddf9..496cf44 100644
--- a/ui/gl/gl_image_glx.cc
+++ b/ui/gl/gl_image_glx.cc
@@ -13,6 +13,7 @@ extern "C" {
#include "ui/gl/gl_surface_glx.h"
namespace gfx {
+
namespace {
bool ValidFormat(unsigned internalformat) {
@@ -61,7 +62,7 @@ unsigned PixmapDepth(unsigned internalformat) {
}
}
-bool ActualPixmapGeometry(XID pixmap, Size* size, unsigned* depth) {
+bool ActualPixmapGeometry(XID pixmap, gfx::Size* size, unsigned* depth) {
XID root_return;
int x_return;
int y_return;
@@ -69,13 +70,19 @@ bool ActualPixmapGeometry(XID pixmap, Size* size, unsigned* depth) {
unsigned height_return;
unsigned border_width_return;
unsigned depth_return;
- if (!XGetGeometry(GetXDisplay(), pixmap, &root_return, &x_return, &y_return,
- &width_return, &height_return, &border_width_return,
+ if (!XGetGeometry(gfx::GetXDisplay(),
+ pixmap,
+ &root_return,
+ &x_return,
+ &y_return,
+ &width_return,
+ &height_return,
+ &border_width_return,
&depth_return))
return false;
if (size)
- *size = Size(width_return, height_return);
+ *size = gfx::Size(width_return, height_return);
if (depth)
*depth = depth_return;
return true;
@@ -89,18 +96,19 @@ unsigned ActualPixmapDepth(XID pixmap) {
return depth;
}
-Size ActualPixmapSize(XID pixmap) {
- Size size;
+gfx::Size ActualPixmapSize(XID pixmap) {
+ gfx::Size size;
if (!ActualPixmapGeometry(pixmap, &size, NULL))
- return Size();
+ return gfx::Size();
return size;
}
-} // namespace
+} // namespace anonymous
-GLImageGLX::GLImageGLX(const Size& size, unsigned internalformat)
- : glx_pixmap_(0), size_(size), internalformat_(internalformat) {}
+GLImageGLX::GLImageGLX(const gfx::Size& size, unsigned internalformat)
+ : glx_pixmap_(0), size_(size), internalformat_(internalformat) {
+}
GLImageGLX::~GLImageGLX() {
DCHECK_EQ(0u, glx_pixmap_);
@@ -126,8 +134,8 @@ bool GLImageGLX::Initialize(XID pixmap) {
BindToTextureFormat(internalformat_), GL_TRUE,
0};
int num_elements = 0;
- XScopedPtr<GLXFBConfig> config(
- glXChooseFBConfig(GetXDisplay(), DefaultScreen(GetXDisplay()),
+ gfx::XScopedPtr<GLXFBConfig> config(
+ glXChooseFBConfig(gfx::GetXDisplay(), DefaultScreen(gfx::GetXDisplay()),
config_attribs, &num_elements));
if (!config.get()) {
DVLOG(0) << "glXChooseFBConfig failed.";
@@ -141,8 +149,8 @@ bool GLImageGLX::Initialize(XID pixmap) {
int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
GLX_TEXTURE_FORMAT_EXT,
TextureFormat(internalformat_), 0};
- glx_pixmap_ =
- glXCreatePixmap(GetXDisplay(), *config.get(), pixmap, pixmap_attribs);
+ glx_pixmap_ = glXCreatePixmap(
+ gfx::GetXDisplay(), *config.get(), pixmap, pixmap_attribs);
if (!glx_pixmap_) {
DVLOG(0) << "glXCreatePixmap failed.";
return false;
@@ -153,14 +161,12 @@ bool GLImageGLX::Initialize(XID pixmap) {
void GLImageGLX::Destroy(bool have_context) {
if (glx_pixmap_) {
- glXDestroyGLXPixmap(GetXDisplay(), glx_pixmap_);
+ glXDestroyGLXPixmap(gfx::GetXDisplay(), glx_pixmap_);
glx_pixmap_ = 0;
}
}
-Size GLImageGLX::GetSize() {
- return size_;
-}
+gfx::Size GLImageGLX::GetSize() { return size_; }
unsigned GLImageGLX::GetInternalFormat() { return internalformat_; }
@@ -172,7 +178,7 @@ bool GLImageGLX::BindTexImage(unsigned target) {
if (target != GL_TEXTURE_2D)
return false;
- glXBindTexImageEXT(GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT, 0);
+ glXBindTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT, 0);
return true;
}
@@ -180,11 +186,7 @@ void GLImageGLX::ReleaseTexImage(unsigned target) {
DCHECK_NE(0u, glx_pixmap_);
DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target);
- glXReleaseTexImageEXT(GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT);
-}
-
-bool GLImageGLX::CopyTexImage(unsigned target) {
- return false;
+ glXReleaseTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT);
}
bool GLImageGLX::CopyTexSubImage(unsigned target,
@@ -193,7 +195,7 @@ bool GLImageGLX::CopyTexSubImage(unsigned target,
return false;
}
-bool GLImageGLX::ScheduleOverlayPlane(AcceleratedWidget widget,
+bool GLImageGLX::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_glx.h b/ui/gl/gl_image_glx.h
index e22512e..5de1d0d 100644
--- a/ui/gl/gl_image_glx.h
+++ b/ui/gl/gl_image_glx.h
@@ -14,21 +14,24 @@ namespace gfx {
class GL_EXPORT GLImageGLX : public GLImage {
public:
- GLImageGLX(const Size& size, unsigned internalformat);
+ GLImageGLX(const gfx::Size& size, unsigned internalformat);
bool Initialize(XID pixmap);
// Overridden from GLImage:
void Destroy(bool have_context) override;
- Size GetSize() override;
+ gfx::Size GetSize() override;
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override;
- bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
- bool ScheduleOverlayPlane(AcceleratedWidget widget,
+ void WillUseTexImage() override {}
+ void DidUseTexImage() override {}
+ void WillModifyTexImage() override {}
+ void DidModifyTexImage() override {}
+ bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
@@ -42,7 +45,7 @@ class GL_EXPORT GLImageGLX : public GLImage {
private:
XID glx_pixmap_;
- const Size size_;
+ const gfx::Size size_;
unsigned internalformat_;
DISALLOW_COPY_AND_ASSIGN(GLImageGLX);
diff --git a/ui/gl/gl_image_io_surface.h b/ui/gl/gl_image_io_surface.h
index 45bd3ac..56b4478 100644
--- a/ui/gl/gl_image_io_surface.h
+++ b/ui/gl/gl_image_io_surface.h
@@ -9,8 +9,7 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/threading/thread_checker.h"
-#include "ui/gfx/buffer_types.h"
-#include "ui/gfx/generic_shared_memory_id.h"
+#include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gl/gl_image.h"
#if defined(__OBJC__)
@@ -23,23 +22,26 @@ namespace gfx {
class GL_EXPORT GLImageIOSurface : public GLImage {
public:
- GLImageIOSurface(const Size& size, unsigned internalformat);
+ GLImageIOSurface(const gfx::Size& size, unsigned internalformat);
bool Initialize(IOSurfaceRef io_surface,
- GenericSharedMemoryId io_surface_id,
+ gfx::GenericSharedMemoryId io_surface_id,
BufferFormat format);
// Overridden from GLImage:
void Destroy(bool have_context) override;
- Size GetSize() override;
+ gfx::Size GetSize() override;
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override {}
- bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
- bool ScheduleOverlayPlane(AcceleratedWidget widget,
+ void WillUseTexImage() override {}
+ void DidUseTexImage() override {}
+ void WillModifyTexImage() override {}
+ void DidModifyTexImage() override {}
+ bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
@@ -50,17 +52,18 @@ class GL_EXPORT GLImageIOSurface : public GLImage {
base::ScopedCFTypeRef<IOSurfaceRef> io_surface();
- static void SetLayerForWidget(AcceleratedWidget widget, CALayer* layer);
+ static void SetLayerForWidget(gfx::AcceleratedWidget widget,
+ CALayer* layer);
protected:
~GLImageIOSurface() override;
private:
- const Size size_;
+ const gfx::Size size_;
const unsigned internalformat_;
BufferFormat format_;
base::ScopedCFTypeRef<IOSurfaceRef> io_surface_;
- GenericSharedMemoryId io_surface_id_;
+ gfx::GenericSharedMemoryId io_surface_id_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(GLImageIOSurface);
diff --git a/ui/gl/gl_image_io_surface.mm b/ui/gl/gl_image_io_surface.mm
index 4294298..3f4964e 100644
--- a/ui/gl/gl_image_io_surface.mm
+++ b/ui/gl/gl_image_io_surface.mm
@@ -8,9 +8,6 @@
#include "base/lazy_instance.h"
#include "base/mac/foundation_util.h"
-#include "base/trace_event/memory_allocator_dump.h"
-#include "base/trace_event/memory_dump_manager.h"
-#include "base/trace_event/process_memory_dump.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
@@ -21,7 +18,7 @@
namespace gfx {
namespace {
-using WidgetToLayerMap = std::map<AcceleratedWidget, CALayer*>;
+typedef std::map<gfx::AcceleratedWidget,CALayer*> WidgetToLayerMap;
base::LazyInstance<WidgetToLayerMap> g_widget_to_layer_map;
bool ValidInternalFormat(unsigned internalformat) {
@@ -141,7 +138,8 @@ GLenum DataType(BufferFormat format) {
} // namespace
-GLImageIOSurface::GLImageIOSurface(const Size& size, unsigned internalformat)
+GLImageIOSurface::GLImageIOSurface(const gfx::Size& size,
+ unsigned internalformat)
: size_(size),
internalformat_(internalformat),
format_(BufferFormat::RGBA_8888) {}
@@ -152,7 +150,7 @@ GLImageIOSurface::~GLImageIOSurface() {
}
bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface,
- GenericSharedMemoryId io_surface_id,
+ gfx::GenericSharedMemoryId io_surface_id,
BufferFormat format) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!io_surface_);
@@ -178,9 +176,7 @@ void GLImageIOSurface::Destroy(bool have_context) {
io_surface_.reset();
}
-Size GLImageIOSurface::GetSize() {
- return size_;
-}
+gfx::Size GLImageIOSurface::GetSize() { return size_; }
unsigned GLImageIOSurface::GetInternalFormat() { return internalformat_; }
@@ -209,17 +205,13 @@ bool GLImageIOSurface::BindTexImage(unsigned target) {
return true;
}
-bool GLImageIOSurface::CopyTexImage(unsigned target) {
- return false;
-}
-
bool GLImageIOSurface::CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) {
return false;
}
-bool GLImageIOSurface::ScheduleOverlayPlane(AcceleratedWidget widget,
+bool GLImageIOSurface::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
@@ -241,8 +233,8 @@ void GLImageIOSurface::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
static_cast<uint64_t>(size_bytes));
- auto guid =
- GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_);
+ auto guid = gfx::GetGenericSharedMemoryGUIDForTracing(process_tracing_id,
+ io_surface_id_);
pmd->CreateSharedGlobalAllocatorDump(guid);
pmd->AddOwnershipEdge(dump->guid(), guid);
}
@@ -252,8 +244,8 @@ base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() {
}
// static
-void GLImageIOSurface::SetLayerForWidget(AcceleratedWidget widget,
- CALayer* layer) {
+void GLImageIOSurface::SetLayerForWidget(
+ gfx::AcceleratedWidget widget, CALayer* layer) {
if (layer)
g_widget_to_layer_map.Pointer()->insert(std::make_pair(widget, layer));
else
diff --git a/ui/gl/gl_image_memory.cc b/ui/gl/gl_image_memory.cc
index 045c50c..c91ad56 100644
--- a/ui/gl/gl_image_memory.cc
+++ b/ui/gl/gl_image_memory.cc
@@ -7,6 +7,12 @@
#include "base/logging.h"
#include "base/trace_event/trace_event.h"
#include "ui/gl/gl_bindings.h"
+#include "ui/gl/scoped_binders.h"
+
+#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
+ defined(USE_OZONE)
+#include "ui/gl/gl_surface_egl.h"
+#endif
namespace gfx {
namespace {
@@ -146,11 +152,26 @@ GLsizei SizeInBytes(const Size& size, BufferFormat format) {
GLImageMemory::GLImageMemory(const Size& size, unsigned internalformat)
: size_(size),
internalformat_(internalformat),
- memory_(nullptr),
- format_(BufferFormat::RGBA_8888) {}
+ memory_(NULL),
+ format_(BufferFormat::RGBA_8888),
+ in_use_(false),
+ target_(0),
+ need_do_bind_tex_image_(false)
+#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
+ defined(USE_OZONE)
+ ,
+ egl_texture_id_(0u),
+ egl_image_(EGL_NO_IMAGE_KHR)
+#endif
+{
+}
GLImageMemory::~GLImageMemory() {
- DCHECK(!memory_);
+#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
+ defined(USE_OZONE)
+ DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
+ DCHECK_EQ(0u, egl_texture_id_);
+#endif
}
// static
@@ -222,7 +243,20 @@ bool GLImageMemory::Initialize(const unsigned char* memory,
}
void GLImageMemory::Destroy(bool have_context) {
- memory_ = nullptr;
+#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
+ defined(USE_OZONE)
+ if (egl_image_ != EGL_NO_IMAGE_KHR) {
+ eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
+ egl_image_ = EGL_NO_IMAGE_KHR;
+ }
+
+ if (egl_texture_id_) {
+ if (have_context)
+ glDeleteTextures(1, &egl_texture_id_);
+ egl_texture_id_ = 0u;
+ }
+#endif
+ memory_ = NULL;
}
Size GLImageMemory::GetSize() {
@@ -234,27 +268,19 @@ unsigned GLImageMemory::GetInternalFormat() {
}
bool GLImageMemory::BindTexImage(unsigned target) {
- return false;
-}
-
-bool GLImageMemory::CopyTexImage(unsigned target) {
- TRACE_EVENT2("gpu", "GLImageMemory::CopyTexImage", "width", size_.width(),
- "height", size_.height());
-
- // GL_TEXTURE_EXTERNAL_OES is not a supported target.
- if (target == GL_TEXTURE_EXTERNAL_OES)
+ if (target_ && target_ != target) {
+ LOG(ERROR) << "GLImage can only be bound to one target";
return false;
+ }
+ target_ = target;
- if (IsCompressedFormat(format_)) {
- glCompressedTexImage2D(target, 0, TextureFormat(format_), size_.width(),
- size_.height(), 0, SizeInBytes(size_, format_),
- memory_);
- } else {
- glTexImage2D(target, 0, TextureFormat(format_), size_.width(),
- size_.height(), 0, DataFormat(format_), DataType(format_),
- memory_);
+ // Defer DoBindTexImage if not currently in use.
+ if (!in_use_) {
+ need_do_bind_tex_image_ = true;
+ return true;
}
+ DoBindTexImage(target);
return true;
}
@@ -264,7 +290,7 @@ bool GLImageMemory::CopyTexSubImage(unsigned target,
TRACE_EVENT2("gpu", "GLImageMemory::CopyTexSubImage", "width", rect.width(),
"height", rect.height());
- // GL_TEXTURE_EXTERNAL_OES is not a supported target.
+ // GL_TEXTURE_EXTERNAL_OES is not a supported CopyTexSubImage target.
if (target == GL_TEXTURE_EXTERNAL_OES)
return false;
@@ -282,18 +308,36 @@ bool GLImageMemory::CopyTexSubImage(unsigned target,
DCHECK(memory_);
const unsigned char* data = memory_ + rect.y() * stride_in_bytes;
if (IsCompressedFormat(format_)) {
- glCompressedTexSubImage2D(target, 0, offset.x(), offset.y(), rect.width(),
+ glCompressedTexSubImage2D(target,
+ 0, // level
+ offset.x(), offset.y(), rect.width(),
rect.height(), DataFormat(format_),
SizeInBytes(rect.size(), format_), data);
} else {
- glTexSubImage2D(target, 0, offset.x(), offset.y(), rect.width(),
- rect.height(), DataFormat(format_), DataType(format_),
- data);
+ glTexSubImage2D(target, 0, // level
+ offset.x(), offset.y(), rect.width(), rect.height(),
+ DataFormat(format_), DataType(format_), data);
}
return true;
}
+void GLImageMemory::WillUseTexImage() {
+ DCHECK(!in_use_);
+ in_use_ = true;
+
+ if (!need_do_bind_tex_image_)
+ return;
+
+ DCHECK(target_);
+ DoBindTexImage(target_);
+}
+
+void GLImageMemory::DidUseTexImage() {
+ DCHECK(in_use_);
+ in_use_ = false;
+}
+
bool GLImageMemory::ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
@@ -302,4 +346,132 @@ bool GLImageMemory::ScheduleOverlayPlane(AcceleratedWidget widget,
return false;
}
+void GLImageMemory::DoBindTexImage(unsigned target) {
+ TRACE_EVENT0("gpu", "GLImageMemory::DoBindTexImage");
+
+ DCHECK(need_do_bind_tex_image_);
+ need_do_bind_tex_image_ = false;
+
+ DCHECK(memory_);
+#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
+ defined(USE_OZONE)
+ if (target == GL_TEXTURE_EXTERNAL_OES) {
+ if (egl_image_ == EGL_NO_IMAGE_KHR) {
+ DCHECK_EQ(0u, egl_texture_id_);
+ glGenTextures(1, &egl_texture_id_);
+
+ {
+ ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ if (IsCompressedFormat(format_)) {
+ glCompressedTexImage2D(GL_TEXTURE_2D,
+ 0, // mip level
+ TextureFormat(format_), size_.width(),
+ size_.height(),
+ 0, // border
+ SizeInBytes(size_, format_), memory_);
+ } else {
+ glTexImage2D(GL_TEXTURE_2D,
+ 0, // mip level
+ TextureFormat(format_),
+ size_.width(),
+ size_.height(),
+ 0, // border
+ DataFormat(format_),
+ DataType(format_),
+ memory_);
+ }
+ }
+
+ EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
+ // Need to pass current EGL rendering context to eglCreateImageKHR for
+ // target type EGL_GL_TEXTURE_2D_KHR.
+ egl_image_ =
+ eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
+ eglGetCurrentContext(),
+ EGL_GL_TEXTURE_2D_KHR,
+ reinterpret_cast<EGLClientBuffer>(egl_texture_id_),
+ attrs);
+ DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
+ << "Error creating EGLImage: " << eglGetError();
+ } else {
+ ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
+
+ if (IsCompressedFormat(format_)) {
+ glCompressedTexSubImage2D(GL_TEXTURE_2D,
+ 0, // mip level
+ 0, // x-offset
+ 0, // y-offset
+ size_.width(), size_.height(),
+ DataFormat(format_),
+ SizeInBytes(size_, format_), memory_);
+ } else {
+ glTexSubImage2D(GL_TEXTURE_2D,
+ 0, // mip level
+ 0, // x-offset
+ 0, // y-offset
+ size_.width(),
+ size_.height(),
+ DataFormat(format_),
+ DataType(format_),
+ memory_);
+ }
+ }
+
+ glEGLImageTargetTexture2DOES(target, egl_image_);
+ DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
+ return;
+ }
+#endif
+
+ DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target);
+ if (IsCompressedFormat(format_)) {
+ glCompressedTexImage2D(target,
+ 0, // mip level
+ TextureFormat(format_), size_.width(),
+ size_.height(),
+ 0, // border
+ SizeInBytes(size_, format_), memory_);
+ } else {
+ glTexImage2D(target,
+ 0, // mip level
+ TextureFormat(format_),
+ size_.width(),
+ size_.height(),
+ 0, // border
+ DataFormat(format_),
+ DataType(format_),
+ memory_);
+ }
+}
+
+void GLImageMemory::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
+ uint64_t process_tracing_id,
+ const std::string& dump_name) {
+ // Note that the following calculation does not consider whether this GLImage
+ // has been un-bound from a texture. It also relies on this GLImage only ever
+ // being bound to a single texture. We could check these conditions more
+ // thoroughly, but at the cost of extra GL queries.
+ bool is_bound_to_texture = target_ && !need_do_bind_tex_image_;
+
+#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
+ defined(USE_OZONE)
+ is_bound_to_texture |= !!egl_texture_id_;
+#endif
+
+ size_t size_in_bytes = is_bound_to_texture ? SizeInBytes(size_, format_) : 0;
+
+ base::trace_event::MemoryAllocatorDump* dump =
+ pmd->CreateAllocatorDump(dump_name + "/texture_memory");
+ dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes,
+ static_cast<uint64_t>(size_in_bytes));
+
+ // No need for a global shared edge here. This object in the GPU process is
+ // the sole owner of this texture id.
+}
+
} // namespace gfx
diff --git a/ui/gl/gl_image_memory.h b/ui/gl/gl_image_memory.h
index 4f1fe04..10b1a3b 100644
--- a/ui/gl/gl_image_memory.h
+++ b/ui/gl/gl_image_memory.h
@@ -7,8 +7,14 @@
#include "ui/gl/gl_image.h"
+#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
+ defined(USE_OZONE)
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#endif
+
#include "base/numerics/safe_math.h"
-#include "ui/gfx/buffer_types.h"
+#include "ui/gfx/gpu_memory_buffer.h"
namespace gfx {
@@ -28,26 +34,45 @@ class GL_EXPORT GLImageMemory : public GLImage {
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override {}
- bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
+ void WillUseTexImage() override;
+ void DidUseTexImage() override;
+ void WillModifyTexImage() override {}
+ void DidModifyTexImage() override {}
bool ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
const RectF& crop_rect) override;
+ // Only dumps the GLTexture portion of the memory usage. Subclasses are
+ // responsible for dumping the CPU-side memory.
+ void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
+ uint64_t process_tracing_id,
+ const std::string& dump_name) override;
+
protected:
~GLImageMemory() override;
BufferFormat format() const { return format_; }
private:
+ void DoBindTexImage(unsigned target);
+
const Size size_;
const unsigned internalformat_;
const unsigned char* memory_;
BufferFormat format_;
+ bool in_use_;
+ unsigned target_;
+ bool need_do_bind_tex_image_;
+#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
+ defined(USE_OZONE)
+ unsigned egl_texture_id_;
+ EGLImageKHR egl_image_;
+#endif
DISALLOW_COPY_AND_ASSIGN(GLImageMemory);
};
diff --git a/ui/gl/gl_image_ozone_native_pixmap.cc b/ui/gl/gl_image_ozone_native_pixmap.cc
index e0d0e37..3e0cfb5 100644
--- a/ui/gl/gl_image_ozone_native_pixmap.cc
+++ b/ui/gl/gl_image_ozone_native_pixmap.cc
@@ -26,7 +26,7 @@ bool ValidInternalFormat(unsigned internalformat) {
}
}
-bool ValidFormat(BufferFormat format) {
+bool ValidFormat(gfx::BufferFormat format) {
switch (format) {
case BufferFormat::RGBA_8888:
case BufferFormat::BGRA_8888:
@@ -49,7 +49,7 @@ bool ValidFormat(BufferFormat format) {
return false;
}
-EGLint FourCC(BufferFormat format) {
+EGLint FourCC(gfx::BufferFormat format) {
switch (format) {
case BufferFormat::RGBA_8888:
return DRM_FORMAT_ABGR8888;
@@ -87,12 +87,12 @@ GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() {
bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap,
BufferFormat format) {
DCHECK(!pixmap_);
+
+ bool result = true;
if (pixmap->GetEGLClientBuffer()) {
EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
- if (!GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR,
- pixmap->GetEGLClientBuffer(), attrs)) {
- return false;
- }
+ result = GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR,
+ pixmap->GetEGLClientBuffer(), attrs);
} else if (pixmap->GetDmaBufFd() >= 0) {
if (!ValidInternalFormat(internalformat_)) {
LOG(ERROR) << "Invalid internalformat: " << internalformat_;
@@ -119,14 +119,13 @@ bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap,
EGL_DMA_BUF_PLANE0_PITCH_EXT,
pixmap->GetDmaBufPitch(),
EGL_NONE};
- if (!GLImageEGL::Initialize(EGL_LINUX_DMA_BUF_EXT,
- static_cast<EGLClientBuffer>(nullptr), attrs)) {
- return false;
- }
+ result = GLImageEGL::Initialize(
+ EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(nullptr), attrs);
}
- pixmap_ = pixmap;
- return true;
+ if (result)
+ pixmap_ = pixmap;
+ return result;
}
unsigned GLImageOzoneNativePixmap::GetInternalFormat() {
diff --git a/ui/gl/gl_image_ozone_native_pixmap.h b/ui/gl/gl_image_ozone_native_pixmap.h
index 6505299..e164f39 100644
--- a/ui/gl/gl_image_ozone_native_pixmap.h
+++ b/ui/gl/gl_image_ozone_native_pixmap.h
@@ -5,7 +5,7 @@
#ifndef UI_GL_GL_IMAGE_OZONE_NATIVE_PIXMAP_H_
#define UI_GL_GL_IMAGE_OZONE_NATIVE_PIXMAP_H_
-#include "ui/gfx/buffer_types.h"
+#include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gl/gl_image_egl.h"
#include "ui/ozone/public/native_pixmap.h"
diff --git a/ui/gl/gl_image_ref_counted_memory.cc b/ui/gl/gl_image_ref_counted_memory.cc
index 6533568..7aadd24 100644
--- a/ui/gl/gl_image_ref_counted_memory.cc
+++ b/ui/gl/gl_image_ref_counted_memory.cc
@@ -6,15 +6,13 @@
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
-#include "base/trace_event/memory_allocator_dump.h"
-#include "base/trace_event/memory_dump_manager.h"
-#include "base/trace_event/process_memory_dump.h"
namespace gfx {
-GLImageRefCountedMemory::GLImageRefCountedMemory(const Size& size,
+GLImageRefCountedMemory::GLImageRefCountedMemory(const gfx::Size& size,
unsigned internalformat)
- : GLImageMemory(size, internalformat) {}
+ : GLImageMemory(size, internalformat) {
+}
GLImageRefCountedMemory::~GLImageRefCountedMemory() {
DCHECK(!ref_counted_memory_.get());
@@ -22,7 +20,7 @@ GLImageRefCountedMemory::~GLImageRefCountedMemory() {
bool GLImageRefCountedMemory::Initialize(
base::RefCountedMemory* ref_counted_memory,
- BufferFormat format) {
+ gfx::BufferFormat format) {
if (!GLImageMemory::Initialize(ref_counted_memory->front(), format))
return false;
@@ -33,7 +31,7 @@ bool GLImageRefCountedMemory::Initialize(
void GLImageRefCountedMemory::Destroy(bool have_context) {
GLImageMemory::Destroy(have_context);
- ref_counted_memory_ = nullptr;
+ ref_counted_memory_ = NULL;
}
void GLImageRefCountedMemory::OnMemoryDump(
@@ -54,6 +52,9 @@ void GLImageRefCountedMemory::OnMemoryDump(
pmd->AddSuballocation(dump->guid(),
base::trace_event::MemoryDumpManager::GetInstance()
->system_allocator_pool_name());
+
+ // Also dump the base class's texture memory.
+ GLImageMemory::OnMemoryDump(pmd, process_tracing_id, dump_name);
}
} // namespace gfx
diff --git a/ui/gl/gl_image_ref_counted_memory.h b/ui/gl/gl_image_ref_counted_memory.h
index f68acc5..db07954 100644
--- a/ui/gl/gl_image_ref_counted_memory.h
+++ b/ui/gl/gl_image_ref_counted_memory.h
@@ -16,10 +16,10 @@ namespace gfx {
class GL_EXPORT GLImageRefCountedMemory : public GLImageMemory {
public:
- GLImageRefCountedMemory(const Size& size, unsigned internalformat);
+ GLImageRefCountedMemory(const gfx::Size& size, unsigned internalformat);
bool Initialize(base::RefCountedMemory* ref_counted_memory,
- BufferFormat format);
+ gfx::BufferFormat format);
// Overridden from GLImage:
void Destroy(bool have_context) override;
diff --git a/ui/gl/gl_image_ref_counted_memory_unittest.cc b/ui/gl/gl_image_ref_counted_memory_unittest.cc
index c3d77e2..1edccf2 100644
--- a/ui/gl/gl_image_ref_counted_memory_unittest.cc
+++ b/ui/gl/gl_image_ref_counted_memory_unittest.cc
@@ -37,9 +37,5 @@ INSTANTIATE_TYPED_TEST_CASE_P(GLImageRefCountedMemory,
GLImageTest,
GLImageRefCountedMemoryTestDelegate);
-INSTANTIATE_TYPED_TEST_CASE_P(GLImageRefCountedMemory,
- GLImageCopyTest,
- GLImageRefCountedMemoryTestDelegate);
-
} // namespace
} // namespace gfx
diff --git a/ui/gl/gl_image_shared_memory.cc b/ui/gl/gl_image_shared_memory.cc
index 6ca7905..16ec6cb 100644
--- a/ui/gl/gl_image_shared_memory.cc
+++ b/ui/gl/gl_image_shared_memory.cc
@@ -5,18 +5,16 @@
#include "ui/gl/gl_image_shared_memory.h"
#include "base/logging.h"
-#include "base/memory/shared_memory.h"
#include "base/numerics/safe_math.h"
#include "base/process/process_handle.h"
-#include "base/trace_event/memory_allocator_dump.h"
-#include "base/trace_event/memory_dump_manager.h"
-#include "base/trace_event/process_memory_dump.h"
namespace gfx {
namespace {
// Returns true if the size is valid and false otherwise.
-bool SizeInBytes(const Size& size, BufferFormat format, size_t* size_in_bytes) {
+bool SizeInBytes(const gfx::Size& size,
+ gfx::BufferFormat format,
+ size_t* size_in_bytes) {
if (size.IsEmpty())
return false;
@@ -33,17 +31,19 @@ bool SizeInBytes(const Size& size, BufferFormat format, size_t* size_in_bytes) {
} // namespace
-GLImageSharedMemory::GLImageSharedMemory(const Size& size,
+GLImageSharedMemory::GLImageSharedMemory(const gfx::Size& size,
unsigned internalformat)
- : GLImageMemory(size, internalformat) {}
+ : GLImageMemory(size, internalformat) {
+}
GLImageSharedMemory::~GLImageSharedMemory() {
DCHECK(!shared_memory_);
}
-bool GLImageSharedMemory::Initialize(const base::SharedMemoryHandle& handle,
- GenericSharedMemoryId shared_memory_id,
- BufferFormat format) {
+bool GLImageSharedMemory::Initialize(
+ const base::SharedMemoryHandle& handle,
+ gfx::GenericSharedMemoryId shared_memory_id,
+ gfx::BufferFormat format) {
size_t size_in_bytes;
if (!SizeInBytes(GetSize(), format, &size_in_bytes))
return false;
@@ -98,15 +98,18 @@ void GLImageSharedMemory::OnMemoryDump(
// Dump under "/shared_memory", as the base class may also dump to
// "/texture_memory".
base::trace_event::MemoryAllocatorDump* dump =
- pmd->CreateAllocatorDump(dump_name + "/shared_memory");
+ pmd->CreateAllocatorDump(dump_name + "/private_memory");
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
static_cast<uint64_t>(size_in_bytes));
- auto guid = GetGenericSharedMemoryGUIDForTracing(process_tracing_id,
- shared_memory_id_);
+ auto guid = gfx::GetGenericSharedMemoryGUIDForTracing(process_tracing_id,
+ shared_memory_id_);
pmd->CreateSharedGlobalAllocatorDump(guid);
pmd->AddOwnershipEdge(dump->guid(), guid);
+
+ // Also dump the base class's texture memory.
+ GLImageMemory::OnMemoryDump(pmd, process_tracing_id, dump_name);
}
} // namespace gfx
diff --git a/ui/gl/gl_image_shared_memory.h b/ui/gl/gl_image_shared_memory.h
index 2e6374b5..622eb3d 100644
--- a/ui/gl/gl_image_shared_memory.h
+++ b/ui/gl/gl_image_shared_memory.h
@@ -7,21 +7,16 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/shared_memory_handle.h"
-#include "ui/gfx/generic_shared_memory_id.h"
#include "ui/gl/gl_image_memory.h"
-namespace base {
-class SharedMemory;
-}
-
namespace gfx {
class GL_EXPORT GLImageSharedMemory : public GLImageMemory {
public:
- GLImageSharedMemory(const Size& size, unsigned internalformat);
+ GLImageSharedMemory(const gfx::Size& size, unsigned internalformat);
bool Initialize(const base::SharedMemoryHandle& handle,
- GenericSharedMemoryId shared_memory_id,
+ gfx::GenericSharedMemoryId shared_memory_id,
BufferFormat format);
// Overridden from GLImage:
diff --git a/ui/gl/gl_image_shared_memory_unittest.cc b/ui/gl/gl_image_shared_memory_unittest.cc
index 9c280f9..44c8e97 100644
--- a/ui/gl/gl_image_shared_memory_unittest.cc
+++ b/ui/gl/gl_image_shared_memory_unittest.cc
@@ -39,9 +39,5 @@ INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory,
GLImageTest,
GLImageSharedMemoryTestDelegate);
-INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory,
- GLImageCopyTest,
- GLImageSharedMemoryTestDelegate);
-
} // namespace
} // namespace gfx
diff --git a/ui/gl/gl_image_stub.cc b/ui/gl/gl_image_stub.cc
index 803a05f..afbf6e0 100644
--- a/ui/gl/gl_image_stub.cc
+++ b/ui/gl/gl_image_stub.cc
@@ -12,25 +12,19 @@ GLImageStub::GLImageStub() {}
GLImageStub::~GLImageStub() {}
-Size GLImageStub::GetSize() {
- return Size(1, 1);
-}
+gfx::Size GLImageStub::GetSize() { return gfx::Size(1, 1); }
unsigned GLImageStub::GetInternalFormat() { return GL_RGBA; }
bool GLImageStub::BindTexImage(unsigned target) { return true; }
-bool GLImageStub::CopyTexImage(unsigned target) {
- return true;
-}
-
bool GLImageStub::CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) {
return true;
}
-bool GLImageStub::ScheduleOverlayPlane(AcceleratedWidget widget,
+bool GLImageStub::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_stub.h b/ui/gl/gl_image_stub.h
index c95fda9..be31bff 100644
--- a/ui/gl/gl_image_stub.h
+++ b/ui/gl/gl_image_stub.h
@@ -16,15 +16,18 @@ class GL_EXPORT GLImageStub : public GLImage {
// Overridden from GLImage:
void Destroy(bool have_context) override {}
- Size GetSize() override;
+ gfx::Size GetSize() override;
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override {}
- bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
- bool ScheduleOverlayPlane(AcceleratedWidget widget,
+ void WillUseTexImage() override {}
+ void DidUseTexImage() override {}
+ void WillModifyTexImage() override {}
+ void DidModifyTexImage() override {}
+ bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_surface_texture.cc b/ui/gl/gl_image_surface_texture.cc
index 6ad3667..910551d 100644
--- a/ui/gl/gl_image_surface_texture.cc
+++ b/ui/gl/gl_image_surface_texture.cc
@@ -9,8 +9,9 @@
namespace gfx {
-GLImageSurfaceTexture::GLImageSurfaceTexture(const Size& size)
- : size_(size), texture_id_(0) {}
+GLImageSurfaceTexture::GLImageSurfaceTexture(const gfx::Size& size)
+ : size_(size), texture_id_(0) {
+}
GLImageSurfaceTexture::~GLImageSurfaceTexture() {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -31,9 +32,7 @@ void GLImageSurfaceTexture::Destroy(bool have_context) {
texture_id_ = 0;
}
-Size GLImageSurfaceTexture::GetSize() {
- return size_;
-}
+gfx::Size GLImageSurfaceTexture::GetSize() { return size_; }
unsigned GLImageSurfaceTexture::GetInternalFormat() { return GL_RGBA; }
@@ -79,17 +78,13 @@ bool GLImageSurfaceTexture::BindTexImage(unsigned target) {
return true;
}
-bool GLImageSurfaceTexture::CopyTexImage(unsigned target) {
- return false;
-}
-
bool GLImageSurfaceTexture::CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) {
return false;
}
-bool GLImageSurfaceTexture::ScheduleOverlayPlane(AcceleratedWidget widget,
+bool GLImageSurfaceTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_surface_texture.h b/ui/gl/gl_image_surface_texture.h
index f18eaa2..d8c4abb 100644
--- a/ui/gl/gl_image_surface_texture.h
+++ b/ui/gl/gl_image_surface_texture.h
@@ -15,21 +15,24 @@ class SurfaceTexture;
class GL_EXPORT GLImageSurfaceTexture : public GLImage {
public:
- explicit GLImageSurfaceTexture(const Size& size);
+ explicit GLImageSurfaceTexture(const gfx::Size& size);
bool Initialize(SurfaceTexture* surface_texture);
// Overridden from GLImage:
void Destroy(bool have_context) override;
- Size GetSize() override;
+ gfx::Size GetSize() override;
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override {}
- bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
- bool ScheduleOverlayPlane(AcceleratedWidget widget,
+ void WillUseTexImage() override {}
+ void DidUseTexImage() override {}
+ void WillModifyTexImage() override {}
+ void DidModifyTexImage() override {}
+ bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
@@ -43,7 +46,7 @@ class GL_EXPORT GLImageSurfaceTexture : public GLImage {
private:
scoped_refptr<SurfaceTexture> surface_texture_;
- const Size size_;
+ const gfx::Size size_;
GLint texture_id_;
base::ThreadChecker thread_checker_;
diff --git a/ui/gl/gl_tests.gyp b/ui/gl/gl_tests.gyp
index eaf0df0..09821e7 100644
--- a/ui/gl/gl_tests.gyp
+++ b/ui/gl/gl_tests.gyp
@@ -28,7 +28,6 @@
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/third_party/mesa/mesa.gyp:osmesa',
'<(DEPTH)/ui/gfx/gfx.gyp:gfx',
- '<(DEPTH)/ui/gfx/gfx.gyp:gfx_geometry',
'<(DEPTH)/ui/gl/gl.gyp:gl',
'<(DEPTH)/ui/gl/gl.gyp:gl_test_support',
'<(DEPTH)/ui/gl/gl.gyp:gl_unittest_utils',
diff --git a/ui/gl/test/gl_image_test_template.h b/ui/gl/test/gl_image_test_template.h
index e7b685d..8533ce2 100644
--- a/ui/gl/test/gl_image_test_template.h
+++ b/ui/gl/test/gl_image_test_template.h
@@ -51,51 +51,9 @@ class GLImageTest : public testing::Test {
TYPED_TEST_CASE_P(GLImageTest);
-TYPED_TEST_P(GLImageTest, CreateAndDestroy) {
- const Size small_image_size(4, 4);
- const Size large_image_size(512, 512);
- const uint8_t image_color[] = {0, 0xff, 0, 0xff};
-
- // Create a small solid color green image of preferred format. This must
- // succeed in order for a GLImage to be conformant.
- scoped_refptr<GLImage> small_image = this->delegate_.CreateSolidColorImage(
- small_image_size, GLImageTestSupport::GetPreferredInternalFormat(),
- GLImageTestSupport::GetPreferredBufferFormat(), image_color);
- ASSERT_TRUE(small_image);
-
- // Create a large solid color green image of preferred format. This must
- // succeed in order for a GLImage to be conformant.
- scoped_refptr<GLImage> large_image = this->delegate_.CreateSolidColorImage(
- large_image_size, GLImageTestSupport::GetPreferredInternalFormat(),
- GLImageTestSupport::GetPreferredBufferFormat(), image_color);
- ASSERT_TRUE(large_image);
-
- // Verify that image size is correct.
- EXPECT_EQ(small_image->GetSize().ToString(), small_image_size.ToString());
- EXPECT_EQ(large_image->GetSize().ToString(), large_image_size.ToString());
-
- // Verify that internal format is correct.
- EXPECT_EQ(small_image->GetInternalFormat(),
- GLImageTestSupport::GetPreferredInternalFormat());
- EXPECT_EQ(large_image->GetInternalFormat(),
- GLImageTestSupport::GetPreferredInternalFormat());
-
- // Verify that destruction of images work correctly both when we have a
- // context and when we don't.
- small_image->Destroy(true /* have_context */);
- large_image->Destroy(false /* have_context */);
-}
-
-// The GLImageTest test case verifies the behaviour that is expected from a
-// GLImage in order to be conformant.
-REGISTER_TYPED_TEST_CASE_P(GLImageTest, CreateAndDestroy);
-
-template <typename GLImageTestDelegate>
-class GLImageCopyTest : public GLImageTest<GLImageTestDelegate> {};
-
-TYPED_TEST_CASE_P(GLImageCopyTest);
-
-TYPED_TEST_P(GLImageCopyTest, CopyTexImage) {
+// Copy image to texture. Support is optional. Texels should be updated if
+// supported, and left unchanged if not.
+TYPED_TEST_P(GLImageTest, CopyTexSubImage) {
const Size image_size(256, 256);
const uint8_t image_color[] = {0, 0xff, 0, 0xff};
const uint8_t texture_color[] = {0, 0, 0xff, 0xff};
@@ -133,9 +91,9 @@ TYPED_TEST_P(GLImageCopyTest, CopyTexImage) {
GLImageTestSupport::GetPreferredInternalFormat(),
GL_UNSIGNED_BYTE, pixels.get());
- // Copy |image| to |texture|.
- bool rv = image->CopyTexImage(GL_TEXTURE_2D);
- EXPECT_TRUE(rv);
+ // Attempt to copy |image| to |texture|.
+ // Returns true on success, false on failure.
+ bool rv = image->CopyTexSubImage(GL_TEXTURE_2D, Point(), Rect(image_size));
// clang-format off
const char kVertexShader[] = STRINGIZE(
@@ -203,7 +161,7 @@ TYPED_TEST_P(GLImageCopyTest, CopyTexImage) {
// Draw |texture| to viewport and read back pixels to check expectations.
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(),
- image_color);
+ rv ? image_color : texture_color);
// Clean up.
glDeleteProgram(program);
@@ -215,9 +173,9 @@ TYPED_TEST_P(GLImageCopyTest, CopyTexImage) {
image->Destroy(true);
}
-// The GLImageCopyTest test case verifies that the GLImage implementation
-// handles CopyTexImage correctly.
-REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage);
+// The GLImageTest test case verifies behaviour that is expected from a
+// GLImage in order to be conformant.
+REGISTER_TYPED_TEST_CASE_P(GLImageTest, CopyTexSubImage);
} // namespace gfx