gl_share_group.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2012 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. #include "ui/gl/gl_share_group.h"
  5. #include "base/check.h"
  6. #include "build/build_config.h"
  7. #include "ui/gl/gl_context.h"
  8. #include "ui/gl/gl_implementation.h"
  9. namespace gl {
  10. GLShareGroup::GLShareGroup()
  11. #if BUILDFLAG(IS_APPLE)
  12. : renderer_id_(-1)
  13. #endif
  14. {
  15. }
  16. void GLShareGroup::AddContext(GLContext* context) {
  17. contexts_.insert(context);
  18. }
  19. void GLShareGroup::RemoveContext(GLContext* context) {
  20. contexts_.erase(context);
  21. if (shared_context_ == context)
  22. shared_context_ = nullptr;
  23. }
  24. void* GLShareGroup::GetHandle() {
  25. GLContext* context = GetContext();
  26. if (context)
  27. return context->GetHandle();
  28. return NULL;
  29. }
  30. GLContext* GLShareGroup::GetContext() {
  31. for (auto it = contexts_.begin(); it != contexts_.end(); ++it) {
  32. if ((*it)->GetHandle())
  33. return *it;
  34. }
  35. return NULL;
  36. }
  37. void GLShareGroup::SetSharedContext(GLContext* context) {
  38. DCHECK(contexts_.find(context) != contexts_.end());
  39. shared_context_ = context;
  40. }
  41. #if BUILDFLAG(IS_APPLE)
  42. void GLShareGroup::SetRendererID(int renderer_id) {
  43. renderer_id_ = renderer_id;
  44. }
  45. int GLShareGroup::GetRendererID() {
  46. return renderer_id_;
  47. }
  48. #endif
  49. GLShareGroup::~GLShareGroup() {
  50. }
  51. } // namespace gl