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

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

Issue 2885533002: cc: Allocate resources on worker context.
Patch Set: fix tests Created 3 years, 7 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/raster/one_copy_raster_buffer_provider.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 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 13 matching lines...) Expand all
234 // The following lock classes are part of the ResourceProvider API and are 235 // The following lock classes are part of the ResourceProvider API and are
235 // needed to read and write the resource contents. The user must ensure 236 // needed to read and write the resource contents. The user must ensure
236 // that they only use GL locks on GL resources, etc, and this is enforced 237 // that they only use GL locks on GL resources, etc, and this is enforced
237 // by assertions. 238 // by assertions.
238 class CC_EXPORT ScopedReadLockGL { 239 class CC_EXPORT ScopedReadLockGL {
239 public: 240 public:
240 ScopedReadLockGL(ResourceProvider* resource_provider, 241 ScopedReadLockGL(ResourceProvider* resource_provider,
241 ResourceId resource_id); 242 ResourceId resource_id);
242 ~ScopedReadLockGL(); 243 ~ScopedReadLockGL();
243 244
244 unsigned texture_id() const { return texture_id_; } 245 unsigned texture_id() const { return resource_->gl_id; }
245 GLenum target() const { return target_; } 246 GLenum target() const { return resource_->target; }
246 const gfx::Size& size() const { return size_; } 247 const gfx::Size& size() const { return resource_->size; }
247 const gfx::ColorSpace& color_space() const { return color_space_; } 248 const gfx::ColorSpace& color_space() const {
249 return resource_->color_space;
250 }
248 251
249 private: 252 private:
250 ResourceProvider* resource_provider_; 253 ResourceProvider* resource_provider_;
251 ResourceId resource_id_; 254 ResourceId resource_id_;
252 unsigned texture_id_; 255 const Resource* resource_;
253 GLenum target_;
254 gfx::Size size_;
255 gfx::ColorSpace color_space_;
256 256
257 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL); 257 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL);
258 }; 258 };
259 259
260 class CC_EXPORT ScopedSamplerGL { 260 class CC_EXPORT ScopedSamplerGL {
261 public: 261 public:
262 ScopedSamplerGL(ResourceProvider* resource_provider, 262 ScopedSamplerGL(ResourceProvider* resource_provider,
263 ResourceId resource_id, 263 ResourceId resource_id,
264 GLenum filter); 264 GLenum filter);
265 ScopedSamplerGL(ResourceProvider* resource_provider, 265 ScopedSamplerGL(ResourceProvider* resource_provider,
(...skipping 13 matching lines...) Expand all
279 GLenum unit_; 279 GLenum unit_;
280 GLenum target_; 280 GLenum target_;
281 281
282 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL); 282 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL);
283 }; 283 };
284 284
285 class CC_EXPORT ScopedWriteLockGL { 285 class CC_EXPORT ScopedWriteLockGL {
286 public: 286 public:
287 ScopedWriteLockGL(ResourceProvider* resource_provider, 287 ScopedWriteLockGL(ResourceProvider* resource_provider,
288 ResourceId resource_id, 288 ResourceId resource_id,
289 bool create_mailbox); 289 bool async_worker_context_enabled);
290 ~ScopedWriteLockGL(); 290 ~ScopedWriteLockGL();
291 291
292 unsigned texture_id() const { return texture_id_; } 292 unsigned texture_id() const { return resource_->gl_id; }
293 GLenum target() const { return target_; } 293 GLenum target() const { return resource_->target; }
294 ResourceFormat format() const { return format_; } 294 ResourceFormat format() const { return resource_->format; }
295 const gfx::Size& size() const { return size_; } 295 const gfx::Size& size() const { return resource_->size; }
296
296 // Will return the invalid color space unless 297 // Will return the invalid color space unless
297 // |enable_color_correct_rasterization| is true. 298 // |enable_color_correct_rasterization| is true.
298 const gfx::ColorSpace& color_space_for_raster() const { 299 const gfx::ColorSpace& color_space_for_raster() const {
299 return color_space_; 300 return color_space_;
300 } 301 }
301 302
302 const TextureMailbox& mailbox() const { return mailbox_; } 303 const TextureMailbox& mailbox() const { return resource_->mailbox(); }
303 304
304 void set_sync_token(const gpu::SyncToken& sync_token) { 305 void LazyAllocate(gpu::gles2::GLES2Interface* gl, unsigned gl_id);
305 sync_token_ = sync_token;
306 has_sync_token_ = true;
307 }
308 306
309 void set_synchronized(bool synchronized) { synchronized_ = synchronized; } 307 void UpdateSyncToken(const gpu::SyncToken& sync_token);
310 308
311 private: 309 private:
312 ResourceProvider* resource_provider_; 310 ResourceProvider* resource_provider_;
313 ResourceId resource_id_; 311 ResourceProvider::Resource* resource_;
piman 2017/05/17 20:58:58 I don't think it's safe to keep a pointer to the R
sunnyps 2017/05/17 22:01:35 unordered_map doesn't invalidate references except
vmiura 2017/05/17 22:13:10 I think pointers can be invalidated when the items
sunnyps 2017/06/08 00:30:07 Changed this to not use Resource*. Although it's n
314 unsigned texture_id_; 312 gfx::ColorSpace color_space_;
315 GLenum target_; 313
316 ResourceFormat format_;
317 gfx::Size size_;
318 TextureMailbox mailbox_;
319 gpu::SyncToken sync_token_;
320 bool has_sync_token_;
321 bool synchronized_;
322 base::ThreadChecker thread_checker_; 314 base::ThreadChecker thread_checker_;
323 gfx::ColorSpace color_space_;
324 315
325 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL); 316 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL);
326 }; 317 };
327 318
328 class CC_EXPORT ScopedTextureProvider { 319 class CC_EXPORT ScopedTextureProvider {
329 public: 320 public:
330 ScopedTextureProvider(gpu::gles2::GLES2Interface* gl, 321 ScopedTextureProvider(gpu::gles2::GLES2Interface* gl,
331 ScopedWriteLockGL* resource_lock, 322 ScopedWriteLockGL* resource_lock,
332 bool use_mailbox); 323 bool async_worker_context_enabled);
333 ~ScopedTextureProvider(); 324 ~ScopedTextureProvider();
334 325
335 unsigned texture_id() const { return texture_id_; } 326 unsigned texture_id() const { return texture_id_; }
336 327
337 private: 328 private:
338 gpu::gles2::GLES2Interface* gl_; 329 gpu::gles2::GLES2Interface* gl_;
339 bool use_mailbox_; 330 bool async_worker_context_enabled_;
340 unsigned texture_id_; 331 unsigned texture_id_ = 0;
341 332
342 DISALLOW_COPY_AND_ASSIGN(ScopedTextureProvider); 333 DISALLOW_COPY_AND_ASSIGN(ScopedTextureProvider);
343 }; 334 };
344 335
345 class CC_EXPORT ScopedSkSurfaceProvider { 336 class CC_EXPORT ScopedSkSurfaceProvider {
346 public: 337 public:
347 ScopedSkSurfaceProvider(ContextProvider* context_provider, 338 ScopedSkSurfaceProvider(ContextProvider* context_provider,
348 ScopedWriteLockGL* resource_lock, 339 ScopedWriteLockGL* resource_lock,
349 bool use_mailbox, 340 bool async_worker_context_enabled,
350 bool use_distance_field_text, 341 bool use_distance_field_text,
351 bool can_use_lcd_text, 342 bool can_use_lcd_text,
352 int msaa_sample_count); 343 int msaa_sample_count);
353 ~ScopedSkSurfaceProvider(); 344 ~ScopedSkSurfaceProvider();
354 345
355 SkSurface* sk_surface() { return sk_surface_.get(); } 346 SkSurface* sk_surface() { return sk_surface_.get(); }
356 347
357 private: 348 private:
358 ScopedTextureProvider texture_provider_; 349 ScopedTextureProvider texture_provider_;
359 sk_sp<SkSurface> sk_surface_; 350 sk_sp<SkSurface> sk_surface_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 SkBitmap& sk_bitmap() { return sk_bitmap_; } 400 SkBitmap& sk_bitmap() { return sk_bitmap_; }
410 bool valid() const { return !!sk_bitmap_.getPixels(); } 401 bool valid() const { return !!sk_bitmap_.getPixels(); }
411 // Will return the invalid color space unless 402 // Will return the invalid color space unless
412 // |enable_color_correct_rasterization| is true. 403 // |enable_color_correct_rasterization| is true.
413 const gfx::ColorSpace& color_space_for_raster() const { 404 const gfx::ColorSpace& color_space_for_raster() const {
414 return color_space_; 405 return color_space_;
415 } 406 }
416 407
417 private: 408 private:
418 ResourceProvider* resource_provider_; 409 ResourceProvider* resource_provider_;
419 ResourceId resource_id_; 410 Resource* resource_;
411 gfx::ColorSpace color_space_;
420 SkBitmap sk_bitmap_; 412 SkBitmap sk_bitmap_;
421 gfx::ColorSpace color_space_; 413
422 base::ThreadChecker thread_checker_; 414 base::ThreadChecker thread_checker_;
423 415
424 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); 416 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware);
425 }; 417 };
426 418
427 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { 419 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer {
428 public: 420 public:
429 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, 421 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider,
430 ResourceId resource_id); 422 ResourceId resource_id);
431 ~ScopedWriteLockGpuMemoryBuffer(); 423 ~ScopedWriteLockGpuMemoryBuffer();
432 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer(); 424 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer();
433 // Will return the invalid color space unless 425 // Will return the invalid color space unless
434 // |enable_color_correct_rasterization| is true. 426 // |enable_color_correct_rasterization| is true.
435 const gfx::ColorSpace& color_space_for_raster() const { 427 const gfx::ColorSpace& color_space_for_raster() const {
436 return color_space_; 428 return color_space_;
437 } 429 }
438 430
439 private: 431 private:
440 ResourceProvider* resource_provider_; 432 ResourceProvider* resource_provider_;
441 ResourceId resource_id_; 433 Resource* resource_;
442 ResourceFormat format_;
443 gfx::BufferUsage usage_;
444 gfx::Size size_;
445 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_;
446 gfx::ColorSpace color_space_; 434 gfx::ColorSpace color_space_;
435
447 base::ThreadChecker thread_checker_; 436 base::ThreadChecker thread_checker_;
448 437
449 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); 438 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer);
450 }; 439 };
451 440
452 // All resources that are returned to children while an instance of this 441 // 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. 442 // class exists will be stored and returned when the instance is destroyed.
454 class CC_EXPORT ScopedBatchReturnResources { 443 class CC_EXPORT ScopedBatchReturnResources {
455 public: 444 public:
456 explicit ScopedBatchReturnResources(ResourceProvider* resource_provider); 445 explicit ScopedBatchReturnResources(ResourceProvider* resource_provider);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 Resource* InsertResource(ResourceId id, Resource resource); 708 Resource* InsertResource(ResourceId id, Resource resource);
720 Resource* GetResource(ResourceId id); 709 Resource* GetResource(ResourceId id);
721 const Resource* LockForRead(ResourceId id); 710 const Resource* LockForRead(ResourceId id);
722 void UnlockForRead(ResourceId id); 711 void UnlockForRead(ResourceId id);
723 Resource* LockForWrite(ResourceId id); 712 Resource* LockForWrite(ResourceId id);
724 void UnlockForWrite(Resource* resource); 713 void UnlockForWrite(Resource* resource);
725 714
726 void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, 715 void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap,
727 const Resource* resource); 716 const Resource* resource);
728 717
729 void CreateMailboxAndBindResource(gpu::gles2::GLES2Interface* gl,
730 Resource* resource);
731 718
732 void TransferResource(Resource* source, 719 void TransferResource(Resource* source,
733 ResourceId id, 720 ResourceId id,
734 TransferableResource* resource); 721 TransferableResource* resource);
735 enum DeleteStyle { 722 enum DeleteStyle {
736 NORMAL, 723 NORMAL,
737 FOR_SHUTDOWN, 724 FOR_SHUTDOWN,
738 }; 725 };
739 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style); 726 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style);
740 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it, 727 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it,
741 DeleteStyle style, 728 DeleteStyle style,
742 const ResourceIdArray& unused); 729 const ResourceIdArray& unused);
743 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style); 730 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style);
731
744 void LazyCreate(Resource* resource); 732 void LazyCreate(Resource* resource);
745 void LazyAllocate(Resource* resource);
746 void LazyCreateImage(Resource* resource);
747 733
748 void BindImageForSampling(Resource* resource); 734 void LazyCreateMailbox(Resource* resource);
735
736 void LazyAllocate(ResourceProvider::Resource* resource,
piman 2017/05/17 20:58:58 nit: no need for ResourceProvider::
737 gpu::gles2::GLES2Interface* gl,
738 unsigned texture_id);
739
740 void LazyAllocateGpuMemoryBuffer(ResourceProvider::Resource* resource);
piman 2017/05/17 20:58:58 nit: ditto
741
742 void LazyCreateImage(Resource* resource, gpu::gles2::GLES2Interface* gl);
743
744 void BindImageForSampling(Resource* resource,
745 gpu::gles2::GLES2Interface* gl,
746 unsigned texture_id);
747
749 // Binds the given GL resource to a texture target for sampling using the 748 // Binds the given GL resource to a texture target for sampling using the
750 // specified filter for both minification and magnification. Returns the 749 // specified filter for both minification and magnification. Returns the
751 // texture target used. The resource must be locked for reading. 750 // texture target used. The resource must be locked for reading.
752 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter); 751 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter);
753 752
754 // Returns null if we do not have a ContextProvider. 753 // Returns null if we do not have a ContextProvider.
755 gpu::gles2::GLES2Interface* ContextGL() const; 754 gpu::gles2::GLES2Interface* ContextGL() const;
756 bool IsGLContextLost() const; 755 bool IsGLContextLost() const;
757 756
758 // Will return the invalid color space unless 757 // 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. 811 // Set of resource Ids that would like to be notified about promotion hints.
813 ResourceIdSet wants_promotion_hints_set_; 812 ResourceIdSet wants_promotion_hints_set_;
814 #endif 813 #endif
815 814
816 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); 815 DISALLOW_COPY_AND_ASSIGN(ResourceProvider);
817 }; 816 };
818 817
819 } // namespace cc 818 } // namespace cc
820 819
821 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ 820 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_
OLDNEW
« no previous file with comments | « cc/raster/one_copy_raster_buffer_provider.cc ('k') | cc/resources/resource_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698