Update from https://crrev.com/319330
- New chromium clang rules require explicit external destructors so
system/lib added for MessagePipe, DataPipe and SharedBuffer
- New chromium clang rules require override and no virtual in
declarations, so many files updated.
- cc_strip_video patch updated.
BUG=
R=jamesr@chromium.org
Review URL: https://codereview.chromium.org/988693005
diff --git a/ui/gl/android/surface_texture.cc b/ui/gl/android/surface_texture.cc
index bf9012a..a9f52dc 100644
--- a/ui/gl/android/surface_texture.cc
+++ b/ui/gl/android/surface_texture.cc
@@ -87,19 +87,6 @@
env->ReleaseFloatArrayElements(jmatrix.obj(), elements, JNI_ABORT);
}
-void SurfaceTexture::SetDefaultBufferSize(int width, int height) {
- JNIEnv* env = base::android::AttachCurrentThread();
-
- if (width > 0 && height > 0) {
- Java_SurfaceTexturePlatformWrapper_setDefaultBufferSize(
- env, j_surface_texture_.obj(), static_cast<jint>(width),
- static_cast<jint>(height));
- } else {
- LOG(WARNING) << "Not setting surface texture buffer size - "
- "width or height is 0";
- }
-}
-
void SurfaceTexture::AttachToGLContext() {
if (GlContextMethodsAvailable()) {
int texture_id;
diff --git a/ui/gl/android/surface_texture.h b/ui/gl/android/surface_texture.h
index 05bc5a3..b22e5c4 100644
--- a/ui/gl/android/surface_texture.h
+++ b/ui/gl/android/surface_texture.h
@@ -46,9 +46,6 @@
// texture image set by the most recent call to updateTexImage.
void GetTransformMatrix(float mtx[16]);
- // Set the default size of the image buffers.
- void SetDefaultBufferSize(int width, int height);
-
// Attach the SurfaceTexture to the texture currently bound to
// GL_TEXTURE_EXTERNAL_OES.
void AttachToGLContext();
diff --git a/ui/gl/gl_context_egl.cc b/ui/gl/gl_context_egl.cc
index 5fa2c44..950558b 100644
--- a/ui/gl/gl_context_egl.cc
+++ b/ui/gl/gl_context_egl.cc
@@ -4,6 +4,7 @@
#include "ui/gl/gl_context_egl.h"
+#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/trace_event/trace_event.h"
@@ -38,12 +39,18 @@
DCHECK(compatible_surface);
DCHECK(!context_);
- static const EGLint kContextAttributes[] = {
- EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGLint context_client_version = 2;
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableUnsafeES3APIs)) {
+ context_client_version = 3;
+ }
+
+ const EGLint kContextAttributes[] = {
+ EGL_CONTEXT_CLIENT_VERSION, context_client_version,
EGL_NONE
};
- static const EGLint kContextRobustnessAttributes[] = {
- EGL_CONTEXT_CLIENT_VERSION, 2,
+ const EGLint kContextRobustnessAttributes[] = {
+ EGL_CONTEXT_CLIENT_VERSION, context_client_version,
EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
EGL_LOSE_CONTEXT_ON_RESET_EXT,
EGL_NONE
diff --git a/ui/gl/gl_image_memory.cc b/ui/gl/gl_image_memory.cc
index 6b9a519..ca106b7 100644
--- a/ui/gl/gl_image_memory.cc
+++ b/ui/gl/gl_image_memory.cc
@@ -183,30 +183,6 @@
return false;
}
-// static
-bool GLImageMemory::ValidSize(const gfx::Size& size,
- gfx::GpuMemoryBuffer::Format format) {
- switch (format) {
- case gfx::GpuMemoryBuffer::ATC:
- case gfx::GpuMemoryBuffer::ATCIA:
- case gfx::GpuMemoryBuffer::DXT1:
- case gfx::GpuMemoryBuffer::DXT5:
- case gfx::GpuMemoryBuffer::ETC1:
- // Compressed images must have a width and height that's evenly divisible
- // by the block size.
- return size.width() % 4 == 0 && size.height() % 4 == 0;
- case gfx::GpuMemoryBuffer::RGBA_8888:
- case gfx::GpuMemoryBuffer::BGRA_8888:
- return true;
- case gfx::GpuMemoryBuffer::RGBX_8888:
- NOTREACHED();
- return false;
- }
-
- NOTREACHED();
- return false;
-}
-
bool GLImageMemory::Initialize(const unsigned char* memory,
gfx::GpuMemoryBuffer::Format format) {
if (!ValidInternalFormat(internalformat_)) {
@@ -221,6 +197,8 @@
DCHECK(memory);
DCHECK(!memory_);
+ DCHECK_IMPLIES(IsCompressedFormat(format), size_.width() % 4 == 0);
+ DCHECK_IMPLIES(IsCompressedFormat(format), size_.height() % 4 == 0);
memory_ = memory;
format_ = format;
return true;
diff --git a/ui/gl/gl_image_memory.h b/ui/gl/gl_image_memory.h
index befc3a8..a50a380 100644
--- a/ui/gl/gl_image_memory.h
+++ b/ui/gl/gl_image_memory.h
@@ -26,9 +26,6 @@
gfx::GpuMemoryBuffer::Format format,
size_t* stride_in_bytes);
- static bool ValidSize(const gfx::Size& size,
- gfx::GpuMemoryBuffer::Format format);
-
bool Initialize(const unsigned char* memory,
gfx::GpuMemoryBuffer::Format format);
diff --git a/ui/gl/gl_image_shared_memory.cc b/ui/gl/gl_image_shared_memory.cc
index 363ebf5..d9e31a7 100644
--- a/ui/gl/gl_image_shared_memory.cc
+++ b/ui/gl/gl_image_shared_memory.cc
@@ -18,9 +18,6 @@
if (size.IsEmpty())
return false;
- if (!GLImageMemory::ValidSize(size, format))
- return false;
-
size_t stride_in_bytes = 0;
if (!GLImageMemory::StrideInBytes(size.width(), format, &stride_in_bytes))
return false;
diff --git a/ui/gl/gl_surface.h b/ui/gl/gl_surface.h
index 48d7cd2..da70422 100644
--- a/ui/gl/gl_surface.h
+++ b/ui/gl/gl_surface.h
@@ -156,6 +156,15 @@
static scoped_refptr<GLSurface> CreateViewGLSurface(
gfx::AcceleratedWidget window);
+#if defined(USE_OZONE)
+ // Create a GL surface that renders directly into a window with surfaceless
+ // semantics - there is no default framebuffer and the primary surface must
+ // be presented as an overlay. If surfaceless mode is not supported or
+ // enabled it will return a null pointer.
+ static scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface(
+ gfx::AcceleratedWidget window);
+#endif // defined(USE_OZONE)
+
// Create a GL surface used for offscreen rendering.
static scoped_refptr<GLSurface> CreateOffscreenGLSurface(
const gfx::Size& size);
diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc
index 2dcdc88..61c3c05 100644
--- a/ui/gl/gl_surface_egl.cc
+++ b/ui/gl/gl_surface_egl.cc
@@ -37,6 +37,10 @@
#define EGL_FIXED_SIZE_ANGLE 0x3201
#endif
+#if !defined(EGL_OPENGL_ES3_BIT)
+#define EGL_OPENGL_ES3_BIT 0x00000040
+#endif
+
#if defined(OS_WIN)
// From ANGLE's egl/eglext.h.
@@ -172,13 +176,18 @@
// Choose an EGL configuration.
// On X this is only used for PBuffer surfaces.
- static const EGLint kConfigAttribs[] = {
+ EGLint renderable_type = EGL_OPENGL_ES2_BIT;
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableUnsafeES3APIs)) {
+ renderable_type = EGL_OPENGL_ES3_BIT;
+ }
+ const EGLint kConfigAttribs[] = {
EGL_BUFFER_SIZE, 32,
EGL_ALPHA_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_RENDERABLE_TYPE, renderable_type,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
EGL_NONE
};
diff --git a/ui/gl/gl_surface_ozone.cc b/ui/gl/gl_surface_ozone.cc
index cba706b..47ea8d6 100644
--- a/ui/gl/gl_surface_ozone.cc
+++ b/ui/gl/gl_surface_ozone.cc
@@ -4,16 +4,20 @@
#include "ui/gl/gl_surface.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_image.h"
+#include "ui/gl/gl_image_linux_dma_buffer.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/gl_surface_osmesa.h"
#include "ui/gl/gl_surface_stub.h"
+#include "ui/gl/scoped_binders.h"
#include "ui/gl/scoped_make_current.h"
+#include "ui/ozone/public/native_pixmap.h"
#include "ui/ozone/public/surface_factory_ozone.h"
#include "ui/ozone/public/surface_ozone_egl.h"
@@ -157,15 +161,15 @@
return SwapBuffersAsync(callback);
}
- private:
+ protected:
~GLSurfaceOzoneSurfaceless() override {
Destroy(); // EGL surface must be destroyed before SurfaceOzone
}
bool Flush() {
glFlush();
- // TODO: the following should be replaced by a per surface flush as it gets
- // implemented in GL drivers.
+ // TODO: crbug.com/462360 the following should be replaced by a per surface
+ // flush as it gets implemented in GL drivers.
if (has_implicit_external_sync_) {
const EGLint attrib_list[] = {
EGL_SYNC_CONDITION_KHR,
@@ -182,6 +186,8 @@
} else {
return false;
}
+ } else if (ozone_surface_->IsUniversalDisplayLinkDevice()) {
+ glFinish();
}
return true;
}
@@ -194,6 +200,157 @@
DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless);
};
+// This provides surface-like semantics implemented through surfaceless.
+// A framebuffer is bound automatically.
+class GL_EXPORT GLSurfaceOzoneSurfacelessSurfaceImpl
+ : public GLSurfaceOzoneSurfaceless {
+ public:
+ GLSurfaceOzoneSurfacelessSurfaceImpl(
+ scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface,
+ AcceleratedWidget widget)
+ : GLSurfaceOzoneSurfaceless(ozone_surface.Pass(), widget),
+ fbo_(0),
+ current_surface_(0) {
+ for (auto& texture : textures_)
+ texture = 0;
+ }
+
+ unsigned int GetBackingFrameBufferObject() override { return fbo_; }
+
+ bool OnMakeCurrent(GLContext* context) override {
+ if (!fbo_) {
+ glGenFramebuffersEXT(1, &fbo_);
+ if (!fbo_)
+ return false;
+ glGenTextures(arraysize(textures_), textures_);
+ if (!CreatePixmaps())
+ return false;
+ }
+ BindFramebuffer();
+ glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_);
+ return SurfacelessEGL::OnMakeCurrent(context);
+ }
+
+ bool Resize(const gfx::Size& size) override {
+ if (size == GetSize())
+ return true;
+ return GLSurfaceOzoneSurfaceless::Resize(size) && CreatePixmaps();
+ }
+
+ bool SupportsPostSubBuffer() override { return false; }
+
+ bool SwapBuffers() override {
+ if (!images_[current_surface_]->ScheduleOverlayPlane(
+ widget_, 0, OverlayTransform::OVERLAY_TRANSFORM_NONE,
+ gfx::Rect(GetSize()), gfx::RectF(1, 1)))
+ return false;
+ if (!GLSurfaceOzoneSurfaceless::SwapBuffers())
+ return false;
+ current_surface_ ^= 1;
+ BindFramebuffer();
+ return true;
+ }
+
+ bool SwapBuffersAsync(const SwapCompletionCallback& callback) override {
+ if (!images_[current_surface_]->ScheduleOverlayPlane(
+ widget_, 0, OverlayTransform::OVERLAY_TRANSFORM_NONE,
+ gfx::Rect(GetSize()), gfx::RectF(1, 1)))
+ return false;
+ if (!GLSurfaceOzoneSurfaceless::SwapBuffersAsync(callback))
+ return false;
+ current_surface_ ^= 1;
+ BindFramebuffer();
+ return true;
+ }
+
+ void Destroy() override {
+ GLContext* current_context = GLContext::GetCurrent();
+ DCHECK(current_context && current_context->IsCurrent(this));
+ glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
+ if (fbo_) {
+ glDeleteTextures(arraysize(textures_), textures_);
+ for (auto& texture : textures_)
+ texture = 0;
+ glDeleteFramebuffersEXT(1, &fbo_);
+ fbo_ = 0;
+ }
+ for (auto image : images_) {
+ if (image)
+ image->Destroy(true);
+ }
+ }
+
+ private:
+ class SurfaceImage : public GLImageLinuxDMABuffer {
+ public:
+ SurfaceImage(const gfx::Size& size, unsigned internalformat)
+ : GLImageLinuxDMABuffer(size, internalformat) {}
+
+ bool Initialize(scoped_refptr<ui::NativePixmap> pixmap,
+ gfx::GpuMemoryBuffer::Format format) {
+ base::FileDescriptor handle(pixmap->GetDmaBufFd(), false);
+ if (!GLImageLinuxDMABuffer::Initialize(handle, format,
+ pixmap->GetDmaBufPitch()))
+ return false;
+ pixmap_ = pixmap;
+ return true;
+ }
+ bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+ int z_order,
+ gfx::OverlayTransform transform,
+ const gfx::Rect& bounds_rect,
+ const gfx::RectF& crop_rect) override {
+ return ui::SurfaceFactoryOzone::GetInstance()->ScheduleOverlayPlane(
+ widget, z_order, transform, pixmap_, bounds_rect, crop_rect);
+ }
+
+ private:
+ ~SurfaceImage() override {}
+
+ scoped_refptr<ui::NativePixmap> pixmap_;
+ };
+
+ ~GLSurfaceOzoneSurfacelessSurfaceImpl() override {
+ DCHECK(!fbo_);
+ for (size_t i = 0; i < arraysize(textures_); i++)
+ DCHECK(!textures_[i]) << "texture " << i << " not released";
+ }
+
+ void BindFramebuffer() {
+ ScopedFrameBufferBinder fb(fbo_);
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, textures_[current_surface_], 0);
+ }
+
+ bool CreatePixmaps() {
+ if (!fbo_)
+ return true;
+ for (size_t i = 0; i < arraysize(textures_); i++) {
+ scoped_refptr<ui::NativePixmap> pixmap =
+ ui::SurfaceFactoryOzone::GetInstance()->CreateNativePixmap(
+ widget_, GetSize(), ui::SurfaceFactoryOzone::RGBA_8888,
+ ui::SurfaceFactoryOzone::SCANOUT);
+ if (!pixmap)
+ return false;
+ scoped_refptr<SurfaceImage> image = new SurfaceImage(GetSize(), GL_RGBA);
+ if (!image->Initialize(pixmap, gfx::GpuMemoryBuffer::Format::BGRA_8888))
+ return false;
+ images_[i] = image;
+ // Bind image to texture.
+ ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]);
+ if (!images_[i]->BindTexImage(GL_TEXTURE_2D))
+ return false;
+ }
+ return true;
+ }
+
+ GLuint fbo_;
+ GLuint textures_[2];
+ scoped_refptr<GLImage> images_[2];
+ int current_surface_;
+ DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfacelessSurfaceImpl);
+};
+
} // namespace
// static
@@ -215,6 +372,27 @@
}
// static
+scoped_refptr<GLSurface> GLSurface::CreateSurfacelessViewGLSurface(
+ gfx::AcceleratedWidget window) {
+ if (GetGLImplementation() == kGLImplementationEGLGLES2 &&
+ window != kNullAcceleratedWidget &&
+ GLSurfaceEGL::IsEGLSurfacelessContextSupported() &&
+ ui::SurfaceFactoryOzone::GetInstance()->CanShowPrimaryPlaneAsOverlay()) {
+ scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone =
+ ui::SurfaceFactoryOzone::GetInstance()
+ ->CreateSurfacelessEGLSurfaceForWidget(window);
+ if (!surface_ozone)
+ return nullptr;
+ scoped_refptr<GLSurface> surface;
+ surface = new GLSurfaceOzoneSurfaceless(surface_ozone.Pass(), window);
+ if (surface->Initialize())
+ return surface;
+ }
+
+ return nullptr;
+}
+
+// static
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
gfx::AcceleratedWidget window) {
if (GetGLImplementation() == kGLImplementationOSMesaGL) {
@@ -234,7 +412,8 @@
->CreateSurfacelessEGLSurfaceForWidget(window);
if (!surface_ozone)
return NULL;
- surface = new GLSurfaceOzoneSurfaceless(surface_ozone.Pass(), window);
+ surface = new GLSurfaceOzoneSurfacelessSurfaceImpl(surface_ozone.Pass(),
+ window);
} else {
scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone =
ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget(
diff --git a/ui/gl/gl_switches.cc b/ui/gl/gl_switches.cc
index 479ff69..8817156 100644
--- a/ui/gl/gl_switches.cc
+++ b/ui/gl/gl_switches.cc
@@ -58,6 +58,9 @@
// On Windows only: use the WARP software rasterizer in the GPU process.
const char kUseWarp[] = "use-warp";
+// Enable OpenGL ES 3 APIs without proper service side validation.
+const char kEnableUnsafeES3APIs[] = "enable-unsafe-es3-apis";
+
// Disables GL drawing operations which produce pixel output. With this
// the GL output will not be correct but tests will run faster.
const char kDisableGLDrawingForTests[] = "disable-gl-drawing-for-tests";
@@ -74,6 +77,7 @@
kDisableD3D11,
kEnableGPUServiceLogging,
kEnableGPUServiceTracing,
+ kEnableUnsafeES3APIs,
kGpuNoContextLost,
kDisableGLDrawingForTests,
kOverrideUseGLWithOSMesaForTests,
diff --git a/ui/gl/gl_switches.h b/ui/gl/gl_switches.h
index ce27df0..0715ad9 100644
--- a/ui/gl/gl_switches.h
+++ b/ui/gl/gl_switches.h
@@ -36,6 +36,7 @@
GL_EXPORT extern const char kTestGLLib[];
GL_EXPORT extern const char kUseGpuInTests[];
GL_EXPORT extern const char kUseWarp[];
+GL_EXPORT extern const char kEnableUnsafeES3APIs[];
// These flags are used by the test harness code, not passed in by users.
GL_EXPORT extern const char kDisableGLDrawingForTests[];
diff --git a/ui/gl/gpu_timing.cc b/ui/gl/gpu_timing.cc
index 22a4a64..a3b697f 100644
--- a/ui/gl/gpu_timing.cc
+++ b/ui/gl/gpu_timing.cc
@@ -30,6 +30,17 @@
return new GPUTimingClient(this);
}
+uint32_t GPUTiming::GetDisjointCount() {
+ if (timer_type_ == kTimerTypeDisjoint) {
+ GLint disjoint_value = 0;
+ glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value);
+ if (disjoint_value) {
+ disjoint_counter_++;
+ }
+ }
+ return disjoint_counter_;
+}
+
GPUTimer::~GPUTimer() {
glDeleteQueriesARB(2, queries_);
}
@@ -87,6 +98,7 @@
: gpu_timing_(gpu_timing) {
if (gpu_timing) {
timer_type_ = gpu_timing->GetTimerType();
+ disjoint_counter_ = gpu_timing_->GetDisjointCount();
}
}
@@ -111,12 +123,13 @@
bool GPUTimingClient::CheckAndResetTimerErrors() {
if (timer_type_ == GPUTiming::kTimerTypeDisjoint) {
- GLint disjoint_value = 0;
- glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value);
- return disjoint_value != 0;
- } else {
- return false;
+ DCHECK(gpu_timing_ != nullptr);
+ const uint32_t total_disjoint_count = gpu_timing_->GetDisjointCount();
+ const bool disjoint_triggered = total_disjoint_count != disjoint_counter_;
+ disjoint_counter_ = total_disjoint_count;
+ return disjoint_triggered;
}
+ return false;
}
int64 GPUTimingClient::CalculateTimerOffset() {
diff --git a/ui/gl/gpu_timing.h b/ui/gl/gpu_timing.h
index 9702fe1..1c8f8cf 100644
--- a/ui/gl/gpu_timing.h
+++ b/ui/gl/gpu_timing.h
@@ -52,6 +52,7 @@
};
TimerType GetTimerType() const { return timer_type_; }
+ uint32_t GetDisjointCount();
private:
friend struct base::DefaultDeleter<GPUTiming>;
@@ -62,6 +63,7 @@
scoped_refptr<GPUTimingClient> CreateGPUTimingClient();
TimerType timer_type_ = kTimerTypeInvalid;
+ uint32_t disjoint_counter_ = 0;
DISALLOW_COPY_AND_ASSIGN(GPUTiming);
};
@@ -125,6 +127,7 @@
GPUTiming* gpu_timing_;
GPUTiming::TimerType timer_type_ = GPUTiming::kTimerTypeInvalid;
int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB
+ uint32_t disjoint_counter_ = 0;
bool offset_valid_ = false;
base::Callback<int64(void)> cpu_time_for_testing_;