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

Unified Diff: app/resource_bundle_linux.cc

Issue 288005: First fix to minimize copying of image data. (Closed)
Patch Set: Modify gyp Created 11 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: app/resource_bundle_linux.cc
diff --git a/app/resource_bundle_linux.cc b/app/resource_bundle_linux.cc
index 911cc033c9868848bdd7345edbc053126621ef23..929a77f99338db92d8ecf32c450014adbe2d711b 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) {
« no previous file with comments | « app/resource_bundle.cc ('k') | app/resource_bundle_mac.mm » ('j') | base/ref_counted_memory.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698