diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-07 08:17:42 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-07 08:17:42 +0000 |
commit | 6929154213ec00236e4e123d63ff1f88f458391e (patch) | |
tree | 3e6354f008c0eaed7cb06faf61a0fbefa57b0fc6 /mojo/aura | |
parent | be32d87d0e255ed03bae17ddefa0a6559765975c (diff) | |
download | chromium_src-6929154213ec00236e4e123d63ff1f88f458391e.zip chromium_src-6929154213ec00236e4e123d63ff1f88f458391e.tar.gz chromium_src-6929154213ec00236e4e123d63ff1f88f458391e.tar.bz2 |
Moves common view_manager related aura files to mojo/aura
I'm going to use these files in other examples. I refactored the code slightly to update compositor via a delegate. This way the code can easily (hopefully) be used by view_manager_lib related code.
I'm also making aura::Env extend base::SupportsUserData so that
consumers can add arbitrary key/value pairs to Env.
BUG=365012
TEST=none
R=ben@chromium.org
Review URL: https://codereview.chromium.org/314113011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275638 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/aura')
-rw-r--r-- | mojo/aura/DEPS | 1 | ||||
-rw-r--r-- | mojo/aura/context_factory_mojo.cc | 136 | ||||
-rw-r--r-- | mojo/aura/context_factory_mojo.h | 40 | ||||
-rw-r--r-- | mojo/aura/window_tree_host_mojo.cc | 161 | ||||
-rw-r--r-- | mojo/aura/window_tree_host_mojo.h | 66 | ||||
-rw-r--r-- | mojo/aura/window_tree_host_mojo_delegate.h | 24 |
6 files changed, 428 insertions, 0 deletions
diff --git a/mojo/aura/DEPS b/mojo/aura/DEPS index 698be88..ad60823 100644 --- a/mojo/aura/DEPS +++ b/mojo/aura/DEPS @@ -1,5 +1,6 @@ include_rules = [ "+cc", + "+skia", "+ui/aura", "+ui/compositor", "+ui/events", diff --git a/mojo/aura/context_factory_mojo.cc b/mojo/aura/context_factory_mojo.cc new file mode 100644 index 0000000..6b2b709 --- /dev/null +++ b/mojo/aura/context_factory_mojo.cc @@ -0,0 +1,136 @@ +// Copyright 2014 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 "mojo/aura/context_factory_mojo.h" + +#include "base/bind.h" +#include "cc/output/output_surface.h" +#include "cc/output/software_output_device.h" +#include "cc/resources/shared_bitmap_manager.h" +#include "mojo/aura/window_tree_host_mojo.h" +#include "skia/ext/platform_canvas.h" +#include "ui/compositor/reflector.h" + +namespace mojo { +namespace { + +void FreeSharedBitmap(cc::SharedBitmap* shared_bitmap) { + delete shared_bitmap->memory(); +} + +void IgnoreSharedBitmap(cc::SharedBitmap* shared_bitmap) {} + +class SoftwareOutputDeviceViewManager : public cc::SoftwareOutputDevice { + public: + explicit SoftwareOutputDeviceViewManager(ui::Compositor* compositor) + : compositor_(compositor) { + } + virtual ~SoftwareOutputDeviceViewManager() {} + + // cc::SoftwareOutputDevice: + virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE { + WindowTreeHostMojo* window_tree_host = + WindowTreeHostMojo::ForCompositor(compositor_); + DCHECK(window_tree_host); + window_tree_host->SetContents( + skia::GetTopDevice(*canvas_)->accessBitmap(true)); + + SoftwareOutputDevice::EndPaint(frame_data); + } + + private: + ui::Compositor* compositor_; + + DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceViewManager); +}; + +// TODO(sky): this is a copy from cc/test. Copy to a common place. +class TestSharedBitmapManager : public cc::SharedBitmapManager { + public: + TestSharedBitmapManager() {} + virtual ~TestSharedBitmapManager() {} + + virtual scoped_ptr<cc::SharedBitmap> AllocateSharedBitmap( + const gfx::Size& size) OVERRIDE { + base::AutoLock lock(lock_); + scoped_ptr<base::SharedMemory> memory(new base::SharedMemory); + memory->CreateAndMapAnonymous(size.GetArea() * 4); + cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); + bitmap_map_[id] = memory.get(); + return scoped_ptr<cc::SharedBitmap>( + new cc::SharedBitmap(memory.release(), id, + base::Bind(&FreeSharedBitmap))); + } + + virtual scoped_ptr<cc::SharedBitmap> GetSharedBitmapFromId( + const gfx::Size&, + const cc::SharedBitmapId& id) OVERRIDE { + base::AutoLock lock(lock_); + if (bitmap_map_.find(id) == bitmap_map_.end()) + return scoped_ptr<cc::SharedBitmap>(); + return scoped_ptr<cc::SharedBitmap>( + new cc::SharedBitmap(bitmap_map_[id], id, + base::Bind(&IgnoreSharedBitmap))); + } + + virtual scoped_ptr<cc::SharedBitmap> GetBitmapForSharedMemory( + base::SharedMemory* memory) OVERRIDE { + base::AutoLock lock(lock_); + cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); + bitmap_map_[id] = memory; + return scoped_ptr<cc::SharedBitmap>( + new cc::SharedBitmap(memory, id, base::Bind(&IgnoreSharedBitmap))); + } + + private: + base::Lock lock_; + std::map<cc::SharedBitmapId, base::SharedMemory*> bitmap_map_; + + DISALLOW_COPY_AND_ASSIGN(TestSharedBitmapManager); +}; + +} // namespace + +ContextFactoryMojo::ContextFactoryMojo() + : shared_bitmap_manager_(new TestSharedBitmapManager()) { +} + +ContextFactoryMojo::~ContextFactoryMojo() {} + +scoped_ptr<cc::OutputSurface> ContextFactoryMojo::CreateOutputSurface( + ui::Compositor* compositor, + bool software_fallback) { + scoped_ptr<cc::SoftwareOutputDevice> output_device( + new SoftwareOutputDeviceViewManager(compositor)); + return make_scoped_ptr(new cc::OutputSurface(output_device.Pass())); +} + +scoped_refptr<ui::Reflector> ContextFactoryMojo::CreateReflector( + ui::Compositor* mirroed_compositor, + ui::Layer* mirroring_layer) { + return new ui::Reflector(); +} + +void ContextFactoryMojo::RemoveReflector( + scoped_refptr<ui::Reflector> reflector) { +} + +scoped_refptr<cc::ContextProvider> +ContextFactoryMojo::SharedMainThreadContextProvider() { + return scoped_refptr<cc::ContextProvider>(NULL); +} + +void ContextFactoryMojo::RemoveCompositor(ui::Compositor* compositor) {} + +bool ContextFactoryMojo::DoesCreateTestContexts() { return false; } + +cc::SharedBitmapManager* ContextFactoryMojo::GetSharedBitmapManager() { + return shared_bitmap_manager_.get(); +} + +base::MessageLoopProxy* ContextFactoryMojo::GetCompositorMessageLoop() { + return NULL; +} + +} // namespace mojo diff --git a/mojo/aura/context_factory_mojo.h b/mojo/aura/context_factory_mojo.h new file mode 100644 index 0000000..800afa7 --- /dev/null +++ b/mojo/aura/context_factory_mojo.h @@ -0,0 +1,40 @@ +// Copyright 2014 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 MOJO_AURA_CONTEXT_FACTORY_MOJO_H_ +#define MOJO_AURA_CONTEXT_FACTORY_MOJO_H_ + +#include "ui/compositor/compositor.h" + +namespace mojo { + +class ContextFactoryMojo : public ui::ContextFactory { + public: + ContextFactoryMojo(); + virtual ~ContextFactoryMojo(); + + private: + // ContextFactory: + virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface( + ui::Compositor* compositor, + bool software_fallback) OVERRIDE; + virtual scoped_refptr<ui::Reflector> CreateReflector( + ui::Compositor* mirrored_compositor, + ui::Layer* mirroring_layer) OVERRIDE; + virtual void RemoveReflector(scoped_refptr<ui::Reflector> reflector) OVERRIDE; + virtual scoped_refptr<cc::ContextProvider> SharedMainThreadContextProvider() + OVERRIDE; + virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE; + virtual bool DoesCreateTestContexts() OVERRIDE; + virtual cc::SharedBitmapManager* GetSharedBitmapManager() OVERRIDE; + virtual base::MessageLoopProxy* GetCompositorMessageLoop() OVERRIDE; + + scoped_ptr<cc::SharedBitmapManager> shared_bitmap_manager_; + + DISALLOW_COPY_AND_ASSIGN(ContextFactoryMojo); +}; + +} // namespace mojo + +#endif // MOJO_AURA_CONTEXT_FACTORY_MOJO_H_ diff --git a/mojo/aura/window_tree_host_mojo.cc b/mojo/aura/window_tree_host_mojo.cc new file mode 100644 index 0000000..9a51f2e --- /dev/null +++ b/mojo/aura/window_tree_host_mojo.cc @@ -0,0 +1,161 @@ +// Copyright 2014 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 "mojo/aura/window_tree_host_mojo.h" + +#include <vector> + +#include "mojo/aura/window_tree_host_mojo_delegate.h" +#include "ui/aura/env.h" +#include "ui/aura/window.h" +#include "ui/aura/window_event_dispatcher.h" +#include "ui/events/event.h" +#include "ui/events/event_constants.h" + +namespace mojo { +namespace { + +const char kTreeHostsKey[] = "tree_hosts"; + +typedef std::vector<WindowTreeHostMojo*> Managers; + +class TreeHosts : public base::SupportsUserData::Data { + public: + TreeHosts() {} + virtual ~TreeHosts() {} + + static TreeHosts* Get() { + TreeHosts* hosts = static_cast<TreeHosts*>( + aura::Env::GetInstance()->GetUserData(kTreeHostsKey)); + if (!hosts) { + hosts = new TreeHosts; + aura::Env::GetInstance()->SetUserData(kTreeHostsKey, hosts); + } + return hosts; + } + + void Add(WindowTreeHostMojo* manager) { + managers_.push_back(manager); + } + + void Remove(WindowTreeHostMojo* manager) { + Managers::iterator i = std::find(managers_.begin(), managers_.end(), + manager); + DCHECK(i != managers_.end()); + managers_.erase(i); + } + + const std::vector<WindowTreeHostMojo*> managers() const { + return managers_; + } + + private: + Managers managers_; + + DISALLOW_COPY_AND_ASSIGN(TreeHosts); +}; + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// +// WindowTreeHostMojo, public: + +WindowTreeHostMojo::WindowTreeHostMojo(const gfx::Rect& bounds, + WindowTreeHostMojoDelegate* delegate) + : bounds_(bounds), + delegate_(delegate) { + CreateCompositor(GetAcceleratedWidget()); + + TreeHosts::Get()->Add(this); +} + +WindowTreeHostMojo::~WindowTreeHostMojo() { + TreeHosts::Get()->Remove(this); + DestroyCompositor(); + DestroyDispatcher(); +} + +// static +WindowTreeHostMojo* WindowTreeHostMojo::ForCompositor( + ui::Compositor* compositor) { + const Managers& managers = TreeHosts::Get()->managers(); + for (size_t i = 0; i < managers.size(); ++i) { + if (managers[i]->compositor() == compositor) + return managers[i]; + } + return NULL; +} + +void WindowTreeHostMojo::SetContents(const SkBitmap& contents) { + delegate_->CompositorContentsChanged(contents); +} + +//////////////////////////////////////////////////////////////////////////////// +// WindowTreeHostMojo, aura::WindowTreeHost implementation: + +ui::EventSource* WindowTreeHostMojo::GetEventSource() { + return this; +} + +gfx::AcceleratedWidget WindowTreeHostMojo::GetAcceleratedWidget() { + NOTIMPLEMENTED() << "GetAcceleratedWidget"; + return gfx::kNullAcceleratedWidget; +} + +void WindowTreeHostMojo::Show() { + window()->Show(); +} + +void WindowTreeHostMojo::Hide() { +} + +gfx::Rect WindowTreeHostMojo::GetBounds() const { + return bounds_; +} + +void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) { +} + +gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const { + return gfx::Point(0, 0); +} + +void WindowTreeHostMojo::SetCapture() { + NOTIMPLEMENTED(); +} + +void WindowTreeHostMojo::ReleaseCapture() { + NOTIMPLEMENTED(); +} + +void WindowTreeHostMojo::PostNativeEvent( + const base::NativeEvent& native_event) { + NOTIMPLEMENTED(); +} + +void WindowTreeHostMojo::OnDeviceScaleFactorChanged( + float device_scale_factor) { + NOTIMPLEMENTED(); +} + +void WindowTreeHostMojo::SetCursorNative(gfx::NativeCursor cursor) { + NOTIMPLEMENTED(); +} + +void WindowTreeHostMojo::MoveCursorToNative(const gfx::Point& location) { + NOTIMPLEMENTED(); +} + +void WindowTreeHostMojo::OnCursorVisibilityChangedNative(bool show) { + NOTIMPLEMENTED(); +} + +//////////////////////////////////////////////////////////////////////////////// +// WindowTreeHostMojo, ui::EventSource implementation: + +ui::EventProcessor* WindowTreeHostMojo::GetEventProcessor() { + return dispatcher(); +} + +} // namespace mojo diff --git a/mojo/aura/window_tree_host_mojo.h b/mojo/aura/window_tree_host_mojo.h new file mode 100644 index 0000000..fe5ca77 --- /dev/null +++ b/mojo/aura/window_tree_host_mojo.h @@ -0,0 +1,66 @@ +// Copyright 2014 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 MOJO_EXAMPLES_AURA_DEMO_WINDOW_TREE_HOST_VIEW_MANAGER_H_ +#define MOJO_EXAMPLES_AURA_DEMO_WINDOW_TREE_HOST_VIEW_MANAGER_H_ + +#include "ui/aura/window_tree_host.h" +#include "ui/events/event_source.h" +#include "ui/gfx/geometry/rect.h" + +class SkBitmap; + +namespace ui { +class Compositor; +} + +namespace mojo { + +class WindowTreeHostMojoDelegate; + +class WindowTreeHostMojo : public aura::WindowTreeHost, public ui::EventSource { + public: + WindowTreeHostMojo(const gfx::Rect& bounds, + WindowTreeHostMojoDelegate* delegate); + virtual ~WindowTreeHostMojo(); + + // Returns the WindowTreeHostMojo for the specified compositor. + static WindowTreeHostMojo* ForCompositor(ui::Compositor* compositor); + + const gfx::Rect& bounds() const { return bounds_; } + + // Sets the contents to show in this WindowTreeHost. This forwards to the + // delegate. + void SetContents(const SkBitmap& contents); + + private: + // WindowTreeHost: + virtual ui::EventSource* GetEventSource() OVERRIDE; + virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; + virtual void Show() OVERRIDE; + virtual void Hide() OVERRIDE; + virtual gfx::Rect GetBounds() const OVERRIDE; + virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; + virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; + virtual void SetCapture() OVERRIDE; + virtual void ReleaseCapture() OVERRIDE; + virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE; + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; + virtual void SetCursorNative(gfx::NativeCursor cursor) OVERRIDE; + virtual void MoveCursorToNative(const gfx::Point& location) OVERRIDE; + virtual void OnCursorVisibilityChangedNative(bool show) OVERRIDE; + + // ui::EventSource: + virtual ui::EventProcessor* GetEventProcessor() OVERRIDE; + + gfx::Rect bounds_; + + WindowTreeHostMojoDelegate* delegate_; + + DISALLOW_COPY_AND_ASSIGN(WindowTreeHostMojo); +}; + +} // namespace mojo + +#endif // MOJO_EXAMPLES_AURA_DEMO_WINDOW_TREE_HOST_VIEW_MANAGER_H_ diff --git a/mojo/aura/window_tree_host_mojo_delegate.h b/mojo/aura/window_tree_host_mojo_delegate.h new file mode 100644 index 0000000..9ab13b2 --- /dev/null +++ b/mojo/aura/window_tree_host_mojo_delegate.h @@ -0,0 +1,24 @@ +// Copyright 2014 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 MOJO_EXAMPLES_AURA_DEMO_WINDOW_TREE_HOST_VIEW_MANAGER_DELEGATE_H_ +#define MOJO_EXAMPLES_AURA_DEMO_WINDOW_TREE_HOST_VIEW_MANAGER_DELEGATE_H_ + +class SkBitmap; + +namespace mojo { + +class WindowTreeHostMojoDelegate { + public: + // Invoked when the contents of the composite associated with the + // WindowTreeHostMojo are updated. + virtual void CompositorContentsChanged(const SkBitmap& bitmap) = 0; + + protected: + virtual ~WindowTreeHostMojoDelegate() {} +}; + +} // namespace mojo + +#endif // MOJO_EXAMPLES_AURA_DEMO_WINDOW_TREE_HOST_VIEW_MANAGER_DELEGATE_H_ |