layer.h 3.8 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef FLUTTER_FLOW_LAYERS_LAYER_H_
#define FLUTTER_FLOW_LAYERS_LAYER_H_
7 8 9 10

#include <memory>
#include <vector>

11 12
#include "flutter/flow/instrumentation.h"
#include "flutter/flow/raster_cache.h"
13
#include "flutter/flow/texture.h"
14
#include "flutter/fml/build_config.h"
15
#include "flutter/fml/compiler_specific.h"
16 17
#include "flutter/fml/logging.h"
#include "flutter/fml/macros.h"
18
#include "flutter/fml/trace_event.h"
19 20 21 22 23 24 25
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkRRect.h"
26
#include "third_party/skia/include/core/SkRect.h"
27

28 29
#if defined(OS_FUCHSIA)

30
#include "flutter/flow/scene_update_context.h"  //nogncheck
31 32
#include "lib/ui/scenic/cpp/resources.h"        //nogncheck
#include "lib/ui/scenic/cpp/session.h"          //nogncheck
33 34 35

#endif  // defined(OS_FUCHSIA)

A
Adam Barth 已提交
36
namespace flow {
37

38
// This should be an exact copy of the Clip enum in painting.dart.
39
enum Clip { none, hardEdge, antiAlias, antiAliasWithSaveLayer };
40

41
class ContainerLayer;
42

43 44
// Represents a single composited layer. Created on the UI thread but then
// subquently used on the Rasterizer thread.
45 46 47 48 49
class Layer {
 public:
  Layer();
  virtual ~Layer();

50
  struct PrerollContext {
51
    RasterCache* raster_cache;
52
    GrContext* gr_context;
53
    SkColorSpace* dst_color_space;
54 55 56 57
    SkRect child_paint_bounds;
  };

  virtual void Preroll(PrerollContext* context, const SkMatrix& matrix);
58 59 60 61 62

  struct PaintContext {
    SkCanvas& canvas;
    const Stopwatch& frame_time;
    const Stopwatch& engine_time;
63
    TextureRegistry& texture_registry;
64 65 66 67 68 69 70
    const bool checkerboard_offscreen_layers;
  };

  // Calls SkCanvas::saveLayer and restores the layer upon destruction. Also
  // draws a checkerboard over the layer if that is enabled in the PaintContext.
  class AutoSaveLayer {
   public:
71 72 73 74 75 76 77 78 79 80 81 82
    FML_WARN_UNUSED_RESULT static AutoSaveLayer Create(
        const PaintContext& paint_context,
        const SkRect& bounds,
        const SkPaint* paint);

    FML_WARN_UNUSED_RESULT static AutoSaveLayer Create(
        const PaintContext& paint_context,
        const SkCanvas::SaveLayerRec& layer_rec);

    ~AutoSaveLayer();

   private:
83 84 85 86 87 88 89 90 91
    AutoSaveLayer(const PaintContext& paint_context,
                  const SkRect& bounds,
                  const SkPaint* paint);

    AutoSaveLayer(const PaintContext& paint_context,
                  const SkCanvas::SaveLayerRec& layer_rec);

    const PaintContext& paint_context_;
    const SkRect bounds_;
92 93
  };

94
  virtual void Paint(PaintContext& context) const = 0;
J
Jeff Brown 已提交
95 96

#if defined(OS_FUCHSIA)
97 98
  // Updates the system composited scene.
  virtual void UpdateScene(SceneUpdateContext& context);
J
Jeff Brown 已提交
99
#endif
100

101
  ContainerLayer* parent() const { return parent_; }
102

103 104
  void set_parent(ContainerLayer* parent) { parent_ = parent; }

105 106 107 108 109
  bool needs_system_composite() const { return needs_system_composite_; }
  void set_needs_system_composite(bool value) {
    needs_system_composite_ = value;
  }

110
  const SkRect& paint_bounds() const { return paint_bounds_; }
111

112 113
  // This must be set by the time Preroll() returns otherwise the layer will
  // be assumed to have empty paint bounds (paints no content).
114 115 116
  void set_paint_bounds(const SkRect& paint_bounds) {
    paint_bounds_ = paint_bounds;
  }
117

118 119
  bool needs_painting() const { return !paint_bounds_.isEmpty(); }

120 121
 private:
  ContainerLayer* parent_;
122
  bool needs_system_composite_;
123 124
  SkRect paint_bounds_;

125
  FML_DISALLOW_COPY_AND_ASSIGN(Layer);
126 127
};

A
Adam Barth 已提交
128
}  // namespace flow
129

130
#endif  // FLUTTER_FLOW_LAYERS_LAYER_H_