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

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

Issue 197563003: gpu: Allow fences to check whether a flush has occurred (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
11 #include "ui/gl/gl_bindings.h" 11 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_context.h" 12 #include "ui/gl/gl_context.h"
13 #include "ui/gl/gl_gl_api_implementation.h" 13 #include "ui/gl/gl_gl_api_implementation.h"
14 #include "ui/gl/gl_implementation.h" 14 #include "ui/gl/gl_implementation.h"
15 #include "ui/gl/gl_surface.h" 15 #include "ui/gl/gl_surface.h"
16 #include "ui/gl/gl_switches.h" 16 #include "ui/gl/gl_switches.h"
17 #include "ui/gl/gl_version_info.h" 17 #include "ui/gl/gl_version_info.h"
18 18
19 namespace gfx { 19 namespace gfx {
20 20
21 namespace { 21 namespace {
22 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky 22 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky
23 current_context_ = LAZY_INSTANCE_INITIALIZER; 23 current_context_ = LAZY_INSTANCE_INITIALIZER;
24 24
25 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky 25 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky
26 current_real_context_ = LAZY_INSTANCE_INITIALIZER; 26 current_real_context_ = LAZY_INSTANCE_INITIALIZER;
27 } // namespace 27 } // namespace
28 28
29 GLContext::FlushEvent::FlushEvent() : state_(0) {
30 }
31
32 GLContext::FlushEvent::~FlushEvent() {
33 }
34
35 void GLContext::FlushEvent::Signal() {
36 base::subtle::NoBarrier_AtomicExchange(&state_, 1);
piman 2014/03/15 00:18:40 I'm not convinced whether this is correct or not.
no sievers 2014/03/19 01:25:21 Done.
37 }
38
39 bool GLContext::FlushEvent::IsSignaled() {
40 return base::subtle::NoBarrier_CompareAndSwap(&state_, 1, 1) != 0;
41 }
42
29 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) { 43 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) {
30 if (!share_group_.get()) 44 if (!share_group_.get())
31 share_group_ = new GLShareGroup; 45 share_group_ = new GLShareGroup;
32 46
33 share_group_->AddContext(this); 47 share_group_->AddContext(this);
34 } 48 }
35 49
36 GLContext::~GLContext() { 50 GLContext::~GLContext() {
37 share_group_->RemoveContext(this); 51 share_group_->RemoveContext(this);
38 if (GetCurrent() == this) { 52 if (GetCurrent() == this) {
39 SetCurrent(NULL); 53 SetCurrent(NULL);
40 } 54 }
41 } 55 }
42 56
57 scoped_refptr<GLContext::FlushEvent>
58 GLContext::SignalFlush() {
59 scoped_refptr<FlushEvent> flush_event = new FlushEvent();
60 flush_events_.push_back(flush_event);
61 return flush_event;
62 }
63
43 bool GLContext::GetTotalGpuMemory(size_t* bytes) { 64 bool GLContext::GetTotalGpuMemory(size_t* bytes) {
44 DCHECK(bytes); 65 DCHECK(bytes);
45 *bytes = 0; 66 *bytes = 0;
46 return false; 67 return false;
47 } 68 }
48 69
49 void GLContext::SetSafeToForceGpuSwitch() { 70 void GLContext::SetSafeToForceGpuSwitch() {
50 } 71 }
51 72
52 void GLContext::SetUnbindFboOnMakeCurrent() { 73 void GLContext::SetUnbindFboOnMakeCurrent() {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 186
166 void GLContext::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { 187 void GLContext::OnReleaseVirtuallyCurrent(GLContext* virtual_context) {
167 if (virtual_gl_api_) 188 if (virtual_gl_api_)
168 virtual_gl_api_->OnReleaseVirtuallyCurrent(virtual_context); 189 virtual_gl_api_->OnReleaseVirtuallyCurrent(virtual_context);
169 } 190 }
170 191
171 void GLContext::SetRealGLApi() { 192 void GLContext::SetRealGLApi() {
172 SetGLToRealGLApi(); 193 SetGLToRealGLApi();
173 } 194 }
174 195
196 void GLContext::OnFlush() {
197 for (size_t n = 0; n < flush_events_.size(); n++)
198 flush_events_[n]->Signal();
199 flush_events_.clear();
200 }
201
175 GLContextReal::GLContextReal(GLShareGroup* share_group) 202 GLContextReal::GLContextReal(GLShareGroup* share_group)
176 : GLContext(share_group) {} 203 : GLContext(share_group) {}
177 204
178 GLContextReal::~GLContextReal() {} 205 GLContextReal::~GLContextReal() {}
179 206
180 void GLContextReal::SetCurrent(GLSurface* surface) { 207 void GLContextReal::SetCurrent(GLSurface* surface) {
181 GLContext::SetCurrent(surface); 208 GLContext::SetCurrent(surface);
182 current_real_context_.Pointer()->Set(surface ? this : NULL); 209 current_real_context_.Pointer()->Set(surface ? this : NULL);
183 } 210 }
184 211
185 } // namespace gfx 212 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_context.h ('k') | ui/gl/gl_fence.h » ('j') | ui/gl/gl_fence.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698