OLD | NEW |
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 3883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3894 float scale = static_cast<float>(max_texture_size - 1) / edge; | 3894 float scale = static_cast<float>(max_texture_size - 1) / edge; |
3895 DCHECK_LT(scale, 1.f); | 3895 DCHECK_LT(scale, 1.f); |
3896 upload_size = gfx::ScaleToCeiledSize(source_size, scale, scale); | 3896 upload_size = gfx::ScaleToCeiledSize(source_size, scale, scale); |
3897 } | 3897 } |
3898 | 3898 |
3899 id = resource_provider_->CreateResource( | 3899 id = resource_provider_->CreateResource( |
3900 upload_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, | 3900 upload_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, |
3901 gfx::ColorSpace::CreateSRGB()); | 3901 gfx::ColorSpace::CreateSRGB()); |
3902 | 3902 |
3903 if (!scaled) { | 3903 if (!scaled) { |
3904 AutoLockUIResourceBitmap bitmap_lock(bitmap); | 3904 resource_provider_->CopyToResource(id, bitmap.GetPixels(), source_size); |
3905 auto* pixels = bitmap_lock.GetPixels(); | |
3906 resource_provider_->CopyToResource(id, pixels, source_size); | |
3907 } else { | 3905 } else { |
3908 // Only support auto-resizing for N32 textures (since this is primarily for | 3906 // Only support auto-resizing for N32 textures (since this is primarily for |
3909 // scrollbars). Users of other types need to ensure they are not too big. | 3907 // scrollbars). Users of other types need to ensure they are not too big. |
3910 DCHECK_EQ(bitmap.GetFormat(), UIResourceBitmap::RGBA8); | 3908 DCHECK_EQ(bitmap.GetFormat(), UIResourceBitmap::RGBA8); |
3911 | 3909 |
3912 float canvas_scale_x = | 3910 float canvas_scale_x = |
3913 upload_size.width() / static_cast<float>(source_size.width()); | 3911 upload_size.width() / static_cast<float>(source_size.width()); |
3914 float canvas_scale_y = | 3912 float canvas_scale_y = |
3915 upload_size.height() / static_cast<float>(source_size.height()); | 3913 upload_size.height() / static_cast<float>(source_size.height()); |
3916 | 3914 |
3917 // Uses kPremul_SkAlphaType since that is what SkBitmap's allocN32Pixels | 3915 // Uses kPremul_SkAlphaType since that is what SkBitmap's allocN32Pixels |
3918 // makes, and we only support the RGBA8 format here. | 3916 // makes, and we only support the RGBA8 format here. |
3919 SkImageInfo info = SkImageInfo::MakeN32( | 3917 SkImageInfo info = SkImageInfo::MakeN32( |
3920 source_size.width(), source_size.height(), kPremul_SkAlphaType); | 3918 source_size.width(), source_size.height(), kPremul_SkAlphaType); |
3921 int row_bytes = source_size.width() * 4; | 3919 int row_bytes = source_size.width() * 4; |
3922 | 3920 |
3923 AutoLockUIResourceBitmap bitmap_lock(bitmap); | |
3924 SkBitmap source_bitmap; | 3921 SkBitmap source_bitmap; |
3925 source_bitmap.setInfo(info, row_bytes); | 3922 source_bitmap.setInfo(info, row_bytes); |
3926 source_bitmap.setPixels(const_cast<uint8_t*>(bitmap_lock.GetPixels())); | 3923 source_bitmap.setPixels(const_cast<uint8_t*>(bitmap.GetPixels())); |
3927 | 3924 |
3928 // This applies the scale to draw the |bitmap| into |scaled_bitmap|. | 3925 // This applies the scale to draw the |bitmap| into |scaled_bitmap|. |
3929 SkBitmap scaled_bitmap; | 3926 SkBitmap scaled_bitmap; |
3930 scaled_bitmap.allocN32Pixels(upload_size.width(), upload_size.height()); | 3927 scaled_bitmap.allocN32Pixels(upload_size.width(), upload_size.height()); |
3931 SkCanvas scaled_canvas(scaled_bitmap); | 3928 SkCanvas scaled_canvas(scaled_bitmap); |
3932 scaled_canvas.scale(canvas_scale_x, canvas_scale_y); | 3929 scaled_canvas.scale(canvas_scale_x, canvas_scale_y); |
3933 // The |canvas_scale_x| and |canvas_scale_y| may have some floating point | 3930 // The |canvas_scale_x| and |canvas_scale_y| may have some floating point |
3934 // error for large enough values, causing pixels on the edge to be not | 3931 // error for large enough values, causing pixels on the edge to be not |
3935 // fully filled by drawBitmap(), so we ensure they start empty. (See | 3932 // fully filled by drawBitmap(), so we ensure they start empty. (See |
3936 // crbug.com/642011 for an example.) | 3933 // crbug.com/642011 for an example.) |
3937 scaled_canvas.clear(SK_ColorTRANSPARENT); | 3934 scaled_canvas.clear(SK_ColorTRANSPARENT); |
3938 scaled_canvas.drawBitmap(source_bitmap, 0, 0); | 3935 scaled_canvas.drawBitmap(source_bitmap, 0, 0); |
3939 | 3936 |
3940 SkAutoLockPixels scaled_bitmap_lock(scaled_bitmap); | |
3941 auto* pixels = static_cast<uint8_t*>(scaled_bitmap.getPixels()); | 3937 auto* pixels = static_cast<uint8_t*>(scaled_bitmap.getPixels()); |
3942 resource_provider_->CopyToResource(id, pixels, upload_size); | 3938 resource_provider_->CopyToResource(id, pixels, upload_size); |
3943 } | 3939 } |
3944 | 3940 |
3945 UIResourceData data; | 3941 UIResourceData data; |
3946 data.resource_id = id; | 3942 data.resource_id = id; |
3947 data.opaque = bitmap.GetOpaque(); | 3943 data.opaque = bitmap.GetOpaque(); |
3948 ui_resource_map_[uid] = data; | 3944 ui_resource_map_[uid] = data; |
3949 | 3945 |
3950 resource_provider_->GenerateSyncTokenForResource(id); | 3946 resource_provider_->GenerateSyncTokenForResource(id); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4299 } | 4295 } |
4300 | 4296 |
4301 void LayerTreeHostImpl::UpdateScrollSourceInfo(bool is_wheel_scroll) { | 4297 void LayerTreeHostImpl::UpdateScrollSourceInfo(bool is_wheel_scroll) { |
4302 if (is_wheel_scroll) | 4298 if (is_wheel_scroll) |
4303 has_scrolled_by_wheel_ = true; | 4299 has_scrolled_by_wheel_ = true; |
4304 else | 4300 else |
4305 has_scrolled_by_touch_ = true; | 4301 has_scrolled_by_touch_ = true; |
4306 } | 4302 } |
4307 | 4303 |
4308 } // namespace cc | 4304 } // namespace cc |
OLD | NEW |