Commit a37ba3b9 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

Revert "Compute colors for the frame and tabs from provided images."

This reverts commit df84748a.

Reason for revert: To fix unit_tests (I have to revert this before the earlier patch). Likely suspect for BrowserThemePackTest.HiDpiThemeTest failing on bots. For example, https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/linux-chromeos-rel/11230 :

[ RUN      ] BrowserThemePackTest.HiDpiThemeTest
../../chrome/browser/themes/browser_theme_pack_unittest.cc:204: Failure
Expected equality of these values:
  ""
  error
    Which is: "File doesn't exist."
Stack trace:
#0 0x0000026103ac testing::internal::UnitTestImpl::CurrentOsStackTraceExceptTop()
#1 0x00000260fd89 testing::internal::AssertHelper::operator=()
#2 0x000000fc9b98 BrowserThemePackTest::BuildFromUnpackedExtension()
#3 0x000000fd22cc BrowserThemePackTest_HiDpiThemeTest_Test::TestBody()
../../chrome/browser/themes/browser_theme_pack_unittest.cc:205: Failure
Value of: valid_value.get()
  Actual: false
Expected: true
Stack trace:
#0 0x0000026103ac testing::internal::UnitTestImpl::CurrentOsStackTraceExceptTop()
#1 0x00000260fd89 testing::internal::AssertHelper::operator=()
#2 0x000000fc9e0b BrowserThemePackTest::BuildFromUnpackedExtension()
#3 0x000000fd22cc BrowserThemePackTest_HiDpiThemeTest_Test::TestBody()
Received signal 11 SEGV_MAPERR 000000000028
#0 0x000004d00e1c base::debug::StackTrace::StackTrace()
#1 0x000004d00981 base::debug::(anonymous namespace)::StackDumpSignalHandler()
#2 0x7f26bba79330 <unknown>
#3 0x0000050f3e24 BrowserThemePack::WriteToDisk()
#4 0x000000fd22db BrowserThemePackTest_HiDpiThemeTest_Test::TestBody()
#5 0x0000026161b2 testing::Test::Run()
#6 0x000002616d30 testing::TestInfo::Run()
#7 0x000002617247 testing::TestCase::Run()
#8 0x000002622747 testing::internal::UnitTestImpl::RunAllTests()
#9 0x0000026222bd testing::UnitTest::Run()
#10 0x0000045565d1 base::TestSuite::Run()
#11 0x000004557fca base::(anonymous namespace)::LaunchUnitTestsInternal()
#12 0x000004557e7a base::LaunchUnitTests()
#13 0x00000454e155 main
#14 0x7f26b86c9f45 __libc_start_main
#15 0x0000006fa82a _start
  r8: 0000000000000000  r9: 54656d6568546970 r10: 747365545f747365 r11: 0000000000000000
 r12: 000024a8af0c0d20 r13: 00007fff447924e8 r14: 00007fff44792560 r15: 0000000000000000
  di: 0000000000000000  si: 00007fff44792560  bp: 00007fff44792520  bx: 00007fff44792578
  dx: 00000000000005e7  ax: 0000000000001fdd  cx: 0000000000000023  sp: 00007fff44792490
  ip: 00000000050f3e24 efl: 0000000000010206 cgf: 0000000000000033 erf: 0000000000000004
 trp: 000000000000000e msk: 0000000000000000 cr2: 0000000000000028
[end of stack trace]

Original change's description:
> Compute colors for the frame and tabs from provided images.
> 
> If theme authors explicitly provide values here, we'll use them; but if they
> don't, but do provide images, set the colors to be the dominant colors of the
> images, using an existing K-means algorithm (similar to what we use for
> computing representative favicon colors etc.).
> 
> This allows us to rely on those colors later when deciding what color to make
> tab text, the new tab button, and similar tabstrip/window frame items.
> 
> This also does a bit of cleanup to the theme pack code, e.g. moving a map used
> in only one function into that function to make its provenance clearer.  I can
> try to split this apart into more CLs if desired.
> 
> Bug: 862664
> Change-Id: I8c3f15893ad491a6fee8aa5f76ae162cecb2c6fd
> Reviewed-on: https://chromium-review.googlesource.com/1152517
> Commit-Queue: Peter Kasting <pkasting@chromium.org>
> Reviewed-by: Alexei Svitkine <asvitkine@chromium.org>
> Reviewed-by: Evan Stade <estade@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#578823}

