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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 ~ScopedWriteLockSoftware(); | 297 ~ScopedWriteLockSoftware(); |
298 | 298 |
299 SkCanvas* sk_canvas() { return sk_canvas_.get(); } | 299 SkCanvas* sk_canvas() { return sk_canvas_.get(); } |
300 bool valid() const { return !!sk_bitmap_.getPixels(); } | 300 bool valid() const { return !!sk_bitmap_.getPixels(); } |
301 | 301 |
302 private: | 302 private: |
303 ResourceProvider* resource_provider_; | 303 ResourceProvider* resource_provider_; |
304 ResourceProvider::Resource* resource_; | 304 ResourceProvider::Resource* resource_; |
305 SkBitmap sk_bitmap_; | 305 SkBitmap sk_bitmap_; |
306 scoped_ptr<SkCanvas> sk_canvas_; | 306 scoped_ptr<SkCanvas> sk_canvas_; |
| 307 base::ThreadChecker thread_checker_; |
307 | 308 |
308 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); | 309 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); |
309 }; | 310 }; |
310 | 311 |
311 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { | 312 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { |
312 public: | 313 public: |
313 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, | 314 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, |
314 ResourceProvider::ResourceId resource_id); | 315 ResourceProvider::ResourceId resource_id); |
315 ~ScopedWriteLockGpuMemoryBuffer(); | 316 ~ScopedWriteLockGpuMemoryBuffer(); |
316 | 317 |
317 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer(); | 318 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer(); |
318 | 319 |
319 private: | 320 private: |
320 ResourceProvider* resource_provider_; | 321 ResourceProvider* resource_provider_; |
321 ResourceProvider::Resource* resource_; | 322 ResourceProvider::Resource* resource_; |
322 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; | 323 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; |
323 gfx::GpuMemoryBuffer* gpu_memory_buffer_; | 324 gfx::GpuMemoryBuffer* gpu_memory_buffer_; |
324 gfx::Size size_; | 325 gfx::Size size_; |
325 ResourceFormat format_; | 326 ResourceFormat format_; |
| 327 base::ThreadChecker thread_checker_; |
326 | 328 |
327 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); | 329 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); |
328 }; | 330 }; |
329 | 331 |
330 class CC_EXPORT ScopedWriteLockGr { | 332 class CC_EXPORT ScopedWriteLockGr { |
331 public: | 333 public: |
332 ScopedWriteLockGr(ResourceProvider* resource_provider, | 334 ScopedWriteLockGr(ResourceProvider* resource_provider, |
333 ResourceProvider::ResourceId resource_id); | 335 ResourceProvider::ResourceId resource_id); |
334 ~ScopedWriteLockGr(); | 336 ~ScopedWriteLockGr(); |
335 | 337 |
336 SkSurface* GetSkSurface(bool use_distance_field_text); | 338 SkSurface* GetSkSurface(bool use_distance_field_text); |
337 | 339 |
338 private: | 340 private: |
339 ResourceProvider* resource_provider_; | 341 ResourceProvider* resource_provider_; |
340 ResourceProvider::Resource* resource_; | 342 ResourceProvider::Resource* resource_; |
| 343 base::ThreadChecker thread_checker_; |
341 | 344 |
342 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGr); | 345 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGr); |
343 }; | 346 }; |
344 | 347 |
345 class Fence : public base::RefCounted<Fence> { | 348 class Fence : public base::RefCounted<Fence> { |
346 public: | 349 public: |
347 Fence() {} | 350 Fence() {} |
348 | 351 |
349 virtual void Set() = 0; | 352 virtual void Set() = 0; |
350 virtual bool HasPassed() = 0; | 353 virtual bool HasPassed() = 0; |
| 354 virtual void Wait() = 0; |
351 | 355 |
352 protected: | 356 protected: |
353 friend class base::RefCounted<Fence>; | 357 friend class base::RefCounted<Fence>; |
354 virtual ~Fence() {} | 358 virtual ~Fence() {} |
355 | 359 |
356 private: | 360 private: |
357 DISALLOW_COPY_AND_ASSIGN(Fence); | 361 DISALLOW_COPY_AND_ASSIGN(Fence); |
358 }; | 362 }; |
359 | 363 |
| 364 class SynchronousFence : public ResourceProvider::Fence { |
| 365 public: |
| 366 explicit SynchronousFence(gpu::gles2::GLES2Interface* gl); |
| 367 |
| 368 // Overridden from Fence: |
| 369 void Set() override; |
| 370 bool HasPassed() override; |
| 371 void Wait() override; |
| 372 |
| 373 // Returns true if fence has been set but not yet synchornized. |
| 374 bool has_synchronized() const { return has_synchronized_; } |
| 375 |
| 376 private: |
| 377 ~SynchronousFence() override; |
| 378 |
| 379 void Synchronize(); |
| 380 |
| 381 gpu::gles2::GLES2Interface* gl_; |
| 382 bool has_synchronized_; |
| 383 |
| 384 DISALLOW_COPY_AND_ASSIGN(SynchronousFence); |
| 385 }; |
| 386 |
360 // Acquire pixel buffer for resource. The pixel buffer can be used to | 387 // Acquire pixel buffer for resource. The pixel buffer can be used to |
361 // set resource pixels without performing unnecessary copying. | 388 // set resource pixels without performing unnecessary copying. |
362 void AcquirePixelBuffer(ResourceId resource); | 389 void AcquirePixelBuffer(ResourceId resource); |
363 void ReleasePixelBuffer(ResourceId resource); | 390 void ReleasePixelBuffer(ResourceId resource); |
364 // Map/unmap the acquired pixel buffer. | 391 // Map/unmap the acquired pixel buffer. |
365 uint8_t* MapPixelBuffer(ResourceId id, int* stride); | 392 uint8_t* MapPixelBuffer(ResourceId id, int* stride); |
366 void UnmapPixelBuffer(ResourceId id); | 393 void UnmapPixelBuffer(ResourceId id); |
367 // Asynchronously update pixels from acquired pixel buffer. | 394 // Asynchronously update pixels from acquired pixel buffer. |
368 void BeginSetPixels(ResourceId id); | 395 void BeginSetPixels(ResourceId id); |
369 void ForceSetPixelsToComplete(ResourceId id); | 396 void ForceSetPixelsToComplete(ResourceId id); |
(...skipping 14 matching lines...) Expand all Loading... |
384 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } | 411 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } |
385 | 412 |
386 // Indicates if we can currently lock this resource for write. | 413 // Indicates if we can currently lock this resource for write. |
387 bool CanLockForWrite(ResourceId id); | 414 bool CanLockForWrite(ResourceId id); |
388 | 415 |
389 // Copy pixels from source to destination. | 416 // Copy pixels from source to destination. |
390 void CopyResource(ResourceId source_id, ResourceId dest_id); | 417 void CopyResource(ResourceId source_id, ResourceId dest_id); |
391 | 418 |
392 void WaitSyncPointIfNeeded(ResourceId id); | 419 void WaitSyncPointIfNeeded(ResourceId id); |
393 | 420 |
| 421 void WaitReadLockIfNeeded(ResourceId id); |
| 422 |
394 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); | 423 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); |
395 | 424 |
396 private: | 425 private: |
397 struct Resource { | 426 struct Resource { |
398 enum Origin { Internal, External, Delegated }; | 427 enum Origin { Internal, External, Delegated }; |
399 | 428 |
400 Resource(); | 429 Resource(); |
401 ~Resource(); | 430 ~Resource(); |
402 Resource(unsigned texture_id, | 431 Resource(unsigned texture_id, |
403 const gfx::Size& size, | 432 const gfx::Size& size, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 base::ThreadChecker thread_checker_; | 582 base::ThreadChecker thread_checker_; |
554 | 583 |
555 scoped_refptr<Fence> current_read_lock_fence_; | 584 scoped_refptr<Fence> current_read_lock_fence_; |
556 bool use_rgba_4444_texture_format_; | 585 bool use_rgba_4444_texture_format_; |
557 | 586 |
558 const size_t id_allocation_chunk_size_; | 587 const size_t id_allocation_chunk_size_; |
559 scoped_ptr<IdAllocator> texture_id_allocator_; | 588 scoped_ptr<IdAllocator> texture_id_allocator_; |
560 scoped_ptr<IdAllocator> buffer_id_allocator_; | 589 scoped_ptr<IdAllocator> buffer_id_allocator_; |
561 | 590 |
562 bool use_sync_query_; | 591 bool use_sync_query_; |
| 592 // Fence used for CopyResource if CHROMIUM_sync_query is not supported. |
| 593 scoped_refptr<SynchronousFence> synchronous_fence_; |
563 | 594 |
564 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 595 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
565 }; | 596 }; |
566 | 597 |
567 | 598 |
568 // TODO(epenner): Move these format conversions to resource_format.h | 599 // TODO(epenner): Move these format conversions to resource_format.h |
569 // once that builds on mac (npapi.h currently #includes OpenGL.h). | 600 // once that builds on mac (npapi.h currently #includes OpenGL.h). |
570 inline unsigned BitsPerPixel(ResourceFormat format) { | 601 inline unsigned BitsPerPixel(ResourceFormat format) { |
571 DCHECK_LE(format, RESOURCE_FORMAT_MAX); | 602 DCHECK_LE(format, RESOURCE_FORMAT_MAX); |
572 static const unsigned format_bits_per_pixel[RESOURCE_FORMAT_MAX + 1] = { | 603 static const unsigned format_bits_per_pixel[RESOURCE_FORMAT_MAX + 1] = { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 return format_gl_data_format[format]; | 640 return format_gl_data_format[format]; |
610 } | 641 } |
611 | 642 |
612 inline GLenum GLInternalFormat(ResourceFormat format) { | 643 inline GLenum GLInternalFormat(ResourceFormat format) { |
613 return GLDataFormat(format); | 644 return GLDataFormat(format); |
614 } | 645 } |
615 | 646 |
616 } // namespace cc | 647 } // namespace cc |
617 | 648 |
618 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 649 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
OLD | NEW |