OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/scheduler/texture_uploader.h" | 5 #include "cc/scheduler/texture_uploader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 void TextureUploader::EndQuery() { | 128 void TextureUploader::EndQuery() { |
129 available_queries_.front()->End(); | 129 available_queries_.front()->End(); |
130 pending_queries_.push_back(available_queries_.take_front()); | 130 pending_queries_.push_back(available_queries_.take_front()); |
131 num_blocking_texture_uploads_++; | 131 num_blocking_texture_uploads_++; |
132 } | 132 } |
133 | 133 |
134 void TextureUploader::Upload(const uint8* image, | 134 void TextureUploader::Upload(const uint8* image, |
135 gfx::Rect image_rect, | 135 gfx::Rect image_rect, |
136 gfx::Rect source_rect, | 136 gfx::Rect source_rect, |
137 gfx::Vector2d dest_offset, | 137 gfx::Vector2d dest_offset, |
138 GLenum format, | 138 ResourceFormat format, |
139 gfx::Size size) { | 139 gfx::Size size) { |
140 CHECK(image_rect.Contains(source_rect)); | 140 CHECK(image_rect.Contains(source_rect)); |
141 | 141 |
142 bool is_full_upload = dest_offset.IsZero() && source_rect.size() == size; | 142 bool is_full_upload = dest_offset.IsZero() && source_rect.size() == size; |
143 | 143 |
144 if (is_full_upload) | 144 if (is_full_upload) |
145 BeginQuery(); | 145 BeginQuery(); |
146 | 146 |
147 if (use_map_tex_sub_image_) { | 147 if (use_map_tex_sub_image_) { |
148 UploadWithMapTexSubImage( | 148 UploadWithMapTexSubImage( |
(...skipping 22 matching lines...) Expand all Loading... | |
171 | 171 |
172 void TextureUploader::ReleaseCachedQueries() { | 172 void TextureUploader::ReleaseCachedQueries() { |
173 ProcessQueries(); | 173 ProcessQueries(); |
174 available_queries_.clear(); | 174 available_queries_.clear(); |
175 } | 175 } |
176 | 176 |
177 void TextureUploader::UploadWithTexSubImage(const uint8* image, | 177 void TextureUploader::UploadWithTexSubImage(const uint8* image, |
178 gfx::Rect image_rect, | 178 gfx::Rect image_rect, |
179 gfx::Rect source_rect, | 179 gfx::Rect source_rect, |
180 gfx::Vector2d dest_offset, | 180 gfx::Vector2d dest_offset, |
181 GLenum format) { | 181 ResourceFormat format) { |
182 // Instrumentation to debug issue 156107 | 182 // Instrumentation to debug issue 156107 |
183 int source_rect_x = source_rect.x(); | 183 int source_rect_x = source_rect.x(); |
184 int source_rect_y = source_rect.y(); | 184 int source_rect_y = source_rect.y(); |
185 int source_rect_width = source_rect.width(); | 185 int source_rect_width = source_rect.width(); |
186 int source_rect_height = source_rect.height(); | 186 int source_rect_height = source_rect.height(); |
187 int image_rect_x = image_rect.x(); | 187 int image_rect_x = image_rect.x(); |
188 int image_rect_y = image_rect.y(); | 188 int image_rect_y = image_rect.y(); |
189 int image_rect_width = image_rect.width(); | 189 int image_rect_width = image_rect.width(); |
190 int image_rect_height = image_rect.height(); | 190 int image_rect_height = image_rect.height(); |
191 int dest_offset_x = dest_offset.x(); | 191 int dest_offset_x = dest_offset.x(); |
192 int dest_offset_y = dest_offset.y(); | 192 int dest_offset_y = dest_offset.y(); |
193 base::debug::Alias(&image); | 193 base::debug::Alias(&image); |
194 base::debug::Alias(&source_rect_x); | 194 base::debug::Alias(&source_rect_x); |
195 base::debug::Alias(&source_rect_y); | 195 base::debug::Alias(&source_rect_y); |
196 base::debug::Alias(&source_rect_width); | 196 base::debug::Alias(&source_rect_width); |
197 base::debug::Alias(&source_rect_height); | 197 base::debug::Alias(&source_rect_height); |
198 base::debug::Alias(&image_rect_x); | 198 base::debug::Alias(&image_rect_x); |
199 base::debug::Alias(&image_rect_y); | 199 base::debug::Alias(&image_rect_y); |
200 base::debug::Alias(&image_rect_width); | 200 base::debug::Alias(&image_rect_width); |
201 base::debug::Alias(&image_rect_height); | 201 base::debug::Alias(&image_rect_height); |
202 base::debug::Alias(&dest_offset_x); | 202 base::debug::Alias(&dest_offset_x); |
203 base::debug::Alias(&dest_offset_y); | 203 base::debug::Alias(&dest_offset_y); |
204 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexSubImage"); | 204 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexSubImage"); |
205 | 205 |
206 // Offset from image-rect to source-rect. | 206 // Offset from image-rect to source-rect. |
207 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 207 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
208 | 208 |
209 const uint8* pixel_source; | 209 const uint8* pixel_source; |
210 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 210 size_t bytes_per_pixel = ResourceProvider::BytesPerPixel(format); |
211 // Use 4-byte row alignment (OpenGL default) for upload performance. | 211 DCHECK(format != RGBA_4444 || (source_rect.width() % 2) == 0); |
reveman
2013/09/17 13:52:02
I'm still confused by this. Why does width need to
kaanb
2013/09/17 16:41:59
Because we're not setting GL_UNPACK_ALIGNMENT to 2
reveman
2013/09/17 17:44:16
But this breaks support for uneven resource dimens
kaanb
2013/09/17 18:44:26
It turns out we don't have uneven resource dimensi
reveman
2013/09/17 19:13:13
Hm, I think you can set it to an uneven size using
| |
212 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | |
reveman
2013/09/17 17:44:16
I don't think you should be removing this comment.
kaanb
2013/09/17 18:44:26
Done.
| |
213 unsigned int upload_image_stride = | 212 unsigned int upload_image_stride = |
214 RoundUp(bytes_per_pixel * source_rect.width(), 4u); | 213 RoundUp(bytes_per_pixel * source_rect.width(), static_cast<size_t>(4)); |
reveman
2013/09/17 13:52:02
why change this? 4u would be preferred.
kaanb
2013/09/17 16:41:59
I get a compiler error. I guess I could leave 4u a
reveman
2013/09/17 17:44:16
I guess you get this error because you changed the
kaanb
2013/09/17 18:44:26
Done.
| |
215 | 214 |
216 if (upload_image_stride == image_rect.width() * bytes_per_pixel && | 215 if (upload_image_stride == image_rect.width() * bytes_per_pixel && |
217 !offset.x()) { | 216 !offset.x()) { |
218 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()]; | 217 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()]; |
219 } else { | 218 } else { |
220 size_t needed_size = upload_image_stride * source_rect.height(); | 219 size_t needed_size = upload_image_stride * source_rect.height(); |
221 if (sub_image_size_ < needed_size) { | 220 if (sub_image_size_ < needed_size) { |
222 sub_image_.reset(new uint8[needed_size]); | 221 sub_image_.reset(new uint8[needed_size]); |
223 sub_image_size_ = needed_size; | 222 sub_image_size_ = needed_size; |
224 } | 223 } |
225 // Strides not equal, so do a row-by-row memcpy from the | 224 // Strides not equal, so do a row-by-row memcpy from the |
226 // paint results into a temp buffer for uploading. | 225 // paint results into a temp buffer for uploading. |
227 for (int row = 0; row < source_rect.height(); ++row) | 226 for (int row = 0; row < source_rect.height(); ++row) |
228 memcpy(&sub_image_[upload_image_stride * row], | 227 memcpy(&sub_image_[upload_image_stride * row], |
229 &image[bytes_per_pixel * | 228 &image[bytes_per_pixel * |
230 (offset.x() + (offset.y() + row) * image_rect.width())], | 229 (offset.x() + (offset.y() + row) * image_rect.width())], |
231 source_rect.width() * bytes_per_pixel); | 230 source_rect.width() * bytes_per_pixel); |
232 | 231 |
233 pixel_source = &sub_image_[0]; | 232 pixel_source = &sub_image_[0]; |
234 } | 233 } |
235 | 234 |
236 context_->texSubImage2D(GL_TEXTURE_2D, | 235 context_->texSubImage2D(GL_TEXTURE_2D, |
237 0, | 236 0, |
238 dest_offset.x(), | 237 dest_offset.x(), |
239 dest_offset.y(), | 238 dest_offset.y(), |
240 source_rect.width(), | 239 source_rect.width(), |
241 source_rect.height(), | 240 source_rect.height(), |
242 format, | 241 ResourceProvider::GetGLDataFormat(format), |
243 GL_UNSIGNED_BYTE, | 242 ResourceProvider::GetGLDataType(format), |
244 pixel_source); | 243 pixel_source); |
245 } | 244 } |
246 | 245 |
247 void TextureUploader::UploadWithMapTexSubImage(const uint8* image, | 246 void TextureUploader::UploadWithMapTexSubImage(const uint8* image, |
248 gfx::Rect image_rect, | 247 gfx::Rect image_rect, |
249 gfx::Rect source_rect, | 248 gfx::Rect source_rect, |
250 gfx::Vector2d dest_offset, | 249 gfx::Vector2d dest_offset, |
251 GLenum format) { | 250 ResourceFormat format) { |
252 // Instrumentation to debug issue 156107 | 251 // Instrumentation to debug issue 156107 |
253 int source_rect_x = source_rect.x(); | 252 int source_rect_x = source_rect.x(); |
254 int source_rect_y = source_rect.y(); | 253 int source_rect_y = source_rect.y(); |
255 int source_rect_width = source_rect.width(); | 254 int source_rect_width = source_rect.width(); |
256 int source_rect_height = source_rect.height(); | 255 int source_rect_height = source_rect.height(); |
257 int image_rect_x = image_rect.x(); | 256 int image_rect_x = image_rect.x(); |
258 int image_rect_y = image_rect.y(); | 257 int image_rect_y = image_rect.y(); |
259 int image_rect_width = image_rect.width(); | 258 int image_rect_width = image_rect.width(); |
260 int image_rect_height = image_rect.height(); | 259 int image_rect_height = image_rect.height(); |
261 int dest_offset_x = dest_offset.x(); | 260 int dest_offset_x = dest_offset.x(); |
262 int dest_offset_y = dest_offset.y(); | 261 int dest_offset_y = dest_offset.y(); |
263 base::debug::Alias(&image); | 262 base::debug::Alias(&image); |
264 base::debug::Alias(&source_rect_x); | 263 base::debug::Alias(&source_rect_x); |
265 base::debug::Alias(&source_rect_y); | 264 base::debug::Alias(&source_rect_y); |
266 base::debug::Alias(&source_rect_width); | 265 base::debug::Alias(&source_rect_width); |
267 base::debug::Alias(&source_rect_height); | 266 base::debug::Alias(&source_rect_height); |
268 base::debug::Alias(&image_rect_x); | 267 base::debug::Alias(&image_rect_x); |
269 base::debug::Alias(&image_rect_y); | 268 base::debug::Alias(&image_rect_y); |
270 base::debug::Alias(&image_rect_width); | 269 base::debug::Alias(&image_rect_width); |
271 base::debug::Alias(&image_rect_height); | 270 base::debug::Alias(&image_rect_height); |
272 base::debug::Alias(&dest_offset_x); | 271 base::debug::Alias(&dest_offset_x); |
273 base::debug::Alias(&dest_offset_y); | 272 base::debug::Alias(&dest_offset_y); |
274 | 273 |
275 TRACE_EVENT0("cc", "TextureUploader::UploadWithMapTexSubImage"); | 274 TRACE_EVENT0("cc", "TextureUploader::UploadWithMapTexSubImage"); |
276 | 275 |
277 // Offset from image-rect to source-rect. | 276 // Offset from image-rect to source-rect. |
278 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 277 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
279 | 278 |
280 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 279 size_t bytes_per_pixel = ResourceProvider::BytesPerPixel(format); |
281 // Use 4-byte row alignment (OpenGL default) for upload performance. | 280 DCHECK(format != RGBA_4444 || (source_rect.width() % 2) == 0); |
282 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | |
283 unsigned int upload_image_stride = | 281 unsigned int upload_image_stride = |
284 RoundUp(bytes_per_pixel * source_rect.width(), 4u); | 282 RoundUp(bytes_per_pixel * source_rect.width(), static_cast<size_t>(4)); |
reveman
2013/09/17 13:52:02
same here. why not 4u?
kaanb
2013/09/17 16:41:59
same answer.
reveman
2013/09/17 17:44:16
same suggestions as above.
kaanb
2013/09/17 18:44:26
Done.
| |
285 | 283 |
286 // Upload tile data via a mapped transfer buffer | 284 // Upload tile data via a mapped transfer buffer |
287 uint8* pixel_dest = static_cast<uint8*>( | 285 uint8* pixel_dest = static_cast<uint8*>( |
288 context_->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 286 context_->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
289 0, | 287 0, |
290 dest_offset.x(), | 288 dest_offset.x(), |
291 dest_offset.y(), | 289 dest_offset.y(), |
292 source_rect.width(), | 290 source_rect.width(), |
293 source_rect.height(), | 291 source_rect.height(), |
294 format, | 292 ResourceProvider::GetGLDataFormat( |
295 GL_UNSIGNED_BYTE, | 293 format), |
294 ResourceProvider::GetGLDataType( | |
295 format), | |
296 GL_WRITE_ONLY)); | 296 GL_WRITE_ONLY)); |
297 | 297 |
298 if (!pixel_dest) { | 298 if (!pixel_dest) { |
299 UploadWithTexSubImage(image, image_rect, source_rect, dest_offset, format); | 299 UploadWithTexSubImage(image, image_rect, source_rect, dest_offset, format); |
300 return; | 300 return; |
301 } | 301 } |
302 | 302 |
303 if (upload_image_stride == image_rect.width() * bytes_per_pixel && | 303 if (upload_image_stride == image_rect.width() * bytes_per_pixel && |
304 !offset.x()) { | 304 !offset.x()) { |
305 memcpy(pixel_dest, | 305 memcpy(pixel_dest, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 textures_per_second_history_.erase(textures_per_second_history_.begin()); | 341 textures_per_second_history_.erase(textures_per_second_history_.begin()); |
342 textures_per_second_history_.erase(--textures_per_second_history_.end()); | 342 textures_per_second_history_.erase(--textures_per_second_history_.end()); |
343 } | 343 } |
344 textures_per_second_history_.insert(textures_per_second); | 344 textures_per_second_history_.insert(textures_per_second); |
345 | 345 |
346 available_queries_.push_back(pending_queries_.take_front()); | 346 available_queries_.push_back(pending_queries_.take_front()); |
347 } | 347 } |
348 } | 348 } |
349 | 349 |
350 } // namespace cc | 350 } // namespace cc |
OLD | NEW |