// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_PAINT_PREVIEW_COMMON_SERIALIZED_RECORDING_H_ #define COMPONENTS_PAINT_PREVIEW_COMMON_SERIALIZED_RECORDING_H_ #include <optional> #include "base/files/file.h" #include "base/gtest_prod_util.h" #include "base/unguessable_token.h" #include "components/paint_preview/common/mojom/paint_preview_types.mojom-shared.h" #include "components/paint_preview/common/serial_utils.h" #include "mojo/public/cpp/base/big_buffer.h" #include "mojo/public/cpp/bindings/union_traits.h" #include "third_party/skia/include/core/SkRefCnt.h" class SkPicture; namespace paint_preview { class PaintPreviewTracker; // Enumeration of strategies to store artifacts (i.e. frame recordings) of a // paint preview capture. enum class RecordingPersistence { … }; // Struct for containing an SkPicture and its deserialization context. struct SkpResult { … }; // This is an object that contains the serialized |SkPicture| that results from // a rendering frame recording. It will be backed by a value corresponding to // its |persistence_| value. // // The contents of a |SerializedRecording| must be generated by |RecordToFile| // or |RecordToBuffer| to be safely deserialized. class SerializedRecording { … }; // Serialize and write |skp| to |file|. // // If |max_size| is set, it is a limit on the total serialized size, else the // capture will be unrestricted in size. If |max_size| is exceeded the // serialization will fail. |serialized_size| will contain the size of the // serialized output. // // Returns |true| on success. bool RecordToFile(base::File file, sk_sp<const SkPicture> skp, PaintPreviewTracker* tracker, std::optional<size_t> max_capture_size, size_t* serialized_size); // Serialize and write |recording| to a memory buffer. // // If |max_size| is set, it is a limit on the total serialized size, else the // capture will be unrestricted in size. If |max_size| is exceeded the // serialization will fail. |serialized_size| will contain the size of the // serialized output. // // Returns the memory buffer on success. std::optional<mojo_base::BigBuffer> RecordToBuffer( sk_sp<const SkPicture> skp, PaintPreviewTracker* tracker, std::optional<size_t> max_capture_size, size_t* serialized_size); } // namespace paint_preview #endif // COMPONENTS_PAINT_PREVIEW_COMMON_SERIALIZED_RECORDING_H_