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

Unified Diff: cc/trees/layer_tree_host_impl.cc

Issue 2276633003: 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: uploadscale: fixmath Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_pixeltest_scrollbars.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/layer_tree_host_impl.cc
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index d7d0f4c22d156bb9797bef7a43a6dd004a967c6f..068e0e524e972946d4a022dad78f2ef50a4a522d 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -3761,21 +3761,68 @@ void LayerTreeHostImpl::CreateUIResource(UIResourceId uid,
format = ETC1;
break;
}
+
+ const gfx::Size source_size = bitmap.GetSize();
+ gfx::Size upload_size = bitmap.GetSize();
+ bool scaled = false;
+
+ int max_texture_size = resource_provider_->max_texture_size();
+ if (source_size.width() > max_texture_size ||
+ source_size.height() > max_texture_size) {
+ // Must resize the bitmap to fit within the max texture size.
+ scaled = true;
+ int edge = std::max(source_size.width(), source_size.height());
+ float scale = static_cast<float>(max_texture_size - 1) / edge;
+ DCHECK_LT(scale, 1.f);
+ upload_size = gfx::ScaleToCeiledSize(source_size, scale, scale);
+ }
+
id = resource_provider_->CreateResource(
- bitmap.GetSize(), ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
+ upload_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
gfx::ColorSpace());
+ if (!scaled) {
+ AutoLockUIResourceBitmap bitmap_lock(bitmap);
+ auto* pixels = bitmap_lock.GetPixels();
+ resource_provider_->CopyToResource(id, pixels, source_size);
+ } else {
+ // Only support auto-resizing for N32 textures (since this is primarily for
+ // scrollbars). Users of other types need to ensure they are not too big.
+ DCHECK_EQ(bitmap.GetFormat(), UIResourceBitmap::RGBA8);
+
+ float canvas_scale_x =
+ upload_size.width() / static_cast<float>(source_size.width());
+ float canvas_scale_y =
+ upload_size.height() / static_cast<float>(source_size.height());
+
+ // Uses kPremul_SkAlphaType since that is what SkBitmap's allocN32Pixels
+ // makes, and we only support the RGBA8 format here.
+ SkImageInfo info = SkImageInfo::MakeN32(
+ source_size.width(), source_size.height(), kPremul_SkAlphaType);
+ int row_bytes = source_size.width() * 4;
+
+ AutoLockUIResourceBitmap bitmap_lock(bitmap);
+ SkBitmap source_bitmap;
+ source_bitmap.setInfo(info, row_bytes);
+ source_bitmap.setPixels(const_cast<uint8_t*>(bitmap_lock.GetPixels()));
+
+ // This applies the scale to draw the |bitmap| into |scaled_bitmap|.
+ SkBitmap scaled_bitmap;
+ scaled_bitmap.allocN32Pixels(upload_size.width(), upload_size.height());
+ SkCanvas scaled_canvas(scaled_bitmap);
+ scaled_canvas.scale(canvas_scale_x, canvas_scale_y);
+ scaled_canvas.drawBitmap(source_bitmap, 0, 0);
+
+ SkAutoLockPixels scaled_bitmap_lock(scaled_bitmap);
+ auto* pixels = static_cast<uint8_t*>(scaled_bitmap.getPixels());
+ resource_provider_->CopyToResource(id, pixels, upload_size);
+ }
+
UIResourceData data;
data.resource_id = id;
- data.size = bitmap.GetSize();
data.opaque = bitmap.GetOpaque();
-
ui_resource_map_[uid] = data;
- AutoLockUIResourceBitmap bitmap_lock(bitmap);
- resource_provider_->CopyToResource(id, bitmap_lock.GetPixels(),
- bitmap.GetSize());
-
resource_provider_->GenerateSyncTokenForResource(id);
MarkUIResourceNotEvicted(uid);
}
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_pixeltest_scrollbars.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698