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

Side by Side Diff: ui/compositor/compositor.cc

Issue 12212007: cc: Route offscreen context creation for compositor to the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Android build Created 7 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 | 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 "ui/compositor/compositor.h" 5 #include "ui/compositor/compositor.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
16 #include "cc/input_handler.h" 16 #include "cc/input_handler.h"
17 #include "cc/layer.h" 17 #include "cc/layer.h"
18 #include "cc/layer_tree_host.h" 18 #include "cc/layer_tree_host.h"
19 #include "cc/output_surface.h" 19 #include "cc/output_surface.h"
20 #include "cc/thread_impl.h" 20 #include "cc/thread_impl.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/compositor/compositor_observer.h" 22 #include "ui/compositor/compositor_observer.h"
23 #include "ui/compositor/compositor_switches.h" 23 #include "ui/compositor/compositor_switches.h"
24 #include "ui/compositor/dip_util.h" 24 #include "ui/compositor/dip_util.h"
25 #include "ui/compositor/layer.h" 25 #include "ui/compositor/layer.h"
26 #include "ui/compositor/test_web_graphics_context_3d.h" 26 #include "ui/compositor/test_web_graphics_context_3d.h"
27 #include "ui/gl/context_provider.h"
27 #include "ui/gl/gl_context.h" 28 #include "ui/gl/gl_context.h"
28 #include "ui/gl/gl_implementation.h" 29 #include "ui/gl/gl_implementation.h"
29 #include "ui/gl/gl_surface.h" 30 #include "ui/gl/gl_surface.h"
30 #include "ui/gl/gl_switches.h" 31 #include "ui/gl/gl_switches.h"
32 #include "webkit/gpu/grcontext_for_webgraphicscontext3d.h"
31 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" 33 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
32 34
33 #if defined(OS_CHROMEOS) 35 #if defined(OS_CHROMEOS)
34 #include "base/chromeos/chromeos_version.h" 36 #include "base/chromeos/chromeos_version.h"
35 #endif 37 #endif
36 38
37 namespace { 39 namespace {
38 40
39 const double kDefaultRefreshRate = 60.0; 41 const double kDefaultRefreshRate = 60.0;
40 const double kTestRefreshRate = 100.0; 42 const double kTestRefreshRate = 100.0;
(...skipping 22 matching lines...) Expand all
63 private: 65 private:
64 friend class ui::PostedSwapQueue; 66 friend class ui::PostedSwapQueue;
65 67
66 SwapType type_; 68 SwapType type_;
67 bool posted_; 69 bool posted_;
68 ui::PostedSwapQueue* posted_swaps_; 70 ui::PostedSwapQueue* posted_swaps_;
69 71
70 DISALLOW_COPY_AND_ASSIGN(PendingSwap); 72 DISALLOW_COPY_AND_ASSIGN(PendingSwap);
71 }; 73 };
72 74
75 class NullContextProvider : public ui::ContextProvider {
76 public:
77 virtual bool InitializeOnMainThread() OVERRIDE { return true; }
78 virtual bool BindToCurrentThread() OVERRIDE { return false; }
79 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { return NULL; }
80 virtual class GrContext* GrContext() OVERRIDE { return NULL; }
81 virtual void VerifyContexts() OVERRIDE {}
82 protected:
piman 2013/02/21 22:49:48 nit: blank line before 'protected:'
danakj 2013/02/22 01:56:31 Done.
83 virtual ~NullContextProvider() {}
84 };
85
86 static scoped_refptr<NullContextProvider>
piman 2013/02/21 22:49:48 You can't have non-POD as globals. Use Singletons?
danakj 2013/02/22 01:56:31 Oh right, POD only.. I used a Singleton class that
87 g_test_offscreen_contexts_main_thread;
88 static scoped_refptr<NullContextProvider>
89 g_test_offscreen_contexts_compositor_thread;
90
73 } // namespace 91 } // namespace
74 92
75 namespace ui { 93 namespace ui {
76 94
77 // static 95 // static
78 ContextFactory* ContextFactory::GetInstance() { 96 ContextFactory* ContextFactory::GetInstance() {
79 // We leak the shared resources so that we don't race with 97 // We leak the shared resources so that we don't race with
80 // the tear down of the gl_bindings. 98 // the tear down of the gl_bindings.
81 if (!g_context_factory) { 99 if (!g_context_factory) {
82 DVLOG(1) << "Using DefaultSharedResource"; 100 DVLOG(1) << "Using DefaultSharedResource";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface( 133 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface(
116 Compositor* compositor) { 134 Compositor* compositor) {
117 return new cc::OutputSurface( 135 return new cc::OutputSurface(
118 make_scoped_ptr(CreateContextCommon(compositor, false))); 136 make_scoped_ptr(CreateContextCommon(compositor, false)));
119 } 137 }
120 138
121 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { 139 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() {
122 return CreateContextCommon(NULL, true); 140 return CreateContextCommon(NULL, true);
123 } 141 }
124 142
143 class DefaultContextFactory::DefaultContextProvider
144 : public ui::ContextProvider {
145 public:
146 DefaultContextProvider(ContextFactory* factory)
147 : factory_(factory),
148 destroyed_(false) {}
149
150 virtual bool InitializeOnMainThread() OVERRIDE {
151 context3d_.reset(factory_->CreateOffscreenContext());
152 return !!context3d_;
153 }
154
155 virtual bool BindToCurrentThread() {
156 return context3d_->makeContextCurrent();
157 }
158
159 virtual WebKit::WebGraphicsContext3D* Context3d() { return context3d_.get(); }
160
161 virtual class GrContext* GrContext() {
162 if (!gr_context_) {
163 gr_context_.reset(
164 new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get()));
165 }
166 return gr_context_->get();
167 }
168
169 virtual void VerifyContexts() OVERRIDE {
170 if (!context3d_ || context3d_->isContextLost())
171 destroyed_ = true;
piman 2013/02/21 22:49:48 same here wrt thread safety
danakj 2013/02/22 01:56:31 Done.
172 }
173
174 bool destroyed() const { return destroyed_; }
175
176 protected:
177 virtual ~DefaultContextProvider() {}
178
179 private:
180 ContextFactory* factory_;
181 bool destroyed_;
182 scoped_ptr<WebKit::WebGraphicsContext3D> context3d_;
183 scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> gr_context_;
184 };
185
186 scoped_refptr<ui::ContextProvider>
187 DefaultContextFactory::OffscreenContextProviderForMainThread() {
188 if (!offscreen_contexts_main_thread_ ||
189 !offscreen_contexts_main_thread_->destroyed()) {
190 offscreen_contexts_main_thread_ = new DefaultContextProvider(this);
191 }
192 return offscreen_contexts_main_thread_;
193 }
194
195 scoped_refptr<ui::ContextProvider>
196 DefaultContextFactory::OffscreenContextProviderForCompositorThread() {
197 if (!offscreen_contexts_compositor_thread_ ||
198 !offscreen_contexts_compositor_thread_->destroyed()) {
199 offscreen_contexts_compositor_thread_ = new DefaultContextProvider(this);
200 }
201 return offscreen_contexts_compositor_thread_;
202 }
203
125 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { 204 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) {
126 } 205 }
127 206
128 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( 207 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon(
129 Compositor* compositor, 208 Compositor* compositor,
130 bool offscreen) { 209 bool offscreen) {
131 DCHECK(offscreen || compositor); 210 DCHECK(offscreen || compositor);
132 WebKit::WebGraphicsContext3D::Attributes attrs; 211 WebKit::WebGraphicsContext3D::Attributes attrs;
133 attrs.depth = false; 212 attrs.depth = false;
134 attrs.stencil = false; 213 attrs.stencil = false;
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 void Compositor::didCompleteSwapBuffers() { 590 void Compositor::didCompleteSwapBuffers() {
512 DCHECK(g_compositor_thread); 591 DCHECK(g_compositor_thread);
513 NotifyEnd(); 592 NotifyEnd();
514 } 593 }
515 594
516 void Compositor::scheduleComposite() { 595 void Compositor::scheduleComposite() {
517 if (!disable_schedule_composite_) 596 if (!disable_schedule_composite_)
518 ScheduleDraw(); 597 ScheduleDraw();
519 } 598 }
520 599
600 scoped_refptr<ui::ContextProvider>
601 Compositor::OffscreenContextProviderForMainThread() {
602 if (g_test_compositor_enabled) {
603 if (!g_test_offscreen_contexts_main_thread)
604 g_test_offscreen_contexts_main_thread = new NullContextProvider;
605 return g_test_offscreen_contexts_main_thread;
606 }
607 return ContextFactory::GetInstance()->OffscreenContextProviderForMainThread();
608 }
609
610 scoped_refptr<ui::ContextProvider>
611 Compositor::OffscreenContextProviderForCompositorThread() {
612 if (g_test_compositor_enabled) {
613 if (!g_test_offscreen_contexts_compositor_thread)
614 g_test_offscreen_contexts_compositor_thread = new NullContextProvider;
615 return g_test_offscreen_contexts_compositor_thread;
616 }
617 return ContextFactory::GetInstance()->
618 OffscreenContextProviderForCompositorThread();
619 }
620
521 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { 621 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
522 if (!compositor_lock_) { 622 if (!compositor_lock_) {
523 compositor_lock_ = new CompositorLock(this); 623 compositor_lock_ = new CompositorLock(this);
524 if (g_compositor_thread) 624 if (g_compositor_thread)
525 host_->setDeferCommits(true); 625 host_->setDeferCommits(true);
526 FOR_EACH_OBSERVER(CompositorObserver, 626 FOR_EACH_OBSERVER(CompositorObserver,
527 observer_list_, 627 observer_list_,
528 OnCompositingLockStateChanged(this)); 628 OnCompositingLockStateChanged(this));
529 } 629 }
530 return compositor_lock_; 630 return compositor_lock_;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 667
568 COMPOSITOR_EXPORT void DisableTestCompositor() { 668 COMPOSITOR_EXPORT void DisableTestCompositor() {
569 g_test_compositor_enabled = false; 669 g_test_compositor_enabled = false;
570 } 670 }
571 671
572 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { 672 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() {
573 return g_test_compositor_enabled; 673 return g_test_compositor_enabled;
574 } 674 }
575 675
576 } // namespace ui 676 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698