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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
18 #include "cc/base/cc_export.h" | 18 #include "cc/base/cc_export.h" |
19 #include "cc/output/context_provider.h" | 19 #include "cc/output/context_provider.h" |
20 #include "cc/output/output_surface.h" | 20 #include "cc/output/output_surface.h" |
21 #include "cc/resources/release_callback.h" | 21 #include "cc/resources/release_callback.h" |
| 22 #include "cc/resources/resource_format.h" |
22 #include "cc/resources/single_release_callback.h" | 23 #include "cc/resources/single_release_callback.h" |
23 #include "cc/resources/texture_mailbox.h" | 24 #include "cc/resources/texture_mailbox.h" |
24 #include "cc/resources/transferable_resource.h" | 25 #include "cc/resources/transferable_resource.h" |
25 #include "third_party/khronos/GLES2/gl2.h" | 26 #include "third_party/khronos/GLES2/gl2.h" |
26 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
27 #include "third_party/skia/include/core/SkCanvas.h" | 28 #include "third_party/skia/include/core/SkCanvas.h" |
28 #include "ui/gfx/size.h" | 29 #include "ui/gfx/size.h" |
29 | 30 |
30 namespace WebKit { class WebGraphicsContext3D; } | 31 namespace WebKit { class WebGraphicsContext3D; } |
31 | 32 |
(...skipping 17 matching lines...) Expand all Loading... |
49 TextureUsageAny, | 50 TextureUsageAny, |
50 TextureUsageFramebuffer, | 51 TextureUsageFramebuffer, |
51 }; | 52 }; |
52 enum ResourceType { | 53 enum ResourceType { |
53 InvalidType = 0, | 54 InvalidType = 0, |
54 GLTexture = 1, | 55 GLTexture = 1, |
55 Bitmap, | 56 Bitmap, |
56 }; | 57 }; |
57 | 58 |
58 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface, | 59 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface, |
59 int highp_threshold_min); | 60 int highp_threshold_min, |
60 | 61 bool use_rgba_4444_texture_format); |
61 virtual ~ResourceProvider(); | 62 virtual ~ResourceProvider(); |
62 | 63 |
63 void InitializeSoftware(); | 64 void InitializeSoftware(); |
64 bool InitializeGL(); | 65 bool InitializeGL(); |
65 | 66 |
66 void DidLoseOutputSurface() { lost_output_surface_ = true; } | 67 void DidLoseOutputSurface() { lost_output_surface_ = true; } |
67 | 68 |
68 int max_texture_size() const { return max_texture_size_; } | 69 int max_texture_size() const { return max_texture_size_; } |
69 GLenum best_texture_format() const { return best_texture_format_; } | 70 ResourceFormat memory_efficient_texture_format() const { |
| 71 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_; |
| 72 } |
| 73 ResourceFormat best_texture_format() const { return best_texture_format_; } |
70 size_t num_resources() const { return resources_.size(); } | 74 size_t num_resources() const { return resources_.size(); } |
71 | 75 |
72 // Checks whether a resource is in use by a consumer. | 76 // Checks whether a resource is in use by a consumer. |
73 bool InUseByConsumer(ResourceId id); | 77 bool InUseByConsumer(ResourceId id); |
74 | 78 |
75 | 79 |
76 // Producer interface. | 80 // Producer interface. |
77 | 81 |
78 ResourceType default_resource_type() const { return default_resource_type_; } | 82 ResourceType default_resource_type() const { return default_resource_type_; } |
79 ResourceType GetResourceType(ResourceId id); | 83 ResourceType GetResourceType(ResourceId id); |
80 | 84 |
81 // Creates a resource of the default resource type. | 85 // Creates a resource of the default resource type. |
82 ResourceId CreateResource(gfx::Size size, | 86 ResourceId CreateResource(gfx::Size size, |
83 GLenum format, | |
84 GLint wrap_mode, | 87 GLint wrap_mode, |
85 TextureUsageHint hint); | 88 TextureUsageHint hint, |
| 89 ResourceFormat format); |
86 | 90 |
87 // 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 |
88 // accounting purposes. | 92 // accounting purposes. |
89 ResourceId CreateManagedResource(gfx::Size size, | 93 ResourceId CreateManagedResource(gfx::Size size, |
90 GLenum format, | |
91 GLint wrap_mode, | 94 GLint wrap_mode, |
92 TextureUsageHint hint); | 95 TextureUsageHint hint, |
| 96 ResourceFormat format); |
93 | 97 |
94 // You can also explicitly create a specific resource type. | 98 // You can also explicitly create a specific resource type. |
95 ResourceId CreateGLTexture(gfx::Size size, | 99 ResourceId CreateGLTexture(gfx::Size size, |
96 GLenum format, | |
97 GLenum texture_pool, | 100 GLenum texture_pool, |
98 GLint wrap_mode, | 101 GLint wrap_mode, |
99 TextureUsageHint hint); | 102 TextureUsageHint hint, |
| 103 ResourceFormat format); |
100 | 104 |
101 ResourceId CreateBitmap(gfx::Size size); | 105 ResourceId CreateBitmap(gfx::Size size); |
102 // Wraps an external texture into a GL resource. | 106 // Wraps an external texture into a GL resource. |
103 ResourceId CreateResourceFromExternalTexture( | 107 ResourceId CreateResourceFromExternalTexture( |
104 unsigned texture_target, | 108 unsigned texture_target, |
105 unsigned texture_id); | 109 unsigned texture_id); |
106 | 110 |
107 // Wraps an external texture mailbox into a GL resource. | 111 // Wraps an external texture mailbox into a GL resource. |
108 ResourceId CreateResourceFromTextureMailbox( | 112 ResourceId CreateResourceFromTextureMailbox( |
109 const TextureMailbox& mailbox, | 113 const TextureMailbox& mailbox, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 } | 331 } |
328 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } | 332 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } |
329 | 333 |
330 // Enable read lock fences for a specific resource. | 334 // Enable read lock fences for a specific resource. |
331 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); | 335 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); |
332 | 336 |
333 // Indicates if we can currently lock this resource for write. | 337 // Indicates if we can currently lock this resource for write. |
334 bool CanLockForWrite(ResourceId id); | 338 bool CanLockForWrite(ResourceId id); |
335 | 339 |
336 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); | 340 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); |
| 341 static size_t BytesPerPixel(ResourceFormat format); |
| 342 static GLenum GetGLDataType(ResourceFormat format); |
| 343 static GLenum GetGLDataFormat(ResourceFormat format); |
| 344 static GLenum GetGLInternalFormat(ResourceFormat format); |
337 | 345 |
338 private: | 346 private: |
339 struct Resource { | 347 struct Resource { |
340 Resource(); | 348 Resource(); |
341 ~Resource(); | 349 ~Resource(); |
342 Resource(unsigned texture_id, | 350 Resource(unsigned texture_id, |
343 gfx::Size size, | 351 gfx::Size size, |
344 GLenum format, | |
345 GLenum filter, | 352 GLenum filter, |
346 GLenum texture_pool, | 353 GLenum texture_pool, |
347 GLint wrap_mode, | 354 GLint wrap_mode, |
348 TextureUsageHint hint); | 355 TextureUsageHint hint, |
| 356 ResourceFormat format); |
349 Resource(uint8_t* pixels, | 357 Resource(uint8_t* pixels, |
350 gfx::Size size, | 358 gfx::Size size, |
351 GLenum format, | |
352 GLenum filter, | 359 GLenum filter, |
353 GLint wrap_mode); | 360 GLint wrap_mode); |
354 | 361 |
355 unsigned gl_id; | 362 unsigned gl_id; |
356 // Pixel buffer used for set pixels without unnecessary copying. | 363 // Pixel buffer used for set pixels without unnecessary copying. |
357 unsigned gl_pixel_buffer_id; | 364 unsigned gl_pixel_buffer_id; |
358 // Query used to determine when asynchronous set pixels complete. | 365 // Query used to determine when asynchronous set pixels complete. |
359 unsigned gl_upload_query_id; | 366 unsigned gl_upload_query_id; |
360 TextureMailbox mailbox; | 367 TextureMailbox mailbox; |
361 ReleaseCallback release_callback; | 368 ReleaseCallback release_callback; |
362 uint8_t* pixels; | 369 uint8_t* pixels; |
363 uint8_t* pixel_buffer; | 370 uint8_t* pixel_buffer; |
364 int lock_for_read_count; | 371 int lock_for_read_count; |
365 int imported_count; | 372 int imported_count; |
366 int exported_count; | 373 int exported_count; |
367 bool locked_for_write; | 374 bool locked_for_write; |
368 bool external; | 375 bool external; |
369 bool marked_for_deletion; | 376 bool marked_for_deletion; |
370 bool pending_set_pixels; | 377 bool pending_set_pixels; |
371 bool set_pixels_completion_forced; | 378 bool set_pixels_completion_forced; |
372 bool allocated; | 379 bool allocated; |
373 bool enable_read_lock_fences; | 380 bool enable_read_lock_fences; |
374 scoped_refptr<Fence> read_lock_fence; | 381 scoped_refptr<Fence> read_lock_fence; |
375 gfx::Size size; | 382 gfx::Size size; |
376 GLenum format; | |
377 // TODO(skyostil): Use a separate sampler object for filter state. | 383 // TODO(skyostil): Use a separate sampler object for filter state. |
378 GLenum original_filter; | 384 GLenum original_filter; |
379 GLenum filter; | 385 GLenum filter; |
380 GLenum target; | 386 GLenum target; |
381 unsigned image_id; | 387 unsigned image_id; |
382 GLenum texture_pool; | 388 GLenum texture_pool; |
383 GLint wrap_mode; | 389 GLint wrap_mode; |
384 TextureUsageHint hint; | 390 TextureUsageHint hint; |
385 ResourceType type; | 391 ResourceType type; |
| 392 ResourceFormat format; |
386 }; | 393 }; |
387 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 394 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
388 struct Child { | 395 struct Child { |
389 Child(); | 396 Child(); |
390 ~Child(); | 397 ~Child(); |
391 | 398 |
392 ResourceIdMap child_to_parent_map; | 399 ResourceIdMap child_to_parent_map; |
393 ResourceIdMap parent_to_child_map; | 400 ResourceIdMap parent_to_child_map; |
394 }; | 401 }; |
395 typedef base::hash_map<int, Child> ChildMap; | 402 typedef base::hash_map<int, Child> ChildMap; |
396 | 403 |
397 bool ReadLockFenceHasPassed(Resource* resource) { | 404 bool ReadLockFenceHasPassed(Resource* resource) { |
398 return !resource->read_lock_fence.get() || | 405 return !resource->read_lock_fence.get() || |
399 resource->read_lock_fence->HasPassed(); | 406 resource->read_lock_fence->HasPassed(); |
400 } | 407 } |
401 | 408 |
402 explicit ResourceProvider(OutputSurface* output_surface, | 409 ResourceProvider(OutputSurface* output_surface, |
403 int highp_threshold_min); | 410 int highp_threshold_min, |
| 411 bool use_rgba_4444_texture_format); |
404 | 412 |
405 void CleanUpGLIfNeeded(); | 413 void CleanUpGLIfNeeded(); |
406 | 414 |
407 Resource* GetResource(ResourceId id); | 415 Resource* GetResource(ResourceId id); |
408 const Resource* LockForRead(ResourceId id); | 416 const Resource* LockForRead(ResourceId id); |
409 void UnlockForRead(ResourceId id); | 417 void UnlockForRead(ResourceId id); |
410 const Resource* LockForWrite(ResourceId id); | 418 const Resource* LockForWrite(ResourceId id); |
411 void UnlockForWrite(ResourceId id); | 419 void UnlockForWrite(ResourceId id); |
412 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 420 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
413 const Resource* resource); | 421 const Resource* resource); |
(...skipping 30 matching lines...) Expand all Loading... |
444 ResourceMap resources_; | 452 ResourceMap resources_; |
445 int next_child_; | 453 int next_child_; |
446 ChildMap children_; | 454 ChildMap children_; |
447 | 455 |
448 ResourceType default_resource_type_; | 456 ResourceType default_resource_type_; |
449 bool use_texture_storage_ext_; | 457 bool use_texture_storage_ext_; |
450 bool use_texture_usage_hint_; | 458 bool use_texture_usage_hint_; |
451 bool use_shallow_flush_; | 459 bool use_shallow_flush_; |
452 scoped_ptr<TextureUploader> texture_uploader_; | 460 scoped_ptr<TextureUploader> texture_uploader_; |
453 int max_texture_size_; | 461 int max_texture_size_; |
454 GLenum best_texture_format_; | 462 ResourceFormat best_texture_format_; |
455 | 463 |
456 base::ThreadChecker thread_checker_; | 464 base::ThreadChecker thread_checker_; |
457 | 465 |
458 scoped_refptr<Fence> current_read_lock_fence_; | 466 scoped_refptr<Fence> current_read_lock_fence_; |
| 467 bool use_rgba_4444_texture_format_; |
459 | 468 |
460 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 469 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
461 }; | 470 }; |
462 | 471 |
463 } // namespace cc | 472 } // namespace cc |
464 | 473 |
465 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 474 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
OLD | NEW |