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

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

Issue 2008193002: Change mojo geometry structs from using type converters to StructTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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 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/surfaces/surfaces_type_converters.h" 13 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h"
14 #include "components/mus/public/cpp/surfaces/surfaces_utils.h" 14 #include "components/mus/public/cpp/surfaces/surfaces_utils.h"
15 #include "components/mus/public/cpp/window.h" 15 #include "components/mus/public/cpp/window.h"
16 #include "components/mus/public/cpp/window_surface.h" 16 #include "components/mus/public/cpp/window_surface.h"
17 #include "services/shell/public/cpp/connector.h" 17 #include "services/shell/public/cpp/connector.h"
18 #include "ui/gfx/geometry/mojo/geometry_type_converters.h"
19 18
20 namespace bitmap_uploader { 19 namespace bitmap_uploader {
21 namespace { 20 namespace {
22 21
23 const uint32_t g_transparent_color = 0x00000000; 22 const uint32_t g_transparent_color = 0x00000000;
24 23
25 } // namespace 24 } // namespace
26 25
27 const char kBitmapUploaderForAcceleratedWidget[] = 26 const char kBitmapUploaderForAcceleratedWidget[] =
28 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; 27 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__";
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 frame->metadata = std::move(meta); 90 frame->metadata = std::move(meta);
92 91
93 frame->resources.resize(0u); 92 frame->resources.resize(0u);
94 93
95 pass->quads.resize(0u); 94 pass->quads.resize(0u);
96 pass->shared_quad_states.push_back( 95 pass->shared_quad_states.push_back(
97 mojo::CreateDefaultSQS(bounds.size())); 96 mojo::CreateDefaultSQS(bounds.size()));
98 97
99 if (bitmap_.get()) { 98 if (bitmap_.get()) {
100 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); 99 gpu::gles2::GLES2Interface* gl = gles2_context_->interface();
101 mojo::Size bitmap_size; 100 gfx::Size bitmap_size(width_, height_);
102 bitmap_size.width = width_;
103 bitmap_size.height = height_;
104 GLuint texture_id = BindTextureForSize(bitmap_size); 101 GLuint texture_id = BindTextureForSize(bitmap_size);
105 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap_size.width, 102 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap_size.width(),
106 bitmap_size.height, TextureFormat(), GL_UNSIGNED_BYTE, 103 bitmap_size.height(), TextureFormat(), GL_UNSIGNED_BYTE,
107 &((*bitmap_)[0])); 104 &((*bitmap_)[0]));
108 105
109 gpu::Mailbox mailbox; 106 gpu::Mailbox mailbox;
110 gl->GenMailboxCHROMIUM(mailbox.name); 107 gl->GenMailboxCHROMIUM(mailbox.name);
111 gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 108 gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
112 109
113 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); 110 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM();
114 gl->ShallowFlushCHROMIUM(); 111 gl->ShallowFlushCHROMIUM();
115 112
116 gpu::SyncToken sync_token; 113 gpu::SyncToken sync_token;
117 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); 114 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData());
118 115
119 mus::mojom::TransferableResourcePtr resource = 116 mus::mojom::TransferableResourcePtr resource =
120 mus::mojom::TransferableResource::New(); 117 mus::mojom::TransferableResource::New();
121 resource->id = next_resource_id_++; 118 resource->id = next_resource_id_++;
122 resource_to_texture_id_map_[resource->id] = texture_id; 119 resource_to_texture_id_map_[resource->id] = texture_id;
123 resource->format = mus::mojom::ResourceFormat::RGBA_8888; 120 resource->format = mus::mojom::ResourceFormat::RGBA_8888;
124 resource->filter = GL_LINEAR; 121 resource->filter = GL_LINEAR;
125 resource->size = bitmap_size.Clone(); 122 resource->size = bitmap_size;
126 resource->mailbox_holder = 123 resource->mailbox_holder =
127 gpu::MailboxHolder(mailbox, sync_token, GL_TEXTURE_2D); 124 gpu::MailboxHolder(mailbox, sync_token, GL_TEXTURE_2D);
128 resource->read_lock_fences_enabled = false; 125 resource->read_lock_fences_enabled = false;
129 resource->is_software = false; 126 resource->is_software = false;
130 resource->is_overlay_candidate = false; 127 resource->is_overlay_candidate = false;
131 128
132 mus::mojom::QuadPtr quad = mus::mojom::Quad::New(); 129 mus::mojom::QuadPtr quad = mus::mojom::Quad::New();
133 quad->material = mus::mojom::Material::TEXTURE_CONTENT; 130 quad->material = mus::mojom::Material::TEXTURE_CONTENT;
134 131
135 mojo::RectPtr rect = mojo::Rect::New(); 132 gfx::Size rect_size;
136 if (width_ <= bounds.width() && height_ <= bounds.height()) { 133 if (width_ <= bounds.width() && height_ <= bounds.height()) {
137 rect->width = width_; 134 rect_size.SetSize(width_, height_);
138 rect->height = height_;
139 } else { 135 } else {
140 // The source bitmap is larger than the viewport. Resize it while 136 // The source bitmap is larger than the viewport. Resize it while
141 // maintaining the aspect ratio. 137 // maintaining the aspect ratio.
142 float width_ratio = static_cast<float>(width_) / bounds.width(); 138 float width_ratio = static_cast<float>(width_) / bounds.width();
143 float height_ratio = static_cast<float>(height_) / bounds.height(); 139 float height_ratio = static_cast<float>(height_) / bounds.height();
144 if (width_ratio > height_ratio) { 140 if (width_ratio > height_ratio) {
145 rect->width = bounds.width(); 141 rect_size.SetSize(bounds.width(), height_ / width_ratio);
146 rect->height = height_ / width_ratio;
147 } else { 142 } else {
148 rect->height = bounds.height(); 143 rect_size.SetSize(width_ / height_ratio, bounds.height());
149 rect->width = width_ / height_ratio;
150 } 144 }
151 } 145 }
152 quad->rect = rect.Clone(); 146 gfx::Rect rect(rect_size);
153 quad->opaque_rect = rect.Clone(); 147 quad->rect = rect;
154 quad->visible_rect = rect.Clone(); 148 quad->opaque_rect = rect;
149 quad->visible_rect = rect;
155 quad->needs_blending = true; 150 quad->needs_blending = true;
156 quad->shared_quad_state_index = 0u; 151 quad->shared_quad_state_index = 0u;
157 152
158 mus::mojom::TextureQuadStatePtr texture_state = 153 mus::mojom::TextureQuadStatePtr texture_state =
159 mus::mojom::TextureQuadState::New(); 154 mus::mojom::TextureQuadState::New();
160 texture_state->resource_id = resource->id; 155 texture_state->resource_id = resource->id;
161 texture_state->premultiplied_alpha = true; 156 texture_state->premultiplied_alpha = true;
162 texture_state->uv_top_left = mojo::PointF::New(); 157 texture_state->uv_top_left.SetPoint(0.f, 0.f);
163 texture_state->uv_bottom_right = mojo::PointF::New(); 158 texture_state->uv_bottom_right.SetPoint(1.f, 1.f);
164 texture_state->uv_bottom_right->x = 1.f;
165 texture_state->uv_bottom_right->y = 1.f;
166 texture_state->background_color = mus::mojom::Color::New(); 159 texture_state->background_color = mus::mojom::Color::New();
167 texture_state->background_color->rgba = g_transparent_color; 160 texture_state->background_color->rgba = g_transparent_color;
168 for (int i = 0; i < 4; ++i) 161 for (int i = 0; i < 4; ++i)
169 texture_state->vertex_opacity.push_back(1.f); 162 texture_state->vertex_opacity.push_back(1.f);
170 texture_state->y_flipped = false; 163 texture_state->y_flipped = false;
171 164
172 frame->resources.push_back(std::move(resource)); 165 frame->resources.push_back(std::move(resource));
173 quad->texture_quad_state = std::move(texture_state); 166 quad->texture_quad_state = std::move(texture_state);
174 pass->quads.push_back(std::move(quad)); 167 pass->quads.push_back(std::move(quad));
175 } 168 }
176 169
177 if (color_ != g_transparent_color) { 170 if (color_ != g_transparent_color) {
178 mus::mojom::QuadPtr quad = mus::mojom::Quad::New(); 171 mus::mojom::QuadPtr quad = mus::mojom::Quad::New();
179 quad->material = mus::mojom::Material::SOLID_COLOR; 172 quad->material = mus::mojom::Material::SOLID_COLOR;
180 quad->rect = mojo::Rect::From(bounds); 173 quad->rect = bounds;
181 quad->opaque_rect = mojo::Rect::New(); 174 quad->visible_rect = bounds;
182 quad->visible_rect = mojo::Rect::From(bounds);
183 quad->needs_blending = true; 175 quad->needs_blending = true;
184 quad->shared_quad_state_index = 0u; 176 quad->shared_quad_state_index = 0u;
185 177
186 mus::mojom::SolidColorQuadStatePtr color_state = 178 mus::mojom::SolidColorQuadStatePtr color_state =
187 mus::mojom::SolidColorQuadState::New(); 179 mus::mojom::SolidColorQuadState::New();
188 color_state->color = mus::mojom::Color::New(); 180 color_state->color = mus::mojom::Color::New();
189 color_state->color->rgba = color_; 181 color_state->color->rgba = color_;
190 color_state->force_anti_aliasing_off = false; 182 color_state->force_anti_aliasing_off = false;
191 183
192 quad->solid_color_quad_state = std::move(color_state); 184 quad->solid_color_quad_state = std::move(color_state);
193 pass->quads.push_back(std::move(quad)); 185 pass->quads.push_back(std::move(quad));
194 } 186 }
195 187
196 frame->passes.push_back(std::move(pass)); 188 frame->passes.push_back(std::move(pass));
197 189
198 // TODO(rjkroege, fsamuel): We should throttle frames. 190 // TODO(rjkroege, fsamuel): We should throttle frames.
199 surface_->SubmitCompositorFrame(std::move(frame), mojo::Closure()); 191 surface_->SubmitCompositorFrame(std::move(frame), mojo::Closure());
200 } 192 }
201 193
202 uint32_t BitmapUploader::BindTextureForSize(const mojo::Size size) { 194 uint32_t BitmapUploader::BindTextureForSize(const gfx::Size& size) {
203 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); 195 gpu::gles2::GLES2Interface* gl = gles2_context_->interface();
204 // TODO(jamesr): Recycle textures. 196 // TODO(jamesr): Recycle textures.
205 GLuint texture = 0u; 197 GLuint texture = 0u;
206 gl->GenTextures(1, &texture); 198 gl->GenTextures(1, &texture);
207 gl->BindTexture(GL_TEXTURE_2D, texture); 199 gl->BindTexture(GL_TEXTURE_2D, texture);
208 gl->TexImage2D(GL_TEXTURE_2D, 0, TextureFormat(), size.width, size.height, 0, 200 gl->TexImage2D(GL_TEXTURE_2D, 0, TextureFormat(), size.width(), size.height(),
209 TextureFormat(), GL_UNSIGNED_BYTE, 0); 201 0, TextureFormat(), GL_UNSIGNED_BYTE, 0);
210 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 202 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
211 return texture; 203 return texture;
212 } 204 }
213 205
214 void BitmapUploader::SetIdNamespace(uint32_t id_namespace) { 206 void BitmapUploader::SetIdNamespace(uint32_t id_namespace) {
215 id_namespace_ = id_namespace; 207 id_namespace_ = id_namespace;
216 if (color_ != g_transparent_color || bitmap_.get()) 208 if (color_ != g_transparent_color || bitmap_.get())
217 Upload(); 209 Upload();
218 } 210 }
219 211
220 void BitmapUploader::OnResourcesReturned( 212 void BitmapUploader::OnResourcesReturned(
221 mus::WindowSurface* surface, 213 mus::WindowSurface* surface,
222 mojo::Array<mus::mojom::ReturnedResourcePtr> resources) { 214 mojo::Array<mus::mojom::ReturnedResourcePtr> resources) {
223 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); 215 gpu::gles2::GLES2Interface* gl = gles2_context_->interface();
224 // TODO(jamesr): Recycle. 216 // TODO(jamesr): Recycle.
225 for (size_t i = 0; i < resources.size(); ++i) { 217 for (size_t i = 0; i < resources.size(); ++i) {
226 mus::mojom::ReturnedResourcePtr resource = std::move(resources[i]); 218 mus::mojom::ReturnedResourcePtr resource = std::move(resources[i]);
227 DCHECK_EQ(1, resource->count); 219 DCHECK_EQ(1, resource->count);
228 gl->WaitSyncTokenCHROMIUM(resource->sync_token.GetConstData()); 220 gl->WaitSyncTokenCHROMIUM(resource->sync_token.GetConstData());
229 uint32_t texture_id = resource_to_texture_id_map_[resource->id]; 221 uint32_t texture_id = resource_to_texture_id_map_[resource->id];
230 DCHECK_NE(0u, texture_id); 222 DCHECK_NE(0u, texture_id);
231 resource_to_texture_id_map_.erase(resource->id); 223 resource_to_texture_id_map_.erase(resource->id);
232 gl->DeleteTextures(1, &texture_id); 224 gl->DeleteTextures(1, &texture_id);
233 } 225 }
234 } 226 }
235 227
236 } // namespace bitmap_uploader 228 } // namespace bitmap_uploader
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698