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 #include "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} | 114 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} |
115 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { | 115 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { |
116 dst->setPixels(buffer_); | 116 dst->setPixels(buffer_); |
117 return true; | 117 return true; |
118 } | 118 } |
119 | 119 |
120 private: | 120 private: |
121 void* buffer_; | 121 void* buffer_; |
122 }; | 122 }; |
123 | 123 |
124 void MakeBitmap(SkBitmap* bitmap, | |
125 uint8_t* buffer, | |
126 ResourceFormat format, | |
127 const gfx::Size& size, | |
128 int stride) { | |
129 switch (format) { | |
130 case RGBA_4444: | |
131 // Use the default stride if we will eventually convert this | |
132 // bitmap to 4444. | |
133 bitmap->allocN32Pixels(size.width(), size.height()); | |
134 break; | |
135 case RGBA_8888: | |
136 case BGRA_8888: { | |
137 SkImageInfo info = | |
138 SkImageInfo::MakeN32Premul(size.width(), size.height()); | |
139 if (0 == stride) | |
140 stride = info.minRowBytes(); | |
141 bitmap->installPixels(info, buffer, stride); | |
142 break; | |
143 } | |
144 case LUMINANCE_8: | |
145 case RGB_565: | |
146 case ETC1: | |
147 NOTREACHED(); | |
148 break; | |
149 } | |
150 } | |
151 | |
124 void CopyBitmap(const SkBitmap& src, uint8_t* dst, SkColorType dst_colorType) { | 152 void CopyBitmap(const SkBitmap& src, uint8_t* dst, SkColorType dst_colorType) { |
125 SkBitmap dst_bitmap; | 153 SkBitmap dst_bitmap; |
126 IdentityAllocator allocator(dst); | 154 IdentityAllocator allocator(dst); |
127 src.copyTo(&dst_bitmap, dst_colorType, &allocator); | 155 src.copyTo(&dst_bitmap, dst_colorType, &allocator); |
128 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the | 156 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the |
129 // bitmap data. This check will be removed once crbug.com/293728 is fixed. | 157 // bitmap data. This check will be removed once crbug.com/293728 is fixed. |
130 CHECK_EQ(0u, dst_bitmap.rowBytes() % 4); | 158 CHECK_EQ(0u, dst_bitmap.rowBytes() % 4); |
131 } | 159 } |
132 | 160 |
133 class ScopedSetActiveTexture { | 161 class ScopedSetActiveTexture { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 shared_bitmap(NULL) { | 423 shared_bitmap(NULL) { |
396 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 424 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
397 } | 425 } |
398 | 426 |
399 ResourceProvider::GpuRasterBuffer::GpuRasterBuffer( | 427 ResourceProvider::GpuRasterBuffer::GpuRasterBuffer( |
400 const Resource* resource, | 428 const Resource* resource, |
401 ResourceProvider* resource_provider, | 429 ResourceProvider* resource_provider, |
402 bool use_distance_field_text) | 430 bool use_distance_field_text) |
403 : resource_(resource), | 431 : resource_(resource), |
404 resource_provider_(resource_provider), | 432 resource_provider_(resource_provider), |
405 locked_canvas_(NULL), | |
406 canvas_save_count_(0), | |
407 surface_generation_id_(0u), | 433 surface_generation_id_(0u), |
408 use_distance_field_text_(use_distance_field_text) { | 434 use_distance_field_text_(use_distance_field_text) { |
435 surface_ = CreateSurface(); | |
436 surface_generation_id_ = surface_ ? surface_->generationID() : 0u; | |
409 } | 437 } |
410 | 438 |
411 ResourceProvider::GpuRasterBuffer::~GpuRasterBuffer() { | 439 ResourceProvider::GpuRasterBuffer::~GpuRasterBuffer() { |
412 } | 440 } |
413 | 441 |
414 void ResourceProvider::GpuRasterBuffer::LockForWrite() { | 442 skia::RefPtr<SkCanvas> ResourceProvider::GpuRasterBuffer::AcquireSkCanvas() { |
415 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
416 "ResourceProvider::GpuRasterBuffer::LockForWrite"); | |
417 | |
418 DCHECK(!locked_canvas_); | |
419 | |
420 if (!surface_) | |
421 surface_ = CreateSurface(); | |
422 surface_generation_id_ = surface_ ? surface_->generationID() : 0u; | |
423 } | |
424 | |
425 bool ResourceProvider::GpuRasterBuffer::UnlockForWrite() { | |
426 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
427 "ResourceProvider::GpuRasterBuffer::UnlockForWrite"); | |
428 | |
429 DCHECK(!locked_canvas_); | |
430 | |
431 // generationID returns a non-zero, unique value corresponding to the content | |
432 // of surface. Hence, a change since LockForWrite was called means the surface | |
433 // has changed. | |
434 return surface_ ? surface_generation_id_ != surface_->generationID() : false; | |
435 } | |
436 | |
437 SkCanvas* ResourceProvider::GpuRasterBuffer::AcquireSkCanvas() { | |
438 // Note that this function is called from a worker thread. | 443 // Note that this function is called from a worker thread. |
439 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 444 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
440 "ResourceProvider::GpuRasterBuffer::AcquireSkCanvas"); | 445 "ResourceProvider::GpuRasterBuffer::AcquireSkCanvas"); |
441 | 446 |
442 DCHECK(!locked_canvas_); | 447 return surface_ ? skia::SharePtr(surface_->getCanvas()) |
443 locked_canvas_ = surface_ ? surface_->getCanvas() : NULL; | 448 : skia::RefPtr<SkCanvas>(); |
444 canvas_save_count_ = locked_canvas_ ? locked_canvas_->save() : 0; | |
445 return locked_canvas_; | |
446 } | 449 } |
447 | 450 |
448 void ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas() { | 451 bool ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas(SkCanvas* canvas) { |
449 // Note that this function is called from a worker thread. | 452 // Note that this function is called from a worker thread. |
450 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 453 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
451 "ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas"); | 454 "ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas"); |
452 | 455 |
453 if (locked_canvas_) { | 456 return surface_ ? surface_generation_id_ != surface_->generationID() : false; |
454 locked_canvas_->restoreToCount(canvas_save_count_); | |
455 locked_canvas_ = NULL; | |
456 } | |
457 } | 457 } |
458 | 458 |
459 skia::RefPtr<SkSurface> ResourceProvider::GpuRasterBuffer::CreateSurface() { | 459 skia::RefPtr<SkSurface> ResourceProvider::GpuRasterBuffer::CreateSurface() { |
reveman
2014/08/13 19:19:50
Is it still worth having this function? Looks like
auygun
2014/08/14 10:35:42
Done.
| |
460 DCHECK_EQ(GLTexture, resource()->type); | 460 DCHECK_EQ(GLTexture, resource_->type); |
461 DCHECK(resource()->gl_id); | 461 DCHECK(resource_->gl_id); |
462 | 462 |
463 class GrContext* gr_context = resource_provider()->GrContext(); | 463 class GrContext* gr_context = resource_provider_->GrContext(); |
464 // TODO(alokp): Implement TestContextProvider::GrContext(). | 464 // TODO(alokp): Implement TestContextProvider::GrContext(). |
465 if (!gr_context) | 465 if (!gr_context) |
466 return skia::RefPtr<SkSurface>(); | 466 return skia::RefPtr<SkSurface>(); |
467 | 467 |
468 GrBackendTextureDesc desc; | 468 GrBackendTextureDesc desc; |
469 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 469 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
470 desc.fWidth = resource()->size.width(); | 470 desc.fWidth = resource_->size.width(); |
471 desc.fHeight = resource()->size.height(); | 471 desc.fHeight = resource_->size.height(); |
472 desc.fConfig = ToGrPixelConfig(resource()->format); | 472 desc.fConfig = ToGrPixelConfig(resource_->format); |
473 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 473 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
474 desc.fTextureHandle = resource()->gl_id; | 474 desc.fTextureHandle = resource_->gl_id; |
475 skia::RefPtr<GrTexture> gr_texture = | 475 skia::RefPtr<GrTexture> gr_texture = |
476 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | 476 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
477 SkSurface::TextRenderMode text_render_mode = | 477 SkSurface::TextRenderMode text_render_mode = |
478 use_distance_field_text_ ? SkSurface::kDistanceField_TextRenderMode | 478 use_distance_field_text_ ? SkSurface::kDistanceField_TextRenderMode |
479 : SkSurface::kStandard_TextRenderMode; | 479 : SkSurface::kStandard_TextRenderMode; |
480 return skia::AdoptRef(SkSurface::NewRenderTargetDirect( | 480 return skia::AdoptRef(SkSurface::NewRenderTargetDirect( |
481 gr_texture->asRenderTarget(), text_render_mode)); | 481 gr_texture->asRenderTarget(), text_render_mode)); |
482 } | 482 } |
483 | 483 |
484 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( | |
485 const Resource* resource, | |
486 ResourceProvider* resource_provider) | |
487 : resource_(resource), | |
488 resource_provider_(resource_provider), | |
489 canvas_save_count_(0), | |
490 mapped_buffer_(NULL), | |
491 raster_bitmap_generation_id_(0u), | |
492 raster_bitmap_changed_(false), | |
493 stride_(0) { | |
494 } | |
495 | |
496 ResourceProvider::BitmapRasterBuffer::~BitmapRasterBuffer() {} | |
497 | |
498 void ResourceProvider::BitmapRasterBuffer::LockForWrite() { | |
499 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
500 "ResourceProvider::BitmapRasterBuffer::LockForWrite"); | |
501 | |
502 DCHECK(!mapped_buffer_); | |
503 DCHECK(!raster_canvas_); | |
504 | |
505 stride_ = 0; | |
506 mapped_buffer_ = MapBuffer(&stride_); | |
507 raster_bitmap_changed_ = false; | |
508 } | |
509 | |
510 bool ResourceProvider::BitmapRasterBuffer::UnlockForWrite() { | |
511 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
512 "ResourceProvider::BitmapRasterBuffer::UnlockForWrite"); | |
513 | |
514 DCHECK(!raster_canvas_); | |
515 | |
516 UnmapBuffer(); | |
517 mapped_buffer_ = NULL; | |
518 return raster_bitmap_changed_; | |
519 } | |
520 | |
521 SkCanvas* ResourceProvider::BitmapRasterBuffer::AcquireSkCanvas() { | |
522 // Note that this function is called from a worker thread. | |
523 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
524 "ResourceProvider::BitmapRasterBuffer::AcquireSkCanvas"); | |
525 | |
526 if (!mapped_buffer_) | |
527 return NULL; | |
528 | |
529 switch (resource()->format) { | |
530 case RGBA_4444: | |
531 // Use the default stride if we will eventually convert this | |
532 // bitmap to 4444. | |
533 raster_bitmap_.allocN32Pixels(resource()->size.width(), | |
534 resource()->size.height()); | |
535 break; | |
536 case RGBA_8888: | |
537 case BGRA_8888: { | |
538 SkImageInfo info = SkImageInfo::MakeN32Premul(resource()->size.width(), | |
539 resource()->size.height()); | |
540 if (0 == stride_) | |
541 stride_ = info.minRowBytes(); | |
542 raster_bitmap_.installPixels(info, mapped_buffer_, stride_); | |
543 break; | |
544 } | |
545 case LUMINANCE_8: | |
546 case RGB_565: | |
547 case ETC1: | |
548 NOTREACHED(); | |
549 break; | |
550 } | |
551 | |
552 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); | |
553 | |
554 DCHECK(!raster_canvas_); | |
555 raster_canvas_ = skia::AdoptRef(new SkCanvas(raster_bitmap_)); | |
556 canvas_save_count_ = raster_canvas_->save(); | |
557 return raster_canvas_.get(); | |
558 } | |
559 | |
560 void ResourceProvider::BitmapRasterBuffer::ReleaseSkCanvas() { | |
561 // Note that this function is called from a worker thread. | |
562 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
563 "ResourceProvider::BitmapRasterBuffer::ReleaseSkCanvas"); | |
564 | |
565 if (raster_canvas_) { | |
566 raster_canvas_->restoreToCount(canvas_save_count_); | |
567 raster_canvas_.clear(); | |
568 } | |
569 | |
570 // getGenerationID returns a non-zero, unique value corresponding to the | |
571 // pixels in bitmap. Hence, a change since LockForWrite was called means the | |
572 // bitmap has changed. | |
573 raster_bitmap_changed_ = | |
574 raster_bitmap_generation_id_ != raster_bitmap_.getGenerationID(); | |
575 if (raster_bitmap_changed_) { | |
576 SkColorType buffer_colorType = | |
577 ResourceFormatToSkColorType(resource()->format); | |
578 if (mapped_buffer_ && (buffer_colorType != raster_bitmap_.colorType())) | |
579 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_colorType); | |
580 } | |
581 raster_bitmap_.reset(); | |
582 } | |
583 | |
584 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( | 484 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( |
585 const Resource* resource, | 485 const Resource* resource, |
586 ResourceProvider* resource_provider) | 486 ResourceProvider* resource_provider) |
587 : BitmapRasterBuffer(resource, resource_provider) {} | 487 : resource_(resource), |
588 | 488 resource_provider_(resource_provider), |
589 ResourceProvider::ImageRasterBuffer::~ImageRasterBuffer() {} | 489 mapped_buffer_(NULL), |
590 | 490 raster_bitmap_generation_id_(0u), |
591 uint8_t* ResourceProvider::ImageRasterBuffer::MapBuffer(int* stride) { | 491 stride_(0) { |
592 return resource_provider()->MapImage(resource(), stride); | |
593 } | 492 } |
594 | 493 |
595 void ResourceProvider::ImageRasterBuffer::UnmapBuffer() { | 494 ResourceProvider::ImageRasterBuffer::~ImageRasterBuffer() { |
596 resource_provider()->UnmapImage(resource()); | 495 } |
496 | |
497 void ResourceProvider::ImageRasterBuffer::LockForWrite() { | |
498 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
499 "ResourceProvider::ImageRasterBuffer::LockForWrite"); | |
500 | |
501 DCHECK(!mapped_buffer_); | |
502 | |
503 stride_ = 0; | |
504 mapped_buffer_ = resource_provider_->MapImage(resource_, &stride_); | |
505 } | |
506 | |
507 void ResourceProvider::ImageRasterBuffer::UnlockForWrite() { | |
508 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
509 "ResourceProvider::ImageRasterBuffer::UnlockForWrite"); | |
510 | |
511 resource_provider_->UnmapImage(resource_); | |
512 mapped_buffer_ = NULL; | |
513 } | |
514 | |
515 skia::RefPtr<SkCanvas> ResourceProvider::ImageRasterBuffer::AcquireSkCanvas() { | |
516 // Note that this function is called from a worker thread. | |
517 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
518 "ResourceProvider::ImageRasterBuffer::AcquireSkCanvas"); | |
519 | |
520 if (!mapped_buffer_) | |
521 return skia::RefPtr<SkCanvas>(); | |
522 | |
523 MakeBitmap(&raster_bitmap_, | |
524 mapped_buffer_, | |
525 resource_->format, | |
526 resource_->size, | |
527 stride_); | |
528 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); | |
reveman
2014/08/13 19:19:49
Let's not bother with the generation Id anymore. T
auygun
2014/08/14 10:35:42
Done.
| |
529 return skia::AdoptRef(new SkCanvas(raster_bitmap_)); | |
530 } | |
531 | |
532 bool ResourceProvider::ImageRasterBuffer::ReleaseSkCanvas(SkCanvas* canvas) { | |
533 // Note that this function is called from a worker thread. | |
534 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
535 "ResourceProvider::ImageRasterBuffer::ReleaseSkCanvas"); | |
536 | |
537 // getGenerationID returns a non-zero, unique value corresponding to the | |
538 // pixels in bitmap. Hence, a change since LockForWrite was called means the | |
539 // bitmap has changed. | |
540 bool raster_bitmap_changed = | |
541 raster_bitmap_generation_id_ != raster_bitmap_.getGenerationID(); | |
reveman
2014/08/13 19:19:50
Remove generation id related code. It can be assum
auygun
2014/08/14 10:35:42
Done.
| |
542 if (raster_bitmap_changed) { | |
543 SkColorType buffer_colorType = | |
544 ResourceFormatToSkColorType(resource_->format); | |
545 if (mapped_buffer_ && (buffer_colorType != raster_bitmap_.colorType())) | |
546 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_colorType); | |
547 } | |
548 raster_bitmap_.reset(); | |
549 return raster_bitmap_changed; | |
597 } | 550 } |
598 | 551 |
599 ResourceProvider::PixelRasterBuffer::PixelRasterBuffer( | 552 ResourceProvider::PixelRasterBuffer::PixelRasterBuffer( |
600 const Resource* resource, | 553 const Resource* resource, |
601 ResourceProvider* resource_provider) | 554 ResourceProvider* resource_provider) |
602 : BitmapRasterBuffer(resource, resource_provider) {} | 555 : resource_(resource), |
603 | 556 resource_provider_(resource_provider), |
604 ResourceProvider::PixelRasterBuffer::~PixelRasterBuffer() {} | 557 mapped_buffer_(NULL), |
605 | 558 raster_bitmap_generation_id_(0u), |
606 uint8_t* ResourceProvider::PixelRasterBuffer::MapBuffer(int* stride) { | 559 stride_(0) { |
607 return resource_provider()->MapPixelBuffer(resource(), stride); | |
608 } | 560 } |
609 | 561 |
610 void ResourceProvider::PixelRasterBuffer::UnmapBuffer() { | 562 ResourceProvider::PixelRasterBuffer::~PixelRasterBuffer() { |
611 resource_provider()->UnmapPixelBuffer(resource()); | 563 } |
564 | |
565 void ResourceProvider::PixelRasterBuffer::LockForWrite() { | |
566 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
567 "ResourceProvider::PixelRasterBuffer::LockForWrite"); | |
568 | |
569 DCHECK(!mapped_buffer_); | |
570 | |
571 stride_ = 0; | |
572 mapped_buffer_ = resource_provider_->MapPixelBuffer(resource_, &stride_); | |
573 } | |
574 | |
575 void ResourceProvider::PixelRasterBuffer::UnlockForWrite() { | |
576 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
577 "ResourceProvider::PixelRasterBuffer::UnlockForWrite"); | |
578 | |
579 resource_provider_->UnmapPixelBuffer(resource_); | |
580 mapped_buffer_ = NULL; | |
581 } | |
582 | |
583 skia::RefPtr<SkCanvas> ResourceProvider::PixelRasterBuffer::AcquireSkCanvas() { | |
584 // Note that this function is called from a worker thread. | |
585 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
586 "ResourceProvider::PixelRasterBuffer::AcquireSkCanvas"); | |
587 | |
588 if (!mapped_buffer_) | |
589 return skia::RefPtr<SkCanvas>(); | |
590 | |
591 MakeBitmap(&raster_bitmap_, | |
592 mapped_buffer_, | |
593 resource_->format, | |
594 resource_->size, | |
595 stride_); | |
596 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); | |
597 return skia::AdoptRef(new SkCanvas(raster_bitmap_)); | |
598 } | |
599 | |
600 bool ResourceProvider::PixelRasterBuffer::ReleaseSkCanvas(SkCanvas* canvas) { | |
601 // Note that this function is called from a worker thread. | |
602 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
603 "ResourceProvider::PixelRasterBuffer::ReleaseSkCanvas"); | |
604 | |
605 // getGenerationID returns a non-zero, unique value corresponding to the | |
606 // pixels in bitmap. Hence, a change since LockForWrite was called means the | |
607 // bitmap has changed. | |
608 bool raster_bitmap_changed = | |
609 raster_bitmap_generation_id_ != raster_bitmap_.getGenerationID(); | |
reveman
2014/08/13 19:19:49
Same here. Remove generation id related code.
auygun
2014/08/14 10:35:42
Done.
| |
610 if (raster_bitmap_changed) { | |
611 SkColorType buffer_colorType = | |
612 ResourceFormatToSkColorType(resource_->format); | |
613 if (mapped_buffer_ && (buffer_colorType != raster_bitmap_.colorType())) | |
614 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_colorType); | |
615 } | |
616 raster_bitmap_.reset(); | |
617 return raster_bitmap_changed; | |
612 } | 618 } |
613 | 619 |
614 ResourceProvider::Child::Child() : marked_for_deletion(false) {} | 620 ResourceProvider::Child::Child() : marked_for_deletion(false) {} |
615 | 621 |
616 ResourceProvider::Child::~Child() {} | 622 ResourceProvider::Child::~Child() {} |
617 | 623 |
618 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 624 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
619 OutputSurface* output_surface, | 625 OutputSurface* output_surface, |
620 SharedBitmapManager* shared_bitmap_manager, | 626 SharedBitmapManager* shared_bitmap_manager, |
621 int highp_threshold_min, | 627 int highp_threshold_min, |
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1761 | 1767 |
1762 RasterBuffer* ResourceProvider::AcquireGpuRasterBuffer(ResourceId id) { | 1768 RasterBuffer* ResourceProvider::AcquireGpuRasterBuffer(ResourceId id) { |
1763 // Resource needs to be locked for write since GpuRasterBuffer writes | 1769 // Resource needs to be locked for write since GpuRasterBuffer writes |
1764 // directly to it. | 1770 // directly to it. |
1765 LockForWrite(id); | 1771 LockForWrite(id); |
1766 Resource* resource = GetResource(id); | 1772 Resource* resource = GetResource(id); |
1767 if (!resource->gpu_raster_buffer.get()) { | 1773 if (!resource->gpu_raster_buffer.get()) { |
1768 resource->gpu_raster_buffer.reset( | 1774 resource->gpu_raster_buffer.reset( |
1769 new GpuRasterBuffer(resource, this, use_distance_field_text_)); | 1775 new GpuRasterBuffer(resource, this, use_distance_field_text_)); |
1770 } | 1776 } |
1771 resource->gpu_raster_buffer->LockForWrite(); | |
1772 return resource->gpu_raster_buffer.get(); | 1777 return resource->gpu_raster_buffer.get(); |
1773 } | 1778 } |
1774 | 1779 |
1775 void ResourceProvider::ReleaseGpuRasterBuffer(ResourceId id) { | 1780 void ResourceProvider::ReleaseGpuRasterBuffer(ResourceId id) { |
1776 Resource* resource = GetResource(id); | 1781 Resource* resource = GetResource(id); |
1777 DCHECK(resource->gpu_raster_buffer.get()); | 1782 DCHECK(resource->gpu_raster_buffer.get()); |
1778 resource->gpu_raster_buffer->UnlockForWrite(); | |
1779 UnlockForWrite(id); | 1783 UnlockForWrite(id); |
1780 } | 1784 } |
1781 | 1785 |
1782 RasterBuffer* ResourceProvider::AcquireImageRasterBuffer(ResourceId id) { | 1786 RasterBuffer* ResourceProvider::AcquireImageRasterBuffer(ResourceId id) { |
1783 Resource* resource = GetResource(id); | 1787 Resource* resource = GetResource(id); |
1784 AcquireImage(resource); | 1788 AcquireImage(resource); |
1785 if (!resource->image_raster_buffer.get()) | 1789 if (!resource->image_raster_buffer.get()) |
1786 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); | 1790 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); |
1787 resource->image_raster_buffer->LockForWrite(); | 1791 resource->image_raster_buffer->LockForWrite(); |
1788 return resource->image_raster_buffer.get(); | 1792 return resource->image_raster_buffer.get(); |
1789 } | 1793 } |
1790 | 1794 |
1791 bool ResourceProvider::ReleaseImageRasterBuffer(ResourceId id) { | 1795 void ResourceProvider::ReleaseImageRasterBuffer(ResourceId id) { |
1792 Resource* resource = GetResource(id); | 1796 Resource* resource = GetResource(id); |
1793 resource->dirty_image = true; | 1797 resource->dirty_image = true; |
1794 return resource->image_raster_buffer->UnlockForWrite(); | 1798 resource->image_raster_buffer->UnlockForWrite(); |
1795 } | 1799 } |
1796 | 1800 |
1797 void ResourceProvider::AcquirePixelRasterBuffer(ResourceId id) { | 1801 RasterBuffer* ResourceProvider::AcquirePixelRasterBuffer(ResourceId id) { |
1798 Resource* resource = GetResource(id); | 1802 Resource* resource = GetResource(id); |
1799 AcquirePixelBuffer(resource); | 1803 AcquirePixelBuffer(resource); |
1800 resource->pixel_raster_buffer.reset(new PixelRasterBuffer(resource, this)); | 1804 resource->pixel_raster_buffer.reset(new PixelRasterBuffer(resource, this)); |
1805 resource->pixel_raster_buffer->LockForWrite(); | |
1806 return resource->pixel_raster_buffer.get(); | |
1801 } | 1807 } |
1802 | 1808 |
1803 void ResourceProvider::ReleasePixelRasterBuffer(ResourceId id) { | 1809 void ResourceProvider::ReleasePixelRasterBuffer(ResourceId id) { |
1804 Resource* resource = GetResource(id); | 1810 Resource* resource = GetResource(id); |
1811 DCHECK(resource->pixel_raster_buffer.get()); | |
1812 resource->pixel_raster_buffer->UnlockForWrite(); | |
1805 resource->pixel_raster_buffer.reset(); | 1813 resource->pixel_raster_buffer.reset(); |
1806 ReleasePixelBuffer(resource); | 1814 ReleasePixelBuffer(resource); |
1807 } | 1815 } |
1808 | 1816 |
1809 RasterBuffer* ResourceProvider::MapPixelRasterBuffer(ResourceId id) { | |
1810 Resource* resource = GetResource(id); | |
1811 DCHECK(resource->pixel_raster_buffer.get()); | |
1812 resource->pixel_raster_buffer->LockForWrite(); | |
1813 return resource->pixel_raster_buffer.get(); | |
1814 } | |
1815 | |
1816 bool ResourceProvider::UnmapPixelRasterBuffer(ResourceId id) { | |
1817 Resource* resource = GetResource(id); | |
1818 DCHECK(resource->pixel_raster_buffer.get()); | |
1819 return resource->pixel_raster_buffer->UnlockForWrite(); | |
1820 } | |
1821 | |
1822 void ResourceProvider::AcquirePixelBuffer(Resource* resource) { | 1817 void ResourceProvider::AcquirePixelBuffer(Resource* resource) { |
1823 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1818 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
1824 "ResourceProvider::AcquirePixelBuffer"); | 1819 "ResourceProvider::AcquirePixelBuffer"); |
1825 | 1820 |
1826 DCHECK(resource->origin == Resource::Internal); | 1821 DCHECK(resource->origin == Resource::Internal); |
1827 DCHECK_EQ(resource->exported_count, 0); | 1822 DCHECK_EQ(resource->exported_count, 0); |
1828 DCHECK(!resource->image_id); | 1823 DCHECK(!resource->image_id); |
1829 DCHECK_NE(ETC1, resource->format); | 1824 DCHECK_NE(ETC1, resource->format); |
1830 | 1825 |
1831 DCHECK_EQ(GLTexture, resource->type); | 1826 DCHECK_EQ(GLTexture, resource->type); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1945 return target; | 1940 return target; |
1946 } | 1941 } |
1947 | 1942 |
1948 void ResourceProvider::BeginSetPixels(ResourceId id) { | 1943 void ResourceProvider::BeginSetPixels(ResourceId id) { |
1949 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1944 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
1950 "ResourceProvider::BeginSetPixels"); | 1945 "ResourceProvider::BeginSetPixels"); |
1951 | 1946 |
1952 Resource* resource = GetResource(id); | 1947 Resource* resource = GetResource(id); |
1953 DCHECK(!resource->pending_set_pixels); | 1948 DCHECK(!resource->pending_set_pixels); |
1954 | 1949 |
1950 DCHECK(resource->pixel_raster_buffer.get()); | |
1951 resource->pixel_raster_buffer->UnlockForWrite(); | |
1952 | |
1955 LazyCreate(resource); | 1953 LazyCreate(resource); |
1956 DCHECK(resource->origin == Resource::Internal); | 1954 DCHECK(resource->origin == Resource::Internal); |
1957 DCHECK(resource->gl_id || resource->allocated); | 1955 DCHECK(resource->gl_id || resource->allocated); |
1958 DCHECK(ReadLockFenceHasPassed(resource)); | 1956 DCHECK(ReadLockFenceHasPassed(resource)); |
1959 DCHECK(!resource->image_id); | 1957 DCHECK(!resource->image_id); |
1960 | 1958 |
1961 bool allocate = !resource->allocated; | 1959 bool allocate = !resource->allocated; |
1962 resource->allocated = true; | 1960 resource->allocated = true; |
1963 LockForWrite(id); | 1961 LockForWrite(id); |
1964 | 1962 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2287 ContextProvider* context_provider = output_surface_->context_provider(); | 2285 ContextProvider* context_provider = output_surface_->context_provider(); |
2288 return context_provider ? context_provider->ContextGL() : NULL; | 2286 return context_provider ? context_provider->ContextGL() : NULL; |
2289 } | 2287 } |
2290 | 2288 |
2291 class GrContext* ResourceProvider::GrContext() const { | 2289 class GrContext* ResourceProvider::GrContext() const { |
2292 ContextProvider* context_provider = output_surface_->context_provider(); | 2290 ContextProvider* context_provider = output_surface_->context_provider(); |
2293 return context_provider ? context_provider->GrContext() : NULL; | 2291 return context_provider ? context_provider->GrContext() : NULL; |
2294 } | 2292 } |
2295 | 2293 |
2296 } // namespace cc | 2294 } // namespace cc |
OLD | NEW |