| 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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "components/mus/public/cpp/window.h" | 12 #include "components/mus/public/cpp/window.h" |
| 13 #include "components/mus/public/cpp/window_surface.h" | 13 #include "components/mus/public/cpp/window_surface.h" |
| 14 #include "mojo/converters/geometry/geometry_type_converters.h" | 14 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 15 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 15 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 16 #include "mojo/converters/surfaces/surfaces_utils.h" | 16 #include "mojo/converters/surfaces/surfaces_utils.h" |
| 17 #include "mojo/public/c/gles2/chromium_extension.h" | 17 #include "mojo/public/c/gles2/chromium_extension.h" |
| 18 #include "mojo/public/c/gles2/gles2.h" | 18 #include "mojo/public/c/gles2/gles2.h" |
| 19 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | 19 #include "mojo/shell/public/cpp/shell.h" |
| 20 #include "mojo/shell/public/cpp/application_impl.h" | |
| 21 #include "mojo/shell/public/cpp/connect.h" | |
| 22 #include "mojo/shell/public/interfaces/shell.mojom.h" | |
| 23 | 20 |
| 24 namespace bitmap_uploader { | 21 namespace bitmap_uploader { |
| 25 namespace { | 22 namespace { |
| 26 | 23 |
| 27 const uint32_t g_transparent_color = 0x00000000; | 24 const uint32_t g_transparent_color = 0x00000000; |
| 28 | 25 |
| 29 void LostContext(void*) { | 26 void LostContext(void*) { |
| 30 // TODO(fsamuel): Figure out if there's something useful to do here. | 27 // TODO(fsamuel): Figure out if there's something useful to do here. |
| 31 } | 28 } |
| 32 | 29 |
| 33 void OnGotRemoteIDs(uint32_t remote_id, uint32_t content_handler_id) {} | |
| 34 | |
| 35 } // namespace | 30 } // namespace |
| 36 | 31 |
| 37 const char kBitmapUploaderForAcceleratedWidget[] = | 32 const char kBitmapUploaderForAcceleratedWidget[] = |
| 38 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; | 33 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; |
| 39 | 34 |
| 40 BitmapUploader::BitmapUploader(mus::Window* window) | 35 BitmapUploader::BitmapUploader(mus::Window* window) |
| 41 : window_(window), | 36 : window_(window), |
| 42 color_(g_transparent_color), | 37 color_(g_transparent_color), |
| 43 width_(0), | 38 width_(0), |
| 44 height_(0), | 39 height_(0), |
| 45 format_(BGRA), | 40 format_(BGRA), |
| 46 next_resource_id_(1u), | 41 next_resource_id_(1u), |
| 47 id_namespace_(0u), | 42 id_namespace_(0u), |
| 48 surface_client_binding_(this) {} | 43 surface_client_binding_(this) {} |
| 49 | 44 |
| 50 BitmapUploader::~BitmapUploader() { | 45 BitmapUploader::~BitmapUploader() { |
| 51 MojoGLES2DestroyContext(gles2_context_); | 46 MojoGLES2DestroyContext(gles2_context_); |
| 52 } | 47 } |
| 53 | 48 |
| 54 void BitmapUploader::Init(mojo::shell::mojom::Shell* shell) { | 49 void BitmapUploader::Init(mojo::Shell* shell) { |
| 55 surface_ = window_->RequestSurface(mus::mojom::SurfaceType::DEFAULT); | 50 surface_ = window_->RequestSurface(mus::mojom::SurfaceType::DEFAULT); |
| 56 surface_->BindToThread(); | 51 surface_->BindToThread(); |
| 57 | 52 |
| 58 mojo::ServiceProviderPtr gpu_service_provider; | 53 shell->ConnectToService("mojo:mus", &gpu_service_); |
| 59 mojo::URLRequestPtr request2(mojo::URLRequest::New()); | |
| 60 request2->url = mojo::String::From("mojo:mus"); | |
| 61 shell->ConnectToApplication(std::move(request2), | |
| 62 mojo::GetProxy(&gpu_service_provider), nullptr, | |
| 63 mojo::CreatePermissiveCapabilityFilter(), | |
| 64 base::Bind(&OnGotRemoteIDs)); | |
| 65 ConnectToService(gpu_service_provider.get(), &gpu_service_); | |
| 66 | |
| 67 mus::mojom::CommandBufferPtr gles2_client; | 54 mus::mojom::CommandBufferPtr gles2_client; |
| 68 gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client)); | 55 gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client)); |
| 69 gles2_context_ = MojoGLES2CreateContext( | 56 gles2_context_ = MojoGLES2CreateContext( |
| 70 gles2_client.PassInterface().PassHandle().release().value(), | 57 gles2_client.PassInterface().PassHandle().release().value(), |
| 71 nullptr, | 58 nullptr, |
| 72 &LostContext, nullptr, mojo::Environment::GetDefaultAsyncWaiter()); | 59 &LostContext, nullptr, mojo::Environment::GetDefaultAsyncWaiter()); |
| 73 MojoGLES2MakeCurrent(gles2_context_); | 60 MojoGLES2MakeCurrent(gles2_context_); |
| 74 } | 61 } |
| 75 | 62 |
| 76 // Sets the color which is RGBA. | 63 // Sets the color which is RGBA. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 glWaitSyncTokenCHROMIUM( | 249 glWaitSyncTokenCHROMIUM( |
| 263 resource->sync_token.To<gpu::SyncToken>().GetConstData()); | 250 resource->sync_token.To<gpu::SyncToken>().GetConstData()); |
| 264 uint32_t texture_id = resource_to_texture_id_map_[resource->id]; | 251 uint32_t texture_id = resource_to_texture_id_map_[resource->id]; |
| 265 DCHECK_NE(0u, texture_id); | 252 DCHECK_NE(0u, texture_id); |
| 266 resource_to_texture_id_map_.erase(resource->id); | 253 resource_to_texture_id_map_.erase(resource->id); |
| 267 glDeleteTextures(1, &texture_id); | 254 glDeleteTextures(1, &texture_id); |
| 268 } | 255 } |
| 269 } | 256 } |
| 270 | 257 |
| 271 } // namespace bitmap_uploader | 258 } // namespace bitmap_uploader |
| OLD | NEW |