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

Side by Side Diff: ui/gl/gl_share_group.cc

Issue 1652873002: Android: Use virtualized context only for those with compatible config (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "ui/gl/gl_share_group.h" 5 #include "ui/gl/gl_share_group.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "ui/gl/gl_context.h" 9 #include "ui/gl/gl_context.h"
10 10
11 namespace gfx { 11 namespace gfx {
12 12
13 GLShareGroup::GLShareGroup() 13 GLShareGroup::GLShareGroup()
14 : shared_context_(NULL) 14 : shared_contexts_(
15 make_scoped_ptr(new std::map<GLSurface::Format,
16 scoped_refptr<GLContext>>())),
17 active_context_(nullptr),
18 format_(GLSurface::GetDefaultFormat())
15 #if defined(OS_MACOSX) 19 #if defined(OS_MACOSX)
16 , renderer_id_(-1) 20 , renderer_id_(-1)
17 #endif 21 #endif
18 { 22 {
19 } 23 }
20 24
21 void GLShareGroup::AddContext(GLContext* context) { 25 void GLShareGroup::AddContext(GLContext* context) {
22 contexts_.insert(context); 26 contexts_.insert(context);
23 } 27 }
24 28
25 void GLShareGroup::RemoveContext(GLContext* context) { 29 void GLShareGroup::RemoveContext(GLContext* context) {
26 contexts_.erase(context); 30 contexts_.erase(context);
27 if (shared_context_ == context)
28 shared_context_ = NULL;
29 } 31 }
30 32
31 void* GLShareGroup::GetHandle() { 33 void* GLShareGroup::GetHandle() {
32 GLContext* context = GetContext(); 34 GLContext* context = GetContext();
33 if (context) 35 if (context)
34 return context->GetHandle(); 36 return context->GetHandle();
35 37
36 return NULL; 38 return NULL;
37 } 39 }
38 40
39 GLContext* GLShareGroup::GetContext() { 41 GLContext* GLShareGroup::GetContext() {
40 for (ContextSet::iterator it = contexts_.begin(); 42 for (auto context : contexts_) {
41 it != contexts_.end(); 43 if (context->GetFormat() == format_ && context->GetHandle())
42 ++it) { 44 return context;
43 if ((*it)->GetHandle())
44 return *it;
45 } 45 }
46 46
47 return NULL; 47 return NULL;
48 } 48 }
49 49
50 void GLShareGroup::SetSharedContext(GLContext* context) { 50 void GLShareGroup::UpdateActiveSharedContext(GLSurface* surface,
51 DCHECK(contexts_.find(context) != contexts_.end()); 51 GpuPreference preference) {
52 shared_context_ = context; 52 GLSurface::Format format = surface->GetFormat();
53 scoped_refptr<GLContext> context;
54 auto it = shared_contexts_->find(format);
55 if (it == shared_contexts_->end()) {
56 // The shared context with the matched config not found. Create a new one.
57 context = GLContext::CreateGLContext(this, surface, preference);
58 if (context.get()) {
59 shared_contexts_->insert({format, context});
60 } else {
61 LOG(ERROR) << "Failed to create GLContext.";
62 return;
63 }
64 } else {
65 context = it->second;
66 }
67 active_context_ = context.get();
53 } 68 }
54 69
55 GLContext* GLShareGroup::GetSharedContext() { 70 GLContext* GLShareGroup::GetSharedContext() {
56 return shared_context_; 71 return active_context_;
57 } 72 }
58 73
59 #if defined(OS_MACOSX) 74 #if defined(OS_MACOSX)
60 void GLShareGroup::SetRendererID(int renderer_id) { 75 void GLShareGroup::SetRendererID(int renderer_id) {
61 renderer_id_ = renderer_id; 76 renderer_id_ = renderer_id;
62 } 77 }
63 78
64 int GLShareGroup::GetRendererID() { 79 int GLShareGroup::GetRendererID() {
65 return renderer_id_; 80 return renderer_id_;
66 } 81 }
67 #endif 82 #endif
68 83
69 GLShareGroup::~GLShareGroup() { 84 GLShareGroup::~GLShareGroup() {
70 } 85 }
71 86
72 } // namespace gfx 87 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698