| 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/playback/compositing_display_item.h" | 5 #include "cc/playback/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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 SkRect* bounds, | 24 SkRect* bounds, |
| 25 skia::RefPtr<SkColorFilter> cf) { | 25 skia::RefPtr<SkColorFilter> cf) { |
| 26 alpha_ = alpha; | 26 alpha_ = alpha; |
| 27 xfermode_ = xfermode; | 27 xfermode_ = xfermode; |
| 28 has_bounds_ = !!bounds; | 28 has_bounds_ = !!bounds; |
| 29 if (bounds) | 29 if (bounds) |
| 30 bounds_ = SkRect(*bounds); | 30 bounds_ = SkRect(*bounds); |
| 31 color_filter_ = cf; | 31 color_filter_ = cf; |
| 32 | 32 |
| 33 // TODO(pdr): Include color_filter's memory here. | 33 // TODO(pdr): Include color_filter's memory here. |
| 34 size_t memory_usage = | 34 size_t external_memory_usage = 0; |
| 35 sizeof(float) + sizeof(bool) + sizeof(SkRect) + sizeof(SkXfermode::Mode); | |
| 36 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, | 35 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, |
| 37 memory_usage); | 36 external_memory_usage); |
| 38 } | 37 } |
| 39 | 38 |
| 40 void CompositingDisplayItem::Raster( | 39 void CompositingDisplayItem::Raster( |
| 41 SkCanvas* canvas, | 40 SkCanvas* canvas, |
| 42 const gfx::Rect& canvas_target_playback_rect, | 41 const gfx::Rect& canvas_target_playback_rect, |
| 43 SkPicture::AbortCallback* callback) const { | 42 SkPicture::AbortCallback* callback) const { |
| 44 SkPaint paint; | 43 SkPaint paint; |
| 45 paint.setXfermodeMode(xfermode_); | 44 paint.setXfermodeMode(xfermode_); |
| 46 paint.setAlpha(alpha_); | 45 paint.setAlpha(alpha_); |
| 47 paint.setColorFilter(color_filter_.get()); | 46 paint.setColorFilter(color_filter_.get()); |
| 48 canvas->saveLayer(has_bounds_ ? &bounds_ : nullptr, &paint); | 47 canvas->saveLayer(has_bounds_ ? &bounds_ : nullptr, &paint); |
| 49 } | 48 } |
| 50 | 49 |
| 51 void CompositingDisplayItem::AsValueInto( | 50 void CompositingDisplayItem::AsValueInto( |
| 52 base::trace_event::TracedValue* array) const { | 51 base::trace_event::TracedValue* array) const { |
| 53 array->AppendString(base::StringPrintf( | 52 array->AppendString(base::StringPrintf( |
| 54 "CompositingDisplayItem alpha: %d, xfermode: %d", alpha_, xfermode_)); | 53 "CompositingDisplayItem alpha: %d, xfermode: %d", alpha_, xfermode_)); |
| 55 if (has_bounds_) | 54 if (has_bounds_) |
| 56 array->AppendString(base::StringPrintf( | 55 array->AppendString(base::StringPrintf( |
| 57 ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_.x()), | 56 ", bounds: [%f, %f, %f, %f]", static_cast<float>(bounds_.x()), |
| 58 static_cast<float>(bounds_.y()), static_cast<float>(bounds_.width()), | 57 static_cast<float>(bounds_.y()), static_cast<float>(bounds_.width()), |
| 59 static_cast<float>(bounds_.height()))); | 58 static_cast<float>(bounds_.height()))); |
| 60 } | 59 } |
| 61 | 60 |
| 62 EndCompositingDisplayItem::EndCompositingDisplayItem() { | 61 EndCompositingDisplayItem::EndCompositingDisplayItem() { |
| 63 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, | 62 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, |
| 64 0 /* memory_usage */); | 63 0 /* external_memory_usage */); |
| 65 } | 64 } |
| 66 | 65 |
| 67 EndCompositingDisplayItem::~EndCompositingDisplayItem() { | 66 EndCompositingDisplayItem::~EndCompositingDisplayItem() { |
| 68 } | 67 } |
| 69 | 68 |
| 70 void EndCompositingDisplayItem::Raster( | 69 void EndCompositingDisplayItem::Raster( |
| 71 SkCanvas* canvas, | 70 SkCanvas* canvas, |
| 72 const gfx::Rect& canvas_target_playback_rect, | 71 const gfx::Rect& canvas_target_playback_rect, |
| 73 SkPicture::AbortCallback* callback) const { | 72 SkPicture::AbortCallback* callback) const { |
| 74 canvas->restore(); | 73 canvas->restore(); |
| 75 } | 74 } |
| 76 | 75 |
| 77 void EndCompositingDisplayItem::AsValueInto( | 76 void EndCompositingDisplayItem::AsValueInto( |
| 78 base::trace_event::TracedValue* array) const { | 77 base::trace_event::TracedValue* array) const { |
| 79 array->AppendString("EndCompositingDisplayItem"); | 78 array->AppendString("EndCompositingDisplayItem"); |
| 80 } | 79 } |
| 81 | 80 |
| 82 } // namespace cc | 81 } // namespace cc |
| OLD | NEW |