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

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

Issue 2280663002: Reland of Move scaling of ui resources for scrollbars to the time of upload (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scrollbarpixeltests
Patch Set: Created 4 years, 3 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/trees/layer_tree_host_impl.h ('k') | no next file » | 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 3743 matching lines...) Expand 10 before | Expand all | Expand 10 after
3754 switch (bitmap.GetFormat()) { 3754 switch (bitmap.GetFormat()) {
3755 case UIResourceBitmap::RGBA8: 3755 case UIResourceBitmap::RGBA8:
3756 break; 3756 break;
3757 case UIResourceBitmap::ALPHA_8: 3757 case UIResourceBitmap::ALPHA_8:
3758 format = ALPHA_8; 3758 format = ALPHA_8;
3759 break; 3759 break;
3760 case UIResourceBitmap::ETC1: 3760 case UIResourceBitmap::ETC1:
3761 format = ETC1; 3761 format = ETC1;
3762 break; 3762 break;
3763 } 3763 }
3764
3765 const gfx::Size source_size = bitmap.GetSize();
3766 gfx::Size upload_size = bitmap.GetSize();
3767 bool scaled = false;
3768
3769 int max_texture_size = resource_provider_->max_texture_size();
3770 if (source_size.width() > max_texture_size ||
3771 source_size.height() > max_texture_size) {
3772 // Must resize the bitmap to fit within the max texture size.
3773 scaled = true;
3774 int edge = std::max(source_size.width(), source_size.height());
3775 float scale = nextafterf(static_cast<float>(max_texture_size) / edge, 0);
3776 DCHECK_LT(scale, 1.f);
3777 upload_size = gfx::ScaleToFlooredSize(source_size, scale, scale);
3778 }
3779
3764 id = resource_provider_->CreateResource( 3780 id = resource_provider_->CreateResource(
3765 bitmap.GetSize(), ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, 3781 upload_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
3766 gfx::ColorSpace()); 3782 gfx::ColorSpace());
3767 3783
3784 if (!scaled) {
3785 AutoLockUIResourceBitmap bitmap_lock(bitmap);
3786 auto* pixels = bitmap_lock.GetPixels();
3787 resource_provider_->CopyToResource(id, pixels, source_size);
3788 } else {
3789 // Only support auto-resizing for N32 textures (since this is primarily for
3790 // scrollbars). Users of other types need to ensure they are not too big.
3791 DCHECK_EQ(bitmap.GetFormat(), UIResourceBitmap::RGBA8);
3792
3793 float canvas_scale_x =
3794 upload_size.width() / static_cast<float>(source_size.width());
3795 float canvas_scale_y =
3796 upload_size.height() / static_cast<float>(source_size.height());
3797
3798 // Uses kPremul_SkAlphaType since that is what SkBitmap's allocN32Pixels
3799 // makes, and we only support the RGBA8 format here.
3800 SkImageInfo info = SkImageInfo::MakeN32(
3801 source_size.width(), source_size.height(), kPremul_SkAlphaType);
3802 int row_bytes = source_size.width() * 4;
3803
3804 AutoLockUIResourceBitmap bitmap_lock(bitmap);
3805 SkBitmap source_bitmap;
3806 source_bitmap.setInfo(info, row_bytes);
3807 source_bitmap.setPixels(const_cast<uint8_t*>(bitmap_lock.GetPixels()));
3808
3809 // This applies the scale to draw the |bitmap| into |scaled_bitmap|.
3810 SkBitmap scaled_bitmap;
3811 scaled_bitmap.allocN32Pixels(upload_size.width(), upload_size.height());
3812 SkCanvas scaled_canvas(scaled_bitmap);
3813 scaled_canvas.scale(canvas_scale_x, canvas_scale_y);
3814 scaled_canvas.drawBitmap(source_bitmap, 0, 0);
3815
3816 SkAutoLockPixels scaled_bitmap_lock(scaled_bitmap);
3817 auto* pixels = static_cast<uint8_t*>(scaled_bitmap.getPixels());
3818 resource_provider_->CopyToResource(id, pixels, upload_size);
3819 }
3820
3768 UIResourceData data; 3821 UIResourceData data;
3769 data.resource_id = id; 3822 data.resource_id = id;
3770 data.size = bitmap.GetSize();
3771 data.opaque = bitmap.GetOpaque(); 3823 data.opaque = bitmap.GetOpaque();
3772
3773 ui_resource_map_[uid] = data; 3824 ui_resource_map_[uid] = data;
3774 3825
3775 AutoLockUIResourceBitmap bitmap_lock(bitmap);
3776 resource_provider_->CopyToResource(id, bitmap_lock.GetPixels(),
3777 bitmap.GetSize());
3778
3779 resource_provider_->GenerateSyncTokenForResource(id); 3826 resource_provider_->GenerateSyncTokenForResource(id);
3780 MarkUIResourceNotEvicted(uid); 3827 MarkUIResourceNotEvicted(uid);
3781 } 3828 }
3782 3829
3783 void LayerTreeHostImpl::DeleteUIResource(UIResourceId uid) { 3830 void LayerTreeHostImpl::DeleteUIResource(UIResourceId uid) {
3784 ResourceId id = ResourceIdForUIResource(uid); 3831 ResourceId id = ResourceIdForUIResource(uid);
3785 if (id) { 3832 if (id) {
3786 resource_provider_->DeleteResource(id); 3833 resource_provider_->DeleteResource(id);
3787 ui_resource_map_.erase(uid); 3834 ui_resource_map_.erase(uid);
3788 } 3835 }
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
4112 return task_runner_provider_->HasImplThread(); 4159 return task_runner_provider_->HasImplThread();
4113 } 4160 }
4114 4161
4115 bool LayerTreeHostImpl::CommitToActiveTree() const { 4162 bool LayerTreeHostImpl::CommitToActiveTree() const {
4116 // In single threaded mode we skip the pending tree and commit directly to the 4163 // In single threaded mode we skip the pending tree and commit directly to the
4117 // active tree. 4164 // active tree.
4118 return !task_runner_provider_->HasImplThread(); 4165 return !task_runner_provider_->HasImplThread();
4119 } 4166 }
4120 4167
4121 } // namespace cc 4168 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698