Chromium Code Reviews| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "gpu/GLES2/gl2chromium.h" | 12 #include "gpu/GLES2/gl2chromium.h" |
| 13 #include "gpu/GLES2/gl2extchromium.h" | 13 #include "gpu/GLES2/gl2extchromium.h" |
| 14 #include "mojo/public/c/gles2/gles2.h" | 14 #include "mojo/public/c/gles2/gles2.h" |
| 15 #include "mojo/public/cpp/application/connect.h" | 15 #include "mojo/public/cpp/application/connect.h" |
| 16 #include "mojo/public/interfaces/application/shell.mojom.h" | 16 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 17 #include "mojo/services/geometry/public/cpp/geometry_util.h" | 17 #include "mojo/services/geometry/public/cpp/geometry_util.h" |
| 18 #include "mojo/services/surfaces/public/cpp/surfaces_utils.h" | 18 #include "mojo/services/surfaces/public/cpp/surfaces_utils.h" |
| 19 | 19 |
| 20 namespace examples { | 20 namespace examples { |
| 21 | 21 |
| 22 TextureUploader::Client::~Client() { | 22 TextureUploader::Client::~Client() { |
| 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_(0), | 30 next_resource_id_(0u), |
| 31 id_namespace_(0), | 31 id_namespace_(0u), |
| 32 local_id_(0u), | |
| 32 weak_factory_(this) { | 33 weak_factory_(this) { |
| 33 context_->AddObserver(this); | 34 context_->AddObserver(this); |
| 34 | 35 |
| 35 mojo::ServiceProviderPtr surfaces_service_provider; | 36 mojo::ServiceProviderPtr surfaces_service_provider; |
| 36 shell->ConnectToApplication("mojo:surfaces_service", | 37 shell->ConnectToApplication("mojo:surfaces_service", |
| 37 mojo::GetProxy(&surfaces_service_provider)); | 38 mojo::GetProxy(&surfaces_service_provider)); |
| 38 mojo::ConnectToService(surfaces_service_provider.get(), &surfaces_service_); | 39 mojo::ConnectToService(surfaces_service_provider.get(), &surface_); |
| 39 | 40 surface_.set_client(this); |
| 40 surfaces_service_->CreateSurfaceConnection( | |
| 41 base::Bind(&TextureUploader::OnSurfaceConnectionCreated, | |
| 42 weak_factory_.GetWeakPtr())); | |
| 43 } | 41 } |
| 44 | 42 |
| 45 TextureUploader::~TextureUploader() { | 43 TextureUploader::~TextureUploader() { |
| 46 if (surface_id_) | 44 if (local_id_ != 0u) |
| 47 surface_->DestroySurface(surface_id_.Clone()); | 45 surface_->DestroySurface(local_id_); |
|
sky
2015/01/13 18:14:27
As the pipe is destroyed in the destructor is this
jamesr
2015/01/14 01:50:29
It's not, closing the pipe destroys all associated
| |
| 48 if (context_.get()) | 46 if (context_.get()) |
| 49 context_->RemoveObserver(this); | 47 context_->RemoveObserver(this); |
| 50 } | 48 } |
| 51 | 49 |
| 52 void TextureUploader::Upload(scoped_ptr<mojo::GLTexture> texture) { | 50 void TextureUploader::Upload(scoped_ptr<mojo::GLTexture> texture) { |
| 53 if (!surface_) { | 51 if (!surface_) { |
| 54 pending_upload_ = texture.Pass(); | 52 pending_upload_ = texture.Pass(); |
| 55 return; | 53 return; |
| 56 } | 54 } |
| 57 | 55 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 texture_state->background_color->rgba = 0; | 112 texture_state->background_color->rgba = 0; |
| 115 for (int i = 0; i < 4; ++i) | 113 for (int i = 0; i < 4; ++i) |
| 116 texture_state->vertex_opacity.push_back(1.f); | 114 texture_state->vertex_opacity.push_back(1.f); |
| 117 texture_state->flipped = false; | 115 texture_state->flipped = false; |
| 118 | 116 |
| 119 frame->resources.push_back(resource.Pass()); | 117 frame->resources.push_back(resource.Pass()); |
| 120 quad->texture_quad_state = texture_state.Pass(); | 118 quad->texture_quad_state = texture_state.Pass(); |
| 121 pass->quads.push_back(quad.Pass()); | 119 pass->quads.push_back(quad.Pass()); |
| 122 | 120 |
| 123 frame->passes.push_back(pass.Pass()); | 121 frame->passes.push_back(pass.Pass()); |
| 124 surface_->SubmitFrame(surface_id_.Clone(), frame.Pass(), mojo::Closure()); | 122 surface_->SubmitFrame(local_id_, frame.Pass(), mojo::Closure()); |
| 125 } | 123 } |
| 126 | 124 |
| 127 void TextureUploader::EnsureSurfaceForSize(const mojo::Size& size) { | 125 void TextureUploader::EnsureSurfaceForSize(const mojo::Size& size) { |
| 128 if (surface_id_ && size == surface_size_) | 126 if (local_id_ != 0u && size == surface_size_) |
| 129 return; | 127 return; |
| 130 | 128 |
| 131 if (surface_id_) { | 129 if (local_id_ != 0u) { |
| 132 surface_->DestroySurface(surface_id_.Clone()); | 130 surface_->DestroySurface(local_id_); |
| 133 } else { | |
| 134 surface_id_ = mojo::SurfaceId::New(); | |
| 135 surface_id_->id_namespace = id_namespace_; | |
| 136 } | 131 } |
| 137 | 132 |
| 138 surface_id_->local++; | 133 local_id_++; |
| 139 surface_->CreateSurface(surface_id_.Clone()); | 134 surface_->CreateSurface(local_id_); |
| 140 client_->OnSurfaceIdAvailable(surface_id_.Clone()); | |
| 141 surface_size_ = size; | 135 surface_size_ = size; |
| 136 if (id_namespace_ != 0u) | |
| 137 SendFullyQualifiedID(); | |
| 138 } | |
| 139 void TextureUploader::SendFullyQualifiedID() { | |
| 140 auto qualified_id = mojo::SurfaceId::New(); | |
| 141 qualified_id->id_namespace = id_namespace_; | |
| 142 qualified_id->local = local_id_; | |
| 143 client_->OnSurfaceIdAvailable(qualified_id.Pass()); | |
| 142 } | 144 } |
| 143 | 145 |
| 144 void TextureUploader::OnContextLost() { | 146 void TextureUploader::OnContextLost() { |
| 145 LOG(FATAL) << "Context lost."; | 147 LOG(FATAL) << "Context lost."; |
| 146 } | 148 } |
| 147 | 149 |
| 148 void TextureUploader::SetIdNamespace(uint32_t id_namespace) { | 150 void TextureUploader::SetIdNamespace(uint32_t id_namespace) { |
| 151 id_namespace_ = id_namespace; | |
| 152 if (local_id_ != 0u) | |
| 153 SendFullyQualifiedID(); | |
| 149 } | 154 } |
| 150 | 155 |
| 151 void TextureUploader::ReturnResources( | 156 void TextureUploader::ReturnResources( |
| 152 mojo::Array<mojo::ReturnedResourcePtr> resources) { | 157 mojo::Array<mojo::ReturnedResourcePtr> resources) { |
| 153 if (!resources.size()) | 158 if (!resources.size()) |
| 154 return; | 159 return; |
| 155 context_->MakeCurrent(); | 160 context_->MakeCurrent(); |
| 156 for (size_t i = 0u; i < resources.size(); ++i) { | 161 for (size_t i = 0u; i < resources.size(); ++i) { |
| 157 mojo::ReturnedResourcePtr resource = resources[i].Pass(); | 162 mojo::ReturnedResourcePtr resource = resources[i].Pass(); |
| 158 DCHECK_EQ(1, resource->count); | 163 DCHECK_EQ(1, resource->count); |
| 159 glWaitSyncPointCHROMIUM(resource->sync_point); | 164 glWaitSyncPointCHROMIUM(resource->sync_point); |
| 160 mojo::GLTexture* texture = resource_to_texture_map_[resource->id]; | 165 mojo::GLTexture* texture = resource_to_texture_map_[resource->id]; |
| 161 DCHECK_NE(0u, texture->texture_id()); | 166 DCHECK_NE(0u, texture->texture_id()); |
| 162 resource_to_texture_map_.erase(resource->id); | 167 resource_to_texture_map_.erase(resource->id); |
| 163 delete texture; | 168 delete texture; |
| 164 } | 169 } |
| 165 } | 170 } |
| 166 | 171 |
| 167 void TextureUploader::OnSurfaceConnectionCreated(mojo::SurfacePtr surface, | |
| 168 uint32_t id_namespace) { | |
| 169 surface_ = surface.Pass(); | |
| 170 surface_.set_client(this); | |
| 171 id_namespace_ = id_namespace; | |
| 172 | |
| 173 if (pending_upload_) | |
| 174 Upload(pending_upload_.Pass()); | |
| 175 } | |
| 176 | |
| 177 } // namespace examples | 172 } // namespace examples |
| OLD | NEW |