OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/bitmap_uploader/bitmap_uploader.h" | 5 #include "components/bitmap_uploader/bitmap_uploader.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 const char kBitmapUploaderForAcceleratedWidget[] = | 32 const char kBitmapUploaderForAcceleratedWidget[] = |
33 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; | 33 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; |
34 | 34 |
35 BitmapUploader::BitmapUploader(mus::Window* window) | 35 BitmapUploader::BitmapUploader(mus::Window* window) |
36 : window_(window), | 36 : window_(window), |
37 color_(g_transparent_color), | 37 color_(g_transparent_color), |
38 width_(0), | 38 width_(0), |
39 height_(0), | 39 height_(0), |
40 format_(BGRA), | 40 format_(BGRA), |
41 next_resource_id_(1u), | 41 next_resource_id_(1u), |
42 id_namespace_(0u), | 42 id_namespace_(0u) {} |
43 surface_client_binding_(this) {} | |
44 | 43 |
45 BitmapUploader::~BitmapUploader() { | 44 BitmapUploader::~BitmapUploader() { |
46 MojoGLES2DestroyContext(gles2_context_); | 45 MojoGLES2DestroyContext(gles2_context_); |
47 } | 46 } |
48 | 47 |
49 void BitmapUploader::Init(mojo::Connector* connector) { | 48 void BitmapUploader::Init(mojo::Connector* connector) { |
50 surface_ = window_->RequestSurface(mus::mojom::SurfaceType::DEFAULT); | 49 surface_ = window_->RequestSurface(mus::mojom::SurfaceType::DEFAULT); |
51 surface_->BindToThread(); | 50 surface_->BindToThread(); |
| 51 surface_->set_client(this); |
52 | 52 |
53 connector->ConnectToInterface("mojo:mus", &gpu_service_); | 53 connector->ConnectToInterface("mojo:mus", &gpu_service_); |
54 mus::mojom::CommandBufferPtr gles2_client; | 54 mus::mojom::CommandBufferPtr gles2_client; |
55 gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client)); | 55 gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client)); |
56 gles2_context_ = MojoGLES2CreateContext( | 56 gles2_context_ = MojoGLES2CreateContext( |
57 gles2_client.PassInterface().PassHandle().release().value(), nullptr, | 57 gles2_client.PassInterface().PassHandle().release().value(), nullptr, |
58 &LostContext, nullptr); | 58 &LostContext, nullptr); |
59 MojoGLES2MakeCurrent(gles2_context_); | 59 MojoGLES2MakeCurrent(gles2_context_); |
60 } | 60 } |
61 | 61 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
225 return texture; | 225 return texture; |
226 } | 226 } |
227 | 227 |
228 void BitmapUploader::SetIdNamespace(uint32_t id_namespace) { | 228 void BitmapUploader::SetIdNamespace(uint32_t id_namespace) { |
229 id_namespace_ = id_namespace; | 229 id_namespace_ = id_namespace; |
230 if (color_ != g_transparent_color || bitmap_.get()) | 230 if (color_ != g_transparent_color || bitmap_.get()) |
231 Upload(); | 231 Upload(); |
232 } | 232 } |
233 | 233 |
234 void BitmapUploader::ReturnResources( | 234 void BitmapUploader::OnResourcesReturned( |
| 235 mus::WindowSurface* surface, |
235 mojo::Array<mus::mojom::ReturnedResourcePtr> resources) { | 236 mojo::Array<mus::mojom::ReturnedResourcePtr> resources) { |
236 MojoGLES2MakeCurrent(gles2_context_); | 237 MojoGLES2MakeCurrent(gles2_context_); |
237 // TODO(jamesr): Recycle. | 238 // TODO(jamesr): Recycle. |
238 for (size_t i = 0; i < resources.size(); ++i) { | 239 for (size_t i = 0; i < resources.size(); ++i) { |
239 mus::mojom::ReturnedResourcePtr resource = std::move(resources[i]); | 240 mus::mojom::ReturnedResourcePtr resource = std::move(resources[i]); |
240 DCHECK_EQ(1, resource->count); | 241 DCHECK_EQ(1, resource->count); |
241 glWaitSyncTokenCHROMIUM( | 242 glWaitSyncTokenCHROMIUM( |
242 resource->sync_token.GetConstData()); | 243 resource->sync_token.GetConstData()); |
243 uint32_t texture_id = resource_to_texture_id_map_[resource->id]; | 244 uint32_t texture_id = resource_to_texture_id_map_[resource->id]; |
244 DCHECK_NE(0u, texture_id); | 245 DCHECK_NE(0u, texture_id); |
245 resource_to_texture_id_map_.erase(resource->id); | 246 resource_to_texture_id_map_.erase(resource->id); |
246 glDeleteTextures(1, &texture_id); | 247 glDeleteTextures(1, &texture_id); |
247 } | 248 } |
248 } | 249 } |
249 | 250 |
250 } // namespace bitmap_uploader | 251 } // namespace bitmap_uploader |
OLD | NEW |