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

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: ashnit 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
84 canvas->DrawImageInt(icon_, 0, 0); 85 canvas->DrawImageInt(icon_, 0, 0);
85 86
86 std::unique_ptr<gfx::Canvas> masking_canvas( 87 SkBitmap mask_bitmap;
87 new gfx::Canvas(gfx::Size(icon_.width(), icon_.height()), 1.0f, false)); 88 mask_bitmap.allocN32Pixels(icon_.width(), icon_.height(), false);
88 DCHECK(masking_canvas); 89 sk_sp<SkSurface> mask_surface = SkSurface::MakeRasterDirect(
89 90 mask_bitmap.info(), mask_bitmap.getPixels(), mask_bitmap.rowBytes());
90 cc::PaintFlags opaque_flags; 91 mask_surface->getCanvas()->clear(SK_ColorTRANSPARENT);
91 opaque_flags.setAntiAlias(true); 92 SkPaint mask_paint;
92 opaque_flags.setColor(SK_ColorWHITE); 93 mask_paint.setAntiAlias(true);
93 masking_canvas->DrawRoundRect(gfx::Rect(icon_.width(), icon_.height()), 94 mask_paint.setColor(SK_ColorWHITE);
94 kRoundingRadius, opaque_flags); 95 mask_surface->getCanvas()->drawRoundRect(
96 gfx::RectToSkRect(gfx::Rect(icon_.width(), icon_.height())),
97 kRoundingRadius, kRoundingRadius, mask_paint);
95 98
96 cc::PaintFlags masking_flags; 99 cc::PaintFlags masking_flags;
97 masking_flags.setBlendMode(SkBlendMode::kDstIn); 100 masking_flags.setBlendMode(SkBlendMode::kDstIn);
98 canvas->DrawImageInt(gfx::ImageSkia(masking_canvas->ExtractImageRep()), 0, 101 canvas->sk_canvas()->drawBitmap(mask_bitmap, 0, 0, &masking_flags);
99 0, masking_flags);
100 } 102 }
101 103
102 gfx::ImageSkia icon_; 104 gfx::ImageSkia icon_;
103 105
104 DISALLOW_COPY_AND_ASSIGN(RoundedCornersImageSource); 106 DISALLOW_COPY_AND_ASSIGN(RoundedCornersImageSource);
105 }; 107 };
106 108
107 } // namespace 109 } // namespace
108 110
109 ExtensionAppItem::ExtensionAppItem( 111 ExtensionAppItem::ExtensionAppItem(
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 // static 308 // static
307 const char ExtensionAppItem::kItemType[] = "ExtensionAppItem"; 309 const char ExtensionAppItem::kItemType[] = "ExtensionAppItem";
308 310
309 const char* ExtensionAppItem::GetItemType() const { 311 const char* ExtensionAppItem::GetItemType() const {
310 return ExtensionAppItem::kItemType; 312 return ExtensionAppItem::kItemType;
311 } 313 }
312 314
313 void ExtensionAppItem::ExecuteLaunchCommand(int event_flags) { 315 void ExtensionAppItem::ExecuteLaunchCommand(int event_flags) {
314 Launch(event_flags); 316 Launch(event_flags);
315 } 317 }
OLDNEW
« no previous file with comments | « ash/common/frame/caption_buttons/frame_caption_button.cc ('k') | chrome/browser/ui/webui/app_launcher_login_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698