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 ResourceProvider::Format 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( |
149 image, image_rect, source_rect, dest_offset, format); | 149 image, image_rect, source_rect, dest_offset, format); |
150 } else { | 150 } else { |
151 UploadWithTexSubImage(image, image_rect, source_rect, dest_offset, format); | 151 UploadWithTexSubImage( |
152 image, image_rect, source_rect, dest_offset, format); | |
152 } | 153 } |
153 | 154 |
154 if (is_full_upload) | 155 if (is_full_upload) |
155 EndQuery(); | 156 EndQuery(); |
156 | 157 |
157 num_texture_uploads_since_last_flush_++; | 158 num_texture_uploads_since_last_flush_++; |
158 if (num_texture_uploads_since_last_flush_ >= kTextureUploadFlushPeriod) | 159 if (num_texture_uploads_since_last_flush_ >= kTextureUploadFlushPeriod) |
159 Flush(); | 160 Flush(); |
160 } | 161 } |
161 | 162 |
162 void TextureUploader::Flush() { | 163 void TextureUploader::Flush() { |
163 if (!num_texture_uploads_since_last_flush_) | 164 if (!num_texture_uploads_since_last_flush_) |
164 return; | 165 return; |
165 | 166 |
166 if (use_shallow_flush_) | 167 if (use_shallow_flush_) |
167 context_->shallowFlushCHROMIUM(); | 168 context_->shallowFlushCHROMIUM(); |
168 | 169 |
169 num_texture_uploads_since_last_flush_ = 0; | 170 num_texture_uploads_since_last_flush_ = 0; |
170 } | 171 } |
171 | 172 |
172 void TextureUploader::ReleaseCachedQueries() { | 173 void TextureUploader::ReleaseCachedQueries() { |
173 ProcessQueries(); | 174 ProcessQueries(); |
174 available_queries_.clear(); | 175 available_queries_.clear(); |
175 } | 176 } |
176 | 177 |
177 void TextureUploader::UploadWithTexSubImage(const uint8* image, | 178 void TextureUploader::UploadWithTexSubImage( |
178 gfx::Rect image_rect, | 179 const uint8* image, |
179 gfx::Rect source_rect, | 180 gfx::Rect image_rect, |
180 gfx::Vector2d dest_offset, | 181 gfx::Rect source_rect, |
181 GLenum format) { | 182 gfx::Vector2d dest_offset, |
183 ResourceProvider::Format format) { | |
182 // Instrumentation to debug issue 156107 | 184 // Instrumentation to debug issue 156107 |
183 int source_rect_x = source_rect.x(); | 185 int source_rect_x = source_rect.x(); |
184 int source_rect_y = source_rect.y(); | 186 int source_rect_y = source_rect.y(); |
185 int source_rect_width = source_rect.width(); | 187 int source_rect_width = source_rect.width(); |
186 int source_rect_height = source_rect.height(); | 188 int source_rect_height = source_rect.height(); |
187 int image_rect_x = image_rect.x(); | 189 int image_rect_x = image_rect.x(); |
188 int image_rect_y = image_rect.y(); | 190 int image_rect_y = image_rect.y(); |
189 int image_rect_width = image_rect.width(); | 191 int image_rect_width = image_rect.width(); |
190 int image_rect_height = image_rect.height(); | 192 int image_rect_height = image_rect.height(); |
191 int dest_offset_x = dest_offset.x(); | 193 int dest_offset_x = dest_offset.x(); |
192 int dest_offset_y = dest_offset.y(); | 194 int dest_offset_y = dest_offset.y(); |
193 base::debug::Alias(&image); | 195 base::debug::Alias(&image); |
194 base::debug::Alias(&source_rect_x); | 196 base::debug::Alias(&source_rect_x); |
195 base::debug::Alias(&source_rect_y); | 197 base::debug::Alias(&source_rect_y); |
196 base::debug::Alias(&source_rect_width); | 198 base::debug::Alias(&source_rect_width); |
197 base::debug::Alias(&source_rect_height); | 199 base::debug::Alias(&source_rect_height); |
198 base::debug::Alias(&image_rect_x); | 200 base::debug::Alias(&image_rect_x); |
199 base::debug::Alias(&image_rect_y); | 201 base::debug::Alias(&image_rect_y); |
200 base::debug::Alias(&image_rect_width); | 202 base::debug::Alias(&image_rect_width); |
201 base::debug::Alias(&image_rect_height); | 203 base::debug::Alias(&image_rect_height); |
202 base::debug::Alias(&dest_offset_x); | 204 base::debug::Alias(&dest_offset_x); |
203 base::debug::Alias(&dest_offset_y); | 205 base::debug::Alias(&dest_offset_y); |
204 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexSubImage"); | 206 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexSubImage"); |
205 | 207 |
206 // Offset from image-rect to source-rect. | 208 // Offset from image-rect to source-rect. |
207 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 209 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
208 | 210 |
209 const uint8* pixel_source; | 211 const uint8* pixel_source; |
210 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 212 unsigned int bytes_per_pixel = ResourceProvider::BytesPerPixel(format); |
211 // Use 4-byte row alignment (OpenGL default) for upload performance. | 213 DCHECK(format != ResourceProvider::RGBA_4444 || |
212 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | 214 (source_rect.width() % 2) == 0); |
213 unsigned int upload_image_stride = | 215 unsigned int upload_image_stride = |
214 RoundUp(bytes_per_pixel * source_rect.width(), 4u); | 216 RoundUp(bytes_per_pixel * source_rect.width(), |
217 ResourceProvider::GetStride(format)); | |
piman
2013/09/13 04:56:51
I don't understand the change here, to accomodate
kaanb
2013/09/13 19:57:39
Done.
| |
215 | 218 |
216 if (upload_image_stride == image_rect.width() * bytes_per_pixel && | 219 if (upload_image_stride == image_rect.width() * bytes_per_pixel && |
217 !offset.x()) { | 220 !offset.x()) { |
218 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()]; | 221 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()]; |
219 } else { | 222 } else { |
220 size_t needed_size = upload_image_stride * source_rect.height(); | 223 size_t needed_size = upload_image_stride * source_rect.height(); |
221 if (sub_image_size_ < needed_size) { | 224 if (sub_image_size_ < needed_size) { |
222 sub_image_.reset(new uint8[needed_size]); | 225 sub_image_.reset(new uint8[needed_size]); |
223 sub_image_size_ = needed_size; | 226 sub_image_size_ = needed_size; |
224 } | 227 } |
225 // Strides not equal, so do a row-by-row memcpy from the | 228 // Strides not equal, so do a row-by-row memcpy from the |
226 // paint results into a temp buffer for uploading. | 229 // paint results into a temp buffer for uploading. |
227 for (int row = 0; row < source_rect.height(); ++row) | 230 for (int row = 0; row < source_rect.height(); ++row) |
228 memcpy(&sub_image_[upload_image_stride * row], | 231 memcpy(&sub_image_[upload_image_stride * row], |
229 &image[bytes_per_pixel * | 232 &image[bytes_per_pixel * |
230 (offset.x() + (offset.y() + row) * image_rect.width())], | 233 (offset.x() + (offset.y() + row) * image_rect.width())], |
231 source_rect.width() * bytes_per_pixel); | 234 source_rect.width() * bytes_per_pixel); |
232 | 235 |
233 pixel_source = &sub_image_[0]; | 236 pixel_source = &sub_image_[0]; |
234 } | 237 } |
235 | 238 |
236 context_->texSubImage2D(GL_TEXTURE_2D, | 239 context_->texSubImage2D(GL_TEXTURE_2D, |
237 0, | 240 0, |
238 dest_offset.x(), | 241 dest_offset.x(), |
239 dest_offset.y(), | 242 dest_offset.y(), |
240 source_rect.width(), | 243 source_rect.width(), |
241 source_rect.height(), | 244 source_rect.height(), |
242 format, | 245 ResourceProvider::GetGLDataFormat(format), |
243 GL_UNSIGNED_BYTE, | 246 ResourceProvider::GetGLDataType(format), |
244 pixel_source); | 247 pixel_source); |
245 } | 248 } |
246 | 249 |
247 void TextureUploader::UploadWithMapTexSubImage(const uint8* image, | 250 void TextureUploader::UploadWithMapTexSubImage( |
248 gfx::Rect image_rect, | 251 const uint8* image, |
249 gfx::Rect source_rect, | 252 gfx::Rect image_rect, |
250 gfx::Vector2d dest_offset, | 253 gfx::Rect source_rect, |
251 GLenum format) { | 254 gfx::Vector2d dest_offset, |
255 ResourceProvider::Format format) { | |
252 // Instrumentation to debug issue 156107 | 256 // Instrumentation to debug issue 156107 |
253 int source_rect_x = source_rect.x(); | 257 int source_rect_x = source_rect.x(); |
254 int source_rect_y = source_rect.y(); | 258 int source_rect_y = source_rect.y(); |
255 int source_rect_width = source_rect.width(); | 259 int source_rect_width = source_rect.width(); |
256 int source_rect_height = source_rect.height(); | 260 int source_rect_height = source_rect.height(); |
257 int image_rect_x = image_rect.x(); | 261 int image_rect_x = image_rect.x(); |
258 int image_rect_y = image_rect.y(); | 262 int image_rect_y = image_rect.y(); |
259 int image_rect_width = image_rect.width(); | 263 int image_rect_width = image_rect.width(); |
260 int image_rect_height = image_rect.height(); | 264 int image_rect_height = image_rect.height(); |
261 int dest_offset_x = dest_offset.x(); | 265 int dest_offset_x = dest_offset.x(); |
262 int dest_offset_y = dest_offset.y(); | 266 int dest_offset_y = dest_offset.y(); |
263 base::debug::Alias(&image); | 267 base::debug::Alias(&image); |
264 base::debug::Alias(&source_rect_x); | 268 base::debug::Alias(&source_rect_x); |
265 base::debug::Alias(&source_rect_y); | 269 base::debug::Alias(&source_rect_y); |
266 base::debug::Alias(&source_rect_width); | 270 base::debug::Alias(&source_rect_width); |
267 base::debug::Alias(&source_rect_height); | 271 base::debug::Alias(&source_rect_height); |
268 base::debug::Alias(&image_rect_x); | 272 base::debug::Alias(&image_rect_x); |
269 base::debug::Alias(&image_rect_y); | 273 base::debug::Alias(&image_rect_y); |
270 base::debug::Alias(&image_rect_width); | 274 base::debug::Alias(&image_rect_width); |
271 base::debug::Alias(&image_rect_height); | 275 base::debug::Alias(&image_rect_height); |
272 base::debug::Alias(&dest_offset_x); | 276 base::debug::Alias(&dest_offset_x); |
273 base::debug::Alias(&dest_offset_y); | 277 base::debug::Alias(&dest_offset_y); |
274 | 278 |
275 TRACE_EVENT0("cc", "TextureUploader::UploadWithMapTexSubImage"); | 279 TRACE_EVENT0("cc", "TextureUploader::UploadWithMapTexSubImage"); |
276 | 280 |
277 // Offset from image-rect to source-rect. | 281 // Offset from image-rect to source-rect. |
278 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 282 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
279 | 283 |
280 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 284 unsigned int bytes_per_pixel = ResourceProvider::BytesPerPixel(format); |
enne (OOO)
2013/09/13 01:39:44
unsigned int => size_t, here and elsewhere.
kaanb
2013/09/13 03:43:56
Done.
| |
281 // Use 4-byte row alignment (OpenGL default) for upload performance. | 285 DCHECK(format != ResourceProvider::RGBA_4444 || |
282 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | 286 (source_rect.width() % 2) == 0); |
283 unsigned int upload_image_stride = | 287 unsigned int upload_image_stride = |
284 RoundUp(bytes_per_pixel * source_rect.width(), 4u); | 288 RoundUp(bytes_per_pixel * source_rect.width(), |
289 ResourceProvider::GetStride(format)); | |
285 | 290 |
286 // Upload tile data via a mapped transfer buffer | |
287 uint8* pixel_dest = static_cast<uint8*>( | 291 uint8* pixel_dest = static_cast<uint8*>( |
288 context_->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 292 context_->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
289 0, | 293 0, |
290 dest_offset.x(), | 294 dest_offset.x(), |
291 dest_offset.y(), | 295 dest_offset.y(), |
292 source_rect.width(), | 296 source_rect.width(), |
293 source_rect.height(), | 297 source_rect.height(), |
294 format, | 298 ResourceProvider::GetGLDataFormat( |
295 GL_UNSIGNED_BYTE, | 299 format), |
300 ResourceProvider::GetGLDataType( | |
301 format), | |
296 GL_WRITE_ONLY)); | 302 GL_WRITE_ONLY)); |
297 | 303 |
298 if (!pixel_dest) { | 304 if (!pixel_dest) { |
299 UploadWithTexSubImage(image, image_rect, source_rect, dest_offset, format); | 305 UploadWithTexSubImage(image, image_rect, source_rect, dest_offset, format); |
300 return; | 306 return; |
301 } | 307 } |
302 | 308 |
303 if (upload_image_stride == image_rect.width() * bytes_per_pixel && | 309 if (upload_image_stride == image_rect.width() * bytes_per_pixel && |
304 !offset.x()) { | 310 !offset.x()) { |
305 memcpy(pixel_dest, | 311 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()); | 347 textures_per_second_history_.erase(textures_per_second_history_.begin()); |
342 textures_per_second_history_.erase(--textures_per_second_history_.end()); | 348 textures_per_second_history_.erase(--textures_per_second_history_.end()); |
343 } | 349 } |
344 textures_per_second_history_.insert(textures_per_second); | 350 textures_per_second_history_.insert(textures_per_second); |
345 | 351 |
346 available_queries_.push_back(pending_queries_.take_front()); | 352 available_queries_.push_back(pending_queries_.take_front()); |
347 } | 353 } |
348 } | 354 } |
349 | 355 |
350 } // namespace cc | 356 } // namespace cc |
OLD | NEW |