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 "cc/resources/compositing_display_item.h" | 5 #include "cc/resources/compositing_display_item.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/trace_event/trace_event_argument.h" | 8 #include "base/trace_event/trace_event_argument.h" |
9 #include "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
10 #include "third_party/skia/include/core/SkPaint.h" | 10 #include "third_party/skia/include/core/SkPaint.h" |
11 #include "third_party/skia/include/core/SkXfermode.h" | 11 #include "third_party/skia/include/core/SkXfermode.h" |
12 #include "ui/gfx/skia_util.h" | 12 #include "ui/gfx/skia_util.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 CompositingDisplayItem::CompositingDisplayItem(float opacity, | 16 CompositingDisplayItem::CompositingDisplayItem(float opacity, |
17 SkXfermode::Mode xfermode, | 17 SkXfermode::Mode xfermode, |
| 18 SkRect* bounds, |
18 skia::RefPtr<SkColorFilter> cf) | 19 skia::RefPtr<SkColorFilter> cf) |
19 : opacity_(opacity), xfermode_(xfermode), color_filter_(cf) { | 20 : opacity_(opacity), |
| 21 xfermode_(xfermode), |
| 22 has_bounds_(!!bounds), |
| 23 color_filter_(cf) { |
| 24 if (bounds) |
| 25 bounds_ = SkRect(*bounds); |
20 } | 26 } |
21 | 27 |
22 CompositingDisplayItem::~CompositingDisplayItem() { | 28 CompositingDisplayItem::~CompositingDisplayItem() { |
23 } | 29 } |
24 | 30 |
25 void CompositingDisplayItem::Raster(SkCanvas* canvas, | 31 void CompositingDisplayItem::Raster(SkCanvas* canvas, |
26 SkDrawPictureCallback* callback) const { | 32 SkDrawPictureCallback* callback) const { |
27 SkPaint paint; | 33 SkPaint paint; |
28 paint.setXfermodeMode(xfermode_); | 34 paint.setXfermodeMode(xfermode_); |
29 paint.setAlpha(opacity_ * 255); | 35 paint.setAlpha(opacity_ * 255); |
30 paint.setColorFilter(color_filter_.get()); | 36 paint.setColorFilter(color_filter_.get()); |
31 canvas->saveLayer(NULL, &paint); | 37 canvas->saveLayer(has_bounds_ ? &bounds_ : nullptr, &paint); |
32 } | 38 } |
33 | 39 |
34 bool CompositingDisplayItem::IsSuitableForGpuRasterization() const { | 40 bool CompositingDisplayItem::IsSuitableForGpuRasterization() const { |
35 return true; | 41 return true; |
36 } | 42 } |
37 | 43 |
38 int CompositingDisplayItem::ApproximateOpCount() const { | 44 int CompositingDisplayItem::ApproximateOpCount() const { |
39 return 1; | 45 return 1; |
40 } | 46 } |
41 | 47 |
42 size_t CompositingDisplayItem::PictureMemoryUsage() const { | 48 size_t CompositingDisplayItem::PictureMemoryUsage() const { |
43 // TODO(pdr): Include color_filter's memory here. | 49 // TODO(pdr): Include color_filter's memory here. |
44 return sizeof(float) + sizeof(SkXfermode::Mode); | 50 return sizeof(float) + sizeof(bool) + sizeof(SkRect) + |
| 51 sizeof(SkXfermode::Mode); |
45 } | 52 } |
46 | 53 |
47 void CompositingDisplayItem::AsValueInto( | 54 void CompositingDisplayItem::AsValueInto( |
48 base::trace_event::TracedValue* array) const { | 55 base::trace_event::TracedValue* array) const { |
49 array->AppendString(base::StringPrintf( | 56 array->AppendString(base::StringPrintf( |
50 "CompositingDisplayItem opacity: %f, xfermode: %d", opacity_, xfermode_)); | 57 "CompositingDisplayItem opacity: %f, xfermode: %d", opacity_, xfermode_)); |
| 58 if (has_bounds_) |
| 59 array->AppendString(base::StringPrintf( |
| 60 ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_.x()), |
| 61 static_cast<float>(bounds_.y()), static_cast<float>(bounds_.width()), |
| 62 static_cast<float>(bounds_.height()))); |
51 } | 63 } |
52 | 64 |
53 EndCompositingDisplayItem::EndCompositingDisplayItem() { | 65 EndCompositingDisplayItem::EndCompositingDisplayItem() { |
54 } | 66 } |
55 | 67 |
56 EndCompositingDisplayItem::~EndCompositingDisplayItem() { | 68 EndCompositingDisplayItem::~EndCompositingDisplayItem() { |
57 } | 69 } |
58 | 70 |
59 void EndCompositingDisplayItem::Raster(SkCanvas* canvas, | 71 void EndCompositingDisplayItem::Raster(SkCanvas* canvas, |
60 SkDrawPictureCallback* callback) const { | 72 SkDrawPictureCallback* callback) const { |
(...skipping 11 matching lines...) Expand all Loading... |
72 size_t EndCompositingDisplayItem::PictureMemoryUsage() const { | 84 size_t EndCompositingDisplayItem::PictureMemoryUsage() const { |
73 return 0; | 85 return 0; |
74 } | 86 } |
75 | 87 |
76 void EndCompositingDisplayItem::AsValueInto( | 88 void EndCompositingDisplayItem::AsValueInto( |
77 base::trace_event::TracedValue* array) const { | 89 base::trace_event::TracedValue* array) const { |
78 array->AppendString("EndCompositingDisplayItem"); | 90 array->AppendString("EndCompositingDisplayItem"); |
79 } | 91 } |
80 | 92 |
81 } // namespace cc | 93 } // namespace cc |
OLD | NEW |