layer.h 2.3 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 13
#include "flutter/flow/instrumentation.h"
#include "flutter/flow/raster_cache.h"
#include "flutter/glue/trace_event.h"
A
Adam Barth 已提交
14 15
#include "lib/ftl/logging.h"
#include "lib/ftl/macros.h"
16 17 18 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/SkRect.h"
#include "third_party/skia/include/core/SkRRect.h"
#include "third_party/skia/include/core/SkXfermode.h"

26 27 28 29 30 31 32 33 34
namespace mojo {
namespace gfx {
namespace composition {
class SceneUpdate;
class Node;
}  // composition
}  // namespace gfx
}  // namespace mojo

A
Adam Barth 已提交
35
namespace flow {
36

37
class ContainerLayer;
38 39 40 41 42
class Layer {
 public:
  Layer();
  virtual ~Layer();

43
  struct PrerollContext {
44 45
    RasterCache& raster_cache;
    GrContext* gr_context;
46 47 48 49
    SkRect child_paint_bounds;
  };

  virtual void Preroll(PrerollContext* context, const SkMatrix& matrix);
50 51 52 53 54 55 56 57

  struct PaintContext {
    SkCanvas& canvas;
    const Stopwatch& frame_time;
    const Stopwatch& engine_time;
  };

  virtual void Paint(PaintContext& context) = 0;
58 59 60
  virtual void UpdateScene(mojo::gfx::composition::SceneUpdate* update,
                           mojo::gfx::composition::Node* container);

61
  ContainerLayer* parent() const { return parent_; }
62

63 64
  void set_parent(ContainerLayer* parent) { parent_ = parent; }

H
Hixie 已提交
65
  // subclasses should assume this will be true by the time Paint() is called
66
  bool has_paint_bounds() const { return has_paint_bounds_; }
H
Hixie 已提交
67 68

  const SkRect& paint_bounds() const {
A
Adam Barth 已提交
69
    FTL_DCHECK(has_paint_bounds_);
H
Hixie 已提交
70 71
    return paint_bounds_;
  }
72 73

  void set_paint_bounds(const SkRect& paint_bounds) {
H
Hixie 已提交
74
    has_paint_bounds_ = true;
75 76
    paint_bounds_ = paint_bounds;
  }
77 78 79

 private:
  ContainerLayer* parent_;
A
Adam Barth 已提交
80
  bool has_paint_bounds_;  // if false, paint_bounds_ is not valid
81 82
  SkRect paint_bounds_;

A
Adam Barth 已提交
83
  FTL_DISALLOW_COPY_AND_ASSIGN(Layer);
84 85
};

A
Adam Barth 已提交
86
}  // namespace flow
87

88
#endif  // FLUTTER_FLOW_LAYERS_LAYER_H_