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

Side by Side Diff: cc/trees/layer_tree_host_impl.cc

Issue 2823003002: SkBitmap and SkPixelRef no longer need lock/unlock (Closed)
Patch Set: win fix after rebase Created 3 years, 8 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
« no previous file with comments | « cc/test/pixel_comparator.cc ('k') | chrome/browser/android/thumbnail/thumbnail_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/trees/layer_tree_host_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 3870 matching lines...) Expand 10 before | Expand all | Expand 10 after
3881 float scale = static_cast<float>(max_texture_size - 1) / edge; 3881 float scale = static_cast<float>(max_texture_size - 1) / edge;
3882 DCHECK_LT(scale, 1.f); 3882 DCHECK_LT(scale, 1.f);
3883 upload_size = gfx::ScaleToCeiledSize(source_size, scale, scale); 3883 upload_size = gfx::ScaleToCeiledSize(source_size, scale, scale);
3884 } 3884 }
3885 3885
3886 id = resource_provider_->CreateResource( 3886 id = resource_provider_->CreateResource(
3887 upload_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, 3887 upload_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
3888 gfx::ColorSpace::CreateSRGB()); 3888 gfx::ColorSpace::CreateSRGB());
3889 3889
3890 if (!scaled) { 3890 if (!scaled) {
3891 AutoLockUIResourceBitmap bitmap_lock(bitmap); 3891 resource_provider_->CopyToResource(id, bitmap.GetPixels(), source_size);
3892 auto* pixels = bitmap_lock.GetPixels();
3893 resource_provider_->CopyToResource(id, pixels, source_size);
3894 } else { 3892 } else {
3895 // Only support auto-resizing for N32 textures (since this is primarily for 3893 // Only support auto-resizing for N32 textures (since this is primarily for
3896 // scrollbars). Users of other types need to ensure they are not too big. 3894 // scrollbars). Users of other types need to ensure they are not too big.
3897 DCHECK_EQ(bitmap.GetFormat(), UIResourceBitmap::RGBA8); 3895 DCHECK_EQ(bitmap.GetFormat(), UIResourceBitmap::RGBA8);
3898 3896
3899 float canvas_scale_x = 3897 float canvas_scale_x =
3900 upload_size.width() / static_cast<float>(source_size.width()); 3898 upload_size.width() / static_cast<float>(source_size.width());
3901 float canvas_scale_y = 3899 float canvas_scale_y =
3902 upload_size.height() / static_cast<float>(source_size.height()); 3900 upload_size.height() / static_cast<float>(source_size.height());
3903 3901
3904 // Uses kPremul_SkAlphaType since that is what SkBitmap's allocN32Pixels 3902 // Uses kPremul_SkAlphaType since that is what SkBitmap's allocN32Pixels
3905 // makes, and we only support the RGBA8 format here. 3903 // makes, and we only support the RGBA8 format here.
3906 SkImageInfo info = SkImageInfo::MakeN32( 3904 SkImageInfo info = SkImageInfo::MakeN32(
3907 source_size.width(), source_size.height(), kPremul_SkAlphaType); 3905 source_size.width(), source_size.height(), kPremul_SkAlphaType);
3908 int row_bytes = source_size.width() * 4; 3906 int row_bytes = source_size.width() * 4;
3909 3907
3910 AutoLockUIResourceBitmap bitmap_lock(bitmap);
3911 SkBitmap source_bitmap; 3908 SkBitmap source_bitmap;
3912 source_bitmap.setInfo(info, row_bytes); 3909 source_bitmap.setInfo(info, row_bytes);
3913 source_bitmap.setPixels(const_cast<uint8_t*>(bitmap_lock.GetPixels())); 3910 source_bitmap.setPixels(const_cast<uint8_t*>(bitmap.GetPixels()));
3914 3911
3915 // This applies the scale to draw the |bitmap| into |scaled_bitmap|. 3912 // This applies the scale to draw the |bitmap| into |scaled_bitmap|.
3916 SkBitmap scaled_bitmap; 3913 SkBitmap scaled_bitmap;
3917 scaled_bitmap.allocN32Pixels(upload_size.width(), upload_size.height()); 3914 scaled_bitmap.allocN32Pixels(upload_size.width(), upload_size.height());
3918 SkCanvas scaled_canvas(scaled_bitmap); 3915 SkCanvas scaled_canvas(scaled_bitmap);
3919 scaled_canvas.scale(canvas_scale_x, canvas_scale_y); 3916 scaled_canvas.scale(canvas_scale_x, canvas_scale_y);
3920 // The |canvas_scale_x| and |canvas_scale_y| may have some floating point 3917 // The |canvas_scale_x| and |canvas_scale_y| may have some floating point
3921 // error for large enough values, causing pixels on the edge to be not 3918 // error for large enough values, causing pixels on the edge to be not
3922 // fully filled by drawBitmap(), so we ensure they start empty. (See 3919 // fully filled by drawBitmap(), so we ensure they start empty. (See
3923 // crbug.com/642011 for an example.) 3920 // crbug.com/642011 for an example.)
3924 scaled_canvas.clear(SK_ColorTRANSPARENT); 3921 scaled_canvas.clear(SK_ColorTRANSPARENT);
3925 scaled_canvas.drawBitmap(source_bitmap, 0, 0); 3922 scaled_canvas.drawBitmap(source_bitmap, 0, 0);
3926 3923
3927 SkAutoLockPixels scaled_bitmap_lock(scaled_bitmap);
3928 auto* pixels = static_cast<uint8_t*>(scaled_bitmap.getPixels()); 3924 auto* pixels = static_cast<uint8_t*>(scaled_bitmap.getPixels());
3929 resource_provider_->CopyToResource(id, pixels, upload_size); 3925 resource_provider_->CopyToResource(id, pixels, upload_size);
3930 } 3926 }
3931 3927
3932 UIResourceData data; 3928 UIResourceData data;
3933 data.resource_id = id; 3929 data.resource_id = id;
3934 data.opaque = bitmap.GetOpaque(); 3930 data.opaque = bitmap.GetOpaque();
3935 ui_resource_map_[uid] = data; 3931 ui_resource_map_[uid] = data;
3936 3932
3937 resource_provider_->GenerateSyncTokenForResource(id); 3933 resource_provider_->GenerateSyncTokenForResource(id);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
4286 } 4282 }
4287 4283
4288 void LayerTreeHostImpl::UpdateScrollSourceInfo(bool is_wheel_scroll) { 4284 void LayerTreeHostImpl::UpdateScrollSourceInfo(bool is_wheel_scroll) {
4289 if (is_wheel_scroll) 4285 if (is_wheel_scroll)
4290 has_scrolled_by_wheel_ = true; 4286 has_scrolled_by_wheel_ = true;
4291 else 4287 else
4292 has_scrolled_by_touch_ = true; 4288 has_scrolled_by_touch_ = true;
4293 } 4289 }
4294 4290
4295 } // namespace cc 4291 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/pixel_comparator.cc ('k') | chrome/browser/android/thumbnail/thumbnail_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698