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

Side by Side Diff: examples/bitmap_uploader/bitmap_uploader.cc

Issue 871373015: De-Client Surface interface (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
OLDNEW
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/bitmap_uploader/bitmap_uploader.h" 5 #include "examples/bitmap_uploader/bitmap_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 // GL_GLEXT_PROTOTYPES 9 #endif // GL_GLEXT_PROTOTYPES
10 10
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 33
34 BitmapUploader::BitmapUploader(View* view) 34 BitmapUploader::BitmapUploader(View* view)
35 : view_(view), 35 : view_(view),
36 color_(TRANSPARENT_COLOR), 36 color_(TRANSPARENT_COLOR),
37 width_(0), 37 width_(0),
38 height_(0), 38 height_(0),
39 format_(BGRA), 39 format_(BGRA),
40 next_resource_id_(1u), 40 next_resource_id_(1u),
41 id_namespace_(0u), 41 id_namespace_(0u),
42 local_id_(0u) { 42 local_id_(0u),
43 returner_binding_(this) {
43 } 44 }
44 45
45 void BitmapUploader::Init(Shell* shell) { 46 void BitmapUploader::Init(Shell* shell) {
46 ServiceProviderPtr surfaces_service_provider; 47 ServiceProviderPtr surfaces_service_provider;
47 shell->ConnectToApplication("mojo:surfaces_service", 48 shell->ConnectToApplication("mojo:surfaces_service",
48 GetProxy(&surfaces_service_provider), nullptr); 49 GetProxy(&surfaces_service_provider), nullptr);
49 ConnectToService(surfaces_service_provider.get(), &surface_); 50 ConnectToService(surfaces_service_provider.get(), &surface_);
50 surface_.set_client(this); 51 surface_->GetIdNamespace(
52 base::Bind(&BitmapUploader::SetIdNamespace, base::Unretained(this)));
53 mojo::ResourceReturnerPtr returner_ptr;
54 returner_binding_.Bind(GetProxy(&returner_ptr));
55 surface_->SetResourceReturner(returner_ptr.Pass());
51 56
52 ServiceProviderPtr gpu_service_provider; 57 ServiceProviderPtr gpu_service_provider;
53 shell->ConnectToApplication("mojo:native_viewport_service", 58 shell->ConnectToApplication("mojo:native_viewport_service",
54 GetProxy(&gpu_service_provider), nullptr); 59 GetProxy(&gpu_service_provider), nullptr);
55 ConnectToService(gpu_service_provider.get(), &gpu_service_); 60 ConnectToService(gpu_service_provider.get(), &gpu_service_);
56 61
57 CommandBufferPtr gles2_client; 62 CommandBufferPtr gles2_client;
58 gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client)); 63 gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client));
59 gles2_context_ = 64 gles2_context_ =
60 MojoGLES2CreateContext(gles2_client.PassMessagePipe().release().value(), 65 MojoGLES2CreateContext(gles2_client.PassMessagePipe().release().value(),
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 surface_->SubmitFrame(local_id_, frame.Pass(), mojo::Closure()); 231 surface_->SubmitFrame(local_id_, frame.Pass(), mojo::Closure());
227 } 232 }
228 233
229 void BitmapUploader::SetIdNamespace(uint32_t id_namespace) { 234 void BitmapUploader::SetIdNamespace(uint32_t id_namespace) {
230 id_namespace_ = id_namespace; 235 id_namespace_ = id_namespace;
231 if (color_ != TRANSPARENT_COLOR || bitmap_.get()) 236 if (color_ != TRANSPARENT_COLOR || bitmap_.get())
232 Upload(); 237 Upload();
233 } 238 }
234 239
235 void BitmapUploader::ReturnResources(Array<ReturnedResourcePtr> resources) { 240 void BitmapUploader::ReturnResources(Array<ReturnedResourcePtr> resources) {
236 if (!resources.size())
237 return;
238 MojoGLES2MakeCurrent(gles2_context_); 241 MojoGLES2MakeCurrent(gles2_context_);
239 // TODO(jamesr): Recycle. 242 // TODO(jamesr): Recycle.
240 for (size_t i = 0; i < resources.size(); ++i) { 243 for (size_t i = 0; i < resources.size(); ++i) {
241 ReturnedResourcePtr resource = resources[i].Pass(); 244 ReturnedResourcePtr resource = resources[i].Pass();
242 DCHECK_EQ(1, resource->count); 245 DCHECK_EQ(1, resource->count);
243 glWaitSyncPointCHROMIUM(resource->sync_point); 246 glWaitSyncPointCHROMIUM(resource->sync_point);
244 uint32_t texture_id = resource_to_texture_id_map_[resource->id]; 247 uint32_t texture_id = resource_to_texture_id_map_[resource->id];
245 DCHECK_NE(0u, texture_id); 248 DCHECK_NE(0u, texture_id);
246 resource_to_texture_id_map_.erase(resource->id); 249 resource_to_texture_id_map_.erase(resource->id);
247 glDeleteTextures(1, &texture_id); 250 glDeleteTextures(1, &texture_id);
(...skipping 16 matching lines...) Expand all
264 0); 267 0);
265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 268 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
266 return texture; 269 return texture;
267 } 270 }
268 271
269 uint32_t BitmapUploader::TextureFormat() { 272 uint32_t BitmapUploader::TextureFormat() {
270 return format_ == BGRA ? GL_BGRA_EXT : GL_RGBA; 273 return format_ == BGRA ? GL_BGRA_EXT : GL_RGBA;
271 } 274 }
272 275
273 } // namespace mojo 276 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698