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

Unified Diff: trunk/src/ui/compositor/compositor.cc

Issue 22648006: Revert 216780 "Clean up compositor initialization/destruction." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « trunk/src/ui/compositor/compositor.h ('k') | trunk/src/ui/compositor/compositor.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/ui/compositor/compositor.cc
===================================================================
--- trunk/src/ui/compositor/compositor.cc (revision 216906)
+++ trunk/src/ui/compositor/compositor.cc (working copy)
@@ -50,9 +50,10 @@
READPIXELS_SWAP,
};
-bool g_compositor_initialized = false;
base::Thread* g_compositor_thread = NULL;
+bool g_test_compositor_enabled = false;
+
ui::ContextFactory* g_implicit_factory = NULL;
ui::ContextFactory* g_context_factory = NULL;
@@ -76,13 +77,39 @@
DISALLOW_COPY_AND_ASSIGN(PendingSwap);
};
+void SetupImplicitFactory() {
+ // We leak the implicit factory so that we don't race with the tear down of
+ // the gl_bindings.
+ DCHECK(!g_context_factory);
+ DCHECK(!g_implicit_factory);
+ if (g_test_compositor_enabled) {
+ g_implicit_factory = new ui::TestContextFactory;
+ } else {
+ DVLOG(1) << "Using DefaultContextFactory";
+ scoped_ptr<ui::DefaultContextFactory> instance(
+ new ui::DefaultContextFactory());
+ if (instance->Initialize())
+ g_implicit_factory = instance.release();
+ }
+ g_context_factory = g_implicit_factory;
+}
+
+void ResetImplicitFactory() {
+ if (!g_implicit_factory || g_context_factory != g_implicit_factory)
+ return;
+ delete g_implicit_factory;
+ g_implicit_factory = NULL;
+ g_context_factory = NULL;
+}
+
} // namespace
namespace ui {
// static
ContextFactory* ContextFactory::GetInstance() {
- DCHECK(g_context_factory);
+ if (!g_context_factory)
+ SetupImplicitFactory();
return g_context_factory;
}
@@ -153,8 +180,6 @@
void DefaultContextFactory::RemoveCompositor(Compositor* compositor) {
}
-bool DefaultContextFactory::DoesCreateTestContexts() { return false; }
-
scoped_ptr<WebKit::WebGraphicsContext3D>
DefaultContextFactory::CreateContextCommon(Compositor* compositor,
bool offscreen) {
@@ -223,8 +248,6 @@
void TestContextFactory::RemoveCompositor(Compositor* compositor) {
}
-bool TestContextFactory::DoesCreateTestContexts() { return true; }
-
Texture::Texture(bool flipped, const gfx::Size& size, float device_scale_factor)
: size_(size),
flipped_(flipped),
@@ -387,9 +410,6 @@
next_draw_is_resize_(false),
disable_schedule_composite_(false),
compositor_lock_(NULL) {
- DCHECK(g_compositor_initialized)
- << "Compositor::Initialize must be called before creating a Compositor.";
-
root_web_layer_ = cc::Layer::Create();
root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f));
@@ -397,9 +417,7 @@
cc::LayerTreeSettings settings;
settings.refresh_rate =
- ContextFactory::GetInstance()->DoesCreateTestContexts()
- ? kTestRefreshRate
- : kDefaultRefreshRate;
+ g_test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate;
settings.partial_swap_enabled =
!command_line->HasSwitch(cc::switches::kUIDisablePartialSwap);
settings.per_tile_painting_enabled =
@@ -434,8 +452,6 @@
}
Compositor::~Compositor() {
- DCHECK(g_compositor_initialized);
-
CancelCompositorLock();
DCHECK(!compositor_lock_);
@@ -452,41 +468,6 @@
}
// static
-void Compositor::InitializeContextFactoryForTests(bool allow_test_contexts) {
- DCHECK(!g_context_factory) << "ContextFactory already initialized.";
- DCHECK(!g_implicit_factory) <<
- "ContextFactory for tests already initialized.";
-
- bool use_test_contexts = true;
-
- // Always use test contexts unless the disable command line flag is used.
- CommandLine* command_line = CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(switches::kDisableTestCompositor))
- use_test_contexts = false;
-
-#if defined(OS_CHROMEOS)
- // If the test is running on the chromeos envrionment (such as
- // device or vm bots), always use real contexts.
- if (base::chromeos::IsRunningOnChromeOS())
- use_test_contexts = false;
-#endif
-
- if (!allow_test_contexts)
- use_test_contexts = false;
-
- if (use_test_contexts) {
- g_implicit_factory = new ui::TestContextFactory;
- } else {
- DVLOG(1) << "Using DefaultContextFactory";
- scoped_ptr<ui::DefaultContextFactory> instance(
- new ui::DefaultContextFactory());
- if (instance->Initialize())
- g_implicit_factory = instance.release();
- }
- g_context_factory = g_implicit_factory;
-}
-
-// static
void Compositor::Initialize() {
#if defined(OS_CHROMEOS)
bool use_thread = !CommandLine::ForCurrentProcess()->HasSwitch(
@@ -502,9 +483,6 @@
g_compositor_thread = new base::Thread("Browser Compositor");
g_compositor_thread->Start();
}
-
- DCHECK(!g_compositor_initialized) << "Compositor initialized twice.";
- g_compositor_initialized = true;
}
// static
@@ -522,24 +500,11 @@
// static
void Compositor::Terminate() {
- if (g_context_factory) {
- if (g_implicit_factory) {
- delete g_implicit_factory;
- g_implicit_factory = NULL;
- }
- g_context_factory = NULL;
- }
-
if (g_compositor_thread) {
- DCHECK(!g_context_factory)
- << "The ContextFactory should not outlive the compositor thread.";
g_compositor_thread->Stop();
delete g_compositor_thread;
g_compositor_thread = NULL;
}
-
- DCHECK(g_compositor_initialized) << "Compositor::Initialize() didn't happen.";
- g_compositor_initialized = false;
}
void Compositor::ScheduleDraw() {
@@ -786,4 +751,27 @@
OnCompositingEnded(this));
}
+COMPOSITOR_EXPORT void SetupTestCompositor() {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableTestCompositor)) {
+ g_test_compositor_enabled = true;
+ }
+#if defined(OS_CHROMEOS)
+ // If the test is running on the chromeos envrionment (such as
+ // device or vm bots), use the real compositor.
+ if (base::chromeos::IsRunningOnChromeOS())
+ g_test_compositor_enabled = false;
+#endif
+ ResetImplicitFactory();
+}
+
+COMPOSITOR_EXPORT void DisableTestCompositor() {
+ ResetImplicitFactory();
+ g_test_compositor_enabled = false;
+}
+
+COMPOSITOR_EXPORT bool IsTestCompositorEnabled() {
+ return g_test_compositor_enabled;
+}
+
} // namespace ui
Property changes on: trunk/src/ui/compositor/compositor.cc
___________________________________________________________________
Deleted: svn:mergeinfo
« no previous file with comments | « trunk/src/ui/compositor/compositor.h ('k') | trunk/src/ui/compositor/compositor.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698