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

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

Issue 197883017: SkColorType instead of (deprecated) SkBitmap::Config (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 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 | Annotate | Revision Log
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 #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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 surface = skia::AdoptRef( 442 surface = skia::AdoptRef(
443 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); 443 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget()));
444 } 444 }
445 break; 445 break;
446 } 446 }
447 case Bitmap: { 447 case Bitmap: {
448 DCHECK(resource()->pixels); 448 DCHECK(resource()->pixels);
449 DCHECK_EQ(RGBA_8888, resource()->format); 449 DCHECK_EQ(RGBA_8888, resource()->format);
450 SkImageInfo image_info = SkImageInfo::MakeN32Premul( 450 SkImageInfo image_info = SkImageInfo::MakeN32Premul(
451 resource()->size.width(), resource()->size.height()); 451 resource()->size.width(), resource()->size.height());
452 size_t row_bytes = SkBitmap::ComputeRowBytes(SkBitmap::kARGB_8888_Config,
453 resource()->size.width());
454 surface = skia::AdoptRef(SkSurface::NewRasterDirect( 452 surface = skia::AdoptRef(SkSurface::NewRasterDirect(
455 image_info, resource()->pixels, row_bytes)); 453 image_info, resource()->pixels, image_info.minRowBytes()));
456 break; 454 break;
457 } 455 }
458 default: 456 default:
459 NOTREACHED(); 457 NOTREACHED();
460 } 458 }
461 return surface; 459 return surface;
462 } 460 }
463 461
464 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( 462 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer(
465 const Resource* resource, 463 const Resource* resource,
(...skipping 10 matching lines...) Expand all
476 474
477 int stride = 0; 475 int stride = 0;
478 mapped_buffer_ = MapBuffer(&stride); 476 mapped_buffer_ = MapBuffer(&stride);
479 if (!mapped_buffer_) 477 if (!mapped_buffer_)
480 return NULL; 478 return NULL;
481 479
482 switch (resource()->format) { 480 switch (resource()->format) {
483 case RGBA_4444: 481 case RGBA_4444:
484 // Use the default stride if we will eventually convert this 482 // Use the default stride if we will eventually convert this
485 // bitmap to 4444. 483 // bitmap to 4444.
486 raster_bitmap_.setConfig(SkBitmap::kARGB_8888_Config, 484 raster_bitmap_.allocN32Pixels(resource()->size.width(),
487 resource()->size.width(), 485 resource()->size.height());
488 resource()->size.height());
489 raster_bitmap_.allocPixels();
490 break; 486 break;
491 case RGBA_8888: 487 case RGBA_8888:
492 case BGRA_8888: 488 case BGRA_8888: {
493 raster_bitmap_.setConfig(SkBitmap::kARGB_8888_Config, 489 SkImageInfo info = SkImageInfo::MakeN32Premul(resource()->size.width(),
494 resource()->size.width(), 490 resource()->size.height());
495 resource()->size.height(), 491 if (0 == stride)
496 stride); 492 stride = info.minRowBytes();
497 raster_bitmap_.setPixels(mapped_buffer_); 493 raster_bitmap_.installPixels(info, mapped_buffer_, stride);
498 break; 494 break;
495 }
499 case LUMINANCE_8: 496 case LUMINANCE_8:
500 case RGB_565: 497 case RGB_565:
501 case ETC1: 498 case ETC1:
502 NOTREACHED(); 499 NOTREACHED();
503 break; 500 break;
504 } 501 }
505 raster_canvas_ = skia::AdoptRef(new SkCanvas(raster_bitmap_)); 502 raster_canvas_ = skia::AdoptRef(new SkCanvas(raster_bitmap_));
506 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); 503 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID();
507 return raster_canvas_.get(); 504 return raster_canvas_.get();
508 } 505 }
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 texture_uploader_->Upload(image, 923 texture_uploader_->Upload(image,
927 image_rect, 924 image_rect,
928 source_rect, 925 source_rect,
929 dest_offset, 926 dest_offset,
930 resource->format, 927 resource->format,
931 resource->size); 928 resource->size);
932 } else { 929 } else {
933 DCHECK_EQ(Bitmap, resource->type); 930 DCHECK_EQ(Bitmap, resource->type);
934 DCHECK(resource->allocated); 931 DCHECK(resource->allocated);
935 DCHECK_EQ(RGBA_8888, resource->format); 932 DCHECK_EQ(RGBA_8888, resource->format);
936 SkBitmap src_full; 933 DCHECK(source_rect.x() >= image_rect.x());
937 src_full.setConfig( 934 DCHECK(source_rect.y() >= image_rect.y());
938 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); 935 DCHECK(source_rect.width() <= image_rect.width());
danakj 2014/03/25 16:13:59 check right/bottom instead of width/height?
reed1 2014/03/25 17:19:41 good point. what I really want is image_rect.conta
939 src_full.setPixels(const_cast<uint8_t*>(image)); 936 DCHECK(source_rect.height() <= image_rect.height());
940 SkBitmap src_subset; 937 SkImageInfo info =
danakj 2014/03/25 16:13:59 source_info
reed1 2014/03/25 17:19:41 Done.
941 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), 938 SkImageInfo::MakeN32Premul(source_rect.width(), source_rect.height());
942 source_rect.y(), 939 size_t rowBytes = image_rect.width() * 4;
danakj 2014/03/25 16:13:59 image_row_bytes
reed1 2014/03/25 17:19:41 Done.
943 source_rect.width(), 940 int dx = source_rect.x() - image_rect.x();
danakj 2014/03/25 16:13:59 how about: gfx::Vector2d source_offset = source_r
reed1 2014/03/25 17:19:41 Done.
944 source_rect.height()); 941 int dy = source_rect.y() - image_rect.y();
945 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); 942 image += dy * rowBytes + dx * 4;
946 src_full.extractSubset(&src_subset, sk_source_rect);
947 943
948 ScopedWriteLockSoftware lock(this, id); 944 ScopedWriteLockSoftware lock(this, id);
949 SkCanvas* dest = lock.sk_canvas(); 945 SkCanvas* dest = lock.sk_canvas();
950 dest->writePixels(src_subset, dest_offset.x(), dest_offset.y()); 946 dest->writePixels(info, image, rowBytes, dest_offset.x(), dest_offset.y());
951 } 947 }
952 } 948 }
953 949
954 size_t ResourceProvider::NumBlockingUploads() { 950 size_t ResourceProvider::NumBlockingUploads() {
955 if (!texture_uploader_) 951 if (!texture_uploader_)
956 return 0; 952 return 0;
957 953
958 return texture_uploader_->NumBlockingUploads(); 954 return texture_uploader_->NumBlockingUploads();
959 } 955 }
960 956
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 DCHECK(texture_id_); 1164 DCHECK(texture_id_);
1169 } 1165 }
1170 1166
1171 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { 1167 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() {
1172 resource_provider_->UnlockForWrite(resource_id_); 1168 resource_provider_->UnlockForWrite(resource_id_);
1173 } 1169 }
1174 1170
1175 void ResourceProvider::PopulateSkBitmapWithResource( 1171 void ResourceProvider::PopulateSkBitmapWithResource(
1176 SkBitmap* sk_bitmap, const Resource* resource) { 1172 SkBitmap* sk_bitmap, const Resource* resource) {
1177 DCHECK_EQ(RGBA_8888, resource->format); 1173 DCHECK_EQ(RGBA_8888, resource->format);
1178 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, 1174 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(),
1179 resource->size.width(), 1175 resource->size.height());
1180 resource->size.height()); 1176 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes());
1181 sk_bitmap->setPixels(resource->pixels);
1182 } 1177 }
1183 1178
1184 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( 1179 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(
1185 ResourceProvider* resource_provider, 1180 ResourceProvider* resource_provider,
1186 ResourceProvider::ResourceId resource_id) 1181 ResourceProvider::ResourceId resource_id)
1187 : resource_provider_(resource_provider), 1182 : resource_provider_(resource_provider),
1188 resource_id_(resource_id) { 1183 resource_id_(resource_id) {
1189 const Resource* resource = resource_provider->LockForRead(resource_id); 1184 const Resource* resource = resource_provider->LockForRead(resource_id);
1190 wrap_mode_ = resource->wrap_mode; 1185 wrap_mode_ = resource->wrap_mode;
1191 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); 1186 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource);
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
2215 ContextProvider* context_provider = output_surface_->context_provider(); 2210 ContextProvider* context_provider = output_surface_->context_provider();
2216 return context_provider ? context_provider->ContextGL() : NULL; 2211 return context_provider ? context_provider->ContextGL() : NULL;
2217 } 2212 }
2218 2213
2219 class GrContext* ResourceProvider::GrContext() const { 2214 class GrContext* ResourceProvider::GrContext() const {
2220 ContextProvider* context_provider = output_surface_->context_provider(); 2215 ContextProvider* context_provider = output_surface_->context_provider();
2221 return context_provider ? context_provider->GrContext() : NULL; 2216 return context_provider ? context_provider->GrContext() : NULL;
2222 } 2217 }
2223 2218
2224 } // namespace cc 2219 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698