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

Side by Side Diff: chrome/browser/themes/theme_service.cc

Issue 1869693002: Theme suppliers: Avoid all Image copying. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/themes/theme_service.h ('k') | chrome/browser/themes/theme_service_aurax11.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/themes/theme_service.h" 5 #include "chrome/browser/themes/theme_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 const double luminance = color_utils::GetRelativeLuminance( 665 const double luminance = color_utils::GetRelativeLuminance(
666 color_utils::AlphaBlend(separator_color, frame_color, alpha)); 666 color_utils::AlphaBlend(separator_color, frame_color, alpha));
667 if (luminance == target_luminance) 667 if (luminance == target_luminance)
668 break; 668 break;
669 alpha += (luminance < target_luminance) ? -delta : delta; 669 alpha += (luminance < target_luminance) ? -delta : delta;
670 } 670 }
671 return SkColorSetA(separator_color, alpha); 671 return SkColorSetA(separator_color, alpha);
672 } 672 }
673 673
674 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id, bool incognito) const { 674 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id, bool incognito) const {
675 gfx::Image image = GetImageNamed(id, incognito); 675 const gfx::Image& image = GetImageNamed(id, incognito);
676 if (image.IsEmpty()) 676 if (image.IsEmpty())
677 return nullptr; 677 return nullptr;
678 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns 678 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns
679 // its images const. GetImageSkiaNamed() also should but has many callsites. 679 // its images const. GetImageSkiaNamed() also should but has many callsites.
680 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); 680 return const_cast<gfx::ImageSkia*>(image.ToImageSkia());
681 } 681 }
682 682
683 SkColor ThemeService::GetColor(int id, bool incognito) const { 683 SkColor ThemeService::GetColor(int id, bool incognito) const {
684 DCHECK(CalledOnValidThread()); 684 DCHECK(CalledOnValidThread());
685 685
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 737
738 base::RefCountedMemory* data = nullptr; 738 base::RefCountedMemory* data = nullptr;
739 if (theme_supplier_) 739 if (theme_supplier_)
740 data = theme_supplier_->GetRawData(id, scale_factor); 740 data = theme_supplier_->GetRawData(id, scale_factor);
741 if (!data) 741 if (!data)
742 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); 742 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P);
743 743
744 return data; 744 return data;
745 } 745 }
746 746
747 gfx::Image ThemeService::GetImageNamed(int id, bool incognito) const { 747 const gfx::Image& ThemeService::GetImageNamed(int id, bool incognito) const {
748 DCHECK(CalledOnValidThread()); 748 DCHECK(CalledOnValidThread());
749 749
750 int adjusted_id = id; 750 int adjusted_id = id;
751 if (incognito) { 751 if (incognito) {
752 if (id == IDR_THEME_FRAME) 752 if (id == IDR_THEME_FRAME)
753 adjusted_id = IDR_THEME_FRAME_INCOGNITO; 753 adjusted_id = IDR_THEME_FRAME_INCOGNITO;
754 else if (id == IDR_THEME_FRAME_INACTIVE) 754 else if (id == IDR_THEME_FRAME_INACTIVE)
755 adjusted_id = IDR_THEME_FRAME_INCOGNITO_INACTIVE; 755 adjusted_id = IDR_THEME_FRAME_INCOGNITO_INACTIVE;
756 } 756 }
757 757
758 gfx::Image image; 758 if (theme_supplier_) {
759 if (theme_supplier_) 759 const gfx::Image& image = theme_supplier_->GetImageNamed(adjusted_id);
760 image = theme_supplier_->GetImageNamed(adjusted_id); 760 if (!image.IsEmpty())
761 return image;
762 }
761 763
762 if (image.IsEmpty()) 764 return rb_.GetNativeImageNamed(adjusted_id);
763 image = rb_.GetNativeImageNamed(adjusted_id);
764
765 return image;
766 } 765 }
767 766
768 void ThemeService::OnExtensionServiceReady() { 767 void ThemeService::OnExtensionServiceReady() {
769 if (!ready_) { 768 if (!ready_) {
770 // If the ThemeService is not ready yet, the custom theme data pack needs to 769 // If the ThemeService is not ready yet, the custom theme data pack needs to
771 // be recreated from the extension. 770 // be recreated from the extension.
772 MigrateTheme(); 771 MigrateTheme();
773 set_ready(); 772 set_ready();
774 773
775 // Send notification in case anyone requested data and cached it when the 774 // Send notification in case anyone requested data and cached it when the
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 858
860 #if defined(ENABLE_SUPERVISED_USERS) 859 #if defined(ENABLE_SUPERVISED_USERS)
861 bool ThemeService::IsSupervisedUser() const { 860 bool ThemeService::IsSupervisedUser() const {
862 return profile_->IsSupervised(); 861 return profile_->IsSupervised();
863 } 862 }
864 863
865 void ThemeService::SetSupervisedUserTheme() { 864 void ThemeService::SetSupervisedUserTheme() {
866 SetCustomDefaultTheme(new SupervisedUserTheme); 865 SetCustomDefaultTheme(new SupervisedUserTheme);
867 } 866 }
868 #endif 867 #endif
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_service.h ('k') | chrome/browser/themes/theme_service_aurax11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698