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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 surface = skia::AdoptRef( | 441 surface = skia::AdoptRef( |
442 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); | 442 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); |
443 } | 443 } |
444 break; | 444 break; |
445 } | 445 } |
446 case Bitmap: { | 446 case Bitmap: { |
447 DCHECK(resource()->pixels); | 447 DCHECK(resource()->pixels); |
448 DCHECK_EQ(RGBA_8888, resource()->format); | 448 DCHECK_EQ(RGBA_8888, resource()->format); |
449 SkImageInfo image_info = SkImageInfo::MakeN32Premul( | 449 SkImageInfo image_info = SkImageInfo::MakeN32Premul( |
450 resource()->size.width(), resource()->size.height()); | 450 resource()->size.width(), resource()->size.height()); |
451 size_t row_bytes = SkBitmap::ComputeRowBytes(SkBitmap::kARGB_8888_Config, | |
452 resource()->size.width()); | |
453 surface = skia::AdoptRef(SkSurface::NewRasterDirect( | 451 surface = skia::AdoptRef(SkSurface::NewRasterDirect( |
454 image_info, resource()->pixels, row_bytes)); | 452 image_info, resource()->pixels, image_info.minRowBytes())); |
455 break; | 453 break; |
456 } | 454 } |
457 default: | 455 default: |
458 NOTREACHED(); | 456 NOTREACHED(); |
459 } | 457 } |
460 return surface; | 458 return surface; |
461 } | 459 } |
462 | 460 |
463 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( | 461 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( |
464 const Resource* resource, | 462 const Resource* resource, |
(...skipping 10 matching lines...) Expand all Loading... | |
475 | 473 |
476 int stride = 0; | 474 int stride = 0; |
477 mapped_buffer_ = MapBuffer(&stride); | 475 mapped_buffer_ = MapBuffer(&stride); |
478 if (!mapped_buffer_) | 476 if (!mapped_buffer_) |
479 return NULL; | 477 return NULL; |
480 | 478 |
481 switch (resource()->format) { | 479 switch (resource()->format) { |
482 case RGBA_4444: | 480 case RGBA_4444: |
483 // Use the default stride if we will eventually convert this | 481 // Use the default stride if we will eventually convert this |
484 // bitmap to 4444. | 482 // bitmap to 4444. |
485 raster_bitmap_.setConfig(SkBitmap::kARGB_8888_Config, | 483 raster_bitmap_.allocN32Pixels(resource()->size.width(), |
486 resource()->size.width(), | 484 resource()->size.height()); |
487 resource()->size.height()); | |
488 raster_bitmap_.allocPixels(); | |
489 break; | 485 break; |
490 case RGBA_8888: | 486 case RGBA_8888: |
491 case BGRA_8888: | 487 case BGRA_8888: { |
492 raster_bitmap_.setConfig(SkBitmap::kARGB_8888_Config, | 488 SkImageInfo info = SkImageInfo::MakeN32Premul(resource()->size.width(), |
493 resource()->size.width(), | 489 resource()->size.height()); |
494 resource()->size.height(), | 490 raster_bitmap_.installPixels(info, mapped_buffer_, stride); |
495 stride); | |
496 raster_bitmap_.setPixels(mapped_buffer_); | |
497 break; | 491 break; |
492 } | |
498 case LUMINANCE_8: | 493 case LUMINANCE_8: |
499 case RGB_565: | 494 case RGB_565: |
500 case ETC1: | 495 case ETC1: |
501 NOTREACHED(); | 496 NOTREACHED(); |
502 break; | 497 break; |
503 } | 498 } |
504 raster_canvas_ = skia::AdoptRef(new SkCanvas(raster_bitmap_)); | 499 raster_canvas_ = skia::AdoptRef(new SkCanvas(raster_bitmap_)); |
505 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); | 500 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); |
506 return raster_canvas_.get(); | 501 return raster_canvas_.get(); |
507 } | 502 } |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
919 texture_uploader_->Upload(image, | 914 texture_uploader_->Upload(image, |
920 image_rect, | 915 image_rect, |
921 source_rect, | 916 source_rect, |
922 dest_offset, | 917 dest_offset, |
923 resource->format, | 918 resource->format, |
924 resource->size); | 919 resource->size); |
925 } else { | 920 } else { |
926 DCHECK_EQ(Bitmap, resource->type); | 921 DCHECK_EQ(Bitmap, resource->type); |
927 DCHECK(resource->allocated); | 922 DCHECK(resource->allocated); |
928 DCHECK_EQ(RGBA_8888, resource->format); | 923 DCHECK_EQ(RGBA_8888, resource->format); |
929 SkBitmap src_full; | 924 DCHECK(source_rect.x() >= image_rect.x()); |
930 src_full.setConfig( | 925 DCHECK(source_rect.y() >= image_rect.y()); |
931 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); | 926 DCHECK(source_rect.width() <= image_rect.width()); |
932 src_full.setPixels(const_cast<uint8_t*>(image)); | 927 DCHECK(source_rect.height() <= image_rect.height()); |
933 SkBitmap src_subset; | 928 SkImageInfo info = |
934 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), | 929 SkImageInfo::MakeN32Premul(source_rect.width(), source_rect.height()); |
935 source_rect.y(), | 930 size_t rowBytes = image_rect.width() * 4; |
936 source_rect.width(), | 931 int dx = source_rect.x() - image_rect.x(); |
937 source_rect.height()); | 932 int dy = source_rect.y() - image_rect.y(); |
938 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); | 933 image += dy * rowBytes + dx * 4; |
Stephen White
2014/03/18 20:14:07
IWBN if we could still put the full image in an Sk
reed1
2014/03/21 20:49:01
Doesn't work against it per-se, but given that thi
| |
939 src_full.extractSubset(&src_subset, sk_source_rect); | |
940 | 934 |
941 ScopedWriteLockSoftware lock(this, id); | 935 ScopedWriteLockSoftware lock(this, id); |
942 SkCanvas* dest = lock.sk_canvas(); | 936 SkCanvas* dest = lock.sk_canvas(); |
943 dest->writePixels(src_subset, dest_offset.x(), dest_offset.y()); | 937 dest->writePixels(info, image, rowBytes, dest_offset.x(), dest_offset.y()); |
944 } | 938 } |
945 } | 939 } |
946 | 940 |
947 size_t ResourceProvider::NumBlockingUploads() { | 941 size_t ResourceProvider::NumBlockingUploads() { |
948 if (!texture_uploader_) | 942 if (!texture_uploader_) |
949 return 0; | 943 return 0; |
950 | 944 |
951 return texture_uploader_->NumBlockingUploads(); | 945 return texture_uploader_->NumBlockingUploads(); |
952 } | 946 } |
953 | 947 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1161 DCHECK(texture_id_); | 1155 DCHECK(texture_id_); |
1162 } | 1156 } |
1163 | 1157 |
1164 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 1158 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
1165 resource_provider_->UnlockForWrite(resource_id_); | 1159 resource_provider_->UnlockForWrite(resource_id_); |
1166 } | 1160 } |
1167 | 1161 |
1168 void ResourceProvider::PopulateSkBitmapWithResource( | 1162 void ResourceProvider::PopulateSkBitmapWithResource( |
1169 SkBitmap* sk_bitmap, const Resource* resource) { | 1163 SkBitmap* sk_bitmap, const Resource* resource) { |
1170 DCHECK_EQ(RGBA_8888, resource->format); | 1164 DCHECK_EQ(RGBA_8888, resource->format); |
1171 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 1165 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), |
1172 resource->size.width(), | 1166 resource->size.height()); |
1173 resource->size.height()); | 1167 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); |
1174 sk_bitmap->setPixels(resource->pixels); | |
1175 } | 1168 } |
1176 | 1169 |
1177 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 1170 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
1178 ResourceProvider* resource_provider, | 1171 ResourceProvider* resource_provider, |
1179 ResourceProvider::ResourceId resource_id) | 1172 ResourceProvider::ResourceId resource_id) |
1180 : resource_provider_(resource_provider), | 1173 : resource_provider_(resource_provider), |
1181 resource_id_(resource_id) { | 1174 resource_id_(resource_id) { |
1182 const Resource* resource = resource_provider->LockForRead(resource_id); | 1175 const Resource* resource = resource_provider->LockForRead(resource_id); |
1183 wrap_mode_ = resource->wrap_mode; | 1176 wrap_mode_ = resource->wrap_mode; |
1184 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); | 1177 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2208 ContextProvider* context_provider = output_surface_->context_provider(); | 2201 ContextProvider* context_provider = output_surface_->context_provider(); |
2209 return context_provider ? context_provider->ContextGL() : NULL; | 2202 return context_provider ? context_provider->ContextGL() : NULL; |
2210 } | 2203 } |
2211 | 2204 |
2212 class GrContext* ResourceProvider::GrContext() const { | 2205 class GrContext* ResourceProvider::GrContext() const { |
2213 ContextProvider* context_provider = output_surface_->context_provider(); | 2206 ContextProvider* context_provider = output_surface_->context_provider(); |
2214 return context_provider ? context_provider->GrContext() : NULL; | 2207 return context_provider ? context_provider->GrContext() : NULL; |
2215 } | 2208 } |
2216 | 2209 |
2217 } // namespace cc | 2210 } // namespace cc |
OLD | NEW |