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

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

Issue 454843002: cc: Do bitmap conversion for RasterBuffer in the worker thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 <deque> 8 #include <deque>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
17 #include "base/memory/linked_ptr.h" 17 #include "base/memory/linked_ptr.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/threading/thread_checker.h" 19 #include "base/threading/thread_checker.h"
20 #include "cc/base/cc_export.h" 20 #include "cc/base/cc_export.h"
21 #include "cc/output/context_provider.h" 21 #include "cc/output/context_provider.h"
22 #include "cc/output/output_surface.h" 22 #include "cc/output/output_surface.h"
23 #include "cc/resources/rasterizer.h"
23 #include "cc/resources/release_callback.h" 24 #include "cc/resources/release_callback.h"
24 #include "cc/resources/resource_format.h" 25 #include "cc/resources/resource_format.h"
25 #include "cc/resources/return_callback.h" 26 #include "cc/resources/return_callback.h"
26 #include "cc/resources/shared_bitmap.h" 27 #include "cc/resources/shared_bitmap.h"
27 #include "cc/resources/single_release_callback.h" 28 #include "cc/resources/single_release_callback.h"
28 #include "cc/resources/texture_mailbox.h" 29 #include "cc/resources/texture_mailbox.h"
29 #include "cc/resources/transferable_resource.h" 30 #include "cc/resources/transferable_resource.h"
30 #include "third_party/khronos/GLES2/gl2.h" 31 #include "third_party/khronos/GLES2/gl2.h"
31 #include "third_party/khronos/GLES2/gl2ext.h" 32 #include "third_party/khronos/GLES2/gl2ext.h"
32 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 friend class base::RefCounted<Fence>; 310 friend class base::RefCounted<Fence>;
310 virtual ~Fence() {} 311 virtual ~Fence() {}
311 312
312 private: 313 private:
313 DISALLOW_COPY_AND_ASSIGN(Fence); 314 DISALLOW_COPY_AND_ASSIGN(Fence);
314 }; 315 };
315 316
316 // Returns a canvas for gpu rasterization. 317 // Returns a canvas for gpu rasterization.
317 // Call Unmap before the resource can be read or used for compositing. 318 // Call Unmap before the resource can be read or used for compositing.
318 // It is used for direct gpu rasterization. 319 // It is used for direct gpu rasterization.
319 SkCanvas* MapGpuRasterBuffer(ResourceId id); 320 RasterCanvas* MapGpuRasterBuffer(ResourceId id);
320 void UnmapGpuRasterBuffer(ResourceId id); 321 void UnmapGpuRasterBuffer(ResourceId id);
321 322
322 // Returns a canvas backed by an image buffer. UnmapImageRasterBuffer 323 // Returns a canvas backed by an image buffer. UnmapImageRasterBuffer
323 // returns true if canvas was written to while mapped. 324 // returns true if canvas was written to while mapped.
324 // Rasterizing to the canvas writes the content into the image buffer, 325 // Rasterizing to the canvas writes the content into the image buffer,
325 // which is internally bound to the underlying resource when read. 326 // which is internally bound to the underlying resource when read.
326 // Call Unmap before the resource can be read or used for compositing. 327 // Call Unmap before the resource can be read or used for compositing.
327 // It is used by ImageRasterWorkerPool. 328 // It is used by ImageRasterWorkerPool.
328 SkCanvas* MapImageRasterBuffer(ResourceId id); 329 RasterCanvas* MapImageRasterBuffer(ResourceId id);
329 bool UnmapImageRasterBuffer(ResourceId id); 330 bool UnmapImageRasterBuffer(ResourceId id);
330 331
331 // Returns a canvas backed by pixel buffer. UnmapPixelRasterBuffer 332 // Returns a canvas backed by pixel buffer. UnmapPixelRasterBuffer
332 // returns true if canvas was written to while mapped. 333 // returns true if canvas was written to while mapped.
333 // The pixel buffer needs to be uploaded to the underlying resource 334 // The pixel buffer needs to be uploaded to the underlying resource
334 // using BeginSetPixels before the resouce can be used for compositing. 335 // using BeginSetPixels before the resouce can be used for compositing.
335 // It is used by PixelRasterWorkerPool. 336 // It is used by PixelRasterWorkerPool.
336 void AcquirePixelRasterBuffer(ResourceId id); 337 void AcquirePixelRasterBuffer(ResourceId id);
337 void ReleasePixelRasterBuffer(ResourceId id); 338 void ReleasePixelRasterBuffer(ResourceId id);
338 SkCanvas* MapPixelRasterBuffer(ResourceId id); 339 RasterCanvas* MapPixelRasterBuffer(ResourceId id);
339 bool UnmapPixelRasterBuffer(ResourceId id); 340 bool UnmapPixelRasterBuffer(ResourceId id);
340 341
341 // Asynchronously update pixels from acquired pixel buffer. 342 // Asynchronously update pixels from acquired pixel buffer.
342 void BeginSetPixels(ResourceId id); 343 void BeginSetPixels(ResourceId id);
343 void ForceSetPixelsToComplete(ResourceId id); 344 void ForceSetPixelsToComplete(ResourceId id);
344 bool DidSetPixelsComplete(ResourceId id); 345 bool DidSetPixelsComplete(ResourceId id);
345 346
346 // For tests only! This prevents detecting uninitialized reads. 347 // For tests only! This prevents detecting uninitialized reads.
347 // Use SetPixels or LockForWrite to allocate implicitly. 348 // Use SetPixels or LockForWrite to allocate implicitly.
348 void AllocateForTesting(ResourceId id); 349 void AllocateForTesting(ResourceId id);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 ResourceType type; 439 ResourceType type;
439 ResourceFormat format; 440 ResourceFormat format;
440 SharedBitmapId shared_bitmap_id; 441 SharedBitmapId shared_bitmap_id;
441 SharedBitmap* shared_bitmap; 442 SharedBitmap* shared_bitmap;
442 linked_ptr<GpuRasterBuffer> gpu_raster_buffer; 443 linked_ptr<GpuRasterBuffer> gpu_raster_buffer;
443 linked_ptr<ImageRasterBuffer> image_raster_buffer; 444 linked_ptr<ImageRasterBuffer> image_raster_buffer;
444 linked_ptr<PixelRasterBuffer> pixel_raster_buffer; 445 linked_ptr<PixelRasterBuffer> pixel_raster_buffer;
445 }; 446 };
446 typedef base::hash_map<ResourceId, Resource> ResourceMap; 447 typedef base::hash_map<ResourceId, Resource> ResourceMap;
447 448
448 class RasterBuffer { 449 class RasterBuffer : public RasterCanvas {
reveman 2014/08/11 11:46:21 Do we need both a RasterBuffer and a RasterCanvas
auygun 2014/08/11 14:03:00 I'll try to do that. Looks like RasterBuffer can e
449 public: 450 public:
450 virtual ~RasterBuffer(); 451 virtual ~RasterBuffer();
451 452
452 SkCanvas* LockForWrite(); 453 void LockForWrite();
453 // Returns true if canvas was written to while locked. 454 // Returns true if canvas was written to while locked.
454 bool UnlockForWrite(); 455 bool UnlockForWrite();
455 456
456 protected: 457 protected:
457 RasterBuffer(const Resource* resource, ResourceProvider* resource_provider); 458 RasterBuffer(const Resource* resource, ResourceProvider* resource_provider);
458 const Resource* resource() const { return resource_; } 459 const Resource* resource() const { return resource_; }
459 ResourceProvider* resource_provider() const { return resource_provider_; } 460 ResourceProvider* resource_provider() const { return resource_provider_; }
460 461
461 virtual SkCanvas* DoLockForWrite() = 0; 462 virtual SkCanvas* DoLockForWrite() = 0;
462 virtual bool DoUnlockForWrite() = 0; 463 virtual bool DoUnlockForWrite() = 0;
463 464
464 private: 465 private:
465 const Resource* resource_; 466 const Resource* resource_;
466 ResourceProvider* resource_provider_; 467 ResourceProvider* resource_provider_;
467 SkCanvas* locked_canvas_;
468 int canvas_save_count_; 468 int canvas_save_count_;
469 }; 469 };
470 470
471 class GpuRasterBuffer : public RasterBuffer { 471 class GpuRasterBuffer : public RasterBuffer {
472 public: 472 public:
473 GpuRasterBuffer(const Resource* resource, 473 GpuRasterBuffer(const Resource* resource,
474 ResourceProvider* resource_provider, 474 ResourceProvider* resource_provider,
475 bool use_distance_field_text); 475 bool use_distance_field_text);
476 virtual ~GpuRasterBuffer(); 476 virtual ~GpuRasterBuffer();
477 477
478 protected: 478 protected:
479 virtual SkCanvas* DoLockForWrite() OVERRIDE; 479 virtual SkCanvas* DoLockForWrite() OVERRIDE;
480 virtual bool DoUnlockForWrite() OVERRIDE; 480 virtual bool DoUnlockForWrite() OVERRIDE;
481 virtual void Flush() OVERRIDE {}
481 skia::RefPtr<SkSurface> CreateSurface(); 482 skia::RefPtr<SkSurface> CreateSurface();
482 483
483 private: 484 private:
484 skia::RefPtr<SkSurface> surface_; 485 skia::RefPtr<SkSurface> surface_;
485 uint32_t surface_generation_id_; 486 uint32_t surface_generation_id_;
486 const bool use_distance_field_text_; 487 const bool use_distance_field_text_;
487 488
488 DISALLOW_COPY_AND_ASSIGN(GpuRasterBuffer); 489 DISALLOW_COPY_AND_ASSIGN(GpuRasterBuffer);
489 }; 490 };
490 491
491 class BitmapRasterBuffer : public RasterBuffer { 492 class BitmapRasterBuffer : public RasterBuffer {
492 public: 493 public:
493 virtual ~BitmapRasterBuffer(); 494 virtual ~BitmapRasterBuffer();
494 495
495 protected: 496 protected:
496 BitmapRasterBuffer(const Resource* resource, 497 BitmapRasterBuffer(const Resource* resource,
497 ResourceProvider* resource_provider); 498 ResourceProvider* resource_provider);
498 499
499 virtual SkCanvas* DoLockForWrite() OVERRIDE; 500 virtual SkCanvas* DoLockForWrite() OVERRIDE;
500 virtual bool DoUnlockForWrite() OVERRIDE; 501 virtual bool DoUnlockForWrite() OVERRIDE;
502 virtual void Flush() OVERRIDE;
501 503
502 virtual uint8_t* MapBuffer(int* stride) = 0; 504 virtual uint8_t* MapBuffer(int* stride) = 0;
503 virtual void UnmapBuffer() = 0; 505 virtual void UnmapBuffer() = 0;
504 506
505 private: 507 private:
506 uint8_t* mapped_buffer_; 508 uint8_t* mapped_buffer_;
507 SkBitmap raster_bitmap_; 509 SkBitmap raster_bitmap_;
508 uint32_t raster_bitmap_generation_id_; 510 uint32_t raster_bitmap_generation_id_;
509 skia::RefPtr<SkCanvas> raster_canvas_; 511 skia::RefPtr<SkCanvas> raster_canvas_;
510 }; 512 };
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 return format_gl_data_format[format]; 698 return format_gl_data_format[format];
697 } 699 }
698 700
699 inline GLenum GLInternalFormat(ResourceFormat format) { 701 inline GLenum GLInternalFormat(ResourceFormat format) {
700 return GLDataFormat(format); 702 return GLDataFormat(format);
701 } 703 }
702 704
703 } // namespace cc 705 } // namespace cc
704 706
705 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ 707 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698