IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / renderer_host / compositing_iosurface_context_mac.h
blobda9fc44597d9278decfc98335f085854e440b3e2
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 CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_
8 #import <AppKit/NSOpenGL.h>
9 #include <OpenGL/OpenGL.h>
10 #include <map>
12 #include "base/basictypes.h"
13 #include "base/lazy_instance.h"
14 #include "base/mac/scoped_nsobject.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
18 namespace content {
20 class CompositingIOSurfaceShaderPrograms;
22 class CompositingIOSurfaceContext
23 : public base::RefCounted<CompositingIOSurfaceContext> {
24 public:
25 enum { kOffscreenContextWindowNumber = -2 };
27 // Get or create a GL context for the specified window with the specified
28 // surface ordering. Share these GL contexts as much as possible because
29 // creating and destroying them can be expensive
30 // http://crbug.com/180463
31 static scoped_refptr<CompositingIOSurfaceContext> Get(int window_number);
33 // Mark that all the currently existing GL contexts shouldn't be returned
34 // anymore by Get, but rather, new contexts should be created. This is
35 // called as a precaution when unexpected GL errors occur.
36 static void MarkExistingContextsAsNotShareable();
38 CompositingIOSurfaceShaderPrograms* shader_program_cache() const {
39 return shader_program_cache_.get();
41 NSOpenGLContext* nsgl_context() const { return nsgl_context_; }
42 CGLContextObj cgl_context() const { return cgl_context_; }
43 bool is_vsync_disabled() const { return is_vsync_disabled_; }
44 int window_number() const { return window_number_; }
46 bool IsVendorIntel();
48 private:
49 friend class base::RefCounted<CompositingIOSurfaceContext>;
51 CompositingIOSurfaceContext(
52 int window_number,
53 NSOpenGLContext* nsgl_context,
54 CGLContextObj clg_context,
55 bool is_vsync_disabled_,
56 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache);
57 ~CompositingIOSurfaceContext();
59 int window_number_;
60 base::scoped_nsobject<NSOpenGLContext> nsgl_context_;
61 CGLContextObj cgl_context_; // weak, backed by |nsgl_context_|
62 bool is_vsync_disabled_;
63 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache_;
64 bool can_be_shared_;
66 bool initialized_is_intel_;
67 bool is_intel_;
68 GLint screen_;
70 // The global map from window number and window ordering to
71 // context data.
72 typedef std::map<int, CompositingIOSurfaceContext*> WindowMap;
73 static base::LazyInstance<WindowMap> window_map_;
74 static WindowMap* window_map();
77 } // namespace content
79 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_