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 Format { |
| 56 RGBA_8888, |
| 57 RGBA_4444, |
| 58 BGRA_8888, |
| 59 LUMINANCE_8, |
| 60 }; |
55 | 61 |
56 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface, | 62 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface, |
57 int highp_threshold_min); | 63 int highp_threshold_min); |
58 | 64 |
59 virtual ~ResourceProvider(); | 65 virtual ~ResourceProvider(); |
60 | 66 |
61 void InitializeSoftware(); | 67 void InitializeSoftware(); |
62 bool InitializeGL(); | 68 bool InitializeGL(); |
63 | 69 |
64 void DidLoseOutputSurface() { lost_output_surface_ = true; } | 70 void DidLoseOutputSurface() { lost_output_surface_ = true; } |
65 | 71 |
66 int max_texture_size() const { return max_texture_size_; } | 72 int max_texture_size() const { return max_texture_size_; } |
67 GLenum best_texture_format() const { return best_texture_format_; } | 73 Format best_texture_format() const { return best_texture_format_; } |
68 size_t num_resources() const { return resources_.size(); } | 74 size_t num_resources() const { return resources_.size(); } |
69 | 75 |
70 // Checks whether a resource is in use by a consumer. | 76 // Checks whether a resource is in use by a consumer. |
71 bool InUseByConsumer(ResourceId id); | 77 bool InUseByConsumer(ResourceId id); |
72 | 78 |
73 | 79 |
74 // Producer interface. | 80 // Producer interface. |
75 | 81 |
76 ResourceType default_resource_type() const { return default_resource_type_; } | 82 ResourceType default_resource_type() const { return default_resource_type_; } |
77 ResourceType GetResourceType(ResourceId id); | 83 ResourceType GetResourceType(ResourceId id); |
78 | 84 |
79 // Creates a resource of the default resource type. | 85 // Creates a resource of the default resource type. |
80 ResourceId CreateResource(gfx::Size size, | 86 ResourceId CreateResource(gfx::Size size, |
81 GLenum format, | |
82 GLint wrap_mode, | 87 GLint wrap_mode, |
83 TextureUsageHint hint); | 88 TextureUsageHint hint, |
| 89 Format texture_format); |
84 | 90 |
85 // Creates a resource which is tagged as being managed for GPU memory | 91 // Creates a resource which is tagged as being managed for GPU memory |
86 // accounting purposes. | 92 // accounting purposes. |
87 ResourceId CreateManagedResource(gfx::Size size, | 93 ResourceId CreateManagedResource(gfx::Size size, |
88 GLenum format, | |
89 GLint wrap_mode, | 94 GLint wrap_mode, |
90 TextureUsageHint hint); | 95 TextureUsageHint hint, |
| 96 Format texture_format); |
91 | 97 |
92 // You can also explicitly create a specific resource type. | 98 // You can also explicitly create a specific resource type. |
93 ResourceId CreateGLTexture(gfx::Size size, | 99 ResourceId CreateGLTexture(gfx::Size size, |
94 GLenum format, | |
95 GLenum texture_pool, | 100 GLenum texture_pool, |
96 GLint wrap_mode, | 101 GLint wrap_mode, |
97 TextureUsageHint hint); | 102 TextureUsageHint hint, |
| 103 Format texture_format); |
98 | 104 |
99 ResourceId CreateBitmap(gfx::Size size); | 105 ResourceId CreateBitmap(gfx::Size size); |
100 // Wraps an external texture into a GL resource. | 106 // Wraps an external texture into a GL resource. |
101 ResourceId CreateResourceFromExternalTexture( | 107 ResourceId CreateResourceFromExternalTexture( |
102 unsigned texture_target, | 108 unsigned texture_target, |
103 unsigned texture_id); | 109 unsigned texture_id); |
104 | 110 |
105 // Wraps an external texture mailbox into a GL resource. | 111 // Wraps an external texture mailbox into a GL resource. |
106 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); | 112 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); |
107 | 113 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 329 } |
324 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } | 330 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } |
325 | 331 |
326 // Enable read lock fences for a specific resource. | 332 // Enable read lock fences for a specific resource. |
327 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); | 333 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); |
328 | 334 |
329 // Indicates if we can currently lock this resource for write. | 335 // Indicates if we can currently lock this resource for write. |
330 bool CanLockForWrite(ResourceId id); | 336 bool CanLockForWrite(ResourceId id); |
331 | 337 |
332 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); | 338 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); |
| 339 static size_t BytesPerPixel(Format type); |
| 340 static GLenum GetGLDataType(Format format); |
| 341 static GLenum GetGLDataFormat(Format format); |
| 342 static GLenum GetGLInternalFormat(Format 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 Format 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 Format 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 Format 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 |