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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 }; | 199 }; |
200 | 200 |
201 // Generic fence implementation for query objects. Fence has passed when query | 201 // Generic fence implementation for query objects. Fence has passed when query |
202 // result is available. | 202 // result is available. |
203 class QueryFence : public ResourceProvider::Fence { | 203 class QueryFence : public ResourceProvider::Fence { |
204 public: | 204 public: |
205 QueryFence(gpu::gles2::GLES2Interface* gl, unsigned query_id) | 205 QueryFence(gpu::gles2::GLES2Interface* gl, unsigned query_id) |
206 : gl_(gl), query_id_(query_id) {} | 206 : gl_(gl), query_id_(query_id) {} |
207 | 207 |
208 // Overridden from ResourceProvider::Fence: | 208 // Overridden from ResourceProvider::Fence: |
| 209 virtual void Set() OVERRIDE {} |
209 virtual bool HasPassed() OVERRIDE { | 210 virtual bool HasPassed() OVERRIDE { |
210 unsigned available = 1; | 211 unsigned available = 1; |
211 gl_->GetQueryObjectuivEXT( | 212 gl_->GetQueryObjectuivEXT( |
212 query_id_, GL_QUERY_RESULT_AVAILABLE_EXT, &available); | 213 query_id_, GL_QUERY_RESULT_AVAILABLE_EXT, &available); |
213 return !!available; | 214 return !!available; |
214 } | 215 } |
215 | 216 |
216 private: | 217 private: |
217 virtual ~QueryFence() {} | 218 virtual ~QueryFence() {} |
218 | 219 |
(...skipping 15 matching lines...) Expand all Loading... |
234 lock_for_read_count(0), | 235 lock_for_read_count(0), |
235 imported_count(0), | 236 imported_count(0), |
236 exported_count(0), | 237 exported_count(0), |
237 dirty_image(false), | 238 dirty_image(false), |
238 locked_for_write(false), | 239 locked_for_write(false), |
239 lost(false), | 240 lost(false), |
240 marked_for_deletion(false), | 241 marked_for_deletion(false), |
241 pending_set_pixels(false), | 242 pending_set_pixels(false), |
242 set_pixels_completion_forced(false), | 243 set_pixels_completion_forced(false), |
243 allocated(false), | 244 allocated(false), |
244 enable_read_lock_fences(false), | 245 read_lock_fences_enabled(false), |
245 has_shared_bitmap_id(false), | 246 has_shared_bitmap_id(false), |
246 allow_overlay(false), | 247 allow_overlay(false), |
247 read_lock_fence(NULL), | 248 read_lock_fence(NULL), |
248 size(), | 249 size(), |
249 origin(Internal), | 250 origin(Internal), |
250 target(0), | 251 target(0), |
251 original_filter(0), | 252 original_filter(0), |
252 filter(0), | 253 filter(0), |
253 image_id(0), | 254 image_id(0), |
254 bound_image_id(0), | 255 bound_image_id(0), |
255 texture_pool(0), | 256 texture_pool(0), |
256 wrap_mode(0), | 257 wrap_mode(0), |
257 hint(TextureUsageAny), | 258 hint(TextureUsageAny), |
258 type(InvalidType), | 259 type(InvalidType), |
259 format(RGBA_8888), | 260 format(RGBA_8888), |
260 shared_bitmap(NULL) {} | 261 shared_bitmap(NULL) { |
| 262 } |
261 | 263 |
262 ResourceProvider::Resource::~Resource() {} | 264 ResourceProvider::Resource::~Resource() {} |
263 | 265 |
264 ResourceProvider::Resource::Resource(GLuint texture_id, | 266 ResourceProvider::Resource::Resource(GLuint texture_id, |
265 const gfx::Size& size, | 267 const gfx::Size& size, |
266 Origin origin, | 268 Origin origin, |
267 GLenum target, | 269 GLenum target, |
268 GLenum filter, | 270 GLenum filter, |
269 GLenum texture_pool, | 271 GLenum texture_pool, |
270 GLint wrap_mode, | 272 GLint wrap_mode, |
271 TextureUsageHint hint, | 273 TextureUsageHint hint, |
272 ResourceFormat format) | 274 ResourceFormat format) |
273 : child_id(0), | 275 : child_id(0), |
274 gl_id(texture_id), | 276 gl_id(texture_id), |
275 gl_pixel_buffer_id(0), | 277 gl_pixel_buffer_id(0), |
276 gl_upload_query_id(0), | 278 gl_upload_query_id(0), |
277 gl_read_lock_query_id(0), | 279 gl_read_lock_query_id(0), |
278 pixels(NULL), | 280 pixels(NULL), |
279 lock_for_read_count(0), | 281 lock_for_read_count(0), |
280 imported_count(0), | 282 imported_count(0), |
281 exported_count(0), | 283 exported_count(0), |
282 dirty_image(false), | 284 dirty_image(false), |
283 locked_for_write(false), | 285 locked_for_write(false), |
284 lost(false), | 286 lost(false), |
285 marked_for_deletion(false), | 287 marked_for_deletion(false), |
286 pending_set_pixels(false), | 288 pending_set_pixels(false), |
287 set_pixels_completion_forced(false), | 289 set_pixels_completion_forced(false), |
288 allocated(false), | 290 allocated(false), |
289 enable_read_lock_fences(false), | 291 read_lock_fences_enabled(false), |
290 has_shared_bitmap_id(false), | 292 has_shared_bitmap_id(false), |
291 allow_overlay(false), | 293 allow_overlay(false), |
292 read_lock_fence(NULL), | 294 read_lock_fence(NULL), |
293 size(size), | 295 size(size), |
294 origin(origin), | 296 origin(origin), |
295 target(target), | 297 target(target), |
296 original_filter(filter), | 298 original_filter(filter), |
297 filter(filter), | 299 filter(filter), |
298 image_id(0), | 300 image_id(0), |
299 bound_image_id(0), | 301 bound_image_id(0), |
(...skipping 22 matching lines...) Expand all Loading... |
322 lock_for_read_count(0), | 324 lock_for_read_count(0), |
323 imported_count(0), | 325 imported_count(0), |
324 exported_count(0), | 326 exported_count(0), |
325 dirty_image(false), | 327 dirty_image(false), |
326 locked_for_write(false), | 328 locked_for_write(false), |
327 lost(false), | 329 lost(false), |
328 marked_for_deletion(false), | 330 marked_for_deletion(false), |
329 pending_set_pixels(false), | 331 pending_set_pixels(false), |
330 set_pixels_completion_forced(false), | 332 set_pixels_completion_forced(false), |
331 allocated(false), | 333 allocated(false), |
332 enable_read_lock_fences(false), | 334 read_lock_fences_enabled(false), |
333 has_shared_bitmap_id(!!bitmap), | 335 has_shared_bitmap_id(!!bitmap), |
334 allow_overlay(false), | 336 allow_overlay(false), |
335 read_lock_fence(NULL), | 337 read_lock_fence(NULL), |
336 size(size), | 338 size(size), |
337 origin(origin), | 339 origin(origin), |
338 target(0), | 340 target(0), |
339 original_filter(filter), | 341 original_filter(filter), |
340 filter(filter), | 342 filter(filter), |
341 image_id(0), | 343 image_id(0), |
342 bound_image_id(0), | 344 bound_image_id(0), |
(...skipping 23 matching lines...) Expand all Loading... |
366 lock_for_read_count(0), | 368 lock_for_read_count(0), |
367 imported_count(0), | 369 imported_count(0), |
368 exported_count(0), | 370 exported_count(0), |
369 dirty_image(false), | 371 dirty_image(false), |
370 locked_for_write(false), | 372 locked_for_write(false), |
371 lost(false), | 373 lost(false), |
372 marked_for_deletion(false), | 374 marked_for_deletion(false), |
373 pending_set_pixels(false), | 375 pending_set_pixels(false), |
374 set_pixels_completion_forced(false), | 376 set_pixels_completion_forced(false), |
375 allocated(false), | 377 allocated(false), |
376 enable_read_lock_fences(false), | 378 read_lock_fences_enabled(false), |
377 has_shared_bitmap_id(true), | 379 has_shared_bitmap_id(true), |
378 allow_overlay(false), | 380 allow_overlay(false), |
379 read_lock_fence(NULL), | 381 read_lock_fence(NULL), |
380 size(size), | 382 size(size), |
381 origin(origin), | 383 origin(origin), |
382 target(0), | 384 target(0), |
383 original_filter(filter), | 385 original_filter(filter), |
384 filter(filter), | 386 filter(filter), |
385 image_id(0), | 387 image_id(0), |
386 bound_image_id(0), | 388 bound_image_id(0), |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 scoped_ptr<SharedBitmap> bitmap = | 1057 scoped_ptr<SharedBitmap> bitmap = |
1056 shared_bitmap_manager_->GetSharedBitmapFromId( | 1058 shared_bitmap_manager_->GetSharedBitmapFromId( |
1057 resource->size, resource->shared_bitmap_id); | 1059 resource->size, resource->shared_bitmap_id); |
1058 if (bitmap) { | 1060 if (bitmap) { |
1059 resource->shared_bitmap = bitmap.release(); | 1061 resource->shared_bitmap = bitmap.release(); |
1060 resource->pixels = resource->shared_bitmap->pixels(); | 1062 resource->pixels = resource->shared_bitmap->pixels(); |
1061 } | 1063 } |
1062 } | 1064 } |
1063 | 1065 |
1064 resource->lock_for_read_count++; | 1066 resource->lock_for_read_count++; |
1065 if (resource->enable_read_lock_fences) | 1067 if (resource->read_lock_fences_enabled) { |
| 1068 if (current_read_lock_fence_) |
| 1069 current_read_lock_fence_->Set(); |
1066 resource->read_lock_fence = current_read_lock_fence_; | 1070 resource->read_lock_fence = current_read_lock_fence_; |
| 1071 } |
1067 | 1072 |
1068 return resource; | 1073 return resource; |
1069 } | 1074 } |
1070 | 1075 |
1071 void ResourceProvider::UnlockForRead(ResourceId id) { | 1076 void ResourceProvider::UnlockForRead(ResourceId id) { |
1072 DCHECK(thread_checker_.CalledOnValidThread()); | 1077 DCHECK(thread_checker_.CalledOnValidThread()); |
1073 ResourceMap::iterator it = resources_.find(id); | 1078 ResourceMap::iterator it = resources_.find(id); |
1074 CHECK(it != resources_.end()); | 1079 CHECK(it != resources_.end()); |
1075 | 1080 |
1076 Resource* resource = &it->second; | 1081 Resource* resource = &it->second; |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 Resource* resource = &map_iterator->second; | 1520 Resource* resource = &map_iterator->second; |
1516 | 1521 |
1517 CHECK_GE(resource->exported_count, returned.count); | 1522 CHECK_GE(resource->exported_count, returned.count); |
1518 resource->exported_count -= returned.count; | 1523 resource->exported_count -= returned.count; |
1519 resource->lost |= returned.lost; | 1524 resource->lost |= returned.lost; |
1520 if (resource->exported_count) | 1525 if (resource->exported_count) |
1521 continue; | 1526 continue; |
1522 | 1527 |
1523 // Need to wait for the current read lock fence to pass before we can | 1528 // Need to wait for the current read lock fence to pass before we can |
1524 // recycle this resource. | 1529 // recycle this resource. |
1525 if (resource->enable_read_lock_fences) | 1530 if (resource->read_lock_fences_enabled) { |
| 1531 if (current_read_lock_fence_) |
| 1532 current_read_lock_fence_->Set(); |
1526 resource->read_lock_fence = current_read_lock_fence_; | 1533 resource->read_lock_fence = current_read_lock_fence_; |
| 1534 } |
1527 | 1535 |
1528 if (returned.sync_point) { | 1536 if (returned.sync_point) { |
1529 DCHECK(!resource->has_shared_bitmap_id); | 1537 DCHECK(!resource->has_shared_bitmap_id); |
1530 if (resource->origin == Resource::Internal) { | 1538 if (resource->origin == Resource::Internal) { |
1531 DCHECK(resource->gl_id); | 1539 DCHECK(resource->gl_id); |
1532 GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); | 1540 GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); |
1533 } else { | 1541 } else { |
1534 DCHECK(!resource->gl_id); | 1542 DCHECK(!resource->gl_id); |
1535 resource->mailbox.set_sync_point(returned.sync_point); | 1543 resource->mailbox.set_sync_point(returned.sync_point); |
1536 } | 1544 } |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2095 DCHECK(resource->image_id); | 2103 DCHECK(resource->image_id); |
2096 | 2104 |
2097 // Release image currently bound to texture. | 2105 // Release image currently bound to texture. |
2098 if (resource->bound_image_id) | 2106 if (resource->bound_image_id) |
2099 gl->ReleaseTexImage2DCHROMIUM(resource->target, resource->bound_image_id); | 2107 gl->ReleaseTexImage2DCHROMIUM(resource->target, resource->bound_image_id); |
2100 gl->BindTexImage2DCHROMIUM(resource->target, resource->image_id); | 2108 gl->BindTexImage2DCHROMIUM(resource->target, resource->image_id); |
2101 resource->bound_image_id = resource->image_id; | 2109 resource->bound_image_id = resource->image_id; |
2102 resource->dirty_image = false; | 2110 resource->dirty_image = false; |
2103 } | 2111 } |
2104 | 2112 |
2105 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 2113 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id) { |
2106 bool enable) { | |
2107 Resource* resource = GetResource(id); | 2114 Resource* resource = GetResource(id); |
2108 resource->enable_read_lock_fences = enable; | 2115 resource->read_lock_fences_enabled = true; |
2109 } | 2116 } |
2110 | 2117 |
2111 void ResourceProvider::AcquireImage(Resource* resource) { | 2118 void ResourceProvider::AcquireImage(Resource* resource) { |
2112 DCHECK(resource->origin == Resource::Internal); | 2119 DCHECK(resource->origin == Resource::Internal); |
2113 DCHECK_EQ(resource->exported_count, 0); | 2120 DCHECK_EQ(resource->exported_count, 0); |
2114 | 2121 |
2115 if (resource->type != GLTexture) | 2122 if (resource->type != GLTexture) |
2116 return; | 2123 return; |
2117 | 2124 |
2118 if (resource->image_id) | 2125 if (resource->image_id) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2243 ContextProvider* context_provider = output_surface_->context_provider(); | 2250 ContextProvider* context_provider = output_surface_->context_provider(); |
2244 return context_provider ? context_provider->ContextGL() : NULL; | 2251 return context_provider ? context_provider->ContextGL() : NULL; |
2245 } | 2252 } |
2246 | 2253 |
2247 class GrContext* ResourceProvider::GrContext() const { | 2254 class GrContext* ResourceProvider::GrContext() const { |
2248 ContextProvider* context_provider = output_surface_->context_provider(); | 2255 ContextProvider* context_provider = output_surface_->context_provider(); |
2249 return context_provider ? context_provider->GrContext() : NULL; | 2256 return context_provider ? context_provider->GrContext() : NULL; |
2250 } | 2257 } |
2251 | 2258 |
2252 } // namespace cc | 2259 } // namespace cc |
OLD | NEW |