| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 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 #ifndef CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_CONTEXT_MAC_H_ | |
| 6 #define CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_CONTEXT_MAC_H_ | |
| 7 | |
| 8 #include <OpenGL/OpenGL.h> | |
| 9 #include <map> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/lazy_instance.h" | |
| 13 #include "base/mac/scoped_nsobject.h" | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "ui/gl/gpu_switching_observer.h" | |
| 17 #include "ui/gl/scoped_cgl.h" | |
| 18 | |
| 19 namespace content { | |
| 20 | |
| 21 class IOSurfaceContext | |
| 22 : public base::RefCounted<IOSurfaceContext>, | |
| 23 public ui::GpuSwitchingObserver { | |
| 24 public: | |
| 25 enum Type { | |
| 26 // The number used to look up the context used for async readback and for | |
| 27 // initializing the IOSurface. | |
| 28 kOffscreenContext = -2, | |
| 29 // The number used to look up the context used by CAOpenGLLayers. | |
| 30 kCALayerContext = -3, | |
| 31 }; | |
| 32 | |
| 33 // Get or create a GL context of the specified type. Share these GL contexts | |
| 34 // as much as possible because creating and destroying them can be expensive. | |
| 35 // http://crbug.com/180463 | |
| 36 static scoped_refptr<IOSurfaceContext> Get(Type type); | |
| 37 | |
| 38 // Mark that all the GL contexts in the same sharegroup as this context as | |
| 39 // invalid, so they shouldn't be returned anymore by Get, but rather, new | |
| 40 // contexts should be created. This is called as a precaution when unexpected | |
| 41 // GL errors occur, or after a GPU switch. | |
| 42 void PoisonContextAndSharegroup(); | |
| 43 bool HasBeenPoisoned() const { return poisoned_; } | |
| 44 | |
| 45 CGLContextObj cgl_context() const { return cgl_context_; } | |
| 46 | |
| 47 // content::GpuDataManagerObserver implementation. | |
| 48 void OnGpuSwitched() override; | |
| 49 | |
| 50 private: | |
| 51 friend class base::RefCounted<IOSurfaceContext>; | |
| 52 | |
| 53 IOSurfaceContext( | |
| 54 Type type, | |
| 55 base::ScopedTypeRef<CGLContextObj> clg_context_strong); | |
| 56 virtual ~IOSurfaceContext(); | |
| 57 | |
| 58 Type type_; | |
| 59 base::ScopedTypeRef<CGLContextObj> cgl_context_; | |
| 60 | |
| 61 bool poisoned_; | |
| 62 | |
| 63 // The global map from window number and window ordering to | |
| 64 // context data. | |
| 65 typedef std::map<Type, IOSurfaceContext*> TypeMap; | |
| 66 static base::LazyInstance<TypeMap> type_map_; | |
| 67 static TypeMap* type_map(); | |
| 68 }; | |
| 69 | |
| 70 } // namespace content | |
| 71 | |
| 72 #endif // CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_CONTEXT_MAC_H_ | |
| OLD | NEW |