OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/base/resource/resource_bundle.h" | 5 #include "ui/base/resource/resource_bundle.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // ResourceBundle on demand for a given |resource_id|. If the bitmap for the | 117 // ResourceBundle on demand for a given |resource_id|. If the bitmap for the |
118 // requested scale factor does not exist, it will return the 1x bitmap scaled | 118 // requested scale factor does not exist, it will return the 1x bitmap scaled |
119 // by the scale factor. This may lead to broken UI if the correct size of the | 119 // by the scale factor. This may lead to broken UI if the correct size of the |
120 // scaled image is not exactly |scale_factor| * the size of the 1x resource. | 120 // scaled image is not exactly |scale_factor| * the size of the 1x resource. |
121 // When --highlight-missing-scaled-resources flag is specified, scaled 1x images | 121 // When --highlight-missing-scaled-resources flag is specified, scaled 1x images |
122 // are higlighted by blending them with red. | 122 // are higlighted by blending them with red. |
123 class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { | 123 class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { |
124 public: | 124 public: |
125 ResourceBundleImageSource(ResourceBundle* rb, int resource_id) | 125 ResourceBundleImageSource(ResourceBundle* rb, int resource_id) |
126 : rb_(rb), resource_id_(resource_id) {} | 126 : rb_(rb), resource_id_(resource_id) {} |
127 virtual ~ResourceBundleImageSource() {} | 127 ~ResourceBundleImageSource() override {} |
128 | 128 |
129 // gfx::ImageSkiaSource overrides: | 129 // gfx::ImageSkiaSource overrides: |
130 virtual gfx::ImageSkiaRep GetImageForScale(float scale) override { | 130 gfx::ImageSkiaRep GetImageForScale(float scale) override { |
131 SkBitmap image; | 131 SkBitmap image; |
132 bool fell_back_to_1x = false; | 132 bool fell_back_to_1x = false; |
133 ScaleFactor scale_factor = GetSupportedScaleFactor(scale); | 133 ScaleFactor scale_factor = GetSupportedScaleFactor(scale); |
134 bool found = rb_->LoadBitmap(resource_id_, &scale_factor, | 134 bool found = rb_->LoadBitmap(resource_id_, &scale_factor, |
135 &image, &fell_back_to_1x); | 135 &image, &fell_back_to_1x); |
136 if (!found) | 136 if (!found) |
137 return gfx::ImageSkiaRep(); | 137 return gfx::ImageSkiaRep(); |
138 | 138 |
139 // If the resource is in the package with SCALE_FACTOR_NONE, it | 139 // If the resource is in the package with SCALE_FACTOR_NONE, it |
140 // can be used in any scale factor. The image is maked as "unscaled" | 140 // can be used in any scale factor. The image is maked as "unscaled" |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 // static | 859 // static |
860 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 860 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
861 size_t size, | 861 size_t size, |
862 SkBitmap* bitmap, | 862 SkBitmap* bitmap, |
863 bool* fell_back_to_1x) { | 863 bool* fell_back_to_1x) { |
864 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 864 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
865 return gfx::PNGCodec::Decode(buf, size, bitmap); | 865 return gfx::PNGCodec::Decode(buf, size, bitmap); |
866 } | 866 } |
867 | 867 |
868 } // namespace ui | 868 } // namespace ui |
OLD | NEW |