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

Side by Side Diff: ui/views/shadow_border.cc

Issue 18003003: Message center re-organized (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Border caching added Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/shadow_border.h"
6
7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/insets.h"
9 #include "ui/gfx/shadow_value.h"
10 #include "ui/gfx/skia_util.h"
11
12 namespace views {
13
14 ShadowBorder::ShadowBorder(int blur,
15 SkColor color,
16 int vertical_offset,
17 int horizontal_offset)
18 : views::Border(),
19 blur_(blur),
20 color_(color),
21 vertical_offset_(vertical_offset),
22 horizontal_offset_(horizontal_offset) {}
23
24 ShadowBorder::~ShadowBorder() {}
25
26 void ShadowBorder::Paint(const views::View& view, gfx::Canvas* canvas) {
27 gfx::Rect bounds(view.size());
28
29 if (bounds != cache_bounds_ || !cached_border_.get()) {
30 cache_bounds_ = bounds;
31
32 // We cache the border since re-painting a shadow looper on every paint call
33 // may yield poor performance. So we draw the border on a separate canvas
34 // and cache the bitmap of the drawn border.
35 gfx::Canvas border_canvas(view.size(), canvas->scale_factor(), false);
36
37 SkPaint paint;
38 std::vector<gfx::ShadowValue> shadows;
39 shadows.push_back(gfx::ShadowValue(gfx::Point(), blur_, color_));
40 skia::RefPtr<SkDrawLooper> looper = gfx::CreateShadowDrawLooper(shadows);
41 paint.setLooper(looper.get());
42 paint.setColor(SK_ColorTRANSPARENT);
43 paint.setStrokeJoin(SkPaint::kRound_Join);
44 bounds.Inset(gfx::Insets(blur_ / 2, blur_ / 2, blur_ / 2, blur_ / 2));
45 border_canvas.DrawRect(bounds, paint);
46
47 cached_border_.reset(new gfx::ImageSkia(border_canvas.ExtractImageRep()));
dewittj 2013/07/15 18:38:58 Does this cache an image the size of the contained
sidharthms 2013/07/15 23:16:37 Removed for now. I'll submit a separate cl to add
48 }
49 canvas->DrawImageInt(*cached_border_.get(), 0, 0);
50 }
51
52 gfx::Insets ShadowBorder::GetInsets() const {
53 return gfx::Insets(blur_ / 2 - vertical_offset_,
54 blur_ / 2 - horizontal_offset_,
55 blur_ / 2 + vertical_offset_,
56 blur_ / 2 + horizontal_offset_);
57 }
58
59 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698