diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-19 17:04:46 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-19 17:04:46 +0000 |
commit | 6de2799a47cbc201d943b32e0ac62555dc45f662 (patch) | |
tree | 6c64342df90783c5f334d370d6f8cb08472fcd7f /app/resource_bundle.h | |
parent | 5f1b13bc6952eb89149716930e654c9d989b9e13 (diff) | |
download | chromium_src-6de2799a47cbc201d943b32e0ac62555dc45f662.zip chromium_src-6de2799a47cbc201d943b32e0ac62555dc45f662.tar.gz chromium_src-6de2799a47cbc201d943b32e0ac62555dc45f662.tar.bz2 |
First fix to minimize copying of image data.
This is the first of multiple patches that clean up handling of memory
regarding images. Previously, the code did several memcpy()s or
equivalents. This change:
- Creates an abstract interface RefCountedMemory which provides access to the
front() of a memory range and the size() of it. It is a RefCountedThreadSafe.
- Adds a RefCountedStaticMemory class which isa RefCountedMemory.
- Pushes RefCountedBytes up into base/ from chrome/ and make it conform to
RefCountedMemory.
- Have ResourceBundle return RefCountedStaticMemory to the mmaped() or DLL
loaded resources instead of memcpy()ing them.
- General cleanups to minimize copies in constructing RefCountedBytes.
- Use the above consistent interface in the BrowserThemeProvider, along with
special casing the loading of the new tab page background.
This patch is mostly cleanups and there should only be a slight performance
gain if any. Most of the real speedups should come in subsequent patches.
BUG=http://crbug.com/24493
TEST=Slightly faster on Perf bot; does not introduce crashes.
Review URL: http://codereview.chromium.org/288005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29412 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/resource_bundle.h')
-rw-r--r-- | app/resource_bundle.h | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/app/resource_bundle.h b/app/resource_bundle.h index 23f39c5..f2fdb58 100644 --- a/app/resource_bundle.h +++ b/app/resource_bundle.h @@ -17,6 +17,7 @@ #include "base/basictypes.h" #include "base/file_path.h" #include "base/lock.h" +#include "base/ref_counted_memory.h" #include "base/scoped_ptr.h" #include "base/string16.h" @@ -90,14 +91,12 @@ class ResourceBundle { // Loads the raw bytes of an image resource into |bytes|, // without doing any processing or interpretation of // the resource. Returns whether we successfully read the resource. - bool LoadImageResourceBytes(int resource_id, - std::vector<unsigned char>* bytes); + RefCountedStaticMemory* LoadImageResourceBytes(int resource_id); // Loads the raw bytes of a data resource into |bytes|, // without doing any processing or interpretation of // the resource. Returns whether we successfully read the resource. - bool LoadDataResourceBytes(int resource_id, - std::vector<unsigned char>* bytes); + RefCountedStaticMemory* LoadDataResourceBytes(int resource_id); // Return the contents of a file in a string given the resource id. // This will copy the data from the resource and return it as a string. @@ -185,12 +184,12 @@ class ResourceBundle { // string if no locale data files are found. FilePath GetLocaleFilePath(const std::wstring& pref_locale); - // Loads the raw bytes of a resource from |module| into |bytes|, - // without doing any processing or interpretation of - // the resource. Returns whether we successfully read the resource. - static bool LoadResourceBytes(DataHandle module, - int resource_id, - std::vector<unsigned char>* bytes); + // Returns a handle to bytes from the resource |module|, without doing any + // processing or interpretation of the resource. Returns whether we + // successfully read the resource. Caller does not own the data returned + // through this method and must not modify the data pointed to by |bytes|. + static RefCountedStaticMemory* LoadResourceBytes(DataHandle module, + int resource_id); // Creates and returns a new SkBitmap given the data file to look in and the // resource id. It's up to the caller to free the returned bitmap when |