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