summaryrefslogtreecommitdiffstats
path: root/app/resource_bundle.cc
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 17:04:46 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 17:04:46 +0000
commit6de2799a47cbc201d943b32e0ac62555dc45f662 (patch)
tree6c64342df90783c5f334d370d6f8cb08472fcd7f /app/resource_bundle.cc
parent5f1b13bc6952eb89149716930e654c9d989b9e13 (diff)
downloadchromium_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.cc')
-rw-r--r--app/resource_bundle.cc28
1 files changed, 14 insertions, 14 deletions
diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc
index a108660..7261dfd 100644
--- a/app/resource_bundle.cc
+++ b/app/resource_bundle.cc
@@ -69,20 +69,20 @@ void ResourceBundle::FreeImages() {
/* static */
SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) {
- std::vector<unsigned char> raw_data, png_data;
- bool success = false;
+ std::vector<unsigned char> png_data;
- if (!success)
- success = LoadResourceBytes(data_handle, resource_id, &raw_data);
- if (!success)
+ scoped_refptr<RefCountedMemory> memory(
+ LoadResourceBytes(data_handle, resource_id));
+ if (!memory)
return NULL;
// Decode the PNG.
int image_width;
int image_height;
- if (!gfx::PNGCodec::Decode(&raw_data.front(), raw_data.size(),
- gfx::PNGCodec::FORMAT_BGRA,
- &png_data, &image_width, &image_height)) {
+ if (!gfx::PNGCodec::Decode(
+ memory->front(), memory->size(),
+ gfx::PNGCodec::FORMAT_BGRA,
+ &png_data, &image_width, &image_height)) {
NOTREACHED() << "Unable to decode image resource " << resource_id;
return NULL;
}
@@ -96,14 +96,14 @@ std::string ResourceBundle::GetDataResource(int resource_id) {
return GetRawDataResource(resource_id).as_string();
}
-bool ResourceBundle::LoadImageResourceBytes(int resource_id,
- std::vector<unsigned char>* bytes) {
- return LoadResourceBytes(theme_data_, resource_id, bytes);
+RefCountedStaticMemory* ResourceBundle::LoadImageResourceBytes(
+ int resource_id) {
+ return LoadResourceBytes(theme_data_, resource_id);
}
-bool ResourceBundle::LoadDataResourceBytes(int resource_id,
- std::vector<unsigned char>* bytes) {
- return LoadResourceBytes(resources_data_, resource_id, bytes);
+RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes(
+ int resource_id) {
+ return LoadResourceBytes(resources_data_, resource_id);
}
SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) {