Remove APIPermission::kFileSystemWriteDirectory
[chromium-blink-merge.git] / ui / accelerated_widget_mac / io_surface_context.h
blobbf2b25471136398b619b7e9452d1d1226ae38cdc
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.
5 #ifndef UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_CONTEXT_H_
6 #define UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_CONTEXT_H_
8 #include <OpenGL/OpenGL.h>
9 #include <map>
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/accelerated_widget_mac/accelerated_widget_mac_export.h"
17 #include "ui/gl/gpu_switching_observer.h"
18 #include "ui/gl/scoped_cgl.h"
20 namespace ui {
22 class IOSurfaceContext
23 : public base::RefCounted<IOSurfaceContext>,
24 public ui::GpuSwitchingObserver {
25 public:
26 enum Type {
27 // The number used to look up the context used for async readback and for
28 // initializing the IOSurface.
29 kOffscreenContext = -2,
30 // The number used to look up the context used by CAOpenGLLayers.
31 kCALayerContext = -3,
34 // Get or create a GL context of the specified type. Share these GL contexts
35 // as much as possible because creating and destroying them can be expensive.
36 // http://crbug.com/180463
37 ACCELERATED_WIDGET_MAC_EXPORT static scoped_refptr<IOSurfaceContext> Get(
38 Type type);
40 // Mark that all the GL contexts in the same sharegroup as this context as
41 // invalid, so they shouldn't be returned anymore by Get, but rather, new
42 // contexts should be created. This is called as a precaution when unexpected
43 // GL errors occur, or after a GPU switch.
44 void PoisonContextAndSharegroup();
45 bool HasBeenPoisoned() const { return poisoned_; }
47 CGLContextObj cgl_context() const { return cgl_context_; }
49 // ui::GpuSwitchingObserver implementation.
50 void OnGpuSwitched() override;
52 private:
53 friend class base::RefCounted<IOSurfaceContext>;
55 IOSurfaceContext(
56 Type type,
57 base::ScopedTypeRef<CGLContextObj> clg_context_strong);
58 virtual ~IOSurfaceContext();
60 Type type_;
61 base::ScopedTypeRef<CGLContextObj> cgl_context_;
63 bool poisoned_;
65 // The global map from window number and window ordering to
66 // context data.
67 typedef std::map<Type, IOSurfaceContext*> TypeMap;
68 static base::LazyInstance<TypeMap> type_map_;
69 static TypeMap* type_map();
72 } // namespace ui
74 #endif // UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_CONTEXT_H_