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/gles2_context.h" | 12 #include "components/mus/public/cpp/gles2_context.h" |
| 13 #include "components/mus/public/cpp/gpu_service.h" |
13 #include "components/mus/public/cpp/window.h" | 14 #include "components/mus/public/cpp/window.h" |
14 #include "components/mus/public/cpp/window_surface.h" | 15 #include "components/mus/public/cpp/window_surface.h" |
15 #include "mojo/converters/geometry/geometry_type_converters.h" | 16 #include "mojo/converters/geometry/geometry_type_converters.h" |
16 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 17 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
17 #include "mojo/converters/surfaces/surfaces_utils.h" | 18 #include "mojo/converters/surfaces/surfaces_utils.h" |
18 #include "services/shell/public/cpp/connector.h" | 19 #include "services/shell/public/cpp/connector.h" |
19 | 20 |
20 namespace bitmap_uploader { | 21 namespace bitmap_uploader { |
21 namespace { | 22 namespace { |
22 | 23 |
(...skipping 14 matching lines...) Expand all Loading... |
37 id_namespace_(0u) {} | 38 id_namespace_(0u) {} |
38 | 39 |
39 BitmapUploader::~BitmapUploader() { | 40 BitmapUploader::~BitmapUploader() { |
40 } | 41 } |
41 | 42 |
42 void BitmapUploader::Init(shell::Connector* connector) { | 43 void BitmapUploader::Init(shell::Connector* connector) { |
43 surface_ = window_->RequestSurface(mus::mojom::SurfaceType::DEFAULT); | 44 surface_ = window_->RequestSurface(mus::mojom::SurfaceType::DEFAULT); |
44 surface_->BindToThread(); | 45 surface_->BindToThread(); |
45 surface_->set_client(this); | 46 surface_->set_client(this); |
46 | 47 |
47 connector->ConnectToInterface("mojo:mus", &gpu_service_); | 48 mojo::ScopedMessagePipeHandle scoped_handle; |
48 mus::mojom::CommandBufferPtr gles2_client; | 49 if (!mus::GpuService::UseChromeGpuCommandBuffer()) { |
49 gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client)); | 50 connector->ConnectToInterface("mojo:mus", &gpu_service_); |
50 gles2_context_.reset(new mus::GLES2Context( | 51 mus::mojom::CommandBufferPtr gles2_client; |
51 std::vector<int32_t>(), gles2_client.PassInterface().PassHandle())); | 52 gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client)); |
| 53 scoped_handle = gles2_client.PassInterface().PassHandle(); |
| 54 } else { |
| 55 mus::GpuService::Initialize(connector); |
| 56 } |
| 57 |
| 58 gles2_context_.reset( |
| 59 new mus::GLES2Context(std::vector<int32_t>(), std::move(scoped_handle))); |
52 DCHECK(gles2_context_->Initialize()); | 60 DCHECK(gles2_context_->Initialize()); |
53 } | 61 } |
54 | 62 |
55 // Sets the color which is RGBA. | 63 // Sets the color which is RGBA. |
56 void BitmapUploader::SetColor(uint32_t color) { | 64 void BitmapUploader::SetColor(uint32_t color) { |
57 if (color_ == color) | 65 if (color_ == color) |
58 return; | 66 return; |
59 color_ = color; | 67 color_ = color; |
60 if (surface_) | 68 if (surface_) |
61 Upload(); | 69 Upload(); |
(...skipping 28 matching lines...) Expand all Loading... |
90 meta->device_scale_factor = 1.0f; | 98 meta->device_scale_factor = 1.0f; |
91 frame->metadata = std::move(meta); | 99 frame->metadata = std::move(meta); |
92 | 100 |
93 frame->resources.resize(0u); | 101 frame->resources.resize(0u); |
94 | 102 |
95 pass->quads.resize(0u); | 103 pass->quads.resize(0u); |
96 pass->shared_quad_states.push_back( | 104 pass->shared_quad_states.push_back( |
97 mojo::CreateDefaultSQS(bounds.size())); | 105 mojo::CreateDefaultSQS(bounds.size())); |
98 | 106 |
99 if (bitmap_.get()) { | 107 if (bitmap_.get()) { |
100 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); | |
101 mojo::Size bitmap_size; | 108 mojo::Size bitmap_size; |
102 bitmap_size.width = width_; | 109 bitmap_size.width = width_; |
103 bitmap_size.height = height_; | 110 bitmap_size.height = height_; |
| 111 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); |
104 GLuint texture_id = BindTextureForSize(bitmap_size); | 112 GLuint texture_id = BindTextureForSize(bitmap_size); |
105 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap_size.width, | 113 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap_size.width, |
106 bitmap_size.height, TextureFormat(), GL_UNSIGNED_BYTE, | 114 bitmap_size.height, TextureFormat(), GL_UNSIGNED_BYTE, |
107 &((*bitmap_)[0])); | 115 &((*bitmap_)[0])); |
108 | 116 |
109 gpu::Mailbox mailbox; | 117 gpu::Mailbox mailbox; |
110 gl->GenMailboxCHROMIUM(mailbox.name); | 118 gl->GenMailboxCHROMIUM(mailbox.name); |
111 gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 119 gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
112 | 120 |
113 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); | 121 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 DCHECK_EQ(1, resource->count); | 235 DCHECK_EQ(1, resource->count); |
228 gl->WaitSyncTokenCHROMIUM(resource->sync_token.GetConstData()); | 236 gl->WaitSyncTokenCHROMIUM(resource->sync_token.GetConstData()); |
229 uint32_t texture_id = resource_to_texture_id_map_[resource->id]; | 237 uint32_t texture_id = resource_to_texture_id_map_[resource->id]; |
230 DCHECK_NE(0u, texture_id); | 238 DCHECK_NE(0u, texture_id); |
231 resource_to_texture_id_map_.erase(resource->id); | 239 resource_to_texture_id_map_.erase(resource->id); |
232 gl->DeleteTextures(1, &texture_id); | 240 gl->DeleteTextures(1, &texture_id); |
233 } | 241 } |
234 } | 242 } |
235 | 243 |
236 } // namespace bitmap_uploader | 244 } // namespace bitmap_uploader |
OLD | NEW |