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

Unified Diff: chrome/browser/browser_theme_provider.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: chrome/browser/browser_theme_provider.cc
diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc
index f234d8433ae694a844a329c158bce2502abd0a93..61623722a7cda9d0dc3512340808eb137e4dbe00 100644
--- a/chrome/browser/browser_theme_provider.cc
+++ b/chrome/browser/browser_theme_provider.cc
@@ -447,9 +447,7 @@ bool BrowserThemeProvider::HasCustomImage(int id) const {
UTF8ToWide(names_iter->second), false);
}
-bool BrowserThemeProvider::GetRawData(
- int id,
- std::vector<unsigned char>* raw_data) const {
+RefCountedMemory* BrowserThemeProvider::GetRawData(int id) const {
// Check to see whether we should substitute some images.
int ntp_alternate;
GetDisplayProperty(NTP_LOGO_ALTERNATE, &ntp_alternate);
@@ -458,16 +456,17 @@ bool BrowserThemeProvider::GetRawData(
RawDataMap::const_iterator data_iter = raw_data_.find(id);
if (data_iter != raw_data_.end()) {
- *raw_data = data_iter->second;
- return true;
+ return data_iter->second;
}
brettw 2009/10/16 23:03:12 You should also remove the {} for this conditional
- if (!ReadThemeFileData(id, raw_data) &&
- !rb_.LoadImageResourceBytes(id, raw_data))
- return false;
+ RefCountedMemory* data = ReadThemeFileData(id);
+ if (!data)
+ data = rb_.LoadImageResourceBytes(id);
+ if (!data)
+ return NULL;
- raw_data_[id] = *raw_data;
- return true;
+ raw_data_[id] = data;
+ return data;
}
void BrowserThemeProvider::SetTheme(Extension* extension) {
@@ -522,8 +521,7 @@ std::string BrowserThemeProvider::GetThemeID() const {
return WideToUTF8(id);
}
-bool BrowserThemeProvider::ReadThemeFileData(
- int id, std::vector<unsigned char>* raw_data) const {
+RefCountedMemory* BrowserThemeProvider::ReadThemeFileData(int id) const {
ImageMap::const_iterator images_iter = images_.find(id);
if (images_iter != images_.end()) {
// First check to see if we have a registered theme extension and whether
@@ -540,16 +538,17 @@ bool BrowserThemeProvider::ReadThemeFileData(
int64 avail = file.Available();
if (avail > 0 && avail < INT_MAX) {
size_t size = static_cast<size_t>(avail);
- raw_data->resize(size);
- char* data = reinterpret_cast<char*>(&(raw_data->front()));
+ std::vector<unsigned char> raw_data;
+ raw_data.resize(size);
+ char* data = reinterpret_cast<char*>(&(raw_data.front()));
if (file.ReadUntilComplete(data, size) == avail)
- return true;
+ return RefCountedBytes::TakeVector(&raw_data);
}
}
}
}
- return false;
+ return NULL;
}
// static
@@ -803,14 +802,27 @@ SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) const {
if (!themeable_images.count(id))
return NULL;
- // Attempt to find the image in our theme bundle.
- std::vector<unsigned char> raw_data, png_data;
- if (ReadThemeFileData(id, &raw_data)) {
+ scoped_refptr<RefCountedMemory> raw_data;
+
+ // We special case images related to the NTP so we first try raw data. Why?
+ // Because the DOMUI stuff uses that interface and otherwise we would be
+ // loading big images twice. Ouch. So either we prime the cache for when
+ // DOMUIThemeSource requests our image, or we take advantage of the already
+ // loaded data, saving a trip to disk.
brettw 2009/10/16 23:03:12 In person, I asked for some clarification of the c
+ if (id == IDR_THEME_NTP_BACKGROUND)
+ raw_data = GetRawData(id);
+
+ if (!raw_data)
+ raw_data = ReadThemeFileData(id);
+
+ if (raw_data) {
+ std::vector<unsigned char> png_data;
+
// Decode the PNG.
int image_width = 0;
int image_height = 0;
- if (!gfx::PNGCodec::Decode(&raw_data.front(), raw_data.size(),
+ if (!gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(),
gfx::PNGCodec::FORMAT_BGRA, &png_data,
&image_width, &image_height)) {
NOTREACHED() << "Unable to decode theme image resource " << id;

Powered by Google App Engine
This is Rietveld 408576698