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

Side by Side Diff: chrome/browser/ui/app_list/extension_app_item.cc

Issue 2760133002: ui: Remove a bunch of uses of gfx::Canvas::ExtractImageRep() (Closed)
Patch Set: canvasbounds: . Created 3 years, 9 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
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/ui/app_list/extension_app_item.h" 5 #include "chrome/browser/ui/app_list/extension_app_item.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 14 matching lines...) Expand all
25 #include "extensions/browser/extension_registry.h" 25 #include "extensions/browser/extension_registry.h"
26 #include "extensions/common/extension.h" 26 #include "extensions/common/extension.h"
27 #include "extensions/common/extension_icon_set.h" 27 #include "extensions/common/extension_icon_set.h"
28 #include "extensions/common/manifest_handlers/icons_handler.h" 28 #include "extensions/common/manifest_handlers/icons_handler.h"
29 #include "extensions/common/manifest_url_handlers.h" 29 #include "extensions/common/manifest_url_handlers.h"
30 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/events/event_constants.h" 31 #include "ui/events/event_constants.h"
32 #include "ui/gfx/canvas.h" 32 #include "ui/gfx/canvas.h"
33 #include "ui/gfx/geometry/rect.h" 33 #include "ui/gfx/geometry/rect.h"
34 #include "ui/gfx/image/canvas_image_source.h" 34 #include "ui/gfx/image/canvas_image_source.h"
35 #include "ui/gfx/skia_util.h"
35 36
36 #if defined(OS_CHROMEOS) 37 #if defined(OS_CHROMEOS)
37 #include "chrome/browser/chromeos/extensions/gfx_utils.h" 38 #include "chrome/browser/chromeos/extensions/gfx_utils.h"
38 #endif 39 #endif
39 40
40 using extensions::Extension; 41 using extensions::Extension;
41 42
42 namespace { 43 namespace {
43 44
44 // Overlays a shortcut icon over the bottom left corner of a given image. 45 // Overlays a shortcut icon over the bottom left corner of a given image.
(...skipping 29 matching lines...) Expand all
74 icon_(icon) { 75 icon_(icon) {
75 } 76 }
76 ~RoundedCornersImageSource() override {} 77 ~RoundedCornersImageSource() override {}
77 78
78 private: 79 private:
79 // gfx::CanvasImageSource overrides: 80 // gfx::CanvasImageSource overrides:
80 void Draw(gfx::Canvas* canvas) override { 81 void Draw(gfx::Canvas* canvas) override {
81 // The radius used to round the app icon. 82 // The radius used to round the app icon.
82 const size_t kRoundingRadius = 2; 83 const size_t kRoundingRadius = 2;
83 84
85 SkBitmap mask_bitmap;
Peter Kasting 2017/03/20 22:49:21 Nit: Trivial, but I liked having this block below
danakj 2017/03/21 15:25:56 Sure, done. I liked having all the calls to |canva
86 mask_bitmap.allocN32Pixels(icon_.width(), icon_.height(), false);
87 sk_sp<SkSurface> mask_surface = SkSurface::MakeRasterDirect(
88 mask_bitmap.info(), mask_bitmap.getPixels(), mask_bitmap.rowBytes());
89 mask_surface->getCanvas()->clear(SK_ColorTRANSPARENT);
90 SkPaint mask_paint;
91 mask_paint.setAntiAlias(true);
92 mask_paint.setColor(SK_ColorWHITE);
93 mask_surface->getCanvas()->drawRoundRect(
94 gfx::RectToSkRect(gfx::Rect(icon_.width(), icon_.height())),
95 kRoundingRadius, kRoundingRadius, mask_paint);
96
84 canvas->DrawImageInt(icon_, 0, 0); 97 canvas->DrawImageInt(icon_, 0, 0);
85
86 std::unique_ptr<gfx::Canvas> masking_canvas(
87 new gfx::Canvas(gfx::Size(icon_.width(), icon_.height()), 1.0f, false));
88 DCHECK(masking_canvas);
89
90 cc::PaintFlags opaque_flags;
91 opaque_flags.setAntiAlias(true);
92 opaque_flags.setColor(SK_ColorWHITE);
93 masking_canvas->DrawRoundRect(gfx::Rect(icon_.width(), icon_.height()),
94 kRoundingRadius, opaque_flags);
95
96 cc::PaintFlags masking_flags; 98 cc::PaintFlags masking_flags;
97 masking_flags.setBlendMode(SkBlendMode::kDstIn); 99 masking_flags.setBlendMode(SkBlendMode::kDstIn);
98 canvas->DrawImageInt(gfx::ImageSkia(masking_canvas->ExtractImageRep()), 0, 100 canvas->sk_canvas()->drawBitmap(mask_bitmap, 0, 0, &masking_flags);
99 0, masking_flags);
100 } 101 }
101 102
102 gfx::ImageSkia icon_; 103 gfx::ImageSkia icon_;
103 104
104 DISALLOW_COPY_AND_ASSIGN(RoundedCornersImageSource); 105 DISALLOW_COPY_AND_ASSIGN(RoundedCornersImageSource);
105 }; 106 };
106 107
107 } // namespace 108 } // namespace
108 109
109 ExtensionAppItem::ExtensionAppItem( 110 ExtensionAppItem::ExtensionAppItem(
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 // static 307 // static
307 const char ExtensionAppItem::kItemType[] = "ExtensionAppItem"; 308 const char ExtensionAppItem::kItemType[] = "ExtensionAppItem";
308 309
309 const char* ExtensionAppItem::GetItemType() const { 310 const char* ExtensionAppItem::GetItemType() const {
310 return ExtensionAppItem::kItemType; 311 return ExtensionAppItem::kItemType;
311 } 312 }
312 313
313 void ExtensionAppItem::ExecuteLaunchCommand(int event_flags) { 314 void ExtensionAppItem::ExecuteLaunchCommand(int event_flags) {
314 Launch(event_flags); 315 Launch(event_flags);
315 } 316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698