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

Unified Diff: ui/gfx/image/image_skia.cc

Issue 2902153002: arc: Support non-standard display scale factors. (Closed)
Patch Set: rebase + unit test update to match this CL Created 3 years, 7 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 | « ui/gfx/image/image_skia.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image_skia.cc
diff --git a/ui/gfx/image/image_skia.cc b/ui/gfx/image/image_skia.cc
index 20349b4baf14c71cd7fd7200697b559abc4fcf84..981c585f6eb926fa223dd33a71b71f6ea140d4da 100644
--- a/ui/gfx/image/image_skia.cc
+++ b/ui/gfx/image/image_skia.cc
@@ -41,6 +41,17 @@ std::vector<float>* g_supported_scales = NULL;
// the image to 1.25.
const float kFallbackToSmallerScaleDiff = 0.20f;
+// Maps to the closest supported scale. Returns an exact match, a smaller
+// scale within 0.2 units, the nearest larger scale, or the min/max
+// supported scale.
+float MapToSupportedScale(float scale) {
+ for (float supported_scale : *g_supported_scales) {
+ if (supported_scale + kFallbackToSmallerScaleDiff >= scale)
+ return supported_scale;
+ }
+ return g_supported_scales->back();
+}
+
} // namespace
namespace internal {
@@ -219,18 +230,8 @@ std::vector<ImageSkiaRep>::iterator ImageSkiaStorage::FindRepresentation(
ImageSkiaRep image;
float resource_scale = scale;
- if (!HasRepresentationAtAllScales() && g_supported_scales) {
- if (g_supported_scales->back() <= scale) {
- resource_scale = g_supported_scales->back();
- } else {
- for (size_t i = 0; i < g_supported_scales->size(); ++i) {
- if ((*g_supported_scales)[i] + kFallbackToSmallerScaleDiff >= scale) {
- resource_scale = (*g_supported_scales)[i];
- break;
- }
- }
- }
- }
+ if (!HasRepresentationAtAllScales() && g_supported_scales)
+ resource_scale = MapToSupportedScale(scale);
if (scale != resource_scale) {
std::vector<ImageSkiaRep>::iterator iter =
FindRepresentation(resource_scale, fetch_new_image);
@@ -481,6 +482,14 @@ void ImageSkia::EnsureRepsForSupportedScales() const {
}
}
+void ImageSkia::RemoveUnsupportedRepresentationsForScale(float scale) {
+ for (const ImageSkiaRep& image_rep_to_test : image_reps()) {
+ const float test_scale = image_rep_to_test.scale();
+ if (test_scale != scale && MapToSupportedScale(test_scale) == scale)
+ RemoveRepresentation(test_scale);
+ }
+}
+
void ImageSkia::Init(const ImageSkiaRep& image_rep) {
// TODO(pkotwicz): The image should be null whenever image rep is null.
if (image_rep.sk_bitmap().empty()) {
« no previous file with comments | « ui/gfx/image/image_skia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698