| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "examples/ganesh_app/texture_uploader.h" | 5 #include "examples/ganesh_app/texture_uploader.h" |
| 6 | 6 |
| 7 #ifndef GL_GLEXT_PROTOTYPES | 7 #ifndef GL_GLEXT_PROTOTYPES |
| 8 #define GL_GLEXT_PROTOTYPES | 8 #define GL_GLEXT_PROTOTYPES |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 } | 23 } |
| 24 | 24 |
| 25 TextureUploader::TextureUploader(Client* client, | 25 TextureUploader::TextureUploader(Client* client, |
| 26 mojo::Shell* shell, | 26 mojo::Shell* shell, |
| 27 base::WeakPtr<mojo::GLContext> context) | 27 base::WeakPtr<mojo::GLContext> context) |
| 28 : client_(client), | 28 : client_(client), |
| 29 context_(context), | 29 context_(context), |
| 30 next_resource_id_(0u), | 30 next_resource_id_(0u), |
| 31 id_namespace_(0u), | 31 id_namespace_(0u), |
| 32 local_id_(0u), | 32 local_id_(0u), |
| 33 returner_binding_(this), |
| 33 weak_factory_(this) { | 34 weak_factory_(this) { |
| 34 context_->AddObserver(this); | 35 context_->AddObserver(this); |
| 35 | 36 |
| 36 mojo::ServiceProviderPtr surfaces_service_provider; | 37 mojo::ServiceProviderPtr surfaces_service_provider; |
| 37 shell->ConnectToApplication("mojo:surfaces_service", | 38 shell->ConnectToApplication("mojo:surfaces_service", |
| 38 mojo::GetProxy(&surfaces_service_provider), | 39 mojo::GetProxy(&surfaces_service_provider), |
| 39 nullptr); | 40 nullptr); |
| 40 mojo::ConnectToService(surfaces_service_provider.get(), &surface_); | 41 mojo::ConnectToService(surfaces_service_provider.get(), &surface_); |
| 41 surface_.set_client(this); | 42 surface_->GetIdNamespace( |
| 43 base::Bind(&TextureUploader::SetIdNamespace, base::Unretained(this))); |
| 44 mojo::ResourceReturnerPtr returner_ptr; |
| 45 returner_binding_.Bind(GetProxy(&returner_ptr)); |
| 46 surface_->SetResourceReturner(returner_ptr.Pass()); |
| 42 } | 47 } |
| 43 | 48 |
| 44 TextureUploader::~TextureUploader() { | 49 TextureUploader::~TextureUploader() { |
| 45 if (context_.get()) | 50 if (context_.get()) |
| 46 context_->RemoveObserver(this); | 51 context_->RemoveObserver(this); |
| 47 } | 52 } |
| 48 | 53 |
| 49 void TextureUploader::Upload(scoped_ptr<mojo::GLTexture> texture) { | 54 void TextureUploader::Upload(scoped_ptr<mojo::GLTexture> texture) { |
| 50 if (!surface_) { | 55 if (!surface_) { |
| 51 pending_upload_ = texture.Pass(); | 56 pending_upload_ = texture.Pass(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 152 } |
| 148 | 153 |
| 149 void TextureUploader::SetIdNamespace(uint32_t id_namespace) { | 154 void TextureUploader::SetIdNamespace(uint32_t id_namespace) { |
| 150 id_namespace_ = id_namespace; | 155 id_namespace_ = id_namespace; |
| 151 if (local_id_ != 0u) | 156 if (local_id_ != 0u) |
| 152 SendFullyQualifiedID(); | 157 SendFullyQualifiedID(); |
| 153 } | 158 } |
| 154 | 159 |
| 155 void TextureUploader::ReturnResources( | 160 void TextureUploader::ReturnResources( |
| 156 mojo::Array<mojo::ReturnedResourcePtr> resources) { | 161 mojo::Array<mojo::ReturnedResourcePtr> resources) { |
| 157 if (!resources.size()) | |
| 158 return; | |
| 159 context_->MakeCurrent(); | 162 context_->MakeCurrent(); |
| 160 for (size_t i = 0u; i < resources.size(); ++i) { | 163 for (size_t i = 0u; i < resources.size(); ++i) { |
| 161 mojo::ReturnedResourcePtr resource = resources[i].Pass(); | 164 mojo::ReturnedResourcePtr resource = resources[i].Pass(); |
| 162 DCHECK_EQ(1, resource->count); | 165 DCHECK_EQ(1, resource->count); |
| 163 glWaitSyncPointCHROMIUM(resource->sync_point); | 166 glWaitSyncPointCHROMIUM(resource->sync_point); |
| 164 mojo::GLTexture* texture = resource_to_texture_map_[resource->id]; | 167 mojo::GLTexture* texture = resource_to_texture_map_[resource->id]; |
| 165 DCHECK_NE(0u, texture->texture_id()); | 168 DCHECK_NE(0u, texture->texture_id()); |
| 166 resource_to_texture_map_.erase(resource->id); | 169 resource_to_texture_map_.erase(resource->id); |
| 167 delete texture; | 170 delete texture; |
| 168 } | 171 } |
| 169 } | 172 } |
| 170 | 173 |
| 171 } // namespace examples | 174 } // namespace examples |
| OLD | NEW |