Chromium Code Reviews| Index: mojo/services/view_manager/display_manager.cc |
| diff --git a/mojo/services/view_manager/display_manager.cc b/mojo/services/view_manager/display_manager.cc |
| index 34dac52856bd3618cc510825041ead86424dbd0a..80600342c399538f13b234b0788f1caea36c0536 100644 |
| --- a/mojo/services/view_manager/display_manager.cc |
| +++ b/mojo/services/view_manager/display_manager.cc |
| @@ -4,25 +4,14 @@ |
| #include "mojo/services/view_manager/display_manager.h" |
| -#include "base/auto_reset.h" |
| -#include "base/scoped_observer.h" |
| +#include "cc/surfaces/surface_id_allocator.h" |
| #include "mojo/public/cpp/application/application_connection.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/surfaces/surfaces_utils.h" |
| #include "mojo/services/public/interfaces/gpu/gpu.mojom.h" |
| +#include "mojo/services/public/interfaces/surfaces/quads.mojom.h" |
| #include "mojo/services/view_manager/connection_manager.h" |
| -#include "mojo/services/view_manager/display_manager_delegate.h" |
| -#include "mojo/services/view_manager/screen_impl.h" |
| -#include "mojo/services/view_manager/window_tree_host_impl.h" |
| -#include "ui/aura/client/default_capture_client.h" |
| -#include "ui/aura/client/focus_client.h" |
| -#include "ui/aura/client/window_tree_client.h" |
| -#include "ui/aura/window.h" |
| -#include "ui/aura/window_delegate.h" |
| -#include "ui/base/cursor/cursor.h" |
| -#include "ui/base/hit_test.h" |
| -#include "ui/compositor/layer.h" |
| -#include "ui/gfx/canvas.h" |
| -#include "ui/gfx/image/image_skia.h" |
| -#include "ui/gfx/native_widget_types.h" |
| namespace mojo { |
| namespace service { |
| @@ -37,193 +26,133 @@ gfx::Rect ConvertRectToRoot(const ServerView* view, const gfx::Rect& bounds) { |
| return gfx::Rect(origin, bounds.size()); |
| } |
| -void PaintViewTree(gfx::Canvas* canvas, |
| - const ServerView* view, |
| - const gfx::Point& origin) { |
| +void DrawViewTree(Pass* pass, const ServerView* view, gfx::Point offset) { |
|
sky
2014/09/03 22:45:28
const gfx::Point& offset.
jamesr
2014/09/03 23:32:47
Done.
|
| if (!view->visible()) |
| return; |
| - canvas->DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(view->bitmap()), |
| - origin.x(), |
| - origin.y()); |
| - std::vector<const ServerView*> children(view->GetChildren()); |
| - for (size_t i = 0; i < children.size(); ++i) { |
| - PaintViewTree( |
| - canvas, children[i], origin + children[i]->bounds().OffsetFromOrigin()); |
| - } |
| -} |
| + cc::SurfaceId node_id = view->surface_id(); |
| -} // namespace |
| + SurfaceQuadStatePtr surface_quad_state = SurfaceQuadState::New(); |
| + surface_quad_state->surface = SurfaceId::From(node_id); |
| -class DisplayManager::RootWindowDelegateImpl : public aura::WindowDelegate { |
| - public: |
| - explicit RootWindowDelegateImpl(const ServerView* root_view) |
| - : root_view_(root_view) {} |
| - virtual ~RootWindowDelegateImpl() {} |
| + const gfx::Rect& node_bounds = view->bounds(); |
| + gfx::Transform node_transform; |
| + node_transform.Translate(offset.x(), offset.y()); |
| - // aura::WindowDelegate: |
| - virtual gfx::Size GetMinimumSize() const OVERRIDE { |
| - return gfx::Size(); |
| - } |
| - virtual gfx::Size GetMaximumSize() const OVERRIDE { |
| - return gfx::Size(); |
| - } |
| - virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
| - const gfx::Rect& new_bounds) OVERRIDE { |
| - } |
| - virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { |
| - return gfx::kNullCursor; |
| - } |
| - virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { |
| - return HTCAPTION; |
| - } |
| - virtual bool ShouldDescendIntoChildForEventHandling( |
| - aura::Window* child, |
| - const gfx::Point& location) OVERRIDE { |
| - return true; |
| - } |
| - virtual bool CanFocus() OVERRIDE { |
| - return true; |
| - } |
| - virtual void OnCaptureLost() OVERRIDE { |
| - } |
| - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| - PaintViewTree(canvas, root_view_, gfx::Point()); |
| - } |
| - virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
| - } |
| - virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { |
| - } |
| - virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE { |
| - } |
| - virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE { |
| - } |
| - virtual bool HasHitTestMask() const OVERRIDE { |
| - return false; |
| - } |
| - virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE { |
| - } |
| + QuadPtr surface_quad = Quad::New(); |
| + surface_quad->material = Material::MATERIAL_SURFACE_CONTENT; |
| + surface_quad->rect = Rect::From(node_bounds); |
| + surface_quad->opaque_rect = Rect::From(node_bounds); |
| + surface_quad->visible_rect = Rect::From(node_bounds); |
| + surface_quad->needs_blending = true; |
| + surface_quad->shared_quad_state_index = pass->shared_quad_states.size(); |
| + surface_quad->surface_quad_state = surface_quad_state.Pass(); |
| - private: |
| - const ServerView* root_view_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(RootWindowDelegateImpl); |
| -}; |
| - |
| -// TODO(sky): Remove once aura is removed from the service. |
| -class FocusClientImpl : public aura::client::FocusClient { |
| - public: |
| - FocusClientImpl() {} |
| - virtual ~FocusClientImpl() {} |
| - |
| - private: |
| - // Overridden from aura::client::FocusClient: |
| - virtual void AddObserver( |
| - aura::client::FocusChangeObserver* observer) OVERRIDE {} |
| - virtual void RemoveObserver( |
| - aura::client::FocusChangeObserver* observer) OVERRIDE {} |
| - virtual void FocusWindow(aura::Window* window) OVERRIDE {} |
| - virtual void ResetFocusWithinActiveWindow(aura::Window* window) OVERRIDE {} |
| - virtual aura::Window* GetFocusedWindow() OVERRIDE { return NULL; } |
| - |
| - DISALLOW_COPY_AND_ASSIGN(FocusClientImpl); |
| -}; |
| - |
| -class WindowTreeClientImpl : public aura::client::WindowTreeClient { |
| - public: |
| - explicit WindowTreeClientImpl(aura::Window* window) : window_(window) { |
| - aura::client::SetWindowTreeClient(window_, this); |
| - } |
| + SharedQuadStatePtr sqs = CreateDefaultSQS(node_bounds.size()); |
| + sqs->content_to_target_transform = Transform::From(node_transform); |
| - virtual ~WindowTreeClientImpl() { |
| - aura::client::SetWindowTreeClient(window_, NULL); |
| - } |
| + pass->quads.push_back(surface_quad.Pass()); |
| + pass->shared_quad_states.push_back(sqs.Pass()); |
| - // Overridden from aura::client::WindowTreeClient: |
| - virtual aura::Window* GetDefaultParent(aura::Window* context, |
| - aura::Window* window, |
| - const gfx::Rect& bounds) OVERRIDE { |
| - if (!capture_client_) { |
| - capture_client_.reset( |
| - new aura::client::DefaultCaptureClient(window_->GetRootWindow())); |
| - } |
| - return window_; |
| + std::vector<const ServerView*> children(view->GetChildren()); |
| + for (size_t i = 0; i < children.size(); ++i) { |
| + DrawViewTree( |
| + pass, children[i], offset + children[i]->bounds().OffsetFromOrigin()); |
| } |
| +} |
| - private: |
| - aura::Window* window_; |
| - |
| - scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImpl); |
| -}; |
| +} // namespace |
| DisplayManager::DisplayManager( |
| ApplicationConnection* app_connection, |
| ConnectionManager* connection_manager, |
| - DisplayManagerDelegate* delegate, |
| const Callback<void()>& native_viewport_closed_callback) |
| - : delegate_(delegate), |
| - connection_manager_(connection_manager), |
| + : connection_manager_(connection_manager), |
| in_setup_(false), |
| - root_window_(NULL) { |
| - screen_.reset(ScreenImpl::Create()); |
| - gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
| - NativeViewportPtr viewport; |
| - app_connection->ConnectToService( |
| - "mojo:mojo_native_viewport_service", &viewport); |
| - GpuPtr gpu_service; |
| - // TODO(jamesr): Should be mojo:mojo_gpu_service |
| + bounds_(800, 600), |
|
sky
2014/09/03 22:45:28
Same comment about size here.
jamesr
2014/09/03 23:32:47
We're passing the bounds to NativeViewport in the
|
| + draw_timer_(false, false), |
| + weak_factory_(this) { |
| app_connection->ConnectToService("mojo:mojo_native_viewport_service", |
| - &gpu_service); |
| - window_tree_host_.reset(new WindowTreeHostImpl( |
| - viewport.Pass(), |
| - gpu_service.Pass(), |
| - gfx::Rect(800, 600), |
| - base::Bind(&DisplayManager::OnCompositorCreated, base::Unretained(this)), |
| - native_viewport_closed_callback, |
| - base::Bind(&ConnectionManager::DispatchViewInputEventToWindowManager, |
| - base::Unretained(connection_manager_)))); |
| + &native_viewport_); |
| + native_viewport_.set_client(this); |
| + native_viewport_->Create(Rect::From(bounds_)); |
| + native_viewport_->Show(); |
| + app_connection->ConnectToService("mojo:mojo_surfaces_service", |
| + &surfaces_service_); |
| + surfaces_service_->CreateSurfaceConnection(base::Bind( |
| + &DisplayManager::OnSurfaceConnectionCreated, weak_factory_.GetWeakPtr())); |
| } |
| DisplayManager::~DisplayManager() { |
| - window_tree_client_.reset(); |
| - window_tree_host_.reset(); |
| - gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); |
| } |
| void DisplayManager::SchedulePaint(const ServerView* view, |
| const gfx::Rect& bounds) { |
| - if (root_window_) |
| - root_window_->SchedulePaintInRect(ConvertRectToRoot(view, bounds)); |
| + dirty_rect_.Union(ConvertRectToRoot(view, bounds)); |
|
sky
2014/09/03 22:45:28
This should do nothing if view (and all its ancest
jamesr
2014/09/03 23:32:47
Done.
|
| + if (!draw_timer_.IsRunning()) { |
| + draw_timer_.Start( |
| + FROM_HERE, |
| + base::TimeDelta(), |
| + base::Bind(&DisplayManager::Draw, base::Unretained(this))); |
| + } |
| +} |
| + |
| +void DisplayManager::OnSurfaceConnectionCreated(SurfacePtr surface, |
| + uint32_t id_namespace) { |
| + surface_ = surface.Pass(); |
| + surface_.set_client(this); |
| + surface_id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); |
| + Draw(); |
| } |
| -void DisplayManager::OnCompositorCreated() { |
| - base::AutoReset<bool> resetter(&in_setup_, true); |
| - window_tree_host_->InitHost(); |
| +void DisplayManager::Draw() { |
| + if (!surface_) |
| + return; |
| + if (surface_id_.is_null()) { |
| + surface_id_ = surface_id_allocator_->GenerateId(); |
| + surface_->CreateSurface(SurfaceId::From(surface_id_), |
| + Size::From(bounds_.size())); |
| + } |
| - window_delegate_.reset( |
| - new RootWindowDelegateImpl(connection_manager_->root())); |
| - root_window_ = new aura::Window(window_delegate_.get()); |
| - root_window_->Init(aura::WINDOW_LAYER_TEXTURED); |
| - root_window_->Show(); |
| - root_window_->SetBounds( |
| - gfx::Rect(window_tree_host_->window()->bounds().size())); |
| - window_tree_host_->window()->AddChild(root_window_); |
| + PassPtr pass = CreateDefaultPass(1, bounds_); |
| + pass->damage_rect = Rect::From(dirty_rect_); |
| - connection_manager_->root()->SetBounds( |
| - gfx::Rect(window_tree_host_->window()->bounds().size())); |
| + DrawViewTree(pass.get(), connection_manager_->root(), gfx::Point()); |
| - window_tree_client_.reset( |
| - new WindowTreeClientImpl(window_tree_host_->window())); |
| + FramePtr frame = Frame::New(); |
| + frame->passes.push_back(pass.Pass()); |
| + frame->resources.resize(0u); |
| + surface_->SubmitFrame(SurfaceId::From(surface_id_), frame.Pass()); |
| - focus_client_.reset(new FocusClientImpl); |
| - aura::client::SetFocusClient(window_tree_host_->window(), |
| - focus_client_.get()); |
| + native_viewport_->SubmittedFrame(SurfaceId::From(surface_id_)); |
| - window_tree_host_->Show(); |
| + dirty_rect_ = gfx::Rect(); |
| +} |
| + |
| +void DisplayManager::OnCreated(uint64_t native_viewport_id) { |
| +} |
| + |
| +void DisplayManager::OnDestroyed() { |
| + native_viewport_closed_callback_.Run(); |
| +} |
| + |
| +void DisplayManager::OnBoundsChanged(RectPtr bounds) { |
| + connection_manager_->root()->SetBounds(bounds_); |
|
sky
2014/09/03 22:45:28
Doesn't this need to propagate bounds to bounds_?
jamesr
2014/09/03 23:32:47
Done.
|
| + if (surface_id_.is_null()) |
| + return; |
| + surface_->DestroySurface(SurfaceId::From(surface_id_)); |
| + surface_id_ = cc::SurfaceId(); |
| + SchedulePaint(connection_manager_->root(), bounds_); |
| +} |
| + |
| +void DisplayManager::OnEvent(EventPtr event, |
| + const mojo::Callback<void()>& callback) { |
| + connection_manager_->DispatchViewInputEventToWindowManager(event.Pass()); |
| + callback.Run(); |
| +} |
| - delegate_->OnDisplayManagerWindowTreeHostCreated(); |
| +void DisplayManager::ReturnResources(Array<ReturnedResourcePtr> resources) { |
| + DCHECK_EQ(0u, resources.size()); |
| } |
| } // namespace service |