1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61

cc / paint / path_effect.h [blame]

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_PAINT_PATH_EFFECT_H_
#define CC_PAINT_PATH_EFFECT_H_

#include "cc/paint/paint_export.h"
#include "third_party/skia/include/core/SkRefCnt.h"

class SkPathEffect;

namespace cc {

class PaintOpWriter;
class PaintOpReader;

class CC_PAINT_EXPORT PathEffect : public SkRefCnt {
 public:
  PathEffect(const PathEffect&) = delete;
  PathEffect& operator=(const PathEffect&) = delete;

  static sk_sp<PathEffect> MakeDash(const float intervals[],
                                    int count,
                                    float phase);
  static sk_sp<PathEffect> MakeCorner(float radius);

  bool EqualsForTesting(const PathEffect& other) const;

  // If this is a Dash PathEffect, how many intervals are in the dash pattern?
  // Returns 0 for all other kinds of PathEffect.
  virtual size_t dash_interval_count() const;

 protected:
  friend class PaintFlags;
  friend class PaintOpReader;
  friend class PaintOpWriter;

  enum class Type {
    // kNull is for serialization purposes only, to indicate a null path effect
    // in a containing object (e.g. PaintFlags).
    kNull,
    kDash,
    kCorner,
    kMaxValue = kCorner,
  };

  virtual sk_sp<SkPathEffect> GetSkPathEffect() const = 0;

  explicit PathEffect(Type type);
  // These functions don't handle type_. It's handled in PaintOpWriter/Reader.
  virtual size_t SerializedDataSize() const = 0;
  virtual void SerializeData(PaintOpWriter& writer) const = 0;
  static sk_sp<PathEffect> Deserialize(PaintOpReader& reader, Type type);

  Type type_;
};

}  // namespace cc

#endif  // CC_PAINT_PATH_EFFECT_H_