summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrjkroege <rjkroege@chromium.org>2015-11-18 17:40:47 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-19 01:41:51 +0000
commitc109de6120382395cafa9de062710e0f9eed861a (patch)
treee5a4c90c469a7add3ead771cd72ea4f9b7e18722
parent295eb08c795eb217486531380d908acd64a01695 (diff)
downloadchromium_src-c109de6120382395cafa9de062710e0f9eed861a.zip
chromium_src-c109de6120382395cafa9de062710e0f9eed861a.tar.gz
chromium_src-c109de6120382395cafa9de062710e0f9eed861a.tar.bz2
p1 mus+ash chrome renders ui and content
This patch forces mus+ash Chrome to software composite the ui and content region into a single bitmap that is uploaded to the mus window server. The approach here is similar to how Chrome paints to X11 when hardware acceleration is not available. BUG=554699 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Committed: https://crrev.com/e482a6010424204e7c8e313c5922acc38506be5c Cr-Commit-Position: refs/heads/master@{#360289} Review URL: https://codereview.chromium.org/1438903002 Cr-Commit-Position: refs/heads/master@{#360464}
-rw-r--r--base/threading/thread_restrictions.h6
-rw-r--r--chrome/browser/ui/BUILD.gn4
-rw-r--r--components/bitmap_uploader/bitmap_uploader.cc3
-rw-r--r--components/bitmap_uploader/bitmap_uploader.h2
-rw-r--r--content/browser/BUILD.gn6
-rw-r--r--content/browser/compositor/DEPS3
-rw-r--r--content/browser/compositor/gpu_process_transport_factory.cc19
-rw-r--r--content/browser/compositor/software_output_device_mus.cc64
-rw-r--r--content/browser/compositor/software_output_device_mus.h36
-rw-r--r--ui/views/mus/BUILD.gn1
-rw-r--r--ui/views/mus/DEPS1
-rw-r--r--ui/views/mus/native_widget_mus.cc8
-rw-r--r--ui/views/mus/platform_window_mus.cc16
-rw-r--r--ui/views/mus/window_tree_host_mus.cc9
-rw-r--r--ui/views/mus/window_tree_host_mus.h10
15 files changed, 182 insertions, 6 deletions
diff --git a/base/threading/thread_restrictions.h b/base/threading/thread_restrictions.h
index 3fda3ac..2d78c9b 100644
--- a/base/threading/thread_restrictions.h
+++ b/base/threading/thread_restrictions.h
@@ -42,6 +42,7 @@ class GpuChannelHost;
class NestedMessagePumpAndroid;
class ScopedAllowWaitForAndroidLayoutTests;
class ScopedAllowWaitForDebugURL;
+class SoftwareOutputDeviceMus;
class TextInputClientMac;
} // namespace content
namespace dbus {
@@ -217,7 +218,10 @@ class BASE_EXPORT ThreadRestrictions {
friend class net::NetworkChangeNotifierMac; // http://crbug.com/125097
friend class ::BrowserProcessImpl; // http://crbug.com/125207
friend class ::NativeBackendKWallet; // http://crbug.com/125331
- // END USAGE THAT NEEDS TO BE FIXED.
+#if !defined(OFFICIAL_BUILD)
+ friend class content::SoftwareOutputDeviceMus; // Interim non-production code
+#endif
+// END USAGE THAT NEEDS TO BE FIXED.
#if ENABLE_THREAD_RESTRICTIONS
static bool SetWaitAllowed(bool allowed);
diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn
index e2ee391..f89f2b2 100644
--- a/chrome/browser/ui/BUILD.gn
+++ b/chrome/browser/ui/BUILD.gn
@@ -154,6 +154,10 @@ source_set("ui") {
}
}
+ if (use_aura) {
+ defines += [ "MOJO_RUNNER_CLIENT" ]
+ }
+
if (enable_basic_printing || enable_print_preview) {
deps += [ "//printing" ]
}
diff --git a/components/bitmap_uploader/bitmap_uploader.cc b/components/bitmap_uploader/bitmap_uploader.cc
index f6525da..bfa8cd9 100644
--- a/components/bitmap_uploader/bitmap_uploader.cc
+++ b/components/bitmap_uploader/bitmap_uploader.cc
@@ -29,6 +29,9 @@ void OnGotContentHandlerID(uint32_t content_handler_id) {}
} // namespace
+const char kBitmapUploaderForAcceleratedWidget[] =
+ "__BITMAP_UPLOADER_ACCELERATED_WIDGET__";
+
BitmapUploader::BitmapUploader(mus::Window* window)
: window_(window),
color_(g_transparent_color),
diff --git a/components/bitmap_uploader/bitmap_uploader.h b/components/bitmap_uploader/bitmap_uploader.h
index ccb4d7a..8ced893 100644
--- a/components/bitmap_uploader/bitmap_uploader.h
+++ b/components/bitmap_uploader/bitmap_uploader.h
@@ -20,6 +20,8 @@ class Shell;
namespace bitmap_uploader {
+extern const char kBitmapUploaderForAcceleratedWidget[];
+
// BitmapUploader is useful if you want to draw a bitmap or color in a
// mus::Window.
class BitmapUploader : public mus::mojom::SurfaceClient {
diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn
index 9990e72..e98e681 100644
--- a/content/browser/BUILD.gn
+++ b/content/browser/BUILD.gn
@@ -421,7 +421,13 @@ source_set("browser") {
"//ui/strings",
"//ui/views/mus:for_component",
"//ui/wm",
+ "//components/bitmap_uploader",
]
+ sources += [
+ "compositor/software_output_device_mus.cc",
+ "compositor/software_output_device_mus.h",
+ ]
+ defines += [ "MOJO_RUNNER_CLIENT" ]
} else { # Not aura.
sources -= [
"media/capture/cursor_renderer_aura.cc",
diff --git a/content/browser/compositor/DEPS b/content/browser/compositor/DEPS
index 1701f72..70240ed 100644
--- a/content/browser/compositor/DEPS
+++ b/content/browser/compositor/DEPS
@@ -1,3 +1,4 @@
include_rules = [
- "+ui/platform_window",
+ "+components/bitmap_uploader",
+ "+ui/platform_window",
]
diff --git a/content/browser/compositor/gpu_process_transport_factory.cc b/content/browser/compositor/gpu_process_transport_factory.cc
index 7e2c513b9..2b9cd696 100644
--- a/content/browser/compositor/gpu_process_transport_factory.cc
+++ b/content/browser/compositor/gpu_process_transport_factory.cc
@@ -28,6 +28,7 @@
#include "content/browser/compositor/offscreen_browser_compositor_output_surface.h"
#include "content/browser/compositor/reflector_impl.h"
#include "content/browser/compositor/software_browser_compositor_output_surface.h"
+#include "content/browser/compositor/software_output_device_mus.h"
#include "content/browser/gpu/browser_gpu_channel_host_factory.h"
#include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
#include "content/browser/gpu/compositor_util.h"
@@ -148,6 +149,14 @@ GpuProcessTransportFactory::CreateOffscreenCommandBufferContext() {
scoped_ptr<cc::SoftwareOutputDevice>
GpuProcessTransportFactory::CreateSoftwareOutputDevice(
ui::Compositor* compositor) {
+#if defined(MOJO_RUNNER_CLIENT)
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ "mojo-platform-channel-handle")) {
+ return scoped_ptr<cc::SoftwareOutputDevice>(
+ new SoftwareOutputDeviceMus(compositor));
+ }
+#endif
+
#if defined(OS_WIN)
return scoped_ptr<cc::SoftwareOutputDevice>(
new SoftwareOutputDeviceWin(software_backing_.get(), compositor));
@@ -192,6 +201,16 @@ CreateOverlayCandidateValidator(gfx::AcceleratedWidget widget) {
}
static bool ShouldCreateGpuOutputSurface(ui::Compositor* compositor) {
+#if defined(MOJO_RUNNER_CLIENT)
+ // Chrome running as a mojo app currently can only use software compositing.
+ // TODO(rjkroege): http://crbug.com/548451
+ // TODO(rjkroege): Make IsRunningInMojoRunner callable from content.
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ "mojo-platform-channel-handle")) {
+ return false;
+ }
+#endif
+
#if defined(OS_CHROMEOS)
// Software fallback does not happen on Chrome OS.
return true;
diff --git a/content/browser/compositor/software_output_device_mus.cc b/content/browser/compositor/software_output_device_mus.cc
new file mode 100644
index 0000000..6180114
--- /dev/null
+++ b/content/browser/compositor/software_output_device_mus.cc
@@ -0,0 +1,64 @@
+// 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 "content/browser/compositor/software_output_device_mus.h"
+
+#include "components/bitmap_uploader/bitmap_uploader.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkDevice.h"
+#include "ui/base/view_prop.h"
+#include "ui/compositor/compositor.h"
+#include "ui/gfx/skia_util.h"
+
+#if !defined(OFFICIAL_BUILD)
+#include "base/threading/thread_restrictions.h"
+#endif
+
+namespace content {
+
+SoftwareOutputDeviceMus::SoftwareOutputDeviceMus(ui::Compositor* compositor)
+ : compositor_(compositor) {}
+
+void SoftwareOutputDeviceMus::EndPaint() {
+ SoftwareOutputDevice::EndPaint();
+#if !defined(OFFICIAL_BUILD)
+ base::ThreadRestrictions::ScopedAllowWait wait;
+#endif
+
+ if (!surface_)
+ return;
+
+ gfx::Rect rect = damage_rect_;
+ rect.Intersect(gfx::Rect(viewport_pixel_size_));
+ if (rect.IsEmpty())
+ return;
+
+ gfx::AcceleratedWidget widget = compositor_->widget();
+ bitmap_uploader::BitmapUploader* uploader =
+ reinterpret_cast<bitmap_uploader::BitmapUploader*>(ui::ViewProp::GetValue(
+ widget, bitmap_uploader::kBitmapUploaderForAcceleratedWidget));
+ DCHECK(uploader);
+
+ SkImageInfo info;
+ size_t rowBytes;
+ const void* addr = surface_->peekPixels(&info, &rowBytes);
+
+ if (!addr) {
+ LOG(WARNING) << "SoftwareOutputDeviceMus: skia surface did not provide us "
+ "with pixels";
+ return;
+ }
+
+ const unsigned char* pixels = static_cast<const unsigned char*>(addr);
+
+ // TODO(rjkroege): This makes an additional copy. Improve the
+ // bitmap_uploader API to remove.
+ scoped_ptr<std::vector<unsigned char>> data(new std::vector<unsigned char>(
+ pixels, pixels + rowBytes * viewport_pixel_size_.height()));
+ uploader->SetBitmap(viewport_pixel_size_.width(),
+ viewport_pixel_size_.height(), data.Pass(),
+ bitmap_uploader::BitmapUploader::BGRA);
+}
+
+} // namespace content
diff --git a/content/browser/compositor/software_output_device_mus.h b/content/browser/compositor/software_output_device_mus.h
new file mode 100644
index 0000000..d4a2e450
--- /dev/null
+++ b/content/browser/compositor/software_output_device_mus.h
@@ -0,0 +1,36 @@
+// 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.
+
+#ifndef CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_MUS_H_
+#define CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_MUS_H_
+
+#include "base/macros.h"
+#include "cc/output/software_output_device.h"
+#include "content/common/content_export.h"
+
+namespace ui {
+class Compositor;
+}
+
+namespace content {
+
+// Mus implementation of software compositing: Chrome will do a software
+// composite and ship the resultant bitmap to an instance of the mus
+// window server. Remove this upon completion of http://crbug.com/548451
+class SoftwareOutputDeviceMus : public cc::SoftwareOutputDevice {
+ public:
+ explicit SoftwareOutputDeviceMus(ui::Compositor* compositor);
+
+ private:
+ // cc::SoftwareOutputDevice
+ void EndPaint() override;
+
+ ui::Compositor* compositor_;
+
+ DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceMus);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_MUS_H_
diff --git a/ui/views/mus/BUILD.gn b/ui/views/mus/BUILD.gn
index dd80c4a..5ab84dc 100644
--- a/ui/views/mus/BUILD.gn
+++ b/ui/views/mus/BUILD.gn
@@ -42,6 +42,7 @@ component("mus") {
"//base/third_party/dynamic_annotations",
"//cc",
"//cc/surfaces",
+ "//components/bitmap_uploader",
"//components/mus/gles2:lib",
"//components/mus/public/cpp",
"//components/mus/public/interfaces",
diff --git a/ui/views/mus/DEPS b/ui/views/mus/DEPS
index 6ddcc64..447d4b4 100644
--- a/ui/views/mus/DEPS
+++ b/ui/views/mus/DEPS
@@ -2,6 +2,7 @@ include_rules = [
"+cc",
"-cc/blink",
"+components/font_service/public",
+ "+components/bitmap_uploader",
"+components/gpu",
"+components/mus",
"+components/resource_provider",
diff --git a/ui/views/mus/native_widget_mus.cc b/ui/views/mus/native_widget_mus.cc
index 578c9ea..70245bc 100644
--- a/ui/views/mus/native_widget_mus.cc
+++ b/ui/views/mus/native_widget_mus.cc
@@ -259,13 +259,15 @@ void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) {
// picked up.
ui::ContextFactory* default_context_factory =
aura::Env::GetInstance()->context_factory();
- aura::Env::GetInstance()->set_context_factory(context_factory_.get());
+ // For Chrome, we need the GpuProcessTransportFactory so that renderer and
+ // browser pixels are composited into a single backing
+ // SoftwareOutputDeviceMus.
+ if (!default_context_factory)
+ aura::Env::GetInstance()->set_context_factory(context_factory_.get());
window_tree_host_.reset(
new WindowTreeHostMus(shell_, this, window_, surface_type_));
window_tree_host_->InitHost();
aura::Env::GetInstance()->set_context_factory(default_context_factory);
- DCHECK_EQ(context_factory_.get(),
- window_tree_host_->compositor()->context_factory());
focus_client_.reset(new wm::FocusController(new FocusRulesImpl));
diff --git a/ui/views/mus/platform_window_mus.cc b/ui/views/mus/platform_window_mus.cc
index be343eb..3a9c85f 100644
--- a/ui/views/mus/platform_window_mus.cc
+++ b/ui/views/mus/platform_window_mus.cc
@@ -13,6 +13,11 @@
namespace views {
+namespace {
+static uint32_t accelerated_widget_count = 1;
+
+} // namespace
+
PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate,
mus::Window* mus_window)
: delegate_(delegate),
@@ -23,9 +28,18 @@ PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate,
DCHECK(mus_window_);
mus_window_->AddObserver(this);
+ // We need accelerated widget numbers to be different for each
+ // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t
+ // has this property.
+#if defined(OS_WIN)
+ delegate_->OnAcceleratedWidgetAvailable(
+ reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++),
+ mus_window_->viewport_metrics().device_pixel_ratio);
+#else
delegate_->OnAcceleratedWidgetAvailable(
- gfx::kNullAcceleratedWidget,
+ static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++),
mus_window_->viewport_metrics().device_pixel_ratio);
+#endif
}
PlatformWindowMus::~PlatformWindowMus() {
diff --git a/ui/views/mus/window_tree_host_mus.cc b/ui/views/mus/window_tree_host_mus.cc
index 7e01767..5f0b825 100644
--- a/ui/views/mus/window_tree_host_mus.cc
+++ b/ui/views/mus/window_tree_host_mus.cc
@@ -4,9 +4,11 @@
#include "ui/views/mus/window_tree_host_mus.h"
+#include "components/bitmap_uploader/bitmap_uploader.h"
#include "mojo/application/public/interfaces/shell.mojom.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
+#include "ui/base/view_prop.h"
#include "ui/events/event.h"
#include "ui/views/mus/input_method_mus.h"
#include "ui/views/mus/native_widget_mus.h"
@@ -31,6 +33,13 @@ WindowTreeHostMus::WindowTreeHostMus(mojo::Shell* shell,
dispatcher()->set_transform_events(false);
compositor()->SetHostHasTransparentBackground(true);
+ bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(window));
+ bitmap_uploader_->Init(shell);
+ prop_.reset(
+ new ui::ViewProp(GetAcceleratedWidget(),
+ bitmap_uploader::kBitmapUploaderForAcceleratedWidget,
+ bitmap_uploader_.get()));
+
input_method_.reset(new InputMethodMUS(this, window));
SetSharedInputMethod(input_method_.get());
}
diff --git a/ui/views/mus/window_tree_host_mus.h b/ui/views/mus/window_tree_host_mus.h
index 5882a28..1a4473e 100644
--- a/ui/views/mus/window_tree_host_mus.h
+++ b/ui/views/mus/window_tree_host_mus.h
@@ -12,6 +12,10 @@
class SkBitmap;
+namespace bitmap_uploader {
+class BitmapUploader;
+}
+
namespace mojo {
class Shell;
}
@@ -22,6 +26,7 @@ class Window;
namespace ui {
class Compositor;
+class ViewProp;
}
namespace views {
@@ -39,6 +44,9 @@ class VIEWS_MUS_EXPORT WindowTreeHostMus : public aura::WindowTreeHostPlatform {
~WindowTreeHostMus() override;
PlatformWindowMus* platform_window();
+ bitmap_uploader::BitmapUploader* bitmap_uploader() {
+ return bitmap_uploader_.get();
+ };
ui::PlatformWindowState show_state() const { return show_state_; }
private:
@@ -51,6 +59,8 @@ class VIEWS_MUS_EXPORT WindowTreeHostMus : public aura::WindowTreeHostPlatform {
NativeWidgetMus* native_widget_;
scoped_ptr<InputMethodMUS> input_method_;
ui::PlatformWindowState show_state_;
+ scoped_ptr<bitmap_uploader::BitmapUploader> bitmap_uploader_;
+ scoped_ptr<ui::ViewProp> prop_;
DISALLOW_COPY_AND_ASSIGN(WindowTreeHostMus);
};