diff options
author | sky <sky@chromium.org> | 2014-10-07 12:53:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-07 19:53:38 +0000 |
commit | 9e877c0132baa5ac52186addf7bf31c4521b105b (patch) | |
tree | e32f2ca9858edb466df7ba5d21457c1ecedd5020 /mojo | |
parent | 00425c257e1d5a9cf8c7f0bd9e4d05904cda3f5b (diff) | |
download | chromium_src-9e877c0132baa5ac52186addf7bf31c4521b105b.zip chromium_src-9e877c0132baa5ac52186addf7bf31c4521b105b.tar.gz chromium_src-9e877c0132baa5ac52186addf7bf31c4521b105b.tar.bz2 |
Makes it so each mojo::View outputs a surface
I didn't remove SetContents yet. There is one consumer that needs to
converted. I'll do that separately.
BUG=none
TEST=none
R=ben@chromium.org, jamesr@chromium.org
Review URL: https://codereview.chromium.org/618073005
Cr-Commit-Position: refs/heads/master@{#298546}
Diffstat (limited to 'mojo')
31 files changed, 503 insertions, 354 deletions
diff --git a/mojo/aura/BUILD.gn b/mojo/aura/BUILD.gn index f6d6450..62d135f 100644 --- a/mojo/aura/BUILD.gn +++ b/mojo/aura/BUILD.gn @@ -7,13 +7,14 @@ source_set("aura") { sources = [ "aura_init.cc", "aura_init.h", - "context_factory_mojo.cc", - "context_factory_mojo.h", "screen_mojo.cc", "screen_mojo.h", + "surface_binding.cc", + "surface_binding.h", + "surface_context_factory.cc", + "surface_context_factory.h", "window_tree_host_mojo.cc", "window_tree_host_mojo.h", - "window_tree_host_mojo_delegate.h", ] public_deps = [ @@ -28,7 +29,14 @@ source_set("aura") { "//ui/events:events_base", "//ui/gl", "//mojo/cc", + "//mojo/public/cpp/application", "//mojo/public/gles2:for_shared_library", + "//mojo/public/interfaces/application:application", + "//mojo/services/public/cpp/geometry", + "//mojo/services/public/cpp/surfaces", + "//mojo/services/public/cpp/view_manager", + "//mojo/services/public/interfaces/gpu", "//mojo/services/public/interfaces/native_viewport", + "//mojo/services/public/interfaces/surfaces", ] } diff --git a/mojo/aura/aura_init.cc b/mojo/aura/aura_init.cc index df17ab7..39b2fee 100644 --- a/mojo/aura/aura_init.cc +++ b/mojo/aura/aura_init.cc @@ -4,7 +4,6 @@ #include "mojo/aura/aura_init.h" -#include "mojo/aura/context_factory_mojo.h" #include "mojo/aura/screen_mojo.h" #include "ui/aura/env.h" @@ -13,9 +12,6 @@ namespace mojo { AuraInit::AuraInit() { aura::Env::CreateInstance(false); - context_factory_.reset(new ContextFactoryMojo); - aura::Env::GetInstance()->set_context_factory(context_factory_.get()); - screen_.reset(ScreenMojo::Create()); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); } diff --git a/mojo/aura/aura_init.h b/mojo/aura/aura_init.h index dea1684..3f59449 100644 --- a/mojo/aura/aura_init.h +++ b/mojo/aura/aura_init.h @@ -7,10 +7,6 @@ #include "base/memory/scoped_ptr.h" -namespace ui { -class ContextFactory; -} - namespace mojo { class ScreenMojo; @@ -22,7 +18,6 @@ class AuraInit { ~AuraInit(); private: - scoped_ptr<ui::ContextFactory> context_factory_; scoped_ptr<ScreenMojo> screen_; DISALLOW_COPY_AND_ASSIGN(AuraInit); diff --git a/mojo/aura/context_factory_mojo.cc b/mojo/aura/context_factory_mojo.cc deleted file mode 100644 index 5b55cba..0000000 --- a/mojo/aura/context_factory_mojo.cc +++ /dev/null @@ -1,137 +0,0 @@ -// 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 "base/macros.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/surface_binding.cc b/mojo/aura/surface_binding.cc new file mode 100644 index 0000000..ada166e --- /dev/null +++ b/mojo/aura/surface_binding.cc @@ -0,0 +1,251 @@ +// 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/surface_binding.h" + +#include <map> + +#include "base/bind.h" +#include "base/lazy_instance.h" +#include "base/threading/thread_local.h" +#include "cc/output/compositor_frame.h" +#include "cc/output/output_surface.h" +#include "cc/output/output_surface_client.h" +#include "cc/output/software_output_device.h" +#include "cc/resources/shared_bitmap_manager.h" +#include "mojo/aura/window_tree_host_mojo.h" +#include "mojo/cc/context_provider_mojo.h" +#include "mojo/cc/output_surface_mojo.h" +#include "mojo/public/cpp/application/connect.h" +#include "mojo/public/interfaces/application/shell.mojom.h" +#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" +#include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" +#include "mojo/services/public/cpp/view_manager/view.h" +#include "mojo/services/public/cpp/view_manager/view_manager.h" +#include "mojo/services/public/interfaces/gpu/gpu.mojom.h" +#include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h" +#include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h" + +namespace mojo { +namespace { + +// SurfaceclientImpl ----------------------------------------------------------- + +class SurfaceClientImpl : public SurfaceClient { + public: + SurfaceClientImpl() {} + virtual ~SurfaceClientImpl() {} + + // SurfaceClient: + virtual void ReturnResources(Array<ReturnedResourcePtr> resources) override { + // TODO (sky|jamesr): figure out right way to recycle resources. + } + + private: + DISALLOW_COPY_AND_ASSIGN(SurfaceClientImpl); +}; + +// OutputSurface --------------------------------------------------------------- + +// OutputSurface implementation for a view. Pushes the surface id to View when +// appropriate. +class OutputSurfaceImpl : public cc::OutputSurface { + public: + OutputSurfaceImpl(View* view, + const scoped_refptr<cc::ContextProvider>& context_provider, + Surface* surface, + cc::SurfaceIdAllocator* id_allocator); + virtual ~OutputSurfaceImpl(); + + // cc::OutputSurface: + virtual void SwapBuffers(cc::CompositorFrame* frame) override; + + private: + View* view_; + Surface* surface_; + cc::SurfaceIdAllocator* id_allocator_; + cc::SurfaceId surface_id_; + gfx::Size surface_size_; + + DISALLOW_COPY_AND_ASSIGN(OutputSurfaceImpl); +}; + +OutputSurfaceImpl::OutputSurfaceImpl( + View* view, + const scoped_refptr<cc::ContextProvider>& context_provider, + Surface* surface, + cc::SurfaceIdAllocator* id_allocator) + : cc::OutputSurface(context_provider), + view_(view), + surface_(surface), + id_allocator_(id_allocator) { + capabilities_.delegated_rendering = true; + capabilities_.max_frames_pending = 1; +} + +OutputSurfaceImpl::~OutputSurfaceImpl() { +} + +void OutputSurfaceImpl::SwapBuffers(cc::CompositorFrame* frame) { + gfx::Size frame_size = + frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); + if (frame_size != surface_size_) { + if (!surface_id_.is_null()) + surface_->DestroySurface(SurfaceId::From(surface_id_)); + surface_id_ = id_allocator_->GenerateId(); + surface_->CreateSurface(SurfaceId::From(surface_id_), + Size::From(frame_size)); + view_->SetSurfaceId(SurfaceId::From(surface_id_)); + surface_size_ = frame_size; + } + + surface_->SubmitFrame(SurfaceId::From(surface_id_), Frame::From(*frame)); + + client_->DidSwapBuffers(); + client_->DidSwapBuffersComplete(); +} + +} // namespace + +// PerViewManagerState --------------------------------------------------------- + +// State needed per ViewManager. Provides the real implementation of +// CreateOutputSurface. SurfaceBinding obtains a pointer to the +// PerViewManagerState appropriate for the ViewManager. PerViewManagerState is +// stored in a thread local map. When no more refereces to a PerViewManagerState +// remain the PerViewManagerState is deleted and the underlying map cleaned up. +class SurfaceBinding::PerViewManagerState + : public base::RefCounted<PerViewManagerState> { + public: + static PerViewManagerState* Get(Shell* shell, ViewManager* view_manager); + + scoped_ptr<cc::OutputSurface> CreateOutputSurface(View* view); + + private: + typedef std::map<ViewManager*, PerViewManagerState*> ViewManagerToStateMap; + + friend class base::RefCounted<PerViewManagerState>; + + PerViewManagerState(Shell* shell, ViewManager* view_manager); + ~PerViewManagerState(); + + void Init(); + + // Callback when a Surface has been created. + void OnCreatedSurfaceConnection(SurfacePtr surface, uint32_t id_namespace); + + static base::LazyInstance< + base::ThreadLocalPointer<ViewManagerToStateMap>>::Leaky view_states; + + Shell* shell_; + ViewManager* view_manager_; + + // Set of state needed to create an OutputSurface. + scoped_ptr<SurfaceClient> surface_client_; + GpuPtr gpu_; + SurfacePtr surface_; + SurfacesServicePtr surfaces_service_; + scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; + + DISALLOW_COPY_AND_ASSIGN(PerViewManagerState); +}; + +// static +base::LazyInstance<base::ThreadLocalPointer< + SurfaceBinding::PerViewManagerState::ViewManagerToStateMap>>::Leaky + SurfaceBinding::PerViewManagerState::view_states; + +// static +SurfaceBinding::PerViewManagerState* SurfaceBinding::PerViewManagerState::Get( + Shell* shell, + ViewManager* view_manager) { + ViewManagerToStateMap* view_map = view_states.Pointer()->Get(); + if (!view_map) { + view_map = new ViewManagerToStateMap; + view_states.Pointer()->Set(view_map); + } + if (!(*view_map)[view_manager]) { + (*view_map)[view_manager] = new PerViewManagerState(shell, view_manager); + (*view_map)[view_manager]->Init(); + } + return (*view_map)[view_manager]; +} + +scoped_ptr<cc::OutputSurface> +SurfaceBinding::PerViewManagerState::CreateOutputSurface(View* view) { + // TODO(sky): figure out lifetime here. Do I need to worry about the return + // value outliving this? + CommandBufferPtr cb; + gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); + scoped_refptr<cc::ContextProvider> context_provider( + new ContextProviderMojo(cb.PassMessagePipe())); + return scoped_ptr<cc::OutputSurface>(new OutputSurfaceImpl( + view, context_provider, surface_.get(), surface_id_allocator_.get())); +} + +SurfaceBinding::PerViewManagerState::PerViewManagerState( + Shell* shell, + ViewManager* view_manager) + : shell_(shell), view_manager_(view_manager) { +} + +SurfaceBinding::PerViewManagerState::~PerViewManagerState() { + ViewManagerToStateMap* view_map = view_states.Pointer()->Get(); + DCHECK(view_map); + DCHECK_EQ(this, (*view_map)[view_manager_]); + view_map->erase(view_manager_); + if (view_map->empty()) { + delete view_map; + view_states.Pointer()->Set(nullptr); + } +} + +void SurfaceBinding::PerViewManagerState::Init() { + DCHECK(!surfaces_service_.get()); + + ServiceProviderPtr surfaces_service_provider; + shell_->ConnectToApplication("mojo:mojo_surfaces_service", + GetProxy(&surfaces_service_provider)); + ConnectToService(surfaces_service_provider.get(), &surfaces_service_); + // base::Unretained is ok here as we block until the call is received. + surfaces_service_->CreateSurfaceConnection( + base::Bind(&PerViewManagerState::OnCreatedSurfaceConnection, + base::Unretained(this))); + // Block until we get the surface. This is done to make it easy for client + // code. OTOH blocking is ick and leads to all sorts of problems. + // TODO(sky): ick! There needs to be a better way to deal with this. + surfaces_service_.WaitForIncomingMethodCall(); + DCHECK(surface_.get()); + surface_client_.reset(new SurfaceClientImpl); + surface_.set_client(surface_client_.get()); + + ServiceProviderPtr gpu_service_provider; + // TODO(jamesr): Should be mojo:mojo_gpu_service + shell_->ConnectToApplication("mojo:mojo_native_viewport_service", + GetProxy(&gpu_service_provider)); + ConnectToService(gpu_service_provider.get(), &gpu_); +} + +void SurfaceBinding::PerViewManagerState::OnCreatedSurfaceConnection( + SurfacePtr surface, + uint32_t id_namespace) { + surface_id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); + surface_ = surface.Pass(); +} + +// SurfaceBinding -------------------------------------------------------------- + +SurfaceBinding::SurfaceBinding(Shell* shell, View* view) + : view_(view), + state_(PerViewManagerState::Get(shell, view->view_manager())) { +} + +SurfaceBinding::~SurfaceBinding() { +} + +scoped_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { + return state_->CreateOutputSurface(view_); +} + +} // namespace mojo diff --git a/mojo/aura/surface_binding.h b/mojo/aura/surface_binding.h new file mode 100644 index 0000000..33f6eac --- /dev/null +++ b/mojo/aura/surface_binding.h @@ -0,0 +1,45 @@ +// 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_SURFACE_BINDING_H_ +#define MOJO_AURA_SURFACE_BINDING_H_ + +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" + +namespace cc { +class OutputSurface; +} + +namespace mojo { +class Shell; +class View; + +// SurfaceBinding is responsible for managing the connections necessary to +// bind a View to the surfaces service. +// Internally SurfaceBinding manages one connection (and related structures) per +// ViewManager. That is, all Views from a particular ViewManager share the same +// connection. +class SurfaceBinding { + public: + SurfaceBinding(Shell* shell, View* view); + ~SurfaceBinding(); + + // Creates an OutputSurface that renders to the View supplied to the + // constructor. + scoped_ptr<cc::OutputSurface> CreateOutputSurface(); + + private: + class PerViewManagerState; + + Shell* shell_; + View* view_; + scoped_refptr<PerViewManagerState> state_; + + DISALLOW_COPY_AND_ASSIGN(SurfaceBinding); +}; + +} // namespace mojo + +#endif // MOJO_AURA_SURFACE_BINDING_H_ diff --git a/mojo/aura/surface_context_factory.cc b/mojo/aura/surface_context_factory.cc new file mode 100644 index 0000000..1e56029 --- /dev/null +++ b/mojo/aura/surface_context_factory.cc @@ -0,0 +1,58 @@ +// 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/surface_context_factory.h" + +#include "cc/output/output_surface.h" +#include "cc/resources/shared_bitmap_manager.h" +#include "mojo/public/interfaces/application/shell.mojom.h" +#include "mojo/services/public/cpp/view_manager/view.h" +#include "ui/compositor/reflector.h" + +namespace mojo { + +SurfaceContextFactory::SurfaceContextFactory(Shell* shell, View* view) + : surface_binding_(shell, view) { +} + +SurfaceContextFactory::~SurfaceContextFactory() { +} + +scoped_ptr<cc::OutputSurface> SurfaceContextFactory::CreateOutputSurface( + ui::Compositor* compositor, + bool software_fallback) { + return surface_binding_.CreateOutputSurface(); +} + +scoped_refptr<ui::Reflector> SurfaceContextFactory::CreateReflector( + ui::Compositor* mirroed_compositor, + ui::Layer* mirroring_layer) { + return new ui::Reflector(); +} + +void SurfaceContextFactory::RemoveReflector( + scoped_refptr<ui::Reflector> reflector) { +} + +scoped_refptr<cc::ContextProvider> +SurfaceContextFactory::SharedMainThreadContextProvider() { + return nullptr; +} + +void SurfaceContextFactory::RemoveCompositor(ui::Compositor* compositor) { +} + +bool SurfaceContextFactory::DoesCreateTestContexts() { + return false; +} + +cc::SharedBitmapManager* SurfaceContextFactory::GetSharedBitmapManager() { + return nullptr; +} + +base::MessageLoopProxy* SurfaceContextFactory::GetCompositorMessageLoop() { + return nullptr; +} + +} // namespace mojo diff --git a/mojo/aura/context_factory_mojo.h b/mojo/aura/surface_context_factory.h index 437359d..dc0e8d0 100644 --- a/mojo/aura/context_factory_mojo.h +++ b/mojo/aura/surface_context_factory.h @@ -2,18 +2,20 @@ // 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_ +#ifndef MOJO_AURA_SURFACE_CONTEXT_FACTORY_H_ +#define MOJO_AURA_SURFACE_CONTEXT_FACTORY_H_ -#include "base/macros.h" +#include "mojo/aura/surface_binding.h" #include "ui/compositor/compositor.h" namespace mojo { +class Shell; +class View; -class ContextFactoryMojo : public ui::ContextFactory { +class SurfaceContextFactory : public ui::ContextFactory { public: - ContextFactoryMojo(); - virtual ~ContextFactoryMojo(); + SurfaceContextFactory(Shell* shell, View* view); + virtual ~SurfaceContextFactory(); private: // ContextFactory: @@ -31,11 +33,11 @@ class ContextFactoryMojo : public ui::ContextFactory { virtual cc::SharedBitmapManager* GetSharedBitmapManager() override; virtual base::MessageLoopProxy* GetCompositorMessageLoop() override; - scoped_ptr<cc::SharedBitmapManager> shared_bitmap_manager_; + SurfaceBinding surface_binding_; - DISALLOW_COPY_AND_ASSIGN(ContextFactoryMojo); + DISALLOW_COPY_AND_ASSIGN(SurfaceContextFactory); }; } // namespace mojo -#endif // MOJO_AURA_CONTEXT_FACTORY_MOJO_H_ +#endif // MOJO_AURA_SURFACE_CONTEXT_FACTORY_H_ diff --git a/mojo/aura/window_tree_host_mojo.cc b/mojo/aura/window_tree_host_mojo.cc index 8ef87c6..9f30e13 100644 --- a/mojo/aura/window_tree_host_mojo.cc +++ b/mojo/aura/window_tree_host_mojo.cc @@ -4,9 +4,9 @@ #include "mojo/aura/window_tree_host_mojo.h" -#include <vector> - -#include "mojo/aura/window_tree_host_mojo_delegate.h" +#include "mojo/aura/surface_context_factory.h" +#include "mojo/public/interfaces/application/shell.mojom.h" +#include "mojo/services/public/cpp/view_manager/view_manager.h" #include "ui/aura/env.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" @@ -14,86 +14,32 @@ #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(View* view, - WindowTreeHostMojoDelegate* delegate) - : view_(view), - bounds_(view->bounds()), - delegate_(delegate) { +WindowTreeHostMojo::WindowTreeHostMojo(Shell* shell, View* view) + : view_(view), bounds_(view->bounds()) { view_->AddObserver(this); - CreateCompositor(GetAcceleratedWidget()); - TreeHosts::Get()->Add(this); + context_factory_.reset(new SurfaceContextFactory(shell, view_)); + // WindowTreeHost creates the compositor using the ContextFactory from + // aura::Env. Install |context_factory_| there so that |context_factory_| is + // picked up. + ui::ContextFactory* default_context_factory = + aura::Env::GetInstance()->context_factory(); + aura::Env::GetInstance()->set_context_factory(context_factory_.get()); + CreateCompositor(GetAcceleratedWidget()); + aura::Env::GetInstance()->set_context_factory(default_context_factory); + DCHECK_EQ(context_factory_.get(), compositor()->context_factory()); } WindowTreeHostMojo::~WindowTreeHostMojo() { view_->RemoveObserver(this); - 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: diff --git a/mojo/aura/window_tree_host_mojo.h b/mojo/aura/window_tree_host_mojo.h index af00203..f43e90d 100644 --- a/mojo/aura/window_tree_host_mojo.h +++ b/mojo/aura/window_tree_host_mojo.h @@ -19,24 +19,18 @@ class Compositor; namespace mojo { -class WindowTreeHostMojoDelegate; +class Shell; +class SurfaceContextFactory; class WindowTreeHostMojo : public aura::WindowTreeHost, public ui::EventSource, public ViewObserver { public: - WindowTreeHostMojo(View* view, WindowTreeHostMojoDelegate* delegate); + WindowTreeHostMojo(Shell* shell, View* view); 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); - ui::EventDispatchDetails SendEventToProcessor(ui::Event* event) { return ui::EventSource::SendEventToProcessor(event); } @@ -69,7 +63,7 @@ class WindowTreeHostMojo : public aura::WindowTreeHost, gfx::Rect bounds_; - WindowTreeHostMojoDelegate* delegate_; + scoped_ptr<SurfaceContextFactory> context_factory_; DISALLOW_COPY_AND_ASSIGN(WindowTreeHostMojo); }; diff --git a/mojo/aura/window_tree_host_mojo_delegate.h b/mojo/aura/window_tree_host_mojo_delegate.h deleted file mode 100644 index 9ab13b2..0000000 --- a/mojo/aura/window_tree_host_mojo_delegate.h +++ /dev/null @@ -1,24 +0,0 @@ -// 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_ diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc index 1895761..917ea61 100644 --- a/mojo/examples/aura_demo/aura_demo.cc +++ b/mojo/examples/aura_demo/aura_demo.cc @@ -8,10 +8,8 @@ #include "base/bind.h" #include "base/macros.h" #include "mojo/application/application_runner_chromium.h" -#include "mojo/aura/context_factory_mojo.h" #include "mojo/aura/screen_mojo.h" #include "mojo/aura/window_tree_host_mojo.h" -#include "mojo/aura/window_tree_host_mojo_delegate.h" #include "mojo/public/c/system/main.h" #include "mojo/public/cpp/application/application_connection.h" #include "mojo/public/cpp/application/application_delegate.h" @@ -107,10 +105,10 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient { }; class AuraDemo : public mojo::ApplicationDelegate, - public mojo::WindowTreeHostMojoDelegate, public mojo::ViewManagerDelegate { public: - AuraDemo() : window1_(NULL), window2_(NULL), window21_(NULL) {} + AuraDemo() + : shell_(nullptr), window1_(NULL), window2_(NULL), window21_(NULL) {} virtual ~AuraDemo() {} private: @@ -123,7 +121,7 @@ class AuraDemo : public mojo::ApplicationDelegate, // TODO(beng): this function could be called multiple times! root_ = root; - window_tree_host_.reset(new mojo::WindowTreeHostMojo(root, this)); + window_tree_host_.reset(new mojo::WindowTreeHostMojo(shell_, root)); window_tree_host_->InitHost(); window_tree_client_.reset( @@ -157,17 +155,11 @@ class AuraDemo : public mojo::ApplicationDelegate, base::MessageLoop::current()->Quit(); } - // WindowTreeHostMojoDelegate: - virtual void CompositorContentsChanged(const SkBitmap& bitmap) override { - root_->SetContents(bitmap); - } - virtual void Initialize(mojo::ApplicationImpl* app) override { + shell_ = app->shell(); view_manager_client_factory_.reset( - new mojo::ViewManagerClientFactory(app->shell(), this)); + new mojo::ViewManagerClientFactory(shell_, this)); aura::Env::CreateInstance(true); - context_factory_.reset(new mojo::ContextFactoryMojo); - aura::Env::GetInstance()->set_context_factory(context_factory_.get()); screen_.reset(mojo::ScreenMojo::Create()); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); } @@ -178,9 +170,9 @@ class AuraDemo : public mojo::ApplicationDelegate, return true; } - scoped_ptr<DemoWindowTreeClient> window_tree_client_; + mojo::Shell* shell_; - scoped_ptr<ui::ContextFactory> context_factory_; + scoped_ptr<DemoWindowTreeClient> window_tree_client_; scoped_ptr<mojo::ScreenMojo> screen_; diff --git a/mojo/examples/browser/browser.cc b/mojo/examples/browser/browser.cc index 2a77f89..2f22d16 100644 --- a/mojo/examples/browser/browser.cc +++ b/mojo/examples/browser/browser.cc @@ -155,9 +155,7 @@ class Browser : public ApplicationDelegate, public ViewObserver { public: Browser() - : view_manager_(NULL), - root_(NULL), - widget_(NULL) {} + : shell_(nullptr), view_manager_(NULL), root_(NULL), widget_(NULL) {} virtual ~Browser() { if (root_) @@ -167,8 +165,9 @@ class Browser : public ApplicationDelegate, private: // Overridden from ApplicationDelegate: virtual void Initialize(ApplicationImpl* app) override { + shell_ = app->shell(); view_manager_client_factory_.reset( - new ViewManagerClientFactory(app->shell(), this)); + new ViewManagerClientFactory(shell_, this)); views_init_.reset(new ViewsInit); app->ConnectToService("mojo:mojo_window_manager", &window_manager_); } @@ -193,7 +192,7 @@ class Browser : public ApplicationDelegate, widget_ = new views::Widget; views::Widget::InitParams params( views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - params.native_widget = new NativeWidgetViewManager(widget_, view); + params.native_widget = new NativeWidgetViewManager(widget_, shell_, view); params.delegate = widget_delegate; params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height()); widget_->Init(params); @@ -252,6 +251,8 @@ class Browser : public ApplicationDelegate, root_ = NULL; } + Shell* shell_; + scoped_ptr<ViewsInit> views_init_; ViewManager* view_manager_; diff --git a/mojo/examples/keyboard/keyboard.cc b/mojo/examples/keyboard/keyboard.cc index 8eae684..3cd4a4e 100644 --- a/mojo/examples/keyboard/keyboard.cc +++ b/mojo/examples/keyboard/keyboard.cc @@ -51,7 +51,8 @@ class Keyboard : public ApplicationDelegate, public KeyboardDelegate { public: Keyboard() - : keyboard_service_factory_(this), + : shell_(nullptr), + keyboard_service_factory_(this), view_manager_(NULL), keyboard_service_(NULL), target_(0) {} @@ -68,8 +69,9 @@ class Keyboard : public ApplicationDelegate, private: // Overridden from ApplicationDelegate: virtual void Initialize(ApplicationImpl* app) override { + shell_ = app->shell(); view_manager_client_factory_.reset( - new ViewManagerClientFactory(app->shell(), this)); + new ViewManagerClientFactory(shell_, this)); } virtual bool ConfigureIncomingConnection( @@ -88,7 +90,7 @@ class Keyboard : public ApplicationDelegate, views::Widget* widget = new views::Widget; views::Widget::InitParams params( views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - params.native_widget = new NativeWidgetViewManager(widget, view); + params.native_widget = new NativeWidgetViewManager(widget, shell_, view); params.delegate = widget_delegate; params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height()); widget->Init(params); @@ -119,6 +121,8 @@ class Keyboard : public ApplicationDelegate, event_flags); } + Shell* shell_; + InterfaceFactoryImplWithContext<KeyboardServiceImpl, Keyboard> keyboard_service_factory_; diff --git a/mojo/examples/media_viewer/media_viewer.cc b/mojo/examples/media_viewer/media_viewer.cc index 33cf200..9aece56 100644 --- a/mojo/examples/media_viewer/media_viewer.cc +++ b/mojo/examples/media_viewer/media_viewer.cc @@ -134,11 +134,12 @@ class ControlPanel : public views::ButtonListener { virtual void ButtonPressed(ControlType type) = 0; }; - ControlPanel(Delegate* delegate) : delegate_(delegate), buttons_() {} + explicit ControlPanel(Delegate* delegate) + : delegate_(delegate), shell_(nullptr), buttons_() {} virtual ~ControlPanel() {} - void Initialize(View* view) { + void Initialize(View* view, Shell* shell) { const char* kNames[] = { "Zoom In", "Actual Size", "Zoom Out" }; views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; @@ -160,7 +161,7 @@ class ControlPanel : public views::ButtonListener { views::Widget* widget = new views::Widget; views::Widget::InitParams params( views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - params.native_widget = new NativeWidgetViewManager(widget, view); + params.native_widget = new NativeWidgetViewManager(widget, shell, view); params.delegate = widget_delegate; params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height()); params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; @@ -181,6 +182,7 @@ class ControlPanel : public views::ButtonListener { } Delegate* delegate_; + Shell* shell_; views::Button* buttons_[CONTROL_COUNT]; DISALLOW_COPY_AND_ASSIGN(ControlPanel); @@ -193,7 +195,8 @@ class MediaViewer public ViewObserver { public: MediaViewer() - : app_(NULL), + : shell_(nullptr), + app_(NULL), view_manager_(NULL), root_view_(NULL), control_view_(NULL), @@ -213,6 +216,7 @@ class MediaViewer // Overridden from ApplicationDelegate: virtual void Initialize(ApplicationImpl* app) override { + shell_ = app->shell(); view_manager_client_factory_.reset( new ViewManagerClientFactory(app->shell(), this)); app_ = app; @@ -248,7 +252,7 @@ class MediaViewer content_view_ = View::Create(view_manager_); root_view_->AddChild(content_view_); - control_panel_.Initialize(control_view_); + control_panel_.Initialize(control_view_, shell_); LayoutViews(); root_view_->AddObserver(this); @@ -297,6 +301,8 @@ class MediaViewer return it != handler_map_.end() ? it->second : std::string(); } + Shell* shell_; + scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; ApplicationImpl* app_; diff --git a/mojo/examples/window_manager/debug_panel.cc b/mojo/examples/window_manager/debug_panel.cc index c65785c..7d86cfe 100644 --- a/mojo/examples/window_manager/debug_panel.cc +++ b/mojo/examples/window_manager/debug_panel.cc @@ -24,23 +24,27 @@ const int kNavigationTargetGroupId = 1; } // namespace -DebugPanel::DebugPanel(Delegate* delegate, View* view) +DebugPanel::DebugPanel(Delegate* delegate, Shell* shell, View* view) : delegate_(delegate), view_(view), - navigation_target_label_(new views::Label( - base::ASCIIToUTF16("Navigation target:"))), - navigation_target_new_(new views::RadioButton( - base::ASCIIToUTF16("New window"), kNavigationTargetGroupId)), - navigation_target_source_(new views::RadioButton( - base::ASCIIToUTF16("Source window"), kNavigationTargetGroupId)), - navigation_target_default_(new views::RadioButton( - base::ASCIIToUTF16("Default"), kNavigationTargetGroupId)), - colored_square_(new views::BlueButton( - this, base::ASCIIToUTF16("Local nav test"))), - close_last_(new views::BlueButton( - this, base::ASCIIToUTF16("Close last window"))), - cross_app_(new views::BlueButton( - this, base::ASCIIToUTF16("Cross-app nav test"))) { + navigation_target_label_( + new views::Label(base::ASCIIToUTF16("Navigation target:"))), + navigation_target_new_( + new views::RadioButton(base::ASCIIToUTF16("New window"), + kNavigationTargetGroupId)), + navigation_target_source_( + new views::RadioButton(base::ASCIIToUTF16("Source window"), + kNavigationTargetGroupId)), + navigation_target_default_( + new views::RadioButton(base::ASCIIToUTF16("Default"), + kNavigationTargetGroupId)), + colored_square_( + new views::BlueButton(this, base::ASCIIToUTF16("Local nav test"))), + close_last_( + new views::BlueButton(this, base::ASCIIToUTF16("Close last window"))), + cross_app_( + new views::BlueButton(this, + base::ASCIIToUTF16("Cross-app nav test"))) { navigation_target_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); navigation_target_default_->SetChecked(true); @@ -59,7 +63,7 @@ DebugPanel::DebugPanel(Delegate* delegate, View* view) views::Widget* widget = new views::Widget(); views::Widget::InitParams params( views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - params.native_widget = new NativeWidgetViewManager(widget, view); + params.native_widget = new NativeWidgetViewManager(widget, shell, view); params.delegate = widget_delegate; params.bounds = gfx::Rect(view->bounds().size()); widget->Init(params); diff --git a/mojo/examples/window_manager/debug_panel.h b/mojo/examples/window_manager/debug_panel.h index 160e400..eec3067 100644 --- a/mojo/examples/window_manager/debug_panel.h +++ b/mojo/examples/window_manager/debug_panel.h @@ -20,13 +20,11 @@ class RadioButton; namespace mojo { +class Shell; class View; namespace examples { -namespace { -} - // A panel of controls intended to demonstrate the functionality of the window // manager. class DebugPanel : public views::LayoutManager, public views::ButtonListener { @@ -42,7 +40,7 @@ class DebugPanel : public views::LayoutManager, public views::ButtonListener { virtual ~Delegate(){} }; - DebugPanel(Delegate* delegate, View* view); + DebugPanel(Delegate* delegate, Shell* shell, View* view); virtual ~DebugPanel(); Target navigation_target() const; @@ -57,6 +55,7 @@ class DebugPanel : public views::LayoutManager, public views::ButtonListener { void Navigate(const std::string& url); Delegate* delegate_; + Shell* shell_; View* view_; views::Label* navigation_target_label_; diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc index 2cb5458..fbbf074 100644 --- a/mojo/examples/window_manager/window_manager.cc +++ b/mojo/examples/window_manager/window_manager.cc @@ -340,7 +340,8 @@ class WindowManager public ui::EventHandler { public: WindowManager() - : window_manager_factory_(this), + : shell_(nullptr), + window_manager_factory_(this), launcher_ui_(NULL), view_manager_(NULL), window_manager_app_(new WindowManagerApp(this, this)), @@ -408,6 +409,7 @@ class WindowManager // Overridden from ApplicationDelegate: virtual void Initialize(ApplicationImpl* app) override { + shell_ = app->shell(); app_ = app; views_init_.reset(new ViewsInit); window_manager_app_->Initialize(app); @@ -558,7 +560,7 @@ class WindowManager kTextfieldHeight); view->SetBounds(bounds); - debug_panel_ = new DebugPanel(this, view); + debug_panel_ = new DebugPanel(this, shell_, view); return view->id(); } @@ -573,6 +575,8 @@ class WindowManager return windows_.end(); } + Shell* shell_; + InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager> window_manager_factory_; diff --git a/mojo/examples/wm_flow/wm/frame_controller.cc b/mojo/examples/wm_flow/wm/frame_controller.cc index 7ed1dac..40ff041 100644 --- a/mojo/examples/wm_flow/wm/frame_controller.cc +++ b/mojo/examples/wm_flow/wm/frame_controller.cc @@ -95,6 +95,7 @@ class FrameController::FrameEventHandler : public ui::EventHandler { // FrameController, public: FrameController::FrameController( + mojo::Shell* shell, mojo::View* view, mojo::View** app_view, aura::client::ActivationClient* activation_client, @@ -117,7 +118,8 @@ FrameController::FrameController( frame_view_->AddPreTargetHandler(frame_event_handler_.get()); views::Widget::InitParams params( views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - params.native_widget = new mojo::NativeWidgetViewManager(widget_, view_); + params.native_widget = + new mojo::NativeWidgetViewManager(widget_, shell, view_); params.bounds = gfx::Rect(view_->bounds().size()); widget_->Init(params); widget_->SetContentsView(frame_view_); diff --git a/mojo/examples/wm_flow/wm/frame_controller.h b/mojo/examples/wm_flow/wm/frame_controller.h index 2c7d9e9..0add0a1 100644 --- a/mojo/examples/wm_flow/wm/frame_controller.h +++ b/mojo/examples/wm_flow/wm/frame_controller.h @@ -17,6 +17,7 @@ class ActivationClient; namespace mojo { class NativeWidgetViewManager; +class Shell; class View; class WindowManagerApp; } @@ -31,7 +32,8 @@ class Widget; // to any events targeted at it. class FrameController : mojo::ViewObserver { public: - FrameController(mojo::View* view, + FrameController(mojo::Shell* shell, + mojo::View* view, mojo::View** app_view, aura::client::ActivationClient* activation_client, mojo::WindowManagerApp* window_manager_app); diff --git a/mojo/examples/wm_flow/wm/wm.cc b/mojo/examples/wm_flow/wm/wm.cc index f2787fc..56d8b39 100644 --- a/mojo/examples/wm_flow/wm/wm.cc +++ b/mojo/examples/wm_flow/wm/wm.cc @@ -91,7 +91,8 @@ class SimpleWM : public mojo::ApplicationDelegate, public mojo::ViewObserver { public: SimpleWM() - : window_manager_app_(new mojo::WindowManagerApp(this, this)), + : shell_(nullptr), + window_manager_app_(new mojo::WindowManagerApp(this, this)), view_manager_(NULL), root_(NULL), window_container_(NULL), @@ -101,6 +102,7 @@ class SimpleWM : public mojo::ApplicationDelegate, private: // Overridden from mojo::ApplicationDelegate: virtual void Initialize(mojo::ApplicationImpl* impl) override { + shell_ = impl->shell(); window_manager_app_->Initialize(impl); } virtual bool ConfigureIncomingConnection( @@ -175,11 +177,13 @@ class SimpleWM : public mojo::ApplicationDelegate, aura::client::ActivationClient* client = aura::client::GetActivationClient( window_manager_app_->host()->window()); - new FrameController(frame_view, app_view, client, - window_manager_app_.get()); + new FrameController( + shell_, frame_view, app_view, client, window_manager_app_.get()); return frame_view; } + mojo::Shell* shell_; + scoped_ptr<mojo::WindowManagerApp> window_manager_app_; mojo::ViewManager* view_manager_; diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp index 96966b4..e927a20 100644 --- a/mojo/mojo.gyp +++ b/mojo/mojo.gyp @@ -530,7 +530,14 @@ '../ui/events/events.gyp:events', '../ui/events/events.gyp:events_base', 'mojo_cc_support', + 'mojo_geometry_lib', 'mojo_native_viewport_bindings', + 'mojo_gpu_bindings', + 'mojo_surfaces_bindings', + 'mojo_surfaces_lib', + 'mojo_view_manager_lib', + 'public/mojo_public.gyp:mojo_application_base', + 'public/mojo_public.gyp:mojo_application_bindings', ], 'includes': [ 'mojo_public_gles2_for_loadable_module.gypi', @@ -538,13 +545,14 @@ 'sources': [ 'aura/aura_init.cc', 'aura/aura_init.h', - 'aura/context_factory_mojo.cc', - 'aura/context_factory_mojo.h', 'aura/screen_mojo.cc', 'aura/screen_mojo.h', + 'aura/surface_binding.cc', + 'aura/surface_binding.h', + 'aura/surface_context_factory.cc', + 'aura/surface_context_factory.h', 'aura/window_tree_host_mojo.cc', 'aura/window_tree_host_mojo.h', - 'aura/window_tree_host_mojo_delegate.h', ], }, { @@ -564,6 +572,7 @@ 'mojo_aura_support', 'mojo_views_support_internal', 'mojo_view_manager_bindings', + 'mojo_view_manager_lib', ], 'sources': [ 'views/input_method_mojo_linux.cc', diff --git a/mojo/mojo_services.gypi b/mojo/mojo_services.gypi index 0e84e24..5c5bd7a 100644 --- a/mojo/mojo_services.gypi +++ b/mojo/mojo_services.gypi @@ -946,8 +946,8 @@ '../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx_geometry', '../ui/wm/wm.gyp:wm', - 'mojo_base.gyp:mojo_common_lib', 'mojo_base.gyp:mojo_application_chromium', + 'mojo_base.gyp:mojo_common_lib', 'mojo_aura_support', 'mojo_core_window_manager_bindings', 'mojo_input_events_lib', diff --git a/mojo/services/html_viewer/html_document_view.cc b/mojo/services/html_viewer/html_document_view.cc index 4fa4cdc..400d8cab 100644 --- a/mojo/services/html_viewer/html_document_view.cc +++ b/mojo/services/html_viewer/html_document_view.cc @@ -156,14 +156,14 @@ void HTMLDocumentView::initializeLayerTreeView() { ServiceProviderPtr surfaces_service_provider; shell_->ConnectToApplication("mojo:mojo_surfaces_service", GetProxy(&surfaces_service_provider)); - InterfacePtr<SurfacesService> surfaces_service; + SurfacesServicePtr surfaces_service; ConnectToService(surfaces_service_provider.get(), &surfaces_service); ServiceProviderPtr gpu_service_provider; // TODO(jamesr): Should be mojo:mojo_gpu_service shell_->ConnectToApplication("mojo:mojo_native_viewport_service", GetProxy(&gpu_service_provider)); - InterfacePtr<Gpu> gpu_service; + GpuPtr gpu_service; ConnectToService(gpu_service_provider.get(), &gpu_service); web_layer_tree_view_impl_.reset(new WebLayerTreeViewImpl( compositor_thread_, surfaces_service.Pass(), gpu_service.Pass())); diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h index 3a116f8..b236559 100644 --- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h +++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h @@ -19,10 +19,10 @@ class SkBitmap; namespace mojo { +class Shell; class ViewManager; class ViewManagerDelegate; class ViewManagerTransaction; -class Shell; // Manages the connection with the View Manager service. class ViewManagerClientImpl : public ViewManager, diff --git a/mojo/services/window_manager/BUILD.gn b/mojo/services/window_manager/BUILD.gn index b439775..8a93b2f 100644 --- a/mojo/services/window_manager/BUILD.gn +++ b/mojo/services/window_manager/BUILD.gn @@ -41,6 +41,7 @@ source_set("lib") { "//mojo/common", "//mojo/environment:chromium", "//mojo/public/cpp/bindings", + "//mojo/public/interfaces/application:application", "//mojo/services/public/cpp/input_events", "//mojo/services/public/cpp/view_manager", "//mojo/services/public/interfaces/window_manager", diff --git a/mojo/services/window_manager/window_manager_app.cc b/mojo/services/window_manager/window_manager_app.cc index 7609119..3f4c5f0 100644 --- a/mojo/services/window_manager/window_manager_app.cc +++ b/mojo/services/window_manager/window_manager_app.cc @@ -9,6 +9,7 @@ #include "mojo/aura/aura_init.h" #include "mojo/public/cpp/application/application_connection.h" #include "mojo/public/cpp/application/application_impl.h" +#include "mojo/public/interfaces/application/shell.mojom.h" #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" #include "mojo/services/public/cpp/view_manager/view.h" #include "mojo/services/public/cpp/view_manager/view_manager.h" @@ -79,7 +80,8 @@ Id GetIdForWindow(aura::Window* window) { WindowManagerApp::WindowManagerApp( ViewManagerDelegate* view_manager_delegate, WindowManagerDelegate* window_manager_delegate) - : window_manager_service_factory_(this), + : shell_(nullptr), + window_manager_service_factory_(this), wrapped_view_manager_delegate_(view_manager_delegate), wrapped_window_manager_delegate_(window_manager_delegate), view_manager_(NULL), @@ -147,9 +149,10 @@ void WindowManagerApp::InitFocus(wm::FocusRules* rules) { // WindowManagerApp, ApplicationDelegate implementation: void WindowManagerApp::Initialize(ApplicationImpl* impl) { + shell_ = impl->shell(); aura_init_.reset(new AuraInit); view_manager_client_factory_.reset( - new ViewManagerClientFactory(impl->shell(), this)); + new ViewManagerClientFactory(shell_, this)); } bool WindowManagerApp::ConfigureIncomingConnection( @@ -171,7 +174,7 @@ void WindowManagerApp::OnEmbed(ViewManager* view_manager, view_manager_->SetWindowManagerDelegate(this); root_ = root; - window_tree_host_.reset(new WindowTreeHostMojo(root_, this)); + window_tree_host_.reset(new WindowTreeHostMojo(shell_, root_)); window_tree_host_->window()->SetBounds(root->bounds()); window_tree_host_->window()->Show(); @@ -262,14 +265,6 @@ void WindowManagerApp::OnViewBoundsChanged(View* view, } //////////////////////////////////////////////////////////////////////////////// -// WindowManagerApp, WindowTreeHostMojoDelegate implementation: - -void WindowManagerApp::CompositorContentsChanged(const SkBitmap& bitmap) { - // We draw nothing. - NOTREACHED(); -} - -//////////////////////////////////////////////////////////////////////////////// // WindowManagerApp, ui::EventHandler implementation: void WindowManagerApp::OnEvent(ui::Event* event) { diff --git a/mojo/services/window_manager/window_manager_app.h b/mojo/services/window_manager/window_manager_app.h index 095832b..c168a16 100644 --- a/mojo/services/window_manager/window_manager_app.h +++ b/mojo/services/window_manager/window_manager_app.h @@ -9,7 +9,6 @@ #include "base/memory/scoped_ptr.h" #include "mojo/aura/window_tree_host_mojo.h" -#include "mojo/aura/window_tree_host_mojo_delegate.h" #include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/interface_factory_impl.h" #include "mojo/public/cpp/bindings/string.h" @@ -59,7 +58,6 @@ class WindowManagerApp public ViewManagerDelegate, public WindowManagerDelegate, public ViewObserver, - public WindowTreeHostMojoDelegate, public ui::EventHandler, public aura::client::FocusChangeObserver, public aura::client::ActivationChangeObserver { @@ -118,9 +116,6 @@ class WindowManagerApp const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) override; - // Overridden from WindowTreeHostMojoDelegate: - virtual void CompositorContentsChanged(const SkBitmap& bitmap) override; - // Overridden from ui::EventHandler: virtual void OnEvent(ui::Event* event) override; @@ -141,6 +136,8 @@ class WindowManagerApp // and removes from the registry. void UnregisterSubtree(View* view); + Shell* shell_; + InterfaceFactoryImplWithContext<WindowManagerServiceImpl, WindowManagerApp> window_manager_service_factory_; diff --git a/mojo/views/BUILD.gn b/mojo/views/BUILD.gn index 005654a..0e8e483 100644 --- a/mojo/views/BUILD.gn +++ b/mojo/views/BUILD.gn @@ -28,6 +28,7 @@ source_set("views") { "//ui/views", "//ui/wm", "//mojo/aura", + "//mojo/services/public/cpp/view_manager", ] } diff --git a/mojo/views/native_widget_view_manager.cc b/mojo/views/native_widget_view_manager.cc index 345f2cd..9927c89 100644 --- a/mojo/views/native_widget_view_manager.cc +++ b/mojo/views/native_widget_view_manager.cc @@ -95,11 +95,12 @@ class MinimalInputEventFilter : public ui::internal::InputMethodDelegate, } // namespace NativeWidgetViewManager::NativeWidgetViewManager( - views::internal::NativeWidgetDelegate* delegate, View* view) - : NativeWidgetAura(delegate), - view_(view) { + views::internal::NativeWidgetDelegate* delegate, + Shell* shell, + View* view) + : NativeWidgetAura(delegate), view_(view) { view_->AddObserver(this); - window_tree_host_.reset(new WindowTreeHostMojo(view_, this)); + window_tree_host_.reset(new WindowTreeHostMojo(shell, view_)); window_tree_host_->InitHost(); ime_filter_.reset( @@ -129,16 +130,12 @@ void NativeWidgetViewManager::InitNativeWidget( NativeWidgetAura::InitNativeWidget(params); } -void NativeWidgetViewManager::CompositorContentsChanged( - const SkBitmap& bitmap) { - if (view_) - view_->SetContents(bitmap); -} - void NativeWidgetViewManager::OnViewDestroyed(View* view) { DCHECK_EQ(view, view_); view->RemoveObserver(this); view_ = NULL; + // TODO(sky): WindowTreeHostMojo assumes the View outlives it. + // NativeWidgetViewManager needs to deal, likely by deleting this. } void NativeWidgetViewManager::OnViewBoundsChanged(View* view, diff --git a/mojo/views/native_widget_view_manager.h b/mojo/views/native_widget_view_manager.h index dc3cb73..499a766 100644 --- a/mojo/views/native_widget_view_manager.h +++ b/mojo/views/native_widget_view_manager.h @@ -5,7 +5,6 @@ #ifndef MOJO_VIEWS_NATIVE_WIDGET_VIEW_MANAGER_H_ #define MOJO_VIEWS_NATIVE_WIDGET_VIEW_MANAGER_H_ -#include "mojo/aura/window_tree_host_mojo_delegate.h" #include "mojo/services/public/cpp/view_manager/view_observer.h" #include "ui/views/widget/native_widget_aura.h" @@ -27,13 +26,14 @@ class FocusController; namespace mojo { +class Shell; class WindowTreeHostMojo; class NativeWidgetViewManager : public views::NativeWidgetAura, - public WindowTreeHostMojoDelegate, public ViewObserver { public: NativeWidgetViewManager(views::internal::NativeWidgetDelegate* delegate, + Shell* shell, View* view); virtual ~NativeWidgetViewManager(); @@ -42,9 +42,6 @@ class NativeWidgetViewManager : public views::NativeWidgetAura, virtual void InitNativeWidget( const views::Widget::InitParams& in_params) override; - // WindowTreeHostMojoDelegate: - virtual void CompositorContentsChanged(const SkBitmap& bitmap) override; - // ViewObserver: virtual void OnViewDestroyed(View* view) override; virtual void OnViewBoundsChanged(View* view, |