chromium/cc/paint/paint_op.h

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#ifndef CC_PAINT_PAINT_OP_H_
#define CC_PAINT_PAINT_OP_H_

#include <stdint.h>

#include <cmath>
#include <iosfwd>
#include <limits>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/debug/alias.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/notreached.h"
#include "cc/base/math_util.h"
#include "cc/paint/element_id.h"
#include "cc/paint/node_id.h"
#include "cc/paint/paint_canvas.h"
#include "cc/paint/paint_export.h"
#include "cc/paint/paint_filter.h"
#include "cc/paint/paint_flags.h"
#include "cc/paint/paint_record.h"
#include "cc/paint/refcounted_buffer.h"
#include "cc/paint/skottie_color_map.h"
#include "cc/paint/skottie_frame_data.h"
#include "cc/paint/skottie_resource_metadata.h"
#include "cc/paint/skottie_text_property_value.h"
#include "cc/paint/skottie_wrapper.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "third_party/skia/include/core/SkRRect.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkScalar.h"
#include "ui/gfx/display_color_spaces.h"
#include "ui/gfx/geometry/rect.h"

class SkImage;
class SkTextBlob;
namespace sktext::gpu {
class Slug;
}

namespace cc {

class DisplayItemList;
class PaintOpWriter;
class PaintOpReader;

class CC_PAINT_EXPORT ThreadsafePath : public SkPath {};

// See PaintOp::Serialize/Deserialize for comments.  Serialize() of derived
// types don't write the type/serialized_size header because they don't know how
// much data they will need to write. PaintOp::Serialize itself must update the
// header after calling Serialize() of the derived type.
#define HAS_SERIALIZATION_FUNCTIONS

enum class PaintOpType : uint8_t {};

CC_PAINT_EXPORT std::string PaintOpTypeToString(PaintOpType type);
CC_PAINT_EXPORT std::ostream& operator<<(std::ostream&, PaintOpType);

class CC_PAINT_EXPORT PaintOp {};

class CC_PAINT_EXPORT PaintOpWithFlags : public PaintOp {};

class CC_PAINT_EXPORT AnnotateOp final : public PaintOp {};

class CC_PAINT_EXPORT ClipPathOp final : public PaintOp {};

class CC_PAINT_EXPORT ClipRectOp final : public PaintOp {};

class CC_PAINT_EXPORT ClipRRectOp final : public PaintOp {};

class CC_PAINT_EXPORT ConcatOp final : public PaintOp {};

class CC_PAINT_EXPORT CustomDataOp final : public PaintOp {};

class CC_PAINT_EXPORT DrawColorOp final : public PaintOp {};

class CC_PAINT_EXPORT DrawDRRectOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT DrawImageOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT DrawImageRectOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT DrawIRectOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT DrawLineOp final : public PaintOpWithFlags {};

// TODO(crbug.com/340122178): figure out a better way to unify types.
class CC_PAINT_EXPORT DrawLineLiteOp final : public PaintOp {};

// TODO(crbug.com/340122178): figure out a better way to unify types.
class CC_PAINT_EXPORT DrawArcLiteOp final : public PaintOp {};

class CC_PAINT_EXPORT DrawArcOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT DrawOvalOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT DrawPathOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT DrawRecordOp final : public PaintOp {};

class CC_PAINT_EXPORT DrawRectOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT DrawRRectOp final : public PaintOpWithFlags {};

// This is used to draw non-composited scrolling contents. The display item
// list should contain painted results beyond the current scroll port like
// composited scrolling contents. During rasterization or serialization, the
// current clip of the canvas and the current scroll offset and will be applied
// to the display item list. This PaintOp doesn't apply the overflow clip of
// the scroller, but the client should emit ClipRectOp.
class CC_PAINT_EXPORT DrawScrollingContentsOp final : public PaintOp {};

class CC_PAINT_EXPORT DrawVerticesOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT DrawSkottieOp final : public PaintOp {};

class CC_PAINT_EXPORT DrawSlugOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT DrawTextBlobOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT NoopOp final : public PaintOp {};

class CC_PAINT_EXPORT RestoreOp final : public PaintOp {};

class CC_PAINT_EXPORT RotateOp final : public PaintOp {};

class CC_PAINT_EXPORT SaveOp final : public PaintOp {};

class CC_PAINT_EXPORT SaveLayerOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT SaveLayerAlphaOp final : public PaintOp {};

class CC_PAINT_EXPORT SaveLayerFiltersOp final : public PaintOpWithFlags {};

class CC_PAINT_EXPORT ScaleOp final : public PaintOp {};

class CC_PAINT_EXPORT SetMatrixOp final : public PaintOp {};

class CC_PAINT_EXPORT SetNodeIdOp final : public PaintOp {};

class CC_PAINT_EXPORT TranslateOp final : public PaintOp {};

#undef HAS_SERIALIZATION_FUNCTIONS

// TODO(vmpstr): Revisit this when sizes of DrawImageRectOp change.
LargestPaintOp;

// When allocating a buffer for deserialization of a single PaintOp, the buffer
// should be aligned as PaintOpBuffer::kPaintOpAlign, and the size should be
// kLargestPaintOpAlignedSize instead of sizeof(LargestPaintOp).
inline constexpr size_t kLargestPaintOpAlignedSize =;

// This is declared here for use in gtest-based unit tests but is defined in
// the //cc:test_support target. Depend on that to use this in your unit test.
// This should not be used in production code.
void PrintTo(const PaintOp& rect, std::ostream* os);

CC_PAINT_EXPORT bool AreLiteOpsEnabled();

}  // namespace cc

#endif  // CC_PAINT_PAINT_OP_H_