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

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

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

Powered by Google App Engine
This is Rietveld 408576698