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 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_ | 5 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_ |
6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ | 6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; | 45 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; |
46 enum TextureUsageHint { | 46 enum TextureUsageHint { |
47 TextureUsageAny, | 47 TextureUsageAny, |
48 TextureUsageFramebuffer, | 48 TextureUsageFramebuffer, |
49 }; | 49 }; |
50 enum ResourceType { | 50 enum ResourceType { |
51 InvalidType = 0, | 51 InvalidType = 0, |
52 GLTexture = 1, | 52 GLTexture = 1, |
53 Bitmap, | 53 Bitmap, |
54 }; | 54 }; |
55 enum TextureFormat { | |
reveman
2013/09/12 15:57:40
This will need to be set properly for software res
kaanb
2013/09/13 00:11:08
Done.
| |
56 INVALID_FORMAT, | |
reveman
2013/09/12 15:57:40
what's needed to remove INVALID_FORMAT? Is this ju
kaanb
2013/09/13 00:11:08
Done.
| |
57 RGBA_8888, | |
58 RGBA_4444, | |
59 BGRA_8888, | |
60 LUMINANCE_8, | |
61 }; | |
55 | 62 |
56 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface, | 63 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface, |
57 int highp_threshold_min); | 64 int highp_threshold_min); |
58 | 65 |
59 virtual ~ResourceProvider(); | 66 virtual ~ResourceProvider(); |
60 | 67 |
61 void InitializeSoftware(); | 68 void InitializeSoftware(); |
62 bool InitializeGL(); | 69 bool InitializeGL(); |
63 | 70 |
64 void DidLoseOutputSurface() { lost_output_surface_ = true; } | 71 void DidLoseOutputSurface() { lost_output_surface_ = true; } |
65 | 72 |
66 int max_texture_size() const { return max_texture_size_; } | 73 int max_texture_size() const { return max_texture_size_; } |
67 GLenum best_texture_format() const { return best_texture_format_; } | 74 TextureFormat best_texture_format() const { return best_texture_format_; } |
68 size_t num_resources() const { return resources_.size(); } | 75 size_t num_resources() const { return resources_.size(); } |
69 | 76 |
70 // Checks whether a resource is in use by a consumer. | 77 // Checks whether a resource is in use by a consumer. |
71 bool InUseByConsumer(ResourceId id); | 78 bool InUseByConsumer(ResourceId id); |
72 | 79 |
73 | 80 |
74 // Producer interface. | 81 // Producer interface. |
75 | 82 |
76 ResourceType default_resource_type() const { return default_resource_type_; } | 83 ResourceType default_resource_type() const { return default_resource_type_; } |
77 ResourceType GetResourceType(ResourceId id); | 84 ResourceType GetResourceType(ResourceId id); |
78 | 85 |
79 // Creates a resource of the default resource type. | 86 // Creates a resource of the default resource type. |
80 ResourceId CreateResource(gfx::Size size, | 87 ResourceId CreateResource(gfx::Size size, |
81 GLenum format, | |
82 GLint wrap_mode, | 88 GLint wrap_mode, |
83 TextureUsageHint hint); | 89 TextureUsageHint hint, |
90 TextureFormat texture_format); | |
84 | 91 |
85 // Creates a resource which is tagged as being managed for GPU memory | 92 // Creates a resource which is tagged as being managed for GPU memory |
86 // accounting purposes. | 93 // accounting purposes. |
87 ResourceId CreateManagedResource(gfx::Size size, | 94 ResourceId CreateManagedResource(gfx::Size size, |
88 GLenum format, | |
89 GLint wrap_mode, | 95 GLint wrap_mode, |
90 TextureUsageHint hint); | 96 TextureUsageHint hint, |
97 TextureFormat texture_format); | |
91 | 98 |
92 // You can also explicitly create a specific resource type. | 99 // You can also explicitly create a specific resource type. |
93 ResourceId CreateGLTexture(gfx::Size size, | 100 ResourceId CreateGLTexture(gfx::Size size, |
94 GLenum format, | |
95 GLenum texture_pool, | 101 GLenum texture_pool, |
96 GLint wrap_mode, | 102 GLint wrap_mode, |
97 TextureUsageHint hint); | 103 TextureUsageHint hint, |
104 TextureFormat texture_format); | |
98 | 105 |
99 ResourceId CreateBitmap(gfx::Size size); | 106 ResourceId CreateBitmap(gfx::Size size); |
100 // Wraps an external texture into a GL resource. | 107 // Wraps an external texture into a GL resource. |
101 ResourceId CreateResourceFromExternalTexture( | 108 ResourceId CreateResourceFromExternalTexture( |
102 unsigned texture_target, | 109 unsigned texture_target, |
103 unsigned texture_id); | 110 unsigned texture_id); |
104 | 111 |
105 // Wraps an external texture mailbox into a GL resource. | 112 // Wraps an external texture mailbox into a GL resource. |
106 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); | 113 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); |
107 | 114 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 } | 330 } |
324 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } | 331 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } |
325 | 332 |
326 // Enable read lock fences for a specific resource. | 333 // Enable read lock fences for a specific resource. |
327 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); | 334 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); |
328 | 335 |
329 // Indicates if we can currently lock this resource for write. | 336 // Indicates if we can currently lock this resource for write. |
330 bool CanLockForWrite(ResourceId id); | 337 bool CanLockForWrite(ResourceId id); |
331 | 338 |
332 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); | 339 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); |
340 static size_t BytesPerPixel(TextureFormat type); | |
341 static GLenum GetGLDataType(TextureFormat format); | |
342 static GLenum GetGLDataFormat(TextureFormat format); | |
333 | 343 |
334 private: | 344 private: |
335 struct Resource { | 345 struct Resource { |
336 Resource(); | 346 Resource(); |
337 ~Resource(); | 347 ~Resource(); |
338 Resource(unsigned texture_id, | 348 Resource(unsigned texture_id, |
339 gfx::Size size, | 349 gfx::Size size, |
340 GLenum format, | |
341 GLenum filter, | 350 GLenum filter, |
342 GLenum texture_pool, | 351 GLenum texture_pool, |
343 GLint wrap_mode, | 352 GLint wrap_mode, |
344 TextureUsageHint hint); | 353 TextureUsageHint hint, |
354 TextureFormat texture_format); | |
345 Resource(uint8_t* pixels, | 355 Resource(uint8_t* pixels, |
346 gfx::Size size, | 356 gfx::Size size, |
347 GLenum format, | |
348 GLenum filter, | 357 GLenum filter, |
349 GLint wrap_mode); | 358 GLint wrap_mode); |
350 | 359 |
351 unsigned gl_id; | 360 unsigned gl_id; |
352 // Pixel buffer used for set pixels without unnecessary copying. | 361 // Pixel buffer used for set pixels without unnecessary copying. |
353 unsigned gl_pixel_buffer_id; | 362 unsigned gl_pixel_buffer_id; |
354 // Query used to determine when asynchronous set pixels complete. | 363 // Query used to determine when asynchronous set pixels complete. |
355 unsigned gl_upload_query_id; | 364 unsigned gl_upload_query_id; |
356 TextureMailbox mailbox; | 365 TextureMailbox mailbox; |
357 uint8_t* pixels; | 366 uint8_t* pixels; |
358 uint8_t* pixel_buffer; | 367 uint8_t* pixel_buffer; |
359 int lock_for_read_count; | 368 int lock_for_read_count; |
360 int imported_count; | 369 int imported_count; |
361 int exported_count; | 370 int exported_count; |
362 bool locked_for_write; | 371 bool locked_for_write; |
363 bool external; | 372 bool external; |
364 bool marked_for_deletion; | 373 bool marked_for_deletion; |
365 bool pending_set_pixels; | 374 bool pending_set_pixels; |
366 bool set_pixels_completion_forced; | 375 bool set_pixels_completion_forced; |
367 bool allocated; | 376 bool allocated; |
368 bool enable_read_lock_fences; | 377 bool enable_read_lock_fences; |
369 scoped_refptr<Fence> read_lock_fence; | 378 scoped_refptr<Fence> read_lock_fence; |
370 gfx::Size size; | 379 gfx::Size size; |
371 GLenum format; | |
372 // TODO(skyostil): Use a separate sampler object for filter state. | 380 // TODO(skyostil): Use a separate sampler object for filter state. |
373 GLenum filter; | 381 GLenum filter; |
374 unsigned image_id; | 382 unsigned image_id; |
375 GLenum texture_pool; | 383 GLenum texture_pool; |
376 GLint wrap_mode; | 384 GLint wrap_mode; |
377 TextureUsageHint hint; | 385 TextureUsageHint hint; |
378 ResourceType type; | 386 ResourceType type; |
387 TextureFormat texture_format; | |
379 }; | 388 }; |
380 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 389 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
381 struct Child { | 390 struct Child { |
382 Child(); | 391 Child(); |
383 ~Child(); | 392 ~Child(); |
384 | 393 |
385 ResourceIdMap child_to_parent_map; | 394 ResourceIdMap child_to_parent_map; |
386 ResourceIdMap parent_to_child_map; | 395 ResourceIdMap parent_to_child_map; |
387 }; | 396 }; |
388 typedef base::hash_map<int, Child> ChildMap; | 397 typedef base::hash_map<int, Child> ChildMap; |
389 | 398 |
390 bool ReadLockFenceHasPassed(Resource* resource) { | 399 bool ReadLockFenceHasPassed(Resource* resource) { |
391 return !resource->read_lock_fence.get() || | 400 return !resource->read_lock_fence.get() || |
392 resource->read_lock_fence->HasPassed(); | 401 resource->read_lock_fence->HasPassed(); |
393 } | 402 } |
394 | 403 |
395 explicit ResourceProvider(OutputSurface* output_surface, | 404 ResourceProvider(OutputSurface* output_surface, |
396 int highp_threshold_min); | 405 int highp_threshold_min); |
397 | 406 |
398 void CleanUpGLIfNeeded(); | 407 void CleanUpGLIfNeeded(); |
399 | 408 |
400 Resource* GetResource(ResourceId id); | 409 Resource* GetResource(ResourceId id); |
401 const Resource* LockForRead(ResourceId id); | 410 const Resource* LockForRead(ResourceId id); |
402 void UnlockForRead(ResourceId id); | 411 void UnlockForRead(ResourceId id); |
403 const Resource* LockForWrite(ResourceId id); | 412 const Resource* LockForWrite(ResourceId id); |
404 void UnlockForWrite(ResourceId id); | 413 void UnlockForWrite(ResourceId id); |
405 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 414 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
406 const Resource* resource); | 415 const Resource* resource); |
(...skipping 30 matching lines...) Expand all Loading... | |
437 ResourceMap resources_; | 446 ResourceMap resources_; |
438 int next_child_; | 447 int next_child_; |
439 ChildMap children_; | 448 ChildMap children_; |
440 | 449 |
441 ResourceType default_resource_type_; | 450 ResourceType default_resource_type_; |
442 bool use_texture_storage_ext_; | 451 bool use_texture_storage_ext_; |
443 bool use_texture_usage_hint_; | 452 bool use_texture_usage_hint_; |
444 bool use_shallow_flush_; | 453 bool use_shallow_flush_; |
445 scoped_ptr<TextureUploader> texture_uploader_; | 454 scoped_ptr<TextureUploader> texture_uploader_; |
446 int max_texture_size_; | 455 int max_texture_size_; |
447 GLenum best_texture_format_; | 456 TextureFormat best_texture_format_; |
448 | 457 |
449 base::ThreadChecker thread_checker_; | 458 base::ThreadChecker thread_checker_; |
450 | 459 |
451 scoped_refptr<Fence> current_read_lock_fence_; | 460 scoped_refptr<Fence> current_read_lock_fence_; |
452 | 461 |
453 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 462 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
454 }; | 463 }; |
455 | 464 |
456 } // namespace cc | 465 } // namespace cc |
457 | 466 |
458 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 467 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
OLD | NEW |