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/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 ResourceProvider::Resource::Resource() | 203 ResourceProvider::Resource::Resource() |
204 : child_id(0), | 204 : child_id(0), |
205 gl_id(0), | 205 gl_id(0), |
206 gl_pixel_buffer_id(0), | 206 gl_pixel_buffer_id(0), |
207 gl_upload_query_id(0), | 207 gl_upload_query_id(0), |
208 pixels(NULL), | 208 pixels(NULL), |
209 pixel_buffer(NULL), | 209 pixel_buffer(NULL), |
210 lock_for_read_count(0), | 210 lock_for_read_count(0), |
211 imported_count(0), | 211 imported_count(0), |
212 exported_count(0), | 212 exported_count(0), |
| 213 image_id(0), |
| 214 bound_image_id(0), |
| 215 dirty_image(false), |
213 locked_for_write(false), | 216 locked_for_write(false), |
214 origin(Internal), | 217 lost(false), |
215 marked_for_deletion(false), | 218 marked_for_deletion(false), |
216 pending_set_pixels(false), | 219 pending_set_pixels(false), |
217 set_pixels_completion_forced(false), | 220 set_pixels_completion_forced(false), |
218 allocated(false), | 221 allocated(false), |
219 enable_read_lock_fences(false), | 222 enable_read_lock_fences(false), |
| 223 has_shared_bitmap_id(false), |
220 read_lock_fence(NULL), | 224 read_lock_fence(NULL), |
221 size(), | 225 size(), |
| 226 origin(Internal), |
222 target(0), | 227 target(0), |
223 original_filter(0), | 228 original_filter(0), |
224 filter(0), | 229 filter(0), |
225 image_id(0), | |
226 bound_image_id(0), | |
227 dirty_image(false), | |
228 texture_pool(0), | 230 texture_pool(0), |
229 wrap_mode(0), | 231 wrap_mode(0), |
230 lost(false), | |
231 hint(TextureUsageAny), | 232 hint(TextureUsageAny), |
232 type(InvalidType), | 233 type(InvalidType), |
233 format(RGBA_8888), | 234 format(RGBA_8888), |
234 has_shared_bitmap_id(false), | |
235 shared_bitmap(NULL) {} | 235 shared_bitmap(NULL) {} |
236 | 236 |
237 ResourceProvider::Resource::~Resource() {} | 237 ResourceProvider::Resource::~Resource() {} |
238 | 238 |
239 ResourceProvider::Resource::Resource(GLuint texture_id, | 239 ResourceProvider::Resource::Resource(GLuint texture_id, |
240 const gfx::Size& size, | 240 const gfx::Size& size, |
241 Origin origin, | 241 Origin origin, |
242 GLenum target, | 242 GLenum target, |
243 GLenum filter, | 243 GLenum filter, |
244 GLenum texture_pool, | 244 GLenum texture_pool, |
245 GLint wrap_mode, | 245 GLint wrap_mode, |
246 TextureUsageHint hint, | 246 TextureUsageHint hint, |
247 ResourceFormat format) | 247 ResourceFormat format) |
248 : child_id(0), | 248 : child_id(0), |
249 gl_id(texture_id), | 249 gl_id(texture_id), |
250 gl_pixel_buffer_id(0), | 250 gl_pixel_buffer_id(0), |
251 gl_upload_query_id(0), | 251 gl_upload_query_id(0), |
252 pixels(NULL), | 252 pixels(NULL), |
253 pixel_buffer(NULL), | 253 pixel_buffer(NULL), |
254 lock_for_read_count(0), | 254 lock_for_read_count(0), |
255 imported_count(0), | 255 imported_count(0), |
256 exported_count(0), | 256 exported_count(0), |
| 257 image_id(0), |
| 258 bound_image_id(0), |
| 259 dirty_image(false), |
257 locked_for_write(false), | 260 locked_for_write(false), |
258 origin(origin), | 261 lost(false), |
259 marked_for_deletion(false), | 262 marked_for_deletion(false), |
260 pending_set_pixels(false), | 263 pending_set_pixels(false), |
261 set_pixels_completion_forced(false), | 264 set_pixels_completion_forced(false), |
262 allocated(false), | 265 allocated(false), |
263 enable_read_lock_fences(false), | 266 enable_read_lock_fences(false), |
| 267 has_shared_bitmap_id(false), |
264 read_lock_fence(NULL), | 268 read_lock_fence(NULL), |
265 size(size), | 269 size(size), |
| 270 origin(origin), |
266 target(target), | 271 target(target), |
267 original_filter(filter), | 272 original_filter(filter), |
268 filter(filter), | 273 filter(filter), |
269 image_id(0), | |
270 bound_image_id(0), | |
271 dirty_image(false), | |
272 texture_pool(texture_pool), | 274 texture_pool(texture_pool), |
273 wrap_mode(wrap_mode), | 275 wrap_mode(wrap_mode), |
274 lost(false), | |
275 hint(hint), | 276 hint(hint), |
276 type(GLTexture), | 277 type(GLTexture), |
277 format(format), | 278 format(format), |
278 has_shared_bitmap_id(false), | |
279 shared_bitmap(NULL) { | 279 shared_bitmap(NULL) { |
280 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 280 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
281 DCHECK_EQ(origin == Internal, !!texture_pool); | 281 DCHECK_EQ(origin == Internal, !!texture_pool); |
282 } | 282 } |
283 | 283 |
284 ResourceProvider::Resource::Resource(uint8_t* pixels, | 284 ResourceProvider::Resource::Resource(uint8_t* pixels, |
285 SharedBitmap* bitmap, | 285 SharedBitmap* bitmap, |
286 const gfx::Size& size, | 286 const gfx::Size& size, |
287 Origin origin, | 287 Origin origin, |
288 GLenum filter, | 288 GLenum filter, |
289 GLint wrap_mode) | 289 GLint wrap_mode) |
290 : child_id(0), | 290 : child_id(0), |
291 gl_id(0), | 291 gl_id(0), |
292 gl_pixel_buffer_id(0), | 292 gl_pixel_buffer_id(0), |
293 gl_upload_query_id(0), | 293 gl_upload_query_id(0), |
294 pixels(pixels), | 294 pixels(pixels), |
295 pixel_buffer(NULL), | 295 pixel_buffer(NULL), |
296 lock_for_read_count(0), | 296 lock_for_read_count(0), |
297 imported_count(0), | 297 imported_count(0), |
298 exported_count(0), | 298 exported_count(0), |
| 299 image_id(0), |
| 300 bound_image_id(0), |
| 301 dirty_image(false), |
299 locked_for_write(false), | 302 locked_for_write(false), |
300 origin(origin), | 303 lost(false), |
301 marked_for_deletion(false), | 304 marked_for_deletion(false), |
302 pending_set_pixels(false), | 305 pending_set_pixels(false), |
303 set_pixels_completion_forced(false), | 306 set_pixels_completion_forced(false), |
304 allocated(false), | 307 allocated(false), |
305 enable_read_lock_fences(false), | 308 enable_read_lock_fences(false), |
| 309 has_shared_bitmap_id(!!bitmap), |
306 read_lock_fence(NULL), | 310 read_lock_fence(NULL), |
307 size(size), | 311 size(size), |
| 312 origin(origin), |
308 target(0), | 313 target(0), |
309 original_filter(filter), | 314 original_filter(filter), |
310 filter(filter), | 315 filter(filter), |
311 image_id(0), | |
312 bound_image_id(0), | |
313 dirty_image(false), | |
314 texture_pool(0), | 316 texture_pool(0), |
315 wrap_mode(wrap_mode), | 317 wrap_mode(wrap_mode), |
316 lost(false), | |
317 hint(TextureUsageAny), | 318 hint(TextureUsageAny), |
318 type(Bitmap), | 319 type(Bitmap), |
319 format(RGBA_8888), | 320 format(RGBA_8888), |
320 has_shared_bitmap_id(!!bitmap), | |
321 shared_bitmap(bitmap) { | 321 shared_bitmap(bitmap) { |
322 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 322 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
323 DCHECK(origin == Delegated || pixels); | 323 DCHECK(origin == Delegated || pixels); |
324 if (bitmap) | 324 if (bitmap) |
325 shared_bitmap_id = bitmap->id(); | 325 shared_bitmap_id = bitmap->id(); |
326 } | 326 } |
327 | 327 |
328 ResourceProvider::Resource::Resource(const SharedBitmapId& bitmap_id, | 328 ResourceProvider::Resource::Resource(const SharedBitmapId& bitmap_id, |
329 const gfx::Size& size, | 329 const gfx::Size& size, |
330 Origin origin, | 330 Origin origin, |
331 GLenum filter, | 331 GLenum filter, |
332 GLint wrap_mode) | 332 GLint wrap_mode) |
333 : child_id(0), | 333 : child_id(0), |
334 gl_id(0), | 334 gl_id(0), |
335 gl_pixel_buffer_id(0), | 335 gl_pixel_buffer_id(0), |
336 gl_upload_query_id(0), | 336 gl_upload_query_id(0), |
337 pixels(NULL), | 337 pixels(NULL), |
338 pixel_buffer(NULL), | 338 pixel_buffer(NULL), |
339 lock_for_read_count(0), | 339 lock_for_read_count(0), |
340 imported_count(0), | 340 imported_count(0), |
341 exported_count(0), | 341 exported_count(0), |
| 342 image_id(0), |
| 343 bound_image_id(0), |
| 344 dirty_image(false), |
342 locked_for_write(false), | 345 locked_for_write(false), |
343 origin(origin), | 346 lost(false), |
344 marked_for_deletion(false), | 347 marked_for_deletion(false), |
345 pending_set_pixels(false), | 348 pending_set_pixels(false), |
346 set_pixels_completion_forced(false), | 349 set_pixels_completion_forced(false), |
347 allocated(false), | 350 allocated(false), |
348 enable_read_lock_fences(false), | 351 enable_read_lock_fences(false), |
| 352 has_shared_bitmap_id(true), |
349 read_lock_fence(NULL), | 353 read_lock_fence(NULL), |
350 size(size), | 354 size(size), |
| 355 origin(origin), |
351 target(0), | 356 target(0), |
352 original_filter(filter), | 357 original_filter(filter), |
353 filter(filter), | 358 filter(filter), |
354 image_id(0), | |
355 bound_image_id(0), | |
356 dirty_image(false), | |
357 texture_pool(0), | 359 texture_pool(0), |
358 wrap_mode(wrap_mode), | 360 wrap_mode(wrap_mode), |
359 lost(false), | |
360 hint(TextureUsageAny), | 361 hint(TextureUsageAny), |
361 type(Bitmap), | 362 type(Bitmap), |
362 format(RGBA_8888), | 363 format(RGBA_8888), |
363 has_shared_bitmap_id(true), | |
364 shared_bitmap_id(bitmap_id), | 364 shared_bitmap_id(bitmap_id), |
365 shared_bitmap(NULL) { | 365 shared_bitmap(NULL) { |
366 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 366 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
367 } | 367 } |
368 | 368 |
369 ResourceProvider::RasterBuffer::RasterBuffer( | 369 ResourceProvider::RasterBuffer::RasterBuffer( |
370 const Resource* resource, | 370 const Resource* resource, |
371 ResourceProvider* resource_provider) | 371 ResourceProvider* resource_provider) |
372 : resource_(resource), | 372 : resource_(resource), |
373 resource_provider_(resource_provider), | 373 resource_provider_(resource_provider), |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 | 1036 |
1037 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { | 1037 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { |
1038 Resource* resource = GetResource(id); | 1038 Resource* resource = GetResource(id); |
1039 DCHECK(!resource->locked_for_write || | 1039 DCHECK(!resource->locked_for_write || |
1040 resource->set_pixels_completion_forced) << | 1040 resource->set_pixels_completion_forced) << |
1041 "locked for write: " << resource->locked_for_write << | 1041 "locked for write: " << resource->locked_for_write << |
1042 " pixels completion forced: " << resource->set_pixels_completion_forced; | 1042 " pixels completion forced: " << resource->set_pixels_completion_forced; |
1043 DCHECK_EQ(resource->exported_count, 0); | 1043 DCHECK_EQ(resource->exported_count, 0); |
1044 // Uninitialized! Call SetPixels or LockForWrite first. | 1044 // Uninitialized! Call SetPixels or LockForWrite first. |
1045 DCHECK(resource->allocated); | 1045 DCHECK(resource->allocated); |
| 1046 DCHECK_NE(resource->lock_for_read_count, std::numeric_limits<uint16>::max()); |
1046 | 1047 |
1047 LazyCreate(resource); | 1048 LazyCreate(resource); |
1048 | 1049 |
1049 if (resource->type == GLTexture && !resource->gl_id) { | 1050 if (resource->type == GLTexture && !resource->gl_id) { |
1050 DCHECK(resource->origin != Resource::Internal); | 1051 DCHECK(resource->origin != Resource::Internal); |
1051 DCHECK(resource->mailbox.IsTexture()); | 1052 DCHECK(resource->mailbox.IsTexture()); |
1052 GLES2Interface* gl = ContextGL(); | 1053 GLES2Interface* gl = ContextGL(); |
1053 DCHECK(gl); | 1054 DCHECK(gl); |
1054 if (resource->mailbox.sync_point()) { | 1055 if (resource->mailbox.sync_point()) { |
1055 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); | 1056 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 DCHECK(thread_checker_.CalledOnValidThread()); | 1342 DCHECK(thread_checker_.CalledOnValidThread()); |
1342 GLES2Interface* gl = ContextGL(); | 1343 GLES2Interface* gl = ContextGL(); |
1343 bool need_sync_point = false; | 1344 bool need_sync_point = false; |
1344 for (ResourceIdArray::const_iterator it = resources.begin(); | 1345 for (ResourceIdArray::const_iterator it = resources.begin(); |
1345 it != resources.end(); | 1346 it != resources.end(); |
1346 ++it) { | 1347 ++it) { |
1347 TransferableResource resource; | 1348 TransferableResource resource; |
1348 TransferResource(gl, *it, &resource); | 1349 TransferResource(gl, *it, &resource); |
1349 if (!resource.mailbox_holder.sync_point && !resource.is_software) | 1350 if (!resource.mailbox_holder.sync_point && !resource.is_software) |
1350 need_sync_point = true; | 1351 need_sync_point = true; |
| 1352 DCHECK_NE(resources_.find(*it)->second.exported_count, |
| 1353 std::numeric_limits<uint16>::max()); |
1351 ++resources_.find(*it)->second.exported_count; | 1354 ++resources_.find(*it)->second.exported_count; |
1352 list->push_back(resource); | 1355 list->push_back(resource); |
1353 } | 1356 } |
1354 if (need_sync_point) { | 1357 if (need_sync_point) { |
1355 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); | 1358 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); |
1356 for (TransferableResourceArray::iterator it = list->begin(); | 1359 for (TransferableResourceArray::iterator it = list->begin(); |
1357 it != list->end(); | 1360 it != list->end(); |
1358 ++it) { | 1361 ++it) { |
1359 if (!it->mailbox_holder.sync_point) | 1362 if (!it->mailbox_holder.sync_point) |
1360 it->mailbox_holder.sync_point = sync_point; | 1363 it->mailbox_holder.sync_point = sync_point; |
1361 } | 1364 } |
1362 } | 1365 } |
1363 } | 1366 } |
1364 | 1367 |
1365 void ResourceProvider::ReceiveFromChild( | 1368 void ResourceProvider::ReceiveFromChild( |
1366 int child, const TransferableResourceArray& resources) { | 1369 int child, const TransferableResourceArray& resources) { |
1367 DCHECK(thread_checker_.CalledOnValidThread()); | 1370 DCHECK(thread_checker_.CalledOnValidThread()); |
1368 GLES2Interface* gl = ContextGL(); | 1371 GLES2Interface* gl = ContextGL(); |
1369 Child& child_info = children_.find(child)->second; | 1372 Child& child_info = children_.find(child)->second; |
1370 DCHECK(!child_info.marked_for_deletion); | 1373 DCHECK(!child_info.marked_for_deletion); |
1371 for (TransferableResourceArray::const_iterator it = resources.begin(); | 1374 for (TransferableResourceArray::const_iterator it = resources.begin(); |
1372 it != resources.end(); | 1375 it != resources.end(); |
1373 ++it) { | 1376 ++it) { |
1374 ResourceIdMap::iterator resource_in_map_it = | 1377 ResourceIdMap::iterator resource_in_map_it = |
1375 child_info.child_to_parent_map.find(it->id); | 1378 child_info.child_to_parent_map.find(it->id); |
1376 if (resource_in_map_it != child_info.child_to_parent_map.end()) { | 1379 if (resource_in_map_it != child_info.child_to_parent_map.end()) { |
1377 Resource& resource = resources_[resource_in_map_it->second]; | 1380 Resource& resource = resources_[resource_in_map_it->second]; |
| 1381 DCHECK_NE(resource.imported_count, std::numeric_limits<uint16>::max()); |
1378 resource.marked_for_deletion = false; | 1382 resource.marked_for_deletion = false; |
1379 resource.imported_count++; | 1383 resource.imported_count++; |
1380 continue; | 1384 continue; |
1381 } | 1385 } |
1382 | 1386 |
1383 if ((!it->is_software && !gl) || | 1387 if ((!it->is_software && !gl) || |
1384 (it->is_software && !shared_bitmap_manager_)) { | 1388 (it->is_software && !shared_bitmap_manager_)) { |
1385 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid"); | 1389 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid"); |
1386 ReturnedResourceArray to_return; | 1390 ReturnedResourceArray to_return; |
1387 to_return.push_back(it->ToReturnedResource()); | 1391 to_return.push_back(it->ToReturnedResource()); |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2208 ContextProvider* context_provider = output_surface_->context_provider(); | 2212 ContextProvider* context_provider = output_surface_->context_provider(); |
2209 return context_provider ? context_provider->ContextGL() : NULL; | 2213 return context_provider ? context_provider->ContextGL() : NULL; |
2210 } | 2214 } |
2211 | 2215 |
2212 class GrContext* ResourceProvider::GrContext() const { | 2216 class GrContext* ResourceProvider::GrContext() const { |
2213 ContextProvider* context_provider = output_surface_->context_provider(); | 2217 ContextProvider* context_provider = output_surface_->context_provider(); |
2214 return context_provider ? context_provider->GrContext() : NULL; | 2218 return context_provider ? context_provider->GrContext() : NULL; |
2215 } | 2219 } |
2216 | 2220 |
2217 } // namespace cc | 2221 } // namespace cc |
OLD | NEW |