| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/gl/gl_surface.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/trace_event/trace_event.h" | |
| 12 #include "ui/gl/gl_bindings.h" | |
| 13 #include "ui/gl/gl_context.h" | |
| 14 #include "ui/gl/gl_export.h" | |
| 15 #include "ui/gl/gl_implementation.h" | |
| 16 #include "ui/gl/gl_surface_osmesa.h" | |
| 17 #include "ui/gl/gl_surface_stub.h" | |
| 18 | |
| 19 namespace gl { | |
| 20 namespace { | |
| 21 | |
| 22 // A "no-op" surface. It is not required that a CGLContextObj have an | |
| 23 // associated drawable (pbuffer or fullscreen context) in order to be | |
| 24 // made current. Everywhere this surface type is used, we allocate an | |
| 25 // FBO at the user level as the drawable of the associated context. | |
| 26 class GL_EXPORT NoOpGLSurface : public GLSurface { | |
| 27 public: | |
| 28 explicit NoOpGLSurface(const gfx::Size& size) : size_(size) {} | |
| 29 | |
| 30 // Implement GLSurface. | |
| 31 bool Initialize(GLSurface::Format format) override { return true; } | |
| 32 void Destroy() override {} | |
| 33 bool IsOffscreen() override { return true; } | |
| 34 gfx::SwapResult SwapBuffers() override { | |
| 35 NOTREACHED() << "Cannot call SwapBuffers on a NoOpGLSurface."; | |
| 36 return gfx::SwapResult::SWAP_FAILED; | |
| 37 } | |
| 38 gfx::Size GetSize() override { return size_; } | |
| 39 void* GetHandle() override { return NULL; } | |
| 40 void* GetDisplay() override { return NULL; } | |
| 41 bool IsSurfaceless() const override { return true; } | |
| 42 | |
| 43 protected: | |
| 44 ~NoOpGLSurface() override {} | |
| 45 | |
| 46 private: | |
| 47 gfx::Size size_; | |
| 48 | |
| 49 DISALLOW_COPY_AND_ASSIGN(NoOpGLSurface); | |
| 50 }; | |
| 51 | |
| 52 } // namespace | |
| 53 | |
| 54 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | |
| 55 gfx::AcceleratedWidget window) { | |
| 56 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); | |
| 57 switch (GetGLImplementation()) { | |
| 58 case kGLImplementationDesktopGL: | |
| 59 case kGLImplementationDesktopGLCoreProfile: | |
| 60 case kGLImplementationAppleGL: { | |
| 61 NOTIMPLEMENTED() << "No onscreen support on Mac."; | |
| 62 return NULL; | |
| 63 } | |
| 64 case kGLImplementationOSMesaGL: { | |
| 65 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | |
| 66 if (!surface->Initialize()) | |
| 67 return NULL; | |
| 68 return surface; | |
| 69 } | |
| 70 case kGLImplementationMockGL: | |
| 71 return new GLSurfaceStub; | |
| 72 default: | |
| 73 NOTREACHED(); | |
| 74 return NULL; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( | |
| 79 const gfx::Size& size) { | |
| 80 TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface"); | |
| 81 switch (GetGLImplementation()) { | |
| 82 case kGLImplementationOSMesaGL: { | |
| 83 scoped_refptr<GLSurface> surface( | |
| 84 new GLSurfaceOSMesa(SURFACE_OSMESA_RGBA, size)); | |
| 85 if (!surface->Initialize()) | |
| 86 return NULL; | |
| 87 | |
| 88 return surface; | |
| 89 } | |
| 90 case kGLImplementationDesktopGL: | |
| 91 case kGLImplementationDesktopGLCoreProfile: | |
| 92 case kGLImplementationAppleGL: { | |
| 93 scoped_refptr<GLSurface> surface(new NoOpGLSurface(size)); | |
| 94 if (!surface->Initialize()) | |
| 95 return NULL; | |
| 96 | |
| 97 return surface; | |
| 98 } | |
| 99 case kGLImplementationMockGL: | |
| 100 return new GLSurfaceStub; | |
| 101 default: | |
| 102 NOTREACHED(); | |
| 103 return NULL; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 } // namespace gl | |
| OLD | NEW |