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

Side by Side Diff: content/browser/web_contents/aura/shadow_layer_delegate.cc

Issue 1057873004: Pass a ui::PaintContext from ui::Layer to layer delegates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: layer-paintcontext: mac Created 5 years, 8 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) 2013 The Chromium Authors. All rights reserved. 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 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 "content/browser/web_contents/aura/shadow_layer_delegate.h" 5 #include "content/browser/web_contents/aura/shadow_layer_delegate.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "third_party/skia/include/effects/SkGradientShader.h" 8 #include "third_party/skia/include/effects/SkGradientShader.h"
9 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/compositor/layer.h" 10 #include "ui/compositor/layer.h"
11 #include "ui/compositor/paint_context.h"
11 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/skia_util.h" 13 #include "ui/gfx/skia_util.h"
13 14
14 namespace { 15 namespace {
15 16
16 const SkColor kShadowLightColor = SkColorSetARGB(0x0, 0, 0, 0); 17 const SkColor kShadowLightColor = SkColorSetARGB(0x0, 0, 0, 0);
17 const SkColor kShadowDarkColor = SkColorSetARGB(0x70, 0, 0, 0); 18 const SkColor kShadowDarkColor = SkColorSetARGB(0x70, 0, 0, 0);
18 const int kShadowThick = 7; 19 const int kShadowThick = 7;
19 20
20 } // namespace 21 } // namespace
21 22
22 namespace content { 23 namespace content {
23 24
24 ShadowLayerDelegate::ShadowLayerDelegate(ui::Layer* shadow_for) 25 ShadowLayerDelegate::ShadowLayerDelegate(ui::Layer* shadow_for)
25 : layer_(new ui::Layer(ui::LAYER_TEXTURED)) { 26 : layer_(new ui::Layer(ui::LAYER_TEXTURED)) {
26 layer_->set_delegate(this); 27 layer_->set_delegate(this);
27 layer_->SetBounds(gfx::Rect(-kShadowThick, 0, kShadowThick, 28 layer_->SetBounds(gfx::Rect(-kShadowThick, 0, kShadowThick,
28 shadow_for->bounds().height())); 29 shadow_for->bounds().height()));
29 layer_->SetFillsBoundsOpaquely(false); 30 layer_->SetFillsBoundsOpaquely(false);
30 shadow_for->Add(layer_.get()); 31 shadow_for->Add(layer_.get());
31 } 32 }
32 33
33 ShadowLayerDelegate::~ShadowLayerDelegate() { 34 ShadowLayerDelegate::~ShadowLayerDelegate() {
34 } 35 }
35 36
36 void ShadowLayerDelegate::OnPaintLayer(gfx::Canvas* canvas) { 37 void ShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
37 SkPoint points[2]; 38 SkPoint points[2];
38 const SkColor kShadowColors[2] = { kShadowLightColor, kShadowDarkColor }; 39 const SkColor kShadowColors[2] = { kShadowLightColor, kShadowDarkColor };
39 40
40 points[0].iset(0, 0); 41 points[0].iset(0, 0);
41 points[1].iset(kShadowThick, 0); 42 points[1].iset(kShadowThick, 0);
42 43
43 skia::RefPtr<SkShader> shader = skia::AdoptRef( 44 skia::RefPtr<SkShader> shader = skia::AdoptRef(
44 SkGradientShader::CreateLinear(points, kShadowColors, NULL, 45 SkGradientShader::CreateLinear(points, kShadowColors, NULL,
45 arraysize(points), SkShader::kRepeat_TileMode)); 46 arraysize(points), SkShader::kRepeat_TileMode));
46 47
47 gfx::Rect paint_rect = gfx::Rect(0, 0, kShadowThick, 48 gfx::Rect paint_rect = gfx::Rect(0, 0, kShadowThick,
48 layer_->bounds().height()); 49 layer_->bounds().height());
49 SkPaint paint; 50 SkPaint paint;
50 paint.setShader(shader.get()); 51 paint.setShader(shader.get());
51 canvas->sk_canvas()->drawRect(gfx::RectToSkRect(paint_rect), paint); 52 context.canvas()->sk_canvas()->drawRect(gfx::RectToSkRect(paint_rect), paint);
52 } 53 }
53 54
54 void ShadowLayerDelegate::OnDelegatedFrameDamage( 55 void ShadowLayerDelegate::OnDelegatedFrameDamage(
55 const gfx::Rect& damage_rect_in_dip) { 56 const gfx::Rect& damage_rect_in_dip) {
56 } 57 }
57 58
58 void ShadowLayerDelegate::OnDeviceScaleFactorChanged(float scale_factor) { 59 void ShadowLayerDelegate::OnDeviceScaleFactorChanged(float scale_factor) {
59 } 60 }
60 61
61 base::Closure ShadowLayerDelegate::PrepareForLayerBoundsChange() { 62 base::Closure ShadowLayerDelegate::PrepareForLayerBoundsChange() {
62 return base::Bind(&base::DoNothing); 63 return base::Bind(&base::DoNothing);
63 } 64 }
64 65
65 } // namespace content 66 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/aura/shadow_layer_delegate.h ('k') | content/browser/web_contents/web_contents_view_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698