| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/android/resources/resource_manager.h" | |
| 6 | |
| 7 #include "base/trace_event/memory_usage_estimator.h" | |
| 8 #include "ui/gfx/geometry/insets_f.h" | |
| 9 | |
| 10 namespace ui { | |
| 11 | |
| 12 ResourceManager::Resource::Resource() { | |
| 13 } | |
| 14 | |
| 15 ResourceManager::Resource::~Resource() { | |
| 16 } | |
| 17 | |
| 18 gfx::Rect ResourceManager::Resource::Border(const gfx::Size& bounds) const { | |
| 19 return Border(bounds, gfx::InsetsF(1.f, 1.f, 1.f, 1.f)); | |
| 20 } | |
| 21 | |
| 22 gfx::Rect ResourceManager::Resource::Border(const gfx::Size& bounds, | |
| 23 const gfx::InsetsF& scale) const { | |
| 24 // Calculate whether or not we need to scale down the border if the bounds of | |
| 25 // the layer are going to be smaller than the aperture padding. | |
| 26 float x_scale = std::min((float)bounds.width() / size.width(), 1.f); | |
| 27 float y_scale = std::min((float)bounds.height() / size.height(), 1.f); | |
| 28 | |
| 29 float left_scale = std::min(x_scale * scale.left(), 1.f); | |
| 30 float right_scale = std::min(x_scale * scale.right(), 1.f); | |
| 31 float top_scale = std::min(y_scale * scale.top(), 1.f); | |
| 32 float bottom_scale = std::min(y_scale * scale.bottom(), 1.f); | |
| 33 | |
| 34 return gfx::Rect(aperture.x() * left_scale, aperture.y() * top_scale, | |
| 35 (size.width() - aperture.width()) * right_scale, | |
| 36 (size.height() - aperture.height()) * bottom_scale); | |
| 37 } | |
| 38 | |
| 39 size_t ResourceManager::Resource::EstimateMemoryUsage() const { | |
| 40 return base::trace_event::EstimateMemoryUsage(ui_resource); | |
| 41 } | |
| 42 | |
| 43 } // namespace ui | |
| OLD | NEW |