summaryrefslogtreecommitdiff
path: root/chromium/blimp/client/app/blimp_startup.cc
blob: ad36ed10866c1e05e7e57e58bcf05fb64a85a999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "blimp/client/app/blimp_startup.h"

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "blimp/client/app/blimp_discardable_memory_allocator.h"
#include "blimp/client/feature/compositor/decoding_image_generator.h"
#include "third_party/skia/include/core/SkGraphics.h"
#include "ui/gl/gl_surface.h"

class SkImageGenerator;

namespace {
base::LazyInstance<std::unique_ptr<base::MessageLoopForUI>>
    g_main_message_loop = LAZY_INSTANCE_INITIALIZER;

base::LazyInstance<blimp::client::BlimpDiscardableMemoryAllocator>
    g_discardable_memory_allocator = LAZY_INSTANCE_INITIALIZER;

SkImageGenerator* CreateImageGenerator(SkData* data) {
  return blimp::client::DecodingImageGenerator::create(data);
}

}  // namespace

namespace blimp {
namespace client {

void InitializeLogging() {
  // TODO(haibinlu): Remove this before release.
  // Enables a few verbose log by default.
  if (!base::CommandLine::ForCurrentProcess()->HasSwitch("vmodule")) {
    std::string log_filter =
        std::string("blimp_message_pump=1, blimp_connection=1,") +
        std::string("blimp_compositor=1, blimp_compositor_manager=1,") +
        std::string("remote_channel_impl=1");
    base::CommandLine::ForCurrentProcess()->AppendSwitchASCII("vmodule",
                                                              log_filter);
  }

  logging::LoggingSettings settings;
#if defined(OS_ANDROID)
  settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
#else
  base::FilePath log_filename;
  PathService::Get(base::DIR_EXE, &log_filename);
  log_filename = log_filename.AppendASCII("blimp_client.log");
  settings.logging_dest = logging::LOG_TO_ALL;
  settings.log_file = log_filename.value().c_str();
  settings.delete_old = logging::DELETE_OLD_LOG_FILE;
#endif  // OS_ANDROID
  logging::InitLogging(settings);
  logging::SetLogItems(false,   // Process ID
                       false,   // Thread ID
                       false,   // Timestamp
                       false);  // Tick count
  VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel()
          << ", default verbosity = " << logging::GetVlogVerbosity();
}

bool InitializeMainMessageLoop() {
  // TODO(dtrainor): Initialize ICU?

  // Set the DiscardableMemoryAllocator.
  base::DiscardableMemoryAllocator::SetInstance(
      g_discardable_memory_allocator.Pointer());
  if (!gfx::GLSurface::InitializeOneOff())
    return false;
  SkGraphics::Init();
  SkGraphics::SetImageGeneratorFromEncodedFactory(CreateImageGenerator);
  g_main_message_loop.Get().reset(new base::MessageLoopForUI);
  return true;
}

}  // namespace client
}  // namespace blimp