summaryrefslogtreecommitdiffstats
path: root/ui/gl/gl_surface_mac.cc
diff options
context:
space:
mode:
authorccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-18 07:30:37 +0000
committerccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-18 07:30:37 +0000
commita187cf51deb0f5c8dd345d8ee3352adc6e36711f (patch)
tree21e4847418a485f5767eea335a0bcd6daf16aef7 /ui/gl/gl_surface_mac.cc
parent306f10df04bc7f153c7ac29cb49d7a269eb865ae (diff)
downloadchromium_src-a187cf51deb0f5c8dd345d8ee3352adc6e36711f.zip
chromium_src-a187cf51deb0f5c8dd345d8ee3352adc6e36711f.tar.gz
chromium_src-a187cf51deb0f5c8dd345d8ee3352adc6e36711f.tar.bz2
Clean up GLSurfaceCGL
This is in preparation for support for using remote CALayers. The big change is to separate out ImageTransportSurfaceIOSurface into ImageTransportSurfaceFBO and its StorageProvider. The IOSurface- specific bits of ImageTransportSurfaceIOSurface are moved into the StorageProvider. A separate CALayer-specific version will be added later. While in the neighborhood, don't make everything inherit from GLSurfaceCGL (that class doesn't actually do anything). Move the helper functions and classes from its file to more appropriate locations. Make image_transport_surface_mac.cc a .mm file, because it will need to include Objective C code in the near future. Move the ImageTransportSurfaceFBO into its own file. Also make the IOSurface handles in renderer_host use the 32-bit IOSurfaceID handle type instead of uint64, since that is the type actually used by the interface, and those other bits may find use in disambiguating handle types. BUG=312462 Review URL: https://codereview.chromium.org/334173006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277970 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gl/gl_surface_mac.cc')
-rw-r--r--ui/gl/gl_surface_mac.cc83
1 files changed, 80 insertions, 3 deletions
diff --git a/ui/gl/gl_surface_mac.cc b/ui/gl/gl_surface_mac.cc
index cd93cb0..dd5fa0e 100644
--- a/ui/gl/gl_surface_mac.cc
+++ b/ui/gl/gl_surface_mac.cc
@@ -4,23 +4,100 @@
#include "ui/gl/gl_surface.h"
+#include <OpenGL/CGLRenderers.h>
+
+#include "base/basictypes.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
+#include "base/mac/mac_util.h"
#include "base/memory/scoped_ptr.h"
#include "third_party/mesa/src/include/GL/osmesa.h"
#include "ui/gl/gl_bindings.h"
+#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
-#include "ui/gl/gl_surface_cgl.h"
#include "ui/gl/gl_surface_osmesa.h"
#include "ui/gl/gl_surface_stub.h"
+#include "ui/gl/gpu_switching_manager.h"
namespace gfx {
+namespace {
+
+// A "no-op" surface. It is not required that a CGLContextObj have an
+// associated drawable (pbuffer or fullscreen context) in order to be
+// made current. Everywhere this surface type is used, we allocate an
+// FBO at the user level as the drawable of the associated context.
+class GL_EXPORT NoOpGLSurface : public GLSurface {
+ public:
+ explicit NoOpGLSurface(const gfx::Size& size) : size_(size) {}
+
+ // Implement GLSurface.
+ virtual bool Initialize() OVERRIDE { return true; }
+ virtual void Destroy() OVERRIDE {}
+ virtual bool IsOffscreen() OVERRIDE { return true; }
+ virtual bool SwapBuffers() OVERRIDE {
+ NOTREACHED() << "Cannot call SwapBuffers on a NoOpGLSurface.";
+ return false;
+ }
+ virtual gfx::Size GetSize() OVERRIDE { return size_; }
+ virtual void* GetHandle() OVERRIDE { return NULL; }
+ virtual void* GetDisplay() OVERRIDE { return NULL; }
+
+ protected:
+ virtual ~NoOpGLSurface() {}
+
+ private:
+ gfx::Size size_;
+
+ DISALLOW_COPY_AND_ASSIGN(NoOpGLSurface);
+};
+
+// static
+bool InitializeOneOffForSandbox() {
+ static bool initialized = false;
+ if (initialized)
+ return true;
+
+ // This is called from the sandbox warmup code on Mac OS X.
+ // GPU-related stuff is very slow without this, probably because
+ // the sandbox prevents loading graphics drivers or some such.
+ std::vector<CGLPixelFormatAttribute> attribs;
+ if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) {
+ // Avoid switching to the discrete GPU just for this pixel
+ // format selection.
+ attribs.push_back(kCGLPFAAllowOfflineRenderers);
+ }
+ if (GetGLImplementation() == kGLImplementationAppleGL) {
+ attribs.push_back(kCGLPFARendererID);
+ attribs.push_back(static_cast<CGLPixelFormatAttribute>(
+ kCGLRendererGenericFloatID));
+ }
+ attribs.push_back(static_cast<CGLPixelFormatAttribute>(0));
+
+ CGLPixelFormatObj format;
+ GLint num_pixel_formats;
+ if (CGLChoosePixelFormat(&attribs.front(),
+ &format,
+ &num_pixel_formats) != kCGLNoError) {
+ LOG(ERROR) << "Error choosing pixel format.";
+ return false;
+ }
+ if (!format) {
+ LOG(ERROR) << "format == 0.";
+ return false;
+ }
+ CGLReleasePixelFormat(format);
+ DCHECK_NE(num_pixel_formats, 0);
+ initialized = true;
+ return true;
+}
+
+} // namespace
bool GLSurface::InitializeOneOffInternal() {
switch (GetGLImplementation()) {
case kGLImplementationDesktopGL:
case kGLImplementationAppleGL:
- if (!GLSurfaceCGL::InitializeOneOff()) {
+ if (!InitializeOneOffForSandbox()) {
LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
return false;
}
@@ -62,7 +139,7 @@ scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
}
case kGLImplementationDesktopGL:
case kGLImplementationAppleGL: {
- scoped_refptr<GLSurface> surface(new NoOpGLSurfaceCGL(size));
+ scoped_refptr<GLSurface> surface(new NoOpGLSurface(size));
if (!surface->Initialize())
return NULL;