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

Unified Diff: examples/ganesh_app/texture_uploader.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
« no previous file with comments | « examples/ganesh_app/texture_uploader.h ('k') | examples/surfaces_app/child_gl_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/ganesh_app/texture_uploader.cc
diff --git a/examples/ganesh_app/texture_uploader.cc b/examples/ganesh_app/texture_uploader.cc
index 2c8f831dd0ca4d08331d20378ab9dd584e5bea66..f26be75290397b4129dcb77d16c300ba5669861e 100644
--- a/examples/ganesh_app/texture_uploader.cc
+++ b/examples/ganesh_app/texture_uploader.cc
@@ -27,24 +27,20 @@ TextureUploader::TextureUploader(Client* client,
base::WeakPtr<mojo::GLContext> context)
: client_(client),
context_(context),
- next_resource_id_(0),
- id_namespace_(0),
+ next_resource_id_(0u),
+ id_namespace_(0u),
+ local_id_(0u),
weak_factory_(this) {
context_->AddObserver(this);
mojo::ServiceProviderPtr surfaces_service_provider;
shell->ConnectToApplication("mojo:surfaces_service",
mojo::GetProxy(&surfaces_service_provider));
- mojo::ConnectToService(surfaces_service_provider.get(), &surfaces_service_);
-
- surfaces_service_->CreateSurfaceConnection(
- base::Bind(&TextureUploader::OnSurfaceConnectionCreated,
- weak_factory_.GetWeakPtr()));
+ mojo::ConnectToService(surfaces_service_provider.get(), &surface_);
+ surface_.set_client(this);
}
TextureUploader::~TextureUploader() {
- if (surface_id_)
- surface_->DestroySurface(surface_id_.Clone());
if (context_.get())
context_->RemoveObserver(this);
}
@@ -121,24 +117,28 @@ void TextureUploader::Upload(scoped_ptr<mojo::GLTexture> texture) {
pass->quads.push_back(quad.Pass());
frame->passes.push_back(pass.Pass());
- surface_->SubmitFrame(surface_id_.Clone(), frame.Pass(), mojo::Closure());
+ surface_->SubmitFrame(local_id_, frame.Pass(), mojo::Closure());
}
void TextureUploader::EnsureSurfaceForSize(const mojo::Size& size) {
- if (surface_id_ && size == surface_size_)
+ if (local_id_ != 0u && size == surface_size_)
return;
- if (surface_id_) {
- surface_->DestroySurface(surface_id_.Clone());
- } else {
- surface_id_ = mojo::SurfaceId::New();
- surface_id_->id_namespace = id_namespace_;
+ if (local_id_ != 0u) {
+ surface_->DestroySurface(local_id_);
}
- surface_id_->local++;
- surface_->CreateSurface(surface_id_.Clone());
- client_->OnSurfaceIdAvailable(surface_id_.Clone());
+ local_id_++;
+ surface_->CreateSurface(local_id_);
surface_size_ = size;
+ if (id_namespace_ != 0u)
+ SendFullyQualifiedID();
+}
+void TextureUploader::SendFullyQualifiedID() {
+ auto qualified_id = mojo::SurfaceId::New();
+ qualified_id->id_namespace = id_namespace_;
+ qualified_id->local = local_id_;
+ client_->OnSurfaceIdAvailable(qualified_id.Pass());
}
void TextureUploader::OnContextLost() {
@@ -146,6 +146,9 @@ void TextureUploader::OnContextLost() {
}
void TextureUploader::SetIdNamespace(uint32_t id_namespace) {
+ id_namespace_ = id_namespace;
+ if (local_id_ != 0u)
+ SendFullyQualifiedID();
}
void TextureUploader::ReturnResources(
@@ -164,14 +167,4 @@ void TextureUploader::ReturnResources(
}
}
-void TextureUploader::OnSurfaceConnectionCreated(mojo::SurfacePtr surface,
- uint32_t id_namespace) {
- surface_ = surface.Pass();
- surface_.set_client(this);
- id_namespace_ = id_namespace;
-
- if (pending_upload_)
- Upload(pending_upload_.Pass());
-}
-
} // namespace examples
« no previous file with comments | « examples/ganesh_app/texture_uploader.h ('k') | examples/surfaces_app/child_gl_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698