Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(758)

Unified Diff: services/view_manager/display_manager.cc

Issue 826423008: Use local ids for Surfaces APIs that can only apply to local surfaces (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: services/view_manager/display_manager.cc
diff --git a/services/view_manager/display_manager.cc b/services/view_manager/display_manager.cc
index 175c25e385c2f6c212eed763568dd803c4f27be0..ed3a58f5b6ac001dd06566448515d41d4d213765 100644
--- a/services/view_manager/display_manager.cc
+++ b/services/view_manager/display_manager.cc
@@ -76,6 +76,8 @@ DefaultDisplayManager::DefaultDisplayManager(
: app_connection_(app_connection),
connection_manager_(nullptr),
draw_timer_(false, false),
+ id_namespace_(0u),
+ local_id_(0u),
native_viewport_closed_callback_(native_viewport_closed_callback),
weak_factory_(this) {
metrics_.size = mojo::Size::New();
@@ -93,11 +95,9 @@ void DefaultDisplayManager::Init(ConnectionManager* connection_manager) {
base::Bind(&DefaultDisplayManager::OnCreatedNativeViewport,
weak_factory_.GetWeakPtr()));
native_viewport_->Show();
- app_connection_->ConnectToService("mojo:surfaces_service",
- &surfaces_service_);
- surfaces_service_->CreateSurfaceConnection(
- base::Bind(&DefaultDisplayManager::OnSurfaceConnectionCreated,
- weak_factory_.GetWeakPtr()));
+
+ app_connection_->ConnectToService("mojo:surfaces_service", &surface_);
+ surface_.set_client(this);
mojo::NativeViewportEventDispatcherPtr event_dispatcher;
app_connection_->ConnectToService(&event_dispatcher);
@@ -135,20 +135,10 @@ void DefaultDisplayManager::OnCreatedNativeViewport(
uint64_t native_viewport_id) {
}
-void DefaultDisplayManager::OnSurfaceConnectionCreated(mojo::SurfacePtr surface,
- uint32_t id_namespace) {
- surface_ = surface.Pass();
- surface_.set_client(this);
- surface_id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
- Draw();
-}
-
void DefaultDisplayManager::Draw() {
- if (!surface_)
- return;
- if (surface_id_.is_null()) {
- surface_id_ = surface_id_allocator_->GenerateId();
- surface_->CreateSurface(mojo::SurfaceId::From(surface_id_));
+ if (local_id_ == 0u) {
+ local_id_ = 1u;
+ surface_->CreateSurface(local_id_);
}
Rect rect;
@@ -162,12 +152,16 @@ void DefaultDisplayManager::Draw() {
auto frame = mojo::Frame::New();
frame->passes.push_back(pass.Pass());
frame->resources.resize(0u);
- surface_->SubmitFrame(mojo::SurfaceId::From(surface_id_), frame.Pass(),
- mojo::Closure());
+ surface_->SubmitFrame(local_id_, frame.Pass(), mojo::Closure());
+ dirty_rect_ = gfx::Rect();
- native_viewport_->SubmittedFrame(mojo::SurfaceId::From(surface_id_));
+ if (id_namespace_ == 0u)
+ return;
- dirty_rect_ = gfx::Rect();
+ auto qualified_id = mojo::SurfaceId::New();
+ qualified_id->id_namespace = id_namespace_;
+ qualified_id->local = local_id_;
+ native_viewport_->SubmittedFrame(qualified_id.Pass());
}
void DefaultDisplayManager::OnDestroyed() {
@@ -181,14 +175,21 @@ void DefaultDisplayManager::OnMetricsChanged(mojo::ViewportMetricsPtr metrics) {
metrics_.device_pixel_ratio = metrics->device_pixel_ratio;
gfx::Rect bounds(metrics_.size.To<gfx::Size>());
connection_manager_->root()->SetBounds(bounds);
- if (surface_id_.is_null())
+ if (local_id_ == 0u)
return;
- surface_->DestroySurface(mojo::SurfaceId::From(surface_id_));
- surface_id_ = cc::SurfaceId();
+ surface_->DestroySurface(local_id_);
+ local_id_ = 0u;
SchedulePaint(connection_manager_->root(), bounds);
}
void DefaultDisplayManager::SetIdNamespace(uint32_t id_namespace) {
+ id_namespace_ = id_namespace;
+ if (local_id_ != 0u) {
+ auto qualified_id = mojo::SurfaceId::New();
+ qualified_id->id_namespace = id_namespace_;
+ qualified_id->local = local_id_;
+ native_viewport_->SubmittedFrame(qualified_id.Pass());
+ }
}
void DefaultDisplayManager::ReturnResources(

Powered by Google App Engine
This is Rietveld 408576698