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 18 matching lines...) Expand all Loading... |
29 #include "cc/resources/transferable_resource.h" | 29 #include "cc/resources/transferable_resource.h" |
30 #include "third_party/khronos/GLES2/gl2.h" | 30 #include "third_party/khronos/GLES2/gl2.h" |
31 #include "third_party/khronos/GLES2/gl2ext.h" | 31 #include "third_party/khronos/GLES2/gl2ext.h" |
32 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
33 #include "third_party/skia/include/core/SkCanvas.h" | 33 #include "third_party/skia/include/core/SkCanvas.h" |
34 #include "ui/gfx/geometry/size.h" | 34 #include "ui/gfx/geometry/size.h" |
35 | 35 |
36 class GrContext; | 36 class GrContext; |
37 | 37 |
38 namespace gpu { | 38 namespace gpu { |
| 39 class GpuMemoryBufferManager; |
39 namespace gles { | 40 namespace gles { |
40 class GLES2Interface; | 41 class GLES2Interface; |
41 } | 42 } |
42 } | 43 } |
43 | 44 |
44 namespace gfx { | 45 namespace gfx { |
45 class GpuMemoryBuffer; | 46 class GpuMemoryBuffer; |
46 class Rect; | 47 class Rect; |
47 class Vector2d; | 48 class Vector2d; |
48 } | 49 } |
49 | 50 |
50 namespace cc { | 51 namespace cc { |
51 class BlockingTaskRunner; | 52 class BlockingTaskRunner; |
52 class GpuMemoryBufferManager; | |
53 class IdAllocator; | 53 class IdAllocator; |
54 class SharedBitmap; | 54 class SharedBitmap; |
55 class SharedBitmapManager; | 55 class SharedBitmapManager; |
56 class TextureUploader; | 56 class TextureUploader; |
57 | 57 |
58 // This class is not thread-safe and can only be called from the thread it was | 58 // This class is not thread-safe and can only be called from the thread it was |
59 // created on (in practice, the impl thread). | 59 // created on (in practice, the impl thread). |
60 class CC_EXPORT ResourceProvider { | 60 class CC_EXPORT ResourceProvider { |
| 61 private: |
| 62 struct Resource; |
| 63 |
61 public: | 64 public: |
62 typedef unsigned ResourceId; | 65 typedef unsigned ResourceId; |
63 typedef std::vector<ResourceId> ResourceIdArray; | 66 typedef std::vector<ResourceId> ResourceIdArray; |
64 typedef std::set<ResourceId> ResourceIdSet; | 67 typedef std::set<ResourceId> ResourceIdSet; |
65 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; | 68 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; |
66 enum TextureHint { | 69 enum TextureHint { |
67 TextureHintDefault = 0x0, | 70 TextureHintDefault = 0x0, |
68 TextureHintImmutable = 0x1, | 71 TextureHintImmutable = 0x1, |
69 TextureHintFramebuffer = 0x2, | 72 TextureHintFramebuffer = 0x2, |
70 TextureHintImmutableFramebuffer = | 73 TextureHintImmutableFramebuffer = |
71 TextureHintImmutable | TextureHintFramebuffer | 74 TextureHintImmutable | TextureHintFramebuffer |
72 }; | 75 }; |
73 enum ResourceType { | 76 enum ResourceType { |
74 InvalidType = 0, | 77 InvalidType = 0, |
75 GLTexture = 1, | 78 GLTexture = 1, |
76 Bitmap, | 79 Bitmap, |
77 }; | 80 }; |
78 | 81 |
79 static scoped_ptr<ResourceProvider> Create( | 82 static scoped_ptr<ResourceProvider> Create( |
80 OutputSurface* output_surface, | 83 OutputSurface* output_surface, |
81 SharedBitmapManager* shared_bitmap_manager, | 84 SharedBitmapManager* shared_bitmap_manager, |
82 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 85 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
83 BlockingTaskRunner* blocking_main_thread_task_runner, | 86 BlockingTaskRunner* blocking_main_thread_task_runner, |
84 int highp_threshold_min, | 87 int highp_threshold_min, |
85 bool use_rgba_4444_texture_format, | 88 bool use_rgba_4444_texture_format, |
86 size_t id_allocation_chunk_size); | 89 size_t id_allocation_chunk_size); |
87 virtual ~ResourceProvider(); | 90 virtual ~ResourceProvider(); |
88 | 91 |
89 void InitializeSoftware(); | 92 void InitializeSoftware(); |
90 void InitializeGL(); | 93 void InitializeGL(); |
91 | 94 |
92 void DidLoseOutputSurface() { lost_output_surface_ = true; } | 95 void DidLoseOutputSurface() { lost_output_surface_ = true; } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 class CC_EXPORT ScopedWriteLockGL { | 254 class CC_EXPORT ScopedWriteLockGL { |
252 public: | 255 public: |
253 ScopedWriteLockGL(ResourceProvider* resource_provider, | 256 ScopedWriteLockGL(ResourceProvider* resource_provider, |
254 ResourceProvider::ResourceId resource_id); | 257 ResourceProvider::ResourceId resource_id); |
255 ~ScopedWriteLockGL(); | 258 ~ScopedWriteLockGL(); |
256 | 259 |
257 unsigned texture_id() const { return texture_id_; } | 260 unsigned texture_id() const { return texture_id_; } |
258 | 261 |
259 private: | 262 private: |
260 ResourceProvider* resource_provider_; | 263 ResourceProvider* resource_provider_; |
261 ResourceProvider::ResourceId resource_id_; | 264 ResourceProvider::Resource* resource_; |
262 unsigned texture_id_; | 265 unsigned texture_id_; |
263 | 266 |
264 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL); | 267 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL); |
265 }; | 268 }; |
266 | 269 |
267 class CC_EXPORT ScopedReadLockSoftware { | 270 class CC_EXPORT ScopedReadLockSoftware { |
268 public: | 271 public: |
269 ScopedReadLockSoftware(ResourceProvider* resource_provider, | 272 ScopedReadLockSoftware(ResourceProvider* resource_provider, |
270 ResourceProvider::ResourceId resource_id); | 273 ResourceProvider::ResourceId resource_id); |
271 ~ScopedReadLockSoftware(); | 274 ~ScopedReadLockSoftware(); |
(...skipping 19 matching lines...) Expand all Loading... |
291 public: | 294 public: |
292 ScopedWriteLockSoftware(ResourceProvider* resource_provider, | 295 ScopedWriteLockSoftware(ResourceProvider* resource_provider, |
293 ResourceProvider::ResourceId resource_id); | 296 ResourceProvider::ResourceId resource_id); |
294 ~ScopedWriteLockSoftware(); | 297 ~ScopedWriteLockSoftware(); |
295 | 298 |
296 SkCanvas* sk_canvas() { return sk_canvas_.get(); } | 299 SkCanvas* sk_canvas() { return sk_canvas_.get(); } |
297 bool valid() const { return !!sk_bitmap_.getPixels(); } | 300 bool valid() const { return !!sk_bitmap_.getPixels(); } |
298 | 301 |
299 private: | 302 private: |
300 ResourceProvider* resource_provider_; | 303 ResourceProvider* resource_provider_; |
301 ResourceProvider::ResourceId resource_id_; | 304 ResourceProvider::Resource* resource_; |
302 SkBitmap sk_bitmap_; | 305 SkBitmap sk_bitmap_; |
303 scoped_ptr<SkCanvas> sk_canvas_; | 306 scoped_ptr<SkCanvas> sk_canvas_; |
304 | 307 |
305 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); | 308 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); |
306 }; | 309 }; |
307 | 310 |
308 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { | 311 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { |
309 public: | 312 public: |
310 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, | 313 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, |
311 ResourceProvider::ResourceId resource_id); | 314 ResourceProvider::ResourceId resource_id); |
312 ~ScopedWriteLockGpuMemoryBuffer(); | 315 ~ScopedWriteLockGpuMemoryBuffer(); |
313 | 316 |
314 gfx::GpuMemoryBuffer* gpu_memory_buffer() { return gpu_memory_buffer_; } | 317 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer(); |
315 | 318 |
316 private: | 319 private: |
317 ResourceProvider* resource_provider_; | 320 ResourceProvider* resource_provider_; |
318 ResourceProvider::ResourceId resource_id_; | 321 ResourceProvider::Resource* resource_; |
| 322 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; |
319 gfx::GpuMemoryBuffer* gpu_memory_buffer_; | 323 gfx::GpuMemoryBuffer* gpu_memory_buffer_; |
| 324 gfx::Size size_; |
| 325 ResourceFormat format_; |
320 | 326 |
321 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); | 327 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); |
322 }; | 328 }; |
323 | 329 |
324 class CC_EXPORT ScopedWriteLockGr { | 330 class CC_EXPORT ScopedWriteLockGr { |
325 public: | 331 public: |
326 ScopedWriteLockGr(ResourceProvider* resource_provider, | 332 ScopedWriteLockGr(ResourceProvider* resource_provider, |
327 ResourceProvider::ResourceId resource_id); | 333 ResourceProvider::ResourceId resource_id); |
328 ~ScopedWriteLockGr(); | 334 ~ScopedWriteLockGr(); |
329 | 335 |
330 SkSurface* GetSkSurface(bool use_distance_field_text); | 336 SkSurface* GetSkSurface(bool use_distance_field_text); |
331 | 337 |
332 private: | 338 private: |
333 ResourceProvider* resource_provider_; | 339 ResourceProvider* resource_provider_; |
334 ResourceProvider::ResourceId resource_id_; | 340 ResourceProvider::Resource* resource_; |
335 | 341 |
336 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGr); | 342 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGr); |
337 }; | 343 }; |
338 | 344 |
339 class Fence : public base::RefCounted<Fence> { | 345 class Fence : public base::RefCounted<Fence> { |
340 public: | 346 public: |
341 Fence() {} | 347 Fence() {} |
342 | 348 |
343 virtual void Set() = 0; | 349 virtual void Set() = 0; |
344 virtual bool HasPassed() = 0; | 350 virtual bool HasPassed() = 0; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 }; | 481 }; |
476 typedef base::hash_map<int, Child> ChildMap; | 482 typedef base::hash_map<int, Child> ChildMap; |
477 | 483 |
478 bool ReadLockFenceHasPassed(const Resource* resource) { | 484 bool ReadLockFenceHasPassed(const Resource* resource) { |
479 return !resource->read_lock_fence.get() || | 485 return !resource->read_lock_fence.get() || |
480 resource->read_lock_fence->HasPassed(); | 486 resource->read_lock_fence->HasPassed(); |
481 } | 487 } |
482 | 488 |
483 ResourceProvider(OutputSurface* output_surface, | 489 ResourceProvider(OutputSurface* output_surface, |
484 SharedBitmapManager* shared_bitmap_manager, | 490 SharedBitmapManager* shared_bitmap_manager, |
485 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 491 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
486 BlockingTaskRunner* blocking_main_thread_task_runner, | 492 BlockingTaskRunner* blocking_main_thread_task_runner, |
487 int highp_threshold_min, | 493 int highp_threshold_min, |
488 bool use_rgba_4444_texture_format, | 494 bool use_rgba_4444_texture_format, |
489 size_t id_allocation_chunk_size); | 495 size_t id_allocation_chunk_size); |
490 | 496 |
491 void CleanUpGLIfNeeded(); | 497 void CleanUpGLIfNeeded(); |
492 | 498 |
493 Resource* GetResource(ResourceId id); | 499 Resource* GetResource(ResourceId id); |
494 const Resource* LockForRead(ResourceId id); | 500 const Resource* LockForRead(ResourceId id); |
495 void UnlockForRead(ResourceId id); | 501 void UnlockForRead(ResourceId id); |
496 const Resource* LockForWrite(ResourceId id); | 502 Resource* LockForWrite(ResourceId id); |
497 void UnlockForWrite(ResourceId id); | 503 void UnlockForWrite(Resource* resource); |
498 const Resource* LockForWriteToGpuMemoryBuffer(ResourceId id); | |
499 void UnlockForWriteToGpuMemoryBuffer(ResourceId id); | |
500 void LockForWriteToSkSurface(ResourceId id); | |
501 void UnlockForWriteToSkSurface(ResourceId id); | |
502 | 504 |
503 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 505 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
504 const Resource* resource); | 506 const Resource* resource); |
505 | 507 |
506 void TransferResource(gpu::gles2::GLES2Interface* gl, | 508 void TransferResource(gpu::gles2::GLES2Interface* gl, |
507 ResourceId id, | 509 ResourceId id, |
508 TransferableResource* resource); | 510 TransferableResource* resource); |
509 enum DeleteStyle { | 511 enum DeleteStyle { |
510 Normal, | 512 Normal, |
511 ForShutdown, | 513 ForShutdown, |
(...skipping 11 matching lines...) Expand all Loading... |
523 // specified filter for both minification and magnification. Returns the | 525 // specified filter for both minification and magnification. Returns the |
524 // texture target used. The resource must be locked for reading. | 526 // texture target used. The resource must be locked for reading. |
525 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter); | 527 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter); |
526 | 528 |
527 // Returns NULL if the output_surface_ does not have a ContextProvider. | 529 // Returns NULL if the output_surface_ does not have a ContextProvider. |
528 gpu::gles2::GLES2Interface* ContextGL() const; | 530 gpu::gles2::GLES2Interface* ContextGL() const; |
529 class GrContext* GrContext() const; | 531 class GrContext* GrContext() const; |
530 | 532 |
531 OutputSurface* output_surface_; | 533 OutputSurface* output_surface_; |
532 SharedBitmapManager* shared_bitmap_manager_; | 534 SharedBitmapManager* shared_bitmap_manager_; |
533 GpuMemoryBufferManager* gpu_memory_buffer_manager_; | 535 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; |
534 BlockingTaskRunner* blocking_main_thread_task_runner_; | 536 BlockingTaskRunner* blocking_main_thread_task_runner_; |
535 bool lost_output_surface_; | 537 bool lost_output_surface_; |
536 int highp_threshold_min_; | 538 int highp_threshold_min_; |
537 ResourceId next_id_; | 539 ResourceId next_id_; |
538 ResourceMap resources_; | 540 ResourceMap resources_; |
539 int next_child_; | 541 int next_child_; |
540 ChildMap children_; | 542 ChildMap children_; |
541 | 543 |
542 ResourceType default_resource_type_; | 544 ResourceType default_resource_type_; |
543 bool use_texture_storage_ext_; | 545 bool use_texture_storage_ext_; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 return format_gl_data_format[format]; | 609 return format_gl_data_format[format]; |
608 } | 610 } |
609 | 611 |
610 inline GLenum GLInternalFormat(ResourceFormat format) { | 612 inline GLenum GLInternalFormat(ResourceFormat format) { |
611 return GLDataFormat(format); | 613 return GLDataFormat(format); |
612 } | 614 } |
613 | 615 |
614 } // namespace cc | 616 } // namespace cc |
615 | 617 |
616 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 618 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
OLD | NEW |