#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "cc/paint/paint_op_buffer.h"
#include <algorithm>
#include <array>
#include <string>
#include <vector>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "cc/paint/decoded_draw_image.h"
#include "cc/paint/display_item_list.h"
#include "cc/paint/draw_looper.h"
#include "cc/paint/image_provider.h"
#include "cc/paint/image_transfer_cache_entry.h"
#include "cc/paint/paint_filter.h"
#include "cc/paint/paint_flags.h"
#include "cc/paint/paint_image_builder.h"
#include "cc/paint/paint_op_buffer_iterator.h"
#include "cc/paint/paint_op_buffer_serializer.h"
#include "cc/paint/paint_op_reader.h"
#include "cc/paint/paint_op_writer.h"
#include "cc/paint/refcounted_buffer.h"
#include "cc/paint/shader_transfer_cache_entry.h"
#include "cc/paint/skottie_resource_metadata.h"
#include "cc/paint/skottie_text_property_value.h"
#include "cc/paint/skottie_wrapper.h"
#include "cc/paint/transfer_cache_entry.h"
#include "cc/test/lottie_test_data.h"
#include "cc/test/paint_op_matchers.h"
#include "cc/test/skia_common.h"
#include "cc/test/test_options_provider.h"
#include "cc/test/test_paint_worklet_input.h"
#include "cc/test/test_skcanvas.h"
#include "cc/test/transfer_cache_test_helper.h"
#include "skia/buildflags.h"
#include "skia/ext/font_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkBlendMode.h"
#include "third_party/skia/include/core/SkBlurTypes.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkClipOp.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkFont.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkSamplingOptions.h"
#include "third_party/skia/include/core/SkScalar.h"
#include "third_party/skia/include/core/SkTextBlob.h"
#include "third_party/skia/include/core/SkTileMode.h"
#include "third_party/skia/include/effects/SkColorMatrixFilter.h"
#include "third_party/skia/include/private/chromium/SkChromeRemoteGlyphCache.h"
#include "ui/gfx/geometry/test/geometry_util.h"
namespace cc {
namespace {
_;
AllOf;
AtLeast;
Contains;
Each;
ElementsAre;
Eq;
FloatEq;
InSequence;
Key;
Le;
Matcher;
Mock;
NiceMock;
NotNull;
Pointee;
ResultOf;
StrictMock;
static constexpr size_t kSerializedBytesPerOp = …;
static constexpr size_t kDefaultSerializedBufferSize = …;
std::unique_ptr<char, base::AlignedFreeDeleter> AllocateSerializedBuffer(
size_t size = kDefaultSerializedBufferSize) { … }
bool ReadAndValidateOpHeader(const void* memory,
size_t size,
uint8_t* op_type,
size_t* serialized_size) { … }
}
class PaintOpSerializationTestUtils { … };
TEST(PaintOpBufferTest, Empty) { … }
class PaintOpAppendTest : public ::testing::Test { … };
TEST_F(PaintOpAppendTest, SimpleAppend) { … }
TEST_F(PaintOpAppendTest, MoveThenDestruct) { … }
TEST_F(PaintOpAppendTest, MoveThenDestructOperatorEq) { … }
TEST_F(PaintOpAppendTest, MoveThenReappend) { … }
TEST_F(PaintOpAppendTest, MoveThenReappendOperatorEq) { … }
TEST(PaintOpBufferTest, SaveDrawRestore) { … }
TEST(PaintOpBufferTest, SaveDrawTextBlobRestore) { … }
TEST(PaintOpBufferTest, SaveSaveLayerFiltersRestore) { … }
TEST(PaintOpBufferTest, SaveDrawRestoreFail_BadFlags) { … }
TEST(PaintOpBufferTest, SaveDrawRestore_BadFlags255Alpha) { … }
TEST(PaintOpBufferTest, SaveDrawRestoreFail_TooManyOps) { … }
TEST(PaintOpBufferTest, SaveDrawRestore_SingleOpNotADrawOp) { … }
TEST(PaintOpBufferTest, SaveDrawRestore_SingleOpRecordWithSingleOp) { … }
TEST(PaintOpBufferTest, SaveDrawRestore_SingleOpRecordWithSingleNonDrawOp) { … }
TEST(PaintOpBufferTest, SaveLayerRestore_DrawColor) { … }
TEST(PaintOpBufferTest, DiscardableImagesTracking_EmptyBuffer) { … }
TEST(PaintOpBufferTest, DiscardableImagesTracking_NoImageOp) { … }
TEST(PaintOpBufferTest, DiscardableImagesTracking_DrawImage) { … }
TEST(PaintOpBufferTest, DiscardableImagesTracking_PaintWorkletImage) { … }
TEST(PaintOpBufferTest, DiscardableImagesTracking_PaintWorkletImageRect) { … }
TEST(PaintOpBufferTest, DiscardableImagesTracking_DrawImageRect) { … }
TEST(PaintOpBufferTest, DiscardableImagesTracking_OpWithFlags) { … }
TEST(PaintOpBufferTest, SlowPaths) { … }
TEST(PaintOpBufferTest, NonAAPaint) { … }
class PaintOpBufferOffsetsTest : public ::testing::Test { … };
TEST_F(PaintOpBufferOffsetsTest, EmptyClipRectShouldRejectAnOp) { … }
TEST_F(PaintOpBufferOffsetsTest, ContiguousIndices) { … }
TEST_F(PaintOpBufferOffsetsTest, NonContiguousIndices) { … }
TEST_F(PaintOpBufferOffsetsTest, FirstTwoIndices) { … }
TEST_F(PaintOpBufferOffsetsTest, MiddleIndex) { … }
TEST_F(PaintOpBufferOffsetsTest, LastTwoElements) { … }
TEST_F(PaintOpBufferOffsetsTest, ContiguousIndicesWithSaveLayerAlphaRestore) { … }
TEST_F(PaintOpBufferOffsetsTest,
NonContiguousIndicesWithSaveLayerAlphaRestore) { … }
TEST_F(PaintOpBufferOffsetsTest,
ContiguousIndicesWithSaveLayerAlphaDrawRestore) { … }
TEST_F(PaintOpBufferOffsetsTest,
NonContiguousIndicesWithSaveLayerAlphaDrawRestore) { … }
TEST(PaintOpBufferTest, SaveLayerAlphaDrawRestoreWithBadBlendMode) { … }
TEST(PaintOpBufferTest, UnmatchedSaveRestoreNoSideEffects) { … }
std::vector<float> test_floats = …;
std::vector<float> test_angles = …;
std::vector<uint8_t> test_uint8s = …;
static SkRect make_largest_skrect() { … }
static SkIRect make_largest_skirect() { … }
std::vector<SkRect> test_rects = …;
std::vector<SkRRect> test_rrects = …rrect = …;
std::vector<SkIRect> test_irects = …;
std::vector<uint32_t> test_ids = …;
std::vector<SkM44> test_matrices = …;
std::vector<SkPath> test_paths = …path;
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
path.lineTo(SkIntToScalar(30), SkIntToScalar(30));
path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
return path;
}(),
[] { … }(),
SkPath(),
};
std::vector<PaintFlags> test_flags = …flags;
flags.setColor(SK_ColorMAGENTA);
flags.setStrokeWidth(4.2f);
flags.setStrokeMiter(5.91f);
flags.setBlendMode(SkBlendMode::kDst);
flags.setStrokeCap(PaintFlags::kSquare_Cap);
flags.setStrokeJoin(PaintFlags::kBevel_Join);
flags.setStyle(PaintFlags::kStroke_Style);
flags.setFilterQuality(PaintFlags::FilterQuality::kMedium);
flags.setShader(PaintShader::MakeColor({ … }));
return flags;
}(),
[] { … }(),
[] { … }(),
[] { … }(),
[] { … }(),
[] { … }(),
PaintFlags(),
PaintFlags(),
};
std::vector<SkColor4f> test_colors = …;
std::vector<std::string> test_strings = …;
std::vector<std::vector<SkPoint>> test_point_arrays = …;
std::vector<PaintImage> test_images = …;
#if BUILDFLAG(SKIA_SUPPORT_SKOTTIE)
bool kIsSkottieSupported = …;
#else
bool kIsSkottieSupported = false;
#endif
class SimpleSerializer { … };
class DeserializerIterator { … };
void PushAnnotateOps(PaintOpBuffer* buffer) { … }
void PushClipPathOps(PaintOpBuffer* buffer) { … }
void PushClipRectOps(PaintOpBuffer* buffer) { … }
void PushClipRRectOps(PaintOpBuffer* buffer) { … }
void PushConcatOps(PaintOpBuffer* buffer) { … }
void PushCustomDataOps(PaintOpBuffer* buffer) { … }
void PushDrawColorOps(PaintOpBuffer* buffer) { … }
void PushDrawDRRectOps(PaintOpBuffer* buffer) { … }
void PushDrawImageOps(PaintOpBuffer* buffer) { … }
void PushDrawImageRectOps(PaintOpBuffer* buffer) { … }
void PushDrawIRectOps(PaintOpBuffer* buffer) { … }
void PushDrawLineOps(PaintOpBuffer* buffer) { … }
void PushDrawLineLiteOps(PaintOpBuffer* buffer) { … }
void PushDrawArcOps(PaintOpBuffer* buffer) { … }
void PushDrawArcLiteOps(PaintOpBuffer* buffer) { … }
void PushDrawOvalOps(PaintOpBuffer* buffer) { … }
void PushDrawPathOps(PaintOpBuffer* buffer) { … }
void PushDrawRectOps(PaintOpBuffer* buffer) { … }
void PushDrawRRectOps(PaintOpBuffer* buffer) { … }
void PushDrawVerticesOps(PaintOpBuffer* buffer) { … }
SkottieFrameDataMap GetTestImagesForSkottie(SkottieWrapper& skottie,
const SkRect& skottie_rect,
PaintFlags::FilterQuality quality,
float t) { … }
SkottieFrameDataMap GetNullImagesForSkottie(SkottieWrapper& skottie, float t) { … }
void PushDrawSkottieOps(PaintOpBuffer* buffer) { … }
void PushDrawTextBlobOps(PaintOpBuffer* buffer) { … }
void PushNoopOps(PaintOpBuffer* buffer) { … }
void PushRestoreOps(PaintOpBuffer* buffer) { … }
void PushRotateOps(PaintOpBuffer* buffer) { … }
void PushSaveOps(PaintOpBuffer* buffer) { … }
void PushSaveLayerOps(PaintOpBuffer* buffer) { … }
void PushSaveLayerAlphaOps(PaintOpBuffer* buffer) { … }
void PushSaveLayerFiltersOps(PaintOpBuffer* buffer) { … }
void PushScaleOps(PaintOpBuffer* buffer) { … }
void PushSetMatrixOps(PaintOpBuffer* buffer) { … }
void PushTranslateOps(PaintOpBuffer* buffer) { … }
void PushSetNodeIdOps(PaintOpBuffer* buffer) { … }
class PaintOpSerializationTest : public ::testing::TestWithParam<uint8_t> { … };
sk_sp<PaintOpBuffer> SerializeAndDeserialize(
const PaintOpBuffer& buffer,
const PaintOpBufferSerializer::Preamble* preamble = nullptr) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(PaintOpSerializationTest, SmokeTest) { … }
TEST_P(PaintOpSerializationTest, SerializationFailures) { … }
TEST_P(PaintOpSerializationTest, DeserializationFailures) { … }
TEST_P(PaintOpSerializationTest, UsesOverridenFlags) { … }
TEST(PaintOpSerializationTest, CompleteBufferSerialization) { … }
TEST(PaintOpSerializationTest, Preamble) { … }
TEST(PaintOpSerializationTest,
ConvertToDrawSlugWhenSerializationAndRasterization) { … }
TEST(PaintOpSerializationTest, SerializesNestedRecords) { … }
TEST(PaintOpBufferTest, ClipsImagesDuringSerialization) { … }
TEST(PaintOpBufferSerializationTest, AlphaFoldingDuringSerialization) { … }
TEST(PaintOpBufferTest, PaintOpDeserialize) { … }
TEST(PaintOpBufferTest, ValidateRects) { … }
TEST(PaintOpBufferTest, ValidateSkClip) { … }
TEST(PaintOpBufferTest, ValidateSkBlendMode) { … }
TEST(PaintOpBufferTest, BoundingRect_DrawImageOp) { … }
TEST(PaintOpBufferTest, BoundingRect_DrawImageRectOp) { … }
TEST(PaintOpBufferTest, BoundingRect_DrawIRectOp) { … }
TEST(PaintOpBufferTest, BoundingRect_DrawOvalOp) { … }
TEST(PaintOpBufferTest, BoundingRect_DrawPathOp) { … }
TEST(PaintOpBufferTest, BoundingRect_DrawRectOp) { … }
TEST(PaintOpBufferTest, BoundingRect_DrawArcOp) { … }
TEST(PaintOpBufferTest, BoundingRect_DrawRRectOp) { … }
TEST(PaintOpBufferTest, BoundingRect_DrawLineOp) { … }
TEST(PaintOpBufferTest, BoundingRect_DrawDRRectOp) { … }
TEST(PaintOpBufferTest, BoundingRect_DrawTextBlobOp) { … }
class MockImageProvider : public ImageProvider { … };
TEST(PaintOpBufferTest, SkipsOpsOutsideClip) { … }
TEST(PaintOpBufferTest, SkipsOpsWithFailedDecodes) { … }
MATCHER(NonLazyImage, "") { … }
MATCHER_P(MatchesPaintImage, paint_image, "") { … }
MATCHER_P2(MatchesRect, rect, scale, "") { … }
MATCHER_P(MatchesQuality, quality, "") { … }
MATCHER_P2(MatchesShader, flags, scale, "") { … }
TEST(PaintOpBufferTest, RasterPaintWorkletImageRectBasicCase) { … }
TEST(PaintOpBufferTest, RasterPaintWorkletImageRectTranslated) { … }
TEST(PaintOpBufferTest, RasterPaintWorkletImageRectScaled) { … }
TEST(PaintOpBufferTest, RasterPaintWorkletImageRectClipped) { … }
TEST(PaintOpBufferTest, ReplacesImagesFromProvider) { … }
TEST(PaintOpBufferTest, DrawImageRectOpWithLooperNoImageProvider) { … }
TEST(PaintOpBufferTest, DrawImageRectOpWithLooperWithImageProvider) { … }
TEST(PaintOpBufferTest, ReplacesImagesFromProviderOOP) { … }
class PaintFilterSerializationTest : public ::testing::TestWithParam<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(PaintFilterSerializationTest, Basic) { … }
TEST(PaintOpBufferTest, RecordPaintFilterDeserializationInvalidPaintOp) { … }
TEST(PaintOpBufferTest, PaintRecordShaderSerialization) { … }
#if BUILDFLAG(SKIA_SUPPORT_SKOTTIE)
TEST(PaintOpBufferTest, BoundingRect_DrawSkottieOp) { … }
TEST(PaintOpBufferTest,
DrawSkottieOpSerializationFailureFromUnPrivilegedProcess) { … }
TEST(PaintOpBufferTest, DrawSkottieOpRasterWithoutImageAssets) { … }
TEST(PaintOpBufferTest, DrawSkottieOpRasterWithNullImages) { … }
TEST(PaintOpBufferTest, DrawSkottieOpRasterWithoutImageProvider) { … }
TEST(PaintOpBufferTest, DrawSkottieOpRasterWithImageProvider) { … }
TEST(PaintOpBufferTest, DiscardableImagesTrackingSkottieOpNoImages) { … }
TEST(PaintOpBufferTest, DiscardableImagesTrackingSkottieOpWithImages) { … }
TEST(PaintOpBufferTest, OpHasDiscardableImagesSkottieOpNoImages) { … }
TEST(PaintOpBufferTest, OpHasDiscardableImagesSkottieOpWithImages) { … }
#endif
TEST(PaintOpBufferTest, CustomData) { … }
TEST(PaintOpBufferTest, SecurityConstrainedImageSerialization) { … }
TEST(PaintOpBufferTest, DrawImageRectSerializeScaledImages) { … }
TEST(PaintOpBufferTest, RecordShadersSerializeScaledImages) { … }
TEST(PaintOpBufferTest, RecordShadersCached) { … }
TEST(PaintOpBufferTest, RecordShadersCachedSize) { … }
TEST(PaintOpBufferTest, RecordFilterSerializeScaledImages) { … }
TEST(PaintOpBufferTest, TotalOpCount) { … }
TEST(PaintOpBufferTest, NullImages) { … }
TEST(PaintOpBufferTest, HasDrawOpsAndHasDrawTextOps) { … }
TEST(PaintOpBufferTest, HasEffectsPreventingLCDTextForSaveLayerAlpha) { … }
TEST(PaintOpBufferTest, NeedsAdditionalInvalidationForLCDText) { … }
TEST(PaintOpBufferTest, SetMatrixOpWithNonIdentityPlaybackParams) { … }
TEST(PaintOpBufferTest, PlaybackSetMatrixWithLocalCTM) { … }
TEST(PaintOpBufferTest, PlaybackSetMatrixWithNonLocalCTM) { … }
TEST(PaintOpBufferTest, PlaybackDrawRecordWithLocalCTM) { … }
TEST(PaintOpBufferTest, PlaybackDrawRecordWithNonLocalCTM) { … }
TEST(PaintOpBufferTest, PlaybackDrawRecordNestedLocalAndNonLocalCTM) { … }
TEST(PaintOpBufferTest, PlaybackDrawRecordNestedNonLocalAndNonLocalCTM) { … }
TEST(PaintOpBufferTest, PathCaching) { … }
TEST(PaintOpBufferTest, ShrinkToFit) { … }
TEST(PaintOpBufferTest, ReleaseAsRecord) { … }
TEST(IteratorTest, StlContainerLikeIterationTest) { … }
TEST(IteratorTest, IterationTest) { … }
TEST(IteratorTest, OffsetIterationTest) { … }
TEST(IteratorTest, CompositeIterationTest) { … }
TEST(IteratorTest, EqualityTest) { … }
TEST(IteratorTest, OffsetEqualityTest) { … }
TEST(IteratorTest, CompositeEqualityTest) { … }
TEST(IteratorTest, CompositeOffsetEqualityTest) { … }
TEST(IteratorTest, CompositeOffsetMixedTypeEqualityTest) { … }
TEST(IteratorTest, CompositeOffsetBoolCheck) { … }
TEST(IteratorTest, PlaybackFoldingIteratorEmptyDrawRecordInSaveLayerAlpha) { … }
TEST(PaintOpBufferTest, ContentColorUsageFromImages) { … }
TEST(PaintOpBufferTest, ContentColorUsageFromShader) { … }
TEST(PaintOpBufferTest, ContentColorUsageFromFilter) { … }
}