Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: cc/resources/resource_provider.h

Issue 2885533002: cc: Allocate resources on worker context.
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/resource_format.cc ('k') | cc/resources/resource_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // Receives resources from a child, moving them from mailboxes. Resource IDs 198 // Receives resources from a child, moving them from mailboxes. Resource IDs
199 // passed are in the child namespace, and will be translated to the parent 199 // passed are in the child namespace, and will be translated to the parent
200 // namespace, added to the child->parent map. 200 // namespace, added to the child->parent map.
201 // This adds the resources to the working set in the ResourceProvider without 201 // This adds the resources to the working set in the ResourceProvider without
202 // declaring which resources are in use. Use DeclareUsedResourcesFromChild 202 // declaring which resources are in use. Use DeclareUsedResourcesFromChild
203 // after calling this method to do that. All calls to ReceiveFromChild should 203 // after calling this method to do that. All calls to ReceiveFromChild should
204 // be followed by a DeclareUsedResourcesFromChild. 204 // be followed by a DeclareUsedResourcesFromChild.
205 // NOTE: if the sync_token is set on any TransferableResource, this will 205 // NOTE: if the sync_token is set on any TransferableResource, this will
206 // wait on it. 206 // wait on it.
207 void ReceiveFromChild( 207 void ReceiveFromChild(
208 int child, const TransferableResourceArray& transferable_resources); 208 int child,
209 const TransferableResourceArray& transferable_resources);
209 210
210 // Once a set of resources have been received, they may or may not be used. 211 // Once a set of resources have been received, they may or may not be used.
211 // This declares what set of resources are currently in use from the child, 212 // This declares what set of resources are currently in use from the child,
212 // releasing any other resources back to the child. 213 // releasing any other resources back to the child.
213 void DeclareUsedResourcesFromChild(int child, 214 void DeclareUsedResourcesFromChild(int child,
214 const ResourceIdSet& resources_from_child); 215 const ResourceIdSet& resources_from_child);
215 216
216 // Receives resources from the parent, moving them from mailboxes. Resource 217 // Receives resources from the parent, moving them from mailboxes. Resource
217 // IDs passed are in the child namespace. 218 // IDs passed are in the child namespace.
218 // NOTE: if the sync_token is set on any TransferableResource, this will 219 // NOTE: if the sync_token is set on any TransferableResource, this will
(...skipping 21 matching lines...) Expand all
240 ~ScopedReadLockGL(); 241 ~ScopedReadLockGL();
241 242
242 unsigned texture_id() const { return texture_id_; } 243 unsigned texture_id() const { return texture_id_; }
243 GLenum target() const { return target_; } 244 GLenum target() const { return target_; }
244 const gfx::Size& size() const { return size_; } 245 const gfx::Size& size() const { return size_; }
245 const gfx::ColorSpace& color_space() const { return color_space_; } 246 const gfx::ColorSpace& color_space() const { return color_space_; }
246 247
247 private: 248 private:
248 ResourceProvider* resource_provider_; 249 ResourceProvider* resource_provider_;
249 ResourceId resource_id_; 250 ResourceId resource_id_;
251
250 unsigned texture_id_; 252 unsigned texture_id_;
251 GLenum target_; 253 GLenum target_;
252 gfx::Size size_; 254 gfx::Size size_;
253 gfx::ColorSpace color_space_; 255 gfx::ColorSpace color_space_;
254 256
255 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL); 257 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL);
256 }; 258 };
257 259
258 class CC_EXPORT ScopedSamplerGL { 260 class CC_EXPORT ScopedSamplerGL {
259 public: 261 public:
(...skipping 17 matching lines...) Expand all
277 GLenum unit_; 279 GLenum unit_;
278 GLenum target_; 280 GLenum target_;
279 281
280 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL); 282 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL);
281 }; 283 };
282 284
283 class CC_EXPORT ScopedWriteLockGL { 285 class CC_EXPORT ScopedWriteLockGL {
284 public: 286 public:
285 ScopedWriteLockGL(ResourceProvider* resource_provider, 287 ScopedWriteLockGL(ResourceProvider* resource_provider,
286 ResourceId resource_id, 288 ResourceId resource_id,
287 bool create_mailbox); 289 bool async_worker_context_enabled);
288 ~ScopedWriteLockGL(); 290 ~ScopedWriteLockGL();
289 291
290 unsigned texture_id() const { return texture_id_; } 292 unsigned texture_id() const { return texture_id_; }
291 GLenum target() const { return target_; } 293 GLenum target() const { return target_; }
292 ResourceFormat format() const { return format_; } 294 ResourceFormat format() const { return format_; }
293 const gfx::Size& size() const { return size_; } 295 const gfx::Size& size() const { return size_; }
296
294 // Will return the invalid color space unless 297 // Will return the invalid color space unless
295 // |enable_color_correct_rasterization| is true. 298 // |enable_color_correct_rasterization| is true.
296 const gfx::ColorSpace& color_space_for_raster() const { 299 const gfx::ColorSpace& color_space_for_raster() const {
297 return color_space_; 300 return color_space_for_raster_;
298 } 301 }
299 302
300 const TextureMailbox& mailbox() const { return mailbox_; }
301
302 void set_sync_token(const gpu::SyncToken& sync_token) { 303 void set_sync_token(const gpu::SyncToken& sync_token) {
304 set_sync_token_ = true;
303 sync_token_ = sync_token; 305 sync_token_ = sync_token;
304 has_sync_token_ = true;
305 } 306 }
306 307
307 void set_synchronized(bool synchronized) { synchronized_ = synchronized; } 308 // Creates a texture id, allocating if necessary, on the given context. The
309 // texture id must be deleted by the caller.
310 unsigned ConsumeTexture(gpu::gles2::GLES2Interface* gl);
308 311
309 private: 312 private:
310 ResourceProvider* resource_provider_; 313 ResourceProvider* resource_provider_;
311 ResourceId resource_id_; 314 ResourceId resource_id_;
315 bool async_worker_context_enabled_;
316
317 ResourceType type_;
312 unsigned texture_id_; 318 unsigned texture_id_;
319 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_;
320 gfx::BufferUsage usage_;
321 unsigned image_id_;
322 unsigned bound_image_id_;
323 bool dirty_image_;
313 GLenum target_; 324 GLenum target_;
314 ResourceFormat format_; 325 ResourceFormat format_;
315 gfx::Size size_; 326 gfx::Size size_;
316 TextureMailbox mailbox_; 327 gfx::ColorSpace color_space_;
328 gfx::ColorSpace color_space_for_raster_;
329 TextureHint hint_;
330 bool allocated_;
331 gpu::Mailbox mailbox_;
317 gpu::SyncToken sync_token_; 332 gpu::SyncToken sync_token_;
318 bool has_sync_token_; 333 bool set_sync_token_;
319 bool synchronized_; 334
320 base::ThreadChecker thread_checker_; 335 base::ThreadChecker thread_checker_;
321 gfx::ColorSpace color_space_;
322 336
323 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL); 337 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL);
324 }; 338 };
325 339
326 class CC_EXPORT ScopedTextureProvider {
327 public:
328 ScopedTextureProvider(gpu::gles2::GLES2Interface* gl,
329 ScopedWriteLockGL* resource_lock,
330 bool use_mailbox);
331 ~ScopedTextureProvider();
332
333 unsigned texture_id() const { return texture_id_; }
334
335 private:
336 gpu::gles2::GLES2Interface* gl_;
337 bool use_mailbox_;
338 unsigned texture_id_;
339
340 DISALLOW_COPY_AND_ASSIGN(ScopedTextureProvider);
341 };
342
343 class CC_EXPORT ScopedSkSurfaceProvider {
344 public:
345 ScopedSkSurfaceProvider(ContextProvider* context_provider,
346 ScopedWriteLockGL* resource_lock,
347 bool use_mailbox,
348 bool use_distance_field_text,
349 bool can_use_lcd_text,
350 int msaa_sample_count);
351 ~ScopedSkSurfaceProvider();
352
353 SkSurface* sk_surface() { return sk_surface_.get(); }
354
355 private:
356 ScopedTextureProvider texture_provider_;
357 sk_sp<SkSurface> sk_surface_;
358
359 DISALLOW_COPY_AND_ASSIGN(ScopedSkSurfaceProvider);
360 };
361
362 class CC_EXPORT ScopedReadLockSoftware { 340 class CC_EXPORT ScopedReadLockSoftware {
363 public: 341 public:
364 ScopedReadLockSoftware(ResourceProvider* resource_provider, 342 ScopedReadLockSoftware(ResourceProvider* resource_provider,
365 ResourceId resource_id); 343 ResourceId resource_id);
366 ~ScopedReadLockSoftware(); 344 ~ScopedReadLockSoftware();
367 345
368 const SkBitmap* sk_bitmap() const { 346 const SkBitmap* sk_bitmap() const {
369 DCHECK(valid()); 347 DCHECK(valid());
370 return &sk_bitmap_; 348 return &sk_bitmap_;
371 } 349 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 bool valid() const { return !!sk_bitmap_.getPixels(); } 386 bool valid() const { return !!sk_bitmap_.getPixels(); }
409 // Will return the invalid color space unless 387 // Will return the invalid color space unless
410 // |enable_color_correct_rasterization| is true. 388 // |enable_color_correct_rasterization| is true.
411 const gfx::ColorSpace& color_space_for_raster() const { 389 const gfx::ColorSpace& color_space_for_raster() const {
412 return color_space_; 390 return color_space_;
413 } 391 }
414 392
415 private: 393 private:
416 ResourceProvider* resource_provider_; 394 ResourceProvider* resource_provider_;
417 ResourceId resource_id_; 395 ResourceId resource_id_;
396 gfx::ColorSpace color_space_;
418 SkBitmap sk_bitmap_; 397 SkBitmap sk_bitmap_;
419 gfx::ColorSpace color_space_; 398
420 base::ThreadChecker thread_checker_; 399 base::ThreadChecker thread_checker_;
421 400
422 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); 401 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware);
423 }; 402 };
424 403
425 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { 404 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer {
426 public: 405 public:
427 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, 406 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider,
428 ResourceId resource_id); 407 ResourceId resource_id);
429 ~ScopedWriteLockGpuMemoryBuffer(); 408 ~ScopedWriteLockGpuMemoryBuffer();
430 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer(); 409 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer();
431 // Will return the invalid color space unless 410 // Will return the invalid color space unless
432 // |enable_color_correct_rasterization| is true. 411 // |enable_color_correct_rasterization| is true.
433 const gfx::ColorSpace& color_space_for_raster() const { 412 const gfx::ColorSpace& color_space_for_raster() const {
434 return color_space_; 413 return color_space_;
435 } 414 }
436 415
437 private: 416 private:
438 ResourceProvider* resource_provider_; 417 ResourceProvider* resource_provider_;
439 ResourceId resource_id_; 418 ResourceId resource_id_;
419
420 gfx::Size size_;
440 ResourceFormat format_; 421 ResourceFormat format_;
441 gfx::BufferUsage usage_; 422 gfx::BufferUsage usage_;
442 gfx::Size size_; 423 gfx::ColorSpace color_space_;
424
443 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; 425 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_;
444 gfx::ColorSpace color_space_; 426
445 base::ThreadChecker thread_checker_; 427 base::ThreadChecker thread_checker_;
446 428
447 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); 429 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer);
448 }; 430 };
449 431
450 // All resources that are returned to children while an instance of this 432 // All resources that are returned to children while an instance of this
451 // class exists will be stored and returned when the instance is destroyed. 433 // class exists will be stored and returned when the instance is destroyed.
452 class CC_EXPORT ScopedBatchReturnResources { 434 class CC_EXPORT ScopedBatchReturnResources {
453 public: 435 public:
454 explicit ScopedBatchReturnResources(ResourceProvider* resource_provider); 436 explicit ScopedBatchReturnResources(ResourceProvider* resource_provider);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 gfx::Size size; 638 gfx::Size size;
657 Origin origin; 639 Origin origin;
658 GLenum target; 640 GLenum target;
659 // TODO(skyostil): Use a separate sampler object for filter state. 641 // TODO(skyostil): Use a separate sampler object for filter state.
660 GLenum original_filter; 642 GLenum original_filter;
661 GLenum filter; 643 GLenum filter;
662 unsigned image_id; 644 unsigned image_id;
663 unsigned bound_image_id; 645 unsigned bound_image_id;
664 TextureHint hint; 646 TextureHint hint;
665 ResourceType type; 647 ResourceType type;
666
667 // GpuMemoryBuffer resource allocation needs to know how the resource will 648 // GpuMemoryBuffer resource allocation needs to know how the resource will
668 // be used. 649 // be used.
669 gfx::BufferUsage usage; 650 gfx::BufferUsage usage;
670 // This is the the actual format of the underlaying GpuMemoryBuffer, if any, 651 // TODO(sunnyps): Unused. To be removed in a followup cleanup CL.
671 // and might not correspond to ResourceFormat. This format is needed to
672 // scanout the buffer as HW overlay.
673 gfx::BufferFormat buffer_format; 652 gfx::BufferFormat buffer_format;
674 // Resource format is the format as seen from the compositor and might not 653 // Resource format is the format as seen from the compositor and might not
675 // correspond to buffer_format (e.g: A resouce that was created from a YUV 654 // correspond to buffer_format (e.g: A resouce that was created from a YUV
676 // buffer could be seen as RGB from the compositor/GL.) 655 // buffer could be seen as RGB from the compositor/GL.) The format of the
656 // underlying GpuMemoryBuffer, if any, may be different and can be obtained
657 // from |ResourceProvider::GetBufferFormat|.
677 ResourceFormat format; 658 ResourceFormat format;
678 SharedBitmapId shared_bitmap_id; 659 SharedBitmapId shared_bitmap_id;
679 SharedBitmap* shared_bitmap; 660 SharedBitmap* shared_bitmap;
680 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer; 661 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer;
681 gfx::ColorSpace color_space; 662 gfx::ColorSpace color_space;
682 663
683 private: 664 private:
684 SynchronizationState synchronization_state_ = SYNCHRONIZED; 665 SynchronizationState synchronization_state_ = SYNCHRONIZED;
685 bool needs_sync_token_ = false; 666 bool needs_sync_token_ = false;
686 TextureMailbox mailbox_; 667 TextureMailbox mailbox_;
(...skipping 30 matching lines...) Expand all
717 Resource* InsertResource(ResourceId id, Resource resource); 698 Resource* InsertResource(ResourceId id, Resource resource);
718 Resource* GetResource(ResourceId id); 699 Resource* GetResource(ResourceId id);
719 const Resource* LockForRead(ResourceId id); 700 const Resource* LockForRead(ResourceId id);
720 void UnlockForRead(ResourceId id); 701 void UnlockForRead(ResourceId id);
721 Resource* LockForWrite(ResourceId id); 702 Resource* LockForWrite(ResourceId id);
722 void UnlockForWrite(Resource* resource); 703 void UnlockForWrite(Resource* resource);
723 704
724 void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, 705 void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap,
725 const Resource* resource); 706 const Resource* resource);
726 707
727 void CreateMailboxAndBindResource(gpu::gles2::GLES2Interface* gl,
728 Resource* resource);
729
730 void TransferResource(Resource* source, 708 void TransferResource(Resource* source,
731 ResourceId id, 709 ResourceId id,
732 TransferableResource* resource); 710 TransferableResource* resource);
733 enum DeleteStyle { 711 enum DeleteStyle {
734 NORMAL, 712 NORMAL,
735 FOR_SHUTDOWN, 713 FOR_SHUTDOWN,
736 }; 714 };
737 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style); 715 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style);
738 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it, 716 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it,
739 DeleteStyle style, 717 DeleteStyle style,
740 const ResourceIdArray& unused); 718 const ResourceIdArray& unused);
741 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style); 719 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style);
720
742 void LazyCreate(Resource* resource); 721 void LazyCreate(Resource* resource);
722
723 void LazyCreateMailbox(Resource* resource);
724
743 void LazyAllocate(Resource* resource); 725 void LazyAllocate(Resource* resource);
726
727 void AllocateGLTexture(gpu::gles2::GLES2Interface* gl,
728 unsigned gl_id,
729 GLenum target,
730 const gfx::Size& size,
731 ResourceFormat format,
732 TextureHint hint);
733
734 std::unique_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer(
735 const gfx::Size& size,
736 ResourceFormat format,
737 gfx::BufferUsage usage,
738 gfx::ColorSpace color_space);
739
740 void SetGpuMemoryBuffer(
741 Resource* resource,
742 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer);
743
744 unsigned CreateImage(gpu::gles2::GLES2Interface* gl,
745 gfx::GpuMemoryBuffer* gpu_memory_buffer,
746 const gfx::Size& size,
747 ResourceFormat format);
748
744 void LazyCreateImage(Resource* resource); 749 void LazyCreateImage(Resource* resource);
745 750
746 void BindImageForSampling(Resource* resource); 751 void BindImageForSampling(Resource* resource);
752
747 // Binds the given GL resource to a texture target for sampling using the 753 // Binds the given GL resource to a texture target for sampling using the
748 // specified filter for both minification and magnification. Returns the 754 // specified filter for both minification and magnification. Returns the
749 // texture target used. The resource must be locked for reading. 755 // texture target used. The resource must be locked for reading.
750 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter); 756 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter);
751 757
752 // Returns null if we do not have a ContextProvider. 758 // Returns null if we do not have a ContextProvider.
753 gpu::gles2::GLES2Interface* ContextGL() const; 759 gpu::gles2::GLES2Interface* ContextGL() const;
754 bool IsGLContextLost() const; 760 bool IsGLContextLost() const;
755 761
756 // Will return the invalid color space unless 762 // Will return the invalid color space unless
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 // Set of resource Ids that would like to be notified about promotion hints. 816 // Set of resource Ids that would like to be notified about promotion hints.
811 ResourceIdSet wants_promotion_hints_set_; 817 ResourceIdSet wants_promotion_hints_set_;
812 #endif 818 #endif
813 819
814 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); 820 DISALLOW_COPY_AND_ASSIGN(ResourceProvider);
815 }; 821 };
816 822
817 } // namespace cc 823 } // namespace cc
818 824
819 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ 825 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_
OLDNEW
« no previous file with comments | « cc/resources/resource_format.cc ('k') | cc/resources/resource_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698