Flutter Engine
color_filter_layer.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 "flutter/flow/layers/color_filter_layer.h"
6 
7 namespace flutter {
8 
9 ColorFilterLayer::ColorFilterLayer(sk_sp<SkColorFilter> filter)
10  : filter_(std::move(filter)) {}
11 
12 #ifdef FLUTTER_ENABLE_DIFF_CONTEXT
13 
14 void ColorFilterLayer::Diff(DiffContext* context, const Layer* old_layer) {
15  DiffContext::AutoSubtreeRestore subtree(context);
16  auto* prev = static_cast<const ColorFilterLayer*>(old_layer);
17  if (!context->IsSubtreeDirty()) {
18  FML_DCHECK(prev);
19  if (filter_ != prev->filter_) {
20  context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
21  }
22  }
23 
24  DiffChildren(context, prev);
25 
26  context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
27 }
28 
29 #endif // FLUTTER_ENABLE_DIFF_CONTEXT
30 
32  const SkMatrix& matrix) {
35  ContainerLayer::Preroll(context, matrix);
36 }
37 
38 void ColorFilterLayer::Paint(PaintContext& context) const {
39  TRACE_EVENT0("flutter", "ColorFilterLayer::Paint");
40  FML_DCHECK(needs_painting(context));
41 
42  SkPaint paint;
43  paint.setColorFilter(filter_);
44 
46  Layer::AutoSaveLayer::Create(context, paint_bounds(), &paint);
47  PaintChildren(context);
48 }
49 
50 } // namespace flutter
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
#define FML_DCHECK(condition)
Definition: logging.h:86
Definition: ref_ptr.h:252
bool needs_painting(PaintContext &context) const
Definition: layer.h:249
void Paint(PaintContext &context) const override
ColorFilterLayer(sk_sp< SkColorFilter > filter)
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition: layer.cc:44
const SkRect & paint_bounds() const
Definition: layer.h:227
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
void PaintChildren(PaintContext &context) const
static AutoSaveLayer Create(const PaintContext &paint_context, const SkRect &bounds, const SkPaint *paint, SaveMode save_mode=SaveMode::kInternalNodesCanvas)
Definition: layer.cc:82