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_linux.cc | |
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_linux.cc')
-rw-r--r-- | app/resource_bundle_linux.cc | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/app/resource_bundle_linux.cc b/app/resource_bundle_linux.cc index 911cc03..929a77f 100644 --- a/app/resource_bundle_linux.cc +++ b/app/resource_bundle_linux.cc @@ -25,10 +25,10 @@ namespace { // Convert the raw image data into a GdkPixbuf. The GdkPixbuf that is returned // has a ref count of 1 so the caller must call g_object_unref to free the // memory. -GdkPixbuf* LoadPixbuf(std::vector<unsigned char>& data, bool rtl_enabled) { +GdkPixbuf* LoadPixbuf(RefCountedStaticMemory* data, bool rtl_enabled) { ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); bool ok = gdk_pixbuf_loader_write(loader.get(), - static_cast<guint8*>(data.data()), data.size(), NULL); + reinterpret_cast<const guint8*>(data->front()), data->size(), NULL); if (!ok) return NULL; // Calling gdk_pixbuf_loader_close forces the data to be parsed by the @@ -117,18 +117,16 @@ void ResourceBundle::LoadThemeResources() { DCHECK(success) << "failed to load theme data"; } -/* static */ -bool ResourceBundle::LoadResourceBytes(DataHandle module, int resource_id, - std::vector<unsigned char>* bytes) { +// static +RefCountedStaticMemory* ResourceBundle::LoadResourceBytes( + DataHandle module, int resource_id) { DCHECK(module); - base::StringPiece data; - if (!module->Get(resource_id, &data)) - return false; - - bytes->resize(data.length()); - memcpy(&(bytes->front()), data.data(), data.length()); + base::StringPiece bytes; + if (!module->Get(resource_id, &bytes)) + return NULL; - return true; + return new RefCountedStaticMemory( + reinterpret_cast<const unsigned char*>(bytes.data()), bytes.length()); } base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) { @@ -176,9 +174,9 @@ GdkPixbuf* ResourceBundle::GetPixbufImpl(int resource_id, bool rtl_enabled) { return found->second; } - std::vector<unsigned char> data; - LoadImageResourceBytes(resource_id, &data); - GdkPixbuf* pixbuf = LoadPixbuf(data, rtl_enabled); + scoped_refptr<RefCountedStaticMemory> data( + LoadImageResourceBytes(resource_id)); + GdkPixbuf* pixbuf = LoadPixbuf(data.get(), rtl_enabled); // We loaded successfully. Cache the pixbuf. if (pixbuf) { |