| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/favicon/core/fallback_icon_service.h" | 5 #include "components/favicon/core/fallback_icon_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "cc/paint/skia_paint_canvas.h" |
| 11 #include "components/favicon/core/fallback_icon_client.h" | 12 #include "components/favicon/core/fallback_icon_client.h" |
| 12 #include "components/favicon/core/fallback_url_util.h" | 13 #include "components/favicon/core/fallback_url_util.h" |
| 13 #include "components/favicon_base/fallback_icon_style.h" | 14 #include "components/favicon_base/fallback_icon_style.h" |
| 14 #include "third_party/skia/include/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
| 15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/codec/png_codec.h" | 17 #include "ui/gfx/codec/png_codec.h" |
| 17 #include "ui/gfx/font_list.h" | 18 #include "ui/gfx/font_list.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/geometry/size.h" | 20 #include "ui/gfx/geometry/size.h" |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 } | 34 } |
| 34 | 35 |
| 35 FallbackIconService::~FallbackIconService() { | 36 FallbackIconService::~FallbackIconService() { |
| 36 } | 37 } |
| 37 | 38 |
| 38 std::vector<unsigned char> FallbackIconService::RenderFallbackIconBitmap( | 39 std::vector<unsigned char> FallbackIconService::RenderFallbackIconBitmap( |
| 39 const GURL& icon_url, | 40 const GURL& icon_url, |
| 40 int size, | 41 int size, |
| 41 const favicon_base::FallbackIconStyle& style) { | 42 const favicon_base::FallbackIconStyle& style) { |
| 42 int size_to_use = std::min(kMaxFallbackFaviconSize, size); | 43 int size_to_use = std::min(kMaxFallbackFaviconSize, size); |
| 43 gfx::Canvas canvas(gfx::Size(size_to_use, size_to_use), 1.0f, false); | 44 SkBitmap bitmap; |
| 45 bitmap.allocN32Pixels(size_to_use, size_to_use, false); |
| 46 cc::SkiaPaintCanvas paint_canvas(bitmap); |
| 47 gfx::Canvas canvas(&paint_canvas, 1.f); |
| 48 |
| 44 DrawFallbackIcon(icon_url, size_to_use, style, &canvas); | 49 DrawFallbackIcon(icon_url, size_to_use, style, &canvas); |
| 45 | 50 |
| 46 std::vector<unsigned char> bitmap_data; | 51 std::vector<unsigned char> bitmap_data; |
| 47 if (!gfx::PNGCodec::EncodeBGRASkBitmap(canvas.ExtractImageRep().sk_bitmap(), | 52 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &bitmap_data)) |
| 48 false, &bitmap_data)) { | |
| 49 bitmap_data.clear(); | 53 bitmap_data.clear(); |
| 50 } | |
| 51 return bitmap_data; | 54 return bitmap_data; |
| 52 } | 55 } |
| 53 | 56 |
| 54 void FallbackIconService::DrawFallbackIcon( | 57 void FallbackIconService::DrawFallbackIcon( |
| 55 const GURL& icon_url, | 58 const GURL& icon_url, |
| 56 int size, | 59 int size, |
| 57 const favicon_base::FallbackIconStyle& style, | 60 const favicon_base::FallbackIconStyle& style, |
| 58 gfx::Canvas* canvas) { | 61 gfx::Canvas* canvas) { |
| 59 const int kOffsetX = 0; | 62 const int kOffsetX = 0; |
| 60 const int kOffsetY = 0; | 63 const int kOffsetY = 0; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 78 | 81 |
| 79 canvas->DrawStringRectWithFlags( | 82 canvas->DrawStringRectWithFlags( |
| 80 icon_text, | 83 icon_text, |
| 81 gfx::FontList(fallback_icon_client_->GetFontNameList(), gfx::Font::NORMAL, | 84 gfx::FontList(fallback_icon_client_->GetFontNameList(), gfx::Font::NORMAL, |
| 82 font_size, gfx::Font::Weight::NORMAL), | 85 font_size, gfx::Font::Weight::NORMAL), |
| 83 style.text_color, gfx::Rect(kOffsetX, kOffsetY, size, size), | 86 style.text_color, gfx::Rect(kOffsetX, kOffsetY, size, size), |
| 84 gfx::Canvas::TEXT_ALIGN_CENTER); | 87 gfx::Canvas::TEXT_ALIGN_CENTER); |
| 85 } | 88 } |
| 86 | 89 |
| 87 } // namespace favicon | 90 } // namespace favicon |
| OLD | NEW |