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); | |
343 static unsigned GetStride(Format format); | |
piman
2013/09/13 01:42:01
What does this represent, and how is it related to
kaanb
2013/09/13 03:43:56
It is used by the TextureUploader to decide what v
piman
2013/09/13 04:56:51
GetStrideAlignment?
Please add a comment about wha
kaanb
2013/09/13 19:57:39
Removed.
| |
333 | 344 |
334 private: | 345 private: |
335 struct Resource { | 346 struct Resource { |
336 Resource(); | 347 Resource(); |
337 ~Resource(); | 348 ~Resource(); |
338 Resource(unsigned texture_id, | 349 Resource(unsigned texture_id, |
339 gfx::Size size, | 350 gfx::Size size, |
340 GLenum format, | |
341 GLenum filter, | 351 GLenum filter, |
342 GLenum texture_pool, | 352 GLenum texture_pool, |
343 GLint wrap_mode, | 353 GLint wrap_mode, |
344 TextureUsageHint hint); | 354 TextureUsageHint hint, |
355 Format texture_format); | |
345 Resource(uint8_t* pixels, | 356 Resource(uint8_t* pixels, |
346 gfx::Size size, | 357 gfx::Size size, |
347 GLenum format, | |
348 GLenum filter, | 358 GLenum filter, |
349 GLint wrap_mode); | 359 GLint wrap_mode); |
350 | 360 |
351 unsigned gl_id; | 361 unsigned gl_id; |
352 // Pixel buffer used for set pixels without unnecessary copying. | 362 // Pixel buffer used for set pixels without unnecessary copying. |
353 unsigned gl_pixel_buffer_id; | 363 unsigned gl_pixel_buffer_id; |
354 // Query used to determine when asynchronous set pixels complete. | 364 // Query used to determine when asynchronous set pixels complete. |
355 unsigned gl_upload_query_id; | 365 unsigned gl_upload_query_id; |
356 TextureMailbox mailbox; | 366 TextureMailbox mailbox; |
357 uint8_t* pixels; | 367 uint8_t* pixels; |
358 uint8_t* pixel_buffer; | 368 uint8_t* pixel_buffer; |
359 int lock_for_read_count; | 369 int lock_for_read_count; |
360 int imported_count; | 370 int imported_count; |
361 int exported_count; | 371 int exported_count; |
362 bool locked_for_write; | 372 bool locked_for_write; |
363 bool external; | 373 bool external; |
364 bool marked_for_deletion; | 374 bool marked_for_deletion; |
365 bool pending_set_pixels; | 375 bool pending_set_pixels; |
366 bool set_pixels_completion_forced; | 376 bool set_pixels_completion_forced; |
367 bool allocated; | 377 bool allocated; |
368 bool enable_read_lock_fences; | 378 bool enable_read_lock_fences; |
369 scoped_refptr<Fence> read_lock_fence; | 379 scoped_refptr<Fence> read_lock_fence; |
370 gfx::Size size; | 380 gfx::Size size; |
371 GLenum format; | |
372 // TODO(skyostil): Use a separate sampler object for filter state. | 381 // TODO(skyostil): Use a separate sampler object for filter state. |
373 GLenum filter; | 382 GLenum filter; |
374 unsigned image_id; | 383 unsigned image_id; |
375 GLenum texture_pool; | 384 GLenum texture_pool; |
376 GLint wrap_mode; | 385 GLint wrap_mode; |
377 TextureUsageHint hint; | 386 TextureUsageHint hint; |
378 ResourceType type; | 387 ResourceType type; |
388 Format texture_format; | |
reveman
2013/09/13 14:32:49
just "Format format;" as it doesn't just apply to
kaanb
2013/09/13 19:57:39
Done.
| |
379 }; | 389 }; |
380 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 390 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
381 struct Child { | 391 struct Child { |
382 Child(); | 392 Child(); |
383 ~Child(); | 393 ~Child(); |
384 | 394 |
385 ResourceIdMap child_to_parent_map; | 395 ResourceIdMap child_to_parent_map; |
386 ResourceIdMap parent_to_child_map; | 396 ResourceIdMap parent_to_child_map; |
387 }; | 397 }; |
388 typedef base::hash_map<int, Child> ChildMap; | 398 typedef base::hash_map<int, Child> ChildMap; |
389 | 399 |
390 bool ReadLockFenceHasPassed(Resource* resource) { | 400 bool ReadLockFenceHasPassed(Resource* resource) { |
391 return !resource->read_lock_fence.get() || | 401 return !resource->read_lock_fence.get() || |
392 resource->read_lock_fence->HasPassed(); | 402 resource->read_lock_fence->HasPassed(); |
393 } | 403 } |
394 | 404 |
395 explicit ResourceProvider(OutputSurface* output_surface, | 405 ResourceProvider(OutputSurface* output_surface, |
396 int highp_threshold_min); | 406 int highp_threshold_min); |
397 | 407 |
398 void CleanUpGLIfNeeded(); | 408 void CleanUpGLIfNeeded(); |
399 | 409 |
400 Resource* GetResource(ResourceId id); | 410 Resource* GetResource(ResourceId id); |
401 const Resource* LockForRead(ResourceId id); | 411 const Resource* LockForRead(ResourceId id); |
402 void UnlockForRead(ResourceId id); | 412 void UnlockForRead(ResourceId id); |
403 const Resource* LockForWrite(ResourceId id); | 413 const Resource* LockForWrite(ResourceId id); |
404 void UnlockForWrite(ResourceId id); | 414 void UnlockForWrite(ResourceId id); |
405 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 415 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
406 const Resource* resource); | 416 const Resource* resource); |
(...skipping 30 matching lines...) Expand all Loading... | |
437 ResourceMap resources_; | 447 ResourceMap resources_; |
438 int next_child_; | 448 int next_child_; |
439 ChildMap children_; | 449 ChildMap children_; |
440 | 450 |
441 ResourceType default_resource_type_; | 451 ResourceType default_resource_type_; |
442 bool use_texture_storage_ext_; | 452 bool use_texture_storage_ext_; |
443 bool use_texture_usage_hint_; | 453 bool use_texture_usage_hint_; |
444 bool use_shallow_flush_; | 454 bool use_shallow_flush_; |
445 scoped_ptr<TextureUploader> texture_uploader_; | 455 scoped_ptr<TextureUploader> texture_uploader_; |
446 int max_texture_size_; | 456 int max_texture_size_; |
447 GLenum best_texture_format_; | 457 Format best_texture_format_; |
448 | 458 |
449 base::ThreadChecker thread_checker_; | 459 base::ThreadChecker thread_checker_; |
450 | 460 |
451 scoped_refptr<Fence> current_read_lock_fence_; | 461 scoped_refptr<Fence> current_read_lock_fence_; |
452 | 462 |
453 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 463 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
454 }; | 464 }; |
455 | 465 |
456 } // namespace cc | 466 } // namespace cc |
457 | 467 |
458 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 468 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
OLD | NEW |