TBR=pkasting@chromium.org,asvitkine@chromium.org,estade@chromium.org

Change-Id: I6a5a7f2916136ccf93101f36c34a17a4e5ef5d4f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 862664
Reviewed-on: https://chromium-review.googlesource.com/1153988Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578856}
parent b6b32cb9
This diff is collapsed.
......@@ -111,14 +111,6 @@ class BrowserThemePack : public CustomThemeSupplier {
~BrowserThemePack() override;
// Modifies |colors_| to set the entry with identifier |id| to |color|. Only
// valid to call after BuildColorsFromJSON(), which creates |colors_|.
void SetColor(int id, SkColor color);
// If |colors_| does not already contain an entry with identifier |id|, sets
// it to the dominant color of the top |height| rows of |image|.
void ComputeColorFromImage(int id, int height, const gfx::Image& image);
// Builds a header ready to write to disk.
void BuildHeader(const extensions::Extension* extension);
......@@ -133,6 +125,7 @@ class BrowserThemePack : public CustomThemeSupplier {
// Implementation details of BuildColorsFromJSON().
void ReadColorsFromJSON(const base::DictionaryValue* colors_value,
std::map<int, SkColor>* temp_colors);
void GenerateMissingColors(std::map<int, SkColor>* temp_colors);
// Transforms the JSON display properties into |display_properties_|.
void BuildDisplayPropertiesFromJSON(
......@@ -157,23 +150,23 @@ class BrowserThemePack : public CustomThemeSupplier {
bool LoadRawBitmapsTo(const FilePathMap& file_paths,
ImageCache* image_cache);
// Populate |images| cache with empty gfx::Images. Image reps are lazily
// generated when an image rep is requested via ImageSkia::GetRepresentation.
// Source and destination is |images|.
void CreateImages(ImageCache* images) const;
// Crops images down to a size such that most of the cropped image will be
// displayed in the UI. Cropping is useful because images from custom themes
// can be of any size. Source and destination is |images|.
void CropImages(ImageCache* images) const;
// Creates tinted and composited frame images. Source and destination is
// |images|. Also sets frame colors corresponding to these images if no
// explicit color has been specified for these colors.
void CreateFrameImagesAndColors(ImageCache* images);
// Generates any frame colors which have not already been set.
void GenerateFrameColors();
// |images|.
void CreateFrameImages(ImageCache* images) const;
// Creates the semi-transparent tab background images, putting the results
// in |images|. Also sets colors corresponding to these images if no explicit
// color has been specified. Must be called after GenerateFrameImages().
void CreateTabBackgroundImagesAndColors(ImageCache* images);
// in |images|. Must be called after GenerateFrameImages().
void CreateTabBackgroundImages(ImageCache* images) const;
// Takes all the SkBitmaps in |images|, encodes them as PNGs and places
// them in |reencoded_images|.
......
......@@ -145,7 +145,6 @@ void BrowserThemePackTest::LoadColorJSON(const std::string& json) {
void BrowserThemePackTest::LoadColorDictionary(base::DictionaryValue* value) {
theme_pack_->BuildColorsFromJSON(value);
theme_pack_->GenerateFrameColors();
}
void BrowserThemePackTest::LoadTintJSON(const std::string& json) {
......
......@@ -543,8 +543,7 @@ SkColor CalculateKMeanColorOfBuffer(uint8_t* decoded_data,
int img_height,
const HSL& lower_bound,
const HSL& upper_bound,
KMeanImageSampler* sampler,
bool find_closest) {
KMeanImageSampler* sampler) {
SkColor color = kDefaultBgColor;
if (img_width > 0 && img_height > 0) {
std::vector<KMeanCluster> clusters;
......@@ -676,11 +675,9 @@ SkColor CalculateKMeanColorOfBuffer(uint8_t* decoded_data,
}
}
// The K-mean cluster center will not usually be a color that appears in the
// image. If desired, find a color that actually appears.
return find_closest
? FindClosestColor(decoded_data, img_width, img_height, color)
: color;
// Find a color that actually appears in the image (the K-mean cluster center
// will not usually be a color that appears in the image).
return FindClosestColor(decoded_data, img_width, img_height, color);
}
SkColor CalculateKMeanColorOfPNG(scoped_refptr<base::RefCountedMemory> png,
......@@ -693,11 +690,18 @@ SkColor CalculateKMeanColorOfPNG(scoped_refptr<base::RefCountedMemory> png,
SkColor color = kDefaultBgColor;
if (png.get() && png->size() &&
gfx::PNGCodec::Decode(png->front(), png->size(),
gfx::PNGCodec::FORMAT_BGRA, &decoded_data,
&img_width, &img_height)) {
return CalculateKMeanColorOfBuffer(&decoded_data[0], img_width, img_height,
lower_bound, upper_bound, sampler, true);
gfx::PNGCodec::Decode(png->front(),
png->size(),
gfx::PNGCodec::FORMAT_BGRA,
&decoded_data,
&img_width,
&img_height)) {
return CalculateKMeanColorOfBuffer(&decoded_data[0],
img_width,
img_height,
lower_bound,
upper_bound,
sampler);
}
return color;
}
......@@ -709,27 +713,25 @@ SkColor CalculateKMeanColorOfPNG(scoped_refptr<base::RefCountedMemory> png) {
}
SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap,
int height,
const HSL& lower_bound,
const HSL& upper_bound,
bool find_closest) {
KMeanImageSampler* sampler) {
// SkBitmap uses pre-multiplied alpha but the KMean clustering function
// above uses non-pre-multiplied alpha. Transform the bitmap before we
// analyze it because the function reads each pixel multiple times.
int pixel_count = bitmap.width() * height;
int pixel_count = bitmap.width() * bitmap.height();
std::unique_ptr<uint32_t[]> image(new uint32_t[pixel_count]);
UnPreMultiply(bitmap, image.get(), pixel_count);
GridSampler sampler;
return CalculateKMeanColorOfBuffer(reinterpret_cast<uint8_t*>(image.get()),
bitmap.width(), height, lower_bound,
upper_bound, &sampler, find_closest);
bitmap.width(), bitmap.height(),
lower_bound, upper_bound, sampler);
}
SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap) {
GridSampler sampler;
return CalculateKMeanColorOfBitmap(
bitmap, bitmap.height(), kDefaultLowerHSLBound, kDefaultUpperHSLBound,
true);
bitmap, kDefaultLowerHSLBound, kDefaultUpperHSLBound, &sampler);
}
std::vector<SkColor> CalculateProminentColorsOfBitmap(
......
......@@ -98,17 +98,12 @@ GFX_EXPORT SkColor
GFX_EXPORT SkColor CalculateKMeanColorOfPNG(
scoped_refptr<base::RefCountedMemory> png);
// Computes a dominant color for the first |height| rows of |bitmap| using the
// above algorithm and a reasonable default sampler. If |find_closest| is true,
// the returned color will be the closest color to the true K-mean color that
// actually appears in the image; if false, the true color is returned
// regardless of whether it actually appears.
// Returns an SkColor that represents the calculated dominant color in the
// image. See CalculateKMeanColorOfPNG() for details.
GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap,
int height,
const HSL& lower_bound,
const HSL& upper_bound,
bool find_closest);
KMeanImageSampler* sampler);
// Computes a dominant color using the above algorithm and reasonable defaults
// for |lower_bound|, |upper_bound| and |sampler|.
GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment