Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: content/browser/compositor/io_surface_context_mac.h

Issue 647553002: Revert of Use a single CGLContextObj to draw and update the IOSurface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/compositor/io_surface_context_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_CONTEXT_MAC_H_ 5 #ifndef CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_CONTEXT_MAC_H_
6 #define CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_CONTEXT_MAC_H_ 6 #define CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_CONTEXT_MAC_H_
7 7
8 #include <OpenGL/OpenGL.h> 8 #include <OpenGL/OpenGL.h>
9 #include <map> 9 #include <map>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/mac/scoped_nsobject.h" 13 #include "base/mac/scoped_nsobject.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "content/public/browser/gpu_data_manager_observer.h" 16 #include "content/public/browser/gpu_data_manager_observer.h"
17 #include "ui/gl/scoped_cgl.h" 17 #include "ui/gl/scoped_cgl.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 // The CGL context used to update and draw an IOSurface-backed texture. If an
22 // error occurs on this context, or if the current GPU changes, then the
23 // context is poisoned, and a new one is created.
24 class IOSurfaceContext 21 class IOSurfaceContext
25 : public base::RefCounted<IOSurfaceContext>, 22 : public base::RefCounted<IOSurfaceContext>,
26 public content::GpuDataManagerObserver { 23 public content::GpuDataManagerObserver {
27 public: 24 public:
28 // Get or create a GL context. Share these GL contexts as much as possible 25 enum Type {
29 // because creating and destroying them can be expensive. 26 // The number used to look up the context used for async readback and for
30 static scoped_refptr<IOSurfaceContext> Get(); 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);
31 37
32 // Mark that all the GL contexts in the same sharegroup as this context as 38 // Mark that all the GL contexts in the same sharegroup as this context as
33 // invalid, so they shouldn't be returned anymore by Get, but rather, new 39 // invalid, so they shouldn't be returned anymore by Get, but rather, new
34 // contexts should be created. This is called as a precaution when unexpected 40 // contexts should be created. This is called as a precaution when unexpected
35 // GL errors occur, or after a GPU switch. 41 // GL errors occur, or after a GPU switch.
36 void PoisonContextAndSharegroup(); 42 void PoisonContextAndSharegroup();
37 bool HasBeenPoisoned() const { return poisoned_; } 43 bool HasBeenPoisoned() const { return poisoned_; }
38 44
39 CGLContextObj cgl_context() const { return cgl_context_; } 45 CGLContextObj cgl_context() const { return cgl_context_; }
40 46
41 // content::GpuDataManagerObserver implementation. 47 // content::GpuDataManagerObserver implementation.
42 virtual void OnGpuSwitching() override; 48 virtual void OnGpuSwitching() override;
43 49
44 private: 50 private:
45 friend class base::RefCounted<IOSurfaceContext>; 51 friend class base::RefCounted<IOSurfaceContext>;
46 52
47 IOSurfaceContext(base::ScopedTypeRef<CGLContextObj> clg_context_strong); 53 IOSurfaceContext(
54 Type type,
55 base::ScopedTypeRef<CGLContextObj> clg_context_strong);
48 virtual ~IOSurfaceContext(); 56 virtual ~IOSurfaceContext();
49 57
58 Type type_;
50 base::ScopedTypeRef<CGLContextObj> cgl_context_; 59 base::ScopedTypeRef<CGLContextObj> cgl_context_;
60
51 bool poisoned_; 61 bool poisoned_;
52 62
53 // The current non-poisoned context, shared by all layers. 63 // The global map from window number and window ordering to
54 static IOSurfaceContext* current_context_; 64 // context data.
65 typedef std::map<Type, IOSurfaceContext*> TypeMap;
66 static base::LazyInstance<TypeMap> type_map_;
67 static TypeMap* type_map();
55 }; 68 };
56 69
57 } // namespace content 70 } // namespace content
58 71
59 #endif // CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_CONTEXT_MAC_H_ 72 #endif // CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_CONTEXT_MAC_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/compositor/io_surface_context_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698