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

Side by Side Diff: ui/base/resource/resource_bundle.h

Issue 1968993002: Compressing .pak resources with new option: "type=GZIPPABLE_BINDATA" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating comments Created 4 years, 6 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 unified diff | Download patch
OLDNEW
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 #ifndef UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ 5 #ifndef UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_
6 #define UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ 6 #define UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // such as theme graphics. Every resource is loaded only once. 43 // such as theme graphics. Every resource is loaded only once.
44 class UI_BASE_EXPORT ResourceBundle { 44 class UI_BASE_EXPORT ResourceBundle {
45 public: 45 public:
46 // Legacy font size deltas. Consider these to be magic numbers. New code 46 // Legacy font size deltas. Consider these to be magic numbers. New code
47 // should declare their own size delta constant using an identifier that 47 // should declare their own size delta constant using an identifier that
48 // imparts some semantic meaning. 48 // imparts some semantic meaning.
49 static const int kSmallFontDelta = -1; 49 static const int kSmallFontDelta = -1;
50 static const int kMediumFontDelta = 3; 50 static const int kMediumFontDelta = 3;
51 static const int kLargeFontDelta = 8; 51 static const int kLargeFontDelta = 8;
52 52
53 static constexpr const char* CUSTOM_GZIP_HEADER = "\xff\x1f\x8b";
54
53 // Legacy font style mappings. TODO(tapted): Phase these out in favour of 55 // Legacy font style mappings. TODO(tapted): Phase these out in favour of
54 // client code providing their own constant with the desired font size delta. 56 // client code providing their own constant with the desired font size delta.
55 enum FontStyle { 57 enum FontStyle {
56 SmallFont, 58 SmallFont,
57 SmallBoldFont, 59 SmallBoldFont,
58 BaseFont, 60 BaseFont,
59 BoldFont, 61 BoldFont,
60 MediumFont, 62 MediumFont,
61 MediumBoldFont, 63 MediumBoldFont,
62 LargeFont, 64 LargeFont,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // Similar to GetImageNamed, but rather than loading the image in Skia format, 211 // Similar to GetImageNamed, but rather than loading the image in Skia format,
210 // it will load in the native platform type. This can avoid conversion from 212 // it will load in the native platform type. This can avoid conversion from
211 // one image type to another. ResourceBundle owns the result. 213 // one image type to another. ResourceBundle owns the result.
212 // 214 //
213 // Note that if the same resource has already been loaded in GetImageNamed(), 215 // Note that if the same resource has already been loaded in GetImageNamed(),
214 // gfx::Image will perform a conversion, rather than using the native image 216 // gfx::Image will perform a conversion, rather than using the native image
215 // loading code of ResourceBundle. 217 // loading code of ResourceBundle.
216 gfx::Image& GetNativeImageNamed(int resource_id); 218 gfx::Image& GetNativeImageNamed(int resource_id);
217 219
218 // Loads the raw bytes of a scale independent data resource. 220 // Loads the raw bytes of a scale independent data resource.
221 // Will perform gzip decompression on any resource which has
222 // ResourceBundle::CUSTOM_GZIP_HEADER as its first 3 bytes.
agrieve 2016/05/27 17:40:00 nit: can you also add here that you can enable thi
smaier 2016/05/27 17:48:47 Done.
219 base::RefCountedMemory* LoadDataResourceBytes(int resource_id) const; 223 base::RefCountedMemory* LoadDataResourceBytes(int resource_id) const;
220 224
221 // Loads the raw bytes of a data resource nearest the scale factor 225 // Loads the raw bytes of a data resource nearest the scale factor
222 // |scale_factor| into |bytes|, without doing any processing or 226 // |scale_factor| into |bytes|, without doing any processing or
223 // interpretation of the resource. Use ResourceHandle::SCALE_FACTOR_NONE 227 // interpretation of the resource. Use ResourceHandle::SCALE_FACTOR_NONE
224 // for scale independent image resources (such as wallpaper). 228 // for scale independent image resources (such as wallpaper).
229 // Will perform gzip decompression on any resource which has
230 // ResourceBundle::CUSTOM_GZIP_HEADER as its first 3 bytes.
225 // Returns NULL if we fail to read the resource. 231 // Returns NULL if we fail to read the resource.
226 base::RefCountedMemory* LoadDataResourceBytesForScale( 232 base::RefCountedMemory* LoadDataResourceBytesForScale(
227 int resource_id, 233 int resource_id,
228 ScaleFactor scale_factor) const; 234 ScaleFactor scale_factor) const;
229 235
230 // Return the contents of a scale independent resource in a 236 // Return the contents of a scale independent resource in a
231 // StringPiece given the resource id 237 // StringPiece given the resource id.
238 // NOTE: CHECKs to ensure this is not called on a resource which has
239 // ResourceBundle::CUSTOM_GZIP_HEADER as its first 3 bytes.
232 base::StringPiece GetRawDataResource(int resource_id) const; 240 base::StringPiece GetRawDataResource(int resource_id) const;
233 241
234 // Return the contents of a resource in a StringPiece given the resource id 242 // Return the contents of a resource in a StringPiece given the resource id
235 // nearest the scale factor |scale_factor|. 243 // nearest the scale factor |scale_factor|.
236 // Use ResourceHandle::SCALE_FACTOR_NONE for scale independent image resources 244 // Use ResourceHandle::SCALE_FACTOR_NONE for scale independent image resources
237 // (such as wallpaper). 245 // (such as wallpaper).
246 // NOTE: CHECKs to ensure this is not called on a resource which has
247 // ResourceBundle::CUSTOM_GZIP_HEADER as its first 3 bytes.
238 base::StringPiece GetRawDataResourceForScale(int resource_id, 248 base::StringPiece GetRawDataResourceForScale(int resource_id,
239 ScaleFactor scale_factor) const; 249 ScaleFactor scale_factor) const;
240 250
241 // Get a localized string given a message id. Returns an empty 251 // Get a localized string given a message id. Returns an empty
242 // string if the message_id is not found. 252 // string if the message_id is not found.
243 base::string16 GetLocalizedString(int message_id); 253 base::string16 GetLocalizedString(int message_id);
244 254
245 // Returns a font list derived from the platform-specific "Base" font list. 255 // Returns a font list derived from the platform-specific "Base" font list.
246 // The result is always cached and exists for the lifetime of the process. 256 // The result is always cached and exists for the lifetime of the process.
247 const gfx::FontList& GetFontListWithDelta( 257 const gfx::FontList& GetFontListWithDelta(
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 385
376 // Fills the |bitmap| given the |resource_id| and |scale_factor|. 386 // Fills the |bitmap| given the |resource_id| and |scale_factor|.
377 // Returns false if the resource does not exist. This may fall back to 387 // Returns false if the resource does not exist. This may fall back to
378 // the data pack with SCALE_FACTOR_NONE, and when this happens, 388 // the data pack with SCALE_FACTOR_NONE, and when this happens,
379 // |scale_factor| will be set to SCALE_FACTOR_100P. 389 // |scale_factor| will be set to SCALE_FACTOR_100P.
380 bool LoadBitmap(int resource_id, 390 bool LoadBitmap(int resource_id,
381 ScaleFactor* scale_factor, 391 ScaleFactor* scale_factor,
382 SkBitmap* bitmap, 392 SkBitmap* bitmap,
383 bool* fell_back_to_1x) const; 393 bool* fell_back_to_1x) const;
384 394
395 // Loads the raw bytes of a data resource nearest the scale factor
396 // |scale_factor| into |bytes|, without doing any processing or
397 // interpretation of the resource. Use ResourceHandle::SCALE_FACTOR_NONE
398 // for scale independent image resources (such as wallpaper).
399 // Returns NULL if we fail to read the resource.
400 base::StringPiece DoGetRawDataResourceForScale(
401 int resource_id,
402 ScaleFactor scale_factor) const;
403
385 // Returns true if missing scaled resources should be visually indicated when 404 // Returns true if missing scaled resources should be visually indicated when
386 // drawing the fallback (e.g., by tinting the image). 405 // drawing the fallback (e.g., by tinting the image).
387 static bool ShouldHighlightMissingScaledResources(); 406 static bool ShouldHighlightMissingScaledResources();
388 407
389 // Returns true if the data in |buf| is a PNG that has the special marker 408 // Returns true if the data in |buf| is a PNG that has the special marker
390 // added by GRIT that indicates that the image is actually 1x data. 409 // added by GRIT that indicates that the image is actually 1x data.
391 static bool PNGContainsFallbackMarker(const unsigned char* buf, size_t size); 410 static bool PNGContainsFallbackMarker(const unsigned char* buf, size_t size);
392 411
393 // A wrapper for PNGCodec::Decode that returns information about custom 412 // A wrapper for PNGCodec::Decode that returns information about custom
394 // chunks. For security reasons we can't alter PNGCodec to return this 413 // chunks. For security reasons we can't alter PNGCodec to return this
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 462
444 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); 463 DISALLOW_COPY_AND_ASSIGN(ResourceBundle);
445 }; 464 };
446 465
447 } // namespace ui 466 } // namespace ui
448 467
449 // TODO(beng): Someday, maybe, get rid of this. 468 // TODO(beng): Someday, maybe, get rid of this.
450 using ui::ResourceBundle; 469 using ui::ResourceBundle;
451 470
452 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ 471 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698