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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 surface = skia::AdoptRef( | 435 surface = skia::AdoptRef( |
436 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); | 436 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); |
437 } | 437 } |
438 break; | 438 break; |
439 } | 439 } |
440 case Bitmap: { | 440 case Bitmap: { |
441 DCHECK(resource()->pixels); | 441 DCHECK(resource()->pixels); |
442 DCHECK_EQ(RGBA_8888, resource()->format); | 442 DCHECK_EQ(RGBA_8888, resource()->format); |
443 SkImageInfo image_info = SkImageInfo::MakeN32Premul( | 443 SkImageInfo image_info = SkImageInfo::MakeN32Premul( |
444 resource()->size.width(), resource()->size.height()); | 444 resource()->size.width(), resource()->size.height()); |
445 size_t row_bytes = SkBitmap::ComputeRowBytes(SkBitmap::kARGB_8888_Config, | |
446 resource()->size.width()); | |
447 surface = skia::AdoptRef(SkSurface::NewRasterDirect( | 445 surface = skia::AdoptRef(SkSurface::NewRasterDirect( |
448 image_info, resource()->pixels, row_bytes)); | 446 image_info, resource()->pixels, image_info.minRowBytes())); |
449 break; | 447 break; |
450 } | 448 } |
451 default: | 449 default: |
452 NOTREACHED(); | 450 NOTREACHED(); |
453 } | 451 } |
454 return surface; | 452 return surface; |
455 } | 453 } |
456 | 454 |
457 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( | 455 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( |
458 const Resource* resource, | 456 const Resource* resource, |
(...skipping 10 matching lines...) Expand all Loading... |
469 | 467 |
470 int stride = 0; | 468 int stride = 0; |
471 mapped_buffer_ = MapBuffer(&stride); | 469 mapped_buffer_ = MapBuffer(&stride); |
472 if (!mapped_buffer_) | 470 if (!mapped_buffer_) |
473 return NULL; | 471 return NULL; |
474 | 472 |
475 switch (resource()->format) { | 473 switch (resource()->format) { |
476 case RGBA_4444: | 474 case RGBA_4444: |
477 // Use the default stride if we will eventually convert this | 475 // Use the default stride if we will eventually convert this |
478 // bitmap to 4444. | 476 // bitmap to 4444. |
479 raster_bitmap_.setConfig(SkBitmap::kARGB_8888_Config, | 477 raster_bitmap_.allocN32Pixels(resource()->size.width(), |
480 resource()->size.width(), | 478 resource()->size.height()); |
481 resource()->size.height()); | |
482 raster_bitmap_.allocPixels(); | |
483 break; | 479 break; |
484 case RGBA_8888: | 480 case RGBA_8888: |
485 case BGRA_8888: | 481 case BGRA_8888: { |
486 raster_bitmap_.setConfig(SkBitmap::kARGB_8888_Config, | 482 SkImageInfo info = SkImageInfo::MakeN32Premul(resource()->size.width(), |
487 resource()->size.width(), | 483 resource()->size.height()); |
488 resource()->size.height(), | 484 raster_bitmap_.installPixels(info, mapped_buffer_, stride); |
489 stride); | |
490 raster_bitmap_.setPixels(mapped_buffer_); | |
491 break; | 485 break; |
| 486 } |
492 case LUMINANCE_8: | 487 case LUMINANCE_8: |
493 case RGB_565: | 488 case RGB_565: |
494 case ETC1: | 489 case ETC1: |
495 NOTREACHED(); | 490 NOTREACHED(); |
496 break; | 491 break; |
497 } | 492 } |
498 raster_canvas_ = skia::AdoptRef(new SkCanvas(raster_bitmap_)); | 493 raster_canvas_ = skia::AdoptRef(new SkCanvas(raster_bitmap_)); |
499 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); | 494 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); |
500 return raster_canvas_.get(); | 495 return raster_canvas_.get(); |
501 } | 496 } |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 texture_uploader_->Upload(image, | 908 texture_uploader_->Upload(image, |
914 image_rect, | 909 image_rect, |
915 source_rect, | 910 source_rect, |
916 dest_offset, | 911 dest_offset, |
917 resource->format, | 912 resource->format, |
918 resource->size); | 913 resource->size); |
919 } else { | 914 } else { |
920 DCHECK_EQ(Bitmap, resource->type); | 915 DCHECK_EQ(Bitmap, resource->type); |
921 DCHECK(resource->allocated); | 916 DCHECK(resource->allocated); |
922 DCHECK_EQ(RGBA_8888, resource->format); | 917 DCHECK_EQ(RGBA_8888, resource->format); |
923 SkBitmap src_full; | 918 DCHECK(source_rect.x() >= image_rect.x()); |
924 src_full.setConfig( | 919 DCHECK(source_rect.y() >= image_rect.y()); |
925 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); | 920 DCHECK(source_rect.width() <= image_rect.width()); |
926 src_full.setPixels(const_cast<uint8_t*>(image)); | 921 DCHECK(source_rect.height() <= image_rect.height()); |
927 SkBitmap src_subset; | 922 SkImageInfo info = |
928 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), | 923 SkImageInfo::MakeN32Premul(source_rect.width(), source_rect.height()); |
929 source_rect.y(), | 924 size_t rowBytes = image_rect.width() * 4; |
930 source_rect.width(), | 925 int dx = source_rect.x() - image_rect.x(); |
931 source_rect.height()); | 926 int dy = source_rect.y() - image_rect.y(); |
932 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); | 927 image += dy * rowBytes + dx * 4; |
933 src_full.extractSubset(&src_subset, sk_source_rect); | |
934 | 928 |
935 ScopedWriteLockSoftware lock(this, id); | 929 ScopedWriteLockSoftware lock(this, id); |
936 SkCanvas* dest = lock.sk_canvas(); | 930 SkCanvas* dest = lock.sk_canvas(); |
937 dest->writePixels(src_subset, dest_offset.x(), dest_offset.y()); | 931 dest->writePixels(info, image, rowBytes, dest_offset.x(), dest_offset.y()); |
938 } | 932 } |
939 } | 933 } |
940 | 934 |
941 size_t ResourceProvider::NumBlockingUploads() { | 935 size_t ResourceProvider::NumBlockingUploads() { |
942 if (!texture_uploader_) | 936 if (!texture_uploader_) |
943 return 0; | 937 return 0; |
944 | 938 |
945 return texture_uploader_->NumBlockingUploads(); | 939 return texture_uploader_->NumBlockingUploads(); |
946 } | 940 } |
947 | 941 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 DCHECK(texture_id_); | 1149 DCHECK(texture_id_); |
1156 } | 1150 } |
1157 | 1151 |
1158 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 1152 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
1159 resource_provider_->UnlockForWrite(resource_id_); | 1153 resource_provider_->UnlockForWrite(resource_id_); |
1160 } | 1154 } |
1161 | 1155 |
1162 void ResourceProvider::PopulateSkBitmapWithResource( | 1156 void ResourceProvider::PopulateSkBitmapWithResource( |
1163 SkBitmap* sk_bitmap, const Resource* resource) { | 1157 SkBitmap* sk_bitmap, const Resource* resource) { |
1164 DCHECK_EQ(RGBA_8888, resource->format); | 1158 DCHECK_EQ(RGBA_8888, resource->format); |
1165 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 1159 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), |
1166 resource->size.width(), | 1160 resource->size.height()); |
1167 resource->size.height()); | 1161 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); |
1168 sk_bitmap->setPixels(resource->pixels); | |
1169 } | 1162 } |
1170 | 1163 |
1171 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 1164 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
1172 ResourceProvider* resource_provider, | 1165 ResourceProvider* resource_provider, |
1173 ResourceProvider::ResourceId resource_id) | 1166 ResourceProvider::ResourceId resource_id) |
1174 : resource_provider_(resource_provider), | 1167 : resource_provider_(resource_provider), |
1175 resource_id_(resource_id) { | 1168 resource_id_(resource_id) { |
1176 const Resource* resource = resource_provider->LockForRead(resource_id); | 1169 const Resource* resource = resource_provider->LockForRead(resource_id); |
1177 wrap_mode_ = resource->wrap_mode; | 1170 wrap_mode_ = resource->wrap_mode; |
1178 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); | 1171 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 ContextProvider* context_provider = output_surface_->context_provider(); | 2174 ContextProvider* context_provider = output_surface_->context_provider(); |
2182 return context_provider ? context_provider->ContextGL() : NULL; | 2175 return context_provider ? context_provider->ContextGL() : NULL; |
2183 } | 2176 } |
2184 | 2177 |
2185 class GrContext* ResourceProvider::GrContext() const { | 2178 class GrContext* ResourceProvider::GrContext() const { |
2186 ContextProvider* context_provider = output_surface_->context_provider(); | 2179 ContextProvider* context_provider = output_surface_->context_provider(); |
2187 return context_provider ? context_provider->GrContext() : NULL; | 2180 return context_provider ? context_provider->GrContext() : NULL; |
2188 } | 2181 } |
2189 | 2182 |
2190 } // namespace cc | 2183 } // namespace cc |
OLD | NEW |