io_surface_context.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #ifndef UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_CONTEXT_H_
  5. #define UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_CONTEXT_H_
  6. #include <OpenGL/OpenGL.h>
  7. #include "base/mac/scoped_nsobject.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h"
  10. #include "ui/gl/gpu_switching_observer.h"
  11. #include "ui/gl/scoped_cgl.h"
  12. namespace ui {
  13. class IOSurfaceContext
  14. : public base::RefCounted<IOSurfaceContext>,
  15. public ui::GpuSwitchingObserver {
  16. public:
  17. enum Type {
  18. // The number used to look up the context used for async readback and for
  19. // initializing the IOSurface.
  20. kOffscreenContext = -2,
  21. // The number used to look up the context used by CAOpenGLLayers.
  22. kCALayerContext = -3,
  23. };
  24. // Get or create a GL context of the specified type. Share these GL contexts
  25. // as much as possible because creating and destroying them can be expensive.
  26. // http://crbug.com/180463
  27. ACCELERATED_WIDGET_MAC_EXPORT static scoped_refptr<IOSurfaceContext> Get(
  28. Type type);
  29. // Mark that all the GL contexts in the same sharegroup as this context as
  30. // invalid, so they shouldn't be returned anymore by Get, but rather, new
  31. // contexts should be created. This is called as a precaution when unexpected
  32. // GL errors occur, or after a GPU switch.
  33. void PoisonContextAndSharegroup();
  34. bool HasBeenPoisoned() const { return poisoned_; }
  35. CGLContextObj cgl_context() const { return cgl_context_; }
  36. // ui::GpuSwitchingObserver implementation.
  37. void OnGpuSwitched(gl::GpuPreference active_gpu_heuristic) override;
  38. private:
  39. friend class base::RefCounted<IOSurfaceContext>;
  40. IOSurfaceContext(
  41. Type type,
  42. base::ScopedTypeRef<CGLContextObj> clg_context_strong);
  43. ~IOSurfaceContext() override;
  44. Type type_;
  45. base::ScopedTypeRef<CGLContextObj> cgl_context_;
  46. bool poisoned_;
  47. };
  48. } // namespace ui
  49. #endif // UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_CONTEXT_H_