Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::testing Namespace Reference

Classes

class  BlendFilterContentsTest
 
struct  BlendModeSelection
 
struct  CheckSameSignature
 
struct  CheckSameSignature< Ret(Args...), Ret(Args...)>
 
struct  ColorBlendTestData
 
class  CompareFunctionUIData
 
struct  CVTest
 
struct  DiscardFrameBufferParams
 
class  FailingAllocator
 
class  FlushTestAllocator
 
class  FlushTestContentContext
 
class  FlushTestDeviceBuffer
 
struct  Foo
 
class  GaussianBlurFilterContentsTest
 
class  GoldenDigest
 Manages a global variable for tracking instances of golden images. More...
 
class  GoldenDigestManager
 
class  GoldenScreenshotter
 
class  GoldenTests
 
class  IMockGLESImpl
 
struct  MaskBlurTestConfig
 
class  MatrixFilterContentsTest
 
class  MetalGoldenScreenshotter
 
class  MetalScreenshot
 A screenshot that was produced from MetalScreenshotter. More...
 
class  MetalScreenshotter
 
class  MockAllocator
 
class  MockBlitPass
 
class  MockCapabilities
 
class  MockCommandBuffer
 
class  MockCommandQueue
 
class  MockDeviceBuffer
 
class  MockDeviceHolder
 
class  MockFence
 
class  MockGLES
 Provides a mocked version of the |ProcTableGLES| class. More...
 
class  MockGLESImpl
 
class  MockIdleWaiter
 
class  MockImpellerContext
 
class  MockPathVertexWriter
 
class  MockPipelineLibrary
 
class  MockRenderPass
 
class  MockSampler
 
class  MockSamplerLibrary
 
class  MockSegmentReceiver
 
class  MockTexture
 
class  MockVulkanContextBuilder
 
class  MockWorker
 
class  MorphologyFilterContentsTest
 
class  RecordingRenderPass
 
class  RendererDartTest
 
class  RenderPassGLESCommandTest
 
class  RenderPassGLESWithDiscardFrameBufferExtTest
 
struct  RWFoo
 
class  Screenshot
 
class  Screenshotter
 
class  TestAllocator
 
class  TestPipelineCompileQueue
 
class  TestReactorGLES
 
class  TestWorker
 
struct  TextRenderOptions
 
class  VulkanGoldenScreenshotter
 
class  VulkanScreenshotter
 
class  WorkingDirectory
 

Typedefs

using AiksTest = AiksPlaygroundWithGoldens
 
using DisplayListTest = DlPlayground
 
using HostBufferTest = EntityPlayground
 
using TextContentsTest = PlaygroundTest
 
using EntityTest = EntityPlayground
 
using EntityPassTargetTest = EntityPlayground
 
using RenderTargetCacheTest = EntityPlayground
 
using SaveLayerUtilsTest = ::testing::Test
 
using PipelineLibraryGLESTest = PlaygroundTest
 
using SurfaceGLESTest = PlaygroundTest
 
using TextureGLESTest = PlaygroundTest
 
using AllocatorMTLTest = PlaygroundTest
 
using ContextMTLTest = PlaygroundTest
 
using SwapchainTransientsMTLTest = PlaygroundTest
 
using DriverInfoVKTest = PlaygroundTest
 
using PipelineCacheDataVKPlaygroundTest = PlaygroundTest
 
using RendererTest = PlaygroundTest
 
using BlitPassTest = AiksTest
 
using ComputeTest = ComputePlaygroundTest
 
using DeviceBufferTest = Playground
 
using RendererGoldenTest = PlaygroundTestWithGoldens
 
using RuntimeStageTest = RuntimeStagePlayground
 
using TessellatorPlaygroundTest = PlaygroundTest
 
using TypographerTest = PlaygroundTest
 

Functions

 TEST (AllocationSizeTest, CanCreateTypedAllocations)
 
 TEST (AllocationSizeTest, CanCreateTypedAllocationsWithLiterals)
 
 TEST (AllocationSizeTest, CanConvert)
 
 TEST (AllocationSizeTest, ConversionsAreNonTruncating)
 
 TEST (AllocationSizeTest, CanGetFloatValues)
 
 TEST (AllocationSizeTest, RelationalOperatorsAreFunctional)
 
 TEST (AllocationSizeTest, CanCast)
 
 TEST (AllocationSizeTest, CanPerformSimpleArithmetic)
 
 TEST (AllocationSizeTest, CanConstructWithArith)
 
 TEST (AllocationTest, ReserveNPOTPotentialOverflow)
 
 TEST (AllocationTest, NextPowerOfTwoSize)
 
 TEST (ThreadTest, CanCreateMutex)
 
 TEST (ThreadTest, CanCreateMutexLock)
 
 TEST (ThreadTest, CanCreateRWMutex)
 
 TEST (ThreadTest, CanCreateRWMutexLock)
 
 TEST (ConditionVariableTest, WaitUntil)
 
 TEST (ConditionVariableTest, WaitFor)
 
 TEST (ConditionVariableTest, WaitForever)
 
 TEST (ConditionVariableTest, TestsCriticalSectionAfterWaitForUntil)
 
 TEST (ConditionVariableTest, TestsCriticalSectionAfterWait)
 
 TEST (BaseTest, NoExceptionPromiseValue)
 
 TEST (BaseTest, NoExceptionPromiseEmpty)
 
 TEST (BaseTest, CanUseTypedMasks)
 
 TEST (AllocatorTest, TextureDescriptorCompatibility)
 
 TEST (AllocatorTest, RangeTest)
 
 TEST (AllocatorTest, CompressedFormatClassification)
 
 TEST (AllocatorTest, CompressedFormatBlockMath)
 
 TEST (AllocatorTest, CompressedFormatRegionByteSizes)
 
 TEST (AllocatorTest, CompressedTextureDescriptorByteSizes)
 
 TEST (BufferViewTest, Empty)
 
 TEST (BufferViewTest, TakeRaw)
 
 TEST (SamplerDescriptorTest, ToKeyIncludesAllFields)
 
 TEST (ShaderTypesTest, VertexAttributeFormatFloat32)
 
 TEST (ShaderTypesTest, VertexAttributeFormatHalfFloat)
 
 TEST (ShaderTypesTest, VertexAttributeFormatIntegers)
 
 TEST (ShaderTypesTest, VertexAttributeFormatRejectsMatrices)
 
 TEST (ShaderTypesTest, VertexAttributeFormatRejectsBadComponentCount)
 
 TEST (ShaderTypesTest, VertexAttributeFormatRejectsBadBitWidth)
 
 TEST (ShaderTypesTest, VertexAttributeFormatRejectsUnsupportedScalarKinds)
 
 TEST_P (AiksTest, DrawAtlasNoColor)
 
 TEST_P (AiksTest, DrawAtlasWithColorAdvanced)
 
 TEST_P (AiksTest, DrawAtlasWithColorSimple)
 
 TEST_P (AiksTest, DrawAtlasWithOpacity)
 
 TEST_P (AiksTest, DrawAtlasNoColorFullSize)
 
 TEST_P (AiksTest, DrawAtlasAdvancedAndTransform)
 
 TEST_P (AiksTest, DrawAtlasWithColorAdvancedAndTransform)
 
 TEST_P (AiksTest, DrawAtlasPlusWideGamut)
 
 TEST_P (AiksTest, DlAtlasGeometryNoBlendRenamed)
 
 TEST_P (AiksTest, DlAtlasGeometryBlend)
 
 TEST_P (AiksTest, DlAtlasGeometryColorButNoBlend)
 
 TEST_P (AiksTest, DlAtlasGeometrySkip)
 
 TEST_P (AiksTest, DrawImageRectWithBlendColorFilter)
 
 TEST_P (AiksTest, DrawImageRectWithMatrixColorFilter)
 
 TEST_P (AiksTest, DrawAtlasWithColorBurn)
 
 TEST_P (AiksTest, CanRenderColoredRect)
 
 TEST_P (AiksTest, CanRenderColoredRectPrimitive)
 
 TEST_P (AiksTest, CanRenderWideStrokedRectWithoutOverlap)
 
 TEST_P (AiksTest, CanRenderWideStrokedRectPathWithoutOverlap)
 
 TEST_P (AiksTest, CanRenderImage)
 
 TEST_P (AiksTest, CanRenderInvertedImageWithColorFilter)
 
 TEST_P (AiksTest, CanRenderColorFilterWithInvertColors)
 
 TEST_P (AiksTest, CanRenderColorFilterWithInvertColorsDrawPaint)
 
 TEST_P (AiksTest, CanRenderTiledTextureClamp)
 
 TEST_P (AiksTest, CanRenderTiledTextureRepeat)
 
 TEST_P (AiksTest, CanRenderTiledTextureMirror)
 
 TEST_P (AiksTest, CanRenderTiledTextureDecal)
 
 TEST_P (AiksTest, CanRenderTiledTextureClampWithTranslate)
 
 TEST_P (AiksTest, CanRenderImageRect)
 
 TEST_P (AiksTest, DrawImageRectSrcOutsideBounds)
 
 TEST_P (AiksTest, CanRenderSimpleClips)
 
 TEST_P (AiksTest, CanSaveLayerStandalone)
 
 TEST_P (AiksTest, CanRenderDifferentShapesWithSameColorSource)
 
 TEST_P (AiksTest, CanRenderRoundedRectWithNonUniformRadii)
 
 TEST_P (AiksTest, CanRenderRoundedRectWithUniformRadii)
 
 TEST_P (AiksTest, CanDrawPaint)
 
 TEST_P (AiksTest, CanDrawPaintMultipleTimes)
 
 TEST_P (AiksTest, StrokedRectsRenderCorrectly)
 
 TEST_P (AiksTest, FilledCirclesRenderCorrectly)
 
 TEST_P (AiksTest, DrawThinStrokedCircle)
 
 TEST_P (AiksTest, StrokedCirclesRenderCorrectly)
 
 TEST_P (AiksTest, ZoomedStrokedPathRendersCorrectly)
 
 TEST_P (AiksTest, StrokedPathWithLargeStrokeWidthRendersCorrectly)
 
 TEST_P (AiksTest, FilledEllipsesRenderCorrectly)
 
 TEST_P (AiksTest, FilledArcsRenderCorrectly)
 
 TEST_P (AiksTest, TranslucentFilledArcsRenderCorrectly)
 
 TEST_P (AiksTest, FilledArcsRenderCorrectlyWithCenter)
 
 TEST_P (AiksTest, NonSquareFilledArcsRenderCorrectly)
 
 TEST_P (AiksTest, NonSquareFilledArcsRenderCorrectlyWithCenter)
 
 TEST_P (AiksTest, StrokedArcsRenderCorrectlyWithButtEnds)
 
 TEST_P (AiksTest, StrokedArcsRenderCorrectlyWithSquareEnds)
 
 TEST_P (AiksTest, StrokedArcsRenderCorrectlyWithTranslucencyAndSquareEnds)
 
 TEST_P (AiksTest, StrokedArcsRenderCorrectlyWithRoundEnds)
 
 TEST_P (AiksTest, StrokedArcsRenderCorrectlyWithTranslucencyAndRoundEnds)
 
 TEST_P (AiksTest, StrokedArcsRenderCorrectlyWithBevelJoinsAndCenter)
 
 TEST_P (AiksTest, StrokedArcsRenderCorrectlyWithMiterJoinsAndCenter)
 
 TEST_P (AiksTest, StrokedArcsRenderCorrectlyWithRoundJoinsAndCenter)
 
 TEST_P (AiksTest, StrokedArcsRenderCorrectlyWithSquareAndButtEnds)
 
 TEST_P (AiksTest, StrokedArcsRenderCorrectlyWithSquareAndButtAndRoundEnds)
 
 TEST_P (AiksTest, StrokedArcsCoverFullArcWithButtEnds)
 
 TEST_P (AiksTest, FilledRoundRectsRenderCorrectly)
 
 TEST_P (AiksTest, SolidColorCirclesOvalsRRectsMaskBlurCorrectly)
 
 TEST_P (AiksTest, CanRenderClippedBackdropFilter)
 
 TEST_P (AiksTest, CanDrawPerspectiveTransformWithClips)
 
 TEST_P (AiksTest, ImageColorSourceEffectTransform)
 
 TEST_P (AiksTest, SubpassWithClearColorOptimization)
 
 TEST_P (AiksTest, MatrixImageFilterDoesntCullWhenTranslatedFromOffscreen)
 
 TEST_P (AiksTest, MatrixImageFilterDoesntCullWhenScaledAndTranslatedFromOffscreen)
 
 TEST_P (AiksTest, ClearColorOptimizationWhenSubpassIsBiggerThanParentPass)
 
 TEST_P (AiksTest, EmptySaveLayerIgnoresPaint)
 
 TEST_P (AiksTest, EmptySaveLayerRendersWithClear)
 
 TEST_P (AiksTest, CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated)
 
 TEST_P (AiksTest, FormatWideGamut)
 
 TEST_P (AiksTest, FormatSRGB)
 
 TEST_P (AiksTest, CoordinateConversionsAreCorrect)
 
 TEST_P (AiksTest, CanPerformFullScreenMSAA)
 
 TEST_P (AiksTest, CanPerformSkew)
 
 TEST_P (AiksTest, CanPerformSaveLayerWithBounds)
 
 TEST_P (AiksTest, FilledRoundRectPathsRenderCorrectly)
 
 TEST_P (AiksTest, CoverageOriginShouldBeAccountedForInSubpasses)
 
 TEST_P (AiksTest, SaveLayerDrawsBehindSubsequentEntities)
 
 TEST_P (AiksTest, SiblingSaveLayerBoundsAreRespected)
 
 TEST_P (AiksTest, CanRenderClippedLayers)
 
 TEST_P (AiksTest, SaveLayerFiltersScaleWithTransform)
 
 TEST_P (AiksTest, FastEllipticalRRectMaskBlursRenderCorrectly)
 
 TEST_P (AiksTest, PipelineBlendSingleParameter)
 
 TEST_P (AiksTest, MassiveScalingMatrixImageFilter)
 
 TEST_P (AiksTest, NoDimplesInRRectPath)
 
 TEST_P (AiksTest, BackdropFilterOverUnclosedClip)
 
 TEST_P (AiksTest, PerspectiveRectangle)
 
 TEST_P (AiksTest, CanRenderFilledRoundSuperellipses)
 
 TEST_P (AiksTest, CanRenderAsymmetricRoundSuperellipses)
 
 TEST_P (AiksTest, CanRenderStrokedRoundSuperellipses)
 
 TEST_P (AiksTest, CanRenderSmallRadiusRoundSuperellipses)
 
 TEST_P (AiksTest, CanRenderThickStrokedRoundSuperellipses)
 
 TEST_P (AiksTest, CanRenderRoundSuperellipseGrid)
 
 TEST_P (AiksTest, CanRenderTransformedRoundSuperellipse)
 
 TEST_P (AiksTest, CompareAntiAliasAndNonAntiAlias)
 
 TEST_P (AiksTest, CompareDiffRoundRectAndRoundRect)
 
 TEST_P (AiksTest, CanRenderLinesWithCapsAnglesAndAlphas)
 
static BlendModeSelection GetBlendModeSelection ()
 
 TEST_P (AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
 
 TEST_P (AiksTest, BlendModeShouldCoverWholeScreen)
 
 TEST_P (AiksTest, CanDrawPaintWithAdvancedBlend)
 
 TEST_P (AiksTest, DrawPaintWithAdvancedBlendOverFilter)
 
 TEST_P (AiksTest, DrawAdvancedBlendPartlyOffscreen)
 
 TEST_P (AiksTest, PaintBlendModeIsRespected)
 
 TEST_P (AiksTest, ColorFilterBlend)
 
 TEST_P (AiksTest, ColorFilterAdvancedBlend)
 
 TEST_P (AiksTest, ColorFilterAdvancedBlendNoFbFetch)
 
 TEST_P (AiksTest, BlendModePlusAlphaWideGamut)
 
 TEST_P (AiksTest, BlendModePlusAlphaColorFilterWideGamut)
 
 TEST_P (AiksTest, ForegroundBlendSubpassCollapseOptimization)
 
 TEST_P (AiksTest, ClearBlend)
 
static sk_sp< DisplayListBlendModeTest (AiksTest *test, Vector2 content_scale, BlendMode blend_mode, const sk_sp< DlImageImpeller > &src_image, const sk_sp< DlImageImpeller > &dst_image, Scalar src_alpha)
 
 TEST_P (AiksTest, CanDrawPaintMultipleTimesInteractive)
 
 TEST_P (AiksTest, ForegroundPipelineBlendAppliesTransformCorrectly)
 
 TEST_P (AiksTest, ForegroundAdvancedBlendAppliesTransformCorrectly)
 
 TEST_P (AiksTest, FramebufferAdvancedBlendCoverage)
 
 TEST_P (AiksTest, ColorWheel)
 
 TEST_P (AiksTest, DestructiveBlendColorFilterFloodsClip)
 
 TEST_P (AiksTest, AdvancedBlendColorFilterWithDestinationOpacity)
 
 TEST_P (AiksTest, EmulatedAdvancedBlendRestore)
 
 TEST_P (AiksTest, SolidColorOvalsMaskBlurTinySigma)
 
sk_sp< flutter::DisplayListDoGradientOvalStrokeMaskBlur (Vector2 content_Scale, Scalar sigma, DlBlurStyle style)
 
 TEST_P (AiksTest, GradientOvalStrokeMaskBlur)
 
 TEST_P (AiksTest, GradientOvalStrokeMaskBlurSigmaZero)
 
 TEST_P (AiksTest, GradientOvalStrokeMaskBlurOuter)
 
 TEST_P (AiksTest, GradientOvalStrokeMaskBlurInner)
 
 TEST_P (AiksTest, GradientOvalStrokeMaskBlurSolid)
 
 TEST_P (AiksTest, SolidColorCircleMaskBlurTinySigma)
 
 TEST_P (AiksTest, CanRenderMaskBlurHugeSigma)
 
 TEST_P (AiksTest, CanRenderForegroundBlendWithMaskBlur)
 
 TEST_P (AiksTest, CanRenderForegroundAdvancedBlendWithMaskBlur)
 
 TEST_P (AiksTest, CanRenderBackdropBlurInteractive)
 
 TEST_P (AiksTest, CanRenderBackdropBlur)
 
 TEST_P (AiksTest, CanRenderBackdropBlurWithSingleBackdropId)
 
 TEST_P (AiksTest, CanRenderMultipleBackdropBlurWithSingleBackdropId)
 
 TEST_P (AiksTest, CanRenderMultipleBackdropBlurWithSingleBackdropIdAndDistinctFilters)
 
 TEST_P (AiksTest, CanRenderBackdropBlurHugeSigma)
 
 TEST_P (AiksTest, CanRenderBoundedBlur)
 
 TEST_P (AiksTest, CanRenderClippedBlur)
 
 TEST_P (AiksTest, ComposePaintBlurOuter)
 
 TEST_P (AiksTest, ComposePaintBlurInner)
 
 TEST_P (AiksTest, ClippedBlurFilterRendersCorrectlyInteractive)
 
 TEST_P (AiksTest, ClippedBlurFilterRendersCorrectly)
 
 TEST_P (AiksTest, ClearBlendWithBlur)
 
 TEST_P (AiksTest, BlurHasNoEdge)
 
 TEST_P (AiksTest, MaskBlurWithZeroSigmaIsSkipped)
 
 TEST_P (AiksTest, MaskBlurOnZeroDimensionIsSkippedWideGamut)
 
static sk_sp< DisplayListMaskBlurVariantTest (const AiksTest &test_context, const MaskBlurTestConfig &config)
 
 TEST_P (AiksTest, GaussianBlurStyleInner)
 
 TEST_P (AiksTest, GaussianBlurStyleOuter)
 
 TEST_P (AiksTest, GaussianBlurStyleSolid)
 
 TEST_P (AiksTest, MaskBlurTexture)
 
 TEST_P (AiksTest, MaskBlurDoesntStretchContents)
 
 TEST_P (AiksTest, GaussianBlurAtPeripheryVertical)
 
 TEST_P (AiksTest, GaussianBlurAtPeripheryHorizontal)
 
 TEST_P (AiksTest, GaussianBlurAnimatedBackdrop)
 
 TEST_P (AiksTest, GaussianBlurStyleInnerGradient)
 
 TEST_P (AiksTest, GaussianBlurStyleSolidGradient)
 
 TEST_P (AiksTest, GaussianBlurStyleOuterGradient)
 
 TEST_P (AiksTest, GaussianBlurScaledAndClipped)
 
 TEST_P (AiksTest, GaussianBlurRotatedAndClippedInteractive)
 
 TEST_P (AiksTest, GaussianBlurOneDimension)
 
 TEST_P (AiksTest, GaussianBlurRotatedAndClipped)
 
 TEST_P (AiksTest, GaussianBlurRotatedNonUniform)
 
 TEST_P (AiksTest, BlurredRectangleWithShader)
 
 TEST_P (AiksTest, GaussianBlurSolidColorTinyMipMap)
 
 TEST_P (AiksTest, GaussianBlurBackdropTinyMipMap)
 
 TEST_P (AiksTest, CanRenderMultipleBackdropBlurWithSingleBackdropIdDifferentLayers)
 
 TEST_P (AiksTest, BlurGradientWithOpacity)
 
 TEST_P (AiksTest, CanRenderNestedBackdropBlur)
 
 TEST_P (AiksTest, GaussianBlurFlipped)
 
 TEST_P (AiksTest, CanRenderNestedClips)
 
 TEST_P (AiksTest, CanRenderDifferenceClips)
 
 TEST_P (AiksTest, CanRenderWithContiguousClipRestores)
 
 TEST_P (AiksTest, ClipsUseCurrentTransform)
 
 TEST_P (AiksTest, FramebufferBlendsRespectClips)
 
 TEST_P (AiksTest, CanRenderLinearGradientClamp)
 
 TEST_P (AiksTest, CanRenderLinearGradientRepeat)
 
 TEST_P (AiksTest, CanRenderLinearGradientMirror)
 
 TEST_P (AiksTest, CanRenderLinearGradientDecal)
 
 TEST_P (AiksTest, CanRenderLinearGradientDecalWithColorFilter)
 
 TEST_P (AiksTest, CanRenderLinearGradientWithImageFilter)
 
static void CanRenderLinearGradientWithDithering (AiksTest *aiks_test)
 
 TEST_P (AiksTest, CanRenderLinearGradientWithDitheringEnabled)
 
static void CanRenderRadialGradientWithDithering (AiksTest *aiks_test)
 
 TEST_P (AiksTest, CanRenderRadialGradientWithDitheringEnabled)
 
static void CanRenderSweepGradientWithDithering (AiksTest *aiks_test)
 
 TEST_P (AiksTest, CanRenderSweepGradientWithDitheringEnabled)
 
static void CanRenderConicalGradientWithDithering (AiksTest *aiks_test)
 
 TEST_P (AiksTest, CanRenderConicalGradientWithDitheringEnabled)
 
 TEST_P (AiksTest, CanRenderLinearGradientWithOverlappingStopsClamp)
 
 TEST_P (AiksTest, CanRenderLinearGradientWithIncompleteStops)
 
 TEST_P (AiksTest, CanRenderRadialGradientWithIncompleteStops)
 
 TEST_P (AiksTest, CanRenderConicalGradientWithIncompleteStops)
 
 TEST_P (AiksTest, CanRenderSweepGradientWithIncompleteStops)
 
 TEST_P (AiksTest, CanRenderLinearGradientManyColorsClamp)
 
 TEST_P (AiksTest, CanRenderLinearGradientManyColorsRepeat)
 
 TEST_P (AiksTest, CanRenderLinearGradientManyColorsMirror)
 
 TEST_P (AiksTest, CanRenderLinearGradientManyColorsDecal)
 
 TEST_P (AiksTest, CanRenderLinearGradientWayManyColorsClamp)
 
 TEST_P (AiksTest, CanRenderLinearGradientManyColorsUnevenStops)
 
 TEST_P (AiksTest, CanRenderLinearGradientMaskBlur)
 
 TEST_P (AiksTest, CanRenderRadialGradient)
 
 TEST_P (AiksTest, CanRenderRadialGradientManyColors)
 
 TEST_P (AiksTest, CanRenderSweepGradientClamp)
 
 TEST_P (AiksTest, CanRenderSweepGradientRepeat)
 
 TEST_P (AiksTest, CanRenderSweepGradientMirror)
 
 TEST_P (AiksTest, CanRenderSweepGradientDecal)
 
 TEST_P (AiksTest, CanRenderSweepGradientManyColorsClamp)
 
 TEST_P (AiksTest, CanRenderSweepGradientManyColorsRepeat)
 
 TEST_P (AiksTest, CanRenderSweepGradientManyColorsMirror)
 
 TEST_P (AiksTest, CanRenderSweepGradientManyColorsDecal)
 
 TEST_P (AiksTest, CanRenderConicalGradient)
 
 TEST_P (AiksTest, CanRenderGradientDecalWithBackground)
 
 TEST_P (AiksTest, GradientStrokesRenderCorrectly)
 
 TEST_P (AiksTest, FastGradientTestHorizontal)
 
 TEST_P (AiksTest, FastGradientTestVertical)
 
 TEST_P (AiksTest, FastGradientTestHorizontalReversed)
 
 TEST_P (AiksTest, FastGradientTestVerticalReversed)
 
 TEST_P (AiksTest, VerifyNonOptimizedGradient)
 
 TEST_P (AiksTest, DrawOpacityPeephole)
 
 TEST_P (AiksTest, CanRenderGroupOpacity)
 
 TEST_P (AiksTest, CanRenderGroupOpacityToSavelayer)
 
 TEST_P (AiksTest, RotateColorFilteredPath)
 
 TEST_P (AiksTest, CanRenderStrokes)
 
 TEST_P (AiksTest, CanRenderCurvedStrokes)
 
 TEST_P (AiksTest, CanRenderThickCurvedStrokes)
 
 TEST_P (AiksTest, CanRenderThinCurvedStrokes)
 
 TEST_P (AiksTest, CanRenderStrokePathThatEndsAtSharpTurn)
 
 TEST_P (AiksTest, CanRenderStrokePathWithCubicLine)
 
 TEST_P (AiksTest, CanRenderQuadraticStrokeWithInstantTurn)
 
 TEST_P (AiksTest, CanRenderFilledConicPaths)
 
 TEST_P (AiksTest, CanRenderStrokedConicPaths)
 
 TEST_P (AiksTest, DrawLinesWithPath)
 
 TEST_P (AiksTest, DrawLinesWithDrawLine)
 
 TEST_P (AiksTest, DrawLinesWithFilledRects)
 
 TEST_P (AiksTest, DrawLinesWithFilledRoundRects)
 
 TEST_P (AiksTest, CanRenderTightConicPath)
 
 TEST_P (AiksTest, CanRenderDifferencePaths)
 
 TEST_P (AiksTest, CanDrawAnOpenPath)
 
 TEST_P (AiksTest, CanDrawAnOpenPathThatIsntARect)
 
 TEST_P (AiksTest, SolidStrokesRenderCorrectly)
 
 TEST_P (AiksTest, DrawLinesRenderCorrectly)
 
 TEST_P (AiksTest, DrawRectStrokesRenderCorrectly)
 
 TEST_P (AiksTest, DrawRectStrokesWithBevelJoinRenderCorrectly)
 
 TEST_P (AiksTest, CanDrawMultiContourConvexPath)
 
 TEST_P (AiksTest, ArcWithZeroSweepAndBlur)
 
 TEST_P (AiksTest, CanRenderClips)
 
 TEST_P (AiksTest, FatStrokeArc)
 
 TEST_P (AiksTest, CanRenderOverlappingMultiContourPath)
 
 TEST_P (AiksTest, TwoContourPathWithSinglePointContour)
 
 TEST_P (AiksTest, TwoContourPathWithConnectingLines)
 
 TEST_P (AiksTest, StrokeCapsAndJoins)
 
 TEST_P (AiksTest, BlurredCircleWithStrokeWidth)
 
 TEST_P (AiksTest, PrimitiveShapePlayground)
 
 TEST_P (AiksTest, CanRenderSkewedCircleHairline)
 
 TEST_P (AiksTest, CanRenderClippedRuntimeEffects)
 
 TEST_P (AiksTest, DrawPaintTransformsBounds)
 
 TEST_P (AiksTest, CanRenderRuntimeEffectFilter)
 
 TEST_P (AiksTest, RuntimeEffectWithInvalidSamplerDoesNotCrash)
 
 TEST_P (AiksTest, ComposePaintRuntimeOuter)
 
 TEST_P (AiksTest, ComposePaintRuntimeInner)
 
 TEST_P (AiksTest, ComposeBackdropRuntimeOuterBlurInner)
 
 TEST_P (AiksTest, ComposeBackdropRuntimeOuterBlurInnerSmallSigma)
 
 TEST_P (AiksTest, ClippedComposeBackdropRuntimeOuterBlurInnerSmallSigma)
 
 TEST_P (AiksTest, ClippedBackdropFilterWithShader)
 
 TEST_P (AiksTest, RuntimeEffectImageFilterRotated)
 
 TEST_P (AiksTest, RuntimeEffectVectorArray)
 
 TEST_P (AiksTest, DrawShadowDoesNotOptimizeHourglass)
 
 TEST_P (AiksTest, DrawShadowDoesNotOptimizeInnerOuterSpiral)
 
 TEST_P (AiksTest, DrawShadowDoesNotOptimizeOuterInnerSpiral)
 
 TEST_P (AiksTest, DrawShadowDoesNotOptimizeMultipleContours)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeClockwiseTriangle)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeCounterClockwiseTriangle)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeClockwiseRect)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeCounterClockwiseRect)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeClockwiseCircle)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeCounterClockwiseCircle)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeClockwiseOval)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeCounterClockwiseOval)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeClockwiseUniformRoundRect)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeCounterClockwiseUniformRoundRect)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeClockwiseMultiRadiiRoundRect)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeCounterClockwiseMultiRadiiRoundRect)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeClockwiseQuadratic)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeCounterClockwiseQuadratic)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeClockwiseConic)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeCounterClockwiseConic)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeClockwiseCubic)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeCounterClockwiseCubic)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeClockwiseOctagon)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeCounterClockwiseOctagon)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeWithExtraneousMoveTos)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeClockwiseWithExtraColinearVertices)
 
 TEST_P (AiksTest, DrawShadowCanOptimizeCounterClockwiseWithExtraColinearVertices)
 
 TEST_P (AiksTest, CanDrawPerspectiveConvexShadow)
 
 TEST_P (AiksTest, CanDrawRotatedConvexShadow)
 
 TEST_P (AiksTest, CanDrawNonuniformScaleConvexShadow)
 
bool RenderTextInCanvasSkia (const std::shared_ptr< Context > &context, DisplayListBuilder &canvas, const std::string &text, const std::string_view &font_fixture, const TextRenderOptions &options={}, const std::optional< SkFont > &font=std::nullopt)
 
 TEST_P (AiksTest, CanRenderTextFrame)
 
 TEST_P (AiksTest, CanRenderTextFrameWithInvertedTransform)
 
 TEST_P (AiksTest, CanRenderStrokedTextFrame)
 
 TEST_P (AiksTest, CanRenderTextStrokeWidth)
 
 TEST_P (AiksTest, CanRenderTextFrameWithHalfScaling)
 
 TEST_P (AiksTest, ScaledK)
 
 TEST_P (AiksTest, MassiveScaleConvertToPath)
 
 TEST_P (AiksTest, CanRenderTextFrameWithScalingOverflow)
 
 TEST_P (AiksTest, CanRenderTextFrameWithFractionScaling)
 
 TEST_P (AiksTest, TextRotated180Degrees)
 
 TEST_P (AiksTest, TextFrameSubpixelAlignment)
 
 TEST_P (AiksTest, CanRenderItalicizedText)
 
 TEST_P (AiksTest, CanRenderEmojiTextFrame)
 
 TEST_P (AiksTest, CanRenderEmojiTextFrameWithBlur)
 
 TEST_P (AiksTest, CanRenderEmojiTextFrameWithAlpha)
 
 TEST_P (AiksTest, CanRenderTextInSaveLayer)
 
 TEST_P (AiksTest, CanRenderTextOutsideBoundaries)
 
 TEST_P (AiksTest, TextRotated)
 
 TEST_P (AiksTest, DrawScaledTextWithPerspectiveNoSaveLayer)
 
 TEST_P (AiksTest, DrawScaledTextWithPerspectiveSaveLayer)
 
 TEST_P (AiksTest, CanRenderTextWithLargePerspectiveTransform)
 
 TEST_P (AiksTest, CanRenderTextWithPerspectiveTransformInSublist)
 
 TEST_P (AiksTest, TextForegroundShaderWithTransform)
 
 TEST_P (AiksTest, DifferenceClipsMustRenderIdenticallyAcrossBackends)
 
 TEST_P (AiksTest, TextContentsMismatchedTransformTest)
 
 TEST_P (AiksTest, CanRenderTextFrameWithThinLightAndDarkColors)
 
 TEST_P (AiksTest, TextWithShadowCache)
 
 TEST_P (AiksTest, MultipleTextWithShadowCache)
 
 TEST_P (AiksTest, MultipleColorWithShadowCache)
 
 TEST_P (AiksTest, SingleIconShadowTest)
 
 TEST_P (AiksTest, VarietyOfTextScalesShowingRasterAndPath)
 
 TEST_P (AiksTest, TextFramesDoNotShareRenderDataBigSmall)
 
 TEST_P (AiksTest, TextFramesDoNotShareRenderDataSmallBig)
 
 TEST_P (AiksTest, TextWithNonUniformScale)
 
 TEST_P (AiksTest, TextGammaCorrectionGoldenTest)
 
 TEST_P (AiksTest, TextWithShadowAndPosition)
 
 TEST_P (AiksTest, CollapsedDrawPaintInSubpass)
 
 TEST_P (AiksTest, CollapsedDrawPaintInSubpassBackdropFilter)
 
 TEST_P (AiksTest, ColorMatrixFilterSubpassCollapseOptimization)
 
 TEST_P (AiksTest, LinearToSrgbFilterSubpassCollapseOptimization)
 
 TEST_P (AiksTest, SrgbToLinearFilterSubpassCollapseOptimization)
 
 TEST_P (AiksTest, TranslucentSaveLayerDrawsCorrectly)
 
 TEST_P (AiksTest, TranslucentSaveLayerWithBlendColorFilterDrawsCorrectly)
 
 TEST_P (AiksTest, TranslucentSaveLayerWithBlendImageFilterDrawsCorrectly)
 
 TEST_P (AiksTest, TranslucentSaveLayerWithColorAndImageFilterDrawsCorrectly)
 
 TEST_P (AiksTest, ImageFilteredUnboundedSaveLayerWithUnboundedContents)
 
 TEST_P (AiksTest, TranslucentSaveLayerImageDrawsCorrectly)
 
 TEST_P (AiksTest, TranslucentSaveLayerWithColorMatrixColorFilterDrawsCorrectly)
 
 TEST_P (AiksTest, TranslucentSaveLayerWithColorMatrixImageFilterDrawsCorrectly)
 
 TEST_P (AiksTest, TranslucentSaveLayerWithColorFilterAndImageFilterDrawsCorrectly)
 
 TEST_P (AiksTest, TranslucentSaveLayerWithAdvancedBlendModeDrawsCorrectly)
 
 TEST_P (AiksTest, CanRenderTinyOverlappingSubpasses)
 
 TEST_P (AiksTest, CanRenderDestructiveSaveLayer)
 
 TEST_P (AiksTest, CanDrawPoints)
 
 TEST_P (AiksTest, CanDrawPointsWithTextureMap)
 
 TEST_P (AiksTest, MipmapGenerationWorksCorrectly)
 
 TEST_P (AiksTest, StrokedPathWithMoveToThenCloseDrawnCorrectly)
 
 TEST_P (AiksTest, SetContentsWithRegion)
 
 TEST_P (AiksTest, ReleasesTextureOnTeardown)
 
 TEST_P (AiksTest, MatrixImageFilterMagnify)
 
 TEST_P (AiksTest, ImageFilteredSaveLayerWithUnboundedContents)
 
 TEST_P (AiksTest, MatrixBackdropFilter)
 
 TEST_P (AiksTest, MatrixSaveLayerFilter)
 
 TEST_P (AiksTest, CanDrawScaledPointsSmallScaleLargeRadius)
 
 TEST_P (AiksTest, CanDrawScaledPointsLargeScaleSmallRadius)
 
 TEST_P (AiksTest, TransparentShadowProducesCorrectColor)
 
 TEST_P (AiksTest, DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists)
 
 TEST_P (AiksTest, BackdropRestoreUsesCorrectCoverageForFirstRestoredClip)
 
 TEST_P (AiksTest, CanPictureConvertToImage)
 
 TEST_P (AiksTest, CanEmptyPictureConvertToImage)
 
 TEST_P (AiksTest, DepthValuesForLineMode)
 
 TEST_P (AiksTest, DepthValuesForPolygonMode)
 
 TEST_P (AiksTest, ToImageFromImage)
 
 TEST_P (AiksTest, DisplayListToTextureAllocationFailure)
 
 TEST_P (AiksTest, DisplayListToTextureWithMipGeneration)
 
 TEST_P (AiksTest, VerticesGeometryUVPositionData)
 
 TEST_P (AiksTest, VerticesGeometryUVPositionDataWithTranslate)
 
 TEST_P (AiksTest, VerticesGeometryColorUVPositionData)
 
 TEST_P (AiksTest, VerticesGeometryColorUVPositionDataAdvancedBlend)
 
 TEST_P (AiksTest, CanConvertTriangleFanToTriangles)
 
 TEST_P (AiksTest, DrawVerticesSolidColorTrianglesWithoutIndices)
 
 TEST_P (AiksTest, DrawVerticesLinearGradientWithoutIndices)
 
 TEST_P (AiksTest, DrawVerticesLinearGradientWithTextureCoordinates)
 
 TEST_P (AiksTest, DrawVerticesImageSourceWithTextureCoordinates)
 
 TEST_P (AiksTest, DrawVerticesImageSourceWithTextureCoordinatesAndColorBlending)
 
 TEST_P (AiksTest, DrawVerticesSolidColorTrianglesWithIndices)
 
 TEST_P (AiksTest, DrawVerticesPremultipliesColors)
 
 TEST_P (AiksTest, DrawVerticesWithInvalidIndices)
 
 TEST_P (AiksTest, DrawVerticesTextureCoordinatesWithFragmentShader)
 
 TEST_P (AiksTest, DrawVerticesTextureCoordinatesWithFragmentShaderNonZeroOrigin)
 
 TEST_P (AiksTest, VerticesGeometryWithMaskFilter)
 
 INSTANTIATE_PLAYGROUND_SUITE (AiksTest)
 
std::unique_ptr< CanvasCreateTestCanvas (ContentContext &context, std::optional< Rect > cull_rect=std::nullopt, bool requires_readback=false)
 
 TEST_P (AiksTest, TransformMultipliesCorrectly)
 
 TEST_P (AiksTest, CanvasCanPushPopCTM)
 
 TEST_P (AiksTest, CanvasCTMCanBeUpdated)
 
 TEST_P (AiksTest, BackdropCountDownNormal)
 
 TEST_P (AiksTest, BackdropCountDownBackdropId)
 
 TEST_P (AiksTest, BackdropCountDownBackdropIdMixed)
 
 TEST_P (AiksTest, BackdropCountDownWithNestedSaveLayers)
 
 TEST_P (AiksTest, DrawVerticesLinearGradientWithEmptySize)
 
 TEST_P (AiksTest, DrawVerticesWithEmptyTextureCoordinates)
 
 TEST_P (AiksTest, SupportsBlitToOnscreen)
 
 TEST_P (AiksTest, RoundSuperellipseShadowComparison)
 
 TEST_P (AiksTest, ImageTextureCacheBehavesCorrectly)
 
 TEST_P (AiksTest, BlendModeCompatibilityWithSDFRendering)
 
 TEST (CanvasTest, NonAntialiasedPaintIncompatibleWithSDFRendering)
 
 TEST (CanvasTest, AntialiasedPaintCompatibleWithSDFRendering)
 
flutter::DlColor toColor (const float *components)
 
 INSTANTIATE_PLAYGROUND_SUITE (DisplayListTest)
 
 TEST_P (DisplayListTest, CanDrawRect)
 
 TEST_P (DisplayListTest, CanDrawTextBlob)
 
 TEST_P (DisplayListTest, CanDrawTextBlobWithGradient)
 
 TEST_P (DisplayListTest, CanDrawTextWithSaveLayer)
 
 TEST_P (DisplayListTest, CanDrawImage)
 
 TEST_P (DisplayListTest, CanDrawCapsAndJoins)
 
 TEST_P (DisplayListTest, CanDrawArc)
 
 TEST_P (DisplayListTest, StrokedPathsDrawCorrectly)
 
 TEST_P (DisplayListTest, CanDrawWithOddPathWinding)
 
 TEST_P (DisplayListTest, CanDrawAnOpenPath)
 
 TEST_P (DisplayListTest, CanDrawWithMaskBlur)
 
 TEST_P (DisplayListTest, CanDrawStrokedText)
 
 TEST_P (DisplayListTest, StrokedTextNotOffsetFromNormalText)
 
 TEST_P (DisplayListTest, IgnoreMaskFilterWhenSavingLayer)
 
 TEST_P (DisplayListTest, CanDrawWithBlendColorFilter)
 
 TEST_P (DisplayListTest, CanDrawWithColorFilterImageFilter)
 
 TEST_P (DisplayListTest, CanDrawWithImageBlurFilter)
 
 TEST_P (DisplayListTest, CanDrawWithComposeImageFilter)
 
 TEST_P (DisplayListTest, CanClampTheResultingColorOfColorMatrixFilter)
 
 TEST_P (DisplayListTest, CanDrawBackdropFilter)
 
 TEST_P (DisplayListTest, CanDrawBoundedBlur)
 
 TEST_P (DisplayListTest, CanDrawNinePatchImage)
 
 TEST_P (DisplayListTest, CanDrawNinePatchImageCenterWidthBiggerThanDest)
 
 TEST_P (DisplayListTest, CanDrawNinePatchImageCenterHeightBiggerThanDest)
 
 TEST_P (DisplayListTest, CanDrawNinePatchImageCenterBiggerThanDest)
 
 TEST_P (DisplayListTest, CanDrawNinePatchImageCornersScaledDown)
 
 TEST_P (DisplayListTest, NinePatchImagePrecision)
 
 TEST_P (DisplayListTest, NinePatchImageColorFilter)
 
 TEST_P (DisplayListTest, CanDrawPoints)
 
 TEST_P (DisplayListTest, CanDrawZeroLengthLine)
 
 TEST_P (DisplayListTest, CanDrawShadow)
 
 TEST_P (DisplayListTest, CanDrawZeroWidthLine)
 
 TEST_P (DisplayListTest, CanDrawWithMatrixFilter)
 
 TEST_P (DisplayListTest, CanDrawWithMatrixFilterWhenSavingLayer)
 
 TEST_P (DisplayListTest, CanDrawRectWithLinearToSrgbColorFilter)
 
 TEST_P (DisplayListTest, CanDrawPaintWithColorSource)
 
 TEST_P (DisplayListTest, CanBlendDstOverAndDstCorrectly)
 
 TEST_P (DisplayListTest, CanDrawCorrectlyWithColorFilterAndImageFilter)
 
 TEST_P (DisplayListTest, MaskBlursApplyCorrectlyToColorSources)
 
 TEST_P (DisplayListTest, DrawShapes)
 
 TEST_P (DisplayListTest, DrawCirclesWithTransformations)
 
 TEST_P (DisplayListTest, ClipDrawRRectWithNonCircularRadii)
 
 TEST_P (DisplayListTest, DrawVerticesBlendModes)
 
 TEST_P (DisplayListTest, DrawPaintIgnoresMaskFilter)
 
 TEST_P (DisplayListTest, DrawMaskBlursThatMightUseSaveLayers)
 
 TEST (PaintTest, OptionalStrokeWithFill)
 
 TEST (PaintTest, OptionalStrokeWithStroke)
 
 TEST (PaintTest, GradientStopConversion)
 
 TEST (PaintTest, GradientMissing0)
 
 TEST (PaintTest, GradientMissingLastValue)
 
 TEST (PaintTest, GradientStopGreaterThan1)
 
 TEST (PaintTest, GradientConversionNonMonotonic)
 
 TEST (SkiaConversionTest, ToSamplerDescriptor)
 
 TEST (SkiaConversionsTest, ToColor)
 
 TEST (EntityPassClipStackTest, CanPushAndPopEntities)
 
 TEST (EntityPassClipStackTest, CanPopEntitiesSafely)
 
 TEST (EntityPassClipStackTest, AppendAndRestoreClipCoverage)
 
 TEST (EntityPassClipStackTest, AppendAndRestoreClipCoverageNonAA)
 
 TEST (EntityPassClipStackTest, AppendLargerClipCoverage)
 
 TEST (EntityPassClipStackTest, AppendLargerClipCoverageWithDifferenceOrNonSquare)
 
 TEST (EntityPassClipStackTest, AppendDecreasingSizeClipCoverage)
 
 TEST (EntityPassClipStackTest, AppendIncreasingSizeClipCoverage)
 
 TEST (EntityPassClipStackTest, UnbalancedRestore)
 
 TEST (EntityPassClipStackTest, ClipAndRestoreWithSubpasses)
 
 TEST (EntityPassClipStackTest, ClipAndRestoreWithSubpassesNonAA)
 
 INSTANTIATE_PLAYGROUND_SUITE (BlendFilterContentsTest)
 
 TEST_P (BlendFilterContentsTest, AdvancedBlendColorAlignsColorTo4)
 
 INSTANTIATE_PLAYGROUND_SUITE (GaussianBlurFilterContentsTest)
 
 TEST (GaussianBlurFilterContentsTest, Create)
 
 TEST (GaussianBlurFilterContentsTest, CoverageEmpty)
 
 TEST (GaussianBlurFilterContentsTest, CoverageSimple)
 
 TEST (GaussianBlurFilterContentsTest, CoverageWithSigma)
 
 TEST_P (GaussianBlurFilterContentsTest, CoverageWithTexture)
 
 TEST_P (GaussianBlurFilterContentsTest, CoverageWithEffectTransform)
 
 TEST (GaussianBlurFilterContentsTest, FilterSourceCoverage)
 
 TEST (GaussianBlurFilterContentsTest, FilterSourceCoverageNegativeScale)
 
 TEST (GaussianBlurFilterContentsTest, CalculateSigmaValues)
 
 TEST_P (GaussianBlurFilterContentsTest, RenderCoverageMatchesGetCoverage)
 
 TEST_P (GaussianBlurFilterContentsTest, RenderCoverageMatchesGetCoverageTranslate)
 
 TEST_P (GaussianBlurFilterContentsTest, RenderCoverageMatchesGetCoverageRotated)
 
 TEST_P (GaussianBlurFilterContentsTest, CalculateUVsSimple)
 
 TEST_P (GaussianBlurFilterContentsTest, TextureContentsWithDestinationRect)
 
 TEST_P (GaussianBlurFilterContentsTest, TextureContentsWithDestinationRectScaled)
 
 TEST_P (GaussianBlurFilterContentsTest, TextureContentsWithEffectTransform)
 
 TEST (GaussianBlurFilterContentsTest, CalculateSigmaForBlurRadius)
 
 TEST (GaussianBlurFilterContentsTest, Coefficients)
 
 TEST (GaussianBlurFilterContentsTest, LerpHackKernelSamplesSimple)
 
 TEST (GaussianBlurFilterContentsTest, LerpHackKernelSamplesComplex)
 
 TEST (GaussianBlurFilterContentsTest, ChopHugeBlurs)
 
 TEST (FilterInputTest, CanSetLocalTransformForTexture)
 
 INSTANTIATE_PLAYGROUND_SUITE (MatrixFilterContentsTest)
 
 TEST (MatrixFilterContentsTest, CoverageEmpty)
 
 TEST (MatrixFilterContentsTest, CoverageSimple)
 
 TEST (MatrixFilterContentsTest, Coverage2x)
 
 TEST (MatrixFilterContentsTest, Coverage2xEffect)
 
 TEST_P (MatrixFilterContentsTest, RenderCoverageMatchesGetCoverageIdentity)
 
 TEST_P (MatrixFilterContentsTest, RenderCoverageMatchesGetCoverageTranslate)
 
 TEST_P (MatrixFilterContentsTest, RenderCoverageMatchesGetCoverageClippedSubpassTranslate)
 
 TEST_P (MatrixFilterContentsTest, RenderCoverageMatchesGetCoverageScale)
 
 TEST_P (MatrixFilterContentsTest, RenderCoverageMatchesGetCoverageClippedSubpassScale)
 
 TEST_P (MatrixFilterContentsTest, RenderCoverageMatchesGetCoverageSubpassScale)
 
 INSTANTIATE_PLAYGROUND_SUITE (MorphologyFilterContentsTest)
 
 TEST_P (MorphologyFilterContentsTest, RenderCoverageMatchesGetCoverage)
 
 TEST_P (MorphologyFilterContentsTest, RenderDilateWithFractionalCoverageIsSymmetric)
 
 TEST_P (MorphologyFilterContentsTest, RenderDilateYWithFractionalCoverageIsSymmetric)
 
 INSTANTIATE_PLAYGROUND_SUITE (HostBufferTest)
 
 TEST_P (HostBufferTest, IdleWaiter)
 
 TEST_P (HostBufferTest, CanEmplace)
 
 TEST_P (HostBufferTest, CanEmplaceWithAlignment)
 
 TEST_P (HostBufferTest, HostBufferInitialState)
 
 TEST_P (HostBufferTest, ResetIncrementsFrameCounter)
 
 TEST_P (HostBufferTest, EmplacingLargerThanBlockSizeCreatesOneOffBufferCallback)
 
 TEST_P (HostBufferTest, EmplacingLargerThanBlockSizeCreatesOneOffBuffer)
 
 TEST_P (HostBufferTest, UnusedBuffersAreDiscardedWhenResetting)
 
 TEST_P (HostBufferTest, EmplaceWithProcIsAligned)
 
 TEST (GpuSubmissionTrackerTest, WatermarkHandlesOutOfOrderCompletion)
 
 TEST_P (HostBufferTest, PendingEntriesAreReplacedNotReused)
 
 TEST_P (HostBufferTest, CompletedEntriesAreReusedWithoutTrackerChurn)
 
 TEST_P (HostBufferTest, EmplaceWithFailingAllocationDoesntCrash)
 
 INSTANTIATE_PLAYGROUND_SUITE (TextContentsTest)
 
 TEST_P (TextContentsTest, SimpleComputeVertexData)
 
 TEST_P (TextContentsTest, SimpleComputeVertexData2x)
 
 TEST_P (TextContentsTest, MaintainsShape)
 
 TEST_P (TextContentsTest, SimpleSubpixel)
 
 TEST_P (TextContentsTest, SimpleSubpixel3x)
 
 TEST_P (TextContentsTest, SimpleSubpixel26)
 
 TEST_P (TextContentsTest, SimpleSubpixel80)
 
 TEST_P (EntityTest, TiledTextureContentsRendersWithCorrectPipeline)
 
 TEST_P (EntityTest, TiledTextureContentsRendersWithCorrectPipelineExternalOES)
 
 TEST (UberSDFContentsTest, ApplyColorFilter)
 
 TEST (UberSDFContentsTest, AsBackgroundColor)
 
 TEST (UberSDFContentsTest, AsBackgroundColorExactSize)
 
 TEST (UberSDFContentsTest, AsBackgroundColorNonRect)
 
 TEST (UberSDFContentsTest, AsBackgroundColorStrokedRect)
 
 TEST (UberSDFParametersTest, MakeFillRect)
 
 TEST (UberSDFParametersTest, MakeStrokeRect)
 
 TEST (UberSDFParametersTest, MakeStrokeRectLowMiterLimitBecomesBevel)
 
 TEST (UberSDFParametersTest, MakeFillCircle)
 
 TEST (UberSDFParametersTest, MakeStrokeCircle)
 
 TEST (UberSDFParametersTest, MakeFillOval)
 
 TEST (UberSDFParametersTest, MakeStrokeOval)
 
 TEST (UberSDFParametersTest, MakeRoundedRect)
 
 TEST (UberSDFParametersTest, MakeRoundedSuperellipse)
 
 TEST (DrawOrderResolverTest, GetSortedDrawsReturnsCorrectOrderWithNoClips)
 
 TEST (DrawOrderResolverTest, GetSortedDrawsReturnsCorrectOrderWithClips)
 
 TEST (DrawOrderResolverTest, GetSortedDrawsRespectsSkipCounts)
 
 TEST (DrawOrderResolverTest, GetSortedDrawsReturnsCorrectOrderWithFlush)
 
 TEST_P (EntityPassTargetTest, SwapWithMSAATexture)
 
 TEST_P (EntityPassTargetTest, SwapWithMSAAImplicitResolve)
 
 TEST_P (EntityTest, CanCreateEntity)
 
 TEST_P (EntityTest, FilterCoverageRespectsCropRect)
 
 TEST_P (EntityTest, GeometryBoundsAreTransformed)
 
 TEST_P (EntityTest, ThreeStrokesInOnePath)
 
 TEST_P (EntityTest, StrokeWithTextureContents)
 
 TEST_P (EntityTest, TriangleInsideASquare)
 
 TEST_P (EntityTest, StrokeCapAndJoinTest)
 
 TEST_P (EntityTest, CubicCurveTest)
 
 TEST_P (EntityTest, CanDrawCorrectlyWithRotatedTransform)
 
 TEST_P (EntityTest, CubicCurveAndOverlapTest)
 
 TEST_P (EntityTest, SolidColorContentsStrokeSetStrokeCapsAndJoins)
 
 TEST_P (EntityTest, SolidColorContentsStrokeSetMiterLimit)
 
 TEST_P (EntityTest, BlendingModeOptions)
 
 TEST_P (EntityTest, BezierCircleScaled)
 
 TEST_P (EntityTest, Filters)
 
 TEST_P (EntityTest, GaussianBlurFilter)
 
 TEST_P (EntityTest, MorphologyFilter)
 
 TEST_P (EntityTest, SetBlendMode)
 
 TEST_P (EntityTest, ContentsGetBoundsForEmptyPathReturnsNullopt)
 
 TEST (EntityTest, UberSDFContentsCoverageFillRect)
 
 TEST (EntityTest, UberSDFContentsCoverageStrokeRect)
 
 TEST (EntityTest, UberSDFContentsCoverageFillCircle)
 
 TEST (EntityTest, UberSDFContentsCoverageStrokeCircle)
 
 TEST_P (EntityTest, SolidStrokeCoverageIsCorrect)
 
 TEST_P (EntityTest, BorderMaskBlurCoverageIsCorrect)
 
 TEST_P (EntityTest, SolidFillCoverageIsCorrect)
 
 TEST_P (EntityTest, RRectShadowTest)
 
 TEST_P (EntityTest, ColorMatrixFilterCoverageIsCorrect)
 
 TEST_P (EntityTest, ColorMatrixFilterEditable)
 
 TEST_P (EntityTest, LinearToSrgbFilterCoverageIsCorrect)
 
 TEST_P (EntityTest, LinearToSrgbFilter)
 
 TEST_P (EntityTest, SrgbToLinearFilterCoverageIsCorrect)
 
 TEST_P (EntityTest, SrgbToLinearFilter)
 
static Vector3 RGBToYUV (Vector3 rgb, YUVColorSpace yuv_color_space)
 
static std::vector< std::shared_ptr< Texture > > CreateTestYUVTextures (Context *context, YUVColorSpace yuv_color_space)
 
 TEST_P (EntityTest, YUVToRGBFilter)
 
 TEST_P (EntityTest, RuntimeEffect)
 
 TEST_P (EntityTest, RuntimeEffectCanSuccessfullyRender)
 
 TEST_P (EntityTest, RuntimeEffectCanPrecache)
 
 TEST_P (EntityTest, RuntimeEffectSetsRightSizeWhenUniformIsStruct)
 
 TEST_P (EntityTest, ColorFilterWithForegroundColorAdvancedBlend)
 
 TEST_P (EntityTest, ColorFilterWithForegroundColorClearBlend)
 
 TEST_P (EntityTest, ColorFilterWithForegroundColorSrcBlend)
 
 TEST_P (EntityTest, ColorFilterWithForegroundColorDstBlend)
 
 TEST_P (EntityTest, ColorFilterWithForegroundColorSrcInBlend)
 
 TEST_P (EntityTest, CoverageForStrokePathWithNegativeValuesInTransform)
 
 TEST_P (EntityTest, SolidColorContentsIsOpaque)
 
 TEST_P (EntityTest, ConicalGradientContentsIsOpaque)
 
 TEST_P (EntityTest, LinearGradientContentsIsOpaque)
 
 TEST_P (EntityTest, RadialGradientContentsIsOpaque)
 
 TEST_P (EntityTest, SweepGradientContentsIsOpaque)
 
 TEST_P (EntityTest, TiledTextureContentsIsOpaque)
 
 TEST_P (EntityTest, PointFieldGeometryCoverage)
 
 TEST_P (EntityTest, ColorFilterContentsWithLargeGeometry)
 
 TEST_P (EntityTest, TextContentsCeilsGlyphScaleToDecimal)
 
 TEST_P (EntityTest, SpecializationConstantsAreAppliedToVariants)
 
 TEST_P (EntityTest, DecalSpecializationAppliedToMorphologyFilter)
 
 TEST_P (EntityTest, ContentContextOptionsHasReasonableHashFunctions)
 
 TEST_P (EntityTest, FillPathGeometryGetPositionBufferReturnsExpectedMode)
 
 TEST_P (EntityTest, StrokeArcGeometryGetPositionBufferReturnsExpectedMode)
 
 TEST_P (EntityTest, FailOnValidationError)
 
 TEST_P (EntityTest, CanComputeGeometryForEmptyPathsWithoutCrashing)
 
 TEST_P (EntityTest, CanRenderEmptyPathsWithoutCrashing)
 
 TEST_P (EntityTest, DrawSuperEllipse)
 
 TEST_P (EntityTest, DrawRoundSuperEllipse)
 
 TEST_P (EntityTest, DrawRoundSuperEllipseWithLargeN)
 
 TEST_P (EntityTest, CanDrawRoundSuperEllipseWithTinyRadius)
 
 TEST_P (EntityTest, CanDrawRoundSuperEllipseWithJustEnoughRadius)
 
 TEST_P (EntityTest, SolidColorApplyColorFilter)
 
 APPLY_COLOR_FILTER_GRADIENT_TEST (Linear)
 
 APPLY_COLOR_FILTER_GRADIENT_TEST (Radial)
 
 APPLY_COLOR_FILTER_GRADIENT_TEST (Conical)
 
 APPLY_COLOR_FILTER_GRADIENT_TEST (Sweep)
 
 TEST_P (EntityTest, GiantStrokePathAllocation)
 
 TEST_P (EntityTest, RoundSuperellipseGetPositionBufferFlushes)
 
 TEST (EntityGeometryTest, RectGeometryCoversArea)
 
 TEST (EntityGeometryTest, UberSDFGeometryPaddingIsAdjustedByInverseMaxBasis)
 
 TEST (EntityGeometryTest, FillPathGeometryCoversArea)
 
 TEST (EntityGeometryTest, FillPathGeometryCoversAreaNoInnerRect)
 
 TEST (EntityGeometryTest, FillArcGeometryCoverage)
 
 TEST (EntityGeometryTest, StrokeArcGeometryCoverage)
 
 TEST (EntityGeometryTest, FillRoundRectGeometryCoversArea)
 
 TEST (EntityGeometryTest, LineGeometryCoverage)
 
 TEST (EntityGeometryTest, RoundRectGeometryCoversArea)
 
 TEST (EntityGeometryTest, GeometryResultHasReasonableDefaults)
 
 TEST (EntityGeometryTest, AlphaCoverageStrokePaths)
 
 TEST (EntityGeometryTest, SimpleTwoLineStrokeVerticesButtCap)
 
 TEST (EntityGeometryTest, SimpleTwoLineStrokeVerticesRoundCap)
 
 TEST (EntityGeometryTest, SimpleTwoLineStrokeVerticesSquareCap)
 
 TEST (EntityGeometryTest, TwoLineSegmentsRightTurnStrokeVerticesBevelJoin)
 
 TEST (EntityGeometryTest, TwoLineSegmentsLeftTurnStrokeVerticesBevelJoin)
 
 TEST (EntityGeometryTest, TwoLineSegmentsInDifferentContoursAreNotJoined)
 
 TEST (EntityGeometryTest, TwoLineSegmentsRightTurnStrokeVerticesMiterJoin)
 
 TEST (EntityGeometryTest, TwoLineSegmentsLeftTurnStrokeVerticesMiterJoin)
 
 TEST (EntityGeometryTest, TinyQuadGeneratesCaps)
 
 TEST (EntityGeometryTest, TinyConicGeneratesCaps)
 
 TEST (EntityGeometryTest, TinyCubicGeneratesCaps)
 
 TEST (EntityGeometryTest, TwoLineSegmentsMiterLimit)
 
 TEST (EntityGeometryTest, TwoLineSegments180DegreeJoins)
 
 TEST (EntityGeometryTest, TightQuadratic180DegreeJoins)
 
 TEST (EntityGeometryTest, TightConic180DegreeJoins)
 
 TEST (EntityGeometryTest, TightCubic180DegreeJoins)
 
 TEST (EntityGeometryTest, RotatedFilledCircleGeometryCoverage)
 
 TEST (EntityGeometryTest, RotatedStrokedCircleGeometryCoverage)
 
 TEST (ShadowPathGeometryTest, EmptyPathTest)
 
 TEST (ShadowPathGeometryTest, MoveToOnlyTest)
 
 TEST (ShadowPathGeometryTest, OnePathSegmentTest)
 
 TEST (ShadowPathGeometryTest, TwoColinearSegmentsTest)
 
 TEST (ShadowPathGeometryTest, EmptyRectTest)
 
 TEST (ShadowPathGeometryTest, GetAndTakeVertices)
 
 TEST (ShadowPathGeometryTest, ClockwiseTriangleTest)
 
 TEST (ShadowPathGeometryTest, CounterClockwiseTriangleTest)
 
 TEST (ShadowPathGeometryTest, ClockwiseRectTest)
 
 TEST (ShadowPathGeometryTest, CounterClockwiseRectTest)
 
 TEST (ShadowPathGeometryTest, ClockwiseRectExtraColinearPointsTest)
 
 TEST (ShadowPathGeometryTest, CounterClockwiseRectExtraColinearPointsTest)
 
 TEST (ShadowPathGeometryTest, ClockwiseRectTrickyColinearPointsTest)
 
 TEST (ShadowPathGeometryTest, CounterClockwiseRectTrickyColinearPointsTest)
 
 TEST (ShadowPathGeometryTest, ClockwiseRectTrickyDupColinearPointsTest)
 
 TEST (ShadowPathGeometryTest, CounterClockwiseRectTrickyDupColinearPointsTest)
 
 TEST (ShadowPathGeometryTest, ClockwiseRectNearlyColinearPointsTest)
 
 TEST (ShadowPathGeometryTest, CounterClockwiseRectNearlyColinearPointsTest)
 
 TEST (ShadowPathGeometryTest, ScaledRectTest)
 
 TEST (ShadowPathGeometryTest, EllipseTest)
 
 TEST (ShadowPathGeometryTest, RoundRectTest)
 
 TEST (ShadowPathGeometryTest, HourglassSelfIntersectingTest)
 
 TEST (ShadowPathGeometryTest, ReverseHourglassSelfIntersectingTest)
 
 TEST (ShadowPathGeometryTest, InnerToOuterOverturningSpiralTest)
 
 TEST (ShadowPathGeometryTest, ReverseInnerToOuterOverturningSpiralTest)
 
 TEST (ShadowPathGeometryTest, OuterToInnerOverturningSpiralTest)
 
 TEST (ShadowPathGeometryTest, ReverseOuterToInnerOverturningSpiralTest)
 
 TEST (ShadowPathGeometryTest, ClockwiseOctagonCollapsedUmbraPolygonTest)
 
 TEST (ShadowPathGeometryTest, CounterClockwiseOctagonCollapsedUmbraPolygonTest)
 
 TEST (ShadowPathGeometryTest, MultipleContoursTest)
 
 TEST_P (RenderTargetCacheTest, CachesUsedTexturesAcrossFrames)
 
 TEST_P (RenderTargetCacheTest, CachesUsedTexturesAcrossFramesWithKeepAlive)
 
 TEST_P (RenderTargetCacheTest, DoesNotPersistFailedAllocations)
 
 TEST_P (RenderTargetCacheTest, CachedTextureGetsNewAttachmentConfig)
 
 TEST_P (RenderTargetCacheTest, CreateWithEmptySize)
 
 TEST (SaveLayerUtilsTest, SimplePaintComputedCoverage)
 
 TEST (SaveLayerUtilsTest, BackdropFiterComputedCoverage)
 
 TEST (SaveLayerUtilsTest, ImageFiterComputedCoverage)
 
 TEST (SaveLayerUtilsTest, ImageFiterSmallScaleComputedCoverageLargerThanBoundsLimit)
 
 TEST (SaveLayerUtilsTest, ImageFiterLargeScaleComputedCoverageLargerThanBoundsLimit)
 
 TEST (SaveLayerUtilsTest, DisjointCoverage)
 
 TEST (SaveLayerUtilsTest, DisjointCoverageTransformedByImageFilter)
 
 TEST (SaveLayerUtilsTest, DisjointCoveragTransformedByCTM)
 
 TEST (SaveLayerUtilsTest, BasicEmptyCoverage)
 
 TEST (SaveLayerUtilsTest, ImageFilterEmptyCoverage)
 
 TEST (SaveLayerUtilsTest, BackdropFilterEmptyCoverage)
 
 TEST (SaveLayerUtilsTest, FloodInputCoverage)
 
 TEST (SaveLayerUtilsTest, FloodInputCoverageWithImageFilter)
 
 TEST (SaveLayerUtilsTest, FloodInputCoverageWithImageFilterWithNoCoverageProducesNoCoverage)
 
 TEST (SaveLayerUtilsTest, CoverageLimitIgnoredIfIntersectedValueIsCloseToActualCoverageSmallerWithImageFilter)
 
 TEST (SaveLayerUtilsTest, CoverageLimitIgnoredIfIntersectedValueIsCloseToActualCoverageLargerWithImageFilter)
 
 TEST (SaveLayerUtilsTest, CoverageLimitRespectedIfSubstantiallyDifferentFromContentCoverage)
 
 TEST (SaveLayerUtilsTest, RoundUpCoverageWhenCloseToCoverageLimit)
 
 TEST (SaveLayerUtilsTest, DontRoundUpCoverageWhenNotCloseToCoverageLimitWidth)
 
 TEST (SaveLayerUtilsTest, DontRoundUpCoverageWhenNotCloseToCoverageLimitHeight)
 
 TEST (SaveLayerUtilsTest, DontRoundUpCoverageWhenNotCloseToCoverageLimitWidthHeight)
 
 TEST (ArcTest, ArcIterationsFullCircle)
 
 TEST (ArcTest, ArcIterationsVariousStartAnglesNearQuadrantAxis)
 
 TEST (ArcTest, ArcIterationsVariousEndAnglesNearQuadrantAxis)
 
 TEST (ArcTest, ArcIterationsVariousTinyArcsNearQuadrantAxis)
 
 TEST (ArcTest, ArcIterationsOnlyFirstQuadrant)
 
 TEST (ArcTest, ArcIterationsOnlySecondQuadrant)
 
 TEST (ArcTest, ArcIterationsOnlyThirdQuadrant)
 
 TEST (ArcTest, ArcIterationsOnlyFourthQuadrant)
 
 TEST (ArcTest, ArcIterationsAllQuadrantsFromFirst)
 
 TEST (ArcTest, ArcIterationsAllQuadrantsFromSecond)
 
 TEST (ArcTest, ArcIterationsAllQuadrantsFromThird)
 
 TEST (ArcTest, ArcIterationsAllQuadrantsFromFourth)
 
 TEST (GeometryTest, ScalarNearlyEqual)
 
 TEST (GeometryTest, MakeColumn)
 
 TEST (GeometryTest, MakeRow)
 
 TEST (GeometryTest, RotationMatrix)
 
 TEST (GeometryTest, InvertMultMatrix)
 
 TEST (GeometryTest, MatrixBasis)
 
 TEST (GeometryTest, MutliplicationMatrix)
 
 TEST (GeometryTest, DeterminantTest)
 
 TEST (GeometryTest, InvertMatrix)
 
 TEST (GeometryTest, TestDecomposition)
 
 TEST (GeometryTest, TestDecomposition2)
 
 TEST (GeometryTest, TestRecomposition)
 
 TEST (GeometryTest, TestRecomposition2)
 
 TEST (GeometryTest, MatrixVectorMultiplication)
 
 TEST (GeometryTest, MatrixMakeRotationFromQuaternion)
 
 TEST (GeometryTest, MatrixTransformDirection)
 
 TEST (GeometryTest, MatrixGetMaxBasisLengthXY)
 
 TEST (GeometryTest, MatrixMakeOrthographic)
 
 TEST (GeometryTest, MatrixMakePerspective)
 
 TEST (GeometryTest, MatrixGetBasisVectors)
 
 TEST (GeometryTest, MatrixGetDirectionScale)
 
 TEST (GeometryTest, MatrixTranslationScaleOnly)
 
 TEST (GeometryTest, MatrixLookAt)
 
 TEST (GeometryTest, QuaternionLerp)
 
 TEST (GeometryTest, QuaternionVectorMultiply)
 
 TEST (GeometryTest, CanGenerateMipCounts)
 
 TEST (GeometryTest, CanConvertTTypesExplicitly)
 
 TEST (GeometryTest, CanPerformAlgebraicPointOps)
 
 TEST (GeometryTest, CanPerformAlgebraicPointOpsWithArithmeticTypes)
 
 TEST (GeometryTest, PointIntegerCoercesToFloat)
 
 TEST (GeometryTest, SizeCoercesToPoint)
 
 TEST (GeometryTest, CanUsePointAssignmentOperators)
 
 TEST (GeometryTest, PointDotProduct)
 
 TEST (GeometryTest, PointCrossProduct)
 
 TEST (GeometryTest, PointReflect)
 
 TEST (GeometryTest, PointAbs)
 
 TEST (GeometryTest, PointRotate)
 
 TEST (GeometryTest, PointAngleTo)
 
 TEST (GeometryTest, PointMin)
 
 TEST (GeometryTest, Vector4IsFinite)
 
 TEST (GeometryTest, Vector3Min)
 
 TEST (GeometryTest, Vector4Min)
 
 TEST (GeometryTest, PointMax)
 
 TEST (GeometryTest, Vector3Max)
 
 TEST (GeometryTest, Vector4Max)
 
 TEST (GeometryTest, PointFloor)
 
 TEST (GeometryTest, Vector3Floor)
 
 TEST (GeometryTest, Vector4Floor)
 
 TEST (GeometryTest, PointCeil)
 
 TEST (GeometryTest, Vector3Ceil)
 
 TEST (GeometryTest, Vector4Ceil)
 
 TEST (GeometryTest, PointRound)
 
 TEST (GeometryTest, Vector3Round)
 
 TEST (GeometryTest, Vector4Round)
 
 TEST (GeometryTest, PointLerp)
 
 TEST (GeometryTest, Vector3Lerp)
 
 TEST (GeometryTest, Vector4Lerp)
 
 TEST (GeometryTest, SeparatedVector2NormalizesWithConstructor)
 
 TEST (GeometryTest, SeparatedVector2GetVector)
 
 TEST (GeometryTest, SeparatedVector2GetAlignment)
 
 TEST (GeometryTest, SeparatedVector2AngleTo)
 
 TEST (GeometryTest, CanUseVector3AssignmentOperators)
 
 TEST (GeometryTest, CanPerformAlgebraicVector3Ops)
 
 TEST (GeometryTest, CanPerformAlgebraicVector3OpsWithArithmeticTypes)
 
 TEST (GeometryTest, ColorPremultiply)
 
 TEST (GeometryTest, ColorR8G8B8A8)
 
 TEST (GeometryTest, ColorLerp)
 
 TEST (GeometryTest, ColorClamp01)
 
 TEST (GeometryTest, ColorMakeRGBA8)
 
 TEST (GeometryTest, ColorApplyColorMatrix)
 
 TEST (GeometryTest, ColorLinearToSRGB)
 
 TEST (GeometryTest, ColorSRGBToLinear)
 
 TEST (GeometryTest, ColorBlendReturnsExpectedResults)
 
 TEST (GeometryTest, BlendModeToString)
 
 TEST (GeometryTest, CanConvertBetweenDegressAndRadians)
 
 TEST (GeometryTest, MatrixPrinting)
 
 TEST (GeometryTest, PointPrinting)
 
 TEST (GeometryTest, Vector3Printing)
 
 TEST (GeometryTest, Vector4Printing)
 
 TEST (GeometryTest, ColorPrinting)
 
 TEST (GeometryTest, ToIColor)
 
 TEST (GeometryTest, Gradient)
 
 TEST (GeometryTest, HalfConversions)
 
 TEST (MatrixTest, Multiply)
 
 TEST (MatrixTest, Equals)
 
 TEST (MatrixTest, NotEquals)
 
 TEST (MatrixTest, HasPerspective2D)
 
 TEST (MatrixTest, HasPerspective)
 
 TEST (MatrixTest, HasTranslation)
 
 TEST (MatrixTest, IsTranslationOnly)
 
 TEST (MatrixTest, IsTranslationScaleOnly)
 
 TEST (MatrixTest, IsInvertibleGetDeterminant)
 
 TEST (MatrixTest, IsFinite)
 
 TEST (MatrixTest, IsAligned2D)
 
 TEST (MatrixTest, IsAligned)
 
 TEST (MatrixTest, TransformHomogenous)
 
 TEST (MatrixTest, GetMaxBasisXYNegativeScale)
 
 TEST (MatrixTest, GetMaxBasisXYWithLargeAndSmallScalingFactor)
 
 TEST (MatrixTest, GetMaxBasisXYWithLargeAndSmallScalingFactorNonScaleTranslate)
 
 TEST (MatrixTest, GetBasisXYScale2D)
 
 TEST (MatrixTest, TranslateWithPerspective)
 
 TEST (MatrixTest, MakeScaleTranslate)
 
 TEST (MatrixTest, To3x3)
 
 TEST (MatrixTest, MinMaxScales2D)
 
 TEST (PathSourceTest, RectSourceTest)
 
 TEST (PathSourceTest, EllipseSourceTest)
 
 TEST (PathSourceTest, RoundRectSourceTest)
 
 TEST (PathSourceTest, DiffRoundRectSourceTest)
 
 TEST (PathSourceTest, DashedLinePathSource)
 
 TEST (PathSourceTest, EmptyDashedLinePathSource)
 
 TEST (PathSourceTest, DashedLinePathSourceZeroOffGaps)
 
 TEST (PathSourceTest, DashedLinePathSourceInvalidOffGaps)
 
 TEST (PathSourceTest, DashedLinePathSourceInvalidOnRegion)
 
 TEST (PathSourceTest, PathTransformerRectSourceTest)
 
 TEST (PathSourceTest, PathTransformerAllSegmentsTest)
 
 TEST (PointTest, Length)
 
 TEST (PointTest, Distance)
 
 TEST (PointTest, PerpendicularLeft)
 
 TEST (PointTest, PerpendicularRight)
 
 TEST (PointTest, PointToSegment)
 
 TEST (PointTest, CrossProductThreePoints)
 
 TEST (RectTest, RectEmptyDeclaration)
 
 TEST (RectTest, IRectEmptyDeclaration)
 
 TEST (RectTest, RectDefaultConstructor)
 
 TEST (RectTest, IRectDefaultConstructor)
 
 TEST (RectTest, RectSimpleLTRB)
 
 TEST (RectTest, IRectSimpleLTRB)
 
 TEST (RectTest, RectSimpleXYWH)
 
 TEST (RectTest, IRectSimpleXYWH)
 
 TEST (RectTest, RectSimpleWH)
 
 TEST (RectTest, IRectSimpleWH)
 
 TEST (RectTest, RectFromIRect)
 
 TEST (RectTest, RectMakeCircleBounds)
 
 TEST (RectTest, RectMakeCircleBoundsNegativeRadius)
 
 TEST (RectTest, IRectMakeCircleBounds)
 
 TEST (RectTest, IRectMakeCircleBoundsNegativeRadius)
 
 TEST (RectTest, RectMakeEllipseBoundsSize)
 
 TEST (RectTest, RectMakeEllipseBoundsNegativeSize)
 
 TEST (RectTest, RectMakeEllipseBoundsPoint)
 
 TEST (RectTest, RectMakeEllipseBoundsNegativePoint)
 
 TEST (RectTest, IRectMakeEllipseBoundsSize)
 
 TEST (RectTest, IRectMakeEllipseBoundsNegativeSize)
 
 TEST (RectTest, IRectMakeEllipseBoundsPoint)
 
 TEST (RectTest, IRectMakeEllipseBoundsNegativePoint)
 
 TEST (RectTest, RectOverflowXYWH)
 
 TEST (RectTest, IRectOverflowXYWH)
 
 TEST (RectTest, RectOverflowLTRB)
 
 TEST (RectTest, IRectOverflowLTRB)
 
 TEST (RectTest, RectMakeSize)
 
 TEST (RectTest, RectMakeMaximum)
 
 TEST (RectTest, IRectMakeMaximum)
 
 TEST (RectTest, RectFromRect)
 
 TEST (RectTest, IRectFromIRect)
 
 TEST (RectTest, RectCopy)
 
 TEST (RectTest, IRectCopy)
 
 TEST (RectTest, RectOriginSizeXYWHGetters)
 
 TEST (RectTest, IRectOriginSizeXYWHGetters)
 
 TEST (RectTest, RectRoundOutEmpty)
 
 TEST (RectTest, RectRoundOutSimple)
 
 TEST (RectTest, RectRoundOutToIRectHuge)
 
 TEST (RectTest, RectDoesNotIntersectEmpty)
 
 TEST (RectTest, IRectDoesNotIntersectEmpty)
 
 TEST (RectTest, EmptyRectDoesNotIntersect)
 
 TEST (RectTest, EmptyIRectDoesNotIntersect)
 
 TEST (RectTest, RectScale)
 
 TEST (RectTest, IRectScale)
 
 TEST (RectTest, RectArea)
 
 TEST (RectTest, IRectArea)
 
 TEST (RectTest, RectGetNormalizingTransform)
 
 TEST (RectTest, IRectGetNormalizingTransform)
 
 TEST (RectTest, RectXYWHIsEmpty)
 
 TEST (RectTest, IRectXYWHIsEmpty)
 
 TEST (RectTest, MakePointBoundsQuad)
 
 TEST (RectTest, IsSquare)
 
 TEST (RectTest, GetCenter)
 
 TEST (RectTest, RectExpand)
 
 TEST (RectTest, IRectExpand)
 
 TEST (RectTest, RectExpandToMinTransformedSizeNullForScaledToZero)
 
 TEST (RectTest, RectExpandToMinTransformedSizeReturnsUnmodifiedWhenLargeEnough)
 
 TEST (RectTest, RectExpandToMinTransformedSizeReturnsUnmodifiedWhenLargeEnoughWithFractionalSize)
 
 TEST (RectTest, RectExpandToMinTransformedSizeRectWithIdentityTransform)
 
 TEST (RectTest, RectExpandToMinTransformedSizeRectWithScalingTransform)
 
 TEST (RectTest, ContainsFloatingPoint)
 
 TEST (RectTest, FloatContainsInteger)
 
template<typename R >
static constexpr R flip_lr (R rect)
 
template<typename R >
static constexpr R flip_tb (R rect)
 
template<typename R >
static constexpr R flip_lrtb (R rect)
 
static constexpr Rect swap_nan (const Rect &rect, int index)
 
static constexpr Point swap_nan (const Point &point, int index)
 
 TEST (RectTest, RectUnion)
 
 TEST (RectTest, OptRectUnion)
 
 TEST (RectTest, IRectUnion)
 
 TEST (RectTest, OptIRectUnion)
 
 TEST (RectTest, RectIntersection)
 
 TEST (RectTest, OptRectIntersection)
 
 TEST (RectTest, IRectIntersection)
 
 TEST (RectTest, OptIRectIntersection)
 
 TEST (RectTest, RectIntersectsWithRect)
 
 TEST (RectTest, IRectIntersectsWithRect)
 
 TEST (RectTest, RectContainsPoint)
 
 TEST (RectTest, IRectContainsIPoint)
 
 TEST (RectTest, RectContainsInclusivePoint)
 
 TEST (RectTest, IRectContainsInclusiveIPoint)
 
 TEST (RectTest, RectContainsRect)
 
 TEST (RectTest, IRectContainsIRect)
 
 TEST (RectTest, RectCutOut)
 
 TEST (RectTest, IRectCutOut)
 
 TEST (RectTest, RectGetPoints)
 
 TEST (RectTest, RectShift)
 
 TEST (RectTest, RectGetTransformedPoints)
 
 TEST (RectTest, RectMakePointBounds)
 
 TEST (RectTest, RectGetPositive)
 
 TEST (RectTest, RectDirections)
 
 TEST (RectTest, RectProject)
 
 TEST (RectTest, RectRoundOut)
 
 TEST (RectTest, IRectRoundOut)
 
 TEST (RectTest, RectRound)
 
 TEST (RectTest, IRectRound)
 
 TEST (RectTest, TransformAndClipBoundsNoCornersClipped)
 
 TEST (RectTest, TransformAndClipBoundsOneCornerClipped)
 
 TEST (RectTest, TransformAndClipBoundsTwoCornersClipped)
 
 TEST (RectTest, TransformAndClipBoundsThreeCornersClipped)
 
 TEST (RectTest, TransformAndClipBoundsAllFourCornersClipped)
 
 TEST (RoundRectTest, EmptyDeclaration)
 
 TEST (RoundRectTest, DefaultConstructor)
 
 TEST (RoundRectTest, EmptyRectConstruction)
 
 TEST (RoundRectTest, RectConstructor)
 
 TEST (RoundRectTest, InvertedRectConstruction)
 
 TEST (RoundRectTest, EmptyOvalConstruction)
 
 TEST (RoundRectTest, OvalConstructor)
 
 TEST (RoundRectTest, InvertedOvalConstruction)
 
 TEST (RoundRectTest, RectRadiusConstructor)
 
 TEST (RoundRectTest, RectXYConstructor)
 
 TEST (RoundRectTest, RectSizeConstructor)
 
 TEST (RoundRectTest, RectRadiiConstructor)
 
 TEST (RoundRectTest, RectRadiiOverflowWidthConstructor)
 
 TEST (RoundRectTest, RectRadiiOverflowHeightConstructor)
 
 TEST (RoundRectTest, Shift)
 
 TEST (RoundRectTest, ExpandScalar)
 
 TEST (RoundRectTest, ExpandTwoScalars)
 
 TEST (RoundRectTest, ExpandFourScalars)
 
 TEST (RoundRectTest, ContractScalar)
 
 TEST (RoundRectTest, ContractTwoScalars)
 
 TEST (RoundRectTest, ContractFourScalars)
 
 TEST (RoundRectTest, ContractAndRequireRadiiAdjustment)
 
 TEST (RoundRectTest, NoCornerRoundRectContains)
 
 TEST (RoundRectTest, TinyCornerRoundRectContains)
 
 TEST (RoundRectTest, UniformCircularRoundRectContains)
 
 TEST (RoundRectTest, UniformEllipticalRoundRectContains)
 
 TEST (RoundRectTest, DifferingCornersRoundRectContains)
 
 TEST (RoudingRadiiTest, RoundingRadiiEmptyDeclaration)
 
 TEST (RoudingRadiiTest, RoundingRadiiDefaultConstructor)
 
 TEST (RoudingRadiiTest, RoundingRadiiScalarConstructor)
 
 TEST (RoudingRadiiTest, RoundingRadiiEmptyScalarConstructor)
 
 TEST (RoudingRadiiTest, RoundingRadiiSizeConstructor)
 
 TEST (RoudingRadiiTest, RoundingRadiiEmptySizeConstructor)
 
 TEST (RoudingRadiiTest, RoundingRadiiNamedSizesConstructor)
 
 TEST (RoudingRadiiTest, RoundingRadiiPartialNamedSizesConstructor)
 
 TEST (RoudingRadiiTest, RoundingRadiiMultiply)
 
 TEST (RoudingRadiiTest, RoundingRadiiEquals)
 
 TEST (RoudingRadiiTest, RoundingRadiiNotEquals)
 
 TEST (RoudingRadiiTest, RoundingRadiiCornersSameTolerance)
 
 TEST (RSTransformTest, Construction)
 
 TEST (RSTransformTest, CompareToMatrix)
 
 TEST (SaturatedMath, ExplicitAddOfSignedInts)
 
 TEST (SaturatedMath, ImplicitAddOfSignedInts)
 
 TEST (SaturatedMath, ExplicitAddOfFloatingPoint)
 
 TEST (SaturatedMath, ImplicitAddOfFloatingPoint)
 
 TEST (SaturatedMath, ExplicitSubOfSignedInts)
 
 TEST (SaturatedMath, ImplicitSubOfSignedInts)
 
 TEST (SaturatedMath, ExplicitSubOfFloatingPoint)
 
 TEST (SaturatedMath, ImplicitSubOfFloatingPoint)
 
 TEST (SaturatedMath, ExplicitAverageScalarOfSignedInts)
 
 TEST (SaturatedMath, ImplicitAverageScalarOfSignedInts)
 
 TEST (SaturatedMath, ExplicitAverageScalarOfFloatingPoint)
 
 TEST (SaturatedMath, ImplicitAverageScalarOfFloatingPoint)
 
 TEST (SaturatedMath, CastingFiniteDoubleToFloatStaysFinite)
 
 TEST (SaturatedMath, CastingInfiniteDoubleToFloatStaysInfinite)
 
 TEST (SaturatedMath, CastingNaNDoubleToFloatStaysNaN)
 
 TEST (SaturatedMath, CastingLargeScalarToSignedIntProducesLimit)
 
 TEST (SaturatedMath, CastingInfiniteScalarToSignedIntProducesLimit)
 
 TEST (SaturatedMath, CastingNaNScalarToSignedIntProducesZero)
 
 TEST (SizeTest, SizeIsEmpty)
 
 TEST (SizeTest, ISizeIsEmpty)
 
 TEST (SizeTest, IsSquare)
 
 TEST (SizeTest, MaxDimension)
 
 TEST (SizeTest, NegationOperator)
 
 TEST (TrigTest, TrigAngles)
 
 TEST (TrigTest, MultiplyByScalarRadius)
 
 TEST (WangsFormulaTest, Cubic)
 
 TEST (WangsFormulaTest, Quadratic)
 
 TEST_F (GoldenTests, ConicalGradient)
 
 TEST (BlitCommandGLESTest, BlitCopyBufferToTextureCommandGLESRGBA)
 
 TEST (BlitCommandGLESTest, BlitCopyBufferToTextureCommandGLESBGRA)
 
 TEST (BlitCommandGLESTest, BlitCopyTextureToBufferCommandGLESBindsFramebuffer)
 
 TEST (BlitCommandGLESTest, BlitCopyTextureToBufferCommandGLESRGBA)
 
 TEST (BlitCommandGLESTest, BlitCopyTextureToBufferCommandGLESBGRA)
 
 TEST (BlitCommandGLESTest, BlitCopyTextureToBufferCommandGLESUnsupportedPixelFormats)
 
 TEST (BlitCommandGLESTest, BlitCopyBufferToTextureCommandAllocatesOnlyTheRequestedBaseMip)
 
 TEST (BlitCommandGLESTest, BlitCopyBufferToTextureCommandAllocatesNonZeroMipLevelOnFirstUpload)
 
 TEST (BlitCommandGLESTest, BlitCopyBufferToTextureCommandAllocatesEachMipLevelOnFirstWrite)
 
 TEST (BlitCommandGLESTest, BlitCopyBufferToTextureCommandDoesNotReallocateOnSubsequentUpload)
 
 TEST (BlitCommandGLESTest, BlitCopyBufferToTextureCommandUsesCubemapFaceTargetForCubemap)
 
 FML_TEST_CLASS (BufferBindingsGLESTest, BindUniformData)
 
 FML_TEST_CLASS (BufferBindingsGLESTest, BindArrayData)
 
 FML_TEST_CLASS (BufferBindingsGLESTest, BindUniformDataVerticesAndMatrices)
 
 FML_TEST_CLASS (BufferBindingsGLESTest, BindUniformFailsWithoutFloatType)
 
 TEST (BufferBindingsGLESTest, ToVertexAttribTypeSupportedFormats)
 
 TEST (BufferBindingsGLESTest, ToVertexAttribTypeRejectsUnsupportedFormats)
 
 TEST (BufferBindingsGLESTest, BindUniformData)
 
 TEST (BufferBindingsGLESTest, BindArrayData)
 
 TEST (BufferBindingsGLESTest, BindUniformDataVerticesAndMatrices)
 
 TEST (BufferBindingsGLESTest, BindUniformFailsWithoutFloatType)
 
 TEST (BufferBindingsGLESTest, BindVertexAttributesSetsInstanceRateDivisor)
 
 TEST (CommandBufferGLES, SubmitWithoutCurrentContextIsAcceptedAndCompletesAfterReaction)
 
 TEST (CommandBufferGLES, SubmitWithoutCallbackIsAcceptedWithoutCurrentContext)
 
 TEST (CommandBufferGLES, DeferredSubmitCallbackErrorsIfReactorIsDestroyed)
 
 TEST (CommandBufferGLES, DeferredSubmitCompletesAfterPreviouslyQueuedWork)
 
 TEST (CommandBufferGLES, LaterCurrentSubmitDrainsPreviouslyDeferredWork)
 
 TEST (CommandBufferGLES, BufferToTextureBlitCanBeSubmittedBeforeContextCurrent)
 
 TEST (DeviceBufferGLESTest, FlushDuringUploadIsNotDiscarded)
 
 TEST (DeviceBufferGLESTest, BindUniformData)
 
 TEST_P (RenderPassGLESWithDiscardFrameBufferExtTest, DiscardFramebufferExt)
 
 INSTANTIATE_TEST_SUITE_P (FrameBufferObject, RenderPassGLESWithDiscardFrameBufferExtTest, ::testing::ValuesIn(std::vector< DiscardFrameBufferParams >{ {.frame_buffer_id=0,.expected_attachments={GL_COLOR_EXT, GL_DEPTH_EXT, GL_STENCIL_EXT}}, {.frame_buffer_id=1,.expected_attachments={GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}}}), [](const ::testing::TestParamInfo< DiscardFrameBufferParams > &info) { return(info.param.frame_buffer_id==0) ? "Default" :"NonDefault";})
 
 TEST_P (RenderPassGLESWithDiscardFrameBufferExtTest, InvalidateFramebuffer)
 
 TEST (RenderPassGLESTest, ResolvingMultisampleTextureCachesResolveFBO)
 
 TEST_F (RenderPassGLESCommandTest, ViewportCachedAcrossCommands)
 
 TEST_F (RenderPassGLESCommandTest, CommandsWithoutViewportGetRenderPassViewport)
 
 TEST_F (RenderPassGLESCommandTest, ViewportWithNonZeroXOffsetReachesGL)
 
 TEST_F (RenderPassGLESCommandTest, HardwareInstancedArrayDraw)
 
 TEST_F (RenderPassGLESCommandTest, HardwareInstancedElementsDraw)
 
 TEST_F (RenderPassGLESCommandTest, EmulatedInstancedArrayDraw)
 
 TEST_F (RenderPassGLESCommandTest, EmulatedInstancedElementsDraw)
 
 TEST_F (RenderPassGLESCommandTest, NonInstancedDrawIssuesSingleDrawArrays)
 
 TEST_F (RenderPassGLESCommandTest, ZeroInstanceCountIssuesNoDraw)
 
 TEST (CapabilitiesGLES, CanInitializeWithDefaults)
 
 TEST (CapabilitiesGLES, SupportsDecalSamplerAddressMode)
 
 TEST (CapabilitiesGLES, SupportsDecalSamplerAddressModeNotOES)
 
 TEST (CapabilitiesGLES, SupportsFramebufferFetch)
 
 TEST (CapabilitiesGLES, SupportsMSAA)
 
 TEST (CapabilitiesGLES, MaxSamplerAnisotropyUnsupportedByDefault)
 
 TEST (CapabilitiesGLES, MaxSamplerAnisotropyWithExtension)
 
 TEST (FormatsGLES, CanFormatFramebufferErrorMessage)
 
void doNothing ()
 
const unsigned char * mockGetString (GLenum name)
 
const unsigned char * mockGetStringi (GLenum name, GLuint index)
 
void mockGetIntegerv (GLenum name, int *value)
 
GLenum mockGetError ()
 
void mockPopDebugGroupKHR ()
 
void mockPushDebugGroupKHR (GLenum source, GLuint id, GLsizei length, const GLchar *message)
 
void mockGenQueriesEXT (GLsizei n, GLuint *ids)
 
void mockBeginQueryEXT (GLenum target, GLuint id)
 
void mockEndQueryEXT (GLuint id)
 
void mockGetQueryObjectuivEXT (GLuint id, GLenum target, GLuint *result)
 
void mockGetQueryObjectui64vEXT (GLuint id, GLenum target, GLuint64 *result)
 
void mockDeleteQueriesEXT (GLsizei size, const GLuint *queries)
 
void mockDeleteTextures (GLsizei size, const GLuint *queries)
 
void mockUniform1fv (GLint location, GLsizei count, const GLfloat *value)
 
void mockUniform2fv (GLint location, GLsizei count, const GLfloat *value)
 
void mockUniform3fv (GLint location, GLsizei count, const GLfloat *value)
 
void mockUniform4fv (GLint location, GLsizei count, const GLfloat *value)
 
void mockUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 
void mockUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 
void mockUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 
void mockGenTextures (GLsizei n, GLuint *textures)
 
void mockGenBuffers (GLsizei n, GLuint *buffers)
 
void mockBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
 
void mockObjectLabelKHR (GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
 
void mockTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels)
 
void mockTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)
 
void mockBindTexture (GLenum target, GLuint texture)
 
GLboolean mockIsTexture (GLuint texture)
 
GLenum mockCheckFramebufferStatus (GLenum target)
 
void mockGenFramebuffers (GLsizei n, GLuint *ids)
 
void mockBindFramebuffer (GLenum target, GLuint framebuffer)
 
void mockReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data)
 
void mockDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments)
 
void mockViewport (GLint x, GLint y, GLsizei width, GLsizei height)
 
void mockInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments)
 
void mockDrawArrays (GLenum mode, GLint first, GLsizei count)
 
void mockDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices)
 
void mockDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instancecount)
 
void mockDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount)
 
void mockVertexAttribDivisor (GLuint index, GLuint divisor)
 
 TEST (MockGLES, CanInitialize)
 
 TEST (MockGLES, CanCallUnmockedFunction)
 
 TEST (PipelineCompileQueueGLESTest, CreateReturnsNullWithNullTaskRunner)
 
 TEST (PipelineCompileQueueGLESTest, CreateSucceedsWithValidTaskRunner)
 
 TEST (PipelineCompileQueueGLESTest, PostJobDoesNothingWithNullClosure)
 
 TEST (PipelineCompileQueueGLESTest, OnJobAddedProcessesJobsSequentially)
 
 TEST (PipelineCompileQueueGLESTest, PostJobForDescriptorWithDuplicateRunsEagerly)
 
 TEST (PipelineCompileQueueGLESTest, IsProcessingResetsAfterAllJobsComplete)
 
 TEST (PipelineCompileQueueGLESTest, DestroyQueueWithPendingTasks)
 
 INSTANTIATE_OPENGLES_PLAYGROUND_SUITE (PipelineLibraryGLESTest)
 
 TEST_P (PipelineLibraryGLESTest, ProgramHandlesAreReused)
 
 TEST_P (PipelineLibraryGLESTest, ChangingSpecConstantsCausesNewProgramObject)
 
 TEST_P (PipelineLibraryGLESTest, ClearingPipelineWillAlsoClearProgramHandle)
 
 TEST (ProcTableGLES, ResolvesCorrectClearDepthProcOnES)
 
 TEST (ProcTableGLES, ResolvesCorrectClearDepthProcOnDesktopGL)
 
 TEST (ProcTableGLES, CheckFrameBufferStatusDebugOnly)
 
 TEST (ProcTableGLES, GLES2VertexAttribDivisor)
 
 TEST (ProcTableGLES, GLES3VertexAttribDivisor)
 
 TEST (GLErrorToString, ReturnsCorrectStringForKnownErrors)
 
 TEST (GLErrorToString, ReturnsUnknownForInvalidError)
 
 TEST (GLErrorToString, ReturnValueIsValidStringView)
 
 TEST (GLProc, NameFieldWorksWithStringView)
 
 TEST (ReactorGLES, CanAttachCleanupCallbacksToHandles)
 
 TEST (ReactorGLES, DeletesHandlesDuringShutdown)
 
 TEST (ReactorGLES, UntrackedHandle)
 
 TEST (ReactorGLES, NameUntrackedHandle)
 
 TEST (ReactorGLES, PerThreadOperationQueues)
 
 TEST (ReactorGLES, CanDeferOperations)
 
 TEST (ReactorGLES, FramebufferDeletedOnOwnerThread)
 
 TEST (SpecConstant, CanCreateShaderWithSpecializationConstant)
 
 TEST (SpecConstant, CanCreateShaderWithSpecializationConstantMultipleValues)
 
 TEST_P (SurfaceGLESTest, CanWrapNonZeroFBO)
 
 TEST_P (TextureGLESTest, CanSetSyncFence)
 
 TEST_P (TextureGLESTest, TextureDtorDeletesFence)
 
 TEST_P (TextureGLESTest, Binds2DTexture)
 
 TEST_P (TextureGLESTest, Leak)
 
 TEST_P (TextureGLESTest, CreatingAndBindingEmptyTexturesDoesNotCrash)
 
 TEST (UniqueHandleGLES, MakeUntracked)
 
 INSTANTIATE_METAL_PLAYGROUND_SUITE (AllocatorMTLTest)
 
 TEST_P (AllocatorMTLTest, DebugTraceMemoryStatistics)
 
 TEST_P (AllocatorMTLTest, ManagedMemory)
 
 TEST_P (ContextMTLTest, FlushTask)
 
 TEST_P (ContextMTLTest, FlushTaskWithGPULoss)
 
 TEST_P (SwapchainTransientsMTLTest, CanAllocateSwapchainTextures)
 
 TEST (AllocatorVKTest, ToVKImageUsageFlags)
 
 TEST (AllocatorVKTest, MemoryTypeSelectionSingleHeap)
 
 TEST (AllocatorVKTest, MemoryTypeSelectionTwoHeap)
 
 TEST (AllocatorVKTest, ImageResourceKeepsVulkanDeviceAlive)
 
 TEST (AllocatorVKTest, RetriesUncompressedOnCompressionExhausted)
 
 TEST (CommandEncoderVKTest, DeleteEncoderAfterThreadDies)
 
 TEST (CommandEncoderVKTest, CleanupAfterSubmit)
 
 TEST (CommandPoolRecyclerVKTest, GetsACommandPoolPerThread)
 
 TEST (CommandPoolRecyclerVKTest, GetsTheSameCommandPoolOnSameThread)
 
 TEST (CommandPoolRecyclerVKTest, ReclaimMakesCommandPoolAvailable)
 
 TEST (CommandPoolRecyclerVKTest, CommandBuffersAreRecycled)
 
 TEST (CommandPoolRecyclerVKTest, ExtraCommandBufferAllocationsTriggerTrim)
 
 TEST (CommandPoolRecyclerVKTest, RecyclerGlobalPoolMapSize)
 
 TEST (CommandPoolVKTest, DestroysCleanlyIfDeviceIsDestroyed)
 
 TEST (CommandQueueVKTest, QueueSubmit)
 
 TEST (CommandQueueVKTest, SubmitAfterFenceWaiterTerminated)
 
 TEST (ContextVKTest, CommonHardwareConcurrencyConfigurations)
 
 TEST (ContextVKTest, DeletesCommandPools)
 
 TEST (ContextVKTest, DeletesCommandPoolsOnAllThreads)
 
 TEST (ContextVKTest, ThreadLocalCleanupDeletesCommandPool)
 
 TEST (ContextVKTest, DeletePipelineAfterContext)
 
 TEST (ContextVKTest, DeleteShaderFunctionAfterContext)
 
 TEST (ContextVKTest, DeletePipelineLibraryAfterContext)
 
 TEST (ContextVKTest, CanCreateContextInAbsenceOfValidationLayers)
 
 TEST (ContextVKTest, CanCreateContextWithValidationLayers)
 
 TEST (CapabilitiesVKTest, ContextInitializesWithNoStencilFormat)
 
 TEST (CapabilitiesVKTest, ContextFailsInitializationForNoCombinedDepthStencilFormat)
 
 TEST (ContextVKTest, WarmUpFunctionCreatesRenderPass)
 
 TEST (ContextVKTest, FatalMissingValidations)
 
 TEST (ContextVKTest, HasDefaultColorFormat)
 
 TEST (ContextVKTest, EmbedderOverridesUsesInstanceExtensions)
 
 TEST (ContextVKTest, EmbedderOverrides)
 
 TEST (ContextVKTest, BatchSubmitCommandBuffersOnArm)
 
 TEST (ContextVKTest, BatchSubmitCommandBuffersOnNonArm)
 
 TEST (ContextVKTest, AHBSwapchainCapabilitiesCanBeMissing)
 
 TEST (ContextVKTest, HashIsUniqueAcrossThreads)
 
 TEST (DescriptorPoolRecyclerVKTest, GetDescriptorPoolRecyclerCreatesNewPools)
 
 TEST (DescriptorPoolRecyclerVKTest, ReclaimMakesDescriptorPoolAvailable)
 
 TEST (DescriptorPoolRecyclerVKTest, ReclaimDropsDescriptorPoolIfSizeIsExceeded)
 
 TEST (DescriptorPoolRecyclerVKTest, MultipleCommandBuffersShareDescriptorPool)
 
 TEST (DescriptorPoolRecyclerVKTest, DescriptorsAreRecycled)
 
 INSTANTIATE_VULKAN_PLAYGROUND_SUITE (DriverInfoVKTest)
 
 TEST_P (DriverInfoVKTest, CanQueryDriverInfo)
 
 TEST_P (DriverInfoVKTest, CanDumpToLog)
 
 TEST (DriverInfoVKTest, CanIdentifyBadMaleoonDriver)
 
bool IsBadVersionTest (std::string_view driver_name, bool qc=true)
 
bool CanBatchSubmitTest (std::string_view driver_name, bool qc=true)
 
 TEST (DriverInfoVKTest, CanBatchSubmitCommandBuffers)
 
bool CanUsePrimitiveRestartSubmitTest (std::string_view driver_name, bool qc=true)
 
 TEST (DriverInfoVKTest, CanUsePrimitiveRestart)
 
bool CanUseMipgeneration (std::string_view driver_name, bool qc=true)
 
 TEST (DriverInfoVKTest, CanGenerateMipMaps)
 
 TEST (DriverInfoVKTest, DriverParsingMali)
 
 TEST (DriverInfoVKTest, DriverParsingAdreno)
 
 TEST (DriverInfoVKTest, DisabledDevices)
 
 TEST (DriverInfoVKTest, EnabledDevicesMali)
 
 TEST (DriverInfoVKTest, EnabledDevicesAdreno)
 
bool CanUseFramebufferFetch (std::string_view driver_name, bool qc=true)
 
 TEST (DriverInfoVKTest, CanUseFramebufferFetch)
 
 TEST (DriverInfoVKTest, DisableOldXclipseDriver)
 
 TEST (DriverInfoVKTest, OldPowerVRDisabled)
 
 TEST (DriverInfoVKTest, NewPowerVREnabled)
 
 TEST (DriverInfoVKTest, PowerVRBSeries)
 
 TEST (FenceWaiterVKTest, IgnoresNullFence)
 
 TEST (FenceWaiterVKTest, IgnoresNullCallback)
 
 TEST (FenceWaiterVKTest, ReturnsSubmitError)
 
 TEST (FenceWaiterVKTest, ExecutesFenceCallback)
 
 TEST (FenceWaiterVKTest, ExecutesFenceCallbackX2)
 
 TEST (FenceWaiterVKTest, ExecutesNewFenceThenOldFence)
 
 TEST (FenceWaiterVKTest, AddFenceDoesNothingIfTerminating)
 
 TEST (FenceWaiterVKTest, InProgressFencesStillWaitIfTerminated)
 
 TEST (FormatsVKTest, DescriptorMapping)
 
 TEST (PipelineCacheDataVKTest, CanTestHeaderCompatibility)
 
 TEST (PipelineCacheDataVKTest, CanCreateFromDeviceProperties)
 
 TEST (PipelineCacheDataVKTest, WritesIncompleteCacheData)
 
 TEST_P (PipelineCacheDataVKPlaygroundTest, CanPersistAndRetrievePipelineCache)
 
 TEST_P (PipelineCacheDataVKPlaygroundTest, IntegrityChecksArePerformedOnPersistedData)
 
 TEST (RenderPassBuilder, CreatesRenderPassWithNoDepthStencil)
 
 TEST (RenderPassBuilder, RenderPassWithLoadOpUsesCurrentLayout)
 
 TEST (RenderPassBuilder, CreatesRenderPassWithCombinedDepthStencil)
 
 TEST (RenderPassBuilder, CreatesRenderPassWithOnlyStencil)
 
 TEST (RenderPassBuilder, CreatesMSAAResolveWithCorrectStore)
 
 TEST_P (RendererTest, CachesRenderPassAndFramebuffer)
 
 TEST_P (RendererTest, CachesRenderPassAndFramebufferNonMSAA)
 
 TEST_P (RendererTest, CachesRenderPassAndFramebufferMixed)
 
 TEST (RenderPassVK, DoesNotRedundantlySetStencil)
 
 TEST (RenderPassVK, SetViewportPropagatesAllUserSuppliedFields)
 
 TEST (ResourceManagerVKTest, CreatesANewInstance)
 
 TEST (ResourceManagerVKTest, ReclaimMovesAResourceAndDestroysIt)
 
 TEST (ResourceManagerVKTest, TerminatesWhenOutOfScope)
 
 TEST (ResourceManagerVKTest, IsThreadSafe)
 
 TEST (SurfaceContextVK, TearsDownSwapchain)
 
std::shared_ptr< std::vector< std::string > > GetMockVulkanFunctions (VkDevice device)
 
void SetSwapchainImageSize (ISize size)
 Override the image size returned by all swapchain images.
 
std::vector< VkImageMemoryBarrier > & GetImageMemoryBarriers (VkCommandBuffer buffer)
 
const std::vector< VkViewport > & GetRecordedViewports (VkCommandBuffer buffer)
 Returns the viewports passed to vkCmdSetViewport calls on the given command buffer, in call order.
 
 TEST (MockVulkanContextTest, IsThreadSafe)
 
 TEST (MockVulkanContextTest, DefaultFenceAlwaysReportsSuccess)
 
 TEST (MockVulkanContextTest, MockedFenceReportsStatus)
 
 TEST (PipelineCompileQueueVulkanTest, CreateSucceedsWithValidTaskRunner)
 
 TEST (PipelineCompileQueueVulkanTest, PostJobDoesNothingWithNullClosure)
 
 TEST (PipelineCompileQueueVulkanTest, OnJobAddedProcessesJobsInParallel)
 
 TEST (PipelineCompileQueueVulkanTest, PostJobForDescriptorWithDuplicateRunsEagerly)
 
 TEST (PipelineCompileQueueVulkanTest, MultipleJobsCompleteSuccessfully)
 
 TEST (SamplerLibraryVK, WorkaroundsCanDisableReadingFromMipLevels)
 
 TEST (SamplerLibraryVK, MaxAnisotropyIsClampedToTheDeviceLimit)
 
 TEST (SamplerLibraryVK, MaxAnisotropyIsDisabledWhenUnsupported)
 
vk::UniqueSurfaceKHR CreateSurface (const ContextVK &context)
 
 TEST (SwapchainTest, CanCreateSwapchain)
 
 TEST (SwapchainTest, RecreateSwapchainWhenSizeChanges)
 
 TEST (SwapchainTest, CachesRenderPassOnSwapchainImage)
 
 TEST (SwapchainTest, NoFenceWaitAfterAcquireNextImageFailure)
 
 TEST_P (BlitPassTest, BlitAcrossDifferentPixelFormatsFails)
 
 TEST_P (BlitPassTest, BlitAcrossDifferentSampleCountsFails)
 
 TEST_P (BlitPassTest, BlitPassesForMatchingFormats)
 
 TEST_P (BlitPassTest, ChecksInvalidSliceParameters)
 
 TEST_P (BlitPassTest, CanBlitSmallRegionToUninitializedTexture)
 
 TEST_P (BlitPassTest, ChecksInvalidMipLevelParameter)
 
 TEST_P (BlitPassTest, CanBlitToHigherTextureMipLevels)
 
 TEST_P (BlitPassTest, CanResizeTextures)
 
 TEST_P (BlitPassTest, CanResizeTexturesPlayground)
 
 CAPABILITY_TEST (SupportsOffscreenMSAA, false)
 
 CAPABILITY_TEST (SupportsSSBO, false)
 
 CAPABILITY_TEST (SupportsTextureToTextureBlits, false)
 
 CAPABILITY_TEST (SupportsFramebufferFetch, false)
 
 CAPABILITY_TEST (SupportsCompute, false)
 
 CAPABILITY_TEST (SupportsComputeSubgroups, false)
 
 CAPABILITY_TEST (SupportsReadFromResolve, false)
 
 CAPABILITY_TEST (SupportsDecalSamplerAddressMode, false)
 
 CAPABILITY_TEST (SupportsDeviceTransientTextures, false)
 
 CAPABILITY_TEST (SupportsTriangleFan, false)
 
 CAPABILITY_TEST (SupportsExtendedRangeFormats, false)
 
 CAPABILITY_TEST (NeedsPartitionedHostBuffer, false)
 
 TEST (CapabilitiesTest, DefaultColorFormat)
 
 TEST (CapabilitiesTest, DefaultStencilFormat)
 
 TEST (CapabilitiesTest, DefaultDepthStencilFormat)
 
 TEST (CapabilitiesTest, DefaultGlyphAtlasFormat)
 
 TEST (CapabilitiesTest, MaxRenderPassAttachmentSize)
 
 TEST (CapabilitiesTest, SupportsTextureCompression)
 
 TEST (CapabilitiesTest, MinUniformAlignment)
 
 TEST (CapabilitiesTest, MaxSamplerAnisotropy)
 
 INSTANTIATE_COMPUTE_SUITE (ComputeTest)
 
 TEST_P (ComputeTest, CapabilitiesReportSupport)
 
 TEST_P (ComputeTest, CanCreateComputePass)
 
 TEST_P (ComputeTest, CanComputePrefixSum)
 
 TEST_P (ComputeTest, 1DThreadgroupSizingIsCorrect)
 
 TEST_P (ComputeTest, 3DWorkgroupDispatchIsCorrect)
 
 TEST_P (ComputeTest, CanComputePrefixSumLargeInteractive)
 
 TEST_P (ComputeTest, MultiStageInputAndOutput)
 
 TEST_P (ComputeTest, CanCompute1DimensionalData)
 
 TEST_P (ComputeTest, ReturnsEarlyWhenAnyGridDimensionIsZero)
 
 TEST (PipelineCompileQueueTest, AddJobReturnsTrueForNewDescriptor)
 
 TEST (PipelineCompileQueueTest, AddJobReturnsFalseForDuplicateDescriptor)
 
 TEST (PipelineCompileQueueTest, HasPendingJobsReturnsCorrectState)
 
 TEST (PipelineCompileQueueTest, PerformJobEagerlyExecutesJob)
 
 TEST (PipelineCompileQueueTest, FinishAllJobsDrainsQueue)
 
 TEST (PipelineDescriptorTest, PrimitiveTypeHashEquality)
 
 TEST (MockPipelineLibrary, LogAndGetPipelineUsageSinglePipeline)
 
 TEST (MockPipelineLibrary, LogAndGetPipelineUsageMultiplePipelines)
 
 TEST (PoolTest, Simple)
 
 TEST (PoolTest, Overload)
 
static void InstantiateTestShaderLibrary (Context::BackendType backend_type)
 
static bool DrainMicrotasks ()
 
 INSTANTIATE_PLAYGROUND_SUITE (RendererDartTest)
 
 TEST_P (RendererDartTest, CanRunDartInPlaygroundFrame)
 
 TEST_P (RendererDartTest, CanInstantiateFlutterGPUContext)
 
 TEST_P (RendererDartTest, CanCreateShaderLibrary)
 
 TEST_P (RendererDartTest, CanReflectUniformStructs)
 
 TEST_P (RendererDartTest, CanCreateRenderPassAndSubmit)
 
 INSTANTIATE_PLAYGROUND_SUITE (RendererGoldenTest)
 
 TEST_P (RendererGoldenTest, BabysFirstTriangle)
 
 TEST_P (RendererGoldenTest, CanRenderInstancedWithVertexAttributes)
 
static void DrawCompressedTextureGolden (RendererGoldenTest &test, PixelFormat format, const std::vector< uint8_t > &block_data, ISize size)
 
 TEST_P (RendererGoldenTest, CanRenderBC1CompressedTexture)
 
 TEST_P (RendererGoldenTest, CanRenderETC2CompressedTexture)
 
 TEST_P (RendererGoldenTest, CanRenderASTCCompressedTexture)
 
static void DrawManuallyMippedTextureGolden (RendererGoldenTest &test, float lod)
 
 TEST_P (RendererGoldenTest, CanSampleManuallyMippedTexture)
 
 TEST_P (RendererGoldenTest, CanSampleManuallyMippedTextureLod1)
 
 TEST_P (RendererTest, CanCreateBoxPrimitive)
 
 TEST_P (RendererTest, CanRenderPerspectiveCube)
 
 TEST_P (RendererTest, CanRenderMultiplePrimitives)
 
 TEST_P (RendererTest, CanRenderToTexture)
 
 TEST_P (RendererTest, CanRenderInstanced)
 
 TEST_P (RendererTest, CanBlitTextureToTexture)
 
 TEST_P (RendererTest, CanBlitTextureToBuffer)
 
 TEST_P (RendererTest, CanGenerateMipmaps)
 
 TEST_P (RendererTest, TheImpeller)
 
 TEST_P (RendererTest, Planet)
 
 TEST_P (RendererTest, ArrayUniforms)
 
 TEST_P (RendererTest, InactiveUniforms)
 
 TEST_P (RendererTest, DefaultIndexSize)
 
 TEST_P (RendererTest, DefaultIndexBehavior)
 
 TEST_P (RendererTest, VertexBufferBuilder)
 
static const CompareFunctionUIDataCompareFunctionUI ()
 
 TEST_P (RendererTest, StencilMask)
 
 TEST_P (RendererTest, CanLookupRenderTargetProperties)
 
 TEST_P (RendererTest, RenderTargetCreateOffscreenMSAASetsDefaultDepthStencilFormat)
 
template<class VertexShader , class FragmentShader >
std::shared_ptr< Pipeline< PipelineDescriptor > > CreateDefaultPipeline (RendererTest *test, const std::shared_ptr< Context > &context)
 
 TEST_P (RendererTest, CanSepiaToneWithSubpasses)
 
 TEST_P (RendererTest, CanSepiaToneThenSwizzleWithSubpasses)
 
 TEST_P (RendererTest, BindingNullTexturesDoesNotCrash)
 
 TEST_P (RendererTest, CanRenderToTextureSlice)
 
 TEST_P (RendererTest, CanRenderToMipLevel)
 
 TEST_P (RendererTest, AttachmentRejectsOutOfRangeSubresource)
 
 INSTANTIATE_PLAYGROUND_SUITE (RuntimeStageTest)
 
 TEST_P (RuntimeStageTest, CanReadValidBlob)
 
 TEST_P (RuntimeStageTest, RejectInvalidFormatVersion)
 
 TEST_P (RuntimeStageTest, CanRejectInvalidBlob)
 
 TEST_P (RuntimeStageTest, RejectsCorruptBufferWithValidIdentifier)
 
 TEST_P (RuntimeStageTest, CanReadUniforms)
 
 TEST_P (RuntimeStageTest, CanReadUniformsSamplerBeforeUBO)
 
 TEST_P (RuntimeStageTest, CanReadUniformsSamplerAfterUBO)
 
 TEST_P (RuntimeStageTest, CanRegisterStage)
 
 TEST_P (RuntimeStageTest, CanCreatePipelineFromRuntimeStage)
 
 TEST_P (RuntimeStageTest, ContainsExpectedShaderTypes)
 
 TEST_P (RuntimeStageTest, ContainsExpectedShaderTypesNoSksl)
 
 TEST (ShaderKeyTest, MakeUserScopedNameProducesScopedString)
 
 TEST (ShaderKeyTest, MakeUserScopedNameContainsColonSeparator)
 
 TEST (ShaderKeyTest, MakeUserScopedNameDifferentLibraryIdsDoNotCollide)
 
 TEST (ShaderKeyTest, MakeUserScopedNameDifferentScopesDoNotCollide)
 
 TEST (ShaderKeyTest, MakeUserScopedNameHandlesLongInputs)
 
 TEST_P (RuntimeStageTest, RuntimeStageHasUniqueLibraryIdByDefault)
 
 TEST_P (RuntimeStageTest, RuntimeStageLibraryIdCanBeOverridden)
 
static std::shared_ptr< fml::MappingCreateMappingFromString (std::string p_string)
 
const std::string CreateStringFromMapping (const fml::Mapping &mapping)
 
 TEST (ShaderArchiveTest, CanReadAndWriteBlobs)
 
 TEST (ShaderArchiveTest, ReturnsErrorOnInvalidVersion)
 
 TEST (ShaderArchiveTest, RejectsCorruptBufferWithValidIdentifier)
 
 TEST (PathTessellatorTest, EmptyPath)
 
 TEST (PathTessellatorTest, EmptyPathMultipleMoveTo)
 
 TEST (PathTessellatorTest, SimpleClosedPath)
 
 TEST (PathTessellatorTest, SimpleUnclosedPath)
 
 TEST (PathTessellatorTest, SimplePathTrailingMoveTo)
 
 TEST (PathTessellatorTest, DegenerateSegmentsPath)
 
 TEST (PathTessellatorTest, QuadToLineToOptimization)
 
 TEST (PathTessellatorTest, ConicToLineToOptimization)
 
 TEST (PathTessellatorTest, ConicToQuadToOptimization)
 
 TEST (PathTessellatorTest, SimplePathMultipleMoveTo)
 
 TEST (PathTessellatorTest, ComplexPath)
 
 TEST (PathTessellatorTest, ComplexPathTrailingMoveTo)
 
 TEST (PathTessellatorTest, LinearQuadToPointCount)
 
 TEST (PathTessellatorTest, LinearConicToPointCount)
 
 TEST (PathTessellatorTest, LinearCubicToPointCount)
 
template<typename T >
std::vector< T > CopyBufferView (const BufferView &vertex_buffer)
 
 TEST_P (TessellatorPlaygroundTest, TessellateConvex16or32Bit)
 
 TEST (TessellatorTest, TessellatorBuilderReturnsCorrectResultStatus)
 
 TEST (TessellatorTest, TessellateConvex)
 
 TEST (TessellatorTest, TessellateConvexUnclosedPath)
 
 TEST (TessellatorTest, CircleVertexCounts)
 
 TEST (TessellatorTest, FilledCircleTessellationVertices)
 
 TEST (TessellatorTest, StrokedCircleTessellationVertices)
 
 TEST (TessellatorTest, FilledArcStripTessellationVertices)
 
 TEST (TessellatorTest, RoundCapLineTessellationVertices)
 
 TEST (TessellatorTest, FilledEllipseTessellationVertices)
 
 TEST (TessellatorTest, FilledRoundRectTessellationVertices)
 
 TEST (TessellatorTest, EarlyReturnEmptyConvexShape)
 
void ImpellerUnittestSetup ()
 
static std::shared_ptr< GlyphAtlasCreateGlyphAtlas (Context &context, const TypographerContext *typographer_context, HostBuffer &data_host_buffer, GlyphAtlas::Type type, const Matrix &transform, const std::shared_ptr< GlyphAtlasContext > &atlas_context, const std::shared_ptr< TextFrame > &frame)
 
static std::shared_ptr< GlyphAtlasCreateGlyphAtlas (Context &context, const TypographerContext *typographer_context, HostBuffer &data_host_buffer, GlyphAtlas::Type type, const Matrix &transform, const std::shared_ptr< GlyphAtlasContext > &atlas_context, const std::vector< std::shared_ptr< TextFrame > > &frames, const std::vector< GlyphProperties > &properties)
 
 TEST_P (TypographerTest, CanConvertTextBlob)
 
 TEST_P (TypographerTest, CanCreateRenderContext)
 
 TEST_P (TypographerTest, CanCreateGlyphAtlas)
 
 TEST_P (TypographerTest, LazyAtlasTracksColor)
 
 TEST_P (TypographerTest, GlyphAtlasWithOddUniqueGlyphSize)
 
 TEST_P (TypographerTest, GlyphAtlasIsRecycledIfUnchanged)
 
 TEST_P (TypographerTest, GlyphAtlasWithLotsOfdUniqueGlyphSize)
 
 TEST_P (TypographerTest, GlyphAtlasTextureIsRecycledIfUnchanged)
 
 TEST_P (TypographerTest, GlyphColorIsPartOfCacheKey)
 
 TEST_P (TypographerTest, GlyphColorIsIgnoredForNonEmojiFonts)
 
 TEST_P (TypographerTest, GlyphIsLightIsPartOfCacheKey)
 
 TEST_P (TypographerTest, RectanglePackerAddsNonoverlapingRectangles)
 
 TEST (TypographerTest, RectanglePackerFillsRows)
 
 TEST_P (TypographerTest, GlyphAtlasTextureWillGrowTilMaxTextureSize)
 
 TEST_P (TypographerTest, InvalidAtlasForcesRepopulation)
 
 TEST_P (TypographerTest, ColorBitmapAtlasSkiaBitmapIsRGBA8888)
 
 TEST_P (TypographerTest, AlphaBitmapAtlasSkiaBitmapIsA8)
 
 TEST_P (TypographerTest, AlphaBitmapAtlasWithLightGlyphsSkiaBitmapIsRGBA8888)
 

Variables

static const std::map< std::string, MaskBlurTestConfigkPaintVariations
 
static constexpr std::string_view kFontFixture
 
static constexpr const size_t kMagicFailingAllocation = 1024000 * 2
 
std::vector< Pointgolden_cubic_and_quad_points
 
static std::mutex g_test_lock
 
static std::weak_ptr< MockGLESg_mock_gles
 
static std::vector< const char * > g_extensions
 
static const char * g_version
 
static std::string g_extensions_string
 
auto const kMockVendor = "MockGLES"
 
const auto kMockShadingLanguageVersion = "GLSL ES 1.0"
 
auto const kExtensions
 
const ProcTableGLES::Resolver kMockResolverGLES
 
const ProcTableGLES::Resolver kMockResolverGLESWithoutInstancing
 

Typedef Documentation

◆ AiksTest

Definition at line 17 of file aiks_unittests.h.

◆ AllocatorMTLTest

◆ BlitPassTest

Definition at line 27 of file blit_pass_unittests.cc.

◆ ComputeTest

Definition at line 42 of file compute_unittests.cc.

◆ ContextMTLTest

Definition at line 25 of file context_mtl_unittests.mm.

◆ DeviceBufferTest

Definition at line 12 of file device_buffer_unittests.cc.

◆ DisplayListTest

Definition at line 45 of file dl_unittests.cc.

◆ DriverInfoVKTest

◆ EntityPassTargetTest

◆ EntityTest

◆ HostBufferTest

◆ PipelineCacheDataVKPlaygroundTest

◆ PipelineLibraryGLESTest

◆ RendererGoldenTest

◆ RendererTest

◆ RenderTargetCacheTest

◆ RuntimeStageTest

◆ SaveLayerUtilsTest

using impeller::testing::SaveLayerUtilsTest = typedef ::testing::Test

Definition at line 15 of file save_layer_utils_unittests.cc.

◆ SurfaceGLESTest

◆ SwapchainTransientsMTLTest

◆ TessellatorPlaygroundTest

◆ TextContentsTest

◆ TextureGLESTest

◆ TypographerTest

Function Documentation

◆ APPLY_COLOR_FILTER_GRADIENT_TEST() [1/4]

impeller::testing::APPLY_COLOR_FILTER_GRADIENT_TEST ( Conical  )

◆ APPLY_COLOR_FILTER_GRADIENT_TEST() [2/4]

impeller::testing::APPLY_COLOR_FILTER_GRADIENT_TEST ( Linear  )

◆ APPLY_COLOR_FILTER_GRADIENT_TEST() [3/4]

impeller::testing::APPLY_COLOR_FILTER_GRADIENT_TEST ( Radial  )

◆ APPLY_COLOR_FILTER_GRADIENT_TEST() [4/4]

impeller::testing::APPLY_COLOR_FILTER_GRADIENT_TEST ( Sweep  )

◆ BlendModeTest()

static sk_sp< DisplayList > impeller::testing::BlendModeTest ( AiksTest test,
Vector2  content_scale,
BlendMode  blend_mode,
const sk_sp< DlImageImpeller > &  src_image,
const sk_sp< DlImageImpeller > &  dst_image,
Scalar  src_alpha 
)
static
  1. Save layer blending (top squares).
  1. CPU blend modes (bottom squares).
  1. Image blending (bottom images).

Compare these results with the images in the Flutter blend mode documentation: https://api.flutter.dev/flutter/dart-ui/BlendMode.html

Definition at line 509 of file aiks_dl_blend_unittests.cc.

514 {
515 if (test->IsPlaygroundEnabled()) {
516 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
517 ImGui::SliderFloat("Source alpha", &src_alpha, 0, 1);
518 ImGui::End();
519 }
520
521 Color destination_color = Color::CornflowerBlue().WithAlpha(0.75);
522 auto source_colors = std::vector<Color>({Color::White().WithAlpha(0.75),
523 Color::LimeGreen().WithAlpha(0.75),
524 Color::Black().WithAlpha(0.75)});
525
526 DisplayListBuilder builder;
527 {
528 DlPaint paint;
529 paint.setColor(DlColor::kBlack());
530 builder.DrawPaint(paint);
531 }
532 // TODO(bdero): Why does this cause the left image to double scale on high DPI
533 // displays.
534 // builder.Scale(content_scale);
535
536 //----------------------------------------------------------------------------
537 /// 1. Save layer blending (top squares).
538 ///
539
540 builder.Save();
541 for (const auto& color : source_colors) {
542 builder.Save();
543 {
544 builder.ClipRect(DlRect::MakeXYWH(25, 25, 100, 100));
545 // Perform the blend in a SaveLayer so that the initial backdrop color is
546 // fully transparent black. SourceOver blend the result onto the parent
547 // pass.
548 builder.SaveLayer(std::nullopt);
549 {
550 DlPaint draw_paint;
551 draw_paint.setColor(
552 DlColor::RGBA(destination_color.red, destination_color.green,
553 destination_color.blue, destination_color.alpha));
554 builder.DrawPaint(draw_paint);
555
556 // Draw the source color in an offscreen pass and blend it to the parent
557 // pass.
558 DlPaint save_paint;
559 save_paint.setBlendMode(static_cast<DlBlendMode>(blend_mode));
560 builder.SaveLayer(std::nullopt, &save_paint);
561 { //
562 DlPaint paint;
563 paint.setColor(
564 DlColor::RGBA(color.red, color.green, color.blue, color.alpha));
565 builder.DrawRect(DlRect::MakeXYWH(25, 25, 100, 100), paint);
566 }
567 builder.Restore();
568 }
569 builder.Restore();
570 }
571 builder.Restore();
572 builder.Translate(100, 0);
573 }
574 builder.RestoreToCount(0);
575
576 //----------------------------------------------------------------------------
577 /// 2. CPU blend modes (bottom squares).
578 ///
579
580 builder.Save();
581 builder.Translate(0, 100);
582 // Perform the blend in a SaveLayer so that the initial backdrop color is
583 // fully transparent black. SourceOver blend the result onto the parent pass.
584 builder.SaveLayer(std::nullopt);
585 for (const auto& color : source_colors) {
586 // Simply write the CPU blended color to the pass.
587 DlPaint paint;
588 auto dest = destination_color.Blend(color, blend_mode);
589 paint.setColor(DlColor::RGBA(dest.red, dest.green, dest.blue, dest.alpha));
590 paint.setBlendMode(DlBlendMode::kSrcOver);
591 builder.DrawRect(DlRect::MakeXYWH(25, 25, 100, 100), paint);
592 builder.Translate(100, 0);
593 }
594 builder.Restore();
595 builder.Restore();
596
597 //----------------------------------------------------------------------------
598 /// 3. Image blending (bottom images).
599 ///
600 /// Compare these results with the images in the Flutter blend mode
601 /// documentation: https://api.flutter.dev/flutter/dart-ui/BlendMode.html
602 ///
603
604 builder.Translate(0, 250);
605
606 // Draw grid behind the images.
607 {
608 DlPaint paint;
609 paint.setColor(DlColor::RGBA(41 / 255.0, 41 / 255.0, 41 / 255.0, 1));
610 builder.DrawRect(DlRect::MakeLTRB(0, 0, 800, 400), paint);
611 }
612
613 DlPaint square_paint;
614 square_paint.setColor(DlColor::RGBA(15 / 255.0, 15 / 255.0, 15 / 255.0, 1));
615 for (int y = 0; y < 400 / 8; y++) {
616 for (int x = 0; x < 800 / 16; x++) {
617 builder.DrawRect(DlRect::MakeXYWH(x * 16 + (y % 2) * 8, y * 8, 8, 8),
618 square_paint);
619 }
620 }
621
622 // Uploaded image source (left image).
623 DlPaint paint;
624 paint.setBlendMode(DlBlendMode::kSrcOver);
625 builder.Save();
626 builder.SaveLayer(std::nullopt, &paint);
627 {
628 builder.DrawImage(dst_image, DlPoint(0, 0), DlImageSampling::kMipmapLinear,
629 &paint);
630
631 paint.setColor(DlColor::kWhite().withAlpha(src_alpha * 255));
632 paint.setBlendMode(static_cast<DlBlendMode>(blend_mode));
633 builder.DrawImage(src_image, DlPoint(0, 0), DlImageSampling::kMipmapLinear,
634 &paint);
635 }
636 builder.Restore();
637 builder.Restore();
638
639 // Rendered image source (right image).
640 builder.Save();
641
642 DlPaint save_paint;
643 builder.SaveLayer(std::nullopt, &save_paint);
644 {
645 builder.DrawImage(dst_image, DlPoint(400, 0),
646 DlImageSampling::kMipmapLinear, nullptr);
647
648 DlPaint save_paint;
649 save_paint.setColor(DlColor::kWhite().withAlpha(src_alpha * 255));
650 save_paint.setBlendMode(static_cast<DlBlendMode>(blend_mode));
651 builder.SaveLayer(std::nullopt, &save_paint);
652 {
653 builder.DrawImage(src_image, DlPoint(400, 0),
654 DlImageSampling::kMipmapLinear, nullptr);
655 }
656 builder.Restore();
657 }
658 builder.Restore();
659 builder.Restore();
660
661 return builder.Build();
662}
DlPaint & setColor(DlColor color)
Definition dl_paint.h:70
DlPaint & setBlendMode(DlBlendMode mode)
Definition dl_paint.h:85
bool IsPlaygroundEnabled() const
int32_t x
double y
impeller::BlendMode DlBlendMode
impeller::Point DlPoint
flutter::DlPaint DlPaint
Scalar blue
Definition color.h:138
Scalar alpha
Definition color.h:143
constexpr Color WithAlpha(Scalar new_alpha) const
Definition color.h:283
Scalar red
Definition color.h:128
Scalar green
Definition color.h:133
Color Blend(Color source, BlendMode blend_mode) const
Blends an unpremultiplied destination color into a given unpremultiplied source color to form a new u...
Definition color.cc:155

References impeller::Color::alpha, impeller::Color::Black(), impeller::Color::Blend(), impeller::Color::blue, impeller::Color::CornflowerBlue(), impeller::Color::green, impeller::Playground::IsPlaygroundEnabled(), flutter::DlColor::kBlack(), flutter::DlColor::kWhite(), impeller::Color::LimeGreen(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeXYWH(), impeller::Color::red, flutter::DlColor::RGBA(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), impeller::Color::White(), impeller::Color::WithAlpha(), flutter::DlColor::withAlpha(), x, and y.

◆ CanBatchSubmitTest()

bool impeller::testing::CanBatchSubmitTest ( std::string_view  driver_name,
bool  qc = true 
)

Definition at line 71 of file driver_info_vk_unittests.cc.

71 {
72 auto const context =
75 [&driver_name, qc](VkPhysicalDevice device,
76 VkPhysicalDeviceProperties* prop) {
77 if (qc) {
78 prop->vendorID = 0x168C; // Qualcomm
79 } else {
80 prop->vendorID = 0x13B5; // ARM
81 }
82 driver_name.copy(prop->deviceName, driver_name.size());
83 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
84 })
85 .Build();
86 return !GetWorkaroundsFromDriverInfo(*context->GetDriverInfo())
88}
MockVulkanContextBuilder & SetPhysicalPropertiesCallback(std::function< void(VkPhysicalDevice device, VkPhysicalDeviceProperties *physicalProperties)> physical_properties_callback)
VkDevice device
Definition main.cc:69
WorkaroundsVK GetWorkaroundsFromDriverInfo(DriverInfoVK &driver_info)
std::shared_ptr< ContextGLES > context

References impeller::WorkaroundsVK::batch_submit_command_buffer_timeout, context, device, impeller::GetWorkaroundsFromDriverInfo(), and impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback().

Referenced by TEST().

◆ CanRenderConicalGradientWithDithering()

static void impeller::testing::CanRenderConicalGradientWithDithering ( AiksTest aiks_test)
static

Definition at line 175 of file aiks_dl_gradient_unittests.cc.

175 {
176 DisplayListBuilder builder;
177 builder.Scale(aiks_test->GetContentScale().x, aiks_test->GetContentScale().y);
178 DlPaint paint;
179 builder.Translate(100.0, 100.0);
180
181 // #FFF -> #000
182 std::vector<DlColor> colors = {DlColor(Color{1.0, 1.0, 1.0, 1.0}.ToARGB()),
183 DlColor(Color{0.0, 0.0, 0.0, 1.0}.ToARGB())};
184 std::vector<Scalar> stops = {0.0, 1.0};
185
186 paint.setColorSource(DlColorSource::MakeConical({0, 1}, 0, {100, 100}, 100, 2,
187 colors.data(), stops.data(),
188 DlTileMode::kMirror));
189
190 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
191 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(builder.Build()));
192}
void Scale(DlScalar sx, DlScalar sy) override
void Translate(DlScalar tx, DlScalar ty) override
sk_sp< DisplayList > Build()
void DrawRect(const DlRect &rect, const DlPaint &paint) override
static std::shared_ptr< DlColorSource > MakeConical(DlPoint start_center, DlScalar start_radius, DlPoint end_center, DlScalar end_radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
DlPaint & setColorSource(std::nullptr_t source)
Definition dl_paint.h:131
bool OpenPlaygroundHere(const AiksDlPlaygroundCallback &callback)
Point GetContentScale() const
uint32_t ToARGB() const
Convert to ARGB 32 bit color.
Definition color.h:259
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition rect.h:136

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), impeller::Playground::GetContentScale(), flutter::DlColorSource::MakeConical(), impeller::TRect< Scalar >::MakeXYWH(), impeller::AiksPlayground::OpenPlaygroundHere(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColorSource(), impeller::Color::ToARGB(), flutter::DisplayListBuilder::Translate(), flutter::Point::x(), and flutter::Point::y().

Referenced by TEST_P().

◆ CanRenderLinearGradientWithDithering()

static void impeller::testing::CanRenderLinearGradientWithDithering ( AiksTest aiks_test)
static

Definition at line 112 of file aiks_dl_gradient_unittests.cc.

112 {
113 DisplayListBuilder builder;
114 DlPaint paint;
115 builder.Translate(100.0, 100.0);
116
117 // 0xffcccccc --> 0xff333333, taken from
118 // https://github.com/flutter/flutter/issues/118073#issue-1521699748
119 std::vector<DlColor> colors = {DlColor(0xFFCCCCCC), DlColor(0xFF333333)};
120 std::vector<Scalar> stops = {0.0, 1.0};
121
123 {0, 0}, {800, 500}, 2, colors.data(), stops.data(), DlTileMode::kClamp));
124 builder.DrawRect(DlRect::MakeXYWH(0, 0, 800, 500), paint);
125 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(builder.Build()));
126}
static std::shared_ptr< DlColorSource > MakeLinear(const DlPoint start_point, const DlPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeXYWH(), impeller::AiksPlayground::OpenPlaygroundHere(), flutter::DlPaint::setColorSource(), and flutter::DisplayListBuilder::Translate().

Referenced by TEST_P().

◆ CanRenderRadialGradientWithDithering()

static void impeller::testing::CanRenderRadialGradientWithDithering ( AiksTest aiks_test)
static

Definition at line 132 of file aiks_dl_gradient_unittests.cc.

132 {
133 DisplayListBuilder builder;
134 DlPaint paint;
135 builder.Translate(100.0, 100.0);
136
137 // #FFF -> #000
138 std::vector<DlColor> colors = {DlColor(Color{1.0, 1.0, 1.0, 1.0}.ToARGB()),
139 DlColor(Color{0.0, 0.0, 0.0, 1.0}.ToARGB())};
140 std::vector<Scalar> stops = {0.0, 1.0};
141
143 {600, 600}, 600, 2, colors.data(), stops.data(), DlTileMode::kClamp));
144 builder.DrawRect(DlRect::MakeXYWH(0, 0, 1200, 1200), paint);
145 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(builder.Build()));
146}
static std::shared_ptr< DlColorSource > MakeRadial(DlPoint center, DlScalar radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColorSource::MakeRadial(), impeller::TRect< Scalar >::MakeXYWH(), impeller::AiksPlayground::OpenPlaygroundHere(), flutter::DlPaint::setColorSource(), impeller::Color::ToARGB(), and flutter::DisplayListBuilder::Translate().

Referenced by TEST_P().

◆ CanRenderSweepGradientWithDithering()

static void impeller::testing::CanRenderSweepGradientWithDithering ( AiksTest aiks_test)
static

Definition at line 152 of file aiks_dl_gradient_unittests.cc.

152 {
153 DisplayListBuilder builder;
154 builder.Scale(aiks_test->GetContentScale().x, aiks_test->GetContentScale().y);
155 DlPaint paint;
156 builder.Translate(100.0, 100.0);
157
158 // #FFF -> #000
159 std::vector<DlColor> colors = {DlColor(Color{1.0, 1.0, 1.0, 1.0}.ToARGB()),
160 DlColor(Color{0.0, 0.0, 0.0, 1.0}.ToARGB())};
161 std::vector<Scalar> stops = {0.0, 1.0};
162
164 {100, 100}, /*start=*/45, /*end=*/135, 2, colors.data(), stops.data(),
165 DlTileMode::kMirror));
166
167 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
168 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(builder.Build()));
169}
static std::shared_ptr< DlColorSource > MakeSweep(DlPoint center, DlScalar start, DlScalar end, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), impeller::Playground::GetContentScale(), flutter::DlColorSource::MakeSweep(), impeller::TRect< Scalar >::MakeXYWH(), impeller::AiksPlayground::OpenPlaygroundHere(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColorSource(), impeller::Color::ToARGB(), flutter::DisplayListBuilder::Translate(), flutter::Point::x(), and flutter::Point::y().

Referenced by TEST_P().

◆ CanUseFramebufferFetch()

bool impeller::testing::CanUseFramebufferFetch ( std::string_view  driver_name,
bool  qc = true 
)

Definition at line 197 of file driver_info_vk_unittests.cc.

197 {
198 auto const context =
201 [&driver_name, qc](VkPhysicalDevice device,
202 VkPhysicalDeviceProperties* prop) {
203 if (qc) {
204 prop->vendorID = 0x168C; // Qualcomm
205 } else {
206 prop->vendorID = 0x13B5; // ARM
207 }
208 driver_name.copy(prop->deviceName, driver_name.size());
209 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
210 })
211 .Build();
212 return !GetWorkaroundsFromDriverInfo(*context->GetDriverInfo())
214}

References context, device, impeller::GetWorkaroundsFromDriverInfo(), impeller::WorkaroundsVK::input_attachment_self_dependency_broken, and impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback().

Referenced by TEST().

◆ CanUseMipgeneration()

bool impeller::testing::CanUseMipgeneration ( std::string_view  driver_name,
bool  qc = true 
)

Definition at line 127 of file driver_info_vk_unittests.cc.

127 {
128 auto const context =
131 [&driver_name, qc](VkPhysicalDevice device,
132 VkPhysicalDeviceProperties* prop) {
133 if (qc) {
134 prop->vendorID = 0x168C; // Qualcomm
135 } else {
136 prop->vendorID = 0x13B5; // ARM
137 }
138 driver_name.copy(prop->deviceName, driver_name.size());
139 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
140 })
141 .Build();
142 return !GetWorkaroundsFromDriverInfo(*context->GetDriverInfo())
144}

References impeller::WorkaroundsVK::broken_mipmap_generation, context, device, impeller::GetWorkaroundsFromDriverInfo(), and impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback().

Referenced by TEST().

◆ CanUsePrimitiveRestartSubmitTest()

bool impeller::testing::CanUsePrimitiveRestartSubmitTest ( std::string_view  driver_name,
bool  qc = true 
)

Definition at line 98 of file driver_info_vk_unittests.cc.

99 {
100 auto const context =
103 [&driver_name, qc](VkPhysicalDevice device,
104 VkPhysicalDeviceProperties* prop) {
105 if (qc) {
106 prop->vendorID = 0x168C; // Qualcomm
107 } else {
108 prop->vendorID = 0x13B5; // ARM
109 }
110 driver_name.copy(prop->deviceName, driver_name.size());
111 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
112 })
113 .Build();
114 return !GetWorkaroundsFromDriverInfo(*context->GetDriverInfo())
116}

References context, device, impeller::GetWorkaroundsFromDriverInfo(), impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback(), and impeller::WorkaroundsVK::slow_primitive_restart_performance.

Referenced by TEST().

◆ CAPABILITY_TEST() [1/12]

impeller::testing::CAPABILITY_TEST ( NeedsPartitionedHostBuffer  ,
false   
)

◆ CAPABILITY_TEST() [2/12]

impeller::testing::CAPABILITY_TEST ( SupportsCompute  ,
false   
)

◆ CAPABILITY_TEST() [3/12]

impeller::testing::CAPABILITY_TEST ( SupportsComputeSubgroups  ,
false   
)

◆ CAPABILITY_TEST() [4/12]

impeller::testing::CAPABILITY_TEST ( SupportsDecalSamplerAddressMode  ,
false   
)

◆ CAPABILITY_TEST() [5/12]

impeller::testing::CAPABILITY_TEST ( SupportsDeviceTransientTextures  ,
false   
)

◆ CAPABILITY_TEST() [6/12]

impeller::testing::CAPABILITY_TEST ( SupportsExtendedRangeFormats  ,
false   
)

◆ CAPABILITY_TEST() [7/12]

impeller::testing::CAPABILITY_TEST ( SupportsFramebufferFetch  ,
false   
)

◆ CAPABILITY_TEST() [8/12]

impeller::testing::CAPABILITY_TEST ( SupportsOffscreenMSAA  ,
false   
)

◆ CAPABILITY_TEST() [9/12]

impeller::testing::CAPABILITY_TEST ( SupportsReadFromResolve  ,
false   
)

◆ CAPABILITY_TEST() [10/12]

impeller::testing::CAPABILITY_TEST ( SupportsSSBO  ,
false   
)

◆ CAPABILITY_TEST() [11/12]

impeller::testing::CAPABILITY_TEST ( SupportsTextureToTextureBlits  ,
false   
)

◆ CAPABILITY_TEST() [12/12]

impeller::testing::CAPABILITY_TEST ( SupportsTriangleFan  ,
false   
)

◆ CompareFunctionUI()

static const CompareFunctionUIData & impeller::testing::CompareFunctionUI ( )
static

Definition at line 1176 of file renderer_unittests.cc.

1176 {
1178 return data;
1179}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36

References flutter::data.

Referenced by TEST_P().

◆ CopyBufferView()

template<typename T >
std::vector< T > impeller::testing::CopyBufferView ( const BufferView vertex_buffer)

Definition at line 19 of file tessellator_playground_unittests.cc.

19 {
20 Range range = vertex_buffer.GetRange();
21 uint8_t* base_ptr = vertex_buffer.GetBuffer()->OnGetContents() + range.offset;
22 return std::vector<T>(reinterpret_cast<T*>(base_ptr),
23 reinterpret_cast<T*>(base_ptr + range.length));
24}
virtual uint8_t * OnGetContents() const =0
Range GetRange() const
Definition buffer_view.h:27
const DeviceBuffer * GetBuffer() const
size_t length
Definition range.h:15
size_t offset
Definition range.h:14

References impeller::BufferView::GetBuffer(), impeller::BufferView::GetRange(), impeller::Range::length, impeller::Range::offset, and impeller::DeviceBuffer::OnGetContents().

◆ CreateDefaultPipeline()

template<class VertexShader , class FragmentShader >
std::shared_ptr< Pipeline< PipelineDescriptor > > impeller::testing::CreateDefaultPipeline ( RendererTest test,
const std::shared_ptr< Context > &  context 
)

Definition at line 1375 of file renderer_unittests.cc.

1377 {
1378 using TexturePipelineBuilder = PipelineBuilder<VertexShader, FragmentShader>;
1379 auto pipeline_desc =
1380 TexturePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
1381 if (!pipeline_desc.has_value()) {
1382 return nullptr;
1383 }
1384 if (!test->InitializePipelineDescriptorForRendering(*pipeline_desc)) {
1385 return nullptr;
1386 }
1387 auto pipeline =
1388 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
1389 if (!pipeline || !pipeline->IsValid()) {
1390 return nullptr;
1391 }
1392 return pipeline;
1393}
bool InitializePipelineDescriptorForRendering(PipelineDescriptor &desc) const
Initializes the provided |PipelineDescriptor| with appropriate default values to match the conditions...
std::shared_ptr< PipelineGLES > pipeline
An optional (but highly recommended) utility for creating pipelines from reflected shader information...

References context, impeller::Playground::InitializePipelineDescriptorForRendering(), and pipeline.

◆ CreateGlyphAtlas() [1/2]

static std::shared_ptr< GlyphAtlas > impeller::testing::CreateGlyphAtlas ( Context context,
const TypographerContext typographer_context,
HostBuffer data_host_buffer,
GlyphAtlas::Type  type,
const Matrix transform,
const std::shared_ptr< GlyphAtlasContext > &  atlas_context,
const std::shared_ptr< TextFrame > &  frame 
)
static

Definition at line 32 of file typographer_unittests.cc.

39 {
40 RenderableText render_frame{
41 .text_frame = frame,
42 .origin_transform = transform,
43 .properties = GlyphProperties{},
44 };
45 return typographer_context->CreateGlyphAtlas(context, type, data_host_buffer,
46 atlas_context, {render_frame});
47}
virtual std::shared_ptr< GlyphAtlas > CreateGlyphAtlas(Context &context, GlyphAtlas::Type type, HostBuffer &host_buffer, const std::shared_ptr< GlyphAtlasContext > &atlas_context, const std::vector< RenderableText > &text_frames) const =0
impeller::ShaderType type
const std::shared_ptr< TextFrame > text_frame
The TextFrame being rendered.

References context, impeller::TypographerContext::CreateGlyphAtlas(), impeller::RenderableText::text_frame, transform, and type.

Referenced by TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), and TEST_P().

◆ CreateGlyphAtlas() [2/2]

static std::shared_ptr< GlyphAtlas > impeller::testing::CreateGlyphAtlas ( Context context,
const TypographerContext typographer_context,
HostBuffer data_host_buffer,
GlyphAtlas::Type  type,
const Matrix transform,
const std::shared_ptr< GlyphAtlasContext > &  atlas_context,
const std::vector< std::shared_ptr< TextFrame > > &  frames,
const std::vector< GlyphProperties > &  properties 
)
static

Definition at line 49 of file typographer_unittests.cc.

57 {
58 size_t offset = 0;
59 std::vector<RenderableText> render_frames;
60 render_frames.reserve(frames.size());
61 for (auto& frame : frames) {
62 render_frames.emplace_back(frame, transform, properties[offset++]);
63 }
64 return typographer_context->CreateGlyphAtlas(context, type, data_host_buffer,
65 atlas_context, render_frames);
66}

References context, impeller::TypographerContext::CreateGlyphAtlas(), transform, and type.

◆ CreateMappingFromString()

static std::shared_ptr< fml::Mapping > impeller::testing::CreateMappingFromString ( std::string  p_string)
static

Definition at line 18 of file shader_archive_unittests.cc.

19 {
20 auto string = std::make_shared<std::string>(std::move(p_string));
21 return std::make_shared<fml::NonOwnedMapping>(
22 reinterpret_cast<const uint8_t*>(string->data()), string->size(),
23 [string](auto, auto) {});
24}

Referenced by TEST().

◆ CreateStringFromMapping()

const std::string impeller::testing::CreateStringFromMapping ( const fml::Mapping mapping)

Definition at line 26 of file shader_archive_unittests.cc.

26 {
27 return std::string{reinterpret_cast<const char*>(mapping.GetMapping()),
28 mapping.GetSize()};
29}
virtual const uint8_t * GetMapping() const =0
virtual size_t GetSize() const =0

References fml::Mapping::GetMapping(), and fml::Mapping::GetSize().

Referenced by TEST().

◆ CreateSurface()

vk::UniqueSurfaceKHR impeller::testing::CreateSurface ( const ContextVK context)

Definition at line 16 of file swapchain_unittests.cc.

16 {
17#if FML_OS_DARWIN
18 impeller::vk::MetalSurfaceCreateInfoEXT createInfo = {};
19 auto [result, surface] =
20 context.GetInstance().createMetalSurfaceEXTUnique(createInfo);
21 FML_DCHECK(result == vk::Result::eSuccess);
22 return std::move(surface);
23#else
24 return {};
25#endif // FML_OS_DARWIN
26}
VkSurfaceKHR surface
Definition main.cc:65
#define FML_DCHECK(condition)
Definition logging.h:122

References context, FML_DCHECK, and surface.

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ CreateTestCanvas()

std::unique_ptr< Canvas > impeller::testing::CreateTestCanvas ( ContentContext context,
std::optional< Rect cull_rect = std::nullopt,
bool  requires_readback = false 
)

Definition at line 27 of file canvas_unittests.cc.

30 {
31 TextureDescriptor onscreen_desc;
32 onscreen_desc.size = {100, 100};
33 onscreen_desc.format =
34 context.GetDeviceCapabilities().GetDefaultColorFormat();
35 onscreen_desc.usage = TextureUsage::kRenderTarget;
36 onscreen_desc.storage_mode = StorageMode::kDevicePrivate;
37 onscreen_desc.sample_count = SampleCount::kCount1;
38 std::shared_ptr<Texture> onscreen =
39 context.GetContext()->GetResourceAllocator()->CreateTexture(
40 onscreen_desc);
41
42 ColorAttachment color0;
43 color0.load_action = LoadAction::kClear;
44 if (context.GetContext()->GetCapabilities()->SupportsOffscreenMSAA()) {
45 TextureDescriptor onscreen_msaa_desc = onscreen_desc;
46 onscreen_msaa_desc.sample_count = SampleCount::kCount4;
47 onscreen_msaa_desc.storage_mode = StorageMode::kDeviceTransient;
48 onscreen_msaa_desc.type = TextureType::kTexture2DMultisample;
49
50 std::shared_ptr<Texture> onscreen_msaa =
51 context.GetContext()->GetResourceAllocator()->CreateTexture(
52 onscreen_msaa_desc);
53 color0.resolve_texture = onscreen;
54 color0.texture = onscreen_msaa;
55 color0.store_action = StoreAction::kMultisampleResolve;
56 } else {
57 color0.texture = onscreen;
58 }
59
60 RenderTarget render_target;
61 render_target.SetColorAttachment(color0, 0);
62
63 if (cull_rect.has_value()) {
64 return std::make_unique<Canvas>(
65 context, render_target, /*is_onscreen=*/false,
66 /*requires_readback=*/requires_readback, cull_rect.value());
67 }
68 return std::make_unique<Canvas>(context, render_target, /*is_onscreen=*/false,
69 /*requires_readback=*/requires_readback);
70}
std::shared_ptr< Texture > resolve_texture
Definition formats.h:910
LoadAction load_action
Definition formats.h:911
std::shared_ptr< Texture > texture
Definition formats.h:909
StoreAction store_action
Definition formats.h:912
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...

References context, impeller::TextureDescriptor::format, impeller::kClear, impeller::kCount1, impeller::kCount4, impeller::kDevicePrivate, impeller::kDeviceTransient, impeller::kMultisampleResolve, impeller::kRenderTarget, impeller::kTexture2DMultisample, impeller::Attachment::load_action, impeller::Attachment::resolve_texture, impeller::TextureDescriptor::sample_count, impeller::RenderTarget::SetColorAttachment(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::Attachment::store_action, impeller::Attachment::texture, impeller::TextureDescriptor::type, and impeller::TextureDescriptor::usage.

Referenced by TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), and TEST_P().

◆ CreateTestYUVTextures()

static std::vector< std::shared_ptr< Texture > > impeller::testing::CreateTestYUVTextures ( Context context,
YUVColorSpace  yuv_color_space 
)
static

Definition at line 1702 of file entity_unittests.cc.

1704 {
1705 Vector3 red = {244.0 / 255.0, 67.0 / 255.0, 54.0 / 255.0};
1706 Vector3 green = {76.0 / 255.0, 175.0 / 255.0, 80.0 / 255.0};
1707 Vector3 blue = {33.0 / 255.0, 150.0 / 255.0, 243.0 / 255.0};
1708 Vector3 white = {1.0, 1.0, 1.0};
1709 Vector3 red_yuv = RGBToYUV(red, yuv_color_space);
1710 Vector3 green_yuv = RGBToYUV(green, yuv_color_space);
1711 Vector3 blue_yuv = RGBToYUV(blue, yuv_color_space);
1712 Vector3 white_yuv = RGBToYUV(white, yuv_color_space);
1713 std::vector<Vector3> yuvs{red_yuv, green_yuv, blue_yuv, white_yuv};
1714 std::vector<uint8_t> y_data;
1715 std::vector<uint8_t> uv_data;
1716 for (int i = 0; i < 4; i++) {
1717 auto yuv = yuvs[i];
1718 uint8_t y = std::round(yuv.x * 255.0);
1719 uint8_t u = std::round(yuv.y * 255.0);
1720 uint8_t v = std::round(yuv.z * 255.0);
1721 for (int j = 0; j < 16; j++) {
1722 y_data.push_back(y);
1723 }
1724 for (int j = 0; j < 8; j++) {
1725 uv_data.push_back(j % 2 == 0 ? u : v);
1726 }
1727 }
1728 auto cmd_buffer = context->CreateCommandBuffer();
1729 auto blit_pass = cmd_buffer->CreateBlitPass();
1730
1731 impeller::TextureDescriptor y_texture_descriptor;
1733 y_texture_descriptor.format = PixelFormat::kR8UNormInt;
1734 y_texture_descriptor.size = {8, 8};
1735 auto y_texture =
1736 context->GetResourceAllocator()->CreateTexture(y_texture_descriptor);
1737 auto y_mapping = std::make_shared<fml::DataMapping>(y_data);
1738 auto y_mapping_buffer =
1739 context->GetResourceAllocator()->CreateBufferWithCopy(*y_mapping);
1740
1741 blit_pass->AddCopy(DeviceBuffer::AsBufferView(y_mapping_buffer), y_texture);
1742
1743 impeller::TextureDescriptor uv_texture_descriptor;
1744 uv_texture_descriptor.storage_mode = impeller::StorageMode::kHostVisible;
1745 uv_texture_descriptor.format = PixelFormat::kR8G8UNormInt;
1746 uv_texture_descriptor.size = {4, 4};
1747 auto uv_texture =
1748 context->GetResourceAllocator()->CreateTexture(uv_texture_descriptor);
1749 auto uv_mapping = std::make_shared<fml::DataMapping>(uv_data);
1750 auto uv_mapping_buffer =
1751 context->GetResourceAllocator()->CreateBufferWithCopy(*uv_mapping);
1752
1753 blit_pass->AddCopy(DeviceBuffer::AsBufferView(uv_mapping_buffer), uv_texture);
1754
1755 if (!blit_pass->EncodeCommands() ||
1756 !context->GetCommandQueue()->Submit({cmd_buffer}).ok()) {
1757 FML_DLOG(ERROR) << "Could not copy contents into Y/UV texture.";
1758 }
1759
1760 return {y_texture, uv_texture};
1761}
#define FML_DLOG(severity)
Definition logging.h:121
static Vector3 RGBToYUV(Vector3 rgb, YUVColorSpace yuv_color_space)

References impeller::DeviceBuffer::AsBufferView(), context, FML_DLOG, impeller::TextureDescriptor::format, i, impeller::kHostVisible, impeller::kR8G8UNormInt, impeller::kR8UNormInt, RGBToYUV(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, and y.

Referenced by TEST_P().

◆ DoGradientOvalStrokeMaskBlur()

sk_sp< flutter::DisplayList > impeller::testing::DoGradientOvalStrokeMaskBlur ( Vector2  content_Scale,
Scalar  sigma,
DlBlurStyle  style 
)

Definition at line 63 of file aiks_dl_blur_unittests.cc.

65 {
66 DisplayListBuilder builder;
67 builder.Scale(content_Scale.x, content_Scale.y);
68
69 DlPaint background_paint;
70 background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
71 builder.DrawPaint(background_paint);
72
73 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue()};
74 std::vector<Scalar> stops = {0.0, 1.0};
75
76 DlPaint paint;
77 paint.setMaskFilter(DlBlurMaskFilter::Make(style, sigma));
78 auto gradient = DlColorSource::MakeLinear(
79 {0, 0}, {200, 200}, 2, colors.data(), stops.data(), DlTileMode::kClamp);
80 paint.setColorSource(gradient);
81 paint.setColor(DlColor::kWhite());
82 paint.setDrawStyle(DlDrawStyle::kStroke);
83 paint.setStrokeWidth(20);
84
85 builder.Save();
86 builder.Translate(100, 100);
87
88 {
89 DlPaint line_paint;
90 line_paint.setColor(DlColor::kWhite());
91 builder.DrawLine(DlPoint(100, 0), DlPoint(100, 60), line_paint);
92 builder.DrawLine(DlPoint(0, 30), DlPoint(200, 30), line_paint);
93 }
94
95 DlRoundRect rrect =
96 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(0, 0, 200.0f, 60.0f), 50, 100);
97 builder.DrawRoundRect(rrect, paint);
98 builder.Restore();
99
100 return builder.Build();
101}
void DrawRoundRect(const DlRoundRect &rrect, const DlPaint &paint) override
void DrawLine(const DlPoint &p0, const DlPoint &p1, const DlPaint &paint) override
void DrawPaint(const DlPaint &paint) override
DlPaint & setMaskFilter(std::nullptr_t filter)
Definition dl_paint.h:185
impeller::RoundRect DlRoundRect

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawLine(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlBlurMaskFilter::Make(), flutter::DlColorSource::MakeLinear(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setMaskFilter(), flutter::DlPaint::setStrokeWidth(), flutter::DisplayListBuilder::Translate(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by TEST_P(), TEST_P(), TEST_P(), TEST_P(), and TEST_P().

◆ doNothing()

void impeller::testing::doNothing ( )

Definition at line 34 of file mock_gles.cc.

34{}

◆ DrainMicrotasks()

static bool impeller::testing::DrainMicrotasks ( )
static

◆ DrawCompressedTextureGolden()

static void impeller::testing::DrawCompressedTextureGolden ( RendererGoldenTest test,
PixelFormat  format,
const std::vector< uint8_t > &  block_data,
ISize  size 
)
static

Definition at line 207 of file renderer_golden_unittests.cc.

210 {
211 using VS = TextureVertexShader;
212 using FS = TextureFragmentShader;
213
214 std::shared_ptr<Context> context = test.GetContext();
215 ASSERT_TRUE(context);
216
217 TextureDescriptor texture_desc;
218 texture_desc.storage_mode = StorageMode::kHostVisible;
219 texture_desc.format = format;
220 texture_desc.size = size;
221 texture_desc.mip_count = 1u;
222 texture_desc.usage = TextureUsage::kShaderRead;
223 auto texture = context->GetResourceAllocator()->CreateTexture(texture_desc);
224 ASSERT_TRUE(texture);
225 ASSERT_TRUE(texture->SetContents(block_data.data(), block_data.size()));
226
228 ASSERT_TRUE(desc.has_value());
229 ASSERT_TRUE(test.InitializePipelineDescriptorForRendering(*desc));
230 auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).Get();
231 ASSERT_TRUE(pipeline);
232
233 // A fullscreen quad in normalized device coordinates with an identity MVP.
234 VertexBufferBuilder<VS::PerVertexData> vertex_buffer_builder;
235 vertex_buffer_builder.AddVertices({
236 {{-1, -1, 0.0}, {0.0, 0.0}},
237 {{1, -1, 0.0}, {1.0, 0.0}},
238 {{1, 1, 0.0}, {1.0, 1.0}},
239 {{-1, -1, 0.0}, {0.0, 0.0}},
240 {{1, 1, 0.0}, {1.0, 1.0}},
241 {{-1, 1, 0.0}, {0.0, 1.0}},
242 });
243 auto vertex_buffer = vertex_buffer_builder.CreateVertexBuffer(
244 *context->GetResourceAllocator());
245
246 const auto& sampler = context->GetSamplerLibrary()->GetSampler({});
247
248 auto host_buffer = HostBuffer::Create(
249 context->GetResourceAllocator(), context->GetIdleWaiter(),
250 context->GetCapabilities()->GetMinimumUniformAlignment());
251
252 ASSERT_TRUE(test.OpenPlaygroundHere([&](RenderPass& pass) -> bool {
253 host_buffer->Reset();
254 pass.SetPipeline(pipeline);
255 pass.SetVertexBuffer(vertex_buffer);
256
257 VS::UniformBuffer uniforms;
258 uniforms.mvp = Matrix();
259 VS::BindUniformBuffer(pass, host_buffer->EmplaceUniform(uniforms));
260 FS::BindTextureContents(pass, texture, sampler);
261
262 return pass.Draw().ok();
263 }));
264}
bool OpenPlaygroundHere(const RenderCallback &render_callback)
std::shared_ptr< Context > GetContext() const
VertexBuffer CreateVertexBuffer(HostBuffer &data_host_buffer, HostBuffer &indexes_host_buffer) const
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
uint32_t uint32_t * format
FlTexture * texture
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
GlyphAtlasPipeline::VertexShader VS
GlyphAtlasPipeline::FragmentShader FS

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), context, impeller::HostBuffer::Create(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::TextureDescriptor::format, format, impeller::Playground::GetContext(), impeller::Playground::InitializePipelineDescriptorForRendering(), impeller::kHostVisible, impeller::kShaderRead, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::TextureDescriptor::mip_count, impeller::Playground::OpenPlaygroundHere(), pipeline, impeller::TextureDescriptor::size, flutter::size, impeller::TextureDescriptor::storage_mode, texture, and impeller::TextureDescriptor::usage.

Referenced by TEST_P(), TEST_P(), and TEST_P().

◆ DrawManuallyMippedTextureGolden()

static void impeller::testing::DrawManuallyMippedTextureGolden ( RendererGoldenTest test,
float  lod 
)
static

Definition at line 380 of file renderer_golden_unittests.cc.

381 {
382 using VS = MipmapsVertexShader;
383 using FS = MipmapsFragmentShader;
384
385 std::shared_ptr<Context> context = test.GetContext();
386 ASSERT_TRUE(context);
387
388 TextureDescriptor texture_desc;
389 texture_desc.storage_mode = StorageMode::kHostVisible;
390 texture_desc.format = PixelFormat::kR8G8B8A8UNormInt;
391 texture_desc.size = ISize{8, 8};
392 texture_desc.mip_count = 2u; // base 8x8 + one 4x4 mip; populated by hand.
393 texture_desc.usage = TextureUsage::kShaderRead;
394 auto texture = context->GetResourceAllocator()->CreateTexture(texture_desc);
395 ASSERT_TRUE(texture);
396
397 // Base level: a 2x2 grid of red/green/blue/white quadrants.
398 std::vector<uint8_t> base_data(8 * 8 * 4);
399 for (int y = 0; y < 8; ++y) {
400 for (int x = 0; x < 8; ++x) {
401 const size_t i = (static_cast<size_t>(y) * 8 + x) * 4;
402 const bool right = x >= 4;
403 const bool bottom = y >= 4;
404 uint8_t r = 0, g = 0, b = 0;
405 if (!right && !bottom) {
406 r = 0xFF; // top-left: red.
407 } else if (right && !bottom) {
408 g = 0xFF; // top-right: green.
409 } else if (!right && bottom) {
410 b = 0xFF; // bottom-left: blue.
411 } else {
412 r = g = b = 0xFF; // bottom-right: white.
413 }
414 base_data[i] = r;
415 base_data[i + 1] = g;
416 base_data[i + 2] = b;
417 base_data[i + 3] = 0xFF;
418 }
419 }
420 ASSERT_TRUE(texture->SetContents(base_data.data(), base_data.size()));
421
422 // Second level (4x4), solid orange so it is distinct from the base and from
423 // an empty level. Uploaded by hand via a blit copy rather than the
424 // GenerateMipmap blit, which keeps NeedsMipmapGeneration() true. This
425 // initializes the whole mip chain so the texture is complete on backends
426 // that require it (OpenGL ES samples a mipmapped texture as incomplete
427 // otherwise).
428 std::vector<uint8_t> mip_data(4 * 4 * 4);
429 for (size_t i = 0; i < mip_data.size(); i += 4) {
430 mip_data[i] = 0xFF; // r
431 mip_data[i + 1] = 0x80; // g
432 mip_data[i + 2] = 0x00; // b
433 mip_data[i + 3] = 0xFF; // a
434 }
435 auto mip_buffer = context->GetResourceAllocator()->CreateBufferWithCopy(
436 mip_data.data(), mip_data.size());
437 ASSERT_TRUE(mip_buffer);
438 auto cmd_buffer = context->CreateCommandBuffer();
439 ASSERT_TRUE(cmd_buffer);
440 auto blit_pass = cmd_buffer->CreateBlitPass();
441 ASSERT_TRUE(blit_pass);
442 // The destination region must match the 4x4 second level, not the 8x8 base,
443 // or the copy size check rejects the smaller source buffer.
444 ASSERT_TRUE(
445 blit_pass->AddCopy(DeviceBuffer::AsBufferView(mip_buffer), texture,
446 /*destination_region=*/IRect::MakeSize(ISize{4, 4}),
447 /*label=*/"Upload mip 1", /*mip_level=*/1u));
448 ASSERT_TRUE(blit_pass->EncodeCommands());
449 ASSERT_TRUE(context->GetCommandQueue()->Submit({cmd_buffer}).ok());
450
451 auto desc = PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor(*context);
452 ASSERT_TRUE(desc.has_value());
453 ASSERT_TRUE(test.InitializePipelineDescriptorForRendering(*desc));
454 auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).Get();
455 ASSERT_TRUE(pipeline);
456
457 // A fullscreen quad in normalized device coordinates with an identity MVP.
458 VertexBufferBuilder<VS::PerVertexData> vertex_buffer_builder;
459 vertex_buffer_builder.AddVertices({
460 {{-1, -1}, {0.0, 0.0}},
461 {{1, -1}, {1.0, 0.0}},
462 {{1, 1}, {1.0, 1.0}},
463 {{-1, -1}, {0.0, 0.0}},
464 {{1, 1}, {1.0, 1.0}},
465 {{-1, 1}, {0.0, 1.0}},
466 });
467 auto vertex_buffer = vertex_buffer_builder.CreateVertexBuffer(
468 *context->GetResourceAllocator());
469
470 const auto& sampler = context->GetSamplerLibrary()->GetSampler({});
471
472 auto host_buffer = HostBuffer::Create(
473 context->GetResourceAllocator(), context->GetIdleWaiter(),
474 context->GetCapabilities()->GetMinimumUniformAlignment());
475
476 ASSERT_TRUE(test.OpenPlaygroundHere([&](RenderPass& pass) -> bool {
477 host_buffer->Reset();
478 pass.SetPipeline(pipeline);
479 pass.SetVertexBuffer(vertex_buffer);
480
481 VS::FrameInfo frame_info;
482 frame_info.mvp = Matrix();
483 VS::BindFrameInfo(pass, host_buffer->EmplaceUniform(frame_info));
484
485 FS::FragInfo frag_info;
486 frag_info.lod = lod;
487 FS::BindFragInfo(pass, host_buffer->EmplaceUniform(frag_info));
488
489 FS::BindTex(pass, texture, sampler);
490
491 return pass.Draw().ok();
492 }));
493}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), impeller::DeviceBuffer::AsBufferView(), context, impeller::HostBuffer::Create(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::TextureDescriptor::format, impeller::Playground::GetContext(), i, impeller::Playground::InitializePipelineDescriptorForRendering(), impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, impeller::kShaderRead, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::TRect< T >::MakeSize(), impeller::TextureDescriptor::mip_count, impeller::Playground::OpenPlaygroundHere(), pipeline, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, texture, impeller::TextureDescriptor::usage, x, and y.

Referenced by TEST_P(), and TEST_P().

◆ flip_lr()

template<typename R >
static constexpr R impeller::testing::flip_lr ( rect)
inlinestaticconstexpr

Definition at line 1573 of file rect_unittests.cc.

1573 {
1574 return R::MakeLTRB(rect.GetRight(), rect.GetTop(), //
1575 rect.GetLeft(), rect.GetBottom());
1576}

Referenced by flip_lrtb(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ flip_lrtb()

template<typename R >
static constexpr R impeller::testing::flip_lrtb ( rect)
inlinestaticconstexpr

Definition at line 1585 of file rect_unittests.cc.

1585 {
1586 return flip_lr(flip_tb(rect));
1587}
static constexpr R flip_tb(R rect)
static constexpr R flip_lr(R rect)

References flip_lr(), and flip_tb().

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ flip_tb()

template<typename R >
static constexpr R impeller::testing::flip_tb ( rect)
inlinestaticconstexpr

Definition at line 1579 of file rect_unittests.cc.

1579 {
1580 return R::MakeLTRB(rect.GetLeft(), rect.GetBottom(), //
1581 rect.GetRight(), rect.GetTop());
1582}

Referenced by flip_lrtb(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ FML_TEST_CLASS() [1/4]

impeller::testing::FML_TEST_CLASS ( BufferBindingsGLESTest  ,
BindArrayData   
)

◆ FML_TEST_CLASS() [2/4]

impeller::testing::FML_TEST_CLASS ( BufferBindingsGLESTest  ,
BindUniformData   
)

◆ FML_TEST_CLASS() [3/4]

impeller::testing::FML_TEST_CLASS ( BufferBindingsGLESTest  ,
BindUniformDataVerticesAndMatrices   
)

◆ FML_TEST_CLASS() [4/4]

impeller::testing::FML_TEST_CLASS ( BufferBindingsGLESTest  ,
BindUniformFailsWithoutFloatType   
)

◆ GetBlendModeSelection()

static BlendModeSelection impeller::testing::GetBlendModeSelection ( )
static

Definition at line 44 of file aiks_dl_blend_unittests.cc.

44 {
45 std::vector<const char*> blend_mode_names;
46 std::vector<BlendMode> blend_mode_values;
47 {
48 const std::vector<std::tuple<const char*, BlendMode>> blends = {
50 assert(blends.size() ==
51 static_cast<size_t>(Entity::kLastAdvancedBlendMode) + 1);
52 for (const auto& [name, mode] : blends) {
53 blend_mode_names.push_back(name);
54 blend_mode_values.push_back(mode);
55 }
56 }
57
58 return {blend_mode_names, blend_mode_values};
59}
#define BLEND_MODE_TUPLE(blend_mode)
#define IMPELLER_FOR_EACH_BLEND_MODE(V)
Definition color.h:19
const char * name
Definition fuchsia.cc:50

References BLEND_MODE_TUPLE, IMPELLER_FOR_EACH_BLEND_MODE, impeller::Entity::kLastAdvancedBlendMode, flutter::mode, and flutter::name.

Referenced by TEST_P(), and TEST_P().

◆ GetImageMemoryBarriers()

std::vector< VkImageMemoryBarrier > & impeller::testing::GetImageMemoryBarriers ( VkCommandBuffer  buffer)

Definition at line 1339 of file mock_vulkan.cc.

1340 {
1341 MockCommandBuffer* mock_command_buffer =
1342 reinterpret_cast<MockCommandBuffer*>(buffer);
1343 return mock_command_buffer->image_memory_barriers_;
1344}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98

References flutter::buffer.

Referenced by impeller::TEST().

◆ GetMockVulkanFunctions()

std::shared_ptr< std::vector< std::string > > impeller::testing::GetMockVulkanFunctions ( VkDevice  device)

Definition at line 1329 of file mock_vulkan.cc.

1330 {
1331 MockDevice* mock_device = MockDevice::Unwrap(device);
1332 return mock_device->GetCalledFunctions();
1333}

References device, and GetMockVulkanFunctions().

Referenced by GetMockVulkanFunctions(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ GetRecordedViewports()

const std::vector< VkViewport > & impeller::testing::GetRecordedViewports ( VkCommandBuffer  buffer)

Returns the viewports passed to vkCmdSetViewport calls on the given command buffer, in call order.

Definition at line 1346 of file mock_vulkan.cc.

1346 {
1347 MockCommandBuffer* mock_command_buffer =
1348 reinterpret_cast<MockCommandBuffer*>(buffer);
1349 return mock_command_buffer->recorded_viewports_;
1350}

References flutter::buffer.

Referenced by TEST().

◆ ImpellerUnittestSetup()

void impeller::testing::ImpellerUnittestSetup ( )

◆ INSTANTIATE_COMPUTE_SUITE()

impeller::testing::INSTANTIATE_COMPUTE_SUITE ( ComputeTest  )

◆ INSTANTIATE_METAL_PLAYGROUND_SUITE()

impeller::testing::INSTANTIATE_METAL_PLAYGROUND_SUITE ( AllocatorMTLTest  )

◆ INSTANTIATE_OPENGLES_PLAYGROUND_SUITE()

impeller::testing::INSTANTIATE_OPENGLES_PLAYGROUND_SUITE ( PipelineLibraryGLESTest  )

◆ INSTANTIATE_PLAYGROUND_SUITE() [1/11]

impeller::testing::INSTANTIATE_PLAYGROUND_SUITE ( AiksTest  )

◆ INSTANTIATE_PLAYGROUND_SUITE() [2/11]

impeller::testing::INSTANTIATE_PLAYGROUND_SUITE ( BlendFilterContentsTest  )

◆ INSTANTIATE_PLAYGROUND_SUITE() [3/11]

impeller::testing::INSTANTIATE_PLAYGROUND_SUITE ( DisplayListTest  )

◆ INSTANTIATE_PLAYGROUND_SUITE() [4/11]

impeller::testing::INSTANTIATE_PLAYGROUND_SUITE ( GaussianBlurFilterContentsTest  )

◆ INSTANTIATE_PLAYGROUND_SUITE() [5/11]

impeller::testing::INSTANTIATE_PLAYGROUND_SUITE ( HostBufferTest  )

◆ INSTANTIATE_PLAYGROUND_SUITE() [6/11]

impeller::testing::INSTANTIATE_PLAYGROUND_SUITE ( MatrixFilterContentsTest  )

◆ INSTANTIATE_PLAYGROUND_SUITE() [7/11]

impeller::testing::INSTANTIATE_PLAYGROUND_SUITE ( MorphologyFilterContentsTest  )

◆ INSTANTIATE_PLAYGROUND_SUITE() [8/11]

impeller::testing::INSTANTIATE_PLAYGROUND_SUITE ( RendererDartTest  )

◆ INSTANTIATE_PLAYGROUND_SUITE() [9/11]

impeller::testing::INSTANTIATE_PLAYGROUND_SUITE ( RendererGoldenTest  )

◆ INSTANTIATE_PLAYGROUND_SUITE() [10/11]

impeller::testing::INSTANTIATE_PLAYGROUND_SUITE ( RuntimeStageTest  )

◆ INSTANTIATE_PLAYGROUND_SUITE() [11/11]

impeller::testing::INSTANTIATE_PLAYGROUND_SUITE ( TextContentsTest  )

◆ INSTANTIATE_TEST_SUITE_P()

impeller::testing::INSTANTIATE_TEST_SUITE_P ( FrameBufferObject  ,
RenderPassGLESWithDiscardFrameBufferExtTest  ,
::testing::ValuesIn(std::vector< DiscardFrameBufferParams >{ {.frame_buffer_id=0,.expected_attachments={GL_COLOR_EXT, GL_DEPTH_EXT, GL_STENCIL_EXT}}, {.frame_buffer_id=1,.expected_attachments={GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}}})  ,
[] (const ::testing::TestParamInfo< DiscardFrameBufferParams > &info) { return(info.param.frame_buffer_id==0) ? "Default" :"NonDefault";}   
)

◆ INSTANTIATE_VULKAN_PLAYGROUND_SUITE()

impeller::testing::INSTANTIATE_VULKAN_PLAYGROUND_SUITE ( DriverInfoVKTest  )

◆ InstantiateTestShaderLibrary()

static void impeller::testing::InstantiateTestShaderLibrary ( Context::BackendType  backend_type)
static

Definition at line 35 of file renderer_dart_unittests.cc.

35 {
36 auto fixture =
37 flutter::testing::OpenFixtureAsMapping("playground.shaderbundle");
39 backend_type, std::move(fixture));
41}
static void SetOverride(fml::RefPtr< ShaderLibrary > override_shader_library)
Sets a return override for MakeFromAsset for testing purposes.
static fml::RefPtr< ShaderLibrary > MakeFromFlatbuffer(impeller::Context::BackendType backend_type, std::shared_ptr< fml::Mapping > payload, std::string library_id="")
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.
Definition testing.cc:58

References flutter::gpu::ShaderLibrary::MakeFromFlatbuffer(), flutter::testing::OpenFixtureAsMapping(), and flutter::gpu::ShaderLibrary::SetOverride().

Referenced by impeller::testing::RendererDartTest::GetIsolate().

◆ IsBadVersionTest()

bool impeller::testing::IsBadVersionTest ( std::string_view  driver_name,
bool  qc = true 
)

Definition at line 53 of file driver_info_vk_unittests.cc.

53 {
54 auto const context =
57 [&driver_name, qc](VkPhysicalDevice device,
58 VkPhysicalDeviceProperties* prop) {
59 if (qc) {
60 prop->vendorID = 0x168C; // Qualcomm
61 } else {
62 prop->vendorID = 0x13B5; // ARM
63 }
64 driver_name.copy(prop->deviceName, driver_name.size());
65 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
66 })
67 .Build();
68 return context->GetDriverInfo()->IsKnownBadDriver();
69}

References context, device, and impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback().

Referenced by TEST(), TEST(), and TEST().

◆ MaskBlurVariantTest()

static sk_sp< DisplayList > impeller::testing::MaskBlurVariantTest ( const AiksTest test_context,
const MaskBlurTestConfig config 
)
static

Definition at line 604 of file aiks_dl_blur_unittests.cc.

606 {
607 DisplayListBuilder builder;
608 builder.Scale(test_context.GetContentScale().x,
609 test_context.GetContentScale().y);
610 builder.Scale(0.8f, 0.8f);
611 builder.Translate(50.f, 50.f);
612
613 DlPaint draw_paint;
614 draw_paint.setColor(
615 DlColor::RGBA(Color::AntiqueWhite().red, Color::AntiqueWhite().green,
616 Color::AntiqueWhite().blue, Color::AntiqueWhite().alpha));
617 builder.DrawPaint(draw_paint);
618
619 DlPaint paint;
620 paint.setMaskFilter(DlBlurMaskFilter::Make(config.style, config.sigma));
621 paint.setInvertColors(config.invert_colors);
622 paint.setImageFilter(config.image_filter);
623 paint.setBlendMode(config.blend_mode);
624
625 const Scalar x = 50;
626 const Scalar radius = 20.0f;
627 const Scalar y_spacing = 100.0f;
628 Scalar alpha = config.alpha * 255;
629
630 Scalar y = 50;
631 paint.setColor(DlColor::kCrimson().withAlpha(alpha));
632 builder.DrawRect(DlRect::MakeXYWH(x + 25 - radius / 2, y + radius / 2, //
633 radius, 60.0f - radius),
634 paint);
635
636 y += y_spacing;
637 paint.setColor(DlColor::kBlue().withAlpha(alpha));
638 builder.DrawCircle(DlPoint{x + 25, y + 25}, radius, paint);
639
640 y += y_spacing;
641 paint.setColor(DlColor::kGreen().withAlpha(alpha));
642 builder.DrawOval(DlRect::MakeXYWH(x + 25 - radius / 2, y + radius / 2, //
643 radius, 60.0f - radius),
644 paint);
645
646 y += y_spacing;
647 paint.setColor(DlColor::kPurple().withAlpha(alpha));
648 DlRoundRect rrect = DlRoundRect::MakeRectXY(
649 DlRect::MakeXYWH(x, y, 60.0f, 60.0f), radius, radius);
650 builder.DrawRoundRect(rrect, paint);
651
652 y += y_spacing;
653 paint.setColor(DlColor::kOrange().withAlpha(alpha));
654
655 rrect = DlRoundRect::MakeRectXY(DlRect::MakeXYWH(x, y, 60.0f, 60.0f), //
656 radius, 5.0);
657 builder.DrawRoundRect(rrect, paint);
658
659 y += y_spacing;
660 paint.setColor(DlColor::kMaroon().withAlpha(alpha));
661
662 {
663 DlPathBuilder path_builder;
664 path_builder.MoveTo(DlPoint(x + 0, y + 60));
665 path_builder.LineTo(DlPoint(x + 30, y + 0));
666 path_builder.LineTo(DlPoint(x + 60, y + 60));
667 path_builder.Close();
668
669 builder.DrawPath(path_builder.TakePath(), paint);
670 }
671
672 y += y_spacing;
673 paint.setColor(DlColor::kMaroon().withAlpha(alpha));
674 {
675 DlPath path = DlPath::MakeArc(Rect::MakeXYWH(x + 5, y, 50, 50), //
676 Degrees(90), Degrees(180), false) +
677 DlPath::MakeArc(Rect::MakeXYWH(x + 25, y, 50, 50), //
678 Degrees(90), Degrees(180), false);
679 builder.DrawPath(path, paint);
680 }
681
682 return builder.Build();
683}
void DrawOval(const DlRect &bounds, const DlPaint &paint) override
void DrawCircle(const DlPoint &center, DlScalar radius, const DlPaint &paint) override
void DrawPath(const DlPath &path, const DlPaint &paint) override
DlPaint & setInvertColors(bool isInvertColors)
Definition dl_paint.h:64
DlPaint & setImageFilter(std::nullptr_t filter)
Definition dl_paint.h:167
float Scalar
Definition scalar.h:19
std::shared_ptr< DlImageFilter > image_filter

References impeller::testing::MaskBlurTestConfig::alpha, impeller::Color::AntiqueWhite(), impeller::testing::MaskBlurTestConfig::blend_mode, flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawOval(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawRoundRect(), impeller::Playground::GetContentScale(), impeller::testing::MaskBlurTestConfig::image_filter, impeller::testing::MaskBlurTestConfig::invert_colors, flutter::DlColor::kBlue(), flutter::DlColor::kCrimson(), flutter::DlColor::kGreen(), flutter::DlColor::kMaroon(), flutter::DlColor::kOrange(), flutter::DlColor::kPurple(), flutter::DlPathBuilder::LineTo(), flutter::DlBlurMaskFilter::Make(), flutter::DlPath::MakeArc(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), flutter::DlPaint::setInvertColors(), flutter::DlPaint::setMaskFilter(), impeller::testing::MaskBlurTestConfig::sigma, impeller::testing::MaskBlurTestConfig::style, flutter::DlPathBuilder::TakePath(), flutter::DisplayListBuilder::Translate(), x, flutter::Point::x(), flutter::Point::y(), and y.

◆ mockBeginQueryEXT()

void impeller::testing::mockBeginQueryEXT ( GLenum  target,
GLuint  id 
)

Definition at line 145 of file mock_gles.cc.

145 {
146 CallMockMethod(&IMockGLESImpl::BeginQueryEXT, target, id);
147}
uint32_t * target

References impeller::testing::IMockGLESImpl::BeginQueryEXT(), and target.

◆ mockBindFramebuffer()

void impeller::testing::mockBindFramebuffer ( GLenum  target,
GLuint  framebuffer 
)

Definition at line 327 of file mock_gles.cc.

327 {
328 return CallMockMethod(&IMockGLESImpl::BindFramebuffer, target, framebuffer);
329}

References impeller::testing::IMockGLESImpl::BindFramebuffer(), and target.

◆ mockBindTexture()

void impeller::testing::mockBindTexture ( GLenum  target,
GLuint  texture 
)

Definition at line 300 of file mock_gles.cc.

300 {
301 CallMockMethod(&IMockGLESImpl::BindTexture, target, texture);
302}

References impeller::testing::IMockGLESImpl::BindTexture(), target, and texture.

◆ mockBufferSubData()

void impeller::testing::mockBufferSubData ( GLenum  target,
GLintptr  offset,
GLsizeiptr  size,
const void *  data 
)

Definition at line 247 of file mock_gles.cc.

250 {
251 CallMockMethod(&IMockGLESImpl::BufferSubData, target, offset, size, data);
252}

References impeller::testing::IMockGLESImpl::BufferSubData(), flutter::data, flutter::size, and target.

◆ mockCheckFramebufferStatus()

GLenum impeller::testing::mockCheckFramebufferStatus ( GLenum  target)

Definition at line 313 of file mock_gles.cc.

313 {
314 return CallMockMethod(&IMockGLESImpl::CheckFramebufferStatus, target);
315}

References impeller::testing::IMockGLESImpl::CheckFramebufferStatus(), and target.

◆ mockDeleteQueriesEXT()

void impeller::testing::mockDeleteQueriesEXT ( GLsizei  size,
const GLuint *  queries 
)

Definition at line 173 of file mock_gles.cc.

173 {
174 CallMockMethod(&IMockGLESImpl::DeleteQueriesEXT, size, queries);
175}

References impeller::testing::IMockGLESImpl::DeleteQueriesEXT(), and flutter::size.

◆ mockDeleteTextures()

void impeller::testing::mockDeleteTextures ( GLsizei  size,
const GLuint *  queries 
)

Definition at line 177 of file mock_gles.cc.

177 {
178 CallMockMethod(&IMockGLESImpl::DeleteTextures, size, queries);
179}

References impeller::testing::IMockGLESImpl::DeleteTextures(), and flutter::size.

◆ mockDiscardFramebufferEXT()

void impeller::testing::mockDiscardFramebufferEXT ( GLenum  target,
GLsizei  numAttachments,
const GLenum *  attachments 
)

Definition at line 345 of file mock_gles.cc.

347 {
348 return CallMockMethod(&IMockGLESImpl::DiscardFramebufferEXT, target,
349 numAttachments, attachments);
350}

References impeller::testing::IMockGLESImpl::DiscardFramebufferEXT(), and target.

◆ mockDrawArrays()

void impeller::testing::mockDrawArrays ( GLenum  mode,
GLint  first,
GLsizei  count 
)

Definition at line 369 of file mock_gles.cc.

369 {
370 CallMockMethod(&IMockGLESImpl::DrawArrays, mode, first, count);
371}

References impeller::testing::IMockGLESImpl::DrawArrays(), and flutter::mode.

◆ mockDrawArraysInstanced()

void impeller::testing::mockDrawArraysInstanced ( GLenum  mode,
GLint  first,
GLsizei  count,
GLsizei  instancecount 
)

Definition at line 386 of file mock_gles.cc.

389 {
390 CallMockMethod(&IMockGLESImpl::DrawArraysInstanced, mode, first, count,
391 instancecount);
392}

References impeller::testing::IMockGLESImpl::DrawArraysInstanced(), and flutter::mode.

◆ mockDrawElements()

void impeller::testing::mockDrawElements ( GLenum  mode,
GLsizei  count,
GLenum  type,
const void *  indices 
)

Definition at line 376 of file mock_gles.cc.

379 {
380 CallMockMethod(&IMockGLESImpl::DrawElements, mode, count, type, indices);
381}

References impeller::testing::IMockGLESImpl::DrawElements(), flutter::mode, and type.

◆ mockDrawElementsInstanced()

void impeller::testing::mockDrawElementsInstanced ( GLenum  mode,
GLsizei  count,
GLenum  type,
const void *  indices,
GLsizei  instancecount 
)

Definition at line 397 of file mock_gles.cc.

401 {
402 CallMockMethod(&IMockGLESImpl::DrawElementsInstanced, mode, count, type,
403 indices, instancecount);
404}

References impeller::testing::IMockGLESImpl::DrawElementsInstanced(), flutter::mode, and type.

◆ mockEndQueryEXT()

void impeller::testing::mockEndQueryEXT ( GLuint  id)

Definition at line 152 of file mock_gles.cc.

152 {
153 CallMockMethod(&IMockGLESImpl::EndQueryEXT, id);
154}

References impeller::testing::IMockGLESImpl::EndQueryEXT().

◆ mockGenBuffers()

void impeller::testing::mockGenBuffers ( GLsizei  n,
GLuint *  buffers 
)

Definition at line 243 of file mock_gles.cc.

243 {
244 CallMockMethod(&IMockGLESImpl::GenBuffers, n, buffers);
245}

References impeller::testing::IMockGLESImpl::GenBuffers().

◆ mockGenFramebuffers()

void impeller::testing::mockGenFramebuffers ( GLsizei  n,
GLuint *  ids 
)

Definition at line 320 of file mock_gles.cc.

320 {
321 return CallMockMethod(&IMockGLESImpl::GenFramebuffers, n, ids);
322}

References impeller::testing::IMockGLESImpl::GenFramebuffers().

◆ mockGenQueriesEXT()

void impeller::testing::mockGenQueriesEXT ( GLsizei  n,
GLuint *  ids 
)

Definition at line 138 of file mock_gles.cc.

138 {
139 CallMockMethod(&IMockGLESImpl::GenQueriesEXT, n, ids);
140}

References impeller::testing::IMockGLESImpl::GenQueriesEXT().

◆ mockGenTextures()

void impeller::testing::mockGenTextures ( GLsizei  n,
GLuint *  textures 
)

Definition at line 236 of file mock_gles.cc.

236 {
237 CallMockMethod(&IMockGLESImpl::GenTextures, n, textures);
238}

◆ mockGetError()

GLenum impeller::testing::mockGetError ( )

Definition at line 118 of file mock_gles.cc.

118 {
119 return GL_NO_ERROR;
120}

◆ mockGetIntegerv()

void impeller::testing::mockGetIntegerv ( GLenum  name,
int *  value 
)

Definition at line 95 of file mock_gles.cc.

95 {
96 switch (name) {
97 case GL_NUM_EXTENSIONS: {
98 *value = g_extensions.size();
99 } break;
100 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
101 *value = 8;
102 break;
103 case GL_MAX_LABEL_LENGTH_KHR:
104 *value = 64;
105 break;
106 case GL_MAX_TEXTURE_SIZE:
107 *value = 4096;
108 break;
109 default:
110 CallMockMethod(&IMockGLESImpl::GetIntegerv, name, value);
111 break;
112 }
113}
int32_t value
static std::vector< const char * > g_extensions
Definition mock_gles.cc:22

References g_extensions, impeller::testing::IMockGLESImpl::GetIntegerv(), flutter::name, and value.

◆ mockGetQueryObjectui64vEXT()

void impeller::testing::mockGetQueryObjectui64vEXT ( GLuint  id,
GLenum  target,
GLuint64 *  result 
)

Definition at line 166 of file mock_gles.cc.

166 {
167 CallMockMethod(&IMockGLESImpl::GetQueryObjectui64vEXT, id, target, result);
168}

References impeller::testing::IMockGLESImpl::GetQueryObjectui64vEXT(), and target.

◆ mockGetQueryObjectuivEXT()

void impeller::testing::mockGetQueryObjectuivEXT ( GLuint  id,
GLenum  target,
GLuint *  result 
)

Definition at line 159 of file mock_gles.cc.

159 {
160 CallMockMethod(&IMockGLESImpl::GetQueryObjectuivEXT, id, target, result);
161}

References impeller::testing::IMockGLESImpl::GetQueryObjectuivEXT(), and target.

◆ mockGetString()

const unsigned char * impeller::testing::mockGetString ( GLenum  name)

Definition at line 63 of file mock_gles.cc.

63 {
64 switch (name) {
65 case GL_VENDOR:
66 return reinterpret_cast<const unsigned char*>(kMockVendor);
67 case GL_VERSION:
68 return reinterpret_cast<const unsigned char*>(g_version);
69 case GL_EXTENSIONS:
70 return reinterpret_cast<const unsigned char*>(
71 g_extensions_string.c_str());
72 case GL_SHADING_LANGUAGE_VERSION:
73 return reinterpret_cast<const unsigned char*>(
75 default:
76 return reinterpret_cast<const unsigned char*>("");
77 }
78}
const auto kMockShadingLanguageVersion
Definition mock_gles.cc:37
static std::string g_extensions_string
Definition mock_gles.cc:25
auto const kMockVendor
Definition mock_gles.cc:36
static const char * g_version
Definition mock_gles.cc:24

References g_extensions_string, g_version, kMockShadingLanguageVersion, kMockVendor, and flutter::name.

◆ mockGetStringi()

const unsigned char * impeller::testing::mockGetStringi ( GLenum  name,
GLuint  index 
)

Definition at line 83 of file mock_gles.cc.

83 {
84 switch (name) {
85 case GL_EXTENSIONS:
86 return reinterpret_cast<const unsigned char*>(g_extensions[index]);
87 default:
88 return reinterpret_cast<const unsigned char*>("");
89 }
90}

References g_extensions, and flutter::name.

◆ mockInvalidateFramebuffer()

void impeller::testing::mockInvalidateFramebuffer ( GLenum  target,
GLsizei  numAttachments,
const GLenum *  attachments 
)

Definition at line 359 of file mock_gles.cc.

361 {
362 return CallMockMethod(&IMockGLESImpl::InvalidateFramebuffer, target,
363 numAttachments, attachments);
364}

References impeller::testing::IMockGLESImpl::InvalidateFramebuffer(), and target.

◆ mockIsTexture()

GLboolean impeller::testing::mockIsTexture ( GLuint  texture)

Definition at line 306 of file mock_gles.cc.

306 {
307 return CallMockMethod(&IMockGLESImpl::IsTexture, texture);
308}

References impeller::testing::IMockGLESImpl::IsTexture(), and texture.

◆ mockObjectLabelKHR()

void impeller::testing::mockObjectLabelKHR ( GLenum  identifier,
GLuint  name,
GLsizei  length,
const GLchar *  label 
)

Definition at line 260 of file mock_gles.cc.

263 {
264 CallMockMethod(&IMockGLESImpl::ObjectLabelKHR, identifier, name, length,
265 label);
266}
size_t length

References length, flutter::name, and impeller::testing::IMockGLESImpl::ObjectLabelKHR().

◆ mockPopDebugGroupKHR()

void impeller::testing::mockPopDebugGroupKHR ( )

Definition at line 125 of file mock_gles.cc.

125{}

◆ mockPushDebugGroupKHR()

void impeller::testing::mockPushDebugGroupKHR ( GLenum  source,
GLuint  id,
GLsizei  length,
const GLchar *  message 
)

Definition at line 130 of file mock_gles.cc.

133 {}

◆ mockReadPixels()

void impeller::testing::mockReadPixels ( GLint  x,
GLint  y,
GLsizei  width,
GLsizei  height,
GLenum  format,
GLenum  type,
void *  data 
)

Definition at line 334 of file mock_gles.cc.

340 {
341 return CallMockMethod(&IMockGLESImpl::ReadPixels, x, y, width, height, format,
342 type, data);
343}
int32_t height
int32_t width

References flutter::data, format, height, impeller::testing::IMockGLESImpl::ReadPixels(), type, width, x, and y.

◆ mockTexImage2D()

void impeller::testing::mockTexImage2D ( GLenum  target,
GLint  level,
GLint  internalformat,
GLsizei  width,
GLsizei  height,
GLint  border,
GLenum  format,
GLenum  type,
const void *  pixels 
)

Definition at line 285 of file mock_gles.cc.

293 {
294 CallMockMethod(&IMockGLESImpl::TexImage2D, target, level, internalformat,
295 width, height, border, format, type, pixels);
296}

References format, height, target, impeller::testing::IMockGLESImpl::TexImage2D(), type, and width.

◆ mockTexSubImage2D()

void impeller::testing::mockTexSubImage2D ( GLenum  target,
GLint  level,
GLint  xoffset,
GLint  yoffset,
GLsizei  width,
GLsizei  height,
GLenum  format,
GLenum  type,
const void *  pixels 
)

Definition at line 270 of file mock_gles.cc.

278 {
279 CallMockMethod(&IMockGLESImpl::TexSubImage2D, target, level, xoffset, yoffset,
280 width, height, format, type, pixels);
281}

References format, height, target, impeller::testing::IMockGLESImpl::TexSubImage2D(), type, and width.

◆ mockUniform1fv()

void impeller::testing::mockUniform1fv ( GLint  location,
GLsizei  count,
const GLfloat *  value 
)

Definition at line 184 of file mock_gles.cc.

184 {
185 CallMockMethod(&IMockGLESImpl::Uniform1fv, location, count, value);
186}
uint32_t location

References location, impeller::testing::IMockGLESImpl::Uniform1fv(), and value.

◆ mockUniform2fv()

void impeller::testing::mockUniform2fv ( GLint  location,
GLsizei  count,
const GLfloat *  value 
)

Definition at line 188 of file mock_gles.cc.

188 {
189 CallMockMethod(&IMockGLESImpl::Uniform2fv, location, count, value);
190}

References location, impeller::testing::IMockGLESImpl::Uniform2fv(), and value.

◆ mockUniform3fv()

void impeller::testing::mockUniform3fv ( GLint  location,
GLsizei  count,
const GLfloat *  value 
)

Definition at line 194 of file mock_gles.cc.

194 {
195 CallMockMethod(&IMockGLESImpl::Uniform3fv, location, count, value);
196}

References location, impeller::testing::IMockGLESImpl::Uniform3fv(), and value.

◆ mockUniform4fv()

void impeller::testing::mockUniform4fv ( GLint  location,
GLsizei  count,
const GLfloat *  value 
)

Definition at line 200 of file mock_gles.cc.

200 {
201 CallMockMethod(&IMockGLESImpl::Uniform4fv, location, count, value);
202}

References location, impeller::testing::IMockGLESImpl::Uniform4fv(), and value.

◆ mockUniformMatrix2fv()

void impeller::testing::mockUniformMatrix2fv ( GLint  location,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Definition at line 206 of file mock_gles.cc.

209 {
210 CallMockMethod(&IMockGLESImpl::UniformMatrix2fv, location, count, transpose,
211 value);
212}

References location, impeller::testing::IMockGLESImpl::UniformMatrix2fv(), and value.

◆ mockUniformMatrix3fv()

void impeller::testing::mockUniformMatrix3fv ( GLint  location,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Definition at line 216 of file mock_gles.cc.

219 {
220 CallMockMethod(&IMockGLESImpl::UniformMatrix3fv, location, count, transpose,
221 value);
222}

References location, impeller::testing::IMockGLESImpl::UniformMatrix3fv(), and value.

◆ mockUniformMatrix4fv()

void impeller::testing::mockUniformMatrix4fv ( GLint  location,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Definition at line 226 of file mock_gles.cc.

229 {
230 CallMockMethod(&IMockGLESImpl::UniformMatrix4fv, location, count, transpose,
231 value);
232}

References location, impeller::testing::IMockGLESImpl::UniformMatrix4fv(), and value.

◆ mockVertexAttribDivisor()

void impeller::testing::mockVertexAttribDivisor ( GLuint  index,
GLuint  divisor 
)

Definition at line 409 of file mock_gles.cc.

409 {
410 CallMockMethod(&IMockGLESImpl::VertexAttribDivisor, index, divisor);
411}

References impeller::testing::IMockGLESImpl::VertexAttribDivisor().

◆ mockViewport()

void impeller::testing::mockViewport ( GLint  x,
GLint  y,
GLsizei  width,
GLsizei  height 
)

Definition at line 352 of file mock_gles.cc.

352 {
353 return CallMockMethod(&IMockGLESImpl::Viewport, x, y, width, height);
354}

References height, impeller::testing::IMockGLESImpl::Viewport(), width, x, and y.

◆ RenderTextInCanvasSkia()

bool impeller::testing::RenderTextInCanvasSkia ( const std::shared_ptr< Context > &  context,
DisplayListBuilder canvas,
const std::string &  text,
const std::string_view &  font_fixture,
const TextRenderOptions options = {},
const std::optional< SkFont > &  font = std::nullopt 
)

Definition at line 47 of file aiks_dl_text_unittests.cc.

51 {},
52 const std::optional<SkFont>& font = std::nullopt) {
53 // Draw the baseline.
54 DlPaint paint;
55 paint.setColor(DlColor::kAqua().withAlpha(255 * 0.25));
56 canvas.DrawRect(
57 DlRect::MakeXYWH(options.position.x - 50, options.position.y, 900, 10),
58 paint);
59
60 // Mark the point at which the text is drawn.
61 paint.setColor(DlColor::kRed().withAlpha(255 * 0.25));
62 canvas.DrawCircle(options.position, 5.0, paint);
63
64 // Construct the text blob.
65 SkFont selected_font;
66 if (!font.has_value()) {
67 auto c_font_fixture = std::string(font_fixture);
68 auto mapping =
69 flutter::testing::OpenFixtureAsSkData(c_font_fixture.c_str());
70 if (!mapping) {
71 return false;
72 }
73 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
74 selected_font = SkFont(font_mgr->makeFromData(mapping), options.font_size);
75 if (options.is_subpixel) {
76 selected_font.setSubpixel(true);
77 }
78 } else {
79 selected_font = font.value();
80 }
81 auto blob = SkTextBlob::MakeFromString(text.c_str(), selected_font);
82 if (!blob) {
83 return false;
84 }
85
86 // Create the Impeller text frame and draw it at the designated baseline.
87 auto frame = MakeTextFrameFromTextBlobSkia(blob);
88
89 DlPaint text_paint;
90 text_paint.setColor(options.color);
91 text_paint.setMaskFilter(options.filter);
92 text_paint.setStrokeWidth(options.stroke_width);
93 text_paint.setDrawStyle(options.stroke ? DlDrawStyle::kStroke
95 canvas.DrawText(DlTextImpeller::Make(frame), options.position.x,
96 options.position.y, text_paint);
97 return true;
98}
void DrawText(const std::shared_ptr< DlText > &text, DlScalar x, DlScalar y, const DlPaint &paint) override
DlPaint & setStrokeWidth(float width)
Definition dl_paint.h:115
DlPaint & setDrawStyle(DlDrawStyle style)
Definition dl_paint.h:93
static std::shared_ptr< DlTextImpeller > Make(const std::shared_ptr< impeller::TextFrame > &frame)
std::u16string text
sk_sp< SkData > OpenFixtureAsSkData(const std::string &fixture_name)
Opens a fixture of the given file name and returns a Skia SkData holding its contents.
Definition testing.cc:63
DlDrawStyle
Definition dl_paint.h:19
@ kFill
fills interior of shapes
std::shared_ptr< TextFrame > MakeTextFrameFromTextBlobSkia(const sk_sp< SkTextBlob > &blob)
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
Definition platform.cc:17
static constexpr DlColor kAqua()
Definition dl_color.h:86
static constexpr DlColor kRed()
Definition dl_color.h:71
DlColor withAlpha(uint8_t alpha) const
Definition dl_color.h:120
std::shared_ptr< DlMaskFilter > filter

Referenced by TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), and TEST_P().

◆ RGBToYUV()

static Vector3 impeller::testing::RGBToYUV ( Vector3  rgb,
YUVColorSpace  yuv_color_space 
)
static

Definition at line 1685 of file entity_unittests.cc.

1685 {
1686 Vector3 yuv;
1687 switch (yuv_color_space) {
1688 case YUVColorSpace::kBT601FullRange:
1689 yuv.x = rgb.x * 0.299 + rgb.y * 0.587 + rgb.z * 0.114;
1690 yuv.y = rgb.x * -0.169 + rgb.y * -0.331 + rgb.z * 0.5 + 0.5;
1691 yuv.z = rgb.x * 0.5 + rgb.y * -0.419 + rgb.z * -0.081 + 0.5;
1692 break;
1693 case YUVColorSpace::kBT601LimitedRange:
1694 yuv.x = rgb.x * 0.257 + rgb.y * 0.516 + rgb.z * 0.100 + 0.063;
1695 yuv.y = rgb.x * -0.145 + rgb.y * -0.291 + rgb.z * 0.439 + 0.5;
1696 yuv.z = rgb.x * 0.429 + rgb.y * -0.368 + rgb.z * -0.071 + 0.5;
1697 break;
1698 }
1699 return yuv;
1700}

References impeller::kBT601FullRange, impeller::kBT601LimitedRange, impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

Referenced by CreateTestYUVTextures().

◆ SetSwapchainImageSize()

void impeller::testing::SetSwapchainImageSize ( ISize  size)

Override the image size returned by all swapchain images.

Definition at line 1335 of file mock_vulkan.cc.

1335 {
1336 currentImageSize = size;
1337}

References flutter::size.

Referenced by TEST(), TEST(), and TEST().

◆ swap_nan() [1/2]

static constexpr Point impeller::testing::swap_nan ( const Point point,
int  index 
)
inlinestaticconstexpr

Definition at line 1599 of file rect_unittests.cc.

1599 {
1600 Scalar nan = std::numeric_limits<Scalar>::quiet_NaN();
1601 FML_DCHECK(index >= 0 && index <= 3);
1602 Scalar x = ((index & (1 << 0)) != 0) ? nan : point.x;
1603 Scalar y = ((index & (1 << 1)) != 0) ? nan : point.y;
1604 return Point(x, y);
1605}

References FML_DCHECK, x, flutter::Point::x(), flutter::Point::y(), and y.

◆ swap_nan() [2/2]

static constexpr Rect impeller::testing::swap_nan ( const Rect rect,
int  index 
)
inlinestaticconstexpr

Definition at line 1589 of file rect_unittests.cc.

1589 {
1590 Scalar nan = std::numeric_limits<Scalar>::quiet_NaN();
1591 FML_DCHECK(index >= 0 && index <= 15);
1592 Scalar l = ((index & (1 << 0)) != 0) ? nan : rect.GetLeft();
1593 Scalar t = ((index & (1 << 1)) != 0) ? nan : rect.GetTop();
1594 Scalar r = ((index & (1 << 2)) != 0) ? nan : rect.GetRight();
1595 Scalar b = ((index & (1 << 3)) != 0) ? nan : rect.GetBottom();
1596 return Rect::MakeLTRB(l, t, r, b);
1597}

References FML_DCHECK, and impeller::TRect< Scalar >::MakeLTRB().

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ TEST() [1/689]

impeller::testing::TEST ( AllocationSizeTest  ,
CanCast   
)

Definition at line 77 of file allocation_size_unittests.cc.

77 {
78 using namespace allocation_size_literals;
79 {
80 auto a = KiloBytes{1500_bytes};
81 ASSERT_DOUBLE_EQ(a.GetSize(), 1.5);
82 }
83 {
84 auto a = KiloBytes{Bytes{1500}};
85 ASSERT_DOUBLE_EQ(a.GetSize(), 1.5);
86 }
87
88 ASSERT_DOUBLE_EQ(MebiBytes{Bytes{4194304}}.GetSize(), 4);
89}
AllocationSize< 1 '000u > KiloBytes

References impeller::AllocationSize< Period >::GetSize().

◆ TEST() [2/689]

impeller::testing::TEST ( AllocationSizeTest  ,
CanConstructWithArith   
)

Definition at line 110 of file allocation_size_unittests.cc.

110 {
111 {
112 KiloBytes a(1u);
113 ASSERT_EQ(a.GetByteSize(), 1000u);
114 }
115 {
116 KiloBytes a(1.5);
117 ASSERT_EQ(a.GetByteSize(), 2000u);
118 }
119 {
120 KiloBytes a(1.5f);
121 ASSERT_EQ(a.GetByteSize(), 2000u);
122 }
123}

◆ TEST() [3/689]

impeller::testing::TEST ( AllocationSizeTest  ,
CanConvert   
)

Definition at line 44 of file allocation_size_unittests.cc.

44 {
45 using namespace allocation_size_literals;
46 ASSERT_EQ((5_gb).ConvertTo<MegaBytes>().GetSize(), 5000u);
47}

◆ TEST() [4/689]

impeller::testing::TEST ( AllocationSizeTest  ,
CanCreateTypedAllocations   
)

Definition at line 10 of file allocation_size_unittests.cc.

10 {
11 auto bytes = Bytes{1024};
12 ASSERT_EQ(bytes.GetByteSize(), 1024u);
13
14 auto kilobytes = KiloBytes{5};
15 ASSERT_EQ(kilobytes.GetByteSize(), 5u * 1e3);
16
17 auto megabytes = MegaBytes{5};
18 ASSERT_EQ(megabytes.GetByteSize(), 5u * 1e6);
19
20 auto gigabytes = GigaBytes{5};
21 ASSERT_EQ(gigabytes.GetByteSize(), 5u * 1e9);
22
23 auto kibibytes = KibiBytes{1};
24 ASSERT_EQ(kibibytes.GetByteSize(), 1024u);
25
26 auto mebibytes = MebiBytes{1};
27 ASSERT_EQ(mebibytes.GetByteSize(), 1048576u);
28
29 auto gigibytes = GibiBytes{1};
30 ASSERT_EQ(gigibytes.GetByteSize(), 1073741824u);
31}
AllocationSize< 1 '024u *1 '024u > MebiBytes
AllocationSize< 1 '024u *1 '024u *1 '024u > GibiBytes
AllocationSize< 1 '000u *1 '000u *1 '000u > GigaBytes
AllocationSize< 1 '024u > KibiBytes

◆ TEST() [5/689]

impeller::testing::TEST ( AllocationSizeTest  ,
CanCreateTypedAllocationsWithLiterals   
)

Definition at line 33 of file allocation_size_unittests.cc.

33 {
34 using namespace allocation_size_literals;
35 ASSERT_EQ((1024_bytes).GetByteSize(), 1024u);
36 ASSERT_EQ((5_kb).GetByteSize(), 5u * 1e3);
37 ASSERT_EQ((5_mb).GetByteSize(), 5u * 1e6);
38 ASSERT_EQ((5_gb).GetByteSize(), 5u * 1e9);
39 ASSERT_EQ((1_kib).GetByteSize(), 1024u);
40 ASSERT_EQ((1_mib).GetByteSize(), 1048576u);
41 ASSERT_EQ((1_gib).GetByteSize(), 1073741824u);
42}

◆ TEST() [6/689]

impeller::testing::TEST ( AllocationSizeTest  ,
CanGetFloatValues   
)

Definition at line 55 of file allocation_size_unittests.cc.

55 {
56 using namespace allocation_size_literals;
57 ASSERT_DOUBLE_EQ((1500_bytes).ConvertTo<KiloBytes>().GetSize(), 1.5);
58}

◆ TEST() [7/689]

impeller::testing::TEST ( AllocationSizeTest  ,
CanPerformSimpleArithmetic   
)

Definition at line 91 of file allocation_size_unittests.cc.

91 {
92 using namespace allocation_size_literals;
93 {
94 auto a = 100_bytes;
95 auto b = 200_bytes;
96 ASSERT_EQ((a + b).GetByteSize(), 300u);
97 }
98 {
99 auto a = 100_bytes;
100 a += 200_bytes;
101 ASSERT_EQ(a.GetByteSize(), 300u);
102 }
103 {
104 auto a = 100_bytes;
105 a -= 50_bytes;
106 ASSERT_EQ(a.GetByteSize(), 50u);
107 }
108}

◆ TEST() [8/689]

impeller::testing::TEST ( AllocationSizeTest  ,
ConversionsAreNonTruncating   
)

Definition at line 49 of file allocation_size_unittests.cc.

49 {
50 using namespace allocation_size_literals;
51 ASSERT_DOUBLE_EQ((1500_bytes).ConvertTo<KiloBytes>().GetSize(), 1.5);
52 ASSERT_EQ((1500_bytes).ConvertTo<KiloBytes>().GetByteSize(), 1500u);
53}

◆ TEST() [9/689]

impeller::testing::TEST ( AllocationSizeTest  ,
RelationalOperatorsAreFunctional   
)

Definition at line 60 of file allocation_size_unittests.cc.

60 {
61 using namespace allocation_size_literals;
62
63 auto a = 1500_bytes;
64 auto b = 2500_bytes;
65 auto c = 0_bytes;
66
67 ASSERT_TRUE(a != b);
68 ASSERT_FALSE(a == b);
69 ASSERT_TRUE(b > a);
70 ASSERT_TRUE(b >= a);
71 ASSERT_TRUE(a < b);
72 ASSERT_TRUE(a <= b);
73 ASSERT_TRUE(a);
74 ASSERT_FALSE(c);
75}

References c.

◆ TEST() [10/689]

impeller::testing::TEST ( AllocationTest  ,
NextPowerOfTwoSize   
)

Definition at line 41 of file allocation_unittests.cc.

41 {
42 EXPECT_EQ(*Allocation::NextPowerOfTwoSize((1ULL << 32) - 1), 1ULL << 32);
43 EXPECT_EQ(*Allocation::NextPowerOfTwoSize((1ULL << 32) + 1), 1ULL << 33);
44 EXPECT_EQ(*Allocation::NextPowerOfTwoSize(1ULL << 63), 1ULL << 63);
45 EXPECT_EQ(Allocation::NextPowerOfTwoSize((1ULL << 63) + 1).status().code(),
46 absl::StatusCode::kInvalidArgument);
47 EXPECT_EQ(Allocation::NextPowerOfTwoSize(std::numeric_limits<uint64_t>::max())
48 .status()
49 .code(),
50 absl::StatusCode::kInvalidArgument);
51}

References impeller::Allocation::NextPowerOfTwoSize().

◆ TEST() [11/689]

impeller::testing::TEST ( AllocationTest  ,
ReserveNPOTPotentialOverflow   
)

Definition at line 14 of file allocation_unittests.cc.

14 {
15 std::vector<uint8_t> data(64, 0xff);
16
17 auto allocate_and_write = [&](uint64_t size) {
18 Allocation allocation;
19
20 // Allocate a buffer with the size rounded up to the next power of two.
21 if (!allocation.Truncate(Bytes{size})) {
22 // Not enough memory available.
23 return;
24 }
25
26 // If the allocation succeeded, then check that writes are safe.
27 memcpy(allocation.GetBuffer(), data.data(), data.size());
28 EXPECT_EQ(memcmp(allocation.GetBuffer(), data.data(), data.size()), 0);
29 };
30
31 // Try allocations with sizes around the maximum 32-bit value.
32 allocate_and_write((1ULL << 32) + 1);
33 allocate_and_write((1ULL << 32) - 1);
34
35 // Test that an allocation size that is out of range fails immediately.
36 Allocation max_allocation;
37 EXPECT_FALSE(
38 max_allocation.Truncate(Bytes{std::numeric_limits<uint64_t>::max()}));
39}
Describes an allocation on the heap.
Definition allocation.h:23
uint8_t * GetBuffer() const
Gets the pointer to the start of the allocation.
Definition allocation.cc:20
bool Truncate(Bytes length, bool npot=true)
Resize the underlying allocation to at least given number of bytes.
Definition allocation.cc:32

References flutter::data, impeller::Allocation::GetBuffer(), flutter::size, and impeller::Allocation::Truncate().

◆ TEST() [12/689]

impeller::testing::TEST ( AllocatorTest  ,
CompressedFormatBlockMath   
)

Definition at line 147 of file allocator_unittests.cc.

147 {
148 // Block dimensions: everything here is 4x4 except ASTC 8x8.
149 EXPECT_EQ(CompressedBlockWidthForPixelFormat(PixelFormat::kBC1RGBAUNormInt),
150 4u);
151 EXPECT_EQ(CompressedBlockWidthForPixelFormat(PixelFormat::kASTC8x8LDR), 8u);
152 EXPECT_EQ(CompressedBlockHeightForPixelFormat(PixelFormat::kASTC8x8LDR), 8u);
153 EXPECT_EQ(CompressedBlockWidthForPixelFormat(PixelFormat::kASTC4x4HDR), 4u);
154 EXPECT_EQ(CompressedBlockHeightForPixelFormat(PixelFormat::kASTC8x8HDR), 8u);
155 // Uncompressed formats report a 1x1 block.
156 EXPECT_EQ(CompressedBlockWidthForPixelFormat(PixelFormat::kR8G8B8A8UNormInt),
157 1u);
158
159 // Bytes per block: BC1/ETC2-RGB8 are 8 bytes, the rest here are 16.
160 EXPECT_EQ(BytesPerBlockForPixelFormat(PixelFormat::kBC1RGBAUNormInt), 8u);
161 EXPECT_EQ(BytesPerBlockForPixelFormat(PixelFormat::kETC2RGB8UNormInt), 8u);
162 EXPECT_EQ(BytesPerBlockForPixelFormat(PixelFormat::kBC3RGBAUNormInt), 16u);
163 EXPECT_EQ(BytesPerBlockForPixelFormat(PixelFormat::kASTC4x4LDR), 16u);
164 EXPECT_EQ(BytesPerBlockForPixelFormat(PixelFormat::kASTC8x8HDR), 16u);
165 // Uncompressed falls back to bytes-per-pixel.
166 EXPECT_EQ(BytesPerBlockForPixelFormat(PixelFormat::kR8G8B8A8UNormInt), 4u);
167}
constexpr size_t CompressedBlockHeightForPixelFormat(PixelFormat format)
The height, in texels, of one compression block. Uncompressed formats report 1.
Definition formats.h:245
constexpr size_t CompressedBlockWidthForPixelFormat(PixelFormat format)
The width, in texels, of one compression block. Uncompressed formats report 1.
Definition formats.h:217
constexpr size_t BytesPerBlockForPixelFormat(PixelFormat format)
The number of bytes used to store one block of format. For uncompressed formats a block is a single p...
Definition formats.h:697

References impeller::BytesPerBlockForPixelFormat(), impeller::CompressedBlockHeightForPixelFormat(), impeller::CompressedBlockWidthForPixelFormat(), impeller::kASTC4x4HDR, impeller::kASTC4x4LDR, impeller::kASTC8x8HDR, impeller::kASTC8x8LDR, impeller::kBC1RGBAUNormInt, impeller::kBC3RGBAUNormInt, impeller::kETC2RGB8UNormInt, and impeller::kR8G8B8A8UNormInt.

◆ TEST() [13/689]

impeller::testing::TEST ( AllocatorTest  ,
CompressedFormatClassification   
)

Definition at line 129 of file allocator_unittests.cc.

129 {
130 EXPECT_FALSE(IsCompressed(PixelFormat::kR8G8B8A8UNormInt));
131 EXPECT_FALSE(IsCompressed(PixelFormat::kR32Float));
132 EXPECT_TRUE(IsCompressed(PixelFormat::kBC1RGBAUNormInt));
133 EXPECT_TRUE(IsCompressed(PixelFormat::kETC2RGBA8UNormInt));
134 EXPECT_TRUE(IsCompressed(PixelFormat::kASTC8x8LDR));
135 EXPECT_TRUE(IsCompressed(PixelFormat::kASTC4x4HDR));
136
137 EXPECT_EQ(CompressedTextureFamilyForFormat(PixelFormat::kBC7RGBAUNormInt),
138 CompressedTextureFamily::kBC);
139 EXPECT_EQ(CompressedTextureFamilyForFormat(PixelFormat::kETC2RGB8UNormInt),
140 CompressedTextureFamily::kETC2);
141 EXPECT_EQ(CompressedTextureFamilyForFormat(PixelFormat::kASTC4x4LDR),
142 CompressedTextureFamily::kASTC);
143 EXPECT_EQ(CompressedTextureFamilyForFormat(PixelFormat::kASTC8x8HDR),
144 CompressedTextureFamily::kASTCHDR);
145}
constexpr CompressedTextureFamily CompressedTextureFamilyForFormat(PixelFormat format)
The compression family that format belongs to. Only valid for formats where IsCompressed is true.
Definition formats.h:185
constexpr bool IsCompressed(PixelFormat format)
Whether format is a block-compressed format.
Definition formats.h:158

References impeller::CompressedTextureFamilyForFormat(), impeller::IsCompressed(), impeller::kASTC, impeller::kASTC4x4HDR, impeller::kASTC4x4LDR, impeller::kASTC8x8HDR, impeller::kASTC8x8LDR, impeller::kASTCHDR, impeller::kBC, impeller::kBC1RGBAUNormInt, impeller::kBC7RGBAUNormInt, impeller::kETC2, impeller::kETC2RGB8UNormInt, impeller::kETC2RGBA8UNormInt, impeller::kR32Float, and impeller::kR8G8B8A8UNormInt.

◆ TEST() [14/689]

impeller::testing::TEST ( AllocatorTest  ,
CompressedFormatRegionByteSizes   
)

Definition at line 169 of file allocator_unittests.cc.

169 {
170 // BC1: 4x4 blocks of 8 bytes. Dimensions round up to whole blocks.
171 EXPECT_EQ(BytesForTextureRegion(PixelFormat::kBC1RGBAUNormInt, 4, 4), 8u);
172 EXPECT_EQ(BytesForTextureRegion(PixelFormat::kBC1RGBAUNormInt, 8, 8), 32u);
173 EXPECT_EQ(BytesForTextureRegion(PixelFormat::kBC1RGBAUNormInt, 5, 5), 32u);
174 EXPECT_EQ(BytesPerRowForTextureWidth(PixelFormat::kBC1RGBAUNormInt, 8), 16u);
175
176 // ASTC 8x8: a single 16-byte block covers up to 8x8 texels.
177 EXPECT_EQ(BytesForTextureRegion(PixelFormat::kASTC8x8LDR, 8, 8), 16u);
178 EXPECT_EQ(BytesForTextureRegion(PixelFormat::kASTC8x8LDR, 9, 9), 64u);
179
180 // Uncompressed math is unchanged: width * height * bytes-per-pixel.
181 EXPECT_EQ(BytesForTextureRegion(PixelFormat::kR8G8B8A8UNormInt, 100, 100),
182 40000u);
183 EXPECT_EQ(BytesPerRowForTextureWidth(PixelFormat::kR8G8B8A8UNormInt, 100),
184 400u);
185}
constexpr size_t BytesForTextureRegion(PixelFormat format, int64_t width, int64_t height)
The number of bytes required to store a width x height texel region in format. Block-compressed forma...
Definition formats.h:727
constexpr size_t BytesPerRowForTextureWidth(PixelFormat format, int64_t width)
The number of bytes in a single row of texel blocks for a texture of the given width in format.
Definition formats.h:741

References impeller::BytesForTextureRegion(), impeller::BytesPerRowForTextureWidth(), impeller::kASTC8x8LDR, impeller::kBC1RGBAUNormInt, and impeller::kR8G8B8A8UNormInt.

◆ TEST() [15/689]

impeller::testing::TEST ( AllocatorTest  ,
CompressedTextureDescriptorByteSizes   
)

Definition at line 187 of file allocator_unittests.cc.

187 {
188 {
189 TextureDescriptor desc = {.format = PixelFormat::kBC1RGBAUNormInt,
190 .size = ISize(8, 8)};
191 EXPECT_EQ(desc.GetByteSizeOfBaseMipLevel(), 32u);
192 EXPECT_EQ(desc.GetBytesPerRow(), 16u);
193 }
194 {
195 TextureDescriptor desc = {.format = PixelFormat::kASTC8x8LDR,
196 .size = ISize(16, 16)};
197 EXPECT_EQ(desc.GetByteSizeOfBaseMipLevel(), 64u);
198 }
199}
constexpr size_t GetByteSizeOfBaseMipLevel() const
constexpr size_t GetBytesPerRow() const

References impeller::TextureDescriptor::format, impeller::TextureDescriptor::GetByteSizeOfBaseMipLevel(), impeller::TextureDescriptor::GetBytesPerRow(), impeller::kASTC8x8LDR, and impeller::kBC1RGBAUNormInt.

◆ TEST() [16/689]

impeller::testing::TEST ( AllocatorTest  ,
RangeTest   
)

Definition at line 82 of file allocator_unittests.cc.

82 {
83 {
84 Range a = Range{0, 10};
85 Range b = Range{10, 20};
86 auto merged = a.Merge(b);
87
88 EXPECT_EQ(merged.offset, 0u);
89 EXPECT_EQ(merged.length, 30u);
90 }
91
92 {
93 Range a = Range{0, 10};
94 Range b = Range{100, 20};
95 auto merged = a.Merge(b);
96
97 EXPECT_EQ(merged.offset, 0u);
98 EXPECT_EQ(merged.length, 120u);
99 }
100
101 {
102 Range a = Range{0, 10};
103 Range b = Range{100, 20};
104 auto merged = b.Merge(a);
105
106 EXPECT_EQ(merged.offset, 0u);
107 EXPECT_EQ(merged.length, 120u);
108 }
109
110 {
111 Range a = Range{0, 10};
112 Range b = Range{100, 0};
113 auto merged = b.Merge(a);
114
115 EXPECT_EQ(merged.offset, 0u);
116 EXPECT_EQ(merged.length, 10u);
117 }
118
119 {
120 Range a = Range{0, 10};
121 Range b = Range{0, 10};
122 auto merged = b.Merge(a);
123
124 EXPECT_EQ(merged.offset, 0u);
125 EXPECT_EQ(merged.length, 10u);
126 }
127}
constexpr Range Merge(const Range &other)
Create a new range that is a union of this range and other.
Definition range.h:27

References impeller::Range::Merge().

◆ TEST() [17/689]

impeller::testing::TEST ( AllocatorTest  ,
TextureDescriptorCompatibility   
)

Definition at line 16 of file allocator_unittests.cc.

16 {
17 // Size.
18 {
19 TextureDescriptor desc_a = {.size = ISize(100, 100)};
20 TextureDescriptor desc_b = {.size = ISize(100, 100)};
21 TextureDescriptor desc_c = {.size = ISize(101, 100)};
22
23 ASSERT_EQ(desc_a, desc_b);
24 ASSERT_NE(desc_a, desc_c);
25 }
26 // Storage Mode.
27 {
28 TextureDescriptor desc_a = {.storage_mode = StorageMode::kDevicePrivate};
29 TextureDescriptor desc_b = {.storage_mode = StorageMode::kDevicePrivate};
30 TextureDescriptor desc_c = {.storage_mode = StorageMode::kHostVisible};
31
32 ASSERT_EQ(desc_a, desc_b);
33 ASSERT_NE(desc_a, desc_c);
34 }
35 // Format.
36 {
37 TextureDescriptor desc_a = {.format = PixelFormat::kR8G8B8A8UNormInt};
38 TextureDescriptor desc_b = {.format = PixelFormat::kR8G8B8A8UNormInt};
39 TextureDescriptor desc_c = {.format = PixelFormat::kB10G10R10A10XR};
40
41 ASSERT_EQ(desc_a, desc_b);
42 ASSERT_NE(desc_a, desc_c);
43 }
44 // Sample Count.
45 {
46 TextureDescriptor desc_a = {.sample_count = SampleCount::kCount4};
47 TextureDescriptor desc_b = {.sample_count = SampleCount::kCount4};
48 TextureDescriptor desc_c = {.sample_count = SampleCount::kCount1};
49
50 ASSERT_EQ(desc_a, desc_b);
51 ASSERT_NE(desc_a, desc_c);
52 }
53 // Sample Count.
54 {
55 TextureDescriptor desc_a = {.type = TextureType::kTexture2DMultisample};
56 TextureDescriptor desc_b = {.type = TextureType::kTexture2DMultisample};
57 TextureDescriptor desc_c = {.type = TextureType::kTexture2D};
58
59 ASSERT_EQ(desc_a, desc_b);
60 ASSERT_NE(desc_a, desc_c);
61 }
62 // Compression.
63 {
64 TextureDescriptor desc_a = {.compression_type = CompressionType::kLossless};
65 TextureDescriptor desc_b = {.compression_type = CompressionType::kLossless};
66 TextureDescriptor desc_c = {.compression_type = CompressionType::kLossy};
67
68 ASSERT_EQ(desc_a, desc_b);
69 ASSERT_NE(desc_a, desc_c);
70 }
71 // Mip Count.
72 {
73 TextureDescriptor desc_a = {.mip_count = 1};
74 TextureDescriptor desc_b = {.mip_count = 1};
75 TextureDescriptor desc_c = {.mip_count = 4};
76
77 ASSERT_EQ(desc_a, desc_b);
78 ASSERT_NE(desc_a, desc_c);
79 }
80}

References impeller::TextureDescriptor::compression_type, impeller::TextureDescriptor::format, impeller::kB10G10R10A10XR, impeller::kCount1, impeller::kCount4, impeller::kDevicePrivate, impeller::kHostVisible, impeller::kLossless, impeller::kLossy, impeller::kR8G8B8A8UNormInt, impeller::kTexture2D, impeller::kTexture2DMultisample, impeller::TextureDescriptor::mip_count, impeller::TextureDescriptor::sample_count, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, and impeller::TextureDescriptor::type.

◆ TEST() [18/689]

impeller::testing::TEST ( AllocatorVKTest  ,
ImageResourceKeepsVulkanDeviceAlive   
)

Definition at line 79 of file allocator_vk_unittests.cc.

79 {
80 std::shared_ptr<Texture> texture;
81 std::weak_ptr<Allocator> weak_allocator;
82 {
83 auto const context = MockVulkanContextBuilder().Build();
84 weak_allocator = context->GetResourceAllocator();
85 auto allocator = context->GetResourceAllocator();
86
87 texture = allocator->CreateTexture(TextureDescriptor{
88 .storage_mode = StorageMode::kDevicePrivate,
89 .format = PixelFormat::kR8G8B8A8UNormInt,
90 .size = {1, 1},
91 });
92 context->Shutdown();
93 }
94
95 ASSERT_TRUE(weak_allocator.lock());
96}
std::shared_ptr< ContextVK > Build()
Create a Vulkan context with Vulkan functions mocked. The caller is given a chance to tinker on the s...
std::shared_ptr< ImpellerAllocator > allocator

References allocator, impeller::testing::MockVulkanContextBuilder::Build(), context, impeller::kDevicePrivate, impeller::kR8G8B8A8UNormInt, impeller::TextureDescriptor::storage_mode, and texture.

◆ TEST() [19/689]

impeller::testing::TEST ( AllocatorVKTest  ,
MemoryTypeSelectionSingleHeap   
)

Definition at line 41 of file allocator_vk_unittests.cc.

41 {
42 vk::PhysicalDeviceMemoryProperties properties;
43 properties.memoryTypeCount = 1;
44 properties.memoryHeapCount = 1;
45 properties.memoryTypes[0].heapIndex = 0;
46 properties.memoryTypes[0].propertyFlags =
47 vk::MemoryPropertyFlagBits::eDeviceLocal;
48 properties.memoryHeaps[0].size = 1024 * 1024 * 1024;
49 properties.memoryHeaps[0].flags = vk::MemoryHeapFlagBits::eDeviceLocal;
50
51 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(1, properties), 0);
52 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(2, properties), -1);
53 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(3, properties), 0);
54}

References impeller::AllocatorVK::FindMemoryTypeIndex().

◆ TEST() [20/689]

impeller::testing::TEST ( AllocatorVKTest  ,
MemoryTypeSelectionTwoHeap   
)

Definition at line 56 of file allocator_vk_unittests.cc.

56 {
57 vk::PhysicalDeviceMemoryProperties properties;
58 properties.memoryTypeCount = 2;
59 properties.memoryHeapCount = 2;
60 properties.memoryTypes[0].heapIndex = 0;
61 properties.memoryTypes[0].propertyFlags =
62 vk::MemoryPropertyFlagBits::eHostVisible;
63 properties.memoryHeaps[0].size = 1024 * 1024 * 1024;
64 properties.memoryHeaps[0].flags = vk::MemoryHeapFlagBits::eDeviceLocal;
65
66 properties.memoryTypes[1].heapIndex = 1;
67 properties.memoryTypes[1].propertyFlags =
68 vk::MemoryPropertyFlagBits::eDeviceLocal;
69 properties.memoryHeaps[1].size = 1024 * 1024 * 1024;
70 properties.memoryHeaps[1].flags = vk::MemoryHeapFlagBits::eDeviceLocal;
71
72 // First fails because this only looks for eDeviceLocal.
73 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(1, properties), -1);
74 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(2, properties), 1);
75 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(3, properties), 1);
76 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(4, properties), -1);
77}

References impeller::AllocatorVK::FindMemoryTypeIndex().

◆ TEST() [21/689]

impeller::testing::TEST ( AllocatorVKTest  ,
RetriesUncompressedOnCompressionExhausted   
)

Definition at line 98 of file allocator_vk_unittests.cc.

98 {
99 // Advertise fixed-rate compression support, then force the first (compressed)
100 // vkCreateImage to fail with VK_ERROR_COMPRESSION_EXHAUSTED_EXT, as the
101 // PowerVR driver does when its fixed-rate-compression resources are depleted.
102 auto const context =
105 {"VK_KHR_swapchain", "VK_EXT_image_compression_control"})
106 .SetCompressionExhaustedCreateImageFailures(1)
107 .Build();
108 ASSERT_TRUE(context);
109 auto allocator = context->GetResourceAllocator();
110 ASSERT_TRUE(allocator);
111
112 // A lossy (fixed-rate-compressed) render target. The first compressed
113 // allocation fails with COMPRESSION_EXHAUSTED; the allocator must retry
114 // without compression and still produce a valid texture instead of returning
115 // null (a null render target previously crashed the raster thread).
116 auto texture = allocator->CreateTexture(TextureDescriptor{
117 .storage_mode = StorageMode::kDevicePrivate,
118 .format = PixelFormat::kR8G8B8A8UNormInt,
119 .size = {64, 64},
120 .usage = TextureUsage::kRenderTarget | TextureUsage::kShaderRead,
121 .compression_type = CompressionType::kLossy,
122 });
123
124 ASSERT_TRUE(texture);
125 EXPECT_TRUE(texture->IsValid());
126
127 // vkCreateImage was called twice: the compressed attempt (which failed with
128 // COMPRESSION_EXHAUSTED) and the uncompressed retry (which succeeded).
129 auto const called = GetMockVulkanFunctions(context->GetDevice());
130 EXPECT_EQ(std::count(called->begin(), called->end(), "vkCreateImage"), 2);
131}
MockVulkanContextBuilder & SetDeviceExtensions(const std::vector< std::string > &device_extensions)
Definition mock_vulkan.h:92
std::shared_ptr< std::vector< std::string > > GetMockVulkanFunctions(VkDevice device)

References allocator, impeller::testing::MockVulkanContextBuilder::Build(), context, GetMockVulkanFunctions(), impeller::kDevicePrivate, impeller::kLossy, impeller::kR8G8B8A8UNormInt, impeller::kRenderTarget, impeller::kShaderRead, impeller::testing::MockVulkanContextBuilder::SetDeviceExtensions(), impeller::TextureDescriptor::storage_mode, and texture.

◆ TEST() [22/689]

impeller::testing::TEST ( AllocatorVKTest  ,
ToVKImageUsageFlags   
)

Definition at line 22 of file allocator_vk_unittests.cc.

22 {
23 EXPECT_EQ(AllocatorVK::ToVKImageUsageFlags(
24 PixelFormat::kR8G8B8A8UNormInt,
25 static_cast<TextureUsageMask>(TextureUsage::kRenderTarget),
26 StorageMode::kDeviceTransient,
27 /*supports_memoryless_textures=*/true),
28 vk::ImageUsageFlagBits::eInputAttachment |
29 vk::ImageUsageFlagBits::eColorAttachment |
30 vk::ImageUsageFlagBits::eTransientAttachment);
31
32 EXPECT_EQ(AllocatorVK::ToVKImageUsageFlags(
33 PixelFormat::kD24UnormS8Uint,
34 static_cast<TextureUsageMask>(TextureUsage::kRenderTarget),
35 StorageMode::kDeviceTransient,
36 /*supports_memoryless_textures=*/true),
37 vk::ImageUsageFlagBits::eDepthStencilAttachment |
38 vk::ImageUsageFlagBits::eTransientAttachment);
39}

References impeller::kD24UnormS8Uint, impeller::kDeviceTransient, impeller::kR8G8B8A8UNormInt, impeller::kRenderTarget, and impeller::AllocatorVK::ToVKImageUsageFlags().

◆ TEST() [23/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsAllQuadrantsFromFirst   
)

Definition at line 262 of file arc_unittests.cc.

262 {
263 CheckFiveQuadrants(Degrees(90 * 0 + 60), Degrees(330));
264}

◆ TEST() [24/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsAllQuadrantsFromFourth   
)

Definition at line 274 of file arc_unittests.cc.

274 {
275 CheckFiveQuadrants(Degrees(90 * 3 + 60), Degrees(330));
276}

◆ TEST() [25/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsAllQuadrantsFromSecond   
)

Definition at line 266 of file arc_unittests.cc.

266 {
267 CheckFiveQuadrants(Degrees(90 * 1 + 60), Degrees(330));
268}

◆ TEST() [26/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsAllQuadrantsFromThird   
)

Definition at line 270 of file arc_unittests.cc.

270 {
271 CheckFiveQuadrants(Degrees(90 * 2 + 60), Degrees(330));
272}

◆ TEST() [27/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsFullCircle   
)

Definition at line 125 of file arc_unittests.cc.

125 {
126 // Anything with a sweep <=-360 or >=360 is a full circle regardless of
127 // starting angle
128 for (int start = -720; start < 720; start += 30) {
129 for (int sweep = 360; sweep < 1080; sweep += 45) {
130 TestFullCircleArc(Degrees(start), Degrees(sweep));
131 TestFullCircleArc(Degrees(start), Degrees(-sweep));
132 }
133 }
134}
const size_t start

References start.

◆ TEST() [28/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsOnlyFirstQuadrant   
)

Definition at line 210 of file arc_unittests.cc.

210 {
211 CheckOneQuadrant(Degrees(90 * 0 + 30), Degrees(30));
212}

◆ TEST() [29/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsOnlyFourthQuadrant   
)

Definition at line 222 of file arc_unittests.cc.

222 {
223 CheckOneQuadrant(Degrees(90 * 3 + 30), Degrees(30));
224}

◆ TEST() [30/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsOnlySecondQuadrant   
)

Definition at line 214 of file arc_unittests.cc.

214 {
215 CheckOneQuadrant(Degrees(90 * 1 + 30), Degrees(30));
216}

◆ TEST() [31/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsOnlyThirdQuadrant   
)

Definition at line 218 of file arc_unittests.cc.

218 {
219 CheckOneQuadrant(Degrees(90 * 2 + 30), Degrees(30));
220}

◆ TEST() [32/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsVariousEndAnglesNearQuadrantAxis   
)

Definition at line 172 of file arc_unittests.cc.

172 {
173 Tessellator tessellator;
174 const auto trigs = tessellator.GetTrigsForDeviceRadius(100);
175
176 for (int sweep_i = 5; sweep_i < 20000; sweep_i += 5) {
177 const Degrees sweep(sweep_i * 0.01f);
178 for (int quadrant = -360; quadrant <= 360; quadrant += 90) {
179 const Degrees start(quadrant + 80);
180 Arc arc(Rect::MakeLTRB(10, 10, 20, 20), start, sweep, false);
181 const auto& arc_iteration = arc.ComputeIterations(trigs.GetSteps());
182
183 TestArcIterator(arc_iteration, trigs, start, sweep,
184 "Various angles(" + std::to_string(start.degrees) +
185 " += " + std::to_string(sweep.degrees));
186 }
187 }
188}
A utility that generates triangles of the specified fill type given a polyline. This happens on the C...
Definition tessellator.h:37
Trigs GetTrigsForDeviceRadius(Scalar pixel_radius)

References impeller::Arc::ComputeIterations(), impeller::Degrees::degrees, impeller::Tessellator::Trigs::GetSteps(), impeller::Tessellator::GetTrigsForDeviceRadius(), impeller::TRect< Scalar >::MakeLTRB(), and start.

◆ TEST() [33/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsVariousStartAnglesNearQuadrantAxis   
)

Definition at line 153 of file arc_unittests.cc.

153 {
154 Tessellator tessellator;
155 const auto trigs = tessellator.GetTrigsForDeviceRadius(100);
156 const Degrees sweep(45);
157
158 for (int start_i = -1000; start_i < 1000; start_i += 5) {
159 Scalar start_degrees = start_i * 0.01f;
160 for (int quadrant = -360; quadrant <= 360; quadrant += 90) {
161 const Degrees start(quadrant + start_degrees);
162 Arc arc(Rect::MakeLTRB(10, 10, 20, 20), start, sweep, false);
163 const auto& arc_iteration = arc.ComputeIterations(trigs.GetSteps());
164
165 TestArcIterator(arc_iteration, trigs, start, sweep,
166 "Various angles(" + std::to_string(start.degrees) +
167 " += " + std::to_string(sweep.degrees));
168 }
169 }
170}

References impeller::Arc::ComputeIterations(), impeller::Degrees::degrees, impeller::Tessellator::Trigs::GetSteps(), impeller::Tessellator::GetTrigsForDeviceRadius(), impeller::TRect< Scalar >::MakeLTRB(), and start.

◆ TEST() [34/689]

impeller::testing::TEST ( ArcTest  ,
ArcIterationsVariousTinyArcsNearQuadrantAxis   
)

Definition at line 190 of file arc_unittests.cc.

190 {
191 Tessellator tessellator;
192 const auto trigs = tessellator.GetTrigsForDeviceRadius(100);
193 const Degrees sweep(0.1f);
194
195 for (int start_i = -1000; start_i < 1000; start_i += 5) {
196 Scalar start_degrees = start_i * 0.01f;
197 for (int quadrant = -360; quadrant <= 360; quadrant += 90) {
198 const Degrees start(quadrant + start_degrees);
199 Arc arc(Rect::MakeLTRB(10, 10, 20, 20), start, sweep, false);
200 const auto& arc_iteration = arc.ComputeIterations(trigs.GetSteps());
201 ASSERT_EQ(arc_iteration.quadrant_count, 0u);
202
203 TestArcIterator(arc_iteration, trigs, start, sweep,
204 "Various angles(" + std::to_string(start.degrees) +
205 " += " + std::to_string(sweep.degrees));
206 }
207 }
208}

References impeller::Arc::ComputeIterations(), impeller::Degrees::degrees, impeller::Tessellator::Trigs::GetSteps(), impeller::Tessellator::GetTrigsForDeviceRadius(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Arc::Iteration::quadrant_count, and start.

◆ TEST() [35/689]

impeller::testing::TEST ( BaseTest  ,
CanUseTypedMasks   
)

Definition at line 259 of file base_unittests.cc.

259 {
260 {
261 MyMask mask;
262 ASSERT_EQ(static_cast<uint32_t>(mask), 0u);
263 ASSERT_FALSE(mask);
264 }
265
266 {
267 MyMask mask(MyMaskBits::kBar);
268 ASSERT_EQ(static_cast<uint32_t>(mask), 1u);
269 ASSERT_TRUE(mask);
270 }
271
272 {
273 MyMask mask2(MyMaskBits::kBar);
274 MyMask mask(mask2);
275 ASSERT_EQ(static_cast<uint32_t>(mask), 1u);
276 ASSERT_TRUE(mask);
277 }
278
279 {
280 MyMask mask2(MyMaskBits::kBar);
281 MyMask mask(std::move(mask2)); // NOLINT
282 ASSERT_EQ(static_cast<uint32_t>(mask), 1u);
283 ASSERT_TRUE(mask);
284 }
285
286 ASSERT_LT(MyMaskBits::kBar, MyMaskBits::kBaz);
287 ASSERT_LE(MyMaskBits::kBar, MyMaskBits::kBaz);
288 ASSERT_GT(MyMaskBits::kBaz, MyMaskBits::kBar);
289 ASSERT_GE(MyMaskBits::kBaz, MyMaskBits::kBar);
290 ASSERT_EQ(MyMaskBits::kBaz, MyMaskBits::kBaz);
291 ASSERT_NE(MyMaskBits::kBaz, MyMaskBits::kBang);
292
293 {
294 MyMask m1(MyMaskBits::kBar);
295 MyMask m2(MyMaskBits::kBaz);
296 ASSERT_EQ(static_cast<uint32_t>(m1 & m2), 0u);
297 ASSERT_FALSE(m1 & m2);
298 }
299
300 {
301 MyMask m1(MyMaskBits::kBar);
302 MyMask m2(MyMaskBits::kBaz);
303 ASSERT_EQ(static_cast<uint32_t>(m1 | m2), ((1u << 0u) | (1u << 1u)));
304 ASSERT_TRUE(m1 | m2);
305 }
306
307 {
308 MyMask m1(MyMaskBits::kBar);
309 MyMask m2(MyMaskBits::kBaz);
310 ASSERT_EQ(static_cast<uint32_t>(m1 ^ m2), ((1u << 0u) ^ (1u << 1u)));
311 ASSERT_TRUE(m1 ^ m2);
312 }
313
314 {
315 MyMask m1(MyMaskBits::kBar);
316 ASSERT_EQ(static_cast<uint32_t>(~m1), (~(1u << 0u)));
317 ASSERT_TRUE(m1);
318 }
319
320 {
321 MyMask m1 = MyMaskBits::kBar;
322 MyMask m2 = MyMaskBits::kBaz;
323 m2 = m1;
324 ASSERT_EQ(m2, MyMaskBits::kBar);
325 }
326
327 {
328 MyMask m = MyMaskBits::kBar | MyMaskBits::kBaz;
329 ASSERT_TRUE(m);
330 }
331
332 {
333 MyMask m = MyMaskBits::kBar & MyMaskBits::kBaz;
334 ASSERT_FALSE(m);
335 }
336
337 {
338 MyMask m = MyMaskBits::kBar ^ MyMaskBits::kBaz;
339 ASSERT_TRUE(m);
340 }
341
342 {
343 MyMask m = ~MyMaskBits::kBar;
344 ASSERT_TRUE(m);
345 }
346
347 {
348 MyMask m1 = MyMaskBits::kBar;
349 MyMask m2 = MyMaskBits::kBaz;
350 m2 |= m1;
351 ASSERT_EQ(m1, MyMaskBits::kBar);
352 MyMask pred = MyMaskBits::kBar | MyMaskBits::kBaz;
353 ASSERT_EQ(m2, pred);
354 }
355
356 {
357 MyMask m1 = MyMaskBits::kBar;
358 MyMask m2 = MyMaskBits::kBaz;
359 m2 &= m1;
360 ASSERT_EQ(m1, MyMaskBits::kBar);
361 MyMask pred = MyMaskBits::kBar & MyMaskBits::kBaz;
362 ASSERT_EQ(m2, pred);
363 }
364
365 {
366 MyMask m1 = MyMaskBits::kBar;
367 MyMask m2 = MyMaskBits::kBaz;
368 m2 ^= m1;
369 ASSERT_EQ(m1, MyMaskBits::kBar);
370 MyMask pred = MyMaskBits::kBar ^ MyMaskBits::kBaz;
371 ASSERT_EQ(m2, pred);
372 }
373
374 {
375 MyMask x = MyMaskBits::kBar;
376 MyMask m = x | MyMaskBits::kBaz;
377 ASSERT_TRUE(m);
378 }
379
380 {
381 MyMask x = MyMaskBits::kBar;
382 MyMask m = MyMaskBits::kBaz | x;
383 ASSERT_TRUE(m);
384 }
385
386 {
387 MyMask x = MyMaskBits::kBar;
388 MyMask m = x & MyMaskBits::kBaz;
389 ASSERT_FALSE(m);
390 }
391
392 {
393 MyMask x = MyMaskBits::kBar;
394 MyMask m = MyMaskBits::kBaz & x;
395 ASSERT_FALSE(m);
396 }
397
398 {
399 MyMask x = MyMaskBits::kBar;
400 MyMask m = x ^ MyMaskBits::kBaz;
401 ASSERT_TRUE(m);
402 }
403
404 {
405 MyMask x = MyMaskBits::kBar;
406 MyMask m = MyMaskBits::kBaz ^ x;
407 ASSERT_TRUE(m);
408 }
409
410 {
411 MyMask x = MyMaskBits::kBar;
412 MyMask m = ~x;
413 ASSERT_TRUE(m);
414 }
415
416 {
417 MyMaskBits x = MyMaskBits::kBar;
418 MyMask m = MyMaskBits::kBaz;
419 ASSERT_TRUE(x < m);
420 ASSERT_TRUE(x <= m);
421 }
422
423 {
424 MyMaskBits x = MyMaskBits::kBar;
425 MyMask m = MyMaskBits::kBaz;
426 ASSERT_FALSE(x == m);
427 }
428
429 {
430 MyMaskBits x = MyMaskBits::kBar;
431 MyMask m = MyMaskBits::kBaz;
432 ASSERT_TRUE(x != m);
433 }
434
435 {
436 MyMaskBits x = MyMaskBits::kBar;
437 MyMask m = MyMaskBits::kBaz;
438 ASSERT_FALSE(x > m);
439 ASSERT_FALSE(x >= m);
440 }
441}
Mask< MyMaskBits > MyMask

References impeller::kBang, impeller::kBar, impeller::kBaz, and x.

◆ TEST() [36/689]

impeller::testing::TEST ( BaseTest  ,
NoExceptionPromiseEmpty   
)

Definition at line 250 of file base_unittests.cc.

250 {
251 auto wrapper = std::make_shared<NoExceptionPromise<int>>();
252 std::future future = wrapper->get_future();
253
254 // Destroy the empty promise with the future still pending. Verify that the
255 // process does not abort while destructing the promise.
256 wrapper.reset();
257}

◆ TEST() [37/689]

impeller::testing::TEST ( BaseTest  ,
NoExceptionPromiseValue   
)

Definition at line 243 of file base_unittests.cc.

243 {
245 std::future future = wrapper.get_future();
246 wrapper.set_value(123);
247 ASSERT_EQ(future.get(), 123);
248}
std::future< T > get_future()
Definition promise.h:36
void set_value(const T &value)
Definition promise.h:38

References impeller::NoExceptionPromise< T >::get_future(), and impeller::NoExceptionPromise< T >::set_value().

◆ TEST() [38/689]

impeller::testing::TEST ( BlitCommandGLESTest  ,
BlitCopyBufferToTextureCommandAllocatesEachMipLevelOnFirstWrite   
)

Definition at line 389 of file blit_command_gles_unittests.cc.

390 {
391 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
392 auto& mock_gles_impl_ref = *mock_gles_impl;
393 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
394 auto reactor = std::make_shared<TestReactorGLES>();
395 auto worker = std::make_shared<MockWorker>();
396 reactor->AddWorker(worker);
397
398 auto dest = CreateMipTexture(reactor, PixelFormat::kR8G8B8A8UNormInt,
399 ISize{8, 8}, /*mip_count=*/3);
400
401 // Each level needs its own correctly-sized source buffer.
402 auto source0 = CreateMipBuffer(reactor, 8 * 8 * 4);
403 auto source1 = CreateMipBuffer(reactor, 4 * 4 * 4);
404 auto source2 = CreateMipBuffer(reactor, 2 * 2 * 4);
405
406 EXPECT_CALL(mock_gles_impl_ref,
407 TexImage2D(GL_TEXTURE_2D, 0, _, 8, 8, _, _, _, nullptr))
408 .Times(1);
409 EXPECT_CALL(mock_gles_impl_ref,
410 TexImage2D(GL_TEXTURE_2D, 1, _, 4, 4, _, _, _, nullptr))
411 .Times(1);
412 EXPECT_CALL(mock_gles_impl_ref,
413 TexImage2D(GL_TEXTURE_2D, 2, _, 2, 2, _, _, _, nullptr))
414 .Times(1);
415 EXPECT_CALL(mock_gles_impl_ref,
416 TexSubImage2D(GL_TEXTURE_2D, 0, _, _, 8, 8, _, _, _))
417 .Times(1);
418 EXPECT_CALL(mock_gles_impl_ref,
419 TexSubImage2D(GL_TEXTURE_2D, 1, _, _, 4, 4, _, _, _))
420 .Times(1);
421 EXPECT_CALL(mock_gles_impl_ref,
422 TexSubImage2D(GL_TEXTURE_2D, 2, _, _, 2, 2, _, _, _))
423 .Times(1);
424
425 for (const auto& [level, w, source] : std::initializer_list<
426 std::tuple<uint32_t, int32_t, std::shared_ptr<DeviceBufferGLES>>>{
427 {0, 8, source0}, {1, 4, source1}, {2, 2, source2}}) {
428 BlitCopyBufferToTextureCommandGLES command;
429 command.source = DeviceBuffer::AsBufferView(source);
430 command.destination = dest;
431 command.destination_region = IRect::MakeXYWH(0, 0, w, w);
432 command.mip_level = level;
433 command.slice = 0;
434 command.label = "TestBlit";
435 EXPECT_TRUE(command.Encode(*reactor));
436 }
437}
Definition ref_ptr.h:261
std::shared_ptr< ReactorGLES > reactor
std::shared_ptr< MockGLES > mock_gl

References impeller::DeviceBuffer::AsBufferView(), impeller::BlitCopyBufferToTextureCommand::destination, impeller::BlitCopyBufferToTextureCommand::destination_region, impeller::BlitCopyBufferToTextureCommandGLES::Encode(), impeller::testing::MockGLES::Init(), impeller::kR8G8B8A8UNormInt, impeller::BlitCommand::label, impeller::TRect< T >::MakeXYWH(), impeller::BlitCopyBufferToTextureCommand::mip_level, mock_gl, reactor, impeller::BlitCopyBufferToTextureCommand::slice, and impeller::BlitCopyBufferToTextureCommand::source.

◆ TEST() [39/689]

impeller::testing::TEST ( BlitCommandGLESTest  ,
BlitCopyBufferToTextureCommandAllocatesNonZeroMipLevelOnFirstUpload   
)

Definition at line 346 of file blit_command_gles_unittests.cc.

347 {
348 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
349 auto& mock_gles_impl_ref = *mock_gles_impl;
350 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
351 auto reactor = std::make_shared<TestReactorGLES>();
352 auto worker = std::make_shared<MockWorker>();
353 reactor->AddWorker(worker);
354
355 auto dest = CreateMipTexture(reactor, PixelFormat::kR8G8B8A8UNormInt,
356 ISize{8, 8}, /*mip_count=*/3);
357 auto source = CreateMipBuffer(reactor, 4 * 4 * 4);
358
360 command.source = DeviceBuffer::AsBufferView(source);
361 command.destination = dest;
362 command.destination_region = IRect::MakeXYWH(0, 0, 4, 4);
363 command.mip_level = 1;
364 command.slice = 0;
365 command.label = "TestBlit";
366
367 // Only level 1 is allocated, and at the halved 4x4 size.
368 EXPECT_CALL(mock_gles_impl_ref,
369 TexImage2D(GL_TEXTURE_2D, 1, _, 4, 4, _, _, _, nullptr))
370 .Times(1);
371 EXPECT_CALL(mock_gles_impl_ref,
372 TexImage2D(GL_TEXTURE_2D, 0, _, _, _, _, _, _, nullptr))
373 .Times(0);
374 EXPECT_CALL(mock_gles_impl_ref,
375 TexImage2D(GL_TEXTURE_2D, 2, _, _, _, _, _, _, nullptr))
376 .Times(0);
377 EXPECT_CALL(mock_gles_impl_ref,
378 TexSubImage2D(GL_TEXTURE_2D, 1, _, _, 4, 4, _, _, _))
379 .Times(1);
380
381 EXPECT_TRUE(command.Encode(*reactor));
382}
bool Encode(const ReactorGLES &reactor) const override
std::shared_ptr< Texture > destination

References impeller::DeviceBuffer::AsBufferView(), impeller::BlitCopyBufferToTextureCommand::destination, impeller::BlitCopyBufferToTextureCommand::destination_region, impeller::BlitCopyBufferToTextureCommandGLES::Encode(), impeller::testing::MockGLES::Init(), impeller::kR8G8B8A8UNormInt, impeller::BlitCommand::label, impeller::TRect< T >::MakeXYWH(), impeller::BlitCopyBufferToTextureCommand::mip_level, mock_gl, reactor, impeller::BlitCopyBufferToTextureCommand::slice, and impeller::BlitCopyBufferToTextureCommand::source.

◆ TEST() [40/689]

impeller::testing::TEST ( BlitCommandGLESTest  ,
BlitCopyBufferToTextureCommandAllocatesOnlyTheRequestedBaseMip   
)

Definition at line 303 of file blit_command_gles_unittests.cc.

304 {
305 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
306 auto& mock_gles_impl_ref = *mock_gles_impl;
307 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
308 auto reactor = std::make_shared<TestReactorGLES>();
309 auto worker = std::make_shared<MockWorker>();
310 reactor->AddWorker(worker);
311
312 auto dest = CreateMipTexture(reactor, PixelFormat::kR8G8B8A8UNormInt,
313 ISize{8, 8}, /*mip_count=*/3);
314 auto source = CreateMipBuffer(reactor, 8 * 8 * 4);
315
317 command.source = DeviceBuffer::AsBufferView(source);
318 command.destination = dest;
319 command.destination_region = IRect::MakeSize(ISize{8, 8});
320 command.mip_level = 0;
321 command.slice = 0;
322 command.label = "TestBlit";
323
324 EXPECT_CALL(mock_gles_impl_ref,
325 TexImage2D(GL_TEXTURE_2D, 0, _, 8, 8, _, _, _, nullptr))
326 .Times(1);
327 // Higher mip levels must NOT be allocated by a level-0 upload.
328 EXPECT_CALL(mock_gles_impl_ref,
329 TexImage2D(GL_TEXTURE_2D, 1, _, _, _, _, _, _, nullptr))
330 .Times(0);
331 EXPECT_CALL(mock_gles_impl_ref,
332 TexImage2D(GL_TEXTURE_2D, 2, _, _, _, _, _, _, nullptr))
333 .Times(0);
334 EXPECT_CALL(mock_gles_impl_ref,
335 TexSubImage2D(GL_TEXTURE_2D, 0, _, _, 8, 8, _, _, _))
336 .Times(1);
337
338 EXPECT_TRUE(command.Encode(*reactor));
339}

References impeller::DeviceBuffer::AsBufferView(), impeller::BlitCopyBufferToTextureCommand::destination, impeller::BlitCopyBufferToTextureCommand::destination_region, impeller::BlitCopyBufferToTextureCommandGLES::Encode(), impeller::testing::MockGLES::Init(), impeller::kR8G8B8A8UNormInt, impeller::BlitCommand::label, impeller::TRect< T >::MakeSize(), impeller::BlitCopyBufferToTextureCommand::mip_level, mock_gl, reactor, impeller::BlitCopyBufferToTextureCommand::slice, and impeller::BlitCopyBufferToTextureCommand::source.

◆ TEST() [41/689]

impeller::testing::TEST ( BlitCommandGLESTest  ,
BlitCopyBufferToTextureCommandDoesNotReallocateOnSubsequentUpload   
)

Definition at line 441 of file blit_command_gles_unittests.cc.

442 {
443 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
444 auto& mock_gles_impl_ref = *mock_gles_impl;
445 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
446 auto reactor = std::make_shared<TestReactorGLES>();
447 auto worker = std::make_shared<MockWorker>();
448 reactor->AddWorker(worker);
449
450 auto dest = CreateMipTexture(reactor, PixelFormat::kR8G8B8A8UNormInt,
451 ISize{4, 4}, /*mip_count=*/2);
452 auto source = CreateMipBuffer(reactor, 4 * 4 * 4);
453
455 command.source = DeviceBuffer::AsBufferView(source);
456 command.destination = dest;
457 command.destination_region = IRect::MakeSize(ISize{4, 4});
458 command.mip_level = 0;
459 command.slice = 0;
460 command.label = "TestBlit";
461
462 // Across both encodes, only the first allocates level 0.
463 EXPECT_CALL(mock_gles_impl_ref,
464 TexImage2D(GL_TEXTURE_2D, 0, _, 4, 4, _, _, _, nullptr))
465 .Times(1);
466 EXPECT_CALL(mock_gles_impl_ref,
467 TexImage2D(GL_TEXTURE_2D, 1, _, _, _, _, _, _, nullptr))
468 .Times(0);
469 EXPECT_CALL(mock_gles_impl_ref,
470 TexSubImage2D(GL_TEXTURE_2D, 0, _, _, _, _, _, _, _))
471 .Times(2);
472
473 EXPECT_TRUE(command.Encode(*reactor));
474 EXPECT_TRUE(command.Encode(*reactor));
475}

References impeller::DeviceBuffer::AsBufferView(), impeller::BlitCopyBufferToTextureCommand::destination, impeller::BlitCopyBufferToTextureCommand::destination_region, impeller::BlitCopyBufferToTextureCommandGLES::Encode(), impeller::testing::MockGLES::Init(), impeller::kR8G8B8A8UNormInt, impeller::BlitCommand::label, impeller::TRect< T >::MakeSize(), impeller::BlitCopyBufferToTextureCommand::mip_level, mock_gl, reactor, impeller::BlitCopyBufferToTextureCommand::slice, and impeller::BlitCopyBufferToTextureCommand::source.

◆ TEST() [42/689]

impeller::testing::TEST ( BlitCommandGLESTest  ,
BlitCopyBufferToTextureCommandGLESBGRA   
)

Definition at line 117 of file blit_command_gles_unittests.cc.

117 {
118 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
119 auto& mock_gles_impl_ref = *mock_gles_impl;
120
121 // Mock gl to support BGRA.
122 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(
123 std::move(mock_gles_impl),
124 std::vector<const char*>{"GL_EXT_texture_format_BGRA8888"});
125 auto reactor = std::make_shared<TestReactorGLES>();
126 auto worker = std::make_shared<MockWorker>();
127 reactor->AddWorker(worker);
128
129 // Dest texture with BGRA format.
130 std::shared_ptr<TextureGLES> dest_texture =
131 CreateTexture(reactor, PixelFormat::kB8G8R8A8UNormInt);
132 std::shared_ptr<DeviceBufferGLES> source_buffer = CreateBuffer(reactor);
134 CreateCopyBufferToTextureCommand(source_buffer, dest_texture);
135
136 // Expect gl TexSubImage2D with GL_BGRA_EXT.
137 EXPECT_CALL(mock_gles_impl_ref,
138 TexSubImage2D(GL_TEXTURE_2D, _, _, _, _, _, GL_BGRA_EXT, _, _))
139 .Times(1);
140
141 EXPECT_TRUE(command.Encode(*reactor));
142}
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &texture_descriptor, const std::vector< uint8_t > &data, const std::shared_ptr< impeller::Context > &context, std::string_view debug_label)

References impeller::CreateTexture(), impeller::BlitCopyBufferToTextureCommandGLES::Encode(), impeller::testing::MockGLES::Init(), impeller::kB8G8R8A8UNormInt, mock_gl, and reactor.

◆ TEST() [43/689]

impeller::testing::TEST ( BlitCommandGLESTest  ,
BlitCopyBufferToTextureCommandGLESRGBA   
)

Definition at line 93 of file blit_command_gles_unittests.cc.

93 {
94 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
95 auto& mock_gles_impl_ref = *mock_gles_impl;
96
97 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
98 auto reactor = std::make_shared<TestReactorGLES>();
99 auto worker = std::make_shared<MockWorker>();
100 reactor->AddWorker(worker);
101
102 // Dest texture with RGBA format.
103 std::shared_ptr<TextureGLES> dest_texture =
104 CreateTexture(reactor, PixelFormat::kR8G8B8A8UNormInt);
105 std::shared_ptr<DeviceBufferGLES> source_buffer = CreateBuffer(reactor);
107 CreateCopyBufferToTextureCommand(source_buffer, dest_texture);
108
109 // Expect gl TexSubImage2D with GL_RGBA.
110 EXPECT_CALL(mock_gles_impl_ref,
111 TexSubImage2D(GL_TEXTURE_2D, _, _, _, _, _, GL_RGBA, _, _))
112 .Times(1);
113
114 EXPECT_TRUE(command.Encode(*reactor));
115}

References impeller::CreateTexture(), impeller::BlitCopyBufferToTextureCommandGLES::Encode(), impeller::testing::MockGLES::Init(), impeller::kR8G8B8A8UNormInt, mock_gl, and reactor.

◆ TEST() [44/689]

impeller::testing::TEST ( BlitCommandGLESTest  ,
BlitCopyBufferToTextureCommandUsesCubemapFaceTargetForCubemap   
)

Definition at line 481 of file blit_command_gles_unittests.cc.

482 {
483 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
484 auto& mock_gles_impl_ref = *mock_gles_impl;
485 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
486 auto reactor = std::make_shared<TestReactorGLES>();
487 auto worker = std::make_shared<MockWorker>();
488 reactor->AddWorker(worker);
489
490 auto dest =
491 CreateMipTexture(reactor, PixelFormat::kR8G8B8A8UNormInt, ISize{4, 4},
492 /*mip_count=*/2, TextureType::kTextureCube);
493 auto source = CreateMipBuffer(reactor, 4 * 4 * 4);
494
496 command.source = DeviceBuffer::AsBufferView(source);
497 command.destination = dest;
498 command.destination_region = IRect::MakeSize(ISize{4, 4});
499 command.mip_level = 0;
500 command.slice = 2; // GL_TEXTURE_CUBE_MAP_POSITIVE_Z
501 command.label = "TestBlit";
502
503 const GLenum face_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + 2;
504
505 // The bind target is the cubemap parent, even though allocation/upload
506 // calls use the per-face target.
507 EXPECT_CALL(mock_gles_impl_ref, BindTexture(GL_TEXTURE_CUBE_MAP, _)).Times(1);
508 EXPECT_CALL(mock_gles_impl_ref,
509 TexImage2D(face_target, 0, _, 4, 4, _, _, _, nullptr))
510 .Times(1);
511 // Higher mips for this face are not allocated by a level-0 upload.
512 EXPECT_CALL(mock_gles_impl_ref,
513 TexImage2D(face_target, 1, _, _, _, _, _, _, nullptr))
514 .Times(0);
515 // No other face is touched.
516 EXPECT_CALL(mock_gles_impl_ref, TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, _,
517 _, _, _, _, _, _, nullptr))
518 .Times(0);
519 EXPECT_CALL(mock_gles_impl_ref,
520 TexImage2D(GL_TEXTURE_2D, _, _, _, _, _, _, _, nullptr))
521 .Times(0);
522 EXPECT_CALL(mock_gles_impl_ref,
523 TexSubImage2D(face_target, 0, _, _, 4, 4, _, _, _))
524 .Times(1);
525
526 EXPECT_TRUE(command.Encode(*reactor));
527}

References impeller::DeviceBuffer::AsBufferView(), impeller::BlitCopyBufferToTextureCommand::destination, impeller::BlitCopyBufferToTextureCommand::destination_region, impeller::BlitCopyBufferToTextureCommandGLES::Encode(), impeller::testing::MockGLES::Init(), impeller::kR8G8B8A8UNormInt, impeller::kTextureCube, impeller::BlitCommand::label, impeller::TRect< T >::MakeSize(), impeller::BlitCopyBufferToTextureCommand::mip_level, mock_gl, reactor, impeller::BlitCopyBufferToTextureCommand::slice, and impeller::BlitCopyBufferToTextureCommand::source.

◆ TEST() [45/689]

impeller::testing::TEST ( BlitCommandGLESTest  ,
BlitCopyTextureToBufferCommandGLESBGRA   
)

Definition at line 207 of file blit_command_gles_unittests.cc.

207 {
208 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
209 auto& mock_gles_impl_ref = *mock_gles_impl;
210
211 // Mock gl to support BGRA.
212 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(
213 std::move(mock_gles_impl),
214 std::vector<const char*>{"GL_EXT_texture_format_BGRA8888"});
215 auto reactor = std::make_shared<TestReactorGLES>();
216 auto worker = std::make_shared<MockWorker>();
217 reactor->AddWorker(worker);
218
219 // Source texture with BGRA format.
220 std::shared_ptr<TextureGLES> source_texture =
221 CreateTexture(reactor, PixelFormat::kB8G8R8A8UNormInt);
222 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
224 CreateCopyTextureToBufferCommand(source_texture, dest_buffer);
225
226 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(_))
227 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
228 // Expect gl ReadPixels with GL_BGRA_EXT.
229 EXPECT_CALL(mock_gles_impl_ref, ReadPixels(_, _, _, _, GL_BGRA_EXT, _, _))
230 .Times(1);
231
232 EXPECT_TRUE(command.Encode(*reactor));
233}
bool Encode(const ReactorGLES &reactor) const override

References impeller::CreateTexture(), impeller::BlitCopyTextureToBufferCommandGLES::Encode(), impeller::testing::MockGLES::Init(), impeller::kB8G8R8A8UNormInt, mock_gl, and reactor.

◆ TEST() [46/689]

impeller::testing::TEST ( BlitCommandGLESTest  ,
BlitCopyTextureToBufferCommandGLESBindsFramebuffer   
)

Definition at line 146 of file blit_command_gles_unittests.cc.

146 {
147 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
148 auto& mock_gles_impl_ref = *mock_gles_impl;
149
150 EXPECT_CALL(mock_gles_impl_ref, GenFramebuffers(1, _))
151 .WillOnce(::testing::SetArgPointee<1>(3));
152 EXPECT_CALL(mock_gles_impl_ref, GenTextures(1, _))
153 .WillOnce(::testing::SetArgPointee<1>(1));
154 EXPECT_CALL(mock_gles_impl_ref, BindFramebuffer(GL_FRAMEBUFFER, 3)).Times(1);
155 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(GL_FRAMEBUFFER))
156 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
157 EXPECT_CALL(mock_gles_impl_ref, ReadPixels(_, _, _, _, _, _, _)).Times(1);
158 EXPECT_CALL(mock_gles_impl_ref, BindFramebuffer(GL_FRAMEBUFFER, 0)).Times(1);
159
160 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
161 auto reactor = std::make_shared<TestReactorGLES>();
162 auto worker = std::make_shared<MockWorker>();
163 reactor->AddWorker(worker);
164
165 std::shared_ptr<TextureGLES> source_texture =
166 CreateTexture(reactor, PixelFormat::kR8G8B8A8UNormInt);
167 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
168
169 ASSERT_TRUE(reactor->React());
170
172 CreateCopyTextureToBufferCommand(source_texture, dest_buffer);
173
174 EXPECT_TRUE(command.Encode(*reactor));
175
176 source_texture.reset();
177 dest_buffer.reset();
178
179 ASSERT_TRUE(reactor->React());
180}

References impeller::CreateTexture(), impeller::BlitCopyTextureToBufferCommandGLES::Encode(), impeller::testing::MockGLES::Init(), impeller::kR8G8B8A8UNormInt, mock_gl, and reactor.

◆ TEST() [47/689]

impeller::testing::TEST ( BlitCommandGLESTest  ,
BlitCopyTextureToBufferCommandGLESRGBA   
)

Definition at line 182 of file blit_command_gles_unittests.cc.

182 {
183 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
184 auto& mock_gles_impl_ref = *mock_gles_impl;
185
186 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
187 auto reactor = std::make_shared<TestReactorGLES>();
188 auto worker = std::make_shared<MockWorker>();
189 reactor->AddWorker(worker);
190
191 // Source texture with RGBA format.
192 std::shared_ptr<TextureGLES> source_texture =
193 CreateTexture(reactor, PixelFormat::kR8G8B8A8UNormInt);
194 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
196 CreateCopyTextureToBufferCommand(source_texture, dest_buffer);
197
198 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(_))
199 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
200 // Expect gl ReadPixels with GL_RGBA.
201 EXPECT_CALL(mock_gles_impl_ref, ReadPixels(_, _, _, _, GL_RGBA, _, _))
202 .Times(1);
203
204 EXPECT_TRUE(command.Encode(*reactor));
205}

References impeller::CreateTexture(), impeller::BlitCopyTextureToBufferCommandGLES::Encode(), impeller::testing::MockGLES::Init(), impeller::kR8G8B8A8UNormInt, mock_gl, and reactor.

◆ TEST() [48/689]

impeller::testing::TEST ( BlitCommandGLESTest  ,
BlitCopyTextureToBufferCommandGLESUnsupportedPixelFormats   
)

Definition at line 235 of file blit_command_gles_unittests.cc.

236 {
237 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
238 auto& mock_gles_impl_ref = *mock_gles_impl;
239
240 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
241 auto reactor = std::make_shared<TestReactorGLES>();
242 auto worker = std::make_shared<MockWorker>();
243 reactor->AddWorker(worker);
244
245 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
246
247 std::shared_ptr<TextureGLES> source_texture_D32FloatS8Uint =
248 CreateTexture(reactor, PixelFormat::kD32FloatS8UInt);
249 BlitCopyTextureToBufferCommandGLES command_for_D32FloatS8Uint =
250 CreateCopyTextureToBufferCommand(source_texture_D32FloatS8Uint,
251 dest_buffer);
252
253 std::shared_ptr<TextureGLES> source_texture_R8G8UNormInt =
254 CreateTexture(reactor, PixelFormat::kR8G8UNormInt);
255 BlitCopyTextureToBufferCommandGLES command_for_R8G8UNormInt =
256 CreateCopyTextureToBufferCommand(source_texture_R8G8UNormInt,
257 dest_buffer);
258
259 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(_)).Times(0);
260
261 // GL does not support texture with an unsupported pixel format.
262 EXPECT_FALSE(command_for_D32FloatS8Uint.Encode(*reactor));
263
264 // GL does not support texture with another unsupported pixel format.
265 EXPECT_FALSE(command_for_R8G8UNormInt.Encode(*reactor));
266}

References impeller::CreateTexture(), impeller::BlitCopyTextureToBufferCommandGLES::Encode(), impeller::testing::MockGLES::Init(), impeller::kD32FloatS8UInt, impeller::kR8G8UNormInt, mock_gl, and reactor.

◆ TEST() [49/689]

impeller::testing::TEST ( BufferBindingsGLESTest  ,
BindArrayData   
)

Definition at line 78 of file buffer_bindings_gles_unittests.cc.

78 {
79 BufferBindingsGLES bindings;
80 absl::flat_hash_map<std::string, GLint> uniform_bindings;
81 uniform_bindings["SHADERMETADATA.FOOBAR[0]"] = 1;
82 bindings.SetUniformBindings(std::move(uniform_bindings));
83 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
84
85 EXPECT_CALL(*mock_gles_impl, Uniform1fv(_, _, _)).Times(1);
86
87 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
88 std::vector<BufferResource> bound_buffers;
89 std::vector<TextureAndSampler> bound_textures;
90
91 ShaderMetadata shader_metadata = {
92 .name = "shader_metadata",
93 .members = {
94 ShaderStructMemberMetadata{.type = ShaderType::kFloat,
95 .name = "foobar",
96 .offset = 0,
97 .size = sizeof(float),
98 .byte_length = sizeof(float) * 4,
99 .array_elements = 4,
100 .float_type = ShaderFloatType::kFloat}}};
101 std::shared_ptr<ReactorGLES> reactor;
102 auto backing_store = std::make_unique<Allocation>();
103 ASSERT_TRUE(backing_store->Truncate(Bytes{sizeof(float) * 4}));
104 DeviceBufferGLES device_buffer(
105 DeviceBufferDescriptor{.size = sizeof(float) * 4}, reactor,
106 std::move(backing_store));
107 BufferView buffer_view(&device_buffer, Range(0, sizeof(float)));
108 bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view));
109
110 EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
111 bound_buffers, Range{0, 0},
112 Range{0, 1}));
113}
Sets up stage bindings for single draw call in the OpenGLES backend.
bool BindUniformData(const ProcTableGLES &gl, const std::vector< TextureAndSampler > &bound_textures, const std::vector< BufferResource > &bound_buffers, Range texture_range, Range buffer_range)
Resource< BufferView > BufferResource
Definition command.h:55

References impeller::BufferBindingsGLES::BindUniformData(), impeller::testing::MockGLES::Init(), impeller::kFloat, mock_gl, impeller::ShaderMetadata::name, reactor, impeller::DeviceBufferDescriptor::size, and impeller::ShaderStructMemberMetadata::type.

◆ TEST() [50/689]

impeller::testing::TEST ( BufferBindingsGLESTest  ,
BindUniformData   
)

Definition at line 42 of file buffer_bindings_gles_unittests.cc.

42 {
43 BufferBindingsGLES bindings;
44 absl::flat_hash_map<std::string, GLint> uniform_bindings;
45 uniform_bindings["SHADERMETADATA.FOOBAR"] = 1;
46 bindings.SetUniformBindings(std::move(uniform_bindings));
47 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
48
49 EXPECT_CALL(*mock_gles_impl, Uniform1fv(_, _, _)).Times(1);
50
51 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
52 std::vector<BufferResource> bound_buffers;
53 std::vector<TextureAndSampler> bound_textures;
54
55 ShaderMetadata shader_metadata = {
56 .name = "shader_metadata",
57 .members = {
58 ShaderStructMemberMetadata{.type = ShaderType::kFloat,
59 .name = "foobar",
60 .offset = 0,
61 .size = sizeof(float),
62 .byte_length = sizeof(float),
63 .array_elements = std::nullopt,
64 .float_type = ShaderFloatType::kFloat}}};
65 std::shared_ptr<ReactorGLES> reactor;
66 auto backing_store = std::make_unique<Allocation>();
67 ASSERT_TRUE(backing_store->Truncate(Bytes{sizeof(float)}));
68 DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = sizeof(float)},
69 reactor, std::move(backing_store));
70 BufferView buffer_view(&device_buffer, Range(0, sizeof(float)));
71 bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view));
72
73 EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
74 bound_buffers, Range{0, 0},
75 Range{0, 1}));
76}

References impeller::BufferBindingsGLES::BindUniformData(), impeller::testing::MockGLES::Init(), impeller::kFloat, mock_gl, impeller::ShaderMetadata::name, reactor, impeller::DeviceBufferDescriptor::size, and impeller::ShaderStructMemberMetadata::type.

◆ TEST() [51/689]

impeller::testing::TEST ( BufferBindingsGLESTest  ,
BindUniformDataVerticesAndMatrices   
)

Definition at line 115 of file buffer_bindings_gles_unittests.cc.

115 {
116 BufferBindingsGLES bindings;
117 absl::flat_hash_map<std::string, GLint> uniform_bindings;
118 uniform_bindings["SHADERMETADATA.VEC2"] = 1;
119 uniform_bindings["SHADERMETADATA.VEC3"] = 2;
120 uniform_bindings["SHADERMETADATA.VEC4"] = 3;
121 uniform_bindings["SHADERMETADATA.MAT2"] = 4;
122 uniform_bindings["SHADERMETADATA.MAT3"] = 5;
123 uniform_bindings["SHADERMETADATA.MAT4"] = 6;
124 bindings.SetUniformBindings(std::move(uniform_bindings));
125 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
126
127 EXPECT_CALL(*mock_gles_impl, Uniform2fv(1, 1, _)).Times(1);
128 EXPECT_CALL(*mock_gles_impl, Uniform3fv(2, 1, _)).Times(1);
129 EXPECT_CALL(*mock_gles_impl, Uniform4fv(3, 1, _)).Times(1);
130 EXPECT_CALL(*mock_gles_impl, UniformMatrix2fv(4, 1, GL_FALSE, _)).Times(1);
131 EXPECT_CALL(*mock_gles_impl, UniformMatrix3fv(5, 1, GL_FALSE, _)).Times(1);
132 EXPECT_CALL(*mock_gles_impl, UniformMatrix4fv(6, 1, GL_FALSE, _)).Times(1);
133
134 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
135 std::vector<BufferResource> bound_buffers;
136 std::vector<TextureAndSampler> bound_textures;
137
138 auto make_metadata = [](ShaderFloatType float_type, const char* name,
139 size_t size) {
140 return ShaderStructMemberMetadata{.type = ShaderType::kFloat,
141 .name = name,
142 .offset = 0,
143 .size = size,
144 .byte_length = size,
145 .array_elements = std::nullopt,
146 .float_type = float_type};
147 };
148
149 ShaderMetadata shader_metadata = {
150 .name = "shader_metadata",
151 .members = {
152 make_metadata(ShaderFloatType::kVec2, "vec2", sizeof(Vector2)),
153 make_metadata(ShaderFloatType::kVec3, "vec3", sizeof(Vector3)),
154 make_metadata(ShaderFloatType::kVec4, "vec4", sizeof(Vector4)),
155 make_metadata(ShaderFloatType::kMat2, "mat2", sizeof(float) * 4),
156 make_metadata(ShaderFloatType::kMat3, "mat3", sizeof(float) * 9),
157 make_metadata(ShaderFloatType::kMat4, "mat4", sizeof(Matrix)),
158 }};
159
160 std::shared_ptr<ReactorGLES> reactor;
161 auto backing_store = std::make_unique<Allocation>();
162 ASSERT_TRUE(backing_store->Truncate(Bytes{1024})); // Plenty of space
163 DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = 1024}, reactor,
164 std::move(backing_store));
165 BufferView buffer_view(&device_buffer, Range(0, 1024));
166 bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view));
167
168 EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
169 bound_buffers, Range{0, 0},
170 Range{0, 1}));
171}

References impeller::BufferBindingsGLES::BindUniformData(), impeller::testing::MockGLES::Init(), impeller::kFloat, impeller::kMat2, impeller::kMat3, impeller::kMat4, impeller::kVec2, impeller::kVec3, impeller::kVec4, mock_gl, impeller::ShaderMetadata::name, flutter::name, reactor, impeller::DeviceBufferDescriptor::size, flutter::size, and impeller::ShaderStructMemberMetadata::type.

◆ TEST() [52/689]

impeller::testing::TEST ( BufferBindingsGLESTest  ,
BindUniformFailsWithoutFloatType   
)

Definition at line 179 of file buffer_bindings_gles_unittests.cc.

179 {
180 BufferBindingsGLES bindings;
181 absl::flat_hash_map<std::string, GLint> uniform_bindings;
182 uniform_bindings["SHADERMETADATA.FOOBAR"] = 1;
183 bindings.SetUniformBindings(std::move(uniform_bindings));
184 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
185 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
186 std::vector<BufferResource> bound_buffers;
187 std::vector<TextureAndSampler> bound_textures;
188
189 ShaderMetadata shader_metadata = {
190 .name = "shader_metadata",
191 .members = {ShaderStructMemberMetadata{.type = ShaderType::kFloat,
192 .name = "foobar",
193 .offset = 0,
194 .size = sizeof(float),
195 .byte_length = sizeof(float),
196 .array_elements = std::nullopt,
197 .float_type = std::nullopt}}};
198 std::shared_ptr<ReactorGLES> reactor;
199 auto backing_store = std::make_unique<Allocation>();
200 ASSERT_TRUE(backing_store->Truncate(Bytes{sizeof(float)}));
201 DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = sizeof(float)},
202 reactor, std::move(backing_store));
203 BufferView buffer_view(&device_buffer, Range(0, sizeof(float)));
204 bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view));
205
206 EXPECT_FALSE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
207 bound_buffers, Range{0, 0},
208 Range{0, 1}));
209}

References impeller::BufferBindingsGLES::BindUniformData(), impeller::testing::MockGLES::Init(), impeller::kFloat, mock_gl, impeller::ShaderMetadata::name, reactor, impeller::DeviceBufferDescriptor::size, and impeller::ShaderStructMemberMetadata::type.

◆ TEST() [53/689]

impeller::testing::TEST ( BufferBindingsGLESTest  ,
BindVertexAttributesSetsInstanceRateDivisor   
)

Definition at line 215 of file buffer_bindings_gles_unittests.cc.

215 {
216 auto mock_gles_impl = std::make_unique<::testing::NiceMock<MockGLESImpl>>();
217 EXPECT_CALL(*mock_gles_impl, VertexAttribDivisor(0, 0)).Times(1);
218 EXPECT_CALL(*mock_gles_impl, VertexAttribDivisor(1, 1)).Times(1);
219 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
220
221 BufferBindingsGLES bindings;
222
223 ShaderStageIOSlot per_vertex_input = {
224 .name = "position",
225 .location = 0,
226 .set = 0,
227 .binding = 0,
228 .type = ShaderType::kFloat,
229 .bit_width = sizeof(float) * 8,
230 .vec_size = 2,
231 .columns = 1,
232 .offset = 0,
233 };
234 ShaderStageIOSlot per_instance_input = {
235 .name = "instance_offset",
236 .location = 1,
237 .set = 0,
238 .binding = 1,
239 .type = ShaderType::kFloat,
240 .bit_width = sizeof(float) * 8,
241 .vec_size = 2,
242 .columns = 1,
243 .offset = 0,
244 };
245 std::vector<ShaderStageIOSlot> inputs = {per_vertex_input,
246 per_instance_input};
247 std::vector<ShaderStageBufferLayout> layouts = {
248 ShaderStageBufferLayout{.stride = sizeof(float) * 2,
249 .binding = 0,
250 .input_rate = VertexInputRate::kVertex},
251 ShaderStageBufferLayout{.stride = sizeof(float) * 2,
252 .binding = 1,
253 .input_rate = VertexInputRate::kInstance},
254 };
255
256 ASSERT_TRUE(bindings.RegisterVertexStageInput(mock_gl->GetProcTable(), inputs,
257 layouts));
258 // Binding 0 is per-vertex (divisor 0); binding 1 is per-instance
259 // (divisor 1).
260 EXPECT_TRUE(bindings.BindVertexAttributes(mock_gl->GetProcTable(),
261 /*binding=*/0, /*vertex_offset=*/0,
262 /*instance=*/0));
263 EXPECT_TRUE(bindings.BindVertexAttributes(mock_gl->GetProcTable(),
264 /*binding=*/1, /*vertex_offset=*/0,
265 /*instance=*/0));
266}
bool BindVertexAttributes(const ProcTableGLES &gl, size_t binding, size_t vertex_offset, size_t instance=0)
bool RegisterVertexStageInput(const ProcTableGLES &gl, const std::vector< ShaderStageIOSlot > &inputs, const std::vector< ShaderStageBufferLayout > &layouts)
uint32_t vec_size
uint32_t columns

References impeller::BufferBindingsGLES::BindVertexAttributes(), columns, impeller::testing::MockGLES::Init(), impeller::kFloat, impeller::kInstance, impeller::kVertex, mock_gl, impeller::ShaderStageIOSlot::name, impeller::BufferBindingsGLES::RegisterVertexStageInput(), impeller::ShaderStageBufferLayout::stride, and vec_size.

◆ TEST() [54/689]

impeller::testing::TEST ( BufferBindingsGLESTest  ,
ToVertexAttribTypeRejectsUnsupportedFormats   
)

Definition at line 32 of file buffer_bindings_gles_unittests.cc.

32 {
33 // Half-float and 32-bit integer vertex attributes are not available on the
34 // GLES 2.0 floor.
35 EXPECT_FALSE(ToVertexAttribType(VertexAttributeFormat::kFloat16).has_value());
36 EXPECT_FALSE(ToVertexAttribType(VertexAttributeFormat::kSInt32).has_value());
37 EXPECT_FALSE(
38 ToVertexAttribType(VertexAttributeFormat::kUInt32x4).has_value());
39 EXPECT_FALSE(ToVertexAttribType(VertexAttributeFormat::kInvalid).has_value());
40}
constexpr std::optional< GLenum > ToVertexAttribType(VertexAttributeFormat type)

References impeller::kFloat16, impeller::kInvalid, impeller::kSInt32, impeller::kUInt32x4, and impeller::ToVertexAttribType().

◆ TEST() [55/689]

impeller::testing::TEST ( BufferBindingsGLESTest  ,
ToVertexAttribTypeSupportedFormats   
)

Definition at line 19 of file buffer_bindings_gles_unittests.cc.

19 {
20 EXPECT_EQ(ToVertexAttribType(VertexAttributeFormat::kFloat32x3),
21 std::optional<GLenum>(GL_FLOAT));
22 EXPECT_EQ(ToVertexAttribType(VertexAttributeFormat::kSInt8x4),
23 std::optional<GLenum>(GL_BYTE));
24 EXPECT_EQ(ToVertexAttribType(VertexAttributeFormat::kUInt8),
25 std::optional<GLenum>(GL_UNSIGNED_BYTE));
26 EXPECT_EQ(ToVertexAttribType(VertexAttributeFormat::kSInt16x2),
27 std::optional<GLenum>(GL_SHORT));
28 EXPECT_EQ(ToVertexAttribType(VertexAttributeFormat::kUInt16),
29 std::optional<GLenum>(GL_UNSIGNED_SHORT));
30}

References impeller::kFloat32x3, impeller::kSInt16x2, impeller::kSInt8x4, impeller::kUInt16, impeller::kUInt8, and impeller::ToVertexAttribType().

◆ TEST() [56/689]

impeller::testing::TEST ( BufferViewTest  ,
Empty   
)

Definition at line 11 of file buffer_view_unittests.cc.

11 {
12 BufferView buffer_view;
13 EXPECT_FALSE(buffer_view);
14}

◆ TEST() [57/689]

impeller::testing::TEST ( BufferViewTest  ,
TakeRaw   
)

Definition at line 16 of file buffer_view_unittests.cc.

16 {
17 DeviceBuffer* buffer = reinterpret_cast<DeviceBuffer*>(0xcafebabe);
18 BufferView buffer_view(buffer, {0, 123});
19 EXPECT_TRUE(buffer_view);
20 std::shared_ptr<const DeviceBuffer> taken = buffer_view.TakeBuffer();
21 EXPECT_FALSE(taken);
22 EXPECT_EQ(buffer_view.GetBuffer(), buffer);
23}

References flutter::buffer.

◆ TEST() [58/689]

impeller::testing::TEST ( CanvasTest  ,
AntialiasedPaintCompatibleWithSDFRendering   
)

Definition at line 555 of file canvas_unittests.cc.

555 {
556 Paint paint;
557 EXPECT_TRUE(Canvas::IsCompatibleWithSDFRendering(paint));
558}

References impeller::Canvas::IsCompatibleWithSDFRendering().

◆ TEST() [59/689]

impeller::testing::TEST ( CanvasTest  ,
NonAntialiasedPaintIncompatibleWithSDFRendering   
)

Definition at line 549 of file canvas_unittests.cc.

549 {
550 Paint paint;
551 paint.anti_alias = false;
552 EXPECT_FALSE(Canvas::IsCompatibleWithSDFRendering(paint));
553}
bool anti_alias
Definition paint.h:88

References impeller::Paint::anti_alias, and impeller::Canvas::IsCompatibleWithSDFRendering().

◆ TEST() [60/689]

impeller::testing::TEST ( CapabilitiesGLES  ,
CanInitializeWithDefaults   
)

Definition at line 13 of file capabilities_unittests.cc.

13 {
14 auto mock_gles = MockGLES::Init();
15
16 auto capabilities = mock_gles->GetProcTable().GetCapabilities();
17
18 EXPECT_FALSE(capabilities->SupportsOffscreenMSAA());
19 EXPECT_FALSE(capabilities->SupportsSSBO());
20 EXPECT_TRUE(capabilities->SupportsTextureToTextureBlits());
21 EXPECT_FALSE(capabilities->SupportsFramebufferFetch());
22 EXPECT_FALSE(capabilities->SupportsCompute());
23 EXPECT_FALSE(capabilities->SupportsComputeSubgroups());
24 EXPECT_FALSE(capabilities->SupportsReadFromResolve());
25 EXPECT_FALSE(capabilities->SupportsDecalSamplerAddressMode());
26 EXPECT_FALSE(capabilities->SupportsDeviceTransientTextures());
27
28 EXPECT_EQ(capabilities->GetDefaultColorFormat(),
29 PixelFormat::kR8G8B8A8UNormInt);
30 EXPECT_EQ(capabilities->GetDefaultStencilFormat(), PixelFormat::kS8UInt);
31 EXPECT_EQ(capabilities->GetDefaultDepthStencilFormat(),
32 PixelFormat::kD24UnormS8Uint);
33}

References impeller::testing::MockGLES::Init(), impeller::kD24UnormS8Uint, impeller::kR8G8B8A8UNormInt, and impeller::kS8UInt.

◆ TEST() [61/689]

impeller::testing::TEST ( CapabilitiesGLES  ,
MaxSamplerAnisotropyUnsupportedByDefault   
)

Definition at line 75 of file capabilities_unittests.cc.

75 {
76 auto mock_gles = MockGLES::Init();
77 auto capabilities = mock_gles->GetProcTable().GetCapabilities();
78 EXPECT_EQ(capabilities->GetMaxSamplerAnisotropy(), 1u);
79}

References impeller::testing::MockGLES::Init().

◆ TEST() [62/689]

impeller::testing::TEST ( CapabilitiesGLES  ,
MaxSamplerAnisotropyWithExtension   
)

Definition at line 81 of file capabilities_unittests.cc.

81 {
82 auto const extensions = std::vector<const char*>{
83 "GL_KHR_debug", //
84 "GL_EXT_texture_filter_anisotropic", //
85 };
86 auto mock_gles = MockGLES::Init(extensions);
87 auto capabilities = mock_gles->GetProcTable().GetCapabilities();
88 // The extension guarantees a maximum anisotropy of at least 2.
89 EXPECT_GE(capabilities->GetMaxSamplerAnisotropy(), 2u);
90}

References impeller::testing::MockGLES::Init().

◆ TEST() [63/689]

impeller::testing::TEST ( CapabilitiesGLES  ,
SupportsDecalSamplerAddressMode   
)

Definition at line 35 of file capabilities_unittests.cc.

35 {
36 auto const extensions = std::vector<const char*>{
37 "GL_KHR_debug", //
38 "GL_EXT_texture_border_clamp", //
39 };
40 auto mock_gles = MockGLES::Init(extensions);
41 auto capabilities = mock_gles->GetProcTable().GetCapabilities();
42 EXPECT_TRUE(capabilities->SupportsDecalSamplerAddressMode());
43}

References impeller::testing::MockGLES::Init().

◆ TEST() [64/689]

impeller::testing::TEST ( CapabilitiesGLES  ,
SupportsDecalSamplerAddressModeNotOES   
)

Definition at line 45 of file capabilities_unittests.cc.

45 {
46 auto const extensions = std::vector<const char*>{
47 "GL_KHR_debug", //
48 "GL_OES_texture_border_clamp", //
49 };
50 auto mock_gles = MockGLES::Init(extensions);
51 auto capabilities = mock_gles->GetProcTable().GetCapabilities();
52 EXPECT_FALSE(capabilities->SupportsDecalSamplerAddressMode());
53}

References impeller::testing::MockGLES::Init().

◆ TEST() [65/689]

impeller::testing::TEST ( CapabilitiesGLES  ,
SupportsFramebufferFetch   
)

Definition at line 55 of file capabilities_unittests.cc.

55 {
56 auto const extensions = std::vector<const char*>{
57 "GL_KHR_debug", //
58 "GL_EXT_shader_framebuffer_fetch", //
59 };
60 auto mock_gles = MockGLES::Init(extensions);
61 auto capabilities = mock_gles->GetProcTable().GetCapabilities();
62 EXPECT_TRUE(capabilities->SupportsFramebufferFetch());
63}

References impeller::testing::MockGLES::Init().

◆ TEST() [66/689]

impeller::testing::TEST ( CapabilitiesGLES  ,
SupportsMSAA   
)

Definition at line 65 of file capabilities_unittests.cc.

65 {
66 auto const extensions = std::vector<const char*>{
67 "GL_EXT_multisampled_render_to_texture",
68 };
69 auto mock_gles = MockGLES::Init(extensions);
70 auto capabilities = mock_gles->GetProcTable().GetCapabilities();
71 EXPECT_TRUE(capabilities->SupportsImplicitResolvingMSAA());
72 EXPECT_FALSE(capabilities->SupportsOffscreenMSAA());
73}

References impeller::testing::MockGLES::Init().

◆ TEST() [67/689]

impeller::testing::TEST ( CapabilitiesTest  ,
DefaultColorFormat   
)

Definition at line 34 of file capabilities_unittests.cc.

34 {
35 auto defaults = CapabilitiesBuilder().Build();
36 EXPECT_EQ(defaults->GetDefaultColorFormat(), PixelFormat::kUnknown);
37 auto mutated = CapabilitiesBuilder()
38 .SetDefaultColorFormat(PixelFormat::kB10G10R10A10XR)
39 .Build();
40 EXPECT_EQ(mutated->GetDefaultColorFormat(), PixelFormat::kB10G10R10A10XR);
41}
CapabilitiesBuilder & SetDefaultColorFormat(PixelFormat value)
std::unique_ptr< Capabilities > Build()

References impeller::CapabilitiesBuilder::Build(), impeller::kB10G10R10A10XR, impeller::kUnknown, and impeller::CapabilitiesBuilder::SetDefaultColorFormat().

◆ TEST() [68/689]

impeller::testing::TEST ( CapabilitiesTest  ,
DefaultDepthStencilFormat   
)

Definition at line 52 of file capabilities_unittests.cc.

52 {
53 auto defaults = CapabilitiesBuilder().Build();
54 EXPECT_EQ(defaults->GetDefaultDepthStencilFormat(), PixelFormat::kUnknown);
55 auto mutated = CapabilitiesBuilder()
56 .SetDefaultDepthStencilFormat(PixelFormat::kD32FloatS8UInt)
57 .Build();
58 EXPECT_EQ(mutated->GetDefaultDepthStencilFormat(),
59 PixelFormat::kD32FloatS8UInt);
60}
CapabilitiesBuilder & SetDefaultDepthStencilFormat(PixelFormat value)

References impeller::CapabilitiesBuilder::Build(), impeller::kD32FloatS8UInt, impeller::kUnknown, and impeller::CapabilitiesBuilder::SetDefaultDepthStencilFormat().

◆ TEST() [69/689]

impeller::testing::TEST ( CapabilitiesTest  ,
DefaultGlyphAtlasFormat   
)

Definition at line 62 of file capabilities_unittests.cc.

62 {
63 auto defaults = CapabilitiesBuilder().Build();
64 EXPECT_EQ(defaults->GetDefaultGlyphAtlasFormat(), PixelFormat::kUnknown);
65 auto mutated = CapabilitiesBuilder()
66 .SetDefaultGlyphAtlasFormat(PixelFormat::kA8UNormInt)
67 .Build();
68 EXPECT_EQ(mutated->GetDefaultGlyphAtlasFormat(), PixelFormat::kA8UNormInt);
69}
CapabilitiesBuilder & SetDefaultGlyphAtlasFormat(PixelFormat value)

References impeller::CapabilitiesBuilder::Build(), impeller::kA8UNormInt, impeller::kUnknown, and impeller::CapabilitiesBuilder::SetDefaultGlyphAtlasFormat().

◆ TEST() [70/689]

impeller::testing::TEST ( CapabilitiesTest  ,
DefaultStencilFormat   
)

Definition at line 43 of file capabilities_unittests.cc.

43 {
44 auto defaults = CapabilitiesBuilder().Build();
45 EXPECT_EQ(defaults->GetDefaultStencilFormat(), PixelFormat::kUnknown);
46 auto mutated = CapabilitiesBuilder()
47 .SetDefaultStencilFormat(PixelFormat::kS8UInt)
48 .Build();
49 EXPECT_EQ(mutated->GetDefaultStencilFormat(), PixelFormat::kS8UInt);
50}
CapabilitiesBuilder & SetDefaultStencilFormat(PixelFormat value)

References impeller::CapabilitiesBuilder::Build(), impeller::kS8UInt, impeller::kUnknown, and impeller::CapabilitiesBuilder::SetDefaultStencilFormat().

◆ TEST() [71/689]

impeller::testing::TEST ( CapabilitiesTest  ,
MaxRenderPassAttachmentSize   
)

Definition at line 71 of file capabilities_unittests.cc.

71 {
72 auto defaults = CapabilitiesBuilder().Build();
73 EXPECT_EQ(defaults->GetMaximumRenderPassAttachmentSize(), ISize(1, 1));
74 auto mutated = CapabilitiesBuilder()
76 .Build();
77 EXPECT_EQ(mutated->GetMaximumRenderPassAttachmentSize(), ISize(100, 100));
78}
CapabilitiesBuilder & SetMaximumRenderPassAttachmentSize(ISize size)

References impeller::CapabilitiesBuilder::Build(), and impeller::CapabilitiesBuilder::SetMaximumRenderPassAttachmentSize().

◆ TEST() [72/689]

impeller::testing::TEST ( CapabilitiesTest  ,
MaxSamplerAnisotropy   
)

Definition at line 123 of file capabilities_unittests.cc.

123 {
124 auto defaults = CapabilitiesBuilder().Build();
125 EXPECT_EQ(defaults->GetMaxSamplerAnisotropy(), 1u);
127 EXPECT_EQ(mutated->GetMaxSamplerAnisotropy(), 16u);
128}
CapabilitiesBuilder & SetMaxSamplerAnisotropy(uint32_t value)

References impeller::CapabilitiesBuilder::Build(), and impeller::CapabilitiesBuilder::SetMaxSamplerAnisotropy().

◆ TEST() [73/689]

impeller::testing::TEST ( CapabilitiesTest  ,
MinUniformAlignment   
)

Definition at line 116 of file capabilities_unittests.cc.

116 {
117 auto defaults = CapabilitiesBuilder().Build();
118 EXPECT_EQ(defaults->GetMinimumUniformAlignment(), 256u);
120 EXPECT_EQ(mutated->GetMinimumUniformAlignment(), 16u);
121}
CapabilitiesBuilder & SetMinimumUniformAlignment(size_t value)

References impeller::CapabilitiesBuilder::Build(), and impeller::CapabilitiesBuilder::SetMinimumUniformAlignment().

◆ TEST() [74/689]

impeller::testing::TEST ( CapabilitiesTest  ,
SupportsTextureCompression   
)

Definition at line 80 of file capabilities_unittests.cc.

80 {
81 auto defaults = CapabilitiesBuilder().Build();
82 EXPECT_FALSE(
83 defaults->SupportsTextureCompression(CompressedTextureFamily::kBC));
84 EXPECT_FALSE(
85 defaults->SupportsTextureCompression(CompressedTextureFamily::kETC2));
86 EXPECT_FALSE(
87 defaults->SupportsTextureCompression(CompressedTextureFamily::kASTC));
88 EXPECT_FALSE(
89 defaults->SupportsTextureCompression(CompressedTextureFamily::kASTCHDR));
90
91 // Each family is gated independently.
92 auto mutated =
94 .SetSupportsTextureCompression(CompressedTextureFamily::kETC2, true)
95 .Build();
96 EXPECT_FALSE(
97 mutated->SupportsTextureCompression(CompressedTextureFamily::kBC));
98 EXPECT_TRUE(
99 mutated->SupportsTextureCompression(CompressedTextureFamily::kETC2));
100 EXPECT_FALSE(
101 mutated->SupportsTextureCompression(CompressedTextureFamily::kASTC));
102 EXPECT_FALSE(
103 mutated->SupportsTextureCompression(CompressedTextureFamily::kASTCHDR));
104
105 // ASTC LDR and HDR are distinct families.
106 auto astc_hdr = CapabilitiesBuilder()
108 CompressedTextureFamily::kASTCHDR, true)
109 .Build();
110 EXPECT_FALSE(
111 astc_hdr->SupportsTextureCompression(CompressedTextureFamily::kASTC));
112 EXPECT_TRUE(
113 astc_hdr->SupportsTextureCompression(CompressedTextureFamily::kASTCHDR));
114}
CapabilitiesBuilder & SetSupportsTextureCompression(CompressedTextureFamily family, bool value)

References impeller::CapabilitiesBuilder::Build(), impeller::kASTC, impeller::kASTCHDR, impeller::kBC, impeller::kETC2, and impeller::CapabilitiesBuilder::SetSupportsTextureCompression().

◆ TEST() [75/689]

impeller::testing::TEST ( CapabilitiesVKTest  ,
ContextFailsInitializationForNoCombinedDepthStencilFormat   
)

Definition at line 215 of file context_vk_unittests.cc.

216 {
217 ScopedValidationDisable disable_validation;
218 const std::shared_ptr<ContextVK> context =
221 [](VkPhysicalDevice physicalDevice, VkFormat format,
222 VkFormatProperties* pFormatProperties) {
223 if (format == VK_FORMAT_R8G8B8A8_UNORM) {
224 pFormatProperties->optimalTilingFeatures =
225 static_cast<VkFormatFeatureFlags>(
226 vk::FormatFeatureFlagBits::eColorAttachment);
227 }
228 // Ignore combined depth-stencil formats.
229 })
230 .Build();
231 ASSERT_EQ(context, nullptr);
232}
MockVulkanContextBuilder & SetPhysicalDeviceFormatPropertiesCallback(std::function< void(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties *pFormatProperties)> format_properties_callback)

References context, format, and impeller::testing::MockVulkanContextBuilder::SetPhysicalDeviceFormatPropertiesCallback().

◆ TEST() [76/689]

impeller::testing::TEST ( CapabilitiesVKTest  ,
ContextInitializesWithNoStencilFormat   
)

Definition at line 184 of file context_vk_unittests.cc.

184 {
185 const std::shared_ptr<ContextVK> context =
188 [](VkPhysicalDevice physicalDevice, VkFormat format,
189 VkFormatProperties* pFormatProperties) {
190 if (format == VK_FORMAT_R8G8B8A8_UNORM) {
191 pFormatProperties->optimalTilingFeatures =
192 static_cast<VkFormatFeatureFlags>(
193 vk::FormatFeatureFlagBits::eColorAttachment);
194 } else if (format == VK_FORMAT_D32_SFLOAT_S8_UINT) {
195 pFormatProperties->optimalTilingFeatures =
196 static_cast<VkFormatFeatureFlags>(
197 vk::FormatFeatureFlagBits::eDepthStencilAttachment);
198 }
199 // Ignore just the stencil format.
200 })
201 .Build();
202 ASSERT_NE(context, nullptr);
203 const CapabilitiesVK* capabilites_vk =
204 reinterpret_cast<const CapabilitiesVK*>(context->GetCapabilities().get());
205 ASSERT_EQ(capabilites_vk->GetDefaultDepthStencilFormat(),
206 PixelFormat::kD32FloatS8UInt);
207 ASSERT_EQ(capabilites_vk->GetDefaultStencilFormat(),
208 PixelFormat::kD32FloatS8UInt);
209}

References context, format, impeller::CapabilitiesVK::GetDefaultDepthStencilFormat(), impeller::CapabilitiesVK::GetDefaultStencilFormat(), impeller::kD32FloatS8UInt, and impeller::testing::MockVulkanContextBuilder::SetPhysicalDeviceFormatPropertiesCallback().

◆ TEST() [77/689]

impeller::testing::TEST ( CommandBufferGLES  ,
BufferToTextureBlitCanBeSubmittedBeforeContextCurrent   
)

Definition at line 176 of file command_buffer_gles_unittests.cc.

176 {
177 auto mock_gles_impl = std::make_unique<NiceMock<MockGLESImpl>>();
178 auto& mock_gles_impl_ref = *mock_gles_impl;
179 auto mock_gles = MockGLES::Init(std::move(mock_gles_impl));
180 auto context = CreateFakeGLESContext();
181 auto context_base = std::static_pointer_cast<Context>(context);
182 auto worker = std::make_shared<ToggleWorker>(false);
183 context->AddReactorWorker(worker);
184
185 constexpr GLuint kTextureHandle = 1234;
186 bool texture_generated = false;
187 bool texture_uploaded = false;
188 EXPECT_CALL(mock_gles_impl_ref, GenTextures(1, _))
189 .WillOnce([&](GLsizei size, GLuint* textures) {
190 texture_generated = true;
191 textures[0] = kTextureHandle;
192 });
193 EXPECT_CALL(mock_gles_impl_ref, BindTexture(GL_TEXTURE_2D, kTextureHandle))
194 .Times(::testing::AtLeast(1));
195 EXPECT_CALL(mock_gles_impl_ref,
196 TexImage2D(GL_TEXTURE_2D, 0, _, 2, 2, 0, _, _, nullptr))
197 .Times(1);
198 EXPECT_CALL(mock_gles_impl_ref,
199 TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, _, _, _))
200 .WillOnce([&](GLenum target, GLint level, GLint xoffset, GLint yoffset,
201 GLsizei width, GLsizei height, GLenum format, GLenum type,
202 const void* pixels) { texture_uploaded = true; });
203
204 TextureDescriptor texture_descriptor;
205 texture_descriptor.size = {2, 2};
206 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
207 auto texture = context_base->GetResourceAllocator()->CreateTexture(
208 texture_descriptor, /*threadsafe=*/true);
209 ASSERT_TRUE(texture);
210
211 const uint8_t pixels[16] = {};
212 auto buffer =
213 context_base->GetResourceAllocator()->CreateBufferWithCopy(pixels, 16);
214 ASSERT_TRUE(buffer);
215
216 auto command_buffer = context_base->CreateCommandBuffer();
217 ASSERT_TRUE(command_buffer);
218 auto blit_pass = command_buffer->CreateBlitPass();
219 ASSERT_TRUE(blit_pass);
220
221 EXPECT_TRUE(blit_pass->AddCopy(BufferView(buffer, Range(0, 16)), texture,
222 IRect::MakeXYWH(0, 0, 2, 2),
223 "Deferred texture overwrite"));
224 EXPECT_TRUE(blit_pass->EncodeCommands());
225 EXPECT_TRUE(context_base->GetCommandQueue()->Submit({command_buffer}).ok());
226 EXPECT_FALSE(texture_generated);
227 EXPECT_FALSE(texture_uploaded);
228
229 worker->SetAllowed(true);
230 EXPECT_TRUE(context->GetReactor()->React());
231 EXPECT_TRUE(texture_generated);
232 EXPECT_TRUE(texture_uploaded);
233}
std::shared_ptr< CommandBuffer > command_buffer

References flutter::buffer, command_buffer, context, impeller::TextureDescriptor::format, format, height, impeller::testing::MockGLES::Init(), impeller::kR8G8B8A8UNormInt, impeller::TRect< T >::MakeXYWH(), impeller::TextureDescriptor::size, flutter::size, target, texture, type, and width.

◆ TEST() [78/689]

impeller::testing::TEST ( CommandBufferGLES  ,
DeferredSubmitCallbackErrorsIfReactorIsDestroyed   
)

Definition at line 94 of file command_buffer_gles_unittests.cc.

94 {
95 bool callback_called = false;
96 CommandBuffer::Status callback_status = CommandBuffer::Status::kCompleted;
97
98 {
99 auto mock_gles = MockGLES::Init();
100 auto context = CreateFakeGLESContext();
101 auto context_base = std::static_pointer_cast<Context>(context);
102 auto worker = std::make_shared<ToggleWorker>(false);
103 context->AddReactorWorker(worker);
104
105 auto command_buffer = context_base->CreateCommandBuffer();
106 ASSERT_TRUE(command_buffer);
107 auto status = context_base->GetCommandQueue()->Submit(
109 callback_called = true;
110 callback_status = status;
111 });
112
113 EXPECT_TRUE(status.ok());
114 EXPECT_FALSE(callback_called);
115 }
116
117 EXPECT_TRUE(callback_called);
118 EXPECT_EQ(callback_status, CommandBuffer::Status::kError);
119}

References command_buffer, context, impeller::testing::MockGLES::Init(), impeller::CommandBuffer::kCompleted, and impeller::CommandBuffer::kError.

◆ TEST() [79/689]

impeller::testing::TEST ( CommandBufferGLES  ,
DeferredSubmitCompletesAfterPreviouslyQueuedWork   
)

Definition at line 121 of file command_buffer_gles_unittests.cc.

121 {
122 auto mock_gles = MockGLES::Init();
123 auto context = CreateFakeGLESContext();
124 auto context_base = std::static_pointer_cast<Context>(context);
125 auto worker = std::make_shared<ToggleWorker>(false);
126 context->AddReactorWorker(worker);
127
128 std::vector<int> order;
129 ASSERT_TRUE(context->GetReactor()->AddOperation(
130 [&](const ReactorGLES& reactor) { order.push_back(1); },
131 /*defer=*/true));
132
133 auto command_buffer = context_base->CreateCommandBuffer();
134 ASSERT_TRUE(command_buffer);
135 auto status = context_base->GetCommandQueue()->Submit(
137 [&](CommandBuffer::Status status) { order.push_back(2); });
138
139 EXPECT_TRUE(status.ok());
140 EXPECT_TRUE(order.empty());
141
142 worker->SetAllowed(true);
143 EXPECT_TRUE(context->GetReactor()->React());
144 EXPECT_THAT(order, ::testing::ElementsAre(1, 2));
145}
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.

References command_buffer, context, impeller::testing::MockGLES::Init(), and reactor.

◆ TEST() [80/689]

impeller::testing::TEST ( CommandBufferGLES  ,
LaterCurrentSubmitDrainsPreviouslyDeferredWork   
)

Definition at line 147 of file command_buffer_gles_unittests.cc.

147 {
148 auto mock_gles = MockGLES::Init();
149 auto context = CreateFakeGLESContext();
150 auto context_base = std::static_pointer_cast<Context>(context);
151 auto worker = std::make_shared<ToggleWorker>(false);
152 context->AddReactorWorker(worker);
153
154 std::vector<int> order;
155 ASSERT_TRUE(context->GetReactor()->AddOperation(
156 [&](const ReactorGLES& reactor) { order.push_back(1); },
157 /*defer=*/true));
158
159 auto deferred_command_buffer = context_base->CreateCommandBuffer();
160 ASSERT_TRUE(deferred_command_buffer);
161 EXPECT_TRUE(
162 context_base->GetCommandQueue()->Submit({deferred_command_buffer}).ok());
163 EXPECT_TRUE(order.empty());
164
165 worker->SetAllowed(true);
166 auto current_command_buffer = context_base->CreateCommandBuffer();
167 ASSERT_TRUE(current_command_buffer);
168 EXPECT_TRUE(
169 context_base->GetCommandQueue()
170 ->Submit({current_command_buffer},
171 [&](CommandBuffer::Status status) { order.push_back(2); })
172 .ok());
173 EXPECT_THAT(order, ::testing::ElementsAre(1, 2));
174}

References context, impeller::testing::MockGLES::Init(), and reactor.

◆ TEST() [81/689]

impeller::testing::TEST ( CommandBufferGLES  ,
SubmitWithoutCallbackIsAcceptedWithoutCurrentContext   
)

Definition at line 81 of file command_buffer_gles_unittests.cc.

81 {
82 auto mock_gles = MockGLES::Init();
83 auto context = CreateFakeGLESContext();
84 auto context_base = std::static_pointer_cast<Context>(context);
85 auto worker = std::make_shared<ToggleWorker>(false);
86 context->AddReactorWorker(worker);
87
88 auto command_buffer = context_base->CreateCommandBuffer();
89 ASSERT_TRUE(command_buffer);
90
91 EXPECT_TRUE(context_base->GetCommandQueue()->Submit({command_buffer}).ok());
92}

References command_buffer, context, and impeller::testing::MockGLES::Init().

◆ TEST() [82/689]

impeller::testing::TEST ( CommandBufferGLES  ,
SubmitWithoutCurrentContextIsAcceptedAndCompletesAfterReaction   
)

Definition at line 53 of file command_buffer_gles_unittests.cc.

54 {
55 auto mock_gles = MockGLES::Init();
56 auto context = CreateFakeGLESContext();
57 auto context_base = std::static_pointer_cast<Context>(context);
58 auto worker = std::make_shared<ToggleWorker>(false);
59 context->AddReactorWorker(worker);
60
61 auto command_buffer = context_base->CreateCommandBuffer();
62 ASSERT_TRUE(command_buffer);
63
64 bool callback_called = false;
65 CommandBuffer::Status callback_status = CommandBuffer::Status::kError;
66 auto status = context_base->GetCommandQueue()->Submit(
68 callback_called = true;
69 callback_status = status;
70 });
71
72 EXPECT_TRUE(status.ok());
73 EXPECT_FALSE(callback_called);
74
75 worker->SetAllowed(true);
76 EXPECT_TRUE(context->GetReactor()->React());
77 EXPECT_TRUE(callback_called);
78 EXPECT_EQ(callback_status, CommandBuffer::Status::kCompleted);
79}

References command_buffer, context, impeller::testing::MockGLES::Init(), impeller::CommandBuffer::kCompleted, and impeller::CommandBuffer::kError.

◆ TEST() [83/689]

impeller::testing::TEST ( CommandEncoderVKTest  ,
CleanupAfterSubmit   
)

Definition at line 37 of file command_encoder_vk_unittests.cc.

37 {
38 // This tests deleting the TrackedObjects where the thread is killed before
39 // the fence waiter has disposed of them, making sure the command buffer and
40 // its pools are deleted in that order.
41 std::shared_ptr<std::vector<std::string>> called_functions;
42 {
43 fml::AutoResetWaitableEvent wait_for_submit;
44 fml::AutoResetWaitableEvent wait_for_thread_join;
46 std::thread thread([&] {
47 auto buffer = context->CreateCommandBuffer();
48 context->GetCommandQueue()->Submit(
49 {buffer}, [&](CommandBuffer::Status status) {
50 ASSERT_EQ(status, CommandBuffer::Status::kCompleted);
51 wait_for_thread_join.Wait();
52 wait_for_submit.Signal();
53 });
54 });
55 thread.join();
56 wait_for_thread_join.Signal();
57 wait_for_submit.Wait();
58 called_functions = GetMockVulkanFunctions(context->GetDevice());
59 context->Shutdown();
60 }
61
62 auto destroy_pool =
63 std::find(called_functions->begin(), called_functions->end(),
64 "vkDestroyCommandPool");
65 auto free_buffers =
66 std::find(called_functions->begin(), called_functions->end(),
67 "vkFreeCommandBuffers");
68 EXPECT_TRUE(destroy_pool != called_functions->end());
69 EXPECT_TRUE(free_buffers != called_functions->end());
70 EXPECT_TRUE(free_buffers < destroy_pool);
71}

References flutter::buffer, impeller::testing::MockVulkanContextBuilder::Build(), context, GetMockVulkanFunctions(), impeller::CommandBuffer::kCompleted, fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

◆ TEST() [84/689]

impeller::testing::TEST ( CommandEncoderVKTest  ,
DeleteEncoderAfterThreadDies   
)

Definition at line 15 of file command_encoder_vk_unittests.cc.

15 {
16 // Tests that when a CommandEncoderVK is deleted that it will clean up its
17 // command buffers before it cleans up its command pool.
18 std::shared_ptr<std::vector<std::string>> called_functions;
19 {
21 called_functions = GetMockVulkanFunctions(context->GetDevice());
22 std::thread thread([&] { context->CreateCommandBuffer(); });
23 thread.join();
24 context->Shutdown();
25 }
26 auto destroy_pool =
27 std::find(called_functions->begin(), called_functions->end(),
28 "vkDestroyCommandPool");
29 auto free_buffers =
30 std::find(called_functions->begin(), called_functions->end(),
31 "vkFreeCommandBuffers");
32 EXPECT_TRUE(destroy_pool != called_functions->end());
33 EXPECT_TRUE(free_buffers != called_functions->end());
34 EXPECT_TRUE(free_buffers < destroy_pool);
35}

References impeller::testing::MockVulkanContextBuilder::Build(), context, and GetMockVulkanFunctions().

◆ TEST() [85/689]

impeller::testing::TEST ( CommandPoolRecyclerVKTest  ,
CommandBuffersAreRecycled   
)

Definition at line 138 of file command_pool_vk_unittests.cc.

138 {
139 auto const context = MockVulkanContextBuilder().Build();
140
141 {
142 // Fetch a pool (which will be created).
143 auto const recycler = context->GetCommandPoolRecycler();
144 auto pool = recycler->Get();
145
146 auto buffer = pool->CreateCommandBuffer();
147 pool->CollectCommandBuffer(std::move(buffer));
148
149 // This normally is called at the end of a frame.
150 recycler->Dispose();
151 }
152
153 WaitForReclaim(context);
154
155 {
156 // Create a second pool and command buffer, which should reused the existing
157 // pool and cmd buffer.
158 auto const recycler = context->GetCommandPoolRecycler();
159 auto pool = recycler->Get();
160
161 auto buffer = pool->CreateCommandBuffer();
162 pool->CollectCommandBuffer(std::move(buffer));
163
164 // This normally is called at the end of a frame.
165 recycler->Dispose();
166 }
167
168 // Now check that we only ever created one pool and one command buffer.
169 auto const called = ReclaimAndGetMockVulkanFunctions(context);
170 EXPECT_EQ(std::count(called->begin(), called->end(), "vkCreateCommandPool"),
171 1u);
172 EXPECT_EQ(
173 std::count(called->begin(), called->end(), "vkAllocateCommandBuffers"),
174 1u);
175
176 context->Shutdown();
177}

References flutter::buffer, impeller::testing::MockVulkanContextBuilder::Build(), and context.

◆ TEST() [86/689]

impeller::testing::TEST ( CommandPoolRecyclerVKTest  ,
ExtraCommandBufferAllocationsTriggerTrim   
)

Definition at line 179 of file command_pool_vk_unittests.cc.

179 {
180 auto const context = MockVulkanContextBuilder().Build();
181
182 {
183 // Fetch a pool (which will be created).
184 auto const recycler = context->GetCommandPoolRecycler();
185 auto pool = recycler->Get();
186
187 // Allocate a large number of command buffers
188 for (auto i = 0; i < 64; i++) {
189 auto buffer = pool->CreateCommandBuffer();
190 pool->CollectCommandBuffer(std::move(buffer));
191 }
192
193 // This normally is called at the end of a frame.
194 recycler->Dispose();
195 }
196
197 // Command pool is reset but does not release resources.
198 auto called = ReclaimAndGetMockVulkanFunctions(context);
199 EXPECT_EQ(std::count(called->begin(), called->end(), "vkResetCommandPool"),
200 1u);
201
202 // Create the pool a second time, but dont use any command buffers.
203 {
204 // Fetch a pool (which will be created).
205 auto const recycler = context->GetCommandPoolRecycler();
206 auto pool = recycler->Get();
207
208 // This normally is called at the end of a frame.
209 recycler->Dispose();
210 }
211
212 // Verify that the cmd pool was trimmed.
213
214 // Now check that we only ever created one pool and one command buffer.
215 called = ReclaimAndGetMockVulkanFunctions(context);
216 EXPECT_EQ(std::count(called->begin(), called->end(),
217 "vkResetCommandPoolReleaseResources"),
218 1u);
219
220 context->Shutdown();
221}

References flutter::buffer, impeller::testing::MockVulkanContextBuilder::Build(), context, and i.

◆ TEST() [87/689]

impeller::testing::TEST ( CommandPoolRecyclerVKTest  ,
GetsACommandPoolPerThread   
)

Definition at line 15 of file command_pool_vk_unittests.cc.

15 {
16 auto const context = MockVulkanContextBuilder().Build();
17
18 {
19 // Record the memory location of each pointer to a command pool.
20 //
21 // These pools have to be held at this context, otherwise they will be
22 // dropped and recycled and potentially reused by another thread, causing
23 // flaky tests.
24 std::shared_ptr<CommandPoolVK> pool1;
25 std::shared_ptr<CommandPoolVK> pool2;
26
27 // Create a command pool in two threads and record the memory location.
28 std::thread thread1(
29 [&]() { pool1 = context->GetCommandPoolRecycler()->Get(); });
30
31 std::thread thread2(
32 [&]() { pool2 = context->GetCommandPoolRecycler()->Get(); });
33
34 thread1.join();
35 thread2.join();
36
37 // The two command pools should be different.
38 EXPECT_NE(pool1, pool2);
39 }
40
41 context->Shutdown();
42}

References impeller::testing::MockVulkanContextBuilder::Build(), and context.

◆ TEST() [88/689]

impeller::testing::TEST ( CommandPoolRecyclerVKTest  ,
GetsTheSameCommandPoolOnSameThread   
)

Definition at line 44 of file command_pool_vk_unittests.cc.

44 {
45 auto const context = MockVulkanContextBuilder().Build();
46
47 auto const pool1 = context->GetCommandPoolRecycler()->Get();
48 auto const pool2 = context->GetCommandPoolRecycler()->Get();
49
50 // The two command pools should be the same.
51 EXPECT_EQ(pool1.get(), pool2.get());
52
53 context->Shutdown();
54}

References impeller::testing::MockVulkanContextBuilder::Build(), and context.

◆ TEST() [89/689]

impeller::testing::TEST ( CommandPoolRecyclerVKTest  ,
ReclaimMakesCommandPoolAvailable   
)

Definition at line 108 of file command_pool_vk_unittests.cc.

108 {
109 auto const context = MockVulkanContextBuilder().Build();
110
111 {
112 // Fetch a pool (which will be created).
113 auto const recycler = context->GetCommandPoolRecycler();
114 auto const pool = recycler->Get();
115
116 // This normally is called at the end of a frame.
117 recycler->Dispose();
118 }
119
120 WaitForReclaim(context);
121
122 // On another thread explicitly, request a new pool.
123 std::thread thread([&]() {
124 auto const pool = context->GetCommandPoolRecycler()->Get();
125 EXPECT_NE(pool.get(), nullptr);
126 });
127
128 thread.join();
129
130 // Now check that we only ever created one pool.
131 auto const called = ReclaimAndGetMockVulkanFunctions(context);
132 EXPECT_EQ(std::count(called->begin(), called->end(), "vkCreateCommandPool"),
133 1u);
134
135 context->Shutdown();
136}

References impeller::testing::MockVulkanContextBuilder::Build(), and context.

◆ TEST() [90/689]

impeller::testing::TEST ( CommandPoolRecyclerVKTest  ,
RecyclerGlobalPoolMapSize   
)

Definition at line 223 of file command_pool_vk_unittests.cc.

223 {
225 auto const recycler = context->GetCommandPoolRecycler();
226
227 // The global pool list for this context should initially be empty.
228 EXPECT_EQ(CommandPoolRecyclerVK::GetGlobalPoolCount(*context), 0);
229
230 // Creating a pool for this thread should insert the pool into the global map.
231 auto pool = recycler->Get();
232 EXPECT_EQ(CommandPoolRecyclerVK::GetGlobalPoolCount(*context), 1);
233
234 // Disposing this thread's pool should remove it from the global map.
235 pool.reset();
236 recycler->Dispose();
237 EXPECT_EQ(CommandPoolRecyclerVK::GetGlobalPoolCount(*context), 0);
238
239 context->Shutdown();
240}

References impeller::testing::MockVulkanContextBuilder::Build(), context, and impeller::CommandPoolRecyclerVK::GetGlobalPoolCount().

◆ TEST() [91/689]

impeller::testing::TEST ( CommandPoolVKTest  ,
DestroysCleanlyIfDeviceIsDestroyed   
)

Definition at line 255 of file command_pool_vk_unittests.cc.

255 {
256 auto const context = MockVulkanContextBuilder().Build();
257
258 // Create a vk::UniqueCommandPool
259 vk::CommandPoolCreateInfo info;
260 info.setQueueFamilyIndex(context->GetGraphicsQueue()->GetIndex().family);
261 info.setFlags(vk::CommandPoolCreateFlagBits::eTransient);
262
263 auto device = context->GetDevice();
264 auto [result, pool] = device.createCommandPoolUnique(info);
265 ASSERT_EQ(result, vk::Result::eSuccess);
266
267 auto device_holder = std::make_shared<MockDeviceHolder>(device);
268 std::weak_ptr<DeviceHolderVK> weak_device_holder = device_holder;
269
270 auto command_pool = std::make_unique<CommandPoolVK>(
271 std::move(pool), std::vector<vk::UniqueCommandBuffer>{}, context,
272 weak_device_holder);
273
274 // Now, destroy the device holder.
275 device_holder.reset();
276
277 // Now, destroy the command pool. Since the device holder is dead, this should
278 // NOT call vkDestroyCommandPool.
279 command_pool.reset();
280
281 auto const called = ReclaimAndGetMockVulkanFunctions(context);
282 EXPECT_EQ(std::count(called->begin(), called->end(), "vkDestroyCommandPool"),
283 0u);
284
285 context->Shutdown();
286}

References impeller::testing::MockVulkanContextBuilder::Build(), context, and device.

◆ TEST() [92/689]

impeller::testing::TEST ( CommandQueueVKTest  ,
QueueSubmit   
)

Definition at line 16 of file command_queue_vk_unittests.cc.

16 {
17 const auto context = MockVulkanContextBuilder().Build();
18 auto buffer = context->CreateCommandBuffer();
19 auto status = context->GetCommandQueue()->Submit({buffer});
20 EXPECT_TRUE(status.ok());
21
22 const auto called = GetMockVulkanFunctions(context->GetDevice());
23 EXPECT_NE(std::find(called->begin(), called->end(), "vkQueueSubmit"),
24 called->end());
25}

References flutter::buffer, impeller::testing::MockVulkanContextBuilder::Build(), context, and GetMockVulkanFunctions().

◆ TEST() [93/689]

impeller::testing::TEST ( CommandQueueVKTest  ,
SubmitAfterFenceWaiterTerminated   
)

Definition at line 27 of file command_queue_vk_unittests.cc.

27 {
28 const auto context = MockVulkanContextBuilder().Build();
29 auto buffer = context->CreateCommandBuffer();
30 context->GetFenceWaiter()->Terminate();
31 auto status = context->GetCommandQueue()->Submit({buffer});
32 EXPECT_EQ(status.code(), fml::StatusCode::kCancelled);
33
34 // The command buffer should not be submitted to the Vulkan queue if the
35 // fence waiter has been terminated.
36 const auto called = GetMockVulkanFunctions(context->GetDevice());
37 EXPECT_EQ(std::find(called->begin(), called->end(), "vkQueueSubmit"),
38 called->end());
39}

References flutter::buffer, impeller::testing::MockVulkanContextBuilder::Build(), context, GetMockVulkanFunctions(), and fml::kCancelled.

◆ TEST() [94/689]

impeller::testing::TEST ( ConditionVariableTest  ,
TestsCriticalSectionAfterWait   
)

Definition at line 197 of file base_unittests.cc.

197 {
198 std::vector<std::thread> threads;
199 const auto kThreadCount = 10u;
200
201 Mutex mtx;
203 size_t sum = 0u;
204
205 std::condition_variable start_cv;
206 std::mutex start_mtx;
207 bool start = false;
208 auto start_predicate = [&start]() { return start; };
209 auto thread_main = [&]() {
210 {
211 std::unique_lock start_lock(start_mtx);
212 start_cv.wait(start_lock, start_predicate);
213 }
214
215 mtx.Lock();
216 cv.Wait(mtx, []() { return true; });
217 auto old_val = sum;
218 std::this_thread::sleep_for(std::chrono::milliseconds{100u});
219 sum = old_val + 1u;
220 mtx.Unlock();
221 };
222 // Launch all threads. They will wait for the start CV to be signaled.
223 threads.reserve(kThreadCount);
224 for (size_t i = 0; i < kThreadCount; i++) {
225 threads.emplace_back(thread_main);
226 }
227 // Notify all threads that the test may start.
228 {
229 {
230 std::scoped_lock start_lock(start_mtx);
231 start = true;
232 }
233 start_cv.notify_all();
234 }
235 // Join all threads.
236 ASSERT_EQ(threads.size(), kThreadCount);
237 for (size_t i = 0; i < kThreadCount; i++) {
238 threads[i].join();
239 }
240 ASSERT_EQ(sum, kThreadCount);
241}
A condition variable exactly similar to the one in libcxx with two major differences:
Definition thread.h:143
void Wait(Mutex &mutex, const Predicate &should_stop_waiting) IPLR_REQUIRES(mutex)
Atomically unlocks the mutex and waits on the condition variable indefinitely till the predicate dete...
Definition thread.h:257
static constexpr uint64_t kThreadCount

References i, kThreadCount, start, and impeller::ConditionVariable::Wait().

◆ TEST() [95/689]

impeller::testing::TEST ( ConditionVariableTest  ,
TestsCriticalSectionAfterWaitForUntil   
)

Definition at line 151 of file base_unittests.cc.

151 {
152 std::vector<std::thread> threads;
153 const auto kThreadCount = 10u;
154
155 Mutex mtx;
157 size_t sum = 0u;
158
159 std::condition_variable start_cv;
160 std::mutex start_mtx;
161 bool start = false;
162 auto start_predicate = [&start]() { return start; };
163 auto thread_main = [&]() {
164 {
165 std::unique_lock start_lock(start_mtx);
166 start_cv.wait(start_lock, start_predicate);
167 }
168
169 mtx.Lock();
170 cv.WaitFor(mtx, std::chrono::milliseconds{0u}, []() { return true; });
171 auto old_val = sum;
172 std::this_thread::sleep_for(std::chrono::milliseconds{100u});
173 sum = old_val + 1u;
174 mtx.Unlock();
175 };
176 // Launch all threads. They will wait for the start CV to be signaled.
177 threads.reserve(kThreadCount);
178 for (size_t i = 0; i < kThreadCount; i++) {
179 threads.emplace_back(thread_main);
180 }
181 // Notify all threads that the test may start.
182 {
183 {
184 std::scoped_lock start_lock(start_mtx);
185 start = true;
186 }
187 start_cv.notify_all();
188 }
189 // Join all threads.
190 ASSERT_EQ(threads.size(), kThreadCount);
191 for (size_t i = 0; i < kThreadCount; i++) {
192 threads[i].join();
193 }
194 ASSERT_EQ(sum, kThreadCount);
195}
bool WaitFor(Mutex &mutex, const std::chrono::duration< Representation, Period > &duration, const Predicate &should_stop_waiting) IPLR_REQUIRES(mutex)
Atomically unlocks the mutex and waits on the condition variable for a designated duration....
Definition thread.h:228

References i, kThreadCount, start, and impeller::ConditionVariable::WaitFor().

◆ TEST() [96/689]

impeller::testing::TEST ( ConditionVariableTest  ,
WaitFor   
)

Definition at line 113 of file base_unittests.cc.

113 {
114 CVTest test;
115 // test.rando_ivar = 12; // <--- Static analysis error
116 for (size_t i = 0; i < 2; ++i) {
117 test.mutex.Lock(); // <--- Static analysis error without this.
118 auto result = test.cv.WaitFor(
119 test.mutex, std::chrono::milliseconds{10},
120 [&]() IPLR_REQUIRES(test.mutex) {
121 test.rando_ivar = 12; // <-- Static analysics error without the
122 // IPLR_REQUIRES on the pred.
123 return false;
124 });
125 test.mutex.Unlock();
126 ASSERT_FALSE(result);
127 }
128 Lock lock(test.mutex); // <--- Static analysis error without this.
129 // The predicate never returns true. So return has to be due to a non-spurious
130 // wake.
131 ASSERT_EQ(test.rando_ivar, 12u);
132}
#define IPLR_REQUIRES(...)

References impeller::testing::CVTest::cv, i, IPLR_REQUIRES, impeller::testing::CVTest::mutex, and impeller::ConditionVariable::WaitFor().

◆ TEST() [97/689]

impeller::testing::TEST ( ConditionVariableTest  ,
WaitForever   
)

Definition at line 134 of file base_unittests.cc.

134 {
135 CVTest test;
136 // test.rando_ivar = 12; // <--- Static analysis error
137 for (size_t i = 0; i < 2; ++i) {
138 test.mutex.Lock(); // <--- Static analysis error without this.
139 test.cv.Wait(test.mutex, [&]() IPLR_REQUIRES(test.mutex) {
140 test.rando_ivar = 12; // <-- Static analysics error without
141 // the IPLR_REQUIRES on the pred.
142 return true;
143 });
144 test.mutex.Unlock();
145 }
146 Lock lock(test.mutex); // <--- Static analysis error without this.
147 // The wake only happens when the predicate returns true.
148 ASSERT_EQ(test.rando_ivar, 12u);
149}

References impeller::testing::CVTest::cv, i, IPLR_REQUIRES, impeller::testing::CVTest::mutex, and impeller::ConditionVariable::Wait().

◆ TEST() [98/689]

impeller::testing::TEST ( ConditionVariableTest  ,
WaitUntil   
)

Definition at line 90 of file base_unittests.cc.

90 {
91 CVTest test;
92 // test.rando_ivar = 12; // <--- Static analysis error
93 for (size_t i = 0; i < 2; ++i) {
94 test.mutex.Lock(); // <--- Static analysis error without this.
95 auto result = test.cv.WaitUntil(
96 test.mutex,
97 std::chrono::high_resolution_clock::now() +
98 std::chrono::milliseconds{10},
99 [&]() IPLR_REQUIRES(test.mutex) {
100 test.rando_ivar = 12; // <-- Static analysics error without the
101 // IPLR_REQUIRES on the pred.
102 return false;
103 });
104 test.mutex.Unlock();
105 ASSERT_FALSE(result);
106 }
107 Lock lock(test.mutex); // <--- Static analysis error without this.
108 // The predicate never returns true. So return has to be due to a non-spurious
109 // wake.
110 ASSERT_EQ(test.rando_ivar, 12u);
111}
bool WaitUntil(Mutex &mutex, const std::chrono::time_point< Clock, Duration > &time_point, const Predicate &should_stop_waiting) IPLR_REQUIRES(mutex)
Atomically unlocks the mutex and waits on the condition variable up to a specified time point....
Definition thread.h:189

References impeller::testing::CVTest::cv, i, IPLR_REQUIRES, impeller::testing::CVTest::mutex, and impeller::ConditionVariable::WaitUntil().

◆ TEST() [99/689]

impeller::testing::TEST ( ContextVKTest  ,
AHBSwapchainCapabilitiesCanBeMissing   
)

Definition at line 357 of file context_vk_unittests.cc.

357 {
358 {
359 std::shared_ptr<ContextVK> context =
362 settings.enable_surface_control = true;
363 })
364 .Build();
365
366 EXPECT_FALSE(context->GetShouldEnableSurfaceControlSwapchain());
367 }
368
369 ContextVK::EmbedderData data;
370 auto other_context = MockVulkanContextBuilder().Build();
371
372 data.instance = other_context->GetInstance();
373 data.device = other_context->GetDevice();
374 data.physical_device = other_context->GetPhysicalDevice();
375 data.queue = VkQueue{};
376 data.queue_family_index = 0;
377 data.instance_extensions = {"VK_KHR_surface", "VK_KHR_android_surface"};
378 data.device_extensions = {"VK_KHR_swapchain",
379 VK_KHR_EXTERNAL_FENCE_FD_EXTENSION_NAME,
380 VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME,
381 VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME,
382 VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME};
383
384 auto context = MockVulkanContextBuilder()
385 .SetSettingsCallback([](ContextVK::Settings& settings) {
386 settings.enable_surface_control = true;
387 })
388 .SetEmbedderData(data)
389 .Build();
390
391 EXPECT_TRUE(context->GetShouldEnableSurfaceControlSwapchain());
392
393} // namespace impeller
MockVulkanContextBuilder & SetSettingsCallback(const std::function< void(ContextVK::Settings &)> &settings_callback)
Definition mock_vulkan.h:74

References impeller::testing::MockVulkanContextBuilder::Build(), context, flutter::data, impeller::ContextVK::Settings::enable_surface_control, and impeller::testing::MockVulkanContextBuilder::SetSettingsCallback().

◆ TEST() [100/689]

impeller::testing::TEST ( ContextVKTest  ,
BatchSubmitCommandBuffersOnArm   
)

Definition at line 306 of file context_vk_unittests.cc.

306 {
307 std::shared_ptr<ContextVK> context =
310 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
311 prop->vendorID = 0x13B5; // ARM
312 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
313 })
314 .Build();
315
316 EXPECT_TRUE(context->EnqueueCommandBuffer(context->CreateCommandBuffer()));
317 EXPECT_TRUE(context->EnqueueCommandBuffer(context->CreateCommandBuffer()));
318
319 // If command buffers are batch submitted, we should have created them but not
320 // created the fence to track them after enqueing.
321 auto functions = GetMockVulkanFunctions(context->GetDevice());
322 EXPECT_TRUE(std::find(functions->begin(), functions->end(),
323 "vkAllocateCommandBuffers") != functions->end());
324 EXPECT_TRUE(std::find(functions->begin(), functions->end(),
325 "vkCreateFence") == functions->end());
326
327 context->FlushCommandBuffers();
328
329 // After flushing, the fence should be created.
330 functions = GetMockVulkanFunctions(context->GetDevice());
331 EXPECT_TRUE(std::find(functions->begin(), functions->end(),
332 "vkCreateFence") != functions->end());
333}

References context, device, GetMockVulkanFunctions(), and impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback().

◆ TEST() [101/689]

impeller::testing::TEST ( ContextVKTest  ,
BatchSubmitCommandBuffersOnNonArm   
)

Definition at line 335 of file context_vk_unittests.cc.

335 {
336 std::shared_ptr<ContextVK> context =
339 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
340 prop->vendorID = 0x8686; // Made up ID
341 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
342 })
343 .Build();
344
345 EXPECT_TRUE(context->EnqueueCommandBuffer(context->CreateCommandBuffer()));
346 EXPECT_TRUE(context->EnqueueCommandBuffer(context->CreateCommandBuffer()));
347
348 // If command buffers are batched and not submitted, we should have created
349 // them and a corresponding fence immediately.
350 auto functions = GetMockVulkanFunctions(context->GetDevice());
351 EXPECT_TRUE(std::find(functions->begin(), functions->end(),
352 "vkAllocateCommandBuffers") != functions->end());
353 EXPECT_FALSE(std::find(functions->begin(), functions->end(),
354 "vkCreateFence") != functions->end());
355}

References context, device, GetMockVulkanFunctions(), and impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback().

◆ TEST() [102/689]

impeller::testing::TEST ( ContextVKTest  ,
CanCreateContextInAbsenceOfValidationLayers   
)

Definition at line 152 of file context_vk_unittests.cc.

152 {
153 // The mocked methods don't report the presence of a validation layer but we
154 // explicitly ask for validation. Context creation should continue anyway.
156 .SetSettingsCallback([](auto& settings) {
157 settings.enable_validation = true;
158 })
159 .Build();
160 ASSERT_NE(context, nullptr);
161 const CapabilitiesVK* capabilites_vk =
162 reinterpret_cast<const CapabilitiesVK*>(context->GetCapabilities().get());
163 ASSERT_FALSE(capabilites_vk->AreValidationsEnabled());
164}
The Vulkan layers and extensions wrangler.

References impeller::CapabilitiesVK::AreValidationsEnabled(), context, and impeller::testing::MockVulkanContextBuilder::SetSettingsCallback().

◆ TEST() [103/689]

impeller::testing::TEST ( ContextVKTest  ,
CanCreateContextWithValidationLayers   
)

Definition at line 166 of file context_vk_unittests.cc.

166 {
167 auto context =
170 [](auto& settings) { settings.enable_validation = true; })
171 .SetInstanceExtensions(
172 {"VK_KHR_surface", "VK_MVK_macos_surface", "VK_EXT_debug_utils"})
173 .SetInstanceLayers({"VK_LAYER_KHRONOS_validation"})
174 .Build();
175 ASSERT_NE(context, nullptr);
176 const CapabilitiesVK* capabilites_vk =
177 reinterpret_cast<const CapabilitiesVK*>(context->GetCapabilities().get());
178 ASSERT_TRUE(capabilites_vk->AreValidationsEnabled());
179}

References impeller::CapabilitiesVK::AreValidationsEnabled(), context, and impeller::testing::MockVulkanContextBuilder::SetSettingsCallback().

◆ TEST() [104/689]

impeller::testing::TEST ( ContextVKTest  ,
CommonHardwareConcurrencyConfigurations   
)

Definition at line 17 of file context_vk_unittests.cc.

17 {
18 EXPECT_EQ(ContextVK::ChooseThreadCountForWorkers(100u), 4u);
19 EXPECT_EQ(ContextVK::ChooseThreadCountForWorkers(9u), 4u);
20 EXPECT_EQ(ContextVK::ChooseThreadCountForWorkers(8u), 4u);
21 EXPECT_EQ(ContextVK::ChooseThreadCountForWorkers(7u), 3u);
22 EXPECT_EQ(ContextVK::ChooseThreadCountForWorkers(6u), 3u);
23 EXPECT_EQ(ContextVK::ChooseThreadCountForWorkers(5u), 2u);
24 EXPECT_EQ(ContextVK::ChooseThreadCountForWorkers(4u), 2u);
25 EXPECT_EQ(ContextVK::ChooseThreadCountForWorkers(3u), 1u);
26 EXPECT_EQ(ContextVK::ChooseThreadCountForWorkers(2u), 1u);
27 EXPECT_EQ(ContextVK::ChooseThreadCountForWorkers(1u), 1u);
28}

References impeller::ContextVK::ChooseThreadCountForWorkers().

◆ TEST() [105/689]

impeller::testing::TEST ( ContextVKTest  ,
DeletePipelineAfterContext   
)

Definition at line 95 of file context_vk_unittests.cc.

95 {
96 std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
97 std::shared_ptr<std::vector<std::string>> functions;
98 {
99 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
100 PipelineDescriptor pipeline_desc;
101 pipeline_desc.SetVertexDescriptor(std::make_shared<VertexDescriptor>());
102 PipelineFuture<PipelineDescriptor> pipeline_future =
103 context->GetPipelineLibrary()->GetPipeline(pipeline_desc);
104 pipeline = pipeline_future.Get();
105 ASSERT_TRUE(pipeline);
106 functions = GetMockVulkanFunctions(context->GetDevice());
107 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
108 "vkCreateGraphicsPipelines") != functions->end());
109 }
110 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
111 "vkDestroyDevice") != functions->end());
112}
PipelineDescriptor & SetVertexDescriptor(std::shared_ptr< VertexDescriptor > vertex_descriptor)
const std::shared_ptr< Pipeline< T > > Get() const
Definition pipeline.h:33

References impeller::testing::MockVulkanContextBuilder::Build(), context, impeller::PipelineFuture< T >::Get(), GetMockVulkanFunctions(), pipeline, and impeller::PipelineDescriptor::SetVertexDescriptor().

◆ TEST() [106/689]

impeller::testing::TEST ( ContextVKTest  ,
DeletePipelineLibraryAfterContext   
)

Definition at line 136 of file context_vk_unittests.cc.

136 {
137 std::shared_ptr<PipelineLibrary> pipeline_library;
138 std::shared_ptr<std::vector<std::string>> functions;
139 {
140 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
141 PipelineDescriptor pipeline_desc;
142 pipeline_desc.SetVertexDescriptor(std::make_shared<VertexDescriptor>());
143 pipeline_library = context->GetPipelineLibrary();
144 functions = GetMockVulkanFunctions(context->GetDevice());
145 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
146 "vkCreatePipelineCache") != functions->end());
147 }
148 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
149 "vkDestroyDevice") != functions->end());
150}

References impeller::testing::MockVulkanContextBuilder::Build(), context, GetMockVulkanFunctions(), and impeller::PipelineDescriptor::SetVertexDescriptor().

◆ TEST() [107/689]

impeller::testing::TEST ( ContextVKTest  ,
DeletesCommandPools   
)

Definition at line 30 of file context_vk_unittests.cc.

30 {
31 std::weak_ptr<ContextVK> weak_context;
32 std::weak_ptr<CommandPoolVK> weak_pool;
33 {
34 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
35 auto const pool = context->GetCommandPoolRecycler()->Get();
36 weak_pool = pool;
37 weak_context = context;
38 ASSERT_TRUE(weak_pool.lock());
39 ASSERT_TRUE(weak_context.lock());
40 }
41 ASSERT_FALSE(weak_pool.lock());
42 ASSERT_FALSE(weak_context.lock());
43}

References impeller::testing::MockVulkanContextBuilder::Build(), and context.

◆ TEST() [108/689]

impeller::testing::TEST ( ContextVKTest  ,
DeletesCommandPoolsOnAllThreads   
)

Definition at line 45 of file context_vk_unittests.cc.

45 {
46 std::weak_ptr<ContextVK> weak_context;
47 std::weak_ptr<CommandPoolVK> weak_pool_main;
48
49 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
50 weak_pool_main = context->GetCommandPoolRecycler()->Get();
51 weak_context = context;
52 ASSERT_TRUE(weak_pool_main.lock());
53 ASSERT_TRUE(weak_context.lock());
54
55 // Start a second thread that obtains a command pool.
56 fml::AutoResetWaitableEvent latch1, latch2;
57 std::weak_ptr<CommandPoolVK> weak_pool_thread;
58 std::thread thread([&]() {
59 weak_pool_thread = context->GetCommandPoolRecycler()->Get();
60 latch1.Signal();
61 latch2.Wait();
62 });
63
64 // Delete the ContextVK on the main thread.
65 latch1.Wait();
66 context.reset();
67 ASSERT_FALSE(weak_pool_main.lock());
68 ASSERT_FALSE(weak_context.lock());
69
70 // Stop the second thread and check that its command pool has been deleted.
71 latch2.Signal();
72 thread.join();
73 ASSERT_FALSE(weak_pool_thread.lock());
74}

References impeller::testing::MockVulkanContextBuilder::Build(), context, fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

◆ TEST() [109/689]

impeller::testing::TEST ( ContextVKTest  ,
DeleteShaderFunctionAfterContext   
)

Definition at line 114 of file context_vk_unittests.cc.

114 {
115 std::shared_ptr<const ShaderFunction> shader_function;
116 std::shared_ptr<std::vector<std::string>> functions;
117 {
118 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
119 PipelineDescriptor pipeline_desc;
120 pipeline_desc.SetVertexDescriptor(std::make_shared<VertexDescriptor>());
121 std::vector<uint8_t> data = {0x03, 0x02, 0x23, 0x07};
122 context->GetShaderLibrary()->RegisterFunction(
123 "foobar_fragment_main", ShaderStage::kFragment,
124 std::make_shared<fml::DataMapping>(data), [](bool) {});
125 shader_function = context->GetShaderLibrary()->GetFunction(
126 "foobar_fragment_main", ShaderStage::kFragment);
127 ASSERT_TRUE(shader_function);
128 functions = GetMockVulkanFunctions(context->GetDevice());
129 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
130 "vkCreateShaderModule") != functions->end());
131 }
132 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
133 "vkDestroyDevice") != functions->end());
134}

References impeller::testing::MockVulkanContextBuilder::Build(), context, flutter::data, GetMockVulkanFunctions(), impeller::kFragment, and impeller::PipelineDescriptor::SetVertexDescriptor().

◆ TEST() [110/689]

impeller::testing::TEST ( ContextVKTest  ,
EmbedderOverrides   
)

Definition at line 283 of file context_vk_unittests.cc.

283 {
285 auto other_context = MockVulkanContextBuilder().Build();
286
287 data.instance = other_context->GetInstance();
288 data.device = other_context->GetDevice();
289 data.physical_device = other_context->GetPhysicalDevice();
290 data.queue = VkQueue{};
291 data.queue_family_index = 0;
292 data.instance_extensions = {"VK_KHR_surface",
293 "VK_KHR_portability_enumeration"};
294 data.device_extensions = {"VK_KHR_swapchain"};
295
296 auto context = MockVulkanContextBuilder().SetEmbedderData(data).Build();
297
298 EXPECT_TRUE(context->IsValid());
299 EXPECT_EQ(context->GetInstance(), other_context->GetInstance());
300 EXPECT_EQ(context->GetDevice(), other_context->GetDevice());
301 EXPECT_EQ(context->GetPhysicalDevice(), other_context->GetPhysicalDevice());
302 EXPECT_EQ(context->GetGraphicsQueue()->GetIndex().index, 0u);
303 EXPECT_EQ(context->GetGraphicsQueue()->GetIndex().family, 0u);
304}

References impeller::testing::MockVulkanContextBuilder::Build(), context, flutter::data, and impeller::testing::MockVulkanContextBuilder::SetEmbedderData().

◆ TEST() [111/689]

impeller::testing::TEST ( ContextVKTest  ,
EmbedderOverridesUsesInstanceExtensions   
)

Definition at line 264 of file context_vk_unittests.cc.

264 {
266 auto other_context = MockVulkanContextBuilder().Build();
267
268 data.instance = other_context->GetInstance();
269 data.device = other_context->GetDevice();
270 data.physical_device = other_context->GetPhysicalDevice();
271 data.queue = VkQueue{};
272 data.queue_family_index = 0;
273 // Missing surface extension.
274 data.instance_extensions = {};
275 data.device_extensions = {"VK_KHR_swapchain"};
276
277 ScopedValidationDisable scoped;
278 auto context = MockVulkanContextBuilder().SetEmbedderData(data).Build();
279
280 EXPECT_EQ(context, nullptr);
281}

References impeller::testing::MockVulkanContextBuilder::Build(), context, flutter::data, and impeller::testing::MockVulkanContextBuilder::SetEmbedderData().

◆ TEST() [112/689]

impeller::testing::TEST ( ContextVKTest  ,
FatalMissingValidations   
)

Definition at line 245 of file context_vk_unittests.cc.

245 {
246 EXPECT_DEATH(const std::shared_ptr<ContextVK> context =
248 .SetSettingsCallback([](ContextVK::Settings& settings) {
249 settings.enable_validation = true;
250 settings.fatal_missing_validations = true;
251 })
252 .Build(),
253 "");
254}
bool fatal_missing_validations
If validations are requested but cannot be enabled, log a fatal error.
Definition context_vk.h:91

References context, impeller::ContextVK::Settings::enable_validation, and impeller::ContextVK::Settings::fatal_missing_validations.

◆ TEST() [113/689]

impeller::testing::TEST ( ContextVKTest  ,
HasDefaultColorFormat   
)

Definition at line 256 of file context_vk_unittests.cc.

256 {
257 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
258
259 const CapabilitiesVK* capabilites_vk =
260 reinterpret_cast<const CapabilitiesVK*>(context->GetCapabilities().get());
261 ASSERT_NE(capabilites_vk->GetDefaultColorFormat(), PixelFormat::kUnknown);
262}
PixelFormat GetDefaultColorFormat() const override
Returns a supported PixelFormat for textures that store 4-channel colors (red/green/blue/alpha).

References impeller::testing::MockVulkanContextBuilder::Build(), context, impeller::CapabilitiesVK::GetDefaultColorFormat(), and impeller::kUnknown.

◆ TEST() [114/689]

impeller::testing::TEST ( ContextVKTest  ,
HashIsUniqueAcrossThreads   
)

Definition at line 395 of file context_vk_unittests.cc.

395 {
396 uint64_t hash1, hash2;
397 std::thread thread1([&]() {
399 hash1 = context->GetHash();
400 });
401 std::thread thread2([&]() {
402 auto context = MockVulkanContextBuilder().Build();
403 hash2 = context->GetHash();
404 });
405 thread1.join();
406 thread2.join();
407
408 EXPECT_NE(hash1, hash2);
409}

References impeller::testing::MockVulkanContextBuilder::Build(), and context.

◆ TEST() [115/689]

impeller::testing::TEST ( ContextVKTest  ,
ThreadLocalCleanupDeletesCommandPool   
)

Definition at line 76 of file context_vk_unittests.cc.

76 {
77 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
78
79 fml::AutoResetWaitableEvent latch1, latch2;
80 std::weak_ptr<CommandPoolVK> weak_pool;
81 std::thread thread([&]() {
82 weak_pool = context->GetCommandPoolRecycler()->Get();
83 context->DisposeThreadLocalCachedResources();
84 latch1.Signal();
85 latch2.Wait();
86 });
87
88 latch1.Wait();
89 ASSERT_FALSE(weak_pool.lock());
90
91 latch2.Signal();
92 thread.join();
93}

References impeller::testing::MockVulkanContextBuilder::Build(), context, fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

◆ TEST() [116/689]

impeller::testing::TEST ( ContextVKTest  ,
WarmUpFunctionCreatesRenderPass   
)

Definition at line 234 of file context_vk_unittests.cc.

234 {
235 const std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
236
237 context->SetOffscreenFormat(PixelFormat::kR8G8B8A8UNormInt);
238 context->InitializeCommonlyUsedShadersIfNeeded();
239
240 auto functions = GetMockVulkanFunctions(context->GetDevice());
241 ASSERT_TRUE(std::find(functions->begin(), functions->end(),
242 "vkCreateRenderPass") != functions->end());
243}

References impeller::testing::MockVulkanContextBuilder::Build(), context, GetMockVulkanFunctions(), and impeller::kR8G8B8A8UNormInt.

◆ TEST() [117/689]

impeller::testing::TEST ( DescriptorPoolRecyclerVKTest  ,
DescriptorsAreRecycled   
)

Definition at line 110 of file descriptor_pool_vk_unittests.cc.

110 {
111 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
112
113 {
115 pool.AllocateDescriptorSets({}, /*pipeline_key=*/0, *context);
116 }
117
118 // Should reuse the same descriptor set allocated above.
119 std::shared_ptr<DescriptorPoolVK> pool =
120 context->GetDescriptorPoolRecycler()->GetDescriptorPool();
121 pool->AllocateDescriptorSets({}, /*pipeline_key=*/0, *context);
122
123 std::shared_ptr<std::vector<std::string>> called =
124 GetMockVulkanFunctions(context->GetDevice());
125 EXPECT_EQ(
126 std::count(called->begin(), called->end(), "vkAllocateDescriptorSets"),
127 1);
128
129 // Should allocate a new descriptor set.
130 pool->AllocateDescriptorSets({}, /*pipeline_key=*/0, *context);
131 EXPECT_EQ(
132 std::count(called->begin(), called->end(), "vkAllocateDescriptorSets"),
133 2);
134}
A per-frame descriptor pool. Descriptors from this pool don't need to be freed individually....
fml::StatusOr< vk::DescriptorSet > AllocateDescriptorSets(const vk::DescriptorSetLayout &layout, PipelineKey pipeline_key, const ContextVK &context_vk)

References impeller::DescriptorPoolVK::AllocateDescriptorSets(), impeller::testing::MockVulkanContextBuilder::Build(), context, and GetMockVulkanFunctions().

◆ TEST() [118/689]

impeller::testing::TEST ( DescriptorPoolRecyclerVKTest  ,
GetDescriptorPoolRecyclerCreatesNewPools   
)

Definition at line 13 of file descriptor_pool_vk_unittests.cc.

13 {
14 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
15
16 vk::UniqueDescriptorPool pool1 = context->GetDescriptorPoolRecycler()->Get();
17 vk::UniqueDescriptorPool pool2 = context->GetDescriptorPoolRecycler()->Get();
18
19 // The two descriptor pools should be different.
20 EXPECT_NE(pool1.get(), pool2.get());
21
22 context->Shutdown();
23}

References impeller::testing::MockVulkanContextBuilder::Build(), and context.

◆ TEST() [119/689]

impeller::testing::TEST ( DescriptorPoolRecyclerVKTest  ,
MultipleCommandBuffersShareDescriptorPool   
)

Definition at line 88 of file descriptor_pool_vk_unittests.cc.

88 {
89 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
90
91 std::shared_ptr<CommandBuffer> cmd_buffer_1 = context->CreateCommandBuffer();
92 std::shared_ptr<CommandBuffer> cmd_buffer_2 = context->CreateCommandBuffer();
93
94 CommandBufferVK& vk_1 = CommandBufferVK::Cast(*cmd_buffer_1);
95 CommandBufferVK& vk_2 = CommandBufferVK::Cast(*cmd_buffer_2);
96
97 EXPECT_EQ(&vk_1.GetDescriptorPool(), &vk_2.GetDescriptorPool());
98
99 // Resetting resources creates a new pool.
100 context->DisposeThreadLocalCachedResources();
101
102 std::shared_ptr<CommandBuffer> cmd_buffer_3 = context->CreateCommandBuffer();
103 CommandBufferVK& vk_3 = CommandBufferVK::Cast(*cmd_buffer_3);
104
105 EXPECT_NE(&vk_1.GetDescriptorPool(), &vk_3.GetDescriptorPool());
106
107 context->Shutdown();
108}
DescriptorPoolVK & GetDescriptorPool() const

References impeller::testing::MockVulkanContextBuilder::Build(), impeller::BackendCast< CommandBufferVK, CommandBuffer >::Cast(), context, and impeller::CommandBufferVK::GetDescriptorPool().

◆ TEST() [120/689]

impeller::testing::TEST ( DescriptorPoolRecyclerVKTest  ,
ReclaimDropsDescriptorPoolIfSizeIsExceeded   
)

Definition at line 46 of file descriptor_pool_vk_unittests.cc.

46 {
47 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
48
49 // Create 33 pools
50 {
51 std::vector<std::unique_ptr<DescriptorPoolVK>> pools;
52 for (size_t i = 0u; i < 33; i++) {
53 std::unique_ptr<DescriptorPoolVK> pool =
54 std::make_unique<DescriptorPoolVK>(context);
55 pool->AllocateDescriptorSets({}, /*pipeline_key=*/0, *context);
56 pools.push_back(std::move(pool));
57 }
58 }
59
60 std::shared_ptr<std::vector<std::string>> called =
61 GetMockVulkanFunctions(context->GetDevice());
62 EXPECT_EQ(
63 std::count(called->begin(), called->end(), "vkCreateDescriptorPool"),
64 33u);
65
66 // Now create 33 more descriptor pools and observe that only one more is
67 // allocated.
68 {
69 std::vector<std::shared_ptr<DescriptorPoolVK>> pools;
70 for (size_t i = 0u; i < 33; i++) {
71 std::shared_ptr<DescriptorPoolVK> pool =
72 context->GetDescriptorPoolRecycler()->GetDescriptorPool();
73 pool->AllocateDescriptorSets({}, /*pipeline_key=*/0, *context);
74 pools.push_back(std::move(pool));
75 }
76 }
77
78 std::shared_ptr<std::vector<std::string>> called_twice =
79 GetMockVulkanFunctions(context->GetDevice());
80 // 32 of the descriptor pools were recycled, so only one more is created.
81 EXPECT_EQ(
82 std::count(called->begin(), called->end(), "vkCreateDescriptorPool"),
83 34u);
84
85 context->Shutdown();
86}

References impeller::testing::MockVulkanContextBuilder::Build(), context, GetMockVulkanFunctions(), and i.

◆ TEST() [121/689]

impeller::testing::TEST ( DescriptorPoolRecyclerVKTest  ,
ReclaimMakesDescriptorPoolAvailable   
)

Definition at line 25 of file descriptor_pool_vk_unittests.cc.

25 {
26 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
27
28 {
29 // Fetch a pool (which will be created).
31 pool.AllocateDescriptorSets({}, /*pipeline_key=*/0, *context);
32 }
33
34 std::shared_ptr<DescriptorPoolVK> pool =
35 context->GetDescriptorPoolRecycler()->GetDescriptorPool();
36
37 // Now check that we only ever created one pool.
38 std::shared_ptr<std::vector<std::string>> called =
39 GetMockVulkanFunctions(context->GetDevice());
40 EXPECT_EQ(
41 std::count(called->begin(), called->end(), "vkCreateDescriptorPool"), 1u);
42
43 context->Shutdown();
44}

References impeller::DescriptorPoolVK::AllocateDescriptorSets(), impeller::testing::MockVulkanContextBuilder::Build(), context, and GetMockVulkanFunctions().

◆ TEST() [122/689]

impeller::testing::TEST ( DeviceBufferGLESTest  ,
BindUniformData   
)

Definition at line 68 of file device_buffer_gles_unittests.cc.

68 {
69 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
70
71 EXPECT_CALL(*mock_gles_impl, GenBuffers(1, _)).Times(1);
72
73 std::shared_ptr<MockGLES> mock_gled =
74 MockGLES::Init(std::move(mock_gles_impl));
76 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
77 auto worker = std::make_shared<TestWorker>();
78 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
79 reactor->AddWorker(worker);
80
81 auto backing_store = std::make_unique<Allocation>();
82 ASSERT_TRUE(backing_store->Truncate(Bytes{sizeof(float)}));
83 DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = sizeof(float)},
84 reactor, std::move(backing_store));
85 EXPECT_FALSE(device_buffer.GetHandle().has_value());
86 EXPECT_TRUE(device_buffer.BindAndUploadDataIfNecessary(
87 DeviceBufferGLES::BindingType::kUniformBuffer));
88 EXPECT_TRUE(device_buffer.GetHandle().has_value());
89}
std::function< void *(const char *function_name)> Resolver
const ProcTableGLES::Resolver kMockResolverGLES
Definition mock_gles.cc:459

References impeller::testing::MockGLES::Init(), kMockResolverGLES, impeller::DeviceBufferGLES::kUniformBuffer, reactor, and impeller::DeviceBufferDescriptor::size.

◆ TEST() [123/689]

impeller::testing::TEST ( DeviceBufferGLESTest  ,
FlushDuringUploadIsNotDiscarded   
)

Definition at line 28 of file device_buffer_gles_unittests.cc.

28 {
29 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
30
31 DeviceBufferGLES* device_buffer_ptr = nullptr;
32 int upload_count = 0;
33 EXPECT_CALL(*mock_gles_impl, BufferSubData(_, _, _, _))
34 .Times(2)
35 .WillRepeatedly([&](GLenum target, GLintptr offset, GLsizeiptr size,
36 const void* data) {
37 ++upload_count;
38 if (upload_count == 1) {
39 // Simulates a writer thread flushing new data during the upload.
40 device_buffer_ptr->Flush(Range{0, 4});
41 }
42 });
43
44 std::shared_ptr<MockGLES> mock_gles =
45 MockGLES::Init(std::move(mock_gles_impl));
46 ProcTableGLES::Resolver resolver = kMockResolverGLES;
47 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
48 auto worker = std::make_shared<TestWorker>();
49 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
50 reactor->AddWorker(worker);
51
52 auto backing_store = std::make_unique<Allocation>();
53 ASSERT_TRUE(backing_store->Truncate(Bytes{16}));
54 DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = 16}, reactor,
55 std::move(backing_store));
56 device_buffer_ptr = &device_buffer;
57
58 device_buffer.Flush(Range{0, 4});
59 // First bind uploads the flushed range; the mock flushes again mid-upload.
60 EXPECT_TRUE(device_buffer.BindAndUploadDataIfNecessary(
61 DeviceBufferGLES::BindingType::kArrayBuffer));
62 // Second bind must see the mid-upload flush and upload again.
63 EXPECT_TRUE(device_buffer.BindAndUploadDataIfNecessary(
64 DeviceBufferGLES::BindingType::kArrayBuffer));
65 EXPECT_EQ(upload_count, 2);
66}
void Flush(std::optional< Range > range=std::nullopt) const override

References flutter::data, impeller::DeviceBufferGLES::Flush(), impeller::testing::MockGLES::Init(), impeller::DeviceBufferGLES::kArrayBuffer, kMockResolverGLES, reactor, impeller::DeviceBufferDescriptor::size, flutter::size, and target.

◆ TEST() [124/689]

impeller::testing::TEST ( DrawOrderResolverTest  ,
GetSortedDrawsRespectsSkipCounts   
)

Definition at line 89 of file draw_order_resolver_unittests.cc.

89 {
90 DrawOrderResolver resolver;
91
92 // These items will be skipped.
93 resolver.AddElement(0, false);
94 resolver.AddElement(1, true);
95 resolver.AddElement(2, false);
96 // These ones will be included in the final draw list.
97 resolver.AddElement(3, false);
98 resolver.AddElement(4, true);
99 resolver.AddElement(5, true);
100
101 // Form the draw list, skipping elements 0, 1, and 2.
102 // This emulates what happens when entitypass applies the clear color
103 // optimization.
104 auto sorted_elements = resolver.GetSortedDraws(1, 2);
105
106 EXPECT_EQ(sorted_elements.size(), 3u);
107 // First, opaque items are drawn in reverse order.
108 EXPECT_EQ(sorted_elements[0], 5u);
109 EXPECT_EQ(sorted_elements[1], 4u);
110 // Then, translucent items are drawn.
111 EXPECT_EQ(sorted_elements[2], 3u);
112}
ElementRefs GetSortedDraws(size_t opaque_skip_count, size_t translucent_skip_count) const
Returns the sorted draws for the current draw order layer. This should only be called after all recor...
void AddElement(size_t element_index, bool is_opaque)

References impeller::DrawOrderResolver::AddElement(), and impeller::DrawOrderResolver::GetSortedDraws().

◆ TEST() [125/689]

impeller::testing::TEST ( DrawOrderResolverTest  ,
GetSortedDrawsReturnsCorrectOrderWithClips   
)

Definition at line 33 of file draw_order_resolver_unittests.cc.

33 {
34 DrawOrderResolver resolver;
35
36 // Items before clip.
37 resolver.AddElement(0, false);
38 resolver.AddElement(1, true);
39 resolver.AddElement(2, false);
40 resolver.AddElement(3, true);
41
42 // Clip.
43 resolver.PushClip(4);
44 {
45 // Clipped items.
46 resolver.AddElement(5, false);
47 resolver.AddElement(6, false);
48 // Clipped translucent items.
49 resolver.AddElement(7, true);
50 resolver.AddElement(8, true);
51 }
52 resolver.PopClip();
53
54 // Items after clip.
55 resolver.AddElement(9, true);
56 resolver.AddElement(10, false);
57 resolver.AddElement(11, true);
58 resolver.AddElement(12, false);
59
60 auto sorted_elements = resolver.GetSortedDraws(0, 0);
61
62 EXPECT_EQ(sorted_elements.size(), 13u);
63 // First, all the non-clipped opaque items are drawn in reverse order.
64 EXPECT_EQ(sorted_elements[0], 11u);
65 EXPECT_EQ(sorted_elements[1], 9u);
66 EXPECT_EQ(sorted_elements[2], 3u);
67 EXPECT_EQ(sorted_elements[3], 1u);
68 // Then, non-clipped translucent items that came before the clip are drawn in
69 // their original order.
70 EXPECT_EQ(sorted_elements[4], 0u);
71 EXPECT_EQ(sorted_elements[5], 2u);
72
73 // Then, the clip and its sorted child items are drawn.
74 EXPECT_EQ(sorted_elements[6], 4u);
75 {
76 // Opaque clipped items are drawn in reverse order.
77 EXPECT_EQ(sorted_elements[7], 8u);
78 EXPECT_EQ(sorted_elements[8], 7u);
79 // Translucent clipped items are drawn.
80 EXPECT_EQ(sorted_elements[9], 5u);
81 EXPECT_EQ(sorted_elements[10], 6u);
82 }
83 // Finally, the non-clipped translucent items which came after the clip are
84 // drawn in their original order.
85 EXPECT_EQ(sorted_elements[11], 10u);
86 EXPECT_EQ(sorted_elements[12], 12u);
87}
void PushClip(size_t element_index)

References impeller::DrawOrderResolver::AddElement(), impeller::DrawOrderResolver::GetSortedDraws(), impeller::DrawOrderResolver::PopClip(), and impeller::DrawOrderResolver::PushClip().

◆ TEST() [126/689]

impeller::testing::TEST ( DrawOrderResolverTest  ,
GetSortedDrawsReturnsCorrectOrderWithFlush   
)

Definition at line 114 of file draw_order_resolver_unittests.cc.

114 {
115 DrawOrderResolver resolver;
116
117 resolver.AddElement(0, false);
118 resolver.AddElement(1, true);
119 resolver.AddElement(2, false);
120 resolver.AddElement(3, true);
121
122 resolver.Flush();
123
124 resolver.AddElement(4, false);
125 resolver.AddElement(5, true);
126 resolver.AddElement(6, false);
127 resolver.AddElement(7, true);
128
129 resolver.Flush();
130
131 resolver.AddElement(8, false);
132 resolver.AddElement(9, true);
133 resolver.AddElement(10, false);
134 resolver.AddElement(11, true);
135
136 auto sorted_elements = resolver.GetSortedDraws(1, 1);
137
138 EXPECT_EQ(sorted_elements.size(), 10u);
139
140 // Skipped draws apply to the first flush.
141 EXPECT_EQ(sorted_elements[0], 3u);
142 EXPECT_EQ(sorted_elements[1], 2u);
143
144 EXPECT_EQ(sorted_elements[2], 7u);
145 EXPECT_EQ(sorted_elements[3], 5u);
146 EXPECT_EQ(sorted_elements[4], 4u);
147 EXPECT_EQ(sorted_elements[5], 6u);
148
149 EXPECT_EQ(sorted_elements[6], 11u);
150 EXPECT_EQ(sorted_elements[7], 9u);
151 EXPECT_EQ(sorted_elements[8], 8u);
152 EXPECT_EQ(sorted_elements[9], 10u);
153}

References impeller::DrawOrderResolver::AddElement(), impeller::DrawOrderResolver::Flush(), and impeller::DrawOrderResolver::GetSortedDraws().

◆ TEST() [127/689]

impeller::testing::TEST ( DrawOrderResolverTest  ,
GetSortedDrawsReturnsCorrectOrderWithNoClips   
)

Definition at line 12 of file draw_order_resolver_unittests.cc.

12 {
13 DrawOrderResolver resolver;
14
15 // Opaque items.
16 resolver.AddElement(0, true);
17 resolver.AddElement(1, true);
18 // Translucent items.
19 resolver.AddElement(2, false);
20 resolver.AddElement(3, false);
21
22 auto sorted_elements = resolver.GetSortedDraws(0, 0);
23
24 EXPECT_EQ(sorted_elements.size(), 4u);
25 // First, the opaque items are drawn in reverse order.
26 EXPECT_EQ(sorted_elements[0], 1u);
27 EXPECT_EQ(sorted_elements[1], 0u);
28 // Then the translucent items are drawn.
29 EXPECT_EQ(sorted_elements[2], 2u);
30 EXPECT_EQ(sorted_elements[3], 3u);
31}

References impeller::DrawOrderResolver::AddElement(), and impeller::DrawOrderResolver::GetSortedDraws().

◆ TEST() [128/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
CanBatchSubmitCommandBuffers   
)

Definition at line 90 of file driver_info_vk_unittests.cc.

90 {
91 // Old Adreno no batch submit!
92 EXPECT_FALSE(CanBatchSubmitTest("Adreno (TM) 540", true));
93
94 EXPECT_TRUE(CanBatchSubmitTest("Mali-G51", false));
95 EXPECT_TRUE(CanBatchSubmitTest("Adreno (TM) 750", true));
96}
bool CanBatchSubmitTest(std::string_view driver_name, bool qc=true)

References CanBatchSubmitTest().

◆ TEST() [129/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
CanGenerateMipMaps   
)

Definition at line 146 of file driver_info_vk_unittests.cc.

146 {
147 // Adreno no mips
148 EXPECT_FALSE(CanUseMipgeneration("Adreno (TM) 540", true));
149 EXPECT_FALSE(CanUseMipgeneration("Adreno (TM) 750", true));
150
151 // Mali A-OK
152 EXPECT_TRUE(CanUseMipgeneration("Mali-G51", false));
153}
bool CanUseMipgeneration(std::string_view driver_name, bool qc=true)

References CanUseMipgeneration().

◆ TEST() [130/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
CanIdentifyBadMaleoonDriver   
)

Definition at line 40 of file driver_info_vk_unittests.cc.

40 {
41 auto const context =
44 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
45 prop->vendorID = 0x19E5; // Huawei
46 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
47 })
48 .Build();
49
50 EXPECT_TRUE(context->GetDriverInfo()->IsKnownBadDriver());
51}

References context, device, and impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback().

◆ TEST() [131/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
CanUseFramebufferFetch   
)

Definition at line 216 of file driver_info_vk_unittests.cc.

216 {
217 // Adreno no primitive restart on models as or older than 630.
218 EXPECT_FALSE(CanUseFramebufferFetch("Adreno (TM) 540", true));
219 EXPECT_FALSE(CanUseFramebufferFetch("Adreno (TM) 630", true));
220
221 EXPECT_TRUE(CanUseFramebufferFetch("Adreno (TM) 640", true));
222 EXPECT_TRUE(CanUseFramebufferFetch("Adreno (TM) 750", true));
223 EXPECT_TRUE(CanUseFramebufferFetch("Mali-G51", false));
224}
bool CanUseFramebufferFetch(std::string_view driver_name, bool qc=true)

References CanUseFramebufferFetch().

◆ TEST() [132/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
CanUsePrimitiveRestart   
)

Definition at line 118 of file driver_info_vk_unittests.cc.

118 {
119 // Adreno no primitive restart
120 EXPECT_FALSE(CanUsePrimitiveRestartSubmitTest("Adreno (TM) 540", true));
121 EXPECT_FALSE(CanUsePrimitiveRestartSubmitTest("Adreno (TM) 750", true));
122
123 // Mali A-OK
124 EXPECT_TRUE(CanUsePrimitiveRestartSubmitTest("Mali-G51", false));
125}
bool CanUsePrimitiveRestartSubmitTest(std::string_view driver_name, bool qc=true)

References CanUsePrimitiveRestartSubmitTest().

◆ TEST() [133/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
DisabledDevices   
)

Definition at line 166 of file driver_info_vk_unittests.cc.

166 {
167 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 504"));
168 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 505"));
169 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 506"));
170 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 508"));
171 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 509"));
172 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 512"));
173 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 530"));
174 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 610"));
175 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 620"));
176 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 630"));
177 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 640"));
178 EXPECT_TRUE(IsBadVersionTest("Adreno (TM) 650"));
179}
bool IsBadVersionTest(std::string_view driver_name, bool qc=true)

References IsBadVersionTest().

◆ TEST() [134/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
DisableOldXclipseDriver   
)

Definition at line 226 of file driver_info_vk_unittests.cc.

226 {
227 auto context =
230 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
231 prop->vendorID = 0x144D; // Samsung
232 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
233 // Version 1.1.0
234 prop->apiVersion = (1 << 22) | (1 << 12);
235 })
236 .Build();
237
238 EXPECT_TRUE(context->GetDriverInfo()->IsKnownBadDriver());
239
240 context =
241 MockVulkanContextBuilder()
242 .SetPhysicalPropertiesCallback(
243 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
244 prop->vendorID = 0x144D; // Samsung
245 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
246 // Version 1.3.0
247 prop->apiVersion = (1 << 22) | (3 << 12);
248 })
249 .Build();
250
251 EXPECT_FALSE(context->GetDriverInfo()->IsKnownBadDriver());
252}

References context, device, and impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback().

◆ TEST() [135/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
DriverParsingAdreno   
)

Definition at line 161 of file driver_info_vk_unittests.cc.

161 {
162 EXPECT_EQ(GetAdrenoVersion("Adreno (TM) 540"), AdrenoGPU::kAdreno540);
163 EXPECT_EQ(GetAdrenoVersion("Foo Bar"), AdrenoGPU::kUnknown);
164}
AdrenoGPU GetAdrenoVersion(std::string_view version)

References impeller::GetAdrenoVersion(), impeller::kAdreno540, and impeller::kUnknown.

◆ TEST() [136/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
DriverParsingMali   
)

Definition at line 155 of file driver_info_vk_unittests.cc.

155 {
156 EXPECT_EQ(GetMaliVersion("Mali-G51-MORE STUFF"), MaliGPU::kG51);
157 EXPECT_EQ(GetMaliVersion("Mali-G51"), MaliGPU::kG51);
158 EXPECT_EQ(GetMaliVersion("Mali-111111"), MaliGPU::kUnknown);
159}
MaliGPU GetMaliVersion(std::string_view version)

References impeller::GetMaliVersion(), impeller::kG51, and impeller::kUnknown.

◆ TEST() [137/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
EnabledDevicesAdreno   
)

Definition at line 186 of file driver_info_vk_unittests.cc.

186 {
187 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 702"));
188 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 710"));
189 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 720"));
190 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 725"));
191 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 730"));
192 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 732"));
193 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 740"));
194 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 750"));
195}

References IsBadVersionTest().

◆ TEST() [138/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
EnabledDevicesMali   
)

Definition at line 181 of file driver_info_vk_unittests.cc.

181 {
182 EXPECT_FALSE(IsBadVersionTest("Mali-G52", /*qc=*/false));
183 EXPECT_FALSE(IsBadVersionTest("Mali-G54-MORE STUFF", /*qc=*/false));
184}

References IsBadVersionTest().

◆ TEST() [139/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
NewPowerVREnabled   
)

Definition at line 271 of file driver_info_vk_unittests.cc.

271 {
272 std::shared_ptr<ContextVK> context =
275 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
276 prop->vendorID = 0x1010;
277 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
278 std::string name = "PowerVR DXT 123";
279 name.copy(prop->deviceName, name.size());
280 })
281 .Build();
282
283 EXPECT_FALSE(context->GetDriverInfo()->IsKnownBadDriver());
284 EXPECT_EQ(context->GetDriverInfo()->GetPowerVRGPUInfo(),
285 std::optional<PowerVRGPU>(PowerVRGPU::kDXT));
286 EXPECT_TRUE(GetWorkaroundsFromDriverInfo(*context->GetDriverInfo())
288}

References context, device, impeller::GetWorkaroundsFromDriverInfo(), impeller::WorkaroundsVK::input_attachment_self_dependency_broken, impeller::kDXT, flutter::name, and impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback().

◆ TEST() [140/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
OldPowerVRDisabled   
)

Definition at line 254 of file driver_info_vk_unittests.cc.

254 {
255 std::shared_ptr<ContextVK> context =
258 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
259 prop->vendorID = 0x1010;
260 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
261 std::string name = "PowerVR Rogue GE8320";
262 name.copy(prop->deviceName, name.size());
263 })
264 .Build();
265
266 EXPECT_TRUE(context->GetDriverInfo()->IsKnownBadDriver());
267 EXPECT_EQ(context->GetDriverInfo()->GetPowerVRGPUInfo(),
268 std::optional<PowerVRGPU>(PowerVRGPU::kUnknown));
269}

References context, device, impeller::kUnknown, flutter::name, and impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback().

◆ TEST() [141/689]

impeller::testing::TEST ( DriverInfoVKTest  ,
PowerVRBSeries   
)

Definition at line 290 of file driver_info_vk_unittests.cc.

290 {
291 std::shared_ptr<ContextVK> context =
294 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
295 prop->vendorID = 0x1010;
296 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
297 std::string name = "PowerVR BXM-8-256";
298 name.copy(prop->deviceName, name.size());
299 })
300 .Build();
301
302 EXPECT_FALSE(context->GetDriverInfo()->IsKnownBadDriver());
303 EXPECT_EQ(context->GetDriverInfo()->GetPowerVRGPUInfo(),
304 std::optional<PowerVRGPU>(PowerVRGPU::kBXM));
305}

References context, device, impeller::kBXM, flutter::name, and impeller::testing::MockVulkanContextBuilder::SetPhysicalPropertiesCallback().

◆ TEST() [142/689]

impeller::testing::TEST ( EntityGeometryTest  ,
AlphaCoverageStrokePaths   
)

Definition at line 584 of file geometry_unittests.cc.

584 {
585 auto matrix = Matrix::MakeScale(Vector2{3.0, 3.0});
586 EXPECT_EQ(Geometry::MakeStrokePath({}, {.width = 0.5f})
587 ->ComputeAlphaCoverage(matrix),
588 1.0f);
589 EXPECT_NEAR(Geometry::MakeStrokePath({}, {.width = 0.1f})
590 ->ComputeAlphaCoverage(matrix),
591 0.6, 0.05);
592 EXPECT_NEAR(Geometry::MakeStrokePath({}, {.width = 0.05})
593 ->ComputeAlphaCoverage(matrix),
594 0.3, 0.05);
595 EXPECT_NEAR(Geometry::MakeStrokePath({}, {.width = 0.01})
596 ->ComputeAlphaCoverage(matrix),
597 0.1, 0.1);
598 EXPECT_NEAR(Geometry::MakeStrokePath({}, {.width = 0.0000005f})
599 ->ComputeAlphaCoverage(matrix),
600 1e-05, 0.001);
601 EXPECT_EQ(Geometry::MakeStrokePath({}, {.width = 0.0f})
602 ->ComputeAlphaCoverage(matrix),
603 1.0f);
604 EXPECT_EQ(Geometry::MakeStrokePath({}, {.width = 40.0f})
605 ->ComputeAlphaCoverage(matrix),
606 1.0f);
607}

References impeller::Matrix::MakeScale(), and impeller::Geometry::MakeStrokePath().

◆ TEST() [143/689]

impeller::testing::TEST ( EntityGeometryTest  ,
FillArcGeometryCoverage   
)

Definition at line 145 of file geometry_unittests.cc.

145 {
146 Rect oval_bounds = Rect::MakeLTRB(100, 100, 200, 200);
147 Matrix transform45 = Matrix::MakeTranslation(oval_bounds.GetCenter()) *
148 Matrix::MakeRotationZ(Degrees(45)) *
149 Matrix::MakeTranslation(-oval_bounds.GetCenter());
150
151 { // Sweeps <=-360 or >=360
152 for (int start = -720; start <= 720; start += 10) {
153 for (int sweep = 360; sweep <= 720; sweep += 30) {
154 std::string label =
155 "start: " + std::to_string(start) + " + " + std::to_string(sweep);
156 auto geometry = Geometry::MakeFilledArc(oval_bounds, Degrees(start),
157 Degrees(sweep), false);
158 EXPECT_EQ(geometry->GetCoverage({}), oval_bounds)
159 << "start: " << start << ", sweep: " << sweep;
160 geometry = Geometry::MakeFilledArc(oval_bounds, Degrees(start),
161 Degrees(-sweep), false);
162 EXPECT_EQ(geometry->GetCoverage({}), oval_bounds)
163 << "start: " << start << ", sweep: " << -sweep;
164 geometry = Geometry::MakeFilledArc(oval_bounds, Degrees(start),
165 Degrees(-sweep), true);
166 EXPECT_EQ(geometry->GetCoverage({}), oval_bounds)
167 << "start: " << start << ", sweep: " << -sweep << ", with center";
168 }
169 }
170 }
171 { // Sweep from late in one quadrant to earlier in same quadrant
172 for (int start = 60; start < 360; start += 90) {
173 auto geometry = Geometry::MakeFilledArc(oval_bounds, Degrees(start),
174 Degrees(330), false);
175 EXPECT_EQ(geometry->GetCoverage({}), oval_bounds)
176 << "start: " << start << " without center";
177 geometry = Geometry::MakeFilledArc(oval_bounds, Degrees(start),
178 Degrees(330), true);
179 EXPECT_EQ(geometry->GetCoverage({}), oval_bounds)
180 << "start: " << start << " with center";
181 }
182 }
183 { // Sweep from early in one quadrant backwards to later in same quadrant
184 for (int start = 30; start < 360; start += 90) {
185 auto geometry = Geometry::MakeFilledArc(oval_bounds, Degrees(start),
186 Degrees(-330), false);
187 EXPECT_EQ(geometry->GetCoverage({}), oval_bounds)
188 << "start: " << start << " without center";
189 geometry = Geometry::MakeFilledArc(oval_bounds, Degrees(start),
190 Degrees(-330), true);
191 EXPECT_EQ(geometry->GetCoverage({}), oval_bounds)
192 << "start: " << start << " with center";
193 }
194 }
195 { // Sweep past each quadrant axis individually, no center
196 for (int start = -360; start <= 720; start += 360) {
197 { // Quadrant 0
198 auto geometry = Geometry::MakeFilledArc(
199 oval_bounds, Degrees(start - 45), Degrees(90), false);
200 Rect expected_bounds = Rect::MakeLTRB(150 + 50 * kSqrt2Over2, //
201 150 - 50 * kSqrt2Over2, //
202 200, //
203 150 + 50 * kSqrt2Over2);
204 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
205 expected_bounds)
206 << "start: " << start - 45;
207 }
208 { // Quadrant 1
209 auto geometry = Geometry::MakeFilledArc(
210 oval_bounds, Degrees(start + 45), Degrees(90), false);
211 Rect expected_bounds = Rect::MakeLTRB(150 - 50 * kSqrt2Over2, //
212 150 + 50 * kSqrt2Over2, //
213 150 + 50 * kSqrt2Over2, //
214 200);
215 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
216 expected_bounds)
217 << "start: " << start + 45;
218 }
219 { // Quadrant 2
220 auto geometry = Geometry::MakeFilledArc(
221 oval_bounds, Degrees(start + 135), Degrees(90), false);
222 Rect expected_bounds = Rect::MakeLTRB(100, //
223 150 - 50 * kSqrt2Over2, //
224 150 - 50 * kSqrt2Over2, //
225 150 + 50 * kSqrt2Over2);
226 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
227 expected_bounds)
228 << "start: " << start + 135;
229 }
230 { // Quadrant 3
231 auto geometry = Geometry::MakeFilledArc(
232 oval_bounds, Degrees(start + 225), Degrees(90), false);
233 Rect expected_bounds = Rect::MakeLTRB(150 - 50 * kSqrt2Over2, //
234 100, //
235 150 + 50 * kSqrt2Over2, //
236 150 - 50 * kSqrt2Over2);
237 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
238 expected_bounds)
239 << "start: " << start + 225;
240 }
241 }
242 }
243 { // Sweep past each quadrant axis individually, including the center
244 for (int start = -360; start <= 720; start += 360) {
245 { // Quadrant 0
246 auto geometry = Geometry::MakeFilledArc(
247 oval_bounds, Degrees(start - 45), Degrees(90), true);
248 Rect expected_bounds = Rect::MakeLTRB(150, //
249 150 - 50 * kSqrt2Over2, //
250 200, //
251 150 + 50 * kSqrt2Over2);
252 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
253 expected_bounds)
254 << "start: " << start - 45;
255 }
256 { // Quadrant 1
257 auto geometry = Geometry::MakeFilledArc(
258 oval_bounds, Degrees(start + 45), Degrees(90), true);
259 Rect expected_bounds = Rect::MakeLTRB(150 - 50 * kSqrt2Over2, //
260 150, //
261 150 + 50 * kSqrt2Over2, //
262 200);
263 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
264 expected_bounds)
265 << "start: " << start + 45;
266 }
267 { // Quadrant 2
268 auto geometry = Geometry::MakeFilledArc(
269 oval_bounds, Degrees(start + 135), Degrees(90), true);
270 Rect expected_bounds = Rect::MakeLTRB(100, //
271 150 - 50 * kSqrt2Over2, //
272 150, //
273 150 + 50 * kSqrt2Over2);
274 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
275 expected_bounds)
276 << "start: " << start + 135;
277 }
278 { // Quadrant 3
279 auto geometry = Geometry::MakeFilledArc(
280 oval_bounds, Degrees(start + 225), Degrees(90), true);
281 Rect expected_bounds = Rect::MakeLTRB(150 - 50 * kSqrt2Over2, //
282 100, //
283 150 + 50 * kSqrt2Over2, //
284 150);
285 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
286 expected_bounds)
287 << "start: " << start + 225;
288 }
289 }
290 }
291 { // 45 degree tilted full circle
292 auto geometry =
293 Geometry::MakeFilledArc(oval_bounds, Degrees(0), Degrees(360), false);
294 ASSERT_TRUE(oval_bounds.TransformBounds(transform45).Contains(oval_bounds));
295
296 EXPECT_TRUE(geometry->GetCoverage(transform45)
297 .value_or(Rect())
298 .Contains(oval_bounds));
299 }
300 { // 45 degree tilted mostly full circle
301 auto geometry =
302 Geometry::MakeFilledArc(oval_bounds, Degrees(3), Degrees(359), false);
303 ASSERT_TRUE(oval_bounds.TransformBounds(transform45).Contains(oval_bounds));
304
305 EXPECT_TRUE(geometry->GetCoverage(transform45)
306 .value_or(Rect())
307 .Contains(oval_bounds));
308 }
309}
#define EXPECT_RECT_NEAR(a, b)
bool Contains(const Container &container, const Value &value)
TRect< Scalar > Rect
Definition rect.h:857
A 4x4 matrix using column-major storage.
Definition matrix.h:37

References EXPECT_RECT_NEAR, impeller::kSqrt2Over2, impeller::Geometry::MakeFilledArc(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeTranslation(), and start.

◆ TEST() [144/689]

impeller::testing::TEST ( EntityGeometryTest  ,
FillPathGeometryCoversArea   
)

Definition at line 122 of file geometry_unittests.cc.

122 {
124 .AddRect(Rect::MakeLTRB(0, 0, 100, 100))
125 .TakePath();
126 auto geometry = Geometry::MakeFillPath(
127 path, /* inner rect */ Rect::MakeLTRB(0, 0, 100, 100));
128 ASSERT_TRUE(geometry->CoversArea({}, IRect::MakeLTRB(0, 0, 100, 100)));
129 ASSERT_FALSE(geometry->CoversArea({}, IRect::MakeLTRB(-1, 0, 100, 100)));
130 ASSERT_TRUE(geometry->CoversArea({}, IRect::MakeLTRB(1, 1, 100, 100)));
131 ASSERT_TRUE(geometry->CoversArea({}, IRect()));
132}
const DlPath TakePath()
Returns the path constructed by this path builder and resets its internal state to the default state ...
DlPathBuilder & AddRect(const DlRect &rect)
Append a closed rectangular contour to the path.
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switch_defs.h:52

References flutter::DlPathBuilder::AddRect(), impeller::Geometry::MakeFillPath(), impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [145/689]

impeller::testing::TEST ( EntityGeometryTest  ,
FillPathGeometryCoversAreaNoInnerRect   
)

Definition at line 134 of file geometry_unittests.cc.

134 {
136 .AddRect(Rect::MakeLTRB(0, 0, 100, 100))
137 .TakePath();
138 auto geometry = Geometry::MakeFillPath(path);
139 ASSERT_FALSE(geometry->CoversArea({}, IRect::MakeLTRB(0, 0, 100, 100)));
140 ASSERT_FALSE(geometry->CoversArea({}, IRect::MakeLTRB(-1, 0, 100, 100)));
141 ASSERT_FALSE(geometry->CoversArea({}, IRect::MakeLTRB(1, 1, 100, 100)));
142 ASSERT_FALSE(geometry->CoversArea({}, IRect()));
143}

References flutter::DlPathBuilder::AddRect(), impeller::Geometry::MakeFillPath(), impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [146/689]

impeller::testing::TEST ( EntityGeometryTest  ,
FillRoundRectGeometryCoversArea   
)

Definition at line 512 of file geometry_unittests.cc.

512 {
513 Rect bounds = Rect::MakeLTRB(100, 100, 200, 200);
514 RoundRect round_rect =
515 RoundRect::MakeRectRadii(bounds, RoundingRadii{
516 .top_left = Size(1, 11),
517 .top_right = Size(2, 12),
518 .bottom_left = Size(3, 13),
519 .bottom_right = Size(4, 14),
520 });
521 FillRoundRectGeometry geom(round_rect);
522
523 // Tall middle rect should barely be covered.
524 EXPECT_TRUE(geom.CoversArea({}, IRect::MakeLTRB(103, 100, 196, 200)));
525 EXPECT_FALSE(geom.CoversArea({}, IRect::MakeLTRB(102, 100, 196, 200)));
526 EXPECT_FALSE(geom.CoversArea({}, IRect::MakeLTRB(103, 99, 196, 200)));
527 EXPECT_FALSE(geom.CoversArea({}, IRect::MakeLTRB(103, 100, 197, 200)));
528 EXPECT_FALSE(geom.CoversArea({}, IRect::MakeLTRB(103, 100, 196, 201)));
529
530 // Wide middle rect should barely be covered.
531 EXPECT_TRUE(geom.CoversArea({}, IRect::MakeLTRB(100, 112, 200, 186)));
532 EXPECT_FALSE(geom.CoversArea({}, IRect::MakeLTRB(99, 112, 200, 186)));
533 EXPECT_FALSE(geom.CoversArea({}, IRect::MakeLTRB(100, 111, 200, 186)));
534 EXPECT_FALSE(geom.CoversArea({}, IRect::MakeLTRB(100, 112, 201, 186)));
535 EXPECT_FALSE(geom.CoversArea({}, IRect::MakeLTRB(100, 112, 200, 187)));
536}
A Geometry class that produces fillable vertices from any |RoundRect| object regardless of radii unif...

References impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), and impeller::RoundingRadii::top_left.

◆ TEST() [147/689]

impeller::testing::TEST ( EntityGeometryTest  ,
GeometryResultHasReasonableDefaults   
)

Definition at line 577 of file geometry_unittests.cc.

577 {
578 GeometryResult result;
579 EXPECT_EQ(result.type, PrimitiveType::kTriangleStrip);
580 EXPECT_EQ(result.transform, Matrix());
581 EXPECT_EQ(result.mode, GeometryResult::Mode::kNormal);
582}
PrimitiveType type
Definition geometry.h:37

References impeller::GeometryResult::kNormal, impeller::kTriangleStrip, impeller::GeometryResult::mode, impeller::GeometryResult::transform, and impeller::GeometryResult::type.

◆ TEST() [148/689]

impeller::testing::TEST ( EntityGeometryTest  ,
LineGeometryCoverage   
)

Definition at line 538 of file geometry_unittests.cc.

538 {
539 {
540 auto geometry = Geometry::MakeLine( //
541 {10, 10}, {20, 10}, {.width = 2, .cap = Cap::kButt});
542 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(10, 9, 20, 11));
543 EXPECT_TRUE(geometry->CoversArea({}, IRect::MakeLTRB(10, 9, 20, 11)));
544 }
545
546 {
547 auto geometry = Geometry::MakeLine( //
548 {10, 10}, {20, 10}, {.width = 2, .cap = Cap::kSquare});
549 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(9, 9, 21, 11));
550 EXPECT_TRUE(geometry->CoversArea({}, IRect::MakeLTRB(9, 9, 21, 11)));
551 }
552
553 {
554 auto geometry = Geometry::MakeLine( //
555 {10, 10}, {10, 20}, {.width = 2, .cap = Cap::kButt});
556 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(9, 10, 11, 20));
557 EXPECT_TRUE(geometry->CoversArea({}, IRect::MakeLTRB(9, 10, 11, 20)));
558 }
559
560 {
561 auto geometry = Geometry::MakeLine( //
562 {10, 10}, {10, 20}, {.width = 2, .cap = Cap::kSquare});
563 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(9, 9, 11, 21));
564 EXPECT_TRUE(geometry->CoversArea({}, IRect::MakeLTRB(9, 9, 11, 21)));
565 }
566}

References impeller::kButt, impeller::kSquare, impeller::Geometry::MakeLine(), impeller::TRect< T >::MakeLTRB(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [149/689]

impeller::testing::TEST ( EntityGeometryTest  ,
RectGeometryCoversArea   
)

Definition at line 76 of file geometry_unittests.cc.

76 {
77 auto geometry = Geometry::MakeRect(Rect::MakeLTRB(0, 0, 100, 100));
78 ASSERT_TRUE(geometry->CoversArea({}, IRect::MakeLTRB(0, 0, 100, 100)));
79 ASSERT_FALSE(geometry->CoversArea({}, IRect::MakeLTRB(-1, 0, 100, 100)));
80 ASSERT_TRUE(geometry->CoversArea({}, IRect::MakeLTRB(1, 1, 100, 100)));
81 ASSERT_TRUE(geometry->CoversArea({}, IRect()));
82}

References impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::Geometry::MakeRect().

◆ TEST() [150/689]

impeller::testing::TEST ( EntityGeometryTest  ,
RotatedFilledCircleGeometryCoverage   
)

Definition at line 1403 of file geometry_unittests.cc.

1403 {
1404 Point center = Point(50, 50);
1405 auto geometry = Geometry::MakeCircle(center, 50);
1406 Rect circle_bounds = Rect::MakeLTRB(0, 0, 100, 100);
1407 ASSERT_EQ(geometry->GetCoverage({}).value_or(Rect()), circle_bounds);
1408
1409 Matrix transform45 = Matrix::MakeTranslation(center) *
1410 Matrix::MakeRotationZ(Degrees(45)) *
1411 Matrix::MakeTranslation(-center);
1412
1413 EXPECT_TRUE(geometry->GetCoverage(transform45).has_value());
1414 Rect bounds = geometry->GetCoverage(transform45).value_or(Rect());
1415 EXPECT_TRUE(bounds.Contains(circle_bounds))
1416 << "geometry bounds: " << bounds << std::endl
1417 << " circle bounds: " << circle_bounds;
1418}

References impeller::Geometry::MakeCircle(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeRotationZ(), and impeller::Matrix::MakeTranslation().

◆ TEST() [151/689]

impeller::testing::TEST ( EntityGeometryTest  ,
RotatedStrokedCircleGeometryCoverage   
)

Definition at line 1420 of file geometry_unittests.cc.

1420 {
1421 Point center = Point(50, 50);
1422 auto geometry = Geometry::MakeStrokedCircle(center, 50, 10);
1423 Rect circle_bounds = Rect::MakeLTRB(0, 0, 100, 100).Expand(5);
1424 ASSERT_EQ(geometry->GetCoverage({}).value_or(Rect()), circle_bounds);
1425
1426 Matrix transform45 = Matrix::MakeTranslation(center) *
1427 Matrix::MakeRotationZ(Degrees(45)) *
1428 Matrix::MakeTranslation(-center);
1429
1430 EXPECT_TRUE(geometry->GetCoverage(transform45).has_value());
1431 Rect bounds = geometry->GetCoverage(transform45).value_or(Rect());
1432 EXPECT_TRUE(bounds.Contains(circle_bounds))
1433 << "geometry bounds: " << bounds << std::endl
1434 << " circle bounds: " << circle_bounds;
1435}

References impeller::TRect< T >::Expand(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeRotationZ(), impeller::Geometry::MakeStrokedCircle(), and impeller::Matrix::MakeTranslation().

◆ TEST() [152/689]

impeller::testing::TEST ( EntityGeometryTest  ,
RoundRectGeometryCoversArea   
)

Definition at line 568 of file geometry_unittests.cc.

568 {
569 auto geometry =
570 Geometry::MakeRoundRect(Rect::MakeLTRB(0, 0, 100, 100), Size(20, 20));
571 EXPECT_FALSE(geometry->CoversArea({}, IRect::MakeLTRB(15, 15, 85, 85)));
572 EXPECT_TRUE(geometry->CoversArea({}, IRect::MakeLTRB(20, 20, 80, 80)));
573 EXPECT_TRUE(geometry->CoversArea({}, IRect::MakeLTRB(30, 1, 70, 99)));
574 EXPECT_TRUE(geometry->CoversArea({}, IRect::MakeLTRB(1, 30, 99, 70)));
575}

References impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::Geometry::MakeRoundRect().

◆ TEST() [153/689]

impeller::testing::TEST ( EntityGeometryTest  ,
SimpleTwoLineStrokeVerticesButtCap   
)

Definition at line 609 of file geometry_unittests.cc.

609 {
610 flutter::DlPathBuilder path_builder;
611 path_builder.MoveTo({20, 20});
612 path_builder.LineTo({30, 20});
613 path_builder.MoveTo({120, 20});
614 path_builder.LineTo({130, 20});
615 flutter::DlPath path = path_builder.TakePath();
616
617 auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
618 path,
619 {
620 .width = 10.0f,
621 .cap = Cap::kButt,
622 .join = Join::kBevel,
623 .miter_limit = 4.0f,
624 },
625 1.0f);
626
627 std::vector<Point> expected = {
628 // The points for the first segment (20, 20) -> (30, 20)
629 Point(20, 25),
630 Point(20, 15),
631 Point(30, 25),
632 Point(30, 15),
633
634 // The glue points that allow us to "pick up the pen" between segments
635 Point(30, 20),
636 Point(30, 20),
637 Point(120, 20),
638 Point(120, 20),
639
640 // The points for the second segment (120, 20) -> (130, 20)
641 Point(120, 25),
642 Point(120, 15),
643 Point(130, 25),
644 Point(130, 15),
645 };
646
647 EXPECT_EQ(points, expected);
648}
DlPathBuilder & LineTo(DlPoint p2)
Draw a line from the current point to the indicated point p2.
DlPathBuilder & MoveTo(DlPoint p2)
Start a new contour that will originate at the indicated point p2.
TPoint< Scalar > Point
Definition point.h:426
std::vector< Point > points

References impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kButt, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [154/689]

impeller::testing::TEST ( EntityGeometryTest  ,
SimpleTwoLineStrokeVerticesRoundCap   
)

Definition at line 650 of file geometry_unittests.cc.

650 {
651 flutter::DlPathBuilder path_builder;
652 path_builder.MoveTo({20, 20});
653 path_builder.LineTo({30, 20});
654 path_builder.MoveTo({120, 20});
655 path_builder.LineTo({130, 20});
656 flutter::DlPath path = path_builder.TakePath();
657
658 auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
659 path,
660 {
661 .width = 10.0f,
662 .cap = Cap::kRound,
663 .join = Join::kBevel,
664 .miter_limit = 4.0f,
665 },
666 1.0f);
667
668 size_t count = points.size();
669 ASSERT_TRUE((count & 0x1) == 0x0); // Should always be even
670
671 // For a scale factor of 1.0 and a stroke width of 10.0 we currently
672 // generate 40 total points for the 2 line segments based on the number
673 // of quadrant circle divisions for a radius of 5.0
674 //
675 // If the number of points changes because of a change in the way we
676 // compute circle divisions, we need to recompute the circular offsets
677 ASSERT_EQ(points.size(), 40u);
678
679 // Compute the indicated circular end cap offset based on the current
680 // step out of 4 divisions [1, 2, 3] (not 0 or 4) based on whether this
681 // is the left or right side of the path and whether this is a backwards
682 // (starting) cap or a forwards (ending) cap.
683 auto offset = [](int step, bool left, bool backwards) -> Point {
684 Radians angle(kPiOver2 * (step / 4.0f));
685 Point along = Point(5.0f, 0.0f) * std::cos(angle.radians);
686 Point across = Point(0.0f, 5.0f) * std::sin(angle.radians);
687 Point center = backwards ? -along : along;
688 return left ? center + across : center - across;
689 };
690
691 // The points for the first segment (20, 20) -> (30, 20)
692 EXPECT_EQ(points[0], Point(15, 20));
693 EXPECT_EQ(points[1], Point(20, 20) + offset(1, true, true));
694 EXPECT_EQ(points[2], Point(20, 20) + offset(1, false, true));
695 EXPECT_EQ(points[3], Point(20, 20) + offset(2, true, true));
696 EXPECT_EQ(points[4], Point(20, 20) + offset(2, false, true));
697 EXPECT_EQ(points[5], Point(20, 20) + offset(3, true, true));
698 EXPECT_EQ(points[6], Point(20, 20) + offset(3, false, true));
699 EXPECT_EQ(points[7], Point(20, 25));
700 EXPECT_EQ(points[8], Point(20, 15));
701 EXPECT_EQ(points[9], Point(30, 25));
702 EXPECT_EQ(points[10], Point(30, 15));
703 EXPECT_EQ(points[11], Point(30, 20) + offset(3, true, false));
704 EXPECT_EQ(points[12], Point(30, 20) + offset(3, false, false));
705 EXPECT_EQ(points[13], Point(30, 20) + offset(2, true, false));
706 EXPECT_EQ(points[14], Point(30, 20) + offset(2, false, false));
707 EXPECT_EQ(points[15], Point(30, 20) + offset(1, true, false));
708 EXPECT_EQ(points[16], Point(30, 20) + offset(1, false, false));
709 EXPECT_EQ(points[17], Point(35, 20));
710
711 // The glue points that allow us to "pick up the pen" between segments
712 EXPECT_EQ(points[18], Point(30, 20));
713 EXPECT_EQ(points[19], Point(30, 20));
714 EXPECT_EQ(points[20], Point(120, 20));
715 EXPECT_EQ(points[21], Point(120, 20));
716
717 // The points for the second segment (120, 20) -> (130, 20)
718 EXPECT_EQ(points[22], Point(115, 20));
719 EXPECT_EQ(points[23], Point(120, 20) + offset(1, true, true));
720 EXPECT_EQ(points[24], Point(120, 20) + offset(1, false, true));
721 EXPECT_EQ(points[25], Point(120, 20) + offset(2, true, true));
722 EXPECT_EQ(points[26], Point(120, 20) + offset(2, false, true));
723 EXPECT_EQ(points[27], Point(120, 20) + offset(3, true, true));
724 EXPECT_EQ(points[28], Point(120, 20) + offset(3, false, true));
725 EXPECT_EQ(points[29], Point(120, 25));
726 EXPECT_EQ(points[30], Point(120, 15));
727 EXPECT_EQ(points[31], Point(130, 25));
728 EXPECT_EQ(points[32], Point(130, 15));
729 EXPECT_EQ(points[33], Point(130, 20) + offset(3, true, false));
730 EXPECT_EQ(points[34], Point(130, 20) + offset(3, false, false));
731 EXPECT_EQ(points[35], Point(130, 20) + offset(2, true, false));
732 EXPECT_EQ(points[36], Point(130, 20) + offset(2, false, false));
733 EXPECT_EQ(points[37], Point(130, 20) + offset(1, true, false));
734 EXPECT_EQ(points[38], Point(130, 20) + offset(1, false, false));
735 EXPECT_EQ(points[39], Point(135, 20));
736}

References impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kPiOver2, impeller::kRound, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, points, impeller::Radians::radians, and flutter::DlPathBuilder::TakePath().

◆ TEST() [155/689]

impeller::testing::TEST ( EntityGeometryTest  ,
SimpleTwoLineStrokeVerticesSquareCap   
)

Definition at line 738 of file geometry_unittests.cc.

738 {
739 flutter::DlPathBuilder path_builder;
740 path_builder.MoveTo({20, 20});
741 path_builder.LineTo({30, 20});
742 path_builder.MoveTo({120, 20});
743 path_builder.LineTo({130, 20});
744 flutter::DlPath path = path_builder.TakePath();
745
746 auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
747 path,
748 {
749 .width = 10.0f,
750 .cap = Cap::kSquare,
751 .join = Join::kBevel,
752 .miter_limit = 4.0f,
753 },
754 1.0f);
755
756 // clang-format off
757 std::vector<Point> expected = {
758 // The points for the first segment (20, 20) -> (30, 20)
759 Point(15, 25),
760 Point(15, 15),
761 Point(20, 25),
762 Point(20, 15),
763 Point(30, 25),
764 Point(30, 15),
765 Point(35, 25),
766 Point(35, 15),
767
768 // The glue points that allow us to "pick up the pen" between segments
769 Point(30, 20),
770 Point(30, 20),
771 Point(120, 20),
772 Point(120, 20),
773
774 // The points for the second segment (120, 20) -> (130, 20)
775 Point(115, 25),
776 Point(115, 15),
777 Point(120, 25),
778 Point(120, 15),
779 Point(130, 25),
780 Point(130, 15),
781 Point(135, 25),
782 Point(135, 15),
783 };
784 // clang-format on
785
786 EXPECT_EQ(points, expected);
787}

References impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kSquare, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [156/689]

impeller::testing::TEST ( EntityGeometryTest  ,
StrokeArcGeometryCoverage   
)

Definition at line 311 of file geometry_unittests.cc.

311 {
312 Rect oval_bounds = Rect::MakeLTRB(100, 100, 200, 200);
313 Rect expanded_bounds = Rect::MakeLTRB(95, 95, 205, 205);
314 Rect squared_bounds = Rect::MakeLTRB(100 - 5 * kSqrt2, 100 - 5 * kSqrt2,
315 200 + 5 * kSqrt2, 200 + 5 * kSqrt2);
316 Matrix transform45 = Matrix::MakeTranslation(oval_bounds.GetCenter()) *
317 Matrix::MakeRotationZ(Degrees(45)) *
318 Matrix::MakeTranslation(-oval_bounds.GetCenter());
319
320 StrokeParameters butt_params = {
321 .width = 10.0f,
322 .cap = Cap::kButt,
323 };
324 StrokeParameters square_params = {
325 .width = 10.0f,
326 .cap = Cap::kSquare,
327 };
328
329 { // Sweeps <=-360 or >=360
330 for (int start = -720; start <= 720; start += 10) {
331 for (int sweep = 360; sweep <= 720; sweep += 30) {
332 std::string label =
333 "start: " + std::to_string(start) + " + " + std::to_string(sweep);
334 auto geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
335 Degrees(sweep), butt_params);
336 EXPECT_EQ(geometry->GetCoverage({}), expanded_bounds)
337 << "start: " << start << ", sweep: " << sweep;
338 geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
339 Degrees(-sweep), butt_params);
340 EXPECT_EQ(geometry->GetCoverage({}), expanded_bounds)
341 << "start: " << start << ", sweep: " << -sweep;
342 geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
343 Degrees(-sweep), square_params);
344 EXPECT_EQ(geometry->GetCoverage({}), expanded_bounds)
345 << "start: " << start << ", sweep: " << -sweep << ", square caps";
346 }
347 }
348 }
349 { // Sweep from late in one quadrant to earlier in same quadrant
350 for (int start = 60; start < 360; start += 90) {
351 auto geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
352 Degrees(330), butt_params);
353 EXPECT_EQ(geometry->GetCoverage({}), expanded_bounds)
354 << "start: " << start << ", butt caps";
355 geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
356 Degrees(330), square_params);
357 EXPECT_EQ(geometry->GetCoverage({}), squared_bounds)
358 << "start: " << start << ", square caps";
359 }
360 }
361 { // Sweep from early in one quadrant backwards to later in same quadrant
362 for (int start = 30; start < 360; start += 90) {
363 auto geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
364 Degrees(-330), butt_params);
365 EXPECT_EQ(geometry->GetCoverage({}), expanded_bounds)
366 << "start: " << start << " without center";
367 geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
368 Degrees(-330), square_params);
369 EXPECT_EQ(geometry->GetCoverage({}), squared_bounds)
370 << "start: " << start << " with center";
371 }
372 }
373 { // Sweep past each quadrant axis individually with butt caps
374 for (int start = -360; start <= 720; start += 360) {
375 { // Quadrant 0
376 auto geometry = Geometry::MakeStrokedArc(
377 oval_bounds, Degrees(start - 45), Degrees(90), butt_params);
378 Rect expected_bounds = Rect::MakeLTRB(150 + 50 * kSqrt2Over2 - 5, //
379 150 - 50 * kSqrt2Over2 - 5, //
380 205, //
381 150 + 50 * kSqrt2Over2 + 5);
382 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
383 expected_bounds)
384 << "start: " << start - 45;
385 }
386 { // Quadrant 1
387 auto geometry = Geometry::MakeStrokedArc(
388 oval_bounds, Degrees(start + 45), Degrees(90), butt_params);
389 Rect expected_bounds = Rect::MakeLTRB(150 - 50 * kSqrt2Over2 - 5, //
390 150 + 50 * kSqrt2Over2 - 5, //
391 150 + 50 * kSqrt2Over2 + 5, //
392 205);
393 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
394 expected_bounds)
395 << "start: " << start + 45;
396 }
397 { // Quadrant 2
398 auto geometry = Geometry::MakeStrokedArc(
399 oval_bounds, Degrees(start + 135), Degrees(90), butt_params);
400 Rect expected_bounds = Rect::MakeLTRB(95, //
401 150 - 50 * kSqrt2Over2 - 5, //
402 150 - 50 * kSqrt2Over2 + 5, //
403 150 + 50 * kSqrt2Over2 + 5);
404 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
405 expected_bounds)
406 << "start: " << start + 135;
407 }
408 { // Quadrant 3
409 auto geometry = Geometry::MakeStrokedArc(
410 oval_bounds, Degrees(start + 225), Degrees(90), butt_params);
411 Rect expected_bounds = Rect::MakeLTRB(150 - 50 * kSqrt2Over2 - 5, //
412 95, //
413 150 + 50 * kSqrt2Over2 + 5, //
414 150 - 50 * kSqrt2Over2 + 5);
415 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
416 expected_bounds)
417 << "start: " << start + 225;
418 }
419 }
420 }
421 { // Sweep past each quadrant axis individually with square caps
422 Scalar pad = 5 * kSqrt2;
423 for (int start = -360; start <= 720; start += 360) {
424 { // Quadrant 0
425 auto geometry = Geometry::MakeStrokedArc(
426 oval_bounds, Degrees(start - 45), Degrees(90), square_params);
427 Rect expected_bounds = Rect::MakeLTRB(150 + 50 * kSqrt2Over2 - pad, //
428 150 - 50 * kSqrt2Over2 - pad, //
429 200 + pad, //
430 150 + 50 * kSqrt2Over2 + pad);
431 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
432 expected_bounds)
433 << "start: " << start - 45;
434 }
435 { // Quadrant 1
436 auto geometry = Geometry::MakeStrokedArc(
437 oval_bounds, Degrees(start + 45), Degrees(90), square_params);
438 Rect expected_bounds = Rect::MakeLTRB(150 - 50 * kSqrt2Over2 - pad, //
439 150 + 50 * kSqrt2Over2 - pad, //
440 150 + 50 * kSqrt2Over2 + pad, //
441 200 + pad);
442 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
443 expected_bounds)
444 << "start: " << start + 45;
445 }
446 { // Quadrant 2
447 auto geometry = Geometry::MakeStrokedArc(
448 oval_bounds, Degrees(start + 135), Degrees(90), square_params);
449 Rect expected_bounds = Rect::MakeLTRB(100 - pad, //
450 150 - 50 * kSqrt2Over2 - pad, //
451 150 - 50 * kSqrt2Over2 + pad, //
452 150 + 50 * kSqrt2Over2 + pad);
453 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
454 expected_bounds)
455 << "start: " << start + 135;
456 }
457 { // Quadrant 3
458 auto geometry = Geometry::MakeStrokedArc(
459 oval_bounds, Degrees(start + 225), Degrees(90), square_params);
460 Rect expected_bounds = Rect::MakeLTRB(150 - 50 * kSqrt2Over2 - pad, //
461 100 - pad, //
462 150 + 50 * kSqrt2Over2 + pad, //
463 150 - 50 * kSqrt2Over2 + pad);
464 EXPECT_RECT_NEAR(geometry->GetCoverage({}).value_or(Rect()),
465 expected_bounds)
466 << "start: " << start + 225;
467 }
468 }
469 }
470 { // 45 degree tilted full circle, butt caps
471 auto geometry = Geometry::MakeStrokedArc( //
472 oval_bounds, Degrees(0), Degrees(360), butt_params);
473 ASSERT_TRUE(
474 oval_bounds.TransformBounds(transform45).Contains(expanded_bounds));
475
476 EXPECT_TRUE(geometry->GetCoverage(transform45)
477 .value_or(Rect())
478 .Contains(expanded_bounds));
479 }
480 { // 45 degree tilted full circle, square caps
481 auto geometry = Geometry::MakeStrokedArc( //
482 oval_bounds, Degrees(0), Degrees(360), square_params);
483 ASSERT_TRUE(
484 oval_bounds.TransformBounds(transform45).Contains(expanded_bounds));
485
486 EXPECT_TRUE(geometry->GetCoverage(transform45)
487 .value_or(Rect())
488 .Contains(squared_bounds));
489 }
490 { // 45 degree tilted mostly full circle, butt caps
491 auto geometry = Geometry::MakeStrokedArc( //
492 oval_bounds, Degrees(3), Degrees(359), butt_params);
493 ASSERT_TRUE(
494 oval_bounds.TransformBounds(transform45).Contains(expanded_bounds));
495
496 EXPECT_TRUE(geometry->GetCoverage(transform45)
497 .value_or(Rect())
498 .Contains(expanded_bounds));
499 }
500 { // 45 degree tilted mostly full circle, square caps
501 auto geometry = Geometry::MakeStrokedArc( //
502 oval_bounds, Degrees(3), Degrees(359), square_params);
503 ASSERT_TRUE(
504 oval_bounds.TransformBounds(transform45).Contains(expanded_bounds));
505
506 EXPECT_TRUE(geometry->GetCoverage(transform45)
507 .value_or(Rect())
508 .Contains(squared_bounds));
509 }
510}
constexpr float kSqrt2
Definition math.h:45
A structure to store all of the parameters related to stroking a path or basic geometry object.

References EXPECT_RECT_NEAR, impeller::kButt, impeller::kSqrt2, impeller::kSqrt2Over2, impeller::kSquare, impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeRotationZ(), impeller::Geometry::MakeStrokedArc(), impeller::Matrix::MakeTranslation(), start, and impeller::StrokeParameters::width.

◆ TEST() [157/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TightConic180DegreeJoins   
)

Definition at line 1268 of file geometry_unittests.cc.

1268 {
1269 // First, create a mild conic that helps us verify how many points
1270 // should normally be on a quad with 2 legs of length 90.
1271 flutter::DlPathBuilder path_builder_refrence;
1272 path_builder_refrence.MoveTo(Point(10, 10));
1273 path_builder_refrence.ConicCurveTo(Point(100, 10), Point(100, 100), 0.9f);
1274 flutter::DlPath path_reference = path_builder_refrence.TakePath();
1275
1276 auto points_bevel_reference =
1277 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1278 path_reference,
1279 {
1280 .width = 20.0f,
1281 .cap = Cap::kButt,
1282 .join = Join::kBevel,
1283 .miter_limit = 4.0f,
1284 },
1285 1.0f);
1286 // Generates no joins because the curve is smooth
1287 EXPECT_EQ(points_bevel_reference.size(), 78u);
1288
1289 // Now create a path that doubles back on itself with a conic.
1290 flutter::DlPathBuilder path_builder;
1291 path_builder.MoveTo(Point(10, 10));
1292 path_builder.QuadraticCurveTo(Point(100, 10), Point(10, 10));
1293 flutter::DlPath path = path_builder.TakePath();
1294
1295 auto points_bevel =
1296 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1297 path,
1298 {
1299 .width = 20.0f,
1300 .cap = Cap::kButt,
1301 .join = Join::kBevel,
1302 .miter_limit = 4.0f,
1303 },
1304 1.0f);
1305 // Generates round join because it is in the middle of a curved segment
1306 EXPECT_GT(points_bevel.size(), points_bevel_reference.size());
1307
1308 auto points_miter =
1309 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1310 path,
1311 {
1312 .width = 20.0f,
1313 .cap = Cap::kButt,
1314 .join = Join::kMiter,
1315 .miter_limit = 400.0f,
1316 },
1317 1.0f);
1318 // Generates round join because it is in the middle of a curved segment
1319 EXPECT_GT(points_miter.size(), points_bevel_reference.size());
1320
1321 auto points_round =
1322 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1323 path,
1324 {
1325 .width = 20.0f,
1326 .cap = Cap::kButt,
1327 .join = Join::kRound,
1328 .miter_limit = 4.0f,
1329 },
1330 1.0f);
1331 // Generates round join because it is in the middle of a curved segment
1332 EXPECT_GT(points_round.size(), points_bevel_reference.size());
1333}
DlPathBuilder & ConicCurveTo(DlPoint cp, DlPoint p2, DlScalar weight)
Draw a conic curve (a rational quadratic bezier curve) from the current point to the indicated point ...
DlPathBuilder & QuadraticCurveTo(DlPoint cp, DlPoint p2)
Draw a quadratic bezier curve from the current point to the indicated point p2, using the indicated p...

References flutter::DlPathBuilder::ConicCurveTo(), impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kButt, impeller::kMiter, impeller::kRound, flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DlPathBuilder::QuadraticCurveTo(), and flutter::DlPathBuilder::TakePath().

◆ TEST() [158/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TightCubic180DegreeJoins   
)

Definition at line 1335 of file geometry_unittests.cc.

1335 {
1336 // First, create a mild cubic that helps us verify how many points
1337 // should normally be on a quad with 3 legs of length ~50.
1338 flutter::DlPathBuilder path_builder_reference;
1339 path_builder_reference.MoveTo(Point(10, 10));
1340 path_builder_reference.CubicCurveTo(Point(60, 10), Point(100, 40),
1341 Point(100, 90));
1342 flutter::DlPath path_reference = path_builder_reference.TakePath();
1343
1344 auto points_reference =
1345 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1346 path_reference,
1347 {
1348 .width = 20.0f,
1349 .cap = Cap::kButt,
1350 .join = Join::kBevel,
1351 .miter_limit = 4.0f,
1352 },
1353 1.0f);
1354 // Generates no joins because the curve is smooth
1355 EXPECT_EQ(points_reference.size(), 76u);
1356
1357 // Now create a path that doubles back on itself with a cubic.
1358 flutter::DlPathBuilder path_builder;
1359 path_builder.MoveTo(Point(10, 10));
1360 path_builder.CubicCurveTo(Point(60, 10), Point(100, 40), Point(60, 10));
1361 flutter::DlPath path = path_builder.TakePath();
1362
1363 auto points_bevel =
1364 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1365 path,
1366 {
1367 .width = 20.0f,
1368 .cap = Cap::kButt,
1369 .join = Join::kBevel,
1370 .miter_limit = 4.0f,
1371 },
1372 1.0f);
1373 // Generates round join because it is in the middle of a curved segment
1374 EXPECT_GT(points_bevel.size(), points_reference.size());
1375
1376 auto points_miter =
1377 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1378 path,
1379 {
1380 .width = 20.0f,
1381 .cap = Cap::kButt,
1382 .join = Join::kMiter,
1383 .miter_limit = 400.0f,
1384 },
1385 1.0f);
1386 // Generates round join because it is in the middle of a curved segment
1387 EXPECT_GT(points_miter.size(), points_reference.size());
1388
1389 auto points_round =
1390 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1391 path,
1392 {
1393 .width = 20.0f,
1394 .cap = Cap::kButt,
1395 .join = Join::kRound,
1396 .miter_limit = 4.0f,
1397 },
1398 1.0f);
1399 // Generates round join because it is in the middle of a curved segment
1400 EXPECT_GT(points_round.size(), points_reference.size());
1401}
DlPathBuilder & CubicCurveTo(DlPoint cp1, DlPoint cp2, DlPoint p2)
Draw a cubic bezier curve from the current point to the indicated point p2, using the indicated point...

References flutter::DlPathBuilder::CubicCurveTo(), impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kButt, impeller::kMiter, impeller::kRound, flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [159/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TightQuadratic180DegreeJoins   
)

Definition at line 1201 of file geometry_unittests.cc.

1201 {
1202 // First, create a mild quadratic that helps us verify how many points
1203 // should normally be on a quad with 2 legs of length 90.
1204 flutter::DlPathBuilder path_builder_refrence;
1205 path_builder_refrence.MoveTo(Point(10, 10));
1206 path_builder_refrence.QuadraticCurveTo(Point(100, 10), Point(100, 100));
1207 flutter::DlPath path_reference = path_builder_refrence.TakePath();
1208
1209 auto points_bevel_reference =
1210 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1211 path_reference,
1212 {
1213 .width = 20.0f,
1214 .cap = Cap::kButt,
1215 .join = Join::kBevel,
1216 .miter_limit = 4.0f,
1217 },
1218 1.0f);
1219 // Generates no joins because the curve is smooth
1220 EXPECT_EQ(points_bevel_reference.size(), 74u);
1221
1222 // Now create a path that doubles back on itself with a quadratic.
1223 flutter::DlPathBuilder path_builder;
1224 path_builder.MoveTo(Point(10, 10));
1225 path_builder.QuadraticCurveTo(Point(100, 10), Point(10, 10));
1226 flutter::DlPath path = path_builder.TakePath();
1227
1228 auto points_bevel =
1229 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1230 path,
1231 {
1232 .width = 20.0f,
1233 .cap = Cap::kButt,
1234 .join = Join::kBevel,
1235 .miter_limit = 4.0f,
1236 },
1237 1.0f);
1238 // Generates round join because it is in the middle of a curved segment
1239 EXPECT_GT(points_bevel.size(), points_bevel_reference.size());
1240
1241 auto points_miter =
1242 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1243 path,
1244 {
1245 .width = 20.0f,
1246 .cap = Cap::kButt,
1247 .join = Join::kMiter,
1248 .miter_limit = 400.0f,
1249 },
1250 1.0f);
1251 // Generates round join because it is in the middle of a curved segment
1252 EXPECT_GT(points_miter.size(), points_bevel_reference.size());
1253
1254 auto points_round =
1255 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1256 path,
1257 {
1258 .width = 20.0f,
1259 .cap = Cap::kButt,
1260 .join = Join::kRound,
1261 .miter_limit = 4.0f,
1262 },
1263 1.0f);
1264 // Generates round join because it is in the middle of a curved segment
1265 EXPECT_GT(points_round.size(), points_bevel_reference.size());
1266}

References impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kButt, impeller::kMiter, impeller::kRound, flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DlPathBuilder::QuadraticCurveTo(), and flutter::DlPathBuilder::TakePath().

◆ TEST() [160/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TinyConicGeneratesCaps   
)

Definition at line 1015 of file geometry_unittests.cc.

1015 {
1016 flutter::DlPathBuilder path_builder;
1017 path_builder.MoveTo({20, 20});
1018 path_builder.ConicCurveTo({20.125, 20}, {20.250, 20}, 0.6);
1019 flutter::DlPath path = path_builder.TakePath();
1020
1021 auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1022 path,
1023 {
1024 .width = 4.0f,
1025 .cap = Cap::kSquare,
1026 .join = Join::kBevel,
1027 .miter_limit = 4.0f,
1028 },
1029 1.0f);
1030
1031 std::vector<Point> expected = {
1032 // The points for the opening square cap
1033 Point(18, 22),
1034 Point(18, 18),
1035
1036 // The points for the start of the curve
1037 Point(20, 22),
1038 Point(20, 18),
1039
1040 // The points for the end of the curve
1041 Point(20.25, 22),
1042 Point(20.25, 18),
1043
1044 // The points for the closing square cap
1045 Point(22.25, 22),
1046 Point(22.25, 18),
1047 };
1048
1049 EXPECT_EQ(points, expected);
1050}

References flutter::DlPathBuilder::ConicCurveTo(), impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kSquare, flutter::DlPathBuilder::MoveTo(), flutter::path, points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [161/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TinyCubicGeneratesCaps   
)

Definition at line 1052 of file geometry_unittests.cc.

1052 {
1053 flutter::DlPathBuilder path_builder;
1054 path_builder.MoveTo({20, 20});
1055 path_builder.CubicCurveTo({20.0625, 20}, {20.125, 20}, {20.250, 20});
1056 flutter::DlPath path = path_builder.TakePath();
1057
1058 auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1059 path,
1060 {
1061 .width = 4.0f,
1062 .cap = Cap::kSquare,
1063 .join = Join::kBevel,
1064 .miter_limit = 4.0f,
1065 },
1066 1.0f);
1067
1068 std::vector<Point> expected = {
1069 // The points for the opening square cap
1070 Point(18, 22),
1071 Point(18, 18),
1072
1073 // The points for the start of the curve
1074 Point(20, 22),
1075 Point(20, 18),
1076
1077 // The points for the end of the curve
1078 Point(20.25, 22),
1079 Point(20.25, 18),
1080
1081 // The points for the closing square cap
1082 Point(22.25, 22),
1083 Point(22.25, 18),
1084 };
1085
1086 EXPECT_EQ(points, expected);
1087}

References flutter::DlPathBuilder::CubicCurveTo(), impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kSquare, flutter::DlPathBuilder::MoveTo(), flutter::path, points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [162/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TinyQuadGeneratesCaps   
)

Definition at line 978 of file geometry_unittests.cc.

978 {
979 flutter::DlPathBuilder path_builder;
980 path_builder.MoveTo({20, 20});
981 path_builder.QuadraticCurveTo({20.125, 20}, {20.250, 20});
982 flutter::DlPath path = path_builder.TakePath();
983
984 auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
985 path,
986 {
987 .width = 4.0f,
988 .cap = Cap::kSquare,
989 .join = Join::kBevel,
990 .miter_limit = 4.0f,
991 },
992 1.0f);
993
994 std::vector<Point> expected = {
995 // The points for the opening square cap
996 Point(18, 22),
997 Point(18, 18),
998
999 // The points for the start of the curve
1000 Point(20, 22),
1001 Point(20, 18),
1002
1003 // The points for the end of the curve
1004 Point(20.25, 22),
1005 Point(20.25, 18),
1006
1007 // The points for the closing square cap
1008 Point(22.25, 22),
1009 Point(22.25, 18),
1010 };
1011
1012 EXPECT_EQ(points, expected);
1013}

References impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kSquare, flutter::DlPathBuilder::MoveTo(), flutter::path, points, flutter::DlPathBuilder::QuadraticCurveTo(), and flutter::DlPathBuilder::TakePath().

◆ TEST() [163/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TwoLineSegments180DegreeJoins   
)

Definition at line 1153 of file geometry_unittests.cc.

1153 {
1154 // First, create a path that doubles back on itself.
1155 flutter::DlPathBuilder path_builder;
1156 path_builder.MoveTo(Point(10, 10));
1157 path_builder.LineTo(Point(100, 10));
1158 path_builder.LineTo(Point(10, 10));
1159 flutter::DlPath path = path_builder.TakePath();
1160
1161 auto points_bevel =
1162 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1163 path,
1164 {
1165 .width = 20.0f,
1166 .cap = Cap::kButt,
1167 .join = Join::kBevel,
1168 .miter_limit = 4.0f,
1169 },
1170 1.0f);
1171 // Generates no join - because it is a bevel join
1172 EXPECT_EQ(points_bevel.size(), 8u);
1173
1174 auto points_miter =
1175 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1176 path,
1177 {
1178 .width = 20.0f,
1179 .cap = Cap::kButt,
1180 .join = Join::kMiter,
1181 .miter_limit = 400.0f,
1182 },
1183 1.0f);
1184 // Generates no join - even with a very large miter limit
1185 EXPECT_EQ(points_miter.size(), 8u);
1186
1187 auto points_round =
1188 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1189 path,
1190 {
1191 .width = 20.0f,
1192 .cap = Cap::kButt,
1193 .join = Join::kRound,
1194 .miter_limit = 4.0f,
1195 },
1196 1.0f);
1197 // Generates lots of join points - to round off the 180 degree bend
1198 EXPECT_EQ(points_round.size(), 19u);
1199}

References impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kButt, impeller::kMiter, impeller::kRound, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [164/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TwoLineSegmentsInDifferentContoursAreNotJoined   
)

Definition at line 857 of file geometry_unittests.cc.

857 {
858 flutter::DlPathBuilder path_builder;
859 // First contour with a single line.
860 path_builder.MoveTo({20, 20});
861 path_builder.LineTo({30, 20});
862 // Starts a new contour with a MoveTo command. The start of the new contour is
863 // specified to be the same as the end of the previous contour.
864 path_builder.MoveTo({30, 20});
865 // Add a line in the second contour.
866 path_builder.LineTo({30, 30});
867 flutter::DlPath path = path_builder.TakePath();
868
869 auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
870 path,
871 {
872 .width = 10.0f,
873 .cap = Cap::kButt,
874 .join = Join::kBevel,
875 .miter_limit = 4.0f,
876 },
877 1.0f);
878
879 std::vector<Point> expected = {
880 // The points for the first segment (20, 20) -> (30, 20)
881 Point(20, 25),
882 Point(20, 15),
883 Point(30, 25),
884 Point(30, 15),
885
886 // The glue points that allow us to "pick up the pen" between segments.
887 // This prevents segments in different contours from being unintentionally
888 // joined with a bevel.
889 Point(30, 20),
890 Point(30, 20),
891 Point(30, 20),
892 Point(30, 20),
893
894 // The points for the second segment (30, 20) -> (30, 30)
895 Point(25, 20),
896 Point(35, 20),
897 Point(25, 30),
898 Point(35, 30),
899 };
900
901 EXPECT_EQ(points, expected);
902}

References impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kButt, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [165/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TwoLineSegmentsLeftTurnStrokeVerticesBevelJoin   
)

Definition at line 823 of file geometry_unittests.cc.

823 {
824 flutter::DlPathBuilder path_builder;
825 path_builder.MoveTo({20, 20});
826 path_builder.LineTo({30, 20});
827 path_builder.LineTo({30, 10});
828 flutter::DlPath path = path_builder.TakePath();
829
830 auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
831 path,
832 {
833 .width = 10.0f,
834 .cap = Cap::kButt,
835 .join = Join::kBevel,
836 .miter_limit = 4.0f,
837 },
838 1.0f);
839
840 std::vector<Point> expected = {
841 // The points for the first segment (20, 20) -> (30, 20)
842 Point(20, 25),
843 Point(20, 15),
844 Point(30, 25),
845 Point(30, 15),
846
847 // The points for the second segment (30, 20) -> (30, 10)
848 Point(35, 20),
849 Point(25, 20),
850 Point(35, 10),
851 Point(25, 10),
852 };
853
854 EXPECT_EQ(points, expected);
855}

References impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kButt, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [166/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TwoLineSegmentsLeftTurnStrokeVerticesMiterJoin   
)

Definition at line 941 of file geometry_unittests.cc.

941 {
942 flutter::DlPathBuilder path_builder;
943 path_builder.MoveTo({20, 20});
944 path_builder.LineTo({30, 20});
945 path_builder.LineTo({30, 10});
946 flutter::DlPath path = path_builder.TakePath();
947
948 auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
949 path,
950 {
951 .width = 10.0f,
952 .cap = Cap::kButt,
953 .join = Join::kMiter,
954 .miter_limit = 4.0f,
955 },
956 1.0f);
957
958 std::vector<Point> expected = {
959 // The points for the first segment (20, 20) -> (30, 20)
960 Point(20, 25),
961 Point(20, 15),
962 Point(30, 25),
963 Point(30, 15),
964
965 // And one point makes a Miter
966 Point(35, 25),
967
968 // The points for the second segment (120, 20) -> (130, 20)
969 Point(35, 20),
970 Point(25, 20),
971 Point(35, 10),
972 Point(25, 10),
973 };
974
975 EXPECT_EQ(points, expected);
976}

References impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kButt, impeller::kMiter, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [167/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TwoLineSegmentsMiterLimit   
)

Definition at line 1089 of file geometry_unittests.cc.

1089 {
1090 // degrees is the angle that the line deviates from "straight ahead"
1091 for (int degrees = 10; degrees < 180; degrees += 10) {
1092 // Start with a width of 2 since line widths of 1 usually decide
1093 // that they don't need join geometry at a scale of 1.0
1094 for (int width = 2; width <= 10; width++) {
1095 Degrees d(degrees);
1096 Radians r(d);
1097 Point pixel_delta = Point(std::cos(r.radians), std::sin(r.radians));
1098
1099 if (pixel_delta.GetDistance(Point(1, 0)) * width < 1.0f) {
1100 // Some combinations of angle and width result in a join that is
1101 // less than a pixel in size. We don't care about compliance on
1102 // such a small join delta (and, in fact, the implementation may
1103 // decide to elide those small joins).
1104 continue;
1105 }
1106
1107 // Miter limits are based on angle between the vectors/segments
1108 Degrees between(180 - degrees);
1109 Radians r_between(between);
1110 Scalar limit = 1.0f / std::sin(r_between.radians / 2.0f);
1111
1112 flutter::DlPathBuilder path_builder;
1113 path_builder.MoveTo(Point(20, 20));
1114 path_builder.LineTo(Point(30, 20));
1115 path_builder.LineTo(Point(30, 20) + pixel_delta * 10.0f);
1116 flutter::DlPath path = path_builder.TakePath();
1117
1118 // Miter limit too small (99% of required) to allow a miter
1119 auto points1 =
1120 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1121 path,
1122 {
1123 .width = static_cast<Scalar>(width),
1124 .cap = Cap::kButt,
1125 .join = Join::kMiter,
1126 .miter_limit = limit * 0.99f,
1127 },
1128 1.0f);
1129 EXPECT_EQ(points1.size(), 8u)
1130 << "degrees: " << degrees << ", width: " << width << ", "
1131 << points1[4];
1132
1133 // Miter limit large enough (101% of required) to allow a miter
1134 auto points2 =
1135 ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
1136 path,
1137 {
1138 .width = static_cast<Scalar>(width),
1139 .cap = Cap::kButt,
1140 .join = Join::kMiter,
1141 .miter_limit = limit * 1.01f,
1142 },
1143 1.0f);
1144 EXPECT_EQ(points2.size(), 9u)
1145 << "degrees: " << degrees << ", width: " << width;
1146 EXPECT_LE(points2[4].GetDistance({30, 20}), width * limit * 1.05f)
1147 << "degrees: " << degrees << ", width: " << width << ", "
1148 << points2[4];
1149 }
1150 }
1151}
auto & d
Definition main.cc:28

References d, impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kButt, impeller::kMiter, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::Radians::radians, flutter::DlPathBuilder::TakePath(), and width.

◆ TEST() [168/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TwoLineSegmentsRightTurnStrokeVerticesBevelJoin   
)

Definition at line 789 of file geometry_unittests.cc.

789 {
790 flutter::DlPathBuilder path_builder;
791 path_builder.MoveTo({20, 20});
792 path_builder.LineTo({30, 20});
793 path_builder.LineTo({30, 30});
794 flutter::DlPath path = path_builder.TakePath();
795
796 auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
797 path,
798 {
799 .width = 10.0f,
800 .cap = Cap::kButt,
801 .join = Join::kBevel,
802 .miter_limit = 4.0f,
803 },
804 1.0f);
805
806 std::vector<Point> expected = {
807 // The points for the first segment (20, 20) -> (30, 20)
808 Point(20, 25),
809 Point(20, 15),
810 Point(30, 25),
811 Point(30, 15),
812
813 // The points for the second segment (30, 20) -> (30, 30)
814 Point(25, 20),
815 Point(35, 20),
816 Point(25, 30),
817 Point(35, 30),
818 };
819
820 EXPECT_EQ(points, expected);
821}

References impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kBevel, impeller::kButt, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [169/689]

impeller::testing::TEST ( EntityGeometryTest  ,
TwoLineSegmentsRightTurnStrokeVerticesMiterJoin   
)

Definition at line 904 of file geometry_unittests.cc.

904 {
905 flutter::DlPathBuilder path_builder;
906 path_builder.MoveTo({20, 20});
907 path_builder.LineTo({30, 20});
908 path_builder.LineTo({30, 30});
909 flutter::DlPath path = path_builder.TakePath();
910
911 auto points = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(
912 path,
913 {
914 .width = 10.0f,
915 .cap = Cap::kButt,
916 .join = Join::kMiter,
917 .miter_limit = 4.0f,
918 },
919 1.0f);
920
921 std::vector<Point> expected = {
922 // The points for the first segment (20, 20) -> (30, 20)
923 Point(20, 25),
924 Point(20, 15),
925 Point(30, 25),
926 Point(30, 15),
927
928 // And one point makes a Miter
929 Point(35, 15),
930
931 // The points for the second segment (120, 20) -> (130, 20)
932 Point(25, 20),
933 Point(35, 20),
934 Point(25, 30),
935 Point(35, 30),
936 };
937
938 EXPECT_EQ(points, expected);
939}

References impeller::ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices(), impeller::kButt, impeller::kMiter, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [170/689]

impeller::testing::TEST ( EntityGeometryTest  ,
UberSDFGeometryPaddingIsAdjustedByInverseMaxBasis   
)

Definition at line 84 of file geometry_unittests.cc.

84 {
85 UberSDFGeometry geometry(UberSDFParameters::MakeRect(
86 Color::Red(), Rect::MakeLTRB(0, 0, 100, 100), /*stroke=*/std::nullopt));
87
88 // At scale 1, padding should be 1.
89 {
90 auto coverage = geometry.GetCoverage(Matrix());
91 EXPECT_TRUE(coverage.has_value());
92 if (coverage.has_value()) {
93 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(-1, -1, 101, 101));
94 }
95 }
96
97 // At scale 2, padding should be 0.5 in local coordinates, which becomes 1.0
98 // in screen coordinates.
99 {
100 auto matrix = Matrix::MakeScale({2.0, 2.0, 1.0});
101 auto coverage = geometry.GetCoverage(matrix);
102 EXPECT_TRUE(coverage.has_value());
103 if (coverage.has_value()) {
104 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(-0.5, -0.5, 100.5, 100.5)
105 .TransformAndClipBounds(matrix));
106 }
107 }
108
109 // At scale 0.5, padding should be 2.0 in local coordinates, which becomes 1.0
110 // in screen coordinates.
111 {
112 auto matrix = Matrix::MakeScale({0.5, 0.5, 1.0});
113 auto coverage = geometry.GetCoverage(matrix);
114 EXPECT_TRUE(coverage.has_value());
115 if (coverage.has_value()) {
116 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(-2.0, -2.0, 102.0, 102.0)
117 .TransformAndClipBounds(matrix));
118 }
119 }
120}
Geometry for rendering shapes using the UberSDF shader.

References impeller::UberSDFGeometry::GetCoverage(), impeller::TRect< Scalar >::MakeLTRB(), impeller::UberSDFParameters::MakeRect(), impeller::Matrix::MakeScale(), impeller::Color::Red(), and impeller::TRect< T >::TransformAndClipBounds().

◆ TEST() [171/689]

impeller::testing::TEST ( EntityPassClipStackTest  ,
AppendAndRestoreClipCoverage   
)

Definition at line 58 of file clip_stack_unittests.cc.

58 {
59 EntityPassClipStack recorder =
60 EntityPassClipStack(Rect::MakeLTRB(0, 0, 100, 100));
61
62 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
63
64 // Push a clip.
66 recorder.RecordClip(ClipContents(Rect::MakeLTRB(50, 50, 55.5, 55.5),
67 /*is_axis_aligned_rect=*/true),
68 Matrix(), {0, 0}, 0, 100, /*is_aa=*/true);
69 EXPECT_TRUE(result.should_render);
70 EXPECT_TRUE(result.clip_did_change);
71
72 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 2u);
73 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].coverage,
74 Rect::MakeLTRB(50, 50, 55.5, 55.5));
75 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].clip_height, 1u);
76 EXPECT_EQ(recorder.GetReplayEntities().size(), 1u);
77
78 // Restore the clip.
79 recorder.RecordRestore({0, 0}, 0);
80
81 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
82 EXPECT_EQ(recorder.GetClipCoverageLayers()[0].coverage,
83 Rect::MakeSize(Size::MakeWH(100, 100)));
84 EXPECT_EQ(recorder.GetClipCoverageLayers()[0].clip_height, 0u);
85 EXPECT_EQ(recorder.GetReplayEntities().size(), 0u);
86}
A class that tracks all clips that have been recorded in the current entity pass stencil.
const std::vector< ReplayResult > & GetReplayEntities() const
ClipStateResult RecordClip(const ClipContents &clip_contents, Matrix transform, Point global_pass_position, uint32_t clip_depth, size_t clip_height_floor, bool is_aa)
ClipStateResult RecordRestore(Point global_pass_position, size_t restore_height)
const std::vector< ClipCoverageLayer > GetClipCoverageLayers() const

References impeller::EntityPassClipStack::ClipStateResult::clip_did_change, impeller::EntityPassClipStack::GetClipCoverageLayers(), impeller::EntityPassClipStack::GetReplayEntities(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeSize(), impeller::TSize< Scalar >::MakeWH(), impeller::EntityPassClipStack::RecordClip(), impeller::EntityPassClipStack::RecordRestore(), and impeller::EntityPassClipStack::ClipStateResult::should_render.

◆ TEST() [172/689]

impeller::testing::TEST ( EntityPassClipStackTest  ,
AppendAndRestoreClipCoverageNonAA   
)

Definition at line 88 of file clip_stack_unittests.cc.

88 {
89 EntityPassClipStack recorder =
90 EntityPassClipStack(Rect::MakeLTRB(0, 0, 100, 100));
91
92 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
93
94 // Push a clip.
96 recorder.RecordClip(ClipContents(Rect::MakeLTRB(50, 50, 55.4, 55.4),
97 /*is_axis_aligned_rect=*/true),
98 Matrix(), {0, 0}, 0, 100, /*is_aa=*/false);
99 EXPECT_FALSE(result.should_render);
100 EXPECT_TRUE(result.clip_did_change);
101
102 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 2u);
103 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].coverage,
104 Rect::MakeLTRB(50, 50, 55, 55));
105 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].clip_height, 1u);
106 EXPECT_EQ(recorder.GetReplayEntities().size(), 1u);
107
108 // Restore the clip.
109 recorder.RecordRestore({0, 0}, 0);
110
111 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
112 EXPECT_EQ(recorder.GetClipCoverageLayers()[0].coverage,
113 Rect::MakeSize(Size::MakeWH(100, 100)));
114 EXPECT_EQ(recorder.GetClipCoverageLayers()[0].clip_height, 0u);
115 EXPECT_EQ(recorder.GetReplayEntities().size(), 0u);
116}

References impeller::EntityPassClipStack::ClipStateResult::clip_did_change, impeller::EntityPassClipStack::GetClipCoverageLayers(), impeller::EntityPassClipStack::GetReplayEntities(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeSize(), impeller::TSize< Scalar >::MakeWH(), impeller::EntityPassClipStack::RecordClip(), impeller::EntityPassClipStack::RecordRestore(), and impeller::EntityPassClipStack::ClipStateResult::should_render.

◆ TEST() [173/689]

impeller::testing::TEST ( EntityPassClipStackTest  ,
AppendDecreasingSizeClipCoverage   
)

Definition at line 171 of file clip_stack_unittests.cc.

171 {
172 EntityPassClipStack recorder =
173 EntityPassClipStack(Rect::MakeLTRB(0, 0, 100, 100));
174
175 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
176
177 // Push Clips that shrink in size. All should be applied.
178 Entity entity;
179
180 for (auto i = 1; i < 20; i++) {
182 ClipContents(Rect::MakeLTRB(i, i, 99.6 - i, 99.6 - i),
183 /*is_axis_aligned_rect=*/true),
184 Matrix(), {0, 0}, 0, 100, /*is_aa=*/true);
185
186 EXPECT_TRUE(result.should_render);
187 EXPECT_TRUE(result.clip_did_change);
188 EXPECT_EQ(recorder.CurrentClipCoverage(),
189 Rect::MakeLTRB(i, i, 99.6 - i, 99.6 - i));
190 }
191}
std::optional< Rect > CurrentClipCoverage() const

References impeller::EntityPassClipStack::ClipStateResult::clip_did_change, impeller::EntityPassClipStack::CurrentClipCoverage(), impeller::EntityPassClipStack::GetClipCoverageLayers(), i, impeller::TRect< Scalar >::MakeLTRB(), impeller::EntityPassClipStack::RecordClip(), and impeller::EntityPassClipStack::ClipStateResult::should_render.

◆ TEST() [174/689]

impeller::testing::TEST ( EntityPassClipStackTest  ,
AppendIncreasingSizeClipCoverage   
)

Definition at line 193 of file clip_stack_unittests.cc.

193 {
194 EntityPassClipStack recorder =
195 EntityPassClipStack(Rect::MakeLTRB(0, 0, 100, 100));
196
197 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
198
199 // Push Clips that grow in size. All should be skipped.
200
201 for (auto i = 1; i < 20; i++) {
203 ClipContents(Rect::MakeLTRB(0 - i, 0 - i, 100 + i, 100 + i),
204 /*is_axis_aligned_rect=*/true),
205 Matrix(), {0, 0}, 0, 100, /*is_aa=*/true);
206
207 EXPECT_FALSE(result.should_render);
208 EXPECT_FALSE(result.clip_did_change);
209 EXPECT_EQ(recorder.CurrentClipCoverage(), Rect::MakeLTRB(0, 0, 100, 100));
210 }
211}

References impeller::EntityPassClipStack::ClipStateResult::clip_did_change, impeller::EntityPassClipStack::CurrentClipCoverage(), impeller::EntityPassClipStack::GetClipCoverageLayers(), i, impeller::TRect< Scalar >::MakeLTRB(), impeller::EntityPassClipStack::RecordClip(), and impeller::EntityPassClipStack::ClipStateResult::should_render.

◆ TEST() [175/689]

impeller::testing::TEST ( EntityPassClipStackTest  ,
AppendLargerClipCoverage   
)

Definition at line 120 of file clip_stack_unittests.cc.

120 {
121 EntityPassClipStack recorder =
122 EntityPassClipStack(Rect::MakeLTRB(0, 0, 100, 100));
123
124 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
125
126 // Push a clip.
128 recorder.RecordClip(ClipContents(Rect::MakeLTRB(50, 50, 55.5, 55.5),
129 /*is_axis_aligned_rect=*/true),
130 Matrix(), {0, 0}, 0, 100, /*is_aa=*/true);
131
132 EXPECT_TRUE(result.should_render);
133 EXPECT_TRUE(result.clip_did_change);
134
135 // Push a clip with larger coverage than the previous state.
136 result = recorder.RecordClip(ClipContents(Rect::MakeLTRB(0, 0, 100.5, 100.5),
137 /*is_axis_aligned_rect=*/true),
138 Matrix(), {0, 0}, 1, 100, /*is_aa=*/true);
139
140 EXPECT_FALSE(result.should_render);
141 EXPECT_FALSE(result.clip_did_change);
142}

References impeller::EntityPassClipStack::ClipStateResult::clip_did_change, impeller::EntityPassClipStack::GetClipCoverageLayers(), impeller::TRect< Scalar >::MakeLTRB(), impeller::EntityPassClipStack::RecordClip(), and impeller::EntityPassClipStack::ClipStateResult::should_render.

◆ TEST() [176/689]

impeller::testing::TEST ( EntityPassClipStackTest  ,
AppendLargerClipCoverageWithDifferenceOrNonSquare   
)

Definition at line 146 of file clip_stack_unittests.cc.

147 {
148 EntityPassClipStack recorder =
149 EntityPassClipStack(Rect::MakeLTRB(0, 0, 100, 100));
150
151 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
152
153 // Push a clip.
155 recorder.RecordClip(ClipContents(Rect::MakeLTRB(50, 50, 55, 55),
156 /*is_axis_aligned_rect=*/true),
157 Matrix(), {0, 0}, 0, 100, /*is_aa=*/true);
158
159 EXPECT_FALSE(result.should_render);
160 EXPECT_TRUE(result.clip_did_change);
161
162 // Push a clip with larger coverage than the previous state.
163 result = recorder.RecordClip(ClipContents(Rect::MakeLTRB(0, 0, 100, 100),
164 /*is_axis_aligned_rect=*/false),
165 Matrix(), {0, 0}, 0, 100, /*is_aa=*/true);
166
167 EXPECT_TRUE(result.should_render);
168 EXPECT_TRUE(result.clip_did_change);
169}

References impeller::EntityPassClipStack::ClipStateResult::clip_did_change, impeller::EntityPassClipStack::GetClipCoverageLayers(), impeller::TRect< Scalar >::MakeLTRB(), impeller::EntityPassClipStack::RecordClip(), and impeller::EntityPassClipStack::ClipStateResult::should_render.

◆ TEST() [177/689]

impeller::testing::TEST ( EntityPassClipStackTest  ,
CanPopEntitiesSafely   
)

Definition at line 48 of file clip_stack_unittests.cc.

48 {
49 EntityPassClipStack recorder =
50 EntityPassClipStack(Rect::MakeLTRB(0, 0, 100, 100));
51
52 EXPECT_TRUE(recorder.GetReplayEntities().empty());
53
54 recorder.RecordRestore({0, 0}, 0);
55 EXPECT_TRUE(recorder.GetReplayEntities().empty());
56}

References impeller::EntityPassClipStack::GetReplayEntities(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::EntityPassClipStack::RecordRestore().

◆ TEST() [178/689]

impeller::testing::TEST ( EntityPassClipStackTest  ,
CanPushAndPopEntities   
)

Definition at line 14 of file clip_stack_unittests.cc.

14 {
15 EntityPassClipStack recorder =
16 EntityPassClipStack(Rect::MakeLTRB(0, 0, 100, 100));
17
18 EXPECT_TRUE(recorder.GetReplayEntities().empty());
19
20 recorder.RecordClip(ClipContents(Rect::MakeLTRB(0, 0, 100, 100),
21 /*is_axis_aligned_rect=*/false),
22 Matrix(), {0, 0}, 0, 100, /*is_aa=*/true);
23
24 EXPECT_EQ(recorder.GetReplayEntities().size(), 1u);
25
26 recorder.RecordClip(ClipContents(Rect::MakeLTRB(0, 0, 50.5, 50.5),
27 /*is_axis_aligned_rect=*/true),
28 Matrix(), {0, 0}, 2, 100, /*is_aa=*/true);
29
30 EXPECT_EQ(recorder.GetReplayEntities().size(), 2u);
31 ASSERT_TRUE(recorder.GetReplayEntities()[0].clip_coverage.has_value());
32 ASSERT_TRUE(recorder.GetReplayEntities()[1].clip_coverage.has_value());
33
34 // NOLINTBEGIN(bugprone-unchecked-optional-access)
35 EXPECT_EQ(recorder.GetReplayEntities()[0].clip_coverage.value(),
36 Rect::MakeLTRB(0, 0, 100, 100));
37 EXPECT_EQ(recorder.GetReplayEntities()[1].clip_coverage.value(),
38 Rect::MakeLTRB(0, 0, 50.5, 50.5));
39 // NOLINTEND(bugprone-unchecked-optional-access)
40
41 recorder.RecordRestore({0, 0}, 1);
42 EXPECT_EQ(recorder.GetReplayEntities().size(), 1u);
43
44 recorder.RecordRestore({0, 0}, 0);
45 EXPECT_TRUE(recorder.GetReplayEntities().empty());
46}

References impeller::EntityPassClipStack::GetReplayEntities(), impeller::TRect< Scalar >::MakeLTRB(), impeller::EntityPassClipStack::RecordClip(), and impeller::EntityPassClipStack::RecordRestore().

◆ TEST() [179/689]

impeller::testing::TEST ( EntityPassClipStackTest  ,
ClipAndRestoreWithSubpasses   
)

Definition at line 232 of file clip_stack_unittests.cc.

232 {
233 EntityPassClipStack recorder =
234 EntityPassClipStack(Rect::MakeLTRB(0, 0, 100, 100));
235
236 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
237
238 // Push a clip.
239 {
241 recorder.RecordClip(ClipContents(Rect::MakeLTRB(50, 50, 55.5, 55.5),
242 /*is_axis_aligned_rect=*/true),
243 Matrix(), {0, 0}, 0, 100, /*is_aa=*/true);
244
245 EXPECT_TRUE(result.should_render);
246 EXPECT_TRUE(result.clip_did_change);
247 }
248
249 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 2u);
250 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].coverage,
251 Rect::MakeLTRB(50, 50, 55.5, 55.5));
252 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].clip_height, 1u);
253 EXPECT_EQ(recorder.GetReplayEntities().size(), 1u);
254
255 // Begin a subpass.
256 recorder.PushSubpass(Rect::MakeLTRB(50, 50, 55, 55), 1);
257 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
258 EXPECT_EQ(recorder.GetClipCoverageLayers()[0].coverage,
259 Rect::MakeLTRB(50, 50, 55, 55));
260
261 {
262 EntityPassClipStack::ClipStateResult result =
263 recorder.RecordClip(ClipContents(Rect::MakeLTRB(54, 54, 54.5, 54.5),
264 /*is_axis_aligned_rect=*/true),
265 Matrix(), {0, 0}, 0, 100, /*is_aa=*/true);
266
267 EXPECT_TRUE(result.should_render);
268 EXPECT_TRUE(result.clip_did_change);
269 }
270
271 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].coverage,
272 Rect::MakeLTRB(54, 54, 54.5, 54.5));
273
274 // End subpass.
275 recorder.PopSubpass();
276
277 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].coverage,
278 Rect::MakeLTRB(50, 50, 55.5, 55.5));
279}
void PushSubpass(std::optional< Rect > subpass_coverage, size_t clip_height)

References impeller::EntityPassClipStack::ClipStateResult::clip_did_change, impeller::EntityPassClipStack::GetClipCoverageLayers(), impeller::EntityPassClipStack::GetReplayEntities(), impeller::TRect< Scalar >::MakeLTRB(), impeller::EntityPassClipStack::PopSubpass(), impeller::EntityPassClipStack::PushSubpass(), impeller::EntityPassClipStack::RecordClip(), and impeller::EntityPassClipStack::ClipStateResult::should_render.

◆ TEST() [180/689]

impeller::testing::TEST ( EntityPassClipStackTest  ,
ClipAndRestoreWithSubpassesNonAA   
)

Definition at line 281 of file clip_stack_unittests.cc.

281 {
282 EntityPassClipStack recorder =
283 EntityPassClipStack(Rect::MakeLTRB(0, 0, 100, 100));
284
285 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
286
287 // Push a clip.
288 {
290 recorder.RecordClip(ClipContents(Rect::MakeLTRB(50, 50, 55.4, 55.4),
291 /*is_axis_aligned_rect=*/true),
292 Matrix(), {0, 0}, 0, 100, /*is_aa=*/false);
293
294 EXPECT_FALSE(result.should_render);
295 EXPECT_TRUE(result.clip_did_change);
296 }
297
298 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 2u);
299 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].coverage,
300 Rect::MakeLTRB(50, 50, 55.0, 55.0));
301 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].clip_height, 1u);
302 EXPECT_EQ(recorder.GetReplayEntities().size(), 1u);
303
304 // Begin a subpass.
305 recorder.PushSubpass(Rect::MakeLTRB(50, 50, 55, 55), 1);
306 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
307 EXPECT_EQ(recorder.GetClipCoverageLayers()[0].coverage,
308 Rect::MakeLTRB(50, 50, 55, 55));
309
310 {
311 EntityPassClipStack::ClipStateResult result =
312 recorder.RecordClip(ClipContents(Rect::MakeLTRB(54, 54, 55.4, 55.4),
313 /*is_axis_aligned_rect=*/true),
314 Matrix(), {0, 0}, 0, 100, /*is_aa=*/false);
315
316 EXPECT_FALSE(result.should_render);
317 EXPECT_TRUE(result.clip_did_change);
318 }
319
320 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].coverage,
321 Rect::MakeLTRB(54, 54, 55.0, 55.0));
322
323 // End subpass.
324 recorder.PopSubpass();
325
326 EXPECT_EQ(recorder.GetClipCoverageLayers()[1].coverage,
327 Rect::MakeLTRB(50, 50, 55, 55));
328}

References impeller::EntityPassClipStack::ClipStateResult::clip_did_change, impeller::EntityPassClipStack::GetClipCoverageLayers(), impeller::EntityPassClipStack::GetReplayEntities(), impeller::TRect< Scalar >::MakeLTRB(), impeller::EntityPassClipStack::PopSubpass(), impeller::EntityPassClipStack::PushSubpass(), impeller::EntityPassClipStack::RecordClip(), and impeller::EntityPassClipStack::ClipStateResult::should_render.

◆ TEST() [181/689]

impeller::testing::TEST ( EntityPassClipStackTest  ,
UnbalancedRestore   
)

Definition at line 213 of file clip_stack_unittests.cc.

213 {
214 EntityPassClipStack recorder =
215 EntityPassClipStack(Rect::MakeLTRB(0, 0, 100, 100));
216
217 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
218
219 // Restore the clip.
221 recorder.RecordRestore(Point(0, 0), 0);
222 EXPECT_FALSE(result.should_render);
223 EXPECT_FALSE(result.clip_did_change);
224
225 ASSERT_EQ(recorder.GetClipCoverageLayers().size(), 1u);
226 EXPECT_EQ(recorder.GetClipCoverageLayers()[0].coverage,
227 Rect::MakeSize(Size::MakeWH(100, 100)));
228 EXPECT_EQ(recorder.GetClipCoverageLayers()[0].clip_height, 0u);
229 EXPECT_EQ(recorder.GetReplayEntities().size(), 0u);
230}

References impeller::EntityPassClipStack::ClipStateResult::clip_did_change, impeller::EntityPassClipStack::GetClipCoverageLayers(), impeller::EntityPassClipStack::GetReplayEntities(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeSize(), impeller::TSize< Scalar >::MakeWH(), impeller::EntityPassClipStack::RecordRestore(), and impeller::EntityPassClipStack::ClipStateResult::should_render.

◆ TEST() [182/689]

impeller::testing::TEST ( EntityTest  ,
UberSDFContentsCoverageFillCircle   
)

Definition at line 1272 of file entity_unittests.cc.

1272 {
1273 auto params =
1274 UberSDFParameters::MakeCircle(Color::Red(), /*center=*/{50, 50},
1275 /*radius=*/10.0f, /*stroke=*/std::nullopt);
1276 auto geometry = std::make_unique<UberSDFGeometry>(params);
1277 auto contents = UberSDFContents::Make(params, std::move(geometry));
1278
1279 Entity entity;
1280 auto coverage = contents->GetCoverage(entity);
1281 ASSERT_TRUE(coverage.has_value());
1283 coverage.value(),
1284 Rect::MakeXYWH(40, 40, 20, 20).Expand(1.0f)); // expanded by AA
1285}
std::optional< Rect > GetCoverage() const
Definition entity.cc:66
const EmbeddedViewParams * params
#define ASSERT_RECT_NEAR(a, b)

References ASSERT_RECT_NEAR, impeller::TRect< T >::Expand(), impeller::Entity::GetCoverage(), impeller::UberSDFContents::Make(), impeller::UberSDFParameters::MakeCircle(), impeller::TRect< Scalar >::MakeXYWH(), params, and impeller::Color::Red().

◆ TEST() [183/689]

impeller::testing::TEST ( EntityTest  ,
UberSDFContentsCoverageFillRect   
)

Definition at line 1242 of file entity_unittests.cc.

1242 {
1243 auto rect = Rect::MakeXYWH(100, 100, 200, 200);
1244 auto params =
1245 UberSDFParameters::MakeRect(Color::Red(), rect, /*stroke=*/std::nullopt);
1246 auto geometry = std::make_unique<UberSDFGeometry>(params);
1247 auto contents = UberSDFContents::Make(params, std::move(geometry));
1248
1249 Entity entity;
1250 auto coverage = contents->GetCoverage(entity);
1251 ASSERT_TRUE(coverage.has_value());
1253 coverage.value(),
1254 Rect::MakeXYWH(100, 100, 200, 200).Expand(1.0f)); // expanded by AA
1255}

References ASSERT_RECT_NEAR, impeller::TRect< T >::Expand(), impeller::Entity::GetCoverage(), impeller::UberSDFContents::Make(), impeller::UberSDFParameters::MakeRect(), impeller::TRect< Scalar >::MakeXYWH(), params, and impeller::Color::Red().

◆ TEST() [184/689]

impeller::testing::TEST ( EntityTest  ,
UberSDFContentsCoverageStrokeCircle   
)

Definition at line 1287 of file entity_unittests.cc.

1287 {
1288 auto params = UberSDFParameters::MakeCircle(Color::Red(), /*center=*/{50, 50},
1289 /*radius=*/10.0f,
1290 StrokeParameters{.width = 4.0f});
1291 auto geometry = std::make_unique<UberSDFGeometry>(params);
1292 auto contents = UberSDFContents::Make(params, std::move(geometry));
1293
1294 Entity entity;
1295 auto coverage = contents->GetCoverage(entity);
1296 ASSERT_TRUE(coverage.has_value());
1297 ASSERT_RECT_NEAR(coverage.value(),
1298 Rect::MakeXYWH(40, 40, 20, 20)
1299 .Expand(3.0f)); // expanded by half stroke width + AA
1300}

References ASSERT_RECT_NEAR, impeller::TRect< T >::Expand(), impeller::Entity::GetCoverage(), impeller::UberSDFContents::Make(), impeller::UberSDFParameters::MakeCircle(), impeller::TRect< Scalar >::MakeXYWH(), params, impeller::Color::Red(), and impeller::StrokeParameters::width.

◆ TEST() [185/689]

impeller::testing::TEST ( EntityTest  ,
UberSDFContentsCoverageStrokeRect   
)

Definition at line 1257 of file entity_unittests.cc.

1257 {
1258 auto rect = Rect::MakeXYWH(100, 100, 200, 200);
1259 auto params = UberSDFParameters::MakeRect(Color::Red(), rect,
1260 StrokeParameters{.width = 4.0f});
1261 auto geometry = std::make_unique<UberSDFGeometry>(params);
1262 auto contents = UberSDFContents::Make(params, std::move(geometry));
1263
1264 Entity entity;
1265 auto coverage = contents->GetCoverage(entity);
1266 ASSERT_TRUE(coverage.has_value());
1267 ASSERT_RECT_NEAR(coverage.value(),
1268 Rect::MakeXYWH(100, 100, 200, 200)
1269 .Expand(3.0f)); // expanded by half stroke width + AA
1270}

References ASSERT_RECT_NEAR, impeller::TRect< T >::Expand(), impeller::Entity::GetCoverage(), impeller::UberSDFContents::Make(), impeller::UberSDFParameters::MakeRect(), impeller::TRect< Scalar >::MakeXYWH(), params, impeller::Color::Red(), and impeller::StrokeParameters::width.

◆ TEST() [186/689]

impeller::testing::TEST ( FenceWaiterVKTest  ,
AddFenceDoesNothingIfTerminating   
)

Definition at line 121 of file fence_waiter_vk_unittests.cc.

121 {
122 auto signal = fml::ManualResetWaitableEvent();
123
124 {
125 auto const context = MockVulkanContextBuilder().Build();
126 auto const device = context->GetDevice();
127 auto const waiter = context->GetFenceWaiter();
128 waiter->Terminate();
129
130 auto fence = device.createFenceUnique({}).value;
131 waiter->AddFence(std::move(fence), default_submit_callback,
132 [&signal]() { signal.Signal(); });
133 }
134
135 // Ensure the fence did _not_ signal.
136 EXPECT_TRUE(signal.WaitWithTimeout(fml::TimeDelta::FromMilliseconds(100)));
137}
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition time_delta.h:46

References impeller::testing::MockVulkanContextBuilder::Build(), context, device, fml::TimeDelta::FromMilliseconds(), and value.

◆ TEST() [187/689]

impeller::testing::TEST ( FenceWaiterVKTest  ,
ExecutesFenceCallback   
)

Definition at line 51 of file fence_waiter_vk_unittests.cc.

51 {
52 auto const context = MockVulkanContextBuilder().Build();
53 auto const device = context->GetDevice();
54 auto const waiter = context->GetFenceWaiter();
55
56 bool submit_called = false;
57 auto submit_callback = [&](vk::Fence) {
58 submit_called = true;
59 return fml::Status();
60 };
61
62 auto signal = fml::ManualResetWaitableEvent();
63 auto fence = device.createFenceUnique({}).value;
64 waiter->AddFence(std::move(fence), submit_callback,
65 [&signal]() { signal.Signal(); });
66 EXPECT_TRUE(submit_called);
67
68 signal.Wait();
69}

References impeller::testing::MockVulkanContextBuilder::Build(), context, device, and value.

◆ TEST() [188/689]

impeller::testing::TEST ( FenceWaiterVKTest  ,
ExecutesFenceCallbackX2   
)

Definition at line 71 of file fence_waiter_vk_unittests.cc.

71 {
72 auto const context = MockVulkanContextBuilder().Build();
73 auto const device = context->GetDevice();
74 auto const waiter = context->GetFenceWaiter();
75
76 auto signal = fml::ManualResetWaitableEvent();
77 auto fence = device.createFenceUnique({}).value;
78 waiter->AddFence(std::move(fence), default_submit_callback,
79 [&signal]() { signal.Signal(); });
80
81 auto signal2 = fml::ManualResetWaitableEvent();
82 auto fence2 = device.createFenceUnique({}).value;
83 waiter->AddFence(std::move(fence2), default_submit_callback,
84 [&signal2]() { signal2.Signal(); });
85
86 signal.Wait();
87 signal2.Wait();
88}

References impeller::testing::MockVulkanContextBuilder::Build(), context, device, and value.

◆ TEST() [189/689]

impeller::testing::TEST ( FenceWaiterVKTest  ,
ExecutesNewFenceThenOldFence   
)

Definition at line 90 of file fence_waiter_vk_unittests.cc.

90 {
91 auto const context = MockVulkanContextBuilder().Build();
92 auto const device = context->GetDevice();
93 auto const waiter = context->GetFenceWaiter();
94
95 auto signal = fml::ManualResetWaitableEvent();
96 auto fence = device.createFenceUnique({}).value;
97 MockFence::SetStatus(fence, vk::Result::eNotReady);
98 auto raw_fence = MockFence::GetRawPointer(fence);
99 waiter->AddFence(std::move(fence), default_submit_callback,
100 [&signal]() { signal.Signal(); });
101
102 // The easiest way to verify that the callback was _not_ called is to wait
103 // for a timeout, but that could introduce flakiness. Instead, we'll add a
104 // second fence that will signal immediately, and wait for that one instead.
105 {
106 auto signal2 = fml::ManualResetWaitableEvent();
107 auto fence2 = device.createFenceUnique({}).value;
108 MockFence::SetStatus(fence2, vk::Result::eSuccess);
109 waiter->AddFence(std::move(fence2), default_submit_callback,
110 [&signal2]() { signal2.Signal(); });
111 signal2.Wait();
112 }
113
114 // Now, we'll signal the first fence, and wait for the callback to be called.
115 raw_fence->SetStatus(vk::Result::eSuccess);
116
117 // Now, we'll signal the first fence, and wait for the callback to be called.
118 signal.Wait();
119}

References impeller::testing::MockVulkanContextBuilder::Build(), context, device, impeller::testing::MockFence::GetRawPointer(), impeller::testing::MockFence::SetStatus(), and value.

◆ TEST() [190/689]

impeller::testing::TEST ( FenceWaiterVKTest  ,
IgnoresNullCallback   
)

Definition at line 25 of file fence_waiter_vk_unittests.cc.

25 {
26 auto const context = MockVulkanContextBuilder().Build();
27 auto const device = context->GetDevice();
28 auto const waiter = context->GetFenceWaiter();
29
30 auto fence = device.createFenceUnique({}).value;
31 const auto add_status =
32 waiter->AddFence(std::move(fence), default_submit_callback, nullptr);
33 EXPECT_EQ(add_status.code(), fml::StatusCode::kInvalidArgument);
34}

References impeller::testing::MockVulkanContextBuilder::Build(), context, device, fml::kInvalidArgument, and value.

◆ TEST() [191/689]

impeller::testing::TEST ( FenceWaiterVKTest  ,
IgnoresNullFence   
)

Definition at line 17 of file fence_waiter_vk_unittests.cc.

17 {
18 auto const context = MockVulkanContextBuilder().Build();
19 auto const waiter = context->GetFenceWaiter();
20 const auto add_status =
21 waiter->AddFence(vk::UniqueFence(), default_submit_callback, []() {});
22 EXPECT_EQ(add_status.code(), fml::StatusCode::kInvalidArgument);
23}

References impeller::testing::MockVulkanContextBuilder::Build(), context, and fml::kInvalidArgument.

◆ TEST() [192/689]

impeller::testing::TEST ( FenceWaiterVKTest  ,
InProgressFencesStillWaitIfTerminated   
)

Definition at line 139 of file fence_waiter_vk_unittests.cc.

139 {
140 MockFence* raw_fence = nullptr;
141 auto signal = fml::ManualResetWaitableEvent();
142
143 auto const context = MockVulkanContextBuilder().Build();
144 auto const device = context->GetDevice();
145 auto const waiter = context->GetFenceWaiter();
146
147 // Add a fence that isn't signalled yet.
148 auto fence = device.createFenceUnique({}).value;
149
150 // Even if the fence is eSuccess, it's not guaranteed to be called in time.
151 MockFence::SetStatus(fence, vk::Result::eNotReady);
152 raw_fence = MockFence::GetRawPointer(fence);
153 waiter->AddFence(std::move(fence), default_submit_callback,
154 [&signal]() { signal.Signal(); });
155
156 // Signal the fence after a delay.
157 std::thread thread([&]() {
158 std::this_thread::sleep_for(std::chrono::milliseconds{100u});
159 raw_fence->SetStatus(vk::Result::eSuccess);
160 });
161
162 // Terminate the waiter. This will block until all pending fences are
163 // signalled.
164 waiter->Terminate();
165
166 // This will hang if the fence was not signalled.
167 signal.Wait();
168
169 thread.join();
170}
void SetStatus(vk::Result result)
Definition mock_vulkan.h:33

References impeller::testing::MockVulkanContextBuilder::Build(), context, device, impeller::testing::MockFence::GetRawPointer(), impeller::testing::MockFence::SetStatus(), and value.

◆ TEST() [193/689]

impeller::testing::TEST ( FenceWaiterVKTest  ,
ReturnsSubmitError   
)

Definition at line 36 of file fence_waiter_vk_unittests.cc.

36 {
37 auto const context = MockVulkanContextBuilder().Build();
38 auto const device = context->GetDevice();
39 auto const waiter = context->GetFenceWaiter();
40
41 auto submit_callback = [&](vk::Fence) {
42 return fml::Status(fml::StatusCode::kCancelled, "Submit failed");
43 };
44
45 auto fence = device.createFenceUnique({}).value;
46 const auto add_status =
47 waiter->AddFence(std::move(fence), submit_callback, []() {});
48 EXPECT_EQ(add_status.code(), fml::StatusCode::kCancelled);
49}

References impeller::testing::MockVulkanContextBuilder::Build(), context, device, fml::kCancelled, and value.

◆ TEST() [194/689]

impeller::testing::TEST ( FilterInputTest  ,
CanSetLocalTransformForTexture   
)

Definition at line 15 of file filter_input_unittests.cc.

15 {
16 std::shared_ptr<Texture> texture = nullptr;
17 auto input =
18 FilterInput::Make(texture, Matrix::MakeTranslation({1.0, 0.0, 0.0}));
19 Entity e;
20 e.SetTransform(Matrix::MakeTranslation({0.0, 2.0, 0.0}));
21
22 ASSERT_MATRIX_NEAR(input->GetLocalTransform(e),
23 Matrix::MakeTranslation({1.0, 0.0, 0.0}));
24 ASSERT_MATRIX_NEAR(input->GetTransform(e),
25 Matrix::MakeTranslation({1.0, 2.0, 0.0}));
26}
void SetTransform(const Matrix &transform)
Set the global transform matrix for this Entity.
Definition entity.cc:62
static int input(yyscan_t yyscanner)
#define ASSERT_MATRIX_NEAR(a, b)

References ASSERT_MATRIX_NEAR, input(), impeller::FilterInput::Make(), impeller::Matrix::MakeTranslation(), impeller::Entity::SetTransform(), and texture.

◆ TEST() [195/689]

impeller::testing::TEST ( FormatsGLES  ,
CanFormatFramebufferErrorMessage   
)

Definition at line 12 of file formats_gles_unittests.cc.

12 {
13 ASSERT_EQ(DebugToFramebufferError(GL_FRAMEBUFFER_UNDEFINED),
14 "GL_FRAMEBUFFER_UNDEFINED");
15 ASSERT_EQ(DebugToFramebufferError(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
16 "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
17 ASSERT_EQ(
18 DebugToFramebufferError(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT),
19 "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
20 ASSERT_EQ(DebugToFramebufferError(GL_FRAMEBUFFER_UNSUPPORTED),
21 "GL_FRAMEBUFFER_UNSUPPORTED");
22 ASSERT_EQ(DebugToFramebufferError(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE),
23 "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE");
24 ASSERT_EQ(DebugToFramebufferError(0), "Unknown error code: 0");
25}
std::string DebugToFramebufferError(int status)

References impeller::DebugToFramebufferError().

◆ TEST() [196/689]

impeller::testing::TEST ( FormatsVKTest  ,
DescriptorMapping   
)

Definition at line 11 of file formats_vk_unittests.cc.

11 {
12 EXPECT_EQ(ToVKDescriptorType(DescriptorType::kSampledImage),
13 vk::DescriptorType::eCombinedImageSampler);
14 EXPECT_EQ(ToVKDescriptorType(DescriptorType::kUniformBuffer),
15 vk::DescriptorType::eUniformBuffer);
16 EXPECT_EQ(ToVKDescriptorType(DescriptorType::kStorageBuffer),
17 vk::DescriptorType::eStorageBuffer);
18 EXPECT_EQ(ToVKDescriptorType(DescriptorType::kImage),
19 vk::DescriptorType::eSampledImage);
20 EXPECT_EQ(ToVKDescriptorType(DescriptorType::kSampler),
21 vk::DescriptorType::eSampler);
22 EXPECT_EQ(ToVKDescriptorType(DescriptorType::kInputAttachment),
23 vk::DescriptorType::eInputAttachment);
24}
constexpr vk::DescriptorType ToVKDescriptorType(DescriptorType type)
Definition formats_vk.h:328

References impeller::kImage, impeller::kInputAttachment, impeller::kSampledImage, impeller::kSampler, impeller::kStorageBuffer, impeller::kUniformBuffer, and impeller::ToVKDescriptorType().

◆ TEST() [197/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
CalculateSigmaForBlurRadius   
)

Definition at line 490 of file gaussian_blur_filter_contents_unittests.cc.

490 {
491 Scalar sigma = 1.0;
492 Scalar radius = GaussianBlurFilterContents::CalculateBlurRadius(
493 GaussianBlurFilterContents::ScaleSigma(sigma));
494 fml::StatusOr<Scalar> derived_sigma =
495 CalculateSigmaForBlurRadius(radius, Matrix());
496 ASSERT_TRUE(derived_sigma.ok());
497 EXPECT_NEAR(sigma, derived_sigma.value(), 0.01f);
498}
const T & value() const
Definition status_or.h:77
bool ok() const
Definition status_or.h:75

References impeller::GaussianBlurFilterContents::CalculateBlurRadius(), fml::StatusOr< T >::ok(), impeller::GaussianBlurFilterContents::ScaleSigma(), and fml::StatusOr< T >::value().

◆ TEST() [198/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
CalculateSigmaValues   
)

Definition at line 252 of file gaussian_blur_filter_contents_unittests.cc.

252 {
253 EXPECT_EQ(GaussianBlurFilterContents::CalculateScale(1.0f), 1);
254 EXPECT_EQ(GaussianBlurFilterContents::CalculateScale(2.0f), 1);
255 EXPECT_EQ(GaussianBlurFilterContents::CalculateScale(3.0f), 1);
256 EXPECT_EQ(GaussianBlurFilterContents::CalculateScale(4.0f), 1);
257 EXPECT_EQ(GaussianBlurFilterContents::CalculateScale(16.0f), 0.25);
258 // Hang on to 1/8 as long as possible.
259 EXPECT_EQ(GaussianBlurFilterContents::CalculateScale(95.0f), 0.125);
260 EXPECT_EQ(GaussianBlurFilterContents::CalculateScale(96.0f), 0.0625);
261 // Downsample clamped to 1/16th.
262 EXPECT_EQ(GaussianBlurFilterContents::CalculateScale(1024.0f), 0.0625);
263}

References impeller::GaussianBlurFilterContents::CalculateScale().

◆ TEST() [199/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
ChopHugeBlurs   
)

Definition at line 658 of file gaussian_blur_filter_contents_unittests.cc.

658 {
659 Scalar sigma = 30.5f;
660 int32_t blur_radius = static_cast<int32_t>(
661 std::ceil(GaussianBlurFilterContents::CalculateBlurRadius(sigma)));
662 BlurParameters parameters = {.blur_uv_offset = Point(1, 0),
663 .blur_sigma = sigma,
664 .blur_radius = blur_radius,
665 .step_size = 1};
666 KernelSamples kernel_samples = GenerateBlurInfo(parameters);
667 LerpHackResult frag_kernel_samples = LerpHackKernelSamples(kernel_samples);
668 EXPECT_TRUE(frag_kernel_samples.sample_count <= kGaussianBlurMaxKernelSize);
669}
Vector2 blur_radius
Blur radius in source pixels based on scaled_sigma.
LerpHackResult LerpHackKernelSamples(const KernelSamples &parameters)
KernelSamples GenerateBlurInfo(BlurParameters parameters)

References blur_radius, impeller::BlurParameters::blur_uv_offset, impeller::GaussianBlurFilterContents::CalculateBlurRadius(), impeller::GenerateBlurInfo(), impeller::kGaussianBlurMaxKernelSize, impeller::LerpHackKernelSamples(), and impeller::LerpHackResult::sample_count.

◆ TEST() [200/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
Coefficients   
)

Definition at line 500 of file gaussian_blur_filter_contents_unittests.cc.

500 {
501 BlurParameters parameters = {.blur_uv_offset = Point(1, 0),
502 .blur_sigma = 1,
503 .blur_radius = 5,
504 .step_size = 1};
505 KernelSamples samples = GenerateBlurInfo(parameters);
506 EXPECT_EQ(samples.sample_count, 11);
507
508 // Coefficients should add up to 1.
509 Scalar tally = 0;
510 for (int i = 0; i < samples.sample_count; ++i) {
511 tally += samples.samples[i].coefficient;
512 }
513 EXPECT_FLOAT_EQ(tally, 1.0f);
514
515 // Verify the shape of the curve.
516 for (int i = 0; i < 4; ++i) {
517 EXPECT_FLOAT_EQ(samples.samples[i].coefficient,
518 samples.samples[10 - i].coefficient);
519 EXPECT_TRUE(samples.samples[i + 1].coefficient >
520 samples.samples[i].coefficient);
521 }
522}
KernelSample samples[kMaxKernelSize]

References impeller::BlurParameters::blur_uv_offset, impeller::KernelSample::coefficient, impeller::GenerateBlurInfo(), i, impeller::KernelSamples::sample_count, and impeller::KernelSamples::samples.

◆ TEST() [201/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
CoverageEmpty   
)

Definition at line 122 of file gaussian_blur_filter_contents_unittests.cc.

122 {
124 /*sigma_x=*/0.0, /*sigma_y=*/0.0, Entity::TileMode::kDecal,
125 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
126 /*mask_geometry=*/nullptr);
127 FilterInput::Vector inputs = {};
128 Entity entity;
129 std::optional<Rect> coverage =
130 contents.GetFilterCoverage(inputs, entity, /*effect_transform=*/Matrix());
131 ASSERT_FALSE(coverage.has_value());
132}
std::vector< FilterInput::Ref > Vector
Performs a bidirectional Gaussian blur.

References impeller::GaussianBlurFilterContents::GetFilterCoverage(), impeller::Entity::kDecal, and impeller::FilterContents::kNormal.

◆ TEST() [202/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
CoverageSimple   
)

Definition at line 134 of file gaussian_blur_filter_contents_unittests.cc.

134 {
136 /*sigma_x=*/0.0, /*sigma_y=*/0.0, Entity::TileMode::kDecal,
137 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
138 /*mask_geometry=*/nullptr);
139 FilterInput::Vector inputs = {
140 FilterInput::Make(Rect::MakeLTRB(10, 10, 110, 110))};
141 Entity entity;
142 std::optional<Rect> coverage =
143 contents.GetFilterCoverage(inputs, entity, /*effect_transform=*/Matrix());
144
145 ASSERT_EQ(coverage, Rect::MakeLTRB(10, 10, 110, 110));
146}

References impeller::GaussianBlurFilterContents::GetFilterCoverage(), impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::FilterInput::Make(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [203/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
CoverageWithSigma   
)

Definition at line 148 of file gaussian_blur_filter_contents_unittests.cc.

148 {
149 fml::StatusOr<Scalar> sigma_radius_1 =
150 CalculateSigmaForBlurRadius(1.0, Matrix());
151 ASSERT_TRUE(sigma_radius_1.ok());
153 /*sigma_x=*/sigma_radius_1.value(),
154 /*sigma_y=*/sigma_radius_1.value(), Entity::TileMode::kDecal,
155 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
156 /*mask_geometry=*/nullptr);
157 FilterInput::Vector inputs = {
158 FilterInput::Make(Rect::MakeLTRB(100, 100, 200, 200))};
159 Entity entity;
160 std::optional<Rect> coverage =
161 contents.GetFilterCoverage(inputs, entity, /*effect_transform=*/Matrix());
162
163 EXPECT_TRUE(coverage.has_value());
164 if (coverage.has_value()) {
165 EXPECT_RECT_NEAR(coverage.value(), Rect::MakeLTRB(99, 99, 201, 201));
166 }
167}

References EXPECT_RECT_NEAR, impeller::GaussianBlurFilterContents::GetFilterCoverage(), impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), fml::StatusOr< T >::ok(), and fml::StatusOr< T >::value().

◆ TEST() [204/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
Create   
)

Definition at line 113 of file gaussian_blur_filter_contents_unittests.cc.

113 {
115 /*sigma_x=*/0.0, /*sigma_y=*/0.0, Entity::TileMode::kDecal,
116 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
117 /*mask_geometry=*/nullptr);
118 EXPECT_EQ(contents.GetSigmaX(), 0.0);
119 EXPECT_EQ(contents.GetSigmaY(), 0.0);
120}

References impeller::GaussianBlurFilterContents::GetSigmaX(), impeller::GaussianBlurFilterContents::GetSigmaY(), impeller::Entity::kDecal, and impeller::FilterContents::kNormal.

◆ TEST() [205/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
FilterSourceCoverage   
)

Definition at line 214 of file gaussian_blur_filter_contents_unittests.cc.

214 {
215 fml::StatusOr<Scalar> sigma_radius_1 =
216 CalculateSigmaForBlurRadius(1.0, Matrix());
217 ASSERT_TRUE(sigma_radius_1.ok());
218 auto contents = std::make_unique<GaussianBlurFilterContents>(
219 sigma_radius_1.value(), sigma_radius_1.value(), Entity::TileMode::kDecal,
220 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
221 /*mask_geometry=*/nullptr);
222 std::optional<Rect> coverage = contents->GetFilterSourceCoverage(
223 /*effect_transform=*/Matrix::MakeScale({2.0, 2.0, 1.0}),
224 /*output_limit=*/Rect::MakeLTRB(100, 100, 200, 200));
225 EXPECT_TRUE(coverage.has_value());
226 if (coverage.has_value()) {
227 EXPECT_RECT_NEAR(coverage.value(),
228 Rect::MakeLTRB(100 - 2, 100 - 2, 200 + 2, 200 + 2));
229 }
230}

References EXPECT_RECT_NEAR, impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeScale(), fml::StatusOr< T >::ok(), and fml::StatusOr< T >::value().

◆ TEST() [206/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
FilterSourceCoverageNegativeScale   
)

Definition at line 232 of file gaussian_blur_filter_contents_unittests.cc.

232 {
233 fml::StatusOr<Scalar> sigma_radius_1 =
234 CalculateSigmaForBlurRadius(1.0, Matrix());
235 ASSERT_TRUE(sigma_radius_1.ok());
236 auto contents = std::make_unique<GaussianBlurFilterContents>(
237 sigma_radius_1.value(), sigma_radius_1.value(), Entity::TileMode::kDecal,
238 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
239 /*mask_geometry=*/nullptr);
240
241 // Negative scale should still result in an expanded coverage rect.
242 std::optional<Rect> coverage = contents->GetFilterSourceCoverage(
243 /*effect_transform=*/Matrix::MakeScale({-2.0, 2.0, 1.0}),
244 /*output_limit=*/Rect::MakeLTRB(100, 100, 200, 200));
245 ASSERT_TRUE(coverage.has_value());
246 if (coverage.has_value()) {
247 EXPECT_RECT_NEAR(coverage.value(),
248 Rect::MakeLTRB(100 - 2, 100 - 2, 200 + 2, 200 + 2));
249 }
250}

References EXPECT_RECT_NEAR, impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeScale(), fml::StatusOr< T >::ok(), and fml::StatusOr< T >::value().

◆ TEST() [207/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
LerpHackKernelSamplesComplex   
)

Definition at line 604 of file gaussian_blur_filter_contents_unittests.cc.

604 {
605 Scalar sigma = 10.0f;
606 int32_t blur_radius = static_cast<int32_t>(
607 std::ceil(GaussianBlurFilterContents::CalculateBlurRadius(sigma)));
608 BlurParameters parameters = {.blur_uv_offset = Point(1, 0),
609 .blur_sigma = sigma,
610 .blur_radius = blur_radius,
611 .step_size = 1};
612 KernelSamples kernel_samples = GenerateBlurInfo(parameters);
613 EXPECT_EQ(kernel_samples.sample_count, 33);
614 LerpHackResult fast_kernel_samples = LerpHackKernelSamples(kernel_samples);
615 EXPECT_EQ(fast_kernel_samples.sample_count, 17);
616 float data[33];
617 srand(0);
618 for (int i = 0; i < 33; i++) {
619 data[i] = 255.0 * static_cast<double>(IMPELLER_RAND()) / RAND_MAX;
620 }
621
622 auto sampler = [data](Point point) -> Scalar {
623 FML_CHECK(point.y == 0.0f);
624 FML_CHECK(point.x >= -16);
625 FML_CHECK(point.x <= 16);
626 Scalar fint_part;
627 Scalar fract = fabsf(modf(point.x, &fint_part));
628 if (fract == 0) {
629 int32_t int_part = static_cast<int32_t>(fint_part) + 16;
630 return data[int_part];
631 } else {
632 int32_t left = static_cast<int32_t>(floor(point.x)) + 16;
633 int32_t right = static_cast<int32_t>(ceil(point.x)) + 16;
634 if (point.x < 0) {
635 return fract * data[left] + (1.0 - fract) * data[right];
636 } else {
637 return (1.0 - fract) * data[left] + fract * data[right];
638 }
639 }
640 };
641
642 Scalar output = 0.0;
643 for (int i = 0; i < kernel_samples.sample_count; ++i) {
644 auto sample = kernel_samples.samples[i];
645 output += sample.coefficient * sampler(sample.uv_offset);
646 }
647
648 Scalar fast_output = 0.0;
649 for (int i = 0; i < fast_kernel_samples.sample_count; i++) {
650 fast_output +=
651 GetCoefficient(fast_kernel_samples.kernel_samples.sample_data[i]) *
652 sampler(GetUVOffset(fast_kernel_samples.kernel_samples.sample_data[i]));
653 }
654
655 EXPECT_NEAR(output, fast_output, 0.1);
656}
#define FML_CHECK(condition)
Definition logging.h:104
GaussianBlurPipeline::FragmentShader::KernelSamples kernel_samples

References blur_radius, impeller::BlurParameters::blur_uv_offset, impeller::GaussianBlurFilterContents::CalculateBlurRadius(), impeller::KernelSample::coefficient, flutter::data, FML_CHECK, impeller::GenerateBlurInfo(), i, IMPELLER_RAND, impeller::LerpHackResult::kernel_samples, impeller::LerpHackKernelSamples(), impeller::KernelSamples::sample_count, impeller::LerpHackResult::sample_count, and impeller::KernelSamples::samples.

◆ TEST() [208/689]

impeller::testing::TEST ( GaussianBlurFilterContentsTest  ,
LerpHackKernelSamplesSimple   
)

Definition at line 524 of file gaussian_blur_filter_contents_unittests.cc.

524 {
525 KernelSamples kernel_samples = {
526 .sample_count = 5,
527 .samples =
528 {
529 {
530 .uv_offset = Vector2(-2, 0),
531 .coefficient = 0.1f,
532 },
533 {
534 .uv_offset = Vector2(-1, 0),
535 .coefficient = 0.2f,
536 },
537 {
538 .uv_offset = Vector2(0, 0),
539 .coefficient = 0.4f,
540 },
541 {
542 .uv_offset = Vector2(1, 0),
543 .coefficient = 0.2f,
544 },
545 {
546 .uv_offset = Vector2(2, 0),
547 .coefficient = 0.1f,
548 },
549 },
550 };
551
552 LerpHackResult blur_info = LerpHackKernelSamples(kernel_samples);
553 EXPECT_EQ(blur_info.sample_count, 3);
554
555 KernelSample* samples = kernel_samples.samples;
556
557 //////////////////////////////////////////////////////////////////////////////
558 // Check output kernel.
559
560 EXPECT_POINT_NEAR(GetUVOffset(blur_info.kernel_samples.sample_data[0]),
561 Point(-1.3333333, 0));
562 EXPECT_FLOAT_EQ(GetCoefficient(blur_info.kernel_samples.sample_data[0]), 0.3);
563
564 EXPECT_POINT_NEAR(GetUVOffset(blur_info.kernel_samples.sample_data[1]),
565 Point(0, 0));
566 EXPECT_FLOAT_EQ(GetCoefficient(blur_info.kernel_samples.sample_data[1]), 0.4);
567
568 EXPECT_POINT_NEAR(GetUVOffset(blur_info.kernel_samples.sample_data[2]),
569 Point(1.333333, 0));
570 EXPECT_FLOAT_EQ(GetCoefficient(blur_info.kernel_samples.sample_data[2]), 0.3);
571
572 //////////////////////////////////////////////////////////////////////////////
573 // Check output of fast kernel versus original kernel.
574
575 Scalar data[5] = {0.25, 0.5, 0.5, 1.0, 0.2};
576 Scalar original_output =
577 samples[0].coefficient * data[0] + samples[1].coefficient * data[1] +
578 samples[2].coefficient * data[2] + samples[3].coefficient * data[3] +
579 samples[4].coefficient * data[4];
580
581 auto lerp = [](const Point& point, Scalar left, Scalar right) {
582 Scalar int_part;
583 Scalar fract = fabsf(modf(point.x, &int_part));
584 if (point.x < 0) {
585 return left * fract + right * (1.0 - fract);
586 } else {
587 return left * (1.0 - fract) + right * fract;
588 }
589 };
590 Scalar fast_output =
591 /*1st*/ lerp(GetUVOffset(blur_info.kernel_samples.sample_data[0]),
592 data[0], data[1]) *
593 GetCoefficient(blur_info.kernel_samples.sample_data[0]) +
594 /*2nd*/ data[2] *
595 GetCoefficient(blur_info.kernel_samples.sample_data[1]) +
596 /*3rd*/
597 lerp(GetUVOffset(blur_info.kernel_samples.sample_data[2]), data[3],
598 data[4]) *
599 GetCoefficient(blur_info.kernel_samples.sample_data[2]);
600
601 EXPECT_NEAR(original_output, fast_output, 0.01);
602}
#define EXPECT_POINT_NEAR(a, b)
Point Vector2
Definition point.h:430

References impeller::KernelSample::coefficient, flutter::data, EXPECT_POINT_NEAR, impeller::LerpHackResult::kernel_samples, impeller::LerpHackKernelSamples(), impeller::KernelSamples::sample_count, impeller::LerpHackResult::sample_count, impeller::KernelSamples::samples, and flutter::Point::x().

◆ TEST() [209/689]

impeller::testing::TEST ( GeometryTest  ,
BlendModeToString   
)

Definition at line 1709 of file geometry_unittests.cc.

1709 {
1710 using BlendT = std::underlying_type_t<BlendMode>;
1711 for (BlendT i = 0; i <= static_cast<BlendT>(BlendMode::kLastMode); i++) {
1712 auto mode = static_cast<BlendMode>(i);
1713 auto result = BlendModeToString(mode);
1715 }
1716}
#define _BLEND_MODE_NAME_CHECK(blend_mode)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
const char * BlendModeToString(BlendMode blend_mode)
Definition color.cc:45
BlendMode
Definition color.h:58

References _BLEND_MODE_NAME_CHECK, impeller::BlendModeToString(), i, IMPELLER_FOR_EACH_BLEND_MODE, impeller::kLastMode, and flutter::mode.

◆ TEST() [210/689]

impeller::testing::TEST ( GeometryTest  ,
CanConvertBetweenDegressAndRadians   
)

Definition at line 1718 of file geometry_unittests.cc.

1718 {
1719 {
1720 auto deg = Degrees{90.0};
1721 Radians rad = deg;
1722 ASSERT_FLOAT_EQ(rad.radians, kPiOver2);
1723 }
1724}
Scalar radians
Definition scalar.h:45

References impeller::kPiOver2, and impeller::Radians::radians.

◆ TEST() [211/689]

impeller::testing::TEST ( GeometryTest  ,
CanConvertTTypesExplicitly   
)

Definition at line 593 of file geometry_unittests.cc.

593 {
594 {
595 Point p1(1.0, 2.0);
596 IPoint p2 = static_cast<IPoint>(p1);
597 ASSERT_EQ(p2.x, 1u);
598 ASSERT_EQ(p2.y, 2u);
599 }
600
601 {
602 Size s1(1.0, 2.0);
603 ISize s2 = static_cast<ISize>(s1);
604 ASSERT_EQ(s2.width, 1u);
605 ASSERT_EQ(s2.height, 2u);
606 }
607
608 {
609 Size s1(1.0, 2.0);
610 Point p1 = static_cast<Point>(s1);
611 ASSERT_EQ(p1.x, 1u);
612 ASSERT_EQ(p1.y, 2u);
613 }
614}
Type height
Definition size.h:29
Type width
Definition size.h:28

References impeller::TSize< T >::height, p1, p2, impeller::TSize< T >::width, flutter::Point::x(), and flutter::Point::y().

◆ TEST() [212/689]

impeller::testing::TEST ( GeometryTest  ,
CanGenerateMipCounts   
)

Definition at line 580 of file geometry_unittests.cc.

580 {
581 EXPECT_EQ((Size{128, 128}.MipCount()), 7u);
582 EXPECT_EQ((Size{128, 256}.MipCount()), 7u);
583 EXPECT_EQ((Size{128, 130}.MipCount()), 7u);
584 EXPECT_EQ((Size{128, 257}.MipCount()), 7u);
585 EXPECT_EQ((Size{257, 128}.MipCount()), 7u);
586 EXPECT_EQ((Size{128, 0}.MipCount()), 1u);
587 EXPECT_EQ((Size{128, -25}.MipCount()), 1u);
588 EXPECT_EQ((Size{-128, 25}.MipCount()), 1u);
589 EXPECT_EQ((Size{1, 1}.MipCount()), 1u);
590 EXPECT_EQ((Size{0, 0}.MipCount()), 1u);
591}
constexpr size_t MipCount() const
Return the mip count of the texture.
Definition size.h:137

◆ TEST() [213/689]

impeller::testing::TEST ( GeometryTest  ,
CanPerformAlgebraicPointOps   
)

Definition at line 616 of file geometry_unittests.cc.

616 {
617 {
618 IPoint p1(1, 2);
619 IPoint p2 = p1 + IPoint(1, 2);
620 ASSERT_EQ(p2.x, 2u);
621 ASSERT_EQ(p2.y, 4u);
622 }
623
624 {
625 IPoint p1(3, 6);
626 IPoint p2 = p1 - IPoint(1, 2);
627 ASSERT_EQ(p2.x, 2u);
628 ASSERT_EQ(p2.y, 4u);
629 }
630
631 {
632 IPoint p1(1, 2);
633 IPoint p2 = p1 * IPoint(2, 3);
634 ASSERT_EQ(p2.x, 2u);
635 ASSERT_EQ(p2.y, 6u);
636 }
637
638 {
639 IPoint p1(2, 6);
640 IPoint p2 = p1 / IPoint(2, 3);
641 ASSERT_EQ(p2.x, 1u);
642 ASSERT_EQ(p2.y, 2u);
643 }
644}
TPoint< int64_t > IPoint
Definition point.h:427

References p1, p2, flutter::Point::x(), and flutter::Point::y().

◆ TEST() [214/689]

impeller::testing::TEST ( GeometryTest  ,
CanPerformAlgebraicPointOpsWithArithmeticTypes   
)

Definition at line 646 of file geometry_unittests.cc.

646 {
647 // LHS
648 {
649 IPoint p1(1, 2);
650 IPoint p2 = p1 * 2.0f;
651 ASSERT_EQ(p2.x, 2u);
652 ASSERT_EQ(p2.y, 4u);
653 }
654
655 {
656 IPoint p1(2, 6);
657 IPoint p2 = p1 / 2.0f;
658 ASSERT_EQ(p2.x, 1u);
659 ASSERT_EQ(p2.y, 3u);
660 }
661
662 // RHS
663 {
664 IPoint p1(1, 2);
665 IPoint p2 = 2.0f * p1;
666 ASSERT_EQ(p2.x, 2u);
667 ASSERT_EQ(p2.y, 4u);
668 }
669
670 {
671 IPoint p1(2, 6);
672 IPoint p2 = 12.0f / p1;
673 ASSERT_EQ(p2.x, 6u);
674 ASSERT_EQ(p2.y, 2u);
675 }
676}

References p1, p2, flutter::Point::x(), and flutter::Point::y().

◆ TEST() [215/689]

impeller::testing::TEST ( GeometryTest  ,
CanPerformAlgebraicVector3Ops   
)

Definition at line 1276 of file geometry_unittests.cc.

1276 {
1277 {
1278 Vector3 p1(1, 2, 3);
1279 Vector3 p2 = p1 + Vector3(1, 2, 3);
1280 ASSERT_EQ(p2.x, 2u);
1281 ASSERT_EQ(p2.y, 4u);
1282 ASSERT_EQ(p2.z, 6u);
1283 }
1284
1285 {
1286 Vector3 p1(3, 6, 9);
1287 Vector3 p2 = p1 - Vector3(1, 2, 3);
1288 ASSERT_EQ(p2.x, 2u);
1289 ASSERT_EQ(p2.y, 4u);
1290 ASSERT_EQ(p2.z, 6u);
1291 }
1292
1293 {
1294 Vector3 p1(1, 2, 3);
1295 Vector3 p2 = p1 * Vector3(2, 3, 4);
1296 ASSERT_EQ(p2.x, 2u);
1297 ASSERT_EQ(p2.y, 6u);
1298 ASSERT_EQ(p2.z, 12u);
1299 }
1300
1301 {
1302 Vector3 p1(2, 6, 12);
1303 Vector3 p2 = p1 / Vector3(2, 3, 4);
1304 ASSERT_EQ(p2.x, 1u);
1305 ASSERT_EQ(p2.y, 2u);
1306 ASSERT_EQ(p2.z, 3u);
1307 }
1308}

References p1, p2, flutter::Point::x(), and flutter::Point::y().

◆ TEST() [216/689]

impeller::testing::TEST ( GeometryTest  ,
CanPerformAlgebraicVector3OpsWithArithmeticTypes   
)

Definition at line 1310 of file geometry_unittests.cc.

1310 {
1311 // LHS
1312 {
1313 Vector3 p1(1, 2, 3);
1314 Vector3 p2 = p1 + 2.0f;
1315 ASSERT_EQ(p2.x, 3);
1316 ASSERT_EQ(p2.y, 4);
1317 ASSERT_EQ(p2.z, 5);
1318 }
1319
1320 {
1321 Vector3 p1(1, 2, 3);
1322 Vector3 p2 = p1 - 2.0f;
1323 ASSERT_EQ(p2.x, -1);
1324 ASSERT_EQ(p2.y, 0);
1325 ASSERT_EQ(p2.z, 1);
1326 }
1327
1328 {
1329 Vector3 p1(1, 2, 3);
1330 Vector3 p2 = p1 * 2.0f;
1331 ASSERT_EQ(p2.x, 2);
1332 ASSERT_EQ(p2.y, 4);
1333 ASSERT_EQ(p2.z, 6);
1334 }
1335
1336 {
1337 Vector3 p1(2, 6, 12);
1338 Vector3 p2 = p1 / 2.0f;
1339 ASSERT_EQ(p2.x, 1);
1340 ASSERT_EQ(p2.y, 3);
1341 ASSERT_EQ(p2.z, 6);
1342 }
1343
1344 // RHS
1345 {
1346 Vector3 p1(1, 2, 3);
1347 Vector3 p2 = 2.0f + p1;
1348 ASSERT_EQ(p2.x, 3);
1349 ASSERT_EQ(p2.y, 4);
1350 ASSERT_EQ(p2.z, 5);
1351 }
1352
1353 {
1354 Vector3 p1(1, 2, 3);
1355 Vector3 p2 = 2.0f - p1;
1356 ASSERT_EQ(p2.x, 1);
1357 ASSERT_EQ(p2.y, 0);
1358 ASSERT_EQ(p2.z, -1);
1359 }
1360
1361 {
1362 Vector3 p1(1, 2, 3);
1363 Vector3 p2 = 2.0f * p1;
1364 ASSERT_EQ(p2.x, 2);
1365 ASSERT_EQ(p2.y, 4);
1366 ASSERT_EQ(p2.z, 6);
1367 }
1368
1369 {
1370 Vector3 p1(2, 6, 12);
1371 Vector3 p2 = 12.0f / p1;
1372 ASSERT_EQ(p2.x, 6);
1373 ASSERT_EQ(p2.y, 2);
1374 ASSERT_EQ(p2.z, 1);
1375 }
1376}

References p1, p2, flutter::Point::x(), and flutter::Point::y().

◆ TEST() [217/689]

impeller::testing::TEST ( GeometryTest  ,
CanUsePointAssignmentOperators   
)

Definition at line 798 of file geometry_unittests.cc.

798 {
799 // Point on RHS
800 {
801 IPoint p(1, 2);
802 p += IPoint(1, 2);
803 ASSERT_EQ(p.x, 2u);
804 ASSERT_EQ(p.y, 4u);
805 }
806
807 {
808 IPoint p(3, 6);
809 p -= IPoint(1, 2);
810 ASSERT_EQ(p.x, 2u);
811 ASSERT_EQ(p.y, 4u);
812 }
813
814 {
815 IPoint p(1, 2);
816 p *= IPoint(2, 3);
817 ASSERT_EQ(p.x, 2u);
818 ASSERT_EQ(p.y, 6u);
819 }
820
821 {
822 IPoint p(2, 6);
823 p /= IPoint(2, 3);
824 ASSERT_EQ(p.x, 1u);
825 ASSERT_EQ(p.y, 2u);
826 }
827
828 // Size on RHS
829 {
830 IPoint p(1, 2);
831 p += ISize(1, 2);
832 ASSERT_EQ(p.x, 2u);
833 ASSERT_EQ(p.y, 4u);
834 }
835
836 {
837 IPoint p(3, 6);
838 p -= ISize(1, 2);
839 ASSERT_EQ(p.x, 2u);
840 ASSERT_EQ(p.y, 4u);
841 }
842
843 {
844 IPoint p(1, 2);
845 p *= ISize(2, 3);
846 ASSERT_EQ(p.x, 2u);
847 ASSERT_EQ(p.y, 6u);
848 }
849
850 {
851 IPoint p(2, 6);
852 p /= ISize(2, 3);
853 ASSERT_EQ(p.x, 1u);
854 ASSERT_EQ(p.y, 2u);
855 }
856
857 // Arithmetic type on RHS
858 {
859 IPoint p(1, 2);
860 p *= 3;
861 ASSERT_EQ(p.x, 3u);
862 ASSERT_EQ(p.y, 6u);
863 }
864
865 {
866 IPoint p(3, 6);
867 p /= 3;
868 ASSERT_EQ(p.x, 1u);
869 ASSERT_EQ(p.y, 2u);
870 }
871}
ISize64 ISize
Definition size.h:162

References impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

◆ TEST() [218/689]

impeller::testing::TEST ( GeometryTest  ,
CanUseVector3AssignmentOperators   
)

Definition at line 1226 of file geometry_unittests.cc.

1226 {
1227 {
1228 Vector3 p(1, 2, 4);
1229 p += Vector3(1, 2, 4);
1230 ASSERT_EQ(p.x, 2u);
1231 ASSERT_EQ(p.y, 4u);
1232 ASSERT_EQ(p.z, 8u);
1233 }
1234
1235 {
1236 Vector3 p(3, 6, 8);
1237 p -= Vector3(1, 2, 3);
1238 ASSERT_EQ(p.x, 2u);
1239 ASSERT_EQ(p.y, 4u);
1240 ASSERT_EQ(p.z, 5u);
1241 }
1242
1243 {
1244 Vector3 p(1, 2, 3);
1245 p *= Vector3(2, 3, 4);
1246 ASSERT_EQ(p.x, 2u);
1247 ASSERT_EQ(p.y, 6u);
1248 ASSERT_EQ(p.z, 12u);
1249 }
1250
1251 {
1252 Vector3 p(1, 2, 3);
1253 p *= 2;
1254 ASSERT_EQ(p.x, 2u);
1255 ASSERT_EQ(p.y, 4u);
1256 ASSERT_EQ(p.z, 6u);
1257 }
1258
1259 {
1260 Vector3 p(2, 6, 12);
1261 p /= Vector3(2, 3, 4);
1262 ASSERT_EQ(p.x, 1u);
1263 ASSERT_EQ(p.y, 2u);
1264 ASSERT_EQ(p.z, 3u);
1265 }
1266
1267 {
1268 Vector3 p(2, 6, 12);
1269 p /= 2;
1270 ASSERT_EQ(p.x, 1u);
1271 ASSERT_EQ(p.y, 3u);
1272 ASSERT_EQ(p.z, 6u);
1273 }
1274}

References impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

◆ TEST() [219/689]

impeller::testing::TEST ( GeometryTest  ,
ColorApplyColorMatrix   
)

Definition at line 1483 of file geometry_unittests.cc.

1483 {
1484 {
1485 ColorMatrix color_matrix = {
1486 1, 1, 1, 1, 1, //
1487 1, 1, 1, 1, 1, //
1488 1, 1, 1, 1, 1, //
1489 1, 1, 1, 1, 1, //
1490 };
1491 auto result = Color::White().ApplyColorMatrix(color_matrix);
1492 auto expected = Color(1, 1, 1, 1);
1493 ASSERT_COLOR_NEAR(result, expected);
1494 }
1495
1496 {
1497 ColorMatrix color_matrix = {
1498 0.1, 0, 0, 0, 0.01, //
1499 0, 0.2, 0, 0, 0.02, //
1500 0, 0, 0.3, 0, 0.03, //
1501 0, 0, 0, 0.4, 0.04, //
1502 };
1503 auto result = Color::White().ApplyColorMatrix(color_matrix);
1504 auto expected = Color(0.11, 0.22, 0.33, 0.44);
1505 ASSERT_COLOR_NEAR(result, expected);
1506 }
1507}
#define ASSERT_COLOR_NEAR(a, b)

References impeller::Color::ApplyColorMatrix(), ASSERT_COLOR_NEAR, and impeller::Color::White().

◆ TEST() [220/689]

impeller::testing::TEST ( GeometryTest  ,
ColorBlendReturnsExpectedResults   
)

Definition at line 1692 of file geometry_unittests.cc.

1692 {
1693 Color dst = ColorBlendTestData::kDestinationColor;
1694 for (size_t source_i = 0;
1695 source_i < sizeof(ColorBlendTestData::kSourceColors) / sizeof(Color);
1696 source_i++) {
1697 Color src = ColorBlendTestData::kSourceColors[source_i];
1698
1699 Color expected;
1701 }
1702}
#define _BLEND_MODE_RESULT_CHECK(blend_mode)

References _BLEND_MODE_RESULT_CHECK, IMPELLER_FOR_EACH_BLEND_MODE, impeller::testing::ColorBlendTestData::kDestinationColor, and impeller::testing::ColorBlendTestData::kSourceColors.

◆ TEST() [221/689]

impeller::testing::TEST ( GeometryTest  ,
ColorClamp01   
)

Definition at line 1443 of file geometry_unittests.cc.

1443 {
1444 {
1445 Color result = Color(0.5, 0.5, 0.5, 0.5).Clamp01();
1446 Color expected = Color(0.5, 0.5, 0.5, 0.5);
1447 ASSERT_COLOR_NEAR(result, expected);
1448 }
1449
1450 {
1451 Color result = Color(-1, -1, -1, -1).Clamp01();
1452 Color expected = Color(0, 0, 0, 0);
1453 ASSERT_COLOR_NEAR(result, expected);
1454 }
1455
1456 {
1457 Color result = Color(2, 2, 2, 2).Clamp01();
1458 Color expected = Color(1, 1, 1, 1);
1459 ASSERT_COLOR_NEAR(result, expected);
1460 }
1461}
constexpr Color Clamp01() const
Definition color.h:236

References ASSERT_COLOR_NEAR, and impeller::Color::Clamp01().

◆ TEST() [222/689]

impeller::testing::TEST ( GeometryTest  ,
ColorLerp   
)

Definition at line 1421 of file geometry_unittests.cc.

1421 {
1422 {
1423 Color a(0.0, 0.0, 0.0, 0.0);
1424 Color b(1.0, 1.0, 1.0, 1.0);
1425
1426 ASSERT_COLOR_NEAR(Color::Lerp(a, b, 0.5), Color(0.5, 0.5, 0.5, 0.5));
1427 ASSERT_COLOR_NEAR(Color::Lerp(a, b, 0.0), a);
1428 ASSERT_COLOR_NEAR(Color::Lerp(a, b, 1.0), b);
1429 ASSERT_COLOR_NEAR(Color::Lerp(a, b, 0.2), Color(0.2, 0.2, 0.2, 0.2));
1430 }
1431
1432 {
1433 Color a(0.2, 0.4, 1.0, 0.5);
1434 Color b(0.4, 1.0, 0.2, 0.3);
1435
1436 ASSERT_COLOR_NEAR(Color::Lerp(a, b, 0.5), Color(0.3, 0.7, 0.6, 0.4));
1437 ASSERT_COLOR_NEAR(Color::Lerp(a, b, 0.0), a);
1438 ASSERT_COLOR_NEAR(Color::Lerp(a, b, 1.0), b);
1439 ASSERT_COLOR_NEAR(Color::Lerp(a, b, 0.2), Color(0.24, 0.52, 0.84, 0.46));
1440 }
1441}

References ASSERT_COLOR_NEAR, and impeller::Color::Lerp().

◆ TEST() [223/689]

impeller::testing::TEST ( GeometryTest  ,
ColorLinearToSRGB   
)

Definition at line 1509 of file geometry_unittests.cc.

1509 {
1510 {
1511 auto result = Color::White().LinearToSRGB();
1512 auto expected = Color(1, 1, 1, 1);
1513 ASSERT_COLOR_NEAR(result, expected);
1514 }
1515
1516 {
1517 auto result = Color::BlackTransparent().LinearToSRGB();
1518 auto expected = Color(0, 0, 0, 0);
1519 ASSERT_COLOR_NEAR(result, expected);
1520 }
1521
1522 {
1523 auto result = Color(0.2, 0.4, 0.6, 0.8).LinearToSRGB();
1524 auto expected = Color(0.484529, 0.665185, 0.797738, 0.8);
1525 ASSERT_COLOR_NEAR(result, expected);
1526 }
1527}

References ASSERT_COLOR_NEAR, impeller::Color::BlackTransparent(), impeller::Color::LinearToSRGB(), and impeller::Color::White().

◆ TEST() [224/689]

impeller::testing::TEST ( GeometryTest  ,
ColorMakeRGBA8   
)

Definition at line 1463 of file geometry_unittests.cc.

1463 {
1464 {
1465 Color a = Color::MakeRGBA8(0, 0, 0, 0);
1466 Color b = Color::BlackTransparent();
1467 ASSERT_COLOR_NEAR(a, b);
1468 }
1469
1470 {
1471 Color a = Color::MakeRGBA8(255, 255, 255, 255);
1472 Color b = Color::White();
1473 ASSERT_COLOR_NEAR(a, b);
1474 }
1475
1476 {
1477 Color a = Color::MakeRGBA8(63, 127, 191, 127);
1478 Color b(0.247059, 0.498039, 0.74902, 0.498039);
1479 ASSERT_COLOR_NEAR(a, b);
1480 }
1481}

References ASSERT_COLOR_NEAR, impeller::Color::BlackTransparent(), impeller::Color::MakeRGBA8(), and impeller::Color::White().

◆ TEST() [225/689]

impeller::testing::TEST ( GeometryTest  ,
ColorPremultiply   
)

Definition at line 1378 of file geometry_unittests.cc.

1378 {
1379 {
1380 Color a(1.0, 0.5, 0.2, 0.5);
1381 Color premultiplied = a.Premultiply();
1382 Color expected = Color(0.5, 0.25, 0.1, 0.5);
1383 ASSERT_COLOR_NEAR(premultiplied, expected);
1384 }
1385
1386 {
1387 Color a(0.5, 0.25, 0.1, 0.5);
1388 Color unpremultiplied = a.Unpremultiply();
1389 Color expected = Color(1.0, 0.5, 0.2, 0.5);
1390 ASSERT_COLOR_NEAR(unpremultiplied, expected);
1391 }
1392
1393 {
1394 Color a(0.5, 0.25, 0.1, 0.0);
1395 Color unpremultiplied = a.Unpremultiply();
1396 Color expected = Color(0.0, 0.0, 0.0, 0.0);
1397 ASSERT_COLOR_NEAR(unpremultiplied, expected);
1398 }
1399}
constexpr Color Unpremultiply() const
Definition color.h:216
constexpr Color Premultiply() const
Definition color.h:212

References ASSERT_COLOR_NEAR, impeller::Color::Premultiply(), and impeller::Color::Unpremultiply().

◆ TEST() [226/689]

impeller::testing::TEST ( GeometryTest  ,
ColorPrinting   
)

Definition at line 1801 of file geometry_unittests.cc.

1801 {
1802 {
1803 std::stringstream stream;
1804 Color m;
1805 stream << m;
1806 ASSERT_EQ(stream.str(), "(0, 0, 0, 0)");
1807 }
1808
1809 {
1810 std::stringstream stream;
1811 Color m(1, 2, 3, 4);
1812 stream << m;
1813 ASSERT_EQ(stream.str(), "(1, 2, 3, 4)");
1814 }
1815}

◆ TEST() [227/689]

impeller::testing::TEST ( GeometryTest  ,
ColorR8G8B8A8   
)

Definition at line 1401 of file geometry_unittests.cc.

1401 {
1402 {
1403 Color a(1.0, 0.5, 0.2, 0.5);
1404 std::array<uint8_t, 4> expected = {255, 128, 51, 128};
1405 ASSERT_ARRAY_4_NEAR(a.ToR8G8B8A8(), expected);
1406 }
1407
1408 {
1409 Color a(0.0, 0.0, 0.0, 0.0);
1410 std::array<uint8_t, 4> expected = {0, 0, 0, 0};
1411 ASSERT_ARRAY_4_NEAR(a.ToR8G8B8A8(), expected);
1412 }
1413
1414 {
1415 Color a(1.0, 1.0, 1.0, 1.0);
1416 std::array<uint8_t, 4> expected = {255, 255, 255, 255};
1417 ASSERT_ARRAY_4_NEAR(a.ToR8G8B8A8(), expected);
1418 }
1419}
#define ASSERT_ARRAY_4_NEAR(a, b)

References ASSERT_ARRAY_4_NEAR, and impeller::Color::ToR8G8B8A8().

◆ TEST() [228/689]

impeller::testing::TEST ( GeometryTest  ,
ColorSRGBToLinear   
)

Definition at line 1529 of file geometry_unittests.cc.

1529 {
1530 {
1531 auto result = Color::White().SRGBToLinear();
1532 auto expected = Color(1, 1, 1, 1);
1533 ASSERT_COLOR_NEAR(result, expected);
1534 }
1535
1536 {
1537 auto result = Color::BlackTransparent().SRGBToLinear();
1538 auto expected = Color(0, 0, 0, 0);
1539 ASSERT_COLOR_NEAR(result, expected);
1540 }
1541
1542 {
1543 auto result = Color(0.2, 0.4, 0.6, 0.8).SRGBToLinear();
1544 auto expected = Color(0.0331048, 0.132868, 0.318547, 0.8);
1545 ASSERT_COLOR_NEAR(result, expected);
1546 }
1547}

References ASSERT_COLOR_NEAR, impeller::Color::BlackTransparent(), impeller::Color::SRGBToLinear(), and impeller::Color::White().

◆ TEST() [229/689]

impeller::testing::TEST ( GeometryTest  ,
DeterminantTest   
)

Definition at line 121 of file geometry_unittests.cc.

121 {
122 auto matrix = Matrix{3, 4, 14, 155, 2, 1, 3, 4, 2, 3, 2, 1, 1, 2, 4, 2};
123 ASSERT_EQ(matrix.GetDeterminant(), -1889);
124}

◆ TEST() [230/689]

impeller::testing::TEST ( GeometryTest  ,
Gradient   
)

Definition at line 1823 of file geometry_unittests.cc.

1823 {
1824 {
1825 // Simple 2 color gradient produces color buffer containing exactly those
1826 // values.
1827 std::vector<Color> colors = {Color::Red(), Color::Blue()};
1828 std::vector<Scalar> stops = {0.0, 1.0};
1829
1830 auto gradient = CreateGradientBuffer(colors, stops);
1831
1832 ASSERT_COLOR_BUFFER_NEAR(gradient.color_bytes, colors);
1833 ASSERT_EQ(gradient.texture_size, 2u);
1834 }
1835
1836 {
1837 // Gradient with duplicate stops does not create an empty texture.
1838 std::vector<Color> colors = {Color::Red(), Color::Yellow(), Color::Black(),
1839 Color::Blue()};
1840 std::vector<Scalar> stops = {0.0, 0.25, 0.25, 1.0};
1841
1842 auto gradient = CreateGradientBuffer(colors, stops);
1843 ASSERT_EQ(gradient.texture_size, 5u);
1844 }
1845
1846 {
1847 // Simple N color gradient produces color buffer containing exactly those
1848 // values.
1849 std::vector<Color> colors = {Color::Red(), Color::Blue(), Color::Green(),
1850 Color::White()};
1851 std::vector<Scalar> stops = {0.0, 0.33, 0.66, 1.0};
1852
1853 auto gradient = CreateGradientBuffer(colors, stops);
1854
1855 ASSERT_COLOR_BUFFER_NEAR(gradient.color_bytes, colors);
1856 ASSERT_EQ(gradient.texture_size, 4u);
1857 }
1858
1859 {
1860 // Gradient with color stops will lerp and scale buffer.
1861 std::vector<Color> colors = {Color::Red(), Color::Blue(), Color::Green()};
1862 std::vector<Scalar> stops = {0.0, 0.25, 1.0};
1863
1864 auto gradient = CreateGradientBuffer(colors, stops);
1865
1866 std::vector<Color> lerped_colors = {
1867 Color::Red(),
1868 Color::Blue(),
1869 Color::Lerp(Color::Blue(), Color::Green(), 0.3333),
1870 Color::Lerp(Color::Blue(), Color::Green(), 0.6666),
1871 Color::Green(),
1872 };
1873 ASSERT_COLOR_BUFFER_NEAR(gradient.color_bytes, lerped_colors);
1874 ASSERT_EQ(gradient.texture_size, 5u);
1875 }
1876
1877 {
1878 // Gradient size is capped at 1024.
1879 std::vector<Color> colors = {};
1880 std::vector<Scalar> stops = {};
1881 for (auto i = 0u; i < 1025; i++) {
1882 colors.push_back(Color::Blue());
1883 stops.push_back(i / 1025.0);
1884 }
1885
1886 auto gradient = CreateGradientBuffer(colors, stops);
1887
1888 ASSERT_EQ(gradient.texture_size, 1024u);
1889 ASSERT_EQ(gradient.color_bytes.size(), 1024u * 4);
1890 }
1891}
#define ASSERT_COLOR_BUFFER_NEAR(a, b)
GradientData CreateGradientBuffer(const std::vector< Color > &colors, const std::vector< Scalar > &stops)
Populate a vector with the interpolated color bytes for the linear gradient described by colors and s...
Definition gradient.cc:20

References ASSERT_COLOR_BUFFER_NEAR, impeller::Color::Black(), impeller::Color::Blue(), impeller::CreateGradientBuffer(), impeller::Color::Green(), i, impeller::Color::Lerp(), impeller::Color::Red(), impeller::Color::White(), and impeller::Color::Yellow().

◆ TEST() [231/689]

impeller::testing::TEST ( GeometryTest  ,
HalfConversions   
)

Definition at line 1893 of file geometry_unittests.cc.

1893 {
1894#if defined(FML_OS_MACOSX) || defined(FML_OS_IOS) || \
1895 defined(FML_OS_IOS_SIMULATOR)
1896 ASSERT_EQ(ScalarToHalf(0.0), 0.0f16);
1897 ASSERT_EQ(ScalarToHalf(0.05), 0.05f16);
1898 ASSERT_EQ(ScalarToHalf(2.43), 2.43f16);
1899 ASSERT_EQ(ScalarToHalf(-1.45), -1.45f16);
1900
1901 // 65504 is the largest possible half.
1902 ASSERT_EQ(ScalarToHalf(65504.0f), 65504.0f16);
1903 ASSERT_EQ(ScalarToHalf(65504.0f + 1), 65504.0f16);
1904
1905 // Colors
1906 ASSERT_EQ(HalfVector4(Color::Red()),
1907 HalfVector4(1.0f16, 0.0f16, 0.0f16, 1.0f16));
1908 ASSERT_EQ(HalfVector4(Color::Green()),
1909 HalfVector4(0.0f16, 1.0f16, 0.0f16, 1.0f16));
1910 ASSERT_EQ(HalfVector4(Color::Blue()),
1911 HalfVector4(0.0f16, 0.0f16, 1.0f16, 1.0f16));
1912 ASSERT_EQ(HalfVector4(Color::Black().WithAlpha(0)),
1913 HalfVector4(0.0f16, 0.0f16, 0.0f16, 0.0f16));
1914
1915 ASSERT_EQ(HalfVector3(Vector3(4.0, 6.0, -1.0)),
1916 HalfVector3(4.0f16, 6.0f16, -1.0f16));
1917 ASSERT_EQ(HalfVector2(Vector2(4.0, 6.0)), HalfVector2(4.0f16, 6.0f16));
1918
1919 ASSERT_EQ(Half(0.5f), Half(0.5f16));
1920 ASSERT_EQ(Half(0.5), Half(0.5f16));
1921 ASSERT_EQ(Half(5), Half(5.0f16));
1922#else
1923 GTEST_SKIP() << "Half-precision floats (IEEE 754) are not portable and "
1924 "only used on Apple platforms.";
1925#endif // FML_OS_MACOSX || FML_OS_IOS || FML_OS_IOS_SIMULATOR
1926}
constexpr InternalHalf ScalarToHalf(Scalar f)
Convert a scalar to a half precision float.
Definition half.h:32
A storage only class for half precision floating point.
Definition half.h:41
A storage only class for half precision floating point vector 2.
Definition half.h:127
A storage only class for half precision floating point vector 3.
Definition half.h:99
A storage only class for half precision floating point vector 4.
Definition half.h:58

References impeller::Color::Black(), impeller::Color::Blue(), impeller::Color::Green(), impeller::Color::Red(), and impeller::ScalarToHalf().

◆ TEST() [232/689]

impeller::testing::TEST ( GeometryTest  ,
InvertMatrix   
)

Definition at line 126 of file geometry_unittests.cc.

126 {
127 auto inverted = Matrix{10, -9, -12, 8, //
128 7, -12, 11, 22, //
129 -10, 10, 3, 6, //
130 -2, 22, 2, 1}
131 .Invert();
132
133 auto result = Matrix{
134 438.0 / 85123.0, 1751.0 / 85123.0, -7783.0 / 85123.0, 4672.0 / 85123.0,
135 393.0 / 85123.0, -178.0 / 85123.0, -570.0 / 85123.0, 4192 / 85123.0,
136 -5230.0 / 85123.0, 2802.0 / 85123.0, -3461.0 / 85123.0, 962.0 / 85123.0,
137 2690.0 / 85123.0, 1814.0 / 85123.0, 3896.0 / 85123.0, 319.0 / 85123.0};
138
139 ASSERT_MATRIX_NEAR(inverted, result);
140}
Matrix Invert() const
Definition matrix.cc:99

References ASSERT_MATRIX_NEAR, and impeller::Matrix::Invert().

◆ TEST() [233/689]

impeller::testing::TEST ( GeometryTest  ,
InvertMultMatrix   
)

Definition at line 79 of file geometry_unittests.cc.

79 {
80 {
81 auto rotation = Matrix::MakeRotationZ(Radians{kPiOver4});
82 auto invert = rotation.Invert();
83 // clang-format off
84 auto expect = Matrix{k1OverSqrt2, -k1OverSqrt2, 0, 0,
85 k1OverSqrt2, k1OverSqrt2, 0, 0,
86 0, 0, 1, 0,
87 0, 0, 0, 1};
88 // clang-format on
89 ASSERT_MATRIX_NEAR(invert, expect);
90 }
91 {
92 auto scale = Matrix::MakeScale(Vector2{2, 4});
93 auto invert = scale.Invert();
94 auto expect = Matrix{0.5, 0, 0, 0, //
95 0, 0.25, 0, 0, //
96 0, 0, 1, 0, //
97 0, 0, 0, 1};
98 ASSERT_MATRIX_NEAR(invert, expect);
99 }
100}

References ASSERT_MATRIX_NEAR, impeller::Matrix::Invert(), impeller::k1OverSqrt2, impeller::kPiOver4, impeller::Matrix::MakeRotationZ(), and impeller::Matrix::MakeScale().

◆ TEST() [234/689]

impeller::testing::TEST ( GeometryTest  ,
MakeColumn   
)

Definition at line 40 of file geometry_unittests.cc.

40 {
41 auto matrix = Matrix::MakeColumn(1, 2, 3, 4, //
42 5, 6, 7, 8, //
43 9, 10, 11, 12, //
44 13, 14, 15, 16);
45
46 auto expect = Matrix{1, 2, 3, 4, //
47 5, 6, 7, 8, //
48 9, 10, 11, 12, //
49 13, 14, 15, 16};
50
51 ASSERT_TRUE(matrix == expect);
52}

References impeller::Matrix::MakeColumn().

◆ TEST() [235/689]

impeller::testing::TEST ( GeometryTest  ,
MakeRow   
)

Definition at line 54 of file geometry_unittests.cc.

54 {
55 auto matrix = Matrix::MakeRow(1, 2, 3, 4, //
56 5, 6, 7, 8, //
57 9, 10, 11, 12, //
58 13, 14, 15, 16);
59
60 auto expect = Matrix{1, 5, 9, 13, //
61 2, 6, 10, 14, //
62 3, 7, 11, 15, //
63 4, 8, 12, 16};
64
65 ASSERT_TRUE(matrix == expect);
66}

References impeller::Matrix::MakeRow().

◆ TEST() [236/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixBasis   
)

Definition at line 102 of file geometry_unittests.cc.

102 {
103 auto matrix = Matrix{1, 2, 3, 4, //
104 5, 6, 7, 8, //
105 9, 10, 11, 12, //
106 13, 14, 15, 16};
107 auto basis = matrix.Basis();
108 auto expect = Matrix{1, 2, 3, 0, //
109 5, 6, 7, 0, //
110 9, 10, 11, 0, //
111 0, 0, 0, 1};
112 ASSERT_MATRIX_NEAR(basis, expect);
113}
constexpr Matrix Basis() const
The Matrix without its w components (without translation).
Definition matrix.h:239

References ASSERT_MATRIX_NEAR, and impeller::Matrix::Basis().

◆ TEST() [237/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixGetBasisVectors   
)

Definition at line 408 of file geometry_unittests.cc.

408 {
409 {
410 auto m = Matrix();
411 Vector3 x = m.GetBasisX();
412 Vector3 y = m.GetBasisY();
413 Vector3 z = m.GetBasisZ();
414 ASSERT_VECTOR3_NEAR(x, Vector3(1, 0, 0));
415 ASSERT_VECTOR3_NEAR(y, Vector3(0, 1, 0));
416 ASSERT_VECTOR3_NEAR(z, Vector3(0, 0, 1));
417 }
418
419 {
420 auto m = Matrix::MakeRotationZ(Radians{kPiOver2}) *
421 Matrix::MakeRotationX(Radians{kPiOver2}) *
422 Matrix::MakeScale(Vector3(2, 3, 4));
423 Vector3 x = m.GetBasisX();
424 Vector3 y = m.GetBasisY();
425 Vector3 z = m.GetBasisZ();
426 ASSERT_VECTOR3_NEAR(x, Vector3(0, 2, 0));
427 ASSERT_VECTOR3_NEAR(y, Vector3(0, 0, 3));
428 ASSERT_VECTOR3_NEAR(z, Vector3(4, 0, 0));
429 }
430}
#define ASSERT_VECTOR3_NEAR(a, b)

References ASSERT_VECTOR3_NEAR, impeller::kPiOver2, impeller::Matrix::MakeRotationX(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), x, and y.

◆ TEST() [238/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixGetDirectionScale   
)

Definition at line 432 of file geometry_unittests.cc.

432 {
433 {
434 auto m = Matrix();
435 Scalar result = m.GetDirectionScale(Vector3{1, 0, 0});
436 ASSERT_FLOAT_EQ(result, 1);
437 }
438
439 {
440 auto m = Matrix::MakeRotationX(Degrees{10}) *
441 Matrix::MakeRotationY(Degrees{83}) *
442 Matrix::MakeRotationZ(Degrees{172});
443 Scalar result = m.GetDirectionScale(Vector3{0, 1, 0});
444 ASSERT_FLOAT_EQ(result, 1);
445 }
446
447 {
448 auto m = Matrix::MakeRotationZ(Radians{kPiOver2}) *
449 Matrix::MakeScale(Vector3(3, 4, 5));
450 Scalar result = m.GetDirectionScale(Vector3{2, 0, 0});
451 ASSERT_FLOAT_EQ(result, 8);
452 }
453}
constexpr float kPiOver2
Definition math.h:30

References impeller::Matrix::GetDirectionScale(), impeller::kPiOver2, impeller::Matrix::MakeRotationX(), impeller::Matrix::MakeRotationY(), impeller::Matrix::MakeRotationZ(), and impeller::Matrix::MakeScale().

◆ TEST() [239/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixGetMaxBasisLengthXY   
)

Definition at line 333 of file geometry_unittests.cc.

333 {
334 {
335 auto m = Matrix::MakeScale({3, 1, 1});
336 ASSERT_EQ(m.GetMaxBasisLengthXY(), 3);
337
338 m = m * Matrix::MakeSkew(0, 4);
339 ASSERT_EQ(m.GetMaxBasisLengthXY(), 5);
340 }
341
342 {
343 auto m = Matrix::MakeScale({-3, 4, 7});
344 ASSERT_EQ(m.GetMaxBasisLengthXY(), 4);
345 }
346
347 {
348 // clang-format off
349 auto m = Matrix::MakeColumn(
350 1.0f, 0.0f, 0.0f, 0.0f,
351 0.0f, 1.0f, 0.0f, 0.0f,
352 4.0f, 0.0f, 1.0f, 0.0f,
353 0.0f, 0.0f, 0.0f, 1.0f
354 );
355 // clang-format on
356 ASSERT_EQ(m.GetMaxBasisLengthXY(), 1.0f);
357 }
358}

References impeller::Matrix::MakeColumn(), impeller::Matrix::MakeScale(), and impeller::Matrix::MakeSkew().

◆ TEST() [240/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixLookAt   
)

Definition at line 481 of file geometry_unittests.cc.

481 {
482 {
483 auto m = Matrix::MakeLookAt(Vector3(0, 0, -1), Vector3(0, 0, 1),
484 Vector3(0, 1, 0));
485 auto expected = Matrix{
486 1, 0, 0, 0, //
487 0, 1, 0, 0, //
488 0, 0, 1, 0, //
489 0, 0, 1, 1, //
490 };
491 ASSERT_MATRIX_NEAR(m, expected);
492 }
493
494 // Sideways tilt.
495 {
496 auto m = Matrix::MakeLookAt(Vector3(0, 0, -1), Vector3(0, 0, 1),
497 Vector3(1, 1, 0).Normalize());
498
499 // clang-format off
500 auto expected = Matrix{
501 k1OverSqrt2, k1OverSqrt2, 0, 0,
502 -k1OverSqrt2, k1OverSqrt2, 0, 0,
503 0, 0, 1, 0,
504 0, 0, 1, 1,
505 };
506 // clang-format on
507 ASSERT_MATRIX_NEAR(m, expected);
508 }
509
510 // Half way between +x and -y, yaw 90
511 {
512 auto m =
513 Matrix::MakeLookAt(Vector3(), Vector3(10, -10, 0), Vector3(0, 0, -1));
514
515 // clang-format off
516 auto expected = Matrix{
517 -k1OverSqrt2, 0, k1OverSqrt2, 0,
518 -k1OverSqrt2, 0, -k1OverSqrt2, 0,
519 0, -1, 0, 0,
520 0, 0, 0, 1,
521 };
522 // clang-format on
523 ASSERT_MATRIX_NEAR(m, expected);
524 }
525}
constexpr float k1OverSqrt2
Definition math.h:48

References ASSERT_MATRIX_NEAR, impeller::k1OverSqrt2, and impeller::Matrix::MakeLookAt().

◆ TEST() [241/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixMakeOrthographic   
)

Definition at line 360 of file geometry_unittests.cc.

360 {
361 {
362 auto m = Matrix::MakeOrthographic(Size(100, 200));
363 auto expect = Matrix{
364 0.02, 0, 0, 0, //
365 0, -0.01, 0, 0, //
366 0, 0, 0, 0, //
367 -1, 1, 0.5, 1, //
368 };
369 ASSERT_MATRIX_NEAR(m, expect);
370 }
371
372 {
373 auto m = Matrix::MakeOrthographic(Size(400, 100));
374 auto expect = Matrix{
375 0.005, 0, 0, 0, //
376 0, -0.02, 0, 0, //
377 0, 0, 0, 0, //
378 -1, 1, 0.5, 1, //
379 };
380 ASSERT_MATRIX_NEAR(m, expect);
381 }
382}

References ASSERT_MATRIX_NEAR, and impeller::Matrix::MakeOrthographic().

◆ TEST() [242/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixMakePerspective   
)

Definition at line 384 of file geometry_unittests.cc.

384 {
385 {
386 auto m = Matrix::MakePerspective(Degrees(60), Size(100, 200), 1, 10);
387 auto expect = Matrix{
388 3.4641, 0, 0, 0, //
389 0, 1.73205, 0, 0, //
390 0, 0, 1.11111, 1, //
391 0, 0, -1.11111, 0, //
392 };
393 ASSERT_MATRIX_NEAR(m, expect);
394 }
395
396 {
397 auto m = Matrix::MakePerspective(Radians(1), 2, 10, 20);
398 auto expect = Matrix{
399 0.915244, 0, 0, 0, //
400 0, 1.83049, 0, 0, //
401 0, 0, 2, 1, //
402 0, 0, -20, 0, //
403 };
404 ASSERT_MATRIX_NEAR(m, expect);
405 }
406}

References ASSERT_MATRIX_NEAR, and impeller::Matrix::MakePerspective().

◆ TEST() [243/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixMakeRotationFromQuaternion   
)

Definition at line 278 of file geometry_unittests.cc.

278 {
279 {
280 auto matrix = Matrix::MakeRotation(Quaternion({1, 0, 0}, kPiOver2));
281 auto expected = Matrix::MakeRotationX(Radians(kPiOver2));
282 ASSERT_MATRIX_NEAR(matrix, expected);
283 }
284
285 {
286 auto matrix = Matrix::MakeRotation(Quaternion({0, 1, 0}, kPiOver2));
287 auto expected = Matrix::MakeRotationY(Radians(kPiOver2));
288 ASSERT_MATRIX_NEAR(matrix, expected);
289 }
290
291 {
292 auto matrix = Matrix::MakeRotation(Quaternion({0, 0, 1}, kPiOver2));
293 auto expected = Matrix::MakeRotationZ(Radians(kPiOver2));
294 ASSERT_MATRIX_NEAR(matrix, expected);
295 }
296}

References ASSERT_MATRIX_NEAR, impeller::kPiOver2, impeller::Matrix::MakeRotation(), impeller::Matrix::MakeRotationX(), impeller::Matrix::MakeRotationY(), and impeller::Matrix::MakeRotationZ().

◆ TEST() [244/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixPrinting   
)

Definition at line 1726 of file geometry_unittests.cc.

1726 {
1727 {
1728 std::stringstream stream;
1729 Matrix m;
1730 stream << m;
1731 ASSERT_EQ(stream.str(), R"((
1732 1.000000, 0.000000, 0.000000, 0.000000,
1733 0.000000, 1.000000, 0.000000, 0.000000,
1734 0.000000, 0.000000, 1.000000, 0.000000,
1735 0.000000, 0.000000, 0.000000, 1.000000,
1736))");
1737 }
1738
1739 {
1740 std::stringstream stream;
1741 Matrix m = Matrix::MakeTranslation(Vector3(10, 20, 30));
1742 stream << m;
1743
1744 ASSERT_EQ(stream.str(), R"((
1745 1.000000, 0.000000, 0.000000, 10.000000,
1746 0.000000, 1.000000, 0.000000, 20.000000,
1747 0.000000, 0.000000, 1.000000, 30.000000,
1748 0.000000, 0.000000, 0.000000, 1.000000,
1749))");
1750 }
1751}

References impeller::Matrix::MakeTranslation().

◆ TEST() [245/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixTransformDirection   
)

Definition at line 298 of file geometry_unittests.cc.

298 {
299 {
300 auto matrix = Matrix::MakeTranslation({100, 100, 100}) *
301 Matrix::MakeRotationZ(Radians{kPiOver2}) *
302 Matrix::MakeScale({2.0, 2.0, 2.0});
303 auto vector = Vector4(10, 20, 30, 2);
304
305 Vector4 result = matrix.TransformDirection(vector);
306 auto expected = Vector4(-40, 20, 60, 2);
307 ASSERT_VECTOR4_NEAR(result, expected);
308 }
309
310 {
311 auto matrix = Matrix::MakeTranslation({100, 100, 100}) *
312 Matrix::MakeRotationZ(Radians{kPiOver2}) *
313 Matrix::MakeScale({2.0, 2.0, 2.0});
314 auto vector = Vector3(10, 20, 30);
315
316 Vector3 result = matrix.TransformDirection(vector);
317 auto expected = Vector3(-40, 20, 60);
318 ASSERT_VECTOR3_NEAR(result, expected);
319 }
320
321 {
322 auto matrix = Matrix::MakeTranslation({0, -0.4, 100}) *
323 Matrix::MakeRotationZ(Radians{kPiOver2}) *
324 Matrix::MakeScale({2.0, 2.0, 2.0});
325 auto vector = Point(10, 20);
326
327 Point result = matrix.TransformDirection(vector);
328 auto expected = Point(-40, 20);
329 ASSERT_POINT_NEAR(result, expected);
330 }
331}
#define ASSERT_VECTOR4_NEAR(a, b)
#define ASSERT_POINT_NEAR(a, b)

References ASSERT_POINT_NEAR, ASSERT_VECTOR3_NEAR, ASSERT_VECTOR4_NEAR, impeller::kPiOver2, impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), and impeller::Matrix::MakeTranslation().

◆ TEST() [246/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixTranslationScaleOnly   
)

Definition at line 455 of file geometry_unittests.cc.

455 {
456 {
457 auto m = Matrix();
458 bool result = m.IsTranslationScaleOnly();
459 ASSERT_TRUE(result);
460 }
461
462 {
463 auto m = Matrix::MakeScale(Vector3(2, 3, 4));
464 bool result = m.IsTranslationScaleOnly();
465 ASSERT_TRUE(result);
466 }
467
468 {
469 auto m = Matrix::MakeTranslation(Vector3(2, 3, 4));
470 bool result = m.IsTranslationScaleOnly();
471 ASSERT_TRUE(result);
472 }
473
474 {
475 auto m = Matrix::MakeRotationZ(Degrees(10));
476 bool result = m.IsTranslationScaleOnly();
477 ASSERT_FALSE(result);
478 }
479}

References impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), and impeller::Matrix::MakeTranslation().

◆ TEST() [247/689]

impeller::testing::TEST ( GeometryTest  ,
MatrixVectorMultiplication   
)

Definition at line 213 of file geometry_unittests.cc.

213 {
214 {
215 auto matrix = Matrix::MakeTranslation({100, 100, 100}) *
216 Matrix::MakeRotationZ(Radians{kPiOver2}) *
217 Matrix::MakeScale({2.0, 2.0, 2.0});
218 auto vector = Vector4(10, 20, 30, 2);
219
220 Vector4 result = matrix * vector;
221 auto expected = Vector4(160, 220, 260, 2);
222 ASSERT_VECTOR4_NEAR(result, expected);
223 }
224
225 {
226 auto matrix = Matrix::MakeTranslation({100, 100, 100}) *
227 Matrix::MakeRotationZ(Radians{kPiOver2}) *
228 Matrix::MakeScale({2.0, 2.0, 2.0});
229 auto vector = Vector3(10, 20, 30);
230
231 Vector3 result = matrix * vector;
232 auto expected = Vector3(60, 120, 160);
233 ASSERT_VECTOR3_NEAR(result, expected);
234 }
235
236 {
237 auto matrix = Matrix::MakeTranslation({100, 100, 100}) *
238 Matrix::MakeRotationZ(Radians{kPiOver2}) *
239 Matrix::MakeScale({2.0, 2.0, 2.0});
240 auto vector = Point(10, 20);
241
242 Point result = matrix * vector;
243 auto expected = Point(60, 120);
244 ASSERT_POINT_NEAR(result, expected);
245 }
246
247 // Matrix Vector ops should respect perspective transforms.
248 {
249 auto matrix = Matrix::MakePerspective(Radians(kPiOver2), 1, 1, 100);
250 auto vector = Vector3(3, 3, -3);
251
252 Vector3 result = matrix * vector;
253 auto expected = Vector3(-1, -1, 1.3468);
254 ASSERT_VECTOR3_NEAR(result, expected);
255 }
256
257 {
258 auto matrix = Matrix::MakePerspective(Radians(kPiOver2), 1, 1, 100) *
259 Matrix::MakeTranslation(Vector3(0, 0, -3));
260 auto point = Point(3, 3);
261
262 Point result = matrix * point;
263 auto expected = Point(-1, -1);
264 ASSERT_POINT_NEAR(result, expected);
265 }
266
267 // Resolves to 0 on perspective singularity.
268 {
269 auto matrix = Matrix::MakePerspective(Radians(kPiOver2), 1, 1, 100);
270 auto point = Point(3, 3);
271
272 Point result = matrix * point;
273 auto expected = Point(0, 0);
274 ASSERT_POINT_NEAR(result, expected);
275 }
276}

References ASSERT_POINT_NEAR, ASSERT_VECTOR3_NEAR, ASSERT_VECTOR4_NEAR, impeller::kPiOver2, impeller::Matrix::MakePerspective(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), and impeller::Matrix::MakeTranslation().

◆ TEST() [248/689]

impeller::testing::TEST ( GeometryTest  ,
MutliplicationMatrix   
)

Definition at line 115 of file geometry_unittests.cc.

115 {
116 auto rotation = Matrix::MakeRotationZ(Radians{kPiOver4});
117 auto invert = rotation.Invert();
118 ASSERT_MATRIX_NEAR(rotation * invert, Matrix{});
119}

References ASSERT_MATRIX_NEAR, impeller::Matrix::Invert(), impeller::kPiOver4, and impeller::Matrix::MakeRotationZ().

◆ TEST() [249/689]

impeller::testing::TEST ( GeometryTest  ,
PointAbs   
)

Definition at line 938 of file geometry_unittests.cc.

938 {
939 Point a(-1, -2);
940 auto a_abs = a.Abs();
941 auto expected = Point(1, 2);
942 ASSERT_POINT_NEAR(a_abs, expected);
943}

References ASSERT_POINT_NEAR.

◆ TEST() [250/689]

impeller::testing::TEST ( GeometryTest  ,
PointAngleTo   
)

Definition at line 975 of file geometry_unittests.cc.

975 {
976 // Negative result in the CCW (with up = -Y) direction.
977 {
978 Point a(1, 1);
979 Point b(1, -1);
980 Radians actual = a.AngleTo(b);
981 Radians expected = Radians{-kPi / 2};
982 ASSERT_FLOAT_EQ(actual.radians, expected.radians);
983 }
984
985 // Check the other direction to ensure the result is signed correctly.
986 {
987 Point a(1, -1);
988 Point b(1, 1);
989 Radians actual = a.AngleTo(b);
990 Radians expected = Radians{kPi / 2};
991 ASSERT_FLOAT_EQ(actual.radians, expected.radians);
992 }
993
994 // Differences in magnitude should have no impact on the result.
995 {
996 Point a(100, -100);
997 Point b(0.01, 0.01);
998 Radians actual = a.AngleTo(b);
999 Radians expected = Radians{kPi / 2};
1000 ASSERT_FLOAT_EQ(actual.radians, expected.radians);
1001 }
1002}
constexpr float kPi
Definition math.h:27

References flutter::kPi, and impeller::Radians::radians.

◆ TEST() [251/689]

impeller::testing::TEST ( GeometryTest  ,
PointCeil   
)

Definition at line 1113 of file geometry_unittests.cc.

1113 {
1114 Point p(1.5, 2.3);
1115 Point result = p.Ceil();
1116 Point expected(2, 3);
1117 ASSERT_POINT_NEAR(result, expected);
1118}

References ASSERT_POINT_NEAR.

◆ TEST() [252/689]

impeller::testing::TEST ( GeometryTest  ,
PointCrossProduct   
)

Definition at line 893 of file geometry_unittests.cc.

893 {
894 {
895 Point p(1, 0);
896 Scalar s = p.Cross(Point(-1, 0));
897 ASSERT_FLOAT_EQ(s, 0);
898 }
899
900 {
901 Point p(0, -1);
902 Scalar s = p.Cross(Point(-1, 0));
903 ASSERT_FLOAT_EQ(s, -1);
904 }
905
906 {
907 Point p(1, 2);
908 Scalar s = p.Cross(Point(3, -4));
909 ASSERT_FLOAT_EQ(s, -10);
910 }
911}

◆ TEST() [253/689]

impeller::testing::TEST ( GeometryTest  ,
PointDotProduct   
)

Definition at line 873 of file geometry_unittests.cc.

873 {
874 {
875 Point p(1, 0);
876 Scalar s = p.Dot(Point(-1, 0));
877 ASSERT_FLOAT_EQ(s, -1);
878 }
879
880 {
881 Point p(0, -1);
882 Scalar s = p.Dot(Point(-1, 0));
883 ASSERT_FLOAT_EQ(s, 0);
884 }
885
886 {
887 Point p(1, 2);
888 Scalar s = p.Dot(Point(3, -4));
889 ASSERT_FLOAT_EQ(s, -5);
890 }
891}

◆ TEST() [254/689]

impeller::testing::TEST ( GeometryTest  ,
PointFloor   
)

Definition at line 1092 of file geometry_unittests.cc.

1092 {
1093 Point p(1.5, 2.3);
1094 Point result = p.Floor();
1095 Point expected(1, 2);
1096 ASSERT_POINT_NEAR(result, expected);
1097}

References ASSERT_POINT_NEAR.

◆ TEST() [255/689]

impeller::testing::TEST ( GeometryTest  ,
PointIntegerCoercesToFloat   
)

Definition at line 678 of file geometry_unittests.cc.

678 {
679 // Integer on LHS, float on RHS
680 {
681 IPoint p1(1, 2);
682 Point p2 = p1 + Point(1, 2);
683 ASSERT_FLOAT_EQ(p2.x, 2u);
684 ASSERT_FLOAT_EQ(p2.y, 4u);
685 }
686
687 {
688 IPoint p1(3, 6);
689 Point p2 = p1 - Point(1, 2);
690 ASSERT_FLOAT_EQ(p2.x, 2u);
691 ASSERT_FLOAT_EQ(p2.y, 4u);
692 }
693
694 {
695 IPoint p1(1, 2);
696 Point p2 = p1 * Point(2, 3);
697 ASSERT_FLOAT_EQ(p2.x, 2u);
698 ASSERT_FLOAT_EQ(p2.y, 6u);
699 }
700
701 {
702 IPoint p1(2, 6);
703 Point p2 = p1 / Point(2, 3);
704 ASSERT_FLOAT_EQ(p2.x, 1u);
705 ASSERT_FLOAT_EQ(p2.y, 2u);
706 }
707
708 // Float on LHS, integer on RHS
709 {
710 Point p1(1, 2);
711 Point p2 = p1 + IPoint(1, 2);
712 ASSERT_FLOAT_EQ(p2.x, 2u);
713 ASSERT_FLOAT_EQ(p2.y, 4u);
714 }
715
716 {
717 Point p1(3, 6);
718 Point p2 = p1 - IPoint(1, 2);
719 ASSERT_FLOAT_EQ(p2.x, 2u);
720 ASSERT_FLOAT_EQ(p2.y, 4u);
721 }
722
723 {
724 Point p1(1, 2);
725 Point p2 = p1 * IPoint(2, 3);
726 ASSERT_FLOAT_EQ(p2.x, 2u);
727 ASSERT_FLOAT_EQ(p2.y, 6u);
728 }
729
730 {
731 Point p1(2, 6);
732 Point p2 = p1 / IPoint(2, 3);
733 ASSERT_FLOAT_EQ(p2.x, 1u);
734 ASSERT_FLOAT_EQ(p2.y, 2u);
735 }
736}

References p1, p2, flutter::Point::x(), and flutter::Point::y().

◆ TEST() [256/689]

impeller::testing::TEST ( GeometryTest  ,
PointLerp   
)

Definition at line 1155 of file geometry_unittests.cc.

1155 {
1156 Point p(1, 2);
1157 Point result = p.Lerp({5, 10}, 0.75);
1158 Point expected(4, 8);
1159 ASSERT_POINT_NEAR(result, expected);
1160}

References ASSERT_POINT_NEAR.

◆ TEST() [257/689]

impeller::testing::TEST ( GeometryTest  ,
PointMax   
)

Definition at line 1071 of file geometry_unittests.cc.

1071 {
1072 Point p(1, 2);
1073 Point result = p.Max({0, 10});
1074 Point expected(1, 10);
1075 ASSERT_POINT_NEAR(result, expected);
1076}

References ASSERT_POINT_NEAR.

◆ TEST() [258/689]

impeller::testing::TEST ( GeometryTest  ,
PointMin   
)

Definition at line 1004 of file geometry_unittests.cc.

1004 {
1005 Point p(1, 2);
1006 Point result = p.Min({0, 10});
1007 Point expected(0, 2);
1008 ASSERT_POINT_NEAR(result, expected);
1009}

References ASSERT_POINT_NEAR.

◆ TEST() [259/689]

impeller::testing::TEST ( GeometryTest  ,
PointPrinting   
)

Definition at line 1753 of file geometry_unittests.cc.

1753 {
1754 {
1755 std::stringstream stream;
1756 Point m;
1757 stream << m;
1758 ASSERT_EQ(stream.str(), "(0, 0)");
1759 }
1760
1761 {
1762 std::stringstream stream;
1763 Point m(13, 37);
1764 stream << m;
1765 ASSERT_EQ(stream.str(), "(13, 37)");
1766 }
1767}

◆ TEST() [260/689]

impeller::testing::TEST ( GeometryTest  ,
PointReflect   
)

Definition at line 913 of file geometry_unittests.cc.

913 {
914 {
915 Point axis = Point(0, 1);
916 Point a(2, 3);
917 auto reflected = a.Reflect(axis);
918 auto expected = Point(2, -3);
919 ASSERT_POINT_NEAR(reflected, expected);
920 }
921
922 {
923 Point axis = Point(1, 1).Normalize();
924 Point a(1, 0);
925 auto reflected = a.Reflect(axis);
926 auto expected = Point(0, -1);
927 ASSERT_POINT_NEAR(reflected, expected);
928 }
929
930 {
931 Point axis = Point(1, 1).Normalize();
932 Point a(-1, -1);
933 auto reflected = a.Reflect(axis);
934 ASSERT_POINT_NEAR(reflected, -a);
935 }
936}
constexpr TPoint Normalize() const
Definition point.h:286

References ASSERT_POINT_NEAR.

◆ TEST() [261/689]

impeller::testing::TEST ( GeometryTest  ,
PointRotate   
)

Definition at line 945 of file geometry_unittests.cc.

945 {
946 {
947 Point a(1, 0);
948 auto rotated = a.Rotate(Radians{kPiOver2});
949 auto expected = Point(0, 1);
950 ASSERT_POINT_NEAR(rotated, expected);
951 }
952
953 {
954 Point a(1, 0);
955 auto rotated = a.Rotate(Radians{-kPiOver2});
956 auto expected = Point(0, -1);
957 ASSERT_POINT_NEAR(rotated, expected);
958 }
959
960 {
961 Point a(1, 0);
962 auto rotated = a.Rotate(Radians{kPi});
963 auto expected = Point(-1, 0);
964 ASSERT_POINT_NEAR(rotated, expected);
965 }
966
967 {
968 Point a(1, 0);
969 auto rotated = a.Rotate(Radians{kPi * 1.5});
970 auto expected = Point(0, -1);
971 ASSERT_POINT_NEAR(rotated, expected);
972 }
973}

References ASSERT_POINT_NEAR, flutter::kPi, and impeller::kPiOver2.

◆ TEST() [262/689]

impeller::testing::TEST ( GeometryTest  ,
PointRound   
)

Definition at line 1134 of file geometry_unittests.cc.

1134 {
1135 Point p(1.5, 2.3);
1136 Point result = p.Round();
1137 Point expected(2, 2);
1138 ASSERT_POINT_NEAR(result, expected);
1139}

References ASSERT_POINT_NEAR.

◆ TEST() [263/689]

impeller::testing::TEST ( GeometryTest  ,
QuaternionLerp   
)

Definition at line 527 of file geometry_unittests.cc.

527 {
528 auto q1 = Quaternion{{0.0, 0.0, 1.0}, 0.0};
529 auto q2 = Quaternion{{0.0, 0.0, 1.0}, kPiOver4};
530
531 auto q3 = q1.Slerp(q2, 0.5);
532
533 auto expected = Quaternion{{0.0, 0.0, 1.0}, kPiOver4 / 2.0};
534
535 ASSERT_QUATERNION_NEAR(q3, expected);
536}
#define ASSERT_QUATERNION_NEAR(a, b)
constexpr float kPiOver4
Definition math.h:33

References ASSERT_QUATERNION_NEAR, impeller::kPiOver4, and impeller::Quaternion::Slerp().

◆ TEST() [264/689]

impeller::testing::TEST ( GeometryTest  ,
QuaternionVectorMultiply   
)

Definition at line 538 of file geometry_unittests.cc.

538 {
539 {
540 Quaternion q({0, 0, 1}, 0);
541 Vector3 v(0, 1, 0);
542
543 Vector3 result = q * v;
544 Vector3 expected(0, 1, 0);
545
546 ASSERT_VECTOR3_NEAR(result, expected);
547 }
548
549 {
550 Quaternion q({0, 0, 1}, k2Pi);
551 Vector3 v(1, 0, 0);
552
553 Vector3 result = q * v;
554 Vector3 expected(1, 0, 0);
555
556 ASSERT_VECTOR3_NEAR(result, expected);
557 }
558
559 {
560 Quaternion q({0, 0, 1}, kPiOver4);
561 Vector3 v(0, 1, 0);
562
563 Vector3 result = q * v;
564 Vector3 expected(-k1OverSqrt2, k1OverSqrt2, 0);
565
566 ASSERT_VECTOR3_NEAR(result, expected);
567 }
568
569 {
570 Quaternion q(Vector3(1, 0, 1).Normalize(), kPi);
571 Vector3 v(0, 0, -1);
572
573 Vector3 result = q * v;
574 Vector3 expected(-1, 0, 0);
575
576 ASSERT_VECTOR3_NEAR(result, expected);
577 }
578}
constexpr float k2Pi
Definition constants.h:29

References ASSERT_VECTOR3_NEAR, impeller::k1OverSqrt2, impeller::k2Pi, flutter::kPi, and impeller::kPiOver4.

◆ TEST() [265/689]

impeller::testing::TEST ( GeometryTest  ,
RotationMatrix   
)

Definition at line 68 of file geometry_unittests.cc.

68 {
69 auto rotation = Matrix::MakeRotationZ(Radians{kPiOver4});
70 // clang-format off
71 auto expect = Matrix{k1OverSqrt2, k1OverSqrt2, 0, 0,
72 -k1OverSqrt2, k1OverSqrt2, 0, 0,
73 0, 0, 1, 0,
74 0, 0, 0, 1};
75 // clang-format on
76 ASSERT_MATRIX_NEAR(rotation, expect);
77}

References ASSERT_MATRIX_NEAR, impeller::k1OverSqrt2, impeller::kPiOver4, and impeller::Matrix::MakeRotationZ().

◆ TEST() [266/689]

impeller::testing::TEST ( GeometryTest  ,
ScalarNearlyEqual   
)

Definition at line 31 of file geometry_unittests.cc.

31 {
32 ASSERT_FALSE(ScalarNearlyEqual(0.0021f, 0.001f));
33 ASSERT_TRUE(ScalarNearlyEqual(0.0019f, 0.001f));
34 ASSERT_TRUE(ScalarNearlyEqual(0.002f, 0.001f, 0.0011f));
35 ASSERT_FALSE(ScalarNearlyEqual(0.002f, 0.001f, 0.0009f));
36 ASSERT_TRUE(ScalarNearlyEqual(
37 1.0f, 1.0f + std::numeric_limits<float>::epsilon() * 4));
38}
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition scalar.h:36

References impeller::ScalarNearlyEqual().

◆ TEST() [267/689]

impeller::testing::TEST ( GeometryTest  ,
SeparatedVector2AngleTo   
)

Definition at line 1210 of file geometry_unittests.cc.

1210 {
1211 {
1212 SeparatedVector2 v(Vector2(10, 0));
1213 Radians actual = v.AngleTo(SeparatedVector2(Vector2(5, 0)));
1214 Radians expected = Radians{0};
1215 ASSERT_NEAR(actual.radians, expected.radians, kEhCloseEnough);
1216 }
1217
1218 {
1219 SeparatedVector2 v(Vector2(10, 0));
1220 Radians actual = v.AngleTo(SeparatedVector2(Vector2(0, -5)));
1221 Radians expected = Radians{-kPi / 2};
1222 ASSERT_NEAR(actual.radians, expected.radians, kEhCloseEnough);
1223 }
1224}
A Vector2, broken down as a separate magnitude and direction. Assumes that the direction given is nor...

References impeller::SeparatedVector2::AngleTo(), flutter::kEhCloseEnough, flutter::kPi, and impeller::Radians::radians.

◆ TEST() [268/689]

impeller::testing::TEST ( GeometryTest  ,
SeparatedVector2GetAlignment   
)

Definition at line 1187 of file geometry_unittests.cc.

1187 {
1188 // Parallel
1189 {
1190 SeparatedVector2 v(Vector2(10, 0));
1191 Scalar actual = v.GetAlignment(SeparatedVector2(Vector2(5, 0)));
1192 ASSERT_NEAR(actual, 1, kEhCloseEnough);
1193 }
1194
1195 // Perpendicular
1196 {
1197 SeparatedVector2 v(Vector2(10, 0));
1198 Scalar actual = v.GetAlignment(SeparatedVector2(Vector2(0, 5)));
1199 ASSERT_NEAR(actual, 0, kEhCloseEnough);
1200 }
1201
1202 // Opposite parallel
1203 {
1204 SeparatedVector2 v(Vector2(0, 10));
1205 Scalar actual = v.GetAlignment(SeparatedVector2(Vector2(0, -5)));
1206 ASSERT_NEAR(actual, -1, kEhCloseEnough);
1207 }
1208}

References impeller::SeparatedVector2::GetAlignment(), and flutter::kEhCloseEnough.

◆ TEST() [269/689]

impeller::testing::TEST ( GeometryTest  ,
SeparatedVector2GetVector   
)

Definition at line 1182 of file geometry_unittests.cc.

1182 {
1183 SeparatedVector2 v(Vector2(10, 0));
1184 ASSERT_POINT_NEAR(v.GetVector(), Vector2(10, 0));
1185}

References ASSERT_POINT_NEAR, and impeller::SeparatedVector2::GetVector().

◆ TEST() [270/689]

impeller::testing::TEST ( GeometryTest  ,
SeparatedVector2NormalizesWithConstructor   
)

Definition at line 1176 of file geometry_unittests.cc.

1176 {
1177 SeparatedVector2 v(Vector2(10, 0));
1178 ASSERT_POINT_NEAR(v.direction, Vector2(1, 0));
1179 ASSERT_NEAR(v.magnitude, 10, kEhCloseEnough);
1180}

References ASSERT_POINT_NEAR, impeller::SeparatedVector2::direction, flutter::kEhCloseEnough, and impeller::SeparatedVector2::magnitude.

◆ TEST() [271/689]

impeller::testing::TEST ( GeometryTest  ,
SizeCoercesToPoint   
)

Definition at line 738 of file geometry_unittests.cc.

738 {
739 // Point on LHS, Size on RHS
740 {
741 IPoint p1(1, 2);
742 IPoint p2 = p1 + ISize(1, 2);
743 ASSERT_EQ(p2.x, 2u);
744 ASSERT_EQ(p2.y, 4u);
745 }
746
747 {
748 IPoint p1(3, 6);
749 IPoint p2 = p1 - ISize(1, 2);
750 ASSERT_EQ(p2.x, 2u);
751 ASSERT_EQ(p2.y, 4u);
752 }
753
754 {
755 IPoint p1(1, 2);
756 IPoint p2 = p1 * ISize(2, 3);
757 ASSERT_EQ(p2.x, 2u);
758 ASSERT_EQ(p2.y, 6u);
759 }
760
761 {
762 IPoint p1(2, 6);
763 IPoint p2 = p1 / ISize(2, 3);
764 ASSERT_EQ(p2.x, 1u);
765 ASSERT_EQ(p2.y, 2u);
766 }
767
768 // Size on LHS, Point on RHS
769 {
770 ISize p1(1, 2);
771 IPoint p2 = p1 + IPoint(1, 2);
772 ASSERT_EQ(p2.x, 2u);
773 ASSERT_EQ(p2.y, 4u);
774 }
775
776 {
777 ISize p1(3, 6);
778 IPoint p2 = p1 - IPoint(1, 2);
779 ASSERT_EQ(p2.x, 2u);
780 ASSERT_EQ(p2.y, 4u);
781 }
782
783 {
784 ISize p1(1, 2);
785 IPoint p2 = p1 * IPoint(2, 3);
786 ASSERT_EQ(p2.x, 2u);
787 ASSERT_EQ(p2.y, 6u);
788 }
789
790 {
791 ISize p1(2, 6);
792 IPoint p2 = p1 / IPoint(2, 3);
793 ASSERT_EQ(p2.x, 1u);
794 ASSERT_EQ(p2.y, 2u);
795 }
796}

References p1, p2, flutter::Point::x(), and flutter::Point::y().

◆ TEST() [272/689]

impeller::testing::TEST ( GeometryTest  ,
TestDecomposition   
)

Definition at line 142 of file geometry_unittests.cc.

142 {
143 auto rotated = Matrix::MakeRotationZ(Radians{kPiOver4});
144
145 auto result = rotated.Decompose();
146
147 ASSERT_TRUE(result.has_value());
148
149 MatrixDecomposition res = result.value();
150
151 auto quaternion = Quaternion{{0.0, 0.0, 1.0}, kPiOver4};
152 ASSERT_QUATERNION_NEAR(res.rotation, quaternion);
153}

References ASSERT_QUATERNION_NEAR, impeller::Matrix::Decompose(), impeller::kPiOver4, impeller::Matrix::MakeRotationZ(), and impeller::MatrixDecomposition::rotation.

◆ TEST() [273/689]

impeller::testing::TEST ( GeometryTest  ,
TestDecomposition2   
)

Definition at line 155 of file geometry_unittests.cc.

155 {
156 auto rotated = Matrix::MakeRotationZ(Radians{kPiOver4});
157 auto scaled = Matrix::MakeScale({2.0, 3.0, 1.0});
158 auto translated = Matrix::MakeTranslation({-200, 750, 20});
159
160 auto result = (translated * rotated * scaled).Decompose();
161
162 ASSERT_TRUE(result.has_value());
163
164 MatrixDecomposition res = result.value();
165
166 auto quaternion = Quaternion{{0.0, 0.0, 1.0}, kPiOver4};
167
168 ASSERT_QUATERNION_NEAR(res.rotation, quaternion);
169
170 ASSERT_FLOAT_EQ(res.translation.x, -200);
171 ASSERT_FLOAT_EQ(res.translation.y, 750);
172 ASSERT_FLOAT_EQ(res.translation.z, 20);
173
174 ASSERT_FLOAT_EQ(res.scale.x, 2);
175 ASSERT_FLOAT_EQ(res.scale.y, 3);
176 ASSERT_FLOAT_EQ(res.scale.z, 1);
177}

References ASSERT_QUATERNION_NEAR, impeller::kPiOver4, impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::MatrixDecomposition::rotation, impeller::MatrixDecomposition::scale, impeller::MatrixDecomposition::translation, impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

◆ TEST() [274/689]

impeller::testing::TEST ( GeometryTest  ,
TestRecomposition   
)

Definition at line 179 of file geometry_unittests.cc.

179 {
180 /*
181 * Decomposition.
182 */
183 auto rotated = Matrix::MakeRotationZ(Radians{kPiOver4});
184
185 auto result = rotated.Decompose();
186
187 ASSERT_TRUE(result.has_value());
188
189 MatrixDecomposition res = result.value();
190
191 auto quaternion = Quaternion{{0.0, 0.0, 1.0}, kPiOver4};
192
193 ASSERT_QUATERNION_NEAR(res.rotation, quaternion);
194
195 /*
196 * Recomposition.
197 */
198 ASSERT_MATRIX_NEAR(rotated, Matrix{res});
199}

References ASSERT_MATRIX_NEAR, ASSERT_QUATERNION_NEAR, impeller::Matrix::Decompose(), impeller::kPiOver4, impeller::Matrix::MakeRotationZ(), and impeller::MatrixDecomposition::rotation.

◆ TEST() [275/689]

impeller::testing::TEST ( GeometryTest  ,
TestRecomposition2   
)

Definition at line 201 of file geometry_unittests.cc.

201 {
202 auto matrix = Matrix::MakeTranslation({100, 100, 100}) *
203 Matrix::MakeRotationZ(Radians{kPiOver4}) *
204 Matrix::MakeScale({2.0, 2.0, 2.0});
205
206 auto result = matrix.Decompose();
207
208 ASSERT_TRUE(result.has_value());
209
210 ASSERT_MATRIX_NEAR(matrix, Matrix{result.value()});
211}

References ASSERT_MATRIX_NEAR, impeller::Matrix::Decompose(), impeller::kPiOver4, impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), and impeller::Matrix::MakeTranslation().

◆ TEST() [276/689]

impeller::testing::TEST ( GeometryTest  ,
ToIColor   
)

Definition at line 1817 of file geometry_unittests.cc.

1817 {
1818 ASSERT_EQ(Color::ToIColor(Color(0, 0, 0, 0)), 0u);
1819 ASSERT_EQ(Color::ToIColor(Color(1.0, 1.0, 1.0, 1.0)), 0xFFFFFFFF);
1820 ASSERT_EQ(Color::ToIColor(Color(0.5, 0.5, 1.0, 1.0)), 0xFF8080FF);
1821}

References impeller::Color::ToIColor().

◆ TEST() [277/689]

impeller::testing::TEST ( GeometryTest  ,
Vector3Ceil   
)

Definition at line 1120 of file geometry_unittests.cc.

1120 {
1121 Vector3 p(1.5, 2.3, 3.9);
1122 Vector3 result = p.Ceil();
1123 Vector3 expected(2, 3, 4);
1124 ASSERT_VECTOR3_NEAR(result, expected);
1125}
Vector3 Ceil() const
Definition vector.h:82

References ASSERT_VECTOR3_NEAR, and impeller::Vector3::Ceil().

◆ TEST() [278/689]

impeller::testing::TEST ( GeometryTest  ,
Vector3Floor   
)

Definition at line 1099 of file geometry_unittests.cc.

1099 {
1100 Vector3 p(1.5, 2.3, 3.9);
1101 Vector3 result = p.Floor();
1102 Vector3 expected(1, 2, 3);
1103 ASSERT_VECTOR3_NEAR(result, expected);
1104}
Vector3 Floor() const
Definition vector.h:78

References ASSERT_VECTOR3_NEAR, and impeller::Vector3::Floor().

◆ TEST() [279/689]

impeller::testing::TEST ( GeometryTest  ,
Vector3Lerp   
)

Definition at line 1162 of file geometry_unittests.cc.

1162 {
1163 Vector3 p(1, 2, 3);
1164 Vector3 result = p.Lerp({5, 10, 15}, 0.75);
1165 Vector3 expected(4, 8, 12);
1166 ASSERT_VECTOR3_NEAR(result, expected);
1167}
constexpr Vector3 Lerp(const Vector3 &v, Scalar t) const
Definition vector.h:178

References ASSERT_VECTOR3_NEAR, and impeller::Vector3::Lerp().

◆ TEST() [280/689]

impeller::testing::TEST ( GeometryTest  ,
Vector3Max   
)

Definition at line 1078 of file geometry_unittests.cc.

1078 {
1079 Vector3 p(1, 2, 3);
1080 Vector3 result = p.Max({0, 10, 2});
1081 Vector3 expected(1, 10, 3);
1082 ASSERT_VECTOR3_NEAR(result, expected);
1083}
Vector3 Max(const Vector3 &p) const
Definition vector.h:74

References ASSERT_VECTOR3_NEAR, and impeller::Vector3::Max().

◆ TEST() [281/689]

impeller::testing::TEST ( GeometryTest  ,
Vector3Min   
)

Definition at line 1057 of file geometry_unittests.cc.

1057 {
1058 Vector3 p(1, 2, 3);
1059 Vector3 result = p.Min({0, 10, 2});
1060 Vector3 expected(0, 2, 2);
1061 ASSERT_VECTOR3_NEAR(result, expected);
1062}
Vector3 Min(const Vector3 &p) const
Definition vector.h:70

References ASSERT_VECTOR3_NEAR, and impeller::Vector3::Min().

◆ TEST() [282/689]

impeller::testing::TEST ( GeometryTest  ,
Vector3Printing   
)

Definition at line 1769 of file geometry_unittests.cc.

1769 {
1770 {
1771 std::stringstream stream;
1772 Vector3 m;
1773 stream << m;
1774 ASSERT_EQ(stream.str(), "(0, 0, 0)");
1775 }
1776
1777 {
1778 std::stringstream stream;
1779 Vector3 m(1, 2, 3);
1780 stream << m;
1781 ASSERT_EQ(stream.str(), "(1, 2, 3)");
1782 }
1783}

◆ TEST() [283/689]

impeller::testing::TEST ( GeometryTest  ,
Vector3Round   
)

Definition at line 1141 of file geometry_unittests.cc.

1141 {
1142 Vector3 p(1.5, 2.3, 3.9);
1143 Vector3 result = p.Round();
1144 Vector3 expected(2, 2, 4);
1145 ASSERT_VECTOR3_NEAR(result, expected);
1146}
Vector3 Round() const
Definition vector.h:86

References ASSERT_VECTOR3_NEAR, and impeller::Vector3::Round().

◆ TEST() [284/689]

impeller::testing::TEST ( GeometryTest  ,
Vector4Ceil   
)

Definition at line 1127 of file geometry_unittests.cc.

1127 {
1128 Vector4 p(1.5, 2.3, 3.9, 4.0);
1129 Vector4 result = p.Ceil();
1130 Vector4 expected(2, 3, 4, 4);
1131 ASSERT_VECTOR4_NEAR(result, expected);
1132}
Vector4 Ceil() const
Definition vector.h:304

References ASSERT_VECTOR4_NEAR, and impeller::Vector4::Ceil().

◆ TEST() [285/689]

impeller::testing::TEST ( GeometryTest  ,
Vector4Floor   
)

Definition at line 1106 of file geometry_unittests.cc.

1106 {
1107 Vector4 p(1.5, 2.3, 3.9, 4.0);
1108 Vector4 result = p.Floor();
1109 Vector4 expected(1, 2, 3, 4);
1110 ASSERT_VECTOR4_NEAR(result, expected);
1111}
Vector4 Floor() const
Definition vector.h:300

References ASSERT_VECTOR4_NEAR, and impeller::Vector4::Floor().

◆ TEST() [286/689]

impeller::testing::TEST ( GeometryTest  ,
Vector4IsFinite   
)

Definition at line 1011 of file geometry_unittests.cc.

1011 {
1012 {
1013 Vector4 v;
1014 ASSERT_TRUE(v.IsFinite());
1015 v.x = std::numeric_limits<Scalar>::infinity();
1016 ASSERT_FALSE(v.IsFinite());
1017 v.x = -std::numeric_limits<Scalar>::infinity();
1018 ASSERT_FALSE(v.IsFinite());
1019 v.x = -std::numeric_limits<Scalar>::quiet_NaN();
1020 ASSERT_FALSE(v.IsFinite());
1021 }
1022
1023 {
1024 Vector4 v;
1025 ASSERT_TRUE(v.IsFinite());
1026 v.y = std::numeric_limits<Scalar>::infinity();
1027 ASSERT_FALSE(v.IsFinite());
1028 v.y = -std::numeric_limits<Scalar>::infinity();
1029 ASSERT_FALSE(v.IsFinite());
1030 v.y = -std::numeric_limits<Scalar>::quiet_NaN();
1031 ASSERT_FALSE(v.IsFinite());
1032 }
1033
1034 {
1035 Vector4 v;
1036 ASSERT_TRUE(v.IsFinite());
1037 v.z = std::numeric_limits<Scalar>::infinity();
1038 ASSERT_FALSE(v.IsFinite());
1039 v.z = -std::numeric_limits<Scalar>::infinity();
1040 ASSERT_FALSE(v.IsFinite());
1041 v.z = -std::numeric_limits<Scalar>::quiet_NaN();
1042 ASSERT_FALSE(v.IsFinite());
1043 }
1044
1045 {
1046 Vector4 v;
1047 ASSERT_TRUE(v.IsFinite());
1048 v.w = std::numeric_limits<Scalar>::infinity();
1049 ASSERT_FALSE(v.IsFinite());
1050 v.w = -std::numeric_limits<Scalar>::infinity();
1051 ASSERT_FALSE(v.IsFinite());
1052 v.w = -std::numeric_limits<Scalar>::quiet_NaN();
1053 ASSERT_FALSE(v.IsFinite());
1054 }
1055}
bool IsFinite() const
Definition vector.h:256

References impeller::Vector4::IsFinite(), impeller::Vector4::w, impeller::Vector4::x, impeller::Vector4::y, and impeller::Vector4::z.

◆ TEST() [287/689]

impeller::testing::TEST ( GeometryTest  ,
Vector4Lerp   
)

Definition at line 1169 of file geometry_unittests.cc.

1169 {
1170 Vector4 p(1, 2, 3, 4);
1171 Vector4 result = p.Lerp({5, 10, 15, 20}, 0.75);
1172 Vector4 expected(4, 8, 12, 16);
1173 ASSERT_VECTOR4_NEAR(result, expected);
1174}
constexpr Vector4 Lerp(const Vector4 &v, Scalar t) const
Definition vector.h:312

References ASSERT_VECTOR4_NEAR, and impeller::Vector4::Lerp().

◆ TEST() [288/689]

impeller::testing::TEST ( GeometryTest  ,
Vector4Max   
)

Definition at line 1085 of file geometry_unittests.cc.

1085 {
1086 Vector4 p(1, 2, 3, 4);
1087 Vector4 result = p.Max({0, 10, 2, 1});
1088 Vector4 expected(1, 10, 3, 4);
1089 ASSERT_VECTOR4_NEAR(result, expected);
1090}
constexpr Vector4 Max(const Vector4 &p) const
Definition vector.h:295

References ASSERT_VECTOR4_NEAR, and impeller::Vector4::Max().

◆ TEST() [289/689]

impeller::testing::TEST ( GeometryTest  ,
Vector4Min   
)

Definition at line 1064 of file geometry_unittests.cc.

1064 {
1065 Vector4 p(1, 2, 3, 4);
1066 Vector4 result = p.Min({0, 10, 2, 1});
1067 Vector4 expected(0, 2, 2, 1);
1068 ASSERT_VECTOR4_NEAR(result, expected);
1069}
constexpr Vector4 Min(const Vector4 &p) const
Definition vector.h:290

References ASSERT_VECTOR4_NEAR, and impeller::Vector4::Min().

◆ TEST() [290/689]

impeller::testing::TEST ( GeometryTest  ,
Vector4Printing   
)

Definition at line 1785 of file geometry_unittests.cc.

1785 {
1786 {
1787 std::stringstream stream;
1788 Vector4 m;
1789 stream << m;
1790 ASSERT_EQ(stream.str(), "(0, 0, 0, 1)");
1791 }
1792
1793 {
1794 std::stringstream stream;
1795 Vector4 m(1, 2, 3, 4);
1796 stream << m;
1797 ASSERT_EQ(stream.str(), "(1, 2, 3, 4)");
1798 }
1799}

◆ TEST() [291/689]

impeller::testing::TEST ( GeometryTest  ,
Vector4Round   
)

Definition at line 1148 of file geometry_unittests.cc.

1148 {
1149 Vector4 p(1.5, 2.3, 3.9, 4.0);
1150 Vector4 result = p.Round();
1151 Vector4 expected(2, 2, 4, 4);
1152 ASSERT_VECTOR4_NEAR(result, expected);
1153}
Vector4 Round() const
Definition vector.h:308

References ASSERT_VECTOR4_NEAR, and impeller::Vector4::Round().

◆ TEST() [292/689]

impeller::testing::TEST ( GLErrorToString  ,
ReturnsCorrectStringForKnownErrors   
)

Definition at line 62 of file proc_table_gles_unittests.cc.

62 {
63 EXPECT_EQ(GLErrorToString(GL_NO_ERROR), "GL_NO_ERROR");
64 EXPECT_EQ(GLErrorToString(GL_INVALID_ENUM), "GL_INVALID_ENUM");
65 EXPECT_EQ(GLErrorToString(GL_INVALID_VALUE), "GL_INVALID_VALUE");
66 EXPECT_EQ(GLErrorToString(GL_INVALID_OPERATION), "GL_INVALID_OPERATION");
67 EXPECT_EQ(GLErrorToString(GL_INVALID_FRAMEBUFFER_OPERATION),
68 "GL_INVALID_FRAMEBUFFER_OPERATION");
69 EXPECT_EQ(GLErrorToString(GL_FRAMEBUFFER_COMPLETE),
70 "GL_FRAMEBUFFER_COMPLETE");
71 EXPECT_EQ(GLErrorToString(GL_OUT_OF_MEMORY), "GL_OUT_OF_MEMORY");
72}
std::string_view GLErrorToString(GLenum value)

References impeller::GLErrorToString().

◆ TEST() [293/689]

impeller::testing::TEST ( GLErrorToString  ,
ReturnsUnknownForInvalidError   
)

Definition at line 74 of file proc_table_gles_unittests.cc.

74 {
75 // Test with an invalid error code
76 GLenum invalid_error = 0x9999;
77 EXPECT_EQ(GLErrorToString(invalid_error), "Unknown.");
78}

References impeller::GLErrorToString().

◆ TEST() [294/689]

impeller::testing::TEST ( GLErrorToString  ,
ReturnValueIsValidStringView   
)

Definition at line 80 of file proc_table_gles_unittests.cc.

80 {
81 // Test that the returned string_view is valid and non-empty
82 auto result = GLErrorToString(GL_NO_ERROR);
83 EXPECT_FALSE(result.empty());
84 EXPECT_NE(result.data(), nullptr);
85
86 // Test that we can compare with string literals
87 EXPECT_TRUE(result == "GL_NO_ERROR");
88}

References impeller::GLErrorToString().

◆ TEST() [295/689]

impeller::testing::TEST ( GLProc  ,
NameFieldWorksWithStringView   
)

Definition at line 90 of file proc_table_gles_unittests.cc.

90 {
91 GLProc<void()> proc;
92
93 // Test setting name with string literal
94 const char* literal = "glTestFunction";
95 proc.name = literal;
96
97 EXPECT_EQ(proc.name, "glTestFunction");
98 EXPECT_FALSE(proc.name.empty());
99
100 // Test that the string_view properly references the original data
101 EXPECT_EQ(proc.name.data(), literal);
102}
std::string_view name

References impeller::GLProc< T >::name.

◆ TEST() [296/689]

impeller::testing::TEST ( GpuSubmissionTrackerTest  ,
WatermarkHandlesOutOfOrderCompletion   
)

Definition at line 222 of file host_buffer_unittests.cc.

222 {
223 GpuSubmissionTracker tracker;
224 EXPECT_EQ(tracker.CompletedThrough(), 0u);
225 uint64_t a = tracker.RecordSubmission();
226 uint64_t b = tracker.RecordSubmission();
227 uint64_t c = tracker.RecordSubmission();
228 EXPECT_EQ(tracker.LatestSubmission(), c);
229
230 tracker.RecordCompletion(b);
231 EXPECT_EQ(tracker.CompletedThrough(), 0u);
232 tracker.RecordCompletion(a);
233 EXPECT_EQ(tracker.CompletedThrough(), b);
234 tracker.RecordCompletion(c);
235 EXPECT_EQ(tracker.CompletedThrough(), c);
236}
Tracks GPU completion of submitted command buffers as a monotonic watermark.
uint64_t LatestSubmission() const
Returns the id of the most recent submission.
void RecordCompletion(uint64_t id)
Marks a previously recorded submission as completed by the GPU.
uint64_t RecordSubmission()
Records a command buffer submission and returns its id.

References c, impeller::GpuSubmissionTracker::CompletedThrough(), impeller::GpuSubmissionTracker::LatestSubmission(), impeller::GpuSubmissionTracker::RecordCompletion(), and impeller::GpuSubmissionTracker::RecordSubmission().

◆ TEST() [297/689]

impeller::testing::TEST ( MatrixFilterContentsTest  ,
Coverage2x   
)

Definition at line 65 of file matrix_filter_contents_unittests.cc.

65 {
66 MatrixFilterContents contents;
67 contents.SetMatrix(Matrix::MakeScale({2.0, 2.0, 1.0}));
68 FilterInput::Vector inputs = {
69 FilterInput::Make(Rect::MakeXYWH(10, 10, 100, 100))};
70 Entity entity;
71 std::optional<Rect> coverage =
72 contents.GetFilterCoverage(inputs, entity, /*effect_transform=*/Matrix());
73
74 ASSERT_EQ(coverage, Rect::MakeXYWH(20, 20, 200, 200));
75}
std::optional< Rect > GetFilterCoverage(const FilterInput::Vector &inputs, const Entity &entity, const Matrix &effect_transform) const override
Internal utility method for |GetLocalCoverage| that computes the output coverage of this filter acros...

References impeller::MatrixFilterContents::GetFilterCoverage(), impeller::FilterInput::Make(), impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeXYWH(), and impeller::MatrixFilterContents::SetMatrix().

◆ TEST() [298/689]

impeller::testing::TEST ( MatrixFilterContentsTest  ,
Coverage2xEffect   
)

Definition at line 77 of file matrix_filter_contents_unittests.cc.

77 {
78 MatrixFilterContents contents;
79 FilterInput::Vector inputs = {
80 FilterInput::Make(Rect::MakeXYWH(10, 10, 100, 100))};
81 Entity entity;
82 std::optional<Rect> coverage = contents.GetFilterCoverage(
83 inputs, entity, /*effect_transform=*/Matrix::MakeScale({2.0, 2.0, 1.0}));
84
85 ASSERT_EQ(coverage, Rect::MakeXYWH(10, 10, 100, 100));
86}

References impeller::MatrixFilterContents::GetFilterCoverage(), impeller::FilterInput::Make(), impeller::Matrix::MakeScale(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [299/689]

impeller::testing::TEST ( MatrixFilterContentsTest  ,
CoverageEmpty   
)

Definition at line 45 of file matrix_filter_contents_unittests.cc.

45 {
46 MatrixFilterContents contents;
47 FilterInput::Vector inputs = {};
48 Entity entity;
49 std::optional<Rect> coverage =
50 contents.GetFilterCoverage(inputs, entity, /*effect_transform=*/Matrix());
51 ASSERT_FALSE(coverage.has_value());
52}

References impeller::MatrixFilterContents::GetFilterCoverage().

◆ TEST() [300/689]

impeller::testing::TEST ( MatrixFilterContentsTest  ,
CoverageSimple   
)

Definition at line 54 of file matrix_filter_contents_unittests.cc.

54 {
55 MatrixFilterContents contents;
56 FilterInput::Vector inputs = {
57 FilterInput::Make(Rect::MakeLTRB(10, 10, 110, 110))};
58 Entity entity;
59 std::optional<Rect> coverage =
60 contents.GetFilterCoverage(inputs, entity, /*effect_transform=*/Matrix());
61
62 ASSERT_EQ(coverage, Rect::MakeLTRB(10, 10, 110, 110));
63}

References impeller::MatrixFilterContents::GetFilterCoverage(), impeller::FilterInput::Make(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [301/689]

impeller::testing::TEST ( MatrixTest  ,
Equals   
)

Definition at line 28 of file matrix_unittests.cc.

28 {
29 Matrix x;
30 Matrix y = x;
31 EXPECT_TRUE(x.Equals(y));
32}

References x, and y.

◆ TEST() [302/689]

impeller::testing::TEST ( MatrixTest  ,
GetBasisXYScale2D   
)

Definition at line 289 of file matrix_unittests.cc.

289 {
290 Matrix m = Matrix::MakeScale({5.0f, 3.0f, 1.0f});
291 EXPECT_POINT_NEAR(m.GetBasisX2D(), Vector2(5.0f, 0.0f));
292 EXPECT_POINT_NEAR(m.GetBasisY2D(), Vector2(0.0f, 3.0f));
293 EXPECT_POINT_NEAR(m.GetBasisScaleXY(), Vector2(5.0f, 3.0f));
294
295 Matrix m2 = Matrix::MakeColumn(
296 // clang-format off
297 2.0f, 3.0f, 0.0f, 0.0f,
298 5.0f, 7.0f, 0.0f, 0.0f,
299 0.0f, 0.0f, 1.0f, 0.0f,
300 0.0f, 0.0f, 0.0f, 1.0f
301 // clang-format on
302 );
303 EXPECT_POINT_NEAR(m2.GetBasisX2D(), Vector2(2.0f, 3.0f));
304 EXPECT_POINT_NEAR(m2.GetBasisY2D(), Vector2(5.0f, 7.0f));
305 EXPECT_POINT_NEAR(m2.GetBasisScaleXY(), Vector2(sqrt(13.0f), sqrt(74.0f)));
306
307 Matrix m3 = Matrix::MakeColumn(
308 // clang-format off
309 2.0f, 3.0f, 4.0f, 11.0f,
310 5.0f, 7.0f, 6.0f, 13.0f,
311 1.0f, 8.0f, 9.0f, 15.0f,
312 1.0f, 1.0f, 1.0f, 17.0f
313 // clang-format on
314 );
315 EXPECT_POINT_NEAR(m3.GetBasisX2D(), Vector2(2.0f, 3.0f));
316 EXPECT_POINT_NEAR(m3.GetBasisY2D(), Vector2(5.0f, 7.0f));
317 EXPECT_POINT_NEAR(m2.GetBasisScaleXY(), Vector2(sqrt(13.0f), sqrt(74.0f)));
318}
Vector2 GetBasisScaleXY() const
Definition matrix.h:403
constexpr Vector2 GetBasisX2D() const
Definition matrix.h:399
constexpr Vector2 GetBasisY2D() const
Definition matrix.h:401

References EXPECT_POINT_NEAR, impeller::Matrix::GetBasisScaleXY(), impeller::Matrix::GetBasisX2D(), impeller::Matrix::GetBasisY2D(), impeller::Matrix::MakeColumn(), and impeller::Matrix::MakeScale().

◆ TEST() [303/689]

impeller::testing::TEST ( MatrixTest  ,
GetMaxBasisXYNegativeScale   
)

Definition at line 263 of file matrix_unittests.cc.

263 {
264 Matrix m = Matrix::MakeScale({-2, 1, 1});
265
266 EXPECT_EQ(m.GetMaxBasisLengthXY(), 2);
267
268 m = Matrix::MakeScale({1, -3, 1});
269
270 EXPECT_EQ(m.GetMaxBasisLengthXY(), 3);
271}
Scalar GetMaxBasisLengthXY() const
Return the maximum scale applied specifically to either the X axis or Y axis unit vectors (the bases)...
Definition matrix.h:328

References impeller::Matrix::GetMaxBasisLengthXY(), and impeller::Matrix::MakeScale().

◆ TEST() [304/689]

impeller::testing::TEST ( MatrixTest  ,
GetMaxBasisXYWithLargeAndSmallScalingFactor   
)

Definition at line 274 of file matrix_unittests.cc.

274 {
275 Matrix m = Matrix::MakeScale({2.625e+20, 2.625e+20, 1});
276 EXPECT_NEAR(m.GetMaxBasisLengthXY(), 2.625e+20, 1e+20);
277
278 m = Matrix::MakeScale({2.625e-20, 2.625e-20, 1});
279 EXPECT_NEAR(m.GetMaxBasisLengthXY(), 2.625e-20, 1e-20);
280}

References impeller::Matrix::GetMaxBasisLengthXY(), and impeller::Matrix::MakeScale().

◆ TEST() [305/689]

impeller::testing::TEST ( MatrixTest  ,
GetMaxBasisXYWithLargeAndSmallScalingFactorNonScaleTranslate   
)

Definition at line 282 of file matrix_unittests.cc.

282 {
283 Matrix m = Matrix::MakeScale({2.625e+20, 2.625e+20, 1});
284 m.e[0][1] = 2;
285
286 EXPECT_TRUE(std::isinf(m.GetMaxBasisLengthXY()));
287}
Scalar e[4][4]
Definition matrix.h:40

References impeller::Matrix::e, impeller::Matrix::GetMaxBasisLengthXY(), and impeller::Matrix::MakeScale().

◆ TEST() [306/689]

impeller::testing::TEST ( MatrixTest  ,
HasPerspective   
)

Definition at line 58 of file matrix_unittests.cc.

58 {
59 EXPECT_FALSE(Matrix().HasPerspective());
60
61 auto test = [](int index, bool expect) {
62 Matrix matrix;
63 EXPECT_FALSE(matrix.HasPerspective());
64 matrix.m[index] = 0.5f;
65 EXPECT_EQ(matrix.HasPerspective(), expect) << "index: " << index;
66 };
67
68 // clang-format off
69 test( 0, false); test( 1, false); test( 2, false); test( 3, true);
70 test( 4, false); test( 5, false); test( 6, false); test( 7, true);
71 test( 8, false); test( 9, false); test(10, false); test(11, true);
72 test(12, false); test(13, false); test(14, false); test(15, true);
73 // clang-format on
74}
Scalar m[16]
Definition matrix.h:39
constexpr bool HasPerspective() const
Definition matrix.h:426

References impeller::Matrix::HasPerspective(), and impeller::Matrix::m.

◆ TEST() [307/689]

impeller::testing::TEST ( MatrixTest  ,
HasPerspective2D   
)

Definition at line 40 of file matrix_unittests.cc.

40 {
41 EXPECT_FALSE(Matrix().HasPerspective2D());
42
43 auto test = [](int index, bool expect) {
44 Matrix matrix;
45 EXPECT_FALSE(matrix.HasPerspective2D());
46 matrix.m[index] = 0.5f;
47 EXPECT_EQ(matrix.HasPerspective2D(), expect) << "index: " << index;
48 };
49
50 // clang-format off
51 test( 0, false); test( 1, false); test( 2, false); test( 3, true);
52 test( 4, false); test( 5, false); test( 6, false); test( 7, true);
53 test( 8, false); test( 9, false); test(10, false); test(11, false);
54 test(12, false); test(13, false); test(14, false); test(15, true);
55 // clang-format on
56}
constexpr bool HasPerspective2D() const
Definition matrix.h:422

References impeller::Matrix::HasPerspective2D(), and impeller::Matrix::m.

◆ TEST() [308/689]

impeller::testing::TEST ( MatrixTest  ,
HasTranslation   
)

Definition at line 76 of file matrix_unittests.cc.

76 {
77 EXPECT_TRUE(Matrix::MakeTranslation({100, 100, 0}).HasTranslation());
78 EXPECT_TRUE(Matrix::MakeTranslation({0, 100, 0}).HasTranslation());
79 EXPECT_TRUE(Matrix::MakeTranslation({100, 0, 0}).HasTranslation());
80 EXPECT_FALSE(Matrix().HasTranslation());
81}

References impeller::Matrix::MakeTranslation().

◆ TEST() [309/689]

impeller::testing::TEST ( MatrixTest  ,
IsAligned   
)

Definition at line 203 of file matrix_unittests.cc.

203 {
204 EXPECT_TRUE(Matrix().IsAligned());
205 EXPECT_TRUE(Matrix::MakeScale({1.0f, 1.0f, 2.0f}).IsAligned());
206
207 // Begin Legacy tests transferred over from geometry_unittests.cc
208 {
209 auto m = Matrix::MakeTranslation({1, 2, 3});
210 bool result = m.IsAligned();
211 ASSERT_TRUE(result);
212 }
213
214 {
215 auto m = Matrix::MakeRotationZ(Degrees{123});
216 bool result = m.IsAligned();
217 ASSERT_FALSE(result);
218 }
219 // End Legacy tests transferred over from geometry_unittests.cc
220
221 auto test = [](int index, bool expect) {
222 Matrix matrix;
223 EXPECT_TRUE(matrix.IsAligned());
224 matrix.m[index] = 0.5f;
225 EXPECT_EQ(matrix.IsAligned(), expect) << "index: " << index;
226 };
227
228 // clang-format off
229 test( 0, true); test( 1, false); test( 2, false); test( 3, false);
230 test( 4, false); test( 5, true); test( 6, false); test( 7, false);
231 test( 8, false); test( 9, false); test(10, true); test(11, false);
232 test(12, true); test(13, true); test(14, true); test(15, false);
233 // clang-format on
234
235 // True for quadrant rotations from -250 to +250 full circles
236 for (int i = -1000; i < 1000; i++) {
237 Degrees d = Degrees(i * 90);
238 Matrix matrix = Matrix::MakeRotationZ(Degrees(d));
239 EXPECT_TRUE(matrix.IsAligned()) << "degrees: " << d.degrees;
240 }
241
242 // False for half degree rotations from -999.5 to +1000.5 degrees
243 for (int i = -1000; i < 1000; i++) {
244 Degrees d = Degrees(i + 0.5f);
245 Matrix matrix = Matrix::MakeRotationZ(Degrees(d));
246 EXPECT_FALSE(matrix.IsAligned()) << "degrees: " << d.degrees;
247 }
248}

References d, i, impeller::Matrix::IsAligned(), impeller::Matrix::m, impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), and impeller::Matrix::MakeTranslation().

◆ TEST() [310/689]

impeller::testing::TEST ( MatrixTest  ,
IsAligned2D   
)

Definition at line 170 of file matrix_unittests.cc.

170 {
171 EXPECT_TRUE(Matrix().IsAligned2D());
172 EXPECT_TRUE(Matrix::MakeScale({1.0f, 1.0f, 2.0f}).IsAligned2D());
173
174 auto test = [](int index, bool expect) {
175 Matrix matrix;
176 EXPECT_TRUE(matrix.IsAligned2D());
177 matrix.m[index] = 0.5f;
178 EXPECT_EQ(matrix.IsAligned2D(), expect) << "index: " << index;
179 };
180
181 // clang-format off
182 test( 0, true); test( 1, false); test( 2, true); test( 3, false);
183 test( 4, false); test( 5, true); test( 6, true); test( 7, false);
184 test( 8, true); test( 9, true); test(10, true); test(11, true);
185 test(12, true); test(13, true); test(14, true); test(15, false);
186 // clang-format on
187
188 // True for quadrant rotations from -250 to +250 full circles
189 for (int i = -1000; i < 1000; i++) {
190 Degrees d = Degrees(i * 90);
191 Matrix matrix = Matrix::MakeRotationZ(Degrees(d));
192 EXPECT_TRUE(matrix.IsAligned2D()) << "degrees: " << d.degrees;
193 }
194
195 // False for half degree rotations from -999.5 to +1000.5 degrees
196 for (int i = -1000; i < 1000; i++) {
197 Degrees d = Degrees(i + 0.5f);
198 Matrix matrix = Matrix::MakeRotationZ(Degrees(d));
199 EXPECT_FALSE(matrix.IsAligned2D()) << "degrees: " << d.degrees;
200 }
201}
constexpr bool IsAligned2D(Scalar tolerance=0) const
Definition matrix.h:432

References d, i, impeller::Matrix::IsAligned2D(), impeller::Matrix::m, impeller::Matrix::MakeRotationZ(), and impeller::Matrix::MakeScale().

◆ TEST() [311/689]

impeller::testing::TEST ( MatrixTest  ,
IsFinite   
)

Definition at line 132 of file matrix_unittests.cc.

132 {
133 EXPECT_TRUE(Matrix().IsFinite());
134
135 EXPECT_TRUE(Matrix::MakeTranslation({100, 100, 0}).IsFinite());
136 EXPECT_TRUE(Matrix::MakeScale({100, 100, 1}).IsFinite());
137
138 EXPECT_TRUE(Matrix::MakeRotationX(Degrees(30)).IsFinite());
139 EXPECT_TRUE(Matrix::MakeRotationY(Degrees(30)).IsFinite());
140 EXPECT_TRUE(Matrix::MakeRotationZ(Degrees(30)).IsFinite());
141
142 EXPECT_TRUE(Matrix::MakeScale({0, 1, 1}).IsFinite());
143 EXPECT_TRUE(Matrix::MakeScale({1, 0, 1}).IsFinite());
144 EXPECT_TRUE(Matrix::MakeScale({1, 1, 0}).IsFinite());
145
146 for (int i = 0; i < 16; i++) {
147 {
148 Matrix matrix;
149 ASSERT_TRUE(matrix.IsFinite());
150 matrix.m[i] = std::numeric_limits<Scalar>::infinity();
151 ASSERT_FALSE(matrix.IsFinite());
152 }
153
154 {
155 Matrix matrix;
156 ASSERT_TRUE(matrix.IsFinite());
157 matrix.m[i] = -std::numeric_limits<Scalar>::infinity();
158 ASSERT_FALSE(matrix.IsFinite());
159 }
160
161 {
162 Matrix matrix;
163 ASSERT_TRUE(matrix.IsFinite());
164 matrix.m[i] = -std::numeric_limits<Scalar>::quiet_NaN();
165 ASSERT_FALSE(matrix.IsFinite());
166 }
167 }
168}

References i, impeller::Matrix::IsFinite(), impeller::Matrix::m, impeller::Matrix::MakeRotationX(), impeller::Matrix::MakeRotationY(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), and impeller::Matrix::MakeTranslation().

◆ TEST() [312/689]

impeller::testing::TEST ( MatrixTest  ,
IsInvertibleGetDeterminant   
)

Definition at line 105 of file matrix_unittests.cc.

105 {
106 EXPECT_TRUE(Matrix().IsInvertible());
107 EXPECT_NE(Matrix().GetDeterminant(), 0.0f);
108
109 EXPECT_TRUE(Matrix::MakeTranslation({100, 100, 0}).IsInvertible());
110 EXPECT_NE(Matrix::MakeTranslation({100, 100, 0}).GetDeterminant(), 0.0f);
111
112 EXPECT_TRUE(Matrix::MakeScale({100, 100, 1}).IsInvertible());
113 EXPECT_NE(Matrix::MakeScale({100, 100, 1}).GetDeterminant(), 0.0f);
114
115 EXPECT_TRUE(Matrix::MakeRotationX(Degrees(30)).IsInvertible());
116 EXPECT_NE(Matrix::MakeRotationX(Degrees(30)).GetDeterminant(), 0.0f);
117
118 EXPECT_TRUE(Matrix::MakeRotationY(Degrees(30)).IsInvertible());
119 EXPECT_NE(Matrix::MakeRotationY(Degrees(30)).GetDeterminant(), 0.0f);
120
121 EXPECT_TRUE(Matrix::MakeRotationZ(Degrees(30)).IsInvertible());
122 EXPECT_NE(Matrix::MakeRotationZ(Degrees(30)).GetDeterminant(), 0.0f);
123
124 EXPECT_FALSE(Matrix::MakeScale({0, 1, 1}).IsInvertible());
125 EXPECT_EQ(Matrix::MakeScale({0, 1, 1}).GetDeterminant(), 0.0f);
126 EXPECT_FALSE(Matrix::MakeScale({1, 0, 1}).IsInvertible());
127 EXPECT_EQ(Matrix::MakeScale({1, 0, 1}).GetDeterminant(), 0.0f);
128 EXPECT_FALSE(Matrix::MakeScale({1, 1, 0}).IsInvertible());
129 EXPECT_EQ(Matrix::MakeScale({1, 1, 0}).GetDeterminant(), 0.0f);
130}

References impeller::Matrix::MakeRotationX(), impeller::Matrix::MakeRotationY(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), and impeller::Matrix::MakeTranslation().

◆ TEST() [313/689]

impeller::testing::TEST ( MatrixTest  ,
IsTranslationOnly   
)

Definition at line 83 of file matrix_unittests.cc.

83 {
84 EXPECT_TRUE(Matrix::MakeTranslation({100, 100, 0}).IsTranslationOnly());
85 EXPECT_TRUE(Matrix::MakeTranslation({100, 100, 0}).IsTranslationScaleOnly());
86 EXPECT_TRUE(Matrix::MakeTranslation({0, 100, 0}).IsTranslationOnly());
87 EXPECT_TRUE(Matrix::MakeTranslation({0, 100, 0}).IsTranslationScaleOnly());
88 EXPECT_TRUE(Matrix::MakeTranslation({100, 0, 0}).IsTranslationOnly());
89 EXPECT_TRUE(Matrix::MakeTranslation({100, 0, 0}).IsTranslationScaleOnly());
90 EXPECT_TRUE(Matrix().IsTranslationOnly());
91 EXPECT_TRUE(Matrix().IsTranslationScaleOnly());
92}

References impeller::Matrix::MakeTranslation().

◆ TEST() [314/689]

impeller::testing::TEST ( MatrixTest  ,
IsTranslationScaleOnly   
)

Definition at line 94 of file matrix_unittests.cc.

94 {
95 EXPECT_FALSE(Matrix::MakeScale({100, 100, 1}).IsTranslationOnly());
96 EXPECT_TRUE(Matrix::MakeScale({100, 100, 1}).IsTranslationScaleOnly());
97 EXPECT_FALSE(Matrix::MakeScale({1, 100, 1}).IsTranslationOnly());
98 EXPECT_TRUE(Matrix::MakeScale({1, 100, 1}).IsTranslationScaleOnly());
99 EXPECT_FALSE(Matrix::MakeScale({100, 1, 1}).IsTranslationOnly());
100 EXPECT_TRUE(Matrix::MakeScale({100, 1, 1}).IsTranslationScaleOnly());
101 EXPECT_TRUE(Matrix().IsTranslationOnly());
102 EXPECT_TRUE(Matrix().IsTranslationScaleOnly());
103}

References impeller::Matrix::MakeScale().

◆ TEST() [315/689]

impeller::testing::TEST ( MatrixTest  ,
MakeScaleTranslate   
)

Definition at line 332 of file matrix_unittests.cc.

332 {
333 EXPECT_TRUE(MatrixNear(
334 Matrix::MakeTranslateScale({1, 1, 1.0 / 1024}, {10, 10, 1.0 / 1024}),
335 Matrix::MakeTranslation({10, 10, 1.0 / 1024}) *
336 Matrix::MakeScale({1, 1, 1.0 / 1024})));
337
338 EXPECT_TRUE(MatrixNear(
339 Matrix::MakeTranslateScale({2, 2, 2}, {10, 10, 0}),
340 Matrix::MakeTranslation({10, 10, 0}) * Matrix::MakeScale({2, 2, 2})));
341
342 EXPECT_TRUE(MatrixNear(
343 Matrix::MakeTranslateScale({0, 0, 0}, {0, 0, 0}),
344 Matrix::MakeTranslation({0, 0, 0}) * Matrix::MakeScale({0, 0, 0})));
345}
inline ::testing::AssertionResult MatrixNear(impeller::Matrix a, impeller::Matrix b)

References impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslateScale(), impeller::Matrix::MakeTranslation(), and MatrixNear().

◆ TEST() [316/689]

impeller::testing::TEST ( MatrixTest  ,
MinMaxScales2D   
)

Definition at line 356 of file matrix_unittests.cc.

356 {
357 // The GetScales2D() method is allowed to return the scales in any
358 // order so we need to take special care in verifying the return
359 // value to test them in either order.
360 auto check_pair = [](const Matrix& matrix, Scalar scale1, Scalar scale2) {
361 auto pair = matrix.GetScales2D();
362 EXPECT_TRUE(pair.has_value())
363 << "Scales: " << scale1 << ", " << scale2 << ", " << matrix;
364 if (ScalarNearlyEqual(pair->first, scale1)) {
365 EXPECT_FLOAT_EQ(pair->first, scale1) << matrix;
366 EXPECT_FLOAT_EQ(pair->second, scale2) << matrix;
367 } else {
368 EXPECT_FLOAT_EQ(pair->first, scale2) << matrix;
369 EXPECT_FLOAT_EQ(pair->second, scale1) << matrix;
370 }
371 };
372
373 for (int i = 1; i < 10; i++) {
374 Scalar xScale = static_cast<Scalar>(i);
375 for (int j = 1; j < 10; j++) {
376 Scalar yScale = static_cast<Scalar>(j);
377 Scalar minScale = std::min(xScale, yScale);
378 Scalar maxScale = std::max(xScale, yScale);
379
380 {
381 // Simple scale
382 Matrix matrix = Matrix::MakeScale({xScale, yScale, 1.0f});
383 EXPECT_TRUE(matrix.GetMinScale2D().has_value());
384 EXPECT_TRUE(matrix.GetMaxScale2D().has_value());
385 EXPECT_FLOAT_EQ(matrix.GetMinScale2D().value_or(-1.0f), minScale);
386 EXPECT_FLOAT_EQ(matrix.GetMaxScale2D().value_or(-1.0f), maxScale);
387 check_pair(matrix, xScale, yScale);
388 }
389
390 {
391 // Simple scale with Z scale
392 Matrix matrix = Matrix::MakeScale({xScale, yScale, 5.0f});
393 EXPECT_TRUE(matrix.GetMinScale2D().has_value());
394 EXPECT_TRUE(matrix.GetMaxScale2D().has_value());
395 EXPECT_FLOAT_EQ(matrix.GetMinScale2D().value_or(-1.0f), minScale);
396 EXPECT_FLOAT_EQ(matrix.GetMaxScale2D().value_or(-1.0f), maxScale);
397 check_pair(matrix, xScale, yScale);
398 }
399
400 {
401 // Simple scale + translate
402 Matrix matrix = Matrix::MakeTranslateScale({xScale, yScale, 1.0f},
403 {10.0f, 15.0f, 2.0f});
404 EXPECT_TRUE(matrix.GetMinScale2D().has_value());
405 EXPECT_TRUE(matrix.GetMaxScale2D().has_value());
406 EXPECT_FLOAT_EQ(matrix.GetMinScale2D().value_or(-1.0f), minScale);
407 EXPECT_FLOAT_EQ(matrix.GetMaxScale2D().value_or(-1.0f), maxScale);
408 check_pair(matrix, xScale, yScale);
409 }
410
411 for (int d = 45; d < 360; d += 45) {
412 {
413 // Rotation * Scale
414 Matrix matrix = Matrix::MakeScale({xScale, yScale, 1.0f}) *
415 Matrix::MakeRotationZ(Degrees(d));
416 EXPECT_TRUE(matrix.GetMinScale2D().has_value());
417 EXPECT_TRUE(matrix.GetMaxScale2D().has_value());
418 EXPECT_FLOAT_EQ(matrix.GetMinScale2D().value_or(-1.0f), minScale);
419 EXPECT_FLOAT_EQ(matrix.GetMaxScale2D().value_or(-1.0f), maxScale);
420 check_pair(matrix, xScale, yScale);
421 }
422
423 {
424 // Scale * Rotation
425 Matrix matrix = Matrix::MakeRotationZ(Degrees(d)) *
426 Matrix::MakeScale({xScale, yScale, 1.0f});
427 EXPECT_TRUE(matrix.GetMinScale2D().has_value());
428 EXPECT_TRUE(matrix.GetMaxScale2D().has_value());
429 EXPECT_FLOAT_EQ(matrix.GetMinScale2D().value_or(-1.0f), minScale);
430 EXPECT_FLOAT_EQ(matrix.GetMaxScale2D().value_or(-1.0f), maxScale);
431 check_pair(matrix, xScale, yScale);
432 }
433 }
434
435 {
436 // Scale + PerspectiveX (returns invalid values)
437 Matrix matrix = Matrix::MakeScale({xScale, yScale, 1.0f});
438 matrix.m[3] = 0.1;
439 EXPECT_FALSE(matrix.GetMinScale2D().has_value());
440 EXPECT_FALSE(matrix.GetMaxScale2D().has_value());
441 EXPECT_FALSE(matrix.GetScales2D().has_value());
442 }
443
444 {
445 // Scale + PerspectiveY (returns invalid values)
446 Matrix matrix = Matrix::MakeScale({xScale, yScale, 1.0f});
447 matrix.m[7] = 0.1;
448 EXPECT_FALSE(matrix.GetMinScale2D().has_value());
449 EXPECT_FALSE(matrix.GetMaxScale2D().has_value());
450 EXPECT_FALSE(matrix.GetScales2D().has_value());
451 }
452
453 {
454 // Scale + PerspectiveZ (Z ignored; returns actual scales)
455 Matrix matrix = Matrix::MakeScale({xScale, yScale, 1.0f});
456 matrix.m[11] = 0.1;
457 EXPECT_TRUE(matrix.GetMinScale2D().has_value());
458 EXPECT_TRUE(matrix.GetMaxScale2D().has_value());
459 EXPECT_FLOAT_EQ(matrix.GetMinScale2D().value_or(-1.0f), minScale);
460 EXPECT_FLOAT_EQ(matrix.GetMaxScale2D().value_or(-1.0f), maxScale);
461 check_pair(matrix, xScale, yScale);
462 }
463
464 {
465 // Scale + PerspectiveW (returns invalid values)
466 Matrix matrix = Matrix::MakeScale({xScale, yScale, 1.0f});
467 matrix.m[15] = 0.1;
468 EXPECT_FALSE(matrix.GetMinScale2D().has_value());
469 EXPECT_FALSE(matrix.GetMaxScale2D().has_value());
470 EXPECT_FALSE(matrix.GetScales2D().has_value());
471 }
472 }
473 }
474}
std::optional< std::pair< Scalar, Scalar > > GetScales2D() const
Compute the two non-negative scales applied by this matrix to 2D coordinates and return them as an op...
Definition matrix.cc:363

References d, impeller::Matrix::GetMaxScale2D(), impeller::Matrix::GetMinScale2D(), impeller::Matrix::GetScales2D(), i, impeller::Matrix::m, impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslateScale(), and impeller::ScalarNearlyEqual().

◆ TEST() [317/689]

impeller::testing::TEST ( MatrixTest  ,
Multiply   
)

Definition at line 15 of file matrix_unittests.cc.

15 {
16 Matrix x(0.0, 0.0, 0.0, 1.0, //
17 1.0, 0.0, 0.0, 1.0, //
18 0.0, 1.0, 0.0, 1.0, //
19 1.0, 1.0, 0.0, 1.0);
20 Matrix translate = Matrix::MakeTranslation({10, 20, 0});
21 Matrix result = translate * x;
22 EXPECT_TRUE(MatrixNear(result, Matrix(10.0, 20.0, 0.0, 1.0, //
23 11.0, 20.0, 0.0, 1.0, //
24 10.0, 21.0, 0.0, 1.0, //
25 11.0, 21.0, 0.0, 1.0)));
26}

References impeller::Matrix::MakeTranslation(), MatrixNear(), and x.

◆ TEST() [318/689]

impeller::testing::TEST ( MatrixTest  ,
NotEquals   
)

Definition at line 34 of file matrix_unittests.cc.

34 {
35 Matrix x;
36 Matrix y = x.Translate({1, 0, 0});
37 EXPECT_FALSE(x.Equals(y));
38}
constexpr Matrix Translate(const Vector3 &t) const
Definition matrix.h:263

References impeller::Matrix::Translate(), x, and y.

◆ TEST() [319/689]

impeller::testing::TEST ( MatrixTest  ,
To3x3   
)

Definition at line 347 of file matrix_unittests.cc.

347 {
348 Matrix x(1.0, 0.0, 4.0, 0.0, //
349 0.0, 1.0, 4.0, 0.0, //
350 6.0, 5.0, 111.0, 7.0, //
351 0.0, 0.0, 9.0, 1.0);
352
353 EXPECT_TRUE(MatrixNear(x.To3x3(), Matrix()));
354}

References MatrixNear(), and x.

◆ TEST() [320/689]

impeller::testing::TEST ( MatrixTest  ,
TransformHomogenous   
)

Definition at line 250 of file matrix_unittests.cc.

250 {
251 Matrix matrix = Matrix::MakeColumn(
252 // clang-format off
253 2.0f, 3.0f, 5.0f, 7.0f,
254 11.0f, 13.0f, 17.0f, 19.0f,
255 23.0f, 29.0f, 31.0f, 37.0f,
256 41.0f, 43.0f, 47.0f, 53.0f
257 // clang-format on
258 );
259 EXPECT_EQ(matrix.TransformHomogenous({1.0f, -1.0f}),
260 Vector3(32.0f, 33.0f, 41.0f));
261}
constexpr Vector3 TransformHomogenous(const Point &v) const
Definition matrix.h:609

References impeller::Matrix::MakeColumn(), and impeller::Matrix::TransformHomogenous().

◆ TEST() [321/689]

impeller::testing::TEST ( MatrixTest  ,
TranslateWithPerspective   
)

Definition at line 320 of file matrix_unittests.cc.

320 {
321 Matrix m = Matrix::MakeRow(1.0, 0.0, 0.0, 10.0, //
322 0.0, 1.0, 0.0, 20.0, //
323 0.0, 0.0, 1.0, 0.0, //
324 0.0, 2.0, 0.0, 30.0);
325 Matrix result = m.Translate({100, 200});
326 EXPECT_TRUE(MatrixNear(result, Matrix::MakeRow(1.0, 0.0, 0.0, 110.0, //
327 0.0, 1.0, 0.0, 220.0, //
328 0.0, 0.0, 1.0, 0.0, //
329 0.0, 2.0, 0.0, 430.0)));
330}

References impeller::Matrix::MakeRow(), MatrixNear(), and impeller::Matrix::Translate().

◆ TEST() [322/689]

impeller::testing::TEST ( MockGLES  ,
CanCallUnmockedFunction   
)

Definition at line 25 of file mock_gles_unittests.cc.

25 {
26 auto mock_gles = MockGLES::Init();
27
28 auto& gl = mock_gles->GetProcTable();
29 gl.DeleteFramebuffers(1, nullptr);
30
31 // Test should still complete.
32 // If we end up mocking DeleteFramebuffers, delete this test.
33}

References impeller::testing::MockGLES::Init().

◆ TEST() [323/689]

impeller::testing::TEST ( MockGLES  ,
CanInitialize   
)

Definition at line 16 of file mock_gles_unittests.cc.

16 {
17 auto mock_gles = MockGLES::Init();
18
19 std::string_view vendor(reinterpret_cast<const char*>(
20 mock_gles->GetProcTable().GetString(GL_VENDOR)));
21 EXPECT_EQ(vendor, "MockGLES");
22}

References impeller::testing::MockGLES::Init().

◆ TEST() [324/689]

impeller::testing::TEST ( MockPipelineLibrary  ,
LogAndGetPipelineUsageMultiplePipelines   
)

Definition at line 28 of file pipeline_library_unittests.cc.

28 {
29 MockPipelineLibrary pipeline_library;
30
31 PipelineDescriptor pipeline_a;
32 pipeline_a.SetLabel("pipeline_a");
33
34 PipelineDescriptor pipeline_b;
35 pipeline_b.SetLabel("pipeline_b");
36
37 pipeline_library.LogPipelineUsage(pipeline_a);
38 pipeline_library.LogPipelineUsage(pipeline_a);
39 pipeline_library.LogPipelineUsage(pipeline_b);
40
41 auto usage_counts = pipeline_library.GetPipelineUseCounts();
42
43#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG || \
44 FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_PROFILE
45 EXPECT_EQ(usage_counts[pipeline_a], 2);
46 EXPECT_EQ(usage_counts[pipeline_b], 1);
47#else
48 EXPECT_EQ(usage_counts[pipeline_a], 0);
49 EXPECT_EQ(usage_counts[pipeline_b], 0);
50#endif
51}
PipelineDescriptor & SetLabel(std::string_view label)
void LogPipelineUsage(const PipelineDescriptor &p)
std::unordered_map< PipelineDescriptor, int, ComparableHash< PipelineDescriptor >, ComparableEqual< PipelineDescriptor > > GetPipelineUseCounts() const

References impeller::PipelineLibrary::GetPipelineUseCounts(), impeller::PipelineLibrary::LogPipelineUsage(), and impeller::PipelineDescriptor::SetLabel().

◆ TEST() [325/689]

impeller::testing::TEST ( MockPipelineLibrary  ,
LogAndGetPipelineUsageSinglePipeline   
)

Definition at line 10 of file pipeline_library_unittests.cc.

10 {
11 MockPipelineLibrary pipeline_library;
12
13 PipelineDescriptor pipeline_desc;
14 pipeline_desc.SetLabel("pipeline");
15
16 pipeline_library.LogPipelineUsage(pipeline_desc);
17 pipeline_library.LogPipelineUsage(pipeline_desc);
18
19 auto usage_counts = pipeline_library.GetPipelineUseCounts();
20#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG || \
21 FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_PROFILE
22 EXPECT_EQ(usage_counts[pipeline_desc], 2);
23#else
24 EXPECT_EQ(usage_counts[pipeline_desc], 0);
25#endif
26}

References impeller::PipelineLibrary::GetPipelineUseCounts(), impeller::PipelineLibrary::LogPipelineUsage(), and impeller::PipelineDescriptor::SetLabel().

◆ TEST() [326/689]

impeller::testing::TEST ( MockVulkanContextTest  ,
DefaultFenceAlwaysReportsSuccess   
)

Definition at line 37 of file mock_vulkan_unittests.cc.

37 {
38 auto const context = MockVulkanContextBuilder().Build();
39 auto const device = context->GetDevice();
40
41 auto fence = device.createFenceUnique({}).value;
42 EXPECT_EQ(vk::Result::eSuccess, device.getFenceStatus(*fence));
43}

References impeller::testing::MockVulkanContextBuilder::Build(), context, device, and value.

◆ TEST() [327/689]

impeller::testing::TEST ( MockVulkanContextTest  ,
IsThreadSafe   
)

Definition at line 14 of file mock_vulkan_unittests.cc.

14 {
15 // In a typical app, there is a single ContextVK per app, shared b/w threads.
16 //
17 // This test ensures that the (mock) ContextVK is thread-safe.
18 auto const context = MockVulkanContextBuilder().Build();
19
20 // Spawn two threads, and have them create a CommandPoolVK each.
21 std::thread thread1([&context]() {
22 auto const pool = context->GetCommandPoolRecycler()->Get();
23 EXPECT_TRUE(pool);
24 });
25
26 std::thread thread2([&context]() {
27 auto const pool = context->GetCommandPoolRecycler()->Get();
28 EXPECT_TRUE(pool);
29 });
30
31 thread1.join();
32 thread2.join();
33
34 context->Shutdown();
35}

References impeller::testing::MockVulkanContextBuilder::Build(), and context.

◆ TEST() [328/689]

impeller::testing::TEST ( MockVulkanContextTest  ,
MockedFenceReportsStatus   
)

Definition at line 45 of file mock_vulkan_unittests.cc.

45 {
46 auto const context = MockVulkanContextBuilder().Build();
47
48 auto const device = context->GetDevice();
49 auto fence = device.createFenceUnique({}).value;
50 MockFence::SetStatus(fence, vk::Result::eNotReady);
51
52 EXPECT_EQ(vk::Result::eNotReady, device.getFenceStatus(fence.get()));
53
54 MockFence::SetStatus(fence, vk::Result::eSuccess);
55 EXPECT_EQ(vk::Result::eSuccess, device.getFenceStatus(*fence));
56}

References impeller::testing::MockVulkanContextBuilder::Build(), context, device, impeller::testing::MockFence::SetStatus(), and value.

◆ TEST() [329/689]

impeller::testing::TEST ( PaintTest  ,
GradientConversionNonMonotonic   
)

Definition at line 156 of file paint_unittests.cc.

156 {
157 std::vector<flutter::DlColor> colors = {
160 std::vector<float> stops = {0.0, 0.5, 0.4, 1.0};
161 const auto gradient =
163 flutter::DlPoint(1.0, 1.0), //
164 4, //
165 colors.data(), //
166 stops.data(), //
168 nullptr //
169 );
170
171 std::vector<Color> converted_colors;
172 std::vector<Scalar> converted_stops;
173 Paint::ConvertStops(gradient->asLinearGradient(), converted_colors,
174 converted_stops);
175
176 // Value is clamped to 0.5
177 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[0], 0.0f));
178 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[1], 0.5f));
179 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[2], 0.5f));
180 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[3], 1.0f));
181}
static constexpr DlColor kBlue()
Definition dl_color.h:73
static constexpr DlColor kGreen()
Definition dl_color.h:72

References impeller::Paint::ConvertStops(), flutter::DlColor::kBlue(), flutter::kClamp, flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColorSource::MakeLinear(), and impeller::ScalarNearlyEqual().

◆ TEST() [330/689]

impeller::testing::TEST ( PaintTest  ,
GradientMissing0   
)

Definition at line 78 of file paint_unittests.cc.

78 {
79 std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
81 std::vector<float> stops = {0.5, 1.0};
82 const auto gradient =
84 flutter::DlPoint(1.0, 1.0), //
85 2, //
86 colors.data(), //
87 stops.data(), //
89 nullptr //
90 );
91
92 std::vector<Color> converted_colors;
93 std::vector<Scalar> converted_stops;
94 Paint::ConvertStops(gradient->asLinearGradient(), converted_colors,
95 converted_stops);
96
97 // First color is inserted as blue.
98 ASSERT_TRUE(ScalarNearlyEqual(converted_colors[0].blue, 1.0f));
99 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[0], 0.0f));
100 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[1], 0.5f));
101 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[2], 1.0f));
102}

References impeller::Paint::ConvertStops(), flutter::DlColor::kBlue(), flutter::kClamp, flutter::DlColor::kRed(), flutter::DlColorSource::MakeLinear(), and impeller::ScalarNearlyEqual().

◆ TEST() [331/689]

impeller::testing::TEST ( PaintTest  ,
GradientMissingLastValue   
)

Definition at line 104 of file paint_unittests.cc.

104 {
105 std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
107 std::vector<float> stops = {0.0, .5};
108 const auto gradient =
110 flutter::DlPoint(1.0, 1.0), //
111 2, //
112 colors.data(), //
113 stops.data(), //
115 nullptr //
116 );
117
118 std::vector<Color> converted_colors;
119 std::vector<Scalar> converted_stops;
120 Paint::ConvertStops(gradient->asLinearGradient(), converted_colors,
121 converted_stops);
122
123 // Last color is inserted as red.
124 ASSERT_TRUE(ScalarNearlyEqual(converted_colors[2].red, 1.0f));
125 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[0], 0.0f));
126 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[1], 0.5f));
127 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[2], 1.0f));
128}

References impeller::Paint::ConvertStops(), flutter::DlColor::kBlue(), flutter::kClamp, flutter::DlColor::kRed(), flutter::DlColorSource::MakeLinear(), and impeller::ScalarNearlyEqual().

◆ TEST() [332/689]

impeller::testing::TEST ( PaintTest  ,
GradientStopConversion   
)

Definition at line 52 of file paint_unittests.cc.

52 {
53 // Typical gradient.
54 std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
57 std::vector<float> stops = {0.0, 0.5, 1.0};
58 const auto gradient =
60 flutter::DlPoint(1.0, 1.0), //
61 3, //
62 colors.data(), //
63 stops.data(), //
65 nullptr //
66 );
67
68 std::vector<Color> converted_colors;
69 std::vector<Scalar> converted_stops;
70 Paint::ConvertStops(gradient->asLinearGradient(), converted_colors,
71 converted_stops);
72
73 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[0], 0.0f));
74 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[1], 0.5f));
75 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[2], 1.0f));
76}

References impeller::Paint::ConvertStops(), flutter::DlColor::kBlue(), flutter::kClamp, flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColorSource::MakeLinear(), and impeller::ScalarNearlyEqual().

◆ TEST() [333/689]

impeller::testing::TEST ( PaintTest  ,
GradientStopGreaterThan1   
)

Definition at line 130 of file paint_unittests.cc.

130 {
131 std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
134 std::vector<float> stops = {0.0, 100, 1.0};
135 const auto gradient =
137 flutter::DlPoint(1.0, 1.0), //
138 3, //
139 colors.data(), //
140 stops.data(), //
142 nullptr //
143 );
144
145 std::vector<Color> converted_colors;
146 std::vector<Scalar> converted_stops;
147 Paint::ConvertStops(gradient->asLinearGradient(), converted_colors,
148 converted_stops);
149
150 // Value is clamped to 1.0
151 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[0], 0.0f));
152 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[1], 1.0f));
153 ASSERT_TRUE(ScalarNearlyEqual(converted_stops[2], 1.0f));
154}

References impeller::Paint::ConvertStops(), flutter::DlColor::kBlue(), flutter::kClamp, flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColorSource::MakeLinear(), and impeller::ScalarNearlyEqual().

◆ TEST() [334/689]

impeller::testing::TEST ( PaintTest  ,
OptionalStrokeWithFill   
)

Definition at line 17 of file paint_unittests.cc.

17 {
18 Paint paint;
19 paint.style = Paint::Style::kFill;
20 paint.stroke.cap = Cap::kRound;
21 paint.stroke.join = Join::kRound;
22 paint.stroke.width = 20.0f;
23 paint.stroke.miter_limit = 100.0f;
24
25 EXPECT_FALSE(paint.GetStroke().has_value());
26 // Even though optional stroke wasn't returned, the underlying values
27 // are still in the Paint.
28 EXPECT_EQ(paint.stroke.cap, Cap::kRound);
29 EXPECT_EQ(paint.stroke.join, Join::kRound);
30 EXPECT_EQ(paint.stroke.width, 20.0f);
31 EXPECT_EQ(paint.stroke.miter_limit, 100.0f);
32}
Style style
Definition paint.h:85
std::optional< StrokeParameters > GetStroke() const
Return an optional StrokeParameters if this Paint is a stroked Paint, otherwise return a nullopt.
Definition paint.h:95
StrokeParameters stroke
Definition paint.h:84

References impeller::StrokeParameters::cap, impeller::Paint::GetStroke(), impeller::StrokeParameters::join, impeller::Paint::kFill, impeller::kRound, impeller::StrokeParameters::miter_limit, impeller::Paint::stroke, impeller::Paint::style, and impeller::StrokeParameters::width.

◆ TEST() [335/689]

impeller::testing::TEST ( PaintTest  ,
OptionalStrokeWithStroke   
)

Definition at line 34 of file paint_unittests.cc.

34 {
35 Paint paint;
36 paint.style = Paint::Style::kStroke;
37 paint.stroke.cap = Cap::kRound;
38 paint.stroke.join = Join::kRound;
39 paint.stroke.width = 20.0f;
40 paint.stroke.miter_limit = 100.0f;
41
42 std::optional<StrokeParameters> optional_stroke = paint.GetStroke();
43 EXPECT_TRUE(optional_stroke.has_value());
44 if (optional_stroke.has_value()) { // Test to keep clang-tidy happy.
45 EXPECT_EQ(optional_stroke->cap, Cap::kRound);
46 EXPECT_EQ(optional_stroke->join, Join::kRound);
47 EXPECT_EQ(optional_stroke->width, 20.0f);
48 EXPECT_EQ(optional_stroke->miter_limit, 100.0f);
49 }
50}

References impeller::StrokeParameters::cap, impeller::Paint::GetStroke(), impeller::StrokeParameters::join, impeller::kRound, impeller::Paint::kStroke, impeller::StrokeParameters::miter_limit, impeller::Paint::stroke, impeller::Paint::style, and impeller::StrokeParameters::width.

◆ TEST() [336/689]

impeller::testing::TEST ( PathSourceTest  ,
DashedLinePathSource   
)

Definition at line 158 of file path_source_unittests.cc.

158 {
159 DashedLinePathSource source(Point(10, 10), Point(30, 10), 5, 5);
160
161 EXPECT_FALSE(source.IsConvex());
162 EXPECT_EQ(source.GetFillType(), FillType::kNonZero);
163 EXPECT_EQ(source.GetBounds(), Rect::MakeLTRB(10, 10, 30, 10));
164
165 ::testing::StrictMock<DlPathReceiverMock> receiver;
166
167 {
168 ::testing::Sequence sequence;
169
170 EXPECT_CALL(receiver, MoveTo(Point(10, 10), false));
171 EXPECT_CALL(receiver, LineTo(Point(15, 10)));
172 EXPECT_CALL(receiver, MoveTo(Point(20, 10), false));
173 EXPECT_CALL(receiver, LineTo(Point(25, 10)));
174 }
175
176 source.Dispatch(receiver);
177}
A PathSource that generates the various segments of a dashed line.
void MoveTo(PathBuilder *builder, Scalar x, Scalar y)
void LineTo(PathBuilder *builder, Scalar x, Scalar y)

References impeller::DashedLinePathSource::Dispatch(), impeller::DashedLinePathSource::GetBounds(), impeller::DashedLinePathSource::GetFillType(), impeller::DashedLinePathSource::IsConvex(), impeller::kNonZero, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::MoveTo().

◆ TEST() [337/689]

impeller::testing::TEST ( PathSourceTest  ,
DashedLinePathSourceInvalidOffGaps   
)

Definition at line 217 of file path_source_unittests.cc.

217 {
218 DashedLinePathSource source(Point(10, 10), Point(30, 10), 5, -1);
219
220 EXPECT_FALSE(source.IsConvex());
221 EXPECT_EQ(source.GetFillType(), FillType::kNonZero);
222 EXPECT_EQ(source.GetBounds(), Rect::MakeLTRB(10, 10, 30, 10));
223
224 ::testing::StrictMock<DlPathReceiverMock> receiver;
225
226 {
227 ::testing::Sequence sequence;
228
229 EXPECT_CALL(receiver, MoveTo(Point(10, 10), false));
230 EXPECT_CALL(receiver, LineTo(Point(30, 10)));
231 }
232
233 source.Dispatch(receiver);
234}

References impeller::DashedLinePathSource::Dispatch(), impeller::DashedLinePathSource::GetBounds(), impeller::DashedLinePathSource::GetFillType(), impeller::DashedLinePathSource::IsConvex(), impeller::kNonZero, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::MoveTo().

◆ TEST() [338/689]

impeller::testing::TEST ( PathSourceTest  ,
DashedLinePathSourceInvalidOnRegion   
)

Definition at line 236 of file path_source_unittests.cc.

236 {
237 DashedLinePathSource source(Point(10, 10), Point(30, 10), -1, 5);
238
239 EXPECT_FALSE(source.IsConvex());
240 EXPECT_EQ(source.GetFillType(), FillType::kNonZero);
241 EXPECT_EQ(source.GetBounds(), Rect::MakeLTRB(10, 10, 30, 10));
242
243 ::testing::StrictMock<DlPathReceiverMock> receiver;
244
245 {
246 ::testing::Sequence sequence;
247
248 EXPECT_CALL(receiver, MoveTo(Point(10, 10), false));
249 EXPECT_CALL(receiver, LineTo(Point(30, 10)));
250 }
251
252 source.Dispatch(receiver);
253}

References impeller::DashedLinePathSource::Dispatch(), impeller::DashedLinePathSource::GetBounds(), impeller::DashedLinePathSource::GetFillType(), impeller::DashedLinePathSource::IsConvex(), impeller::kNonZero, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::MoveTo().

◆ TEST() [339/689]

impeller::testing::TEST ( PathSourceTest  ,
DashedLinePathSourceZeroOffGaps   
)

Definition at line 198 of file path_source_unittests.cc.

198 {
199 DashedLinePathSource source(Point(10, 10), Point(30, 10), 5, 0);
200
201 EXPECT_FALSE(source.IsConvex());
202 EXPECT_EQ(source.GetFillType(), FillType::kNonZero);
203 EXPECT_EQ(source.GetBounds(), Rect::MakeLTRB(10, 10, 30, 10));
204
205 ::testing::StrictMock<DlPathReceiverMock> receiver;
206
207 {
208 ::testing::Sequence sequence;
209
210 EXPECT_CALL(receiver, MoveTo(Point(10, 10), false));
211 EXPECT_CALL(receiver, LineTo(Point(30, 10)));
212 }
213
214 source.Dispatch(receiver);
215}

References impeller::DashedLinePathSource::Dispatch(), impeller::DashedLinePathSource::GetBounds(), impeller::DashedLinePathSource::GetFillType(), impeller::DashedLinePathSource::IsConvex(), impeller::kNonZero, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::MoveTo().

◆ TEST() [340/689]

impeller::testing::TEST ( PathSourceTest  ,
DiffRoundRectSourceTest   
)

Definition at line 105 of file path_source_unittests.cc.

105 {
106 Rect outer_rect = Rect::MakeLTRB(10, 15, 200, 300);
107 Rect inner_rect = Rect::MakeLTRB(50, 60, 100, 200);
108 ASSERT_TRUE(outer_rect.Contains(inner_rect));
109 RoundingRadii radii = {
110 .top_left = Size(1, 11),
111 .top_right = Size(2, 12),
112 .bottom_left = Size(4, 14),
113 .bottom_right = Size(3, 13),
114 };
115 RoundRect outer_rrect = RoundRect::MakeRectRadii(outer_rect, radii);
116 RoundRect inner_rrect = RoundRect::MakeRectRadii(inner_rect, radii);
117 DiffRoundRectPathSource source(outer_rrect, inner_rrect);
118
119 EXPECT_FALSE(source.IsConvex());
120 EXPECT_EQ(source.GetFillType(), FillType::kOdd);
121 EXPECT_EQ(source.GetBounds(), Rect::MakeLTRB(10, 15, 200, 300));
122
123 ::testing::StrictMock<DlPathReceiverMock> receiver;
124
125 {
126 ::testing::Sequence sequence;
127
128 EXPECT_CALL(receiver, MoveTo(Point(11, 15), true));
129 EXPECT_CALL(receiver, LineTo(Point(198, 15)));
130 EXPECT_CALL(receiver, ConicTo(Point(200, 15), Point(200, 27), kSqrt2Over2));
131 EXPECT_CALL(receiver, LineTo(Point(200, 287)));
132 EXPECT_CALL(receiver,
133 ConicTo(Point(200, 300), Point(197, 300), kSqrt2Over2));
134 EXPECT_CALL(receiver, LineTo(Point(14, 300)));
135 EXPECT_CALL(receiver, ConicTo(Point(10, 300), Point(10, 286), kSqrt2Over2));
136 EXPECT_CALL(receiver, LineTo(Point(10, 26)));
137 EXPECT_CALL(receiver, ConicTo(Point(10, 15), Point(11, 15), kSqrt2Over2));
138 // RetiresOnSaturation keeps identical calls from matching each other
139 EXPECT_CALL(receiver, Close()).RetiresOnSaturation();
140
141 EXPECT_CALL(receiver, MoveTo(Point(51, 60), true));
142 EXPECT_CALL(receiver, LineTo(Point(98, 60)));
143 EXPECT_CALL(receiver, ConicTo(Point(100, 60), Point(100, 72), kSqrt2Over2));
144 EXPECT_CALL(receiver, LineTo(Point(100, 187)));
145 EXPECT_CALL(receiver,
146 ConicTo(Point(100, 200), Point(97, 200), kSqrt2Over2));
147 EXPECT_CALL(receiver, LineTo(Point(54, 200)));
148 EXPECT_CALL(receiver, ConicTo(Point(50, 200), Point(50, 186), kSqrt2Over2));
149 EXPECT_CALL(receiver, LineTo(Point(50, 71)));
150 EXPECT_CALL(receiver, ConicTo(Point(50, 60), Point(51, 60), kSqrt2Over2));
151 // RetiresOnSaturation keeps identical calls from matching each other
152 EXPECT_CALL(receiver, Close()).RetiresOnSaturation();
153 }
154
155 source.Dispatch(receiver);
156}
void Close(PathBuilder *builder)

References impeller::Close(), impeller::DiffRoundRectPathSource::Dispatch(), impeller::DiffRoundRectPathSource::GetBounds(), impeller::DiffRoundRectPathSource::GetFillType(), impeller::DiffRoundRectPathSource::IsConvex(), impeller::kOdd, impeller::kSqrt2Over2, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), impeller::MoveTo(), and impeller::RoundingRadii::top_left.

◆ TEST() [341/689]

impeller::testing::TEST ( PathSourceTest  ,
EllipseSourceTest   
)

Definition at line 46 of file path_source_unittests.cc.

46 {
47 Rect rect = Rect::MakeLTRB(10, 15, 20, 30);
48 EllipsePathSource source(rect);
49
50 EXPECT_TRUE(source.IsConvex());
51 EXPECT_EQ(source.GetFillType(), FillType::kNonZero);
52 EXPECT_EQ(source.GetBounds(), Rect::MakeLTRB(10, 15, 20, 30));
53
54 ::testing::StrictMock<DlPathReceiverMock> receiver;
55
56 {
57 ::testing::Sequence sequence;
58
59 EXPECT_CALL(receiver, MoveTo(Point(10, 22.5), true));
60 EXPECT_CALL(receiver, ConicTo(Point(10, 15), Point(15, 15), kSqrt2Over2));
61 EXPECT_CALL(receiver, ConicTo(Point(20, 15), Point(20, 22.5), kSqrt2Over2));
62 EXPECT_CALL(receiver, ConicTo(Point(20, 30), Point(15, 30), kSqrt2Over2));
63 EXPECT_CALL(receiver, ConicTo(Point(10, 30), Point(10, 22.5), kSqrt2Over2));
64 EXPECT_CALL(receiver, Close());
65 }
66
67 source.Dispatch(receiver);
68}
A PathSource object that provides path iteration for any ellipse inscribed within a Rect bounds.
Definition path_source.h:90

References impeller::Close(), impeller::EllipsePathSource::Dispatch(), impeller::EllipsePathSource::GetBounds(), impeller::EllipsePathSource::GetFillType(), impeller::EllipsePathSource::IsConvex(), impeller::kNonZero, impeller::kSqrt2Over2, impeller::TRect< Scalar >::MakeLTRB(), and impeller::MoveTo().

◆ TEST() [342/689]

impeller::testing::TEST ( PathSourceTest  ,
EmptyDashedLinePathSource   
)

Definition at line 179 of file path_source_unittests.cc.

179 {
180 DashedLinePathSource source(Point(10, 10), Point(10, 10), 5, 5);
181
182 EXPECT_FALSE(source.IsConvex());
183 EXPECT_EQ(source.GetFillType(), FillType::kNonZero);
184 EXPECT_EQ(source.GetBounds(), Rect::MakeLTRB(10, 10, 10, 10));
185
186 ::testing::StrictMock<DlPathReceiverMock> receiver;
187
188 {
189 ::testing::Sequence sequence;
190
191 EXPECT_CALL(receiver, MoveTo(Point(10, 10), false));
192 EXPECT_CALL(receiver, LineTo(Point(10, 10)));
193 }
194
195 source.Dispatch(receiver);
196}

References impeller::DashedLinePathSource::Dispatch(), impeller::DashedLinePathSource::GetBounds(), impeller::DashedLinePathSource::GetFillType(), impeller::DashedLinePathSource::IsConvex(), impeller::kNonZero, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::MoveTo().

◆ TEST() [343/689]

impeller::testing::TEST ( PathSourceTest  ,
PathTransformerAllSegmentsTest   
)

Definition at line 282 of file path_source_unittests.cc.

282 {
283 Matrix matrix =
284 Matrix::MakeTranslateScale({2.0f, 3.0f, 1.0f}, {1.5f, 4.25f, 0.0f});
285
286 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
287 PathTransformer receiver = PathTransformer(mock_receiver, matrix);
288
289 {
290 ::testing::Sequence sequence;
291
292 EXPECT_CALL(mock_receiver, MoveTo(Point(21.5f, 49.25f), false));
293 EXPECT_CALL(mock_receiver, LineTo(Point(41.5f, 49.25f)));
294
295 EXPECT_CALL(mock_receiver, MoveTo(Point(221.5f, 349.25f), true));
296 EXPECT_CALL(mock_receiver,
297 QuadTo(Point(241.5f, 349.25f), Point(241.5f, 394.25f)));
298 EXPECT_CALL(mock_receiver,
299 ConicTo(Point(237.5f, 409.25f), Point(231.5f, 409.25f), 5))
300 .WillOnce(Return(true));
301 EXPECT_CALL(mock_receiver,
302 ConicTo(Point(225.5f, 409.25f), Point(221.5f, 394.25f), 6))
303 .WillOnce(Return(false));
304 EXPECT_CALL(mock_receiver,
305 CubicTo(Point(211.5f, 379.25f), Point(211.5f, 364.25f),
306 Point(221.5f, 349.25f)));
307 EXPECT_CALL(mock_receiver, Close());
308 }
309
310 receiver.MoveTo(Point(10, 15), false);
311 receiver.LineTo(Point(20, 15));
312
313 receiver.MoveTo(Point(110, 115), true);
314 receiver.QuadTo(Point(120, 115), Point(120, 130));
315 EXPECT_TRUE(receiver.ConicTo(Point(118, 135), Point(115, 135), 5));
316 EXPECT_FALSE(receiver.ConicTo(Point(112, 135), Point(110, 130), 6));
317 receiver.CubicTo(Point(105, 125), Point(105, 120), Point(110, 115));
318 receiver.Close();
319}

References impeller::PathTransformer::Close(), impeller::Close(), impeller::PathTransformer::ConicTo(), impeller::PathTransformer::CubicTo(), impeller::CubicTo(), impeller::PathTransformer::LineTo(), impeller::LineTo(), impeller::Matrix::MakeTranslateScale(), impeller::PathTransformer::MoveTo(), impeller::MoveTo(), and impeller::PathTransformer::QuadTo().

◆ TEST() [344/689]

impeller::testing::TEST ( PathSourceTest  ,
PathTransformerRectSourceTest   
)

Definition at line 255 of file path_source_unittests.cc.

255 {
256 Matrix matrix =
257 Matrix::MakeTranslateScale({2.0f, 3.0f, 1.0f}, {1.5f, 4.25f, 0.0f});
258 Rect rect = Rect::MakeLTRB(10, 15, 20, 30);
259 RectPathSource source(rect);
260
261 EXPECT_TRUE(source.IsConvex());
262 EXPECT_EQ(source.GetFillType(), FillType::kNonZero);
263 EXPECT_EQ(source.GetBounds(), Rect::MakeLTRB(10, 15, 20, 30));
264
265 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
266 PathTransformer receiver = PathTransformer(mock_receiver, matrix);
267
268 {
269 ::testing::Sequence sequence;
270
271 EXPECT_CALL(mock_receiver, MoveTo(Point(21.5f, 49.25f), true));
272 EXPECT_CALL(mock_receiver, LineTo(Point(41.5f, 49.25f)));
273 EXPECT_CALL(mock_receiver, LineTo(Point(41.5f, 94.25f)));
274 EXPECT_CALL(mock_receiver, LineTo(Point(21.5f, 94.25f)));
275 EXPECT_CALL(mock_receiver, LineTo(Point(21.5f, 49.25f)));
276 EXPECT_CALL(mock_receiver, Close());
277 }
278
279 source.Dispatch(receiver);
280}

References impeller::Close(), impeller::RectPathSource::Dispatch(), impeller::RectPathSource::GetBounds(), impeller::RectPathSource::GetFillType(), impeller::RectPathSource::IsConvex(), impeller::kNonZero, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeTranslateScale(), and impeller::MoveTo().

◆ TEST() [345/689]

impeller::testing::TEST ( PathSourceTest  ,
RectSourceTest   
)

Definition at line 22 of file path_source_unittests.cc.

22 {
23 Rect rect = Rect::MakeLTRB(10, 15, 20, 30);
24 RectPathSource source(rect);
25
26 EXPECT_TRUE(source.IsConvex());
27 EXPECT_EQ(source.GetFillType(), FillType::kNonZero);
28 EXPECT_EQ(source.GetBounds(), Rect::MakeLTRB(10, 15, 20, 30));
29
30 ::testing::StrictMock<DlPathReceiverMock> receiver;
31
32 {
33 ::testing::Sequence sequence;
34
35 EXPECT_CALL(receiver, MoveTo(Point(10, 15), true));
36 EXPECT_CALL(receiver, LineTo(Point(20, 15)));
37 EXPECT_CALL(receiver, LineTo(Point(20, 30)));
38 EXPECT_CALL(receiver, LineTo(Point(10, 30)));
39 EXPECT_CALL(receiver, LineTo(Point(10, 15)));
40 EXPECT_CALL(receiver, Close());
41 }
42
43 source.Dispatch(receiver);
44}
A PathSource object that provides path iteration for any TRect.
Definition path_source.h:65

References impeller::Close(), impeller::RectPathSource::Dispatch(), impeller::RectPathSource::GetBounds(), impeller::RectPathSource::GetFillType(), impeller::RectPathSource::IsConvex(), impeller::kNonZero, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::MoveTo().

◆ TEST() [346/689]

impeller::testing::TEST ( PathSourceTest  ,
RoundRectSourceTest   
)

Definition at line 70 of file path_source_unittests.cc.

70 {
71 Rect rect = Rect::MakeLTRB(10, 15, 40, 60);
72 RoundingRadii radii = {
73 .top_left = Size(1, 11),
74 .top_right = Size(2, 12),
75 .bottom_left = Size(4, 14),
76 .bottom_right = Size(3, 13),
77 };
78 RoundRect round_rect = RoundRect::MakeRectRadii(rect, radii);
79 RoundRectPathSource source(round_rect);
80
81 EXPECT_TRUE(source.IsConvex());
82 EXPECT_EQ(source.GetFillType(), FillType::kNonZero);
83 EXPECT_EQ(source.GetBounds(), Rect::MakeLTRB(10, 15, 40, 60));
84
85 ::testing::StrictMock<DlPathReceiverMock> receiver;
86
87 {
88 ::testing::Sequence sequence;
89
90 EXPECT_CALL(receiver, MoveTo(Point(11, 15), true));
91 EXPECT_CALL(receiver, LineTo(Point(38, 15)));
92 EXPECT_CALL(receiver, ConicTo(Point(40, 15), Point(40, 27), kSqrt2Over2));
93 EXPECT_CALL(receiver, LineTo(Point(40, 47)));
94 EXPECT_CALL(receiver, ConicTo(Point(40, 60), Point(37, 60), kSqrt2Over2));
95 EXPECT_CALL(receiver, LineTo(Point(14, 60)));
96 EXPECT_CALL(receiver, ConicTo(Point(10, 60), Point(10, 46), kSqrt2Over2));
97 EXPECT_CALL(receiver, LineTo(Point(10, 26)));
98 EXPECT_CALL(receiver, ConicTo(Point(10, 15), Point(11, 15), kSqrt2Over2));
99 EXPECT_CALL(receiver, Close());
100 }
101
102 source.Dispatch(receiver);
103}

References impeller::Close(), impeller::RoundRectPathSource::Dispatch(), impeller::RoundRectPathSource::GetBounds(), impeller::RoundRectPathSource::GetFillType(), impeller::RoundRectPathSource::IsConvex(), impeller::kNonZero, impeller::kSqrt2Over2, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), impeller::MoveTo(), and impeller::RoundingRadii::top_left.

◆ TEST() [347/689]

impeller::testing::TEST ( PathTessellatorTest  ,
ComplexPath   
)

Definition at line 396 of file path_tessellator_unittests.cc.

396 {
397 PathTessellator::Quad quad{{10, 10}, {20, 20}, {20, 10}};
398 PathTessellator::Conic conic{{20, 10}, {30, 20}, {30, 10}, 2.0f};
399 PathTessellator::Cubic cubic{{30, 10}, {40, 20}, {40, 10}, {42, 15}};
400
402 builder.MoveTo({0, 0});
403 builder.LineTo({10, 10});
404 builder.QuadraticCurveTo(quad.cp, quad.p2);
405 builder.ConicCurveTo(conic.cp, conic.p2, conic.weight);
406 builder.CubicCurveTo(cubic.cp1, cubic.cp2, cubic.p2);
407 builder.Close();
408 flutter::DlPath path = builder.TakePath();
409
410 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
411 {
412 ::testing::InSequence sequence;
413
414 EXPECT_CALL(mock_receiver,
415 BeginContour(Point(0, 0), /*will_be_closed=*/true));
416 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 0), Point(10, 10)));
417 EXPECT_CALL(mock_receiver, RecordQuad(quad.p1, quad.cp, quad.p2));
418 EXPECT_CALL(mock_receiver,
419 RecordConic(conic.p1, conic.cp, conic.p2, conic.weight));
420 EXPECT_CALL(mock_receiver,
421 RecordCubic(cubic.p1, cubic.cp1, cubic.cp2, cubic.p2));
422 EXPECT_CALL(mock_receiver, RecordLine(cubic.p2, Point(0, 0)));
423 EXPECT_CALL(mock_receiver, EndContour(Point(0, 0), /*with_close=*/true));
424 }
425 PathTessellator::PathToFilledSegments(path, mock_receiver);
426
427 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
428 EXPECT_EQ(points, 25u);
429 EXPECT_EQ(contours, 1u);
430
431 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
432 {
433 ::testing::InSequence sequence;
434
435 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
436 EXPECT_CALL(mock_writer, Write(Point(10, 10)));
437 {
438 EXPECT_CALL(mock_writer, Write(quad.Solve(1 / 5.0f)));
439 EXPECT_CALL(mock_writer, Write(quad.Solve(2 / 5.0f)));
440 EXPECT_CALL(mock_writer, Write(quad.Solve(3 / 5.0f)));
441 EXPECT_CALL(mock_writer, Write(quad.Solve(4 / 5.0f)));
442 EXPECT_CALL(mock_writer, Write(quad.p2));
443 }
444 {
445 EXPECT_CALL(mock_writer, Write(conic.Solve(1 / 8.0f)));
446 EXPECT_CALL(mock_writer, Write(conic.Solve(2 / 8.0f)));
447 EXPECT_CALL(mock_writer, Write(conic.Solve(3 / 8.0f)));
448 EXPECT_CALL(mock_writer, Write(conic.Solve(4 / 8.0f)));
449 EXPECT_CALL(mock_writer, Write(conic.Solve(5 / 8.0f)));
450 EXPECT_CALL(mock_writer, Write(conic.Solve(6 / 8.0f)));
451 EXPECT_CALL(mock_writer, Write(conic.Solve(7 / 8.0f)));
452 EXPECT_CALL(mock_writer, Write(conic.p2));
453 }
454 {
455 EXPECT_CALL(mock_writer, Write(cubic.Solve(1 / 9.0f)));
456 EXPECT_CALL(mock_writer, Write(cubic.Solve(2 / 9.0f)));
457 EXPECT_CALL(mock_writer, Write(cubic.Solve(3 / 9.0f)));
458 EXPECT_CALL(mock_writer, Write(cubic.Solve(4 / 9.0f)));
459 EXPECT_CALL(mock_writer, Write(cubic.Solve(5 / 9.0f)));
460 EXPECT_CALL(mock_writer, Write(cubic.Solve(6 / 9.0f)));
461 EXPECT_CALL(mock_writer, Write(cubic.Solve(7 / 9.0f)));
462 EXPECT_CALL(mock_writer, Write(cubic.Solve(8 / 9.0f)));
463 EXPECT_CALL(mock_writer, Write(cubic.p2));
464 }
465 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
466 EXPECT_CALL(mock_writer, EndContour());
467 }
468 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
469}
DlPathBuilder & Close()
The path is closed back to the location of the most recent MoveTo call. Contours that are filled are ...
std::vector< Contour > contours

References flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::CubicCurveTo(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, flutter::DlPathBuilder::QuadraticCurveTo(), and flutter::DlPathBuilder::TakePath().

◆ TEST() [348/689]

impeller::testing::TEST ( PathTessellatorTest  ,
ComplexPathTrailingMoveTo   
)

Definition at line 471 of file path_tessellator_unittests.cc.

471 {
472 PathTessellator::Quad quad{{10, 10}, {20, 20}, {20, 10}};
473 PathTessellator::Conic conic{{20, 10}, {30, 20}, {30, 10}, 2.0f};
474 PathTessellator::Cubic cubic{{30, 10}, {40, 20}, {40, 10}, {42, 15}};
475
477 builder.MoveTo({0, 0});
478 builder.LineTo({10, 10});
479 builder.QuadraticCurveTo(quad.cp, quad.p2);
480 builder.ConicCurveTo(conic.cp, conic.p2, conic.weight);
481 builder.CubicCurveTo(cubic.cp1, cubic.cp2, cubic.p2);
482 builder.Close();
483 builder.MoveTo({500, 100});
484 flutter::DlPath path = builder.TakePath();
485
486 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
487 {
488 ::testing::InSequence sequence;
489
490 EXPECT_CALL(mock_receiver,
491 BeginContour(Point(0, 0), /*will_be_closed=*/true));
492 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 0), Point(10, 10)));
493 EXPECT_CALL(mock_receiver, RecordQuad(quad.p1, quad.cp, quad.p2));
494 EXPECT_CALL(mock_receiver,
495 RecordConic(conic.p1, conic.cp, conic.p2, conic.weight));
496 EXPECT_CALL(mock_receiver,
497 RecordCubic(cubic.p1, cubic.cp1, cubic.cp2, cubic.p2));
498 EXPECT_CALL(mock_receiver, RecordLine(cubic.p2, Point(0, 0)));
499 EXPECT_CALL(mock_receiver, EndContour(Point(0, 0), /*with_close=*/true));
500 }
501 PathTessellator::PathToFilledSegments(path, mock_receiver);
502
503 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
504 EXPECT_EQ(points, 25u);
505 EXPECT_EQ(contours, 1u);
506
507 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
508 {
509 ::testing::InSequence sequence;
510
511 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
512 EXPECT_CALL(mock_writer, Write(Point(10, 10)));
513 {
514 EXPECT_CALL(mock_writer, Write(quad.Solve(1 / 5.0f)));
515 EXPECT_CALL(mock_writer, Write(quad.Solve(2 / 5.0f)));
516 EXPECT_CALL(mock_writer, Write(quad.Solve(3 / 5.0f)));
517 EXPECT_CALL(mock_writer, Write(quad.Solve(4 / 5.0f)));
518 EXPECT_CALL(mock_writer, Write(quad.p2));
519 }
520 {
521 EXPECT_CALL(mock_writer, Write(conic.Solve(1 / 8.0f)));
522 EXPECT_CALL(mock_writer, Write(conic.Solve(2 / 8.0f)));
523 EXPECT_CALL(mock_writer, Write(conic.Solve(3 / 8.0f)));
524 EXPECT_CALL(mock_writer, Write(conic.Solve(4 / 8.0f)));
525 EXPECT_CALL(mock_writer, Write(conic.Solve(5 / 8.0f)));
526 EXPECT_CALL(mock_writer, Write(conic.Solve(6 / 8.0f)));
527 EXPECT_CALL(mock_writer, Write(conic.Solve(7 / 8.0f)));
528 EXPECT_CALL(mock_writer, Write(conic.p2));
529 }
530 {
531 EXPECT_CALL(mock_writer, Write(cubic.Solve(1 / 9.0f)));
532 EXPECT_CALL(mock_writer, Write(cubic.Solve(2 / 9.0f)));
533 EXPECT_CALL(mock_writer, Write(cubic.Solve(3 / 9.0f)));
534 EXPECT_CALL(mock_writer, Write(cubic.Solve(4 / 9.0f)));
535 EXPECT_CALL(mock_writer, Write(cubic.Solve(5 / 9.0f)));
536 EXPECT_CALL(mock_writer, Write(cubic.Solve(6 / 9.0f)));
537 EXPECT_CALL(mock_writer, Write(cubic.Solve(7 / 9.0f)));
538 EXPECT_CALL(mock_writer, Write(cubic.Solve(8 / 9.0f)));
539 EXPECT_CALL(mock_writer, Write(cubic.p2));
540 }
541 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
542 EXPECT_CALL(mock_writer, EndContour());
543 }
544 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
545}

References flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::CubicCurveTo(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, flutter::DlPathBuilder::QuadraticCurveTo(), and flutter::DlPathBuilder::TakePath().

◆ TEST() [349/689]

impeller::testing::TEST ( PathTessellatorTest  ,
ConicToLineToOptimization   
)

Definition at line 269 of file path_tessellator_unittests.cc.

269 {
271 builder.MoveTo({0, 0});
272 // CP == P1
273 builder.ConicCurveTo({0, 0}, {10, 10}, 2.0f);
274 // CP == P2
275 builder.ConicCurveTo({20, 10}, {20, 10}, 2.0f);
276 // weight == 0
277 builder.ConicCurveTo({20, 0}, {10, 0}, 0.0f);
278 builder.Close();
279 flutter::DlPath path = builder.TakePath();
280
281 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
282 {
283 ::testing::InSequence sequence;
284
285 EXPECT_CALL(mock_receiver,
286 BeginContour(Point(0, 0), /*will_be_closed=*/true));
287 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 0), Point(10, 10)));
288 EXPECT_CALL(mock_receiver, RecordLine(Point(10, 10), Point(20, 10)));
289 EXPECT_CALL(mock_receiver, RecordLine(Point(20, 10), Point(10, 0)));
290 EXPECT_CALL(mock_receiver, RecordLine(Point(10, 0), Point(0, 0)));
291 EXPECT_CALL(mock_receiver, EndContour(Point(0, 0), /*with_close=*/true));
292 }
293 PathTessellator::PathToFilledSegments(path, mock_receiver);
294
295 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
296 EXPECT_EQ(points, 5u);
297 EXPECT_EQ(contours, 1u);
298
299 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
300 {
301 ::testing::InSequence sequence;
302
303 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
304 EXPECT_CALL(mock_writer, Write(Point(10, 10)));
305 EXPECT_CALL(mock_writer, Write(Point(20, 10)));
306 EXPECT_CALL(mock_writer, Write(Point(10, 0)));
307 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
308 EXPECT_CALL(mock_writer, EndContour());
309 }
310 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
311}

References flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [350/689]

impeller::testing::TEST ( PathTessellatorTest  ,
ConicToQuadToOptimization   
)

Definition at line 313 of file path_tessellator_unittests.cc.

313 {
314 // The conic below will simplify to this quad
315 PathTessellator::Quad quad{{0, 0}, {10, 0}, {0, 10}};
316
318 builder.MoveTo(quad.p1);
319 // weight == 1
320 builder.ConicCurveTo(quad.cp, quad.p2, 1.0f);
321 builder.Close();
322 flutter::DlPath path = builder.TakePath();
323
324 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
325 {
326 ::testing::InSequence sequence;
327
328 EXPECT_CALL(mock_receiver, BeginContour(quad.p1, /*will_be_closed=*/true));
329 EXPECT_CALL(mock_receiver, RecordQuad(quad.p1, quad.cp, quad.p2));
330 EXPECT_CALL(mock_receiver, RecordLine(quad.p2, quad.p1));
331 EXPECT_CALL(mock_receiver, EndContour(quad.p1, /*with_close=*/true));
332 }
333 PathTessellator::PathToFilledSegments(path, mock_receiver);
334
335 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
336 EXPECT_EQ(points, 7u);
337 EXPECT_EQ(contours, 1u);
338
339 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
340 {
341 ::testing::InSequence sequence;
342
343 EXPECT_CALL(mock_writer, Write(quad.p1));
344 {
345 EXPECT_CALL(mock_writer, Write(quad.Solve(1 / 5.0f)));
346 EXPECT_CALL(mock_writer, Write(quad.Solve(2 / 5.0f)));
347 EXPECT_CALL(mock_writer, Write(quad.Solve(3 / 5.0f)));
348 EXPECT_CALL(mock_writer, Write(quad.Solve(4 / 5.0f)));
349 EXPECT_CALL(mock_writer, Write(quad.p2));
350 }
351 EXPECT_CALL(mock_writer, Write(quad.p1));
352 EXPECT_CALL(mock_writer, EndContour());
353 }
354 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
355}

References flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [351/689]

impeller::testing::TEST ( PathTessellatorTest  ,
DegenerateSegmentsPath   
)

Definition at line 191 of file path_tessellator_unittests.cc.

191 {
193 builder.MoveTo({0, 0});
194 builder.LineTo({0, 0});
195 builder.LineTo({0, 0});
196 builder.QuadraticCurveTo({0, 0}, {0, 0});
197 builder.QuadraticCurveTo({0, 0}, {0, 0});
198 builder.ConicCurveTo({0, 0}, {0, 0}, 12.0f);
199 builder.ConicCurveTo({0, 0}, {0, 0}, 12.0f);
200 builder.CubicCurveTo({0, 0}, {0, 0}, {0, 0});
201 builder.CubicCurveTo({0, 0}, {0, 0}, {0, 0});
202 builder.Close();
203 flutter::DlPath path = builder.TakePath();
204
205 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
206 {
207 ::testing::InSequence sequence;
208
209 EXPECT_CALL(mock_receiver,
210 BeginContour(Point(0, 0), /*will_be_closed=*/true));
211 EXPECT_CALL(mock_receiver, EndContour(Point(0, 0), /*with_close=*/true));
212 }
213 PathTessellator::PathToFilledSegments(path, mock_receiver);
214
215 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
216 EXPECT_EQ(points, 1u);
217 EXPECT_EQ(contours, 1u);
218
219 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
220 {
221 ::testing::InSequence sequence;
222
223 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
224 EXPECT_CALL(mock_writer, EndContour());
225 }
226 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
227}

References flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::CubicCurveTo(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, flutter::DlPathBuilder::QuadraticCurveTo(), and flutter::DlPathBuilder::TakePath().

◆ TEST() [352/689]

impeller::testing::TEST ( PathTessellatorTest  ,
EmptyPath   
)

Definition at line 42 of file path_tessellator_unittests.cc.

42 {
44 builder.MoveTo({0, 0});
45 flutter::DlPath path = builder.TakePath();
46
47 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
48 PathTessellator::PathToFilledSegments(path, mock_receiver);
49
50 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
51 EXPECT_EQ(points, 0u);
52 EXPECT_EQ(contours, 0u);
53
54 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
55 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
56}

References contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [353/689]

impeller::testing::TEST ( PathTessellatorTest  ,
EmptyPathMultipleMoveTo   
)

Definition at line 58 of file path_tessellator_unittests.cc.

58 {
60 builder.MoveTo({0, 0});
61 builder.MoveTo({10, 10});
62 builder.MoveTo({20, 20});
63 flutter::DlPath path = builder.TakePath();
64
65 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
66 PathTessellator::PathToFilledSegments(path, mock_receiver);
67
68 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
69 EXPECT_EQ(points, 0u);
70 EXPECT_EQ(contours, 0u);
71
72 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
73 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
74}

References contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [354/689]

impeller::testing::TEST ( PathTessellatorTest  ,
LinearConicToPointCount   
)

Definition at line 559 of file path_tessellator_unittests.cc.

559 {
561 builder.MoveTo({316.3, 121.5});
562 builder.ConicCurveTo({316.4, 121.5}, {316.5, 121.5}, 2.0f);
563 builder.Close();
564 auto path = builder.TakePath();
565
566 auto [points, contours] = PathTessellator::CountFillStorage(path, 2.0f);
567 EXPECT_EQ(points, 3u);
568 EXPECT_EQ(contours, 1u);
569}

References flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::MoveTo(), flutter::path, points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [355/689]

impeller::testing::TEST ( PathTessellatorTest  ,
LinearCubicToPointCount   
)

Definition at line 571 of file path_tessellator_unittests.cc.

571 {
573 builder.MoveTo({316.3, 121.5});
574 builder.CubicCurveTo({316.4, 121.5}, {316.5, 121.5}, {316.6, 121.5});
575 builder.Close();
576 auto path = builder.TakePath();
577
578 auto [points, contours] = PathTessellator::CountFillStorage(path, 2.0f);
579 EXPECT_EQ(points, 3u);
580 EXPECT_EQ(contours, 1u);
581}

References flutter::DlPathBuilder::Close(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::CubicCurveTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [356/689]

impeller::testing::TEST ( PathTessellatorTest  ,
LinearQuadToPointCount   
)

Definition at line 547 of file path_tessellator_unittests.cc.

547 {
549 builder.MoveTo({316.3, 121.5});
550 builder.QuadraticCurveTo({316.4, 121.5}, {316.5, 121.5});
551 builder.Close();
552 auto path = builder.TakePath();
553
554 auto [points, contours] = PathTessellator::CountFillStorage(path, 2.0f);
555 EXPECT_EQ(points, 3u);
556 EXPECT_EQ(contours, 1u);
557}

References flutter::DlPathBuilder::Close(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::MoveTo(), flutter::path, points, flutter::DlPathBuilder::QuadraticCurveTo(), and flutter::DlPathBuilder::TakePath().

◆ TEST() [357/689]

impeller::testing::TEST ( PathTessellatorTest  ,
QuadToLineToOptimization   
)

Definition at line 229 of file path_tessellator_unittests.cc.

229 {
231 builder.MoveTo({0, 0});
232 // CP == P1
233 builder.QuadraticCurveTo({0, 0}, {10, 10});
234 // CP == P2
235 builder.QuadraticCurveTo({20, 10}, {20, 10});
236 builder.Close();
237 flutter::DlPath path = builder.TakePath();
238
239 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
240 {
241 ::testing::InSequence sequence;
242
243 EXPECT_CALL(mock_receiver,
244 BeginContour(Point(0, 0), /*will_be_closed=*/true));
245 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 0), Point(10, 10)));
246 EXPECT_CALL(mock_receiver, RecordLine(Point(10, 10), Point(20, 10)));
247 EXPECT_CALL(mock_receiver, RecordLine(Point(20, 10), Point(0, 0)));
248 EXPECT_CALL(mock_receiver, EndContour(Point(0, 0), /*with_close=*/true));
249 }
250 PathTessellator::PathToFilledSegments(path, mock_receiver);
251
252 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
253 EXPECT_EQ(points, 4u);
254 EXPECT_EQ(contours, 1u);
255
256 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
257 {
258 ::testing::InSequence sequence;
259
260 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
261 EXPECT_CALL(mock_writer, Write(Point(10, 10)));
262 EXPECT_CALL(mock_writer, Write(Point(20, 10)));
263 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
264 EXPECT_CALL(mock_writer, EndContour());
265 }
266 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
267}

References flutter::DlPathBuilder::Close(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, flutter::DlPathBuilder::QuadraticCurveTo(), and flutter::DlPathBuilder::TakePath().

◆ TEST() [358/689]

impeller::testing::TEST ( PathTessellatorTest  ,
SimpleClosedPath   
)

Definition at line 76 of file path_tessellator_unittests.cc.

76 {
78 builder.MoveTo({0, 0});
79 builder.LineTo({10, 10});
80 builder.LineTo({0, 20});
81 builder.Close();
82 flutter::DlPath path = builder.TakePath();
83
84 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
85 {
86 ::testing::InSequence sequence;
87
88 EXPECT_CALL(mock_receiver,
89 BeginContour(Point(0, 0), /*will_be_closed=*/true));
90 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 0), Point(10, 10)));
91 EXPECT_CALL(mock_receiver, RecordLine(Point(10, 10), Point(0, 20)));
92 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 20), Point(0, 0)));
93 EXPECT_CALL(mock_receiver, EndContour(Point(0, 0), /*with_close=*/true));
94 }
95 PathTessellator::PathToFilledSegments(path, mock_receiver);
96
97 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
98 EXPECT_EQ(points, 4u);
99 EXPECT_EQ(contours, 1u);
100
101 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
102 {
103 ::testing::InSequence sequence;
104
105 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
106 EXPECT_CALL(mock_writer, Write(Point(10, 10)));
107 EXPECT_CALL(mock_writer, Write(Point(0, 20)));
108 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
109 EXPECT_CALL(mock_writer, EndContour());
110 }
111 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
112}

References flutter::DlPathBuilder::Close(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [359/689]

impeller::testing::TEST ( PathTessellatorTest  ,
SimplePathMultipleMoveTo   
)

Definition at line 357 of file path_tessellator_unittests.cc.

357 {
359 builder.MoveTo({500, 100});
360 builder.MoveTo({0, 0});
361 builder.LineTo({10, 10});
362 builder.LineTo({0, 20});
363 builder.Close();
364 flutter::DlPath path = builder.TakePath();
365
366 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
367 {
368 ::testing::InSequence sequence;
369
370 EXPECT_CALL(mock_receiver,
371 BeginContour(Point(0, 0), /*will_be_closed=*/true));
372 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 0), Point(10, 10)));
373 EXPECT_CALL(mock_receiver, RecordLine(Point(10, 10), Point(0, 20)));
374 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 20), Point(0, 0)));
375 EXPECT_CALL(mock_receiver, EndContour(Point(0, 0), /*with_close=*/true));
376 }
377 PathTessellator::PathToFilledSegments(path, mock_receiver);
378
379 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
380 EXPECT_EQ(points, 4u);
381 EXPECT_EQ(contours, 1u);
382
383 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
384 {
385 ::testing::InSequence sequence;
386
387 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
388 EXPECT_CALL(mock_writer, Write(Point(10, 10)));
389 EXPECT_CALL(mock_writer, Write(Point(0, 20)));
390 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
391 EXPECT_CALL(mock_writer, EndContour());
392 }
393 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
394}

References flutter::DlPathBuilder::Close(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [360/689]

impeller::testing::TEST ( PathTessellatorTest  ,
SimplePathTrailingMoveTo   
)

Definition at line 152 of file path_tessellator_unittests.cc.

152 {
154 builder.MoveTo({0, 0});
155 builder.LineTo({10, 10});
156 builder.LineTo({0, 20});
157 builder.Close();
158 builder.MoveTo({500, 100});
159 flutter::DlPath path = builder.TakePath();
160
161 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
162 {
163 ::testing::InSequence sequence;
164
165 EXPECT_CALL(mock_receiver,
166 BeginContour(Point(0, 0), /*will_be_closed=*/true));
167 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 0), Point(10, 10)));
168 EXPECT_CALL(mock_receiver, RecordLine(Point(10, 10), Point(0, 20)));
169 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 20), Point(0, 0)));
170 EXPECT_CALL(mock_receiver, EndContour(Point(0, 0), /*with_close=*/true));
171 }
172 PathTessellator::PathToFilledSegments(path, mock_receiver);
173
174 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
175 EXPECT_EQ(points, 4u);
176 EXPECT_EQ(contours, 1u);
177
178 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
179 {
180 ::testing::InSequence sequence;
181
182 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
183 EXPECT_CALL(mock_writer, Write(Point(10, 10)));
184 EXPECT_CALL(mock_writer, Write(Point(0, 20)));
185 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
186 EXPECT_CALL(mock_writer, EndContour());
187 }
188 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
189}

References flutter::DlPathBuilder::Close(), contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [361/689]

impeller::testing::TEST ( PathTessellatorTest  ,
SimpleUnclosedPath   
)

Definition at line 114 of file path_tessellator_unittests.cc.

114 {
116 builder.MoveTo({0, 0});
117 builder.LineTo({10, 10});
118 builder.LineTo({0, 20});
119 // Close not really needed for filled paths
120 flutter::DlPath path = builder.TakePath();
121
122 ::testing::StrictMock<MockSegmentReceiver> mock_receiver;
123 {
124 ::testing::InSequence sequence;
125
126 EXPECT_CALL(mock_receiver,
127 BeginContour(Point(0, 0), /*will_be_closed=*/false));
128 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 0), Point(10, 10)));
129 EXPECT_CALL(mock_receiver, RecordLine(Point(10, 10), Point(0, 20)));
130 EXPECT_CALL(mock_receiver, RecordLine(Point(0, 20), Point(0, 0)));
131 EXPECT_CALL(mock_receiver, EndContour(Point(0, 0), /*with_close=*/false));
132 }
133 PathTessellator::PathToFilledSegments(path, mock_receiver);
134
135 auto [points, contours] = PathTessellator::CountFillStorage(path, 1.0f);
136 EXPECT_EQ(points, 4u);
137 EXPECT_EQ(contours, 1u);
138
139 ::testing::StrictMock<MockPathVertexWriter> mock_writer;
140 {
141 ::testing::InSequence sequence;
142
143 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
144 EXPECT_CALL(mock_writer, Write(Point(10, 10)));
145 EXPECT_CALL(mock_writer, Write(Point(0, 20)));
146 EXPECT_CALL(mock_writer, Write(Point(0, 0)));
147 EXPECT_CALL(mock_writer, EndContour());
148 }
149 PathTessellator::PathToFilledVertices(path, mock_writer, 1.0f);
150}

References contours, impeller::PathTessellator::CountFillStorage(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::PathTessellator::PathToFilledSegments(), impeller::PathTessellator::PathToFilledVertices(), points, and flutter::DlPathBuilder::TakePath().

◆ TEST() [362/689]

impeller::testing::TEST ( PipelineCacheDataVKTest  ,
CanCreateFromDeviceProperties   
)

Definition at line 77 of file pipeline_cache_data_vk_unittests.cc.

77 {
78 vk::PhysicalDeviceProperties props;
79 std::array<uint8_t, 16> uuid{
80 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
81 };
82 props.pipelineCacheUUID = uuid;
83 props.deviceID = 10;
84 props.vendorID = 11;
85 props.driverVersion = 12;
86 PipelineCacheHeaderVK header(props, 99);
87 EXPECT_EQ(uuid.size(), std::size(header.uuid));
88 EXPECT_EQ(props.deviceID, header.device_id);
89 EXPECT_EQ(props.vendorID, header.vendor_id);
90 EXPECT_EQ(props.driverVersion, header.driver_version);
91 for (size_t i = 0; i < uuid.size(); i++) {
92 EXPECT_EQ(header.uuid[i], uuid.at(i));
93 }
94}
An Impeller specific header prepended to all pipeline cache information that is persisted on disk....

References impeller::PipelineCacheHeaderVK::device_id, impeller::PipelineCacheHeaderVK::driver_version, i, impeller::PipelineCacheHeaderVK::uuid, and impeller::PipelineCacheHeaderVK::vendor_id.

◆ TEST() [363/689]

impeller::testing::TEST ( PipelineCacheDataVKTest  ,
CanTestHeaderCompatibility   
)

Definition at line 17 of file pipeline_cache_data_vk_unittests.cc.

17 {
18 {
21 EXPECT_EQ(a.abi, sizeof(void*));
22#ifdef FML_ARCH_CPU_64_BITS
23 EXPECT_EQ(a.abi, 8u);
24#elif FML_ARCH_CPU_32_BITS
25 EXPECT_EQ(a.abi, 4u);
26#endif
27 EXPECT_TRUE(a.IsCompatibleWith(b));
28 }
29 // Different data sizes don't matter.
30 {
33 a.data_size = b.data_size + 100u;
34 EXPECT_TRUE(a.IsCompatibleWith(b));
35 }
36 // Magic, Driver, vendor, ABI, and UUID matter.
37 {
38 PipelineCacheHeaderVK a;
39 PipelineCacheHeaderVK b;
40 b.magic = 100;
41 EXPECT_FALSE(a.IsCompatibleWith(b));
42 }
43 {
44 PipelineCacheHeaderVK a;
45 PipelineCacheHeaderVK b;
46 b.driver_version = 100;
47 EXPECT_FALSE(a.IsCompatibleWith(b));
48 }
49 {
50 PipelineCacheHeaderVK a;
51 PipelineCacheHeaderVK b;
52 b.vendor_id = 100;
53 EXPECT_FALSE(a.IsCompatibleWith(b));
54 }
55 {
56 PipelineCacheHeaderVK a;
57 PipelineCacheHeaderVK b;
58 b.device_id = 100;
59 EXPECT_FALSE(a.IsCompatibleWith(b));
60 }
61 {
62 PipelineCacheHeaderVK a;
63 PipelineCacheHeaderVK b;
64 b.abi = a.abi / 2u;
65 EXPECT_FALSE(a.IsCompatibleWith(b));
66 }
67 {
68 PipelineCacheHeaderVK a;
69 PipelineCacheHeaderVK b;
70 for (size_t i = 0; i < VK_UUID_SIZE; i++) {
71 b.uuid[i] = a.uuid[i] + 1;
72 }
73 EXPECT_FALSE(a.IsCompatibleWith(b));
74 }
75}
bool IsCompatibleWith(const PipelineCacheHeaderVK &other) const
Determines whether the specified o is compatible with.

References impeller::PipelineCacheHeaderVK::abi, impeller::PipelineCacheHeaderVK::data_size, i, impeller::PipelineCacheHeaderVK::IsCompatibleWith(), and impeller::PipelineCacheHeaderVK::uuid.

◆ TEST() [364/689]

impeller::testing::TEST ( PipelineCacheDataVKTest  ,
WritesIncompleteCacheData   
)

Definition at line 96 of file pipeline_cache_data_vk_unittests.cc.

96 {
99 auto cache = context->GetDevice().createPipelineCacheUnique({});
100 const auto& caps = CapabilitiesVK::Cast(*context->GetCapabilities());
101
102 ASSERT_TRUE(PipelineCacheDataPersist(
103 temp_dir.fd(), caps.GetPhysicalDeviceProperties(), cache.value));
104
105 std::unique_ptr<fml::FileMapping> mapping = fml::FileMapping::CreateReadOnly(
106 temp_dir.fd(), "flutter.impeller.vkcache");
107 ASSERT_TRUE(mapping);
109 ASSERT_GE(mapping->GetSize(), sizeof(header));
110 std::memcpy(&header, mapping->GetMapping(), sizeof(header));
111 ASSERT_EQ(mapping->GetSize(), sizeof(header) + header.data_size);
112}
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition mapping.cc:20
const UniqueFD & fd()
Definition file.h:147
bool PipelineCacheDataPersist(const fml::UniqueFD &cache_directory, const VkPhysicalDeviceProperties &props, const vk::UniquePipelineCache &cache)
Persist the pipeline cache to a file in the given cache directory. This function performs integrity c...

References impeller::testing::MockVulkanContextBuilder::Build(), impeller::BackendCast< CapabilitiesVK, Capabilities >::Cast(), context, fml::FileMapping::CreateReadOnly(), impeller::PipelineCacheHeaderVK::data_size, fml::ScopedTemporaryDirectory::fd(), and impeller::PipelineCacheDataPersist().

◆ TEST() [365/689]

impeller::testing::TEST ( PipelineCompileQueueGLESTest  ,
CreateReturnsNullWithNullTaskRunner   
)

Definition at line 30 of file pipeline_compile_queue_gles_unittests.cc.

30 {
31 auto queue = PipelineCompileQueueGLES::Create(nullptr);
32 EXPECT_EQ(queue, nullptr);
33}

References impeller::PipelineCompileQueueGLES::Create(), and queue.

◆ TEST() [366/689]

impeller::testing::TEST ( PipelineCompileQueueGLESTest  ,
CreateSucceedsWithValidTaskRunner   
)

Definition at line 35 of file pipeline_compile_queue_gles_unittests.cc.

35 {
36 fml::Thread thread;
37 auto queue = PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
38 EXPECT_NE(queue, nullptr);
39 thread.Join();
40}
void Join()
Definition thread.cc:168

References impeller::PipelineCompileQueueGLES::Create(), fml::Thread::Join(), and queue.

◆ TEST() [367/689]

impeller::testing::TEST ( PipelineCompileQueueGLESTest  ,
DestroyQueueWithPendingTasks   
)

Definition at line 146 of file pipeline_compile_queue_gles_unittests.cc.

146 {
147 fml::Thread thread;
148 std::atomic<int> completed_jobs{0};
149 fml::CountDownLatch latch(3);
150
151 {
152 auto queue =
153 PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
154 ASSERT_NE(queue, nullptr);
155
156 PipelineDescriptor desc1;
157 desc1.SetSampleCount(SampleCount::kCount1);
158 desc1.SetCullMode(CullMode::kNone);
159
160 PipelineDescriptor desc2;
161 desc2.SetSampleCount(SampleCount::kCount1);
162 desc2.SetCullMode(CullMode::kFrontFace);
163
164 PipelineDescriptor desc3;
165 desc3.SetSampleCount(SampleCount::kCount1);
166 desc3.SetCullMode(CullMode::kBackFace);
167
168 queue->PostJobForDescriptor(desc1, [&]() {
169 std::this_thread::sleep_for(std::chrono::milliseconds(50));
170 completed_jobs++;
171 latch.CountDown();
172 });
173
174 queue->PostJobForDescriptor(desc2, [&]() {
175 std::this_thread::sleep_for(std::chrono::milliseconds(50));
176 completed_jobs++;
177 latch.CountDown();
178 });
179
180 queue->PostJobForDescriptor(desc3, [&]() {
181 std::this_thread::sleep_for(std::chrono::milliseconds(50));
182 completed_jobs++;
183 latch.CountDown();
184 });
185
186 // Queue will be destroyed here with pending jobs.
187 // The destructor should ensure that the pending jobs are either executed
188 // or posted to the queue's thread.
189 }
190
191 // Wait for completion of the jobs.
192 latch.Wait();
193 EXPECT_EQ(completed_jobs, 3);
194
195 thread.Join();
196}
PipelineDescriptor & SetSampleCount(SampleCount samples)

References fml::CountDownLatch::CountDown(), impeller::PipelineCompileQueueGLES::Create(), fml::Thread::Join(), impeller::kBackFace, impeller::kCount1, impeller::kFrontFace, impeller::kNone, queue, impeller::PipelineDescriptor::SetCullMode(), impeller::PipelineDescriptor::SetSampleCount(), and fml::CountDownLatch::Wait().

◆ TEST() [368/689]

impeller::testing::TEST ( PipelineCompileQueueGLESTest  ,
IsProcessingResetsAfterAllJobsComplete   
)

Definition at line 124 of file pipeline_compile_queue_gles_unittests.cc.

124 {
125 fml::Thread thread;
126 auto queue = PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
127 ASSERT_NE(queue, nullptr);
128
129 fml::CountDownLatch latch(1);
130
131 queue->PostJobForDescriptor(PipelineDescriptor{},
132 [&]() { latch.CountDown(); });
133
134 latch.Wait();
135
136 fml::CountDownLatch latch2(1);
137 queue->PostJobForDescriptor(PipelineDescriptor{},
138 [&]() { latch2.CountDown(); });
139
140 latch2.Wait();
141
142 SUCCEED();
143 thread.Join();
144}

References fml::CountDownLatch::CountDown(), impeller::PipelineCompileQueueGLES::Create(), fml::Thread::Join(), queue, and fml::CountDownLatch::Wait().

◆ TEST() [369/689]

impeller::testing::TEST ( PipelineCompileQueueGLESTest  ,
OnJobAddedProcessesJobsSequentially   
)

Definition at line 50 of file pipeline_compile_queue_gles_unittests.cc.

50 {
51 fml::Thread thread;
52 auto queue = PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
53 ASSERT_NE(queue, nullptr);
54
55 std::atomic<int> completed_jobs{0};
56 fml::CountDownLatch latch(3);
57
59 desc1.SetSampleCount(SampleCount::kCount1);
60 desc1.SetCullMode(CullMode::kNone);
61
63 desc2.SetSampleCount(SampleCount::kCount1);
64 desc2.SetCullMode(CullMode::kFrontFace);
65
67 desc3.SetSampleCount(SampleCount::kCount1);
68 desc3.SetCullMode(CullMode::kBackFace);
69
70 queue->PostJobForDescriptor(desc1, [&]() {
71 std::this_thread::sleep_for(std::chrono::milliseconds(80));
72 completed_jobs++;
73 latch.CountDown();
74 });
75
76 queue->PostJobForDescriptor(desc2, [&]() {
77 std::this_thread::sleep_for(std::chrono::milliseconds(80));
78 completed_jobs++;
79 latch.CountDown();
80 });
81
82 queue->PostJobForDescriptor(desc3, [&]() {
83 std::this_thread::sleep_for(std::chrono::milliseconds(80));
84 completed_jobs++;
85 latch.CountDown();
86 });
87
88 latch.Wait();
89
90 EXPECT_EQ(completed_jobs, 3);
91
92 thread.Join();
93}

References fml::CountDownLatch::CountDown(), impeller::PipelineCompileQueueGLES::Create(), fml::Thread::Join(), impeller::kBackFace, impeller::kCount1, impeller::kFrontFace, impeller::kNone, queue, impeller::PipelineDescriptor::SetCullMode(), impeller::PipelineDescriptor::SetSampleCount(), and fml::CountDownLatch::Wait().

◆ TEST() [370/689]

impeller::testing::TEST ( PipelineCompileQueueGLESTest  ,
PostJobDoesNothingWithNullClosure   
)

Definition at line 42 of file pipeline_compile_queue_gles_unittests.cc.

42 {
43 fml::Thread thread;
44 auto queue = PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
45 ASSERT_NE(queue, nullptr);
46 queue->PostJob(nullptr);
47 thread.Join();
48}

References impeller::PipelineCompileQueueGLES::Create(), fml::Thread::Join(), and queue.

◆ TEST() [371/689]

impeller::testing::TEST ( PipelineCompileQueueGLESTest  ,
PostJobForDescriptorWithDuplicateRunsEagerly   
)

Definition at line 95 of file pipeline_compile_queue_gles_unittests.cc.

96 {
97 fml::Thread thread;
98 auto queue = PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
99 ASSERT_NE(queue, nullptr);
100
101 std::atomic<int> first_job_count{0};
102 std::atomic<int> second_job_count{0};
103 fml::CountDownLatch latch(2);
104
105 PipelineDescriptor desc;
106
107 queue->PostJobForDescriptor(desc, [&]() {
108 first_job_count++;
109 latch.CountDown();
110 });
111
112 queue->PostJobForDescriptor(desc, [&]() {
113 second_job_count++;
114 latch.CountDown();
115 });
116
117 latch.Wait();
118
119 EXPECT_EQ(first_job_count, 1);
120 EXPECT_EQ(second_job_count, 1);
121 thread.Join();
122}

References fml::CountDownLatch::CountDown(), impeller::PipelineCompileQueueGLES::Create(), fml::Thread::Join(), queue, and fml::CountDownLatch::Wait().

◆ TEST() [372/689]

impeller::testing::TEST ( PipelineCompileQueueTest  ,
AddJobReturnsFalseForDuplicateDescriptor   
)

Definition at line 42 of file pipeline_compile_queue_unittests.cc.

42 {
45 bool job1_executed = false;
46 bool job2_executed = false;
47 fml::closure job1 = [&job1_executed]() { job1_executed = true; };
48 fml::closure job2 = [&job2_executed]() { job2_executed = true; };
49
50 bool result1 = queue.AddJobForTest(desc, job1);
51 bool result2 = queue.AddJobForTest(desc, job2);
52
53 EXPECT_TRUE(result1);
54 EXPECT_FALSE(result2);
55}
std::function< void()> closure
Definition closure.h:14

References queue.

◆ TEST() [373/689]

impeller::testing::TEST ( PipelineCompileQueueTest  ,
AddJobReturnsTrueForNewDescriptor   
)

Definition at line 32 of file pipeline_compile_queue_unittests.cc.

32 {
35 bool job_executed = false;
36 fml::closure job = [&job_executed]() { job_executed = true; };
37
38 bool result = queue.AddJobForTest(desc, job);
39 EXPECT_TRUE(result);
40}

References queue.

◆ TEST() [374/689]

impeller::testing::TEST ( PipelineCompileQueueTest  ,
FinishAllJobsDrainsQueue   
)

Definition at line 81 of file pipeline_compile_queue_unittests.cc.

81 {
82 auto queue = std::make_shared<TestPipelineCompileQueue>();
84 bool job_executed = false;
85 fml::closure job = [&job_executed]() { job_executed = true; };
86
87 queue->AddJobForTest(desc, job);
88 EXPECT_TRUE(queue->HasPendingJobsForTest());
89
90 queue.reset();
91
92 EXPECT_TRUE(job_executed);
93}

References queue.

◆ TEST() [375/689]

impeller::testing::TEST ( PipelineCompileQueueTest  ,
HasPendingJobsReturnsCorrectState   
)

Definition at line 57 of file pipeline_compile_queue_unittests.cc.

57 {
60 fml::closure job = []() {};
61
62 EXPECT_FALSE(queue.HasPendingJobsForTest());
63
64 queue.AddJobForTest(desc, job);
65 EXPECT_TRUE(queue.HasPendingJobsForTest());
66}

References queue.

◆ TEST() [376/689]

impeller::testing::TEST ( PipelineCompileQueueTest  ,
PerformJobEagerlyExecutesJob   
)

Definition at line 68 of file pipeline_compile_queue_unittests.cc.

68 {
71 bool job_executed = false;
72 fml::closure job = [&job_executed]() { job_executed = true; };
73
74 queue.AddJobForTest(desc, job);
75 queue.PerformJobEagerly(desc);
76
77 EXPECT_TRUE(job_executed);
78 EXPECT_FALSE(queue.HasPendingJobsForTest());
79}

References queue.

◆ TEST() [377/689]

impeller::testing::TEST ( PipelineCompileQueueVulkanTest  ,
CreateSucceedsWithValidTaskRunner   
)

Definition at line 20 of file pipeline_compile_queue_vulkan_unittests.cc.

20 {
22 auto queue = PipelineCompileQueueVulkan::Create(loop->GetTaskRunner());
23 EXPECT_NE(queue, nullptr);
24}
static std::shared_ptr< ConcurrentMessageLoop > Create(size_t worker_count=std::thread::hardware_concurrency())

References fml::ConcurrentMessageLoop::Create(), impeller::PipelineCompileQueueVulkan::Create(), and queue.

◆ TEST() [378/689]

impeller::testing::TEST ( PipelineCompileQueueVulkanTest  ,
MultipleJobsCompleteSuccessfully   
)

Definition at line 121 of file pipeline_compile_queue_vulkan_unittests.cc.

121 {
123 auto queue = PipelineCompileQueueVulkan::Create(loop->GetTaskRunner());
124 ASSERT_NE(queue, nullptr);
125
126 std::atomic<int> completed_jobs{0};
127 fml::CountDownLatch latch(5);
128
129 PipelineDescriptor desc1;
130 desc1.SetSampleCount(SampleCount::kCount1);
131 desc1.SetCullMode(CullMode::kNone);
132
133 PipelineDescriptor desc2;
134 desc2.SetSampleCount(SampleCount::kCount1);
135 desc2.SetCullMode(CullMode::kFrontFace);
136
137 PipelineDescriptor desc3;
138 desc3.SetSampleCount(SampleCount::kCount1);
139 desc3.SetCullMode(CullMode::kBackFace);
140
141 PipelineDescriptor desc4;
142 desc4.SetSampleCount(SampleCount::kCount4);
143 desc4.SetCullMode(CullMode::kNone);
144
145 PipelineDescriptor desc5;
146 desc5.SetSampleCount(SampleCount::kCount4);
147 desc5.SetCullMode(CullMode::kFrontFace);
148
149 // Post 5 jobs with distinct descriptors
150 queue->PostJobForDescriptor(desc1, [&]() {
151 completed_jobs++;
152 latch.CountDown();
153 });
154
155 queue->PostJobForDescriptor(desc2, [&]() {
156 completed_jobs++;
157 latch.CountDown();
158 });
159
160 queue->PostJobForDescriptor(desc3, [&]() {
161 completed_jobs++;
162 latch.CountDown();
163 });
164
165 queue->PostJobForDescriptor(desc4, [&]() {
166 completed_jobs++;
167 latch.CountDown();
168 });
169
170 queue->PostJobForDescriptor(desc5, [&]() {
171 completed_jobs++;
172 latch.CountDown();
173 });
174
175 latch.Wait();
176
177 EXPECT_EQ(completed_jobs, 5);
178}

References fml::CountDownLatch::CountDown(), fml::ConcurrentMessageLoop::Create(), impeller::PipelineCompileQueueVulkan::Create(), impeller::kBackFace, impeller::kCount1, impeller::kCount4, impeller::kFrontFace, impeller::kNone, queue, impeller::PipelineDescriptor::SetCullMode(), impeller::PipelineDescriptor::SetSampleCount(), and fml::CountDownLatch::Wait().

◆ TEST() [379/689]

impeller::testing::TEST ( PipelineCompileQueueVulkanTest  ,
OnJobAddedProcessesJobsInParallel   
)

Definition at line 34 of file pipeline_compile_queue_vulkan_unittests.cc.

34 {
36 auto queue = PipelineCompileQueueVulkan::Create(loop->GetTaskRunner());
37 ASSERT_NE(queue, nullptr);
38
39 std::atomic<int> concurrent_jobs{0};
40 std::atomic<int> max_concurrent{0};
41 fml::CountDownLatch latch(3);
42
43 PipelineDescriptor desc1;
44 desc1.SetSampleCount(SampleCount::kCount1);
45 desc1.SetCullMode(CullMode::kNone);
46
47 PipelineDescriptor desc2;
48 desc2.SetSampleCount(SampleCount::kCount1);
49 desc2.SetCullMode(CullMode::kFrontFace);
50
51 PipelineDescriptor desc3;
52 desc3.SetSampleCount(SampleCount::kCount1);
53 desc3.SetCullMode(CullMode::kBackFace);
54
55 queue->PostJobForDescriptor(desc1, [&]() {
56 int current = ++concurrent_jobs;
57 int prev_max = max_concurrent.load();
58 while (current > prev_max &&
59 !max_concurrent.compare_exchange_weak(prev_max, current)) {
60 }
61 std::this_thread::sleep_for(std::chrono::milliseconds(10));
62 concurrent_jobs--;
63 latch.CountDown();
64 });
65
66 queue->PostJobForDescriptor(desc2, [&]() {
67 int current = ++concurrent_jobs;
68 int prev_max = max_concurrent.load();
69 while (current > prev_max &&
70 !max_concurrent.compare_exchange_weak(prev_max, current)) {
71 }
72 std::this_thread::sleep_for(std::chrono::milliseconds(10));
73 concurrent_jobs--;
74 latch.CountDown();
75 });
76
77 queue->PostJobForDescriptor(desc3, [&]() {
78 int current = ++concurrent_jobs;
79 int prev_max = max_concurrent.load();
80 while (current > prev_max &&
81 !max_concurrent.compare_exchange_weak(prev_max, current)) {
82 }
83 std::this_thread::sleep_for(std::chrono::milliseconds(10));
84 concurrent_jobs--;
85 latch.CountDown();
86 });
87
88 latch.Wait();
89
90 EXPECT_GE(max_concurrent.load(), 1);
91}

References fml::CountDownLatch::CountDown(), fml::ConcurrentMessageLoop::Create(), impeller::PipelineCompileQueueVulkan::Create(), impeller::kBackFace, impeller::kCount1, impeller::kFrontFace, impeller::kNone, queue, impeller::PipelineDescriptor::SetCullMode(), impeller::PipelineDescriptor::SetSampleCount(), and fml::CountDownLatch::Wait().

◆ TEST() [380/689]

impeller::testing::TEST ( PipelineCompileQueueVulkanTest  ,
PostJobDoesNothingWithNullClosure   
)

Definition at line 26 of file pipeline_compile_queue_vulkan_unittests.cc.

26 {
28 auto queue = PipelineCompileQueueVulkan::Create(loop->GetTaskRunner());
29 ASSERT_NE(queue, nullptr);
30
31 queue->PostJob(nullptr);
32}

References fml::ConcurrentMessageLoop::Create(), impeller::PipelineCompileQueueVulkan::Create(), and queue.

◆ TEST() [381/689]

impeller::testing::TEST ( PipelineCompileQueueVulkanTest  ,
PostJobForDescriptorWithDuplicateRunsEagerly   
)

Definition at line 93 of file pipeline_compile_queue_vulkan_unittests.cc.

94 {
96 auto queue = PipelineCompileQueueVulkan::Create(loop->GetTaskRunner());
97 ASSERT_NE(queue, nullptr);
98
99 std::atomic<int> first_job_count{0};
100 std::atomic<int> second_job_count{0};
101 fml::CountDownLatch latch(2);
102
103 PipelineDescriptor desc;
104
105 queue->PostJobForDescriptor(desc, [&]() {
106 first_job_count++;
107 latch.CountDown();
108 });
109
110 queue->PostJobForDescriptor(desc, [&]() {
111 second_job_count++;
112 latch.CountDown();
113 });
114
115 latch.Wait();
116
117 EXPECT_EQ(first_job_count, 1);
118 EXPECT_EQ(second_job_count, 1);
119}

References fml::CountDownLatch::CountDown(), fml::ConcurrentMessageLoop::Create(), impeller::PipelineCompileQueueVulkan::Create(), queue, and fml::CountDownLatch::Wait().

◆ TEST() [382/689]

impeller::testing::TEST ( PipelineDescriptorTest  ,
PrimitiveTypeHashEquality   
)

Definition at line 13 of file pipeline_descriptor_unittests.cc.

13 {
16
17 ASSERT_TRUE(descA.IsEqual(descB));
18 ASSERT_EQ(descA.GetHash(), descB.GetHash());
19
20 descA.SetPrimitiveType(PrimitiveType::kTriangleStrip);
21
22 ASSERT_FALSE(descA.IsEqual(descB));
23 ASSERT_NE(descA.GetHash(), descB.GetHash());
24}
std::size_t GetHash() const override
bool IsEqual(const PipelineDescriptor &other) const override
void SetPrimitiveType(PrimitiveType type)

References impeller::PipelineDescriptor::GetHash(), impeller::PipelineDescriptor::IsEqual(), impeller::kTriangleStrip, and impeller::PipelineDescriptor::SetPrimitiveType().

◆ TEST() [383/689]

impeller::testing::TEST ( PointTest  ,
CrossProductThreePoints   
)

Definition at line 357 of file point_unittests.cc.

357 {
358 // Colinear
359 EXPECT_FLOAT_EQ(Point::Cross(Point(-1, 0), Point(0, 0), Point(1, 0)), 0);
360 EXPECT_FLOAT_EQ(Point::Cross(Point(1, 0), Point(0, 0), Point(-1, 0)), 0);
361
362 // Right turn
363 EXPECT_FLOAT_EQ(Point::Cross(Point(-1, 0), Point(0, 0), Point(0, 1)), 1);
364 EXPECT_FLOAT_EQ(Point::Cross(Point(-2, 0), Point(0, 0), Point(0, 2)), 4);
365
366 // Left turn
367 EXPECT_FLOAT_EQ(Point::Cross(Point(-1, 0), Point(0, 0), Point(0, -1)), -1);
368 EXPECT_FLOAT_EQ(Point::Cross(Point(-2, 0), Point(0, 0), Point(0, -2)), -4);
369
370 // Convenient values for a less obvious left turn.
371 // p1 - p0 == (0, 0) - (3, -4) == (-3, 4)
372 // p2 - p0 == (1, 2) - (3, -4) == (-2, 6)
373 // product of the magnitude of the 2 legs and the sin of their angle
374 // (||(-3, 4)||) * (||(-2, 6)||) * sin(angle)
375 // 5 * sqrt(40) * sin(angle)
376 // angle = arcsin(4 / 5) - arcsin(6 / sqrt(40)) ~= -18.4349
377 // sin(angle) ~= -0.316227766
378 // 5 * sqrt(40) * sin(angle) == -10
379 // The math is cleaner with the cross product:
380 // (-3 * 6) - (-2 * 4) == -18 - -8 == -10
381 EXPECT_FLOAT_EQ(Point::Cross(Point(3, -4), Point(0, 0), Point(1, 2)), -10);
382}

References impeller::TPoint< Scalar >::Cross().

◆ TEST() [384/689]

impeller::testing::TEST ( PointTest  ,
Distance   
)

Definition at line 37 of file point_unittests.cc.

37 {
38 for (int j = 0; j < 21; j++) {
39 for (int i = 0; i < 21; i++) {
40 {
41 Scalar d = i - j;
42
43 EXPECT_EQ(Point(i, 0).GetDistanceSquared(Point(j, 0)), d * d)
44 << "i: " << i << ", j: " << j;
45 EXPECT_EQ(Point(0, i).GetDistanceSquared(Point(0, j)), d * d)
46 << "i: " << i << ", j: " << j;
47 EXPECT_EQ(Point(j, 0).GetDistanceSquared(Point(i, 0)), d * d)
48 << "i: " << i << ", j: " << j;
49 EXPECT_EQ(Point(0, j).GetDistanceSquared(Point(0, i)), d * d)
50 << "i: " << i << ", j: " << j;
51
52 EXPECT_EQ(Point(i, 0).GetDistance(Point(j, 0)), std::abs(d))
53 << "i: " << i << ", j: " << j;
54 EXPECT_EQ(Point(0, i).GetDistance(Point(0, j)), std::abs(d))
55 << "i: " << i << ", j: " << j;
56 EXPECT_EQ(Point(j, 0).GetDistance(Point(i, 0)), std::abs(d))
57 << "i: " << i << ", j: " << j;
58 EXPECT_EQ(Point(0, j).GetDistance(Point(0, i)), std::abs(d))
59 << "i: " << i << ", j: " << j;
60 }
61
62 {
63 Scalar d_squared = i * i + j * j;
64
65 EXPECT_EQ(Point(i, 0).GetDistanceSquared(Point(0, j)), d_squared)
66 << "i: " << i << ", j: " << j;
67 EXPECT_EQ(Point(-i, 0).GetDistanceSquared(Point(0, j)), d_squared)
68 << "i: " << i << ", j: " << j;
69 EXPECT_EQ(Point(i, 0).GetDistanceSquared(Point(0, -j)), d_squared)
70 << "i: " << i << ", j: " << j;
71 EXPECT_EQ(Point(-i, 0).GetDistanceSquared(Point(0, -j)), d_squared)
72 << "i: " << i << ", j: " << j;
73
74 Scalar d = std::sqrt(d_squared);
75
76 EXPECT_FLOAT_EQ(Point(i, 0).GetDistance(Point(0, j)), d)
77 << "i: " << i << ", j: " << j;
78 EXPECT_FLOAT_EQ(Point(-i, 0).GetDistance(Point(0, j)), d)
79 << "i: " << i << ", j: " << j;
80 EXPECT_FLOAT_EQ(Point(i, 0).GetDistance(Point(0, -j)), d)
81 << "i: " << i << ", j: " << j;
82 EXPECT_FLOAT_EQ(Point(-i, 0).GetDistance(Point(0, -j)), d)
83 << "i: " << i << ", j: " << j;
84 }
85 }
86 }
87}

References d, and i.

◆ TEST() [385/689]

impeller::testing::TEST ( PointTest  ,
Length   
)

Definition at line 13 of file point_unittests.cc.

13 {
14 for (int i = 0; i < 21; i++) {
15 EXPECT_EQ(Point(i, 0).GetLengthSquared(), i * i) << "i: " << i;
16 EXPECT_EQ(Point(0, i).GetLengthSquared(), i * i) << "i: " << i;
17 EXPECT_EQ(Point(-i, 0).GetLengthSquared(), i * i) << "i: " << i;
18 EXPECT_EQ(Point(0, -i).GetLengthSquared(), i * i) << "i: " << i;
19
20 EXPECT_EQ(Point(i, 0).GetLength(), i) << "i: " << i;
21 EXPECT_EQ(Point(0, i).GetLength(), i) << "i: " << i;
22 EXPECT_EQ(Point(-i, 0).GetLength(), i) << "i: " << i;
23 EXPECT_EQ(Point(0, -i).GetLength(), i) << "i: " << i;
24
25 EXPECT_EQ(Point(i, i).GetLengthSquared(), 2 * i * i) << "i: " << i;
26 EXPECT_EQ(Point(-i, i).GetLengthSquared(), 2 * i * i) << "i: " << i;
27 EXPECT_EQ(Point(i, -i).GetLengthSquared(), 2 * i * i) << "i: " << i;
28 EXPECT_EQ(Point(-i, -i).GetLengthSquared(), 2 * i * i) << "i: " << i;
29
30 EXPECT_FLOAT_EQ(Point(i, i).GetLength(), kSqrt2 * i) << "i: " << i;
31 EXPECT_FLOAT_EQ(Point(-i, i).GetLength(), kSqrt2 * i) << "i: " << i;
32 EXPECT_FLOAT_EQ(Point(i, -i).GetLength(), kSqrt2 * i) << "i: " << i;
33 EXPECT_FLOAT_EQ(Point(-i, -i).GetLength(), kSqrt2 * i) << "i: " << i;
34 }
35}

References i, and impeller::kSqrt2.

◆ TEST() [386/689]

impeller::testing::TEST ( PointTest  ,
PerpendicularLeft   
)

Definition at line 89 of file point_unittests.cc.

89 {
90 EXPECT_EQ(Point(1, 0).PerpendicularLeft(), Point(0, -1));
91 EXPECT_EQ(Point(0, 1).PerpendicularLeft(), Point(1, 0));
92 EXPECT_EQ(Point(-1, 0).PerpendicularLeft(), Point(0, 1));
93 EXPECT_EQ(Point(0, -1).PerpendicularLeft(), Point(-1, 0));
94
95 EXPECT_EQ(Point(1, 1).PerpendicularLeft(), Point(1, -1));
96 EXPECT_EQ(Point(-1, 1).PerpendicularLeft(), Point(1, 1));
97 EXPECT_EQ(Point(-1, -1).PerpendicularLeft(), Point(-1, 1));
98 EXPECT_EQ(Point(1, -1).PerpendicularLeft(), Point(-1, -1));
99}

◆ TEST() [387/689]

impeller::testing::TEST ( PointTest  ,
PerpendicularRight   
)

Definition at line 101 of file point_unittests.cc.

101 {
102 EXPECT_EQ(Point(1, 0).PerpendicularRight(), Point(0, 1));
103 EXPECT_EQ(Point(0, 1).PerpendicularRight(), Point(-1, 0));
104 EXPECT_EQ(Point(-1, 0).PerpendicularRight(), Point(0, -1));
105 EXPECT_EQ(Point(0, -1).PerpendicularRight(), Point(1, 0));
106
107 EXPECT_EQ(Point(1, 1).PerpendicularRight(), Point(-1, 1));
108 EXPECT_EQ(Point(-1, 1).PerpendicularRight(), Point(-1, -1));
109 EXPECT_EQ(Point(-1, -1).PerpendicularRight(), Point(1, -1));
110 EXPECT_EQ(Point(1, -1).PerpendicularRight(), Point(1, 1));
111}

◆ TEST() [388/689]

impeller::testing::TEST ( PointTest  ,
PointToSegment   
)

Definition at line 137 of file point_unittests.cc.

137 {
138 // Horizontal segment and points to the left of it on the same line.
139 TestPointToSegmentGroup(
140 // Segment
141 {10, 10}, {20, 10},
142 // Starting point, delta, count ({0,10} through {10,10})
143 {0, 10}, {1, 0}, 11,
144 // Distance computation
145 [](Point p) {
146 Scalar d = 10 - p.x;
147 return std::make_pair(d, d * d);
148 });
149
150 // Horizontal segment and points on the segment.
151 TestPointToSegmentGroup(
152 // Segment
153 {10, 10}, {20, 10},
154 // Starting point, delta, count ({11,10} through {19, 10})
155 {11, 10}, {1, 0}, 9,
156 // Distance computation
157 [](Point p) { //
158 return std::make_pair(0.0f, 0.0f);
159 });
160
161 // Horizontal segment and points to the right of it on the same line.
162 TestPointToSegmentGroup(
163 // Segment
164 {10, 10}, {20, 10},
165 // Starting point, delta, count ({20,10} through {30,10})
166 {20, 10}, {1, 0}, 11,
167 // Distance computation
168 [](Point p) {
169 Scalar d = p.x - 20;
170 return std::make_pair(d, d * d);
171 });
172
173 // Vertical segment and points above the top of it on the same line.
174 TestPointToSegmentGroup(
175 // Segment
176 {10, 10}, {10, 20},
177 // Starting point, delta, count ({10,0} through {10,10})
178 {10, 0}, {0, 1}, 11,
179 // Distance computation
180 [](Point p) {
181 Scalar d = 10 - p.y;
182 return std::make_pair(d, d * d);
183 });
184
185 // Vertical segment and points on the segment.
186 TestPointToSegmentGroup(
187 // Segment
188 {10, 10}, {10, 20},
189 // Starting point, delta, count ({10,11} through {10, 19})
190 {10, 11}, {0, 1}, 9,
191 // Distance computation
192 [](Point p) { //
193 return std::make_pair(0.0f, 0.0f);
194 });
195
196 // Vertical segment and points below the bottom of it on the same line.
197 TestPointToSegmentGroup(
198 // Segment
199 {10, 10}, {10, 20},
200 // Starting point, delta, count ({10,20} through {10,30})
201 {10, 20}, {0, 1}, 11,
202 // Distance computation
203 [](Point p) {
204 Scalar d = p.y - 20;
205 return std::make_pair(d, d * d);
206 });
207
208 // Horizontal segment and points 5 pixels above and to the left of it
209 // on the same line.
210 TestPointToSegmentGroup(
211 // Segment
212 {10, 10}, {20, 10},
213 // Starting point, delta, count ({0,5} through {10,5})
214 {0, 5}, {1, 0}, 11,
215 // Distance computation
216 [](Point p) {
217 Scalar d_sq = (10 - p.x) * (10 - p.x) + 25;
218 return std::make_pair(std::sqrt(d_sq), d_sq);
219 });
220
221 // Horizontal segment and points 5 pixels directly above the segment.
222 TestPointToSegmentGroup(
223 // Segment
224 {10, 10}, {20, 10},
225 // Starting point, delta, count ({11,5} through {19, 5})
226 {11, 5}, {1, 0}, 9,
227 // Distance computation
228 [](Point p) { //
229 return std::make_pair(5.0f, 25.0f);
230 });
231
232 // Horizontal segment and points 5 pixels above and to the right of it
233 // on the same line.
234 TestPointToSegmentGroup(
235 // Segment
236 {10, 10}, {20, 10},
237 // Starting point, delta, count ({20,5} through {30,5})
238 {20, 5}, {1, 0}, 11,
239 // Distance computation
240 [](Point p) {
241 Scalar d_sq = (p.x - 20) * (p.x - 20) + 25;
242 return std::make_pair(std::sqrt(d_sq), d_sq);
243 });
244
245 // Vertical segment and points 5 pixels to the left and above the segment
246 // on the same line.
247 TestPointToSegmentGroup(
248 // Segment
249 {10, 10}, {10, 20},
250 // Starting point, delta, count ({5,0} through {5,10})
251 {5, 0}, {0, 1}, 11,
252 // Distance computation
253 [](Point p) {
254 Scalar d_sq = 25 + (10 - p.y) * (10 - p.y);
255 return std::make_pair(std::sqrt(d_sq), d_sq);
256 });
257
258 // Vertical segment and points 5 pixels directly to the left of the segment.
259 TestPointToSegmentGroup(
260 // Segment
261 {10, 10}, {10, 20},
262 // Starting point, delta, count ({5,11} through {5,19,})
263 {5, 11}, {0, 1}, 9,
264 // Distance computation
265 [](Point p) { //
266 return std::make_pair(5.0f, 25.0f);
267 });
268
269 // Vertical segment and points 5 pixels to the left and below the segment
270 // on the same line.
271 TestPointToSegmentGroup(
272 // Segment
273 {10, 10}, {10, 20},
274 // Starting point, delta, count ({20,5} through {30,5})
275 {5, 20}, {0, 1}, 11,
276 // Distance computation
277 [](Point p) {
278 Scalar d_sq = 25 + (p.y - 20) * (p.y - 20);
279 return std::make_pair(std::sqrt(d_sq), d_sq);
280 });
281
282 // Diagonal segment and points up and to the right of the top of the segment.
283 TestPointToSegmentGroup(
284 // Segment
285 {10, 10}, {20, 20},
286 // Starting point, delta, count ({5,-5} through {15,5})
287 {5, -5}, {1, 1}, 11,
288 // Distance computation
289 [](Point p) {
290 Scalar d_sq = (p.x - 10) * (p.x - 10) + (p.y - 10) * (p.y - 10);
291 return std::make_pair(std::sqrt(d_sq), d_sq);
292 });
293
294 // Diagonal segment and points up and to the right of the segment itself.
295 TestPointToSegmentGroup(
296 // Segment
297 {10, 10}, {20, 20},
298 // Starting point, delta, count ({15,5} through {24,14})
299 {15, 5}, {1, 1}, 9,
300 // Distance computation
301 [](Point p) {
302 Scalar d_sq = 50.0f;
303 return std::make_pair(std::sqrt(d_sq), d_sq);
304 });
305
306 // Diagonal segment and points up and to the right of the bottom of the
307 // segment.
308 TestPointToSegmentGroup(
309 // Segment
310 {10, 10}, {20, 20},
311 // Starting point, delta, count ({25,15} through {35,25})
312 {25, 15}, {1, 1}, 11,
313 // Distance computation
314 [](Point p) {
315 Scalar d_sq = (p.x - 20) * (p.x - 20) + (p.y - 20) * (p.y - 20);
316 return std::make_pair(std::sqrt(d_sq), d_sq);
317 });
318
319 // Diagonal segment and points down and to the left of the top of the segment.
320 TestPointToSegmentGroup(
321 // Segment
322 {10, 10}, {20, 20},
323 // Starting point, delta, count ({-5,5} through {5,15})
324 {-5, 5}, {1, 1}, 11,
325 // Distance computation
326 [](Point p) {
327 Scalar d_sq = (p.x - 10) * (p.x - 10) + (p.y - 10) * (p.y - 10);
328 return std::make_pair(std::sqrt(d_sq), d_sq);
329 });
330
331 // Diagonal segment and points down and to the left of the segment itself.
332 TestPointToSegmentGroup(
333 // Segment
334 {10, 10}, {20, 20},
335 // Starting point, delta, count ({5,15} through {14,24})
336 {5, 15}, {1, 1}, 9,
337 // Distance computation
338 [](Point p) {
339 Scalar d_sq = 50.0f;
340 return std::make_pair(std::sqrt(d_sq), d_sq);
341 });
342
343 // Diagonal segment and points down and to the left of the bottom of the
344 // segment.
345 TestPointToSegmentGroup(
346 // Segment
347 {10, 10}, {20, 20},
348 // Starting point, delta, count ({15,25} through {25,35})
349 {15, 25}, {1, 1}, 11,
350 // Distance computation
351 [](Point p) {
352 Scalar d_sq = (p.x - 20) * (p.x - 20) + (p.y - 20) * (p.y - 20);
353 return std::make_pair(std::sqrt(d_sq), d_sq);
354 });
355}

References d.

◆ TEST() [389/689]

impeller::testing::TEST ( PoolTest  ,
Overload   
)

Definition at line 47 of file pool_unittests.cc.

47 {
48 Pool<Foobar> pool(1'000);
49 {
50 std::vector<std::shared_ptr<Foobar>> values;
51 values.reserve(20);
52 for (int i = 0; i < 20; i++) {
53 values.push_back(pool.Grab());
54 }
55 for (const auto& value : values) {
56 value->SetSize(100);
57 pool.Recycle(value);
58 }
59 }
60 EXPECT_EQ(pool.GetSize(), 1'000u);
61}
A thread-safe pool with a limited byte size.
Definition pool.h:17

References impeller::Pool< T >::GetSize(), impeller::Pool< T >::Grab(), i, impeller::Pool< T >::Recycle(), and value.

◆ TEST() [390/689]

impeller::testing::TEST ( PoolTest  ,
Simple   
)

Definition at line 33 of file pool_unittests.cc.

33 {
34 Pool<Foobar> pool(1'000);
35 {
36 auto grabbed = pool.Grab();
37 grabbed->SetSize(123);
38 pool.Recycle(grabbed);
39 EXPECT_EQ(pool.GetSize(), 123u);
40 }
41 auto grabbed = pool.Grab();
42 EXPECT_EQ(grabbed->GetSize(), 123u);
43 EXPECT_TRUE(grabbed->GetIsReset());
44 EXPECT_EQ(pool.GetSize(), 0u);
45}

References impeller::Pool< T >::GetSize(), impeller::Pool< T >::Grab(), and impeller::Pool< T >::Recycle().

◆ TEST() [391/689]

impeller::testing::TEST ( ProcTableGLES  ,
CheckFrameBufferStatusDebugOnly   
)

Definition at line 39 of file proc_table_gles_unittests.cc.

39 {
40 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
41#ifdef IMPELLER_DEBUG
42 EXPECT_CALL(*mock_gles_impl, CheckFramebufferStatus(_)).Times(1);
43#else
44 EXPECT_CALL(*mock_gles_impl, CheckFramebufferStatus(_)).Times(0);
45#endif
46 auto mock_gles = MockGLES::Init(std::move(mock_gles_impl));
47 mock_gles->GetProcTable().CheckFramebufferStatusDebug(0);
48}

References impeller::testing::MockGLES::Init().

◆ TEST() [392/689]

impeller::testing::TEST ( ProcTableGLES  ,
GLES2VertexAttribDivisor   
)

Definition at line 50 of file proc_table_gles_unittests.cc.

50 {
51 const auto extensions = std::vector<const char*>{"GL_EXT_instanced_arrays"};
52 auto mock_gles = MockGLES::Init(extensions);
53 EXPECT_TRUE(mock_gles->GetProcTable().VertexAttribDivisorEXT.IsAvailable());
54}

References impeller::testing::MockGLES::Init().

◆ TEST() [393/689]

impeller::testing::TEST ( ProcTableGLES  ,
GLES3VertexAttribDivisor   
)

Definition at line 56 of file proc_table_gles_unittests.cc.

56 {
57 auto mock_gles = MockGLES::Init();
58 EXPECT_FALSE(mock_gles->GetProcTable().VertexAttribDivisorEXT.IsAvailable());
59 EXPECT_TRUE(mock_gles->GetProcTable().VertexAttribDivisor.IsAvailable());
60}

References impeller::testing::MockGLES::Init().

◆ TEST() [394/689]

impeller::testing::TEST ( ProcTableGLES  ,
ResolvesCorrectClearDepthProcOnDesktopGL   
)

Definition at line 31 of file proc_table_gles_unittests.cc.

31 {
32 auto mock_gles = MockGLES::Init(std::nullopt, "OpenGL 4.0");
33 EXPECT_FALSE(mock_gles->GetProcTable().GetDescription()->IsES());
34
37}
#define FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(PROC)
#define FOR_EACH_IMPELLER_ES_ONLY_PROC(PROC)
#define EXPECT_AVAILABLE(proc_ivar)
#define EXPECT_UNAVAILABLE(proc_ivar)

References EXPECT_AVAILABLE, EXPECT_UNAVAILABLE, FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC, FOR_EACH_IMPELLER_ES_ONLY_PROC, and impeller::testing::MockGLES::Init().

◆ TEST() [395/689]

impeller::testing::TEST ( ProcTableGLES  ,
ResolvesCorrectClearDepthProcOnES   
)

Definition at line 23 of file proc_table_gles_unittests.cc.

23 {
24 auto mock_gles = MockGLES::Init(std::nullopt, "OpenGL ES 3.0");
25 EXPECT_TRUE(mock_gles->GetProcTable().GetDescription()->IsES());
26
29}

References EXPECT_AVAILABLE, EXPECT_UNAVAILABLE, FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC, FOR_EACH_IMPELLER_ES_ONLY_PROC, and impeller::testing::MockGLES::Init().

◆ TEST() [396/689]

impeller::testing::TEST ( ReactorGLES  ,
CanAttachCleanupCallbacksToHandles   
)

Definition at line 30 of file reactor_unittests.cc.

30 {
31 auto mock_gles = MockGLES::Init();
33 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
34 auto worker = std::make_shared<TestWorker>();
35 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
36 reactor->AddWorker(worker);
37
38 int value = 0;
39 auto handle = reactor->CreateHandle(HandleType::kTexture, 1123);
40 auto added =
41 reactor->RegisterCleanupCallback(handle, [&value]() { value++; });
42
43 EXPECT_TRUE(added);
44 EXPECT_TRUE(reactor->React());
45
46 reactor->CollectHandle(handle);
47 EXPECT_TRUE(reactor->AddOperation([](const ReactorGLES& reactor) {}));
48 EXPECT_TRUE(reactor->React());
49 EXPECT_EQ(value, 1);
50}

References impeller::testing::MockGLES::Init(), kMockResolverGLES, impeller::kTexture, reactor, and value.

◆ TEST() [397/689]

impeller::testing::TEST ( ReactorGLES  ,
CanDeferOperations   
)

Definition at line 159 of file reactor_unittests.cc.

159 {
160 auto mock_gles = MockGLES::Init();
162 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
163 auto worker = std::make_shared<TestWorker>();
164 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
165 reactor->AddWorker(worker);
166
167 // Add operation executes tasks as long as the reactor can run tasks on
168 // the current thread.
169 bool did_run = false;
170 EXPECT_TRUE(
171 reactor->AddOperation([&](const ReactorGLES&) { did_run = true; }));
172 EXPECT_TRUE(did_run);
173
174 //...unless defer=true is specified, which only enqueues in the reactor.
175 did_run = false;
176 EXPECT_TRUE(reactor->AddOperation([&](const ReactorGLES&) { did_run = true; },
177 /*defer=*/true));
178 EXPECT_FALSE(did_run);
179 EXPECT_TRUE(reactor->React());
180 EXPECT_TRUE(did_run);
181}

References impeller::testing::MockGLES::Init(), kMockResolverGLES, and reactor.

◆ TEST() [398/689]

impeller::testing::TEST ( ReactorGLES  ,
DeletesHandlesDuringShutdown   
)

Definition at line 52 of file reactor_unittests.cc.

52 {
53 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
54
55 EXPECT_CALL(*mock_gles_impl, GenTextures(1, _))
56 .WillOnce([](GLsizei size, GLuint* queries) { queries[0] = 1234; });
57 EXPECT_CALL(*mock_gles_impl, DeleteTextures(1, ::testing::Pointee(1234)))
58 .Times(1);
59
60 std::shared_ptr<MockGLES> mock_gles =
61 MockGLES::Init(std::move(mock_gles_impl));
62 ProcTableGLES::Resolver resolver = kMockResolverGLES;
63 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
64 auto worker = std::make_shared<TestWorker>();
65 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
66 reactor->AddWorker(worker);
67 reactor->CreateHandle(HandleType::kTexture);
68 reactor.reset();
69}

References impeller::testing::MockGLES::Init(), kMockResolverGLES, impeller::kTexture, reactor, and flutter::size.

◆ TEST() [399/689]

impeller::testing::TEST ( ReactorGLES  ,
FramebufferDeletedOnOwnerThread   
)

Definition at line 183 of file reactor_unittests.cc.

183 {
184 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
185
186 EXPECT_CALL(*mock_gles_impl, GenFramebuffers(1, _))
187 .WillOnce([](GLsizei size, GLuint* queries) { queries[0] = 1234; });
188
189 std::shared_ptr<MockGLES> mock_gles =
190 MockGLES::Init(std::move(mock_gles_impl));
191 ProcTableGLES::Resolver resolver = kMockResolverGLES;
192 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
193 auto worker = std::make_shared<TestWorker>();
194 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
195 reactor->AddWorker(worker);
196
197 HandleGLES handle = reactor->CreateHandle(HandleType::kFrameBuffer);
198
199 std::thread::id cleanup_thread;
200 reactor->RegisterCleanupCallback(
201 handle, [&]() { cleanup_thread = std::this_thread::get_id(); });
202
203 reactor->CollectHandle(handle);
204
205 std::thread thread([&] {
206 EXPECT_TRUE(reactor->AddOperation([](const ReactorGLES& reactor) {}));
207 EXPECT_TRUE(reactor->React());
208 });
209 thread.join();
210
211 EXPECT_EQ(cleanup_thread, std::thread::id());
212
213 EXPECT_TRUE(reactor->AddOperation([](const ReactorGLES& reactor) {}));
214 EXPECT_TRUE(reactor->React());
215 EXPECT_EQ(cleanup_thread, std::this_thread::get_id());
216}
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
Definition handle_gles.h:42

References impeller::testing::MockGLES::Init(), impeller::kFrameBuffer, kMockResolverGLES, reactor, and flutter::size.

◆ TEST() [400/689]

impeller::testing::TEST ( ReactorGLES  ,
NameUntrackedHandle   
)

Definition at line 99 of file reactor_unittests.cc.

99 {
100 auto mock_gles_impl = std::make_unique<NiceMock<MockGLESImpl>>();
101 NiceMock<MockGLESImpl>* raw_mock_gles = mock_gles_impl.get();
102
103 std::shared_ptr<MockGLES> mock_gles =
104 MockGLES::Init(std::move(mock_gles_impl));
106 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
107
108 if (!proc_table->SupportsDebugLabels()) {
109 GTEST_SKIP() << "This device doesn't support labelling.";
110 }
111
112 EXPECT_CALL(*raw_mock_gles, GenTextures(1, _))
113 .WillOnce([](GLsizei size, GLuint* queries) { queries[0] = 1234; });
114 EXPECT_CALL(*raw_mock_gles,
115 ObjectLabelKHR(_, 1234, _, ::testing::StrEq("hello, joe!")))
116 .Times(1);
117 ON_CALL(*raw_mock_gles, IsTexture).WillByDefault(::testing::Return(GL_TRUE));
118
119 auto worker = std::make_shared<TestWorker>();
120 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
121 reactor->AddWorker(worker);
122
123 HandleGLES handle = reactor->CreateUntrackedHandle(HandleType::kTexture);
124 reactor->SetDebugLabel(handle, "hello, joe!");
125}

References impeller::testing::MockGLES::Init(), kMockResolverGLES, impeller::kTexture, reactor, and flutter::size.

◆ TEST() [401/689]

impeller::testing::TEST ( ReactorGLES  ,
PerThreadOperationQueues   
)

Definition at line 127 of file reactor_unittests.cc.

127 {
128 auto mock_gles = MockGLES::Init();
130 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
131 auto worker = std::make_shared<TestWorker>();
132 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
133 reactor->AddWorker(worker);
134
135 bool op1_called = false;
136 EXPECT_TRUE(
137 reactor->AddOperation([&](const ReactorGLES&) { op1_called = true; }));
138
140 bool op2_called = false;
141 std::thread thread([&] {
142 EXPECT_TRUE(reactor->AddOperation(
143 [&](const ReactorGLES&) { op2_called = true; }, true));
144 event.Wait();
145 EXPECT_TRUE(reactor->React());
146 });
147
148 // Reacting on the main thread should only run the main thread's operation.
149 EXPECT_TRUE(reactor->React());
150 EXPECT_TRUE(op1_called);
151 EXPECT_FALSE(op2_called);
152
153 // Reacting on the second thread will run the second thread's operation.
154 event.Signal();
155 thread.join();
156 EXPECT_TRUE(op2_called);
157}

References impeller::testing::MockGLES::Init(), kMockResolverGLES, and reactor.

◆ TEST() [402/689]

impeller::testing::TEST ( ReactorGLES  ,
UntrackedHandle   
)

Definition at line 71 of file reactor_unittests.cc.

71 {
72 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
73
74 EXPECT_CALL(*mock_gles_impl, GenTextures(1, _))
75 .WillOnce([](GLsizei size, GLuint* queries) { queries[0] = 1234; });
76 EXPECT_CALL(*mock_gles_impl, DeleteTextures(1, ::testing::Pointee(1234)))
77 .Times(1);
78
79 std::shared_ptr<MockGLES> mock_gles =
80 MockGLES::Init(std::move(mock_gles_impl));
81 ProcTableGLES::Resolver resolver = kMockResolverGLES;
82 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
83 auto worker = std::make_shared<TestWorker>();
84 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
85 reactor->AddWorker(worker);
86
87 HandleGLES handle = reactor->CreateUntrackedHandle(HandleType::kTexture);
88 EXPECT_FALSE(handle.IsDead());
89 std::optional<GLuint> glint = reactor->GetGLHandle(handle);
90 EXPECT_TRUE(glint.has_value());
91 if (glint.has_value()) {
92 EXPECT_EQ(1234u, *glint);
93 }
94 reactor->CollectHandle(handle);
95 EXPECT_TRUE(reactor->AddOperation([&](const ReactorGLES&) {}));
96 EXPECT_TRUE(reactor->React());
97}
constexpr bool IsDead() const
Determines if the handle is dead.
Definition handle_gles.h:58

References impeller::testing::MockGLES::Init(), impeller::HandleGLES::IsDead(), kMockResolverGLES, impeller::kTexture, reactor, and flutter::size.

◆ TEST() [403/689]

impeller::testing::TEST ( RectTest  ,
ContainsFloatingPoint   
)

Definition at line 1553 of file rect_unittests.cc.

1553 {
1554 auto rect1 =
1555 Rect::MakeXYWH(472.599945f, 440.999969f, 1102.80005f, 654.000061f);
1556 auto rect2 = Rect::MakeXYWH(724.f, 618.f, 600.f, 300.f);
1557 EXPECT_TRUE(rect1.Contains(rect2));
1558}

References impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [404/689]

impeller::testing::TEST ( RectTest  ,
EmptyIRectDoesNotIntersect   
)

Definition at line 1023 of file rect_unittests.cc.

1023 {
1024 IRect rect = IRect::MakeLTRB(50, 50, 100, 100);
1025
1026 auto test = [&rect](int64_t l, int64_t t, int64_t r, int64_t b,
1027 const std::string& label) {
1028 EXPECT_FALSE(IRect::MakeLTRB(l, b, r, t).IntersectsWithRect(rect))
1029 << label << " with Top/Bottom swapped";
1030 EXPECT_FALSE(IRect::MakeLTRB(r, b, l, t).IntersectsWithRect(rect))
1031 << label << " with Left/Right swapped";
1032 EXPECT_FALSE(IRect::MakeLTRB(r, t, l, b).IntersectsWithRect(rect))
1033 << label << " with all sides swapped";
1034 };
1035
1036 test(20, 20, 30, 30, "Above and Left");
1037 test(70, 20, 80, 30, "Above");
1038 test(120, 20, 130, 30, "Above and Right");
1039 test(120, 70, 130, 80, "Right");
1040 test(120, 120, 130, 130, "Below and Right");
1041 test(70, 120, 80, 130, "Below");
1042 test(20, 120, 30, 130, "Below and Left");
1043 test(20, 70, 30, 80, "Left");
1044
1045 test(70, 70, 80, 80, "Inside");
1046
1047 test(40, 70, 60, 80, "Straddling Left");
1048 test(70, 40, 80, 60, "Straddling Top");
1049 test(90, 70, 110, 80, "Straddling Right");
1050 test(70, 90, 80, 110, "Straddling Bottom");
1051}

References impeller::TRect< T >::MakeLTRB().

◆ TEST() [405/689]

impeller::testing::TEST ( RectTest  ,
EmptyRectDoesNotIntersect   
)

Definition at line 993 of file rect_unittests.cc.

993 {
994 Rect rect = Rect::MakeLTRB(50, 50, 100, 100);
995
996 auto test = [&rect](Scalar l, Scalar t, Scalar r, Scalar b,
997 const std::string& label) {
998 EXPECT_FALSE(Rect::MakeLTRB(l, b, r, t).IntersectsWithRect(rect))
999 << label << " with Top/Bottom swapped";
1000 EXPECT_FALSE(Rect::MakeLTRB(r, b, l, t).IntersectsWithRect(rect))
1001 << label << " with Left/Right swapped";
1002 EXPECT_FALSE(Rect::MakeLTRB(r, t, l, b).IntersectsWithRect(rect))
1003 << label << " with all sides swapped";
1004 };
1005
1006 test(20, 20, 30, 30, "Above and Left");
1007 test(70, 20, 80, 30, "Above");
1008 test(120, 20, 130, 30, "Above and Right");
1009 test(120, 70, 130, 80, "Right");
1010 test(120, 120, 130, 130, "Below and Right");
1011 test(70, 120, 80, 130, "Below");
1012 test(20, 120, 30, 130, "Below and Left");
1013 test(20, 70, 30, 80, "Left");
1014
1015 test(70, 70, 80, 80, "Inside");
1016
1017 test(40, 70, 60, 80, "Straddling Left");
1018 test(70, 40, 80, 60, "Straddling Top");
1019 test(90, 70, 110, 80, "Straddling Right");
1020 test(70, 90, 80, 110, "Straddling Bottom");
1021}

References impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [406/689]

impeller::testing::TEST ( RectTest  ,
FloatContainsInteger   
)

Definition at line 1560 of file rect_unittests.cc.

1560 {
1561 auto rect1 =
1562 Rect::MakeLTRB(472.599945f, 440.999969f, 1574.80005f, 1094.000000f);
1563 EXPECT_TRUE(rect1.Contains(IRect::MakeLTRB(473, 441, 1574, 1094)));
1564
1565 // Now test failure to contain same rect expanded by 1 on each side
1566 EXPECT_FALSE(rect1.Contains(IRect::MakeLTRB(472, 441, 1574, 1094)));
1567 EXPECT_FALSE(rect1.Contains(IRect::MakeLTRB(473, 440, 1574, 1094)));
1568 EXPECT_FALSE(rect1.Contains(IRect::MakeLTRB(473, 441, 1575, 1094)));
1569 EXPECT_FALSE(rect1.Contains(IRect::MakeLTRB(473, 441, 1574, 1095)));
1570}

References impeller::TRect< T >::MakeLTRB(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [407/689]

impeller::testing::TEST ( RectTest  ,
GetCenter   
)

Definition at line 1363 of file rect_unittests.cc.

1363 {
1364 EXPECT_EQ(Rect::MakeXYWH(10, 30, 20, 20).GetCenter(), Point(20, 40));
1365 EXPECT_EQ(Rect::MakeXYWH(10, 30, 20, 19).GetCenter(), Point(20, 39.5));
1366 EXPECT_EQ(Rect::MakeMaximum().GetCenter(), Point(0, 0));
1367
1368 // Note that we expect a Point as the answer from an IRect
1369 EXPECT_EQ(IRect::MakeXYWH(10, 30, 20, 20).GetCenter(), Point(20, 40));
1370 EXPECT_EQ(IRect::MakeXYWH(10, 30, 20, 19).GetCenter(), Point(20, 39.5));
1371 EXPECT_EQ(IRect::MakeMaximum().GetCenter(), Point(0, 0));
1372}

References impeller::TRect< T >::MakeMaximum(), impeller::TRect< Scalar >::MakeMaximum(), impeller::TRect< T >::MakeXYWH(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [408/689]

impeller::testing::TEST ( RectTest  ,
IRectArea   
)

Definition at line 1149 of file rect_unittests.cc.

1149 {
1150 EXPECT_EQ(IRect::MakeXYWH(0, 0, 100, 200).Area(), 20000);
1151 EXPECT_EQ(IRect::MakeXYWH(10, 20, 100, 200).Area(), 20000);
1152 EXPECT_EQ(IRect::MakeXYWH(0, 0, 200, 100).Area(), 20000);
1153 EXPECT_EQ(IRect::MakeXYWH(10, 20, 200, 100).Area(), 20000);
1154 EXPECT_EQ(IRect::MakeXYWH(0, 0, 100, 100).Area(), 10000);
1155 EXPECT_EQ(IRect::MakeXYWH(10, 20, 100, 100).Area(), 10000);
1156}

References impeller::TRect< T >::MakeXYWH().

◆ TEST() [409/689]

impeller::testing::TEST ( RectTest  ,
IRectContainsInclusiveIPoint   
)

Definition at line 2653 of file rect_unittests.cc.

2653 {
2654 auto check_empty_flips = [](const IRect& rect, const IPoint& point,
2655 const std::string& label) {
2656 ASSERT_FALSE(rect.IsEmpty());
2657
2658 EXPECT_FALSE(flip_lr(rect).ContainsInclusive(point)) << label;
2659 EXPECT_FALSE(flip_tb(rect).ContainsInclusive(point)) << label;
2660 EXPECT_FALSE(flip_lrtb(rect).ContainsInclusive(point)) << label;
2661 };
2662
2663 auto test_inside = [&check_empty_flips](const IRect& rect,
2664 const IPoint& point) {
2665 ASSERT_FALSE(rect.IsEmpty()) << rect;
2666
2667 std::stringstream stream;
2668 stream << rect << " contains " << point;
2669 auto label = stream.str();
2670
2671 EXPECT_TRUE(rect.ContainsInclusive(point)) << label;
2672 check_empty_flips(rect, point, label);
2673 };
2674
2675 auto test_outside = [&check_empty_flips](const IRect& rect,
2676 const IPoint& point) {
2677 ASSERT_FALSE(rect.IsEmpty()) << rect;
2678
2679 std::stringstream stream;
2680 stream << rect << " contains " << point;
2681 auto label = stream.str();
2682
2683 EXPECT_FALSE(rect.ContainsInclusive(point)) << label;
2684 check_empty_flips(rect, point, label);
2685 };
2686
2687 {
2688 // Origin is inclusive
2689 auto r = IRect::MakeXYWH(100, 100, 100, 100);
2690 auto p = IPoint(100, 100);
2691
2692 test_inside(r, p);
2693 }
2694 {
2695 // Size is inclusive
2696 auto r = IRect::MakeXYWH(100, 100, 100, 100);
2697 auto p = IPoint(200, 200);
2698
2699 test_inside(r, p);
2700 }
2701 {
2702 // Size + "epsilon" is exclusive
2703 auto r = IRect::MakeXYWH(100, 100, 100, 100);
2704 auto p = IPoint(201, 201);
2705
2706 test_outside(r, p);
2707 }
2708 {
2709 auto r = IRect::MakeXYWH(100, 100, 100, 100);
2710 auto p = IPoint(99, 99);
2711
2712 test_outside(r, p);
2713 }
2714 {
2715 auto r = IRect::MakeXYWH(100, 100, 100, 100);
2716 auto p = IPoint(199, 199);
2717
2718 test_inside(r, p);
2719 }
2720
2721 {
2722 auto r = IRect::MakeMaximum();
2723 auto p = IPoint(199, 199);
2724
2725 test_inside(r, p);
2726 }
2727}
static constexpr R flip_lrtb(R rect)
constexpr bool ContainsInclusive(const TPoint< Type > &p) const
Returns true iff the provided point |p| is inside the closed-range interior of this rectangle.
Definition rect.h:274
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition rect.h:331

References impeller::TRect< T >::ContainsInclusive(), flip_lr(), flip_lrtb(), flip_tb(), impeller::TRect< T >::IsEmpty(), impeller::TRect< T >::MakeMaximum(), and impeller::TRect< T >::MakeXYWH().

◆ TEST() [410/689]

impeller::testing::TEST ( RectTest  ,
IRectContainsIPoint   
)

Definition at line 2491 of file rect_unittests.cc.

2491 {
2492 auto check_empty_flips = [](const IRect& rect, const IPoint& point,
2493 const std::string& label) {
2494 ASSERT_FALSE(rect.IsEmpty());
2495
2496 EXPECT_FALSE(flip_lr(rect).Contains(point)) << label;
2497 EXPECT_FALSE(flip_tb(rect).Contains(point)) << label;
2498 EXPECT_FALSE(flip_lrtb(rect).Contains(point)) << label;
2499 };
2500
2501 auto test_inside = [&check_empty_flips](const IRect& rect,
2502 const IPoint& point) {
2503 ASSERT_FALSE(rect.IsEmpty()) << rect;
2504
2505 std::stringstream stream;
2506 stream << rect << " contains " << point;
2507 auto label = stream.str();
2508
2509 EXPECT_TRUE(rect.Contains(point)) << label;
2510 check_empty_flips(rect, point, label);
2511 };
2512
2513 auto test_outside = [&check_empty_flips](const IRect& rect,
2514 const IPoint& point) {
2515 ASSERT_FALSE(rect.IsEmpty()) << rect;
2516
2517 std::stringstream stream;
2518 stream << rect << " contains " << point;
2519 auto label = stream.str();
2520
2521 EXPECT_FALSE(rect.Contains(point)) << label;
2522 check_empty_flips(rect, point, label);
2523 };
2524
2525 {
2526 // Origin is inclusive
2527 auto r = IRect::MakeXYWH(100, 100, 100, 100);
2528 auto p = IPoint(100, 100);
2529
2530 test_inside(r, p);
2531 }
2532 {
2533 // Size is exclusive
2534 auto r = IRect::MakeXYWH(100, 100, 100, 100);
2535 auto p = IPoint(200, 200);
2536
2537 test_outside(r, p);
2538 }
2539 {
2540 auto r = IRect::MakeXYWH(100, 100, 100, 100);
2541 auto p = IPoint(99, 99);
2542
2543 test_outside(r, p);
2544 }
2545 {
2546 auto r = IRect::MakeXYWH(100, 100, 100, 100);
2547 auto p = IPoint(199, 199);
2548
2549 test_inside(r, p);
2550 }
2551
2552 {
2553 auto r = IRect::MakeMaximum();
2554 auto p = IPoint(199, 199);
2555
2556 test_inside(r, p);
2557 }
2558}
constexpr bool Contains(const TPoint< Type > &p) const
Returns true iff the provided point |p| is inside the half-open interior of this rectangle.
Definition rect.h:255

References impeller::TRect< T >::Contains(), flip_lr(), flip_lrtb(), flip_tb(), impeller::TRect< T >::IsEmpty(), impeller::TRect< T >::MakeMaximum(), and impeller::TRect< T >::MakeXYWH().

◆ TEST() [411/689]

impeller::testing::TEST ( RectTest  ,
IRectContainsIRect   
)

Definition at line 2844 of file rect_unittests.cc.

2844 {
2845 auto check_empty_flips = [](const IRect& a, const IRect& b,
2846 const std::string& label) {
2847 ASSERT_FALSE(a.IsEmpty());
2848 // test b rects are allowed to have 0 w/h, but not be backwards
2849 ASSERT_FALSE(b.GetLeft() > b.GetRight() || b.GetTop() > b.GetBottom());
2850
2851 // unflipped a vs flipped (empty) b yields true
2852 EXPECT_TRUE(a.Contains(flip_lr(b))) << label;
2853 EXPECT_TRUE(a.Contains(flip_tb(b))) << label;
2854 EXPECT_TRUE(a.Contains(flip_lrtb(b))) << label;
2855
2856 // flipped (empty) a vs unflipped b yields false
2857 EXPECT_FALSE(flip_lr(a).Contains(b)) << label;
2858 EXPECT_FALSE(flip_tb(a).Contains(b)) << label;
2859 EXPECT_FALSE(flip_lrtb(a).Contains(b)) << label;
2860
2861 // flipped (empty) a vs flipped (empty) b yields empty
2862 EXPECT_FALSE(flip_lr(a).Contains(flip_lr(b))) << label;
2863 EXPECT_FALSE(flip_tb(a).Contains(flip_tb(b))) << label;
2864 EXPECT_FALSE(flip_lrtb(a).Contains(flip_lrtb(b))) << label;
2865 };
2866
2867 auto test_inside = [&check_empty_flips](const IRect& a, const IRect& b) {
2868 ASSERT_FALSE(a.IsEmpty()) << a;
2869 // test b rects are allowed to have 0 w/h, but not be backwards
2870 ASSERT_FALSE(b.GetLeft() > b.GetRight() || b.GetTop() > b.GetBottom());
2871
2872 std::stringstream stream;
2873 stream << a << " contains " << b;
2874 auto label = stream.str();
2875
2876 EXPECT_TRUE(a.Contains(b)) << label;
2877 check_empty_flips(a, b, label);
2878 };
2879
2880 auto test_not_inside = [&check_empty_flips](const IRect& a, const IRect& b) {
2881 ASSERT_FALSE(a.IsEmpty()) << a;
2882 // If b was empty, it would be contained and should not be tested with
2883 // this function - use |test_inside| instead.
2884 ASSERT_FALSE(b.IsEmpty()) << b;
2885
2886 std::stringstream stream;
2887 stream << a << " contains " << b;
2888 auto label = stream.str();
2889
2890 EXPECT_FALSE(a.Contains(b)) << label;
2891 check_empty_flips(a, b, label);
2892 };
2893
2894 {
2895 auto a = IRect::MakeXYWH(100, 100, 100, 100);
2896
2897 test_inside(a, a);
2898 }
2899 {
2900 auto a = IRect::MakeXYWH(100, 100, 100, 100);
2901 auto b = IRect::MakeXYWH(0, 0, 0, 0);
2902
2903 test_inside(a, b);
2904 }
2905 {
2906 auto a = IRect::MakeXYWH(100, 100, 100, 100);
2907 auto b = IRect::MakeXYWH(150, 150, 20, 20);
2908
2909 test_inside(a, b);
2910 }
2911 {
2912 auto a = IRect::MakeXYWH(100, 100, 100, 100);
2913 auto b = IRect::MakeXYWH(150, 150, 100, 100);
2914
2915 test_not_inside(a, b);
2916 }
2917 {
2918 auto a = IRect::MakeXYWH(100, 100, 100, 100);
2919 auto b = IRect::MakeXYWH(50, 50, 100, 100);
2920
2921 test_not_inside(a, b);
2922 }
2923 {
2924 auto a = IRect::MakeXYWH(100, 100, 100, 100);
2925 auto b = IRect::MakeXYWH(0, 0, 300, 300);
2926
2927 test_not_inside(a, b);
2928 }
2929 {
2930 auto a = IRect::MakeMaximum();
2931 auto b = IRect::MakeXYWH(0, 0, 300, 300);
2932
2933 test_inside(a, b);
2934 }
2935}

References impeller::TRect< T >::Contains(), flip_lr(), flip_lrtb(), flip_tb(), impeller::TRect< T >::IsEmpty(), impeller::TRect< T >::MakeMaximum(), and impeller::TRect< T >::MakeXYWH().

◆ TEST() [412/689]

impeller::testing::TEST ( RectTest  ,
IRectCopy   
)

Definition at line 810 of file rect_unittests.cc.

810 {
811 IRect rect = IRect::MakeLTRB(5, 10, 20, 25);
812 IRect copy = rect;
813
814 EXPECT_EQ(rect, copy);
815 EXPECT_EQ(copy.GetLeft(), 5);
816 EXPECT_EQ(copy.GetTop(), 10);
817 EXPECT_EQ(copy.GetRight(), 20);
818 EXPECT_EQ(copy.GetBottom(), 25);
819 EXPECT_EQ(copy.GetX(), 5);
820 EXPECT_EQ(copy.GetY(), 10);
821 EXPECT_EQ(copy.GetWidth(), 15);
822 EXPECT_EQ(copy.GetHeight(), 15);
823 EXPECT_FALSE(copy.IsEmpty());
824}
constexpr auto GetBottom() const
Definition rect.h:391
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
Definition rect.h:371
constexpr auto GetTop() const
Definition rect.h:387
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition rect.h:381
constexpr auto GetLeft() const
Definition rect.h:385
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
Definition rect.h:367
constexpr auto GetRight() const
Definition rect.h:389
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition rect.h:375

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeLTRB().

◆ TEST() [413/689]

impeller::testing::TEST ( RectTest  ,
IRectCutOut   
)

Definition at line 3089 of file rect_unittests.cc.

3089 {
3090 IRect cull_rect = IRect::MakeLTRB(20, 20, 40, 40);
3091
3092 auto check_empty_flips = [&cull_rect](const IRect& diff_rect,
3093 const std::string& label) {
3094 EXPECT_FALSE(diff_rect.IsEmpty());
3095 EXPECT_FALSE(cull_rect.IsEmpty());
3096
3097 // unflipped cull_rect vs flipped(empty) diff_rect
3098 // == cull_rect
3099 EXPECT_TRUE(cull_rect.Cutout(flip_lr(diff_rect)).has_value()) << label;
3100 EXPECT_EQ(cull_rect.Cutout(flip_lr(diff_rect)), cull_rect) << label;
3101 EXPECT_TRUE(cull_rect.Cutout(flip_tb(diff_rect)).has_value()) << label;
3102 EXPECT_EQ(cull_rect.Cutout(flip_tb(diff_rect)), cull_rect) << label;
3103 EXPECT_TRUE(cull_rect.Cutout(flip_lrtb(diff_rect)).has_value()) << label;
3104 EXPECT_EQ(cull_rect.Cutout(flip_lrtb(diff_rect)), cull_rect) << label;
3105
3106 // flipped(empty) cull_rect vs flipped(empty) diff_rect
3107 // == empty
3108 EXPECT_FALSE(flip_lr(cull_rect).Cutout(diff_rect).has_value()) << label;
3109 EXPECT_EQ(flip_lr(cull_rect).CutoutOrEmpty(diff_rect), IRect()) << label;
3110 EXPECT_FALSE(flip_tb(cull_rect).Cutout(diff_rect).has_value()) << label;
3111 EXPECT_EQ(flip_tb(cull_rect).CutoutOrEmpty(diff_rect), IRect()) << label;
3112 EXPECT_FALSE(flip_lrtb(cull_rect).Cutout(diff_rect).has_value()) << label;
3113 EXPECT_EQ(flip_lrtb(cull_rect).CutoutOrEmpty(diff_rect), IRect()) << label;
3114
3115 // flipped(empty) cull_rect vs unflipped diff_rect
3116 // == empty
3117 EXPECT_FALSE(flip_lr(cull_rect).Cutout(flip_lr(diff_rect)).has_value())
3118 << label;
3119 EXPECT_EQ(flip_lr(cull_rect).CutoutOrEmpty(flip_lr(diff_rect)), IRect())
3120 << label;
3121 EXPECT_FALSE(flip_tb(cull_rect).Cutout(flip_tb(diff_rect)).has_value())
3122 << label;
3123 EXPECT_EQ(flip_tb(cull_rect).CutoutOrEmpty(flip_tb(diff_rect)), IRect())
3124 << label;
3125 EXPECT_FALSE(flip_lrtb(cull_rect).Cutout(flip_lrtb(diff_rect)).has_value())
3126 << label;
3127 EXPECT_EQ(flip_lrtb(cull_rect).CutoutOrEmpty(flip_lrtb(diff_rect)), IRect())
3128 << label;
3129 };
3130
3131 auto non_reducing = [&cull_rect, &check_empty_flips](
3132 const IRect& diff_rect, const std::string& label) {
3133 EXPECT_EQ(cull_rect.Cutout(diff_rect), cull_rect) << label;
3134 EXPECT_EQ(cull_rect.CutoutOrEmpty(diff_rect), cull_rect) << label;
3135 check_empty_flips(diff_rect, label);
3136 };
3137
3138 auto reducing = [&cull_rect, &check_empty_flips](const IRect& diff_rect,
3139 const IRect& result_rect,
3140 const std::string& label) {
3141 EXPECT_TRUE(!result_rect.IsEmpty());
3142 EXPECT_EQ(cull_rect.Cutout(diff_rect), result_rect) << label;
3143 EXPECT_EQ(cull_rect.CutoutOrEmpty(diff_rect), result_rect) << label;
3144 check_empty_flips(diff_rect, label);
3145 };
3146
3147 auto emptying = [&cull_rect, &check_empty_flips](const IRect& diff_rect,
3148 const std::string& label) {
3149 EXPECT_FALSE(cull_rect.Cutout(diff_rect).has_value()) << label;
3150 EXPECT_EQ(cull_rect.CutoutOrEmpty(diff_rect), IRect()) << label;
3151 check_empty_flips(diff_rect, label);
3152 };
3153
3154 // Skim the corners and edge
3155 non_reducing(IRect::MakeLTRB(10, 10, 20, 20), "outside UL corner");
3156 non_reducing(IRect::MakeLTRB(20, 10, 40, 20), "Above");
3157 non_reducing(IRect::MakeLTRB(40, 10, 50, 20), "outside UR corner");
3158 non_reducing(IRect::MakeLTRB(40, 20, 50, 40), "Right");
3159 non_reducing(IRect::MakeLTRB(40, 40, 50, 50), "outside LR corner");
3160 non_reducing(IRect::MakeLTRB(20, 40, 40, 50), "Below");
3161 non_reducing(IRect::MakeLTRB(10, 40, 20, 50), "outside LR corner");
3162 non_reducing(IRect::MakeLTRB(10, 20, 20, 40), "Left");
3163
3164 // Overlap corners
3165 non_reducing(IRect::MakeLTRB(15, 15, 25, 25), "covering UL corner");
3166 non_reducing(IRect::MakeLTRB(35, 15, 45, 25), "covering UR corner");
3167 non_reducing(IRect::MakeLTRB(35, 35, 45, 45), "covering LR corner");
3168 non_reducing(IRect::MakeLTRB(15, 35, 25, 45), "covering LL corner");
3169
3170 // Overlap edges, but not across an entire side
3171 non_reducing(IRect::MakeLTRB(20, 15, 39, 25), "Top edge left-biased");
3172 non_reducing(IRect::MakeLTRB(21, 15, 40, 25), "Top edge, right biased");
3173 non_reducing(IRect::MakeLTRB(35, 20, 45, 39), "Right edge, top-biased");
3174 non_reducing(IRect::MakeLTRB(35, 21, 45, 40), "Right edge, bottom-biased");
3175 non_reducing(IRect::MakeLTRB(20, 35, 39, 45), "Bottom edge, left-biased");
3176 non_reducing(IRect::MakeLTRB(21, 35, 40, 45), "Bottom edge, right-biased");
3177 non_reducing(IRect::MakeLTRB(15, 20, 25, 39), "Left edge, top-biased");
3178 non_reducing(IRect::MakeLTRB(15, 21, 25, 40), "Left edge, bottom-biased");
3179
3180 // Slice all the way through the middle
3181 non_reducing(IRect::MakeLTRB(25, 15, 35, 45), "Vertical interior slice");
3182 non_reducing(IRect::MakeLTRB(15, 25, 45, 35), "Horizontal interior slice");
3183
3184 // Slice off each edge
3185 reducing(IRect::MakeLTRB(20, 15, 40, 25), //
3186 IRect::MakeLTRB(20, 25, 40, 40), //
3187 "Slice off top");
3188 reducing(IRect::MakeLTRB(35, 20, 45, 40), //
3189 IRect::MakeLTRB(20, 20, 35, 40), //
3190 "Slice off right");
3191 reducing(IRect::MakeLTRB(20, 35, 40, 45), //
3192 IRect::MakeLTRB(20, 20, 40, 35), //
3193 "Slice off bottom");
3194 reducing(IRect::MakeLTRB(15, 20, 25, 40), //
3195 IRect::MakeLTRB(25, 20, 40, 40), //
3196 "Slice off left");
3197
3198 // cull rect contains diff rect
3199 non_reducing(IRect::MakeLTRB(21, 21, 39, 39), "Contained, non-covering");
3200
3201 // cull rect equals diff rect
3202 emptying(cull_rect, "Perfectly covering");
3203
3204 // diff rect contains cull rect
3205 emptying(IRect::MakeLTRB(15, 15, 45, 45), "Smothering");
3206}
IRect64 IRect
Definition rect.h:860
constexpr std::optional< TRect< T > > Cutout(const TRect &o) const
Returns the new boundary rectangle that would result from this rectangle being cut out by the specifi...
Definition rect.h:591
constexpr TRect CutoutOrEmpty(const TRect &o) const
Definition rect.h:631

References impeller::TRect< T >::Cutout(), impeller::TRect< T >::CutoutOrEmpty(), flip_lr(), flip_lrtb(), flip_tb(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeLTRB().

◆ TEST() [414/689]

impeller::testing::TEST ( RectTest  ,
IRectDefaultConstructor   
)

Definition at line 59 of file rect_unittests.cc.

59 {
60 IRect rect = IRect();
61
62 EXPECT_EQ(rect.GetLeft(), 0);
63 EXPECT_EQ(rect.GetTop(), 0);
64 EXPECT_EQ(rect.GetRight(), 0);
65 EXPECT_EQ(rect.GetBottom(), 0);
66 EXPECT_EQ(rect.GetX(), 0);
67 EXPECT_EQ(rect.GetY(), 0);
68 EXPECT_EQ(rect.GetWidth(), 0);
69 EXPECT_EQ(rect.GetHeight(), 0);
70 EXPECT_TRUE(rect.IsEmpty());
71}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), and impeller::TRect< T >::IsEmpty().

◆ TEST() [415/689]

impeller::testing::TEST ( RectTest  ,
IRectDoesNotIntersectEmpty   
)

Definition at line 963 of file rect_unittests.cc.

963 {
964 IRect rect = IRect::MakeLTRB(50, 50, 100, 100);
965
966 auto test = [&rect](int64_t l, int64_t t, int64_t r, int64_t b,
967 const std::string& label) {
968 EXPECT_FALSE(rect.IntersectsWithRect(IRect::MakeLTRB(l, b, r, t)))
969 << label << " with Top/Bottom swapped";
970 EXPECT_FALSE(rect.IntersectsWithRect(IRect::MakeLTRB(r, b, l, t)))
971 << label << " with Left/Right swapped";
972 EXPECT_FALSE(rect.IntersectsWithRect(IRect::MakeLTRB(r, t, l, b)))
973 << label << " with all sides swapped";
974 };
975
976 test(20, 20, 30, 30, "Above and Left");
977 test(70, 20, 80, 30, "Above");
978 test(120, 20, 130, 30, "Above and Right");
979 test(120, 70, 130, 80, "Right");
980 test(120, 120, 130, 130, "Below and Right");
981 test(70, 120, 80, 130, "Below");
982 test(20, 120, 30, 130, "Below and Left");
983 test(20, 70, 30, 80, "Left");
984
985 test(70, 70, 80, 80, "Inside");
986
987 test(40, 70, 60, 80, "Straddling Left");
988 test(70, 40, 80, 60, "Straddling Top");
989 test(90, 70, 110, 80, "Straddling Right");
990 test(70, 90, 80, 110, "Straddling Bottom");
991}
constexpr bool IntersectsWithRect(const TRect &o) const
Definition rect.h:580

References impeller::TRect< T >::IntersectsWithRect(), and impeller::TRect< T >::MakeLTRB().

◆ TEST() [416/689]

impeller::testing::TEST ( RectTest  ,
IRectEmptyDeclaration   
)

Definition at line 29 of file rect_unittests.cc.

29 {
30 IRect rect;
31
32 EXPECT_EQ(rect.GetLeft(), 0);
33 EXPECT_EQ(rect.GetTop(), 0);
34 EXPECT_EQ(rect.GetRight(), 0);
35 EXPECT_EQ(rect.GetBottom(), 0);
36 EXPECT_EQ(rect.GetX(), 0);
37 EXPECT_EQ(rect.GetY(), 0);
38 EXPECT_EQ(rect.GetWidth(), 0);
39 EXPECT_EQ(rect.GetHeight(), 0);
40 EXPECT_TRUE(rect.IsEmpty());
41 // EXPECT_TRUE(rect.IsFinite()); // should fail to compile
42}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), and impeller::TRect< T >::IsEmpty().

◆ TEST() [417/689]

impeller::testing::TEST ( RectTest  ,
IRectExpand   
)

Definition at line 1407 of file rect_unittests.cc.

1407 {
1408 auto rect = IRect::MakeLTRB(100, 100, 200, 200);
1409
1410 // Expand(T amount)
1411 EXPECT_EQ(rect.Expand(10), IRect::MakeLTRB(90, 90, 210, 210));
1412 EXPECT_EQ(rect.Expand(-10), IRect::MakeLTRB(110, 110, 190, 190));
1413
1414 // Expand(amount, amount)
1415 EXPECT_EQ(rect.Expand(10, 10), IRect::MakeLTRB(90, 90, 210, 210));
1416 EXPECT_EQ(rect.Expand(10, -10), IRect::MakeLTRB(90, 110, 210, 190));
1417 EXPECT_EQ(rect.Expand(-10, 10), IRect::MakeLTRB(110, 90, 190, 210));
1418 EXPECT_EQ(rect.Expand(-10, -10), IRect::MakeLTRB(110, 110, 190, 190));
1419
1420 // Expand(amount, amount, amount, amount)
1421 EXPECT_EQ(rect.Expand(10, 20, 30, 40), IRect::MakeLTRB(90, 80, 230, 240));
1422 EXPECT_EQ(rect.Expand(-10, 20, 30, 40), IRect::MakeLTRB(110, 80, 230, 240));
1423 EXPECT_EQ(rect.Expand(10, -20, 30, 40), IRect::MakeLTRB(90, 120, 230, 240));
1424 EXPECT_EQ(rect.Expand(10, 20, -30, 40), IRect::MakeLTRB(90, 80, 170, 240));
1425 EXPECT_EQ(rect.Expand(10, 20, 30, -40), IRect::MakeLTRB(90, 80, 230, 160));
1426
1427 // Expand(IPoint amount)
1428 EXPECT_EQ(rect.Expand(IPoint{10, 10}), IRect::MakeLTRB(90, 90, 210, 210));
1429 EXPECT_EQ(rect.Expand(IPoint{10, -10}), IRect::MakeLTRB(90, 110, 210, 190));
1430 EXPECT_EQ(rect.Expand(IPoint{-10, 10}), IRect::MakeLTRB(110, 90, 190, 210));
1431 EXPECT_EQ(rect.Expand(IPoint{-10, -10}), IRect::MakeLTRB(110, 110, 190, 190));
1432
1433 // Expand(ISize amount)
1434 EXPECT_EQ(rect.Expand(ISize{10, 10}), IRect::MakeLTRB(90, 90, 210, 210));
1435 EXPECT_EQ(rect.Expand(ISize{10, -10}), IRect::MakeLTRB(90, 110, 210, 190));
1436 EXPECT_EQ(rect.Expand(ISize{-10, 10}), IRect::MakeLTRB(110, 90, 190, 210));
1437 EXPECT_EQ(rect.Expand(ISize{-10, -10}), IRect::MakeLTRB(110, 110, 190, 190));
1438}

References impeller::TRect< T >::MakeLTRB().

◆ TEST() [418/689]

impeller::testing::TEST ( RectTest  ,
IRectFromIRect   
)

Definition at line 785 of file rect_unittests.cc.

785 {
786 EXPECT_EQ(IRect(IRect::MakeXYWH(2, 3, 7, 15)), //
787 IRect::MakeXYWH(2, 3, 7, 15));
788 EXPECT_EQ(IRect(IRect::MakeLTRB(2, 3, 7, 15)), //
789 IRect::MakeLTRB(2, 3, 7, 15));
790}

References impeller::TRect< T >::MakeLTRB(), and impeller::TRect< T >::MakeXYWH().

◆ TEST() [419/689]

impeller::testing::TEST ( RectTest  ,
IRectGetNormalizingTransform   
)

Definition at line 1246 of file rect_unittests.cc.

1246 {
1247 {
1248 // Checks for expected matrix values
1249
1250 auto r = IRect::MakeXYWH(100, 200, 200, 400);
1251
1252 EXPECT_EQ(r.GetNormalizingTransform(),
1253 Matrix::MakeScale({0.005, 0.0025, 1.0}) *
1254 Matrix::MakeTranslation({-100, -200}));
1255 }
1256
1257 {
1258 // Checks for expected transform of points relative to the rect
1259
1260 auto r = IRect::MakeLTRB(300, 500, 400, 700);
1261 auto m = r.GetNormalizingTransform();
1262
1263 // The 4 corners of the rect => (0, 0) to (1, 1)
1264 EXPECT_EQ(m * Point(300, 500), Point(0, 0));
1265 EXPECT_EQ(m * Point(400, 500), Point(1, 0));
1266 EXPECT_EQ(m * Point(400, 700), Point(1, 1));
1267 EXPECT_EQ(m * Point(300, 700), Point(0, 1));
1268
1269 // The center => (0.5, 0.5)
1270 EXPECT_EQ(m * Point(350, 600), Point(0.5, 0.5));
1271
1272 // Outside the 4 corners => (-1, -1) to (2, 2)
1273 EXPECT_EQ(m * Point(200, 300), Point(-1, -1));
1274 EXPECT_EQ(m * Point(500, 300), Point(2, -1));
1275 EXPECT_EQ(m * Point(500, 900), Point(2, 2));
1276 EXPECT_EQ(m * Point(200, 900), Point(-1, 2));
1277 }
1278
1279 {
1280 // Checks for behavior with empty rects
1281
1282 auto zero = Matrix::MakeScale({0.0, 0.0, 1.0});
1283
1284 // Empty for width and/or height == 0
1285 EXPECT_EQ(IRect::MakeXYWH(10, 10, 0, 10).GetNormalizingTransform(), zero);
1286 EXPECT_EQ(IRect::MakeXYWH(10, 10, 10, 0).GetNormalizingTransform(), zero);
1287 EXPECT_EQ(IRect::MakeXYWH(10, 10, 0, 0).GetNormalizingTransform(), zero);
1288
1289 // Empty for width and/or height < 0
1290 EXPECT_EQ(IRect::MakeXYWH(10, 10, -1, 10).GetNormalizingTransform(), zero);
1291 EXPECT_EQ(IRect::MakeXYWH(10, 10, 10, -1).GetNormalizingTransform(), zero);
1292 EXPECT_EQ(IRect::MakeXYWH(10, 10, -1, -1).GetNormalizingTransform(), zero);
1293 }
1294}

References impeller::TRect< T >::MakeLTRB(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), and impeller::TRect< T >::MakeXYWH().

◆ TEST() [420/689]

impeller::testing::TEST ( RectTest  ,
IRectIntersection   
)

Definition at line 2049 of file rect_unittests.cc.

2049 {
2050 auto check_empty_flips = [](const IRect& a, const IRect& b,
2051 const std::string& label) {
2052 ASSERT_FALSE(a.IsEmpty());
2053 // b is allowed to be empty
2054
2055 // unflipped a vs flipped (empty) b yields a
2056 EXPECT_FALSE(a.Intersection(flip_lr(b)).has_value()) << label;
2057 EXPECT_FALSE(a.Intersection(flip_tb(b)).has_value()) << label;
2058 EXPECT_FALSE(a.Intersection(flip_lrtb(b)).has_value()) << label;
2059
2060 // flipped (empty) a vs unflipped b yields b
2061 EXPECT_FALSE(flip_lr(a).Intersection(b).has_value()) << label;
2062 EXPECT_FALSE(flip_tb(a).Intersection(b).has_value()) << label;
2063 EXPECT_FALSE(flip_lrtb(a).Intersection(b).has_value()) << label;
2064
2065 // flipped (empty) a vs flipped (empty) b yields empty
2066 EXPECT_FALSE(flip_lr(a).Intersection(flip_lr(b)).has_value()) << label;
2067 EXPECT_FALSE(flip_tb(a).Intersection(flip_tb(b)).has_value()) << label;
2068 EXPECT_FALSE(flip_lrtb(a).Intersection(flip_lrtb(b)).has_value()) << label;
2069 };
2070
2071 auto test_non_empty = [&check_empty_flips](const IRect& a, const IRect& b,
2072 const IRect& result) {
2073 ASSERT_FALSE(a.IsEmpty()) << a;
2074 // b is allowed to be empty
2075
2076 std::stringstream stream;
2077 stream << a << " union " << b;
2078 auto label = stream.str();
2079
2080 EXPECT_TRUE(a.Intersection(b).has_value()) << label;
2081 EXPECT_TRUE(b.Intersection(a).has_value()) << label;
2082 EXPECT_EQ(a.Intersection(b), result) << label;
2083 EXPECT_EQ(b.Intersection(a), result) << label;
2084 check_empty_flips(a, b, label);
2085 };
2086
2087 auto test_empty = [&check_empty_flips](const IRect& a, const IRect& b) {
2088 ASSERT_FALSE(a.IsEmpty()) << a;
2089 // b is allowed to be empty
2090
2091 std::stringstream stream;
2092 stream << a << " union " << b;
2093 auto label = stream.str();
2094
2095 EXPECT_FALSE(a.Intersection(b).has_value()) << label;
2096 EXPECT_FALSE(b.Intersection(a).has_value()) << label;
2097 check_empty_flips(a, b, label);
2098 };
2099
2100 {
2101 auto a = IRect::MakeXYWH(100, 100, 100, 100);
2102 auto b = IRect::MakeXYWH(0, 0, 0, 0);
2103
2104 test_empty(a, b);
2105 }
2106
2107 {
2108 auto a = IRect::MakeXYWH(100, 100, 100, 100);
2109 auto b = IRect::MakeXYWH(10, 10, 0, 0);
2110
2111 test_empty(a, b);
2112 }
2113
2114 {
2115 auto a = IRect::MakeXYWH(0, 0, 100, 100);
2116 auto b = IRect::MakeXYWH(10, 10, 100, 100);
2117 auto expected = IRect::MakeXYWH(10, 10, 90, 90);
2118
2119 test_non_empty(a, b, expected);
2120 }
2121
2122 {
2123 auto a = IRect::MakeXYWH(0, 0, 100, 100);
2124 auto b = IRect::MakeXYWH(100, 100, 100, 100);
2125
2126 test_empty(a, b);
2127 }
2128
2129 {
2130 auto a = IRect::MakeMaximum();
2131 auto b = IRect::MakeXYWH(10, 10, 300, 300);
2132
2133 test_non_empty(a, b, b);
2134 }
2135
2136 {
2137 auto a = IRect::MakeMaximum();
2138 auto b = IRect::MakeMaximum();
2139
2140 test_non_empty(a, b, IRect::MakeMaximum());
2141 }
2142}
constexpr std::optional< TRect > Intersection(const TRect &o) const
Definition rect.h:562

References flip_lr(), flip_lrtb(), flip_tb(), impeller::TRect< T >::Intersection(), impeller::TRect< T >::IsEmpty(), impeller::TRect< T >::MakeMaximum(), and impeller::TRect< T >::MakeXYWH().

◆ TEST() [421/689]

impeller::testing::TEST ( RectTest  ,
IRectIntersectsWithRect   
)

Definition at line 2314 of file rect_unittests.cc.

2314 {
2315 auto check_empty_flips = [](const IRect& a, const IRect& b,
2316 const std::string& label) {
2317 ASSERT_FALSE(a.IsEmpty());
2318 // b is allowed to be empty
2319
2320 // unflipped a vs flipped (empty) b yields a
2321 EXPECT_FALSE(a.IntersectsWithRect(flip_lr(b))) << label;
2322 EXPECT_FALSE(a.IntersectsWithRect(flip_tb(b))) << label;
2323 EXPECT_FALSE(a.IntersectsWithRect(flip_lrtb(b))) << label;
2324
2325 // flipped (empty) a vs unflipped b yields b
2326 EXPECT_FALSE(flip_lr(a).IntersectsWithRect(b)) << label;
2327 EXPECT_FALSE(flip_tb(a).IntersectsWithRect(b)) << label;
2328 EXPECT_FALSE(flip_lrtb(a).IntersectsWithRect(b)) << label;
2329
2330 // flipped (empty) a vs flipped (empty) b yields empty
2331 EXPECT_FALSE(flip_lr(a).IntersectsWithRect(flip_lr(b))) << label;
2332 EXPECT_FALSE(flip_tb(a).IntersectsWithRect(flip_tb(b))) << label;
2333 EXPECT_FALSE(flip_lrtb(a).IntersectsWithRect(flip_lrtb(b))) << label;
2334 };
2335
2336 auto test_non_empty = [&check_empty_flips](const IRect& a, const IRect& b) {
2337 ASSERT_FALSE(a.IsEmpty()) << a;
2338 // b is allowed to be empty
2339
2340 std::stringstream stream;
2341 stream << a << " union " << b;
2342 auto label = stream.str();
2343
2344 EXPECT_TRUE(a.IntersectsWithRect(b)) << label;
2345 EXPECT_TRUE(b.IntersectsWithRect(a)) << label;
2346 check_empty_flips(a, b, label);
2347 };
2348
2349 auto test_empty = [&check_empty_flips](const IRect& a, const IRect& b) {
2350 ASSERT_FALSE(a.IsEmpty()) << a;
2351 // b is allowed to be empty
2352
2353 std::stringstream stream;
2354 stream << a << " union " << b;
2355 auto label = stream.str();
2356
2357 EXPECT_FALSE(a.IntersectsWithRect(b)) << label;
2358 EXPECT_FALSE(b.IntersectsWithRect(a)) << label;
2359 check_empty_flips(a, b, label);
2360 };
2361
2362 {
2363 auto a = IRect::MakeXYWH(100, 100, 100, 100);
2364 auto b = IRect::MakeXYWH(0, 0, 0, 0);
2365
2366 test_empty(a, b);
2367 }
2368
2369 {
2370 auto a = IRect::MakeXYWH(100, 100, 100, 100);
2371 auto b = IRect::MakeXYWH(10, 10, 0, 0);
2372
2373 test_empty(a, b);
2374 }
2375
2376 {
2377 auto a = IRect::MakeXYWH(0, 0, 100, 100);
2378 auto b = IRect::MakeXYWH(10, 10, 100, 100);
2379
2380 test_non_empty(a, b);
2381 }
2382
2383 {
2384 auto a = IRect::MakeXYWH(0, 0, 100, 100);
2385 auto b = IRect::MakeXYWH(100, 100, 100, 100);
2386
2387 test_empty(a, b);
2388 }
2389
2390 {
2391 auto a = IRect::MakeMaximum();
2392 auto b = IRect::MakeXYWH(10, 10, 100, 100);
2393
2394 test_non_empty(a, b);
2395 }
2396
2397 {
2398 auto a = IRect::MakeMaximum();
2399 auto b = IRect::MakeMaximum();
2400
2401 test_non_empty(a, b);
2402 }
2403}

References flip_lr(), flip_lrtb(), flip_tb(), impeller::TRect< T >::IntersectsWithRect(), impeller::TRect< T >::IsEmpty(), impeller::TRect< T >::MakeMaximum(), and impeller::TRect< T >::MakeXYWH().

◆ TEST() [422/689]

impeller::testing::TEST ( RectTest  ,
IRectMakeCircleBounds   
)

Definition at line 198 of file rect_unittests.cc.

198 {
199 IRect rect = IRect::MakeCircleBounds(IPoint(100, 200), 20);
200
201 EXPECT_FALSE(rect.IsEmpty());
202 EXPECT_EQ(rect.GetLeft(), 80);
203 EXPECT_EQ(rect.GetRight(), 120);
204 EXPECT_EQ(rect.GetTop(), 180);
205 EXPECT_EQ(rect.GetBottom(), 220);
206}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeCircleBounds().

◆ TEST() [423/689]

impeller::testing::TEST ( RectTest  ,
IRectMakeCircleBoundsNegativeRadius   
)

Definition at line 208 of file rect_unittests.cc.

208 {
209 IRect rect = IRect::MakeCircleBounds(IPoint(100, 200), -20);
210
211 EXPECT_TRUE(rect.IsEmpty());
212 EXPECT_EQ(rect.GetLeft(), 120);
213 EXPECT_EQ(rect.GetRight(), 80);
214 EXPECT_EQ(rect.GetTop(), 220);
215 EXPECT_EQ(rect.GetBottom(), 180);
216}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeCircleBounds().

◆ TEST() [424/689]

impeller::testing::TEST ( RectTest  ,
IRectMakeEllipseBoundsNegativePoint   
)

Definition at line 292 of file rect_unittests.cc.

292 {
293 IRect rect = IRect::MakeEllipseBounds(IPoint(100, 200), IPoint(-20, -30));
294
295 EXPECT_TRUE(rect.IsEmpty());
296 EXPECT_EQ(rect.GetLeft(), 120);
297 EXPECT_EQ(rect.GetRight(), 80);
298 EXPECT_EQ(rect.GetTop(), 230);
299 EXPECT_EQ(rect.GetBottom(), 170);
300}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeEllipseBounds().

◆ TEST() [425/689]

impeller::testing::TEST ( RectTest  ,
IRectMakeEllipseBoundsNegativeSize   
)

Definition at line 272 of file rect_unittests.cc.

272 {
273 IRect rect = IRect::MakeEllipseBounds(IPoint(100, 200), ISize(-20, -30));
274
275 EXPECT_TRUE(rect.IsEmpty());
276 EXPECT_EQ(rect.GetLeft(), 120);
277 EXPECT_EQ(rect.GetRight(), 80);
278 EXPECT_EQ(rect.GetTop(), 230);
279 EXPECT_EQ(rect.GetBottom(), 170);
280}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeEllipseBounds().

◆ TEST() [426/689]

impeller::testing::TEST ( RectTest  ,
IRectMakeEllipseBoundsPoint   
)

Definition at line 282 of file rect_unittests.cc.

282 {
283 IRect rect = IRect::MakeEllipseBounds(IPoint(100, 200), IPoint(20, 30));
284
285 EXPECT_FALSE(rect.IsEmpty());
286 EXPECT_EQ(rect.GetLeft(), 80);
287 EXPECT_EQ(rect.GetRight(), 120);
288 EXPECT_EQ(rect.GetTop(), 170);
289 EXPECT_EQ(rect.GetBottom(), 230);
290}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeEllipseBounds().

◆ TEST() [427/689]

impeller::testing::TEST ( RectTest  ,
IRectMakeEllipseBoundsSize   
)

Definition at line 262 of file rect_unittests.cc.

262 {
263 IRect rect = IRect::MakeEllipseBounds(IPoint(100, 200), ISize(20, 30));
264
265 EXPECT_FALSE(rect.IsEmpty());
266 EXPECT_EQ(rect.GetLeft(), 80);
267 EXPECT_EQ(rect.GetRight(), 120);
268 EXPECT_EQ(rect.GetTop(), 170);
269 EXPECT_EQ(rect.GetBottom(), 230);
270}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeEllipseBounds().

◆ TEST() [428/689]

impeller::testing::TEST ( RectTest  ,
IRectMakeMaximum   
)

Definition at line 762 of file rect_unittests.cc.

762 {
763 IRect rect = IRect::MakeMaximum();
764 auto min = std::numeric_limits<int64_t>::min();
765 auto max = std::numeric_limits<int64_t>::max();
766
767 EXPECT_EQ(rect.GetLeft(), min);
768 EXPECT_EQ(rect.GetTop(), min);
769 EXPECT_EQ(rect.GetRight(), max);
770 EXPECT_EQ(rect.GetBottom(), max);
771 EXPECT_EQ(rect.GetX(), min);
772 EXPECT_EQ(rect.GetY(), min);
773 EXPECT_EQ(rect.GetWidth(), max);
774 EXPECT_EQ(rect.GetHeight(), max);
775 EXPECT_FALSE(rect.IsEmpty());
776}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeMaximum().

◆ TEST() [429/689]

impeller::testing::TEST ( RectTest  ,
IRectOriginSizeXYWHGetters   
)

Definition at line 852 of file rect_unittests.cc.

852 {
853 {
854 IRect r = IRect::MakeOriginSize({10, 20}, {50, 40});
855 EXPECT_EQ(r.GetOrigin(), IPoint(10, 20));
856 EXPECT_EQ(r.GetSize(), ISize(50, 40));
857 EXPECT_EQ(r.GetX(), 10);
858 EXPECT_EQ(r.GetY(), 20);
859 EXPECT_EQ(r.GetWidth(), 50);
860 EXPECT_EQ(r.GetHeight(), 40);
861 auto expected_array = std::array<int64_t, 4>{10, 20, 50, 40};
862 EXPECT_EQ(r.GetXYWH(), expected_array);
863 }
864
865 {
866 IRect r = IRect::MakeLTRB(10, 20, 50, 40);
867 EXPECT_EQ(r.GetOrigin(), IPoint(10, 20));
868 EXPECT_EQ(r.GetSize(), ISize(40, 20));
869 EXPECT_EQ(r.GetX(), 10);
870 EXPECT_EQ(r.GetY(), 20);
871 EXPECT_EQ(r.GetWidth(), 40);
872 EXPECT_EQ(r.GetHeight(), 20);
873 auto expected_array = std::array<int64_t, 4>{10, 20, 40, 20};
874 EXPECT_EQ(r.GetXYWH(), expected_array);
875 }
876}
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
Definition rect.h:361
constexpr std::array< T, 4 > GetXYWH() const
Get the x, y coordinates of the origin and the width and height of the rectangle in an array.
Definition rect.h:427
constexpr TPoint< Type > GetOrigin() const
Returns the upper left corner of the rectangle as specified by the left/top or x/y values when it was...
Definition rect.h:354

References impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetOrigin(), impeller::TRect< T >::GetSize(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetXYWH(), impeller::TRect< T >::GetY(), impeller::TRect< T >::MakeLTRB(), and impeller::TRect< T >::MakeOriginSize().

◆ TEST() [430/689]

impeller::testing::TEST ( RectTest  ,
IRectOverflowLTRB   
)

Definition at line 647 of file rect_unittests.cc.

647 {
648 auto min = std::numeric_limits<int64_t>::min();
649 auto max = std::numeric_limits<int64_t>::max();
650
651 // 4 cases
652 // negative l, r near max takes width past max
653 // positive l, r near min takes width below min
654 // negative t, b near max takes width past max
655 // positive t, b near min takes width below min
656
657 {
658 IRect rect = IRect::MakeLTRB(-10, 10, max - 5, 26);
659
660 EXPECT_EQ(rect.GetLeft(), -10);
661 EXPECT_EQ(rect.GetTop(), 10);
662 EXPECT_EQ(rect.GetRight(), max - 5);
663 EXPECT_EQ(rect.GetBottom(), 26);
664 EXPECT_EQ(rect.GetX(), -10);
665 EXPECT_EQ(rect.GetY(), 10);
666 EXPECT_EQ(rect.GetWidth(), max);
667 EXPECT_EQ(rect.GetHeight(), 16);
668 EXPECT_FALSE(rect.IsEmpty());
669 }
670
671 {
672 IRect rect = IRect::MakeLTRB(10, 10, min + 5, 26);
673
674 EXPECT_EQ(rect.GetLeft(), 10);
675 EXPECT_EQ(rect.GetTop(), 10);
676 EXPECT_EQ(rect.GetRight(), min + 5);
677 EXPECT_EQ(rect.GetBottom(), 26);
678 EXPECT_EQ(rect.GetX(), 10);
679 EXPECT_EQ(rect.GetY(), 10);
680 EXPECT_EQ(rect.GetWidth(), min);
681 EXPECT_EQ(rect.GetHeight(), 16);
682 EXPECT_TRUE(rect.IsEmpty());
683 }
684
685 {
686 IRect rect = IRect::MakeLTRB(5, -10, 15, max - 5);
687
688 EXPECT_EQ(rect.GetLeft(), 5);
689 EXPECT_EQ(rect.GetTop(), -10);
690 EXPECT_EQ(rect.GetRight(), 15);
691 EXPECT_EQ(rect.GetBottom(), max - 5);
692 EXPECT_EQ(rect.GetX(), 5);
693 EXPECT_EQ(rect.GetY(), -10);
694 EXPECT_EQ(rect.GetWidth(), 10);
695 EXPECT_EQ(rect.GetHeight(), max);
696 EXPECT_FALSE(rect.IsEmpty());
697 }
698
699 {
700 IRect rect = IRect::MakeLTRB(5, 10, 15, min + 5);
701
702 EXPECT_EQ(rect.GetLeft(), 5);
703 EXPECT_EQ(rect.GetTop(), 10);
704 EXPECT_EQ(rect.GetRight(), 15);
705 EXPECT_EQ(rect.GetBottom(), min + 5);
706 EXPECT_EQ(rect.GetX(), 5);
707 EXPECT_EQ(rect.GetY(), 10);
708 EXPECT_EQ(rect.GetWidth(), 10);
709 EXPECT_EQ(rect.GetHeight(), min);
710 EXPECT_TRUE(rect.IsEmpty());
711 }
712}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeLTRB().

◆ TEST() [431/689]

impeller::testing::TEST ( RectTest  ,
IRectOverflowXYWH   
)

Definition at line 441 of file rect_unittests.cc.

441 {
442 auto min = std::numeric_limits<int64_t>::min();
443 auto max = std::numeric_limits<int64_t>::max();
444
445 // 4 cases
446 // x near max, positive w takes it past max
447 // x near min, negative w takes it below min
448 // y near max, positive h takes it past max
449 // y near min, negative h takes it below min
450
451 {
452 IRect rect = IRect::MakeXYWH(max - 5, 10, 10, 16);
453
454 EXPECT_EQ(rect.GetLeft(), max - 5);
455 EXPECT_EQ(rect.GetTop(), 10);
456 EXPECT_EQ(rect.GetRight(), max);
457 EXPECT_EQ(rect.GetBottom(), 26);
458 EXPECT_EQ(rect.GetX(), max - 5);
459 EXPECT_EQ(rect.GetY(), 10);
460 EXPECT_EQ(rect.GetWidth(), 5);
461 EXPECT_EQ(rect.GetHeight(), 16);
462 EXPECT_FALSE(rect.IsEmpty());
463 }
464
465 {
466 IRect rect = IRect::MakeXYWH(min + 5, 10, -10, 16);
467
468 EXPECT_EQ(rect.GetLeft(), min + 5);
469 EXPECT_EQ(rect.GetTop(), 10);
470 EXPECT_EQ(rect.GetRight(), min);
471 EXPECT_EQ(rect.GetBottom(), 26);
472 EXPECT_EQ(rect.GetX(), min + 5);
473 EXPECT_EQ(rect.GetY(), 10);
474 EXPECT_EQ(rect.GetWidth(), -5);
475 EXPECT_EQ(rect.GetHeight(), 16);
476 EXPECT_TRUE(rect.IsEmpty());
477 }
478
479 {
480 IRect rect = IRect::MakeXYWH(5, max - 10, 10, 16);
481
482 EXPECT_EQ(rect.GetLeft(), 5);
483 EXPECT_EQ(rect.GetTop(), max - 10);
484 EXPECT_EQ(rect.GetRight(), 15);
485 EXPECT_EQ(rect.GetBottom(), max);
486 EXPECT_EQ(rect.GetX(), 5);
487 EXPECT_EQ(rect.GetY(), max - 10);
488 EXPECT_EQ(rect.GetWidth(), 10);
489 EXPECT_EQ(rect.GetHeight(), 10);
490 EXPECT_FALSE(rect.IsEmpty());
491 }
492
493 {
494 IRect rect = IRect::MakeXYWH(5, min + 10, 10, -16);
495
496 EXPECT_EQ(rect.GetLeft(), 5);
497 EXPECT_EQ(rect.GetTop(), min + 10);
498 EXPECT_EQ(rect.GetRight(), 15);
499 EXPECT_EQ(rect.GetBottom(), min);
500 EXPECT_EQ(rect.GetX(), 5);
501 EXPECT_EQ(rect.GetY(), min + 10);
502 EXPECT_EQ(rect.GetWidth(), 10);
503 EXPECT_EQ(rect.GetHeight(), -10);
504 EXPECT_TRUE(rect.IsEmpty());
505 }
506}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeXYWH().

◆ TEST() [432/689]

impeller::testing::TEST ( RectTest  ,
IRectRound   
)

Definition at line 3347 of file rect_unittests.cc.

3347 {
3348 {
3349 auto r = Rect::MakeLTRB(-100, -200, 300, 400);
3350 auto ir = IRect::MakeLTRB(-100, -200, 300, 400);
3351 EXPECT_EQ(IRect::Round(r), ir);
3352 }
3353 {
3354 auto r = Rect::MakeLTRB(-100.4, -200.4, 300.4, 400.4);
3355 auto ir = IRect::MakeLTRB(-100, -200, 300, 400);
3356 EXPECT_EQ(IRect::Round(r), ir);
3357 }
3358 {
3359 auto r = Rect::MakeLTRB(-100.5, -200.5, 300.5, 400.5);
3360 auto ir = IRect::MakeLTRB(-101, -201, 301, 401);
3361 EXPECT_EQ(IRect::Round(r), ir);
3362 }
3363}

References impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::TRect< T >::Round().

◆ TEST() [433/689]

impeller::testing::TEST ( RectTest  ,
IRectRoundOut   
)

Definition at line 3319 of file rect_unittests.cc.

3319 {
3320 {
3321 auto r = Rect::MakeLTRB(-100, -200, 300, 400);
3322 auto ir = IRect::MakeLTRB(-100, -200, 300, 400);
3323 EXPECT_EQ(IRect::RoundOut(r), ir);
3324 }
3325 {
3326 auto r = Rect::MakeLTRB(-100.1, -200.1, 300.1, 400.1);
3327 auto ir = IRect::MakeLTRB(-101, -201, 301, 401);
3328 EXPECT_EQ(IRect::RoundOut(r), ir);
3329 }
3330}

References impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::TRect< T >::RoundOut().

◆ TEST() [434/689]

impeller::testing::TEST ( RectTest  ,
IRectScale   
)

Definition at line 1098 of file rect_unittests.cc.

1098 {
1099 auto test1 = [](IRect rect, int64_t scale) {
1100 IRect expected = IRect::MakeXYWH(rect.GetX() * scale, //
1101 rect.GetY() * scale, //
1102 rect.GetWidth() * scale, //
1103 rect.GetHeight() * scale);
1104
1105 EXPECT_EQ(rect.Scale(scale), expected) //
1106 << rect << " * " << scale;
1107 EXPECT_EQ(rect.Scale(scale, scale), expected) //
1108 << rect << " * " << scale;
1109 EXPECT_EQ(rect.Scale(IPoint(scale, scale)), expected) //
1110 << rect << " * " << scale;
1111 EXPECT_EQ(rect.Scale(ISize(scale, scale)), expected) //
1112 << rect << " * " << scale;
1113 };
1114
1115 auto test2 = [&test1](IRect rect, int64_t scale_x, int64_t scale_y) {
1116 IRect expected = IRect::MakeXYWH(rect.GetX() * scale_x, //
1117 rect.GetY() * scale_y, //
1118 rect.GetWidth() * scale_x, //
1119 rect.GetHeight() * scale_y);
1120
1121 EXPECT_EQ(rect.Scale(scale_x, scale_y), expected) //
1122 << rect << " * " << scale_x << ", " << scale_y;
1123 EXPECT_EQ(rect.Scale(IPoint(scale_x, scale_y)), expected) //
1124 << rect << " * " << scale_x << ", " << scale_y;
1125 EXPECT_EQ(rect.Scale(ISize(scale_x, scale_y)), expected) //
1126 << rect << " * " << scale_x << ", " << scale_y;
1127
1128 test1(rect, scale_x);
1129 test1(rect, scale_y);
1130 };
1131
1132 test2(IRect::MakeLTRB(10, 15, 100, 150), 2, 3);
1133 test2(IRect::MakeLTRB(10, 15, 100, 150), 3, 2);
1134 test2(IRect::MakeLTRB(10, 15, -100, 150), 2, 3);
1135 test2(IRect::MakeLTRB(10, 15, 100, -150), 2, 3);
1136 test2(IRect::MakeLTRB(10, 15, 100, 150), -2, 3);
1137 test2(IRect::MakeLTRB(10, 15, 100, 150), 2, -3);
1138}
constexpr TRect Scale(Type scale) const
Definition rect.h:226

References impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::TRect< T >::MakeLTRB(), impeller::TRect< T >::MakeXYWH(), and impeller::TRect< T >::Scale().

◆ TEST() [435/689]

impeller::testing::TEST ( RectTest  ,
IRectSimpleLTRB   
)

Definition at line 89 of file rect_unittests.cc.

89 {
90 IRect rect = IRect::MakeLTRB(5, 10, 20, 25);
91
92 EXPECT_EQ(rect.GetLeft(), 5);
93 EXPECT_EQ(rect.GetTop(), 10);
94 EXPECT_EQ(rect.GetRight(), 20);
95 EXPECT_EQ(rect.GetBottom(), 25);
96 EXPECT_EQ(rect.GetX(), 5);
97 EXPECT_EQ(rect.GetY(), 10);
98 EXPECT_EQ(rect.GetWidth(), 15);
99 EXPECT_EQ(rect.GetHeight(), 15);
100 EXPECT_FALSE(rect.IsEmpty());
101}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeLTRB().

◆ TEST() [436/689]

impeller::testing::TEST ( RectTest  ,
IRectSimpleWH   
)

Definition at line 149 of file rect_unittests.cc.

149 {
150 // Using fractional-power-of-2 friendly values for equality tests
151 IRect rect = IRect::MakeWH(15, 25);
152
153 EXPECT_EQ(rect.GetLeft(), 0);
154 EXPECT_EQ(rect.GetTop(), 0);
155 EXPECT_EQ(rect.GetRight(), 15);
156 EXPECT_EQ(rect.GetBottom(), 25);
157 EXPECT_EQ(rect.GetX(), 0);
158 EXPECT_EQ(rect.GetY(), 0);
159 EXPECT_EQ(rect.GetWidth(), 15);
160 EXPECT_EQ(rect.GetHeight(), 25);
161 EXPECT_FALSE(rect.IsEmpty());
162}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeWH().

◆ TEST() [437/689]

impeller::testing::TEST ( RectTest  ,
IRectSimpleXYWH   
)

Definition at line 119 of file rect_unittests.cc.

119 {
120 IRect rect = IRect::MakeXYWH(5, 10, 15, 16);
121
122 EXPECT_EQ(rect.GetLeft(), 5);
123 EXPECT_EQ(rect.GetTop(), 10);
124 EXPECT_EQ(rect.GetRight(), 20);
125 EXPECT_EQ(rect.GetBottom(), 26);
126 EXPECT_EQ(rect.GetX(), 5);
127 EXPECT_EQ(rect.GetY(), 10);
128 EXPECT_EQ(rect.GetWidth(), 15);
129 EXPECT_EQ(rect.GetHeight(), 16);
130 EXPECT_FALSE(rect.IsEmpty());
131}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeXYWH().

◆ TEST() [438/689]

impeller::testing::TEST ( RectTest  ,
IRectUnion   
)

Definition at line 1746 of file rect_unittests.cc.

1746 {
1747 auto check_empty_flips = [](const IRect& a, const IRect& b,
1748 const std::string& label) {
1749 ASSERT_FALSE(a.IsEmpty());
1750 // b is allowed to be empty
1751
1752 // unflipped a vs flipped (empty) b yields a
1753 EXPECT_EQ(a.Union(flip_lr(b)), a) << label;
1754 EXPECT_EQ(a.Union(flip_tb(b)), a) << label;
1755 EXPECT_EQ(a.Union(flip_lrtb(b)), a) << label;
1756
1757 // flipped (empty) a vs unflipped b yields b
1758 EXPECT_EQ(flip_lr(a).Union(b), b) << label;
1759 EXPECT_EQ(flip_tb(a).Union(b), b) << label;
1760 EXPECT_EQ(flip_lrtb(a).Union(b), b) << label;
1761
1762 // flipped (empty) a vs flipped (empty) b yields empty
1763 EXPECT_TRUE(flip_lr(a).Union(flip_lr(b)).IsEmpty()) << label;
1764 EXPECT_TRUE(flip_tb(a).Union(flip_tb(b)).IsEmpty()) << label;
1765 EXPECT_TRUE(flip_lrtb(a).Union(flip_lrtb(b)).IsEmpty()) << label;
1766 };
1767
1768 auto test = [&check_empty_flips](const IRect& a, const IRect& b,
1769 const IRect& result) {
1770 ASSERT_FALSE(a.IsEmpty()) << a;
1771 // b is allowed to be empty
1772
1773 std::stringstream stream;
1774 stream << a << " union " << b;
1775 auto label = stream.str();
1776
1777 EXPECT_EQ(a.Union(b), result) << label;
1778 EXPECT_EQ(b.Union(a), result) << label;
1779 check_empty_flips(a, b, label);
1780 };
1781
1782 {
1783 auto a = IRect::MakeXYWH(100, 100, 100, 100);
1784 auto b = IRect::MakeXYWH(0, 0, 0, 0);
1785 auto expected = IRect::MakeXYWH(100, 100, 100, 100);
1786 test(a, b, expected);
1787 }
1788
1789 {
1790 auto a = IRect::MakeXYWH(100, 100, 100, 100);
1791 auto b = IRect::MakeXYWH(0, 0, 1, 1);
1792 auto expected = IRect::MakeXYWH(0, 0, 200, 200);
1793 test(a, b, expected);
1794 }
1795
1796 {
1797 auto a = IRect::MakeXYWH(100, 100, 100, 100);
1798 auto b = IRect::MakeXYWH(10, 10, 1, 1);
1799 auto expected = IRect::MakeXYWH(10, 10, 190, 190);
1800 test(a, b, expected);
1801 }
1802
1803 {
1804 auto a = IRect::MakeXYWH(0, 0, 100, 100);
1805 auto b = IRect::MakeXYWH(10, 10, 100, 100);
1806 auto expected = IRect::MakeXYWH(0, 0, 110, 110);
1807 test(a, b, expected);
1808 }
1809
1810 {
1811 auto a = IRect::MakeXYWH(0, 0, 100, 100);
1812 auto b = IRect::MakeXYWH(100, 100, 100, 100);
1813 auto expected = IRect::MakeXYWH(0, 0, 200, 200);
1814 test(a, b, expected);
1815 }
1816}
constexpr TRect Union(const TRect &o) const
Definition rect.h:547

References flip_lr(), flip_lrtb(), flip_tb(), impeller::TRect< T >::IsEmpty(), impeller::TRect< T >::MakeXYWH(), and impeller::TRect< T >::Union().

◆ TEST() [439/689]

impeller::testing::TEST ( RectTest  ,
IRectXYWHIsEmpty   
)

Definition at line 1320 of file rect_unittests.cc.

1320 {
1321 // Non-empty
1322 EXPECT_FALSE(IRect::MakeXYWH(1, 2, 10, 7).IsEmpty());
1323
1324 // Empty both width and height both 0 or negative, in all combinations
1325 EXPECT_TRUE(IRect::MakeXYWH(1, 2, 0, 0).IsEmpty());
1326 EXPECT_TRUE(IRect::MakeXYWH(1, 2, -1, -1).IsEmpty());
1327 EXPECT_TRUE(IRect::MakeXYWH(1, 2, -1, 0).IsEmpty());
1328 EXPECT_TRUE(IRect::MakeXYWH(1, 2, 0, -1).IsEmpty());
1329
1330 // Empty for 0 or negative width or height (but not both at the same time)
1331 EXPECT_TRUE(IRect::MakeXYWH(1, 2, 10, 0).IsEmpty());
1332 EXPECT_TRUE(IRect::MakeXYWH(1, 2, 10, -1).IsEmpty());
1333 EXPECT_TRUE(IRect::MakeXYWH(1, 2, 0, 7).IsEmpty());
1334 EXPECT_TRUE(IRect::MakeXYWH(1, 2, -1, 7).IsEmpty());
1335}

References impeller::TRect< T >::MakeXYWH().

◆ TEST() [440/689]

impeller::testing::TEST ( RectTest  ,
IsSquare   
)

Definition at line 1351 of file rect_unittests.cc.

1351 {
1352 EXPECT_TRUE(Rect::MakeXYWH(10, 30, 20, 20).IsSquare());
1353 EXPECT_FALSE(Rect::MakeXYWH(10, 30, 20, 19).IsSquare());
1354 EXPECT_FALSE(Rect::MakeXYWH(10, 30, 19, 20).IsSquare());
1355 EXPECT_TRUE(Rect::MakeMaximum().IsSquare());
1356
1357 EXPECT_TRUE(IRect::MakeXYWH(10, 30, 20, 20).IsSquare());
1358 EXPECT_FALSE(IRect::MakeXYWH(10, 30, 20, 19).IsSquare());
1359 EXPECT_FALSE(IRect::MakeXYWH(10, 30, 19, 20).IsSquare());
1360 EXPECT_TRUE(IRect::MakeMaximum().IsSquare());
1361}

References impeller::TRect< T >::MakeMaximum(), impeller::TRect< Scalar >::MakeMaximum(), impeller::TRect< T >::MakeXYWH(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [441/689]

impeller::testing::TEST ( RectTest  ,
MakePointBoundsQuad   
)

Definition at line 1337 of file rect_unittests.cc.

1337 {
1338 Quad quad = {
1339 Point(10, 10),
1340 Point(20, 10),
1341 Point(10, 20),
1342 Point(20, 20),
1343 };
1344 std::optional<Rect> bounds = Rect::MakePointBounds(quad);
1345 EXPECT_TRUE(bounds.has_value());
1346 if (bounds.has_value()) {
1347 EXPECT_TRUE(RectNear(bounds.value(), Rect::MakeLTRB(10, 10, 20, 20)));
1348 }
1349}
inline ::testing::AssertionResult RectNear(impeller::Rect a, impeller::Rect b)
std::array< Point, 4 > Quad
Definition point.h:431

References impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakePointBounds(), and RectNear().

◆ TEST() [442/689]

impeller::testing::TEST ( RectTest  ,
OptIRectIntersection   
)

Definition at line 2144 of file rect_unittests.cc.

2144 {
2145 auto a = IRect::MakeLTRB(0, 0, 110, 110);
2146 auto b = IRect::MakeLTRB(100, 100, 200, 200);
2147 auto c = IRect::MakeLTRB(100, 0, 200, 110);
2148
2149 // NullOpt, NullOpt
2150 EXPECT_FALSE(IRect::Intersection(std::nullopt, std::nullopt).has_value());
2151 EXPECT_EQ(IRect::Intersection(std::nullopt, std::nullopt), std::nullopt);
2152
2153 auto test1 = [](const IRect& r) {
2154 // Rect, NullOpt
2155 EXPECT_TRUE(IRect::Intersection(r, std::nullopt).has_value());
2156 EXPECT_EQ(IRect::Intersection(r, std::nullopt).value(), r);
2157
2158 // OptRect, NullOpt
2159 EXPECT_TRUE(
2160 IRect::Intersection(std::optional(r), std::nullopt).has_value());
2161 EXPECT_EQ(IRect::Intersection(std::optional(r), std::nullopt).value(), r);
2162
2163 // NullOpt, Rect
2164 EXPECT_TRUE(IRect::Intersection(std::nullopt, r).has_value());
2165 EXPECT_EQ(IRect::Intersection(std::nullopt, r).value(), r);
2166
2167 // NullOpt, OptRect
2168 EXPECT_TRUE(
2169 IRect::Intersection(std::nullopt, std::optional(r)).has_value());
2170 EXPECT_EQ(IRect::Intersection(std::nullopt, std::optional(r)).value(), r);
2171 };
2172
2173 test1(a);
2174 test1(b);
2175 test1(c);
2176
2177 auto test2 = [](const IRect& a, const IRect& b, const IRect& i) {
2178 ASSERT_EQ(a.Intersection(b), i);
2179
2180 // Rect, OptRect
2181 EXPECT_TRUE(IRect::Intersection(a, std::optional(b)).has_value());
2182 EXPECT_EQ(IRect::Intersection(a, std::optional(b)).value(), i);
2183
2184 // OptRect, Rect
2185 EXPECT_TRUE(IRect::Intersection(std::optional(a), b).has_value());
2186 EXPECT_EQ(IRect::Intersection(std::optional(a), b).value(), i);
2187
2188 // OptRect, OptRect
2189 EXPECT_TRUE(
2190 IRect::Intersection(std::optional(a), std::optional(b)).has_value());
2191 EXPECT_EQ(IRect::Intersection(std::optional(a), std::optional(b)).value(),
2192 i);
2193 };
2194
2195 test2(a, b, IRect::MakeLTRB(100, 100, 110, 110));
2196 test2(a, c, IRect::MakeLTRB(100, 0, 110, 110));
2197 test2(b, c, IRect::MakeLTRB(100, 100, 200, 110));
2198}

References c, i, impeller::TRect< T >::Intersection(), impeller::TRect< T >::MakeLTRB(), and value.

◆ TEST() [443/689]

impeller::testing::TEST ( RectTest  ,
OptIRectUnion   
)

Definition at line 1818 of file rect_unittests.cc.

1818 {
1819 auto a = IRect::MakeLTRB(0, 0, 100, 100);
1820 auto b = IRect::MakeLTRB(100, 100, 200, 200);
1821 auto c = IRect::MakeLTRB(100, 0, 200, 100);
1822
1823 // NullOpt, NullOpt
1824 EXPECT_FALSE(IRect::Union(std::nullopt, std::nullopt).has_value());
1825 EXPECT_EQ(IRect::Union(std::nullopt, std::nullopt), std::nullopt);
1826
1827 auto test1 = [](const IRect& r) {
1828 // Rect, NullOpt
1829 EXPECT_EQ(IRect::Union(r, std::nullopt), r);
1830
1831 // OptRect, NullOpt
1832 EXPECT_TRUE(IRect::Union(std::optional(r), std::nullopt).has_value());
1833 EXPECT_EQ(IRect::Union(std::optional(r), std::nullopt).value(), r);
1834
1835 // NullOpt, Rect
1836 EXPECT_EQ(IRect::Union(std::nullopt, r), r);
1837
1838 // NullOpt, OptRect
1839 EXPECT_TRUE(IRect::Union(std::nullopt, std::optional(r)).has_value());
1840 EXPECT_EQ(IRect::Union(std::nullopt, std::optional(r)).value(), r);
1841 };
1842
1843 test1(a);
1844 test1(b);
1845 test1(c);
1846
1847 auto test2 = [](const IRect& a, const IRect& b, const IRect& u) {
1848 ASSERT_EQ(a.Union(b), u);
1849
1850 // Rect, OptRect
1851 EXPECT_EQ(IRect::Union(a, std::optional(b)), u);
1852
1853 // OptRect, Rect
1854 EXPECT_EQ(IRect::Union(std::optional(a), b), u);
1855
1856 // OptRect, OptRect
1857 EXPECT_TRUE(IRect::Union(std::optional(a), std::optional(b)).has_value());
1858 EXPECT_EQ(IRect::Union(std::optional(a), std::optional(b)).value(), u);
1859 };
1860
1861 test2(a, b, IRect::MakeLTRB(0, 0, 200, 200));
1862 test2(a, c, IRect::MakeLTRB(0, 0, 200, 100));
1863 test2(b, c, IRect::MakeLTRB(100, 0, 200, 200));
1864}

References c, impeller::TRect< T >::MakeLTRB(), impeller::TRect< T >::Union(), and value.

◆ TEST() [444/689]

impeller::testing::TEST ( RectTest  ,
OptRectIntersection   
)

Definition at line 1995 of file rect_unittests.cc.

1995 {
1996 auto a = Rect::MakeLTRB(0, 0, 110, 110);
1997 auto b = Rect::MakeLTRB(100, 100, 200, 200);
1998 auto c = Rect::MakeLTRB(100, 0, 200, 110);
1999
2000 // NullOpt, NullOpt
2001 EXPECT_FALSE(Rect::Intersection(std::nullopt, std::nullopt).has_value());
2002 EXPECT_EQ(Rect::Intersection(std::nullopt, std::nullopt), std::nullopt);
2003
2004 auto test1 = [](const Rect& r) {
2005 // Rect, NullOpt
2006 EXPECT_TRUE(Rect::Intersection(r, std::nullopt).has_value());
2007 EXPECT_EQ(Rect::Intersection(r, std::nullopt).value(), r);
2008
2009 // OptRect, NullOpt
2010 EXPECT_TRUE(Rect::Intersection(std::optional(r), std::nullopt).has_value());
2011 EXPECT_EQ(Rect::Intersection(std::optional(r), std::nullopt).value(), r);
2012
2013 // NullOpt, Rect
2014 EXPECT_TRUE(Rect::Intersection(std::nullopt, r).has_value());
2015 EXPECT_EQ(Rect::Intersection(std::nullopt, r).value(), r);
2016
2017 // NullOpt, OptRect
2018 EXPECT_TRUE(Rect::Intersection(std::nullopt, std::optional(r)).has_value());
2019 EXPECT_EQ(Rect::Intersection(std::nullopt, std::optional(r)).value(), r);
2020 };
2021
2022 test1(a);
2023 test1(b);
2024 test1(c);
2025
2026 auto test2 = [](const Rect& a, const Rect& b, const Rect& i) {
2027 ASSERT_EQ(a.Intersection(b), i);
2028
2029 // Rect, OptRect
2030 EXPECT_TRUE(Rect::Intersection(a, std::optional(b)).has_value());
2031 EXPECT_EQ(Rect::Intersection(a, std::optional(b)).value(), i);
2032
2033 // OptRect, Rect
2034 EXPECT_TRUE(Rect::Intersection(std::optional(a), b).has_value());
2035 EXPECT_EQ(Rect::Intersection(std::optional(a), b).value(), i);
2036
2037 // OptRect, OptRect
2038 EXPECT_TRUE(
2039 Rect::Intersection(std::optional(a), std::optional(b)).has_value());
2040 EXPECT_EQ(Rect::Intersection(std::optional(a), std::optional(b)).value(),
2041 i);
2042 };
2043
2044 test2(a, b, Rect::MakeLTRB(100, 100, 110, 110));
2045 test2(a, c, Rect::MakeLTRB(100, 0, 110, 110));
2046 test2(b, c, Rect::MakeLTRB(100, 100, 200, 110));
2047}

References c, i, impeller::TRect< Scalar >::Intersection(), impeller::TRect< Scalar >::MakeLTRB(), and value.

◆ TEST() [445/689]

impeller::testing::TEST ( RectTest  ,
OptRectUnion   
)

Definition at line 1698 of file rect_unittests.cc.

1698 {
1699 auto a = Rect::MakeLTRB(0, 0, 100, 100);
1700 auto b = Rect::MakeLTRB(100, 100, 200, 200);
1701 auto c = Rect::MakeLTRB(100, 0, 200, 100);
1702
1703 // NullOpt, NullOpt
1704 EXPECT_FALSE(Rect::Union(std::nullopt, std::nullopt).has_value());
1705 EXPECT_EQ(Rect::Union(std::nullopt, std::nullopt), std::nullopt);
1706
1707 auto test1 = [](const Rect& r) {
1708 // Rect, NullOpt
1709 EXPECT_EQ(Rect::Union(r, std::nullopt), r);
1710
1711 // OptRect, NullOpt
1712 EXPECT_TRUE(Rect::Union(std::optional(r), std::nullopt).has_value());
1713 EXPECT_EQ(Rect::Union(std::optional(r), std::nullopt).value(), r);
1714
1715 // NullOpt, Rect
1716 EXPECT_EQ(Rect::Union(std::nullopt, r), r);
1717
1718 // NullOpt, OptRect
1719 EXPECT_TRUE(Rect::Union(std::nullopt, std::optional(r)).has_value());
1720 EXPECT_EQ(Rect::Union(std::nullopt, std::optional(r)).value(), r);
1721 };
1722
1723 test1(a);
1724 test1(b);
1725 test1(c);
1726
1727 auto test2 = [](const Rect& a, const Rect& b, const Rect& u) {
1728 ASSERT_EQ(a.Union(b), u);
1729
1730 // Rect, OptRect
1731 EXPECT_EQ(Rect::Union(a, std::optional(b)), u);
1732
1733 // OptRect, Rect
1734 EXPECT_EQ(Rect::Union(std::optional(a), b), u);
1735
1736 // OptRect, OptRect
1737 EXPECT_TRUE(Rect::Union(std::optional(a), std::optional(b)).has_value());
1738 EXPECT_EQ(Rect::Union(std::optional(a), std::optional(b)).value(), u);
1739 };
1740
1741 test2(a, b, Rect::MakeLTRB(0, 0, 200, 200));
1742 test2(a, c, Rect::MakeLTRB(0, 0, 200, 100));
1743 test2(b, c, Rect::MakeLTRB(100, 0, 200, 200));
1744}

References c, impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::Union(), and value.

◆ TEST() [446/689]

impeller::testing::TEST ( RectTest  ,
RectArea   
)

Definition at line 1140 of file rect_unittests.cc.

1140 {
1141 EXPECT_EQ(Rect::MakeXYWH(0, 0, 100, 200).Area(), 20000);
1142 EXPECT_EQ(Rect::MakeXYWH(10, 20, 100, 200).Area(), 20000);
1143 EXPECT_EQ(Rect::MakeXYWH(0, 0, 200, 100).Area(), 20000);
1144 EXPECT_EQ(Rect::MakeXYWH(10, 20, 200, 100).Area(), 20000);
1145 EXPECT_EQ(Rect::MakeXYWH(0, 0, 100, 100).Area(), 10000);
1146 EXPECT_EQ(Rect::MakeXYWH(10, 20, 100, 100).Area(), 10000);
1147}

References impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [447/689]

impeller::testing::TEST ( RectTest  ,
RectContainsInclusivePoint   
)

Definition at line 2560 of file rect_unittests.cc.

2560 {
2561 auto check_nans = [](const Rect& rect, const Point& point,
2562 const std::string& label) {
2563 ASSERT_TRUE(rect.IsFinite()) << label;
2564 ASSERT_TRUE(point.IsFinite()) << label;
2565
2566 for (int i = 1; i < 16; i++) {
2567 EXPECT_FALSE(swap_nan(rect, i).ContainsInclusive(point))
2568 << label << ", index = " << i;
2569 for (int j = 1; j < 4; j++) {
2570 EXPECT_FALSE(swap_nan(rect, i).ContainsInclusive(swap_nan(point, j)))
2571 << label << ", indices = " << i << ", " << j;
2572 }
2573 }
2574 };
2575
2576 auto check_empty_flips = [](const Rect& rect, const Point& point,
2577 const std::string& label) {
2578 ASSERT_FALSE(rect.IsEmpty());
2579
2580 EXPECT_FALSE(flip_lr(rect).ContainsInclusive(point)) << label;
2581 EXPECT_FALSE(flip_tb(rect).ContainsInclusive(point)) << label;
2582 EXPECT_FALSE(flip_lrtb(rect).ContainsInclusive(point)) << label;
2583 };
2584
2585 auto test_inside = [&check_nans, &check_empty_flips](const Rect& rect,
2586 const Point& point) {
2587 ASSERT_FALSE(rect.IsEmpty()) << rect;
2588
2589 std::stringstream stream;
2590 stream << rect << " contains " << point;
2591 auto label = stream.str();
2592
2593 EXPECT_TRUE(rect.ContainsInclusive(point)) << label;
2594 check_empty_flips(rect, point, label);
2595 check_nans(rect, point, label);
2596 };
2597
2598 auto test_outside = [&check_nans, &check_empty_flips](const Rect& rect,
2599 const Point& point) {
2600 ASSERT_FALSE(rect.IsEmpty()) << rect;
2601
2602 std::stringstream stream;
2603 stream << rect << " contains " << point;
2604 auto label = stream.str();
2605
2606 EXPECT_FALSE(rect.ContainsInclusive(point)) << label;
2607 check_empty_flips(rect, point, label);
2608 check_nans(rect, point, label);
2609 };
2610
2611 {
2612 // Origin is inclusive
2613 auto r = Rect::MakeXYWH(100, 100, 100, 100);
2614 auto p = Point(100, 100);
2615
2616 test_inside(r, p);
2617 }
2618 {
2619 // Size is inclusive
2620 auto r = Rect::MakeXYWH(100, 100, 100, 100);
2621 auto p = Point(200, 200);
2622
2623 test_inside(r, p);
2624 }
2625 {
2626 // Size + epsilon is exclusive
2627 auto r = Rect::MakeXYWH(100, 100, 100, 100);
2628 auto p = Point(200 + kEhCloseEnough, 200 + kEhCloseEnough);
2629
2630 test_outside(r, p);
2631 }
2632 {
2633 auto r = Rect::MakeXYWH(100, 100, 100, 100);
2634 auto p = Point(99, 99);
2635
2636 test_outside(r, p);
2637 }
2638 {
2639 auto r = Rect::MakeXYWH(100, 100, 100, 100);
2640 auto p = Point(199, 199);
2641
2642 test_inside(r, p);
2643 }
2644
2645 {
2646 auto r = Rect::MakeMaximum();
2647 auto p = Point(199, 199);
2648
2649 test_inside(r, p);
2650 }
2651}
static constexpr Rect swap_nan(const Rect &rect, int index)

References flip_lr(), flip_lrtb(), flip_tb(), i, flutter::kEhCloseEnough, impeller::TRect< Scalar >::MakeMaximum(), impeller::TRect< Scalar >::MakeXYWH(), and swap_nan().

◆ TEST() [448/689]

impeller::testing::TEST ( RectTest  ,
RectContainsPoint   
)

Definition at line 2405 of file rect_unittests.cc.

2405 {
2406 auto check_nans = [](const Rect& rect, const Point& point,
2407 const std::string& label) {
2408 ASSERT_TRUE(rect.IsFinite()) << label;
2409 ASSERT_TRUE(point.IsFinite()) << label;
2410
2411 for (int i = 1; i < 16; i++) {
2412 EXPECT_FALSE(swap_nan(rect, i).Contains(point))
2413 << label << ", index = " << i;
2414 for (int j = 1; j < 4; j++) {
2415 EXPECT_FALSE(swap_nan(rect, i).Contains(swap_nan(point, j)))
2416 << label << ", indices = " << i << ", " << j;
2417 }
2418 }
2419 };
2420
2421 auto check_empty_flips = [](const Rect& rect, const Point& point,
2422 const std::string& label) {
2423 ASSERT_FALSE(rect.IsEmpty());
2424
2425 EXPECT_FALSE(flip_lr(rect).Contains(point)) << label;
2426 EXPECT_FALSE(flip_tb(rect).Contains(point)) << label;
2427 EXPECT_FALSE(flip_lrtb(rect).Contains(point)) << label;
2428 };
2429
2430 auto test_inside = [&check_nans, &check_empty_flips](const Rect& rect,
2431 const Point& point) {
2432 ASSERT_FALSE(rect.IsEmpty()) << rect;
2433
2434 std::stringstream stream;
2435 stream << rect << " contains " << point;
2436 auto label = stream.str();
2437
2438 EXPECT_TRUE(rect.Contains(point)) << label;
2439 check_empty_flips(rect, point, label);
2440 check_nans(rect, point, label);
2441 };
2442
2443 auto test_outside = [&check_nans, &check_empty_flips](const Rect& rect,
2444 const Point& point) {
2445 ASSERT_FALSE(rect.IsEmpty()) << rect;
2446
2447 std::stringstream stream;
2448 stream << rect << " contains " << point;
2449 auto label = stream.str();
2450
2451 EXPECT_FALSE(rect.Contains(point)) << label;
2452 check_empty_flips(rect, point, label);
2453 check_nans(rect, point, label);
2454 };
2455
2456 {
2457 // Origin is inclusive
2458 auto r = Rect::MakeXYWH(100, 100, 100, 100);
2459 auto p = Point(100, 100);
2460
2461 test_inside(r, p);
2462 }
2463 {
2464 // Size is exclusive
2465 auto r = Rect::MakeXYWH(100, 100, 100, 100);
2466 auto p = Point(200, 200);
2467
2468 test_outside(r, p);
2469 }
2470 {
2471 auto r = Rect::MakeXYWH(100, 100, 100, 100);
2472 auto p = Point(99, 99);
2473
2474 test_outside(r, p);
2475 }
2476 {
2477 auto r = Rect::MakeXYWH(100, 100, 100, 100);
2478 auto p = Point(199, 199);
2479
2480 test_inside(r, p);
2481 }
2482
2483 {
2484 auto r = Rect::MakeMaximum();
2485 auto p = Point(199, 199);
2486
2487 test_inside(r, p);
2488 }
2489}

References flip_lr(), flip_lrtb(), flip_tb(), i, impeller::TRect< Scalar >::MakeMaximum(), impeller::TRect< Scalar >::MakeXYWH(), and swap_nan().

◆ TEST() [449/689]

impeller::testing::TEST ( RectTest  ,
RectContainsRect   
)

Definition at line 2729 of file rect_unittests.cc.

2729 {
2730 auto check_nans = [](const Rect& a, const Rect& b, const std::string& label) {
2731 ASSERT_TRUE(a.IsFinite()) << label;
2732 ASSERT_TRUE(b.IsFinite()) << label;
2733 ASSERT_FALSE(a.IsEmpty());
2734
2735 for (int i = 1; i < 16; i++) {
2736 // NaN in a produces false
2737 EXPECT_FALSE(swap_nan(a, i).Contains(b)) << label << ", index = " << i;
2738 // NaN in b produces false
2739 EXPECT_TRUE(a.Contains(swap_nan(b, i))) << label << ", index = " << i;
2740 // NaN in both is false
2741 for (int j = 1; j < 16; j++) {
2742 EXPECT_FALSE(swap_nan(a, i).Contains(swap_nan(b, j)))
2743 << label << ", indices = " << i << ", " << j;
2744 }
2745 }
2746 };
2747
2748 auto check_empty_flips = [](const Rect& a, const Rect& b,
2749 const std::string& label) {
2750 ASSERT_FALSE(a.IsEmpty());
2751 // test b rects are allowed to have 0 w/h, but not be backwards
2752 ASSERT_FALSE(b.GetLeft() > b.GetRight() || b.GetTop() > b.GetBottom());
2753
2754 // unflipped a vs flipped (empty) b yields false
2755 EXPECT_TRUE(a.Contains(flip_lr(b))) << label;
2756 EXPECT_TRUE(a.Contains(flip_tb(b))) << label;
2757 EXPECT_TRUE(a.Contains(flip_lrtb(b))) << label;
2758
2759 // flipped (empty) a vs unflipped b yields false
2760 EXPECT_FALSE(flip_lr(a).Contains(b)) << label;
2761 EXPECT_FALSE(flip_tb(a).Contains(b)) << label;
2762 EXPECT_FALSE(flip_lrtb(a).Contains(b)) << label;
2763
2764 // flipped (empty) a vs flipped (empty) b yields empty
2765 EXPECT_FALSE(flip_lr(a).Contains(flip_lr(b))) << label;
2766 EXPECT_FALSE(flip_tb(a).Contains(flip_tb(b))) << label;
2767 EXPECT_FALSE(flip_lrtb(a).Contains(flip_lrtb(b))) << label;
2768 };
2769
2770 auto test_inside = [&check_nans, &check_empty_flips](const Rect& a,
2771 const Rect& b) {
2772 ASSERT_FALSE(a.IsEmpty()) << a;
2773 // test b rects are allowed to have 0 w/h, but not be backwards
2774 ASSERT_FALSE(b.GetLeft() > b.GetRight() || b.GetTop() > b.GetBottom());
2775
2776 std::stringstream stream;
2777 stream << a << " contains " << b;
2778 auto label = stream.str();
2779
2780 EXPECT_TRUE(a.Contains(b)) << label;
2781 check_empty_flips(a, b, label);
2782 check_nans(a, b, label);
2783 };
2784
2785 auto test_not_inside = [&check_nans, &check_empty_flips](const Rect& a,
2786 const Rect& b) {
2787 ASSERT_FALSE(a.IsEmpty()) << a;
2788 // If b was empty, it would be contained and should not be tested with
2789 // this function - use |test_inside| instead.
2790 ASSERT_FALSE(b.IsEmpty()) << b;
2791
2792 std::stringstream stream;
2793 stream << a << " contains " << b;
2794 auto label = stream.str();
2795
2796 EXPECT_FALSE(a.Contains(b)) << label;
2797 check_empty_flips(a, b, label);
2798 check_nans(a, b, label);
2799 };
2800
2801 {
2802 auto a = Rect::MakeXYWH(100, 100, 100, 100);
2803
2804 test_inside(a, a);
2805 }
2806 {
2807 auto a = Rect::MakeXYWH(100, 100, 100, 100);
2808 auto b = Rect::MakeXYWH(0, 0, 0, 0);
2809
2810 test_inside(a, b);
2811 }
2812 {
2813 auto a = Rect::MakeXYWH(100, 100, 100, 100);
2814 auto b = Rect::MakeXYWH(150, 150, 20, 20);
2815
2816 test_inside(a, b);
2817 }
2818 {
2819 auto a = Rect::MakeXYWH(100, 100, 100, 100);
2820 auto b = Rect::MakeXYWH(150, 150, 100, 100);
2821
2822 test_not_inside(a, b);
2823 }
2824 {
2825 auto a = Rect::MakeXYWH(100, 100, 100, 100);
2826 auto b = Rect::MakeXYWH(50, 50, 100, 100);
2827
2828 test_not_inside(a, b);
2829 }
2830 {
2831 auto a = Rect::MakeXYWH(100, 100, 100, 100);
2832 auto b = Rect::MakeXYWH(0, 0, 300, 300);
2833
2834 test_not_inside(a, b);
2835 }
2836 {
2837 auto a = Rect::MakeMaximum();
2838 auto b = Rect::MakeXYWH(0, 0, 300, 300);
2839
2840 test_inside(a, b);
2841 }
2842}

References flip_lr(), flip_lrtb(), flip_tb(), i, impeller::TRect< Scalar >::MakeMaximum(), impeller::TRect< Scalar >::MakeXYWH(), and swap_nan().

◆ TEST() [450/689]

impeller::testing::TEST ( RectTest  ,
RectCopy   
)

Definition at line 792 of file rect_unittests.cc.

792 {
793 // Using fractional-power-of-2 friendly values for equality tests
794 Rect rect = Rect::MakeLTRB(5.125f, 10.25f, 20.625f, 25.375f);
795 Rect copy = rect;
796
797 EXPECT_EQ(rect, copy);
798 EXPECT_EQ(copy.GetLeft(), 5.125f);
799 EXPECT_EQ(copy.GetTop(), 10.25f);
800 EXPECT_EQ(copy.GetRight(), 20.625f);
801 EXPECT_EQ(copy.GetBottom(), 25.375f);
802 EXPECT_EQ(copy.GetX(), 5.125f);
803 EXPECT_EQ(copy.GetY(), 10.25f);
804 EXPECT_EQ(copy.GetWidth(), 15.5f);
805 EXPECT_EQ(copy.GetHeight(), 15.125f);
806 EXPECT_FALSE(copy.IsEmpty());
807 EXPECT_TRUE(copy.IsFinite());
808}

References impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [451/689]

impeller::testing::TEST ( RectTest  ,
RectCutOut   
)

Definition at line 2937 of file rect_unittests.cc.

2937 {
2938 Rect cull_rect = Rect::MakeLTRB(20, 20, 40, 40);
2939
2940 auto check_nans = [&cull_rect](const Rect& diff_rect,
2941 const std::string& label) {
2942 EXPECT_TRUE(cull_rect.IsFinite()) << label;
2943 EXPECT_TRUE(diff_rect.IsFinite()) << label;
2944
2945 for (int i = 1; i < 16; i++) {
2946 // NaN in cull_rect produces empty
2947 EXPECT_FALSE(swap_nan(cull_rect, i).Cutout(diff_rect).has_value())
2948 << label << ", index " << i;
2949 EXPECT_EQ(swap_nan(cull_rect, i).CutoutOrEmpty(diff_rect), Rect())
2950 << label << ", index " << i;
2951
2952 // NaN in diff_rect is nop
2953 EXPECT_TRUE(cull_rect.Cutout(swap_nan(diff_rect, i)).has_value())
2954 << label << ", index " << i;
2955 EXPECT_EQ(cull_rect.CutoutOrEmpty(swap_nan(diff_rect, i)), cull_rect)
2956 << label << ", index " << i;
2957
2958 for (int j = 1; j < 16; j++) {
2959 // NaN in both is also empty
2960 EXPECT_FALSE(
2961 swap_nan(cull_rect, i).Cutout(swap_nan(diff_rect, j)).has_value())
2962 << label << ", indices " << i << ", " << j;
2963 EXPECT_EQ(swap_nan(cull_rect, i).CutoutOrEmpty(swap_nan(diff_rect, j)),
2964 Rect())
2965 << label << ", indices " << i << ", " << j;
2966 }
2967 }
2968 };
2969
2970 auto check_empty_flips = [&cull_rect](const Rect& diff_rect,
2971 const std::string& label) {
2972 EXPECT_FALSE(cull_rect.IsEmpty()) << label;
2973 EXPECT_FALSE(diff_rect.IsEmpty()) << label;
2974
2975 // unflipped cull_rect vs flipped(empty) diff_rect
2976 // == cull_rect
2977 EXPECT_TRUE(cull_rect.Cutout(flip_lr(diff_rect)).has_value()) << label;
2978 EXPECT_EQ(cull_rect.Cutout(flip_lr(diff_rect)), cull_rect) << label;
2979 EXPECT_TRUE(cull_rect.Cutout(flip_tb(diff_rect)).has_value()) << label;
2980 EXPECT_EQ(cull_rect.Cutout(flip_tb(diff_rect)), cull_rect) << label;
2981 EXPECT_TRUE(cull_rect.Cutout(flip_lrtb(diff_rect)).has_value()) << label;
2982 EXPECT_EQ(cull_rect.Cutout(flip_lrtb(diff_rect)), cull_rect) << label;
2983
2984 // flipped(empty) cull_rect vs unflipped diff_rect
2985 // == empty
2986 EXPECT_FALSE(flip_lr(cull_rect).Cutout(diff_rect).has_value()) << label;
2987 EXPECT_EQ(flip_lr(cull_rect).CutoutOrEmpty(diff_rect), Rect()) << label;
2988 EXPECT_FALSE(flip_tb(cull_rect).Cutout(diff_rect).has_value()) << label;
2989 EXPECT_EQ(flip_tb(cull_rect).CutoutOrEmpty(diff_rect), Rect()) << label;
2990 EXPECT_FALSE(flip_lrtb(cull_rect).Cutout(diff_rect).has_value()) << label;
2991 EXPECT_EQ(flip_lrtb(cull_rect).CutoutOrEmpty(diff_rect), Rect()) << label;
2992
2993 // flipped(empty) cull_rect vs flipped(empty) diff_rect
2994 // == empty
2995 EXPECT_FALSE(flip_lr(cull_rect).Cutout(flip_lr(diff_rect)).has_value())
2996 << label;
2997 EXPECT_EQ(flip_lr(cull_rect).CutoutOrEmpty(flip_lr(diff_rect)), Rect())
2998 << label;
2999 EXPECT_FALSE(flip_tb(cull_rect).Cutout(flip_tb(diff_rect)).has_value())
3000 << label;
3001 EXPECT_EQ(flip_tb(cull_rect).CutoutOrEmpty(flip_tb(diff_rect)), Rect())
3002 << label;
3003 EXPECT_FALSE(flip_lrtb(cull_rect).Cutout(flip_lrtb(diff_rect)).has_value())
3004 << label;
3005 EXPECT_EQ(flip_lrtb(cull_rect).CutoutOrEmpty(flip_lrtb(diff_rect)), Rect())
3006 << label;
3007 };
3008
3009 auto non_reducing = [&cull_rect, &check_empty_flips, &check_nans](
3010 const Rect& diff_rect, const std::string& label) {
3011 EXPECT_EQ(cull_rect.Cutout(diff_rect), cull_rect) << label;
3012 EXPECT_EQ(cull_rect.CutoutOrEmpty(diff_rect), cull_rect) << label;
3013 check_empty_flips(diff_rect, label);
3014 check_nans(diff_rect, label);
3015 };
3016
3017 auto reducing = [&cull_rect, &check_empty_flips, &check_nans](
3018 const Rect& diff_rect, const Rect& result_rect,
3019 const std::string& label) {
3020 EXPECT_TRUE(!result_rect.IsEmpty());
3021 EXPECT_EQ(cull_rect.Cutout(diff_rect), result_rect) << label;
3022 EXPECT_EQ(cull_rect.CutoutOrEmpty(diff_rect), result_rect) << label;
3023 check_empty_flips(diff_rect, label);
3024 check_nans(diff_rect, label);
3025 };
3026
3027 auto emptying = [&cull_rect, &check_empty_flips, &check_nans](
3028 const Rect& diff_rect, const std::string& label) {
3029 EXPECT_FALSE(cull_rect.Cutout(diff_rect).has_value()) << label;
3030 EXPECT_EQ(cull_rect.CutoutOrEmpty(diff_rect), Rect()) << label;
3031 check_empty_flips(diff_rect, label);
3032 check_nans(diff_rect, label);
3033 };
3034
3035 // Skim the corners and edge
3036 non_reducing(Rect::MakeLTRB(10, 10, 20, 20), "outside UL corner");
3037 non_reducing(Rect::MakeLTRB(20, 10, 40, 20), "Above");
3038 non_reducing(Rect::MakeLTRB(40, 10, 50, 20), "outside UR corner");
3039 non_reducing(Rect::MakeLTRB(40, 20, 50, 40), "Right");
3040 non_reducing(Rect::MakeLTRB(40, 40, 50, 50), "outside LR corner");
3041 non_reducing(Rect::MakeLTRB(20, 40, 40, 50), "Below");
3042 non_reducing(Rect::MakeLTRB(10, 40, 20, 50), "outside LR corner");
3043 non_reducing(Rect::MakeLTRB(10, 20, 20, 40), "Left");
3044
3045 // Overlap corners
3046 non_reducing(Rect::MakeLTRB(15, 15, 25, 25), "covering UL corner");
3047 non_reducing(Rect::MakeLTRB(35, 15, 45, 25), "covering UR corner");
3048 non_reducing(Rect::MakeLTRB(35, 35, 45, 45), "covering LR corner");
3049 non_reducing(Rect::MakeLTRB(15, 35, 25, 45), "covering LL corner");
3050
3051 // Overlap edges, but not across an entire side
3052 non_reducing(Rect::MakeLTRB(20, 15, 39, 25), "Top edge left-biased");
3053 non_reducing(Rect::MakeLTRB(21, 15, 40, 25), "Top edge, right biased");
3054 non_reducing(Rect::MakeLTRB(35, 20, 45, 39), "Right edge, top-biased");
3055 non_reducing(Rect::MakeLTRB(35, 21, 45, 40), "Right edge, bottom-biased");
3056 non_reducing(Rect::MakeLTRB(20, 35, 39, 45), "Bottom edge, left-biased");
3057 non_reducing(Rect::MakeLTRB(21, 35, 40, 45), "Bottom edge, right-biased");
3058 non_reducing(Rect::MakeLTRB(15, 20, 25, 39), "Left edge, top-biased");
3059 non_reducing(Rect::MakeLTRB(15, 21, 25, 40), "Left edge, bottom-biased");
3060
3061 // Slice all the way through the middle
3062 non_reducing(Rect::MakeLTRB(25, 15, 35, 45), "Vertical interior slice");
3063 non_reducing(Rect::MakeLTRB(15, 25, 45, 35), "Horizontal interior slice");
3064
3065 // Slice off each edge
3066 reducing(Rect::MakeLTRB(20, 15, 40, 25), //
3067 Rect::MakeLTRB(20, 25, 40, 40), //
3068 "Slice off top");
3069 reducing(Rect::MakeLTRB(35, 20, 45, 40), //
3070 Rect::MakeLTRB(20, 20, 35, 40), //
3071 "Slice off right");
3072 reducing(Rect::MakeLTRB(20, 35, 40, 45), //
3073 Rect::MakeLTRB(20, 20, 40, 35), //
3074 "Slice off bottom");
3075 reducing(Rect::MakeLTRB(15, 20, 25, 40), //
3076 Rect::MakeLTRB(25, 20, 40, 40), //
3077 "Slice off left");
3078
3079 // cull rect contains diff rect
3080 non_reducing(Rect::MakeLTRB(21, 21, 39, 39), "Contained, non-covering");
3081
3082 // cull rect equals diff rect
3083 emptying(cull_rect, "Perfectly covering");
3084
3085 // diff rect contains cull rect
3086 emptying(Rect::MakeLTRB(15, 15, 45, 45), "Smothering");
3087}

References flip_lr(), flip_lrtb(), flip_tb(), i, impeller::TRect< Scalar >::MakeLTRB(), and swap_nan().

◆ TEST() [452/689]

impeller::testing::TEST ( RectTest  ,
RectDefaultConstructor   
)

Definition at line 44 of file rect_unittests.cc.

44 {
45 Rect rect = Rect();
46
47 EXPECT_EQ(rect.GetLeft(), 0.0f);
48 EXPECT_EQ(rect.GetTop(), 0.0f);
49 EXPECT_EQ(rect.GetRight(), 0.0f);
50 EXPECT_EQ(rect.GetBottom(), 0.0f);
51 EXPECT_EQ(rect.GetX(), 0.0f);
52 EXPECT_EQ(rect.GetY(), 0.0f);
53 EXPECT_EQ(rect.GetWidth(), 0.0f);
54 EXPECT_EQ(rect.GetHeight(), 0.0f);
55 EXPECT_TRUE(rect.IsEmpty());
56 EXPECT_TRUE(rect.IsFinite());
57}

◆ TEST() [453/689]

impeller::testing::TEST ( RectTest  ,
RectDirections   
)

Definition at line 3279 of file rect_unittests.cc.

3279 {
3280 auto r = Rect::MakeLTRB(1, 2, 3, 4);
3281
3282 EXPECT_EQ(r.GetLeft(), 1);
3283 EXPECT_EQ(r.GetTop(), 2);
3284 EXPECT_EQ(r.GetRight(), 3);
3285 EXPECT_EQ(r.GetBottom(), 4);
3286
3287 EXPECT_POINT_NEAR(r.GetLeftTop(), Point(1, 2));
3288 EXPECT_POINT_NEAR(r.GetRightTop(), Point(3, 2));
3289 EXPECT_POINT_NEAR(r.GetLeftBottom(), Point(1, 4));
3290 EXPECT_POINT_NEAR(r.GetRightBottom(), Point(3, 4));
3291}

References EXPECT_POINT_NEAR, and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [454/689]

impeller::testing::TEST ( RectTest  ,
RectDoesNotIntersectEmpty   
)

Definition at line 933 of file rect_unittests.cc.

933 {
934 Rect rect = Rect::MakeLTRB(50, 50, 100, 100);
935
936 auto test = [&rect](Scalar l, Scalar t, Scalar r, Scalar b,
937 const std::string& label) {
938 EXPECT_FALSE(rect.IntersectsWithRect(Rect::MakeLTRB(l, b, r, t)))
939 << label << " with Top/Bottom swapped";
940 EXPECT_FALSE(rect.IntersectsWithRect(Rect::MakeLTRB(r, b, l, t)))
941 << label << " with Left/Right swapped";
942 EXPECT_FALSE(rect.IntersectsWithRect(Rect::MakeLTRB(r, t, l, b)))
943 << label << " with all sides swapped";
944 };
945
946 test(20, 20, 30, 30, "Above and Left");
947 test(70, 20, 80, 30, "Above");
948 test(120, 20, 130, 30, "Above and Right");
949 test(120, 70, 130, 80, "Right");
950 test(120, 120, 130, 130, "Below and Right");
951 test(70, 120, 80, 130, "Below");
952 test(20, 120, 30, 130, "Below and Left");
953 test(20, 70, 30, 80, "Left");
954
955 test(70, 70, 80, 80, "Inside");
956
957 test(40, 70, 60, 80, "Straddling Left");
958 test(70, 40, 80, 60, "Straddling Top");
959 test(90, 70, 110, 80, "Straddling Right");
960 test(70, 90, 80, 110, "Straddling Bottom");
961}

References impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [455/689]

impeller::testing::TEST ( RectTest  ,
RectEmptyDeclaration   
)

Definition at line 14 of file rect_unittests.cc.

14 {
15 Rect rect;
16
17 EXPECT_EQ(rect.GetLeft(), 0.0f);
18 EXPECT_EQ(rect.GetTop(), 0.0f);
19 EXPECT_EQ(rect.GetRight(), 0.0f);
20 EXPECT_EQ(rect.GetBottom(), 0.0f);
21 EXPECT_EQ(rect.GetX(), 0.0f);
22 EXPECT_EQ(rect.GetY(), 0.0f);
23 EXPECT_EQ(rect.GetWidth(), 0.0f);
24 EXPECT_EQ(rect.GetHeight(), 0.0f);
25 EXPECT_TRUE(rect.IsEmpty());
26 EXPECT_TRUE(rect.IsFinite());
27}

◆ TEST() [456/689]

impeller::testing::TEST ( RectTest  ,
RectExpand   
)

Definition at line 1374 of file rect_unittests.cc.

1374 {
1375 auto rect = Rect::MakeLTRB(100, 100, 200, 200);
1376
1377 // Expand(T amount)
1378 EXPECT_EQ(rect.Expand(10), Rect::MakeLTRB(90, 90, 210, 210));
1379 EXPECT_EQ(rect.Expand(-10), Rect::MakeLTRB(110, 110, 190, 190));
1380
1381 // Expand(amount, amount)
1382 EXPECT_EQ(rect.Expand(10, 10), Rect::MakeLTRB(90, 90, 210, 210));
1383 EXPECT_EQ(rect.Expand(10, -10), Rect::MakeLTRB(90, 110, 210, 190));
1384 EXPECT_EQ(rect.Expand(-10, 10), Rect::MakeLTRB(110, 90, 190, 210));
1385 EXPECT_EQ(rect.Expand(-10, -10), Rect::MakeLTRB(110, 110, 190, 190));
1386
1387 // Expand(amount, amount, amount, amount)
1388 EXPECT_EQ(rect.Expand(10, 20, 30, 40), Rect::MakeLTRB(90, 80, 230, 240));
1389 EXPECT_EQ(rect.Expand(-10, 20, 30, 40), Rect::MakeLTRB(110, 80, 230, 240));
1390 EXPECT_EQ(rect.Expand(10, -20, 30, 40), Rect::MakeLTRB(90, 120, 230, 240));
1391 EXPECT_EQ(rect.Expand(10, 20, -30, 40), Rect::MakeLTRB(90, 80, 170, 240));
1392 EXPECT_EQ(rect.Expand(10, 20, 30, -40), Rect::MakeLTRB(90, 80, 230, 160));
1393
1394 // Expand(Point amount)
1395 EXPECT_EQ(rect.Expand(Point{10, 10}), Rect::MakeLTRB(90, 90, 210, 210));
1396 EXPECT_EQ(rect.Expand(Point{10, -10}), Rect::MakeLTRB(90, 110, 210, 190));
1397 EXPECT_EQ(rect.Expand(Point{-10, 10}), Rect::MakeLTRB(110, 90, 190, 210));
1398 EXPECT_EQ(rect.Expand(Point{-10, -10}), Rect::MakeLTRB(110, 110, 190, 190));
1399
1400 // Expand(Size amount)
1401 EXPECT_EQ(rect.Expand(Size{10, 10}), Rect::MakeLTRB(90, 90, 210, 210));
1402 EXPECT_EQ(rect.Expand(Size{10, -10}), Rect::MakeLTRB(90, 110, 210, 190));
1403 EXPECT_EQ(rect.Expand(Size{-10, 10}), Rect::MakeLTRB(110, 90, 190, 210));
1404 EXPECT_EQ(rect.Expand(Size{-10, -10}), Rect::MakeLTRB(110, 110, 190, 190));
1405}

References impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [457/689]

impeller::testing::TEST ( RectTest  ,
RectExpandToMinTransformedSizeNullForScaledToZero   
)

Definition at line 1440 of file rect_unittests.cc.

1440 {
1441 auto rect = Rect();
1442 auto transform = Matrix::MakeScale(Vector3(0.0f, 1.0f));
1443 EXPECT_EQ(rect.ExpandToMinTransformedSize({1.0f, 1.0f}, transform),
1444 std::nullopt);
1445}

References impeller::Matrix::MakeScale(), and transform.

◆ TEST() [458/689]

impeller::testing::TEST ( RectTest  ,
RectExpandToMinTransformedSizeRectWithIdentityTransform   
)

Definition at line 1462 of file rect_unittests.cc.

1462 {
1463 Size size = Size(2.0f, 2.0f);
1464 Rect rect = Rect::MakeEllipseBounds(Point(), size * 0.5f);
1465
1466 auto transform = Matrix();
1467
1468 // Expand to a width and height less than the original size.
1469 {
1470 auto expanded = rect.ExpandToMinTransformedSize({0.5f, 0.75f}, transform);
1471 ASSERT_TRUE(expanded.has_value());
1472 if (expanded.has_value()) {
1473 EXPECT_EQ(expanded.value().GetSize(), size);
1474 }
1475 }
1476
1477 // Expand to a minimum width. Minimum height is less than the original size.
1478 {
1479 auto expanded = rect.ExpandToMinTransformedSize({4.0f, 1.5f}, transform);
1480 ASSERT_TRUE(expanded.has_value());
1481 if (expanded.has_value()) {
1482 EXPECT_EQ(expanded.value().GetSize(), Size(4.0f, 2.0f));
1483 }
1484 }
1485
1486 // Expand to a minimum height. Minimum width is less than the original size.
1487 {
1488 auto expanded = rect.ExpandToMinTransformedSize({1.5f, 4.0f}, transform);
1489 ASSERT_TRUE(expanded.has_value());
1490 if (expanded.has_value()) {
1491 EXPECT_EQ(expanded.value().GetSize(), Size(2.0f, 4.0f));
1492 }
1493 }
1494
1495 // Expand to a minimum width and height.
1496 {
1497 auto expanded = rect.ExpandToMinTransformedSize({3.0f, 4.0f}, transform);
1498 ASSERT_TRUE(expanded.has_value());
1499 if (expanded.has_value()) {
1500 EXPECT_EQ(expanded.value().GetSize(), Size(3.0f, 4.0f));
1501 }
1502 }
1503}
TSize< Scalar > Size
Definition size.h:159

References impeller::TRect< Scalar >::MakeEllipseBounds(), flutter::size, and transform.

◆ TEST() [459/689]

impeller::testing::TEST ( RectTest  ,
RectExpandToMinTransformedSizeRectWithScalingTransform   
)

Definition at line 1505 of file rect_unittests.cc.

1505 {
1506 Size size = Size(2.0f, 2.0f);
1507 Rect rect = Rect::MakeEllipseBounds(Point(), size * 0.5f);
1508
1509 // Scale by 2x in the X direction and 3x in the Y direction.
1510 // Transformed rect size is (4.0, 6.0).
1511 auto transform = Matrix::MakeScale(Vector3(2.0f, 3.0f));
1512
1513 // Expand to a transformed width and height less than the transformed size of
1514 // the original rectangle.
1515 {
1516 auto expanded = rect.ExpandToMinTransformedSize({3.0f, 4.0f}, transform);
1517 ASSERT_TRUE(expanded.has_value());
1518 if (expanded.has_value()) {
1519 EXPECT_EQ(expanded.value().GetSize(), size);
1520 }
1521 }
1522
1523 // Expand to 5.0 transformed width.
1524 // This is equal to 5.0 / 2.0 = 2.5 local width.
1525 {
1526 auto expanded = rect.ExpandToMinTransformedSize({5.0f, 4.0f}, transform);
1527 ASSERT_TRUE(expanded.has_value());
1528 if (expanded.has_value()) {
1529 EXPECT_EQ(expanded.value().GetSize(), Size(2.5f, 2.0f));
1530 }
1531 }
1532
1533 // Expand to 9.0 transformed height.
1534 // This is equal to 9.0 / 3.0 = 3.0 local height.
1535 {
1536 auto expanded = rect.ExpandToMinTransformedSize({3.0f, 9.0f}, transform);
1537 ASSERT_TRUE(expanded.has_value());
1538 if (expanded.has_value()) {
1539 EXPECT_EQ(expanded.value().GetSize(), Size(2.0f, 3.0));
1540 }
1541 }
1542
1543 // Expand both width and height.
1544 {
1545 auto expanded = rect.ExpandToMinTransformedSize({5.0f, 9.0f}, transform);
1546 ASSERT_TRUE(expanded.has_value());
1547 if (expanded.has_value()) {
1548 EXPECT_EQ(expanded.value().GetSize(), Size(2.5f, 3.0f));
1549 }
1550 }
1551}

References impeller::TRect< Scalar >::MakeEllipseBounds(), impeller::Matrix::MakeScale(), flutter::size, and transform.

◆ TEST() [460/689]

impeller::testing::TEST ( RectTest  ,
RectExpandToMinTransformedSizeReturnsUnmodifiedWhenLargeEnough   
)

Definition at line 1447 of file rect_unittests.cc.

1447 {
1448 Rect rect = Rect::MakeXYWH(0, 0, 10, 20);
1449 auto transform = Matrix::MakeScale(Vector3(0.5f, 0.5f));
1450 EXPECT_EQ(rect.ExpandToMinTransformedSize({1.0f, 1.0f}, transform), rect);
1451}

References impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeXYWH(), and transform.

◆ TEST() [461/689]

impeller::testing::TEST ( RectTest  ,
RectExpandToMinTransformedSizeReturnsUnmodifiedWhenLargeEnoughWithFractionalSize   
)

Definition at line 1453 of file rect_unittests.cc.

1455 {
1456 // Regression test for https://github.com/flutter/flutter/issues/189807.
1457 Rect rect = Rect::MakeXYWH(100.0f, 50.0f, 64.2f, 40.0f);
1458 auto transform = Matrix();
1459 EXPECT_EQ(rect.ExpandToMinTransformedSize({1.0f, 1.0f}, transform), rect);
1460}

References impeller::TRect< Scalar >::MakeXYWH(), and transform.

◆ TEST() [462/689]

impeller::testing::TEST ( RectTest  ,
RectFromIRect   
)

Definition at line 164 of file rect_unittests.cc.

164 {
165 IRect irect = IRect::MakeLTRB(10, 20, 30, 40);
166 Rect rect = Rect::Make(irect);
167
168 EXPECT_EQ(rect.GetLeft(), 10);
169 EXPECT_EQ(rect.GetTop(), 20);
170 EXPECT_EQ(rect.GetRight(), 30);
171 EXPECT_EQ(rect.GetBottom(), 40);
172
173 // The following do not compile
174 // IRect irect2 = IRect::Make(rect);
175 // IRect irect2 = IRect::Make(irect);
176}

References impeller::TRect< Scalar >::Make(), and impeller::TRect< T >::MakeLTRB().

◆ TEST() [463/689]

impeller::testing::TEST ( RectTest  ,
RectFromRect   
)

Definition at line 778 of file rect_unittests.cc.

778 {
779 EXPECT_EQ(Rect(Rect::MakeXYWH(2, 3, 7, 15)),
780 Rect::MakeXYWH(2.0, 3.0, 7.0, 15.0));
781 EXPECT_EQ(Rect(Rect::MakeLTRB(2, 3, 7, 15)),
782 Rect::MakeLTRB(2.0, 3.0, 7.0, 15.0));
783}

References impeller::TRect< Scalar >::MakeLTRB(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [464/689]

impeller::testing::TEST ( RectTest  ,
RectGetNormalizingTransform   
)

Definition at line 1158 of file rect_unittests.cc.

1158 {
1159 {
1160 // Checks for expected matrix values
1161
1162 auto r = Rect::MakeXYWH(100, 200, 200, 400);
1163
1164 EXPECT_EQ(r.GetNormalizingTransform(),
1165 Matrix::MakeScale({0.005, 0.0025, 1.0}) *
1166 Matrix::MakeTranslation({-100, -200}));
1167 }
1168
1169 {
1170 // Checks for expected transform of points relative to the rect
1171
1172 auto r = Rect::MakeLTRB(300, 500, 400, 700);
1173 auto m = r.GetNormalizingTransform();
1174
1175 // The 4 corners of the rect => (0, 0) to (1, 1)
1176 EXPECT_EQ(m * Point(300, 500), Point(0, 0));
1177 EXPECT_EQ(m * Point(400, 500), Point(1, 0));
1178 EXPECT_EQ(m * Point(400, 700), Point(1, 1));
1179 EXPECT_EQ(m * Point(300, 700), Point(0, 1));
1180
1181 // The center => (0.5, 0.5)
1182 EXPECT_EQ(m * Point(350, 600), Point(0.5, 0.5));
1183
1184 // Outside the 4 corners => (-1, -1) to (2, 2)
1185 EXPECT_EQ(m * Point(200, 300), Point(-1, -1));
1186 EXPECT_EQ(m * Point(500, 300), Point(2, -1));
1187 EXPECT_EQ(m * Point(500, 900), Point(2, 2));
1188 EXPECT_EQ(m * Point(200, 900), Point(-1, 2));
1189 }
1190
1191 {
1192 // Checks for behavior with empty rects
1193
1194 auto zero = Matrix::MakeScale({0.0, 0.0, 1.0});
1195
1196 // Empty for width and/or height == 0
1197 EXPECT_EQ(Rect::MakeXYWH(10, 10, 0, 10).GetNormalizingTransform(), zero);
1198 EXPECT_EQ(Rect::MakeXYWH(10, 10, 10, 0).GetNormalizingTransform(), zero);
1199 EXPECT_EQ(Rect::MakeXYWH(10, 10, 0, 0).GetNormalizingTransform(), zero);
1200
1201 // Empty for width and/or height < 0
1202 EXPECT_EQ(Rect::MakeXYWH(10, 10, -1, 10).GetNormalizingTransform(), zero);
1203 EXPECT_EQ(Rect::MakeXYWH(10, 10, 10, -1).GetNormalizingTransform(), zero);
1204 EXPECT_EQ(Rect::MakeXYWH(10, 10, -1, -1).GetNormalizingTransform(), zero);
1205 }
1206
1207 {
1208 // Checks for behavior with non-finite rects
1209
1210 auto z = Matrix::MakeScale({0.0, 0.0, 1.0});
1211 auto nan = std::numeric_limits<Scalar>::quiet_NaN();
1212 auto inf = std::numeric_limits<Scalar>::infinity();
1213
1214 // Non-finite for width and/or height == nan
1215 EXPECT_EQ(Rect::MakeXYWH(10, 10, nan, 10).GetNormalizingTransform(), z);
1216 EXPECT_EQ(Rect::MakeXYWH(10, 10, 10, nan).GetNormalizingTransform(), z);
1217 EXPECT_EQ(Rect::MakeXYWH(10, 10, nan, nan).GetNormalizingTransform(), z);
1218
1219 // Non-finite for width and/or height == inf
1220 EXPECT_EQ(Rect::MakeXYWH(10, 10, inf, 10).GetNormalizingTransform(), z);
1221 EXPECT_EQ(Rect::MakeXYWH(10, 10, 10, inf).GetNormalizingTransform(), z);
1222 EXPECT_EQ(Rect::MakeXYWH(10, 10, inf, inf).GetNormalizingTransform(), z);
1223
1224 // Non-finite for width and/or height == -inf
1225 EXPECT_EQ(Rect::MakeXYWH(10, 10, -inf, 10).GetNormalizingTransform(), z);
1226 EXPECT_EQ(Rect::MakeXYWH(10, 10, 10, -inf).GetNormalizingTransform(), z);
1227 EXPECT_EQ(Rect::MakeXYWH(10, 10, -inf, -inf).GetNormalizingTransform(), z);
1228
1229 // Non-finite for origin X and/or Y == nan
1230 EXPECT_EQ(Rect::MakeXYWH(nan, 10, 10, 10).GetNormalizingTransform(), z);
1231 EXPECT_EQ(Rect::MakeXYWH(10, nan, 10, 10).GetNormalizingTransform(), z);
1232 EXPECT_EQ(Rect::MakeXYWH(nan, nan, 10, 10).GetNormalizingTransform(), z);
1233
1234 // Non-finite for origin X and/or Y == inf
1235 EXPECT_EQ(Rect::MakeXYWH(inf, 10, 10, 10).GetNormalizingTransform(), z);
1236 EXPECT_EQ(Rect::MakeXYWH(10, inf, 10, 10).GetNormalizingTransform(), z);
1237 EXPECT_EQ(Rect::MakeXYWH(inf, inf, 10, 10).GetNormalizingTransform(), z);
1238
1239 // Non-finite for origin X and/or Y == -inf
1240 EXPECT_EQ(Rect::MakeXYWH(-inf, 10, 10, 10).GetNormalizingTransform(), z);
1241 EXPECT_EQ(Rect::MakeXYWH(10, -inf, 10, 10).GetNormalizingTransform(), z);
1242 EXPECT_EQ(Rect::MakeXYWH(-inf, -inf, 10, 10).GetNormalizingTransform(), z);
1243 }
1244}

References impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [465/689]

impeller::testing::TEST ( RectTest  ,
RectGetPoints   
)

Definition at line 3208 of file rect_unittests.cc.

3208 {
3209 {
3210 Rect r = Rect::MakeXYWH(100, 200, 300, 400);
3211 auto points = r.GetPoints();
3212 EXPECT_POINT_NEAR(points[0], Point(100, 200));
3213 EXPECT_POINT_NEAR(points[1], Point(400, 200));
3214 EXPECT_POINT_NEAR(points[2], Point(100, 600));
3215 EXPECT_POINT_NEAR(points[3], Point(400, 600));
3216 }
3217
3218 {
3219 Rect r = Rect::MakeMaximum();
3220 auto points = r.GetPoints();
3221 EXPECT_EQ(points[0], Point(std::numeric_limits<float>::lowest(),
3222 std::numeric_limits<float>::lowest()));
3223 EXPECT_EQ(points[1], Point(std::numeric_limits<float>::max(),
3224 std::numeric_limits<float>::lowest()));
3225 EXPECT_EQ(points[2], Point(std::numeric_limits<float>::lowest(),
3226 std::numeric_limits<float>::max()));
3227 EXPECT_EQ(points[3], Point(std::numeric_limits<float>::max(),
3228 std::numeric_limits<float>::max()));
3229 }
3230}
constexpr std::array< TPoint< T >, 4 > GetPoints() const
Get the points that represent the 4 corners of this rectangle in a Z order that is compatible with tr...
Definition rect.h:448

References EXPECT_POINT_NEAR, impeller::TRect< Scalar >::MakeMaximum(), impeller::TRect< Scalar >::MakeXYWH(), and points.

◆ TEST() [466/689]

impeller::testing::TEST ( RectTest  ,
RectGetPositive   
)

Definition at line 3265 of file rect_unittests.cc.

3265 {
3266 {
3267 Rect r = Rect::MakeXYWH(100, 200, 300, 400);
3268 auto actual = r.GetPositive();
3269 EXPECT_RECT_NEAR(r, actual);
3270 }
3271 {
3272 Rect r = Rect::MakeXYWH(100, 200, -100, -100);
3273 auto actual = r.GetPositive();
3274 Rect expected = Rect::MakeXYWH(0, 100, 100, 100);
3275 EXPECT_RECT_NEAR(expected, actual);
3276 }
3277}
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition rect.h:432

References EXPECT_RECT_NEAR, and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [467/689]

impeller::testing::TEST ( RectTest  ,
RectGetTransformedPoints   
)

Definition at line 3239 of file rect_unittests.cc.

3239 {
3240 Rect r = Rect::MakeXYWH(100, 200, 300, 400);
3241 auto points = r.GetTransformedPoints(Matrix::MakeTranslation({10, 20}));
3242 EXPECT_POINT_NEAR(points[0], Point(110, 220));
3243 EXPECT_POINT_NEAR(points[1], Point(410, 220));
3244 EXPECT_POINT_NEAR(points[2], Point(110, 620));
3245 EXPECT_POINT_NEAR(points[3], Point(410, 620));
3246}

References EXPECT_POINT_NEAR, impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), and points.

◆ TEST() [468/689]

impeller::testing::TEST ( RectTest  ,
RectIntersection   
)

Definition at line 1866 of file rect_unittests.cc.

1866 {
1867 auto check_nans = [](const Rect& a, const Rect& b, const std::string& label) {
1868 ASSERT_TRUE(a.IsFinite()) << label;
1869 ASSERT_TRUE(b.IsFinite()) << label;
1870
1871 for (int i = 1; i < 16; i++) {
1872 // NaN in a produces empty
1873 EXPECT_FALSE(swap_nan(a, i).Intersection(b).has_value())
1874 << label << ", index = " << i;
1875 // NaN in b produces empty
1876 EXPECT_FALSE(a.Intersection(swap_nan(b, i)).has_value())
1877 << label << ", index = " << i;
1878 // NaN in both is empty
1879 for (int j = 1; j < 16; j++) {
1880 EXPECT_FALSE(swap_nan(a, i).Intersection(swap_nan(b, j)).has_value())
1881 << label << ", indices = " << i << ", " << j;
1882 }
1883 }
1884 };
1885
1886 auto check_empty_flips = [](const Rect& a, const Rect& b,
1887 const std::string& label) {
1888 ASSERT_FALSE(a.IsEmpty());
1889 // b is allowed to be empty
1890
1891 // unflipped a vs flipped (empty) b yields a
1892 EXPECT_FALSE(a.Intersection(flip_lr(b)).has_value()) << label;
1893 EXPECT_TRUE(a.IntersectionOrEmpty(flip_lr(b)).IsEmpty()) << label;
1894 EXPECT_FALSE(a.Intersection(flip_tb(b)).has_value()) << label;
1895 EXPECT_TRUE(a.IntersectionOrEmpty(flip_tb(b)).IsEmpty()) << label;
1896 EXPECT_FALSE(a.Intersection(flip_lrtb(b)).has_value()) << label;
1897 EXPECT_TRUE(a.IntersectionOrEmpty(flip_lrtb(b)).IsEmpty()) << label;
1898
1899 // flipped (empty) a vs unflipped b yields b
1900 EXPECT_FALSE(flip_lr(a).Intersection(b).has_value()) << label;
1901 EXPECT_TRUE(flip_lr(a).IntersectionOrEmpty(b).IsEmpty()) << label;
1902 EXPECT_FALSE(flip_tb(a).Intersection(b).has_value()) << label;
1903 EXPECT_TRUE(flip_tb(a).IntersectionOrEmpty(b).IsEmpty()) << label;
1904 EXPECT_FALSE(flip_lrtb(a).Intersection(b).has_value()) << label;
1905 EXPECT_TRUE(flip_lrtb(a).IntersectionOrEmpty(b).IsEmpty()) << label;
1906
1907 // flipped (empty) a vs flipped (empty) b yields empty
1908 EXPECT_FALSE(flip_lr(a).Intersection(flip_lr(b)).has_value()) << label;
1909 EXPECT_TRUE(flip_lr(a).IntersectionOrEmpty(flip_lr(b)).IsEmpty()) << label;
1910 EXPECT_FALSE(flip_tb(a).Intersection(flip_tb(b)).has_value()) << label;
1911 EXPECT_TRUE(flip_tb(a).IntersectionOrEmpty(flip_tb(b)).IsEmpty()) << label;
1912 EXPECT_FALSE(flip_lrtb(a).Intersection(flip_lrtb(b)).has_value()) << label;
1913 EXPECT_TRUE(flip_lrtb(a).IntersectionOrEmpty(flip_lrtb(b)).IsEmpty())
1914 << label;
1915 };
1916
1917 auto test_non_empty = [&check_nans, &check_empty_flips](
1918 const Rect& a, const Rect& b, const Rect& result) {
1919 ASSERT_FALSE(a.IsEmpty()) << a;
1920 // b is allowed to be empty
1921
1922 std::stringstream stream;
1923 stream << a << " union " << b;
1924 auto label = stream.str();
1925
1926 EXPECT_TRUE(a.Intersection(b).has_value()) << label;
1927 EXPECT_TRUE(b.Intersection(a).has_value()) << label;
1928 EXPECT_EQ(a.Intersection(b), result) << label;
1929 EXPECT_EQ(b.Intersection(a), result) << label;
1930 check_empty_flips(a, b, label);
1931 check_nans(a, b, label);
1932 };
1933
1934 auto test_empty = [&check_nans, &check_empty_flips](const Rect& a,
1935 const Rect& b) {
1936 ASSERT_FALSE(a.IsEmpty()) << a;
1937 // b is allowed to be empty
1938
1939 std::stringstream stream;
1940 stream << a << " union " << b;
1941 auto label = stream.str();
1942
1943 EXPECT_FALSE(a.Intersection(b).has_value()) << label;
1944 EXPECT_TRUE(a.IntersectionOrEmpty(b).IsEmpty()) << label;
1945 EXPECT_FALSE(b.Intersection(a).has_value()) << label;
1946 EXPECT_TRUE(b.IntersectionOrEmpty(a).IsEmpty()) << label;
1947 check_empty_flips(a, b, label);
1948 check_nans(a, b, label);
1949 };
1950
1951 {
1952 auto a = Rect::MakeXYWH(100, 100, 100, 100);
1953 auto b = Rect::MakeXYWH(0, 0, 0, 0);
1954
1955 test_empty(a, b);
1956 }
1957
1958 {
1959 auto a = Rect::MakeXYWH(100, 100, 100, 100);
1960 auto b = Rect::MakeXYWH(10, 10, 0, 0);
1961
1962 test_empty(a, b);
1963 }
1964
1965 {
1966 auto a = Rect::MakeXYWH(0, 0, 100, 100);
1967 auto b = Rect::MakeXYWH(10, 10, 100, 100);
1968 auto expected = Rect::MakeXYWH(10, 10, 90, 90);
1969
1970 test_non_empty(a, b, expected);
1971 }
1972
1973 {
1974 auto a = Rect::MakeXYWH(0, 0, 100, 100);
1975 auto b = Rect::MakeXYWH(100, 100, 100, 100);
1976
1977 test_empty(a, b);
1978 }
1979
1980 {
1981 auto a = Rect::MakeMaximum();
1982 auto b = Rect::MakeXYWH(10, 10, 300, 300);
1983
1984 test_non_empty(a, b, b);
1985 }
1986
1987 {
1988 auto a = Rect::MakeMaximum();
1989 auto b = Rect::MakeMaximum();
1990
1991 test_non_empty(a, b, Rect::MakeMaximum());
1992 }
1993}

References flip_lr(), flip_lrtb(), flip_tb(), i, impeller::TRect< Scalar >::MakeMaximum(), impeller::TRect< Scalar >::MakeXYWH(), and swap_nan().

◆ TEST() [469/689]

impeller::testing::TEST ( RectTest  ,
RectIntersectsWithRect   
)

Definition at line 2200 of file rect_unittests.cc.

2200 {
2201 auto check_nans = [](const Rect& a, const Rect& b, const std::string& label) {
2202 ASSERT_TRUE(a.IsFinite()) << label;
2203 ASSERT_TRUE(b.IsFinite()) << label;
2204
2205 for (int i = 1; i < 16; i++) {
2206 // NaN in a produces b
2207 EXPECT_FALSE(swap_nan(a, i).IntersectsWithRect(b))
2208 << label << ", index = " << i;
2209 // NaN in b produces a
2210 EXPECT_FALSE(a.IntersectsWithRect(swap_nan(b, i)))
2211 << label << ", index = " << i;
2212 // NaN in both is empty
2213 for (int j = 1; j < 16; j++) {
2214 EXPECT_FALSE(swap_nan(a, i).IntersectsWithRect(swap_nan(b, j)))
2215 << label << ", indices = " << i << ", " << j;
2216 }
2217 }
2218 };
2219
2220 auto check_empty_flips = [](const Rect& a, const Rect& b,
2221 const std::string& label) {
2222 ASSERT_FALSE(a.IsEmpty());
2223 // b is allowed to be empty
2224
2225 // unflipped a vs flipped (empty) b yields a
2226 EXPECT_FALSE(a.IntersectsWithRect(flip_lr(b))) << label;
2227 EXPECT_FALSE(a.IntersectsWithRect(flip_tb(b))) << label;
2228 EXPECT_FALSE(a.IntersectsWithRect(flip_lrtb(b))) << label;
2229
2230 // flipped (empty) a vs unflipped b yields b
2231 EXPECT_FALSE(flip_lr(a).IntersectsWithRect(b)) << label;
2232 EXPECT_FALSE(flip_tb(a).IntersectsWithRect(b)) << label;
2233 EXPECT_FALSE(flip_lrtb(a).IntersectsWithRect(b)) << label;
2234
2235 // flipped (empty) a vs flipped (empty) b yields empty
2236 EXPECT_FALSE(flip_lr(a).IntersectsWithRect(flip_lr(b))) << label;
2237 EXPECT_FALSE(flip_tb(a).IntersectsWithRect(flip_tb(b))) << label;
2238 EXPECT_FALSE(flip_lrtb(a).IntersectsWithRect(flip_lrtb(b))) << label;
2239 };
2240
2241 auto test_non_empty = [&check_nans, &check_empty_flips](const Rect& a,
2242 const Rect& b) {
2243 ASSERT_FALSE(a.IsEmpty()) << a;
2244 // b is allowed to be empty
2245
2246 std::stringstream stream;
2247 stream << a << " union " << b;
2248 auto label = stream.str();
2249
2250 EXPECT_TRUE(a.IntersectsWithRect(b)) << label;
2251 EXPECT_TRUE(b.IntersectsWithRect(a)) << label;
2252 check_empty_flips(a, b, label);
2253 check_nans(a, b, label);
2254 };
2255
2256 auto test_empty = [&check_nans, &check_empty_flips](const Rect& a,
2257 const Rect& b) {
2258 ASSERT_FALSE(a.IsEmpty()) << a;
2259 // b is allowed to be empty
2260
2261 std::stringstream stream;
2262 stream << a << " union " << b;
2263 auto label = stream.str();
2264
2265 EXPECT_FALSE(a.IntersectsWithRect(b)) << label;
2266 EXPECT_FALSE(b.IntersectsWithRect(a)) << label;
2267 check_empty_flips(a, b, label);
2268 check_nans(a, b, label);
2269 };
2270
2271 {
2272 auto a = Rect::MakeXYWH(100, 100, 100, 100);
2273 auto b = Rect::MakeXYWH(0, 0, 0, 0);
2274
2275 test_empty(a, b);
2276 }
2277
2278 {
2279 auto a = Rect::MakeXYWH(100, 100, 100, 100);
2280 auto b = Rect::MakeXYWH(10, 10, 0, 0);
2281
2282 test_empty(a, b);
2283 }
2284
2285 {
2286 auto a = Rect::MakeXYWH(0, 0, 100, 100);
2287 auto b = Rect::MakeXYWH(10, 10, 100, 100);
2288
2289 test_non_empty(a, b);
2290 }
2291
2292 {
2293 auto a = Rect::MakeXYWH(0, 0, 100, 100);
2294 auto b = Rect::MakeXYWH(100, 100, 100, 100);
2295
2296 test_empty(a, b);
2297 }
2298
2299 {
2300 auto a = Rect::MakeMaximum();
2301 auto b = Rect::MakeXYWH(10, 10, 100, 100);
2302
2303 test_non_empty(a, b);
2304 }
2305
2306 {
2307 auto a = Rect::MakeMaximum();
2308 auto b = Rect::MakeMaximum();
2309
2310 test_non_empty(a, b);
2311 }
2312}

References flip_lr(), flip_lrtb(), flip_tb(), i, impeller::TRect< Scalar >::MakeMaximum(), impeller::TRect< Scalar >::MakeXYWH(), and swap_nan().

◆ TEST() [470/689]

impeller::testing::TEST ( RectTest  ,
RectMakeCircleBounds   
)

Definition at line 178 of file rect_unittests.cc.

178 {
179 Rect rect = Rect::MakeCircleBounds(Point(100.0f, 200.0f), 20.0f);
180
181 EXPECT_FALSE(rect.IsEmpty());
182 EXPECT_EQ(rect.GetLeft(), 80.0f);
183 EXPECT_EQ(rect.GetRight(), 120.0f);
184 EXPECT_EQ(rect.GetTop(), 180.0f);
185 EXPECT_EQ(rect.GetBottom(), 220.0f);
186}

References impeller::TRect< Scalar >::MakeCircleBounds().

◆ TEST() [471/689]

impeller::testing::TEST ( RectTest  ,
RectMakeCircleBoundsNegativeRadius   
)

Definition at line 188 of file rect_unittests.cc.

188 {
189 Rect rect = Rect::MakeCircleBounds(Point(100.0f, 200.0f), -20.0f);
190
191 EXPECT_TRUE(rect.IsEmpty());
192 EXPECT_EQ(rect.GetLeft(), 120.0f);
193 EXPECT_EQ(rect.GetRight(), 80.0f);
194 EXPECT_EQ(rect.GetTop(), 220.0f);
195 EXPECT_EQ(rect.GetBottom(), 180.0f);
196}

References impeller::TRect< Scalar >::MakeCircleBounds().

◆ TEST() [472/689]

impeller::testing::TEST ( RectTest  ,
RectMakeEllipseBoundsNegativePoint   
)

Definition at line 251 of file rect_unittests.cc.

251 {
252 Rect rect =
253 Rect::MakeEllipseBounds(Point(100.0f, 200.0f), Point(-20.0f, -30.0f));
254
255 EXPECT_TRUE(rect.IsEmpty());
256 EXPECT_EQ(rect.GetLeft(), 120.0f);
257 EXPECT_EQ(rect.GetRight(), 80.0f);
258 EXPECT_EQ(rect.GetTop(), 230.0f);
259 EXPECT_EQ(rect.GetBottom(), 170.0f);
260}

References impeller::TRect< Scalar >::MakeEllipseBounds().

◆ TEST() [473/689]

impeller::testing::TEST ( RectTest  ,
RectMakeEllipseBoundsNegativeSize   
)

Definition at line 229 of file rect_unittests.cc.

229 {
230 Rect rect =
231 Rect::MakeEllipseBounds(Point(100.0f, 200.0f), Size(-20.0f, -30.0f));
232
233 EXPECT_TRUE(rect.IsEmpty());
234 EXPECT_EQ(rect.GetLeft(), 120.0f);
235 EXPECT_EQ(rect.GetRight(), 80.0f);
236 EXPECT_EQ(rect.GetTop(), 230.0f);
237 EXPECT_EQ(rect.GetBottom(), 170.0f);
238}

References impeller::TRect< Scalar >::MakeEllipseBounds().

◆ TEST() [474/689]

impeller::testing::TEST ( RectTest  ,
RectMakeEllipseBoundsPoint   
)

Definition at line 240 of file rect_unittests.cc.

240 {
241 Rect rect =
242 Rect::MakeEllipseBounds(Point(100.0f, 200.0f), Point(20.0f, 30.0f));
243
244 EXPECT_FALSE(rect.IsEmpty());
245 EXPECT_EQ(rect.GetLeft(), 80.0f);
246 EXPECT_EQ(rect.GetRight(), 120.0f);
247 EXPECT_EQ(rect.GetTop(), 170.0f);
248 EXPECT_EQ(rect.GetBottom(), 230.0f);
249}

References impeller::TRect< Scalar >::MakeEllipseBounds().

◆ TEST() [475/689]

impeller::testing::TEST ( RectTest  ,
RectMakeEllipseBoundsSize   
)

Definition at line 218 of file rect_unittests.cc.

218 {
219 Rect rect =
220 Rect::MakeEllipseBounds(Point(100.0f, 200.0f), Size(20.0f, 30.0f));
221
222 EXPECT_FALSE(rect.IsEmpty());
223 EXPECT_EQ(rect.GetLeft(), 80.0f);
224 EXPECT_EQ(rect.GetRight(), 120.0f);
225 EXPECT_EQ(rect.GetTop(), 170.0f);
226 EXPECT_EQ(rect.GetBottom(), 230.0f);
227}

References impeller::TRect< Scalar >::MakeEllipseBounds().

◆ TEST() [476/689]

impeller::testing::TEST ( RectTest  ,
RectMakeMaximum   
)

Definition at line 744 of file rect_unittests.cc.

744 {
745 Rect rect = Rect::MakeMaximum();
746 auto inf = std::numeric_limits<Scalar>::infinity();
747 auto min = std::numeric_limits<Scalar>::lowest();
748 auto max = std::numeric_limits<Scalar>::max();
749
750 EXPECT_EQ(rect.GetLeft(), min);
751 EXPECT_EQ(rect.GetTop(), min);
752 EXPECT_EQ(rect.GetRight(), max);
753 EXPECT_EQ(rect.GetBottom(), max);
754 EXPECT_EQ(rect.GetX(), min);
755 EXPECT_EQ(rect.GetY(), min);
756 EXPECT_EQ(rect.GetWidth(), inf);
757 EXPECT_EQ(rect.GetHeight(), inf);
758 EXPECT_FALSE(rect.IsEmpty());
759 EXPECT_TRUE(rect.IsFinite());
760}

References impeller::TRect< Scalar >::MakeMaximum().

◆ TEST() [477/689]

impeller::testing::TEST ( RectTest  ,
RectMakePointBounds   
)

Definition at line 3248 of file rect_unittests.cc.

3248 {
3249 {
3250 std::vector<Point> points{{1, 5}, {4, -1}, {0, 6}};
3251 auto r = Rect::MakePointBounds(points.begin(), points.end());
3252 auto expected = Rect::MakeXYWH(0, -1, 4, 7);
3253 EXPECT_TRUE(r.has_value());
3254 if (r.has_value()) {
3255 EXPECT_RECT_NEAR(r.value(), expected);
3256 }
3257 }
3258 {
3259 std::vector<Point> points;
3260 std::optional<Rect> r = Rect::MakePointBounds(points.begin(), points.end());
3261 EXPECT_FALSE(r.has_value());
3262 }
3263}

References EXPECT_RECT_NEAR, impeller::TRect< Scalar >::MakePointBounds(), impeller::TRect< Scalar >::MakeXYWH(), and points.

◆ TEST() [478/689]

impeller::testing::TEST ( RectTest  ,
RectMakeSize   
)

Definition at line 714 of file rect_unittests.cc.

714 {
715 {
716 Size s(100, 200);
717 Rect r = Rect::MakeSize(s);
718 Rect expected = Rect::MakeLTRB(0, 0, 100, 200);
719 EXPECT_RECT_NEAR(r, expected);
720 }
721
722 {
723 ISize s(100, 200);
724 Rect r = Rect::MakeSize(s);
725 Rect expected = Rect::MakeLTRB(0, 0, 100, 200);
726 EXPECT_RECT_NEAR(r, expected);
727 }
728
729 {
730 Size s(100, 200);
731 IRect r = IRect::MakeSize(s);
732 IRect expected = IRect::MakeLTRB(0, 0, 100, 200);
733 EXPECT_EQ(r, expected);
734 }
735
736 {
737 ISize s(100, 200);
738 IRect r = IRect::MakeSize(s);
739 IRect expected = IRect::MakeLTRB(0, 0, 100, 200);
740 EXPECT_EQ(r, expected);
741 }
742}

References EXPECT_RECT_NEAR, impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< T >::MakeSize(), and impeller::TRect< Scalar >::MakeSize().

◆ TEST() [479/689]

impeller::testing::TEST ( RectTest  ,
RectOriginSizeXYWHGetters   
)

Definition at line 826 of file rect_unittests.cc.

826 {
827 {
828 Rect r = Rect::MakeOriginSize({10, 20}, {50, 40});
829 EXPECT_EQ(r.GetOrigin(), Point(10, 20));
830 EXPECT_EQ(r.GetSize(), Size(50, 40));
831 EXPECT_EQ(r.GetX(), 10);
832 EXPECT_EQ(r.GetY(), 20);
833 EXPECT_EQ(r.GetWidth(), 50);
834 EXPECT_EQ(r.GetHeight(), 40);
835 auto expected_array = std::array<Scalar, 4>{10, 20, 50, 40};
836 EXPECT_EQ(r.GetXYWH(), expected_array);
837 }
838
839 {
840 Rect r = Rect::MakeLTRB(10, 20, 50, 40);
841 EXPECT_EQ(r.GetOrigin(), Point(10, 20));
842 EXPECT_EQ(r.GetSize(), Size(40, 20));
843 EXPECT_EQ(r.GetX(), 10);
844 EXPECT_EQ(r.GetY(), 20);
845 EXPECT_EQ(r.GetWidth(), 40);
846 EXPECT_EQ(r.GetHeight(), 20);
847 auto expected_array = std::array<Scalar, 4>{10, 20, 40, 20};
848 EXPECT_EQ(r.GetXYWH(), expected_array);
849 }
850}

References impeller::TRect< Scalar >::MakeLTRB(), and impeller::TRect< Scalar >::MakeOriginSize().

◆ TEST() [480/689]

impeller::testing::TEST ( RectTest  ,
RectOverflowLTRB   
)

Definition at line 508 of file rect_unittests.cc.

508 {
509 auto min = std::numeric_limits<Scalar>::lowest();
510 auto max = std::numeric_limits<Scalar>::max();
511 auto inf = std::numeric_limits<Scalar>::infinity();
512
513 // 8 cases:
514 // finite negative X, max W
515 // ~min X, ~max W
516 // finite negative Y, max H
517 // ~min Y, ~max H
518 // finite positive X, min W
519 // ~min X, ~min W
520 // finite positive Y, min H
521 // ~min Y, ~min H
522
523 // a small finite value subtracted from a max value will remain max
524 // a very large finite value (like min) subtracted from max will go to inf
525
526 {
527 Rect rect = Rect::MakeLTRB(-5.0f, 10.0f, max, 25.0f);
528
529 EXPECT_EQ(rect.GetLeft(), -5.0f);
530 EXPECT_EQ(rect.GetTop(), 10.0f);
531 EXPECT_EQ(rect.GetRight(), max);
532 EXPECT_EQ(rect.GetBottom(), 25.0f);
533 EXPECT_EQ(rect.GetX(), -5.0f);
534 EXPECT_EQ(rect.GetY(), 10.0f);
535 EXPECT_EQ(rect.GetWidth(), max);
536 EXPECT_EQ(rect.GetHeight(), 15.0f);
537 EXPECT_FALSE(rect.IsEmpty());
538 EXPECT_TRUE(rect.IsFinite());
539 }
540
541 {
542 Rect rect = Rect::MakeLTRB(min + 5.0f, 10.0f, max - 5.0f, 25.0f);
543
544 EXPECT_EQ(rect.GetLeft(), min + 5.0f);
545 EXPECT_EQ(rect.GetTop(), 10.0f);
546 EXPECT_EQ(rect.GetRight(), max - 5.0f);
547 EXPECT_EQ(rect.GetBottom(), 25.0f);
548 EXPECT_EQ(rect.GetX(), min + 5.0f);
549 EXPECT_EQ(rect.GetY(), 10.0f);
550 EXPECT_EQ(rect.GetWidth(), inf);
551 EXPECT_EQ(rect.GetHeight(), 15.0f);
552 EXPECT_FALSE(rect.IsEmpty());
553 EXPECT_TRUE(rect.IsFinite());
554 }
555
556 {
557 Rect rect = Rect::MakeLTRB(5.0f, -10.0f, 20.0f, max);
558
559 EXPECT_EQ(rect.GetLeft(), 5.0f);
560 EXPECT_EQ(rect.GetTop(), -10.0f);
561 EXPECT_EQ(rect.GetRight(), 20.0f);
562 EXPECT_EQ(rect.GetBottom(), max);
563 EXPECT_EQ(rect.GetX(), 5.0f);
564 EXPECT_EQ(rect.GetY(), -10.0f);
565 EXPECT_EQ(rect.GetWidth(), 15.0f);
566 EXPECT_EQ(rect.GetHeight(), max);
567 EXPECT_FALSE(rect.IsEmpty());
568 EXPECT_TRUE(rect.IsFinite());
569 }
570
571 {
572 Rect rect = Rect::MakeLTRB(5.0f, min + 10.0f, 20.0f, max - 15.0f);
573
574 EXPECT_EQ(rect.GetLeft(), 5.0f);
575 EXPECT_EQ(rect.GetTop(), min + 10.0f);
576 EXPECT_EQ(rect.GetRight(), 20.0f);
577 EXPECT_EQ(rect.GetBottom(), max - 15.0f);
578 EXPECT_EQ(rect.GetX(), 5.0f);
579 EXPECT_EQ(rect.GetY(), min + 10.0f);
580 EXPECT_EQ(rect.GetWidth(), 15.0f);
581 EXPECT_EQ(rect.GetHeight(), inf);
582 EXPECT_FALSE(rect.IsEmpty());
583 EXPECT_TRUE(rect.IsFinite());
584 }
585
586 {
587 Rect rect = Rect::MakeLTRB(5.0f, 10.0f, min, 25.0f);
588
589 EXPECT_EQ(rect.GetLeft(), 5.0f);
590 EXPECT_EQ(rect.GetTop(), 10.0f);
591 EXPECT_EQ(rect.GetRight(), min);
592 EXPECT_EQ(rect.GetBottom(), 25.0f);
593 EXPECT_EQ(rect.GetX(), 5.0f);
594 EXPECT_EQ(rect.GetY(), 10.0f);
595 EXPECT_EQ(rect.GetWidth(), min);
596 EXPECT_EQ(rect.GetHeight(), 15.0f);
597 EXPECT_TRUE(rect.IsEmpty());
598 EXPECT_TRUE(rect.IsFinite());
599 }
600
601 {
602 Rect rect = Rect::MakeLTRB(max - 5.0f, 10.0f, min + 10.0f, 25.0f);
603
604 EXPECT_EQ(rect.GetLeft(), max - 5.0f);
605 EXPECT_EQ(rect.GetTop(), 10.0f);
606 EXPECT_EQ(rect.GetRight(), min + 10.0f);
607 EXPECT_EQ(rect.GetBottom(), 25.0f);
608 EXPECT_EQ(rect.GetX(), max - 5.0f);
609 EXPECT_EQ(rect.GetY(), 10.0f);
610 EXPECT_EQ(rect.GetWidth(), -inf);
611 EXPECT_EQ(rect.GetHeight(), 15.0f);
612 EXPECT_TRUE(rect.IsEmpty());
613 EXPECT_TRUE(rect.IsFinite());
614 }
615
616 {
617 Rect rect = Rect::MakeLTRB(5.0f, 10.0f, 20.0f, min);
618
619 EXPECT_EQ(rect.GetLeft(), 5.0f);
620 EXPECT_EQ(rect.GetTop(), 10.0f);
621 EXPECT_EQ(rect.GetRight(), 20.0f);
622 EXPECT_EQ(rect.GetBottom(), min);
623 EXPECT_EQ(rect.GetX(), 5.0f);
624 EXPECT_EQ(rect.GetY(), 10.0f);
625 EXPECT_EQ(rect.GetWidth(), 15.0f);
626 EXPECT_EQ(rect.GetHeight(), min);
627 EXPECT_TRUE(rect.IsEmpty());
628 EXPECT_TRUE(rect.IsFinite());
629 }
630
631 {
632 Rect rect = Rect::MakeLTRB(5.0f, max - 5.0f, 20.0f, min + 10.0f);
633
634 EXPECT_EQ(rect.GetLeft(), 5.0f);
635 EXPECT_EQ(rect.GetTop(), max - 5.0f);
636 EXPECT_EQ(rect.GetRight(), 20.0f);
637 EXPECT_EQ(rect.GetBottom(), min + 10.0f);
638 EXPECT_EQ(rect.GetX(), 5.0f);
639 EXPECT_EQ(rect.GetY(), max - 5.0f);
640 EXPECT_EQ(rect.GetWidth(), 15.0f);
641 EXPECT_EQ(rect.GetHeight(), -inf);
642 EXPECT_TRUE(rect.IsEmpty());
643 EXPECT_TRUE(rect.IsFinite());
644 }
645}
IsFinite() const
Returns true if all of the fields of this floating point rectangle are finite.
Definition rect.h:322

References impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [481/689]

impeller::testing::TEST ( RectTest  ,
RectOverflowXYWH   
)

Definition at line 302 of file rect_unittests.cc.

302 {
303 auto min = std::numeric_limits<Scalar>::lowest();
304 auto max = std::numeric_limits<Scalar>::max();
305 auto inf = std::numeric_limits<Scalar>::infinity();
306
307 // 8 cases:
308 // finite X, max W
309 // max X, max W
310 // finite Y, max H
311 // max Y, max H
312 // finite X, min W
313 // min X, min W
314 // finite Y, min H
315 // min Y, min H
316
317 // a small finite value added to a max value will remain max
318 // a very large finite value (like max) added to max will go to infinity
319
320 {
321 Rect rect = Rect::MakeXYWH(5.0, 10.0f, max, 15.0f);
322
323 EXPECT_EQ(rect.GetLeft(), 5.0f);
324 EXPECT_EQ(rect.GetTop(), 10.0f);
325 EXPECT_EQ(rect.GetRight(), max);
326 EXPECT_EQ(rect.GetBottom(), 25.0f);
327 EXPECT_EQ(rect.GetX(), 5.0f);
328 EXPECT_EQ(rect.GetY(), 10.0f);
329 EXPECT_EQ(rect.GetWidth(), max);
330 EXPECT_EQ(rect.GetHeight(), 15.0f);
331 EXPECT_FALSE(rect.IsEmpty());
332 EXPECT_TRUE(rect.IsFinite());
333 }
334
335 {
336 Rect rect = Rect::MakeXYWH(max, 10.0f, max, 15.0f);
337
338 EXPECT_EQ(rect.GetLeft(), max);
339 EXPECT_EQ(rect.GetTop(), 10.0f);
340 EXPECT_EQ(rect.GetRight(), inf);
341 EXPECT_EQ(rect.GetBottom(), 25.0f);
342 EXPECT_EQ(rect.GetX(), max);
343 EXPECT_EQ(rect.GetY(), 10.0f);
344 EXPECT_EQ(rect.GetWidth(), inf);
345 EXPECT_EQ(rect.GetHeight(), 15.0f);
346 EXPECT_FALSE(rect.IsEmpty());
347 EXPECT_FALSE(rect.IsFinite());
348 }
349
350 {
351 Rect rect = Rect::MakeXYWH(5.0f, 10.0f, 20.0f, max);
352
353 EXPECT_EQ(rect.GetLeft(), 5.0f);
354 EXPECT_EQ(rect.GetTop(), 10.0f);
355 EXPECT_EQ(rect.GetRight(), 25.0f);
356 EXPECT_EQ(rect.GetBottom(), max);
357 EXPECT_EQ(rect.GetX(), 5.0f);
358 EXPECT_EQ(rect.GetY(), 10.0f);
359 EXPECT_EQ(rect.GetWidth(), 20.0f);
360 EXPECT_EQ(rect.GetHeight(), max);
361 EXPECT_FALSE(rect.IsEmpty());
362 EXPECT_TRUE(rect.IsFinite());
363 }
364
365 {
366 Rect rect = Rect::MakeXYWH(5.0f, max, 20.0f, max);
367
368 EXPECT_EQ(rect.GetLeft(), 5.0f);
369 EXPECT_EQ(rect.GetTop(), max);
370 EXPECT_EQ(rect.GetRight(), 25.0f);
371 EXPECT_EQ(rect.GetBottom(), inf);
372 EXPECT_EQ(rect.GetX(), 5.0f);
373 EXPECT_EQ(rect.GetY(), max);
374 EXPECT_EQ(rect.GetWidth(), 20.0f);
375 EXPECT_EQ(rect.GetHeight(), inf);
376 EXPECT_FALSE(rect.IsEmpty());
377 EXPECT_FALSE(rect.IsFinite());
378 }
379
380 {
381 Rect rect = Rect::MakeXYWH(5.0, 10.0f, min, 15.0f);
382
383 EXPECT_EQ(rect.GetLeft(), 5.0f);
384 EXPECT_EQ(rect.GetTop(), 10.0f);
385 EXPECT_EQ(rect.GetRight(), min);
386 EXPECT_EQ(rect.GetBottom(), 25.0f);
387 EXPECT_EQ(rect.GetX(), 5.0f);
388 EXPECT_EQ(rect.GetY(), 10.0f);
389 EXPECT_EQ(rect.GetWidth(), min);
390 EXPECT_EQ(rect.GetHeight(), 15.0f);
391 EXPECT_TRUE(rect.IsEmpty());
392 EXPECT_TRUE(rect.IsFinite());
393 }
394
395 {
396 Rect rect = Rect::MakeXYWH(min, 10.0f, min, 15.0f);
397
398 EXPECT_EQ(rect.GetLeft(), min);
399 EXPECT_EQ(rect.GetTop(), 10.0f);
400 EXPECT_EQ(rect.GetRight(), -inf);
401 EXPECT_EQ(rect.GetBottom(), 25.0f);
402 EXPECT_EQ(rect.GetX(), min);
403 EXPECT_EQ(rect.GetY(), 10.0f);
404 EXPECT_EQ(rect.GetWidth(), -inf);
405 EXPECT_EQ(rect.GetHeight(), 15.0f);
406 EXPECT_TRUE(rect.IsEmpty());
407 EXPECT_FALSE(rect.IsFinite());
408 }
409
410 {
411 Rect rect = Rect::MakeXYWH(5.0f, 10.0f, 20.0f, min);
412
413 EXPECT_EQ(rect.GetLeft(), 5.0f);
414 EXPECT_EQ(rect.GetTop(), 10.0f);
415 EXPECT_EQ(rect.GetRight(), 25.0f);
416 EXPECT_EQ(rect.GetBottom(), min);
417 EXPECT_EQ(rect.GetX(), 5.0f);
418 EXPECT_EQ(rect.GetY(), 10.0f);
419 EXPECT_EQ(rect.GetWidth(), 20.0f);
420 EXPECT_EQ(rect.GetHeight(), min);
421 EXPECT_TRUE(rect.IsEmpty());
422 EXPECT_TRUE(rect.IsFinite());
423 }
424
425 {
426 Rect rect = Rect::MakeXYWH(5.0f, min, 20.0f, min);
427
428 EXPECT_EQ(rect.GetLeft(), 5.0f);
429 EXPECT_EQ(rect.GetTop(), min);
430 EXPECT_EQ(rect.GetRight(), 25.0f);
431 EXPECT_EQ(rect.GetBottom(), -inf);
432 EXPECT_EQ(rect.GetX(), 5.0f);
433 EXPECT_EQ(rect.GetY(), min);
434 EXPECT_EQ(rect.GetWidth(), 20.0f);
435 EXPECT_EQ(rect.GetHeight(), -inf);
436 EXPECT_TRUE(rect.IsEmpty());
437 EXPECT_FALSE(rect.IsFinite());
438 }
439}

References impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [482/689]

impeller::testing::TEST ( RectTest  ,
RectProject   
)

Definition at line 3293 of file rect_unittests.cc.

3293 {
3294 {
3295 auto r = Rect::MakeLTRB(-100, -100, 100, 100);
3296 auto actual = r.Project(r);
3297 auto expected = Rect::MakeLTRB(0, 0, 1, 1);
3298 EXPECT_RECT_NEAR(expected, actual);
3299 }
3300 {
3301 auto r = Rect::MakeLTRB(-100, -100, 100, 100);
3302 auto actual = r.Project(Rect::MakeLTRB(0, 0, 100, 100));
3303 auto expected = Rect::MakeLTRB(0.5, 0.5, 1, 1);
3304 EXPECT_RECT_NEAR(expected, actual);
3305 }
3306}

References EXPECT_RECT_NEAR, and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [483/689]

impeller::testing::TEST ( RectTest  ,
RectRound   
)

Definition at line 3332 of file rect_unittests.cc.

3332 {
3333 {
3334 auto r = Rect::MakeLTRB(-100, -200, 300, 400);
3335 EXPECT_EQ(Rect::Round(r), r);
3336 }
3337 {
3338 auto r = Rect::MakeLTRB(-100.4, -200.4, 300.4, 400.4);
3339 EXPECT_EQ(Rect::Round(r), Rect::MakeLTRB(-100, -200, 300, 400));
3340 }
3341 {
3342 auto r = Rect::MakeLTRB(-100.5, -200.5, 300.5, 400.5);
3343 EXPECT_EQ(Rect::Round(r), Rect::MakeLTRB(-101, -201, 301, 401));
3344 }
3345}

References impeller::TRect< Scalar >::MakeLTRB(), and impeller::TRect< Scalar >::Round().

◆ TEST() [484/689]

impeller::testing::TEST ( RectTest  ,
RectRoundOut   
)

Definition at line 3308 of file rect_unittests.cc.

3308 {
3309 {
3310 auto r = Rect::MakeLTRB(-100, -200, 300, 400);
3311 EXPECT_EQ(Rect::RoundOut(r), r);
3312 }
3313 {
3314 auto r = Rect::MakeLTRB(-100.1, -200.1, 300.1, 400.1);
3315 EXPECT_EQ(Rect::RoundOut(r), Rect::MakeLTRB(-101, -201, 301, 401));
3316 }
3317}

References impeller::TRect< Scalar >::MakeLTRB(), and impeller::TRect< Scalar >::RoundOut().

◆ TEST() [485/689]

impeller::testing::TEST ( RectTest  ,
RectRoundOutEmpty   
)

Definition at line 878 of file rect_unittests.cc.

878 {
879 Rect rect;
880
881 EXPECT_EQ(Rect::RoundOut(rect), Rect());
882
883 EXPECT_EQ(IRect::RoundOut(rect), IRect());
884}

References impeller::TRect< T >::RoundOut(), and impeller::TRect< Scalar >::RoundOut().

◆ TEST() [486/689]

impeller::testing::TEST ( RectTest  ,
RectRoundOutSimple   
)

Definition at line 886 of file rect_unittests.cc.

886 {
887 Rect rect = Rect::MakeLTRB(5.125f, 10.75f, 20.625f, 25.375f);
888
889 EXPECT_EQ(Rect::RoundOut(rect), Rect::MakeLTRB(5.0f, 10.0f, 21.0f, 26.0f));
890
891 EXPECT_EQ(IRect::RoundOut(rect), IRect::MakeLTRB(5, 10, 21, 26));
892}

References impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< T >::RoundOut(), and impeller::TRect< Scalar >::RoundOut().

◆ TEST() [487/689]

impeller::testing::TEST ( RectTest  ,
RectRoundOutToIRectHuge   
)

Definition at line 894 of file rect_unittests.cc.

894 {
895 auto test = [](int corners) {
896 EXPECT_TRUE(corners >= 0 && corners <= 0xf);
897 Scalar l, t, r, b;
898 int64_t il, it, ir, ib;
899 l = il = 50;
900 t = it = 50;
901 r = ir = 80;
902 b = ib = 80;
903 if ((corners & (1 << 0)) != 0) {
904 l = -1E20;
905 il = std::numeric_limits<int64_t>::min();
906 }
907 if ((corners & (1 << 1)) != 0) {
908 t = -1E20;
909 it = std::numeric_limits<int64_t>::min();
910 }
911 if ((corners & (1 << 2)) != 0) {
912 r = +1E20;
913 ir = std::numeric_limits<int64_t>::max();
914 }
915 if ((corners & (1 << 3)) != 0) {
916 b = +1E20;
917 ib = std::numeric_limits<int64_t>::max();
918 }
919
920 Rect rect = Rect::MakeLTRB(l, t, r, b);
921 IRect irect = IRect::RoundOut(rect);
922 EXPECT_EQ(irect.GetLeft(), il) << corners;
923 EXPECT_EQ(irect.GetTop(), it) << corners;
924 EXPECT_EQ(irect.GetRight(), ir) << corners;
925 EXPECT_EQ(irect.GetBottom(), ib) << corners;
926 };
927
928 for (int corners = 0; corners <= 15; corners++) {
929 test(corners);
930 }
931}

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::TRect< T >::RoundOut().

◆ TEST() [488/689]

impeller::testing::TEST ( RectTest  ,
RectScale   
)

Definition at line 1053 of file rect_unittests.cc.

1053 {
1054 auto test1 = [](Rect rect, Scalar scale) {
1055 Rect expected = Rect::MakeXYWH(rect.GetX() * scale, //
1056 rect.GetY() * scale, //
1057 rect.GetWidth() * scale, //
1058 rect.GetHeight() * scale);
1059
1060 EXPECT_RECT_NEAR(rect.Scale(scale), expected) //
1061 << rect << " * " << scale;
1062 EXPECT_RECT_NEAR(rect.Scale(scale, scale), expected) //
1063 << rect << " * " << scale;
1064 EXPECT_RECT_NEAR(rect.Scale(Point(scale, scale)), expected) //
1065 << rect << " * " << scale;
1066 EXPECT_RECT_NEAR(rect.Scale(Size(scale, scale)), expected) //
1067 << rect << " * " << scale;
1068 };
1069
1070 auto test2 = [&test1](Rect rect, Scalar scale_x, Scalar scale_y) {
1071 Rect expected = Rect::MakeXYWH(rect.GetX() * scale_x, //
1072 rect.GetY() * scale_y, //
1073 rect.GetWidth() * scale_x, //
1074 rect.GetHeight() * scale_y);
1075
1076 EXPECT_RECT_NEAR(rect.Scale(scale_x, scale_y), expected) //
1077 << rect << " * " << scale_x << ", " << scale_y;
1078 EXPECT_RECT_NEAR(rect.Scale(Point(scale_x, scale_y)), expected) //
1079 << rect << " * " << scale_x << ", " << scale_y;
1080 EXPECT_RECT_NEAR(rect.Scale(Size(scale_x, scale_y)), expected) //
1081 << rect << " * " << scale_x << ", " << scale_y;
1082
1083 test1(rect, scale_x);
1084 test1(rect, scale_y);
1085 };
1086
1087 test2(Rect::MakeLTRB(10, 15, 100, 150), 1.0, 0.0);
1088 test2(Rect::MakeLTRB(10, 15, 100, 150), 0.0, 1.0);
1089 test2(Rect::MakeLTRB(10, 15, 100, 150), 0.0, 0.0);
1090 test2(Rect::MakeLTRB(10, 15, 100, 150), 2.5, 3.5);
1091 test2(Rect::MakeLTRB(10, 15, 100, 150), 3.5, 2.5);
1092 test2(Rect::MakeLTRB(10, 15, -100, 150), 2.5, 3.5);
1093 test2(Rect::MakeLTRB(10, 15, 100, -150), 2.5, 3.5);
1094 test2(Rect::MakeLTRB(10, 15, 100, 150), -2.5, 3.5);
1095 test2(Rect::MakeLTRB(10, 15, 100, 150), 2.5, -3.5);
1096}

References EXPECT_RECT_NEAR, impeller::TRect< Scalar >::MakeLTRB(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [489/689]

impeller::testing::TEST ( RectTest  ,
RectShift   
)

Definition at line 3232 of file rect_unittests.cc.

3232 {
3233 auto r = Rect::MakeLTRB(0, 0, 100, 100);
3234
3235 EXPECT_EQ(r.Shift(Point(10, 5)), Rect::MakeLTRB(10, 5, 110, 105));
3236 EXPECT_EQ(r.Shift(Point(-10, -5)), Rect::MakeLTRB(-10, -5, 90, 95));
3237}

References impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [490/689]

impeller::testing::TEST ( RectTest  ,
RectSimpleLTRB   
)

Definition at line 73 of file rect_unittests.cc.

73 {
74 // Using fractional-power-of-2 friendly values for equality tests
75 Rect rect = Rect::MakeLTRB(5.125f, 10.25f, 20.625f, 25.375f);
76
77 EXPECT_EQ(rect.GetLeft(), 5.125f);
78 EXPECT_EQ(rect.GetTop(), 10.25f);
79 EXPECT_EQ(rect.GetRight(), 20.625f);
80 EXPECT_EQ(rect.GetBottom(), 25.375f);
81 EXPECT_EQ(rect.GetX(), 5.125f);
82 EXPECT_EQ(rect.GetY(), 10.25f);
83 EXPECT_EQ(rect.GetWidth(), 15.5f);
84 EXPECT_EQ(rect.GetHeight(), 15.125f);
85 EXPECT_FALSE(rect.IsEmpty());
86 EXPECT_TRUE(rect.IsFinite());
87}

References impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [491/689]

impeller::testing::TEST ( RectTest  ,
RectSimpleWH   
)

Definition at line 133 of file rect_unittests.cc.

133 {
134 // Using fractional-power-of-2 friendly values for equality tests
135 Rect rect = Rect::MakeWH(15.5f, 15.125f);
136
137 EXPECT_EQ(rect.GetLeft(), 0.0f);
138 EXPECT_EQ(rect.GetTop(), 0.0f);
139 EXPECT_EQ(rect.GetRight(), 15.5f);
140 EXPECT_EQ(rect.GetBottom(), 15.125f);
141 EXPECT_EQ(rect.GetX(), 0.0f);
142 EXPECT_EQ(rect.GetY(), 0.0f);
143 EXPECT_EQ(rect.GetWidth(), 15.5f);
144 EXPECT_EQ(rect.GetHeight(), 15.125f);
145 EXPECT_FALSE(rect.IsEmpty());
146 EXPECT_TRUE(rect.IsFinite());
147}

References impeller::TRect< Scalar >::MakeWH().

◆ TEST() [492/689]

impeller::testing::TEST ( RectTest  ,
RectSimpleXYWH   
)

Definition at line 103 of file rect_unittests.cc.

103 {
104 // Using fractional-power-of-2 friendly values for equality tests
105 Rect rect = Rect::MakeXYWH(5.125f, 10.25f, 15.5f, 15.125f);
106
107 EXPECT_EQ(rect.GetLeft(), 5.125f);
108 EXPECT_EQ(rect.GetTop(), 10.25f);
109 EXPECT_EQ(rect.GetRight(), 20.625f);
110 EXPECT_EQ(rect.GetBottom(), 25.375f);
111 EXPECT_EQ(rect.GetX(), 5.125f);
112 EXPECT_EQ(rect.GetY(), 10.25f);
113 EXPECT_EQ(rect.GetWidth(), 15.5f);
114 EXPECT_EQ(rect.GetHeight(), 15.125f);
115 EXPECT_FALSE(rect.IsEmpty());
116 EXPECT_TRUE(rect.IsFinite());
117}

References impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [493/689]

impeller::testing::TEST ( RectTest  ,
RectUnion   
)

Definition at line 1607 of file rect_unittests.cc.

1607 {
1608 auto check_nans = [](const Rect& a, const Rect& b, const std::string& label) {
1609 ASSERT_TRUE(a.IsFinite()) << label;
1610 ASSERT_TRUE(b.IsFinite()) << label;
1611 ASSERT_FALSE(a.Union(b).IsEmpty());
1612
1613 for (int i = 1; i < 16; i++) {
1614 // NaN in a produces b
1615 EXPECT_EQ(swap_nan(a, i).Union(b), b) << label << ", index = " << i;
1616 // NaN in b produces a
1617 EXPECT_EQ(a.Union(swap_nan(b, i)), a) << label << ", index = " << i;
1618 // NaN in both is empty
1619 for (int j = 1; j < 16; j++) {
1620 EXPECT_TRUE(swap_nan(a, i).Union(swap_nan(b, j)).IsEmpty())
1621 << label << ", indices = " << i << ", " << j;
1622 }
1623 }
1624 };
1625
1626 auto check_empty_flips = [](const Rect& a, const Rect& b,
1627 const std::string& label) {
1628 ASSERT_FALSE(a.IsEmpty());
1629 // b is allowed to be empty
1630
1631 // unflipped a vs flipped (empty) b yields a
1632 EXPECT_EQ(a.Union(flip_lr(b)), a) << label;
1633 EXPECT_EQ(a.Union(flip_tb(b)), a) << label;
1634 EXPECT_EQ(a.Union(flip_lrtb(b)), a) << label;
1635
1636 // flipped (empty) a vs unflipped b yields b
1637 EXPECT_EQ(flip_lr(a).Union(b), b) << label;
1638 EXPECT_EQ(flip_tb(a).Union(b), b) << label;
1639 EXPECT_EQ(flip_lrtb(a).Union(b), b) << label;
1640
1641 // flipped (empty) a vs flipped (empty) b yields empty
1642 EXPECT_TRUE(flip_lr(a).Union(flip_lr(b)).IsEmpty()) << label;
1643 EXPECT_TRUE(flip_tb(a).Union(flip_tb(b)).IsEmpty()) << label;
1644 EXPECT_TRUE(flip_lrtb(a).Union(flip_lrtb(b)).IsEmpty()) << label;
1645 };
1646
1647 auto test = [&check_nans, &check_empty_flips](const Rect& a, const Rect& b,
1648 const Rect& result) {
1649 ASSERT_FALSE(a.IsEmpty()) << a;
1650 // b is allowed to be empty
1651
1652 std::stringstream stream;
1653 stream << a << " union " << b;
1654 auto label = stream.str();
1655
1656 EXPECT_EQ(a.Union(b), result) << label;
1657 EXPECT_EQ(b.Union(a), result) << label;
1658 check_empty_flips(a, b, label);
1659 check_nans(a, b, label);
1660 };
1661
1662 {
1663 auto a = Rect::MakeXYWH(100, 100, 100, 100);
1664 auto b = Rect::MakeXYWH(0, 0, 0, 0);
1665 auto expected = Rect::MakeXYWH(100, 100, 100, 100);
1666 test(a, b, expected);
1667 }
1668
1669 {
1670 auto a = Rect::MakeXYWH(100, 100, 100, 100);
1671 auto b = Rect::MakeXYWH(0, 0, 1, 1);
1672 auto expected = Rect::MakeXYWH(0, 0, 200, 200);
1673 test(a, b, expected);
1674 }
1675
1676 {
1677 auto a = Rect::MakeXYWH(100, 100, 100, 100);
1678 auto b = Rect::MakeXYWH(10, 10, 1, 1);
1679 auto expected = Rect::MakeXYWH(10, 10, 190, 190);
1680 test(a, b, expected);
1681 }
1682
1683 {
1684 auto a = Rect::MakeXYWH(0, 0, 100, 100);
1685 auto b = Rect::MakeXYWH(10, 10, 100, 100);
1686 auto expected = Rect::MakeXYWH(0, 0, 110, 110);
1687 test(a, b, expected);
1688 }
1689
1690 {
1691 auto a = Rect::MakeXYWH(0, 0, 100, 100);
1692 auto b = Rect::MakeXYWH(100, 100, 100, 100);
1693 auto expected = Rect::MakeXYWH(0, 0, 200, 200);
1694 test(a, b, expected);
1695 }
1696}

References flip_lr(), flip_lrtb(), flip_tb(), i, impeller::TRect< Scalar >::MakeXYWH(), and swap_nan().

◆ TEST() [494/689]

impeller::testing::TEST ( RectTest  ,
RectXYWHIsEmpty   
)

Definition at line 1296 of file rect_unittests.cc.

1296 {
1297 auto nan = std::numeric_limits<Scalar>::quiet_NaN();
1298
1299 // Non-empty
1300 EXPECT_FALSE(Rect::MakeXYWH(1.5, 2.3, 10.5, 7.2).IsEmpty());
1301
1302 // Empty both width and height both 0 or negative, in all combinations
1303 EXPECT_TRUE(Rect::MakeXYWH(1.5, 2.3, 0.0, 0.0).IsEmpty());
1304 EXPECT_TRUE(Rect::MakeXYWH(1.5, 2.3, -1.0, -1.0).IsEmpty());
1305 EXPECT_TRUE(Rect::MakeXYWH(1.5, 2.3, 0.0, -1.0).IsEmpty());
1306 EXPECT_TRUE(Rect::MakeXYWH(1.5, 2.3, -1.0, 0.0).IsEmpty());
1307
1308 // Empty for 0 or negative width or height (but not both at the same time)
1309 EXPECT_TRUE(Rect::MakeXYWH(1.5, 2.3, 10.5, 0.0).IsEmpty());
1310 EXPECT_TRUE(Rect::MakeXYWH(1.5, 2.3, 10.5, -1.0).IsEmpty());
1311 EXPECT_TRUE(Rect::MakeXYWH(1.5, 2.3, 0.0, 7.2).IsEmpty());
1312 EXPECT_TRUE(Rect::MakeXYWH(1.5, 2.3, -1.0, 7.2).IsEmpty());
1313
1314 // Empty for NaN in width or height or both
1315 EXPECT_TRUE(Rect::MakeXYWH(1.5, 2.3, 10.5, nan).IsEmpty());
1316 EXPECT_TRUE(Rect::MakeXYWH(1.5, 2.3, nan, 7.2).IsEmpty());
1317 EXPECT_TRUE(Rect::MakeXYWH(1.5, 2.3, nan, nan).IsEmpty());
1318}

References impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [495/689]

impeller::testing::TEST ( RectTest  ,
TransformAndClipBoundsAllFourCornersClipped   
)

Definition at line 3567 of file rect_unittests.cc.

3567 {
3568 // This matrix should clip all four corners.
3569 auto matrix = impeller::Matrix::MakeColumn(
3570 // clang-format off
3571 2.0f, 0.0f, 0.0f, -.025f,
3572 0.0f, 2.0f, 0.0f, -.006f,
3573 0.0f, 0.0f, 1.0f, 0.0f,
3574 0.0f, 0.0f, 0.0f, 3.0f
3575 // clang-format on
3576 );
3577 Rect src = Rect::MakeLTRB(100.0f, 100.0f, 200.0f, 200.0f);
3578
3579 // All of these should have a W<0
3580 //
3581 // When W<0 we interpolate the point back towards the adjacent points
3582 // that have W>0 to a location just greater than the W=0 half-plane.
3583 // We interpolate them to W=epsilon where epsilon == 2^-14.
3584
3585 // In this case, none of the homogenous results are in bounds (W > 0)
3586 // so we can perform no interpolation - the operation is not visible.
3587
3588 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetLeftTop()),
3589 Vector3(200.0f, 200.0f, -0.1f));
3590 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetRightTop()),
3591 Vector3(400.0f, 200.0f, -2.6f));
3592 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetLeftBottom()),
3593 Vector3(200.0f, 400.0f, -0.7f));
3594 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetRightBottom()),
3595 Vector3(400.0f, 400.0f, -3.2f));
3596
3597 EXPECT_TRUE(src.TransformAndClipBounds(matrix).IsEmpty());
3598}
#define EXPECT_VECTOR3_NEAR(a, b)
static constexpr Matrix MakeColumn(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
Definition matrix.h:69

References EXPECT_VECTOR3_NEAR, impeller::Matrix::MakeColumn(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [496/689]

impeller::testing::TEST ( RectTest  ,
TransformAndClipBoundsNoCornersClipped   
)

Definition at line 3365 of file rect_unittests.cc.

3365 {
3366 // This matrix should clip no corners.
3367 auto matrix = impeller::Matrix::MakeColumn(
3368 // clang-format off
3369 2.0f, 0.0f, 0.0f, 0.0f,
3370 0.0f, 4.0f, 0.0f, 0.0f,
3371 0.0f, 0.0f, 1.0f, 0.0f,
3372 0.0f, 0.0f, 0.0f, 8.0f
3373 // clang-format on
3374 );
3375 Rect src = Rect::MakeLTRB(100.0f, 100.0f, 200.0f, 200.0f);
3376
3377 // None of these should have a W<0
3378
3379 EXPECT_EQ(matrix.TransformHomogenous(src.GetLeftTop()),
3380 Vector3(200.0f, 400.0f, 8.0f));
3381 EXPECT_EQ(matrix.TransformHomogenous(src.GetRightTop()),
3382 Vector3(400.0f, 400.0f, 8.0f));
3383 EXPECT_EQ(matrix.TransformHomogenous(src.GetLeftBottom()),
3384 Vector3(200.0f, 800.0f, 8.0f));
3385 EXPECT_EQ(matrix.TransformHomogenous(src.GetRightBottom()),
3386 Vector3(400.0f, 800.0f, 8.0f));
3387
3388 Rect expect = Rect::MakeLTRB(25.0f, 50.0f, 50.0f, 100.0f);
3389 EXPECT_FALSE(src.TransformAndClipBounds(matrix).IsEmpty());
3390 EXPECT_EQ(src.TransformAndClipBounds(matrix), expect);
3391}

References impeller::Matrix::MakeColumn(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [497/689]

impeller::testing::TEST ( RectTest  ,
TransformAndClipBoundsOneCornerClipped   
)

Definition at line 3393 of file rect_unittests.cc.

3393 {
3394 // This matrix should clip one corner.
3395 auto matrix = impeller::Matrix::MakeColumn(
3396 // clang-format off
3397 2.0f, 0.0f, 0.0f, -0.01f,
3398 0.0f, 2.0f, 0.0f, -0.006f,
3399 0.0f, 0.0f, 1.0f, 0.0f,
3400 0.0f, 0.0f, 0.0f, 3.0f
3401 // clang-format on
3402 );
3403 Rect src = Rect::MakeLTRB(100.0f, 100.0f, 200.0f, 200.0f);
3404
3405 // Exactly one of these should have a W<0
3406 //
3407 // When W<0 we interpolate the point back towards the adjacent points
3408 // that have W>0 to a location just greater than the W=0 half-plane.
3409 // We interpolate them to W=epsilon where epsilon == 2^-14.
3410
3411 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetLeftTop()),
3412 Vector3(200.0f, 200.0f, 1.4f));
3413 // Contributes (200, 200) / 1.4 == (142.85714, 142.85714)
3414
3415 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetRightTop()),
3416 Vector3(400.0f, 200.0f, 0.4f));
3417 // Contributes (400, 200) / 0.4 == (1000, 500)
3418
3419 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetLeftBottom()),
3420 Vector3(200.0f, 400.0f, 0.8f));
3421 // Contributes (200, 400) / 0.8 == (250, 500)
3422
3423 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetRightBottom()),
3424 Vector3(400.0f, 400.0f, -0.2f));
3425 // Interpolates at epsilon against RightTop to produce:
3426 // t = (epsilon - -.2) / (.4 - -.2)
3427 // = (epsilon + .2) / .6
3428 // = 0.333435
3429 // Lerp(RightBottom, RightTop, 0.333435) = (400, 333.313, epsilon)
3430 // = (6553600, 5461000)
3431 //
3432 // It also interpolates at epsilon against LeftBottom to produce:
3433 // t = (epsilon - -.2) / (.8 - -.2)
3434 // = (epsilon + .2) / 1
3435 // = 0.200061
3436 // Lerp(RightBottom, LeftBottom, 0.200061) = (359.988, 400, epsilon)
3437 // = (5898040, 6553600)
3438
3439 // Min/Max X and Y of all the points generated above are:
3440 // Min X == 142.85714
3441 // Min Y == 142.85714
3442 // Max X == 6553600
3443 // Max Y == 6553600
3444
3445 Rect expect = Rect::MakeLTRB(142.85714f, 142.85714f, 6553600.f, 6553600.f);
3446 EXPECT_FALSE(src.TransformAndClipBounds(matrix).IsEmpty());
3447 EXPECT_RECT_NEAR(src.TransformAndClipBounds(matrix), expect);
3448}

References EXPECT_RECT_NEAR, EXPECT_VECTOR3_NEAR, impeller::Matrix::MakeColumn(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [498/689]

impeller::testing::TEST ( RectTest  ,
TransformAndClipBoundsThreeCornersClipped   
)

Definition at line 3508 of file rect_unittests.cc.

3508 {
3509 // This matrix should clip three corners.
3510 auto matrix = impeller::Matrix::MakeColumn(
3511 // clang-format off
3512 2.0f, 0.0f, 0.0f, -.02f,
3513 0.0f, 2.0f, 0.0f, -.006f,
3514 0.0f, 0.0f, 1.0f, 0.0f,
3515 0.0f, 0.0f, 0.0f, 3.0f
3516 // clang-format on
3517 );
3518 Rect src = Rect::MakeLTRB(100.0f, 100.0f, 200.0f, 200.0f);
3519
3520 // Exactly three of these homogenous results should have a W<0
3521 //
3522 // When W<0 we interpolate the point back towards the adjacent points
3523 // that have W>0 to a location just greater than the W=0 half-plane.
3524 // We interpolate them to W=epsilon where epsilon == 2^-14.
3525
3526 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetLeftTop()),
3527 Vector3(200.0f, 200.0f, 0.4f));
3528 // Contributes (200, 200) / 0.4 == (500, 500) to bounds
3529
3530 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetRightTop()),
3531 Vector3(400.0f, 200.0f, -1.6f));
3532 // Interpolates at epsilon against LeftTop to produce:
3533 // t = (epsilon - -1.6) / (.4 - -1.6)
3534 // = (epsilon + 1.6) / 2
3535 // = 0.8000305
3536 // Lerp(RightTop, LeftTop, 0.8000305) = (239.9939, 200, epsilon)
3537 // = (3932060, 3276800)
3538 // Cannot interpolate against RightBottom because it also has W<0
3539
3540 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetLeftBottom()),
3541 Vector3(200.0f, 400.0f, -0.2f));
3542 // Interpolates against LeftTop to produce:
3543 // t = (epsilon - -.2) / (.4 - -.2)
3544 // = (epsilon + .2) / .6
3545 // = 0.333435
3546 // Lerp(LeftBottom, LeftTop, .333435) = (200, 333.31299, epsilon)
3547 // = (3276800, 5461000)
3548 // Cannot interpolate against RightBottom because it also has W<0
3549
3550 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetRightBottom()),
3551 Vector3(400.0f, 400.0f, -2.2f));
3552 // Cannot interpolate against either RightTop or LeftBottom because
3553 // both of those adjacent points transformed to a W<0 homogenous point.
3554
3555 // Min/Max X and Y of all the points generated above are:
3556 // Min X == 500
3557 // Min Y == 500
3558 // Max X == 3932060
3559 // Max Y == 5461000
3560
3561 Rect expect = Rect::MakeLTRB(500.0f, 500.0f, 3932060.f, 5461000.f);
3562
3563 EXPECT_FALSE(src.TransformAndClipBounds(matrix).IsEmpty());
3564 EXPECT_RECT_NEAR(src.TransformAndClipBounds(matrix), expect);
3565}

References EXPECT_RECT_NEAR, EXPECT_VECTOR3_NEAR, impeller::Matrix::MakeColumn(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [499/689]

impeller::testing::TEST ( RectTest  ,
TransformAndClipBoundsTwoCornersClipped   
)

Definition at line 3450 of file rect_unittests.cc.

3450 {
3451 // This matrix should clip two corners.
3452 auto matrix = impeller::Matrix::MakeColumn(
3453 // clang-format off
3454 2.0f, 0.0f, 0.0f, -.015f,
3455 0.0f, 2.0f, 0.0f, -.006f,
3456 0.0f, 0.0f, 1.0f, 0.0f,
3457 0.0f, 0.0f, 0.0f, 3.0f
3458 // clang-format on
3459 );
3460 Rect src = Rect::MakeLTRB(100.0f, 100.0f, 200.0f, 200.0f);
3461
3462 // Exactly two of these homogenous results should have a W<0
3463 //
3464 // When W<0 we interpolate the point back towards the adjacent points
3465 // that have W>0 to a location just greater than the W=0 half-plane.
3466 // We interpolate them to W=epsilon where epsilon == 2^-14.
3467
3468 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetLeftTop()),
3469 Vector3(200.0f, 200.0f, 0.9f));
3470 // Contributes (200, 200) / 0.9 == (222.2222, 222.2222) to bounds
3471
3472 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetRightTop()),
3473 Vector3(400.0f, 200.0f, -0.6f));
3474 // Interpolates at epsilon against LeftTop to produce:
3475 // t = (epsilon - -.6) / (.9 - -.6)
3476 // = (epsilon + .6) / 1.5
3477 // = 0.4000407
3478 // Lerp(RightTop, LeftTop, 0.4000407) = (319.9919, 200, epsilon)
3479 // = (5242747, 3276800)
3480 // Cannot interpolate against RightBottom because it also has W<0
3481
3482 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetLeftBottom()),
3483 Vector3(200.0f, 400.0f, 0.3f));
3484 // Contributes (200, 400) / 0.3 == (666.6667, 1333.3333) to bounds
3485
3486 EXPECT_VECTOR3_NEAR(matrix.TransformHomogenous(src.GetRightBottom()),
3487 Vector3(400.0f, 400.0f, -1.2f));
3488 // Interpolates at epsilon against LeftBottom to produce:
3489 // t = (epsilon - -1.2) / (.3 - -1.2)
3490 // = (epsilon + 1.2) / 1.5
3491 // = 0.8000407
3492 // Lerp(RightBottom, LeftBottom, 0.8000407) = (239.9919, 400, epsilon)
3493 // = (3932026.667, 6553600)
3494 // Cannot interpolate against RightTop because it also has W<0
3495
3496 // Min/Max X and Y of all the points generated above are:
3497 // Min X == 222.2222
3498 // Min Y == 222.2222
3499 // Max X == 5242747
3500 // Max Y == 6553600
3501
3502 Rect expect = Rect::MakeLTRB(222.2222f, 222.2222f, 5242747.f, 6553600.f);
3503
3504 EXPECT_FALSE(src.TransformAndClipBounds(matrix).IsEmpty());
3505 EXPECT_RECT_NEAR(src.TransformAndClipBounds(matrix), expect);
3506}

References EXPECT_RECT_NEAR, EXPECT_VECTOR3_NEAR, impeller::Matrix::MakeColumn(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [500/689]

impeller::testing::TEST ( RenderPassBuilder  ,
CreatesMSAAResolveWithCorrectStore   
)

Definition at line 133 of file render_pass_builder_vk_unittests.cc.

133 {
135 auto const context = MockVulkanContextBuilder().Build();
136
137 // Create an MSAA color attachment.
138 builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt,
139 SampleCount::kCount4, LoadAction::kClear,
140 StoreAction::kMultisampleResolve);
141
142 auto render_pass = builder.Build(context->GetDevice());
143
144 EXPECT_TRUE(!!render_pass);
145
146 auto maybe_color = builder.GetColor0();
147 ASSERT_TRUE(maybe_color.has_value());
148 if (!maybe_color.has_value()) {
149 return;
150 }
151 vk::AttachmentDescription color = maybe_color.value();
152
153 // MSAA Texture.
154 EXPECT_EQ(color.initialLayout, vk::ImageLayout::eUndefined);
155 EXPECT_EQ(color.finalLayout, vk::ImageLayout::eGeneral);
156 EXPECT_EQ(color.loadOp, vk::AttachmentLoadOp::eClear);
157 EXPECT_EQ(color.storeOp, vk::AttachmentStoreOp::eDontCare);
158
159 auto maybe_resolve = builder.GetColor0Resolve();
160 ASSERT_TRUE(maybe_resolve.has_value());
161 if (!maybe_resolve.has_value()) {
162 return;
163 }
164 vk::AttachmentDescription resolve = maybe_resolve.value();
165
166 // MSAA Resolve Texture.
167 EXPECT_EQ(resolve.initialLayout, vk::ImageLayout::eUndefined);
168 EXPECT_EQ(resolve.finalLayout, vk::ImageLayout::eShaderReadOnlyOptimal);
169 EXPECT_EQ(resolve.loadOp, vk::AttachmentLoadOp::eClear);
170 EXPECT_EQ(resolve.storeOp, vk::AttachmentStoreOp::eStore);
171}
std::optional< vk::AttachmentDescription > GetColor0() const
RenderPassBuilderVK & SetColorAttachment(size_t index, PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action, vk::ImageLayout current_layout=vk::ImageLayout::eUndefined, bool is_swapchain=false)
vk::UniqueRenderPass Build(const vk::Device &device) const
std::optional< vk::AttachmentDescription > GetColor0Resolve() const
std::shared_ptr< RenderPass > render_pass

References impeller::testing::MockVulkanContextBuilder::Build(), impeller::RenderPassBuilderVK::Build(), context, impeller::RenderPassBuilderVK::GetColor0(), impeller::RenderPassBuilderVK::GetColor0Resolve(), impeller::kClear, impeller::kCount4, impeller::kMultisampleResolve, impeller::kR8G8B8A8UNormInt, render_pass, and impeller::RenderPassBuilderVK::SetColorAttachment().

◆ TEST() [501/689]

impeller::testing::TEST ( RenderPassBuilder  ,
CreatesRenderPassWithCombinedDepthStencil   
)

Definition at line 56 of file render_pass_builder_vk_unittests.cc.

56 {
58 auto const context = MockVulkanContextBuilder().Build();
59
60 // Create a single color attachment with a transient depth stencil.
61 builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt,
62 SampleCount::kCount1, LoadAction::kClear,
63 StoreAction::kStore, vk::ImageLayout::eGeneral);
64 builder.SetDepthStencilAttachment(PixelFormat::kD24UnormS8Uint,
65 SampleCount::kCount1, LoadAction::kDontCare,
66 StoreAction::kDontCare);
67
68 auto render_pass = builder.Build(context->GetDevice());
69
70 EXPECT_TRUE(!!render_pass);
71
72 std::optional<vk::AttachmentDescription> maybe_color = builder.GetColor0();
73 ASSERT_TRUE(maybe_color.has_value());
74 if (!maybe_color.has_value()) {
75 return;
76 }
77 vk::AttachmentDescription color = maybe_color.value();
78
79 EXPECT_EQ(color.initialLayout, vk::ImageLayout::eUndefined);
80 EXPECT_EQ(color.finalLayout, vk::ImageLayout::eShaderReadOnlyOptimal);
81 EXPECT_EQ(color.loadOp, vk::AttachmentLoadOp::eClear);
82 EXPECT_EQ(color.storeOp, vk::AttachmentStoreOp::eStore);
83
84 std::optional<vk::AttachmentDescription> maybe_depth_stencil =
85 builder.GetDepthStencil();
86 ASSERT_TRUE(maybe_depth_stencil.has_value());
87 if (!maybe_depth_stencil.has_value()) {
88 return;
89 }
90 vk::AttachmentDescription depth_stencil = maybe_depth_stencil.value();
91
92 EXPECT_EQ(depth_stencil.initialLayout, vk::ImageLayout::eUndefined);
93 EXPECT_EQ(depth_stencil.finalLayout,
94 vk::ImageLayout::eDepthStencilAttachmentOptimal);
95 EXPECT_EQ(depth_stencil.loadOp, vk::AttachmentLoadOp::eDontCare);
96 EXPECT_EQ(depth_stencil.storeOp, vk::AttachmentStoreOp::eDontCare);
97 EXPECT_EQ(depth_stencil.stencilLoadOp, vk::AttachmentLoadOp::eDontCare);
98 EXPECT_EQ(depth_stencil.stencilStoreOp, vk::AttachmentStoreOp::eDontCare);
99}
RenderPassBuilderVK & SetDepthStencilAttachment(PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
const std::optional< vk::AttachmentDescription > & GetDepthStencil() const

References impeller::testing::MockVulkanContextBuilder::Build(), impeller::RenderPassBuilderVK::Build(), context, impeller::RenderPassBuilderVK::GetColor0(), impeller::RenderPassBuilderVK::GetDepthStencil(), impeller::kClear, impeller::kCount1, impeller::kD24UnormS8Uint, impeller::kDontCare, impeller::kR8G8B8A8UNormInt, impeller::kStore, render_pass, impeller::RenderPassBuilderVK::SetColorAttachment(), and impeller::RenderPassBuilderVK::SetDepthStencilAttachment().

◆ TEST() [502/689]

impeller::testing::TEST ( RenderPassBuilder  ,
CreatesRenderPassWithNoDepthStencil   
)

Definition at line 15 of file render_pass_builder_vk_unittests.cc.

15 {
17 auto const context = MockVulkanContextBuilder().Build();
18
19 // Create a single color attachment with a transient depth stencil.
20 builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt,
21 SampleCount::kCount1, LoadAction::kClear,
22 StoreAction::kStore);
23
24 auto render_pass = builder.Build(context->GetDevice());
25
26 EXPECT_TRUE(!!render_pass);
27 EXPECT_FALSE(builder.GetDepthStencil().has_value());
28}

References impeller::testing::MockVulkanContextBuilder::Build(), impeller::RenderPassBuilderVK::Build(), context, impeller::RenderPassBuilderVK::GetDepthStencil(), impeller::kClear, impeller::kCount1, impeller::kR8G8B8A8UNormInt, impeller::kStore, render_pass, and impeller::RenderPassBuilderVK::SetColorAttachment().

◆ TEST() [503/689]

impeller::testing::TEST ( RenderPassBuilder  ,
CreatesRenderPassWithOnlyStencil   
)

Definition at line 101 of file render_pass_builder_vk_unittests.cc.

101 {
103 auto const context = MockVulkanContextBuilder().Build();
104
105 // Create a single color attachment with a transient depth stencil.
106 builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt,
107 SampleCount::kCount1, LoadAction::kClear,
108 StoreAction::kStore);
109 builder.SetStencilAttachment(PixelFormat::kS8UInt, SampleCount::kCount1,
110 LoadAction::kDontCare, StoreAction::kDontCare);
111
112 auto render_pass = builder.Build(context->GetDevice());
113
114 EXPECT_TRUE(!!render_pass);
115
116 std::optional<vk::AttachmentDescription> maybe_depth_stencil =
117 builder.GetDepthStencil();
118 ASSERT_TRUE(maybe_depth_stencil.has_value());
119 if (!maybe_depth_stencil.has_value()) {
120 return;
121 }
122 vk::AttachmentDescription depth_stencil = maybe_depth_stencil.value();
123
124 EXPECT_EQ(depth_stencil.initialLayout, vk::ImageLayout::eUndefined);
125 EXPECT_EQ(depth_stencil.finalLayout,
126 vk::ImageLayout::eDepthStencilAttachmentOptimal);
127 EXPECT_EQ(depth_stencil.loadOp, vk::AttachmentLoadOp::eDontCare);
128 EXPECT_EQ(depth_stencil.storeOp, vk::AttachmentStoreOp::eDontCare);
129 EXPECT_EQ(depth_stencil.stencilLoadOp, vk::AttachmentLoadOp::eDontCare);
130 EXPECT_EQ(depth_stencil.stencilStoreOp, vk::AttachmentStoreOp::eDontCare);
131}
RenderPassBuilderVK & SetStencilAttachment(PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)

References impeller::testing::MockVulkanContextBuilder::Build(), impeller::RenderPassBuilderVK::Build(), context, impeller::RenderPassBuilderVK::GetDepthStencil(), impeller::kClear, impeller::kCount1, impeller::kDontCare, impeller::kR8G8B8A8UNormInt, impeller::kS8UInt, impeller::kStore, render_pass, impeller::RenderPassBuilderVK::SetColorAttachment(), and impeller::RenderPassBuilderVK::SetStencilAttachment().

◆ TEST() [504/689]

impeller::testing::TEST ( RenderPassBuilder  ,
RenderPassWithLoadOpUsesCurrentLayout   
)

Definition at line 30 of file render_pass_builder_vk_unittests.cc.

30 {
32 auto const context = MockVulkanContextBuilder().Build();
33
34 builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt,
35 SampleCount::kCount1, LoadAction::kLoad,
36 StoreAction::kStore,
37 vk::ImageLayout::eColorAttachmentOptimal);
38
39 auto render_pass = builder.Build(context->GetDevice());
40
41 EXPECT_TRUE(!!render_pass);
42
43 std::optional<vk::AttachmentDescription> maybe_color = builder.GetColor0();
44 ASSERT_TRUE(maybe_color.has_value());
45 if (!maybe_color.has_value()) {
46 return;
47 }
48 vk::AttachmentDescription color = maybe_color.value();
49
50 EXPECT_EQ(color.initialLayout, vk::ImageLayout::eColorAttachmentOptimal);
51 EXPECT_EQ(color.finalLayout, vk::ImageLayout::eShaderReadOnlyOptimal);
52 EXPECT_EQ(color.loadOp, vk::AttachmentLoadOp::eLoad);
53 EXPECT_EQ(color.storeOp, vk::AttachmentStoreOp::eStore);
54}

References impeller::testing::MockVulkanContextBuilder::Build(), impeller::RenderPassBuilderVK::Build(), context, impeller::RenderPassBuilderVK::GetColor0(), impeller::kCount1, impeller::kLoad, impeller::kR8G8B8A8UNormInt, impeller::kStore, render_pass, and impeller::RenderPassBuilderVK::SetColorAttachment().

◆ TEST() [505/689]

impeller::testing::TEST ( RenderPassGLESTest  ,
ResolvingMultisampleTextureCachesResolveFBO   
)

Definition at line 173 of file render_pass_gles_unittests.cc.

173 {
174 auto mock_gl_impl = std::make_unique<NiceMock<MockGLESImpl>>();
175 auto& mock_gl_impl_ref = *mock_gl_impl;
176 // Make sure implicit resolving isn't supported so we go down explicit path.
177 auto mock_gl =
178 MockGLES::Init(std::move(mock_gl_impl), std::nullopt, "OpenGL ES 3.0");
179
180 auto context = CreateFakeGLESContext();
181 auto dummy_worker = std::make_shared<MockWorker>();
182 context->AddReactorWorker(dummy_worker);
183 auto reactor = context->GetReactor();
184
185 const auto command_buffer =
186 std::static_pointer_cast<Context>(context)->CreateCommandBuffer();
187
188 const auto msaa_desc =
189 TextureDescriptor{.type = TextureType::kTexture2DMultisample,
190 .format = PixelFormat::kR8G8B8A8UNormInt,
191 .size = {10, 10},
192 .usage = TextureUsage::kRenderTarget,
193 .sample_count = SampleCount::kCount4};
194 const auto resolve_desc =
195 TextureDescriptor{.storage_mode = StorageMode::kDevicePrivate,
196 .type = TextureType::kTexture2D,
197 .format = PixelFormat::kR8G8B8A8UNormInt,
198 .size = {10, 10},
199 .usage = TextureUsage::kRenderTarget,
200 .sample_count = SampleCount::kCount1};
201
202 auto msaa_tex = std::make_shared<TextureGLES>(reactor, msaa_desc);
203 auto resolve_tex = std::make_shared<TextureGLES>(reactor, resolve_desc);
204
205 auto render_target = RenderTarget{};
206 auto color_attachment = ColorAttachment{Attachment{
207 .texture = msaa_tex,
208 .resolve_texture = resolve_tex,
209 .load_action = LoadAction::kClear,
210 .store_action = StoreAction::kMultisampleResolve,
211 }};
212 color_attachment.clear_color = Color::Black();
213 render_target.SetColorAttachment(color_attachment, 0);
214
215 EXPECT_CALL(mock_gl_impl_ref, CheckFramebufferStatus(_))
216 .WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE));
217
218 // Expect GenFramebuffers is called exactly once for the offscreen FBO,
219 // and exactly once for the resolve FBO over two passes.
220 EXPECT_CALL(mock_gl_impl_ref, GenFramebuffers(_, _)).Times(2);
221
222 {
223 const auto render_pass = command_buffer->CreateRenderPass(render_target);
224 ASSERT_TRUE(render_pass->EncodeCommands());
225 ASSERT_TRUE(reactor->React());
226 }
227 {
228 const auto render_pass2 = command_buffer->CreateRenderPass(render_target);
229 ASSERT_TRUE(render_pass2->EncodeCommands());
230 ASSERT_TRUE(reactor->React());
231 }
232}
std::shared_ptr< MockWorker > dummy_worker
testing::NiceMock< MockGLESImpl > & mock_gl_impl_ref

References impeller::Color::Black(), command_buffer, context, dummy_worker, impeller::testing::MockGLES::Init(), impeller::kClear, impeller::kCount1, impeller::kCount4, impeller::kDevicePrivate, impeller::kMultisampleResolve, impeller::kR8G8B8A8UNormInt, impeller::kRenderTarget, impeller::kTexture2D, impeller::kTexture2DMultisample, mock_gl, mock_gl_impl_ref, reactor, render_pass, impeller::TextureDescriptor::storage_mode, impeller::Attachment::texture, and impeller::TextureDescriptor::type.

◆ TEST() [506/689]

impeller::testing::TEST ( RenderPassVK  ,
DoesNotRedundantlySetStencil   
)

Definition at line 18 of file render_pass_vk_unittests.cc.

18 {
19 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
20 std::shared_ptr<Context> copy = context;
21 auto cmd_buffer = context->CreateCommandBuffer();
22
23 RenderTargetAllocator allocator(context->GetResourceAllocator());
24 RenderTarget target = allocator.CreateOffscreenMSAA(*copy.get(), {1, 1}, 1);
25
26 std::shared_ptr<RenderPass> render_pass =
27 cmd_buffer->CreateRenderPass(target);
28
29 // Stencil reference set once at buffer start.
30 auto called_functions = GetMockVulkanFunctions(context->GetDevice());
31 EXPECT_EQ(std::count(called_functions->begin(), called_functions->end(),
32 "vkCmdSetStencilReference"),
33 1);
34
35 // Duplicate stencil ref is not replaced.
36 render_pass->SetStencilReference(0);
37 render_pass->SetStencilReference(0);
38 render_pass->SetStencilReference(0);
39
40 called_functions = GetMockVulkanFunctions(context->GetDevice());
41 EXPECT_EQ(std::count(called_functions->begin(), called_functions->end(),
42 "vkCmdSetStencilReference"),
43 1);
44
45 // Different stencil value is updated.
46 render_pass->SetStencilReference(1);
47 called_functions = GetMockVulkanFunctions(context->GetDevice());
48 EXPECT_EQ(std::count(called_functions->begin(), called_functions->end(),
49 "vkCmdSetStencilReference"),
50 2);
51}
a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated r...

References allocator, impeller::testing::MockVulkanContextBuilder::Build(), context, GetMockVulkanFunctions(), render_pass, and target.

◆ TEST() [507/689]

impeller::testing::TEST ( RenderPassVK  ,
SetViewportPropagatesAllUserSuppliedFields   
)

Definition at line 56 of file render_pass_vk_unittests.cc.

56 {
57 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
58 auto cmd_buffer = context->CreateCommandBuffer();
59
60 RenderTargetAllocator allocator(context->GetResourceAllocator());
61 RenderTarget target = allocator.CreateOffscreenMSAA(*context, {100, 100},
62 /*mip_count=*/1);
63
64 std::shared_ptr<RenderPass> render_pass =
65 cmd_buffer->CreateRenderPass(target);
66
67 // The render pass constructor sets an initial full-target viewport. Capture
68 // a reference to the recorded viewport list before the user-driven call so
69 // we can isolate the call under test.
70 VkCommandBuffer raw_cmd_buffer =
71 CommandBufferVK::Cast(*cmd_buffer).GetCommandBuffer();
72 const std::vector<VkViewport>& recorded =
73 GetRecordedViewports(raw_cmd_buffer);
74 ASSERT_EQ(recorded.size(), 1u); // Initial full-target viewport.
75
76 render_pass->SetViewport(Viewport{
77 .rect = Rect::MakeXYWH(25, 10, 50, 80),
78 .depth_range = DepthRange{.z_near = 0.25f, .z_far = 0.75f},
79 });
80
81 ASSERT_EQ(recorded.size(), 2u);
82 const VkViewport& vp = recorded[1];
83 EXPECT_FLOAT_EQ(vp.x, 25.0f);
84 // Y is computed for the negative-height Y-flip: `y + height` of the
85 // original rect.
86 EXPECT_FLOAT_EQ(vp.y, 90.0f);
87 EXPECT_FLOAT_EQ(vp.width, 50.0f);
88 EXPECT_FLOAT_EQ(vp.height, -80.0f);
89 EXPECT_FLOAT_EQ(vp.minDepth, 0.25f);
90 EXPECT_FLOAT_EQ(vp.maxDepth, 0.75f);
91}

References allocator, impeller::testing::MockVulkanContextBuilder::Build(), impeller::BackendCast< CommandBufferVK, CommandBuffer >::Cast(), context, impeller::CommandBufferVK::GetCommandBuffer(), GetRecordedViewports(), impeller::TRect< Scalar >::MakeXYWH(), impeller::Viewport::rect, render_pass, target, and impeller::DepthRange::z_near.

◆ TEST() [508/689]

impeller::testing::TEST ( ResourceManagerVKTest  ,
CreatesANewInstance   
)

Definition at line 18 of file resource_manager_vk_unittests.cc.

18 {
19 auto const a = ResourceManagerVK::Create();
20 auto const b = ResourceManagerVK::Create();
21 EXPECT_NE(a, b);
22}

References impeller::ResourceManagerVK::Create().

◆ TEST() [509/689]

impeller::testing::TEST ( ResourceManagerVKTest  ,
IsThreadSafe   
)

Definition at line 58 of file resource_manager_vk_unittests.cc.

58 {
59 // In a typical app, there is a single ResourceManagerVK per app, shared b/w
60 // threads.
61 //
62 // This test ensures that the ResourceManagerVK is thread-safe.
63 std::weak_ptr<ResourceManagerVK> manager;
64
65 {
66 auto const manager = ResourceManagerVK::Create();
67
68 // Spawn two threads, and have them both put resources into the manager.
69 struct MockResource {};
70
71 std::thread thread1([&manager]() {
72 UniqueResourceVKT<MockResource>(manager, MockResource{});
73 });
74
75 std::thread thread2([&manager]() {
76 UniqueResourceVKT<MockResource>(manager, MockResource{});
77 });
78
79 thread1.join();
80 thread2.join();
81 }
82
83 // The thread should have terminated.
84 EXPECT_EQ(manager.lock(), nullptr);
85}
A unique handle to a resource which will be reclaimed by the specified resource manager.
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font manager

References impeller::ResourceManagerVK::Create(), and flutter::manager.

◆ TEST() [510/689]

impeller::testing::TEST ( ResourceManagerVKTest  ,
ReclaimMovesAResourceAndDestroysIt   
)

Definition at line 24 of file resource_manager_vk_unittests.cc.

24 {
25 auto const manager = ResourceManagerVK::Create();
26
27 auto waiter = fml::AutoResetWaitableEvent();
28 auto dead = false;
29 auto rattle = fml::ScopedCleanupClosure([&waiter]() { waiter.Signal(); });
30
31 // Not killed immediately.
32 EXPECT_FALSE(waiter.IsSignaledForTest());
33
34 {
36 manager, std::move(rattle));
37 }
38
39 waiter.Wait();
40}
Wraps a closure that is invoked in the destructor unless released by the caller.
Definition closure.h:32

References impeller::ResourceManagerVK::Create(), and flutter::manager.

◆ TEST() [511/689]

impeller::testing::TEST ( ResourceManagerVKTest  ,
TerminatesWhenOutOfScope   
)

Definition at line 43 of file resource_manager_vk_unittests.cc.

43 {
44 // Originally, this shared_ptr was never destroyed, and the thread never
45 // terminated. This test ensures that the thread terminates when the
46 // ResourceManagerVK is out of scope.
47 std::weak_ptr<ResourceManagerVK> manager;
48
49 {
50 auto shared = ResourceManagerVK::Create();
51 manager = shared;
52 }
53
54 // The thread should have terminated.
55 EXPECT_EQ(manager.lock(), nullptr);
56}

References impeller::ResourceManagerVK::Create(), and flutter::manager.

◆ TEST() [512/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiCornersSameTolerance   
)

Definition at line 281 of file rounding_radii_unittests.cc.

281 {
282 RoundingRadii radii{
283 .top_left = {10, 20},
284 .top_right = {10.01, 20.01},
285 .bottom_left = {9.99, 19.99},
286 .bottom_right = {9.99, 20.01},
287 };
288
289 EXPECT_TRUE(radii.AreAllCornersSame(.02));
290
291 {
292 RoundingRadii different = radii;
293 different.top_left.width = 10.03;
294 EXPECT_FALSE(different.AreAllCornersSame(.02));
295 }
296 {
297 RoundingRadii different = radii;
298 different.top_left.height = 20.03;
299 EXPECT_FALSE(different.AreAllCornersSame(.02));
300 }
301 {
302 RoundingRadii different = radii;
303 different.top_right.width = 10.03;
304 EXPECT_FALSE(different.AreAllCornersSame(.02));
305 }
306 {
307 RoundingRadii different = radii;
308 different.top_right.height = 20.03;
309 EXPECT_FALSE(different.AreAllCornersSame(.02));
310 }
311 {
312 RoundingRadii different = radii;
313 different.bottom_left.width = 9.97;
314 EXPECT_FALSE(different.AreAllCornersSame(.02));
315 }
316 {
317 RoundingRadii different = radii;
318 different.bottom_left.height = 19.97;
319 EXPECT_FALSE(different.AreAllCornersSame(.02));
320 }
321 {
322 RoundingRadii different = radii;
323 different.bottom_right.width = 9.97;
324 EXPECT_FALSE(different.AreAllCornersSame(.02));
325 }
326 {
327 RoundingRadii different = radii;
328 different.bottom_right.height = 20.03;
329 EXPECT_FALSE(different.AreAllCornersSame(.02));
330 }
331}

References impeller::RoundingRadii::AreAllCornersSame(), impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, flutter::Size::height(), impeller::RoundingRadii::top_left, impeller::RoundingRadii::top_right, and flutter::Size::width().

◆ TEST() [513/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiDefaultConstructor   
)

Definition at line 35 of file rounding_radii_unittests.cc.

35 {
37
38 EXPECT_TRUE(radii.AreAllCornersEmpty());
39 EXPECT_TRUE(radii.AreAllCornersSame());
40 EXPECT_TRUE(radii.AreAllCornersCircular());
41 EXPECT_TRUE(radii.IsFinite());
42 EXPECT_EQ(radii.top_left, Size());
43 EXPECT_EQ(radii.top_right, Size());
44 EXPECT_EQ(radii.bottom_left, Size());
45 EXPECT_EQ(radii.bottom_right, Size());
46}
constexpr bool AreAllCornersEmpty() const
constexpr bool IsFinite() const
constexpr bool AreAllCornersCircular() const
constexpr bool AreAllCornersSame(Scalar tolerance=kEhCloseEnough) const

References impeller::RoundingRadii::AreAllCornersCircular(), impeller::RoundingRadii::AreAllCornersEmpty(), impeller::RoundingRadii::AreAllCornersSame(), impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundingRadii::IsFinite(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [514/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiEmptyDeclaration   
)

Definition at line 14 of file rounding_radii_unittests.cc.

14 {
15 RoundingRadii radii;
16
17 EXPECT_TRUE(radii.AreAllCornersEmpty());
18 EXPECT_TRUE(radii.AreAllCornersSame());
19 EXPECT_TRUE(radii.AreAllCornersCircular());
20 EXPECT_TRUE(radii.IsFinite());
21 EXPECT_EQ(radii.top_left, Size());
22 EXPECT_EQ(radii.top_right, Size());
23 EXPECT_EQ(radii.bottom_left, Size());
24 EXPECT_EQ(radii.bottom_right, Size());
25 EXPECT_EQ(radii.top_left.width, 0.0f);
26 EXPECT_EQ(radii.top_left.height, 0.0f);
27 EXPECT_EQ(radii.top_right.width, 0.0f);
28 EXPECT_EQ(radii.top_right.height, 0.0f);
29 EXPECT_EQ(radii.bottom_left.width, 0.0f);
30 EXPECT_EQ(radii.bottom_left.height, 0.0f);
31 EXPECT_EQ(radii.bottom_right.width, 0.0f);
32 EXPECT_EQ(radii.bottom_right.height, 0.0f);
33}

References impeller::RoundingRadii::AreAllCornersCircular(), impeller::RoundingRadii::AreAllCornersEmpty(), impeller::RoundingRadii::AreAllCornersSame(), impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, flutter::Size::height(), impeller::RoundingRadii::IsFinite(), impeller::RoundingRadii::top_left, impeller::RoundingRadii::top_right, and flutter::Size::width().

◆ TEST() [515/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiEmptyScalarConstructor   
)

Definition at line 61 of file rounding_radii_unittests.cc.

61 {
62 RoundingRadii radii = RoundingRadii::MakeRadius(-5.0f);
63
64 EXPECT_TRUE(radii.AreAllCornersEmpty());
65 EXPECT_TRUE(radii.AreAllCornersSame());
66 EXPECT_TRUE(radii.AreAllCornersCircular());
67 EXPECT_TRUE(radii.IsFinite());
68 EXPECT_EQ(radii.top_left, Size(-5.0f, -5.0f));
69 EXPECT_EQ(radii.top_right, Size(-5.0f, -5.0f));
70 EXPECT_EQ(radii.bottom_left, Size(-5.0f, -5.0f));
71 EXPECT_EQ(radii.bottom_right, Size(-5.0f, -5.0f));
72}

References impeller::RoundingRadii::AreAllCornersCircular(), impeller::RoundingRadii::AreAllCornersEmpty(), impeller::RoundingRadii::AreAllCornersSame(), impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundingRadii::IsFinite(), impeller::RoundingRadii::MakeRadius(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [516/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiEmptySizeConstructor   
)

Definition at line 87 of file rounding_radii_unittests.cc.

87 {
88 {
89 RoundingRadii radii = RoundingRadii::MakeRadii(Size(-5.0f, 6.0f));
90
91 EXPECT_TRUE(radii.AreAllCornersEmpty());
92 EXPECT_TRUE(radii.AreAllCornersSame());
93 EXPECT_FALSE(radii.AreAllCornersCircular());
94 EXPECT_TRUE(radii.IsFinite());
95 EXPECT_EQ(radii.top_left, Size(-5.0f, 6.0f));
96 EXPECT_EQ(radii.top_right, Size(-5.0f, 6.0f));
97 EXPECT_EQ(radii.bottom_left, Size(-5.0f, 6.0f));
98 EXPECT_EQ(radii.bottom_right, Size(-5.0f, 6.0f));
99 }
100
101 {
102 RoundingRadii radii = RoundingRadii::MakeRadii(Size(5.0f, -6.0f));
103
104 EXPECT_TRUE(radii.AreAllCornersEmpty());
105 EXPECT_TRUE(radii.AreAllCornersSame());
106 EXPECT_FALSE(radii.AreAllCornersCircular());
107 EXPECT_TRUE(radii.IsFinite());
108 EXPECT_EQ(radii.top_left, Size(5.0f, -6.0f));
109 EXPECT_EQ(radii.top_right, Size(5.0f, -6.0f));
110 EXPECT_EQ(radii.bottom_left, Size(5.0f, -6.0f));
111 EXPECT_EQ(radii.bottom_right, Size(5.0f, -6.0f));
112 }
113}

References impeller::RoundingRadii::AreAllCornersCircular(), impeller::RoundingRadii::AreAllCornersEmpty(), impeller::RoundingRadii::AreAllCornersSame(), impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundingRadii::IsFinite(), impeller::RoundingRadii::MakeRadii(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [517/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiEquals   
)

Definition at line 214 of file rounding_radii_unittests.cc.

214 {
215 RoundingRadii radii = {
216 .top_left = Size(5.0f, 5.5f),
217 .top_right = Size(6.0f, 6.5f),
218 .bottom_left = Size(7.0f, 7.5f),
219 .bottom_right = Size(8.0f, 8.5f),
220 };
221 RoundingRadii other = {
222 .top_left = Size(5.0f, 5.5f),
223 .top_right = Size(6.0f, 6.5f),
224 .bottom_left = Size(7.0f, 7.5f),
225 .bottom_right = Size(8.0f, 8.5f),
226 };
227
228 EXPECT_EQ(radii, other);
229}

References impeller::RoundingRadii::top_left.

◆ TEST() [518/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiMultiply   
)

Definition at line 195 of file rounding_radii_unittests.cc.

195 {
196 RoundingRadii radii = {
197 .top_left = Size(5.0f, 5.5f),
198 .top_right = Size(6.0f, 6.5f),
199 .bottom_left = Size(7.0f, 7.5f),
200 .bottom_right = Size(8.0f, 8.5f),
201 };
202 RoundingRadii doubled = radii * 2.0f;
203
204 EXPECT_FALSE(doubled.AreAllCornersEmpty());
205 EXPECT_FALSE(doubled.AreAllCornersSame());
206 EXPECT_FALSE(doubled.AreAllCornersCircular());
207 EXPECT_TRUE(doubled.IsFinite());
208 EXPECT_EQ(doubled.top_left, Size(10.0f, 11.0f));
209 EXPECT_EQ(doubled.top_right, Size(12.0f, 13.0f));
210 EXPECT_EQ(doubled.bottom_left, Size(14.0f, 15.0f));
211 EXPECT_EQ(doubled.bottom_right, Size(16.0f, 17.0f));
212}

References impeller::RoundingRadii::AreAllCornersCircular(), impeller::RoundingRadii::AreAllCornersEmpty(), impeller::RoundingRadii::AreAllCornersSame(), impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundingRadii::IsFinite(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [519/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiNamedSizesConstructor   
)

Definition at line 115 of file rounding_radii_unittests.cc.

115 {
116 RoundingRadii radii = {
117 .top_left = Size(5.0f, 5.5f),
118 .top_right = Size(6.0f, 6.5f),
119 .bottom_left = Size(7.0f, 7.5f),
120 .bottom_right = Size(8.0f, 8.5f),
121 };
122
123 EXPECT_FALSE(radii.AreAllCornersEmpty());
124 EXPECT_FALSE(radii.AreAllCornersSame());
125 EXPECT_FALSE(radii.AreAllCornersCircular());
126 EXPECT_TRUE(radii.IsFinite());
127 EXPECT_EQ(radii.top_left, Size(5.0f, 5.5f));
128 EXPECT_EQ(radii.top_right, Size(6.0f, 6.5f));
129 EXPECT_EQ(radii.bottom_left, Size(7.0f, 7.5f));
130 EXPECT_EQ(radii.bottom_right, Size(8.0f, 8.5f));
131}

References impeller::RoundingRadii::AreAllCornersCircular(), impeller::RoundingRadii::AreAllCornersEmpty(), impeller::RoundingRadii::AreAllCornersSame(), impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundingRadii::IsFinite(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [520/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiNotEquals   
)

Definition at line 231 of file rounding_radii_unittests.cc.

231 {
232 const RoundingRadii radii = {
233 .top_left = Size(5.0f, 5.5f),
234 .top_right = Size(6.0f, 6.5f),
235 .bottom_left = Size(7.0f, 7.5f),
236 .bottom_right = Size(8.0f, 8.5f),
237 };
238
239 {
240 RoundingRadii different = radii;
241 different.top_left.width = 100.0f;
242 EXPECT_NE(different, radii);
243 }
244 {
245 RoundingRadii different = radii;
246 different.top_left.height = 100.0f;
247 EXPECT_NE(different, radii);
248 }
249 {
250 RoundingRadii different = radii;
251 different.top_right.width = 100.0f;
252 EXPECT_NE(different, radii);
253 }
254 {
255 RoundingRadii different = radii;
256 different.top_right.height = 100.0f;
257 EXPECT_NE(different, radii);
258 }
259 {
260 RoundingRadii different = radii;
261 different.bottom_left.width = 100.0f;
262 EXPECT_NE(different, radii);
263 }
264 {
265 RoundingRadii different = radii;
266 different.bottom_left.height = 100.0f;
267 EXPECT_NE(different, radii);
268 }
269 {
270 RoundingRadii different = radii;
271 different.bottom_right.width = 100.0f;
272 EXPECT_NE(different, radii);
273 }
274 {
275 RoundingRadii different = radii;
276 different.bottom_right.height = 100.0f;
277 EXPECT_NE(different, radii);
278 }
279}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, flutter::Size::height(), impeller::RoundingRadii::top_left, impeller::RoundingRadii::top_right, and flutter::Size::width().

◆ TEST() [521/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiPartialNamedSizesConstructor   
)

Definition at line 133 of file rounding_radii_unittests.cc.

133 {
134 {
135 RoundingRadii radii = {
136 .top_left = Size(5.0f, 5.5f),
137 };
138
139 EXPECT_FALSE(radii.AreAllCornersEmpty());
140 EXPECT_FALSE(radii.AreAllCornersSame());
141 EXPECT_FALSE(radii.AreAllCornersCircular());
142 EXPECT_TRUE(radii.IsFinite());
143 EXPECT_EQ(radii.top_left, Size(5.0f, 5.5f));
144 EXPECT_EQ(radii.top_right, Size());
145 EXPECT_EQ(radii.bottom_left, Size());
146 EXPECT_EQ(radii.bottom_right, Size());
147 }
148
149 {
150 RoundingRadii radii = {
151 .top_right = Size(6.0f, 6.5f),
152 };
153
154 EXPECT_FALSE(radii.AreAllCornersEmpty());
155 EXPECT_FALSE(radii.AreAllCornersSame());
156 EXPECT_FALSE(radii.AreAllCornersCircular());
157 EXPECT_TRUE(radii.IsFinite());
158 EXPECT_EQ(radii.top_left, Size());
159 EXPECT_EQ(radii.top_right, Size(6.0f, 6.5f));
160 EXPECT_EQ(radii.bottom_left, Size());
161 EXPECT_EQ(radii.bottom_right, Size());
162 }
163
164 {
165 RoundingRadii radii = {
166 .bottom_left = Size(7.0f, 7.5f),
167 };
168
169 EXPECT_FALSE(radii.AreAllCornersEmpty());
170 EXPECT_FALSE(radii.AreAllCornersSame());
171 EXPECT_FALSE(radii.AreAllCornersCircular());
172 EXPECT_TRUE(radii.IsFinite());
173 EXPECT_EQ(radii.top_left, Size());
174 EXPECT_EQ(radii.top_right, Size());
175 EXPECT_EQ(radii.bottom_left, Size(7.0f, 7.5f));
176 EXPECT_EQ(radii.bottom_right, Size());
177 }
178
179 {
180 RoundingRadii radii = {
181 .bottom_right = Size(8.0f, 8.5f),
182 };
183
184 EXPECT_FALSE(radii.AreAllCornersEmpty());
185 EXPECT_FALSE(radii.AreAllCornersSame());
186 EXPECT_FALSE(radii.AreAllCornersCircular());
187 EXPECT_TRUE(radii.IsFinite());
188 EXPECT_EQ(radii.top_left, Size());
189 EXPECT_EQ(radii.top_right, Size());
190 EXPECT_EQ(radii.bottom_left, Size());
191 EXPECT_EQ(radii.bottom_right, Size(8.0f, 8.5f));
192 }
193}

References impeller::RoundingRadii::AreAllCornersCircular(), impeller::RoundingRadii::AreAllCornersEmpty(), impeller::RoundingRadii::AreAllCornersSame(), impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundingRadii::IsFinite(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [522/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiScalarConstructor   
)

Definition at line 48 of file rounding_radii_unittests.cc.

48 {
49 RoundingRadii radii = RoundingRadii::MakeRadius(5.0f);
50
51 EXPECT_FALSE(radii.AreAllCornersEmpty());
52 EXPECT_TRUE(radii.AreAllCornersSame());
53 EXPECT_TRUE(radii.AreAllCornersCircular());
54 EXPECT_TRUE(radii.IsFinite());
55 EXPECT_EQ(radii.top_left, Size(5.0f, 5.0f));
56 EXPECT_EQ(radii.top_right, Size(5.0f, 5.0f));
57 EXPECT_EQ(radii.bottom_left, Size(5.0f, 5.0f));
58 EXPECT_EQ(radii.bottom_right, Size(5.0f, 5.0f));
59}

References impeller::RoundingRadii::AreAllCornersCircular(), impeller::RoundingRadii::AreAllCornersEmpty(), impeller::RoundingRadii::AreAllCornersSame(), impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundingRadii::IsFinite(), impeller::RoundingRadii::MakeRadius(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [523/689]

impeller::testing::TEST ( RoudingRadiiTest  ,
RoundingRadiiSizeConstructor   
)

Definition at line 74 of file rounding_radii_unittests.cc.

74 {
75 RoundingRadii radii = RoundingRadii::MakeRadii(Size(5.0f, 6.0f));
76
77 EXPECT_FALSE(radii.AreAllCornersEmpty());
78 EXPECT_TRUE(radii.AreAllCornersSame());
79 EXPECT_FALSE(radii.AreAllCornersCircular());
80 EXPECT_TRUE(radii.IsFinite());
81 EXPECT_EQ(radii.top_left, Size(5.0f, 6.0f));
82 EXPECT_EQ(radii.top_right, Size(5.0f, 6.0f));
83 EXPECT_EQ(radii.bottom_left, Size(5.0f, 6.0f));
84 EXPECT_EQ(radii.bottom_right, Size(5.0f, 6.0f));
85}

References impeller::RoundingRadii::AreAllCornersCircular(), impeller::RoundingRadii::AreAllCornersEmpty(), impeller::RoundingRadii::AreAllCornersSame(), impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundingRadii::IsFinite(), impeller::RoundingRadii::MakeRadii(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [524/689]

impeller::testing::TEST ( RoundRectTest  ,
ContractAndRequireRadiiAdjustment   
)

Definition at line 496 of file round_rect_unittests.cc.

496 {
497 RoundRect round_rect =
498 RoundRect::MakeRectRadii(Rect::MakeXYWH(10.0f, 10.0f, 30.0f, 30.0f),
499 {
500 .top_left = Size(1.0f, 2.0f),
501 .top_right = Size(3.0f, 4.0f),
502 .bottom_left = Size(5.0f, 6.0f),
503 .bottom_right = Size(7.0f, 8.0f),
504 });
505 RoundRect expanded = round_rect.Expand(-12.0);
506 // Largest sum of paired radii sizes are the bottom and right edges
507 // both of which sum to 12
508 // Rect was 30x30 reduced by 12 on all sides leaving only 6x6, so all
509 // radii are scaled by half to avoid overflowing the contracted rect
510
511 EXPECT_FALSE(expanded.IsEmpty());
512 EXPECT_FALSE(expanded.IsRect());
513 EXPECT_FALSE(expanded.IsOval());
514 EXPECT_TRUE(expanded.IsFinite());
515 EXPECT_FALSE(expanded.GetBounds().IsEmpty());
516 EXPECT_EQ(expanded.GetBounds(), Rect::MakeLTRB(22.0f, 22.0f, 28.0f, 28.0f));
517 EXPECT_EQ(expanded.GetRadii().top_left, Size(0.5f, 1.0f));
518 EXPECT_EQ(expanded.GetRadii().top_right, Size(1.5f, 2.0f));
519 EXPECT_EQ(expanded.GetRadii().bottom_left, Size(2.5f, 3.0f));
520 EXPECT_EQ(expanded.GetRadii().bottom_right, Size(3.5f, 4.0f));
521
522 // In this test, the MakeRectRadii constructor will make the same
523 // adjustment to the radii that the Expand method applied.
524 EXPECT_EQ(expanded,
525 RoundRect::MakeRectRadii(Rect::MakeXYWH(22.0f, 22.0f, 6.0f, 6.0f),
526 {
527 .top_left = Size(1.0f, 2.0f),
528 .top_right = Size(3.0f, 4.0f),
529 .bottom_left = Size(5.0f, 6.0f),
530 .bottom_right = Size(7.0f, 8.0f),
531 }));
532
533 // In this test, the arguments to the constructor supply the correctly
534 // adjusted radii (though there is no real way to tell other than
535 // the result is the same).
536 EXPECT_EQ(expanded,
537 RoundRect::MakeRectRadii(Rect::MakeXYWH(22.0f, 22.0f, 6.0f, 6.0f),
538 {
539 .top_left = Size(0.5f, 1.0f),
540 .top_right = Size(1.5f, 2.0f),
541 .bottom_left = Size(2.5f, 3.0f),
542 .bottom_right = Size(3.5f, 4.0f),
543 }));
544}
RoundRect Expand(Scalar left, Scalar top, Scalar right, Scalar bottom) const
Returns a round rectangle with expanded edges. Negative expansion results in shrinking.
Definition round_rect.h:98

References impeller::RoundRect::Expand(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [525/689]

impeller::testing::TEST ( RoundRectTest  ,
ContractFourScalars   
)

Definition at line 464 of file round_rect_unittests.cc.

464 {
465 RoundRect round_rect =
466 RoundRect::MakeRectRadii(Rect::MakeXYWH(10.0f, 10.0f, 30.0f, 30.0f),
467 {
468 .top_left = Size(1.0f, 2.0f),
469 .top_right = Size(3.0f, 4.0f),
470 .bottom_left = Size(5.0f, 6.0f),
471 .bottom_right = Size(7.0f, 8.0f),
472 });
473 RoundRect expanded = round_rect.Expand(-1.0, -1.5, -2.0, -2.5);
474
475 EXPECT_FALSE(expanded.IsEmpty());
476 EXPECT_FALSE(expanded.IsRect());
477 EXPECT_FALSE(expanded.IsOval());
478 EXPECT_TRUE(expanded.IsFinite());
479 EXPECT_FALSE(expanded.GetBounds().IsEmpty());
480 EXPECT_EQ(expanded.GetBounds(), Rect::MakeLTRB(11.0f, 11.5f, 38.0f, 37.5f));
481 EXPECT_EQ(expanded.GetRadii().top_left, Size(1.0f, 2.0f));
482 EXPECT_EQ(expanded.GetRadii().top_right, Size(3.0f, 4.0f));
483 EXPECT_EQ(expanded.GetRadii().bottom_left, Size(5.0f, 6.0f));
484 EXPECT_EQ(expanded.GetRadii().bottom_right, Size(7.0f, 8.0f));
485
486 EXPECT_EQ(expanded,
487 RoundRect::MakeRectRadii(Rect::MakeXYWH(11.0f, 11.5f, 27.0f, 26.0f),
488 {
489 .top_left = Size(1.0f, 2.0f),
490 .top_right = Size(3.0f, 4.0f),
491 .bottom_left = Size(5.0f, 6.0f),
492 .bottom_right = Size(7.0f, 8.0f),
493 }));
494}

References impeller::RoundRect::Expand(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [526/689]

impeller::testing::TEST ( RoundRectTest  ,
ContractScalar   
)

Definition at line 400 of file round_rect_unittests.cc.

400 {
401 RoundRect round_rect =
402 RoundRect::MakeRectRadii(Rect::MakeXYWH(10.0f, 10.0f, 30.0f, 30.0f),
403 {
404 .top_left = Size(1.0f, 2.0f),
405 .top_right = Size(3.0f, 4.0f),
406 .bottom_left = Size(5.0f, 6.0f),
407 .bottom_right = Size(7.0f, 8.0f),
408 });
409 RoundRect expanded = round_rect.Expand(-2.0);
410
411 EXPECT_FALSE(expanded.IsEmpty());
412 EXPECT_FALSE(expanded.IsRect());
413 EXPECT_FALSE(expanded.IsOval());
414 EXPECT_TRUE(expanded.IsFinite());
415 EXPECT_FALSE(expanded.GetBounds().IsEmpty());
416 EXPECT_EQ(expanded.GetBounds(), Rect::MakeLTRB(12.0f, 12.0f, 38.0f, 38.0f));
417 EXPECT_EQ(expanded.GetRadii().top_left, Size(1.0f, 2.0f));
418 EXPECT_EQ(expanded.GetRadii().top_right, Size(3.0f, 4.0f));
419 EXPECT_EQ(expanded.GetRadii().bottom_left, Size(5.0f, 6.0f));
420 EXPECT_EQ(expanded.GetRadii().bottom_right, Size(7.0f, 8.0f));
421
422 EXPECT_EQ(expanded,
423 RoundRect::MakeRectRadii(Rect::MakeXYWH(12.0f, 12.0f, 26.0f, 26.0f),
424 {
425 .top_left = Size(1.0f, 2.0f),
426 .top_right = Size(3.0f, 4.0f),
427 .bottom_left = Size(5.0f, 6.0f),
428 .bottom_right = Size(7.0f, 8.0f),
429 }));
430}

References impeller::RoundRect::Expand(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [527/689]

impeller::testing::TEST ( RoundRectTest  ,
ContractTwoScalars   
)

Definition at line 432 of file round_rect_unittests.cc.

432 {
433 RoundRect round_rect =
434 RoundRect::MakeRectRadii(Rect::MakeXYWH(10.0f, 10.0f, 30.0f, 30.0f),
435 {
436 .top_left = Size(1.0f, 2.0f),
437 .top_right = Size(3.0f, 4.0f),
438 .bottom_left = Size(5.0f, 6.0f),
439 .bottom_right = Size(7.0f, 8.0f),
440 });
441 RoundRect expanded = round_rect.Expand(-1.0, -2.0);
442
443 EXPECT_FALSE(expanded.IsEmpty());
444 EXPECT_FALSE(expanded.IsRect());
445 EXPECT_FALSE(expanded.IsOval());
446 EXPECT_TRUE(expanded.IsFinite());
447 EXPECT_FALSE(expanded.GetBounds().IsEmpty());
448 EXPECT_EQ(expanded.GetBounds(), Rect::MakeLTRB(11.0f, 12.0f, 39.0f, 38.0f));
449 EXPECT_EQ(expanded.GetRadii().top_left, Size(1.0f, 2.0f));
450 EXPECT_EQ(expanded.GetRadii().top_right, Size(3.0f, 4.0f));
451 EXPECT_EQ(expanded.GetRadii().bottom_left, Size(5.0f, 6.0f));
452 EXPECT_EQ(expanded.GetRadii().bottom_right, Size(7.0f, 8.0f));
453
454 EXPECT_EQ(expanded,
455 RoundRect::MakeRectRadii(Rect::MakeXYWH(11.0f, 12.0f, 28.0f, 26.0f),
456 {
457 .top_left = Size(1.0f, 2.0f),
458 .top_right = Size(3.0f, 4.0f),
459 .bottom_left = Size(5.0f, 6.0f),
460 .bottom_right = Size(7.0f, 8.0f),
461 }));
462}

References impeller::RoundRect::Expand(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [528/689]

impeller::testing::TEST ( RoundRectTest  ,
DefaultConstructor   
)

Definition at line 41 of file round_rect_unittests.cc.

41 {
42 RoundRect round_rect = RoundRect();
43
44 EXPECT_TRUE(round_rect.IsEmpty());
45 EXPECT_FALSE(round_rect.IsRect());
46 EXPECT_FALSE(round_rect.IsOval());
47 EXPECT_TRUE(round_rect.IsFinite());
48 EXPECT_TRUE(round_rect.GetBounds().IsEmpty());
49 EXPECT_EQ(round_rect.GetBounds(), Rect());
50 EXPECT_EQ(round_rect.GetRadii().top_left, Size());
51 EXPECT_EQ(round_rect.GetRadii().top_right, Size());
52 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size());
53 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size());
54}
constexpr bool IsFinite() const
Definition round_rect.h:57
constexpr bool IsEmpty() const
Definition round_rect.h:65
constexpr bool IsRect() const
Definition round_rect.h:67
constexpr const RoundingRadii & GetRadii() const
Definition round_rect.h:55
constexpr const Rect & GetBounds() const
Definition round_rect.h:53
constexpr bool IsOval() const
Definition round_rect.h:71

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [529/689]

impeller::testing::TEST ( RoundRectTest  ,
DifferingCornersRoundRectContains   
)

Definition at line 652 of file round_rect_unittests.cc.

652 {
653 Rect bounds = Rect::MakeLTRB(-50.0f, -50.0f, 50.0f, 50.0f);
654 auto round_rect =
655 RoundRect::MakeRectRadii(bounds, {
656 .top_left = Size(2.0, 3.0),
657 .top_right = Size(4.0, 5.0),
658 .bottom_left = Size(6.0, 7.0),
659 .bottom_right = Size(8.0, 9.0),
660 });
661
662 // For a corner with radii {A, B}, the "45 degree point" on the
663 // corner curve will be at an offset of:
664 //
665 // (A * sqrt(2) / 2, B * sqrt(2) / 2)
666 //
667 // And the center(s) of these corners are at:
668 //
669 // (+/-(50 - A), +/-(50 - B))
670 auto coord = [](Scalar radius) {
671 return 50 - radius + radius * kSqrt2 / 2.0f - kEhCloseEnough;
672 };
673 auto coord_in = [&coord](Scalar radius) {
674 return coord(radius) - kEhCloseEnough;
675 };
676 auto coord_out = [&coord](Scalar radius) {
677 // For some reason 1 kEhCloseEnough is not enough to put us outside
678 // in some of the cases, so we use 2x the epsilon.
679 return coord(radius) + 2 * kEhCloseEnough;
680 };
681 // Upper left corner (radii = {2.0, 3.0})
682 EXPECT_TRUE(round_rect.Contains({-coord_in(2.0), -coord_in(3.0)}));
683 EXPECT_FALSE(round_rect.Contains({-coord_out(2.0), -coord_out(3.0)}));
684 // Upper right corner (radii = {4.0, 5.0})
685 EXPECT_TRUE(round_rect.Contains({coord_in(4.0), -coord_in(5.0)}));
686 EXPECT_FALSE(round_rect.Contains({coord_out(4.0), -coord_out(5.0)}));
687 // Lower left corner (radii = {6.0, 7.0})
688 EXPECT_TRUE(round_rect.Contains({-coord_in(6.0), coord_in(7.0)}));
689 EXPECT_FALSE(round_rect.Contains({-coord_out(6.0), coord_out(7.0)}));
690 // Lower right corner (radii = {8.0, 9.0})
691 EXPECT_TRUE(round_rect.Contains({coord_in(8.0), coord_in(9.0)}));
692 EXPECT_FALSE(round_rect.Contains({coord_out(8.0), coord_out(9.0)}));
693}
constexpr float kEhCloseEnough
Definition constants.h:57

References flutter::kEhCloseEnough, impeller::kSqrt2, impeller::TRect< Scalar >::MakeLTRB(), and impeller::RoundRect::MakeRectRadii().

◆ TEST() [530/689]

impeller::testing::TEST ( RoundRectTest  ,
EmptyDeclaration   
)

Definition at line 14 of file round_rect_unittests.cc.

14 {
15 RoundRect round_rect;
16
17 EXPECT_TRUE(round_rect.IsEmpty());
18 EXPECT_FALSE(round_rect.IsRect());
19 EXPECT_FALSE(round_rect.IsOval());
20 EXPECT_TRUE(round_rect.IsFinite());
21 EXPECT_TRUE(round_rect.GetBounds().IsEmpty());
22 EXPECT_EQ(round_rect.GetBounds(), Rect());
23 EXPECT_EQ(round_rect.GetBounds().GetLeft(), 0.0f);
24 EXPECT_EQ(round_rect.GetBounds().GetTop(), 0.0f);
25 EXPECT_EQ(round_rect.GetBounds().GetRight(), 0.0f);
26 EXPECT_EQ(round_rect.GetBounds().GetBottom(), 0.0f);
27 EXPECT_EQ(round_rect.GetRadii().top_left, Size());
28 EXPECT_EQ(round_rect.GetRadii().top_right, Size());
29 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size());
30 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size());
31 EXPECT_EQ(round_rect.GetRadii().top_left.width, 0.0f);
32 EXPECT_EQ(round_rect.GetRadii().top_left.height, 0.0f);
33 EXPECT_EQ(round_rect.GetRadii().top_right.width, 0.0f);
34 EXPECT_EQ(round_rect.GetRadii().top_right.height, 0.0f);
35 EXPECT_EQ(round_rect.GetRadii().bottom_left.width, 0.0f);
36 EXPECT_EQ(round_rect.GetRadii().bottom_left.height, 0.0f);
37 EXPECT_EQ(round_rect.GetRadii().bottom_right.width, 0.0f);
38 EXPECT_EQ(round_rect.GetRadii().bottom_right.height, 0.0f);
39}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), flutter::Size::height(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::RoundingRadii::top_left, impeller::RoundingRadii::top_right, and flutter::Size::width().

◆ TEST() [531/689]

impeller::testing::TEST ( RoundRectTest  ,
EmptyOvalConstruction   
)

Definition at line 104 of file round_rect_unittests.cc.

104 {
105 RoundRect round_rect = RoundRect::MakeRectXY(
106 Rect::MakeLTRB(20.0f, 20.0f, 20.0f, 20.0f), 10.0f, 10.0f);
107
108 EXPECT_TRUE(round_rect.IsEmpty());
109 EXPECT_FALSE(round_rect.IsRect());
110 EXPECT_FALSE(round_rect.IsOval());
111 EXPECT_TRUE(round_rect.IsFinite());
112 EXPECT_TRUE(round_rect.GetBounds().IsEmpty());
113 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(20.0f, 20.0f, 20.0f, 20.0f));
114 EXPECT_EQ(round_rect.GetRadii().top_left, Size());
115 EXPECT_EQ(round_rect.GetRadii().top_right, Size());
116 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size());
117 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size());
118}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectXY(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [532/689]

impeller::testing::TEST ( RoundRectTest  ,
EmptyRectConstruction   
)

Definition at line 56 of file round_rect_unittests.cc.

56 {
57 RoundRect round_rect =
58 RoundRect::MakeRect(Rect::MakeLTRB(20.0f, 20.0f, 20.0f, 20.0f));
59
60 EXPECT_TRUE(round_rect.IsEmpty());
61 EXPECT_FALSE(round_rect.IsRect());
62 EXPECT_FALSE(round_rect.IsOval());
63 EXPECT_TRUE(round_rect.IsFinite());
64 EXPECT_TRUE(round_rect.GetBounds().IsEmpty());
65 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(20.0f, 20.0f, 20.0f, 20.0f));
66 EXPECT_EQ(round_rect.GetRadii().top_left, Size());
67 EXPECT_EQ(round_rect.GetRadii().top_right, Size());
68 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size());
69 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size());
70}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRect(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [533/689]

impeller::testing::TEST ( RoundRectTest  ,
ExpandFourScalars   
)

Definition at line 368 of file round_rect_unittests.cc.

368 {
369 RoundRect round_rect =
370 RoundRect::MakeRectRadii(Rect::MakeXYWH(10.0f, 10.0f, 30.0f, 30.0f),
371 {
372 .top_left = Size(1.0f, 2.0f),
373 .top_right = Size(3.0f, 4.0f),
374 .bottom_left = Size(5.0f, 6.0f),
375 .bottom_right = Size(7.0f, 8.0f),
376 });
377 RoundRect expanded = round_rect.Expand(5.0, 6.0, 7.0, 8.0);
378
379 EXPECT_FALSE(expanded.IsEmpty());
380 EXPECT_FALSE(expanded.IsRect());
381 EXPECT_FALSE(expanded.IsOval());
382 EXPECT_TRUE(expanded.IsFinite());
383 EXPECT_FALSE(expanded.GetBounds().IsEmpty());
384 EXPECT_EQ(expanded.GetBounds(), Rect::MakeLTRB(5.0f, 4.0f, 47.0f, 48.0f));
385 EXPECT_EQ(expanded.GetRadii().top_left, Size(1.0f, 2.0f));
386 EXPECT_EQ(expanded.GetRadii().top_right, Size(3.0f, 4.0f));
387 EXPECT_EQ(expanded.GetRadii().bottom_left, Size(5.0f, 6.0f));
388 EXPECT_EQ(expanded.GetRadii().bottom_right, Size(7.0f, 8.0f));
389
390 EXPECT_EQ(expanded,
391 RoundRect::MakeRectRadii(Rect::MakeXYWH(5.0f, 4.0f, 42.0f, 44.0f),
392 {
393 .top_left = Size(1.0f, 2.0f),
394 .top_right = Size(3.0f, 4.0f),
395 .bottom_left = Size(5.0f, 6.0f),
396 .bottom_right = Size(7.0f, 8.0f),
397 }));
398}

References impeller::RoundRect::Expand(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [534/689]

impeller::testing::TEST ( RoundRectTest  ,
ExpandScalar   
)

Definition at line 304 of file round_rect_unittests.cc.

304 {
305 RoundRect round_rect =
306 RoundRect::MakeRectRadii(Rect::MakeXYWH(10.0f, 10.0f, 30.0f, 30.0f),
307 {
308 .top_left = Size(1.0f, 2.0f),
309 .top_right = Size(3.0f, 4.0f),
310 .bottom_left = Size(5.0f, 6.0f),
311 .bottom_right = Size(7.0f, 8.0f),
312 });
313 RoundRect expanded = round_rect.Expand(5.0);
314
315 EXPECT_FALSE(expanded.IsEmpty());
316 EXPECT_FALSE(expanded.IsRect());
317 EXPECT_FALSE(expanded.IsOval());
318 EXPECT_TRUE(expanded.IsFinite());
319 EXPECT_FALSE(expanded.GetBounds().IsEmpty());
320 EXPECT_EQ(expanded.GetBounds(), Rect::MakeLTRB(5.0f, 5.0f, 45.0f, 45.0f));
321 EXPECT_EQ(expanded.GetRadii().top_left, Size(1.0f, 2.0f));
322 EXPECT_EQ(expanded.GetRadii().top_right, Size(3.0f, 4.0f));
323 EXPECT_EQ(expanded.GetRadii().bottom_left, Size(5.0f, 6.0f));
324 EXPECT_EQ(expanded.GetRadii().bottom_right, Size(7.0f, 8.0f));
325
326 EXPECT_EQ(expanded,
327 RoundRect::MakeRectRadii(Rect::MakeXYWH(5.0f, 5.0f, 40.0f, 40.0f),
328 {
329 .top_left = Size(1.0f, 2.0f),
330 .top_right = Size(3.0f, 4.0f),
331 .bottom_left = Size(5.0f, 6.0f),
332 .bottom_right = Size(7.0f, 8.0f),
333 }));
334}

References impeller::RoundRect::Expand(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [535/689]

impeller::testing::TEST ( RoundRectTest  ,
ExpandTwoScalars   
)

Definition at line 336 of file round_rect_unittests.cc.

336 {
337 RoundRect round_rect =
338 RoundRect::MakeRectRadii(Rect::MakeXYWH(10.0f, 10.0f, 30.0f, 30.0f),
339 {
340 .top_left = Size(1.0f, 2.0f),
341 .top_right = Size(3.0f, 4.0f),
342 .bottom_left = Size(5.0f, 6.0f),
343 .bottom_right = Size(7.0f, 8.0f),
344 });
345 RoundRect expanded = round_rect.Expand(5.0, 6.0);
346
347 EXPECT_FALSE(expanded.IsEmpty());
348 EXPECT_FALSE(expanded.IsRect());
349 EXPECT_FALSE(expanded.IsOval());
350 EXPECT_TRUE(expanded.IsFinite());
351 EXPECT_FALSE(expanded.GetBounds().IsEmpty());
352 EXPECT_EQ(expanded.GetBounds(), Rect::MakeLTRB(5.0f, 4.0f, 45.0f, 46.0f));
353 EXPECT_EQ(expanded.GetRadii().top_left, Size(1.0f, 2.0f));
354 EXPECT_EQ(expanded.GetRadii().top_right, Size(3.0f, 4.0f));
355 EXPECT_EQ(expanded.GetRadii().bottom_left, Size(5.0f, 6.0f));
356 EXPECT_EQ(expanded.GetRadii().bottom_right, Size(7.0f, 8.0f));
357
358 EXPECT_EQ(expanded,
359 RoundRect::MakeRectRadii(Rect::MakeXYWH(5.0f, 4.0f, 40.0f, 42.0f),
360 {
361 .top_left = Size(1.0f, 2.0f),
362 .top_right = Size(3.0f, 4.0f),
363 .bottom_left = Size(5.0f, 6.0f),
364 .bottom_right = Size(7.0f, 8.0f),
365 }));
366}

References impeller::RoundRect::Expand(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST() [536/689]

impeller::testing::TEST ( RoundRectTest  ,
InvertedOvalConstruction   
)

Definition at line 136 of file round_rect_unittests.cc.

136 {
137 RoundRect round_rect = RoundRect::MakeRectXY(
138 Rect::MakeLTRB(20.0f, 20.0f, 10.0f, 10.0f), 10.0f, 10.0f);
139
140 EXPECT_FALSE(round_rect.IsEmpty());
141 EXPECT_FALSE(round_rect.IsRect());
142 EXPECT_TRUE(round_rect.IsOval());
143 EXPECT_TRUE(round_rect.IsFinite());
144 EXPECT_FALSE(round_rect.GetBounds().IsEmpty());
145 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f));
146 EXPECT_EQ(round_rect.GetRadii().top_left, Size(5.0f, 5.0f));
147 EXPECT_EQ(round_rect.GetRadii().top_right, Size(5.0f, 5.0f));
148 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size(5.0f, 5.0f));
149 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size(5.0f, 5.0f));
150}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectXY(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [537/689]

impeller::testing::TEST ( RoundRectTest  ,
InvertedRectConstruction   
)

Definition at line 88 of file round_rect_unittests.cc.

88 {
89 RoundRect round_rect =
90 RoundRect::MakeRect(Rect::MakeLTRB(20.0f, 20.0f, 10.0f, 10.0f));
91
92 EXPECT_FALSE(round_rect.IsEmpty());
93 EXPECT_TRUE(round_rect.IsRect());
94 EXPECT_FALSE(round_rect.IsOval());
95 EXPECT_TRUE(round_rect.IsFinite());
96 EXPECT_FALSE(round_rect.GetBounds().IsEmpty());
97 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f));
98 EXPECT_EQ(round_rect.GetRadii().top_left, Size());
99 EXPECT_EQ(round_rect.GetRadii().top_right, Size());
100 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size());
101 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size());
102}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRect(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [538/689]

impeller::testing::TEST ( RoundRectTest  ,
NoCornerRoundRectContains   
)

Definition at line 546 of file round_rect_unittests.cc.

546 {
547 Rect bounds = Rect::MakeLTRB(-50.0f, -50.0f, 50.0f, 50.0f);
548 // RRect of bounds with no corners contains corners just barely
549 auto no_corners = RoundRect::MakeRectXY(bounds, 0.0f, 0.0f);
550
551 EXPECT_TRUE(no_corners.Contains({-50, -50}));
552 // Rectangles have half-in, half-out containment so we need
553 // to be careful about testing containment of right/bottom corners.
554 EXPECT_TRUE(no_corners.Contains({-50, 49.99}));
555 EXPECT_TRUE(no_corners.Contains({49.99, -50}));
556 EXPECT_TRUE(no_corners.Contains({49.99, 49.99}));
557 EXPECT_FALSE(no_corners.Contains({-50.01, -50}));
558 EXPECT_FALSE(no_corners.Contains({-50, -50.01}));
559 EXPECT_FALSE(no_corners.Contains({-50.01, 50}));
560 EXPECT_FALSE(no_corners.Contains({-50, 50.01}));
561 EXPECT_FALSE(no_corners.Contains({50.01, -50}));
562 EXPECT_FALSE(no_corners.Contains({50, -50.01}));
563 EXPECT_FALSE(no_corners.Contains({50.01, 50}));
564 EXPECT_FALSE(no_corners.Contains({50, 50.01}));
565}

References impeller::TRect< Scalar >::MakeLTRB(), and impeller::RoundRect::MakeRectXY().

◆ TEST() [539/689]

impeller::testing::TEST ( RoundRectTest  ,
OvalConstructor   
)

Definition at line 120 of file round_rect_unittests.cc.

120 {
121 RoundRect round_rect =
122 RoundRect::MakeOval(Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f));
123
124 EXPECT_FALSE(round_rect.IsEmpty());
125 EXPECT_FALSE(round_rect.IsRect());
126 EXPECT_TRUE(round_rect.IsOval());
127 EXPECT_TRUE(round_rect.IsFinite());
128 EXPECT_FALSE(round_rect.GetBounds().IsEmpty());
129 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f));
130 EXPECT_EQ(round_rect.GetRadii().top_left, Size(5.0f, 5.0f));
131 EXPECT_EQ(round_rect.GetRadii().top_right, Size(5.0f, 5.0f));
132 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size(5.0f, 5.0f));
133 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size(5.0f, 5.0f));
134}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeOval(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [540/689]

impeller::testing::TEST ( RoundRectTest  ,
RectConstructor   
)

Definition at line 72 of file round_rect_unittests.cc.

72 {
73 RoundRect round_rect =
74 RoundRect::MakeRect(Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f));
75
76 EXPECT_FALSE(round_rect.IsEmpty());
77 EXPECT_TRUE(round_rect.IsRect());
78 EXPECT_FALSE(round_rect.IsOval());
79 EXPECT_TRUE(round_rect.IsFinite());
80 EXPECT_FALSE(round_rect.GetBounds().IsEmpty());
81 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f));
82 EXPECT_EQ(round_rect.GetRadii().top_left, Size());
83 EXPECT_EQ(round_rect.GetRadii().top_right, Size());
84 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size());
85 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size());
86}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRect(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [541/689]

impeller::testing::TEST ( RoundRectTest  ,
RectRadiiConstructor   
)

Definition at line 200 of file round_rect_unittests.cc.

200 {
201 RoundRect round_rect =
202 RoundRect::MakeRectRadii(Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f),
203 {
204 .top_left = Size(1.0, 1.5),
205 .top_right = Size(2.0, 2.5f),
206 .bottom_left = Size(3.0, 3.5f),
207 .bottom_right = Size(4.0, 4.5f),
208 });
209
210 EXPECT_FALSE(round_rect.IsEmpty());
211 EXPECT_FALSE(round_rect.IsRect());
212 EXPECT_FALSE(round_rect.IsOval());
213 EXPECT_TRUE(round_rect.IsFinite());
214 EXPECT_FALSE(round_rect.GetBounds().IsEmpty());
215 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f));
216 EXPECT_EQ(round_rect.GetRadii().top_left, Size(1.0f, 1.5f));
217 EXPECT_EQ(round_rect.GetRadii().top_right, Size(2.0f, 2.5f));
218 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size(3.0f, 3.5f));
219 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size(4.0f, 4.5f));
220}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [542/689]

impeller::testing::TEST ( RoundRectTest  ,
RectRadiiOverflowHeightConstructor   
)

Definition at line 247 of file round_rect_unittests.cc.

247 {
248 RoundRect round_rect =
249 RoundRect::MakeRectRadii(Rect::MakeXYWH(10.0f, 10.0f, 30.0f, 6.0f),
250 {
251 .top_left = Size(1.0f, 2.0f),
252 .top_right = Size(3.0f, 4.0f),
253 .bottom_left = Size(5.0f, 6.0f),
254 .bottom_right = Size(7.0f, 8.0f),
255 });
256 // Largest sum of paired radii heights is the right edge which sums to 12
257 // Rect is only 6 tall so all radii are scaled by half
258 // Rect is 30 wide so no scaling should happen due to radii widths
259
260 EXPECT_FALSE(round_rect.IsEmpty());
261 EXPECT_FALSE(round_rect.IsRect());
262 EXPECT_FALSE(round_rect.IsOval());
263 EXPECT_TRUE(round_rect.IsFinite());
264 EXPECT_FALSE(round_rect.GetBounds().IsEmpty());
265 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(10.0f, 10.0f, 40.0f, 16.0f));
266 EXPECT_EQ(round_rect.GetRadii().top_left, Size(0.5f, 1.0f));
267 EXPECT_EQ(round_rect.GetRadii().top_right, Size(1.5f, 2.0f));
268 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size(2.5f, 3.0f));
269 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size(3.5f, 4.0f));
270}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), impeller::TRect< Scalar >::MakeXYWH(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [543/689]

impeller::testing::TEST ( RoundRectTest  ,
RectRadiiOverflowWidthConstructor   
)

Definition at line 222 of file round_rect_unittests.cc.

222 {
223 RoundRect round_rect =
224 RoundRect::MakeRectRadii(Rect::MakeXYWH(10.0f, 10.0f, 6.0f, 30.0f),
225 {
226 .top_left = Size(1.0f, 2.0f),
227 .top_right = Size(3.0f, 4.0f),
228 .bottom_left = Size(5.0f, 6.0f),
229 .bottom_right = Size(7.0f, 8.0f),
230 });
231 // Largest sum of paired radii widths is the bottom edge which sums to 12
232 // Rect is only 6 wide so all radii are scaled by half
233 // Rect is 30 tall so no scaling should happen due to radii heights
234
235 EXPECT_FALSE(round_rect.IsEmpty());
236 EXPECT_FALSE(round_rect.IsRect());
237 EXPECT_FALSE(round_rect.IsOval());
238 EXPECT_TRUE(round_rect.IsFinite());
239 EXPECT_FALSE(round_rect.GetBounds().IsEmpty());
240 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(10.0f, 10.0f, 16.0f, 40.0f));
241 EXPECT_EQ(round_rect.GetRadii().top_left, Size(0.5f, 1.0f));
242 EXPECT_EQ(round_rect.GetRadii().top_right, Size(1.5f, 2.0f));
243 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size(2.5f, 3.0f));
244 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size(3.5f, 4.0f));
245}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), impeller::TRect< Scalar >::MakeXYWH(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [544/689]

impeller::testing::TEST ( RoundRectTest  ,
RectRadiusConstructor   
)

Definition at line 152 of file round_rect_unittests.cc.

152 {
153 RoundRect round_rect = RoundRect::MakeRectRadius(
154 Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f), 2.0f);
155
156 EXPECT_FALSE(round_rect.IsEmpty());
157 EXPECT_FALSE(round_rect.IsRect());
158 EXPECT_FALSE(round_rect.IsOval());
159 EXPECT_TRUE(round_rect.IsFinite());
160 EXPECT_FALSE(round_rect.GetBounds().IsEmpty());
161 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f));
162 EXPECT_EQ(round_rect.GetRadii().top_left, Size(2.0f, 2.0f));
163 EXPECT_EQ(round_rect.GetRadii().top_right, Size(2.0f, 2.0f));
164 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size(2.0f, 2.0f));
165 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size(2.0f, 2.0f));
166}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadius(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [545/689]

impeller::testing::TEST ( RoundRectTest  ,
RectSizeConstructor   
)

Definition at line 184 of file round_rect_unittests.cc.

184 {
185 RoundRect round_rect = RoundRect::MakeRectXY(
186 Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f), Size(2.0f, 3.0f));
187
188 EXPECT_FALSE(round_rect.IsEmpty());
189 EXPECT_FALSE(round_rect.IsRect());
190 EXPECT_FALSE(round_rect.IsOval());
191 EXPECT_TRUE(round_rect.IsFinite());
192 EXPECT_FALSE(round_rect.GetBounds().IsEmpty());
193 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f));
194 EXPECT_EQ(round_rect.GetRadii().top_left, Size(2.0f, 3.0f));
195 EXPECT_EQ(round_rect.GetRadii().top_right, Size(2.0f, 3.0f));
196 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size(2.0f, 3.0f));
197 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size(2.0f, 3.0f));
198}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectXY(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [546/689]

impeller::testing::TEST ( RoundRectTest  ,
RectXYConstructor   
)

Definition at line 168 of file round_rect_unittests.cc.

168 {
169 RoundRect round_rect = RoundRect::MakeRectXY(
170 Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f), 2.0f, 3.0f);
171
172 EXPECT_FALSE(round_rect.IsEmpty());
173 EXPECT_FALSE(round_rect.IsRect());
174 EXPECT_FALSE(round_rect.IsOval());
175 EXPECT_TRUE(round_rect.IsFinite());
176 EXPECT_FALSE(round_rect.GetBounds().IsEmpty());
177 EXPECT_EQ(round_rect.GetBounds(), Rect::MakeLTRB(10.0f, 10.0f, 20.0f, 20.0f));
178 EXPECT_EQ(round_rect.GetRadii().top_left, Size(2.0f, 3.0f));
179 EXPECT_EQ(round_rect.GetRadii().top_right, Size(2.0f, 3.0f));
180 EXPECT_EQ(round_rect.GetRadii().bottom_left, Size(2.0f, 3.0f));
181 EXPECT_EQ(round_rect.GetRadii().bottom_right, Size(2.0f, 3.0f));
182}

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), impeller::RoundRect::IsEmpty(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), impeller::RoundRect::IsRect(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectXY(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ TEST() [547/689]

impeller::testing::TEST ( RoundRectTest  ,
Shift   
)

Definition at line 272 of file round_rect_unittests.cc.

272 {
273 RoundRect round_rect =
274 RoundRect::MakeRectRadii(Rect::MakeXYWH(10.0f, 10.0f, 30.0f, 30.0f),
275 {
276 .top_left = Size(1.0f, 2.0f),
277 .top_right = Size(3.0f, 4.0f),
278 .bottom_left = Size(5.0f, 6.0f),
279 .bottom_right = Size(7.0f, 8.0f),
280 });
281 RoundRect shifted = round_rect.Shift(5.0, 6.0);
282
283 EXPECT_FALSE(shifted.IsEmpty());
284 EXPECT_FALSE(shifted.IsRect());
285 EXPECT_FALSE(shifted.IsOval());
286 EXPECT_TRUE(shifted.IsFinite());
287 EXPECT_FALSE(shifted.GetBounds().IsEmpty());
288 EXPECT_EQ(shifted.GetBounds(), Rect::MakeLTRB(15.0f, 16.0f, 45.0f, 46.0f));
289 EXPECT_EQ(shifted.GetRadii().top_left, Size(1.0f, 2.0f));
290 EXPECT_EQ(shifted.GetRadii().top_right, Size(3.0f, 4.0f));
291 EXPECT_EQ(shifted.GetRadii().bottom_left, Size(5.0f, 6.0f));
292 EXPECT_EQ(shifted.GetRadii().bottom_right, Size(7.0f, 8.0f));
293
294 EXPECT_EQ(shifted,
295 RoundRect::MakeRectRadii(Rect::MakeXYWH(15.0f, 16.0f, 30.0f, 30.0f),
296 {
297 .top_left = Size(1.0f, 2.0f),
298 .top_right = Size(3.0f, 4.0f),
299 .bottom_left = Size(5.0f, 6.0f),
300 .bottom_right = Size(7.0f, 8.0f),
301 }));
302}
RoundRect Shift(Scalar dx, Scalar dy) const
Returns a new round rectangle translated by the given offset.
Definition round_rect.h:89

References impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadii(), impeller::TRect< Scalar >::MakeXYWH(), and impeller::RoundRect::Shift().

◆ TEST() [548/689]

impeller::testing::TEST ( RoundRectTest  ,
TinyCornerRoundRectContains   
)

Definition at line 567 of file round_rect_unittests.cc.

567 {
568 Rect bounds = Rect::MakeLTRB(-50.0f, -50.0f, 50.0f, 50.0f);
569 // RRect of bounds with even the tiniest corners does not contain corners
570 auto tiny_corners = RoundRect::MakeRectXY(bounds, 0.01f, 0.01f);
571
572 EXPECT_FALSE(tiny_corners.Contains({-50, -50}));
573 EXPECT_FALSE(tiny_corners.Contains({-50, 50}));
574 EXPECT_FALSE(tiny_corners.Contains({50, -50}));
575 EXPECT_FALSE(tiny_corners.Contains({50, 50}));
576}

References impeller::TRect< Scalar >::MakeLTRB(), and impeller::RoundRect::MakeRectXY().

◆ TEST() [549/689]

impeller::testing::TEST ( RoundRectTest  ,
UniformCircularRoundRectContains   
)

Definition at line 578 of file round_rect_unittests.cc.

578 {
579 Rect bounds = Rect::MakeLTRB(-50.0f, -50.0f, 50.0f, 50.0f);
580 auto expanded_2_r_2 = RoundRect::MakeRectXY(bounds.Expand(2.0), 2.0f, 2.0f);
581
582 // Expanded by 2.0 and then with a corner of 2.0 obviously still
583 // contains the corners
584 EXPECT_TRUE(expanded_2_r_2.Contains({-50, -50}));
585 EXPECT_TRUE(expanded_2_r_2.Contains({-50, 50}));
586 EXPECT_TRUE(expanded_2_r_2.Contains({50, -50}));
587 EXPECT_TRUE(expanded_2_r_2.Contains({50, 50}));
588
589 // Now we try to box in the corner containment to exactly where the
590 // rounded corner of the expanded round rect with radii of 2.0 lies.
591 // The 45-degree diagonal point of a circle of radius 2.0 lies at:
592 //
593 // (2 * sqrt(2) / 2, 2 * sqrt(2) / 2)
594 // (sqrt(2), sqrt(2))
595 //
596 // So we test +/- (50 + sqrt(2) +/- epsilon)
597 const auto coord_out = 50 + kSqrt2 + kEhCloseEnough;
598 const auto coord_in = 50 + kSqrt2 - kEhCloseEnough;
599 // Upper left corner
600 EXPECT_TRUE(expanded_2_r_2.Contains({-coord_in, -coord_in}));
601 EXPECT_FALSE(expanded_2_r_2.Contains({-coord_out, -coord_out}));
602 // Upper right corner
603 EXPECT_TRUE(expanded_2_r_2.Contains({coord_in, -coord_in}));
604 EXPECT_FALSE(expanded_2_r_2.Contains({coord_out, -coord_out}));
605 // Lower left corner
606 EXPECT_TRUE(expanded_2_r_2.Contains({-coord_in, coord_in}));
607 EXPECT_FALSE(expanded_2_r_2.Contains({-coord_out, coord_out}));
608 // Lower right corner
609 EXPECT_TRUE(expanded_2_r_2.Contains({coord_in, coord_in}));
610 EXPECT_FALSE(expanded_2_r_2.Contains({coord_out, coord_out}));
611}

References flutter::kEhCloseEnough, impeller::kSqrt2, impeller::TRect< Scalar >::MakeLTRB(), and impeller::RoundRect::MakeRectXY().

◆ TEST() [550/689]

impeller::testing::TEST ( RoundRectTest  ,
UniformEllipticalRoundRectContains   
)

Definition at line 613 of file round_rect_unittests.cc.

613 {
614 Rect bounds = Rect::MakeLTRB(-50.0f, -50.0f, 50.0f, 50.0f);
615 auto expanded_2_r_2 = RoundRect::MakeRectXY(bounds.Expand(2.0), 2.0f, 3.0f);
616
617 // Expanded by 2.0 and then with a corner of 2x3 should still
618 // contain the corners
619 EXPECT_TRUE(expanded_2_r_2.Contains({-50, -50}));
620 EXPECT_TRUE(expanded_2_r_2.Contains({-50, 50}));
621 EXPECT_TRUE(expanded_2_r_2.Contains({50, -50}));
622 EXPECT_TRUE(expanded_2_r_2.Contains({50, 50}));
623
624 // Now we try to box in the corner containment to exactly where the
625 // rounded corner of the expanded round rect with radii of 2x3 lies.
626 // The "45-degree diagonal point" of an ellipse of radii 2x3 lies at:
627 //
628 // (2 * sqrt(2) / 2, 3 * sqrt(2) / 2)
629 // (sqrt(2), 3 * sqrt(2) / 2)
630 //
631 // And the center(s) of these corners are at:
632 // (+/-(50 + 2 - 2), +/-(50 + 2 - 3))
633 // = (+/-50, +/-49)
634 const auto x_coord_out = 50 + kSqrt2 + kEhCloseEnough;
635 const auto x_coord_in = 50 + kSqrt2 - kEhCloseEnough;
636 const auto y_coord_out = 49 + 3 * kSqrt2 / 2 + kEhCloseEnough;
637 const auto y_coord_in = 49 + 3 * kSqrt2 / 2 - kEhCloseEnough;
638 // Upper left corner
639 EXPECT_TRUE(expanded_2_r_2.Contains({-x_coord_in, -y_coord_in}));
640 EXPECT_FALSE(expanded_2_r_2.Contains({-x_coord_out, -y_coord_out}));
641 // Upper right corner
642 EXPECT_TRUE(expanded_2_r_2.Contains({x_coord_in, -y_coord_in}));
643 EXPECT_FALSE(expanded_2_r_2.Contains({x_coord_out, -y_coord_out}));
644 // Lower left corner
645 EXPECT_TRUE(expanded_2_r_2.Contains({-x_coord_in, y_coord_in}));
646 EXPECT_FALSE(expanded_2_r_2.Contains({-x_coord_out, y_coord_out}));
647 // Lower right corner
648 EXPECT_TRUE(expanded_2_r_2.Contains({x_coord_in, y_coord_in}));
649 EXPECT_FALSE(expanded_2_r_2.Contains({x_coord_out, y_coord_out}));
650}

References flutter::kEhCloseEnough, impeller::kSqrt2, impeller::TRect< Scalar >::MakeLTRB(), and impeller::RoundRect::MakeRectXY().

◆ TEST() [551/689]

impeller::testing::TEST ( RSTransformTest  ,
CompareToMatrix   
)

Definition at line 32 of file rstransform_unittests.cc.

32 {
33 for (int tx = 0; tx <= 100; tx += 10) {
34 for (int ty = 0; ty <= 100; ty += 10) {
35 Point origin(tx, ty);
36 for (int scale = 1; scale <= 20; scale += 5) {
37 // Overshoot a full circle by 30 degrees
38 for (int degrees = 0; degrees <= 390; degrees += 45) {
39 auto matrix = Matrix::MakeTranslation(origin) *
40 Matrix::MakeRotationZ(Degrees(degrees)) *
41 Matrix::MakeScale(Vector2(scale, scale));
42 auto rst = RSTransform::Make(origin, scale, Degrees(degrees));
43 EXPECT_MATRIX_NEAR(rst.GetMatrix(), matrix);
44 for (int w = 10; w <= 100; w += 10) {
45 for (int h = 10; h <= 100; h += 10) {
46 Quad q = rst.GetQuad(w, h);
47 auto points = Rect::MakeWH(w, h).GetTransformedPoints(matrix);
48 for (int i = 0; i < 4; i++) {
49 EXPECT_NEAR(q[i].x, points[i].x, kEhCloseEnough);
50 EXPECT_NEAR(q[i].y, points[i].y, kEhCloseEnough);
51 }
52 }
53 }
54 }
55 }
56 }
57 }
58}
#define EXPECT_MATRIX_NEAR(a, b)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder h
Definition switch_defs.h:54

References EXPECT_MATRIX_NEAR, impeller::TRect< T >::GetTransformedPoints(), flutter::h, i, flutter::kEhCloseEnough, impeller::RSTransform::Make(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeWH(), points, x, and y.

◆ TEST() [552/689]

impeller::testing::TEST ( RSTransformTest  ,
Construction   
)

Definition at line 14 of file rstransform_unittests.cc.

14 {
15 RSTransform transform = RSTransform::Make({10.0f, 12.0f}, 2.0f, Degrees(90));
16
17 EXPECT_EQ(transform.scaled_cos, 0.0f);
18 EXPECT_EQ(transform.scaled_sin, 2.0f);
19 EXPECT_EQ(transform.translate_x, 10.0f);
20 EXPECT_EQ(transform.translate_y, 12.0f);
21
22 EXPECT_EQ(transform.GetBounds(20.0f, 30.0f),
23 // relative corners are at
24 // 0, 0
25 // 0, 40
26 // -60, 0
27 // -60, 40
28 // then add 10, 12 to all values
29 Rect::MakeLTRB(10 + -2 * 30, 12 + 0, 10 + 0, 12 + 40));
30}

References impeller::RSTransform::Make(), impeller::TRect< Scalar >::MakeLTRB(), and transform.

◆ TEST() [553/689]

impeller::testing::TEST ( SamplerDescriptorTest  ,
ToKeyIncludesAllFields   
)

Definition at line 11 of file sampler_descriptor_unittests.cc.

11 {
14 EXPECT_EQ(SamplerDescriptor::ToKey(a), SamplerDescriptor::ToKey(b));
15
16 b.min_filter = MinMagFilter::kLinear;
17 EXPECT_NE(SamplerDescriptor::ToKey(a), SamplerDescriptor::ToKey(b));
19
20 b.mag_filter = MinMagFilter::kLinear;
21 EXPECT_NE(SamplerDescriptor::ToKey(a), SamplerDescriptor::ToKey(b));
23
24 b.mip_filter = MipFilter::kLinear;
25 EXPECT_NE(SamplerDescriptor::ToKey(a), SamplerDescriptor::ToKey(b));
26 b = SamplerDescriptor{};
27
28 b.width_address_mode = SamplerAddressMode::kRepeat;
29 EXPECT_NE(SamplerDescriptor::ToKey(a), SamplerDescriptor::ToKey(b));
30 b = SamplerDescriptor{};
31
32 b.height_address_mode = SamplerAddressMode::kRepeat;
33 EXPECT_NE(SamplerDescriptor::ToKey(a), SamplerDescriptor::ToKey(b));
34 b = SamplerDescriptor{};
35
36 b.depth_address_mode = SamplerAddressMode::kRepeat;
37 EXPECT_NE(SamplerDescriptor::ToKey(a), SamplerDescriptor::ToKey(b));
38 b = SamplerDescriptor{};
39
40 b.max_anisotropy = 16;
41 EXPECT_NE(SamplerDescriptor::ToKey(a), SamplerDescriptor::ToKey(b));
42 b.max_anisotropy = 1;
43 EXPECT_EQ(SamplerDescriptor::ToKey(a), SamplerDescriptor::ToKey(b));
44}

References impeller::kLinear, impeller::kRepeat, and impeller::SamplerDescriptor::ToKey().

◆ TEST() [554/689]

impeller::testing::TEST ( SamplerLibraryVK  ,
MaxAnisotropyIsClampedToTheDeviceLimit   
)

Definition at line 38 of file sampler_library_vk_unittests.cc.

38 {
39 auto const context = MockVulkanContextBuilder().Build();
40
41 std::shared_ptr<SamplerLibrary> library = std::make_shared<SamplerLibraryVK>(
42 context->GetDeviceHolder(), /*max_sampler_anisotropy=*/4u);
43
45 desc.min_filter = MinMagFilter::kLinear;
46 desc.mag_filter = MinMagFilter::kLinear;
47 desc.mip_filter = MipFilter::kLinear;
48 desc.max_anisotropy = 16;
49
50 auto sampler = library->GetSampler(desc);
51 EXPECT_EQ(sampler->GetDescriptor().max_anisotropy, 4u);
52
53 // Clamped values share a cache entry.
54 desc.max_anisotropy = 8;
55 EXPECT_EQ(library->GetSampler(desc), sampler);
56}

References impeller::testing::MockVulkanContextBuilder::Build(), context, impeller::kLinear, impeller::SamplerDescriptor::mag_filter, impeller::SamplerDescriptor::max_anisotropy, impeller::SamplerDescriptor::min_filter, and impeller::SamplerDescriptor::mip_filter.

◆ TEST() [555/689]

impeller::testing::TEST ( SamplerLibraryVK  ,
MaxAnisotropyIsDisabledWhenUnsupported   
)

Definition at line 58 of file sampler_library_vk_unittests.cc.

58 {
59 auto const context = MockVulkanContextBuilder().Build();
60
61 std::shared_ptr<SamplerLibrary> library = std::make_shared<SamplerLibraryVK>(
62 context->GetDeviceHolder(), /*max_sampler_anisotropy=*/1u);
63
65 desc.min_filter = MinMagFilter::kLinear;
66 desc.mag_filter = MinMagFilter::kLinear;
67 desc.mip_filter = MipFilter::kLinear;
68 desc.max_anisotropy = 16;
69
70 auto sampler = library->GetSampler(desc);
71 EXPECT_EQ(sampler->GetDescriptor().max_anisotropy, 1u);
72}

References impeller::testing::MockVulkanContextBuilder::Build(), context, impeller::kLinear, impeller::SamplerDescriptor::mag_filter, impeller::SamplerDescriptor::max_anisotropy, impeller::SamplerDescriptor::min_filter, and impeller::SamplerDescriptor::mip_filter.

◆ TEST() [556/689]

impeller::testing::TEST ( SamplerLibraryVK  ,
WorkaroundsCanDisableReadingFromMipLevels   
)

Definition at line 18 of file sampler_library_vk_unittests.cc.

18 {
19 auto const context = MockVulkanContextBuilder().Build();
20
21 auto library_vk = std::make_shared<SamplerLibraryVK>(
22 context->GetDeviceHolder(), /*max_sampler_anisotropy=*/1u);
23 std::shared_ptr<SamplerLibrary> library = library_vk;
24
26 desc.mip_filter = MipFilter::kLinear;
27
28 auto sampler = library->GetSampler(desc);
29 EXPECT_EQ(sampler->GetDescriptor().mip_filter, MipFilter::kLinear);
30
31 // Apply mips disabled workaround.
32 library_vk->ApplyWorkarounds(WorkaroundsVK{.broken_mipmap_generation = true});
33
34 sampler = library->GetSampler(desc);
35 EXPECT_EQ(sampler->GetDescriptor().mip_filter, MipFilter::kBase);
36}
A non-exhaustive set of driver specific workarounds.

References impeller::WorkaroundsVK::broken_mipmap_generation, impeller::testing::MockVulkanContextBuilder::Build(), context, impeller::kBase, impeller::kLinear, and impeller::SamplerDescriptor::mip_filter.

◆ TEST() [557/689]

impeller::testing::TEST ( SaturatedMath  ,
CastingFiniteDoubleToFloatStaysFinite   
)

Definition at line 981 of file saturated_math_unittests.cc.

981 {
982 const double d_max = std::numeric_limits<double>::max();
983 const float f_max = std::numeric_limits<float>::max();
984
985 {
986 const float result = saturated::Cast<double, float>(d_max);
987 EXPECT_EQ(result, f_max);
988 }
989
990 {
991 const float result = saturated::Cast<double, float>(-d_max);
992 EXPECT_EQ(result, -f_max);
993 }
994}

◆ TEST() [558/689]

impeller::testing::TEST ( SaturatedMath  ,
CastingInfiniteDoubleToFloatStaysInfinite   
)

Definition at line 996 of file saturated_math_unittests.cc.

996 {
997 const double d_inf = std::numeric_limits<double>::infinity();
998 const float f_max = std::numeric_limits<float>::infinity();
999
1000 {
1001 const float result = saturated::Cast<double, float>(d_inf);
1002 EXPECT_EQ(result, f_max);
1003 }
1004
1005 {
1006 const float result = saturated::Cast<double, float>(-d_inf);
1007 EXPECT_EQ(result, -f_max);
1008 }
1009}

◆ TEST() [559/689]

impeller::testing::TEST ( SaturatedMath  ,
CastingInfiniteScalarToSignedIntProducesLimit   
)

Definition at line 1066 of file saturated_math_unittests.cc.

1066 {
1067 // larger than even any [u]int64_t;
1068 const Scalar inf = std::numeric_limits<Scalar>::infinity();
1069
1070 {
1071 const auto result = saturated::Cast<Scalar, int8_t>(inf);
1072 EXPECT_EQ(result, int8_t(0x7F));
1073 }
1074 {
1075 const auto result = saturated::Cast<Scalar, int8_t>(-inf);
1076 EXPECT_EQ(result, int8_t(0x80));
1077 }
1078
1079 {
1080 const auto result = saturated::Cast<Scalar, int16_t>(inf);
1081 EXPECT_EQ(result, int16_t(0x7FFF));
1082 }
1083 {
1084 const auto result = saturated::Cast<Scalar, int16_t>(-inf);
1085 EXPECT_EQ(result, int16_t(0x8000));
1086 }
1087
1088 {
1089 const auto result = saturated::Cast<Scalar, int32_t>(inf);
1090 EXPECT_EQ(result, int32_t(0x7FFFFFFF));
1091 }
1092 {
1093 const auto result = saturated::Cast<Scalar, int32_t>(-inf);
1094 EXPECT_EQ(result, int32_t(0x80000000));
1095 }
1096
1097 {
1098 const auto result = saturated::Cast<Scalar, int64_t>(inf);
1099 EXPECT_EQ(result, int64_t(0x7FFFFFFFFFFFFFFF));
1100 }
1101 {
1102 const auto result = saturated::Cast<Scalar, int64_t>(-inf);
1103 EXPECT_EQ(result, int64_t(0x8000000000000000));
1104 }
1105}

◆ TEST() [560/689]

impeller::testing::TEST ( SaturatedMath  ,
CastingLargeScalarToSignedIntProducesLimit   
)

Definition at line 1025 of file saturated_math_unittests.cc.

1025 {
1026 // larger than even any [u]int64_t;
1027 const Scalar large = 1e20f;
1028
1029 {
1030 const auto result = saturated::Cast<Scalar, int8_t>(large);
1031 EXPECT_EQ(result, int8_t(0x7F));
1032 }
1033 {
1034 const auto result = saturated::Cast<Scalar, int8_t>(-large);
1035 EXPECT_EQ(result, int8_t(0x80));
1036 }
1037
1038 {
1039 const auto result = saturated::Cast<Scalar, int16_t>(large);
1040 EXPECT_EQ(result, int16_t(0x7FFF));
1041 }
1042 {
1043 const auto result = saturated::Cast<Scalar, int16_t>(-large);
1044 EXPECT_EQ(result, int16_t(0x8000));
1045 }
1046
1047 {
1048 const auto result = saturated::Cast<Scalar, int32_t>(large);
1049 EXPECT_EQ(result, int32_t(0x7FFFFFFF));
1050 }
1051 {
1052 const auto result = saturated::Cast<Scalar, int32_t>(-large);
1053 EXPECT_EQ(result, int32_t(0x80000000));
1054 }
1055
1056 {
1057 const auto result = saturated::Cast<Scalar, int64_t>(large);
1058 EXPECT_EQ(result, int64_t(0x7FFFFFFFFFFFFFFF));
1059 }
1060 {
1061 const auto result = saturated::Cast<Scalar, int64_t>(-large);
1062 EXPECT_EQ(result, int64_t(0x8000000000000000));
1063 }
1064}

◆ TEST() [561/689]

impeller::testing::TEST ( SaturatedMath  ,
CastingNaNDoubleToFloatStaysNaN   
)

Definition at line 1011 of file saturated_math_unittests.cc.

1011 {
1012 const double d_nan = std::numeric_limits<double>::quiet_NaN();
1013
1014 {
1015 const float result = saturated::Cast<double, float>(d_nan);
1016 EXPECT_TRUE(std::isnan(result));
1017 }
1018
1019 {
1020 const float result = saturated::Cast<double, float>(-d_nan);
1021 EXPECT_TRUE(std::isnan(result));
1022 }
1023}

◆ TEST() [562/689]

impeller::testing::TEST ( SaturatedMath  ,
CastingNaNScalarToSignedIntProducesZero   
)

Definition at line 1107 of file saturated_math_unittests.cc.

1107 {
1108 // larger than even any [u]int64_t;
1109 const Scalar nan = std::numeric_limits<Scalar>::quiet_NaN();
1110
1111 {
1112 const auto result = saturated::Cast<Scalar, int8_t>(nan);
1113 EXPECT_EQ(result, int8_t(0));
1114 }
1115
1116 {
1117 const auto result = saturated::Cast<Scalar, int16_t>(nan);
1118 EXPECT_EQ(result, int16_t(0));
1119 }
1120
1121 {
1122 const auto result = saturated::Cast<Scalar, int32_t>(nan);
1123 EXPECT_EQ(result, int32_t(0));
1124 }
1125
1126 {
1127 const auto result = saturated::Cast<Scalar, int64_t>(nan);
1128 EXPECT_EQ(result, int64_t(0));
1129 }
1130}

◆ TEST() [563/689]

impeller::testing::TEST ( SaturatedMath  ,
ExplicitAddOfFloatingPoint   
)

Definition at line 136 of file saturated_math_unittests.cc.

136 {
137 {
138 const float inf = std::numeric_limits<float>::infinity();
139 const float max = std::numeric_limits<float>::max();
140 const float big = max * 0.5f;
141
142 EXPECT_EQ(saturated::Add<float>(big, big), max);
143 EXPECT_EQ(saturated::Add<float>(max, big), inf);
144 EXPECT_EQ(saturated::Add<float>(big, max), inf);
145 EXPECT_EQ(saturated::Add<float>(max, max), inf);
146 EXPECT_EQ(saturated::Add<float>(max, inf), inf);
147 EXPECT_EQ(saturated::Add<float>(inf, max), inf);
148 EXPECT_EQ(saturated::Add<float>(inf, inf), inf);
149
150 EXPECT_EQ(saturated::Add<float>(-big, -big), -max);
151 EXPECT_EQ(saturated::Add<float>(-max, -big), -inf);
152 EXPECT_EQ(saturated::Add<float>(-big, -max), -inf);
153 EXPECT_EQ(saturated::Add<float>(-max, -max), -inf);
154 EXPECT_EQ(saturated::Add<float>(-max, -inf), -inf);
155 EXPECT_EQ(saturated::Add<float>(-inf, -max), -inf);
156 EXPECT_EQ(saturated::Add<float>(-inf, -inf), -inf);
157
158 EXPECT_EQ(saturated::Add<float>(big, -big), 0.0f);
159 EXPECT_EQ(saturated::Add<float>(max, -big), big);
160 EXPECT_EQ(saturated::Add<float>(big, -max), -big);
161 EXPECT_EQ(saturated::Add<float>(max, -max), 0.0f);
162 EXPECT_EQ(saturated::Add<float>(max, -inf), -inf);
163 EXPECT_EQ(saturated::Add<float>(inf, -max), inf);
164 EXPECT_TRUE(std::isnan(saturated::Add<float>(inf, -inf)));
165
166 EXPECT_EQ(saturated::Add<float>(-big, big), 0.0f);
167 EXPECT_EQ(saturated::Add<float>(-max, big), -big);
168 EXPECT_EQ(saturated::Add<float>(-big, max), big);
169 EXPECT_EQ(saturated::Add<float>(-max, max), 0.0f);
170 EXPECT_EQ(saturated::Add<float>(-max, inf), inf);
171 EXPECT_EQ(saturated::Add<float>(-inf, max), -inf);
172 EXPECT_TRUE(std::isnan(saturated::Add<float>(-inf, inf)));
173 }
174 {
175 const double inf = std::numeric_limits<double>::infinity();
176 const double max = std::numeric_limits<double>::max();
177 const double big = max * 0.5f;
178
179 EXPECT_EQ(saturated::Add<double>(big, big), max);
180 EXPECT_EQ(saturated::Add<double>(max, big), inf);
181 EXPECT_EQ(saturated::Add<double>(big, max), inf);
182 EXPECT_EQ(saturated::Add<double>(max, max), inf);
183 EXPECT_EQ(saturated::Add<double>(max, inf), inf);
184 EXPECT_EQ(saturated::Add<double>(inf, max), inf);
185 EXPECT_EQ(saturated::Add<double>(inf, inf), inf);
186
187 EXPECT_EQ(saturated::Add<double>(-big, -big), -max);
188 EXPECT_EQ(saturated::Add<double>(-max, -big), -inf);
189 EXPECT_EQ(saturated::Add<double>(-big, -max), -inf);
190 EXPECT_EQ(saturated::Add<double>(-max, -max), -inf);
191 EXPECT_EQ(saturated::Add<double>(-max, -inf), -inf);
192 EXPECT_EQ(saturated::Add<double>(-inf, -max), -inf);
193 EXPECT_EQ(saturated::Add<double>(-inf, -inf), -inf);
194
195 EXPECT_EQ(saturated::Add<double>(big, -big), 0.0f);
196 EXPECT_EQ(saturated::Add<double>(max, -big), big);
197 EXPECT_EQ(saturated::Add<double>(big, -max), -big);
198 EXPECT_EQ(saturated::Add<double>(max, -max), 0.0f);
199 EXPECT_EQ(saturated::Add<double>(max, -inf), -inf);
200 EXPECT_EQ(saturated::Add<double>(inf, -max), inf);
201 EXPECT_TRUE(std::isnan(saturated::Add<double>(inf, -inf)));
202
203 EXPECT_EQ(saturated::Add<double>(-big, big), 0.0f);
204 EXPECT_EQ(saturated::Add<double>(-max, big), -big);
205 EXPECT_EQ(saturated::Add<double>(-big, max), big);
206 EXPECT_EQ(saturated::Add<double>(-max, max), 0.0f);
207 EXPECT_EQ(saturated::Add<double>(-max, inf), inf);
208 EXPECT_EQ(saturated::Add<double>(-inf, max), -inf);
209 EXPECT_TRUE(std::isnan(saturated::Add<double>(-inf, inf)));
210 }
211 {
212 const Scalar inf = std::numeric_limits<Scalar>::infinity();
213 const Scalar max = std::numeric_limits<Scalar>::max();
214 const Scalar big = max * 0.5f;
215
216 EXPECT_EQ(saturated::Add<Scalar>(big, big), max);
217 EXPECT_EQ(saturated::Add<Scalar>(max, big), inf);
218 EXPECT_EQ(saturated::Add<Scalar>(big, max), inf);
219 EXPECT_EQ(saturated::Add<Scalar>(max, max), inf);
220 EXPECT_EQ(saturated::Add<Scalar>(max, inf), inf);
221 EXPECT_EQ(saturated::Add<Scalar>(inf, max), inf);
222 EXPECT_EQ(saturated::Add<Scalar>(inf, inf), inf);
223
224 EXPECT_EQ(saturated::Add<Scalar>(-big, -big), -max);
225 EXPECT_EQ(saturated::Add<Scalar>(-max, -big), -inf);
226 EXPECT_EQ(saturated::Add<Scalar>(-big, -max), -inf);
227 EXPECT_EQ(saturated::Add<Scalar>(-max, -max), -inf);
228 EXPECT_EQ(saturated::Add<Scalar>(-max, -inf), -inf);
229 EXPECT_EQ(saturated::Add<Scalar>(-inf, -max), -inf);
230 EXPECT_EQ(saturated::Add<Scalar>(-inf, -inf), -inf);
231
232 EXPECT_EQ(saturated::Add<Scalar>(big, -big), 0.0f);
233 EXPECT_EQ(saturated::Add<Scalar>(max, -big), big);
234 EXPECT_EQ(saturated::Add<Scalar>(big, -max), -big);
235 EXPECT_EQ(saturated::Add<Scalar>(max, -max), 0.0f);
236 EXPECT_EQ(saturated::Add<Scalar>(max, -inf), -inf);
237 EXPECT_EQ(saturated::Add<Scalar>(inf, -max), inf);
238 EXPECT_TRUE(std::isnan(saturated::Add<Scalar>(inf, -inf)));
239
240 EXPECT_EQ(saturated::Add<Scalar>(-big, big), 0.0f);
241 EXPECT_EQ(saturated::Add<Scalar>(-max, big), -big);
242 EXPECT_EQ(saturated::Add<Scalar>(-big, max), big);
243 EXPECT_EQ(saturated::Add<Scalar>(-max, max), 0.0f);
244 EXPECT_EQ(saturated::Add<Scalar>(-max, inf), inf);
245 EXPECT_EQ(saturated::Add<Scalar>(-inf, max), -inf);
246 EXPECT_TRUE(std::isnan(saturated::Add<Scalar>(-inf, inf)));
247 }
248}

◆ TEST() [564/689]

impeller::testing::TEST ( SaturatedMath  ,
ExplicitAddOfSignedInts   
)

Definition at line 12 of file saturated_math_unittests.cc.

12 {
13 {
14 EXPECT_EQ(saturated::Add<int8_t>(0x79, 5), int8_t(0x7E));
15 EXPECT_EQ(saturated::Add<int8_t>(0x7A, 5), int8_t(0x7F));
16 EXPECT_EQ(saturated::Add<int8_t>(0x7B, 5), int8_t(0x7F));
17 }
18 {
19 EXPECT_EQ(saturated::Add<int8_t>(0x86, -5), int8_t(0x81));
20 EXPECT_EQ(saturated::Add<int8_t>(0x85, -5), int8_t(0x80));
21 EXPECT_EQ(saturated::Add<int8_t>(0x84, -5), int8_t(0x80));
22 }
23 {
24 EXPECT_EQ(saturated::Add<int16_t>(0x7FF9, 5), int16_t(0x7FFE));
25 EXPECT_EQ(saturated::Add<int16_t>(0x7FFA, 5), int16_t(0x7FFF));
26 EXPECT_EQ(saturated::Add<int16_t>(0x7FFB, 5), int16_t(0x7FFF));
27 }
28 {
29 EXPECT_EQ(saturated::Add<int16_t>(0x8006, -5), int16_t(0x8001));
30 EXPECT_EQ(saturated::Add<int16_t>(0x8005, -5), int16_t(0x8000));
31 EXPECT_EQ(saturated::Add<int16_t>(0x8004, -5), int16_t(0x8000));
32 }
33 {
34 EXPECT_EQ(saturated::Add<int32_t>(0x7FFFFFF9, 5), int32_t(0x7FFFFFFE));
35 EXPECT_EQ(saturated::Add<int32_t>(0x7FFFFFFA, 5), int32_t(0x7FFFFFFF));
36 EXPECT_EQ(saturated::Add<int32_t>(0x7FFFFFFB, 5), int32_t(0x7FFFFFFF));
37 }
38 {
39 EXPECT_EQ(saturated::Add<int32_t>(0x80000006, -5), int32_t(0x80000001));
40 EXPECT_EQ(saturated::Add<int32_t>(0x80000005, -5), int32_t(0x80000000));
41 EXPECT_EQ(saturated::Add<int32_t>(0x80000004, -5), int32_t(0x80000000));
42 }
43 {
44 EXPECT_EQ(saturated::Add<int64_t>(0x7FFFFFFFFFFFFFF9, 5),
45 int64_t(0x7FFFFFFFFFFFFFFE));
46 EXPECT_EQ(saturated::Add<int64_t>(0x7FFFFFFFFFFFFFFA, 5),
47 int64_t(0x7FFFFFFFFFFFFFFF));
48 EXPECT_EQ(saturated::Add<int64_t>(0x7FFFFFFFFFFFFFFB, 5),
49 int64_t(0x7FFFFFFFFFFFFFFF));
50 }
51 {
52 EXPECT_EQ(saturated::Add<int64_t>(0x8000000000000006, -5),
53 int64_t(0x8000000000000001));
54 EXPECT_EQ(saturated::Add<int64_t>(0x8000000000000005, -5),
55 int64_t(0x8000000000000000));
56 EXPECT_EQ(saturated::Add<int64_t>(0x8000000000000004, -5),
57 int64_t(0x8000000000000000));
58 }
59}

◆ TEST() [565/689]

impeller::testing::TEST ( SaturatedMath  ,
ExplicitAverageScalarOfFloatingPoint   
)

Definition at line 828 of file saturated_math_unittests.cc.

828 {
829 const Scalar s_inf = std::numeric_limits<Scalar>::infinity();
830 const Scalar s_max = std::numeric_limits<Scalar>::max();
831 const Scalar s_big = s_max * 0.5f;
832
833 {
834 const float inf = std::numeric_limits<Scalar>::infinity();
835 const float max = std::numeric_limits<float>::max();
836 const float big = max * 0.5f;
837
838 EXPECT_EQ(saturated::AverageScalar<float>(big, big), s_big);
839 EXPECT_EQ(saturated::AverageScalar<float>(max, max), s_max);
840 EXPECT_EQ(saturated::AverageScalar<float>(big, -big), 0.0f);
841 EXPECT_EQ(saturated::AverageScalar<float>(max, -max), 0.0f);
842 EXPECT_EQ(saturated::AverageScalar<float>(-big, big), 0.0f);
843 EXPECT_EQ(saturated::AverageScalar<float>(-max, max), 0.0f);
844 EXPECT_EQ(saturated::AverageScalar<float>(-big, -big), -s_big);
845 EXPECT_EQ(saturated::AverageScalar<float>(-max, -max), -s_max);
846
847 EXPECT_EQ(saturated::AverageScalar<float>(inf, inf), s_inf);
848 EXPECT_EQ(saturated::AverageScalar<float>(-inf, -inf), -s_inf);
849 EXPECT_TRUE(std::isnan(saturated::AverageScalar<float>(-inf, inf)));
850 EXPECT_TRUE(std::isnan(saturated::AverageScalar<float>(inf, -inf)));
851 }
852 {
853 const double inf = std::numeric_limits<Scalar>::infinity();
854 const double max = std::numeric_limits<double>::max();
855 const double big = max * 0.5;
856
857 // Most of the averages below using the double constants will
858 // overflow the Scalar return value and result in infinity,
859 // so we also test with some Scalar constants (promoted to double)
860 // to verify that they don't overflow in the double template
861 EXPECT_EQ(saturated::AverageScalar<double>(s_big, s_big), s_big);
862 EXPECT_EQ(saturated::AverageScalar<double>(s_max, s_max), s_max);
863 EXPECT_EQ(saturated::AverageScalar<double>(-s_big, -s_big), -s_big);
864 EXPECT_EQ(saturated::AverageScalar<double>(-s_max, -s_max), -s_max);
865
866 // And now testing continues with the double constants which
867 // mostly overflow
868 EXPECT_EQ(saturated::AverageScalar<double>(big, big), s_inf);
869 EXPECT_EQ(saturated::AverageScalar<double>(max, max), s_inf);
870 EXPECT_EQ(saturated::AverageScalar<double>(big, -big), 0.0f);
871 EXPECT_EQ(saturated::AverageScalar<double>(max, -max), 0.0f);
872 EXPECT_EQ(saturated::AverageScalar<double>(-big, big), 0.0f);
873 EXPECT_EQ(saturated::AverageScalar<double>(-max, max), 0.0f);
874 EXPECT_EQ(saturated::AverageScalar<double>(-big, -big), -s_inf);
875 EXPECT_EQ(saturated::AverageScalar<double>(-max, -max), -s_inf);
876
877 EXPECT_EQ(saturated::AverageScalar<double>(inf, inf), s_inf);
878 EXPECT_EQ(saturated::AverageScalar<double>(-inf, -inf), -s_inf);
879 EXPECT_TRUE(std::isnan(saturated::AverageScalar<double>(-inf, inf)));
880 EXPECT_TRUE(std::isnan(saturated::AverageScalar<double>(inf, -inf)));
881 }
882 {
883 const Scalar inf = std::numeric_limits<Scalar>::infinity();
884 const Scalar max = std::numeric_limits<Scalar>::max();
885 const Scalar big = max * 0.5f;
886
887 EXPECT_EQ(saturated::AverageScalar<Scalar>(big, big), s_big);
888 EXPECT_EQ(saturated::AverageScalar<Scalar>(max, max), s_max);
889 EXPECT_EQ(saturated::AverageScalar<Scalar>(big, -big), 0.0f);
890 EXPECT_EQ(saturated::AverageScalar<Scalar>(max, -max), 0.0f);
891 EXPECT_EQ(saturated::AverageScalar<Scalar>(-big, big), 0.0f);
892 EXPECT_EQ(saturated::AverageScalar<Scalar>(-max, max), 0.0f);
893 EXPECT_EQ(saturated::AverageScalar<Scalar>(-big, -big), -s_big);
894 EXPECT_EQ(saturated::AverageScalar<Scalar>(-max, -max), -s_max);
895
896 EXPECT_EQ(saturated::AverageScalar<Scalar>(inf, inf), s_inf);
897 EXPECT_EQ(saturated::AverageScalar<Scalar>(-inf, -inf), -s_inf);
898 EXPECT_TRUE(std::isnan(saturated::AverageScalar<Scalar>(-inf, s_inf)));
899 EXPECT_TRUE(std::isnan(saturated::AverageScalar<Scalar>(inf, -s_inf)));
900 }
901}

◆ TEST() [566/689]

impeller::testing::TEST ( SaturatedMath  ,
ExplicitAverageScalarOfSignedInts   
)

Definition at line 716 of file saturated_math_unittests.cc.

716 {
717 // For each type try:
718 //
719 // - near the limits, averaging to 0
720 // - at the limits, averaging to 0 or 0.5 depending on precision
721 // - both large enough for the sum to overflow
722 // - both negative enough for the sum to underflow
723 {
724 EXPECT_EQ(saturated::AverageScalar<int8_t>(0x81, 0x7F), -0.0f);
725 EXPECT_EQ(saturated::AverageScalar<int8_t>(0x80, 0x7F), -0.5f);
726 EXPECT_EQ(saturated::AverageScalar<int8_t>(0x70, 0x75), 114.5f);
727 EXPECT_EQ(saturated::AverageScalar<int8_t>(0x85, 0x8A), -120.5f);
728 }
729 {
730 EXPECT_EQ(saturated::AverageScalar<int16_t>(0x8001, 0x7FFF), -0.0f);
731 EXPECT_EQ(saturated::AverageScalar<int16_t>(0x8000, 0x7FFF), -0.5f);
732 EXPECT_EQ(saturated::AverageScalar<int16_t>(0x7000, 0x7005), 28674.5f);
733 EXPECT_EQ(saturated::AverageScalar<int16_t>(0x8005, 0x800A), -32760.5f);
734 }
735 {
736 EXPECT_EQ(saturated::AverageScalar<int32_t>(0x80000001, 0x7FFFFFFF), -0.0f);
737 EXPECT_EQ(saturated::AverageScalar<int32_t>(0x80000000, 0x7FFFFFFF), -0.5f);
738 EXPECT_EQ(saturated::AverageScalar<int32_t>(0x70000000, 0x70000005),
739 1879048195.5f);
740 EXPECT_EQ(saturated::AverageScalar<int32_t>(0x80000005, 0x8000000A),
741 -2147483655.5f);
742 }
743 {
744 EXPECT_EQ(saturated::AverageScalar<int64_t>(0x8000000000000001,
745 0x7FFFFFFFFFFFFFFF),
746 0.0f);
747 // 64-bit integers overflow the ability of a Scalar (float) to
748 // represent discrete integers and so the two numbers we are
749 // averaging here will look like the same number with different
750 // signs and the answer will be "0"
751 EXPECT_EQ(saturated::AverageScalar<int64_t>(0x8000000000000000,
752 0x7FFFFFFFFFFFFFFF),
753 0.0f);
754 EXPECT_NEAR(saturated::AverageScalar<int64_t>(0x7000000000000000,
755 0x7000000000000005),
756 8.07045053e+18, 1e18);
757 EXPECT_NEAR(saturated::AverageScalar<int64_t>(0x8000000000000005,
758 0x800000000000000A),
759 -9.223372e+18, 1e18);
760 }
761}

◆ TEST() [567/689]

impeller::testing::TEST ( SaturatedMath  ,
ExplicitSubOfFloatingPoint   
)

Definition at line 488 of file saturated_math_unittests.cc.

488 {
489 {
490 const float inf = std::numeric_limits<float>::infinity();
491 const float max = std::numeric_limits<float>::max();
492 const float big = max * 0.5f;
493
494 EXPECT_EQ(saturated::Sub<float>(big, big), 0.0f);
495 EXPECT_EQ(saturated::Sub<float>(max, big), big);
496 EXPECT_EQ(saturated::Sub<float>(big, max), -big);
497 EXPECT_EQ(saturated::Sub<float>(max, max), 0.0f);
498 EXPECT_EQ(saturated::Sub<float>(max, inf), -inf);
499 EXPECT_EQ(saturated::Sub<float>(inf, max), inf);
500 EXPECT_TRUE(std::isnan(saturated::Sub<float>(inf, inf)));
501
502 EXPECT_EQ(saturated::Sub<float>(-big, -big), 0.0f);
503 EXPECT_EQ(saturated::Sub<float>(-max, -big), -big);
504 EXPECT_EQ(saturated::Sub<float>(-big, -max), big);
505 EXPECT_EQ(saturated::Sub<float>(-max, -max), 0.0f);
506 EXPECT_EQ(saturated::Sub<float>(-max, -inf), inf);
507 EXPECT_EQ(saturated::Sub<float>(-inf, -max), -inf);
508 EXPECT_TRUE(std::isnan(saturated::Sub<float>(-inf, -inf)));
509
510 EXPECT_EQ(saturated::Sub<float>(big, -big), max);
511 EXPECT_EQ(saturated::Sub<float>(max, -big), inf);
512 EXPECT_EQ(saturated::Sub<float>(big, -max), inf);
513 EXPECT_EQ(saturated::Sub<float>(max, -max), inf);
514 EXPECT_EQ(saturated::Sub<float>(max, -inf), inf);
515 EXPECT_EQ(saturated::Sub<float>(inf, -max), inf);
516 EXPECT_EQ(saturated::Sub<float>(inf, -inf), inf);
517
518 EXPECT_EQ(saturated::Sub<float>(-big, big), -max);
519 EXPECT_EQ(saturated::Sub<float>(-max, big), -inf);
520 EXPECT_EQ(saturated::Sub<float>(-big, max), -inf);
521 EXPECT_EQ(saturated::Sub<float>(-max, max), -inf);
522 EXPECT_EQ(saturated::Sub<float>(-max, inf), -inf);
523 EXPECT_EQ(saturated::Sub<float>(-inf, max), -inf);
524 EXPECT_EQ(saturated::Sub<float>(-inf, inf), -inf);
525 }
526 {
527 const double inf = std::numeric_limits<double>::infinity();
528 const double max = std::numeric_limits<double>::max();
529 const double big = max * 0.5f;
530
531 EXPECT_EQ(saturated::Sub<double>(big, big), 0.0f);
532 EXPECT_EQ(saturated::Sub<double>(max, big), big);
533 EXPECT_EQ(saturated::Sub<double>(big, max), -big);
534 EXPECT_EQ(saturated::Sub<double>(max, max), 0.0f);
535 EXPECT_EQ(saturated::Sub<double>(max, inf), -inf);
536 EXPECT_EQ(saturated::Sub<double>(inf, max), inf);
537 EXPECT_TRUE(std::isnan(saturated::Sub<double>(inf, inf)));
538
539 EXPECT_EQ(saturated::Sub<double>(-big, -big), 0.0f);
540 EXPECT_EQ(saturated::Sub<double>(-max, -big), -big);
541 EXPECT_EQ(saturated::Sub<double>(-big, -max), big);
542 EXPECT_EQ(saturated::Sub<double>(-max, -max), 0.0f);
543 EXPECT_EQ(saturated::Sub<double>(-max, -inf), inf);
544 EXPECT_EQ(saturated::Sub<double>(-inf, -max), -inf);
545 EXPECT_TRUE(std::isnan(saturated::Sub<double>(-inf, -inf)));
546
547 EXPECT_EQ(saturated::Sub<double>(big, -big), max);
548 EXPECT_EQ(saturated::Sub<double>(max, -big), inf);
549 EXPECT_EQ(saturated::Sub<double>(big, -max), inf);
550 EXPECT_EQ(saturated::Sub<double>(max, -max), inf);
551 EXPECT_EQ(saturated::Sub<double>(max, -inf), inf);
552 EXPECT_EQ(saturated::Sub<double>(inf, -max), inf);
553 EXPECT_EQ(saturated::Sub<double>(inf, -inf), inf);
554
555 EXPECT_EQ(saturated::Sub<double>(-big, big), -max);
556 EXPECT_EQ(saturated::Sub<double>(-max, big), -inf);
557 EXPECT_EQ(saturated::Sub<double>(-big, max), -inf);
558 EXPECT_EQ(saturated::Sub<double>(-max, max), -inf);
559 EXPECT_EQ(saturated::Sub<double>(-max, inf), -inf);
560 EXPECT_EQ(saturated::Sub<double>(-inf, max), -inf);
561 EXPECT_EQ(saturated::Sub<double>(-inf, inf), -inf);
562 }
563 {
564 const Scalar inf = std::numeric_limits<Scalar>::infinity();
565 const Scalar max = std::numeric_limits<Scalar>::max();
566 const Scalar big = max * 0.5f;
567
568 EXPECT_EQ(saturated::Sub<Scalar>(big, big), 0.0f);
569 EXPECT_EQ(saturated::Sub<Scalar>(max, big), big);
570 EXPECT_EQ(saturated::Sub<Scalar>(big, max), -big);
571 EXPECT_EQ(saturated::Sub<Scalar>(max, max), 0.0f);
572 EXPECT_EQ(saturated::Sub<Scalar>(max, inf), -inf);
573 EXPECT_EQ(saturated::Sub<Scalar>(inf, max), inf);
574 EXPECT_TRUE(std::isnan(saturated::Sub<Scalar>(inf, inf)));
575
576 EXPECT_EQ(saturated::Sub<Scalar>(-big, -big), 0.0f);
577 EXPECT_EQ(saturated::Sub<Scalar>(-max, -big), -big);
578 EXPECT_EQ(saturated::Sub<Scalar>(-big, -max), big);
579 EXPECT_EQ(saturated::Sub<Scalar>(-max, -max), 0.0f);
580 EXPECT_EQ(saturated::Sub<Scalar>(-max, -inf), inf);
581 EXPECT_EQ(saturated::Sub<Scalar>(-inf, -max), -inf);
582 EXPECT_TRUE(std::isnan(saturated::Sub<Scalar>(-inf, -inf)));
583
584 EXPECT_EQ(saturated::Sub<Scalar>(big, -big), max);
585 EXPECT_EQ(saturated::Sub<Scalar>(max, -big), inf);
586 EXPECT_EQ(saturated::Sub<Scalar>(big, -max), inf);
587 EXPECT_EQ(saturated::Sub<Scalar>(max, -max), inf);
588 EXPECT_EQ(saturated::Sub<Scalar>(max, -inf), inf);
589 EXPECT_EQ(saturated::Sub<Scalar>(inf, -max), inf);
590 EXPECT_EQ(saturated::Sub<Scalar>(inf, -inf), inf);
591
592 EXPECT_EQ(saturated::Sub<Scalar>(-big, big), -max);
593 EXPECT_EQ(saturated::Sub<Scalar>(-max, big), -inf);
594 EXPECT_EQ(saturated::Sub<Scalar>(-big, max), -inf);
595 EXPECT_EQ(saturated::Sub<Scalar>(-max, max), -inf);
596 EXPECT_EQ(saturated::Sub<Scalar>(-max, inf), -inf);
597 EXPECT_EQ(saturated::Sub<Scalar>(-inf, max), -inf);
598 EXPECT_EQ(saturated::Sub<Scalar>(-inf, inf), -inf);
599 }
600}

◆ TEST() [568/689]

impeller::testing::TEST ( SaturatedMath  ,
ExplicitSubOfSignedInts   
)

Definition at line 364 of file saturated_math_unittests.cc.

364 {
365 {
366 EXPECT_EQ(saturated::Sub<int8_t>(0x79, -5), int8_t(0x7E));
367 EXPECT_EQ(saturated::Sub<int8_t>(0x7A, -5), int8_t(0x7F));
368 EXPECT_EQ(saturated::Sub<int8_t>(0x7B, -5), int8_t(0x7F));
369 }
370 {
371 EXPECT_EQ(saturated::Sub<int8_t>(0x86, 5), int8_t(0x81));
372 EXPECT_EQ(saturated::Sub<int8_t>(0x85, 5), int8_t(0x80));
373 EXPECT_EQ(saturated::Sub<int8_t>(0x84, 5), int8_t(0x80));
374 }
375 {
376 EXPECT_EQ(saturated::Sub<int16_t>(0x7FF9, -5), int16_t(0x7FFE));
377 EXPECT_EQ(saturated::Sub<int16_t>(0x7FFA, -5), int16_t(0x7FFF));
378 EXPECT_EQ(saturated::Sub<int16_t>(0x7FFB, -5), int16_t(0x7FFF));
379 }
380 {
381 EXPECT_EQ(saturated::Sub<int16_t>(0x8006, 5), int16_t(0x8001));
382 EXPECT_EQ(saturated::Sub<int16_t>(0x8005, 5), int16_t(0x8000));
383 EXPECT_EQ(saturated::Sub<int16_t>(0x8004, 5), int16_t(0x8000));
384 }
385 {
386 EXPECT_EQ(saturated::Sub<int32_t>(0x7FFFFFF9, -5), int32_t(0x7FFFFFFE));
387 EXPECT_EQ(saturated::Sub<int32_t>(0x7FFFFFFA, -5), int32_t(0x7FFFFFFF));
388 EXPECT_EQ(saturated::Sub<int32_t>(0x7FFFFFFB, -5), int32_t(0x7FFFFFFF));
389 }
390 {
391 EXPECT_EQ(saturated::Sub<int32_t>(0x80000006, 5), int32_t(0x80000001));
392 EXPECT_EQ(saturated::Sub<int32_t>(0x80000005, 5), int32_t(0x80000000));
393 EXPECT_EQ(saturated::Sub<int32_t>(0x80000004, 5), int32_t(0x80000000));
394 }
395 {
396 EXPECT_EQ(saturated::Sub<int64_t>(0x7FFFFFFFFFFFFFF9, -5),
397 int64_t(0x7FFFFFFFFFFFFFFE));
398 EXPECT_EQ(saturated::Sub<int64_t>(0x7FFFFFFFFFFFFFFA, -5),
399 int64_t(0x7FFFFFFFFFFFFFFF));
400 EXPECT_EQ(saturated::Sub<int64_t>(0x7FFFFFFFFFFFFFFB, -5),
401 int64_t(0x7FFFFFFFFFFFFFFF));
402 }
403 {
404 EXPECT_EQ(saturated::Sub<int64_t>(0x8000000000000006, 5),
405 int64_t(0x8000000000000001));
406 EXPECT_EQ(saturated::Sub<int64_t>(0x8000000000000005, 5),
407 int64_t(0x8000000000000000));
408 EXPECT_EQ(saturated::Sub<int64_t>(0x8000000000000004, 5),
409 int64_t(0x8000000000000000));
410 }
411}

◆ TEST() [569/689]

impeller::testing::TEST ( SaturatedMath  ,
ImplicitAddOfFloatingPoint   
)

Definition at line 250 of file saturated_math_unittests.cc.

250 {
251 {
252 const float inf = std::numeric_limits<float>::infinity();
253 const float max = std::numeric_limits<float>::max();
254 const float big = max * 0.5f;
255
256 EXPECT_EQ(saturated::Add(big, big), max);
257 EXPECT_EQ(saturated::Add(max, big), inf);
258 EXPECT_EQ(saturated::Add(big, max), inf);
259 EXPECT_EQ(saturated::Add(max, max), inf);
260 EXPECT_EQ(saturated::Add(max, inf), inf);
261 EXPECT_EQ(saturated::Add(inf, max), inf);
262 EXPECT_EQ(saturated::Add(inf, inf), inf);
263
264 EXPECT_EQ(saturated::Add(-big, -big), -max);
265 EXPECT_EQ(saturated::Add(-max, -big), -inf);
266 EXPECT_EQ(saturated::Add(-big, -max), -inf);
267 EXPECT_EQ(saturated::Add(-max, -max), -inf);
268 EXPECT_EQ(saturated::Add(-max, -inf), -inf);
269 EXPECT_EQ(saturated::Add(-inf, -max), -inf);
270 EXPECT_EQ(saturated::Add(-inf, -inf), -inf);
271
272 EXPECT_EQ(saturated::Add(big, -big), 0.0f);
273 EXPECT_EQ(saturated::Add(max, -big), big);
274 EXPECT_EQ(saturated::Add(big, -max), -big);
275 EXPECT_EQ(saturated::Add(max, -max), 0.0f);
276 EXPECT_EQ(saturated::Add(max, -inf), -inf);
277 EXPECT_EQ(saturated::Add(inf, -max), inf);
278 EXPECT_TRUE(std::isnan(saturated::Add(inf, -inf)));
279
280 EXPECT_EQ(saturated::Add(-big, big), 0.0f);
281 EXPECT_EQ(saturated::Add(-max, big), -big);
282 EXPECT_EQ(saturated::Add(-big, max), big);
283 EXPECT_EQ(saturated::Add(-max, max), 0.0f);
284 EXPECT_EQ(saturated::Add(-max, inf), inf);
285 EXPECT_EQ(saturated::Add(-inf, max), -inf);
286 EXPECT_TRUE(std::isnan(saturated::Add(-inf, inf)));
287 }
288 {
289 const double inf = std::numeric_limits<double>::infinity();
290 const double max = std::numeric_limits<double>::max();
291 const double big = max * 0.5f;
292
293 EXPECT_EQ(saturated::Add(big, big), max);
294 EXPECT_EQ(saturated::Add(max, big), inf);
295 EXPECT_EQ(saturated::Add(big, max), inf);
296 EXPECT_EQ(saturated::Add(max, max), inf);
297 EXPECT_EQ(saturated::Add(max, inf), inf);
298 EXPECT_EQ(saturated::Add(inf, max), inf);
299 EXPECT_EQ(saturated::Add(inf, inf), inf);
300
301 EXPECT_EQ(saturated::Add(-big, -big), -max);
302 EXPECT_EQ(saturated::Add(-max, -big), -inf);
303 EXPECT_EQ(saturated::Add(-big, -max), -inf);
304 EXPECT_EQ(saturated::Add(-max, -max), -inf);
305 EXPECT_EQ(saturated::Add(-max, -inf), -inf);
306 EXPECT_EQ(saturated::Add(-inf, -max), -inf);
307 EXPECT_EQ(saturated::Add(-inf, -inf), -inf);
308
309 EXPECT_EQ(saturated::Add(big, -big), 0.0f);
310 EXPECT_EQ(saturated::Add(max, -big), big);
311 EXPECT_EQ(saturated::Add(big, -max), -big);
312 EXPECT_EQ(saturated::Add(max, -max), 0.0f);
313 EXPECT_EQ(saturated::Add(max, -inf), -inf);
314 EXPECT_EQ(saturated::Add(inf, -max), inf);
315 EXPECT_TRUE(std::isnan(saturated::Add(inf, -inf)));
316
317 EXPECT_EQ(saturated::Add(-big, big), 0.0f);
318 EXPECT_EQ(saturated::Add(-max, big), -big);
319 EXPECT_EQ(saturated::Add(-big, max), big);
320 EXPECT_EQ(saturated::Add(-max, max), 0.0f);
321 EXPECT_EQ(saturated::Add(-max, inf), inf);
322 EXPECT_EQ(saturated::Add(-inf, max), -inf);
323 EXPECT_TRUE(std::isnan(saturated::Add(-inf, inf)));
324 }
325 {
326 const Scalar inf = std::numeric_limits<Scalar>::infinity();
327 const Scalar max = std::numeric_limits<Scalar>::max();
328 const Scalar big = max * 0.5f;
329
330 EXPECT_EQ(saturated::Add(big, big), max);
331 EXPECT_EQ(saturated::Add(max, big), inf);
332 EXPECT_EQ(saturated::Add(big, max), inf);
333 EXPECT_EQ(saturated::Add(max, max), inf);
334 EXPECT_EQ(saturated::Add(max, inf), inf);
335 EXPECT_EQ(saturated::Add(inf, max), inf);
336 EXPECT_EQ(saturated::Add(inf, inf), inf);
337
338 EXPECT_EQ(saturated::Add(-big, -big), -max);
339 EXPECT_EQ(saturated::Add(-max, -big), -inf);
340 EXPECT_EQ(saturated::Add(-big, -max), -inf);
341 EXPECT_EQ(saturated::Add(-max, -max), -inf);
342 EXPECT_EQ(saturated::Add(-max, -inf), -inf);
343 EXPECT_EQ(saturated::Add(-inf, -max), -inf);
344 EXPECT_EQ(saturated::Add(-inf, -inf), -inf);
345
346 EXPECT_EQ(saturated::Add(big, -big), 0.0f);
347 EXPECT_EQ(saturated::Add(max, -big), big);
348 EXPECT_EQ(saturated::Add(big, -max), -big);
349 EXPECT_EQ(saturated::Add(max, -max), 0.0f);
350 EXPECT_EQ(saturated::Add(max, -inf), -inf);
351 EXPECT_EQ(saturated::Add(inf, -max), inf);
352 EXPECT_TRUE(std::isnan(saturated::Add(inf, -inf)));
353
354 EXPECT_EQ(saturated::Add(-big, big), 0.0f);
355 EXPECT_EQ(saturated::Add(-max, big), -big);
356 EXPECT_EQ(saturated::Add(-big, max), big);
357 EXPECT_EQ(saturated::Add(-max, max), 0.0f);
358 EXPECT_EQ(saturated::Add(-max, inf), inf);
359 EXPECT_EQ(saturated::Add(-inf, max), -inf);
360 EXPECT_TRUE(std::isnan(saturated::Add(-inf, inf)));
361 }
362}

◆ TEST() [570/689]

impeller::testing::TEST ( SaturatedMath  ,
ImplicitAddOfSignedInts   
)

Definition at line 61 of file saturated_math_unittests.cc.

61 {
62 {
63 int8_t a = 0x79;
64 int8_t b = 5;
65 EXPECT_EQ(saturated::Add(a, b), int8_t(0x7E));
66 a = 0x7A;
67 EXPECT_EQ(saturated::Add(a, b), int8_t(0x7F));
68 a = 0x7B;
69 EXPECT_EQ(saturated::Add(a, b), int8_t(0x7F));
70 }
71 {
72 int8_t a = 0x86;
73 int8_t b = -5;
74 EXPECT_EQ(saturated::Add(a, b), int8_t(0x81));
75 a = 0x85;
76 EXPECT_EQ(saturated::Add(a, b), int8_t(0x80));
77 a = 0x84;
78 EXPECT_EQ(saturated::Add(a, b), int8_t(0x80));
79 }
80 {
81 int16_t a = 0x7FF9;
82 int16_t b = 5;
83 EXPECT_EQ(saturated::Add(a, b), int16_t(0x7FFE));
84 a = 0x7FFA;
85 EXPECT_EQ(saturated::Add(a, b), int16_t(0x7FFF));
86 a = 0x7FFB;
87 EXPECT_EQ(saturated::Add(a, b), int16_t(0x7FFF));
88 }
89 {
90 int16_t a = 0x8006;
91 int16_t b = -5;
92 EXPECT_EQ(saturated::Add(a, b), int16_t(0x8001));
93 a = 0x8005;
94 EXPECT_EQ(saturated::Add(a, b), int16_t(0x8000));
95 a = 0x8004;
96 EXPECT_EQ(saturated::Add(a, b), int16_t(0x8000));
97 }
98 {
99 int32_t a = 0x7FFFFFF9;
100 int32_t b = 5;
101 EXPECT_EQ(saturated::Add(a, b), int32_t(0x7FFFFFFE));
102 a = 0x7FFFFFFA;
103 EXPECT_EQ(saturated::Add(a, b), int32_t(0x7FFFFFFF));
104 a = 0x7FFFFFFB;
105 EXPECT_EQ(saturated::Add(a, b), int32_t(0x7FFFFFFF));
106 }
107 {
108 int32_t a = 0x80000006;
109 int32_t b = -5;
110 EXPECT_EQ(saturated::Add(a, b), int32_t(0x80000001));
111 a = 0x80000005;
112 EXPECT_EQ(saturated::Add(a, b), int32_t(0x80000000));
113 a = 0x80000004;
114 EXPECT_EQ(saturated::Add(a, b), int32_t(0x80000000));
115 }
116 {
117 int64_t a = 0x7FFFFFFFFFFFFFF9;
118 int64_t b = 5;
119 EXPECT_EQ(saturated::Add(a, b), int64_t(0x7FFFFFFFFFFFFFFE));
120 a = 0x7FFFFFFFFFFFFFFA;
121 EXPECT_EQ(saturated::Add(a, b), int64_t(0x7FFFFFFFFFFFFFFF));
122 a = 0x7FFFFFFFFFFFFFFB;
123 EXPECT_EQ(saturated::Add(a, b), int64_t(0x7FFFFFFFFFFFFFFF));
124 }
125 {
126 int64_t a = 0x8000000000000006;
127 int64_t b = -5;
128 EXPECT_EQ(saturated::Add(a, b), int64_t(0x8000000000000001));
129 a = 0x8000000000000005;
130 EXPECT_EQ(saturated::Add(a, b), int64_t(0x8000000000000000));
131 a = 0x8000000000000004;
132 EXPECT_EQ(saturated::Add(a, b), int64_t(0x8000000000000000));
133 }
134}

◆ TEST() [571/689]

impeller::testing::TEST ( SaturatedMath  ,
ImplicitAverageScalarOfFloatingPoint   
)

Definition at line 903 of file saturated_math_unittests.cc.

903 {
904 // All return values are Scalar regardless of the operand types
905 // so these constants are used as the expected answers.
906 const Scalar s_inf = std::numeric_limits<Scalar>::infinity();
907 const Scalar s_max = std::numeric_limits<Scalar>::max();
908 const Scalar s_big = s_max * 0.5f;
909
910 {
911 const float inf = std::numeric_limits<float>::infinity();
912 const float max = std::numeric_limits<float>::max();
913 const float big = max * 0.5f;
914
915 EXPECT_EQ(saturated::AverageScalar(big, big), s_big);
916 EXPECT_EQ(saturated::AverageScalar(max, max), s_max);
917 EXPECT_EQ(saturated::AverageScalar(big, -big), 0.0f);
918 EXPECT_EQ(saturated::AverageScalar(max, -max), 0.0f);
919 EXPECT_EQ(saturated::AverageScalar(-big, big), 0.0f);
920 EXPECT_EQ(saturated::AverageScalar(-max, max), 0.0f);
921 EXPECT_EQ(saturated::AverageScalar(-big, -big), -s_big);
922 EXPECT_EQ(saturated::AverageScalar(-max, -max), -s_max);
923
924 EXPECT_EQ(saturated::AverageScalar(inf, inf), s_inf);
925 EXPECT_EQ(saturated::AverageScalar(-inf, -inf), -s_inf);
926 EXPECT_TRUE(std::isnan(saturated::AverageScalar(-inf, inf)));
927 EXPECT_TRUE(std::isnan(saturated::AverageScalar(inf, -inf)));
928 }
929 {
930 const double inf = std::numeric_limits<double>::infinity();
931 const double max = std::numeric_limits<double>::max();
932 const double big = max * 0.5;
933
934 // The s_constants converted to double. We should get finite results
935 // from finding the averages of these values, but we'll get a lot of
936 // overflow to infinity when testing the large double constants.
937 const double d_s_max = s_max;
938 const double d_s_big = s_big;
939 EXPECT_EQ(saturated::AverageScalar(d_s_big, d_s_big), s_big);
940 EXPECT_EQ(saturated::AverageScalar(d_s_max, d_s_max), s_max);
941 EXPECT_EQ(saturated::AverageScalar(-d_s_big, -d_s_big), -s_big);
942 EXPECT_EQ(saturated::AverageScalar(-d_s_max, -d_s_max), -s_max);
943
944 // And now testing continues with the double constants which
945 // mostly overflow
946 EXPECT_EQ(saturated::AverageScalar(big, big), s_inf);
947 EXPECT_EQ(saturated::AverageScalar(max, max), s_inf);
948 EXPECT_EQ(saturated::AverageScalar(big, -big), 0.0f);
949 EXPECT_EQ(saturated::AverageScalar(max, -max), 0.0f);
950 EXPECT_EQ(saturated::AverageScalar(-big, big), 0.0f);
951 EXPECT_EQ(saturated::AverageScalar(-max, max), 0.0f);
952 EXPECT_EQ(saturated::AverageScalar(-big, -big), -s_inf);
953 EXPECT_EQ(saturated::AverageScalar(-max, -max), -s_inf);
954
955 EXPECT_EQ(saturated::AverageScalar(inf, inf), s_inf);
956 EXPECT_EQ(saturated::AverageScalar(-inf, -inf), -s_inf);
957 EXPECT_TRUE(std::isnan(saturated::AverageScalar(-inf, inf)));
958 EXPECT_TRUE(std::isnan(saturated::AverageScalar(inf, -inf)));
959 }
960 {
961 const Scalar inf = std::numeric_limits<Scalar>::infinity();
962 const Scalar max = std::numeric_limits<Scalar>::max();
963 const Scalar big = max * 0.5f;
964
965 EXPECT_EQ(saturated::AverageScalar(big, big), s_big);
966 EXPECT_EQ(saturated::AverageScalar(max, max), s_max);
967 EXPECT_EQ(saturated::AverageScalar(big, -big), 0.0f);
968 EXPECT_EQ(saturated::AverageScalar(max, -max), 0.0f);
969 EXPECT_EQ(saturated::AverageScalar(-big, big), 0.0f);
970 EXPECT_EQ(saturated::AverageScalar(-max, max), 0.0f);
971 EXPECT_EQ(saturated::AverageScalar(-big, -big), -s_big);
972 EXPECT_EQ(saturated::AverageScalar(-max, -max), -s_max);
973
974 EXPECT_EQ(saturated::AverageScalar(inf, inf), s_inf);
975 EXPECT_EQ(saturated::AverageScalar(-inf, -inf), -s_inf);
976 EXPECT_TRUE(std::isnan(saturated::AverageScalar(-inf, s_inf)));
977 EXPECT_TRUE(std::isnan(saturated::AverageScalar(inf, -s_inf)));
978 }
979}

◆ TEST() [572/689]

impeller::testing::TEST ( SaturatedMath  ,
ImplicitAverageScalarOfSignedInts   
)

Definition at line 763 of file saturated_math_unittests.cc.

763 {
764 // For each type try:
765 //
766 // - near the limits, averaging to 0
767 // - at the limits, averaging to 0 or 0.5 depending on precision
768 // - both large enough for the sum to overflow
769 // - both negative enough for the sum to underflow
770 {
771 int8_t a = 0x81;
772 int8_t b = 0x7f;
773 EXPECT_EQ(saturated::AverageScalar(a, b), -0.0f);
774 a = 0x80;
775 EXPECT_EQ(saturated::AverageScalar(a, b), -0.5f);
776 a = 0x70;
777 b = 0x75;
778 EXPECT_EQ(saturated::AverageScalar(a, b), 114.5f);
779 a = 0x85;
780 b = 0x8A;
781 EXPECT_EQ(saturated::AverageScalar(a, b), -120.5f);
782 }
783 {
784 int16_t a = 0x8001;
785 int16_t b = 0x7FFF;
786 EXPECT_EQ(saturated::AverageScalar(a, b), -0.0f);
787 a = 0x8000;
788 EXPECT_EQ(saturated::AverageScalar(a, b), -0.5f);
789 a = 0x7000;
790 b = 0x7005;
791 EXPECT_EQ(saturated::AverageScalar(a, b), 28674.5f);
792 a = 0x8005;
793 b = 0x800A;
794 EXPECT_EQ(saturated::AverageScalar(a, b), -32760.5f);
795 }
796 {
797 int32_t a = 0x80000001;
798 int32_t b = 0x7FFFFFFF;
799 EXPECT_EQ(saturated::AverageScalar(a, b), -0.0f);
800 a = 0x80000000;
801 EXPECT_EQ(saturated::AverageScalar(a, b), -0.5f);
802 a = 0x70000000;
803 b = 0x70000005;
804 EXPECT_EQ(saturated::AverageScalar(a, b), 1879048195.5f);
805 a = 0x80000005;
806 b = 0x8000000A;
807 EXPECT_EQ(saturated::AverageScalar(a, b), -2147483655.5f);
808 }
809 {
810 int64_t a = 0x8000000000000001;
811 int64_t b = 0x7FFFFFFFFFFFFFFF;
812 EXPECT_EQ(saturated::AverageScalar(a, b), 0.0f);
813 // 64-bit integers overflow the ability of a Scalar (float) to
814 // represent discrete integers and so the two numbers we are
815 // averaging here will look like the same number with different
816 // signs and the answer will be "0"
817 a = 0x8000000000000000;
818 EXPECT_EQ(saturated::AverageScalar<int64_t>(a, b), 0.0f);
819 a = 0x7000000000000000;
820 b = 0x7000000000000005;
821 EXPECT_NEAR(saturated::AverageScalar<int64_t>(a, b), 8.0704505e+18, 1e18);
822 a = 0x8000000000000005;
823 b = 0x800000000000000A;
824 EXPECT_NEAR(saturated::AverageScalar<int64_t>(a, b), -9.223372e+18, 1e18);
825 }
826}

◆ TEST() [573/689]

impeller::testing::TEST ( SaturatedMath  ,
ImplicitSubOfFloatingPoint   
)

Definition at line 602 of file saturated_math_unittests.cc.

602 {
603 {
604 const float inf = std::numeric_limits<float>::infinity();
605 const float max = std::numeric_limits<float>::max();
606 const float big = max * 0.5f;
607
608 EXPECT_EQ(saturated::Sub(big, big), 0.0f);
609 EXPECT_EQ(saturated::Sub(max, big), big);
610 EXPECT_EQ(saturated::Sub(big, max), -big);
611 EXPECT_EQ(saturated::Sub(max, max), 0.0f);
612 EXPECT_EQ(saturated::Sub(max, inf), -inf);
613 EXPECT_EQ(saturated::Sub(inf, max), inf);
614 EXPECT_TRUE(std::isnan(saturated::Sub(inf, inf)));
615
616 EXPECT_EQ(saturated::Sub(-big, -big), 0.0f);
617 EXPECT_EQ(saturated::Sub(-max, -big), -big);
618 EXPECT_EQ(saturated::Sub(-big, -max), big);
619 EXPECT_EQ(saturated::Sub(-max, -max), 0.0f);
620 EXPECT_EQ(saturated::Sub(-max, -inf), inf);
621 EXPECT_EQ(saturated::Sub(-inf, -max), -inf);
622 EXPECT_TRUE(std::isnan(saturated::Sub(-inf, -inf)));
623
624 EXPECT_EQ(saturated::Sub(big, -big), max);
625 EXPECT_EQ(saturated::Sub(max, -big), inf);
626 EXPECT_EQ(saturated::Sub(big, -max), inf);
627 EXPECT_EQ(saturated::Sub(max, -max), inf);
628 EXPECT_EQ(saturated::Sub(max, -inf), inf);
629 EXPECT_EQ(saturated::Sub(inf, -max), inf);
630 EXPECT_EQ(saturated::Sub(inf, -inf), inf);
631
632 EXPECT_EQ(saturated::Sub(-big, big), -max);
633 EXPECT_EQ(saturated::Sub(-max, big), -inf);
634 EXPECT_EQ(saturated::Sub(-big, max), -inf);
635 EXPECT_EQ(saturated::Sub(-max, max), -inf);
636 EXPECT_EQ(saturated::Sub(-max, inf), -inf);
637 EXPECT_EQ(saturated::Sub(-inf, max), -inf);
638 EXPECT_EQ(saturated::Sub(-inf, inf), -inf);
639 }
640 {
641 const double inf = std::numeric_limits<double>::infinity();
642 const double max = std::numeric_limits<double>::max();
643 const double big = max * 0.5f;
644
645 EXPECT_EQ(saturated::Sub(big, big), 0.0f);
646 EXPECT_EQ(saturated::Sub(max, big), big);
647 EXPECT_EQ(saturated::Sub(big, max), -big);
648 EXPECT_EQ(saturated::Sub(max, max), 0.0f);
649 EXPECT_EQ(saturated::Sub(max, inf), -inf);
650 EXPECT_EQ(saturated::Sub(inf, max), inf);
651 EXPECT_TRUE(std::isnan(saturated::Sub(inf, inf)));
652
653 EXPECT_EQ(saturated::Sub(-big, -big), 0.0f);
654 EXPECT_EQ(saturated::Sub(-max, -big), -big);
655 EXPECT_EQ(saturated::Sub(-big, -max), big);
656 EXPECT_EQ(saturated::Sub(-max, -max), 0.0f);
657 EXPECT_EQ(saturated::Sub(-max, -inf), inf);
658 EXPECT_EQ(saturated::Sub(-inf, -max), -inf);
659 EXPECT_TRUE(std::isnan(saturated::Sub(-inf, -inf)));
660
661 EXPECT_EQ(saturated::Sub(big, -big), max);
662 EXPECT_EQ(saturated::Sub(max, -big), inf);
663 EXPECT_EQ(saturated::Sub(big, -max), inf);
664 EXPECT_EQ(saturated::Sub(max, -max), inf);
665 EXPECT_EQ(saturated::Sub(max, -inf), inf);
666 EXPECT_EQ(saturated::Sub(inf, -max), inf);
667 EXPECT_EQ(saturated::Sub(inf, -inf), inf);
668
669 EXPECT_EQ(saturated::Sub(-big, big), -max);
670 EXPECT_EQ(saturated::Sub(-max, big), -inf);
671 EXPECT_EQ(saturated::Sub(-big, max), -inf);
672 EXPECT_EQ(saturated::Sub(-max, max), -inf);
673 EXPECT_EQ(saturated::Sub(-max, inf), -inf);
674 EXPECT_EQ(saturated::Sub(-inf, max), -inf);
675 EXPECT_EQ(saturated::Sub(-inf, inf), -inf);
676 }
677 {
678 const Scalar inf = std::numeric_limits<Scalar>::infinity();
679 const Scalar max = std::numeric_limits<Scalar>::max();
680 const Scalar big = max * 0.5f;
681
682 EXPECT_EQ(saturated::Sub(big, big), 0.0f);
683 EXPECT_EQ(saturated::Sub(max, big), big);
684 EXPECT_EQ(saturated::Sub(big, max), -big);
685 EXPECT_EQ(saturated::Sub(max, max), 0.0f);
686 EXPECT_EQ(saturated::Sub(max, inf), -inf);
687 EXPECT_EQ(saturated::Sub(inf, max), inf);
688 EXPECT_TRUE(std::isnan(saturated::Sub(inf, inf)));
689
690 EXPECT_EQ(saturated::Sub(-big, -big), 0.0f);
691 EXPECT_EQ(saturated::Sub(-max, -big), -big);
692 EXPECT_EQ(saturated::Sub(-big, -max), big);
693 EXPECT_EQ(saturated::Sub(-max, -max), 0.0f);
694 EXPECT_EQ(saturated::Sub(-max, -inf), inf);
695 EXPECT_EQ(saturated::Sub(-inf, -max), -inf);
696 EXPECT_TRUE(std::isnan(saturated::Sub(-inf, -inf)));
697
698 EXPECT_EQ(saturated::Sub(big, -big), max);
699 EXPECT_EQ(saturated::Sub(max, -big), inf);
700 EXPECT_EQ(saturated::Sub(big, -max), inf);
701 EXPECT_EQ(saturated::Sub(max, -max), inf);
702 EXPECT_EQ(saturated::Sub(max, -inf), inf);
703 EXPECT_EQ(saturated::Sub(inf, -max), inf);
704 EXPECT_EQ(saturated::Sub(inf, -inf), inf);
705
706 EXPECT_EQ(saturated::Sub(-big, big), -max);
707 EXPECT_EQ(saturated::Sub(-max, big), -inf);
708 EXPECT_EQ(saturated::Sub(-big, max), -inf);
709 EXPECT_EQ(saturated::Sub(-max, max), -inf);
710 EXPECT_EQ(saturated::Sub(-max, inf), -inf);
711 EXPECT_EQ(saturated::Sub(-inf, max), -inf);
712 EXPECT_EQ(saturated::Sub(-inf, inf), -inf);
713 }
714}

◆ TEST() [574/689]

impeller::testing::TEST ( SaturatedMath  ,
ImplicitSubOfSignedInts   
)

Definition at line 413 of file saturated_math_unittests.cc.

413 {
414 {
415 int8_t a = 0x79;
416 int8_t b = -5;
417 EXPECT_EQ(saturated::Sub(a, b), int8_t(0x7E));
418 a = 0x7A;
419 EXPECT_EQ(saturated::Sub(a, b), int8_t(0x7F));
420 a = 0x7B;
421 EXPECT_EQ(saturated::Sub(a, b), int8_t(0x7F));
422 }
423 {
424 int8_t a = 0x86;
425 int8_t b = 5;
426 EXPECT_EQ(saturated::Sub(a, b), int8_t(0x81));
427 a = 0x85;
428 EXPECT_EQ(saturated::Sub(a, b), int8_t(0x80));
429 a = 0x84;
430 EXPECT_EQ(saturated::Sub(a, b), int8_t(0x80));
431 }
432 {
433 int16_t a = 0x7FF9;
434 int16_t b = -5;
435 EXPECT_EQ(saturated::Sub(a, b), int16_t(0x7FFE));
436 a = 0x7FFA;
437 EXPECT_EQ(saturated::Sub(a, b), int16_t(0x7FFF));
438 a = 0x7FFB;
439 EXPECT_EQ(saturated::Sub(a, b), int16_t(0x7FFF));
440 }
441 {
442 int16_t a = 0x8006;
443 int16_t b = 5;
444 EXPECT_EQ(saturated::Sub(a, b), int16_t(0x8001));
445 a = 0x8005;
446 EXPECT_EQ(saturated::Sub(a, b), int16_t(0x8000));
447 a = 0x8004;
448 EXPECT_EQ(saturated::Sub(a, b), int16_t(0x8000));
449 }
450 {
451 int32_t a = 0x7FFFFFF9;
452 int32_t b = -5;
453 EXPECT_EQ(saturated::Sub(a, b), int32_t(0x7FFFFFFE));
454 a = 0x7FFFFFFA;
455 EXPECT_EQ(saturated::Sub(a, b), int32_t(0x7FFFFFFF));
456 a = 0x7FFFFFFB;
457 EXPECT_EQ(saturated::Sub(a, b), int32_t(0x7FFFFFFF));
458 }
459 {
460 int32_t a = 0x80000006;
461 int32_t b = 5;
462 EXPECT_EQ(saturated::Sub(a, b), int32_t(0x80000001));
463 a = 0x80000005;
464 EXPECT_EQ(saturated::Sub(a, b), int32_t(0x80000000));
465 a = 0x80000004;
466 EXPECT_EQ(saturated::Sub(a, b), int32_t(0x80000000));
467 }
468 {
469 int64_t a = 0x7FFFFFFFFFFFFFF9;
470 int64_t b = -5;
471 EXPECT_EQ(saturated::Sub(a, b), int64_t(0x7FFFFFFFFFFFFFFE));
472 a = 0x7FFFFFFFFFFFFFFA;
473 EXPECT_EQ(saturated::Sub(a, b), int64_t(0x7FFFFFFFFFFFFFFF));
474 a = 0x7FFFFFFFFFFFFFFB;
475 EXPECT_EQ(saturated::Sub(a, b), int64_t(0x7FFFFFFFFFFFFFFF));
476 }
477 {
478 int64_t a = 0x8000000000000006;
479 int64_t b = 5;
480 EXPECT_EQ(saturated::Sub(a, b), int64_t(0x8000000000000001));
481 a = 0x8000000000000005;
482 EXPECT_EQ(saturated::Sub(a, b), int64_t(0x8000000000000000));
483 a = 0x8000000000000004;
484 EXPECT_EQ(saturated::Sub(a, b), int64_t(0x8000000000000000));
485 }
486}

◆ TEST() [575/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
BackdropFilterEmptyCoverage   
)

Definition at line 163 of file save_layer_utils_unittests.cc.

163 {
164 // Empty coverage with backdrop filter.
165 auto coverage = ComputeSaveLayerCoverage(
166 /*content_coverage=*/Rect::MakeLTRB(0, 0, 0, 0), //
167 /*effect_transform=*/{}, //
168 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 2400, 1800), //
169 /*image_filter=*/nullptr, //
170 /*flood_output_coverage=*/true //
171 );
172
173 ASSERT_TRUE(coverage.has_value());
174 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 2400, 1800));
175}
std::optional< Rect > ComputeSaveLayerCoverage(const Rect &content_coverage, const Matrix &effect_transform, const Rect &coverage_limit, const std::shared_ptr< FilterContents > &image_filter, bool flood_output_coverage, bool flood_input_coverage)
Compute the coverage of a subpass in the global coordinate space.

References impeller::ComputeSaveLayerCoverage(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [576/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
BackdropFiterComputedCoverage   
)

Definition at line 29 of file save_layer_utils_unittests.cc.

29 {
30 // Backdrop Filter, computed coverage
31 auto coverage = ComputeSaveLayerCoverage(
32 /*content_coverage=*/Rect::MakeLTRB(0, 0, 10, 10), //
33 /*effect_transform=*/{}, //
34 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 2400, 1800), //
35 /*image_filter=*/nullptr,
36 /*flood_output_coverage=*/false, //
37 /*flood_input_coverage=*/true //
38 );
39
40 ASSERT_TRUE(coverage.has_value());
41 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 2400, 1800));
42}

References impeller::ComputeSaveLayerCoverage(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [577/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
BasicEmptyCoverage   
)

Definition at line 137 of file save_layer_utils_unittests.cc.

137 {
138 auto coverage = ComputeSaveLayerCoverage(
139 /*content_coverage=*/Rect::MakeLTRB(0, 0, 0, 0), //
140 /*effect_transform=*/{}, //
141 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 2400, 1800), //
142 /*image_filter=*/nullptr //
143 );
144
145 ASSERT_FALSE(coverage.has_value());
146}

References impeller::ComputeSaveLayerCoverage(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [578/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
CoverageLimitIgnoredIfIntersectedValueIsCloseToActualCoverageLargerWithImageFilter   
)

Definition at line 246 of file save_layer_utils_unittests.cc.

248 {
249 // Create an image filter that slightly stretches the coverage limit. Even
250 // without the special logic for using the original content coverage, we
251 // verify that we don't introduce any artifacts from the intersection.
252 auto image_filter = FilterContents::MakeMatrixFilter(
253 FilterInput::Make(Rect()), Matrix::MakeScale({0.9, 0.9, 1}), {});
254
255 auto coverage = ComputeSaveLayerCoverage(
256 /*content_coverage=*/Rect::MakeLTRB(0, 0, 100, 100), //
257 /*effect_transform=*/{}, //
258 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), //
259 /*image_filter=*/image_filter //
260 );
261
262 ASSERT_TRUE(coverage.has_value());
263 // The transfomed coverage limit is ((0, 0), (111.111, 111.111)).
264 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 100, 100));
265}

References impeller::ComputeSaveLayerCoverage(), impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::FilterContents::MakeMatrixFilter(), and impeller::Matrix::MakeScale().

◆ TEST() [579/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
CoverageLimitIgnoredIfIntersectedValueIsCloseToActualCoverageSmallerWithImageFilter   
)

Definition at line 227 of file save_layer_utils_unittests.cc.

229 {
230 // Create an image filter that slightly shrinks the coverage limit
231 auto image_filter = FilterContents::MakeMatrixFilter(
232 FilterInput::Make(Rect()), Matrix::MakeScale({1.1, 1.1, 1}), {});
233
234 auto coverage = ComputeSaveLayerCoverage(
235 /*content_coverage=*/Rect::MakeLTRB(0, 0, 100, 100), //
236 /*effect_transform=*/{}, //
237 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), //
238 /*image_filter=*/image_filter //
239 );
240
241 ASSERT_TRUE(coverage.has_value());
242 // The transfomed coverage limit is ((0, 0), (90.9091, 90.9091)).
243 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 100, 100));
244}

References impeller::ComputeSaveLayerCoverage(), impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::FilterContents::MakeMatrixFilter(), and impeller::Matrix::MakeScale().

◆ TEST() [580/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
CoverageLimitRespectedIfSubstantiallyDifferentFromContentCoverage   
)

Definition at line 267 of file save_layer_utils_unittests.cc.

268 {
269 auto image_filter = FilterContents::MakeMatrixFilter(
270 FilterInput::Make(Rect()), Matrix::MakeScale({2, 2, 1}), {});
271
272 auto coverage = ComputeSaveLayerCoverage(
273 /*content_coverage=*/Rect::MakeLTRB(0, 0, 1000, 1000), //
274 /*effect_transform=*/{}, //
275 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), //
276 /*image_filter=*/image_filter //
277 );
278
279 ASSERT_TRUE(coverage.has_value());
280 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 50, 50));
281}

References impeller::ComputeSaveLayerCoverage(), impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::FilterContents::MakeMatrixFilter(), and impeller::Matrix::MakeScale().

◆ TEST() [581/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
DisjointCoverage   
)

Definition at line 94 of file save_layer_utils_unittests.cc.

94 {
95 // No intersection in coverage
96 auto coverage = ComputeSaveLayerCoverage(
97 /*content_coverage=*/Rect::MakeLTRB(200, 200, 210, 210), //
98 /*effect_transform=*/{}, //
99 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), //
100 /*image_filter=*/nullptr //
101 );
102
103 EXPECT_FALSE(coverage.has_value());
104}

References impeller::ComputeSaveLayerCoverage(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [582/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
DisjointCoverageTransformedByImageFilter   
)

Definition at line 106 of file save_layer_utils_unittests.cc.

106 {
107 // Coverage disjoint from parent coverage but transformed into parent space
108 // with image filter.
109 auto image_filter = FilterContents::MakeMatrixFilter(
110 FilterInput::Make(Rect()), Matrix::MakeTranslation({-200, -200, 0}), {});
111
112 auto coverage = ComputeSaveLayerCoverage(
113 /*content_coverage=*/Rect::MakeLTRB(200, 200, 210, 210), //
114 /*effect_transform=*/{}, //
115 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), //
116 /*image_filter=*/image_filter //
117 );
118
119 ASSERT_TRUE(coverage.has_value());
120 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(200, 200, 210, 210));
121}

References impeller::ComputeSaveLayerCoverage(), impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::FilterContents::MakeMatrixFilter(), and impeller::Matrix::MakeTranslation().

◆ TEST() [583/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
DisjointCoveragTransformedByCTM   
)

Definition at line 123 of file save_layer_utils_unittests.cc.

123 {
124 // Coverage disjoint from parent coverage.
125 Matrix ctm = Matrix::MakeTranslation({-200, -200, 0});
126 auto coverage = ComputeSaveLayerCoverage(
127 /*content_coverage=*/Rect::MakeLTRB(200, 200, 210, 210), //
128 /*effect_transform=*/ctm, //
129 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), //
130 /*image_filter=*/nullptr //
131 );
132
133 ASSERT_TRUE(coverage.has_value());
134 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 10, 10));
135}

References impeller::ComputeSaveLayerCoverage(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::Matrix::MakeTranslation().

◆ TEST() [584/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
DontRoundUpCoverageWhenNotCloseToCoverageLimitHeight   
)

Definition at line 311 of file save_layer_utils_unittests.cc.

311 {
312 // X varies, translation is performed on coverage.
313 auto coverage = ComputeSaveLayerCoverage(
314 /*content_coverage=*/Rect::MakeLTRB(0, 0, 90, 50), //
315 /*effect_transform=*/{}, //
316 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), //
317 /*image_filter=*/nullptr //
318 );
319
320 ASSERT_TRUE(coverage.has_value());
321 // Size that matches coverage limit
322 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 90, 50));
323}

References impeller::ComputeSaveLayerCoverage(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [585/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
DontRoundUpCoverageWhenNotCloseToCoverageLimitWidth   
)

Definition at line 297 of file save_layer_utils_unittests.cc.

297 {
298 // X varies, translation is performed on coverage.
299 auto coverage = ComputeSaveLayerCoverage(
300 /*content_coverage=*/Rect::MakeLTRB(0, 0, 50, 90), //
301 /*effect_transform=*/{}, //
302 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), //
303 /*image_filter=*/nullptr //
304 );
305
306 ASSERT_TRUE(coverage.has_value());
307 // Size that matches coverage limit
308 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 50, 90));
309}

References impeller::ComputeSaveLayerCoverage(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [586/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
DontRoundUpCoverageWhenNotCloseToCoverageLimitWidthHeight   
)

Definition at line 325 of file save_layer_utils_unittests.cc.

326 {
327 // X varies, translation is performed on coverage.
328 auto coverage = ComputeSaveLayerCoverage(
329 /*content_coverage=*/Rect::MakeLTRB(0, 0, 50, 50), //
330 /*effect_transform=*/{}, //
331 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), //
332 /*image_filter=*/nullptr //
333 );
334
335 ASSERT_TRUE(coverage.has_value());
336 // Size that matches coverage limit
337 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 50, 50));
338}

References impeller::ComputeSaveLayerCoverage(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [587/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
FloodInputCoverage   
)

Definition at line 177 of file save_layer_utils_unittests.cc.

177 {
178 auto coverage = ComputeSaveLayerCoverage(
179 /*content_coverage=*/Rect::MakeLTRB(0, 0, 0, 0), //
180 /*effect_transform=*/{}, //
181 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 2400, 1800), //
182 /*image_filter=*/nullptr, //
183 /*flood_output_coverage=*/false, //
184 /*flood_input_coverage=*/true //
185 );
186
187 ASSERT_TRUE(coverage.has_value());
188 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 2400, 1800));
189}

References impeller::ComputeSaveLayerCoverage(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [588/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
FloodInputCoverageWithImageFilter   
)

Definition at line 191 of file save_layer_utils_unittests.cc.

191 {
192 auto image_filter = FilterContents::MakeMatrixFilter(
193 FilterInput::Make(Rect()), Matrix::MakeScale({0.5, 0.5, 1}), {});
194
195 auto coverage = ComputeSaveLayerCoverage(
196 /*content_coverage=*/Rect::MakeLTRB(0, 0, 0, 0), //
197 /*effect_transform=*/{}, //
198 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 2400, 1800), //
199 /*image_filter=*/image_filter, //
200 /*flood_output_coverage=*/false, //
201 /*flood_input_coverage=*/true //
202 );
203
204 ASSERT_TRUE(coverage.has_value());
205 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 4800, 3600));
206}

References impeller::ComputeSaveLayerCoverage(), impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::FilterContents::MakeMatrixFilter(), and impeller::Matrix::MakeScale().

◆ TEST() [589/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
FloodInputCoverageWithImageFilterWithNoCoverageProducesNoCoverage   
)

Definition at line 208 of file save_layer_utils_unittests.cc.

209 {
210 // Even if we flood the input coverage due to a bdf, we can still cull out the
211 // layer if the image filter results in no coverage.
212 auto image_filter = FilterContents::MakeMatrixFilter(
213 FilterInput::Make(Rect()), Matrix::MakeScale({1, 1, 0}), {});
214
215 auto coverage = ComputeSaveLayerCoverage(
216 /*content_coverage=*/Rect::MakeLTRB(0, 0, 0, 0), //
217 /*effect_transform=*/{}, //
218 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 2400, 1800), //
219 /*image_filter=*/image_filter, //
220 /*flood_output_coverage=*/false, //
221 /*flood_input_coverage=*/true //
222 );
223
224 ASSERT_FALSE(coverage.has_value());
225}

References impeller::ComputeSaveLayerCoverage(), impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::FilterContents::MakeMatrixFilter(), and impeller::Matrix::MakeScale().

◆ TEST() [590/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
ImageFilterEmptyCoverage   
)

Definition at line 148 of file save_layer_utils_unittests.cc.

148 {
149 // Empty coverage with Image Filter
150 auto image_filter = FilterContents::MakeMatrixFilter(
151 FilterInput::Make(Rect()), Matrix::MakeTranslation({-200, -200, 0}), {});
152
153 auto coverage = ComputeSaveLayerCoverage(
154 /*content_coverage=*/Rect::MakeLTRB(0, 0, 0, 0), //
155 /*effect_transform=*/{}, //
156 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 2400, 1800), //
157 /*image_filter=*/image_filter //
158 );
159
160 ASSERT_FALSE(coverage.has_value());
161}

References impeller::ComputeSaveLayerCoverage(), impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::FilterContents::MakeMatrixFilter(), and impeller::Matrix::MakeTranslation().

◆ TEST() [591/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
ImageFiterComputedCoverage   
)

Definition at line 44 of file save_layer_utils_unittests.cc.

44 {
45 // Image Filter, computed coverage
46 auto image_filter = FilterContents::MakeMatrixFilter(
47 FilterInput::Make(Rect()), Matrix::MakeScale({2, 2, 1}), {});
48
49 auto coverage = ComputeSaveLayerCoverage(
50 /*content_coverage=*/Rect::MakeLTRB(0, 0, 10, 10), //
51 /*effect_transform=*/{}, //
52 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 2400, 1800), //
53 /*image_filter=*/image_filter //
54 );
55
56 ASSERT_TRUE(coverage.has_value());
57 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 10, 10));
58}

References impeller::ComputeSaveLayerCoverage(), impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::FilterContents::MakeMatrixFilter(), and impeller::Matrix::MakeScale().

◆ TEST() [592/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
ImageFiterLargeScaleComputedCoverageLargerThanBoundsLimit   
)

Definition at line 77 of file save_layer_utils_unittests.cc.

78 {
79 // Image Filter scaling small, computed coverage is larger than bounds limit.
80 auto image_filter = FilterContents::MakeMatrixFilter(
81 FilterInput::Make(Rect()), Matrix::MakeScale({0.5, 0.5, 1}), {});
82
83 auto coverage = ComputeSaveLayerCoverage(
84 /*content_coverage=*/Rect::MakeLTRB(0, 0, 10, 10), //
85 /*effect_transform=*/{}, //
86 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 5, 5), //
87 /*image_filter=*/image_filter //
88 );
89
90 ASSERT_TRUE(coverage.has_value());
91 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 10, 10));
92}

References impeller::ComputeSaveLayerCoverage(), impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::FilterContents::MakeMatrixFilter(), and impeller::Matrix::MakeScale().

◆ TEST() [593/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
ImageFiterSmallScaleComputedCoverageLargerThanBoundsLimit   
)

Definition at line 60 of file save_layer_utils_unittests.cc.

61 {
62 // Image Filter scaling large, computed coverage is larger than bounds limit.
63 auto image_filter = FilterContents::MakeMatrixFilter(
64 FilterInput::Make(Rect()), Matrix::MakeScale({2, 2, 1}), {});
65
66 auto coverage = ComputeSaveLayerCoverage(
67 /*content_coverage=*/Rect::MakeLTRB(0, 0, 10, 10), //
68 /*effect_transform=*/{}, //
69 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 5, 5), //
70 /*image_filter=*/image_filter //
71 );
72
73 ASSERT_TRUE(coverage.has_value());
74 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 2.5, 2.5));
75}

References impeller::ComputeSaveLayerCoverage(), impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::FilterContents::MakeMatrixFilter(), and impeller::Matrix::MakeScale().

◆ TEST() [594/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
RoundUpCoverageWhenCloseToCoverageLimit   
)

Definition at line 283 of file save_layer_utils_unittests.cc.

283 {
284 // X varies, translation is performed on coverage.
285 auto coverage = ComputeSaveLayerCoverage(
286 /*content_coverage=*/Rect::MakeLTRB(0, 0, 90, 90), //
287 /*effect_transform=*/{}, //
288 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), //
289 /*image_filter=*/nullptr //
290 );
291
292 ASSERT_TRUE(coverage.has_value());
293 // Size that matches coverage limit
294 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 100, 100));
295}

References impeller::ComputeSaveLayerCoverage(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [595/689]

impeller::testing::TEST ( SaveLayerUtilsTest  ,
SimplePaintComputedCoverage   
)

Definition at line 17 of file save_layer_utils_unittests.cc.

17 {
18 // Basic Case, simple paint, computed coverage
19 auto coverage = ComputeSaveLayerCoverage(
20 /*content_coverage=*/Rect::MakeLTRB(0, 0, 10, 10), //
21 /*effect_transform=*/{}, //
22 /*coverage_limit=*/Rect::MakeLTRB(0, 0, 2400, 1800), //
23 /*image_filter=*/nullptr //
24 );
25 ASSERT_TRUE(coverage.has_value());
26 EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 10, 10));
27}

References impeller::ComputeSaveLayerCoverage(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST() [596/689]

impeller::testing::TEST ( ShaderArchiveTest  ,
CanReadAndWriteBlobs   
)

Definition at line 31 of file shader_archive_unittests.cc.

31 {
33 ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kVertex, "Hello",
34 CreateMappingFromString("World")));
35 ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kFragment, "Foo",
37 ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kVertex, "Baz",
39 ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kVertex, "Ping",
41 ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kFragment, "Pang",
42 CreateMappingFromString("World")));
43
44 auto mapping = writer.CreateMapping();
45 ASSERT_NE(mapping, nullptr);
46
47 auto library = ShaderArchive::Create(mapping);
48 ASSERT_TRUE(library.ok());
49 ASSERT_EQ(library->GetShaderCount(), 5u);
50
51 // Wrong type.
52 ASSERT_EQ(library->GetMapping(ArchiveShaderType::kFragment, "Hello"),
53 nullptr);
54
55 auto hello_vtx = library->GetMapping(ArchiveShaderType::kVertex, "Hello");
56 ASSERT_NE(hello_vtx, nullptr);
57 ASSERT_EQ(CreateStringFromMapping(*hello_vtx), "World");
58}
bool AddShader(ArchiveShaderType type, std::string name, std::shared_ptr< fml::Mapping > mapping)
std::shared_ptr< fml::Mapping > CreateMapping() const
const std::string CreateStringFromMapping(const fml::Mapping &mapping)
static std::shared_ptr< fml::Mapping > CreateMappingFromString(std::string p_string)

References impeller::ShaderArchiveWriter::AddShader(), impeller::ShaderArchive::Create(), impeller::ShaderArchiveWriter::CreateMapping(), CreateMappingFromString(), CreateStringFromMapping(), impeller::kFragment, and impeller::kVertex.

◆ TEST() [597/689]

impeller::testing::TEST ( ShaderArchiveTest  ,
RejectsCorruptBufferWithValidIdentifier   
)

Definition at line 81 of file shader_archive_unittests.cc.

81 {
82 // Construct a buffer with a valid "SHAR" file identifier at bytes 4-7
83 // but a root table offset that points beyond the buffer. This passes
84 // the identifier check but fails FlatBuffer structural verification.
85 auto data = std::make_shared<std::vector<uint8_t>>(32, 0);
86 (*data)[4] = 'S';
87 (*data)[5] = 'H';
88 (*data)[6] = 'A';
89 (*data)[7] = 'R';
90 // Root offset (little-endian uint32 at offset 0) pointing out of bounds.
91 (*data)[0] = 0xFF;
92 (*data)[1] = 0xFF;
93
94 auto mapping = std::make_shared<fml::NonOwnedMapping>(
95 data->data(), data->size(), [data](auto, auto) {});
96 auto archive = ShaderArchive::Create(mapping);
97 ASSERT_FALSE(archive.ok());
98 EXPECT_EQ(archive.status().code(), absl::StatusCode::kInvalidArgument);
99}

References impeller::ShaderArchive::Create(), and flutter::data.

◆ TEST() [598/689]

impeller::testing::TEST ( ShaderArchiveTest  ,
ReturnsErrorOnInvalidVersion   
)

Definition at line 60 of file shader_archive_unittests.cc.

60 {
61 fb::ShaderArchiveT shader_archive;
62 shader_archive.format_version = -1;
63
64 auto builder = std::make_shared<flatbuffers::FlatBufferBuilder>();
65 builder->Finish(fb::ShaderArchive::Pack(*builder.get(), &shader_archive),
66 fb::ShaderArchiveIdentifier());
67 auto mapping = std::make_shared<fml::NonOwnedMapping>(
68 builder->GetBufferPointer(), builder->GetSize(),
69 [builder](auto, auto) {});
70
71 auto library = ShaderArchive::Create(mapping);
72 ASSERT_FALSE(library.ok());
73 ASSERT_EQ(library.status().code(), absl::StatusCode::kInvalidArgument);
74 std::stringstream stream;
75 stream << "Unsupported shader archive format version. Expected: "
76 << static_cast<uint32_t>(fb::ShaderArchiveFormatVersion::kVersion)
77 << ", Got: 4294967295";
78 ASSERT_EQ(library.status().message(), stream.str());
79}

References impeller::ShaderArchive::Create().

◆ TEST() [599/689]

impeller::testing::TEST ( ShaderKeyTest  ,
MakeUserScopedNameContainsColonSeparator   
)

Definition at line 523 of file runtime_stage_unittests.cc.

523 {
524 // The colon separator is what makes user-scoped names unspoofable from
525 // engine-internal entrypoints, since impellerc-generated entrypoints are
526 // valid identifiers and cannot contain ':'.
527 std::string scoped = ShaderKey::MakeUserScopedName(
528 ShaderKey::kScopeRuntimeEffect, "asset", "entry");
529 EXPECT_NE(scoped.find(':'), std::string::npos);
530}

References impeller::ShaderKey::kScopeRuntimeEffect, and impeller::ShaderKey::MakeUserScopedName().

◆ TEST() [600/689]

impeller::testing::TEST ( ShaderKeyTest  ,
MakeUserScopedNameDifferentLibraryIdsDoNotCollide   
)

Definition at line 532 of file runtime_stage_unittests.cc.

532 {
533 // Two user shaders that share an entrypoint name but come from different
534 // logical sources must produce different registry keys, so they cannot
535 // overwrite each other in the shared shader library.
536 std::string a = ShaderKey::MakeUserScopedName(
537 ShaderKey::kScopeFlutterGPU, "packages/pkg_a/bundle", "main");
538 std::string b = ShaderKey::MakeUserScopedName(
539 ShaderKey::kScopeFlutterGPU, "packages/pkg_b/bundle", "main");
540 EXPECT_NE(a, b);
541}

References impeller::ShaderKey::kScopeFlutterGPU, and impeller::ShaderKey::MakeUserScopedName().

◆ TEST() [601/689]

impeller::testing::TEST ( ShaderKeyTest  ,
MakeUserScopedNameDifferentScopesDoNotCollide   
)

Definition at line 543 of file runtime_stage_unittests.cc.

543 {
544 // A FragmentProgram and a Flutter GPU shader can independently share an
545 // asset path and an entrypoint and must still produce different keys.
546 std::string runtime_effect = ShaderKey::MakeUserScopedName(
547 ShaderKey::kScopeRuntimeEffect, "asset", "main");
548 std::string flutter_gpu = ShaderKey::MakeUserScopedName(
549 ShaderKey::kScopeFlutterGPU, "asset", "main");
550 EXPECT_NE(runtime_effect, flutter_gpu);
551}

References impeller::ShaderKey::kScopeFlutterGPU, impeller::ShaderKey::kScopeRuntimeEffect, and impeller::ShaderKey::MakeUserScopedName().

◆ TEST() [602/689]

impeller::testing::TEST ( ShaderKeyTest  ,
MakeUserScopedNameHandlesLongInputs   
)

Definition at line 553 of file runtime_stage_unittests.cc.

553 {
554 // The scoped name is used solely as a `std::string` key in the per-process
555 // shader library registry; there is no fixed length limit. Confirm that
556 // long inputs (e.g. deeply-nested package asset paths) round-trip through
557 // the builder without truncation.
558 const std::string long_library_id(4096, 'a');
559 const std::string long_entrypoint(2048, 'b');
560 std::string scoped = ShaderKey::MakeUserScopedName(
561 ShaderKey::kScopeFlutterGPU, long_library_id, long_entrypoint);
562 EXPECT_EQ(scoped.size(), ShaderKey::kScopeFlutterGPU.size() + 1 +
563 long_library_id.size() + 1 +
564 long_entrypoint.size());
565 EXPECT_EQ(scoped.substr(0, 3), "fg:");
566 EXPECT_EQ(scoped.substr(3, long_library_id.size()), long_library_id);
567 EXPECT_EQ(scoped.substr(3 + long_library_id.size(), 1), ":");
568 EXPECT_EQ(scoped.substr(3 + long_library_id.size() + 1), long_entrypoint);
569}

References impeller::ShaderKey::kScopeFlutterGPU, and impeller::ShaderKey::MakeUserScopedName().

◆ TEST() [603/689]

impeller::testing::TEST ( ShaderKeyTest  ,
MakeUserScopedNameProducesScopedString   
)

Definition at line 511 of file runtime_stage_unittests.cc.

511 {
512 EXPECT_EQ(ShaderKey::MakeUserScopedName(ShaderKey::kScopeRuntimeEffect,
513 "assets/foo.frag", "main"),
514 "re:assets/foo.frag:main");
515 EXPECT_EQ(
516 ShaderKey::MakeUserScopedName(
517 ShaderKey::kScopeFlutterGPU,
518 "packages/pkg_a/assets/shaders.shaderbundle",
519 "solid_fill_fragment_main"),
520 "fg:packages/pkg_a/assets/shaders.shaderbundle:solid_fill_fragment_main");
521}

References impeller::ShaderKey::kScopeFlutterGPU, impeller::ShaderKey::kScopeRuntimeEffect, and impeller::ShaderKey::MakeUserScopedName().

◆ TEST() [604/689]

impeller::testing::TEST ( ShaderTypesTest  ,
VertexAttributeFormatFloat32   
)

Definition at line 31 of file shader_types_unittests.cc.

31 {
32 EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 1u).GetVertexAttributeFormat(),
33 VertexAttributeFormat::kFloat32);
34 EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 2u).GetVertexAttributeFormat(),
35 VertexAttributeFormat::kFloat32x2);
36 EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 3u).GetVertexAttributeFormat(),
37 VertexAttributeFormat::kFloat32x3);
38 EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 4u).GetVertexAttributeFormat(),
39 VertexAttributeFormat::kFloat32x4);
40}

References impeller::kFloat, impeller::kFloat32, impeller::kFloat32x2, impeller::kFloat32x3, and impeller::kFloat32x4.

◆ TEST() [605/689]

impeller::testing::TEST ( ShaderTypesTest  ,
VertexAttributeFormatHalfFloat   
)

Definition at line 42 of file shader_types_unittests.cc.

42 {
43 EXPECT_EQ(
44 MakeSlot(ShaderType::kHalfFloat, 16u, 1u).GetVertexAttributeFormat(),
45 VertexAttributeFormat::kFloat16);
46 EXPECT_EQ(
47 MakeSlot(ShaderType::kHalfFloat, 16u, 4u).GetVertexAttributeFormat(),
48 VertexAttributeFormat::kFloat16x4);
49}

References impeller::kFloat16, impeller::kFloat16x4, and impeller::kHalfFloat.

◆ TEST() [606/689]

impeller::testing::TEST ( ShaderTypesTest  ,
VertexAttributeFormatIntegers   
)

Definition at line 51 of file shader_types_unittests.cc.

51 {
52 EXPECT_EQ(
53 MakeSlot(ShaderType::kSignedByte, 8u, 1u).GetVertexAttributeFormat(),
54 VertexAttributeFormat::kSInt8);
55 EXPECT_EQ(
56 MakeSlot(ShaderType::kUnsignedByte, 8u, 4u).GetVertexAttributeFormat(),
57 VertexAttributeFormat::kUInt8x4);
58 EXPECT_EQ(
59 MakeSlot(ShaderType::kSignedShort, 16u, 2u).GetVertexAttributeFormat(),
60 VertexAttributeFormat::kSInt16x2);
61 EXPECT_EQ(
62 MakeSlot(ShaderType::kUnsignedShort, 16u, 3u).GetVertexAttributeFormat(),
63 VertexAttributeFormat::kUInt16x3);
64 EXPECT_EQ(
65 MakeSlot(ShaderType::kSignedInt, 32u, 1u).GetVertexAttributeFormat(),
66 VertexAttributeFormat::kSInt32);
67 EXPECT_EQ(
68 MakeSlot(ShaderType::kUnsignedInt, 32u, 4u).GetVertexAttributeFormat(),
69 VertexAttributeFormat::kUInt32x4);
70}

References impeller::kSignedByte, impeller::kSignedInt, impeller::kSignedShort, impeller::kSInt16x2, impeller::kSInt32, impeller::kSInt8, impeller::kUInt16x3, impeller::kUInt32x4, impeller::kUInt8x4, impeller::kUnsignedByte, impeller::kUnsignedInt, and impeller::kUnsignedShort.

◆ TEST() [607/689]

impeller::testing::TEST ( ShaderTypesTest  ,
VertexAttributeFormatRejectsBadBitWidth   
)

Definition at line 86 of file shader_types_unittests.cc.

86 {
87 EXPECT_EQ(MakeSlot(ShaderType::kFloat, 16u, 1u).GetVertexAttributeFormat(),
88 VertexAttributeFormat::kInvalid);
89 EXPECT_EQ(
90 MakeSlot(ShaderType::kSignedInt, 16u, 1u).GetVertexAttributeFormat(),
91 VertexAttributeFormat::kInvalid);
92}

References impeller::kFloat, impeller::kInvalid, and impeller::kSignedInt.

◆ TEST() [608/689]

impeller::testing::TEST ( ShaderTypesTest  ,
VertexAttributeFormatRejectsBadComponentCount   
)

Definition at line 79 of file shader_types_unittests.cc.

79 {
80 EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 0u).GetVertexAttributeFormat(),
81 VertexAttributeFormat::kInvalid);
82 EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 5u).GetVertexAttributeFormat(),
83 VertexAttributeFormat::kInvalid);
84}

References impeller::kFloat, and impeller::kInvalid.

◆ TEST() [609/689]

impeller::testing::TEST ( ShaderTypesTest  ,
VertexAttributeFormatRejectsMatrices   
)

Definition at line 72 of file shader_types_unittests.cc.

72 {
73 // Columns greater than one is a matrix input, which is unsupported.
74 EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 4u, /*columns=*/4u)
75 .GetVertexAttributeFormat(),
76 VertexAttributeFormat::kInvalid);
77}

References impeller::kFloat, and impeller::kInvalid.

◆ TEST() [610/689]

impeller::testing::TEST ( ShaderTypesTest  ,
VertexAttributeFormatRejectsUnsupportedScalarKinds   
)

Definition at line 94 of file shader_types_unittests.cc.

94 {
95 EXPECT_EQ(MakeSlot(ShaderType::kBoolean, 8u, 1u).GetVertexAttributeFormat(),
96 VertexAttributeFormat::kInvalid);
97 EXPECT_EQ(MakeSlot(ShaderType::kDouble, 64u, 1u).GetVertexAttributeFormat(),
98 VertexAttributeFormat::kInvalid);
99 EXPECT_EQ(
100 MakeSlot(ShaderType::kSignedInt64, 64u, 1u).GetVertexAttributeFormat(),
101 VertexAttributeFormat::kInvalid);
102}

References impeller::kBoolean, impeller::kDouble, impeller::kInvalid, and impeller::kSignedInt64.

◆ TEST() [611/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
ClockwiseOctagonCollapsedUmbraPolygonTest   
)

Definition at line 972 of file shadow_path_geometry_unittests.cc.

972 {
973 const Matrix matrix = Matrix::MakeScale({2, 2, 1});
974 const Scalar height = 100.0f;
975
976 DlPathBuilder path_builder;
977 path_builder.MoveTo(DlPoint(100, 125));
978 path_builder.LineTo(DlPoint(125, 100));
979 path_builder.LineTo(DlPoint(275, 100));
980 path_builder.LineTo(DlPoint(300, 125));
981 path_builder.LineTo(DlPoint(300, 275));
982 path_builder.LineTo(DlPoint(275, 300));
983 path_builder.LineTo(DlPoint(125, 300));
984 path_builder.LineTo(DlPoint(100, 275));
985 path_builder.Close();
986 DlPath path = path_builder.TakePath();
987
988 Tessellator tessellator;
989 std::shared_ptr<ShadowVertices> shadow_vertices =
990 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
991 matrix);
992
993 ASSERT_NE(shadow_vertices, nullptr);
994 EXPECT_FALSE(shadow_vertices->IsEmpty());
995 EXPECT_EQ(shadow_vertices->GetVertexCount(), 87u);
996 EXPECT_EQ(shadow_vertices->GetIndexCount(), 267u);
997 EXPECT_EQ(shadow_vertices->GetVertices().size(), 87u);
998 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 87u);
999 EXPECT_EQ(shadow_vertices->GetIndices().size(), 267u);
1000 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
1001 // We repeat the first and last vertex that is on the outer umbra.
1002 // There are a couple additional duplicate vertices in this case.
1003 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 3u);
1004 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
1005 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
1006}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), impeller::Matrix::MakeScale(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [612/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
ClockwiseRectExtraColinearPointsTest   
)

Definition at line 417 of file shadow_path_geometry_unittests.cc.

417 {
418 // This path includes a colinear point to each edge of the rectangle
419 // which should be trimmed out and ignored when generating the mesh
420 // resulting in the same number of vertices and triangles as the mesh
421 // above.
422 DlPathBuilder path_builder;
423 path_builder.MoveTo(DlPoint(0, 0));
424 path_builder.LineTo(DlPoint(50, 0));
425 path_builder.LineTo(DlPoint(100, 0));
426 path_builder.LineTo(DlPoint(100, 40));
427 path_builder.LineTo(DlPoint(100, 80));
428 path_builder.LineTo(DlPoint(50, 80));
429 path_builder.LineTo(DlPoint(0, 80));
430 path_builder.LineTo(DlPoint(0, 40));
431 path_builder.Close();
432 const DlPath path = path_builder.TakePath();
433 const Matrix matrix;
434 const Scalar height = 10.0f;
435
436 Tessellator tessellator;
437 std::shared_ptr<ShadowVertices> shadow_vertices =
438 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
439 matrix);
440
441 ASSERT_NE(shadow_vertices, nullptr);
442 EXPECT_FALSE(shadow_vertices->IsEmpty());
443 EXPECT_EQ(shadow_vertices->GetVertexCount(), 34u);
444 EXPECT_EQ(shadow_vertices->GetIndexCount(), 108u);
445 EXPECT_EQ(shadow_vertices->GetVertices().size(), 34u);
446 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 34u);
447 EXPECT_EQ(shadow_vertices->GetIndices().size(), 108u);
448 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
449 // We repeat the first and last vertex that is on the outer umbra.
450 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
451 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
452 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
453
454#if SHADOW_UNITTEST_SHOW_VERTICES
455 ShowVertices("Impeller Vertices", shadow_vertices);
456#endif
457}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [613/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
ClockwiseRectNearlyColinearPointsTest   
)

Definition at line 677 of file shadow_path_geometry_unittests.cc.

677 {
678 // This path includes a bunch of colinear points and one point that
679 // is barely non-colinear but still convex. It should add exactly
680 // one extra set of vertices to the mesh (3 points and 3 triangles)
681 // compared to the regular rects.
682 DlPathBuilder path_builder;
683 path_builder.MoveTo(DlPoint(0, 0));
684 path_builder.LineTo(DlPoint(50, -0.065));
685 path_builder.LineTo(DlPoint(100, 0));
686 path_builder.LineTo(DlPoint(100, 40));
687 path_builder.LineTo(DlPoint(100, 80));
688 path_builder.LineTo(DlPoint(50, 80));
689 path_builder.LineTo(DlPoint(0, 80));
690 path_builder.LineTo(DlPoint(0, 40));
691 path_builder.Close();
692 const DlPath path = path_builder.TakePath();
693 const Matrix matrix;
694 const Scalar height = 10.0f;
695
696 Tessellator tessellator;
697 std::shared_ptr<ShadowVertices> shadow_vertices =
698 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
699 matrix);
700
701 ASSERT_NE(shadow_vertices, nullptr);
702 EXPECT_FALSE(shadow_vertices->IsEmpty());
703 EXPECT_EQ(shadow_vertices->GetVertexCount(), 37u);
704 EXPECT_EQ(shadow_vertices->GetIndexCount(), 120u);
705 EXPECT_EQ(shadow_vertices->GetVertices().size(), 37u);
706 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 37u);
707 EXPECT_EQ(shadow_vertices->GetIndices().size(), 120u);
708 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
709 // We repeat the first and last vertex that is on the outer umbra.
710 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
711 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
712 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
713
714#if SHADOW_UNITTEST_SHOW_VERTICES
715 ShowVertices("Impeller Vertices", shadow_vertices);
716#endif
717}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [614/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
ClockwiseRectTest   
)

Definition at line 349 of file shadow_path_geometry_unittests.cc.

349 {
350 DlPathBuilder path_builder;
351 path_builder.MoveTo(DlPoint(0, 0));
352 path_builder.LineTo(DlPoint(100, 0));
353 path_builder.LineTo(DlPoint(100, 80));
354 path_builder.LineTo(DlPoint(0, 80));
355 path_builder.Close();
356 const DlPath path = path_builder.TakePath();
357 const Matrix matrix;
358 const Scalar height = 10.0f;
359
360 Tessellator tessellator;
361 std::shared_ptr<ShadowVertices> shadow_vertices =
362 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
363 matrix);
364
365 ASSERT_NE(shadow_vertices, nullptr);
366 EXPECT_FALSE(shadow_vertices->IsEmpty());
367 EXPECT_EQ(shadow_vertices->GetVertexCount(), 34u);
368 EXPECT_EQ(shadow_vertices->GetIndexCount(), 108u);
369 EXPECT_EQ(shadow_vertices->GetVertices().size(), 34u);
370 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 34u);
371 EXPECT_EQ(shadow_vertices->GetIndices().size(), 108u);
372 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
373 // We repeat the first and last vertex that is on the outer umbra.
374 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
375 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
376 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
377
378#if SHADOW_UNITTEST_SHOW_VERTICES
379 ShowVertices("Impeller Vertices", shadow_vertices);
380#endif
381}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [615/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
ClockwiseRectTrickyColinearPointsTest   
)

Definition at line 501 of file shadow_path_geometry_unittests.cc.

501 {
502 // This path includes a colinear point added to each edge of the rectangle
503 // which seems to violate convexity, but is eliminated as not contributing
504 // to the path. We should be able to process the path anyway.
505 DlPathBuilder path_builder;
506 path_builder.MoveTo(DlPoint(0, 0));
507 path_builder.LineTo(DlPoint(-10, 0));
508 path_builder.LineTo(DlPoint(100, 0));
509 path_builder.LineTo(DlPoint(100, -10));
510 path_builder.LineTo(DlPoint(100, 80));
511 path_builder.LineTo(DlPoint(110, 80));
512 path_builder.LineTo(DlPoint(0, 80));
513 path_builder.LineTo(DlPoint(0, 90));
514 path_builder.Close();
515 const DlPath path = path_builder.TakePath();
516 const Matrix matrix;
517 const Scalar height = 10.0f;
518
519 Tessellator tessellator;
520 std::shared_ptr<ShadowVertices> shadow_vertices =
521 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
522 matrix);
523
524 ASSERT_NE(shadow_vertices, nullptr);
525 EXPECT_FALSE(shadow_vertices->IsEmpty());
526 EXPECT_EQ(shadow_vertices->GetVertexCount(), 34u);
527 EXPECT_EQ(shadow_vertices->GetIndexCount(), 108u);
528 EXPECT_EQ(shadow_vertices->GetVertices().size(), 34u);
529 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 34u);
530 EXPECT_EQ(shadow_vertices->GetIndices().size(), 108u);
531 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
532 // We repeat the first and last vertex that is on the outer umbra.
533 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
534 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
535 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
536
537#if SHADOW_UNITTEST_SHOW_VERTICES
538 ShowVertices("Impeller Vertices", shadow_vertices);
539#endif
540}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [616/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
ClockwiseRectTrickyDupColinearPointsTest   
)

Definition at line 583 of file shadow_path_geometry_unittests.cc.

583 {
584 // This path includes a colinear point added to each edge of the rectangle
585 // which seems to violate convexity, but is eliminated as not contributing
586 // to the path. We should be able to process the path anyway.
587 // It also includes multiple collinear points on the first and last points
588 // that end up back where we started to make sure that in that case we
589 // eliminate all of the collinear points and the duplicate, rather than
590 // just the intermediate collinear points.
591 DlPathBuilder path_builder;
592 path_builder.MoveTo(DlPoint(0, 0));
593 path_builder.LineTo(DlPoint(-10, 0));
594 path_builder.LineTo(DlPoint(0, 0));
595 path_builder.LineTo(DlPoint(100, 0));
596 path_builder.LineTo(DlPoint(100, -10));
597 path_builder.LineTo(DlPoint(100, 80));
598 path_builder.LineTo(DlPoint(110, 80));
599 path_builder.LineTo(DlPoint(0, 80));
600 path_builder.LineTo(DlPoint(0, 90));
601 path_builder.LineTo(DlPoint(0, 80));
602 path_builder.Close();
603 const DlPath path = path_builder.TakePath();
604 const Matrix matrix;
605 const Scalar height = 10.0f;
606
607 Tessellator tessellator;
608 std::shared_ptr<ShadowVertices> shadow_vertices =
609 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
610 matrix);
611
612 ASSERT_NE(shadow_vertices, nullptr);
613 EXPECT_FALSE(shadow_vertices->IsEmpty());
614 EXPECT_EQ(shadow_vertices->GetVertexCount(), 34u);
615 EXPECT_EQ(shadow_vertices->GetIndexCount(), 108u);
616 EXPECT_EQ(shadow_vertices->GetVertices().size(), 34u);
617 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 34u);
618 EXPECT_EQ(shadow_vertices->GetIndices().size(), 108u);
619 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
620 // We repeat the first and last vertex that is on the outer umbra.
621 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
622 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
623 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
624
625#if SHADOW_UNITTEST_SHOW_VERTICES
626 ShowVertices("Impeller Vertices", shadow_vertices);
627#endif
628}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [617/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
ClockwiseTriangleTest   
)

Definition at line 281 of file shadow_path_geometry_unittests.cc.

281 {
282 DlPathBuilder path_builder;
283 path_builder.MoveTo(DlPoint(100, 0));
284 path_builder.LineTo(DlPoint(200, 110));
285 path_builder.LineTo(DlPoint(0, 110));
286 path_builder.Close();
287 const DlPath path = path_builder.TakePath();
288 const Matrix matrix;
289 const Scalar height = 10.0f;
290
291 Tessellator tessellator;
292 std::shared_ptr<ShadowVertices> shadow_vertices =
293 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
294 matrix);
295
296 ASSERT_NE(shadow_vertices, nullptr);
297 EXPECT_FALSE(shadow_vertices->IsEmpty());
298 EXPECT_EQ(shadow_vertices->GetVertexCount(), 33u);
299 EXPECT_EQ(shadow_vertices->GetIndexCount(), 102u);
300 EXPECT_EQ(shadow_vertices->GetVertices().size(), 33u);
301 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 33u);
302 EXPECT_EQ(shadow_vertices->GetIndices().size(), 102u);
303 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
304 // We repeat the first and last vertex that is on the outer umbra.
305 // There is another duplicate vertex from somewhere else not yet realized.
306 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 2u);
307 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
308 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
309
310#if SHADOW_UNITTEST_SHOW_VERTICES
311 ShowVertices("Impeller Vertices", shadow_vertices);
312#endif
313}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [618/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
CounterClockwiseOctagonCollapsedUmbraPolygonTest   
)

Definition at line 1008 of file shadow_path_geometry_unittests.cc.

1008 {
1009 const Matrix matrix = Matrix::MakeScale({2, 2, 1});
1010 const Scalar height = 100.0f;
1011
1012 DlPathBuilder path_builder;
1013 path_builder.MoveTo(DlPoint(100, 125));
1014 path_builder.LineTo(DlPoint(100, 275));
1015 path_builder.LineTo(DlPoint(125, 300));
1016 path_builder.LineTo(DlPoint(275, 300));
1017 path_builder.LineTo(DlPoint(300, 275));
1018 path_builder.LineTo(DlPoint(300, 125));
1019 path_builder.LineTo(DlPoint(275, 100));
1020 path_builder.LineTo(DlPoint(125, 100));
1021 path_builder.Close();
1022 DlPath path = path_builder.TakePath();
1023
1024 Tessellator tessellator;
1025 std::shared_ptr<ShadowVertices> shadow_vertices =
1026 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
1027 matrix);
1028
1029 ASSERT_NE(shadow_vertices, nullptr);
1030 EXPECT_FALSE(shadow_vertices->IsEmpty());
1031 EXPECT_EQ(shadow_vertices->GetVertexCount(), 88u);
1032 EXPECT_EQ(shadow_vertices->GetIndexCount(), 267u);
1033 EXPECT_EQ(shadow_vertices->GetVertices().size(), 88u);
1034 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 88u);
1035 EXPECT_EQ(shadow_vertices->GetIndices().size(), 267u);
1036 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
1037 // We repeat the first and last vertex that is on the outer umbra.
1038 // There are a couple additional duplicate vertices in this case.
1039 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 3u);
1040 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
1041 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
1042}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), impeller::Matrix::MakeScale(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [619/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
CounterClockwiseRectExtraColinearPointsTest   
)

Definition at line 459 of file shadow_path_geometry_unittests.cc.

459 {
460 // This path includes a colinear point to each edge of the rectangle
461 // which should be trimmed out and ignored when generating the mesh
462 // resulting in the same number of vertices and triangles as the mesh
463 // above.
464 DlPathBuilder path_builder;
465 path_builder.MoveTo(DlPoint(0, 0));
466 path_builder.LineTo(DlPoint(0, 40));
467 path_builder.LineTo(DlPoint(0, 80));
468 path_builder.LineTo(DlPoint(50, 80));
469 path_builder.LineTo(DlPoint(100, 80));
470 path_builder.LineTo(DlPoint(100, 40));
471 path_builder.LineTo(DlPoint(100, 0));
472 path_builder.LineTo(DlPoint(50, 0));
473 path_builder.Close();
474 DlPath path = path_builder.TakePath();
475 Matrix matrix;
476 const Scalar height = 10.0f;
477
478 Tessellator tessellator;
479 std::shared_ptr<ShadowVertices> shadow_vertices =
480 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
481 matrix);
482
483 ASSERT_NE(shadow_vertices, nullptr);
484 EXPECT_FALSE(shadow_vertices->IsEmpty());
485 EXPECT_EQ(shadow_vertices->GetVertexCount(), 34u);
486 EXPECT_EQ(shadow_vertices->GetIndexCount(), 108u);
487 EXPECT_EQ(shadow_vertices->GetVertices().size(), 34u);
488 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 34u);
489 EXPECT_EQ(shadow_vertices->GetIndices().size(), 108u);
490 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
491 // We repeat the first and last vertex that is on the outer umbra.
492 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
493 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
494 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
495
496#if SHADOW_UNITTEST_SHOW_VERTICES
497 ShowVertices("Impeller Vertices", shadow_vertices);
498#endif
499}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [620/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
CounterClockwiseRectNearlyColinearPointsTest   
)

Definition at line 719 of file shadow_path_geometry_unittests.cc.

719 {
720 // This path includes a bunch of colinear points and one point that
721 // is barely non-colinear but still convex. It should add exactly
722 // one extra set of vertices to the mesh (3 points and 3 triangles)
723 // compared to the regular rects.
724 DlPathBuilder path_builder;
725 path_builder.MoveTo(DlPoint(0, 0));
726 path_builder.LineTo(DlPoint(-0.065, 40));
727 path_builder.LineTo(DlPoint(0, 80));
728 path_builder.LineTo(DlPoint(50, 80));
729 path_builder.LineTo(DlPoint(100, 80));
730 path_builder.LineTo(DlPoint(100, 40));
731 path_builder.LineTo(DlPoint(100, 0));
732 path_builder.LineTo(DlPoint(50, 0));
733 path_builder.Close();
734 DlPath path = path_builder.TakePath();
735 Matrix matrix;
736 const Scalar height = 10.0f;
737
738 Tessellator tessellator;
739 std::shared_ptr<ShadowVertices> shadow_vertices =
740 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
741 matrix);
742
743 ASSERT_NE(shadow_vertices, nullptr);
744 EXPECT_FALSE(shadow_vertices->IsEmpty());
745 EXPECT_EQ(shadow_vertices->GetVertexCount(), 37u);
746 EXPECT_EQ(shadow_vertices->GetIndexCount(), 120u);
747 EXPECT_EQ(shadow_vertices->GetVertices().size(), 37u);
748 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 37u);
749 EXPECT_EQ(shadow_vertices->GetIndices().size(), 120u);
750 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
751 // We repeat the first and last vertex that is on the outer umbra.
752 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
753 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
754 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
755
756#if SHADOW_UNITTEST_SHOW_VERTICES
757 ShowVertices("Impeller Vertices", shadow_vertices);
758#endif
759}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [621/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
CounterClockwiseRectTest   
)

Definition at line 383 of file shadow_path_geometry_unittests.cc.

383 {
384 DlPathBuilder path_builder;
385 path_builder.MoveTo(DlPoint(0, 0));
386 path_builder.LineTo(DlPoint(0, 80));
387 path_builder.LineTo(DlPoint(100, 80));
388 path_builder.LineTo(DlPoint(100, 0));
389 path_builder.Close();
390 DlPath path = path_builder.TakePath();
391 Matrix matrix;
392 const Scalar height = 10.0f;
393
394 Tessellator tessellator;
395 std::shared_ptr<ShadowVertices> shadow_vertices =
396 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
397 matrix);
398
399 ASSERT_NE(shadow_vertices, nullptr);
400 EXPECT_FALSE(shadow_vertices->IsEmpty());
401 EXPECT_EQ(shadow_vertices->GetVertexCount(), 34u);
402 EXPECT_EQ(shadow_vertices->GetIndexCount(), 108u);
403 EXPECT_EQ(shadow_vertices->GetVertices().size(), 34u);
404 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 34u);
405 EXPECT_EQ(shadow_vertices->GetIndices().size(), 108u);
406 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
407 // We repeat the first and last vertex that is on the outer umbra.
408 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
409 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
410 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
411
412#if SHADOW_UNITTEST_SHOW_VERTICES
413 ShowVertices("Impeller Vertices", shadow_vertices);
414#endif
415}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [622/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
CounterClockwiseRectTrickyColinearPointsTest   
)

Definition at line 542 of file shadow_path_geometry_unittests.cc.

542 {
543 // This path includes a colinear point added to each edge of the rectangle
544 // which seems to violate convexity, but is eliminated as not contributing
545 // to the path. We should be able to process the path anyway.
546 DlPathBuilder path_builder;
547 path_builder.MoveTo(DlPoint(0, 0));
548 path_builder.LineTo(DlPoint(0, -10));
549 path_builder.LineTo(DlPoint(0, 80));
550 path_builder.LineTo(DlPoint(-10, 80));
551 path_builder.LineTo(DlPoint(100, 80));
552 path_builder.LineTo(DlPoint(100, 90));
553 path_builder.LineTo(DlPoint(100, 0));
554 path_builder.LineTo(DlPoint(110, 0));
555 path_builder.Close();
556 DlPath path = path_builder.TakePath();
557 Matrix matrix;
558 const Scalar height = 10.0f;
559
560 Tessellator tessellator;
561 std::shared_ptr<ShadowVertices> shadow_vertices =
562 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
563 matrix);
564
565 ASSERT_NE(shadow_vertices, nullptr);
566 EXPECT_FALSE(shadow_vertices->IsEmpty());
567 EXPECT_EQ(shadow_vertices->GetVertexCount(), 34u);
568 EXPECT_EQ(shadow_vertices->GetIndexCount(), 108u);
569 EXPECT_EQ(shadow_vertices->GetVertices().size(), 34u);
570 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 34u);
571 EXPECT_EQ(shadow_vertices->GetIndices().size(), 108u);
572 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
573 // We repeat the first and last vertex that is on the outer umbra.
574 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
575 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
576 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
577
578#if SHADOW_UNITTEST_SHOW_VERTICES
579 ShowVertices("Impeller Vertices", shadow_vertices);
580#endif
581}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [623/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
CounterClockwiseRectTrickyDupColinearPointsTest   
)

Definition at line 630 of file shadow_path_geometry_unittests.cc.

630 {
631 // This path includes a colinear point added to each edge of the rectangle
632 // which seems to violate convexity, but is eliminated as not contributing
633 // to the path. We should be able to process the path anyway.
634 // It also includes multiple collinear points on the first and last points
635 // that end up back where we started to make sure that in that case we
636 // eliminate all of the collinear points and the duplicate, rather than
637 // just the intermediate collinear points.
638 DlPathBuilder path_builder;
639 path_builder.MoveTo(DlPoint(0, 0));
640 path_builder.LineTo(DlPoint(0, -10));
641 path_builder.LineTo(DlPoint(0, 0));
642 path_builder.LineTo(DlPoint(0, 80));
643 path_builder.LineTo(DlPoint(-10, 80));
644 path_builder.LineTo(DlPoint(100, 80));
645 path_builder.LineTo(DlPoint(100, 90));
646 path_builder.LineTo(DlPoint(100, 0));
647 path_builder.LineTo(DlPoint(110, 0));
648 path_builder.LineTo(DlPoint(100, 0));
649 path_builder.Close();
650 DlPath path = path_builder.TakePath();
651 Matrix matrix;
652 const Scalar height = 10.0f;
653
654 Tessellator tessellator;
655 std::shared_ptr<ShadowVertices> shadow_vertices =
656 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
657 matrix);
658
659 ASSERT_NE(shadow_vertices, nullptr);
660 EXPECT_FALSE(shadow_vertices->IsEmpty());
661 EXPECT_EQ(shadow_vertices->GetVertexCount(), 34u);
662 EXPECT_EQ(shadow_vertices->GetIndexCount(), 108u);
663 EXPECT_EQ(shadow_vertices->GetVertices().size(), 34u);
664 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 34u);
665 EXPECT_EQ(shadow_vertices->GetIndices().size(), 108u);
666 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
667 // We repeat the first and last vertex that is on the outer umbra.
668 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
669 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
670 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
671
672#if SHADOW_UNITTEST_SHOW_VERTICES
673 ShowVertices("Impeller Vertices", shadow_vertices);
674#endif
675}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [624/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
CounterClockwiseTriangleTest   
)

Definition at line 315 of file shadow_path_geometry_unittests.cc.

315 {
316 DlPathBuilder path_builder;
317 path_builder.MoveTo(DlPoint(100, 0));
318 path_builder.LineTo(DlPoint(0, 110));
319 path_builder.LineTo(DlPoint(200, 110));
320 path_builder.Close();
321 const DlPath path = path_builder.TakePath();
322 const Matrix matrix;
323 const Scalar height = 10.0f;
324
325 Tessellator tessellator;
326 std::shared_ptr<ShadowVertices> shadow_vertices =
327 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
328 matrix);
329
330 ASSERT_NE(shadow_vertices, nullptr);
331 EXPECT_FALSE(shadow_vertices->IsEmpty());
332 EXPECT_EQ(shadow_vertices->GetVertexCount(), 33u);
333 EXPECT_EQ(shadow_vertices->GetIndexCount(), 102u);
334 EXPECT_EQ(shadow_vertices->GetVertices().size(), 33u);
335 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 33u);
336 EXPECT_EQ(shadow_vertices->GetIndices().size(), 102u);
337 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
338 // We repeat the first and last vertex that is on the outer umbra.
339 // There is another duplicate vertex from somewhere else not yet realized.
340 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 2u);
341 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
342 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
343
344#if SHADOW_UNITTEST_SHOW_VERTICES
345 ShowVertices("Impeller Vertices", shadow_vertices);
346#endif
347}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [625/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
EllipseTest   
)

Definition at line 789 of file shadow_path_geometry_unittests.cc.

789 {
790 Tessellator tessellator;
791 DlPath path = DlPath::MakeOval(DlRect::MakeLTRB(0, 0, 100, 80));
792 Matrix matrix;
793 const Scalar height = 10.0f;
794
795 std::shared_ptr<ShadowVertices> shadow_vertices =
796 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
797 matrix);
798
799 ASSERT_NE(shadow_vertices, nullptr);
800 EXPECT_FALSE(shadow_vertices->IsEmpty());
801 EXPECT_EQ(shadow_vertices->GetVertexCount(), 122u);
802 EXPECT_EQ(shadow_vertices->GetIndexCount(), 480u);
803 EXPECT_EQ(shadow_vertices->GetVertices().size(), 122u);
804 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 122u);
805 EXPECT_EQ(shadow_vertices->GetIndices().size(), 480u);
806 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
807 // We repeat the first and last vertex that is on the outer umbra.
808 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
809 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
810 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
811}

References height, impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeOval(), and flutter::path.

◆ TEST() [626/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
EmptyPathTest   
)

Definition at line 175 of file shadow_path_geometry_unittests.cc.

175 {
176 DlPathBuilder path_builder;
177 const DlPath path = path_builder.TakePath();
178 const Matrix matrix;
179 const Scalar height = 10.0f;
180
181 Tessellator tessellator;
182 std::shared_ptr<ShadowVertices> shadow_vertices =
183 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
184 matrix);
185
186 ASSERT_NE(shadow_vertices, nullptr);
187 EXPECT_TRUE(shadow_vertices->IsEmpty());
188}

References height, impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [627/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
EmptyRectTest   
)

Definition at line 241 of file shadow_path_geometry_unittests.cc.

241 {
242 DlPathBuilder path_builder;
243 path_builder.MoveTo(DlPoint(100, 100));
244 path_builder.LineTo(DlPoint(200, 100));
245 path_builder.LineTo(DlPoint(200, 100));
246 path_builder.LineTo(DlPoint(100, 100));
247 path_builder.Close();
248 const DlPath path = path_builder.TakePath();
249 const Matrix matrix;
250 const Scalar height = 10.0f;
251
252 Tessellator tessellator;
253 std::shared_ptr<ShadowVertices> shadow_vertices =
254 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
255 matrix);
256
257 ASSERT_NE(shadow_vertices, nullptr);
258 EXPECT_TRUE(shadow_vertices->IsEmpty());
259}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [628/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
GetAndTakeVertices   
)

Definition at line 261 of file shadow_path_geometry_unittests.cc.

261 {
262 DlPath path = DlPath::MakeRectLTRB(100, 100, 200, 200);
263 const Scalar height = 10.0f;
264
265 Tessellator tessellator;
266 ShadowPathGeometry geometry(tessellator, {}, path, height);
267
268 // Can call Get as many times as you want.
269 for (int i = 0; i < 10; i++) {
270 EXPECT_TRUE(geometry.GetShadowVertices());
271 }
272
273 // Can only call Take once.
274 EXPECT_TRUE(geometry.TakeShadowVertices());
275
276 // Further access wll then fail.
277 EXPECT_FALSE(geometry.GetShadowVertices());
278 EXPECT_FALSE(geometry.TakeShadowVertices());
279}

References height, i, flutter::DlPath::MakeRectLTRB(), and flutter::path.

◆ TEST() [629/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
HourglassSelfIntersectingTest   
)

Definition at line 838 of file shadow_path_geometry_unittests.cc.

838 {
839 DlPathBuilder path_builder;
840 path_builder.MoveTo(DlPoint(0, 0));
841 path_builder.LineTo(DlPoint(100, 80));
842 path_builder.LineTo(DlPoint(100, 0));
843 path_builder.LineTo(DlPoint(0, 80));
844 path_builder.Close();
845 const DlPath path = path_builder.TakePath();
846 const Matrix matrix;
847 const Scalar height = 10.0f;
848
849 Tessellator tessellator;
850 std::shared_ptr<ShadowVertices> shadow_vertices =
851 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
852 matrix);
853
854 EXPECT_EQ(shadow_vertices, nullptr);
855}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [630/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
InnerToOuterOverturningSpiralTest   
)

Definition at line 876 of file shadow_path_geometry_unittests.cc.

876 {
877 const Matrix matrix;
878 const Scalar height = 10.0f;
879 int step_count = 20;
880
881 DlPathBuilder path_builder;
882 path_builder.MoveTo(DlPoint(300, 200));
883 for (int i = 1; i < step_count * 2; i++) {
884 Scalar angle = (k2Pi * i) / step_count;
885 Scalar radius = 80.0f + std::abs(i - step_count);
886 path_builder.LineTo(DlPoint(200, 200) + DlPoint(std::cos(angle) * radius,
887 std::sin(angle) * radius));
888 }
889 path_builder.Close();
890 DlPath path = path_builder.TakePath();
891
892 Tessellator tessellator;
893 std::shared_ptr<ShadowVertices> shadow_vertices =
894 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
895 matrix);
896
897 EXPECT_EQ(shadow_vertices, nullptr);
898}

References flutter::DlPathBuilder::Close(), height, i, impeller::k2Pi, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [631/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
MoveToOnlyTest   
)

Definition at line 190 of file shadow_path_geometry_unittests.cc.

190 {
191 DlPathBuilder path_builder;
192 path_builder.MoveTo(DlPoint(100, 100));
193 const DlPath path = path_builder.TakePath();
194 const Matrix matrix;
195 const Scalar height = 10.0f;
196
197 Tessellator tessellator;
198 std::shared_ptr<ShadowVertices> shadow_vertices =
199 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
200 matrix);
201
202 ASSERT_NE(shadow_vertices, nullptr);
203 EXPECT_TRUE(shadow_vertices->IsEmpty());
204}

References height, impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [632/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
MultipleContoursTest   
)

Definition at line 1044 of file shadow_path_geometry_unittests.cc.

1044 {
1045 const Matrix matrix;
1046 const Scalar height = 10.0f;
1047
1048 DlPathBuilder path_builder;
1049 path_builder.MoveTo(DlPoint(150, 100));
1050 path_builder.LineTo(DlPoint(200, 300));
1051 path_builder.LineTo(DlPoint(100, 300));
1052 path_builder.Close();
1053 path_builder.MoveTo(DlPoint(250, 100));
1054 path_builder.LineTo(DlPoint(300, 300));
1055 path_builder.LineTo(DlPoint(200, 300));
1056 path_builder.Close();
1057 DlPath path = path_builder.TakePath();
1058
1059 Tessellator tessellator;
1060 std::shared_ptr<ShadowVertices> shadow_vertices =
1061 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
1062 matrix);
1063
1064 EXPECT_EQ(shadow_vertices, nullptr);
1065}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [633/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
OnePathSegmentTest   
)

Definition at line 206 of file shadow_path_geometry_unittests.cc.

206 {
207 DlPathBuilder path_builder;
208 path_builder.MoveTo(DlPoint(100, 100));
209 path_builder.LineTo(DlPoint(200, 100));
210 const DlPath path = path_builder.TakePath();
211 const Matrix matrix;
212 const Scalar height = 10.0f;
213
214 Tessellator tessellator;
215 std::shared_ptr<ShadowVertices> shadow_vertices =
216 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
217 matrix);
218
219 ASSERT_NE(shadow_vertices, nullptr);
220 EXPECT_TRUE(shadow_vertices->IsEmpty());
221}

References height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [634/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
OuterToInnerOverturningSpiralTest   
)

Definition at line 924 of file shadow_path_geometry_unittests.cc.

924 {
925 const Matrix matrix;
926 const Scalar height = 10.0f;
927 int step_count = 20;
928
929 DlPathBuilder path_builder;
930 path_builder.MoveTo(DlPoint(280, 200));
931 for (int i = 1; i < step_count * 2; i++) {
932 Scalar angle = (k2Pi * i) / step_count;
933 Scalar radius = 100.0f - std::abs(i - step_count);
934 path_builder.LineTo(DlPoint(200, 200) + DlPoint(std::cos(angle) * radius,
935 std::sin(angle) * radius));
936 }
937 path_builder.Close();
938 DlPath path = path_builder.TakePath();
939
940 Tessellator tessellator;
941 std::shared_ptr<ShadowVertices> shadow_vertices =
942 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
943 matrix);
944
945 EXPECT_EQ(shadow_vertices, nullptr);
946}

References flutter::DlPathBuilder::Close(), height, i, impeller::k2Pi, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [635/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
ReverseHourglassSelfIntersectingTest   
)

Definition at line 857 of file shadow_path_geometry_unittests.cc.

857 {
858 DlPathBuilder path_builder;
859 path_builder.MoveTo(DlPoint(0, 0));
860 path_builder.LineTo(DlPoint(100, 80));
861 path_builder.LineTo(DlPoint(0, 80));
862 path_builder.LineTo(DlPoint(100, 0));
863 path_builder.Close();
864 const DlPath path = path_builder.TakePath();
865 const Matrix matrix;
866 const Scalar height = 10.0f;
867
868 Tessellator tessellator;
869 std::shared_ptr<ShadowVertices> shadow_vertices =
870 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
871 matrix);
872
873 EXPECT_EQ(shadow_vertices, nullptr);
874}

References flutter::DlPathBuilder::Close(), height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [636/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
ReverseInnerToOuterOverturningSpiralTest   
)

Definition at line 900 of file shadow_path_geometry_unittests.cc.

900 {
901 const Matrix matrix;
902 const Scalar height = 10.0f;
903 int step_count = 20;
904
905 DlPathBuilder path_builder;
906 path_builder.MoveTo(DlPoint(300, 200));
907 for (int i = 1; i < step_count * 2; i++) {
908 Scalar angle = -(k2Pi * i) / step_count;
909 Scalar radius = 80.0f + std::abs(i - step_count);
910 path_builder.LineTo(DlPoint(200, 200) + DlPoint(std::cos(angle) * radius,
911 std::sin(angle) * radius));
912 }
913 path_builder.Close();
914 DlPath path = path_builder.TakePath();
915
916 Tessellator tessellator;
917 std::shared_ptr<ShadowVertices> shadow_vertices =
918 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
919 matrix);
920
921 EXPECT_EQ(shadow_vertices, nullptr);
922}

References flutter::DlPathBuilder::Close(), height, i, impeller::k2Pi, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [637/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
ReverseOuterToInnerOverturningSpiralTest   
)

Definition at line 948 of file shadow_path_geometry_unittests.cc.

948 {
949 const Matrix matrix;
950 const Scalar height = 10.0f;
951 int step_count = 20;
952
953 DlPathBuilder path_builder;
954 path_builder.MoveTo(DlPoint(280, 200));
955 for (int i = 1; i < step_count * 2; i++) {
956 Scalar angle = -(k2Pi * i) / step_count;
957 Scalar radius = 100.0f - std::abs(i - step_count);
958 path_builder.LineTo(DlPoint(200, 200) + DlPoint(std::cos(angle) * radius,
959 std::sin(angle) * radius));
960 }
961 path_builder.Close();
962 DlPath path = path_builder.TakePath();
963
964 Tessellator tessellator;
965 std::shared_ptr<ShadowVertices> shadow_vertices =
966 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
967 matrix);
968
969 EXPECT_EQ(shadow_vertices, nullptr);
970}

References flutter::DlPathBuilder::Close(), height, i, impeller::k2Pi, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [638/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
RoundRectTest   
)

Definition at line 813 of file shadow_path_geometry_unittests.cc.

813 {
814 Tessellator tessellator;
815 DlPath path = DlPath::MakeRoundRectXY(DlRect::MakeLTRB(0, 0, 100, 80), 5, 4);
816 Matrix matrix;
817 const Scalar height = 10.0f;
818
819 std::shared_ptr<ShadowVertices> shadow_vertices =
820 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
821 matrix);
822
823 ASSERT_NE(shadow_vertices, nullptr);
824 EXPECT_FALSE(shadow_vertices->IsEmpty());
825 EXPECT_EQ(shadow_vertices->GetVertexCount(), 55u);
826 EXPECT_EQ(shadow_vertices->GetIndexCount(), 168u);
827 EXPECT_EQ(shadow_vertices->GetVertices().size(), 55u);
828 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 55u);
829 EXPECT_EQ(shadow_vertices->GetIndices().size(), 168u);
830 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
831 // We repeat the first and last vertex that is on the outer umbra.
832 // There is another duplicate vertex from somewhere else not yet realized.
833 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 2u);
834 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
835 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
836}

References height, impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRoundRectXY(), and flutter::path.

◆ TEST() [639/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
ScaledRectTest   
)

Definition at line 761 of file shadow_path_geometry_unittests.cc.

761 {
762 Tessellator tessellator;
763 DlPath path = DlPath::MakeRect(DlRect::MakeLTRB(0, 0, 100, 80));
764 Matrix matrix = Matrix::MakeScale({2, 3, 1});
765 const Scalar height = 10.0f;
766
767 std::shared_ptr<ShadowVertices> shadow_vertices =
768 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
769 matrix);
770
771 ASSERT_NE(shadow_vertices, nullptr);
772 EXPECT_FALSE(shadow_vertices->IsEmpty());
773 EXPECT_EQ(shadow_vertices->GetVertexCount(), 34u);
774 EXPECT_EQ(shadow_vertices->GetIndexCount(), 108u);
775 EXPECT_EQ(shadow_vertices->GetVertices().size(), 34u);
776 EXPECT_EQ(shadow_vertices->GetGaussians().size(), 34u);
777 EXPECT_EQ(shadow_vertices->GetIndices().size(), 108u);
778 EXPECT_EQ((shadow_vertices->GetIndices().size() % 3u), 0u);
779 // We repeat the first and last vertex that is on the outer umbra.
780 EXPECT_LE(CountDuplicateVertices(shadow_vertices), 1u);
781 EXPECT_EQ(CountDuplicateTriangles(shadow_vertices), 0u);
782 EXPECT_FALSE(DoTrianglesOverlap(shadow_vertices));
783
784#if SHADOW_UNITTEST_SHOW_VERTICES
785 ShowVertices("Impeller Vertices", shadow_vertices);
786#endif
787}

References height, impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRect(), impeller::Matrix::MakeScale(), and flutter::path.

◆ TEST() [640/689]

impeller::testing::TEST ( ShadowPathGeometryTest  ,
TwoColinearSegmentsTest   
)

Definition at line 223 of file shadow_path_geometry_unittests.cc.

223 {
224 DlPathBuilder path_builder;
225 path_builder.MoveTo(DlPoint(100, 100));
226 path_builder.LineTo(DlPoint(200, 100));
227 path_builder.LineTo(DlPoint(300, 100));
228 const DlPath path = path_builder.TakePath();
229 const Matrix matrix;
230 const Scalar height = 10.0f;
231
232 Tessellator tessellator;
233 std::shared_ptr<ShadowVertices> shadow_vertices =
234 ShadowPathGeometry::MakeAmbientShadowVertices(tessellator, path, height,
235 matrix);
236
237 ASSERT_NE(shadow_vertices, nullptr);
238 EXPECT_TRUE(shadow_vertices->IsEmpty());
239}

References height, flutter::DlPathBuilder::LineTo(), impeller::ShadowPathGeometry::MakeAmbientShadowVertices(), flutter::DlPathBuilder::MoveTo(), flutter::path, and flutter::DlPathBuilder::TakePath().

◆ TEST() [641/689]

impeller::testing::TEST ( SizeTest  ,
ISizeIsEmpty   
)

Definition at line 36 of file size_unittests.cc.

36 {
37 // Non-empty
38 EXPECT_FALSE(ISize(10, 7).IsEmpty());
39
40 // Empty both width and height both 0 or negative, in all combinations
41 EXPECT_TRUE(ISize(0, 0).IsEmpty());
42 EXPECT_TRUE(ISize(-1, -1).IsEmpty());
43 EXPECT_TRUE(ISize(-1, 0).IsEmpty());
44 EXPECT_TRUE(ISize(0, -1).IsEmpty());
45
46 // Empty for 0 or negative width or height (but not both at the same time)
47 EXPECT_TRUE(ISize(10, 0).IsEmpty());
48 EXPECT_TRUE(ISize(10, -1).IsEmpty());
49 EXPECT_TRUE(ISize(0, 7).IsEmpty());
50 EXPECT_TRUE(ISize(-1, 7).IsEmpty());
51}

◆ TEST() [642/689]

impeller::testing::TEST ( SizeTest  ,
IsSquare   
)

Definition at line 53 of file size_unittests.cc.

53 {
54 EXPECT_TRUE(Size(20, 20).IsSquare());
55 EXPECT_FALSE(Size(20, 19).IsSquare());
56 EXPECT_FALSE(Size(19, 20).IsSquare());
57
58 EXPECT_TRUE(ISize(20, 20).IsSquare());
59 EXPECT_FALSE(ISize(20, 19).IsSquare());
60 EXPECT_FALSE(ISize(19, 20).IsSquare());
61}

◆ TEST() [643/689]

impeller::testing::TEST ( SizeTest  ,
MaxDimension   
)

Definition at line 63 of file size_unittests.cc.

63 {
64 EXPECT_EQ(Size(20, 20).MaxDimension(), 20);
65 EXPECT_EQ(Size(20, 19).MaxDimension(), 20);
66 EXPECT_EQ(Size(19, 20).MaxDimension(), 20);
67 EXPECT_EQ(Size(20, 21).MaxDimension(), 21);
68 EXPECT_EQ(Size(21, 20).MaxDimension(), 21);
69
70 EXPECT_EQ(ISize(20, 20).MaxDimension(), 20);
71 EXPECT_EQ(ISize(20, 19).MaxDimension(), 20);
72 EXPECT_EQ(ISize(19, 20).MaxDimension(), 20);
73 EXPECT_EQ(ISize(20, 21).MaxDimension(), 21);
74 EXPECT_EQ(ISize(21, 20).MaxDimension(), 21);
75}

◆ TEST() [644/689]

impeller::testing::TEST ( SizeTest  ,
NegationOperator   
)

Definition at line 77 of file size_unittests.cc.

77 {
78 EXPECT_EQ(-Size(10, 20), Size(-10, -20));
79 EXPECT_EQ(-Size(-10, 20), Size(10, -20));
80 EXPECT_EQ(-Size(10, -20), Size(-10, 20));
81 EXPECT_EQ(-Size(-10, -20), Size(10, 20));
82}

◆ TEST() [645/689]

impeller::testing::TEST ( SizeTest  ,
SizeIsEmpty   
)

Definition at line 12 of file size_unittests.cc.

12 {
13 auto nan = std::numeric_limits<Scalar>::quiet_NaN();
14
15 // Non-empty
16 EXPECT_FALSE(Size(10.5, 7.2).IsEmpty());
17
18 // Empty both width and height both 0 or negative, in all combinations
19 EXPECT_TRUE(Size(0.0, 0.0).IsEmpty());
20 EXPECT_TRUE(Size(-1.0, -1.0).IsEmpty());
21 EXPECT_TRUE(Size(-1.0, 0.0).IsEmpty());
22 EXPECT_TRUE(Size(0.0, -1.0).IsEmpty());
23
24 // Empty for 0 or negative width or height (but not both at the same time)
25 EXPECT_TRUE(Size(10.5, 0.0).IsEmpty());
26 EXPECT_TRUE(Size(10.5, -1.0).IsEmpty());
27 EXPECT_TRUE(Size(0.0, 7.2).IsEmpty());
28 EXPECT_TRUE(Size(-1.0, 7.2).IsEmpty());
29
30 // Empty for NaN in width or height or both
31 EXPECT_TRUE(Size(10.5, nan).IsEmpty());
32 EXPECT_TRUE(Size(nan, 7.2).IsEmpty());
33 EXPECT_TRUE(Size(nan, nan).IsEmpty());
34}

◆ TEST() [646/689]

impeller::testing::TEST ( SkiaConversionsTest  ,
ToColor   
)

Definition at line 46 of file skia_conversions_unittests.cc.

46 {
47 // Create a color with alpha, red, green, and blue values that are all
48 // trivially divisible by 255 so that we can test the conversion results in
49 // correct scalar values.
50 // AARRGGBB
51 const flutter::DlColor color = flutter::DlColor(0x8040C020);
52 auto converted_color = skia_conversions::ToColor(color);
53
54 ASSERT_TRUE(ScalarNearlyEqual(converted_color.alpha, 0x80 * (1.0f / 255)));
55 ASSERT_TRUE(ScalarNearlyEqual(converted_color.red, 0x40 * (1.0f / 255)));
56 ASSERT_TRUE(ScalarNearlyEqual(converted_color.green, 0xC0 * (1.0f / 255)));
57 ASSERT_TRUE(ScalarNearlyEqual(converted_color.blue, 0x20 * (1.0f / 255)));
58}

References impeller::ScalarNearlyEqual(), and impeller::skia_conversions::ToColor().

◆ TEST() [647/689]

impeller::testing::TEST ( SkiaConversionTest  ,
ToSamplerDescriptor   
)

Definition at line 17 of file skia_conversions_unittests.cc.

17 {
18 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
20 .min_filter,
22 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
24 .mip_filter,
26
27 EXPECT_EQ(
28 skia_conversions::ToSamplerDescriptor(flutter::DlImageSampling::kLinear)
29 .min_filter,
31 EXPECT_EQ(
32 skia_conversions::ToSamplerDescriptor(flutter::DlImageSampling::kLinear)
33 .mip_filter,
35
36 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
38 .min_filter,
40 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
42 .mip_filter,
44}
@ kLinear
Sample from the two nearest mip levels and linearly interpolate.
@ kBase
The texture is sampled as if it only had a single mipmap level.
@ kNearest
Select nearest to the sample point. Most widely supported.

References impeller::kBase, flutter::kLinear, impeller::kLinear, flutter::kMipmapLinear, impeller::kNearest, flutter::kNearestNeighbor, and impeller::skia_conversions::ToSamplerDescriptor().

◆ TEST() [648/689]

impeller::testing::TEST ( SpecConstant  ,
CanCreateShaderWithSpecializationConstant   
)

Definition at line 14 of file specialization_constants_unittests.cc.

14 {
15 auto mock_gles = MockGLES::Init();
16 auto& proc_table = mock_gles->GetProcTable();
17 auto shader_source =
18 "#version 100\n"
19 "#ifndef SPIRV_CROSS_CONSTANT_ID_0\n"
20 "#define SPIRV_CROSS_CONSTANT_ID_0 1\n"
21 "#endif\n"
22 "void main() { return vec4(0.0); }";
23 auto test_shader = std::make_shared<fml::DataMapping>(shader_source);
24
25 auto result = proc_table.ComputeShaderWithDefines(*test_shader, {0});
26
27 auto expected_shader_source =
28 "#version 100\n"
29 "#define SPIRV_CROSS_CONSTANT_ID_0 0.000000\n"
30 "#ifndef SPIRV_CROSS_CONSTANT_ID_0\n"
31 "#define SPIRV_CROSS_CONSTANT_ID_0 1\n"
32 "#endif\n"
33 "void main() { return vec4(0.0); }";
34
35 if (!result.has_value()) {
36 GTEST_FAIL() << "Expected shader source";
37 }
38 ASSERT_EQ(result.value(), expected_shader_source);
39}

References impeller::testing::MockGLES::Init().

◆ TEST() [649/689]

impeller::testing::TEST ( SpecConstant  ,
CanCreateShaderWithSpecializationConstantMultipleValues   
)

Definition at line 41 of file specialization_constants_unittests.cc.

41 {
42 auto mock_gles = MockGLES::Init();
43 auto& proc_table = mock_gles->GetProcTable();
44 auto shader_source =
45 "#version 100\n"
46 "#ifndef SPIRV_CROSS_CONSTANT_ID_0\n"
47 "#define SPIRV_CROSS_CONSTANT_ID_0 1\n"
48 "#endif\n"
49 "void main() { return vec4(0.0); }";
50 auto test_shader = std::make_shared<fml::DataMapping>(shader_source);
51
52 auto result =
53 proc_table.ComputeShaderWithDefines(*test_shader, {0, 1, 2, 3, 4, 5});
54
55 auto expected_shader_source =
56 "#version 100\n"
57 "#define SPIRV_CROSS_CONSTANT_ID_0 0.000000\n"
58 "#define SPIRV_CROSS_CONSTANT_ID_1 1.000000\n"
59 "#define SPIRV_CROSS_CONSTANT_ID_2 2.000000\n"
60 "#define SPIRV_CROSS_CONSTANT_ID_3 3.000000\n"
61 "#define SPIRV_CROSS_CONSTANT_ID_4 4.000000\n"
62 "#define SPIRV_CROSS_CONSTANT_ID_5 5.000000\n"
63 "#ifndef SPIRV_CROSS_CONSTANT_ID_0\n"
64 "#define SPIRV_CROSS_CONSTANT_ID_0 1\n"
65 "#endif\n"
66 "void main() { return vec4(0.0); }";
67
68 if (!result.has_value()) {
69 GTEST_FAIL() << "Expected shader source";
70 }
71 ASSERT_EQ(result.value(), expected_shader_source);
72}

References impeller::testing::MockGLES::Init().

◆ TEST() [650/689]

impeller::testing::TEST ( SurfaceContextVK  ,
TearsDownSwapchain   
)

Definition at line 31 of file surface_context_vk_unittests.cc.

31 {
32 SetSwapchainImageSize({100, 100});
33 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
34
35 vk::UniqueSurfaceKHR surface = CreateSurface(*context);
36 SurfaceContextVK surface_context(context);
37
38 EXPECT_TRUE(surface_context.SetWindowSurface(std::move(surface), {100, 100}));
39 EXPECT_NE(surface_context.AcquireNextSurface(), nullptr);
40
41 surface_context.TeardownSwapchain();
42
43 EXPECT_EQ(surface_context.AcquireNextSurface(), nullptr);
44}
void SetSwapchainImageSize(ISize size)
Override the image size returned by all swapchain images.

References impeller::SurfaceContextVK::AcquireNextSurface(), impeller::testing::MockVulkanContextBuilder::Build(), context, CreateSurface(), SetSwapchainImageSize(), impeller::SurfaceContextVK::SetWindowSurface(), surface, and impeller::SurfaceContextVK::TeardownSwapchain().

◆ TEST() [651/689]

impeller::testing::TEST ( SwapchainTest  ,
CachesRenderPassOnSwapchainImage   
)

Definition at line 58 of file swapchain_unittests.cc.

58 {
59 auto const context = MockVulkanContextBuilder().Build();
60
62 auto swapchain =
63 KHRSwapchainVK::Create(context, std::move(surface), ISize{1, 1});
64
65 EXPECT_TRUE(swapchain->IsValid());
66
67 // The mock swapchain will always create 3 images, verify each one starts
68 // out with the same MSAA and depth+stencil texture, and no cached
69 // framebuffer.
70 std::vector<std::shared_ptr<Texture>> msaa_textures;
71 std::vector<std::shared_ptr<Texture>> depth_stencil_textures;
72 for (auto i = 0u; i < 3u; i++) {
73 auto drawable = swapchain->AcquireNextDrawable();
74 RenderTarget render_target = drawable->GetRenderTarget();
75
76 auto texture = render_target.GetRenderTargetTexture();
77 auto& texture_vk = TextureVK::Cast(*texture);
78 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount4).framebuffer,
79 nullptr);
80 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount4).render_pass,
81 nullptr);
82
83 auto command_buffer = context->CreateCommandBuffer();
84 auto render_pass = command_buffer->CreateRenderPass(render_target);
85 render_pass->EncodeCommands();
86
87 auto& depth = render_target.GetDepthAttachment();
88 depth_stencil_textures.push_back(depth.has_value() ? depth->texture
89 : nullptr);
90 msaa_textures.push_back(render_target.GetColorAttachment(0).texture);
91 }
92
93 for (auto i = 1; i < 3; i++) {
94 EXPECT_EQ(msaa_textures[i - 1], msaa_textures[i]);
95 EXPECT_EQ(depth_stencil_textures[i - 1], depth_stencil_textures[i]);
96 }
97
98 // After each images has been acquired once and the render pass presented,
99 // each should have a cached framebuffer and render pass.
100
101 std::vector<SharedHandleVK<vk::Framebuffer>> framebuffers;
102 std::vector<SharedHandleVK<vk::RenderPass>> render_passes;
103 for (auto i = 0u; i < 3u; i++) {
104 auto drawable = swapchain->AcquireNextDrawable();
105 RenderTarget render_target = drawable->GetRenderTarget();
106
107 auto texture = render_target.GetRenderTargetTexture();
108 auto& texture_vk = TextureVK::Cast(*texture);
109
110 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount4).framebuffer,
111 nullptr);
112 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount4).render_pass,
113 nullptr);
114 framebuffers.push_back(
115 texture_vk.GetCachedFrameData(SampleCount::kCount4).framebuffer);
116 render_passes.push_back(
117 texture_vk.GetCachedFrameData(SampleCount::kCount4).render_pass);
118 }
119
120 // Iterate through once more to verify render passes and framebuffers are
121 // unchanged.
122 for (auto i = 0u; i < 3u; i++) {
123 auto drawable = swapchain->AcquireNextDrawable();
124 RenderTarget render_target = drawable->GetRenderTarget();
125
126 auto texture = render_target.GetRenderTargetTexture();
127 auto& texture_vk = TextureVK::Cast(*texture);
128
129 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount4).framebuffer,
130 framebuffers[i]);
131 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount4).render_pass,
132 render_passes[i]);
133 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount1).framebuffer,
134 framebuffers[i]);
135 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount1).render_pass,
136 render_passes[i]);
137 }
138}
ColorAttachment GetColorAttachment(size_t index) const
Get the color attachment at [index].
std::shared_ptr< Texture > GetRenderTargetTexture() const
const std::optional< DepthAttachment > & GetDepthAttachment() const
VkSwapchainKHR swapchain
Definition main.cc:80
vk::UniqueSurfaceKHR CreateSurface(const ContextVK &context)

References impeller::testing::MockVulkanContextBuilder::Build(), impeller::BackendCast< TextureVK, Texture >::Cast(), command_buffer, context, impeller::SwapchainVK::Create(), CreateSurface(), impeller::RenderTarget::GetColorAttachment(), impeller::RenderTarget::GetDepthAttachment(), impeller::RenderTarget::GetRenderTargetTexture(), i, impeller::kCount1, impeller::kCount4, render_pass, surface, swapchain, impeller::Attachment::texture, and texture.

◆ TEST() [652/689]

impeller::testing::TEST ( SwapchainTest  ,
CanCreateSwapchain   
)

Definition at line 28 of file swapchain_unittests.cc.

28 {
29 auto const context = MockVulkanContextBuilder().Build();
30
32 auto swapchain =
33 KHRSwapchainVK::Create(context, std::move(surface), ISize{1, 1});
34
35 EXPECT_TRUE(swapchain->IsValid());
36}

References impeller::testing::MockVulkanContextBuilder::Build(), context, impeller::SwapchainVK::Create(), CreateSurface(), surface, and swapchain.

◆ TEST() [653/689]

impeller::testing::TEST ( SwapchainTest  ,
NoFenceWaitAfterAcquireNextImageFailure   
)

Definition at line 140 of file swapchain_unittests.cc.

140 {
141 bool wait_for_fences_called = false;
142 auto const context =
145 [](VkDevice, VkSwapchainKHR, uint64_t, VkSemaphore, VkFence,
146 uint32_t*) -> VkResult { return VK_ERROR_SURFACE_LOST_KHR; })
147 .SetWaitForFencesCallback([&](VkDevice, uint32_t, const VkFence*,
148 VkBool32, uint64_t) -> VkResult {
149 wait_for_fences_called = true;
150 return VK_SUCCESS;
151 })
152 .Build();
153
154 auto surface = CreateSurface(*context);
155 SetSwapchainImageSize(ISize{1, 1});
156 auto swapchain =
157 KHRSwapchainVK::Create(context, std::move(surface), ISize{1, 1},
158 /*enable_msaa=*/false);
159 auto image = swapchain->AcquireNextDrawable();
160 EXPECT_FALSE(image);
161
162 swapchain->AcquireNextDrawable();
163 EXPECT_FALSE(wait_for_fences_called);
164}
MockVulkanContextBuilder SetAcquireNextImageCallback(std::function< std::remove_pointer_t< PFN_vkAcquireNextImageKHR > > acquire_next_image_callback)
FlutterVulkanImage * image

References context, impeller::SwapchainVK::Create(), CreateSurface(), image, impeller::testing::MockVulkanContextBuilder::SetAcquireNextImageCallback(), SetSwapchainImageSize(), surface, and swapchain.

◆ TEST() [654/689]

impeller::testing::TEST ( SwapchainTest  ,
RecreateSwapchainWhenSizeChanges   
)

Definition at line 38 of file swapchain_unittests.cc.

38 {
39 auto const context = MockVulkanContextBuilder().Build();
40
43 auto swapchain =
44 KHRSwapchainVK::Create(context, std::move(surface), ISize{1, 1},
45 /*enable_msaa=*/false);
46 auto image = swapchain->AcquireNextDrawable();
47 auto expected_size = ISize{1, 1};
48 EXPECT_EQ(image->GetSize(), expected_size);
49
50 SetSwapchainImageSize(ISize{100, 100});
51 swapchain->UpdateSurfaceSize(ISize{100, 100});
52
53 auto image_b = swapchain->AcquireNextDrawable();
54 expected_size = ISize{100, 100};
55 EXPECT_EQ(image_b->GetSize(), expected_size);
56}

References impeller::testing::MockVulkanContextBuilder::Build(), context, impeller::SwapchainVK::Create(), CreateSurface(), image, SetSwapchainImageSize(), surface, and swapchain.

◆ TEST() [655/689]

impeller::testing::TEST ( TessellatorTest  ,
CircleVertexCounts   
)

Definition at line 154 of file tessellator_unittests.cc.

154 {
155 Tessellator tessellator;
156
157 auto test = [&tessellator](const Matrix& transform, Scalar radius) {
158 auto generator = tessellator.FilledCircle(transform, {}, radius);
159 size_t quadrant_divisions = generator.GetVertexCount() / 4;
160
161 // Confirm the approximation error is within the currently accepted
162 // |kCircleTolerance| value advertised by |CircleTessellator|.
163 // (With an additional 1% tolerance for floating point rounding.)
164 double angle = kPiOver2 / quadrant_divisions;
165 Point first = {radius, 0};
166 Point next = {static_cast<Scalar>(cos(angle) * radius),
167 static_cast<Scalar>(sin(angle) * radius)};
168 Point midpoint = (first + next) * 0.5;
169 EXPECT_GE(midpoint.GetLength(),
170 radius - Tessellator::kCircleTolerance * 1.01)
171 << ", transform = " << transform << ", radius = " << radius
172 << ", divisions = " << quadrant_divisions;
173 };
174
175 test({}, 0.0);
176 test({}, 0.9);
177 test({}, 1.0);
178 test({}, 1.9);
179 test(Matrix::MakeScale(Vector2(2.0, 2.0)), 0.95);
180 test({}, 2.0);
181 test(Matrix::MakeScale(Vector2(2.0, 2.0)), 1.0);
182 test({}, 11.9);
183 test({}, 12.0);
184 test({}, 35.9);
185 for (int i = 36; i < 10000; i += 4) {
186 test({}, i);
187 }
188}
size_t GetVertexCount() const override
|VertexGenerator|
EllipticalVertexGenerator FilledCircle(const Matrix &view_transform, const Point &center, Scalar radius)
Create a |VertexGenerator| that can produce vertices for a filled circle of the given radius around t...

References impeller::Tessellator::FilledCircle(), impeller::Tessellator::EllipticalVertexGenerator::GetVertexCount(), i, impeller::Tessellator::kCircleTolerance, impeller::kPiOver2, impeller::Matrix::MakeScale(), and transform.

◆ TEST() [656/689]

impeller::testing::TEST ( TessellatorTest  ,
EarlyReturnEmptyConvexShape   
)

Definition at line 590 of file tessellator_unittests.cc.

590 {
591 // This path is not technically empty (it has a size in one dimension), but
592 // it contains only move commands and no actual path segment definitions.
594 builder.MoveTo({0, 0});
595 builder.MoveTo({10, 10});
596
597 std::vector<Point> points;
598 std::vector<uint16_t> indices;
599 Tessellator::TessellateConvexInternal(builder.TakePath(), points, indices,
600 3.0f);
601
602 EXPECT_TRUE(points.empty());
603 EXPECT_TRUE(indices.empty());
604}

References flutter::DlPathBuilder::MoveTo(), points, flutter::DlPathBuilder::TakePath(), and impeller::Tessellator::TessellateConvexInternal().

◆ TEST() [657/689]

impeller::testing::TEST ( TessellatorTest  ,
FilledArcStripTessellationVertices   
)

Definition at line 306 of file tessellator_unittests.cc.

306 {
307 Tessellator tessellator;
308
309 auto test = [&tessellator](const Matrix& transform, const Arc& arc) {
310 auto generator = tessellator.FilledArc(transform, arc,
311 /*supports_triangle_fans=*/false);
312 EXPECT_EQ(generator.GetTriangleType(), PrimitiveType::kTriangleStrip);
313
314 auto vertex_count = generator.GetVertexCount();
315 auto vertices = std::vector<Point>();
316 generator.GenerateVertices([&vertices](const Point& p) { //
317 vertices.push_back(p);
318 });
319 EXPECT_EQ(vertices.size(), vertex_count);
320
321 auto center = arc.GetOvalBounds().GetCenter();
322 auto radius = arc.GetOvalSize().width * 0.5;
323
324 // Test position of first point
326 vertices[0],
327 Point(center.x + cos(Radians(arc.GetStart()).radians) * radius,
328 center.y + sin(Radians(arc.GetStart()).radians) * radius));
329
330 // Test position of last point
331 auto last_angle = arc.GetStart() + arc.GetSweep();
333 vertices[vertex_count - 1],
334 Point(center.x + cos(Radians(last_angle).radians) * radius,
335 center.y + sin(Radians(last_angle).radians) * radius));
336
337 // Test odd-indexed points. These are all the origin.
338 Point origin = arc.IncludeCenter()
339 ? center
340 : (vertices[0] + vertices[vertex_count - 1]) * 0.5f;
341 for (size_t i = 1; i < vertex_count; i += 2) {
342 EXPECT_POINT_NEAR(vertices[i], origin);
343 }
344
345 // Test even-indexed points. These are points on the outer edge of the arc.
346 auto previous_outer_point = vertices[0];
347 auto outer_increment_distance = (vertices[4] - vertices[2]).GetLength();
348 for (size_t i = 2; i < vertex_count; i += 2) {
349 // Each is |radius| from the center.
350 EXPECT_NEAR((vertices[i] - center).GetLength(), radius, kEhCloseEnough);
351
352 // Each is within |outer_increment_distance| from the previous
353 if (i == 2 || i == vertex_count - 1) {
354 // The very first and last points may be closer than
355 // |outer_increment_distance| to their adjacent outer points
356 EXPECT_LE((vertices[i] - previous_outer_point).GetLength(),
357 outer_increment_distance + kEhCloseEnough);
358 } else {
359 // Other outer points are |outer_increment_distance| apart
360 EXPECT_NEAR((vertices[i] - previous_outer_point).GetLength(),
361 outer_increment_distance, kEhCloseEnough);
362 }
363
364 previous_outer_point = vertices[i];
365 }
366 };
367
368 test({}, Arc(Rect::MakeXYWH(0, 0, 100, 100), Degrees(0), Degrees(90), false));
369 test({}, Arc(Rect::MakeXYWH(0, 0, 100, 100), Degrees(0), Degrees(90), true));
370
371 test({},
372 Arc(Rect::MakeXYWH(0, 0, 100, 100), Degrees(0), Degrees(-270), false));
373 test({},
374 Arc(Rect::MakeXYWH(0, 0, 100, 100), Degrees(0), Degrees(-270), true));
375
376 test({},
377 Arc(Rect::MakeXYWH(0, 0, 100, 100), Degrees(94), Degrees(322), false));
378 test({},
379 Arc(Rect::MakeXYWH(0, 0, 100, 100), Degrees(94), Degrees(322), true));
380}
ArcVertexGenerator FilledArc(const Matrix &view_transform, const Arc &arc, bool supports_triangle_fans)
Create a |VertexGenerator| that can produce vertices for a stroked arc inscribed within the given ova...

References EXPECT_POINT_NEAR, impeller::Tessellator::FilledArc(), i, flutter::kEhCloseEnough, impeller::kTriangleStrip, impeller::TRect< Scalar >::MakeXYWH(), impeller::Radians::radians, and transform.

◆ TEST() [658/689]

impeller::testing::TEST ( TessellatorTest  ,
FilledCircleTessellationVertices   
)

Definition at line 190 of file tessellator_unittests.cc.

190 {
191 Tessellator tessellator;
192
193 auto test = [&tessellator](const Matrix& transform, const Point& center,
194 Scalar radius) {
195 auto generator = tessellator.FilledCircle(transform, center, radius);
196 EXPECT_EQ(generator.GetTriangleType(), PrimitiveType::kTriangleStrip);
197
198 auto vertex_count = generator.GetVertexCount();
199 auto vertices = std::vector<Point>();
200 generator.GenerateVertices([&vertices](const Point& p) { //
201 vertices.push_back(p);
202 });
203 EXPECT_EQ(vertices.size(), vertex_count);
204 ASSERT_EQ(vertex_count % 4, 0u);
205
206 auto quadrant_count = vertex_count / 4;
207 for (size_t i = 0; i < quadrant_count; i++) {
208 double angle = kPiOver2 * i / (quadrant_count - 1);
209 double degrees = angle * 180.0 / kPi;
210 double rsin = sin(angle) * radius;
211 // Note that cos(radians(90 degrees)) isn't exactly 0.0 like it should be
212 double rcos = (i == quadrant_count - 1) ? 0.0f : cos(angle) * radius;
213 EXPECT_POINT_NEAR(vertices[i * 2],
214 Point(center.x - rcos, center.y + rsin))
215 << "vertex " << i << ", angle = " << degrees << std::endl;
216 EXPECT_POINT_NEAR(vertices[i * 2 + 1],
217 Point(center.x - rcos, center.y - rsin))
218 << "vertex " << i << ", angle = " << degrees << std::endl;
219 EXPECT_POINT_NEAR(vertices[vertex_count - i * 2 - 1],
220 Point(center.x + rcos, center.y - rsin))
221 << "vertex " << i << ", angle = " << degrees << std::endl;
222 EXPECT_POINT_NEAR(vertices[vertex_count - i * 2 - 2],
223 Point(center.x + rcos, center.y + rsin))
224 << "vertex " << i << ", angle = " << degrees << std::endl;
225 }
226 };
227
228 test({}, {}, 2.0);
229 test({}, {10, 10}, 2.0);
230 test(Matrix::MakeScale({500.0, 500.0, 0.0}), {}, 2.0);
231 test(Matrix::MakeScale({0.002, 0.002, 0.0}), {}, 1000.0);
232}

References EXPECT_POINT_NEAR, impeller::Tessellator::FilledCircle(), i, flutter::kPi, impeller::kPiOver2, impeller::kTriangleStrip, impeller::Matrix::MakeScale(), and transform.

◆ TEST() [659/689]

impeller::testing::TEST ( TessellatorTest  ,
FilledEllipseTessellationVertices   
)

Definition at line 455 of file tessellator_unittests.cc.

455 {
456 Tessellator tessellator;
457
458 auto test = [&tessellator](const Matrix& transform, const Rect& bounds) {
459 auto center = bounds.GetCenter();
460 auto half_size = bounds.GetSize() * 0.5f;
461
462 auto generator = tessellator.FilledEllipse(transform, bounds);
463 EXPECT_EQ(generator.GetTriangleType(), PrimitiveType::kTriangleStrip);
464
465 auto vertex_count = generator.GetVertexCount();
466 auto vertices = std::vector<Point>();
467 generator.GenerateVertices([&vertices](const Point& p) { //
468 vertices.push_back(p);
469 });
470 EXPECT_EQ(vertices.size(), vertex_count);
471 ASSERT_EQ(vertex_count % 4, 0u);
472
473 auto quadrant_count = vertex_count / 4;
474 for (size_t i = 0; i < quadrant_count; i++) {
475 double angle = kPiOver2 * i / (quadrant_count - 1);
476 double degrees = angle * 180.0 / kPi;
477 // Note that cos(radians(90 degrees)) isn't exactly 0.0 like it should be
478 double rcos =
479 (i == quadrant_count - 1) ? 0.0f : cos(angle) * half_size.width;
480 double rsin = sin(angle) * half_size.height;
481 EXPECT_POINT_NEAR(vertices[i * 2],
482 Point(center.x - rcos, center.y + rsin))
483 << "vertex " << i << ", angle = " << degrees << ", " //
484 << "bounds = " << bounds << std::endl;
485 EXPECT_POINT_NEAR(vertices[i * 2 + 1],
486 Point(center.x - rcos, center.y - rsin))
487 << "vertex " << i << ", angle = " << degrees << ", " //
488 << "bounds = " << bounds << std::endl;
489 EXPECT_POINT_NEAR(vertices[vertex_count - i * 2 - 1],
490 Point(center.x + rcos, center.y - rsin))
491 << "vertex " << i << ", angle = " << degrees << ", " //
492 << "bounds = " << bounds << std::endl;
493 EXPECT_POINT_NEAR(vertices[vertex_count - i * 2 - 2],
494 Point(center.x + rcos, center.y + rsin))
495 << "vertex " << i << ", angle = " << degrees << ", " //
496 << "bounds = " << bounds << std::endl;
497 }
498 };
499
500 // Square bounds should actually use the circle generator, but its
501 // results should match the same math as the ellipse generator.
502 test({}, Rect::MakeXYWH(0, 0, 2, 2));
503
504 test({}, Rect::MakeXYWH(0, 0, 2, 3));
505 test({}, Rect::MakeXYWH(0, 0, 3, 2));
506 test({}, Rect::MakeXYWH(5, 10, 2, 3));
507 test({}, Rect::MakeXYWH(16, 7, 3, 2));
508 test(Matrix::MakeScale({500.0, 500.0, 0.0}), Rect::MakeXYWH(5, 10, 3, 2));
509 test(Matrix::MakeScale({500.0, 500.0, 0.0}), Rect::MakeXYWH(5, 10, 2, 3));
510 test(Matrix::MakeScale({0.002, 0.002, 0.0}),
511 Rect::MakeXYWH(5000, 10000, 3000, 2000));
512 test(Matrix::MakeScale({0.002, 0.002, 0.0}),
513 Rect::MakeXYWH(5000, 10000, 2000, 3000));
514}
EllipticalVertexGenerator FilledEllipse(const Matrix &view_transform, const Rect &bounds)
Create a |VertexGenerator| that can produce vertices for a filled ellipse inscribed within the given ...

References EXPECT_POINT_NEAR, impeller::Tessellator::FilledEllipse(), i, flutter::kPi, impeller::kPiOver2, impeller::kTriangleStrip, impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeXYWH(), and transform.

◆ TEST() [660/689]

impeller::testing::TEST ( TessellatorTest  ,
FilledRoundRectTessellationVertices   
)

Definition at line 516 of file tessellator_unittests.cc.

516 {
517 Tessellator tessellator;
518
519 auto test = [&tessellator](const Matrix& transform, const Rect& bounds,
520 const Size& radii) {
521 FML_DCHECK(radii.width * 2 <= bounds.GetWidth()) << radii << bounds;
522 FML_DCHECK(radii.height * 2 <= bounds.GetHeight()) << radii << bounds;
523
524 Scalar middle_left = bounds.GetX() + radii.width;
525 Scalar middle_top = bounds.GetY() + radii.height;
526 Scalar middle_right = bounds.GetX() + bounds.GetWidth() - radii.width;
527 Scalar middle_bottom = bounds.GetY() + bounds.GetHeight() - radii.height;
528
529 auto generator = tessellator.FilledRoundRect(transform, bounds, radii);
530 EXPECT_EQ(generator.GetTriangleType(), PrimitiveType::kTriangleStrip);
531
532 auto vertex_count = generator.GetVertexCount();
533 auto vertices = std::vector<Point>();
534 generator.GenerateVertices([&vertices](const Point& p) { //
535 vertices.push_back(p);
536 });
537 EXPECT_EQ(vertices.size(), vertex_count);
538 ASSERT_EQ(vertex_count % 4, 0u);
539
540 auto quadrant_count = vertex_count / 4;
541 for (size_t i = 0; i < quadrant_count; i++) {
542 double angle = kPiOver2 * i / (quadrant_count - 1);
543 double degrees = angle * 180.0 / kPi;
544 // Note that cos(radians(90 degrees)) isn't exactly 0.0 like it should be
545 double rcos = (i == quadrant_count - 1) ? 0.0f : cos(angle) * radii.width;
546 double rsin = sin(angle) * radii.height;
547 EXPECT_POINT_NEAR(vertices[i * 2],
548 Point(middle_left - rcos, middle_bottom + rsin))
549 << "vertex " << i << ", angle = " << degrees << ", " //
550 << "bounds = " << bounds << std::endl;
551 EXPECT_POINT_NEAR(vertices[i * 2 + 1],
552 Point(middle_left - rcos, middle_top - rsin))
553 << "vertex " << i << ", angle = " << degrees << ", " //
554 << "bounds = " << bounds << std::endl;
555 EXPECT_POINT_NEAR(vertices[vertex_count - i * 2 - 1],
556 Point(middle_right + rcos, middle_top - rsin))
557 << "vertex " << i << ", angle = " << degrees << ", " //
558 << "bounds = " << bounds << std::endl;
559 EXPECT_POINT_NEAR(vertices[vertex_count - i * 2 - 2],
560 Point(middle_right + rcos, middle_bottom + rsin))
561 << "vertex " << i << ", angle = " << degrees << ", " //
562 << "bounds = " << bounds << std::endl;
563 }
564 };
565
566 // Both radii spanning the bounds should actually use the circle/ellipse
567 // generator, but their results should match the same math as the round
568 // rect generator.
569 test({}, Rect::MakeXYWH(0, 0, 20, 20), {10, 10});
570
571 // One radius spanning the bounds, but not the other will not match the
572 // round rect math if the generator transfers to circle/ellipse
573 test({}, Rect::MakeXYWH(0, 0, 20, 20), {10, 5});
574 test({}, Rect::MakeXYWH(0, 0, 20, 20), {5, 10});
575
576 test({}, Rect::MakeXYWH(0, 0, 20, 30), {2, 2});
577 test({}, Rect::MakeXYWH(0, 0, 30, 20), {2, 2});
578 test({}, Rect::MakeXYWH(5, 10, 20, 30), {2, 3});
579 test({}, Rect::MakeXYWH(16, 7, 30, 20), {2, 3});
580 test(Matrix::MakeScale({500.0, 500.0, 0.0}), Rect::MakeXYWH(5, 10, 30, 20),
581 {2, 3});
582 test(Matrix::MakeScale({500.0, 500.0, 0.0}), Rect::MakeXYWH(5, 10, 20, 30),
583 {2, 3});
584 test(Matrix::MakeScale({0.002, 0.002, 0.0}),
585 Rect::MakeXYWH(5000, 10000, 3000, 2000), {50, 70});
586 test(Matrix::MakeScale({0.002, 0.002, 0.0}),
587 Rect::MakeXYWH(5000, 10000, 2000, 3000), {50, 70});
588}
EllipticalVertexGenerator FilledRoundRect(const Matrix &view_transform, const Rect &bounds, const Size &radii)
Create a |VertexGenerator| that can produce vertices for a filled round rect within the given bounds ...

References EXPECT_POINT_NEAR, impeller::Tessellator::FilledRoundRect(), FML_DCHECK, i, flutter::kPi, impeller::kPiOver2, impeller::kTriangleStrip, impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeXYWH(), and transform.

◆ TEST() [661/689]

impeller::testing::TEST ( TessellatorTest  ,
RoundCapLineTessellationVertices   
)

Definition at line 382 of file tessellator_unittests.cc.

382 {
383 Tessellator tessellator;
384
385 auto test = [&tessellator](const Matrix& transform, const Point& p0,
386 const Point& p1, Scalar radius) {
387 auto generator = tessellator.RoundCapLine(transform, p0, p1, radius);
388 EXPECT_EQ(generator.GetTriangleType(), PrimitiveType::kTriangleStrip);
389
390 auto vertex_count = generator.GetVertexCount();
391 auto vertices = std::vector<Point>();
392 generator.GenerateVertices([&vertices](const Point& p) { //
393 vertices.push_back(p);
394 });
395 EXPECT_EQ(vertices.size(), vertex_count);
396 ASSERT_EQ(vertex_count % 4, 0u);
397
398 Point along = p1 - p0;
399 Scalar length = along.GetLength();
400 if (length > 0) {
401 along *= radius / length;
402 } else {
403 along = {radius, 0};
404 }
405 Point across = {-along.y, along.x};
406
407 auto quadrant_count = vertex_count / 4;
408 for (size_t i = 0; i < quadrant_count; i++) {
409 double angle = kPiOver2 * i / (quadrant_count - 1);
410 double degrees = angle * 180.0 / kPi;
411 // Note that cos(radians(90 degrees)) isn't exactly 0.0 like it should be
412 Point relative_along =
413 along * ((i == quadrant_count - 1) ? 0.0f : cos(angle));
414 Point relative_across = across * sin(angle);
415 EXPECT_POINT_NEAR(vertices[i * 2], //
416 p0 - relative_along + relative_across)
417 << "vertex " << i << ", angle = " << degrees << ", " //
418 << "line = " << p0 << " => " << p1 << ", " //
419 << "radius = " << radius << std::endl;
420 EXPECT_POINT_NEAR(vertices[i * 2 + 1], //
421 p0 - relative_along - relative_across)
422 << "vertex " << i << ", angle = " << degrees << ", " //
423 << "line = " << p0 << " => " << p1 << ", " //
424 << "radius = " << radius << std::endl;
425 EXPECT_POINT_NEAR(vertices[vertex_count - i * 2 - 1], //
426 p1 + relative_along - relative_across)
427 << "vertex " << i << ", angle = " << degrees << ", " //
428 << "line = " << p0 << " => " << p1 << ", " //
429 << "radius = " << radius << std::endl;
430 EXPECT_POINT_NEAR(vertices[vertex_count - i * 2 - 2], //
431 p1 + relative_along + relative_across)
432 << "vertex " << i << ", angle = " << degrees << ", " //
433 << "line = " << p0 << " => " << p1 << ", " //
434 << "radius = " << radius << std::endl;
435 }
436 };
437
438 // Empty line should actually use the circle generator, but its
439 // results should match the same math as the round cap generator.
440 test({}, {0, 0}, {0, 0}, 10);
441
442 test({}, {0, 0}, {10, 0}, 2);
443 test({}, {10, 0}, {0, 0}, 2);
444 test({}, {0, 0}, {10, 10}, 2);
445
446 test(Matrix::MakeScale({500.0, 500.0, 0.0}), {0, 0}, {10, 0}, 2);
447 test(Matrix::MakeScale({500.0, 500.0, 0.0}), {10, 0}, {0, 0}, 2);
448 test(Matrix::MakeScale({500.0, 500.0, 0.0}), {0, 0}, {10, 10}, 2);
449
450 test(Matrix::MakeScale({0.002, 0.002, 0.0}), {0, 0}, {10, 0}, 2);
451 test(Matrix::MakeScale({0.002, 0.002, 0.0}), {10, 0}, {0, 0}, 2);
452 test(Matrix::MakeScale({0.002, 0.002, 0.0}), {0, 0}, {10, 10}, 2);
453}
EllipticalVertexGenerator RoundCapLine(const Matrix &view_transform, const Point &p0, const Point &p1, Scalar radius)
Create a |VertexGenerator| that can produce vertices for a line with round end caps of the given radi...
constexpr Scalar GetLength() const
Definition point.h:210

References EXPECT_POINT_NEAR, i, flutter::kPi, impeller::kPiOver2, impeller::kTriangleStrip, length, impeller::Matrix::MakeScale(), p1, impeller::Tessellator::RoundCapLine(), transform, flutter::Point::x(), and flutter::Point::y().

◆ TEST() [662/689]

impeller::testing::TEST ( TessellatorTest  ,
StrokedCircleTessellationVertices   
)

Definition at line 234 of file tessellator_unittests.cc.

234 {
235 Tessellator tessellator;
236
237 auto test = [&tessellator](const Matrix& transform, const Point& center,
238 Scalar radius, Scalar half_width) {
239 ASSERT_GT(radius, half_width);
240 auto generator =
241 tessellator.StrokedCircle(transform, center, radius, half_width);
242 EXPECT_EQ(generator.GetTriangleType(), PrimitiveType::kTriangleStrip);
243
244 auto vertex_count = generator.GetVertexCount();
245 auto vertices = std::vector<Point>();
246 generator.GenerateVertices([&vertices](const Point& p) { //
247 vertices.push_back(p);
248 });
249 EXPECT_EQ(vertices.size(), vertex_count);
250 ASSERT_EQ(vertex_count % 4, 0u);
251
252 auto quadrant_count = vertex_count / 8;
253
254 // Test outer points first
255 for (size_t i = 0; i < quadrant_count; i++) {
256 double angle = kPiOver2 * i / (quadrant_count - 1);
257 double degrees = angle * 180.0 / kPi;
258 double rsin = sin(angle) * (radius + half_width);
259 // Note that cos(radians(90 degrees)) isn't exactly 0.0 like it should be
260 double rcos =
261 (i == quadrant_count - 1) ? 0.0f : cos(angle) * (radius + half_width);
262 EXPECT_POINT_NEAR(vertices[i * 2],
263 Point(center.x - rcos, center.y - rsin))
264 << "vertex " << i << ", angle = " << degrees << std::endl;
265 EXPECT_POINT_NEAR(vertices[quadrant_count * 2 + i * 2],
266 Point(center.x + rsin, center.y - rcos))
267 << "vertex " << i << ", angle = " << degrees << std::endl;
268 EXPECT_POINT_NEAR(vertices[quadrant_count * 4 + i * 2],
269 Point(center.x + rcos, center.y + rsin))
270 << "vertex " << i << ", angle = " << degrees << std::endl;
271 EXPECT_POINT_NEAR(vertices[quadrant_count * 6 + i * 2],
272 Point(center.x - rsin, center.y + rcos))
273 << "vertex " << i << ", angle = " << degrees << std::endl;
274 }
275
276 // Then test innerer points
277 for (size_t i = 0; i < quadrant_count; i++) {
278 double angle = kPiOver2 * i / (quadrant_count - 1);
279 double degrees = angle * 180.0 / kPi;
280 double rsin = sin(angle) * (radius - half_width);
281 // Note that cos(radians(90 degrees)) isn't exactly 0.0 like it should be
282 double rcos =
283 (i == quadrant_count - 1) ? 0.0f : cos(angle) * (radius - half_width);
284 EXPECT_POINT_NEAR(vertices[i * 2 + 1],
285 Point(center.x - rcos, center.y - rsin))
286 << "vertex " << i << ", angle = " << degrees << std::endl;
287 EXPECT_POINT_NEAR(vertices[quadrant_count * 2 + i * 2 + 1],
288 Point(center.x + rsin, center.y - rcos))
289 << "vertex " << i << ", angle = " << degrees << std::endl;
290 EXPECT_POINT_NEAR(vertices[quadrant_count * 4 + i * 2 + 1],
291 Point(center.x + rcos, center.y + rsin))
292 << "vertex " << i << ", angle = " << degrees << std::endl;
293 EXPECT_POINT_NEAR(vertices[quadrant_count * 6 + i * 2 + 1],
294 Point(center.x - rsin, center.y + rcos))
295 << "vertex " << i << ", angle = " << degrees << std::endl;
296 }
297 };
298
299 test({}, {}, 2.0, 1.0);
300 test({}, {}, 2.0, 0.5);
301 test({}, {10, 10}, 2.0, 1.0);
302 test(Matrix::MakeScale({500.0, 500.0, 0.0}), {}, 2.0, 1.0);
303 test(Matrix::MakeScale({0.002, 0.002, 0.0}), {}, 1000.0, 10.0);
304}
EllipticalVertexGenerator StrokedCircle(const Matrix &view_transform, const Point &center, Scalar radius, Scalar half_width)
Create a |VertexGenerator| that can produce vertices for a stroked circle of the given radius and hal...

References EXPECT_POINT_NEAR, i, flutter::kPi, impeller::kPiOver2, impeller::kTriangleStrip, impeller::Matrix::MakeScale(), impeller::Tessellator::StrokedCircle(), and transform.

◆ TEST() [663/689]

impeller::testing::TEST ( TessellatorTest  ,
TessellateConvex   
)

Definition at line 97 of file tessellator_unittests.cc.

97 {
98 {
99 std::vector<Point> points;
100 std::vector<uint16_t> indices;
101 // Sanity check simple rectangle.
102 Tessellator::TessellateConvexInternal(
103 flutter::DlPath::MakeRect(Rect::MakeLTRB(0, 0, 10, 10)), points,
104 indices, 1.0);
105
106 // Note: the origin point is repeated but not referenced in the indices
107 // below
108 std::vector<Point> expected = {{0, 0}, {10, 0}, {10, 10}, {0, 10}, {0, 0}};
109 std::vector<uint16_t> expected_indices = {0, 1, 3, 2};
110 EXPECT_EQ(points, expected);
111 EXPECT_EQ(indices, expected_indices);
112 }
113
114 {
115 std::vector<Point> points;
116 std::vector<uint16_t> indices;
117 Tessellator::TessellateConvexInternal(
119 .AddRect(Rect::MakeLTRB(0, 0, 10, 10))
120 .AddRect(Rect::MakeLTRB(20, 20, 30, 30))
121 .TakePath()),
122 points, indices, 1.0);
123
124 std::vector<Point> expected = {{0, 0}, {10, 0}, {10, 10}, {0, 10},
125 {0, 0}, {20, 20}, {30, 20}, {30, 30},
126 {20, 30}, {20, 20}};
127 std::vector<uint16_t> expected_indices = {0, 1, 3, 2, 2, 5, 5, 6, 8, 7};
128 EXPECT_EQ(points, expected);
129 EXPECT_EQ(indices, expected_indices);
130 }
131}
static DlPath MakeRect(const DlRect &rect)
Definition dl_path.cc:39

References flutter::DlPathBuilder::AddRect(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRect(), points, and impeller::Tessellator::TessellateConvexInternal().

◆ TEST() [664/689]

impeller::testing::TEST ( TessellatorTest  ,
TessellateConvexUnclosedPath   
)

Definition at line 134 of file tessellator_unittests.cc.

134 {
135 std::vector<Point> points;
136 std::vector<uint16_t> indices;
137
138 // Create a rectangle that lacks an explicit close.
140 .LineTo({100, 0})
141 .LineTo({100, 100})
142 .LineTo({0, 100})
143 .TakePath();
144 Tessellator::TessellateConvexInternal(flutter::DlPath(path), points, indices,
145 1.0);
146
147 std::vector<Point> expected = {
148 {0, 0}, {100, 0}, {100, 100}, {0, 100}, {0, 0}};
149 std::vector<uint16_t> expected_indices = {0, 1, 3, 2};
150 EXPECT_EQ(points, expected);
151 EXPECT_EQ(indices, expected_indices);
152}

References flutter::DlPathBuilder::LineTo(), impeller::LineTo(), flutter::path, points, and impeller::Tessellator::TessellateConvexInternal().

◆ TEST() [665/689]

impeller::testing::TEST ( TessellatorTest  ,
TessellatorBuilderReturnsCorrectResultStatus   
)

Definition at line 17 of file tessellator_unittests.cc.

17 {
18 // Zero points.
19 {
22 .SetFillType(FillType::kOdd)
23 .TakePath();
25 path, 1.0f,
26 [](const float* vertices, size_t vertices_count,
27 const uint16_t* indices, size_t indices_count) { return true; });
28
29 ASSERT_EQ(result, TessellatorLibtess::Result::kInputError);
30 }
31
32 // One point.
33 {
34 TessellatorLibtess t;
36 .LineTo({0, 0})
37 .SetFillType(FillType::kOdd)
38 .TakePath();
39 TessellatorLibtess::Result result = t.Tessellate(
40 path, 1.0f,
41 [](const float* vertices, size_t vertices_count,
42 const uint16_t* indices, size_t indices_count) { return true; });
43
44 ASSERT_EQ(result, TessellatorLibtess::Result::kSuccess);
45 }
46
47 // Two points.
48 {
49 TessellatorLibtess t;
51 .MoveTo({0, 0})
52 .LineTo({0, 1})
53 .SetFillType(FillType::kOdd)
54 .TakePath();
55 TessellatorLibtess::Result result = t.Tessellate(
56 path, 1.0f,
57 [](const float* vertices, size_t vertices_count,
58 const uint16_t* indices, size_t indices_count) { return true; });
59
60 ASSERT_EQ(result, TessellatorLibtess::Result::kSuccess);
61 }
62
63 // Many points.
64 {
65 TessellatorLibtess t;
67 for (int i = 0; i < 1000; i++) {
68 auto coord = i * 1.0f;
69 builder.MoveTo({coord, coord}).LineTo({coord + 1, coord + 1});
70 }
71 auto path = builder.SetFillType(FillType::kOdd).TakePath();
72 TessellatorLibtess::Result result = t.Tessellate(
73 path, 1.0f,
74 [](const float* vertices, size_t vertices_count,
75 const uint16_t* indices, size_t indices_count) { return true; });
76
77 ASSERT_EQ(result, TessellatorLibtess::Result::kSuccess);
78 }
79
80 // Closure fails.
81 {
82 TessellatorLibtess t;
84 .MoveTo({0, 0})
85 .LineTo({0, 1})
86 .SetFillType(FillType::kOdd)
87 .TakePath();
88 TessellatorLibtess::Result result = t.Tessellate(
89 path, 1.0f,
90 [](const float* vertices, size_t vertices_count,
91 const uint16_t* indices, size_t indices_count) { return false; });
92
93 ASSERT_EQ(result, TessellatorLibtess::Result::kInputError);
94 }
95}
DlPathBuilder & SetFillType(DlPathFillType fill_type)
Set the fill type that should be used to determine the interior of this path to the indicated |fill_t...
An extended tessellator that offers arbitrary/concave tessellation via the libtess2 library.
TessellatorLibtess::Result Tessellate(const PathSource &source, Scalar tolerance, const BuilderCallback &callback)
Generates filled triangles from the path. A callback is invoked once for the entire tessellation.

References i, impeller::TessellatorLibtess::kInputError, impeller::kOdd, impeller::TessellatorLibtess::kSuccess, flutter::DlPathBuilder::LineTo(), impeller::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DlPathBuilder::SetFillType(), flutter::DlPathBuilder::TakePath(), and impeller::TessellatorLibtess::Tessellate().

◆ TEST() [666/689]

impeller::testing::TEST ( ThreadTest  ,
CanCreateMutex   
)

Definition at line 36 of file base_unittests.cc.

36 {
37 Foo f = {};
38
39 // f.a = 100; <--- Static analysis error.
40 f.mtx.Lock();
41 f.a = 100;
42 f.mtx.Unlock();
43}

References impeller::testing::Foo::mtx.

◆ TEST() [667/689]

impeller::testing::TEST ( ThreadTest  ,
CanCreateMutexLock   
)

Definition at line 45 of file base_unittests.cc.

45 {
46 Foo f = {};
47
48 // f.a = 100; <--- Static analysis error.
49 auto a = Lock(f.mtx);
50 f.a = 100;
51}

References impeller::testing::Foo::mtx.

◆ TEST() [668/689]

impeller::testing::TEST ( ThreadTest  ,
CanCreateRWMutex   
)

Definition at line 53 of file base_unittests.cc.

53 {
54 RWFoo f = {};
55
56 // f.a = 100; <--- Static analysis error.
57 f.mtx.LockWriter();
58 f.a = 100;
59 f.mtx.UnlockWriter();
60 // int b = f.a; <--- Static analysis error.
61 f.mtx.LockReader();
62 [[maybe_unused]] int b = f.a; // NOLINT(clang-analyzer-deadcode.DeadStores)
63 f.mtx.UnlockReader();
64}

References impeller::testing::RWFoo::mtx.

◆ TEST() [669/689]

impeller::testing::TEST ( ThreadTest  ,
CanCreateRWMutexLock   
)

Definition at line 66 of file base_unittests.cc.

66 {
67 RWFoo f = {};
68
69 // f.a = 100; <--- Static analysis error.
70 {
71 auto write_lock = WriterLock{f.mtx};
72 f.a = 100;
73 }
74
75 // int b = f.a; <--- Static analysis error.
76 {
77 auto read_lock = ReaderLock(f.mtx);
78 [[maybe_unused]] int b = f.a; // NOLINT(clang-analyzer-deadcode.DeadStores)
79 }
80
81 // f.mtx.UnlockReader(); <--- Static analysis error.
82}

References impeller::testing::RWFoo::mtx.

◆ TEST() [670/689]

impeller::testing::TEST ( TrigTest  ,
MultiplyByScalarRadius   
)

Definition at line 65 of file trig_unittests.cc.

65 {
66 for (int i = 0; i <= 360; i++) {
67 for (int i = 1; i <= 10; i++) {
68 Scalar radius = i * 5.0f;
69 EXPECT_EQ(Trig(Degrees(i)) * radius,
70 Point(radius * std::cos(i * kPi / 180),
71 radius * std::sin(i * kPi / 180)))
72 << "at " << i << " degrees and radius " << radius;
73 }
74 }
75}
A structure to store the sine and cosine of an angle.
Definition trig.h:16

References i, and flutter::kPi.

◆ TEST() [671/689]

impeller::testing::TEST ( TrigTest  ,
TrigAngles   
)

Definition at line 15 of file trig_unittests.cc.

15 {
16 {
17 Trig trig(Degrees(0.0));
18 EXPECT_EQ(trig.cos, 1.0);
19 EXPECT_EQ(trig.sin, 0.0);
20 }
21
22 {
23 Trig trig(Radians(0.0));
24 EXPECT_EQ(trig.cos, 1.0);
25 EXPECT_EQ(trig.sin, 0.0);
26 }
27
28 {
29 Trig trig(Degrees(30.0));
30 EXPECT_NEAR(trig.cos, sqrt(0.75), kEhCloseEnough);
31 EXPECT_NEAR(trig.sin, 0.5, kEhCloseEnough);
32 }
33
34 {
35 Trig trig(Radians(kPi / 6.0));
36 EXPECT_NEAR(trig.cos, sqrt(0.75), kEhCloseEnough);
37 EXPECT_NEAR(trig.sin, 0.5, kEhCloseEnough);
38 }
39
40 {
41 Trig trig(Degrees(60.0));
42 EXPECT_NEAR(trig.cos, 0.5, kEhCloseEnough);
43 EXPECT_NEAR(trig.sin, sqrt(0.75), kEhCloseEnough);
44 }
45
46 {
47 Trig trig(Radians(kPi / 3.0));
48 EXPECT_NEAR(trig.cos, 0.5, kEhCloseEnough);
49 EXPECT_NEAR(trig.sin, sqrt(0.75), kEhCloseEnough);
50 }
51
52 {
53 Trig trig(Degrees(90.0));
54 EXPECT_NEAR(trig.cos, 0.0, kEhCloseEnough);
55 EXPECT_NEAR(trig.sin, 1.0, kEhCloseEnough);
56 }
57
58 {
59 Trig trig(Radians(kPi / 2.0));
60 EXPECT_NEAR(trig.cos, 0.0, kEhCloseEnough);
61 EXPECT_NEAR(trig.sin, 1.0, kEhCloseEnough);
62 }
63}

References impeller::Trig::cos, flutter::kEhCloseEnough, flutter::kPi, and impeller::Trig::sin.

◆ TEST() [672/689]

impeller::testing::TEST ( TypographerTest  ,
RectanglePackerFillsRows   
)

Definition at line 456 of file typographer_unittests.cc.

456 {
457 auto skyline = RectanglePacker::Factory(257, 256);
458
459 // Fill up the first row.
460 IPoint16 loc;
461 for (auto i = 0u; i < 16; i++) {
462 skyline->AddRect(16, 16, &loc);
463 }
464 // Last rectangle still in first row.
465 EXPECT_EQ(loc.x(), 256 - 16);
466 EXPECT_EQ(loc.y(), 0);
467
468 // Fill up second row.
469 for (auto i = 0u; i < 16; i++) {
470 skyline->AddRect(16, 16, &loc);
471 }
472
473 EXPECT_EQ(loc.x(), 256 - 16);
474 EXPECT_EQ(loc.y(), 16);
475}
int16_t y() const
int16_t x() const

References impeller::RectanglePacker::Factory(), i, impeller::IPoint16::x(), and impeller::IPoint16::y().

◆ TEST() [673/689]

impeller::testing::TEST ( UberSDFContentsTest  ,
ApplyColorFilter   
)

Definition at line 16 of file uber_sdf_contents_unittests.cc.

16 {
17 auto rect = Rect::MakeXYWH(100, 100, 200, 200);
18 auto params =
19 UberSDFParameters::MakeRect(Color::Red(), rect, /*stroke=*/std::nullopt);
20 auto geometry = std::make_unique<UberSDFGeometry>(params);
21 auto contents = UberSDFContents::Make(params, std::move(geometry));
22
23 EXPECT_EQ(contents->GetColor(), Color::Red());
24
25 bool result =
26 contents->ApplyColorFilter([](Color color) { return Color::Blue(); });
27
28 EXPECT_TRUE(result);
29 EXPECT_EQ(contents->GetColor(), Color::Blue());
30}

References impeller::Color::Blue(), impeller::UberSDFContents::Make(), impeller::UberSDFParameters::MakeRect(), impeller::TRect< Scalar >::MakeXYWH(), params, and impeller::Color::Red().

◆ TEST() [674/689]

impeller::testing::TEST ( UberSDFContentsTest  ,
AsBackgroundColor   
)

Definition at line 32 of file uber_sdf_contents_unittests.cc.

32 {
33 auto rect = Rect::MakeXYWH(-2, -2, 504, 504);
34 auto params =
35 UberSDFParameters::MakeRect(Color::Red(), rect, /*stroke=*/std::nullopt);
36 auto geometry = std::make_unique<UberSDFGeometry>(params);
37 auto contents = UberSDFContents::Make(params, std::move(geometry));
38
39 Entity entity;
40 entity.SetTransform(Matrix());
41
42 EXPECT_EQ(contents->AsBackgroundColor(entity, ISize(500, 500)), Color::Red());
43
44 auto small_bg_color = contents->AsBackgroundColor(entity, ISize(400, 400));
45 EXPECT_TRUE(small_bg_color.has_value());
46 if (small_bg_color.has_value()) {
47 EXPECT_EQ(small_bg_color.value(), Color::Red());
48 }
49
50 auto huge_bg_color = contents->AsBackgroundColor(entity, ISize(600, 600));
51 EXPECT_FALSE(huge_bg_color.has_value());
52}

References impeller::UberSDFContents::Make(), impeller::UberSDFParameters::MakeRect(), impeller::TRect< Scalar >::MakeXYWH(), params, impeller::Color::Red(), and impeller::Entity::SetTransform().

◆ TEST() [675/689]

impeller::testing::TEST ( UberSDFContentsTest  ,
AsBackgroundColorExactSize   
)

Definition at line 54 of file uber_sdf_contents_unittests.cc.

54 {
55 auto rect = Rect::MakeXYWH(0, 0, 500, 500);
56 auto params =
57 UberSDFParameters::MakeRect(Color::Red(), rect, /*stroke=*/std::nullopt);
58 auto geometry = std::make_unique<UberSDFGeometry>(params);
59 auto contents = UberSDFContents::Make(params, std::move(geometry));
60
61 Entity entity;
62 entity.SetTransform(Matrix());
63
64 auto bg_color = contents->AsBackgroundColor(entity, ISize(500, 500));
65 // The exact size now returns true because over-conservative AA insets are
66 // removed
67 EXPECT_TRUE(bg_color.has_value());
68 if (bg_color.has_value()) {
69 EXPECT_EQ(bg_color.value(), Color::Red());
70 }
71}

References impeller::UberSDFContents::Make(), impeller::UberSDFParameters::MakeRect(), impeller::TRect< Scalar >::MakeXYWH(), params, impeller::Color::Red(), and impeller::Entity::SetTransform().

◆ TEST() [676/689]

impeller::testing::TEST ( UberSDFContentsTest  ,
AsBackgroundColorNonRect   
)

Definition at line 73 of file uber_sdf_contents_unittests.cc.

73 {
74 Entity entity;
75 entity.SetTransform(Matrix());
76
77 // Non-rect shape (Circle) should return nullopt
78 auto circle_params = UberSDFParameters::MakeCircle(
79 Color::Red(), Point(250, 250), 250.0f, /*stroke=*/std::nullopt);
80 auto circle_geometry = std::make_unique<UberSDFGeometry>(circle_params);
81 auto circle_contents =
82 UberSDFContents::Make(circle_params, std::move(circle_geometry));
83
84 auto circle_bg_color =
85 circle_contents->AsBackgroundColor(entity, ISize(500, 500));
86 EXPECT_FALSE(circle_bg_color.has_value());
87}

References impeller::UberSDFContents::Make(), impeller::UberSDFParameters::MakeCircle(), impeller::Color::Red(), and impeller::Entity::SetTransform().

◆ TEST() [677/689]

impeller::testing::TEST ( UberSDFContentsTest  ,
AsBackgroundColorStrokedRect   
)

Definition at line 89 of file uber_sdf_contents_unittests.cc.

89 {
90 auto rect = Rect::MakeXYWH(-2, -2, 504, 504);
91 auto params = UberSDFParameters::MakeRect(Color::Red(), rect,
92 StrokeParameters{.width = 2.0f});
93 auto geometry = std::make_unique<UberSDFGeometry>(params);
94 auto contents = UberSDFContents::Make(params, std::move(geometry));
95
96 Entity entity;
97 entity.SetTransform(Matrix());
98
99 auto bg_color = contents->AsBackgroundColor(entity, ISize(500, 500));
100 EXPECT_FALSE(bg_color.has_value());
101}

References impeller::UberSDFContents::Make(), impeller::UberSDFParameters::MakeRect(), impeller::TRect< Scalar >::MakeXYWH(), params, impeller::Color::Red(), impeller::Entity::SetTransform(), and impeller::StrokeParameters::width.

◆ TEST() [678/689]

impeller::testing::TEST ( UberSDFParametersTest  ,
MakeFillCircle   
)

Definition at line 49 of file uber_sdf_parameters_unittests.cc.

49 {
50 Point center = {50, 50};
51 auto params =
52 UberSDFParameters::MakeCircle(Color::Red(), center, 10.0f, std::nullopt);
53
54 EXPECT_EQ(params.type, UberSDFParameters::Type::kCircle);
55 EXPECT_EQ(params.color, Color::Red());
56 EXPECT_EQ(params.center, center);
57 EXPECT_EQ(params.size, Point(10.0f, 10.0f));
58 EXPECT_FALSE(params.stroke.has_value());
59}

References impeller::UberSDFParameters::kCircle, impeller::UberSDFParameters::MakeCircle(), params, and impeller::Color::Red().

◆ TEST() [679/689]

impeller::testing::TEST ( UberSDFParametersTest  ,
MakeFillOval   
)

Definition at line 74 of file uber_sdf_parameters_unittests.cc.

74 {
75 Point center = {25, 25};
76 Size size = Size(50, 50);
77 Rect bounds = Rect::MakeOriginSize(Point(), size);
78
79 auto params = UberSDFParameters::MakeOval(Color::Red(), bounds, std::nullopt);
80
81 EXPECT_EQ(params.type, UberSDFParameters::Type::kOval);
82 EXPECT_EQ(params.color, Color::Red());
83 EXPECT_EQ(params.center, center);
84 EXPECT_EQ(params.size, Point(size) * 0.5f);
85 EXPECT_FALSE(params.stroke.has_value());
86}

References impeller::UberSDFParameters::kOval, impeller::TRect< Scalar >::MakeOriginSize(), impeller::UberSDFParameters::MakeOval(), params, impeller::Color::Red(), and flutter::size.

◆ TEST() [680/689]

impeller::testing::TEST ( UberSDFParametersTest  ,
MakeFillRect   
)

Definition at line 12 of file uber_sdf_parameters_unittests.cc.

12 {
13 auto rect = Rect::MakeLTRB(100, 100, 200, 200);
14 auto params = UberSDFParameters::MakeRect(Color::Red(), rect, std::nullopt);
15
16 EXPECT_EQ(params.type, UberSDFParameters::Type::kRect);
17 EXPECT_EQ(params.color, Color::Red());
18 EXPECT_EQ(params.center, Point(150, 150));
19 EXPECT_EQ(params.size, Point(50, 50));
20 EXPECT_FALSE(params.stroke.has_value());
21}

References impeller::UberSDFParameters::kRect, impeller::TRect< Scalar >::MakeLTRB(), impeller::UberSDFParameters::MakeRect(), params, and impeller::Color::Red().

◆ TEST() [681/689]

impeller::testing::TEST ( UberSDFParametersTest  ,
MakeRoundedRect   
)

Definition at line 103 of file uber_sdf_parameters_unittests.cc.

103 {
104 Rect rect = Rect::MakeXYWH(10, 20, 100, 100);
105 RoundingRadii radii = {
106 .top_left = Size(1.0f, 1.0f),
107 .top_right = Size(2.0f, 2.0f),
108 .bottom_left = Size(3.0f, 3.0f),
109 .bottom_right = Size(4.0f, 4.0f),
110 };
111 auto params = UberSDFParameters::MakeRoundedRect(
112 /*color=*/Color::Red(), /*rect=*/rect, /*radii=*/radii,
113 /*stroke=*/std::nullopt);
114
115 EXPECT_EQ(params.type, UberSDFParameters::Type::kRoundedRect);
116 EXPECT_EQ(params.color, Color::Red());
117 EXPECT_EQ(params.center, Point(60, 70));
118 EXPECT_EQ(params.size, Point(50, 50));
119 EXPECT_EQ(params.radii.w, 1.0f);
120 EXPECT_EQ(params.radii.y, 2.0f);
121 EXPECT_EQ(params.radii.z, 3.0f);
122 EXPECT_EQ(params.radii.x, 4.0f);
123 EXPECT_FALSE(params.stroke.has_value());
124}

References impeller::UberSDFParameters::kRoundedRect, impeller::UberSDFParameters::MakeRoundedRect(), impeller::TRect< Scalar >::MakeXYWH(), params, impeller::Color::Red(), and impeller::RoundingRadii::top_left.

◆ TEST() [682/689]

impeller::testing::TEST ( UberSDFParametersTest  ,
MakeRoundedSuperellipse   
)

Definition at line 126 of file uber_sdf_parameters_unittests.cc.

126 {
127 Rect rect = Rect::MakeXYWH(10, 20, 100, 100);
128 RoundingRadii radii = {
129 .top_left = Size(10.0f, 10.0f),
130 .top_right = Size(10.0f, 10.0f),
131 .bottom_left = Size(10.0f, 10.0f),
132 .bottom_right = Size(10.0f, 10.0f),
133 };
134 auto round_superellipse_params =
135 RoundSuperellipseParam::MakeBoundsRadii(rect, radii);
136 auto params = UberSDFParameters::MakeRoundedSuperellipse(
137 /*color=*/Color::Red(), /*bounds=*/rect,
138 /*round_superellipse_params=*/round_superellipse_params,
139 /*stroke=*/std::nullopt);
140
141 EXPECT_EQ(params.type,
142 UberSDFParameters::Type::kRoundedSuperellipseSymmetric);
143 EXPECT_EQ(params.color, Color::Red());
144 EXPECT_EQ(params.center, Point(60, 70));
145 EXPECT_EQ(params.size, Point(50, 50));
146 EXPECT_FALSE(params.stroke.has_value());
147
148 EXPECT_EQ(params.radii.x,
149 round_superellipse_params.top_right.top.circle_radius);
150 EXPECT_EQ(params.radii.y,
151 round_superellipse_params.top_right.right.circle_radius);
152
153 EXPECT_EQ(params.superellipse_degree.x,
154 round_superellipse_params.top_right.top.se_n);
155 EXPECT_EQ(params.superellipse_degree.y,
156 round_superellipse_params.top_right.right.se_n);
157
158 EXPECT_EQ(params.superellipse_scale.x,
159 round_superellipse_params.top_right.signed_scale.Abs().x);
160 EXPECT_EQ(params.superellipse_scale.y,
161 round_superellipse_params.top_right.signed_scale.Abs().y);
162}

References impeller::UberSDFParameters::kRoundedSuperellipseSymmetric, impeller::RoundSuperellipseParam::MakeBoundsRadii(), impeller::UberSDFParameters::MakeRoundedSuperellipse(), impeller::TRect< Scalar >::MakeXYWH(), params, impeller::Color::Red(), and impeller::RoundingRadii::top_left.

◆ TEST() [683/689]

impeller::testing::TEST ( UberSDFParametersTest  ,
MakeStrokeCircle   
)

Definition at line 61 of file uber_sdf_parameters_unittests.cc.

61 {
62 Point center = {50, 50};
63 StrokeParameters stroke = {.width = 4.0f};
64 auto params =
65 UberSDFParameters::MakeCircle(Color::Red(), center, 10.0f, stroke);
66
67 EXPECT_EQ(params.type, UberSDFParameters::Type::kCircle);
68 EXPECT_EQ(params.color, Color::Red());
69 EXPECT_EQ(params.center, center);
70 EXPECT_EQ(params.size, Point(10.0f, 10.0f));
71 EXPECT_EQ(params.stroke, stroke);
72}

References impeller::UberSDFParameters::kCircle, impeller::UberSDFParameters::MakeCircle(), params, impeller::Color::Red(), and impeller::StrokeParameters::width.

◆ TEST() [684/689]

impeller::testing::TEST ( UberSDFParametersTest  ,
MakeStrokeOval   
)

Definition at line 88 of file uber_sdf_parameters_unittests.cc.

88 {
89 Point center = {25, 25};
90 Size size = Size(50, 50);
91 Rect bounds = Rect::MakeOriginSize(Point(), size);
92 StrokeParameters stroke = {.width = 4.0f};
93
94 auto params = UberSDFParameters::MakeOval(Color::Red(), bounds, stroke);
95
96 EXPECT_EQ(params.type, UberSDFParameters::Type::kOval);
97 EXPECT_EQ(params.color, Color::Red());
98 EXPECT_EQ(params.center, center);
99 EXPECT_EQ(params.size, Point(size) * 0.5f);
100 EXPECT_EQ(params.stroke, stroke);
101}

References impeller::UberSDFParameters::kOval, impeller::TRect< Scalar >::MakeOriginSize(), impeller::UberSDFParameters::MakeOval(), params, impeller::Color::Red(), flutter::size, and impeller::StrokeParameters::width.

◆ TEST() [685/689]

impeller::testing::TEST ( UberSDFParametersTest  ,
MakeStrokeRect   
)

Definition at line 23 of file uber_sdf_parameters_unittests.cc.

23 {
24 auto rect = Rect::MakeLTRB(100, 100, 200, 200);
25 StrokeParameters stroke = {.width = 4.0f};
26 auto params = UberSDFParameters::MakeRect(Color::Red(), rect, stroke);
27
28 EXPECT_EQ(params.type, UberSDFParameters::Type::kRect);
29 EXPECT_EQ(params.color, Color::Red());
30 EXPECT_EQ(params.center, Point(150, 150));
31 EXPECT_EQ(params.size, Point(50, 50));
32 EXPECT_EQ(params.stroke, stroke);
33}

References impeller::UberSDFParameters::kRect, impeller::TRect< Scalar >::MakeLTRB(), impeller::UberSDFParameters::MakeRect(), params, impeller::Color::Red(), and impeller::StrokeParameters::width.

◆ TEST() [686/689]

impeller::testing::TEST ( UberSDFParametersTest  ,
MakeStrokeRectLowMiterLimitBecomesBevel   
)

Definition at line 35 of file uber_sdf_parameters_unittests.cc.

35 {
36 auto rect = Rect::MakeLTRB(100, 100, 200, 200);
37 StrokeParameters stroke = {
38 .width = 4.0f, .join = Join::kMiter, .miter_limit = 1.0f};
39 auto params = UberSDFParameters::MakeRect(Color::Red(), rect, stroke);
40
41 EXPECT_EQ(params.type, UberSDFParameters::Type::kRect);
42 EXPECT_EQ(params.color, Color::Red());
43 EXPECT_EQ(params.center, Point(150, 150));
44 EXPECT_EQ(params.size, Point(50, 50));
45 StrokeParameters expected_stroke = {.width = 4.0f, .join = Join::kBevel};
46 EXPECT_EQ(params.stroke, expected_stroke);
47}

References impeller::kBevel, impeller::kMiter, impeller::UberSDFParameters::kRect, impeller::TRect< Scalar >::MakeLTRB(), impeller::UberSDFParameters::MakeRect(), params, impeller::Color::Red(), and impeller::StrokeParameters::width.

◆ TEST() [687/689]

impeller::testing::TEST ( UniqueHandleGLES  ,
MakeUntracked   
)

Definition at line 26 of file unique_handle_gles_unittests.cc.

26 {
27 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
28
29 EXPECT_CALL(*mock_gles_impl, GenTextures(1, _)).Times(1);
30
31 std::shared_ptr<MockGLES> mock_gled =
32 MockGLES::Init(std::move(mock_gles_impl));
34 auto proc_table = std::make_unique<ProcTableGLES>(resolver);
35 auto worker = std::make_shared<TestWorker>();
36 auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
37 reactor->AddWorker(worker);
38
39 UniqueHandleGLES handle =
40 UniqueHandleGLES::MakeUntracked(reactor, HandleType::kTexture);
41 EXPECT_FALSE(handle.Get().IsDead());
42}
A unique handle to an OpenGL object. The collection of this handle scheduled the destruction of the a...
const HandleGLES & Get() const

References impeller::UniqueHandleGLES::Get(), impeller::testing::MockGLES::Init(), impeller::HandleGLES::IsDead(), kMockResolverGLES, impeller::kTexture, impeller::UniqueHandleGLES::MakeUntracked(), and reactor.

◆ TEST() [688/689]

impeller::testing::TEST ( WangsFormulaTest  ,
Cubic   
)

Definition at line 12 of file wangs_formula_unittests.cc.

12 {
13 Point p0{300, 0};
14 Point p1{0, 0};
15 Point p2{0, 0};
16 Point p3{0, 300};
17 Scalar result = ComputeCubicSubdivisions(1.0, p0, p1, p2, p3);
18 EXPECT_FLOAT_EQ(result, 30.f);
19}
Scalar ComputeCubicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2, Point p3)

References impeller::ComputeCubicSubdivisions(), p1, and p2.

◆ TEST() [689/689]

impeller::testing::TEST ( WangsFormulaTest  ,
Quadratic   
)

Definition at line 21 of file wangs_formula_unittests.cc.

21 {
22 Point p0{15, 0};
23 Point p1{0, 0};
24 Point p2{0, 20};
25 Scalar result = ComputeQuadradicSubdivisions(1.0, p0, p1, p2);
26 EXPECT_FLOAT_EQ(result, 5.f);
27}
Scalar ComputeQuadradicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2)

References impeller::ComputeQuadradicSubdivisions(), p1, and p2.

◆ TEST_F() [1/10]

impeller::testing::TEST_F ( GoldenTests  ,
ConicalGradient   
)

Definition at line 79 of file golden_tests.cc.

79 {
81 flutter::DlPaint paint;
83
84 flutter::DlColor colors[2] = {flutter::DlColor::RGBA(1, 0, 0, 1),
85 flutter::DlColor::RGBA(0, 0, 1, 1)};
86 Scalar stops[2] = {0, 1};
87
89 /*start_center=*/{125, 125}, //
90 /*start_radius=*/125, {180, 180}, //
91 /*end_radius=*/0, //
92 /*stop_count=*/2, //
93 /*colors=*/colors, //
94 /*stops=*/stops, //
95 /*tile_mode=*/flutter::DlTileMode::kClamp //
96 ));
97
98 builder.DrawRect(DlRect::MakeXYWH(10, 10, 250, 250), paint);
99
100 auto aiks_context =
101 AiksContext(Screenshotter().GetPlayground().GetContext(), nullptr);
102 auto screenshot = Screenshotter().MakeScreenshot(
103 aiks_context,
104 DisplayListToTexture(builder.Build(), {240, 240}, aiks_context));
105 ASSERT_TRUE(SaveScreenshot(std::move(screenshot)));
106}
std::shared_ptr< Texture > DisplayListToTexture(const sk_sp< flutter::DisplayList > &display_list, ISize size, AiksContext &context, bool reset_host_buffer, bool generate_mips, std::optional< PixelFormat > target_pixel_format)
Render the provided display list to a texture with the given size.
static constexpr DlColor RGBA(DlScalar r, DlScalar g, DlScalar b, DlScalar a)
Construct a 32 bit color from floating point R, G, B, and A color channels.
Definition dl_color.h:48

References flutter::DisplayListBuilder::Build(), impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawRect(), flutter::kClamp, flutter::kFill, flutter::DlColorSource::MakeConical(), impeller::testing::Screenshotter::MakeScreenshot(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlColor::RGBA(), flutter::DlPaint::setColorSource(), and flutter::DlPaint::setDrawStyle().

◆ TEST_F() [2/10]

impeller::testing::TEST_F ( RenderPassGLESCommandTest  ,
CommandsWithoutViewportGetRenderPassViewport   
)

Definition at line 328 of file render_pass_gles_unittests.cc.

329 {
330 auto ctx = CreateRenderPassGLESContext();
331 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
332 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
333 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
334 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
335
336 render_pass->SetPipeline(PipelineRef(pipeline));
337 render_pass->SetElementCount(1);
338 render_pass->SetIndexBuffer({}, IndexType::kNone);
339 EXPECT_TRUE(render_pass->Draw().ok());
340
341 render_pass->SetPipeline(PipelineRef(pipeline));
342 render_pass->SetElementCount(1);
343 render_pass->SetIndexBuffer({}, IndexType::kNone);
344 render_pass->SetViewport(
345 Viewport{Rect::MakeXYWH(0, 0, 50, 50), DepthRange{0.0f, 1.0f}});
346 EXPECT_TRUE(render_pass->Draw().ok());
347
348 render_pass->SetPipeline(PipelineRef(pipeline));
349 render_pass->SetElementCount(1);
350 render_pass->SetIndexBuffer({}, IndexType::kNone);
351 EXPECT_TRUE(render_pass->Draw().ok());
352
353 EXPECT_CALL(mock_gl_impl_ref, Viewport(_, _, _, _)).Times(0);
354 EXPECT_CALL(mock_gl_impl_ref, Viewport(0, 0, 100, 100)).Times(2);
355 EXPECT_CALL(mock_gl_impl_ref, Viewport(0, 0, 50, 50)).Times(1);
356
357 EXPECT_TRUE(render_pass->EncodeCommands());
358 EXPECT_TRUE(reactor->React());
359}
raw_ptr< Pipeline< PipelineDescriptor > > PipelineRef
A raw ptr to a pipeline object.
Definition pipeline.h:89

References impeller::kNone, impeller::TRect< Scalar >::MakeXYWH(), mock_gl_impl_ref, pipeline, reactor, and render_pass.

◆ TEST_F() [3/10]

impeller::testing::TEST_F ( RenderPassGLESCommandTest  ,
EmulatedInstancedArrayDraw   
)

Definition at line 448 of file render_pass_gles_unittests.cc.

448 {
449 auto ctx = CreateRenderPassGLESContext(kMockResolverGLESWithoutInstancing);
450 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
451 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
452 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
453 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
454
455 render_pass->SetPipeline(PipelineRef(pipeline));
456 render_pass->SetElementCount(3);
457 render_pass->SetIndexBuffer({}, IndexType::kNone);
458 render_pass->SetInstanceCount(4);
459 EXPECT_TRUE(render_pass->Draw().ok());
460
461 EXPECT_CALL(mock_gl_impl_ref,
462 DrawArrays(/*mode=*/_, /*first=*/0, /*count=*/3))
463 .Times(4);
464 EXPECT_CALL(mock_gl_impl_ref, DrawArraysInstanced(_, _, _, _)).Times(0);
465
466 EXPECT_TRUE(render_pass->EncodeCommands());
467 EXPECT_TRUE(reactor->React());
468}

References kMockResolverGLESWithoutInstancing, impeller::kNone, mock_gl_impl_ref, pipeline, reactor, and render_pass.

◆ TEST_F() [4/10]

impeller::testing::TEST_F ( RenderPassGLESCommandTest  ,
EmulatedInstancedElementsDraw   
)

Definition at line 472 of file render_pass_gles_unittests.cc.

472 {
473 auto ctx = CreateRenderPassGLESContext(kMockResolverGLESWithoutInstancing);
474 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
475 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
476 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
477 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
478
479 DeviceBufferDescriptor index_desc;
480 index_desc.size = 6 * sizeof(uint16_t);
481 index_desc.storage_mode = StorageMode::kHostVisible;
482 auto index_buffer = std::static_pointer_cast<Context>(ctx.context)
483 ->GetResourceAllocator()
484 ->CreateBuffer(index_desc);
485 ASSERT_TRUE(index_buffer);
486
487 render_pass->SetPipeline(PipelineRef(pipeline));
488 render_pass->SetElementCount(6);
489 ASSERT_TRUE(render_pass->SetIndexBuffer(
490 DeviceBuffer::AsBufferView(index_buffer), IndexType::k16bit));
491 render_pass->SetInstanceCount(4);
492 EXPECT_TRUE(render_pass->Draw().ok());
493
494 EXPECT_CALL(mock_gl_impl_ref,
495 DrawElements(/*mode=*/_, /*count=*/6, /*type=*/_, /*indices=*/_))
496 .Times(4);
497 EXPECT_CALL(mock_gl_impl_ref, DrawElementsInstanced(_, _, _, _, _)).Times(0);
498
499 EXPECT_TRUE(render_pass->EncodeCommands());
500 EXPECT_TRUE(reactor->React());
501}

References impeller::DeviceBuffer::AsBufferView(), impeller::k16bit, impeller::kHostVisible, kMockResolverGLESWithoutInstancing, mock_gl_impl_ref, pipeline, reactor, render_pass, impeller::DeviceBufferDescriptor::size, and impeller::DeviceBufferDescriptor::storage_mode.

◆ TEST_F() [5/10]

impeller::testing::TEST_F ( RenderPassGLESCommandTest  ,
HardwareInstancedArrayDraw   
)

Definition at line 388 of file render_pass_gles_unittests.cc.

388 {
389 auto ctx = CreateRenderPassGLESContext();
390 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
391 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
392 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
393 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
394
395 render_pass->SetPipeline(PipelineRef(pipeline));
396 render_pass->SetElementCount(3);
397 render_pass->SetIndexBuffer({}, IndexType::kNone);
398 render_pass->SetInstanceCount(4);
399 EXPECT_TRUE(render_pass->Draw().ok());
400
401 EXPECT_CALL(mock_gl_impl_ref,
402 DrawArraysInstanced(/*mode=*/_, /*first=*/0, /*count=*/3,
403 /*instancecount=*/4))
404 .Times(1);
405 EXPECT_CALL(mock_gl_impl_ref, DrawArrays(_, _, _)).Times(0);
406
407 EXPECT_TRUE(render_pass->EncodeCommands());
408 EXPECT_TRUE(reactor->React());
409}

References impeller::kNone, mock_gl_impl_ref, pipeline, reactor, and render_pass.

◆ TEST_F() [6/10]

impeller::testing::TEST_F ( RenderPassGLESCommandTest  ,
HardwareInstancedElementsDraw   
)

Definition at line 413 of file render_pass_gles_unittests.cc.

413 {
414 auto ctx = CreateRenderPassGLESContext();
415 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
416 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
417 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
418 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
419
420 DeviceBufferDescriptor index_desc;
421 index_desc.size = 6 * sizeof(uint16_t);
422 index_desc.storage_mode = StorageMode::kHostVisible;
423 auto index_buffer = std::static_pointer_cast<Context>(ctx.context)
424 ->GetResourceAllocator()
425 ->CreateBuffer(index_desc);
426 ASSERT_TRUE(index_buffer);
427
428 render_pass->SetPipeline(PipelineRef(pipeline));
429 render_pass->SetElementCount(6);
430 ASSERT_TRUE(render_pass->SetIndexBuffer(
431 DeviceBuffer::AsBufferView(index_buffer), IndexType::k16bit));
432 render_pass->SetInstanceCount(4);
433 EXPECT_TRUE(render_pass->Draw().ok());
434
435 EXPECT_CALL(mock_gl_impl_ref,
436 DrawElementsInstanced(/*mode=*/_, /*count=*/6, /*type=*/_,
437 /*indices=*/_, /*instancecount=*/4))
438 .Times(1);
439 EXPECT_CALL(mock_gl_impl_ref, DrawElements(_, _, _, _)).Times(0);
440
441 EXPECT_TRUE(render_pass->EncodeCommands());
442 EXPECT_TRUE(reactor->React());
443}

References impeller::DeviceBuffer::AsBufferView(), impeller::k16bit, impeller::kHostVisible, mock_gl_impl_ref, pipeline, reactor, render_pass, impeller::DeviceBufferDescriptor::size, and impeller::DeviceBufferDescriptor::storage_mode.

◆ TEST_F() [7/10]

impeller::testing::TEST_F ( RenderPassGLESCommandTest  ,
NonInstancedDrawIssuesSingleDrawArrays   
)

Definition at line 505 of file render_pass_gles_unittests.cc.

505 {
506 auto ctx = CreateRenderPassGLESContext();
507 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
508 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
509 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
510 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
511
512 render_pass->SetPipeline(PipelineRef(pipeline));
513 render_pass->SetElementCount(3);
514 render_pass->SetIndexBuffer({}, IndexType::kNone);
515 EXPECT_TRUE(render_pass->Draw().ok());
516
517 EXPECT_CALL(mock_gl_impl_ref,
518 DrawArrays(/*mode=*/_, /*first=*/0, /*count=*/3))
519 .Times(1);
520 EXPECT_CALL(mock_gl_impl_ref, DrawArraysInstanced(_, _, _, _)).Times(0);
521
522 EXPECT_TRUE(render_pass->EncodeCommands());
523 EXPECT_TRUE(reactor->React());
524}

References impeller::kNone, mock_gl_impl_ref, pipeline, reactor, and render_pass.

◆ TEST_F() [8/10]

impeller::testing::TEST_F ( RenderPassGLESCommandTest  ,
ViewportCachedAcrossCommands   
)

Definition at line 292 of file render_pass_gles_unittests.cc.

292 {
293 auto ctx = CreateRenderPassGLESContext();
294 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
295 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
296 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
297 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
298
299 render_pass->SetPipeline(PipelineRef(pipeline));
300 render_pass->SetElementCount(1);
301 render_pass->SetIndexBuffer({}, IndexType::kNone);
302 EXPECT_TRUE(render_pass->Draw().ok());
303
304 render_pass->SetPipeline(PipelineRef(pipeline));
305 render_pass->SetElementCount(1);
306 render_pass->SetIndexBuffer({}, IndexType::kNone);
307 render_pass->SetViewport(
308 Viewport{Rect::MakeXYWH(0, 0, 50, 50), DepthRange{0.0f, 1.0f}});
309 EXPECT_TRUE(render_pass->Draw().ok());
310
311 render_pass->SetPipeline(PipelineRef(pipeline));
312 render_pass->SetElementCount(1);
313 render_pass->SetIndexBuffer({}, IndexType::kNone);
314 render_pass->SetViewport(
315 Viewport{Rect::MakeXYWH(0, 0, 50, 50), DepthRange{0.0f, 1.0f}});
316 EXPECT_TRUE(render_pass->Draw().ok());
317
318 // Viewport should only be called twice. Once for the fallback, once for the
319 // first override. We set a catch-all to 0 to ensure no other calls occur.
320 EXPECT_CALL(mock_gl_impl_ref, Viewport(_, _, _, _)).Times(0);
321 EXPECT_CALL(mock_gl_impl_ref, Viewport(0, 0, 100, 100)).Times(1);
322 EXPECT_CALL(mock_gl_impl_ref, Viewport(0, 0, 50, 50)).Times(1);
323
324 EXPECT_TRUE(render_pass->EncodeCommands());
325 EXPECT_TRUE(reactor->React());
326}

References impeller::kNone, impeller::TRect< Scalar >::MakeXYWH(), mock_gl_impl_ref, pipeline, reactor, and render_pass.

◆ TEST_F() [9/10]

impeller::testing::TEST_F ( RenderPassGLESCommandTest  ,
ViewportWithNonZeroXOffsetReachesGL   
)

Definition at line 364 of file render_pass_gles_unittests.cc.

364 {
365 auto ctx = CreateRenderPassGLESContext();
366 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
367 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
368 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
369 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
370
371 render_pass->SetPipeline(PipelineRef(pipeline));
372 render_pass->SetElementCount(1);
373 render_pass->SetIndexBuffer({}, IndexType::kNone);
374 render_pass->SetViewport(
375 Viewport{Rect::MakeXYWH(25, 0, 50, 100), DepthRange{0.0f, 1.0f}});
376 EXPECT_TRUE(render_pass->Draw().ok());
377
378 EXPECT_CALL(mock_gl_impl_ref, Viewport(_, _, _, _)).Times(0);
379 EXPECT_CALL(mock_gl_impl_ref, Viewport(25, 0, 50, 100)).Times(1);
380
381 EXPECT_TRUE(render_pass->EncodeCommands());
382 EXPECT_TRUE(reactor->React());
383}

References impeller::kNone, impeller::TRect< Scalar >::MakeXYWH(), mock_gl_impl_ref, pipeline, reactor, and render_pass.

◆ TEST_F() [10/10]

impeller::testing::TEST_F ( RenderPassGLESCommandTest  ,
ZeroInstanceCountIssuesNoDraw   
)

Definition at line 528 of file render_pass_gles_unittests.cc.

528 {
529 auto ctx = CreateRenderPassGLESContext();
530 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
531 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
532 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
533 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
534
535 render_pass->SetPipeline(PipelineRef(pipeline));
536 render_pass->SetElementCount(3);
537 render_pass->SetIndexBuffer({}, IndexType::kNone);
538 render_pass->SetInstanceCount(0);
539 EXPECT_TRUE(render_pass->Draw().ok());
540
541 EXPECT_CALL(mock_gl_impl_ref, DrawArrays(_, _, _)).Times(0);
542 EXPECT_CALL(mock_gl_impl_ref, DrawArraysInstanced(_, _, _, _)).Times(0);
543
544 EXPECT_TRUE(render_pass->EncodeCommands());
545 EXPECT_TRUE(reactor->React());
546}

References impeller::kNone, mock_gl_impl_ref, pipeline, reactor, and render_pass.

◆ TEST_P() [1/662]

impeller::testing::TEST_P ( AiksTest  ,
AdvancedBlendColorFilterWithDestinationOpacity   
)

Definition at line 917 of file aiks_dl_blend_unittests.cc.

917 {
918 DisplayListBuilder builder;
919
920 builder.DrawPaint(DlPaint(DlColor::kWhite()));
921
922 DlPaint save_paint;
923 save_paint.setOpacity(0.3);
924 save_paint.setColorFilter(DlColorFilter::MakeBlend(DlColor::kTransparent(),
925 DlBlendMode::kSaturation));
926 builder.SaveLayer(std::nullopt, &save_paint);
927 builder.DrawRect(DlRect::MakeXYWH(100, 100, 300, 300),
928 DlPaint(DlColor::kMaroon()));
929 builder.DrawRect(DlRect::MakeXYWH(200, 200, 300, 300),
930 DlPaint(DlColor::kBlue()));
931 builder.Restore();
932
933 // Should be solid red as the destructive color filter floods the clip.
934 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
935}
void SaveLayer(const std::optional< DlRect > &bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr, std::optional< int64_t > backdrop_id=std::nullopt) override
DlPaint & setOpacity(DlScalar opacity)
Definition dl_paint.h:78
DlPaint & setColorFilter(std::nullptr_t filter)
Definition dl_paint.h:149

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kMaroon(), flutter::DlColor::kTransparent(), flutter::DlColor::kWhite(), flutter::DlColorFilter::MakeBlend(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColorFilter(), and flutter::DlPaint::setOpacity().

◆ TEST_P() [2/662]

impeller::testing::TEST_P ( AiksTest  ,
ArcWithZeroSweepAndBlur   
)

Definition at line 727 of file aiks_dl_path_unittests.cc.

727 {
728 DisplayListBuilder builder;
729 builder.Scale(GetContentScale().x, GetContentScale().y);
730
731 DlPaint paint;
732 paint.setColor(DlColor::kRed());
733
734 std::vector<DlColor> colors = {DlColor::RGBA(1.0, 0.0, 0.0, 1.0),
735 DlColor::RGBA(0.0, 0.0, 0.0, 1.0)};
736 std::vector<Scalar> stops = {0.0, 1.0};
737
738 paint.setColorSource(
739 DlColorSource::MakeSweep({100, 100}, 45, 135, stops.size(), colors.data(),
740 stops.data(), DlTileMode::kMirror));
741 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 20));
742
743 DlPathBuilder path_builder;
744 path_builder.AddArc(DlRect::MakeXYWH(10, 10, 100, 100), //
745 DlDegrees(0), DlDegrees(0));
746 builder.DrawPath(path_builder.TakePath(), paint);
747
748 // Check that this empty picture can be created without crashing.
749 builder.Build();
750}
impeller::Degrees DlDegrees

References flutter::DlPathBuilder::AddArc(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlBlurMaskFilter::Make(), flutter::DlColorSource::MakeSweep(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setMaskFilter(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [3/662]

impeller::testing::TEST_P ( AiksTest  ,
BackdropCountDownBackdropId   
)

Definition at line 177 of file canvas_unittests.cc.

177 {
178 ContentContext& context = GetContentContext();
179 if (!context.GetDeviceCapabilities().SupportsFramebufferFetch()) {
180 GTEST_SKIP() << "Test requires device with framebuffer fetch";
181 }
182 auto canvas = CreateTestCanvas(context, Rect::MakeLTRB(0, 0, 100, 100),
183 /*requires_readback=*/true);
184 // 3 backdrop filters all with same id.
185 std::unordered_map<int64_t, BackdropData> data;
186 data[1] = BackdropData{.backdrop_count = 3};
187 canvas->SetBackdropData(data, 3);
188
189 auto blur =
191
192 EXPECT_TRUE(canvas->RequiresReadback());
193 canvas->DrawRect(flutter::DlRect::MakeLTRB(0, 0, 50, 50),
194 {.color = Color::Azure()});
195 canvas->SaveLayer({}, std::nullopt, blur.get(),
196 ContentBoundsPromise::kContainsContents,
197 /*total_content_depth=*/1, /*can_distribute_opacity=*/false,
198 /*backdrop_id=*/1);
199 canvas->Restore();
200 EXPECT_FALSE(canvas->RequiresReadback());
201
202 canvas->SaveLayer({}, std::nullopt, blur.get(),
203 ContentBoundsPromise::kContainsContents,
204 /*total_content_depth=*/1, /*can_distribute_opacity=*/false,
205 /*backdrop_id=*/1);
206 canvas->Restore();
207 EXPECT_FALSE(canvas->RequiresReadback());
208
209 canvas->SaveLayer({}, std::nullopt, blur.get(),
210 ContentBoundsPromise::kContainsContents,
211 /*total_content_depth=*/1, /*can_distribute_opacity=*/false,
212 /*backdrop_id=*/1);
213 canvas->Restore();
214 EXPECT_FALSE(canvas->RequiresReadback());
215}
static std::shared_ptr< DlImageFilter > MakeBlur(DlScalar sigma_x, DlScalar sigma_y, DlTileMode tile_mode)
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129

References impeller::Color::Azure(), impeller::BackdropData::backdrop_count, context, CreateTestCanvas(), flutter::data, flutter::kClamp, impeller::kContainsContents, flutter::DlImageFilter::MakeBlur(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST_P() [4/662]

impeller::testing::TEST_P ( AiksTest  ,
BackdropCountDownBackdropIdMixed   
)

Definition at line 217 of file canvas_unittests.cc.

217 {
218 ContentContext& context = GetContentContext();
219 if (!context.GetDeviceCapabilities().SupportsFramebufferFetch()) {
220 GTEST_SKIP() << "Test requires device with framebuffer fetch";
221 }
222 auto canvas = CreateTestCanvas(context, Rect::MakeLTRB(0, 0, 100, 100),
223 /*requires_readback=*/true);
224 // 3 backdrop filters, 2 with same id.
225 std::unordered_map<int64_t, BackdropData> data;
226 data[1] = BackdropData{.backdrop_count = 2};
227 canvas->SetBackdropData(data, 3);
228
229 auto blur =
231
232 EXPECT_TRUE(canvas->RequiresReadback());
233 canvas->DrawRect(flutter::DlRect::MakeLTRB(0, 0, 50, 50),
234 {.color = Color::Azure()});
235 canvas->SaveLayer({}, std::nullopt, blur.get(),
236 ContentBoundsPromise::kContainsContents, 1, false);
237 canvas->Restore();
238 EXPECT_TRUE(canvas->RequiresReadback());
239
240 canvas->SaveLayer({}, std::nullopt, blur.get(),
241 ContentBoundsPromise::kContainsContents, 1, false, 1);
242 canvas->Restore();
243 EXPECT_FALSE(canvas->RequiresReadback());
244
245 canvas->SaveLayer({}, std::nullopt, blur.get(),
246 ContentBoundsPromise::kContainsContents, 1, false, 1);
247 canvas->Restore();
248 EXPECT_FALSE(canvas->RequiresReadback());
249}

References impeller::Color::Azure(), impeller::BackdropData::backdrop_count, context, CreateTestCanvas(), flutter::data, flutter::kClamp, impeller::kContainsContents, flutter::DlImageFilter::MakeBlur(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST_P() [5/662]

impeller::testing::TEST_P ( AiksTest  ,
BackdropCountDownNormal   
)

Definition at line 142 of file canvas_unittests.cc.

142 {
143 ContentContext& context = GetContentContext();
144 if (!context.GetDeviceCapabilities().SupportsFramebufferFetch()) {
145 GTEST_SKIP() << "Test requires device with framebuffer fetch";
146 }
147 auto canvas = CreateTestCanvas(context, Rect::MakeLTRB(0, 0, 100, 100),
148 /*requires_readback=*/true);
149 // 3 backdrop filters
150 canvas->SetBackdropData({}, 3);
151
152 auto blur =
154 flutter::DlRect rect = flutter::DlRect::MakeLTRB(0, 0, 50, 50);
155
156 EXPECT_TRUE(canvas->RequiresReadback());
157 canvas->DrawRect(rect, {.color = Color::Azure()});
158 canvas->SaveLayer({}, rect, blur.get(),
159 ContentBoundsPromise::kContainsContents,
160 /*total_content_depth=*/1);
161 canvas->Restore();
162 EXPECT_TRUE(canvas->RequiresReadback());
163
164 canvas->SaveLayer({}, rect, blur.get(),
165 ContentBoundsPromise::kContainsContents,
166 /*total_content_depth=*/1);
167 canvas->Restore();
168 EXPECT_TRUE(canvas->RequiresReadback());
169
170 canvas->SaveLayer({}, rect, blur.get(),
171 ContentBoundsPromise::kContainsContents,
172 /*total_content_depth=*/1);
173 canvas->Restore();
174 EXPECT_FALSE(canvas->RequiresReadback());
175}

References impeller::Color::Azure(), context, CreateTestCanvas(), flutter::kClamp, impeller::kContainsContents, flutter::DlImageFilter::MakeBlur(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST_P() [6/662]

impeller::testing::TEST_P ( AiksTest  ,
BackdropCountDownWithNestedSaveLayers   
)

Definition at line 254 of file canvas_unittests.cc.

254 {
255 ContentContext& context = GetContentContext();
256 if (!context.GetDeviceCapabilities().SupportsFramebufferFetch()) {
257 GTEST_SKIP() << "Test requires device with framebuffer fetch";
258 }
259 auto canvas = CreateTestCanvas(context, Rect::MakeLTRB(0, 0, 100, 100),
260 /*requires_readback=*/true);
261
262 canvas->SetBackdropData({}, 2);
263
264 auto blur =
266
267 EXPECT_TRUE(canvas->RequiresReadback());
268 canvas->DrawRect(flutter::DlRect::MakeLTRB(0, 0, 50, 50),
269 {.color = Color::Azure()});
270 canvas->SaveLayer({}, std::nullopt, blur.get(),
271 ContentBoundsPromise::kContainsContents,
272 /*total_content_depth=*/3);
273
274 // This filter is nested in the first saveLayer. We cannot restore to onscreen
275 // here.
276 canvas->SaveLayer({}, std::nullopt, blur.get(),
277 ContentBoundsPromise::kContainsContents,
278 /*total_content_depth=*/1);
279 canvas->Restore();
280 EXPECT_TRUE(canvas->RequiresReadback());
281
282 canvas->Restore();
283 EXPECT_TRUE(canvas->RequiresReadback());
284}

References impeller::Color::Azure(), context, CreateTestCanvas(), flutter::kClamp, impeller::kContainsContents, flutter::DlImageFilter::MakeBlur(), and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST_P() [7/662]

impeller::testing::TEST_P ( AiksTest  ,
BackdropFilterOverUnclosedClip   
)

Definition at line 2413 of file aiks_dl_basic_unittests.cc.

2413 {
2414 DisplayListBuilder builder;
2415
2416 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
2417 builder.Save();
2418 {
2419 builder.ClipRect(DlRect::MakeLTRB(100, 100, 800, 800));
2420
2421 builder.Save();
2422 {
2423 builder.ClipRect(DlRect::MakeLTRB(600, 600, 800, 800));
2424 builder.DrawPaint(DlPaint().setColor(DlColor::kRed()));
2425 builder.DrawPaint(DlPaint().setColor(DlColor::kBlue().withAlphaF(0.5)));
2426 builder.ClipRect(DlRect::MakeLTRB(700, 700, 750, 800));
2427 builder.DrawPaint(DlPaint().setColor(DlColor::kRed().withAlphaF(0.5)));
2428 }
2429 builder.Restore();
2430
2431 auto image_filter = DlImageFilter::MakeBlur(10, 10, DlTileMode::kDecal);
2432 builder.SaveLayer(std::nullopt, nullptr, image_filter.get());
2433 }
2434 builder.Restore();
2435 builder.DrawCircle(DlPoint(100, 100), 100,
2436 DlPaint().setColor(DlColor::kAqua()));
2437
2438 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2439}
void ClipRect(const DlRect &rect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false) override

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kAqua(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), and flutter::DisplayListBuilder::SaveLayer().

◆ TEST_P() [8/662]

impeller::testing::TEST_P ( AiksTest  ,
BackdropRestoreUsesCorrectCoverageForFirstRestoredClip   
)

Definition at line 906 of file aiks_dl_unittests.cc.

906 {
907 DisplayListBuilder builder;
908
909 DlPaint paint;
910 // Add a difference clip that cuts out the bottom right corner
911 builder.ClipRect(DlRect::MakeLTRB(50, 50, 100, 100), DlClipOp::kDifference);
912
913 // Draw a red rectangle that's going to be completely covered by green later.
914 paint.setColor(DlColor::kRed());
915 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
916
917 // Add a clip restricting the backdrop filter to the top right corner.
918 auto count = builder.GetSaveCount();
919 builder.Save();
920 {
921 builder.ClipRect(DlRect::MakeLTRB(0, 0, 100, 100));
922 {
923 // Create a save layer with a backdrop blur filter.
924 auto backdrop_filter =
925 DlImageFilter::MakeBlur(10.0, 10.0, DlTileMode::kDecal);
926 builder.SaveLayer(std::nullopt, nullptr, backdrop_filter.get());
927 }
928 }
929 builder.RestoreToCount(count);
930
931 // Finally, overwrite all the previous stuff with green.
932 paint.setColor(DlColor::kGreen());
933 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
934
935 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
936}
void RestoreToCount(int restore_count) override
int GetSaveCount() const override
Definition dl_builder.h:71

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::GetSaveCount(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DisplayListBuilder::RestoreToCount(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [9/662]

impeller::testing::TEST_P ( AiksTest  ,
BlendModeCompatibilityWithSDFRendering   
)

Verifies blend mode compatibility with SDF rendering.

The compatibility condition is: mix(blend(src, dst), dst, 1 - sdf_alpha) == blend(src * sdf_alpha, dst)

Definition at line 498 of file canvas_unittests.cc.

498 {
499 std::vector<Color> colors = {
500 Color::BlackTransparent(),
501 Color::Black(),
502 Color::White(),
503 Color::LimeGreen(),
504 Color::CornflowerBlue(),
505 Color::LimeGreen().WithAlpha(0.8),
506 Color::CornflowerBlue().WithAlpha(0.7),
507 };
508
509 for (int i = 0; i <= static_cast<int>(BlendMode::kLastMode); i++) {
510 BlendMode blend_mode = static_cast<BlendMode>(i);
511 bool blend_mode_is_compatible = true;
512
513 for (const auto& src : colors) {
514 for (const auto& dst : colors) {
515 for (Scalar sdf_alpha = 0.0; sdf_alpha < 1.01; sdf_alpha += 0.2) {
516 // `mix(blend(src, dst), dst, 1 - sdf_alpha)`:
517 // 1. Blend src onto dst.
518 Color blended = dst.Blend(src, blend_mode);
519 // 2. Mix with dst using sdf_alpha. Mix by lerping using
520 // pre-multiplied colors.
521 Color blended_then_sdf_alpha_applied =
522 Color::Lerp(blended.Premultiply(), dst.Premultiply(),
523 1.0 - sdf_alpha)
524 .Unpremultiply();
525
526 // `blend(src * sdf_alpha, dst)`:
527 // 1. Apply sdf_alpha to src's alpha.
528 Color sdf_alpha_applied = src.WithAlpha(src.alpha * sdf_alpha);
529 // 2. Blend onto dst.
530 Color sdf_alpha_applied_then_blended =
531 dst.Blend(sdf_alpha_applied, blend_mode);
532
533 // Compare results.
534 if (blended_then_sdf_alpha_applied !=
535 sdf_alpha_applied_then_blended) {
536 blend_mode_is_compatible = false;
537 }
538 }
539 }
540 }
541
542 Paint paint = {.blend_mode = blend_mode};
543 EXPECT_EQ(blend_mode_is_compatible,
544 Canvas::IsCompatibleWithSDFRendering(paint))
545 << "Failure for BlendMode: " << BlendModeToString(blend_mode);
546 }
547}

References impeller::Color::Black(), impeller::Color::BlackTransparent(), impeller::Color::Blend(), impeller::Paint::blend_mode, impeller::BlendModeToString(), impeller::Color::CornflowerBlue(), i, impeller::Canvas::IsCompatibleWithSDFRendering(), impeller::kLastMode, impeller::Color::Lerp(), impeller::Color::LimeGreen(), impeller::Color::Premultiply(), impeller::Color::Unpremultiply(), impeller::Color::White(), and impeller::Color::WithAlpha().

◆ TEST_P() [10/662]

impeller::testing::TEST_P ( AiksTest  ,
BlendModePlusAlphaColorFilterWideGamut   
)

Definition at line 435 of file aiks_dl_blend_unittests.cc.

435 {
436 // Must be called before any methods that use the context to ensure that
437 // this test is always run with wide gamut support.
438 if (!EnsureContextSupportsWideGamut()) {
439 GTEST_SKIP() << "This backend doesn't yet support wide gamut.";
440 }
441
442 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
443 PixelFormat::kB10G10R10A10XR);
444 auto texture = CreateTextureForFixture("airplane.jpg",
445 /*enable_mipmapping=*/true);
446
447 DisplayListBuilder builder;
448 builder.Scale(GetContentScale().x, GetContentScale().y);
449
450 DlPaint paint;
451 paint.setColor(DlColor::RGBA(0.1, 0.2, 0.1, 1.0));
452 builder.DrawPaint(paint);
453
454 DlPaint save_paint;
455 save_paint.setColorFilter(
456 DlColorFilter::MakeBlend(DlColor::RGBA(1, 0, 0, 1), DlBlendMode::kPlus));
457 builder.SaveLayer(std::nullopt, &save_paint);
458
459 paint.setColor(DlColor::kRed());
460 builder.DrawRect(DlRect::MakeXYWH(100, 100, 400, 400), paint);
461
462 paint.setColor(DlColor::kWhite());
463
464 auto rect = Rect::MakeXYWH(100, 100, 400, 400).Expand(-100, -100);
465 builder.DrawImageRect(
466 DlImageImpeller::Make(texture),
467 DlRect::MakeWH(texture->GetSize().width, texture->GetSize().height),
468 DlRect::MakeLTRB(rect.GetLeft(), rect.GetTop(), //
469 rect.GetRight(), rect.GetBottom()),
470 DlImageSampling::kMipmapLinear, &paint);
471 builder.Restore();
472
473 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
474}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageRect(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), impeller::TRect< T >::Expand(), impeller::kB10G10R10A10XR, flutter::DlColor::kRed(), flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeBlend(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeWH(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), texture, x, and y.

◆ TEST_P() [11/662]

impeller::testing::TEST_P ( AiksTest  ,
BlendModePlusAlphaWideGamut   
)

Definition at line 397 of file aiks_dl_blend_unittests.cc.

397 {
398 // Must be called before any methods that use the context to ensure that
399 // this test is always run with wide gamut support.
400 if (!EnsureContextSupportsWideGamut()) {
401 GTEST_SKIP() << "This backend doesn't yet support wide gamut.";
402 }
403
404 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
405 PixelFormat::kB10G10R10A10XR);
406 auto texture = CreateTextureForFixture("airplane.jpg",
407 /*enable_mipmapping=*/true);
408
409 DisplayListBuilder builder;
410 DlPaint paint;
411 builder.Scale(GetContentScale().x, GetContentScale().y);
412
413 paint.setColor(DlColor::RGBA(0.9, 1, 0.9, 1.0));
414 builder.DrawPaint(paint);
415 builder.SaveLayer(std::nullopt);
416
417 paint.setBlendMode(DlBlendMode::kPlus);
418 paint.setColor(DlColor::kRed());
419
420 builder.DrawRect(DlRect::MakeXYWH(100, 100, 400, 400), paint);
421 paint.setColor(DlColor::kWhite());
422
423 auto rect = Rect::MakeXYWH(100, 100, 400, 400).Expand(-100, -100);
424 builder.DrawImageRect(
425 DlImageImpeller::Make(texture),
426 DlRect::MakeWH(texture->GetSize().width, texture->GetSize().height),
427 DlRect::MakeLTRB(rect.GetLeft(), rect.GetTop(), //
428 rect.GetRight(), rect.GetBottom()),
429 DlImageSampling::kMipmapLinear, &paint);
430 builder.Restore();
431 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
432}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageRect(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), impeller::TRect< T >::Expand(), impeller::kB10G10R10A10XR, flutter::DlColor::kRed(), flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeWH(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), texture, x, and y.

◆ TEST_P() [12/662]

impeller::testing::TEST_P ( AiksTest  ,
BlendModeShouldCoverWholeScreen   
)

Definition at line 82 of file aiks_dl_blend_unittests.cc.

82 {
83 DisplayListBuilder builder;
84 DlPaint paint;
85
86 paint.setColor(DlColor::kRed());
87 builder.DrawPaint(paint);
88
89 paint.setBlendMode(DlBlendMode::kSrcOver);
90 builder.SaveLayer(std::nullopt, &paint);
91
92 paint.setColor(DlColor::kWhite());
93 builder.DrawRect(DlRect::MakeXYWH(100, 100, 400, 400), paint);
94
95 paint.setBlendMode(DlBlendMode::kSrc);
96 builder.SaveLayer(std::nullopt, &paint);
97
98 paint.setColor(DlColor::kBlue());
99 builder.DrawRect(DlRect::MakeXYWH(200, 200, 200, 200), paint);
100
101 builder.Restore();
102 builder.Restore();
103
104 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
105}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [13/662]

impeller::testing::TEST_P ( AiksTest  ,
BlurGradientWithOpacity   
)

Definition at line 1440 of file aiks_dl_blur_unittests.cc.

1440 {
1441 DisplayListBuilder builder;
1442 builder.Scale(GetContentScale().x, GetContentScale().y);
1443
1444 std::vector<DlColor> colors = {DlColor(0xFFFF0000), DlColor(0xFF00FF00)};
1445 std::vector<Scalar> stops = {0.0, 1.0};
1446
1447 auto gradient = DlColorSource::MakeLinear(
1448 {0, 0}, {400, 400}, 2, colors.data(), stops.data(), DlTileMode::kClamp);
1449
1450 DlPaint save_paint;
1451 save_paint.setOpacity(0.5);
1452 builder.SaveLayer(std::nullopt, &save_paint);
1453
1454 DlPaint paint;
1455 paint.setColorSource(gradient);
1456 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1));
1457 builder.DrawRect(DlRect::MakeXYWH(100, 100, 200, 200), paint);
1458
1459 builder.Restore();
1460
1461 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1462}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlBlurMaskFilter::Make(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setMaskFilter(), flutter::DlPaint::setOpacity(), x, and y.

◆ TEST_P() [14/662]

impeller::testing::TEST_P ( AiksTest  ,
BlurHasNoEdge   
)

Definition at line 531 of file aiks_dl_blur_unittests.cc.

531 {
532 Scalar sigma = 47.6;
533 auto callback = [&]() -> sk_sp<DisplayList> {
534 if (IsPlaygroundEnabled()) {
535 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
536 ImGui::SliderFloat("Sigma", &sigma, 0, 50);
537 ImGui::End();
538 }
539 DisplayListBuilder builder;
540 builder.Scale(GetContentScale().x, GetContentScale().y);
541 builder.DrawPaint({});
542
543 DlPaint paint;
544 paint.setColor(DlColor::kGreen());
545 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, sigma));
546
547 builder.DrawRect(DlRect::MakeXYWH(300, 300, 200, 200), paint);
548 return builder.Build();
549 };
550
551 ASSERT_TRUE(OpenPlaygroundHere(callback));
552}
FlutterDesktopBinaryReply callback

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kGreen(), flutter::DlBlurMaskFilter::Make(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), x, and y.

◆ TEST_P() [15/662]

impeller::testing::TEST_P ( AiksTest  ,
BlurredCircleWithStrokeWidth   
)

Definition at line 994 of file aiks_dl_path_unittests.cc.

994 {
995 DisplayListBuilder builder;
996 DlPaint paint;
997 paint.setColor(DlColor::kGreen());
998 paint.setDrawStyle(DlDrawStyle::kStroke);
999 paint.setStrokeWidth(30);
1000 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 5));
1001
1002 builder.DrawCircle(DlPoint(200, 200), 100, paint);
1003
1004 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1005}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kGreen(), flutter::DlBlurMaskFilter::Make(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setMaskFilter(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [16/662]

impeller::testing::TEST_P ( AiksTest  ,
BlurredRectangleWithShader   
)

Definition at line 1293 of file aiks_dl_blur_unittests.cc.

1293 {
1294 DisplayListBuilder builder;
1295 builder.Scale(GetContentScale().x, GetContentScale().y);
1296
1297 auto paint_lines = [&builder](Scalar dx, Scalar dy, DlPaint paint) {
1298 auto draw_line = [&builder, &paint](DlPoint a, DlPoint b) {
1299 DlPath line = DlPath::MakeLine(a, b);
1300 builder.DrawPath(line, paint);
1301 };
1302 paint.setStrokeWidth(5);
1303 paint.setDrawStyle(DlDrawStyle::kStroke);
1304 draw_line(DlPoint(dx + 100, dy + 100), DlPoint(dx + 200, dy + 200));
1305 draw_line(DlPoint(dx + 100, dy + 200), DlPoint(dx + 200, dy + 100));
1306 draw_line(DlPoint(dx + 150, dy + 100), DlPoint(dx + 200, dy + 150));
1307 draw_line(DlPoint(dx + 100, dy + 150), DlPoint(dx + 150, dy + 200));
1308 };
1309
1310 AiksContext renderer(GetContext(), nullptr);
1311 DisplayListBuilder recorder_builder;
1312 for (int x = 0; x < 5; ++x) {
1313 for (int y = 0; y < 5; ++y) {
1314 DlRect rect = DlRect::MakeXYWH(x * 20, y * 20, 20, 20);
1315 DlPaint paint;
1316 paint.setColor(((x + y) & 1) == 0 ? DlColor::kYellow()
1317 : DlColor::kBlue());
1318
1319 recorder_builder.DrawRect(rect, paint);
1320 }
1321 }
1322 auto texture =
1323 DisplayListToTexture(recorder_builder.Build(), {100, 100}, renderer);
1324
1325 auto image_source = DlColorSource::MakeImage(
1326 DlImageImpeller::Make(texture), DlTileMode::kRepeat, DlTileMode::kRepeat);
1327 auto blur_filter = DlImageFilter::MakeBlur(5, 5, DlTileMode::kDecal);
1328
1329 DlPaint paint;
1330 paint.setColor(DlColor::kDarkGreen());
1331 builder.DrawRect(DlRect::MakeLTRB(0, 0, 300, 600), paint);
1332
1333 paint.setColorSource(image_source);
1334 builder.DrawRect(DlRect::MakeLTRB(100, 100, 200, 200), paint);
1335
1336 paint.setColorSource(nullptr);
1337 paint.setColor(DlColor::kRed());
1338 builder.DrawRect(DlRect::MakeLTRB(300, 0, 600, 600), paint);
1339
1340 paint.setColorSource(image_source);
1341 paint.setImageFilter(blur_filter);
1342 builder.DrawRect(DlRect::MakeLTRB(400, 100, 500, 200), paint);
1343
1344 paint.setImageFilter(nullptr);
1345 paint_lines(0, 300, paint);
1346
1347 paint.setImageFilter(blur_filter);
1348 paint_lines(300, 300, paint);
1349
1350 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1351}

References flutter::DisplayListBuilder::Build(), impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kDarkGreen(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), flutter::DlColorSource::MakeImage(), flutter::DlPath::MakeLine(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setImageFilter(), texture, x, and y.

◆ TEST_P() [17/662]

impeller::testing::TEST_P ( AiksTest  ,
CanConvertTriangleFanToTriangles   
)

Definition at line 159 of file aiks_dl_vertices_unittests.cc.

159 {
160 constexpr Scalar hexagon_radius = 125;
161 auto hex_start = Point(200.0, -hexagon_radius + 200.0);
162 auto center_to_flat = 1.73 / 2 * hexagon_radius;
163
164 // clang-format off
165 std::vector<DlPoint> vertices = {
166 DlPoint(hex_start.x, hex_start.y),
167 DlPoint(hex_start.x + center_to_flat, hex_start.y + 0.5 * hexagon_radius),
168 DlPoint(hex_start.x + center_to_flat, hex_start.y + 1.5 * hexagon_radius),
169 DlPoint(hex_start.x + center_to_flat, hex_start.y + 1.5 * hexagon_radius),
170 DlPoint(hex_start.x, hex_start.y + 2 * hexagon_radius),
171 DlPoint(hex_start.x, hex_start.y + 2 * hexagon_radius),
172 DlPoint(hex_start.x - center_to_flat, hex_start.y + 1.5 * hexagon_radius),
173 DlPoint(hex_start.x - center_to_flat, hex_start.y + 1.5 * hexagon_radius),
174 DlPoint(hex_start.x - center_to_flat, hex_start.y + 0.5 * hexagon_radius)
175 };
176 // clang-format on
178 auto dl_vertices = flutter::DlVertices::Make(
179 flutter::DlVertexMode::kTriangleFan, vertices.size(), vertices.data(),
180 nullptr, nullptr);
182 builder.DrawVertices(dl_vertices, flutter::DlBlendMode::kSrcOver, paint);
183 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
184}
void DrawVertices(const std::shared_ptr< DlVertices > &vertices, DlBlendMode mode, const DlPaint &paint) override
static std::shared_ptr< DlVertices > Make(DlVertexMode mode, int vertex_count, const DlPoint vertices[], const DlPoint texture_coordinates[], const DlColor colors[], int index_count=0, const uint16_t indices[]=nullptr, const DlRect *bounds=nullptr)
Constructs a DlVector with compact inline storage for all of its required and optional lists of data.
static constexpr DlColor kDarkGrey()
Definition dl_color.h:77

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), flutter::DlColor::kDarkGrey(), flutter::kTriangleFan, and flutter::DlVertices::Make().

◆ TEST_P() [18/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawAnOpenPath   
)

Definition at line 475 of file aiks_dl_path_unittests.cc.

475 {
476 DisplayListBuilder builder;
477
478 // Starting at (50, 50), draw lines from:
479 // 1. (50, height)
480 // 2. (width, height)
481 // 3. (width, 50)
482 DlPathBuilder path_builder;
483 path_builder.MoveTo(DlPoint(50, 50));
484 path_builder.LineTo(DlPoint(50, 100));
485 path_builder.LineTo(DlPoint(100, 100));
486 path_builder.LineTo(DlPoint(100, 50));
487
488 DlPaint paint;
489 paint.setColor(DlColor::kRed());
490 paint.setDrawStyle(DlDrawStyle::kStroke);
491 paint.setStrokeWidth(10);
492
493 builder.DrawPath(path_builder.TakePath(), paint);
494
495 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
496}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), and flutter::DlPathBuilder::TakePath().

◆ TEST_P() [19/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawAnOpenPathThatIsntARect   
)

Definition at line 498 of file aiks_dl_path_unittests.cc.

498 {
499 DisplayListBuilder builder;
500
501 // Draw a stroked path that is explicitly closed to verify
502 // It doesn't become a rectangle.
503 DlPathBuilder path_builder;
504 path_builder.MoveTo(DlPoint(50, 50));
505 path_builder.LineTo(DlPoint(520, 120));
506 path_builder.LineTo(DlPoint(300, 310));
507 path_builder.LineTo(DlPoint(100, 50));
508 path_builder.Close();
509
510 DlPaint paint;
511 paint.setColor(DlColor::kRed());
512 paint.setDrawStyle(DlDrawStyle::kStroke);
513 paint.setStrokeWidth(10);
514
515 builder.DrawPath(path_builder.TakePath(), paint);
516
517 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
518}

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), and flutter::DlPathBuilder::TakePath().

◆ TEST_P() [20/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawMultiContourConvexPath   
)

Definition at line 699 of file aiks_dl_path_unittests.cc.

699 {
700 DlPathBuilder path_builder;
701 for (auto i = 0; i < 10; i++) {
702 if (i % 2 == 0) {
703 // We use the factory method to convert the circle to a path so that it
704 // uses the legacy conics for legacy golden output.
705 DlPath circle =
706 DlPath::MakeCircle(DlPoint(100 + 50 * i, 100 + 50 * i), 100);
707 path_builder.AddPath(circle);
708 path_builder.Close();
709 } else {
710 path_builder.MoveTo(DlPoint(100.f + 50.f * i - 100, 100.f + 50.f * i));
711 path_builder.LineTo(DlPoint(100.f + 50.f * i, 100.f + 50.f * i - 100));
712 path_builder.LineTo(DlPoint(100.f + 50.f * i - 100, //
713 100.f + 50.f * i - 100));
714 path_builder.Close();
715 }
716 }
717 DlPath path = path_builder.TakePath();
718
719 DisplayListBuilder builder;
720 DlPaint paint;
721 paint.setColor(DlColor::kRed().withAlpha(102));
722 builder.DrawPath(path, paint);
723
724 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
725}
DlPathBuilder & AddPath(const DlPath &path)
Append the provided path to this path as if the commands used to construct it were repeated on this p...
flutter::DlPath DlPath

References flutter::DlPathBuilder::AddPath(), flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPath(), i, flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), flutter::DlPath::MakeCircle(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DlPaint::setColor(), and flutter::DlPathBuilder::TakePath().

◆ TEST_P() [21/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawNonuniformScaleConvexShadow   
)

Definition at line 1053 of file aiks_dl_shadow_unittests.cc.

1053 {
1054 DisplayListBuilder builder;
1055 builder.Clear(DlColor::kWhite());
1056 builder.Scale(GetContentScale().x, GetContentScale().y);
1057
1058 DlPathBuilder path_builder;
1059 path_builder.MoveTo(DlPoint(-50, -50));
1060 path_builder.LineTo(DlPoint(50, -50));
1061 path_builder.LineTo(DlPoint(50, 50));
1062 path_builder.LineTo(DlPoint(0, 75));
1063 path_builder.LineTo(DlPoint(-50, 50));
1064 path_builder.Close();
1065 DlPath pentagon_path = path_builder.TakePath();
1066
1067 DlPaint paint;
1068 paint.setColor(DlColor::kGreen().withAlphaF(0.25f));
1069
1070 DlPaint shadow_paint;
1071 shadow_paint.setMaskFilter(
1072 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 10.0f));
1073
1074 // The first row and column will be right at the edge of the screen
1075 // but they should not draw anything anyway.
1076 builder.Translate(50, 50);
1077
1078 for (int y = 0; y <= 5; y++) {
1079 Scalar y_scale = y / 5.0f;
1080 builder.Save();
1081 for (int x = 0; x <= 10; x++) {
1082 Scalar x_scale = x / 10.0f;
1083 builder.Save();
1084 builder.Scale(x_scale, y_scale);
1085 builder.DrawPath(pentagon_path, shadow_paint);
1086 builder.DrawPath(pentagon_path, paint);
1087 builder.Restore();
1088 builder.Translate(100 * x_scale + 20, 0);
1089 }
1090 builder.Restore();
1091 builder.Translate(0, 125 * y_scale + 50);
1092 }
1093
1094 auto dl = builder.Build();
1095 ASSERT_TRUE(OpenPlaygroundHere(dl));
1096}
void Clear(DlColor color)
Definition dl_canvas.h:104

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlBlurMaskFilter::Make(), flutter::DlPathBuilder::MoveTo(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), flutter::DlPathBuilder::TakePath(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [22/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawPaint   
)

Definition at line 515 of file aiks_dl_basic_unittests.cc.

515 {
516 auto medium_turquoise =
517 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
518
519 DisplayListBuilder builder;
520 builder.Scale(0.2, 0.2);
521 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
522 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
523}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::RGBA(), and flutter::DisplayListBuilder::Scale().

◆ TEST_P() [23/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawPaintMultipleTimes   
)

Definition at line 525 of file aiks_dl_basic_unittests.cc.

525 {
526 auto medium_turquoise =
527 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
528 auto orange_red =
529 DlColor::RGBA(255.0f / 255.0f, 69.0f / 255.0f, 0.0f / 255.0f, 1.0f);
530
531 DisplayListBuilder builder;
532 builder.Scale(0.2, 0.2);
533 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
534 builder.DrawPaint(DlPaint().setColor(orange_red.modulateOpacity(0.5f)));
535 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
536}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::RGBA(), and flutter::DisplayListBuilder::Scale().

◆ TEST_P() [24/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawPaintMultipleTimesInteractive   
)

Definition at line 692 of file aiks_dl_blend_unittests.cc.

692 {
693 auto modes = GetBlendModeSelection();
694
695 auto callback = [&]() -> sk_sp<DisplayList> {
696 static Color background = Color::MediumTurquoise();
697 static Color foreground = Color::Color::OrangeRed().WithAlpha(0.5);
698 static int current_blend_index = 3;
699
700 if (IsPlaygroundEnabled()) {
701 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
702 ImGui::ColorEdit4("Background", reinterpret_cast<float*>(&background));
703 ImGui::ColorEdit4("Foreground", reinterpret_cast<float*>(&foreground));
704 ImGui::ListBox("Blend mode", &current_blend_index,
705 modes.blend_mode_names.data(),
706 modes.blend_mode_names.size());
707 ImGui::End();
708 }
709
710 DisplayListBuilder builder;
711 builder.Scale(0.2, 0.2);
712 DlPaint paint;
713 paint.setColor(DlColor(background.ToARGB()));
714 builder.DrawPaint(paint);
715
716 paint.setColor(DlColor(foreground.ToARGB()));
717 paint.setBlendMode(static_cast<DlBlendMode>(current_blend_index));
718 builder.DrawPaint(paint);
719 return builder.Build();
720 };
721 ASSERT_TRUE(OpenPlaygroundHere(callback));
722}
static BlendModeSelection GetBlendModeSelection()

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawPaint(), GetBlendModeSelection(), impeller::Color::MediumTurquoise(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), impeller::Color::ToARGB(), and impeller::Color::WithAlpha().

◆ TEST_P() [25/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawPaintWithAdvancedBlend   
)

Definition at line 107 of file aiks_dl_blend_unittests.cc.

107 {
108 DisplayListBuilder builder;
109
110 builder.Scale(0.2, 0.2);
111 DlPaint paint;
112 paint.setColor(DlColor::RGBA(
113 Color::MediumTurquoise().red, Color::MediumTurquoise().green,
114 Color::MediumTurquoise().blue, Color::MediumTurquoise().alpha));
115 builder.DrawPaint(paint);
116
117 paint.setColor(DlColor::RGBA(Color::OrangeRed().red, Color::OrangeRed().green,
118 Color::OrangeRed().blue, 0.5));
119 paint.setBlendMode(DlBlendMode::kHue);
120 builder.DrawPaint(paint);
121
122 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
123}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), impeller::Color::MediumTurquoise(), impeller::Color::OrangeRed(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [26/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawPerspectiveConvexShadow   
)

Definition at line 933 of file aiks_dl_shadow_unittests.cc.

933 {
934 DisplayListBuilder builder;
935 builder.Clear(DlColor::kWhite());
936 builder.Scale(GetContentScale().x, GetContentScale().y);
937
938 // The rect path should be optimized to a rect-specific shadow shader.
939 DlPath rect_path = DlPath::MakeRectLTRB(-50, -50, 50, 75);
940
941 // The pentagon path should go through the general convex path shadow
942 // tessellator.
943 DlPathBuilder path_builder;
944 path_builder.MoveTo(DlPoint(-50, -50));
945 path_builder.LineTo(DlPoint(50, -50));
946 path_builder.LineTo(DlPoint(50, 50));
947 path_builder.LineTo(DlPoint(0, 75));
948 path_builder.LineTo(DlPoint(-50, 50));
949 path_builder.Close();
950 DlPath pentagon_path = path_builder.TakePath();
951
952 Matrix simple_y_rotate_matrix = Matrix::MakeRotationY(Degrees(45));
953
954 Matrix perspective_matrix;
955 perspective_matrix.e[2][3] = 0.0015f;
956 perspective_matrix = perspective_matrix * simple_y_rotate_matrix;
957
958 auto draw_paths_and_shadows = [&builder](const DlPath& path,
959 const DlColor& color,
960 const Matrix& matrix) {
961 builder.Save();
962
963 DlPaint paint;
964 paint.setColor(color.withAlphaF(0.25f));
965
966 DlPaint shadow_paint;
967 shadow_paint.setMaskFilter(
968 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 10.0f));
969
970 builder.Save();
971 builder.Transform(matrix);
972 builder.DrawPath(path, paint);
973 builder.Restore();
974
975 builder.Translate(150, 0);
976
977 builder.Save();
978 builder.Transform(matrix);
979 builder.DrawPath(path, shadow_paint);
980 builder.Restore();
981
982 builder.Translate(150, 0);
983
984 builder.Save();
985 builder.Transform(matrix);
986 builder.DrawPath(path, shadow_paint);
987 builder.DrawPath(path, paint);
988 builder.Restore();
989
990 builder.Restore();
991 };
992
993 auto draw_test = [&](const DlPath& path) {
994 builder.Save();
995
996 builder.Translate(0, 75);
997 builder.DrawPath(path, DlPaint(DlColor::kPurple()));
998
999 builder.Translate(150, -75);
1000 draw_paths_and_shadows(path, DlColor::kGreen(), simple_y_rotate_matrix);
1001 builder.Translate(0, 175);
1002 draw_paths_and_shadows(path, DlColor::kBlue(), perspective_matrix);
1003
1004 builder.Restore();
1005 };
1006
1007 builder.Translate(100, 100);
1008
1009 draw_test(rect_path);
1010 builder.Translate(0, 350);
1011 draw_test(pentagon_path);
1012
1013 auto dl = builder.Build();
1014 ASSERT_TRUE(OpenPlaygroundHere(dl));
1015}
void Transform(const DlMatrix &matrix) override

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPath(), impeller::Matrix::e, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kPurple(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlBlurMaskFilter::Make(), flutter::DlPath::MakeRectLTRB(), impeller::Matrix::MakeRotationY(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), flutter::DlPathBuilder::TakePath(), flutter::DisplayListBuilder::Transform(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [27/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawPerspectiveTransformWithClips   
)

Definition at line 1620 of file aiks_dl_basic_unittests.cc.

1620 {
1621 // Avoiding `GetSecondsElapsed()` to reduce risk of golden flakiness.
1622 int time = 0;
1623 auto callback = [&]() -> sk_sp<DisplayList> {
1624 DisplayListBuilder builder;
1625
1626 builder.Save();
1627 {
1628 builder.Translate(300, 300);
1629
1630 // 1. Draw/restore a clip before drawing the image, which will get drawn
1631 // to the depth buffer behind the image.
1632 builder.Save();
1633 {
1634 DlPaint paint;
1635 paint.setColor(DlColor::kGreen());
1636 builder.DrawPaint(paint);
1637 builder.ClipRect(DlRect::MakeLTRB(-180, -180, 180, 180),
1638 DlClipOp::kDifference);
1639
1640 paint.setColor(DlColor::kBlack());
1641 builder.DrawPaint(paint);
1642 }
1643 builder.Restore(); // Restore rectangle difference clip.
1644
1645 builder.Save();
1646 {
1647 // 2. Draw an oval clip that applies to the image, which will get drawn
1648 // in front of the image on the depth buffer.
1649 builder.ClipOval(DlRect::MakeLTRB(-200, -200, 200, 200));
1650
1651 Matrix result =
1652 Matrix(1.0, 0.0, 0.0, 0.0, //
1653 0.0, 1.0, 0.0, 0.0, //
1654 0.0, 0.0, 1.0, 0.003, //
1655 0.0, 0.0, 0.0, 1.0) *
1656 Matrix::MakeRotationY({Radians{-1.0f + (time++ / 60.0f)}});
1657
1658 // 3. Draw the rotating image with a perspective transform.
1659 builder.Transform(result);
1660
1661 auto image =
1662 DlImageImpeller::Make(CreateTextureForFixture("airplane.jpg"));
1663 auto position =
1664 -DlPoint(image->GetSize().width, image->GetSize().height) * 0.5;
1665 builder.DrawImage(image, position, {});
1666 }
1667 builder.Restore(); // Restore oval intersect clip.
1668
1669 // 4. Draw a semi-translucent blue circle atop all previous draws.
1670 DlPaint paint;
1671 paint.setColor(DlColor::kBlue().modulateOpacity(0.4));
1672 builder.DrawCircle(DlPoint(), 230, paint);
1673 }
1674 builder.Restore(); // Restore translation.
1675
1676 return builder.Build();
1677 };
1678 ASSERT_TRUE(OpenPlaygroundHere(callback));
1679}
void DrawImage(const sk_sp< DlImage > &image, const DlPoint &point, DlImageSampling sampling, const DlPaint *paint=nullptr) override
void ClipOval(const DlRect &bounds, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false) override

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::ClipOval(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawPaint(), image, flutter::DlColor::kBlack(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeRotationY(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColor(), flutter::DisplayListBuilder::Transform(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [28/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawPoints   
)

Definition at line 405 of file aiks_dl_unittests.cc.

405 {
406 std::vector<DlPoint> points = {
407 {0, 0}, //
408 {100, 100}, //
409 {100, 0}, //
410 {0, 100}, //
411 {0, 0}, //
412 {48, 48}, //
413 {52, 52}, //
414 };
415 DlPaint paint_round;
416 paint_round.setColor(DlColor::kYellow().withAlpha(128));
417 paint_round.setStrokeCap(DlStrokeCap::kRound);
418 paint_round.setStrokeWidth(20);
419
420 DlPaint paint_square;
421 paint_square.setColor(DlColor::kYellow().withAlpha(128));
422 paint_square.setStrokeCap(DlStrokeCap::kSquare);
423 paint_square.setStrokeWidth(20);
424
425 DlPaint background;
426 background.setColor(DlColor::kBlack());
427
428 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
429 builder.DrawPaint(background);
430 builder.Translate(200, 200);
431
432 builder.DrawPoints(DlPointMode::kPoints, points.size(), points.data(),
433 paint_round);
434 builder.Translate(150, 0);
435 builder.DrawPoints(DlPointMode::kPoints, points.size(), points.data(),
436 paint_square);
437
438 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
439}
DlPaint & setStrokeCap(DlStrokeCap cap)
Definition dl_paint.h:101

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPoints(), flutter::DlColor::kBlack(), flutter::DlColor::kYellow(), impeller::TRect< Scalar >::MakeSize(), points, flutter::DlPaint::setColor(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [29/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawPointsWithTextureMap   
)

Definition at line 441 of file aiks_dl_unittests.cc.

441 {
442 auto texture = DlImageImpeller::Make(
443 CreateTextureForFixture("table_mountain_nx.png",
444 /*enable_mipmapping=*/true));
445
446 std::vector<DlPoint> points = {
447 {0, 0}, //
448 {100, 100}, //
449 {100, 0}, //
450 {0, 100}, //
451 {0, 0}, //
452 {48, 48}, //
453 {52, 52}, //
454 };
455
456 auto image_src =
457 DlColorSource::MakeImage(texture, DlTileMode::kClamp, DlTileMode::kClamp);
458
459 DlPaint paint_round;
460 paint_round.setStrokeCap(DlStrokeCap::kRound);
461 paint_round.setColorSource(image_src);
462 paint_round.setStrokeWidth(200);
463
464 DlPaint paint_square;
465 paint_square.setStrokeCap(DlStrokeCap::kSquare);
466 paint_square.setColorSource(image_src);
467 paint_square.setStrokeWidth(200);
468
469 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
470 builder.Translate(200, 200);
471
472 builder.DrawPoints(DlPointMode::kPoints, points.size(), points.data(),
473 paint_round);
474 builder.Translate(150, 0);
475 builder.DrawPoints(DlPointMode::kPoints, points.size(), points.data(),
476 paint_square);
477
478 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
479}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPoints(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), impeller::TRect< Scalar >::MakeSize(), points, flutter::DlPaint::setColorSource(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), texture, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [30/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawRotatedConvexShadow   
)

Definition at line 1017 of file aiks_dl_shadow_unittests.cc.

1017 {
1018 DisplayListBuilder builder;
1019 builder.Clear(DlColor::kWhite());
1020 builder.Scale(GetContentScale().x, GetContentScale().y);
1021
1022 DlPathBuilder path_builder;
1023 path_builder.MoveTo(DlPoint(-50, -50));
1024 path_builder.LineTo(DlPoint(50, -50));
1025 path_builder.LineTo(DlPoint(50, 50));
1026 path_builder.LineTo(DlPoint(0, 75));
1027 path_builder.LineTo(DlPoint(-50, 50));
1028 path_builder.Close();
1029 DlPath pentagon_path = path_builder.TakePath();
1030
1031 DlPaint paint;
1032 paint.setColor(DlColor::kGreen().withAlphaF(0.25f));
1033
1034 DlPaint shadow_paint;
1035 shadow_paint.setMaskFilter(
1036 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 10.0f));
1037
1038 builder.Translate(500, 380);
1039
1040 for (int degrees = 0; degrees < 360; degrees += 30) {
1041 builder.Save();
1042 builder.Rotate(degrees);
1043 builder.Translate(0, -300);
1044 builder.DrawPath(pentagon_path, shadow_paint);
1045 builder.DrawPath(pentagon_path, paint);
1046 builder.Restore();
1047 }
1048
1049 auto dl = builder.Build();
1050 ASSERT_TRUE(OpenPlaygroundHere(dl));
1051}
void Rotate(DlScalar degrees) override

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlBlurMaskFilter::Make(), flutter::DlPathBuilder::MoveTo(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), flutter::DlPathBuilder::TakePath(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [31/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawScaledPointsLargeScaleSmallRadius   
)

Definition at line 844 of file aiks_dl_unittests.cc.

844 {
845 std::vector<DlPoint> point = {
846 {0, 0}, //
847 };
848
849 DlPaint paint;
850 paint.setStrokeCap(DlStrokeCap::kRound);
851 paint.setColor(DlColor::kRed());
852 paint.setStrokeWidth(100 * 0.000001);
853
854 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
855 builder.Translate(200, 200);
856 builder.Scale(1000000, 1000000);
857
858 builder.DrawPoints(DlPointMode::kPoints, point.size(), point.data(), paint);
859 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
860}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPoints(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeSize(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [32/662]

impeller::testing::TEST_P ( AiksTest  ,
CanDrawScaledPointsSmallScaleLargeRadius   
)

Definition at line 824 of file aiks_dl_unittests.cc.

824 {
825 std::vector<DlPoint> point = {
826 {0, 0}, //
827 };
828
829 DlPaint paint;
830 paint.setStrokeCap(DlStrokeCap::kRound);
831 paint.setColor(DlColor::kRed());
832 paint.setStrokeWidth(100 * 1000000);
833
834 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
835 builder.Translate(200, 200);
836 builder.Scale(0.000001, 0.000001);
837
838 builder.DrawPoints(DlPointMode::kPoints, point.size(), point.data(), paint);
839
840 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
841}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPoints(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeSize(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [33/662]

impeller::testing::TEST_P ( AiksTest  ,
CanEmptyPictureConvertToImage   
)

Definition at line 965 of file aiks_dl_unittests.cc.

965 {
966 DisplayListBuilder recorder_builder;
967
968 DisplayListBuilder builder;
969 AiksContext renderer(GetContext(), nullptr);
970
971 DlPaint paint;
972 paint.setColor(DlColor::kTransparent());
973 builder.DrawPaint(paint);
974
975 auto result_image =
976 DisplayListToTexture(builder.Build(), ISize{1000, 1000}, renderer);
977 if (result_image) {
978 recorder_builder.DrawImage(DlImageImpeller::Make(result_image), DlPoint(),
979 {});
980
981 paint.setColor(DlColor::RGBA(0.1, 0.1, 0.1, 0.2));
982 recorder_builder.DrawRect(DlRect::MakeWH(1000, 1000), paint);
983 }
984
985 ASSERT_TRUE(OpenPlaygroundHere(recorder_builder.Build()));
986}

References flutter::DisplayListBuilder::Build(), impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kTransparent(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeWH(), flutter::DlColor::RGBA(), and flutter::DlPaint::setColor().

◆ TEST_P() [34/662]

impeller::testing::TEST_P ( AiksTest  ,
CanPerformFullScreenMSAA   
)

Definition at line 1967 of file aiks_dl_basic_unittests.cc.

1967 {
1968 DisplayListBuilder builder;
1969
1970 DlPaint paint;
1971 paint.setColor(DlColor::kRed());
1972 builder.DrawCircle(DlPoint(250, 250), 125, paint);
1973
1974 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1975}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kRed(), and flutter::DlPaint::setColor().

◆ TEST_P() [35/662]

impeller::testing::TEST_P ( AiksTest  ,
CanPerformSaveLayerWithBounds   
)

Definition at line 1988 of file aiks_dl_basic_unittests.cc.

1988 {
1989 DisplayListBuilder builder;
1990
1991 DlPaint save;
1992 save.setColor(DlColor::kBlack());
1993
1994 DlRect save_bounds = DlRect::MakeXYWH(0, 0, 50, 50);
1995 builder.SaveLayer(save_bounds, &save);
1996
1997 DlPaint paint;
1998 paint.setColor(DlColor::kRed());
1999 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), paint);
2000 paint.setColor(DlColor::kGreen());
2001 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), paint);
2002 paint.setColor(DlColor::kBlue());
2003 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), paint);
2004
2005 builder.Restore();
2006
2007 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2008}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlack(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [36/662]

impeller::testing::TEST_P ( AiksTest  ,
CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated   
)

Definition at line 1883 of file aiks_dl_basic_unittests.cc.

1884 {
1885 DisplayListBuilder builder;
1886
1887 DlPaint red;
1888 red.setColor(DlColor::kRed());
1889
1890 DlPaint green;
1891 green.setColor(DlColor::kGreen());
1892
1893 DlPaint blue;
1894 blue.setColor(DlColor::kBlue());
1895
1896 DlPaint save;
1897 save.setColor(DlColor::kBlack().modulateOpacity(0.5));
1898
1899 DlRect huge_bounds = DlRect::MakeXYWH(0, 0, 100000, 100000);
1900 builder.SaveLayer(huge_bounds, &save);
1901
1902 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1903 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), green);
1904 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), blue);
1905
1906 builder.Restore();
1907
1908 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1909}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlack(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [37/662]

impeller::testing::TEST_P ( AiksTest  ,
CanPerformSkew   
)

Definition at line 1977 of file aiks_dl_basic_unittests.cc.

1977 {
1978 DisplayListBuilder builder;
1979
1980 DlPaint red;
1981 red.setColor(DlColor::kRed());
1982 builder.Skew(2, 5);
1983 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1984
1985 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1986}
void Skew(DlScalar sx, DlScalar sy) override

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), and flutter::DisplayListBuilder::Skew().

◆ TEST_P() [38/662]

impeller::testing::TEST_P ( AiksTest  ,
CanPictureConvertToImage   
)

Definition at line 938 of file aiks_dl_unittests.cc.

938 {
939 DisplayListBuilder recorder_canvas;
940 DlPaint paint;
941 paint.setColor(DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0));
942 recorder_canvas.DrawRect(DlRect::MakeXYWH(100.0, 100.0, 600, 600), paint);
943 paint.setColor(DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0));
944 recorder_canvas.DrawRect(DlRect::MakeXYWH(200.0, 200.0, 600, 600), paint);
945
946 DisplayListBuilder canvas;
947 AiksContext renderer(GetContext(), nullptr);
948 paint.setColor(DlColor::kTransparent());
949 canvas.DrawPaint(paint);
950
951 auto image =
952 DisplayListToTexture(recorder_canvas.Build(), {1000, 1000}, renderer);
953 if (image) {
954 canvas.DrawImage(DlImageImpeller::Make(image), DlPoint(), {});
955 paint.setColor(DlColor::RGBA(0.1, 0.1, 0.1, 0.2));
956 canvas.DrawRect(DlRect::MakeWH(1000, 1000), paint);
957 }
958
959 ASSERT_TRUE(OpenPlaygroundHere(canvas.Build()));
960}

References flutter::DisplayListBuilder::Build(), impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), image, flutter::DlColor::kTransparent(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeWH(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlColor::RGBA(), and flutter::DlPaint::setColor().

◆ TEST_P() [39/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderAdvancedBlendColorFilterWithSaveLayer   
)

Definition at line 61 of file aiks_dl_blend_unittests.cc.

61 {
62 DisplayListBuilder builder;
63
64 DlRect layer_rect = DlRect::MakeXYWH(0, 0, 500, 500);
65 builder.ClipRect(layer_rect);
66
67 DlPaint save_paint;
68 save_paint.setColorFilter(DlColorFilter::MakeBlend(
69 DlColor::RGBA(0, 1, 0, 0.5), DlBlendMode::kDifference));
70 builder.SaveLayer(layer_rect, &save_paint);
71
72 DlPaint paint;
73 paint.setColor(DlColor::kBlack());
74 builder.DrawPaint(paint);
75 paint.setColor(DlColor::kWhite());
76 builder.DrawRect(DlRect::MakeXYWH(100, 100, 300, 300), paint);
77 builder.Restore();
78
79 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
80}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlack(), flutter::DlColor::kWhite(), flutter::DlColorFilter::MakeBlend(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), and flutter::DlPaint::setColorFilter().

◆ TEST_P() [40/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderAsymmetricRoundSuperellipses   
)

Definition at line 2517 of file aiks_dl_basic_unittests.cc.

2517 {
2518 DisplayListBuilder builder;
2519 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2520 DlPaint paint;
2521 paint.setColor(DlColor::kBlue());
2522
2523 builder.DrawRoundSuperellipse(
2524 DlRoundSuperellipse::MakeRectRadii(
2525 /*rect=*/DlRect::MakeXYWH(50, 50, 440, 440), /*radii=*/
2526 {
2527 .top_left = Size(60.0f, 240.0f),
2528 .top_right = Size(200.0f, 40.0f),
2529 .bottom_left = Size(180.0f, 20.0f),
2530 .bottom_right = Size(40.0f, 200.0f),
2531 }),
2532 paint);
2533
2534 builder.DrawRoundSuperellipse(
2535 DlRoundSuperellipse::MakeRectRadii(
2536 /*rect=*/DlRect::MakeXYWH(550, 50, 440, 440), /*radii=*/
2537 {
2538 .top_left = Size(240.0f, 40.0f),
2539 .top_right = Size(40.0f, 240.0f),
2540 .bottom_left = Size(40.0f, 240.0f),
2541 .bottom_right = Size(240.0f, 40.0f),
2542 }),
2543 paint);
2544
2545 builder.DrawRoundSuperellipse(
2546 DlRoundSuperellipse::MakeRectRadii(
2547 /*rect=*/DlRect::MakeXYWH(50, 550, 400, 400), /*radii=*/
2548 {
2549 .top_left = Size(240.0f, 240.0f),
2550 .top_right = Size(40.0f, 40.0f),
2551 .bottom_left = Size(40.0f, 40.0f),
2552 .bottom_right = Size(40.0f, 40.0f),
2553 }),
2554 paint);
2555
2556 builder.DrawRoundSuperellipse(
2557 DlRoundSuperellipse::MakeRectRadii(
2558 /*rect=*/DlRect::MakeXYWH(550, 550, 400, 400), /*radii=*/
2559 {
2560 .top_left = Size(240.0f, 240.0f),
2561 .top_right = Size(40.0f, 40.0f),
2562 .bottom_left = Size(40.0f, 40.0f),
2563 .bottom_right = Size(240.0f, 240.0f),
2564 }),
2565 paint);
2566
2567 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2568}
void DrawColor(DlColor color, DlBlendMode mode) override
void DrawRoundSuperellipse(const DlRoundSuperellipse &rse, const DlPaint &paint) override

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawRoundSuperellipse(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), impeller::RoundSuperellipse::MakeRectRadii(), impeller::TRect< Scalar >::MakeXYWH(), and flutter::DlPaint::setColor().

◆ TEST_P() [41/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderBackdropBlur   
)

Definition at line 242 of file aiks_dl_blur_unittests.cc.

242 {
243 DisplayListBuilder builder;
244
245 DlPaint paint;
246 paint.setColor(DlColor::kCornflowerBlue());
247 builder.DrawCircle(DlPoint(100, 100), 50, paint);
248
249 paint.setColor(DlColor::kGreenYellow());
250 builder.DrawCircle(DlPoint(300, 200), 100, paint);
251
252 paint.setColor(DlColor::kDarkMagenta());
253 builder.DrawCircle(DlPoint(140, 170), 75, paint);
254
255 paint.setColor(DlColor::kOrangeRed());
256 builder.DrawCircle(DlPoint(180, 120), 100, paint);
257
258 DlRoundRect rrect =
259 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(75, 50, 375, 275), 20, 20);
260 builder.ClipRoundRect(rrect);
261
262 DlPaint save_paint;
263 save_paint.setBlendMode(DlBlendMode::kSrc);
264 auto backdrop_filter = DlImageFilter::MakeBlur(30, 30, DlTileMode::kClamp);
265 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
266 builder.Restore();
267
268 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
269}
void ClipRoundRect(const DlRoundRect &rrect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false) override

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRoundRect(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kCornflowerBlue(), flutter::DlColor::kDarkMagenta(), flutter::DlColor::kGreenYellow(), flutter::DlColor::kOrangeRed(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectXY(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [42/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderBackdropBlurHugeSigma   
)

Definition at line 352 of file aiks_dl_blur_unittests.cc.

352 {
353 DisplayListBuilder builder;
354
355 DlPaint paint;
356 paint.setColor(DlColor::kGreen());
357 builder.DrawCircle(DlPoint(400, 400), 300, paint);
358
359 DlPaint save_paint;
360 save_paint.setBlendMode(DlBlendMode::kSrc);
361
362 auto backdrop_filter =
363 DlImageFilter::MakeBlur(999999, 999999, DlTileMode::kClamp);
364 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
365 builder.Restore();
366
367 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
368}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kGreen(), flutter::DlImageFilter::MakeBlur(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [43/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderBackdropBlurInteractive   
)

Definition at line 205 of file aiks_dl_blur_unittests.cc.

205 {
206 auto callback = [&]() -> sk_sp<DisplayList> {
207 static PlaygroundPoint point_a(Point(50, 50), 30, Color::White());
208 static PlaygroundPoint point_b(Point(300, 200), 30, Color::White());
209 auto [a, b] = DrawPlaygroundLine(point_a, point_b);
210
211 DisplayListBuilder builder;
212 DlPaint paint;
213 paint.setColor(DlColor::kCornflowerBlue());
214 builder.DrawCircle(DlPoint(100, 100), 50, paint);
215
216 paint.setColor(DlColor::kGreenYellow());
217 builder.DrawCircle(DlPoint(300, 200), 100, paint);
218
219 paint.setColor(DlColor::kDarkMagenta());
220 builder.DrawCircle(DlPoint(140, 170), 75, paint);
221
222 paint.setColor(DlColor::kOrangeRed());
223 builder.DrawCircle(DlPoint(180, 120), 100, paint);
224
225 DlRoundRect rrect =
226 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(a.x, a.y, b.x, b.y), 20, 20);
227 builder.ClipRoundRect(rrect);
228
229 DlPaint save_paint;
230 save_paint.setBlendMode(DlBlendMode::kSrc);
231
232 auto backdrop_filter = DlImageFilter::MakeBlur(20, 20, DlTileMode::kClamp);
233 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
234 builder.Restore();
235
236 return builder.Build();
237 };
238
239 ASSERT_TRUE(OpenPlaygroundHere(callback));
240}
std::tuple< Point, Point > DrawPlaygroundLine(PlaygroundPoint &point_a, PlaygroundPoint &point_b)
Definition widgets.cc:51

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::ClipRoundRect(), flutter::DisplayListBuilder::DrawCircle(), impeller::DrawPlaygroundLine(), flutter::DlColor::kCornflowerBlue(), flutter::DlColor::kDarkMagenta(), flutter::DlColor::kGreenYellow(), flutter::DlColor::kOrangeRed(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectXY(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), and impeller::Color::White().

◆ TEST_P() [44/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderBackdropBlurWithSingleBackdropId   
)

Definition at line 271 of file aiks_dl_blur_unittests.cc.

271 {
272 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
273
274 DisplayListBuilder builder;
275
276 DlPaint paint;
277 builder.DrawImage(image, DlPoint(50.0, 50.0),
278 DlImageSampling::kNearestNeighbor, &paint);
279
280 DlRoundRect rrect =
281 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(50, 250, 100, 100), 20, 20);
282 builder.Save();
283 builder.ClipRoundRect(rrect);
284
285 DlPaint save_paint;
286 save_paint.setBlendMode(DlBlendMode::kSrc);
287 auto backdrop_filter = DlImageFilter::MakeBlur(30, 30, DlTileMode::kClamp);
288 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get(),
289 /*backdrop_id=*/1);
290 builder.Restore();
291 builder.Restore();
292
293 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
294}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRoundRect(), flutter::DisplayListBuilder::DrawImage(), image, impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setBlendMode().

◆ TEST_P() [45/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderBoundedBlur   
)

Definition at line 370 of file aiks_dl_blur_unittests.cc.

370 {
371 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
372
373 DisplayListBuilder builder;
374
375 DlPaint paint;
376 builder.DrawImage(image, DlPoint(0.0, 0.0), DlImageSampling::kNearestNeighbor,
377 &paint);
378
379 DlPaint save_paint;
380 save_paint.setBlendMode(DlBlendMode::kSrcOver);
381 builder.Save();
382
383 // Subcase 1: The 1st branch of downsampling, where the coverage hint is
384 // non-null but was ignored during snapshotting.
385
386 builder.Scale(1.1, 1.2);
387 builder.Rotate(10);
388 DlRect rect1 = DlRect::MakeLTRB(70, 70, 313, 170);
389 builder.ClipRect(rect1);
390 auto backdrop_filter1 =
391 DlBlurImageFilter::Make(20, 20, DlTileMode::kDecal, /*bounds=*/rect1);
392 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter1.get());
393 builder.Restore();
394 builder.Restore();
395
396 // Subcase 2: The 2nd branch of downsampling, where the coverage hint is null
397 // or was already used during snapshotting.
398
399 builder.Scale(1.1, 1.2);
400 builder.Rotate(10);
401 DlRect rect2 = DlRect::MakeLTRB(55, 190, 298, 290);
402 builder.ClipRect(rect2);
403 auto backdrop_filter2 =
404 DlBlurImageFilter::Make(20, 20, DlTileMode::kDecal, /*bounds=*/rect2);
405 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter2.get());
406 builder.Restore();
407 builder.Restore();
408
409 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
410}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawImage(), image, flutter::DlBlurImageFilter::Make(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), and flutter::DlPaint::setBlendMode().

◆ TEST_P() [46/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderClippedBackdropFilter   
)

Definition at line 1581 of file aiks_dl_basic_unittests.cc.

1581 {
1582 DisplayListBuilder builder;
1583
1584 builder.Scale(GetContentScale().x, GetContentScale().y);
1585
1586 // Draw something interesting in the background.
1587 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
1588 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0)};
1589 std::vector<Scalar> stops = {
1590 0.0,
1591 1.0,
1592 };
1593 DlPaint paint;
1594 paint.setColorSource(DlColorSource::MakeLinear(
1595 /*start_point=*/DlPoint(0, 0), //
1596 /*end_point=*/DlPoint(100, 100), //
1597 /*stop_count=*/2, //
1598 /*colors=*/colors.data(), //
1599 /*stops=*/stops.data(), //
1600 /*tile_mode=*/DlTileMode::kRepeat //
1601 ));
1602
1603 builder.DrawPaint(paint);
1604
1605 DlRect clip_rect = DlRect::MakeLTRB(50, 50, 400, 300);
1606 DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_rect, 100, 100);
1607
1608 // Draw a clipped SaveLayer, where the clip coverage and SaveLayer size are
1609 // the same.
1610 builder.ClipRoundRect(clip_rrect, DlClipOp::kIntersect);
1611
1612 DlPaint save_paint;
1613 auto backdrop_filter = DlImageFilter::MakeColorFilter(
1614 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kExclusion));
1615 builder.SaveLayer(clip_rect, &save_paint, backdrop_filter.get());
1616
1617 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1618}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRoundRect(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kRed(), flutter::DlColorFilter::MakeBlend(), flutter::DlImageFilter::MakeColorFilter(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectXY(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColorSource(), x, and y.

◆ TEST_P() [47/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderClippedBlur   
)

Definition at line 412 of file aiks_dl_blur_unittests.cc.

412 {
413 DisplayListBuilder builder;
414 builder.ClipRect(DlRect::MakeXYWH(100, 150, 400, 400));
415
416 DlPaint paint;
417 paint.setColor(DlColor::kGreen());
418 paint.setImageFilter(DlImageFilter::MakeBlur(20, 20, DlTileMode::kDecal));
419 builder.DrawCircle(DlPoint(400, 400), 200, paint);
420 builder.Restore();
421
422 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
423}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kGreen(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DlPaint::setColor(), and flutter::DlPaint::setImageFilter().

◆ TEST_P() [48/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderClippedLayers   
)

Definition at line 2222 of file aiks_dl_basic_unittests.cc.

2222 {
2223 DisplayListBuilder builder;
2224
2225 DlPaint paint;
2226 paint.setColor(DlColor::kWhite());
2227 builder.DrawPaint(paint);
2228
2229 // Draw a green circle on the screen.
2230 {
2231 // Increase the clip depth for the savelayer to contend with.
2232 DlPath path = DlPath::MakeCircle(DlPoint(100, 100), 50);
2233 builder.ClipPath(path);
2234
2235 DlRect bounds = DlRect::MakeXYWH(50, 50, 100, 100);
2236 DlPaint save_paint;
2237 builder.SaveLayer(bounds, &save_paint);
2238
2239 // Fill the layer with white.
2240 paint.setColor(DlColor::kWhite());
2241 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
2242 // Fill the layer with green, but do so with a color blend that can't be
2243 // collapsed into the parent pass.
2244 paint.setColor(DlColor::kGreen());
2245 paint.setBlendMode(DlBlendMode::kHardLight);
2246 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
2247 }
2248
2249 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2250}
void ClipPath(const DlPath &path, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false) override

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipPath(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), flutter::DlPath::MakeCircle(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), flutter::path, flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [49/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderClippedRuntimeEffects   
)

Definition at line 54 of file aiks_dl_runtime_effect_unittests.cc.

54 {
55 // This test used to be excluded on Vulkan for impeller_golden_tests
56 // but has been running fine so far with the playground-based golden
57 // mechanism, so we will let it run as the underlying problem may
58 // have been fixed since the exclusion was added.
59 // https://github.com/flutter/flutter/blame/ad80825c24d770a19e33f67800fc0338a3b89ec7/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc#L109
60
61 struct FragUniforms {
62 Vector2 iResolution;
63 Scalar iTime;
64 } frag_uniforms = {.iResolution = Vector2(400, 400), .iTime = 100.0};
65 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
66 uniform_data->resize(sizeof(FragUniforms));
67 memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
68
69 DlPaint paint;
70 auto effect =
71 MakeRuntimeEffect(this, "runtime_stage_example.frag.iplr", uniform_data);
72 ABSL_ASSERT_OK(effect);
73 paint.setColorSource(effect.value());
74
75 DisplayListBuilder builder;
76 builder.Save();
77 builder.ClipRoundRect(
78 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(0, 0, 400, 400), 10.0, 10.0),
79 DlClipOp::kIntersect);
80 builder.DrawRect(DlRect::MakeXYWH(0, 0, 400, 400), paint);
81 builder.Restore();
82
83 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
84}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRoundRect(), flutter::DisplayListBuilder::DrawRect(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), and flutter::DlPaint::setColorSource().

◆ TEST_P() [50/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderClips   
)

Definition at line 752 of file aiks_dl_path_unittests.cc.

752 {
753 DisplayListBuilder builder;
754 DlPaint paint;
755 paint.setColor(DlColor::kFuchsia());
756
757 builder.ClipPath(DlPath::MakeRect(DlRect::MakeXYWH(0, 0, 500, 500)));
758 builder.DrawPath(DlPath::MakeCircle(DlPoint(500, 500), 250), paint);
759
760 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
761}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipPath(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kFuchsia(), flutter::DlPath::MakeCircle(), flutter::DlPath::MakeRect(), impeller::TRect< Scalar >::MakeXYWH(), and flutter::DlPaint::setColor().

◆ TEST_P() [51/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderColoredRect   
)

Definition at line 32 of file aiks_dl_basic_unittests.cc.

32 {
33 DisplayListBuilder builder;
34 DlPaint paint;
35 paint.setColor(DlColor::kBlue());
36 builder.DrawPath(DlPath::MakeRectXYWH(100.0f, 100.0f, 100.0f, 100.0f), paint);
37 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
38}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kBlue(), flutter::DlPath::MakeRectXYWH(), and flutter::DlPaint::setColor().

◆ TEST_P() [52/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderColoredRectPrimitive   
)

Definition at line 40 of file aiks_dl_basic_unittests.cc.

40 {
41 DisplayListBuilder builder;
42 DlPaint paint;
43 paint.setColor(DlColor::kBlue());
44 builder.DrawRect(DlRect::MakeXYWH(100.f, 100.f, 100.f, 100.f), paint);
45 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
46}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), impeller::TRect< Scalar >::MakeXYWH(), and flutter::DlPaint::setColor().

◆ TEST_P() [53/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderColorFilterWithInvertColors   
)

Definition at line 141 of file aiks_dl_basic_unittests.cc.

141 {
142 DisplayListBuilder builder;
143 DlPaint paint;
144 paint.setColor(DlColor::kRed());
145 paint.setColorFilter(
146 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
147 paint.setInvertColors(true);
148
149 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
150 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
151}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), flutter::DlColorFilter::MakeBlend(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), and flutter::DlPaint::setInvertColors().

◆ TEST_P() [54/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderColorFilterWithInvertColorsDrawPaint   
)

Definition at line 153 of file aiks_dl_basic_unittests.cc.

153 {
154 DisplayListBuilder builder;
155 DlPaint paint;
156 paint.setColor(DlColor::kRed());
157 paint.setColorFilter(
158 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
159 paint.setInvertColors(true);
160
161 builder.DrawPaint(paint);
162 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
163}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), flutter::DlColorFilter::MakeBlend(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), and flutter::DlPaint::setInvertColors().

◆ TEST_P() [55/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderConicalGradient   
)

Definition at line 675 of file aiks_dl_gradient_unittests.cc.

675 {
676 Scalar size = 256;
677 DisplayListBuilder builder;
678 DlPaint paint;
679 paint.setColor(DlColor::kWhite());
680 builder.DrawRect(DlRect::MakeXYWH(0, 0, size * 3, size * 3), paint);
681 std::vector<DlColor> colors = {
682 DlColor(Color::MakeRGBA8(0xF4, 0x43, 0x36, 0xFF).ToARGB()),
683 DlColor(Color::MakeRGBA8(0xFF, 0xEB, 0x3B, 0xFF).ToARGB()),
684 DlColor(Color::MakeRGBA8(0x4c, 0xAF, 0x50, 0xFF).ToARGB()),
685 DlColor(Color::MakeRGBA8(0x21, 0x96, 0xF3, 0xFF).ToARGB())};
686 std::vector<Scalar> stops = {0.0, 1.f / 3.f, 2.f / 3.f, 1.0};
687 std::array<std::tuple<DlPoint, float, DlPoint, float>, 8> array{
688 std::make_tuple(DlPoint(size / 2.f, size / 2.f), 0.f,
689 DlPoint(size / 2.f, size / 2.f), size / 2.f),
690 std::make_tuple(DlPoint(size / 2.f, size / 2.f), size / 4.f,
691 DlPoint(size / 2.f, size / 2.f), size / 2.f),
692 std::make_tuple(DlPoint(size / 4.f, size / 4.f), 0.f,
693 DlPoint(size / 2.f, size / 2.f), size / 2.f),
694 std::make_tuple(DlPoint(size / 4.f, size / 4.f), size / 2.f,
695 DlPoint(size / 2.f, size / 2.f), 0),
696 std::make_tuple(DlPoint(size / 4.f, size / 4.f), size / 4.f,
697 DlPoint(size / 2.f, size / 2.f), size / 2.f),
698 std::make_tuple(DlPoint(size / 4.f, size / 4.f), size / 16.f,
699 DlPoint(size / 2.f, size / 2.f), size / 8.f),
700 std::make_tuple(DlPoint(size / 4.f, size / 4.f), size / 8.f,
701 DlPoint(size / 2.f, size / 2.f), size / 16.f),
702 std::make_tuple(DlPoint(size / 8.f, size / 8.f), size / 8.f,
703 DlPoint(size / 2.f, size / 2.f), size / 8.f),
704 };
705 for (int i = 0; i < 8; i++) {
706 builder.Save();
707 builder.Translate((i % 3) * size, i / 3 * size);
709 /*start_center=*/std::get<2>(array[i]),
710 /*start_radius=*/std::get<3>(array[i]),
711 /*end_center=*/std::get<0>(array[i]),
712 /*end_radius=*/std::get<1>(array[i]),
713 /*stop_count=*/stops.size(),
714 /*colors=*/colors.data(),
715 /*stops=*/stops.data(),
716 /*tile_mode=*/DlTileMode::kClamp));
717 builder.DrawRect(DlRect::MakeXYWH(0, 0, size, size), paint);
718 builder.Restore();
719 }
720 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
721}
static constexpr DlColor kWhite()
Definition dl_color.h:70
static constexpr Color MakeRGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Definition color.h:152

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), i, flutter::DlColor::kWhite(), flutter::DlColorSource::MakeConical(), impeller::Color::MakeRGBA8(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::size, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [56/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderConicalGradientWithDitheringEnabled   
)

Definition at line 194 of file aiks_dl_gradient_unittests.cc.

194 {
196}
static void CanRenderConicalGradientWithDithering(AiksTest *aiks_test)

References CanRenderConicalGradientWithDithering().

◆ TEST_P() [57/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderConicalGradientWithIncompleteStops   
)

Definition at line 336 of file aiks_dl_gradient_unittests.cc.

336 {
337 CanRenderGradientWithIncompleteStops(this,
338 DlColorSourceType::kConicalGradient);
339}

◆ TEST_P() [58/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderCurvedStrokes   
)

Definition at line 71 of file aiks_dl_path_unittests.cc.

71 {
72 DisplayListBuilder builder;
73 DlPaint paint;
74 paint.setColor(DlColor::kRed());
75 paint.setStrokeWidth(25);
76 paint.setDrawStyle(DlDrawStyle::kStroke);
77
78 builder.DrawPath(DlPath::MakeCircle(DlPoint(500, 500), 250), paint);
79
80 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
81}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPath::MakeCircle(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [59/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderDestructiveSaveLayer   
)

Definition at line 383 of file aiks_dl_unittests.cc.

383 {
384 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
385
386 DlPaint paint;
387 paint.setColor(DlColor::kRed());
388 builder.DrawPaint(paint);
389 // Draw an empty savelayer with a destructive blend mode, which will replace
390 // the entire red screen with fully transparent black, except for the green
391 // circle drawn within the layer.
392
393 DlPaint save_paint;
394 save_paint.setBlendMode(DlBlendMode::kSrc);
395 builder.SaveLayer(std::nullopt, &save_paint);
396
397 DlPaint draw_paint;
398 draw_paint.setColor(DlColor::kGreen());
399 builder.DrawCircle(DlPoint(300, 300), 100, draw_paint);
400 builder.Restore();
401
402 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
403}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeSize(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [60/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderDifferenceClips   
)

Definition at line 35 of file aiks_dl_clip_unittests.cc.

35 {
36 DisplayListBuilder builder;
37 builder.Translate(400, 400);
38
39 // Limit drawing to face circle with a clip.
40 builder.ClipPath(DlPath::MakeCircle(DlPoint(0, 0), 200));
41 builder.Save();
42
43 // Cut away eyes/mouth using difference clips.
44 builder.ClipPath(DlPath::MakeCircle(DlPoint(-100, -50), 30),
45 DlClipOp::kDifference);
46 builder.ClipPath(DlPath::MakeCircle(DlPoint(100, -50), 30),
47 DlClipOp::kDifference);
48
49 DlPathBuilder path_builder;
50 path_builder.MoveTo(DlPoint(-100, 50));
51 path_builder.QuadraticCurveTo(DlPoint(0, 150), DlPoint(100, 50));
52 builder.ClipPath(path_builder.TakePath(), DlClipOp::kDifference);
53
54 // Draw a huge yellow rectangle to prove the clipping works.
55 DlPaint paint;
56 paint.setColor(DlColor::kYellow());
57 builder.DrawRect(DlRect::MakeCircleBounds({0, 0}, 1000), paint);
58
59 // Remove the difference clips and draw hair that partially covers the eyes.
60 builder.Restore();
61 paint.setColor(DlColor::kMaroon());
62 DlPathBuilder path_builder_2;
63 path_builder_2.MoveTo(DlPoint(200, -200));
64 path_builder_2.LineTo(DlPoint(-200, -200));
65 path_builder_2.LineTo(DlPoint(-200, -40));
66 path_builder_2.CubicCurveTo(DlPoint(0, -40), DlPoint(0, -80),
67 DlPoint(200, -80));
68
69 builder.DrawPath(path_builder_2.TakePath(), paint);
70
71 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
72}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipPath(), flutter::DlPathBuilder::CubicCurveTo(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kMaroon(), flutter::DlColor::kYellow(), flutter::DlPathBuilder::LineTo(), flutter::DlPath::MakeCircle(), impeller::TRect< Scalar >::MakeCircleBounds(), flutter::DlPathBuilder::MoveTo(), flutter::DlPathBuilder::QuadraticCurveTo(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColor(), flutter::DlPathBuilder::TakePath(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [61/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderDifferencePaths   
)

Definition at line 442 of file aiks_dl_path_unittests.cc.

442 {
443 DisplayListBuilder builder;
444
445 DlPaint paint;
446 paint.setColor(DlColor::kRed());
447
448 RoundingRadii radii = {
449 .top_left = {50, 25},
450 .top_right = {25, 50},
451 .bottom_left = {25, 50},
452 .bottom_right = {50, 25},
453 };
454 DlPathBuilder path_builder;
455 DlRoundRect rrect =
456 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 200, 200), radii);
457 // We use the factory method to convert the rrect and circle to a path so
458 // that they use the legacy conics for legacy golden output.
459 path_builder.AddPath(DlPath::MakeRoundRect(rrect));
460 path_builder.AddPath(DlPath::MakeCircle(DlPoint(200, 200), 50));
461 path_builder.SetFillType(DlPathFillType::kOdd);
462 DlPath path = path_builder.TakePath();
463
464 builder.DrawImage(
465 DlImageImpeller::Make(CreateTextureForFixture("boston.jpg")),
466 DlPoint{10, 10}, {});
467 builder.DrawPath(path, paint);
468
469 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
470}

References flutter::DlPathBuilder::AddPath(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), impeller::DlImageImpeller::Make(), flutter::DlPath::MakeCircle(), impeller::RoundRect::MakeRectRadii(), flutter::DlPath::MakeRoundRect(), impeller::TRect< Scalar >::MakeXYWH(), flutter::path, flutter::DlPaint::setColor(), flutter::DlPathBuilder::SetFillType(), flutter::DlPathBuilder::TakePath(), and impeller::RoundingRadii::top_left.

◆ TEST_P() [62/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderDifferentShapesWithSameColorSource   
)

Definition at line 427 of file aiks_dl_basic_unittests.cc.

427 {
428 DisplayListBuilder builder;
429 DlPaint paint;
430
431 DlColor colors[2] = {
432 DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
433 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0),
434 };
435 DlScalar stops[2] = {
436 0.0,
437 1.0,
438 };
439
440 paint.setColorSource(DlColorSource::MakeLinear(
441 /*start_point=*/DlPoint(0, 0), //
442 /*end_point=*/DlPoint(100, 100), //
443 /*stop_count=*/2, //
444 /*colors=*/colors, //
445 /*stops=*/stops, //
446 /*tile_mode=*/DlTileMode::kRepeat //
447 ));
448
449 builder.Save();
450 builder.Translate(100, 100);
451 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), paint);
452 builder.Restore();
453
454 builder.Save();
455 builder.Translate(100, 400);
456 builder.DrawCircle(DlPoint(100, 100), 100, paint);
457 builder.Restore();
458 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
459}
flutter::DlScalar DlScalar

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColorSource(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [63/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderEmojiTextFrame   
)

Definition at line 385 of file aiks_dl_text_unittests.cc.

385 {
386 DisplayListBuilder builder;
387
388 DlPaint paint;
389 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
390 builder.DrawPaint(paint);
391
392 ASSERT_TRUE(RenderTextInCanvasSkia(
393 GetContext(), builder, "😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊", kFontFixture));
394 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
395}
bool RenderTextInCanvasSkia(const std::shared_ptr< Context > &context, DisplayListBuilder &canvas, const std::string &text, const std::string_view &font_fixture, const TextRenderOptions &options={}, const std::optional< SkFont > &font=std::nullopt)
static constexpr DlColor ARGB(DlScalar a, DlScalar r, DlScalar g, DlScalar b)
Construct a 32 bit color from floating point A, R, G, and B color channels.
Definition dl_color.h:57

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), kFontFixture, RenderTextInCanvasSkia(), and flutter::DlPaint::setColor().

◆ TEST_P() [64/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderEmojiTextFrameWithAlpha   
)

Definition at line 413 of file aiks_dl_text_unittests.cc.

413 {
414 DisplayListBuilder builder;
415
416 DlPaint paint;
417 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
418 builder.DrawPaint(paint);
419
420 ASSERT_TRUE(RenderTextInCanvasSkia(
421 GetContext(), builder, "😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊", kFontFixture,
422 {.color = DlColor::kBlack().modulateOpacity(0.5)}));
423 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
424}
static constexpr DlColor kBlack()
Definition dl_color.h:69
constexpr DlColor modulateOpacity(DlScalar opacity) const
Definition dl_color.h:150

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kBlack(), kFontFixture, flutter::DlColor::modulateOpacity(), RenderTextInCanvasSkia(), and flutter::DlPaint::setColor().

◆ TEST_P() [65/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderEmojiTextFrameWithBlur   
)

Definition at line 397 of file aiks_dl_text_unittests.cc.

397 {
398 DisplayListBuilder builder;
399
400 builder.Scale(GetContentScale().x, GetContentScale().y);
401 DlPaint paint;
402 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
403 builder.DrawPaint(paint);
404
405 ASSERT_TRUE(RenderTextInCanvasSkia(
406 GetContext(), builder, "😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊", kFontFixture,
409 .filter = DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 4)}));
410 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
411}
static std::shared_ptr< DlMaskFilter > Make(DlBlurStyle style, SkScalar sigma, bool respect_ctm=true)

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), impeller::testing::TextRenderOptions::color, flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kBlue(), kFontFixture, flutter::DlBlurMaskFilter::Make(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [66/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderFilledConicPaths   
)

Definition at line 159 of file aiks_dl_path_unittests.cc.

159 {
160 DisplayListBuilder builder;
161 builder.Scale(GetContentScale().x, GetContentScale().y);
162
163 DlPaint paint;
164 paint.setColor(DlColor::kRed());
165 paint.setDrawStyle(DlDrawStyle::kFill);
166
167 DlPaint reference_paint;
168 reference_paint.setColor(DlColor::kGreen());
169 reference_paint.setDrawStyle(DlDrawStyle::kFill);
170
171 DlPathBuilder path_builder;
172 DlPathBuilder reference_builder;
173
174 // weight of 1.0 is just a quadratic bezier
175 path_builder.MoveTo(DlPoint(100, 100));
176 path_builder.ConicCurveTo(DlPoint(150, 150), DlPoint(200, 100), 1.0f);
177 reference_builder.MoveTo(DlPoint(300, 100));
178 reference_builder.QuadraticCurveTo(DlPoint(350, 150), DlPoint(400, 100));
179
180 // weight of sqrt(2)/2 is a circular section
181 path_builder.MoveTo(DlPoint(100, 200));
182 path_builder.ConicCurveTo(DlPoint(150, 250), DlPoint(200, 200), kSqrt2Over2);
183 reference_builder.MoveTo(DlPoint(300, 200));
184 auto magic = DlPathBuilder::kArcApproximationMagic;
185 reference_builder.CubicCurveTo(DlPoint(300, 200) + DlPoint(50, 50) * magic,
186 DlPoint(400, 200) + DlPoint(-50, 50) * magic,
187 DlPoint(400, 200));
188
189 // weight of .01 is nearly a straight line
190 path_builder.MoveTo(DlPoint(100, 300));
191 path_builder.ConicCurveTo(DlPoint(150, 350), DlPoint(200, 300), 0.01f);
192 reference_builder.MoveTo(DlPoint(300, 300));
193 reference_builder.LineTo(DlPoint(350, 300.5));
194 reference_builder.LineTo(DlPoint(400, 300));
195
196 // weight of 100.0 is nearly a triangle
197 path_builder.MoveTo(DlPoint(100, 400));
198 path_builder.ConicCurveTo(DlPoint(150, 450), DlPoint(200, 400), 100.0f);
199 reference_builder.MoveTo(DlPoint(300, 400));
200 reference_builder.LineTo(DlPoint(350, 450));
201 reference_builder.LineTo(DlPoint(400, 400));
202
203 builder.DrawPath(path_builder.TakePath(), paint);
204 builder.DrawPath(reference_builder.TakePath(), reference_paint);
205
206 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
207}

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::ConicCurveTo(), flutter::DlPathBuilder::CubicCurveTo(), flutter::DisplayListBuilder::DrawPath(), flutter::DlPathBuilder::kArcApproximationMagic, flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::kSqrt2Over2, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::DlPathBuilder::QuadraticCurveTo(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [67/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderFilledRoundSuperellipses   
)

Definition at line 2492 of file aiks_dl_basic_unittests.cc.

2492 {
2493 DisplayListBuilder builder;
2494 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2495 DlPaint paint;
2496 paint.setColor(DlColor::kBlue());
2497
2498 // Square
2499 builder.DrawRoundSuperellipse(
2500 DlRoundSuperellipse::MakeRectRadius(
2501 /*rect=*/DlRect::MakeXYWH(50, 50, 100, 100), /*radius=*/20),
2502 paint);
2503 // Tall
2504 builder.DrawRoundSuperellipse(
2505 DlRoundSuperellipse::MakeRectRadius(
2506 /*rect=*/DlRect::MakeXYWH(200, 50, 60, 140), /*radius=*/20),
2507 paint);
2508 // Wide
2509 builder.DrawRoundSuperellipse(
2510 DlRoundSuperellipse::MakeRectRadius(
2511 /*rect=*/DlRect::MakeXYWH(310, 50, 140, 60), /*radius=*/20),
2512 paint);
2513
2514 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2515}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawRoundSuperellipse(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), impeller::RoundSuperellipse::MakeRectRadius(), impeller::TRect< Scalar >::MakeXYWH(), and flutter::DlPaint::setColor().

◆ TEST_P() [68/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderForegroundAdvancedBlendWithMaskBlur   
)

Definition at line 184 of file aiks_dl_blur_unittests.cc.

184 {
185 // This case triggers the ForegroundAdvancedBlend path. The color filter
186 // should apply to the color only, and respect the alpha mask.
187 DisplayListBuilder builder;
188 builder.ClipRect(DlRect::MakeXYWH(100, 150, 400, 400));
189
190 DlPaint paint;
191 paint.setColor(
192 DlColor::RGBA(128.0f / 255.0f, 128.0f / 255.0f, 128.0f / 255.0f, 1.0f));
193
194 Sigma sigma = Radius(20);
195 paint.setMaskFilter(
196 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, sigma.sigma));
197 paint.setColorFilter(
198 DlColorFilter::MakeBlend(DlColor::kGreen(), DlBlendMode::kColor));
199 builder.DrawCircle(DlPoint(400, 400), 200, paint);
200 builder.Restore();
201
202 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
203}
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
Definition sigma.h:48
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition sigma.h:32
Scalar sigma
Definition sigma.h:33

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kGreen(), flutter::DlBlurMaskFilter::Make(), flutter::DlColorFilter::MakeBlend(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DlColor::RGBA(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), flutter::DlPaint::setMaskFilter(), and impeller::Sigma::sigma.

◆ TEST_P() [69/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderForegroundBlendWithMaskBlur   
)

Definition at line 165 of file aiks_dl_blur_unittests.cc.

165 {
166 // This case triggers the ForegroundPorterDuffBlend path. The color filter
167 // should apply to the color only, and respect the alpha mask.
168 DisplayListBuilder builder;
169 builder.ClipRect(DlRect::MakeXYWH(100, 150, 400, 400));
170
171 DlPaint paint;
172 paint.setColor(DlColor::kWhite());
173
174 Sigma sigma = Radius(20);
175 paint.setMaskFilter(
176 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, sigma.sigma));
177 paint.setColorFilter(
178 DlColorFilter::MakeBlend(DlColor::kGreen(), DlBlendMode::kSrc));
179 builder.DrawCircle(DlPoint(400, 400), 200, paint);
180
181 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
182}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), flutter::DlBlurMaskFilter::Make(), flutter::DlColorFilter::MakeBlend(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), flutter::DlPaint::setMaskFilter(), and impeller::Sigma::sigma.

◆ TEST_P() [70/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderGradientDecalWithBackground   
)

Definition at line 723 of file aiks_dl_gradient_unittests.cc.

723 {
724 std::vector<DlColor> colors = {
725 DlColor(Color::MakeRGBA8(0xF4, 0x43, 0x36, 0xFF).ToARGB()),
726 DlColor(Color::MakeRGBA8(0xFF, 0xEB, 0x3B, 0xFF).ToARGB()),
727 DlColor(Color::MakeRGBA8(0x4c, 0xAF, 0x50, 0xFF).ToARGB()),
728 DlColor(Color::MakeRGBA8(0x21, 0x96, 0xF3, 0xFF).ToARGB())};
729 std::vector<Scalar> stops = {0.0, 1.f / 3.f, 2.f / 3.f, 1.0};
730
731 std::array<std::shared_ptr<DlColorSource>, 3> color_sources = {
732 DlColorSource::MakeLinear({0, 0}, {100, 100}, stops.size(), colors.data(),
733 stops.data(), DlTileMode::kDecal),
734 DlColorSource::MakeRadial({100, 100}, 100, stops.size(), colors.data(),
735 stops.data(), DlTileMode::kDecal),
736 DlColorSource::MakeSweep({100, 100}, 45, 135, stops.size(), colors.data(),
737 stops.data(), DlTileMode::kDecal),
738 };
739
740 DisplayListBuilder builder;
741 DlPaint paint;
742 paint.setColor(DlColor::kWhite());
743 builder.DrawRect(DlRect::MakeLTRB(0, 0, 605, 205), paint);
744 for (int i = 0; i < 3; i++) {
745 builder.Save();
746 builder.Translate(i * 200.0f, 0);
747 paint.setColorSource(color_sources[i]);
748 builder.DrawRect(DlRect::MakeLTRB(0, 0, 200, 200), paint);
749 builder.Restore();
750 }
751 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
752}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), i, flutter::DlColor::kWhite(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlColorSource::MakeRadial(), impeller::Color::MakeRGBA8(), flutter::DlColorSource::MakeSweep(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [71/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderGroupOpacity   
)

Definition at line 34 of file aiks_dl_opacity_unittests.cc.

34 {
35 DisplayListBuilder builder;
36
37 DlPaint red;
38 red.setColor(DlColor::kRed());
39 DlPaint green;
40 green.setColor(DlColor::kGreen().modulateOpacity(0.5));
41 DlPaint blue;
42 blue.setColor(DlColor::kBlue());
43
44 DlPaint alpha;
45 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
46
47 builder.SaveLayer(std::nullopt, &alpha);
48 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
49 builder.DrawRect(DlRect::MakeXYWH(200, 200, 100, 100), green);
50 builder.DrawRect(DlRect::MakeXYWH(400, 400, 100, 100), blue);
51 builder.Restore();
52
53 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
54}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [72/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderGroupOpacityToSavelayer   
)

Definition at line 56 of file aiks_dl_opacity_unittests.cc.

56 {
57 DisplayListBuilder builder;
58
59 DlPaint red;
60 red.setColor(DlColor::kRed());
61
62 DlPaint alpha;
63 alpha.setColor(DlColor::kRed().modulateOpacity(0.7));
64
65 // Create a saveLayer that will forward its opacity to another
66 // saveLayer, to verify that we correctly distribute opacity.
67 DlRect bounds = DlRect::MakeLTRB(0, 0, 500, 500);
68 builder.SaveLayer(bounds, &alpha);
69 builder.SaveLayer(bounds, &alpha);
70 builder.DrawRect(DlRect::MakeXYWH(0, 0, 400, 400), red);
71 builder.DrawRect(DlRect::MakeXYWH(0, 0, 450, 450), red);
72 builder.Restore();
73 builder.Restore();
74
75 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
76}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [73/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderImage   
)

Definition at line 117 of file aiks_dl_basic_unittests.cc.

117 {
118 DisplayListBuilder builder;
119 DlPaint paint;
120 paint.setColor(DlColor::kRed());
121 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
122 builder.DrawImage(image, DlPoint(100.0, 100.0),
123 DlImageSampling::kNearestNeighbor, &paint);
124 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
125}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), image, flutter::DlColor::kRed(), impeller::DlImageImpeller::Make(), and flutter::DlPaint::setColor().

◆ TEST_P() [74/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderImageRect   
)

Definition at line 287 of file aiks_dl_basic_unittests.cc.

287 {
288 DisplayListBuilder builder;
289 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
290
291 DlISize image_half_size =
292 DlISize(image->GetSize().width * 0.5f, image->GetSize().height * 0.5f);
293
294 // Render the bottom right quarter of the source image in a stretched rect.
295 auto source_rect = DlRect::MakeSize(image_half_size);
296 source_rect =
297 source_rect.Shift(image_half_size.width, image_half_size.height);
298
299 builder.DrawImageRect(image, source_rect,
300 DlRect::MakeXYWH(100, 100, 600, 600),
301 DlImageSampling::kNearestNeighbor);
302 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
303}
void DrawImageRect(const sk_sp< DlImage > &image, const DlRect &src, const DlRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, DlSrcRectConstraint constraint=DlSrcRectConstraint::kFast) override

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageRect(), impeller::TSize< T >::height, image, impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), and impeller::TSize< T >::width.

◆ TEST_P() [75/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderInvertedImageWithColorFilter   
)

Definition at line 127 of file aiks_dl_basic_unittests.cc.

127 {
128 DisplayListBuilder builder;
129 DlPaint paint;
130 paint.setColor(DlColor::kRed());
131 paint.setColorFilter(
132 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
133 paint.setInvertColors(true);
134 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
135
136 builder.DrawImage(image, DlPoint(100.0, 100.0),
137 DlImageSampling::kNearestNeighbor, &paint);
138 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
139}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), image, flutter::DlColor::kRed(), flutter::DlColor::kYellow(), impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeBlend(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), and flutter::DlPaint::setInvertColors().

◆ TEST_P() [76/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderItalicizedText   
)

Definition at line 365 of file aiks_dl_text_unittests.cc.

365 {
366 DisplayListBuilder builder;
367
368 DlPaint paint;
369 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
370 builder.DrawPaint(paint);
371
372 ASSERT_TRUE(RenderTextInCanvasSkia(
373 GetContext(), builder, "the quick brown fox jumped over the lazy dog!.?",
374 "HomemadeApple.ttf"));
375 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
376}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), RenderTextInCanvasSkia(), and flutter::DlPaint::setColor().

◆ TEST_P() [77/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientClamp   
)

Definition at line 55 of file aiks_dl_gradient_unittests.cc.

55 {
56 CanRenderLinearGradient(this, DlTileMode::kClamp);
57}

◆ TEST_P() [78/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientDecal   
)

Definition at line 64 of file aiks_dl_gradient_unittests.cc.

64 {
65 CanRenderLinearGradient(this, DlTileMode::kDecal);
66}

◆ TEST_P() [79/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientDecalWithColorFilter   
)

Definition at line 68 of file aiks_dl_gradient_unittests.cc.

68 {
69 DisplayListBuilder builder;
70 Point scale = GetContentScale();
71 builder.Scale(scale.x, scale.y);
72 DlPaint paint;
73 builder.Translate(100.0f, 0);
74
75 std::vector<DlColor> colors = {
76 DlColor(Color{0.9568, 0.2627, 0.2118, 1.0}.ToARGB()),
77 DlColor(Color{0.1294, 0.5882, 0.9529, 0.0}.ToARGB())};
78 std::vector<Scalar> stops = {0.0, 1.0};
79
81 {0, 0}, {200, 200}, 2, colors.data(), stops.data(), DlTileMode::kDecal));
82 // Overlay the gradient with 25% green. This should appear as the entire
83 // rectangle being drawn with 25% green, including the border area outside the
84 // decal gradient.
86 DlBlendMode::kSrcOver));
88 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
89 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
90}
static std::shared_ptr< const DlColorFilter > MakeBlend(DlColor color, DlBlendMode mode)
double x() const
Definition geometry.h:22
double y() const
Definition geometry.h:23

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), flutter::DlColorFilter::MakeBlend(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), flutter::DlPaint::setColorSource(), impeller::Color::ToARGB(), flutter::DisplayListBuilder::Translate(), flutter::Point::x(), and flutter::Point::y().

◆ TEST_P() [80/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientManyColorsClamp   
)

Definition at line 381 of file aiks_dl_gradient_unittests.cc.

381 {
382 CanRenderLinearGradientManyColors(this, DlTileMode::kClamp);
383}

◆ TEST_P() [81/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientManyColorsDecal   
)

Definition at line 390 of file aiks_dl_gradient_unittests.cc.

390 {
391 CanRenderLinearGradientManyColors(this, DlTileMode::kDecal);
392}

◆ TEST_P() [82/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientManyColorsMirror   
)

Definition at line 387 of file aiks_dl_gradient_unittests.cc.

387 {
388 CanRenderLinearGradientManyColors(this, DlTileMode::kMirror);
389}

◆ TEST_P() [83/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientManyColorsRepeat   
)

Definition at line 384 of file aiks_dl_gradient_unittests.cc.

384 {
385 CanRenderLinearGradientManyColors(this, DlTileMode::kRepeat);
386}

◆ TEST_P() [84/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientManyColorsUnevenStops   
)

Definition at line 425 of file aiks_dl_gradient_unittests.cc.

425 {
426 auto callback = [&]() -> sk_sp<DisplayList> {
427 const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
428 const DlTileMode tile_modes[] = {DlTileMode::kClamp, DlTileMode::kRepeat,
429 DlTileMode::kMirror, DlTileMode::kDecal};
430
431 static int selected_tile_mode = 0;
432 static Matrix matrix;
433 if (IsPlaygroundEnabled()) {
434 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
435 ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
436 sizeof(tile_mode_names) / sizeof(char*));
437 std::string label = "##1";
438 for (int i = 0; i < 4; i++) {
439 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
440 &(matrix.vec[i]), 4, NULL, NULL, "%.2f", 0);
441 label[2]++;
442 }
443 ImGui::End();
444 }
445
446 DisplayListBuilder builder;
447 DlPaint paint;
448 builder.Translate(100.0, 100.0);
449 auto tile_mode = tile_modes[selected_tile_mode];
450
451 std::vector<DlColor> colors = {
452 DlColor(Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0}.ToARGB()),
453 DlColor(Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0}.ToARGB()),
454 DlColor(Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0}.ToARGB()),
455 DlColor(Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0}.ToARGB()),
456 DlColor(Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0}.ToARGB()),
457 DlColor(Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0}.ToARGB()),
458 DlColor(Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}.ToARGB())};
459 std::vector<Scalar> stops = {
460 0.0, 2.0 / 62.0, 4.0 / 62.0, 8.0 / 62.0, 16.0 / 62.0, 32.0 / 62.0, 1.0,
461 };
462
463 paint.setColorSource(DlColorSource::MakeLinear({0, 0}, {200, 200},
464 stops.size(), colors.data(),
465 stops.data(), tile_mode));
466
467 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
468 return builder.Build();
469 };
470 ASSERT_TRUE(OpenPlaygroundHere(callback));
471}
Vector4 vec[4]
Definition matrix.h:41

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawRect(), i, flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColorSource(), impeller::Color::ToARGB(), flutter::DisplayListBuilder::Translate(), and impeller::Matrix::vec.

◆ TEST_P() [85/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientMaskBlur   
)

Definition at line 473 of file aiks_dl_gradient_unittests.cc.

473 {
474 DisplayListBuilder builder;
475
476 std::vector<DlColor> colors = {
480 std::vector<Scalar> stops = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5,
481 0.6, 0.7, 0.8, 0.9, 1.0};
482
483 DlPaint paint;
484 paint.setColor(DlColor::kWhite());
486 {200, 200}, {400, 400}, stops.size(), colors.data(), stops.data(),
487 DlTileMode::kClamp));
488 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 20));
489
490 builder.DrawCircle(DlPoint(300, 300), 200, paint);
491 builder.DrawRect(DlRect::MakeLTRB(100, 300, 500, 600), paint);
492
493 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
494}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlBlurMaskFilter::Make(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), and flutter::DlPaint::setMaskFilter().

◆ TEST_P() [86/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientMirror   
)

Definition at line 61 of file aiks_dl_gradient_unittests.cc.

61 {
62 CanRenderLinearGradient(this, DlTileMode::kMirror);
63}

◆ TEST_P() [87/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientRepeat   
)

Definition at line 58 of file aiks_dl_gradient_unittests.cc.

58 {
59 CanRenderLinearGradient(this, DlTileMode::kRepeat);
60}

◆ TEST_P() [88/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientWayManyColorsClamp   
)

Definition at line 421 of file aiks_dl_gradient_unittests.cc.

421 {
422 CanRenderLinearGradientWayManyColors(this, DlTileMode::kClamp);
423}

◆ TEST_P() [89/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientWithDitheringEnabled   
)

Definition at line 128 of file aiks_dl_gradient_unittests.cc.

128 {
130}
static void CanRenderLinearGradientWithDithering(AiksTest *aiks_test)

References CanRenderLinearGradientWithDithering().

◆ TEST_P() [90/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientWithImageFilter   
)

Definition at line 92 of file aiks_dl_gradient_unittests.cc.

92 {
93 DisplayListBuilder builder;
94 Point scale = GetContentScale();
95 builder.Scale(scale.x, scale.y);
96 DlPaint paint;
97 builder.Translate(100.0f, 0);
98
99 std::vector<DlColor> colors = {
100 DlColor(Color{0.9568, 0.2627, 0.2118, 1.0}.ToARGB()),
101 DlColor(Color{0.1294, 0.5882, 0.9529, 0.0}.ToARGB())};
102 std::vector<Scalar> stops = {0.0, 1.0};
103
105 {0, 0}, {200, 200}, 2, colors.data(), stops.data(), DlTileMode::kClamp));
106 paint.setImageFilter(DlImageFilter::MakeBlur(20.0, 20.0, DlTileMode::kDecal));
107 paint.setColor(DlColor::kWhite());
108 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
109 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
110}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kWhite(), flutter::DlImageFilter::MakeBlur(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setImageFilter(), impeller::Color::ToARGB(), flutter::DisplayListBuilder::Translate(), flutter::Point::x(), and flutter::Point::y().

◆ TEST_P() [91/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientWithIncompleteStops   
)

Definition at line 328 of file aiks_dl_gradient_unittests.cc.

328 {
329 CanRenderGradientWithIncompleteStops(this,
330 DlColorSourceType::kLinearGradient);
331}

◆ TEST_P() [92/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinearGradientWithOverlappingStopsClamp   
)

Definition at line 223 of file aiks_dl_gradient_unittests.cc.

223 {
224 CanRenderLinearGradientWithOverlappingStops(this, DlTileMode::kClamp);
225}

◆ TEST_P() [93/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderLinesWithCapsAnglesAndAlphas   
)

Definition at line 2777 of file aiks_dl_basic_unittests.cc.

2777 {
2778 DisplayListBuilder builder;
2779 builder.Scale(GetContentScale().x, GetContentScale().y);
2780 builder.DrawColor(DlColor::kBlack(), DlBlendMode::kSrc);
2781
2782 const float line_length = 30.0f;
2783 const float stroke_width = 10.0f;
2784 const float spacing = 50.0f;
2785
2786 const std::vector<flutter::DlStrokeCap> caps = {
2790 };
2791 const std::vector<float> alphas = {1.0f, 0.75f, 0.5f, 0.25f};
2792 const std::vector<Radians> angles = {
2793 Degrees(0.0f), Degrees(3.0f), Degrees(30.0f), Degrees(45.0f),
2794 Degrees(60.0f), Degrees(87.0f), Degrees(90.0f),
2795 };
2796
2797 DlPaint paint;
2798 paint.setDrawStyle(DlDrawStyle::kStroke);
2799 paint.setStrokeWidth(stroke_width);
2800
2801 for (const DlStrokeCap cap : caps) {
2802 builder.Translate(spacing, 0.0f);
2803 paint.setStrokeCap(cap);
2804
2805 for (const float alpha : alphas) {
2806 builder.Translate(spacing, 0.0f);
2807 paint.setColor(DlColor::kWhite().withAlphaF(alpha));
2808
2809 builder.Save();
2810 for (const Radians angle : angles) {
2811 builder.Translate(0.0f, spacing);
2812 builder.DrawLine(DlPoint(0.0f, 0.0f),
2813 DlPoint(cos(angle.radians) * line_length,
2814 sin(angle.radians) * line_length),
2815 paint);
2816 }
2817 builder.Restore();
2818 }
2819 }
2820
2821 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2822}
@ kRound
adds circle
@ kButt
no stroke extension
@ kSquare
adds square

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawLine(), flutter::DlColor::kBlack(), flutter::kButt, flutter::kRound, flutter::kSquare, flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), flutter::DisplayListBuilder::Translate(), flutter::DlColor::withAlphaF(), x, and y.

◆ TEST_P() [94/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderMaskBlurHugeSigma   
)

Definition at line 153 of file aiks_dl_blur_unittests.cc.

153 {
154 DisplayListBuilder builder;
155
156 DlPaint paint;
157 paint.setColor(DlColor::kGreen());
158 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 99999));
159 builder.DrawCircle(DlPoint(400, 400), 300, paint);
160 builder.Restore();
161
162 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
163}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kGreen(), flutter::DlBlurMaskFilter::Make(), flutter::DisplayListBuilder::Restore(), flutter::DlPaint::setColor(), and flutter::DlPaint::setMaskFilter().

◆ TEST_P() [95/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderMultipleBackdropBlurWithSingleBackdropId   
)

Definition at line 296 of file aiks_dl_blur_unittests.cc.

296 {
297 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
298
299 DisplayListBuilder builder;
300
301 DlPaint paint;
302 builder.DrawImage(image, DlPoint(50.0, 50.0),
303 DlImageSampling::kNearestNeighbor, &paint);
304
305 for (int i = 0; i < 6; i++) {
306 DlRoundRect rrect = DlRoundRect::MakeRectXY(
307 DlRect::MakeXYWH(50 + (i * 100), 250, 100, 100), 20, 20);
308 builder.Save();
309 builder.ClipRoundRect(rrect);
310
311 DlPaint save_paint;
312 save_paint.setBlendMode(DlBlendMode::kSrc);
313 auto backdrop_filter = DlImageFilter::MakeBlur(30, 30, DlTileMode::kClamp);
314 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get(),
315 /*backdrop_id=*/1);
316 builder.Restore();
317 builder.Restore();
318 }
319
320 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
321}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRoundRect(), flutter::DisplayListBuilder::DrawImage(), i, image, impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setBlendMode().

◆ TEST_P() [96/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderMultipleBackdropBlurWithSingleBackdropIdAndDistinctFilters   
)

Definition at line 323 of file aiks_dl_blur_unittests.cc.

324 {
325 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
326
327 DisplayListBuilder builder;
328
329 DlPaint paint;
330 builder.DrawImage(image, DlPoint(50.0, 50.0),
331 DlImageSampling::kNearestNeighbor, &paint);
332
333 for (int i = 0; i < 6; i++) {
334 DlRoundRect rrect = DlRoundRect::MakeRectXY(
335 DlRect::MakeXYWH(50 + (i * 100), 250, 100, 100), 20, 20);
336 builder.Save();
337 builder.ClipRoundRect(rrect);
338
339 DlPaint save_paint;
340 save_paint.setBlendMode(DlBlendMode::kSrc);
341 auto backdrop_filter =
342 DlImageFilter::MakeBlur(30 + i, 30, DlTileMode::kClamp);
343 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get(),
344 /*backdrop_id=*/1);
345 builder.Restore();
346 builder.Restore();
347 }
348
349 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
350}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRoundRect(), flutter::DisplayListBuilder::DrawImage(), i, image, impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setBlendMode().

◆ TEST_P() [97/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderMultipleBackdropBlurWithSingleBackdropIdDifferentLayers   
)

Definition at line 1404 of file aiks_dl_blur_unittests.cc.

1405 {
1406 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
1407
1408 DisplayListBuilder builder;
1409
1410 DlPaint paint;
1411 builder.DrawImage(image, DlPoint(50.0, 50.0),
1412 DlImageSampling::kNearestNeighbor, &paint);
1413
1414 for (int i = 0; i < 6; i++) {
1415 if (i != 0) {
1416 DlPaint paint;
1417 paint.setColor(DlColor::kWhite().withAlphaF(0.95));
1418 builder.SaveLayer(std::nullopt, &paint);
1419 }
1420 DlRoundRect rrect = DlRoundRect::MakeRectXY(
1421 DlRect::MakeXYWH(50 + (i * 100), 250, 100, 100), 20, 20);
1422 builder.Save();
1423 builder.ClipRoundRect(rrect);
1424
1425 DlPaint save_paint;
1426 save_paint.setBlendMode(DlBlendMode::kSrc);
1427 auto backdrop_filter = DlImageFilter::MakeBlur(30, 30, DlTileMode::kClamp);
1428 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get(),
1429 /*backdrop_id=*/1);
1430 builder.Restore();
1431 builder.Restore();
1432 if (i != 0) {
1433 builder.Restore();
1434 }
1435 }
1436
1437 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1438}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRoundRect(), flutter::DisplayListBuilder::DrawImage(), i, image, flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [98/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderNestedBackdropBlur   
)

Definition at line 1468 of file aiks_dl_blur_unittests.cc.

1468 {
1469 int64_t count = 0;
1470 auto callback = [&]() -> sk_sp<DisplayList> {
1471 DisplayListBuilder builder;
1472
1473 Scalar freq = 1.0;
1474 Scalar amp = 50.0;
1475 Scalar offset = amp * sin(freq * 2.0 * M_PI * count / 60.0);
1476
1477 // Draw some background content to be blurred.
1478 DlPaint paint;
1479 paint.setColor(DlColor::kCornflowerBlue());
1480 builder.DrawCircle(DlPoint(100 + offset, 100), 50, paint);
1481 paint.setColor(DlColor::kGreenYellow());
1482 builder.DrawCircle(DlPoint(300, 200 + offset), 100, paint);
1483 paint.setColor(DlColor::kDarkMagenta());
1484 builder.DrawCircle(DlPoint(140, 170), 75, paint);
1485 paint.setColor(DlColor::kOrangeRed());
1486 builder.DrawCircle(DlPoint(180 + offset, 120 + offset), 100, paint);
1487
1488 // This is the first backdrop blur, simulating the navigation transition.
1489 auto backdrop_filter1 = DlImageFilter::MakeBlur(15, 15, DlTileMode::kClamp);
1490 builder.SaveLayer(std::nullopt, nullptr, backdrop_filter1.get());
1491
1492 // Draw the semi-transparent container from the second screen.
1493 DlPaint transparent_paint;
1494 transparent_paint.setColor(DlColor::kWhite().withAlpha(0.1 * 255));
1495 builder.DrawPaint(transparent_paint);
1496
1497 {
1498 // This is the second, nested backdrop blur.
1499 auto backdrop_filter2 =
1500 DlImageFilter::MakeBlur(10, 10, DlTileMode::kClamp);
1501 builder.Save();
1502 builder.ClipRect(DlRect::MakeXYWH(150, 150, 300, 300));
1503 builder.SaveLayer(std::nullopt, nullptr, backdrop_filter2.get());
1504 builder.Restore(); // Restore from SaveLayer
1505 builder.Restore(); // Restore from ClipRect
1506 }
1507
1508 builder.Restore(); // Restore from the first SaveLayer
1509
1510 count++;
1511 return builder.Build();
1512 };
1513 ASSERT_TRUE(OpenPlaygroundHere(callback));
1514}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kCornflowerBlue(), flutter::DlColor::kDarkMagenta(), flutter::DlColor::kGreenYellow(), flutter::DlColor::kOrangeRed(), flutter::DlColor::kWhite(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [99/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderNestedClips   
)

Definition at line 20 of file aiks_dl_clip_unittests.cc.

20 {
21 DisplayListBuilder builder;
22 DlPaint paint;
23 paint.setColor(DlColor::kFuchsia());
24
25 builder.Save();
26 builder.ClipPath(DlPath::MakeCircle(DlPoint(200, 400), 300));
27 builder.Restore();
28 builder.ClipPath(DlPath::MakeCircle(DlPoint(600, 400), 300));
29 builder.ClipPath(DlPath::MakeCircle(DlPoint(400, 600), 300));
30 builder.DrawRect(DlRect::MakeXYWH(200, 200, 400, 400), paint);
31
32 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
33}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kFuchsia(), flutter::DlPath::MakeCircle(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), and flutter::DlPaint::setColor().

◆ TEST_P() [100/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderOverlappingMultiContourPath   
)

Definition at line 802 of file aiks_dl_path_unittests.cc.

802 {
803 DisplayListBuilder builder;
804
805 DlPaint paint;
806 paint.setColor(DlColor::kRed());
807
808 RoundingRadii radii = {
809 .top_left = DlSize(50, 50),
810 .top_right = DlSize(50, 50),
811 .bottom_left = DlSize(50, 50),
812 .bottom_right = DlSize(50, 50),
813 };
814
815 const Scalar kTriangleHeight = 100;
816 DlRoundRect rrect = DlRoundRect::MakeRectRadii(
817 DlRect::MakeCircleBounds({0, 0}, kTriangleHeight * 0.5f), radii);
818 // We use the factory method to convert the rrect to a path so that it
819 // uses the legacy conics for legacy golden output.
820 DlPath rrect_path = DlPath::MakeRoundRect(rrect);
821
822 builder.Translate(200, 200);
823 // Form a path similar to the Material drop slider value indicator. Both
824 // shapes should render identically side-by-side.
825 {
826 DlPathBuilder path_builder;
827 path_builder.MoveTo(DlPoint(0, kTriangleHeight));
828 path_builder.LineTo(DlPoint(-kTriangleHeight / 2.0f, 0));
829 path_builder.LineTo(DlPoint(kTriangleHeight / 2.0f, 0));
830 path_builder.Close();
831 path_builder.AddPath(rrect_path);
832
833 builder.DrawPath(path_builder.TakePath(), paint);
834 }
835 builder.Translate(100, 0);
836
837 {
838 DlPathBuilder path_builder;
839 path_builder.MoveTo(DlPoint(0, kTriangleHeight));
840 path_builder.LineTo(DlPoint(-kTriangleHeight / 2.0f, 0));
841 path_builder.LineTo(DlPoint(0, -10));
842 path_builder.LineTo(DlPoint(kTriangleHeight / 2.0f, 0));
843 path_builder.Close();
844 path_builder.AddPath(rrect_path);
845
846 builder.DrawPath(path_builder.TakePath(), paint);
847 }
848
849 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
850}

References flutter::DlPathBuilder::AddPath(), flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), impeller::TRect< Scalar >::MakeCircleBounds(), impeller::RoundRect::MakeRectRadii(), flutter::DlPath::MakeRoundRect(), flutter::DlPathBuilder::MoveTo(), flutter::DlPaint::setColor(), flutter::DlPathBuilder::TakePath(), impeller::RoundingRadii::top_left, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [101/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderQuadraticStrokeWithInstantTurn   
)

Definition at line 139 of file aiks_dl_path_unittests.cc.

139 {
140 DisplayListBuilder builder;
141
142 DlPaint paint;
143 paint.setColor(DlColor::kRed());
144 paint.setStrokeWidth(50);
145 paint.setDrawStyle(DlDrawStyle::kStroke);
146 paint.setStrokeCap(DlStrokeCap::kRound);
147
148 // Should draw a diagonal pill shape. If flat on either end, the stroke is
149 // rendering wrong.
150 DlPathBuilder path_builder;
151 path_builder.MoveTo(DlPoint(250, 250));
152 path_builder.QuadraticCurveTo(DlPoint(100, 100), DlPoint(250, 250));
153
154 builder.DrawPath(path_builder.TakePath(), paint);
155
156 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
157}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPathBuilder::MoveTo(), flutter::DlPathBuilder::QuadraticCurveTo(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), and flutter::DlPathBuilder::TakePath().

◆ TEST_P() [102/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderRadialGradient   
)

Definition at line 496 of file aiks_dl_gradient_unittests.cc.

496 {
497 auto callback = [&]() -> sk_sp<DisplayList> {
498 const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
499 const DlTileMode tile_modes[] = {DlTileMode::kClamp, DlTileMode::kRepeat,
500 DlTileMode::kMirror, DlTileMode::kDecal};
501
502 static int selected_tile_mode = 0;
503 static Matrix matrix;
504 if (IsPlaygroundEnabled()) {
505 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
506 ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
507 sizeof(tile_mode_names) / sizeof(char*));
508 std::string label = "##1";
509 for (int i = 0; i < 4; i++) {
510 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
511 &(matrix.vec[i]), 4, NULL, NULL, "%.2f", 0);
512 label[2]++;
513 }
514 ImGui::End();
515 }
516
517 DisplayListBuilder builder;
518 DlPaint paint;
519 builder.Translate(100.0, 100.0);
520 auto tile_mode = tile_modes[selected_tile_mode];
521
522 std::vector<DlColor> colors = {
523 DlColor(Color{0.9568, 0.2627, 0.2118, 1.0}.ToARGB()),
524 DlColor(Color{0.1294, 0.5882, 0.9529, 1.0}.ToARGB())};
525 std::vector<Scalar> stops = {0.0, 1.0};
526
528 {100, 100}, 100, 2, colors.data(), stops.data(), tile_mode));
529
530 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
531 return builder.Build();
532 };
533 ASSERT_TRUE(OpenPlaygroundHere(callback));
534}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawRect(), i, flutter::DlColorSource::MakeRadial(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColorSource(), impeller::Color::ToARGB(), flutter::DisplayListBuilder::Translate(), and impeller::Matrix::vec.

◆ TEST_P() [103/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderRadialGradientManyColors   
)

Definition at line 536 of file aiks_dl_gradient_unittests.cc.

536 {
537 auto callback = [&]() -> sk_sp<DisplayList> {
538 const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
539 const DlTileMode tile_modes[] = {DlTileMode::kClamp, DlTileMode::kRepeat,
540 DlTileMode::kMirror, DlTileMode::kDecal};
541
542 static int selected_tile_mode = 0;
543 static Matrix matrix = {
544 1, 0, 0, 0, //
545 0, 1, 0, 0, //
546 0, 0, 1, 0, //
547 0, 0, 0, 1 //
548 };
549 if (IsPlaygroundEnabled()) {
550 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
551 ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
552 sizeof(tile_mode_names) / sizeof(char*));
553 std::string label = "##1";
554 for (int i = 0; i < 4; i++) {
555 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
556 &(matrix.vec[i]), 4, NULL, NULL, "%.2f", 0);
557 label[2]++;
558 }
559 ImGui::End();
560 }
561
562 DisplayListBuilder builder;
563 DlPaint paint;
564 builder.Translate(100.0, 100.0);
565 auto tile_mode = tile_modes[selected_tile_mode];
566
567 std::vector<DlColor> colors = {
568 DlColor(Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0}.ToARGB()),
569 DlColor(Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0}.ToARGB()),
570 DlColor(Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0}.ToARGB()),
571 DlColor(Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0}.ToARGB()),
572 DlColor(Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0}.ToARGB()),
573 DlColor(Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0}.ToARGB()),
574 DlColor(Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}.ToARGB())};
575 std::vector<Scalar> stops = {
576 0.0,
577 (1.0 / 6.0) * 1,
578 (1.0 / 6.0) * 2,
579 (1.0 / 6.0) * 3,
580 (1.0 / 6.0) * 4,
581 (1.0 / 6.0) * 5,
582 1.0,
583 };
584
586 {100, 100}, 100, stops.size(), colors.data(), stops.data(), tile_mode));
587
588 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
589 return builder.Build();
590 };
591 ASSERT_TRUE(OpenPlaygroundHere(callback));
592}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawRect(), i, flutter::DlColorSource::MakeRadial(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColorSource(), impeller::Color::ToARGB(), flutter::DisplayListBuilder::Translate(), and impeller::Matrix::vec.

◆ TEST_P() [104/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderRadialGradientWithDitheringEnabled   
)

Definition at line 148 of file aiks_dl_gradient_unittests.cc.

148 {
150}
static void CanRenderRadialGradientWithDithering(AiksTest *aiks_test)

References CanRenderRadialGradientWithDithering().

◆ TEST_P() [105/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderRadialGradientWithIncompleteStops   
)

Definition at line 332 of file aiks_dl_gradient_unittests.cc.

332 {
333 CanRenderGradientWithIncompleteStops(this,
334 DlColorSourceType::kRadialGradient);
335}

◆ TEST_P() [106/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderRoundedRectWithNonUniformRadii   
)

Definition at line 461 of file aiks_dl_basic_unittests.cc.

461 {
462 DisplayListBuilder builder;
463 DlPaint paint;
464 paint.setColor(DlColor::kRed());
465
466 RoundingRadii radii = {
467 .top_left = DlSize(50, 25),
468 .top_right = DlSize(25, 50),
469 .bottom_left = DlSize(25, 50),
470 .bottom_right = DlSize(50, 25),
471 };
472 DlRoundRect rrect =
473 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 500, 500), radii);
474
475 builder.DrawRoundRect(rrect, paint);
476
477 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
478}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kRed(), impeller::RoundRect::MakeRectRadii(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), and impeller::RoundingRadii::top_left.

◆ TEST_P() [107/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderRoundedRectWithUniformRadii   
)

Definition at line 480 of file aiks_dl_basic_unittests.cc.

480 {
481 Scalar top_left = 20.f;
482 Scalar top_right = 40.f;
483 Scalar bottom_left = 60.f;
484 Scalar bottom_right = 80.f;
485 auto callback = [&]() -> sk_sp<DisplayList> {
486 if (IsPlaygroundEnabled()) {
487 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
488 ImGui::SliderFloat("top_left", &top_left, 0, 250);
489 ImGui::SliderFloat("top_right", &top_right, 0, 250);
490 ImGui::SliderFloat("bottom_left", &bottom_left, 0, 250);
491 ImGui::SliderFloat("bottom_right", &bottom_right, 0, 250);
492 ImGui::End();
493 }
494
495 DisplayListBuilder builder;
496 DlPaint paint;
497 paint.setColor(DlColor::kRed());
498
499 RoundingRadii radii = {
500 .top_left = DlSize(top_left, top_left),
501 .top_right = DlSize(top_right, top_right),
502 .bottom_left = DlSize(bottom_left, bottom_left),
503 .bottom_right = DlSize(bottom_right, bottom_right),
504 };
505 DlRoundRect rrect =
506 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 500, 500), radii);
507
508 builder.DrawRoundRect(rrect, paint);
509 return builder.Build();
510 };
511
512 ASSERT_TRUE(OpenPlaygroundHere(callback));
513}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kRed(), impeller::RoundRect::MakeRectRadii(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), and impeller::RoundingRadii::top_left.

◆ TEST_P() [108/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderRoundSuperellipseGrid   
)

Definition at line 2649 of file aiks_dl_basic_unittests.cc.

2649 {
2650 DisplayListBuilder builder;
2651 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2652 DlPaint paint;
2653 paint.setColor(DlColor::kBlue());
2654
2655 DlScalar radii[] = {10.0f, 30.0f, 50.0f};
2656
2657 for (int row = 0; row < 3; row++) {
2658 DlScalar y = 50.0f + row * 170.0f;
2659 DlScalar radius = radii[row];
2660
2661 // Square
2662 builder.DrawRoundSuperellipse(
2663 DlRoundSuperellipse::MakeRectRadius(
2664 /*rect=*/DlRect::MakeXYWH(50, y, 100, 100), /*radius=*/radius),
2665 paint);
2666 // Tall
2667 builder.DrawRoundSuperellipse(
2668 DlRoundSuperellipse::MakeRectRadius(
2669 /*rect=*/DlRect::MakeXYWH(200, y, 60, 140), /*radius=*/radius),
2670 paint);
2671 // Wide
2672 builder.DrawRoundSuperellipse(
2673 DlRoundSuperellipse::MakeRectRadius(
2674 /*rect=*/DlRect::MakeXYWH(310, y, 140, 60), /*radius=*/radius),
2675 paint);
2676 }
2677
2678 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2679}
impeller::Scalar DlScalar

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawRoundSuperellipse(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), impeller::RoundSuperellipse::MakeRectRadius(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), and y.

◆ TEST_P() [109/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderRuntimeEffectFilter   
)

Definition at line 108 of file aiks_dl_runtime_effect_unittests.cc.

108 {
109 auto runtime_stages_result =
110 OpenAssetAsRuntimeStage("runtime_stage_filter_example.frag.iplr");
111 ABSL_ASSERT_OK(runtime_stages_result);
112 std::shared_ptr<RuntimeStage> runtime_stage =
113 runtime_stages_result.value()[GetRuntimeStageBackend()];
114 ASSERT_TRUE(runtime_stage);
115 ASSERT_TRUE(runtime_stage->IsDirty());
116
117 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
118 nullptr,
119 };
120 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
121 uniform_data->resize(sizeof(Vector2));
122
123 DlPaint paint;
124 paint.setColor(DlColor::kAqua());
125 paint.setImageFilter(DlImageFilter::MakeRuntimeEffect(
126 DlRuntimeEffectImpeller::Make(runtime_stage), sampler_inputs,
127 uniform_data));
128
129 DisplayListBuilder builder;
130 builder.DrawRect(DlRect::MakeXYWH(0, 0, 400, 400), paint);
131
132 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
133}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kAqua(), flutter::DlRuntimeEffectImpeller::Make(), flutter::DlImageFilter::MakeRuntimeEffect(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), and flutter::DlPaint::setImageFilter().

◆ TEST_P() [110/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSimpleClips   
)

Definition at line 325 of file aiks_dl_basic_unittests.cc.

325 {
326 DisplayListBuilder builder;
327 builder.Scale(GetContentScale().x, GetContentScale().y);
328 DlPaint paint;
329
330 paint.setColor(DlColor::kWhite());
331 builder.DrawPaint(paint);
332
333 auto draw = [&builder](const DlPaint& paint, Scalar x, Scalar y) {
334 builder.Save();
335 builder.Translate(x, y);
336 {
337 builder.Save();
338 builder.ClipRect(DlRect::MakeLTRB(50, 50, 150, 150));
339 builder.DrawPaint(paint);
340 builder.Restore();
341 }
342 {
343 builder.Save();
344 builder.ClipOval(DlRect::MakeLTRB(200, 50, 300, 150));
345 builder.DrawPaint(paint);
346 builder.Restore();
347 }
348 {
349 builder.Save();
350 builder.ClipRoundRect(
351 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(50, 200, 150, 300), 20, 20));
352 builder.DrawPaint(paint);
353 builder.Restore();
354 }
355 {
356 builder.Save();
357 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
358 DlRect::MakeLTRB(200, 230, 300, 270), 20, 20));
359 builder.DrawPaint(paint);
360 builder.Restore();
361 }
362 {
363 builder.Save();
364 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
365 DlRect::MakeLTRB(230, 200, 270, 300), 20, 20));
366 builder.DrawPaint(paint);
367 builder.Restore();
368 }
369 builder.Restore();
370 };
371
372 paint.setColor(DlColor::kBlue());
373 draw(paint, 0, 0);
374
375 DlColor gradient_colors[7] = {
376 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
377 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
378 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
379 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
380 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
381 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
382 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
383 };
384 Scalar stops[7] = {
385 0.0,
386 (1.0 / 6.0) * 1,
387 (1.0 / 6.0) * 2,
388 (1.0 / 6.0) * 3,
389 (1.0 / 6.0) * 4,
390 (1.0 / 6.0) * 5,
391 1.0,
392 };
393 auto texture = CreateTextureForFixture("airplane.jpg",
394 /*enable_mipmapping=*/true);
395 auto image = DlImageImpeller::Make(texture);
396
397 paint.setColorSource(DlColorSource::MakeRadial(
398 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
399 draw(paint, 0, 300);
400
401 paint.setColorSource(
402 DlColorSource::MakeImage(image, DlTileMode::kRepeat, DlTileMode::kRepeat,
403 DlImageSampling::kNearestNeighbor));
404 draw(paint, 300, 0);
405
406 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
407}
flutter::DlColor DlColor

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipOval(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::ClipRoundRect(), flutter::DisplayListBuilder::DrawPaint(), image, flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlColorSource::MakeRadial(), impeller::RoundRect::MakeRectXY(), flutter::DisplayListBuilder::Restore(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), texture, flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [111/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSkewedCircleHairline   
)

Definition at line 209 of file aiks_dl_primitive_shape_unittests.cc.

209 {
210 DisplayListBuilder builder;
211 builder.Scale(GetContentScale().x, GetContentScale().y);
212 builder.DrawColor(DlColor::kBlack(), DlBlendMode::kSrc);
213
214 RenderParameters params{
215 .render_type = RenderType::kCircle,
216 .center = GetWindowBounds().GetCenter(),
217 .skew_x = 0.75f,
218 .skew_y = 0.75f,
219 };
220 RenderPrimitiveWithStroke(builder, params);
221
222 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
223}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlack(), params, flutter::DisplayListBuilder::Scale(), x, and y.

◆ TEST_P() [112/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSmallRadiusRoundSuperellipses   
)

Definition at line 2597 of file aiks_dl_basic_unittests.cc.

2597 {
2598 DisplayListBuilder builder;
2599 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2600 DlPaint paint;
2601 paint.setColor(DlColor::kBlue());
2602
2603 // Square
2604 builder.DrawRoundSuperellipse(
2605 DlRoundSuperellipse::MakeRectRadius(
2606 /*rect=*/DlRect::MakeXYWH(50, 50, 100, 100), /*radius=*/2),
2607 paint);
2608 // Tall
2609 builder.DrawRoundSuperellipse(
2610 DlRoundSuperellipse::MakeRectRadius(
2611 /*rect=*/DlRect::MakeXYWH(200, 50, 60, 140), /*radius=*/2),
2612 paint);
2613 // Wide
2614 builder.DrawRoundSuperellipse(
2615 DlRoundSuperellipse::MakeRectRadius(
2616 /*rect=*/DlRect::MakeXYWH(310, 50, 140, 60), /*radius=*/2),
2617 paint);
2618
2619 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2620}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawRoundSuperellipse(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), impeller::RoundSuperellipse::MakeRectRadius(), impeller::TRect< Scalar >::MakeXYWH(), and flutter::DlPaint::setColor().

◆ TEST_P() [113/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderStrokedConicPaths   
)

Definition at line 209 of file aiks_dl_path_unittests.cc.

209 {
210 DisplayListBuilder builder;
211 builder.Scale(GetContentScale().x, GetContentScale().y);
212
213 DlPaint paint;
214 paint.setColor(DlColor::kRed());
215 paint.setStrokeWidth(10);
216 paint.setDrawStyle(DlDrawStyle::kStroke);
217 paint.setStrokeCap(DlStrokeCap::kRound);
218 paint.setStrokeJoin(DlStrokeJoin::kRound);
219
220 DlPaint reference_paint;
221 reference_paint.setColor(DlColor::kGreen());
222 reference_paint.setStrokeWidth(10);
223 reference_paint.setDrawStyle(DlDrawStyle::kStroke);
224 reference_paint.setStrokeCap(DlStrokeCap::kRound);
225 reference_paint.setStrokeJoin(DlStrokeJoin::kRound);
226
227 DlPathBuilder path_builder;
228 DlPathBuilder reference_builder;
229
230 // weight of 1.0 is just a quadratic bezier
231 path_builder.MoveTo(DlPoint(100, 100));
232 path_builder.ConicCurveTo(DlPoint(150, 150), DlPoint(200, 100), 1.0f);
233 reference_builder.MoveTo(DlPoint(300, 100));
234 reference_builder.QuadraticCurveTo(DlPoint(350, 150), DlPoint(400, 100));
235
236 // weight of sqrt(2)/2 is a circular section
237 path_builder.MoveTo(DlPoint(100, 200));
238 path_builder.ConicCurveTo(DlPoint(150, 250), DlPoint(200, 200), kSqrt2Over2);
239 reference_builder.MoveTo(DlPoint(300, 200));
240 auto magic = DlPathBuilder::kArcApproximationMagic;
241 reference_builder.CubicCurveTo(DlPoint(300, 200) + DlPoint(50, 50) * magic,
242 DlPoint(400, 200) + DlPoint(-50, 50) * magic,
243 DlPoint(400, 200));
244
245 // weight of .0 is a straight line
246 path_builder.MoveTo(DlPoint(100, 300));
247 path_builder.ConicCurveTo(DlPoint(150, 350), DlPoint(200, 300), 0.0f);
248 reference_builder.MoveTo(DlPoint(300, 300));
249 reference_builder.LineTo(DlPoint(400, 300));
250
251 // weight of 100.0 is nearly a triangle
252 path_builder.MoveTo(DlPoint(100, 400));
253 path_builder.ConicCurveTo(DlPoint(150, 450), DlPoint(200, 400), 100.0f);
254 reference_builder.MoveTo(DlPoint(300, 400));
255 reference_builder.LineTo(DlPoint(350, 450));
256 reference_builder.LineTo(DlPoint(400, 400));
257
258 builder.DrawPath(path_builder.TakePath(), paint);
259 builder.DrawPath(reference_builder.TakePath(), reference_paint);
260
261 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
262}
DlPaint & setStrokeJoin(DlStrokeJoin join)
Definition dl_paint.h:109

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::ConicCurveTo(), flutter::DlPathBuilder::CubicCurveTo(), flutter::DisplayListBuilder::DrawPath(), flutter::DlPathBuilder::kArcApproximationMagic, flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::kSqrt2Over2, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::DlPathBuilder::QuadraticCurveTo(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [114/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderStrokedRoundSuperellipses   
)

Definition at line 2570 of file aiks_dl_basic_unittests.cc.

2570 {
2571 DisplayListBuilder builder;
2572 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2573 DlPaint paint;
2574 paint.setColor(DlColor::kBlue());
2575 paint.setDrawStyle(DlDrawStyle::kStroke);
2576 paint.setStrokeWidth(5.0f);
2577
2578 // Square
2579 builder.DrawRoundSuperellipse(
2580 DlRoundSuperellipse::MakeRectRadius(
2581 /*rect=*/DlRect::MakeXYWH(50, 50, 100, 100), /*radius=*/20),
2582 paint);
2583 // Tall
2584 builder.DrawRoundSuperellipse(
2585 DlRoundSuperellipse::MakeRectRadius(
2586 /*rect=*/DlRect::MakeXYWH(200, 50, 60, 140), /*radius=*/20),
2587 paint);
2588 // Wide
2589 builder.DrawRoundSuperellipse(
2590 DlRoundSuperellipse::MakeRectRadius(
2591 /*rect=*/DlRect::MakeXYWH(310, 50, 140, 60), /*radius=*/20),
2592 paint);
2593
2594 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2595}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawRoundSuperellipse(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), impeller::RoundSuperellipse::MakeRectRadius(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [115/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderStrokedTextFrame   
)

Definition at line 129 of file aiks_dl_text_unittests.cc.

129 {
130 DisplayListBuilder builder;
131
132 DlPaint paint;
133 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
134 builder.DrawPaint(paint);
135
136 ASSERT_TRUE(RenderTextInCanvasSkia(
137 GetContext(), builder, "the quick brown fox jumped over the lazy dog!.?",
138 "Roboto-Regular.ttf",
139 {
140 .stroke = true,
141 }));
142 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
143}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), RenderTextInCanvasSkia(), and flutter::DlPaint::setColor().

◆ TEST_P() [116/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderStrokePathThatEndsAtSharpTurn   
)

Definition at line 107 of file aiks_dl_path_unittests.cc.

107 {
108 DisplayListBuilder builder;
109 DlPaint paint;
110 paint.setColor(DlColor::kRed());
111 paint.setStrokeWidth(200);
112 paint.setDrawStyle(DlDrawStyle::kStroke);
113
114 DlPath path = DlPath::MakeArc(DlRect::MakeXYWH(100, 100, 200, 200), //
115 DlDegrees(0), DlDegrees(90), false);
116
117 builder.DrawPath(path, paint);
118
119 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
120}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPath::MakeArc(), impeller::TRect< Scalar >::MakeXYWH(), flutter::path, flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [117/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderStrokePathWithCubicLine   
)

Definition at line 122 of file aiks_dl_path_unittests.cc.

122 {
123 DisplayListBuilder builder;
124
125 DlPaint paint;
126 paint.setColor(DlColor::kRed());
127 paint.setStrokeWidth(20);
128 paint.setDrawStyle(DlDrawStyle::kStroke);
129
130 DlPathBuilder path_builder;
131 path_builder.MoveTo(DlPoint(0, 200));
132 path_builder.CubicCurveTo(DlPoint(50, 400), DlPoint(350, 0),
133 DlPoint(400, 200));
134
135 builder.DrawPath(path_builder.TakePath(), paint);
136 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
137}

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::CubicCurveTo(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPathBuilder::MoveTo(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), and flutter::DlPathBuilder::TakePath().

◆ TEST_P() [118/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderStrokes   
)

Definition at line 58 of file aiks_dl_path_unittests.cc.

58 {
59 DisplayListBuilder builder;
60 DlPaint paint;
61 paint.setColor(DlColor::kRed());
62 paint.setStrokeWidth(20);
63 paint.setDrawStyle(DlDrawStyle::kStroke);
64
65 builder.DrawPath(DlPath::MakeLine(DlPoint(200, 100), DlPoint(800, 100)),
66 paint);
67
68 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
69}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPath::MakeLine(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [119/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSweepGradientClamp   
)

Definition at line 615 of file aiks_dl_gradient_unittests.cc.

615 {
616 CanRenderSweepGradient(this, DlTileMode::kClamp);
617}

◆ TEST_P() [120/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSweepGradientDecal   
)

Definition at line 624 of file aiks_dl_gradient_unittests.cc.

624 {
625 CanRenderSweepGradient(this, DlTileMode::kDecal);
626}

◆ TEST_P() [121/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSweepGradientManyColorsClamp   
)

Definition at line 662 of file aiks_dl_gradient_unittests.cc.

662 {
663 CanRenderSweepGradientManyColors(this, DlTileMode::kClamp);
664}

◆ TEST_P() [122/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSweepGradientManyColorsDecal   
)

Definition at line 671 of file aiks_dl_gradient_unittests.cc.

671 {
672 CanRenderSweepGradientManyColors(this, DlTileMode::kDecal);
673}

◆ TEST_P() [123/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSweepGradientManyColorsMirror   
)

Definition at line 668 of file aiks_dl_gradient_unittests.cc.

668 {
669 CanRenderSweepGradientManyColors(this, DlTileMode::kMirror);
670}

◆ TEST_P() [124/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSweepGradientManyColorsRepeat   
)

Definition at line 665 of file aiks_dl_gradient_unittests.cc.

665 {
666 CanRenderSweepGradientManyColors(this, DlTileMode::kRepeat);
667}

◆ TEST_P() [125/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSweepGradientMirror   
)

Definition at line 621 of file aiks_dl_gradient_unittests.cc.

621 {
622 CanRenderSweepGradient(this, DlTileMode::kMirror);
623}

◆ TEST_P() [126/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSweepGradientRepeat   
)

Definition at line 618 of file aiks_dl_gradient_unittests.cc.

618 {
619 CanRenderSweepGradient(this, DlTileMode::kRepeat);
620}

◆ TEST_P() [127/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSweepGradientWithDitheringEnabled   
)

Definition at line 171 of file aiks_dl_gradient_unittests.cc.

171 {
173}
static void CanRenderSweepGradientWithDithering(AiksTest *aiks_test)

References CanRenderSweepGradientWithDithering().

◆ TEST_P() [128/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderSweepGradientWithIncompleteStops   
)

Definition at line 340 of file aiks_dl_gradient_unittests.cc.

340 {
341 CanRenderGradientWithIncompleteStops(this, DlColorSourceType::kSweepGradient);
342}

◆ TEST_P() [129/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTextFrame   
)

Definition at line 100 of file aiks_dl_text_unittests.cc.

100 {
101 DisplayListBuilder builder;
102
103 DlPaint paint;
104 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
105 builder.DrawPaint(paint);
106 ASSERT_TRUE(RenderTextInCanvasSkia(
107 GetContext(), builder, "the quick brown fox jumped over the lazy dog!.?",
108 "Roboto-Regular.ttf"));
109
110 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
111}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), RenderTextInCanvasSkia(), and flutter::DlPaint::setColor().

◆ TEST_P() [130/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTextFrameWithFractionScaling   
)

Definition at line 254 of file aiks_dl_text_unittests.cc.

254 {
255 Scalar fine_scale = 0.f;
256 bool is_subpixel = false;
257 auto callback = [&]() -> sk_sp<DisplayList> {
258 if (IsPlaygroundEnabled()) {
259 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
260 ImGui::SliderFloat("Fine Scale", &fine_scale, -1, 1);
261 ImGui::Checkbox("subpixel", &is_subpixel);
262 ImGui::End();
263 }
264
265 DisplayListBuilder builder;
266 DlPaint paint;
267 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
268 builder.DrawPaint(paint);
269 Scalar scale = 2.625 + fine_scale;
270 builder.Scale(scale, scale);
271 RenderTextInCanvasSkia(GetContext(), builder,
272 "the quick brown fox jumped over the lazy dog!.?",
273 "Roboto-Regular.ttf",
274 TextRenderOptions{.is_subpixel = is_subpixel});
275 return builder.Build();
276 };
277
278 ASSERT_TRUE(OpenPlaygroundHere(callback));
279}
bool is_subpixel

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawPaint(), impeller::testing::TextRenderOptions::is_subpixel, is_subpixel, RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), and flutter::DlPaint::setColor().

◆ TEST_P() [131/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTextFrameWithHalfScaling   
)

Definition at line 161 of file aiks_dl_text_unittests.cc.

161 {
162 DisplayListBuilder builder;
163
164 DlPaint paint;
165 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
166 builder.DrawPaint(paint);
167 builder.Scale(0.5, 0.5);
168
169 ASSERT_TRUE(RenderTextInCanvasSkia(
170 GetContext(), builder, "the quick brown fox jumped over the lazy dog!.?",
171 "Roboto-Regular.ttf"));
172 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
173}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), and flutter::DlPaint::setColor().

◆ TEST_P() [132/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTextFrameWithInvertedTransform   
)

Definition at line 113 of file aiks_dl_text_unittests.cc.

113 {
114 DisplayListBuilder builder;
115
116 DlPaint paint;
117 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
118 builder.DrawPaint(paint);
119 builder.Translate(1000, 0);
120 builder.Scale(-1, 1);
121
122 ASSERT_TRUE(RenderTextInCanvasSkia(
123 GetContext(), builder, "the quick brown fox jumped over the lazy dog!.?",
124 "Roboto-Regular.ttf"));
125
126 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
127}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [133/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTextFrameWithScalingOverflow   
)

Definition at line 225 of file aiks_dl_text_unittests.cc.

225 {
226 Scalar scale = 60.0;
227 Scalar offsetx = -500.0;
228 Scalar offsety = 700.0;
229 auto callback = [&]() -> sk_sp<DisplayList> {
230 if (IsPlaygroundEnabled()) {
231 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
232 ImGui::SliderFloat("scale", &scale, 1.f, 300.f);
233 ImGui::SliderFloat("offsetx", &offsetx, -600.f, 100.f);
234 ImGui::SliderFloat("offsety", &offsety, 600.f, 2048.f);
235 ImGui::End();
236 }
237 DisplayListBuilder builder;
238 builder.Scale(GetContentScale().x, GetContentScale().y);
239 DlPaint paint;
240 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
241 builder.DrawPaint(paint);
242 builder.Scale(scale, scale);
243
244 RenderTextInCanvasSkia(
245 GetContext(), builder, "test", "Roboto-Regular.ttf",
246 TextRenderOptions{
247 .position = DlPoint(offsetx / scale, offsety / scale),
248 });
249 return builder.Build();
250 };
251 ASSERT_TRUE(OpenPlaygroundHere(callback));
252}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawPaint(), impeller::testing::TextRenderOptions::position, RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [134/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTextFrameWithThinLightAndDarkColors   
)

Definition at line 781 of file aiks_dl_text_unittests.cc.

781 {
782 DisplayListBuilder builder;
783 DlPaint paint;
784 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
785 builder.DrawPaint(paint);
786
787 auto mapping =
788 flutter::testing::OpenFixtureAsSkData("RobotoSlab-VariableFont_wght.ttf");
789 ASSERT_TRUE(mapping);
790 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
791
792 // Set the variation axis for weight to 100 (typically "Thin").
793 SkFontArguments::VariationPosition::Coordinate weight_coord{
794 SkSetFourByteTag('w', 'g', 'h', 't'), 100.0f};
795 SkFontArguments args;
796 args.setVariationDesignPosition({&weight_coord, 1});
797
798 SkFont thin_font(font_mgr->makeFromData(mapping)->makeClone(args), 25);
799
800 // Render light text
801 ASSERT_TRUE(RenderTextInCanvasSkia(
802 GetContext(), builder, "the quick brown fox jumped over the lazy dog!.?",
803 "RobotoSlab-VariableFont_wght.ttf",
804 TextRenderOptions{.color = DlColor::kWhite(),
805 .position = DlPoint(100, 200)},
806 thin_font));
807
808 // Render dark text on a light background
809 DlPaint dart_text_background_paint;
810 dart_text_background_paint.setColor(DlColor::ARGB(1, 0.9, 0.9, 0.9));
811 builder.DrawRect(DlRect::MakeXYWH(50, 250, 900, 100),
812 dart_text_background_paint);
813 ASSERT_TRUE(RenderTextInCanvasSkia(
814 GetContext(), builder, "the quick brown fox jumped over the lazy dog!.?",
815 "RobotoSlab-VariableFont_wght.ttf",
816 TextRenderOptions{.color = DlColor::kDarkGreen(),
817 .position = DlPoint(100, 300)},
818 thin_font));
819
820 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
821}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static constexpr DlColor kDarkGreen()
Definition dl_color.h:93

References flutter::DlColor::ARGB(), args, flutter::DisplayListBuilder::Build(), impeller::testing::TextRenderOptions::color, flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), txt::GetDefaultFontManager(), flutter::DlColor::kDarkGreen(), flutter::DlColor::kWhite(), impeller::TRect< Scalar >::MakeXYWH(), flutter::testing::OpenFixtureAsSkData(), RenderTextInCanvasSkia(), and flutter::DlPaint::setColor().

◆ TEST_P() [135/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTextInSaveLayer   
)

Definition at line 426 of file aiks_dl_text_unittests.cc.

426 {
427 DisplayListBuilder builder;
428
429 DlPaint paint;
430 paint.setColor(DlColor::ARGB(0.1, 0.1, 0.1, 0.1));
431 builder.DrawPaint(paint);
432
433 builder.Translate(100, 100);
434 builder.Scale(0.5, 0.5);
435
436 // Blend the layer with the parent pass using kClear to expose the coverage.
437 paint.setBlendMode(DlBlendMode::kClear);
438 builder.SaveLayer(std::nullopt, &paint);
439 ASSERT_TRUE(RenderTextInCanvasSkia(
440 GetContext(), builder, "the quick brown fox jumped over the lazy dog!.?",
441 "Roboto-Regular.ttf"));
442 builder.Restore();
443
444 // Render the text again over the cleared coverage rect.
445 ASSERT_TRUE(RenderTextInCanvasSkia(
446 GetContext(), builder, "the quick brown fox jumped over the lazy dog!.?",
447 "Roboto-Regular.ttf"));
448
449 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
450}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [136/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTextOutsideBoundaries   
)

Definition at line 452 of file aiks_dl_text_unittests.cc.

452 {
453 DisplayListBuilder builder;
454 builder.Translate(200, 150);
455
456 // Construct the text blob.
457 auto mapping = flutter::testing::OpenFixtureAsSkData("wtf.otf");
458 ASSERT_NE(mapping, nullptr);
459
460 Scalar font_size = 80;
461 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
462 SkFont sk_font(font_mgr->makeFromData(mapping), font_size);
463
464 DlPaint text_paint;
465 text_paint.setColor(DlColor::kBlue().withAlpha(255 * 0.8));
466
467 struct {
468 DlPoint position;
469 const char* text;
470 } text[] = {{DlPoint(0, 0), "0F0F0F0"},
471 {DlPoint(1, 2), "789"},
472 {DlPoint(1, 3), "456"},
473 {DlPoint(1, 4), "123"},
474 {DlPoint(0, 6), "0F0F0F0"}};
475 for (auto& t : text) {
476 builder.Save();
477 builder.Translate(t.position.x * font_size * 2,
478 t.position.y * font_size * 1.1);
479 {
480 auto blob = SkTextBlob::MakeFromString(t.text, sk_font);
481 ASSERT_NE(blob, nullptr);
482 auto frame = MakeTextFrameFromTextBlobSkia(blob);
483 builder.DrawText(DlTextImpeller::Make(frame), 0, 0, text_paint);
484 }
485 builder.Restore();
486 }
487
488 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
489}
Scalar font_size

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawText(), font_size, txt::GetDefaultFontManager(), flutter::DlColor::kBlue(), flutter::DlTextImpeller::Make(), impeller::MakeTextFrameFromTextBlobSkia(), flutter::testing::OpenFixtureAsSkData(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColor(), text, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [137/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTextStrokeWidth   
)

Definition at line 145 of file aiks_dl_text_unittests.cc.

145 {
146 DisplayListBuilder builder;
147
148 DlPaint paint;
149 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
150 builder.DrawPaint(paint);
151
152 ASSERT_TRUE(RenderTextInCanvasSkia(GetContext(), builder, "LMNOP VWXYZ",
153 "Roboto-Medium.ttf",
154 {
155 .stroke = true,
156 .stroke_width = 4,
157 }));
158 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
159}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), RenderTextInCanvasSkia(), and flutter::DlPaint::setColor().

◆ TEST_P() [138/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTextWithLargePerspectiveTransform   
)

Definition at line 559 of file aiks_dl_text_unittests.cc.

559 {
560 // Verifies that text scales are clamped to work around
561 // https://github.com/flutter/flutter/issues/136112 .
562
563 DisplayListBuilder builder;
564
565 DlPaint save_paint;
566 builder.SaveLayer(std::nullopt, &save_paint);
567 builder.Transform(Matrix(2000, 0, 0, 0, //
568 0, 2000, 0, 0, //
569 0, 0, -1, 9000, //
570 0, 0, -1, 7000 //
571 ));
572
573 ASSERT_TRUE(RenderTextInCanvasSkia(GetContext(), builder, "Hello world",
574 "Roboto-Regular.ttf"));
575 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
576}

References flutter::DisplayListBuilder::Build(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DisplayListBuilder::Transform().

◆ TEST_P() [139/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTextWithPerspectiveTransformInSublist   
)

Definition at line 578 of file aiks_dl_text_unittests.cc.

578 {
579 DisplayListBuilder text_builder;
580 ASSERT_TRUE(RenderTextInCanvasSkia(GetContext(), text_builder, "Hello world",
581 "Roboto-Regular.ttf"));
582 auto text_display_list = text_builder.Build();
583
584 DisplayListBuilder builder;
585
586 Matrix matrix = Matrix::MakeRow(2.0, 0.0, 0.0, 0.0, //
587 0.0, 2.0, 0.0, 0.0, //
588 0.0, 0.0, 1.0, 0.0, //
589 0.0, 0.002, 0.0, 1.0);
590
591 DlPaint save_paint;
592 DlRect window_bounds =
593 DlRect::MakeXYWH(0, 0, GetWindowSize().width, GetWindowSize().height);
594 builder.SaveLayer(window_bounds, &save_paint);
595 builder.Transform(matrix);
596 builder.DrawDisplayList(text_display_list, 1.0f);
597 builder.Restore();
598
599 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
600}
void DrawDisplayList(const sk_sp< DisplayList > display_list, DlScalar opacity=SK_Scalar1) override
static constexpr Matrix MakeRow(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
Definition matrix.h:83

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawDisplayList(), height, impeller::Matrix::MakeRow(), impeller::TRect< Scalar >::MakeXYWH(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Transform(), and width.

◆ TEST_P() [140/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderThickCurvedStrokes   
)

Definition at line 83 of file aiks_dl_path_unittests.cc.

83 {
84 DisplayListBuilder builder;
85 DlPaint paint;
86 paint.setColor(DlColor::kRed());
87 paint.setStrokeWidth(100);
88 paint.setDrawStyle(DlDrawStyle::kStroke);
89
90 builder.DrawPath(DlPath::MakeCircle(DlPoint(100, 100), 50), paint);
91
92 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
93}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPath::MakeCircle(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [141/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderThickStrokedRoundSuperellipses   
)

Definition at line 2622 of file aiks_dl_basic_unittests.cc.

2622 {
2623 DisplayListBuilder builder;
2624 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2625 DlPaint paint;
2626 paint.setColor(DlColor::kBlue().withAlphaF(0.5));
2627 paint.setDrawStyle(DlDrawStyle::kStroke);
2628 paint.setStrokeWidth(40.0f);
2629
2630 // Square
2631 builder.DrawRoundSuperellipse(
2632 DlRoundSuperellipse::MakeRectRadius(
2633 /*rect=*/DlRect::MakeXYWH(50, 50, 100, 100), /*radius=*/30),
2634 paint);
2635 // Tall
2636 builder.DrawRoundSuperellipse(
2637 DlRoundSuperellipse::MakeRectRadius(
2638 /*rect=*/DlRect::MakeXYWH(200, 50, 60, 140), /*radius=*/30),
2639 paint);
2640 // Wide
2641 builder.DrawRoundSuperellipse(
2642 DlRoundSuperellipse::MakeRectRadius(
2643 /*rect=*/DlRect::MakeXYWH(310, 50, 140, 60), /*radius=*/30),
2644 paint);
2645
2646 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2647}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawRoundSuperellipse(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), impeller::RoundSuperellipse::MakeRectRadius(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [142/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderThinCurvedStrokes   
)

Definition at line 95 of file aiks_dl_path_unittests.cc.

95 {
96 DisplayListBuilder builder;
97 DlPaint paint;
98 paint.setColor(DlColor::kRed());
99 paint.setStrokeWidth(0.01);
100 paint.setDrawStyle(DlDrawStyle::kStroke);
101
102 builder.DrawPath(DlPath::MakeCircle(DlPoint(100, 100), 50), paint);
103
104 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
105}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPath::MakeCircle(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [143/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTightConicPath   
)

Definition at line 393 of file aiks_dl_path_unittests.cc.

393 {
394 DisplayListBuilder builder;
395 builder.Scale(GetContentScale().x, GetContentScale().y);
396
397 DlPaint paint;
398 paint.setColor(DlColor::kRed());
399 paint.setDrawStyle(DlDrawStyle::kFill);
400
401 DlPaint reference_paint;
402 reference_paint.setColor(DlColor::kGreen());
403 reference_paint.setDrawStyle(DlDrawStyle::kFill);
404
405 DlPathBuilder path_builder;
406
407 path_builder.MoveTo(DlPoint(100, 100));
408 path_builder.ConicCurveTo(DlPoint(150, 450), DlPoint(200, 100), 5.0f);
409
410 DlPathBuilder reference_builder;
411 PathTessellator::Conic component{DlPoint(300, 100), //
412 DlPoint(350, 450), //
413 DlPoint(400, 100), //
414 5.0f};
415 reference_builder.MoveTo(component.p1);
416 constexpr int N = 100;
417 for (int i = 1; i < N; i++) {
418 reference_builder.LineTo(component.Solve(static_cast<Scalar>(i) / N));
419 }
420 reference_builder.LineTo(component.p2);
421
422 DlPaint line_paint;
423 line_paint.setColor(DlColor::kYellow());
424 line_paint.setDrawStyle(DlDrawStyle::kStroke);
425 line_paint.setStrokeWidth(1.0f);
426
427 // Draw some lines to provide a spacial reference for the curvature of
428 // the tips of the direct rendering and the manually tessellated versions.
429 builder.DrawLine(DlPoint(145, 100), DlPoint(145, 450), line_paint);
430 builder.DrawLine(DlPoint(155, 100), DlPoint(155, 450), line_paint);
431 builder.DrawLine(DlPoint(345, 100), DlPoint(345, 450), line_paint);
432 builder.DrawLine(DlPoint(355, 100), DlPoint(355, 450), line_paint);
433 builder.DrawLine(DlPoint(100, 392.5f), DlPoint(400, 392.5f), line_paint);
434
435 // Draw the two paths (direct and manually tessellated) on top of the lines.
436 builder.DrawPath(path_builder.TakePath(), paint);
437 builder.DrawPath(reference_builder.TakePath(), reference_paint);
438
439 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
440}

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::ConicCurveTo(), flutter::DisplayListBuilder::DrawLine(), flutter::DisplayListBuilder::DrawPath(), i, flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [144/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTiledTextureClamp   
)

Definition at line 266 of file aiks_dl_basic_unittests.cc.

266 {
267 CanRenderTiledTexture(this, DlTileMode::kClamp);
268}

◆ TEST_P() [145/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTiledTextureClampWithTranslate   
)

Definition at line 282 of file aiks_dl_basic_unittests.cc.

282 {
283 CanRenderTiledTexture(this, DlTileMode::kClamp,
284 Matrix::MakeTranslation({172.f, 172.f, 0.f}));
285}

References impeller::Matrix::MakeTranslation().

◆ TEST_P() [146/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTiledTextureDecal   
)

Definition at line 278 of file aiks_dl_basic_unittests.cc.

278 {
279 CanRenderTiledTexture(this, DlTileMode::kDecal);
280}

◆ TEST_P() [147/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTiledTextureMirror   
)

Definition at line 274 of file aiks_dl_basic_unittests.cc.

274 {
275 CanRenderTiledTexture(this, DlTileMode::kMirror);
276}

◆ TEST_P() [148/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTiledTextureRepeat   
)

Definition at line 270 of file aiks_dl_basic_unittests.cc.

270 {
271 CanRenderTiledTexture(this, DlTileMode::kRepeat);
272}

◆ TEST_P() [149/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTinyOverlappingSubpasses   
)

This is a regression check for https://github.com/flutter/engine/pull/41129 The entire screen is green if successful. If failing, no frames will render, or the entire screen will be transparent black.

Definition at line 358 of file aiks_dl_unittests.cc.

358 {
359 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
360
361 DlPaint paint;
362 paint.setColor(DlColor::kRed());
363 builder.DrawPaint(paint);
364
365 // Draw two overlapping subpixel circles.
366 builder.SaveLayer(std::nullopt);
367
368 DlPaint yellow_paint;
369 yellow_paint.setColor(DlColor::kYellow());
370 builder.DrawCircle(DlPoint(100, 100), 0.1, yellow_paint);
371 builder.Restore();
372 builder.SaveLayer(std::nullopt);
373 builder.DrawCircle(DlPoint(100, 100), 0.1, yellow_paint);
374 builder.Restore();
375
376 DlPaint draw_paint;
377 draw_paint.setColor(DlColor::kGreen());
378 builder.DrawPaint(draw_paint);
379
380 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
381}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), impeller::TRect< Scalar >::MakeSize(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [150/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderTransformedRoundSuperellipse   
)

Definition at line 2681 of file aiks_dl_basic_unittests.cc.

2681 {
2682 DisplayListBuilder builder;
2683 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2684
2685 builder.Save();
2686 builder.Translate(200, 200);
2687 builder.Rotate(45.0f);
2688 builder.Scale(1.5f, 0.8f);
2689
2690 DlPaint paint;
2691 paint.setColor(DlColor::kBlue());
2692 builder.DrawRoundSuperellipse(
2693 DlRoundSuperellipse::MakeRectRadius(
2694 /*rect=*/DlRect::MakeXYWH(-70, -30, 140, 60), /*radius=*/20),
2695 paint);
2696 builder.Restore();
2697
2698 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2699}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawRoundSuperellipse(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), impeller::RoundSuperellipse::MakeRectRadius(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [151/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderWideStrokedRectPathWithoutOverlap   
)

Definition at line 108 of file aiks_dl_basic_unittests.cc.

108 {
109 ASSERT_TRUE(OpenPlaygroundHere(MakeWideStrokedRects(
110 GetContentScale(), [](DisplayListBuilder& builder, const DlRect& rect,
111 const DlPaint& paint) {
112 // Draw the rect as a Path
113 builder.DrawPath(DlPath::MakeRect(rect), paint);
114 })));
115}

References flutter::DisplayListBuilder::DrawPath(), and flutter::DlPath::MakeRect().

◆ TEST_P() [152/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderWideStrokedRectWithoutOverlap   
)

Definition at line 99 of file aiks_dl_basic_unittests.cc.

99 {
100 ASSERT_TRUE(OpenPlaygroundHere(MakeWideStrokedRects(
101 GetContentScale(), [](DisplayListBuilder& builder, const DlRect& rect,
102 const DlPaint& paint) {
103 // Draw the rect directly
104 builder.DrawRect(rect, paint);
105 })));
106}

References flutter::DisplayListBuilder::DrawRect().

◆ TEST_P() [153/662]

impeller::testing::TEST_P ( AiksTest  ,
CanRenderWithContiguousClipRestores   
)

Definition at line 74 of file aiks_dl_clip_unittests.cc.

74 {
75 DisplayListBuilder builder;
76
77 // Cover the whole canvas with red.
78 DlPaint paint;
79 paint.setColor(DlColor::kRed());
80 builder.DrawPaint(paint);
81
82 builder.Save();
83
84 // Append two clips, the second resulting in empty coverage.
85 builder.ClipRect(DlRect::MakeXYWH(100, 100, 100, 100));
86 builder.ClipRect(DlRect::MakeXYWH(300, 300, 100, 100));
87
88 // Restore to no clips.
89 builder.Restore();
90
91 // Replace the whole canvas with green.
92 paint.setColor(DlColor::kGreen());
93 builder.DrawPaint(paint);
94
95 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
96}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), and flutter::DlPaint::setColor().

◆ TEST_P() [154/662]

impeller::testing::TEST_P ( AiksTest  ,
CanSaveLayerStandalone   
)

Definition at line 409 of file aiks_dl_basic_unittests.cc.

409 {
410 DisplayListBuilder builder;
411
412 DlPaint red;
413 red.setColor(DlColor::kRed());
414
415 DlPaint alpha;
416 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
417
418 builder.SaveLayer(std::nullopt, &alpha);
419
420 builder.DrawCircle(DlPoint(125, 125), 125, red);
421
422 builder.Restore();
423
424 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
425}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kRed(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [155/662]

impeller::testing::TEST_P ( AiksTest  ,
CanvasCanPushPopCTM   
)

Definition at line 113 of file canvas_unittests.cc.

113 {
114 ContentContext& context = GetContentContext();
115 auto canvas = CreateTestCanvas(context);
116
117 ASSERT_EQ(canvas->GetSaveCount(), 1u);
118 ASSERT_EQ(canvas->Restore(), false);
119
120 canvas->Translate(Size{100, 100});
121 canvas->Save(10);
122 ASSERT_EQ(canvas->GetSaveCount(), 2u);
123 ASSERT_MATRIX_NEAR(canvas->GetCurrentTransform(),
124 Matrix::MakeTranslation({100.0, 100.0, 0.0}));
125 ASSERT_TRUE(canvas->Restore());
126 ASSERT_EQ(canvas->GetSaveCount(), 1u);
127 ASSERT_MATRIX_NEAR(canvas->GetCurrentTransform(),
128 Matrix::MakeTranslation({100.0, 100.0, 0.0}));
129}
std::unique_ptr< Canvas > CreateTestCanvas(ContentContext &context, std::optional< Rect > cull_rect=std::nullopt, bool requires_readback=false)

References ASSERT_MATRIX_NEAR, context, CreateTestCanvas(), and impeller::Matrix::MakeTranslation().

◆ TEST_P() [156/662]

impeller::testing::TEST_P ( AiksTest  ,
CanvasCTMCanBeUpdated   
)

Definition at line 131 of file canvas_unittests.cc.

131 {
132 ContentContext& context = GetContentContext();
133 auto canvas = CreateTestCanvas(context);
134
135 Matrix identity;
136 ASSERT_MATRIX_NEAR(canvas->GetCurrentTransform(), identity);
137 canvas->Translate(Size{100, 100});
138 ASSERT_MATRIX_NEAR(canvas->GetCurrentTransform(),
139 Matrix::MakeTranslation({100.0, 100.0, 0.0}));
140}

References ASSERT_MATRIX_NEAR, context, CreateTestCanvas(), and impeller::Matrix::MakeTranslation().

◆ TEST_P() [157/662]

impeller::testing::TEST_P ( AiksTest  ,
ClearBlend   
)

Definition at line 494 of file aiks_dl_blend_unittests.cc.

494 {
495 DisplayListBuilder builder;
496
497 DlPaint blue;
498 blue.setColor(DlColor::kBlue());
499 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600.0, 600.0), blue);
500
501 DlPaint clear;
502 clear.setBlendMode(DlBlendMode::kClear);
503
504 builder.DrawCircle(DlPoint(300.0, 300.0), 200.0, clear);
505
506 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
507}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [158/662]

impeller::testing::TEST_P ( AiksTest  ,
ClearBlendWithBlur   
)

Definition at line 516 of file aiks_dl_blur_unittests.cc.

516 {
517 DisplayListBuilder builder;
518 DlPaint paint;
519 paint.setColor(DlColor::kBlue());
520 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600.0, 600.0), paint);
521
522 DlPaint clear;
523 clear.setBlendMode(DlBlendMode::kClear);
524 clear.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 20));
525
526 builder.DrawCircle(DlPoint(300.0, 300.0), 200.0, clear);
527
528 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
529}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlBlurMaskFilter::Make(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), and flutter::DlPaint::setMaskFilter().

◆ TEST_P() [159/662]

impeller::testing::TEST_P ( AiksTest  ,
ClearColorOptimizationWhenSubpassIsBiggerThanParentPass   
)

Definition at line 1827 of file aiks_dl_basic_unittests.cc.

1827 {
1828 SetWindowSize({400, 400});
1829 DisplayListBuilder builder;
1830
1831 builder.Scale(GetContentScale().x, GetContentScale().y);
1832
1833 DlPaint paint;
1834 paint.setColor(DlColor::kRed());
1835 builder.DrawRect(DlRect::MakeLTRB(200, 200, 300, 300), paint);
1836
1837 paint.setImageFilter(DlImageFilter::MakeMatrix(DlMatrix::MakeScale({2, 2, 1}),
1838 DlImageSampling::kLinear));
1839 builder.SaveLayer(std::nullopt, &paint);
1840 // Draw a rectangle that would fully cover the parent pass size, but not
1841 // the subpass that it is rendered in.
1842 paint.setColor(DlColor::kGreen());
1843 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 400), paint);
1844 // Draw a bigger rectangle to force the subpass to be bigger.
1845
1846 paint.setColor(DlColor::kRed());
1847 builder.DrawRect(DlRect::MakeLTRB(0, 0, 800, 800), paint);
1848 builder.Restore();
1849
1850 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1851}

References flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlImageFilter::MakeMatrix(), impeller::Matrix::MakeScale(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), x, and y.

◆ TEST_P() [160/662]

impeller::testing::TEST_P ( AiksTest  ,
ClippedBackdropFilterWithShader   
)

Definition at line 506 of file aiks_dl_runtime_effect_unittests.cc.

506 {
507 struct FragUniforms {
508 Vector2 uSize;
509 } frag_uniforms = {.uSize = Vector2(400, 400)};
510 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
511 uniform_data->resize(sizeof(FragUniforms));
512 memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
513
514 auto runtime_stages_result =
515 OpenAssetAsRuntimeStage("runtime_stage_border.frag.iplr");
516 ABSL_ASSERT_OK(runtime_stages_result);
517 std::shared_ptr<RuntimeStage> runtime_stage =
518 runtime_stages_result.value()[GetRuntimeStageBackend()];
519 ASSERT_TRUE(runtime_stage);
520 ASSERT_TRUE(runtime_stage->IsDirty());
521
522 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
523 nullptr,
524 };
525
526 auto runtime_filter = DlImageFilter::MakeRuntimeEffect(
527 DlRuntimeEffectImpeller::Make(runtime_stage), sampler_inputs,
528 uniform_data);
529
530 DisplayListBuilder builder;
531
532 // Draw a background so the backdrop filter has something to affect
533 DlPaint background_paint;
534 background_paint.setColor(DlColor::kWhite());
535 builder.DrawPaint(background_paint);
536
537 // Draw some pattern to verify the filter effect
538 DlPaint pattern_paint;
539 pattern_paint.setColor(DlColor::kRed());
540 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), pattern_paint);
541 pattern_paint.setColor(DlColor::kBlue());
542 builder.DrawRect(DlRect::MakeXYWH(200, 200, 200, 200), pattern_paint);
543
544 builder.Save();
545
546 // Replicate the clip rect (inset by 66)
547 // Assuming a 400x400 screen, inset 66 gives roughly 66, 66, 268, 268
548 builder.ClipRect(DlRect::MakeXYWH(66, 66, 268, 268));
549
550 DlPaint save_paint;
551 // The Flutter code uses a backdrop filter layer.
552 // In DisplayList, this corresponds to SaveLayer with a backdrop filter.
553 builder.SaveLayer(std::nullopt, &save_paint, runtime_filter.get());
554
555 // The child was empty in the Flutter example, so we don't draw anything
556 // inside the SaveLayer
557
558 builder.Restore(); // Restore SaveLayer
559 builder.Restore(); // Restore Save (Clip)
560
561 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
562}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlRuntimeEffectImpeller::Make(), flutter::DlImageFilter::MakeRuntimeEffect(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [161/662]

impeller::testing::TEST_P ( AiksTest  ,
ClippedBlurFilterRendersCorrectly   
)

Definition at line 499 of file aiks_dl_blur_unittests.cc.

499 {
500 DisplayListBuilder builder;
501 builder.Translate(0, -400);
502 DlPaint paint;
503
504 Sigma sigma = Radius{120 * 3};
505 paint.setMaskFilter(
506 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, sigma.sigma));
507 paint.setColor(DlColor::kRed());
508
509 DlPath path = DlPath::MakeRect(DlRect::MakeLTRB(0, 0, 800, 800));
510 path = path + DlPath::MakeCircle(DlPoint(0, 0), 0.5);
511 builder.DrawPath(path, paint);
512
513 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
514}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlBlurMaskFilter::Make(), flutter::DlPath::MakeCircle(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRect(), flutter::path, flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), impeller::Sigma::sigma, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [162/662]

impeller::testing::TEST_P ( AiksTest  ,
ClippedBlurFilterRendersCorrectlyInteractive   
)

Definition at line 475 of file aiks_dl_blur_unittests.cc.

475 {
476 auto callback = [&]() -> sk_sp<DisplayList> {
477 static PlaygroundPoint playground_point(Point(400, 400), 20,
478 Color::Green());
479 auto point = DrawPlaygroundPoint(playground_point);
480
481 DisplayListBuilder builder;
482 auto location = point - Point(400, 400);
483 builder.Translate(location.x, location.y);
484
485 DlPaint paint;
486 Sigma sigma = Radius{120 * 3};
487 paint.setMaskFilter(
488 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, sigma.sigma));
489 paint.setColor(DlColor::kRed());
490
491 DlPath path = DlPath::MakeRect(DlRect::MakeLTRB(0, 0, 800, 800));
492 path = path + DlPath::MakeCircle(DlPoint(0, 0), 0.5);
493 builder.DrawPath(path, paint);
494 return builder.Build();
495 };
496 ASSERT_TRUE(OpenPlaygroundHere(callback));
497}
Point DrawPlaygroundPoint(PlaygroundPoint &point)
Definition widgets.cc:11

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawPath(), impeller::DrawPlaygroundPoint(), impeller::Color::Green(), flutter::DlColor::kRed(), location, flutter::DlBlurMaskFilter::Make(), flutter::DlPath::MakeCircle(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRect(), flutter::path, flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), impeller::Sigma::sigma, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [163/662]

impeller::testing::TEST_P ( AiksTest  ,
ClippedComposeBackdropRuntimeOuterBlurInnerSmallSigma   
)

Definition at line 431 of file aiks_dl_runtime_effect_unittests.cc.

431 {
432 auto runtime_stages_result =
433 OpenAssetAsRuntimeStage("runtime_stage_filter_circle.frag.iplr");
434 ABSL_ASSERT_OK(runtime_stages_result);
435 std::shared_ptr<RuntimeStage> runtime_stage =
436 runtime_stages_result.value()[GetRuntimeStageBackend()];
437 ASSERT_TRUE(runtime_stage);
438 ASSERT_TRUE(runtime_stage->IsDirty());
439 Scalar sigma = 5.0;
440 Vector2 clip_origin = Vector2(20.f, 20.f);
441 Vector2 clip_size = Vector2(300, 300);
442 Vector2 circle_origin = Vector2(30.f, 30.f);
443
444 auto callback = [&]() -> sk_sp<DisplayList> {
445 if (IsPlaygroundEnabled()) {
446 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
447 ImGui::SliderFloat("sigma", &sigma, 0, 20);
448 ImGui::SliderFloat("clip_x", &clip_origin.x, 0, 2048.f);
449 ImGui::SliderFloat("clip_y", &clip_origin.y, 0, 1536.f);
450 ImGui::SliderFloat("clip_width", &clip_size.x, 0, 2048.f);
451 ImGui::SliderFloat("clip_height", &clip_size.y, 0, 1536.f);
452 ImGui::SliderFloat("circle_x", &circle_origin.x, 0.f, 2048.f);
453 ImGui::SliderFloat("circle_y", &circle_origin.y, 0.f, 1536.f);
454 ImGui::End();
455 }
456 DisplayListBuilder builder;
457 DlPaint background;
458 background.setColor(DlColor(1.0, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
459 builder.DrawPaint(background);
460
461 auto blur_filter =
462 DlImageFilter::MakeBlur(sigma, sigma, DlTileMode::kClamp);
463
464 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
465 nullptr,
466 };
467 struct FragUniforms {
468 Vector2 size;
469 Vector2 origin;
470 } frag_uniforms = {.size = Vector2(1, 1), .origin = circle_origin};
471 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
472 uniform_data->resize(sizeof(FragUniforms));
473 memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
474
475 auto runtime_filter = DlImageFilter::MakeRuntimeEffect(
476 DlRuntimeEffectImpeller::Make(runtime_stage), sampler_inputs,
477 uniform_data);
478
479 auto backdrop_filter = DlImageFilter::MakeCompose(/*outer=*/runtime_filter,
480 /*inner=*/blur_filter);
481
482 builder.ClipRect(DlRect::MakeXYWH(clip_origin.x, clip_origin.y, clip_size.x,
483 clip_size.y));
484
485 DlPaint paint;
486 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
487 builder.DrawImage(image, DlPoint(100.0, 100.0),
488 DlImageSampling::kNearestNeighbor, &paint);
489
490 DlPaint save_paint;
491 save_paint.setBlendMode(DlBlendMode::kSrc);
492 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
493 builder.Restore();
494
495 DlPaint green;
496 green.setColor(DlColor::kGreen());
497 builder.DrawLine({100, 100}, {200, 100}, green);
498 builder.DrawLine({100, 100}, {100, 200}, green);
499
500 return builder.Build();
501 };
502
503 ASSERT_TRUE(OpenPlaygroundHere(callback));
504}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawLine(), flutter::DisplayListBuilder::DrawPaint(), image, flutter::DlColor::kGreen(), flutter::DlRuntimeEffectImpeller::Make(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), flutter::DlImageFilter::MakeCompose(), flutter::DlImageFilter::MakeRuntimeEffect(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), flutter::size, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

◆ TEST_P() [164/662]

impeller::testing::TEST_P ( AiksTest  ,
ClipsUseCurrentTransform   
)

Definition at line 98 of file aiks_dl_clip_unittests.cc.

98 {
99 std::array<DlColor, 5> colors = {DlColor::kWhite(), DlColor::kBlack(),
100 DlColor::kSkyBlue(), DlColor::kRed(),
101 DlColor::kYellow()};
102 DisplayListBuilder builder;
103 DlPaint paint;
104
105 builder.Translate(300, 300);
106 for (int i = 0; i < 15; i++) {
107 builder.Scale(0.8, 0.8);
108
109 paint.setColor(colors[i % colors.size()]);
110 builder.ClipPath(DlPath::MakeCircle(DlPoint(0, 0), 300));
111 builder.DrawRect(DlRect::MakeCircleBounds({0, 0}, 300), paint);
112 }
113 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
114}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipPath(), flutter::DisplayListBuilder::DrawRect(), i, flutter::DlColor::kBlack(), flutter::DlColor::kRed(), flutter::DlColor::kSkyBlue(), flutter::DlColor::kWhite(), flutter::DlColor::kYellow(), flutter::DlPath::MakeCircle(), impeller::TRect< Scalar >::MakeCircleBounds(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [165/662]

impeller::testing::TEST_P ( AiksTest  ,
CollapsedDrawPaintInSubpass   
)

Definition at line 41 of file aiks_dl_unittests.cc.

41 {
42 DisplayListBuilder builder;
43
44 DlPaint paint;
45 paint.setColor(DlColor::kYellow());
46 paint.setBlendMode(DlBlendMode::kSrc);
47 builder.DrawPaint(paint);
48
49 DlPaint save_paint;
50 save_paint.setBlendMode(DlBlendMode::kMultiply);
51 builder.SaveLayer(std::nullopt, &save_paint);
52
53 DlPaint draw_paint;
54 draw_paint.setColor(DlColor::kCornflowerBlue().modulateOpacity(0.75f));
55 builder.DrawPaint(draw_paint);
56
57 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
58}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kCornflowerBlue(), flutter::DlColor::kYellow(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [166/662]

impeller::testing::TEST_P ( AiksTest  ,
CollapsedDrawPaintInSubpassBackdropFilter   
)

Definition at line 60 of file aiks_dl_unittests.cc.

60 {
61 // Bug: https://github.com/flutter/flutter/issues/131576
62 DisplayListBuilder builder;
63
64 DlPaint paint;
65 paint.setColor(DlColor::kYellow());
66 paint.setBlendMode(DlBlendMode::kSrc);
67 builder.DrawPaint(paint);
68
69 auto filter = DlImageFilter::MakeBlur(20.0, 20.0, DlTileMode::kDecal);
70 builder.SaveLayer(std::nullopt, nullptr, filter.get());
71
72 DlPaint draw_paint;
73 draw_paint.setColor(DlColor::kCornflowerBlue());
74 builder.DrawPaint(draw_paint);
75
76 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
77}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kCornflowerBlue(), flutter::DlColor::kYellow(), flutter::DlImageFilter::MakeBlur(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [167/662]

impeller::testing::TEST_P ( AiksTest  ,
ColorFilterAdvancedBlend   
)

Definition at line 250 of file aiks_dl_blend_unittests.cc.

250 {
251 bool has_color_filter = true;
252 auto callback = [&]() -> sk_sp<DisplayList> {
253 if (IsPlaygroundEnabled()) {
254 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
255 ImGui::Checkbox("has color filter", &has_color_filter);
256 ImGui::End();
257 }
258
259 DisplayListBuilder builder;
260 builder.Scale(GetContentScale().x, GetContentScale().y);
261
262 auto src_image =
263 DlImageImpeller::Make(CreateTextureForFixture("blend_mode_src.png"));
264 auto dst_image =
265 DlImageImpeller::Make(CreateTextureForFixture("blend_mode_dst.png"));
266
267 std::vector<DlBlendMode> blend_modes = {
268 DlBlendMode::kScreen, DlBlendMode::kOverlay,
269 DlBlendMode::kDarken, DlBlendMode::kLighten,
270 DlBlendMode::kColorDodge, DlBlendMode::kColorBurn,
271 DlBlendMode::kHardLight, DlBlendMode::kSoftLight,
272 DlBlendMode::kDifference, DlBlendMode::kExclusion,
273 DlBlendMode::kMultiply, DlBlendMode::kHue,
274 DlBlendMode::kSaturation, DlBlendMode::kColor,
275 DlBlendMode::kLuminosity,
276 };
277
278 for (uint32_t i = 0; i < blend_modes.size(); ++i) {
279 builder.Save();
280 builder.Translate((i % 5) * 200, (i / 5) * 200);
281 builder.Scale(0.4, 0.4);
282 {
283 DlPaint dstPaint;
284 builder.DrawImage(dst_image, DlPoint(0, 0),
285 DlImageSampling::kMipmapLinear, &dstPaint);
286 }
287 {
288 DlPaint srcPaint;
289 srcPaint.setBlendMode(blend_modes[i]);
290 if (has_color_filter) {
291 std::shared_ptr<const DlColorFilter> color_filter =
292 DlColorFilter::MakeBlend(DlColor::RGBA(0.9, 0.5, 0.0, 1.0),
293 DlBlendMode::kSrcIn);
294 srcPaint.setColorFilter(color_filter);
295 }
296 builder.DrawImage(src_image, DlPoint(0, 0),
297 DlImageSampling::kMipmapLinear, &srcPaint);
298 }
299 builder.Restore();
300 }
301 return builder.Build();
302 };
303 ASSERT_TRUE(OpenPlaygroundHere(callback));
304}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawImage(), i, impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeBlend(), flutter::DisplayListBuilder::Restore(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColorFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [168/662]

impeller::testing::TEST_P ( AiksTest  ,
ColorFilterAdvancedBlendNoFbFetch   
)

Definition at line 309 of file aiks_dl_blend_unittests.cc.

309 {
310 if (GetParam() != PlaygroundBackend::kMetal) {
311 GTEST_SKIP()
312 << "This backend doesn't yet support setting device capabilities.";
313 }
314
315 std::shared_ptr<const Capabilities> old_capabilities =
316 GetContext()->GetCapabilities();
317 auto mock_capabilities = std::make_shared<MockCapabilities>();
318 EXPECT_CALL(*mock_capabilities, SupportsFramebufferFetch())
319 .Times(::testing::AtLeast(1))
320 .WillRepeatedly(::testing::Return(false));
321 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultColorFormat);
322 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultStencilFormat);
323 FLT_FORWARD(mock_capabilities, old_capabilities,
324 GetDefaultDepthStencilFormat);
325 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsOffscreenMSAA);
326 FLT_FORWARD(mock_capabilities, old_capabilities,
327 SupportsImplicitResolvingMSAA);
328 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsReadFromResolve);
329 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsSSBO);
330 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsCompute);
331 FLT_FORWARD(mock_capabilities, old_capabilities,
332 SupportsTextureToTextureBlits);
333 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultGlyphAtlasFormat);
334 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsTriangleFan);
335 FLT_FORWARD(mock_capabilities, old_capabilities,
336 SupportsDecalSamplerAddressMode);
337 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsPrimitiveRestart);
338 FLT_FORWARD(mock_capabilities, old_capabilities, GetMinimumUniformAlignment);
339 ASSERT_TRUE(SetCapabilities(mock_capabilities).ok());
340
341 bool has_color_filter = true;
342 auto callback = [&]() -> sk_sp<DisplayList> {
343 if (IsPlaygroundEnabled()) {
344 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
345 ImGui::Checkbox("has color filter", &has_color_filter);
346 ImGui::End();
347 }
348
349 DisplayListBuilder builder;
350 builder.Scale(GetContentScale().x, GetContentScale().y);
351
352 auto src_image =
353 DlImageImpeller::Make(CreateTextureForFixture("blend_mode_src.png"));
354 auto dst_image =
355 DlImageImpeller::Make(CreateTextureForFixture("blend_mode_dst.png"));
356
357 std::vector<DlBlendMode> blend_modes = {
358 DlBlendMode::kScreen, DlBlendMode::kOverlay,
359 DlBlendMode::kDarken, DlBlendMode::kLighten,
360 DlBlendMode::kColorDodge, DlBlendMode::kColorBurn,
361 DlBlendMode::kHardLight, DlBlendMode::kSoftLight,
362 DlBlendMode::kDifference, DlBlendMode::kExclusion,
363 DlBlendMode::kMultiply, DlBlendMode::kHue,
364 DlBlendMode::kSaturation, DlBlendMode::kColor,
365 DlBlendMode::kLuminosity,
366 };
367
368 for (uint32_t i = 0; i < blend_modes.size(); ++i) {
369 builder.Save();
370 builder.Translate((i % 5) * 200, (i / 5) * 200);
371 builder.Scale(0.4, 0.4);
372 {
373 DlPaint dstPaint;
374 builder.DrawImage(dst_image, DlPoint(0, 0),
375 DlImageSampling::kMipmapLinear, &dstPaint);
376 }
377 {
378 DlPaint srcPaint;
379 srcPaint.setBlendMode(blend_modes[i]);
380 if (has_color_filter) {
381 std::shared_ptr<const DlColorFilter> color_filter =
382 DlColorFilter::MakeBlend(DlColor::RGBA(0.9, 0.5, 0.0, 1.0),
383 DlBlendMode::kMultiply);
384 srcPaint.setColorFilter(color_filter);
385 }
386 builder.DrawImage(src_image, DlPoint(0, 0),
387 DlImageSampling::kMipmapLinear, &srcPaint);
388 }
389 builder.Restore();
390 }
391 return builder.Build();
392 };
393 ASSERT_TRUE(OpenPlaygroundHere(callback));
394}
#define FLT_FORWARD(mock, real, method)
Definition mocks.h:22

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawImage(), FLT_FORWARD, i, impeller::kMetal, impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeBlend(), flutter::DisplayListBuilder::Restore(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColorFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [169/662]

impeller::testing::TEST_P ( AiksTest  ,
ColorFilterBlend   
)

Definition at line 198 of file aiks_dl_blend_unittests.cc.

198 {
199 bool has_color_filter = true;
200 auto callback = [&]() -> sk_sp<DisplayList> {
201 if (IsPlaygroundEnabled()) {
202 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
203 ImGui::Checkbox("has color filter", &has_color_filter);
204 ImGui::End();
205 }
206
207 DisplayListBuilder builder;
208 builder.Scale(GetContentScale().x, GetContentScale().y);
209
210 auto src_image =
211 DlImageImpeller::Make(CreateTextureForFixture("blend_mode_src.png"));
212 auto dst_image =
213 DlImageImpeller::Make(CreateTextureForFixture("blend_mode_dst.png"));
214
215 std::vector<DlBlendMode> blend_modes = {
216 DlBlendMode::kSrc, DlBlendMode::kSrcATop, DlBlendMode::kSrcOver,
217 DlBlendMode::kSrcIn, DlBlendMode::kSrcOut, DlBlendMode::kDst,
218 DlBlendMode::kDstATop, DlBlendMode::kDstOver, DlBlendMode::kDstIn,
219 DlBlendMode::kDstOut, DlBlendMode::kClear, DlBlendMode::kXor};
220
221 for (uint32_t i = 0; i < blend_modes.size(); ++i) {
222 builder.Save();
223 builder.Translate((i % 5) * 200, (i / 5) * 200);
224 builder.Scale(0.4, 0.4);
225 {
226 DlPaint dstPaint;
227 builder.DrawImage(dst_image, DlPoint(0, 0),
228 DlImageSampling::kMipmapLinear, &dstPaint);
229 }
230 {
231 DlPaint srcPaint;
232 srcPaint.setBlendMode(blend_modes[i]);
233 if (has_color_filter) {
234 std::shared_ptr<const DlColorFilter> color_filter =
235 DlColorFilter::MakeBlend(DlColor::RGBA(0.9, 0.5, 0.0, 1.0),
236 DlBlendMode::kSrcIn);
237 srcPaint.setColorFilter(color_filter);
238 }
239 builder.DrawImage(src_image, DlPoint(0, 0),
240 DlImageSampling::kMipmapLinear, &srcPaint);
241 }
242 builder.Restore();
243 }
244 return builder.Build();
245 };
246 ASSERT_TRUE(OpenPlaygroundHere(callback));
247}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawImage(), i, impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeBlend(), flutter::DisplayListBuilder::Restore(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColorFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [170/662]

impeller::testing::TEST_P ( AiksTest  ,
ColorMatrixFilterSubpassCollapseOptimization   
)

Definition at line 79 of file aiks_dl_unittests.cc.

79 {
80 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
81 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
82
83 const float matrix[20] = {
84 -1.0, 0, 0, 1.0, 0, //
85 0, -1.0, 0, 1.0, 0, //
86 0, 0, -1.0, 1.0, 0, //
87 1.0, 1.0, 1.0, 1.0, 0 //
88 };
89 auto filter = DlColorFilter::MakeMatrix(matrix);
90
91 DlPaint paint;
92 paint.setColorFilter(filter);
93 builder.SaveLayer(std::nullopt, &paint);
94
95 builder.Translate(500, 300);
96 builder.Rotate(120); // 120 deg
97
98 DlPaint draw_paint;
99 draw_paint.setColor(DlColor::kBlue());
100 builder.DrawRect(DlRect::MakeXYWH(100, 100, 200, 200), draw_paint);
101
102 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
103}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DlColorFilter::MakeMatrix(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [171/662]

impeller::testing::TEST_P ( AiksTest  ,
ColorWheel   
)

color_wheel_sampler: r=0 -> fuchsia, r=2pi/3 -> yellow, r=4pi/3 -> cyan domain: r >= 0 (because modulo used is non euclidean)

Definition at line 783 of file aiks_dl_blend_unittests.cc.

783 {
784 // Compare with https://fiddle.skia.org/c/@BlendModes
785
787
788 auto draw_color_wheel = [](DisplayListBuilder& builder) -> void {
789 /// color_wheel_sampler: r=0 -> fuchsia, r=2pi/3 -> yellow, r=4pi/3 ->
790 /// cyan domain: r >= 0 (because modulo used is non euclidean)
791 auto color_wheel_sampler = [](Radians r) {
792 Scalar x = r.radians / k2Pi + 1;
793
794 // https://www.desmos.com/calculator/6nhjelyoaj
795 auto color_cycle = [](Scalar x) {
796 Scalar cycle = std::fmod(x, 6.0f);
797 return std::max(0.0f, std::min(1.0f, 2 - std::abs(2 - cycle)));
798 };
799 return Color(color_cycle(6 * x + 1), //
800 color_cycle(6 * x - 1), //
801 color_cycle(6 * x - 3), //
802 1);
803 };
804
805 DlPaint paint;
806 paint.setBlendMode(DlBlendMode::kSrcOver);
807
808 // Draw a fancy color wheel for the backdrop.
809 // https://www.desmos.com/calculator/xw7kafthwd
810 const int max_dist = 900;
811 for (int i = 0; i <= 900; i++) {
812 Radians r(kPhi / k2Pi * i);
813 Scalar distance = r.radians / std::powf(4.12, 0.0026 * r.radians);
814 Scalar normalized_distance = static_cast<Scalar>(i) / max_dist;
815
816 auto color = color_wheel_sampler(r).WithAlpha(1.0f - normalized_distance);
817 paint.setColor(
818 DlColor::RGBA(color.red, color.green, color.blue, color.alpha));
819 DlPoint position = DlPoint(distance * std::sin(r.radians),
820 -distance * std::cos(r.radians));
821
822 builder.DrawCircle(position, 9 + normalized_distance * 3, paint);
823 }
824 };
825
826 auto callback = [&]() -> sk_sp<DisplayList> {
827 // UI state.
828 static bool cache_the_wheel = true;
829 static int current_blend_index = 3;
830 static float dst_alpha = 1;
831 static float src_alpha = 1;
832 static DlColor color0 = DlColor::kRed();
833 static DlColor color1 = DlColor::kGreen();
834 static DlColor color2 = DlColor::kBlue();
835
836 if (IsPlaygroundEnabled()) {
837 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
838 ImGui::Checkbox("Cache the wheel", &cache_the_wheel);
839 ImGui::ListBox("Blending mode", &current_blend_index,
840 blend_modes.blend_mode_names.data(),
841 blend_modes.blend_mode_names.size());
842 ImGui::SliderFloat("Source alpha", &src_alpha, 0, 1);
843 ImGui::ColorEdit4("Color A", reinterpret_cast<float*>(&color0));
844 ImGui::ColorEdit4("Color B", reinterpret_cast<float*>(&color1));
845 ImGui::ColorEdit4("Color C", reinterpret_cast<float*>(&color2));
846 ImGui::SliderFloat("Destination alpha", &dst_alpha, 0, 1);
847 ImGui::End();
848 }
849
850 DisplayListBuilder builder;
851
852 DlPaint paint;
853 paint.setColor(DlColor::kWhite().withAlpha(dst_alpha * 255));
854 paint.setBlendMode(DlBlendMode::kSrc);
855 builder.SaveLayer(std::nullopt, &paint);
856 {
857 DlPaint paint;
858 paint.setColor(DlColor::kWhite());
859 builder.DrawPaint(paint);
860
861 builder.SaveLayer(std::nullopt, nullptr);
862 builder.Scale(GetContentScale().x, GetContentScale().y);
863 builder.Translate(500, 400);
864 builder.Scale(3, 3);
865 draw_color_wheel(builder);
866 builder.Restore();
867 }
868 builder.Restore();
869
870 builder.Scale(GetContentScale().x, GetContentScale().y);
871 builder.Translate(500, 400);
872 builder.Scale(3, 3);
873
874 // Draw 3 circles to a subpass and blend it in.
875 DlPaint save_paint;
876 save_paint.setColor(DlColor::kWhite().withAlpha(src_alpha * 255));
877 save_paint.setBlendMode(static_cast<DlBlendMode>(
878 blend_modes.blend_mode_values[current_blend_index]));
879 builder.SaveLayer(std::nullopt, &save_paint);
880 {
881 DlPaint paint;
882 paint.setBlendMode(DlBlendMode::kPlus);
883 const Scalar x = std::sin(k2Pi / 3);
884 const Scalar y = -std::cos(k2Pi / 3);
885 paint.setColor(color0);
886 builder.DrawCircle(DlPoint(-x * 45, y * 45), 65, paint);
887 paint.setColor(color1);
888 builder.DrawCircle(DlPoint(0, -45), 65, paint);
889 paint.setColor(color2);
890 builder.DrawCircle(DlPoint(x * 45, y * 45), 65, paint);
891 }
892 builder.Restore();
893
894 return builder.Build();
895 };
896
897 ASSERT_TRUE(OpenPlaygroundHere(callback));
898}

References impeller::testing::BlendModeSelection::blend_mode_names, impeller::testing::BlendModeSelection::blend_mode_values, flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), GetBlendModeSelection(), i, impeller::k2Pi, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), impeller::kPhi, flutter::DlColor::kRed(), flutter::DlColor::kWhite(), impeller::Radians::radians, flutter::DisplayListBuilder::Restore(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [172/662]

impeller::testing::TEST_P ( AiksTest  ,
CompareAntiAliasAndNonAntiAlias   
)

Definition at line 2701 of file aiks_dl_basic_unittests.cc.

2701 {
2702 DisplayListBuilder builder;
2703 builder.DrawColor(DlColor::kBlack(), DlBlendMode::kSrc);
2704
2705 DlPaint paint;
2706 paint.setColor(DlColor::kWhite());
2707
2708 DlRect bounds = DlRect::MakeXYWH(75, 75, 50, 50);
2709
2710 // --- Left Half: Zoom-in on the top-left corner WITH anti-aliasing (SDF) ---
2711 DlPaint layer_paint_left;
2712 layer_paint_left.setImageFilter(DlImageFilter::MakeMatrix(
2713 DlMatrix::MakeTranslation({200, 300}) * DlMatrix::MakeScale({8, 8, 1}) *
2714 DlMatrix::MakeTranslation({-100, -100}),
2715 DlImageSampling::kNearestNeighbor));
2716 builder.SaveLayer(bounds, &layer_paint_left);
2717
2718 paint.setAntiAlias(true);
2719 builder.DrawRoundRect(
2720 DlRoundRect::MakeRectRadius(DlRect::MakeXYWH(100, 100, 200, 200), 50.0f),
2721 paint);
2722 builder.Restore();
2723
2724 // --- Right Half: Zoom-in on the top-left corner WITHOUT anti-aliasing ---
2725 DlPaint layer_paint_right;
2726 layer_paint_right.setImageFilter(DlImageFilter::MakeMatrix(
2727 DlMatrix::MakeTranslation({600, 300}) * DlMatrix::MakeScale({8, 8, 1}) *
2728 DlMatrix::MakeTranslation({-100, -100}),
2729 DlImageSampling::kNearestNeighbor));
2730 builder.SaveLayer(bounds, &layer_paint_right);
2731
2732 paint.setAntiAlias(false);
2733 builder.DrawRoundRect(
2734 DlRoundRect::MakeRectRadius(DlRect::MakeXYWH(100, 100, 200, 200), 50.0f),
2735 paint);
2736 builder.Restore();
2737
2738 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2739}
DlPaint & setAntiAlias(bool isAntiAlias)
Definition dl_paint.h:58

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kBlack(), flutter::DlColor::kWhite(), flutter::DlImageFilter::MakeMatrix(), impeller::RoundRect::MakeRectRadius(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setAntiAlias(), flutter::DlPaint::setColor(), and flutter::DlPaint::setImageFilter().

◆ TEST_P() [173/662]

impeller::testing::TEST_P ( AiksTest  ,
CompareDiffRoundRectAndRoundRect   
)

Definition at line 2741 of file aiks_dl_basic_unittests.cc.

2741 {
2742 DisplayListBuilder builder;
2743 builder.DrawColor(DlColor::kBlack(), DlBlendMode::kSrc);
2744
2745 DlRect outer_rect = DlRect::MakeXYWH(0, 0, 100, 100);
2746 DlRoundingRadii outer_radii = {.top_left = DlSize(5.0f),
2747 .top_right = DlSize(10.0f),
2748 .bottom_left = DlSize(20.0f),
2749 .bottom_right = DlSize(50.0f)};
2750 DlRoundRect outer_rrect = DlRoundRect::MakeRectRadii(outer_rect, outer_radii);
2751
2752 DlScalar inner_inset = 5.0f;
2753 DlRect inner_rect = outer_rect.Expand(-inner_inset);
2754 DlRoundingRadii inner_radii = {
2755 .top_left = DlSize(outer_radii.top_left.width - inner_inset),
2756 .top_right = DlSize(outer_radii.top_right.width - inner_inset),
2757 .bottom_left = DlSize(outer_radii.bottom_left.width - inner_inset),
2758 .bottom_right = DlSize(outer_radii.bottom_right.width - inner_inset)};
2759 DlRoundRect inner_rrect = DlRoundRect::MakeRectRadii(inner_rect, inner_radii);
2760
2761 builder.Translate(50, 50);
2762
2763 // Draw DiffRoundRect.
2764 builder.DrawDiffRoundRect(outer_rrect, inner_rrect,
2765 DlPaint().setColor(DlColor::kSkyBlue()));
2766
2767 // Draw simalated DiffRoundRect by drawing the outer RoundRect and clearing
2768 // the inner RoundRect.
2769 builder.Translate(200, 0);
2770 builder.DrawRoundRect(outer_rrect, DlPaint().setColor(DlColor::kSkyBlue()));
2771 builder.DrawRoundRect(inner_rrect,
2772 DlPaint().setBlendMode(DlBlendMode::kClear));
2773
2774 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2775}
void DrawDiffRoundRect(const DlRoundRect &outer, const DlRoundRect &inner, const DlPaint &paint) override
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
Definition rect.h:652

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawDiffRoundRect(), flutter::DisplayListBuilder::DrawRoundRect(), impeller::TRect< T >::Expand(), flutter::DlColor::kBlack(), flutter::DlColor::kSkyBlue(), impeller::RoundRect::MakeRectRadii(), impeller::TRect< Scalar >::MakeXYWH(), impeller::RoundingRadii::top_left, impeller::RoundingRadii::top_right, flutter::DisplayListBuilder::Translate(), and flutter::Size::width().

◆ TEST_P() [174/662]

impeller::testing::TEST_P ( AiksTest  ,
ComposeBackdropRuntimeOuterBlurInner   
)

Definition at line 304 of file aiks_dl_runtime_effect_unittests.cc.

304 {
305 auto runtime_stages_result =
306 OpenAssetAsRuntimeStage("runtime_stage_filter_circle.frag.iplr");
307 ABSL_ASSERT_OK(runtime_stages_result);
308 std::shared_ptr<RuntimeStage> runtime_stage =
309 runtime_stages_result.value()[GetRuntimeStageBackend()];
310 ASSERT_TRUE(runtime_stage);
311 ASSERT_TRUE(runtime_stage->IsDirty());
312 Scalar sigma = 20.0;
313
314 auto callback = [&]() -> sk_sp<DisplayList> {
315 if (IsPlaygroundEnabled()) {
316 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
317 ImGui::SliderFloat("sigma", &sigma, 0, 20);
318 ImGui::End();
319 }
320 DisplayListBuilder builder;
321 DlPaint background;
322 background.setColor(DlColor(1.0, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
323 builder.DrawPaint(background);
324
325 auto blur_filter =
326 DlImageFilter::MakeBlur(sigma, sigma, DlTileMode::kClamp);
327
328 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
329 nullptr,
330 };
331
332 struct FragUniforms {
333 Vector2 size;
334 Vector2 origin;
335 } frag_uniforms = {.size = Vector2(1, 1), .origin = Vector2(30.f, 30.f)};
336 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
337 uniform_data->resize(sizeof(FragUniforms));
338 memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
339
340 auto runtime_filter = DlImageFilter::MakeRuntimeEffect(
341 DlRuntimeEffectImpeller::Make(runtime_stage), sampler_inputs,
342 uniform_data);
343
344 auto backdrop_filter = DlImageFilter::MakeCompose(/*outer=*/runtime_filter,
345 /*inner=*/blur_filter);
346
347 DlPaint paint;
348 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
349 builder.DrawImage(image, DlPoint(100.0, 100.0),
350 DlImageSampling::kNearestNeighbor, &paint);
351
352 DlPaint save_paint;
353 save_paint.setBlendMode(DlBlendMode::kSrc);
354 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
355 builder.Restore();
356
357 DlPaint green;
358 green.setColor(DlColor::kGreen());
359 builder.DrawLine({100, 100}, {200, 100}, green);
360 builder.DrawLine({100, 100}, {100, 200}, green);
361
362 return builder.Build();
363 };
364
365 ASSERT_TRUE(OpenPlaygroundHere(callback));
366}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawLine(), flutter::DisplayListBuilder::DrawPaint(), image, flutter::DlColor::kGreen(), flutter::DlRuntimeEffectImpeller::Make(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), flutter::DlImageFilter::MakeCompose(), flutter::DlImageFilter::MakeRuntimeEffect(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), and flutter::size.

◆ TEST_P() [175/662]

impeller::testing::TEST_P ( AiksTest  ,
ComposeBackdropRuntimeOuterBlurInnerSmallSigma   
)

Definition at line 368 of file aiks_dl_runtime_effect_unittests.cc.

368 {
369 auto runtime_stages_result =
370 OpenAssetAsRuntimeStage("runtime_stage_filter_circle.frag.iplr");
371 ABSL_ASSERT_OK(runtime_stages_result);
372 std::shared_ptr<RuntimeStage> runtime_stage =
373 runtime_stages_result.value()[GetRuntimeStageBackend()];
374 ASSERT_TRUE(runtime_stage);
375 ASSERT_TRUE(runtime_stage->IsDirty());
376 Scalar sigma = 5.0;
377
378 auto callback = [&]() -> sk_sp<DisplayList> {
379 if (IsPlaygroundEnabled()) {
380 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
381 ImGui::SliderFloat("sigma", &sigma, 0, 20);
382 ImGui::End();
383 }
384 DisplayListBuilder builder;
385 DlPaint background;
386 background.setColor(DlColor(1.0, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
387 builder.DrawPaint(background);
388
389 auto blur_filter =
390 DlImageFilter::MakeBlur(sigma, sigma, DlTileMode::kClamp);
391
392 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
393 nullptr,
394 };
395 struct FragUniforms {
396 Vector2 size;
397 Vector2 origin;
398 } frag_uniforms = {.size = Vector2(1, 1), .origin = Vector2(30.f, 30.f)};
399 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
400 uniform_data->resize(sizeof(FragUniforms));
401 memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
402
403 auto runtime_filter = DlImageFilter::MakeRuntimeEffect(
404 DlRuntimeEffectImpeller::Make(runtime_stage), sampler_inputs,
405 uniform_data);
406
407 auto backdrop_filter = DlImageFilter::MakeCompose(/*outer=*/runtime_filter,
408 /*inner=*/blur_filter);
409
410 DlPaint paint;
411 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
412 builder.DrawImage(image, DlPoint(100.0, 100.0),
413 DlImageSampling::kNearestNeighbor, &paint);
414
415 DlPaint save_paint;
416 save_paint.setBlendMode(DlBlendMode::kSrc);
417 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
418 builder.Restore();
419
420 DlPaint green;
421 green.setColor(DlColor::kGreen());
422 builder.DrawLine({100, 100}, {200, 100}, green);
423 builder.DrawLine({100, 100}, {100, 200}, green);
424
425 return builder.Build();
426 };
427
428 ASSERT_TRUE(OpenPlaygroundHere(callback));
429}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawLine(), flutter::DisplayListBuilder::DrawPaint(), image, flutter::DlColor::kGreen(), flutter::DlRuntimeEffectImpeller::Make(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), flutter::DlImageFilter::MakeCompose(), flutter::DlImageFilter::MakeRuntimeEffect(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), and flutter::size.

◆ TEST_P() [176/662]

impeller::testing::TEST_P ( AiksTest  ,
ComposePaintBlurInner   
)

Definition at line 450 of file aiks_dl_blur_unittests.cc.

450 {
451 DisplayListBuilder builder;
452
453 DlPaint background;
454 background.setColor(DlColor(1.0, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
455 builder.DrawPaint(background);
456
457 DlPaint paint;
458 paint.setColor(DlColor::kGreen());
459 float matrix[] = {
460 0, 1, 0, 0, 0, //
461 1, 0, 0, 0, 0, //
462 0, 0, 1, 0, 0, //
463 0, 0, 0, 1, 0 //
464 };
465 std::shared_ptr<DlImageFilter> color_filter =
466 DlImageFilter::MakeColorFilter(DlColorFilter::MakeMatrix(matrix));
467 std::shared_ptr<DlImageFilter> blur =
468 DlImageFilter::MakeBlur(20, 20, DlTileMode::kDecal);
469 paint.setImageFilter(DlImageFilter::MakeCompose(color_filter, blur));
470 builder.DrawCircle(DlPoint(400, 400), 200, paint);
471
472 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
473}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kGreen(), flutter::DlImageFilter::MakeBlur(), flutter::DlImageFilter::MakeColorFilter(), flutter::DlImageFilter::MakeCompose(), flutter::DlColorFilter::MakeMatrix(), flutter::DlPaint::setColor(), and flutter::DlPaint::setImageFilter().

◆ TEST_P() [177/662]

impeller::testing::TEST_P ( AiksTest  ,
ComposePaintBlurOuter   
)

Definition at line 425 of file aiks_dl_blur_unittests.cc.

425 {
426 DisplayListBuilder builder;
427
428 DlPaint background;
429 background.setColor(DlColor(1.0, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
430 builder.DrawPaint(background);
431
432 DlPaint paint;
433 paint.setColor(DlColor::kGreen());
434 float matrix[] = {
435 0, 1, 0, 0, 0, //
436 1, 0, 0, 0, 0, //
437 0, 0, 1, 0, 0, //
438 0, 0, 0, 1, 0 //
439 };
440 std::shared_ptr<DlImageFilter> color_filter =
441 DlImageFilter::MakeColorFilter(DlColorFilter::MakeMatrix(matrix));
442 std::shared_ptr<DlImageFilter> blur =
443 DlImageFilter::MakeBlur(20, 20, DlTileMode::kDecal);
444 paint.setImageFilter(DlImageFilter::MakeCompose(blur, color_filter));
445 builder.DrawCircle(DlPoint(400, 400), 200, paint);
446
447 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
448}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kGreen(), flutter::DlImageFilter::MakeBlur(), flutter::DlImageFilter::MakeColorFilter(), flutter::DlImageFilter::MakeCompose(), flutter::DlColorFilter::MakeMatrix(), flutter::DlPaint::setColor(), and flutter::DlPaint::setImageFilter().

◆ TEST_P() [178/662]

impeller::testing::TEST_P ( AiksTest  ,
ComposePaintRuntimeInner   
)

Definition at line 217 of file aiks_dl_runtime_effect_unittests.cc.

217 {
218 auto runtime_stages_result =
219 OpenAssetAsRuntimeStage("runtime_stage_filter_warp.frag.iplr");
220 ABSL_ASSERT_OK(runtime_stages_result);
221 std::shared_ptr<RuntimeStage> runtime_stage =
222 runtime_stages_result.value()[GetRuntimeStageBackend()];
223 ASSERT_TRUE(runtime_stage);
224 ASSERT_TRUE(runtime_stage->IsDirty());
225 Scalar xoffset = 50;
226 Scalar yoffset = 50;
227 Scalar xscale = 0.7;
228 Scalar yscale = 0.7;
229 bool compare = false;
230
231 auto callback = [&]() -> sk_sp<DisplayList> {
232 if (IsPlaygroundEnabled()) {
233 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
234 ImGui::SliderFloat("xoffset", &xoffset, -50, 50);
235 ImGui::SliderFloat("yoffset", &yoffset, -50, 50);
236 ImGui::SliderFloat("xscale", &xscale, 0, 1);
237 ImGui::SliderFloat("yscale", &yscale, 0, 1);
238 ImGui::Checkbox("compare", &compare);
239 ImGui::End();
240 }
241 DisplayListBuilder builder;
242 DlPaint background;
243 background.setColor(DlColor(1.0, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
244 builder.DrawPaint(background);
245
246 DlPaint paint;
247 paint.setColor(DlColor::kGreen());
248 float matrix[] = {
249 0, 1, 0, 0, 0, //
250 1, 0, 0, 0, 0, //
251 0, 0, 1, 0, 0, //
252 0, 0, 0, 1, 0 //
253 };
254 std::shared_ptr<DlImageFilter> color_filter =
255 DlImageFilter::MakeColorFilter(DlColorFilter::MakeMatrix(matrix));
256
257 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
258 nullptr,
259 };
260 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
261 uniform_data->resize(sizeof(Vector2));
262
263 auto runtime_filter = DlImageFilter::MakeRuntimeEffect(
264 DlRuntimeEffectImpeller::Make(runtime_stage), sampler_inputs,
265 uniform_data);
266
267 builder.Translate(xoffset, yoffset);
268 builder.Scale(xscale, yscale);
269
270 paint.setImageFilter(
271 DlImageFilter::MakeCompose(color_filter, runtime_filter));
272 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
273 builder.DrawImage(image, DlPoint(100.0, 100.0),
274 DlImageSampling::kNearestNeighbor, &paint);
275
276 if (compare) {
277 paint.setImageFilter(
278 DlImageFilter::MakeCompose(runtime_filter, color_filter));
279 builder.DrawImage(image, DlPoint(800.0, 100.0),
280 DlImageSampling::kNearestNeighbor, &paint);
281
282 paint.setImageFilter(runtime_filter);
283 builder.DrawImage(image, DlPoint(100.0, 800.0),
284 DlImageSampling::kNearestNeighbor, &paint);
285 }
286
287 DlPaint green;
288 green.setColor(DlColor::kGreen());
289 builder.DrawLine({100, 100}, {200, 100}, green);
290 builder.DrawLine({100, 100}, {100, 200}, green);
291 if (compare) {
292 builder.DrawLine({800, 100}, {900, 100}, green);
293 builder.DrawLine({800, 100}, {800, 200}, green);
294 builder.DrawLine({100, 800}, {200, 800}, green);
295 builder.DrawLine({100, 800}, {100, 900}, green);
296 }
297
298 return builder.Build();
299 };
300
301 ASSERT_TRUE(OpenPlaygroundHere(callback));
302}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawLine(), flutter::DisplayListBuilder::DrawPaint(), image, flutter::DlColor::kGreen(), flutter::DlRuntimeEffectImpeller::Make(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeColorFilter(), flutter::DlImageFilter::MakeCompose(), flutter::DlColorFilter::MakeMatrix(), flutter::DlImageFilter::MakeRuntimeEffect(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [179/662]

impeller::testing::TEST_P ( AiksTest  ,
ComposePaintRuntimeOuter   
)

Definition at line 165 of file aiks_dl_runtime_effect_unittests.cc.

165 {
166 DisplayListBuilder builder;
167 DlPaint background;
168 background.setColor(DlColor(1.0, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
169 builder.DrawPaint(background);
170
171 DlPaint paint;
172 paint.setColor(DlColor::kGreen());
173 float matrix[] = {
174 0, 1, 0, 0, 0, //
175 1, 0, 0, 0, 0, //
176 0, 0, 1, 0, 0, //
177 0, 0, 0, 1, 0 //
178 };
179 std::shared_ptr<DlImageFilter> color_filter =
180 DlImageFilter::MakeColorFilter(DlColorFilter::MakeMatrix(matrix));
181
182 auto runtime_stages_result =
183 OpenAssetAsRuntimeStage("runtime_stage_filter_warp.frag.iplr");
184 ABSL_ASSERT_OK(runtime_stages_result);
185 std::shared_ptr<RuntimeStage> runtime_stage =
186 runtime_stages_result.value()[GetRuntimeStageBackend()];
187 ASSERT_TRUE(runtime_stage);
188 ASSERT_TRUE(runtime_stage->IsDirty());
189
190 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
191 nullptr,
192 };
193 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
194 uniform_data->resize(sizeof(Vector2));
195
196 auto runtime_filter = DlImageFilter::MakeRuntimeEffect(
197 DlRuntimeEffectImpeller::Make(runtime_stage), sampler_inputs,
198 uniform_data);
199
200 builder.Translate(50, 50);
201 builder.Scale(0.7, 0.7);
202
203 paint.setImageFilter(
204 DlImageFilter::MakeCompose(runtime_filter, color_filter));
205 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
206 builder.DrawImage(image, DlPoint(100.0, 100.0),
207 DlImageSampling::kNearestNeighbor, &paint);
208
209 DlPaint green;
210 green.setColor(DlColor::kGreen());
211 builder.DrawLine({100, 100}, {200, 100}, green);
212 builder.DrawLine({100, 100}, {100, 200}, green);
213
214 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
215}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawLine(), flutter::DisplayListBuilder::DrawPaint(), image, flutter::DlColor::kGreen(), flutter::DlRuntimeEffectImpeller::Make(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeColorFilter(), flutter::DlImageFilter::MakeCompose(), flutter::DlColorFilter::MakeMatrix(), flutter::DlImageFilter::MakeRuntimeEffect(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [180/662]

impeller::testing::TEST_P ( AiksTest  ,
CoordinateConversionsAreCorrect   
)

Definition at line 1931 of file aiks_dl_basic_unittests.cc.

1931 {
1932 DisplayListBuilder builder;
1933
1934 // Render a texture directly.
1935 {
1936 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
1937
1938 builder.Save();
1939 builder.Translate(100, 200);
1940 builder.Scale(0.5, 0.5);
1941 builder.DrawImage(image, DlPoint(100.0, 100.0),
1942 DlImageSampling::kNearestNeighbor);
1943 builder.Restore();
1944 }
1945
1946 // Render an offscreen rendered texture.
1947 {
1948 DlPaint alpha;
1949 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
1950
1951 builder.SaveLayer(std::nullopt, &alpha);
1952
1953 DlPaint paint;
1954 paint.setColor(DlColor::kRed());
1955 builder.DrawRect(DlRect::MakeXYWH(000, 000, 100, 100), paint);
1956 paint.setColor(DlColor::kGreen());
1957 builder.DrawRect(DlRect::MakeXYWH(020, 020, 100, 100), paint);
1958 paint.setColor(DlColor::kBlue());
1959 builder.DrawRect(DlRect::MakeXYWH(040, 040, 100, 100), paint);
1960
1961 builder.Restore();
1962 }
1963
1964 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1965}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawRect(), image, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [181/662]

impeller::testing::TEST_P ( AiksTest  ,
CoverageOriginShouldBeAccountedForInSubpasses   
)

Definition at line 2112 of file aiks_dl_basic_unittests.cc.

2112 {
2113 auto callback = [&]() -> sk_sp<DisplayList> {
2114 DisplayListBuilder builder;
2115 builder.Scale(GetContentScale().x, GetContentScale().y);
2116
2117 DlPaint alpha;
2118 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
2119
2120 auto current = Point{25, 25};
2121 const auto offset = Point{25, 25};
2122 const auto size = Size(100, 100);
2123
2124 static PlaygroundPoint point_a(Point(40, 40), 10, Color::White());
2125 static PlaygroundPoint point_b(Point(160, 160), 10, Color::White());
2126 auto [b0, b1] = DrawPlaygroundLine(point_a, point_b);
2127 DlRect bounds = DlRect::MakeLTRB(b0.x, b0.y, b1.x, b1.y);
2128
2129 DlPaint stroke_paint;
2130 stroke_paint.setColor(DlColor::kYellow());
2131 stroke_paint.setStrokeWidth(5);
2132 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
2133 builder.DrawRect(bounds, stroke_paint);
2134
2135 builder.SaveLayer(bounds, &alpha);
2136
2137 DlPaint paint;
2138 paint.setColor(DlColor::kRed());
2139 builder.DrawRect(
2140 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
2141
2142 paint.setColor(DlColor::kGreen());
2143 current += offset;
2144 builder.DrawRect(
2145 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
2146
2147 paint.setColor(DlColor::kBlue());
2148 current += offset;
2149 builder.DrawRect(
2150 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
2151
2152 builder.Restore();
2153
2154 return builder.Build();
2155 };
2156
2157 ASSERT_TRUE(OpenPlaygroundHere(callback));
2158}

References flutter::DisplayListBuilder::Build(), callback, impeller::DrawPlaygroundLine(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlColor::modulateOpacity(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), flutter::size, and impeller::Color::White().

◆ TEST_P() [182/662]

impeller::testing::TEST_P ( AiksTest  ,
DepthValuesForLineMode   
)

Definition at line 988 of file aiks_dl_unittests.cc.

988 {
989 // Ensures that the additional draws created by line/polygon mode all
990 // have the same depth values.
991 DisplayListBuilder builder;
992
993 DlPath path = DlPath::MakeCircle(DlPoint(100, 100), 100);
994
995 builder.DrawPath(path, DlPaint()
996 .setColor(DlColor::kRed())
997 .setDrawStyle(DlDrawStyle::kStroke)
998 .setStrokeWidth(5));
999 builder.Save();
1000 builder.ClipPath(path);
1001
1002 std::vector<DlPoint> points = {
1003 DlPoint::MakeXY(0, -200), DlPoint::MakeXY(400, 200),
1004 DlPoint::MakeXY(0, -100), DlPoint::MakeXY(400, 300),
1005 DlPoint::MakeXY(0, 0), DlPoint::MakeXY(400, 400),
1006 DlPoint::MakeXY(0, 100), DlPoint::MakeXY(400, 500),
1007 DlPoint::MakeXY(0, 150), DlPoint::MakeXY(400, 600)};
1008
1009 builder.DrawPoints(DlPointMode::kLines, points.size(), points.data(),
1010 DlPaint().setColor(DlColor::kBlue()).setStrokeWidth(10));
1011 builder.Restore();
1012
1013 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1014}
void DrawPoints(DlPointMode mode, uint32_t count, const DlPoint pts[], const DlPaint &paint) override

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipPath(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawPoints(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlPath::MakeCircle(), impeller::TPoint< Scalar >::MakeXY(), flutter::path, points, flutter::DisplayListBuilder::Restore(), and flutter::DisplayListBuilder::Save().

◆ TEST_P() [183/662]

impeller::testing::TEST_P ( AiksTest  ,
DepthValuesForPolygonMode   
)

Definition at line 1016 of file aiks_dl_unittests.cc.

1016 {
1017 // Ensures that the additional draws created by line/polygon mode all
1018 // have the same depth values.
1019 DisplayListBuilder builder;
1020
1021 DlPath path = DlPath::MakeCircle(DlPoint(100, 100), 100);
1022
1023 builder.DrawPath(path, DlPaint()
1024 .setColor(DlColor::kRed())
1025 .setDrawStyle(DlDrawStyle::kStroke)
1026 .setStrokeWidth(5));
1027 builder.Save();
1028 builder.ClipPath(path);
1029
1030 std::vector<DlPoint> points = {
1031 DlPoint::MakeXY(0, -200), DlPoint::MakeXY(400, 200),
1032 DlPoint::MakeXY(0, -100), DlPoint::MakeXY(400, 300),
1033 DlPoint::MakeXY(0, 0), DlPoint::MakeXY(400, 400),
1034 DlPoint::MakeXY(0, 100), DlPoint::MakeXY(400, 500),
1035 DlPoint::MakeXY(0, 150), DlPoint::MakeXY(400, 600)};
1036
1037 builder.DrawPoints(DlPointMode::kPolygon, points.size(), points.data(),
1038 DlPaint().setColor(DlColor::kBlue()).setStrokeWidth(10));
1039 builder.Restore();
1040
1041 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1042}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipPath(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawPoints(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlPath::MakeCircle(), impeller::TPoint< Scalar >::MakeXY(), flutter::path, points, flutter::DisplayListBuilder::Restore(), and flutter::DisplayListBuilder::Save().

◆ TEST_P() [184/662]

impeller::testing::TEST_P ( AiksTest  ,
DestructiveBlendColorFilterFloodsClip   
)

Definition at line 900 of file aiks_dl_blend_unittests.cc.

900 {
901 DisplayListBuilder builder;
902
903 DlPaint paint;
904 paint.setColor(DlColor::kBlue());
905 builder.DrawPaint(paint);
906
907 DlPaint save_paint;
908 save_paint.setColorFilter(
909 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kSrc));
910 builder.SaveLayer(std::nullopt, &save_paint);
911 builder.Restore();
912
913 // Should be solid red as the destructive color filter floods the clip.
914 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
915}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColorFilter::MakeBlend(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), and flutter::DlPaint::setColorFilter().

◆ TEST_P() [185/662]

impeller::testing::TEST_P ( AiksTest  ,
DifferenceClipsMustRenderIdenticallyAcrossBackends   
)

Definition at line 644 of file aiks_dl_text_unittests.cc.

644 {
645 DisplayListBuilder builder;
646
647 DlPaint paint;
648 DlColor clear_color(1.0, 0.5, 0.5, 0.5, DlColorSpace::kSRGB);
649 paint.setColor(clear_color);
650 builder.DrawPaint(paint);
651
652 DlMatrix identity = {
653 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
654 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
655 };
656 builder.Save();
657 builder.Transform(identity);
658
659 DlRect frame = DlRect::MakeLTRB(1.0, 1.0, 1278.0, 763.0);
660 DlColor white(1.0, 1.0, 1.0, 1.0, DlColorSpace::kSRGB);
661 paint.setColor(white);
662 builder.DrawRect(frame, paint);
663
664 builder.Save();
665 builder.ClipRect(frame, DlClipOp::kIntersect);
666
667 DlMatrix rect_xform = {
668 0.8241262, 0.56640625, 0.0, 0.0, -0.56640625, 0.8241262, 0.0, 0.0,
669 0.0, 0.0, 1.0, 0.0, 271.1137, 489.4733, 0.0, 1.0,
670 };
671 builder.Save();
672 builder.Transform(rect_xform);
673
674 DlRect rect = DlRect::MakeLTRB(0.0, 0.0, 100.0, 100.0);
675 DlColor bluish(1.0, 0.184, 0.501, 0.929, DlColorSpace::kSRGB);
676 paint.setColor(bluish);
677 DlRoundRect rrect = DlRoundRect::MakeRectRadius(rect, 18.0);
678 builder.DrawRoundRect(rrect, paint);
679
680 builder.Save();
681 builder.ClipRect(rect, DlClipOp::kIntersect);
682 builder.Restore();
683
684 builder.Restore();
685
686 DlMatrix path_xform = {
687 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
688 0.0, 0.0, 1.0, 0.0, 675.0, 279.5, 0.0, 1.0,
689 };
690 builder.Save();
691 builder.Transform(path_xform);
692
693 DlPathBuilder path_builder;
694 path_builder.MoveTo(DlPoint(87.5, 349.5));
695 path_builder.LineTo(DlPoint(25.0, 29.5));
696 path_builder.LineTo(DlPoint(150.0, 118.0));
697 path_builder.LineTo(DlPoint(25.0, 118.0));
698 path_builder.LineTo(DlPoint(150.0, 29.5));
699 path_builder.Close();
700 DlPath path = path_builder.TakePath();
701
702 DlColor fill_color(1.0, 1.0, 0.0, 0.0, DlColorSpace::kSRGB);
703 DlColor stroke_color(1.0, 0.0, 0.0, 0.0, DlColorSpace::kSRGB);
704 paint.setColor(fill_color);
705 paint.setDrawStyle(DlDrawStyle::kFill);
706 builder.DrawPath(path, paint);
707
708 paint.setColor(stroke_color);
709 paint.setStrokeWidth(2.0);
710 paint.setDrawStyle(DlDrawStyle::kStroke);
711 builder.DrawPath(path, paint);
712
713 builder.Restore();
714 builder.Restore();
715 builder.Restore();
716
717 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
718}
static RoundRect MakeRectRadius(const Rect &rect, Scalar radius)
Definition round_rect.h:27

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlPathBuilder::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectRadius(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), and flutter::DisplayListBuilder::Transform().

◆ TEST_P() [186/662]

impeller::testing::TEST_P ( AiksTest  ,
DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists   
)

Definition at line 875 of file aiks_dl_unittests.cc.

875 {
876 flutter::DisplayListBuilder sub_builder(true);
877 sub_builder.DrawRect(DlRect::MakeXYWH(0, 0, 50, 50),
879 auto display_list = sub_builder.Build();
880
881 AiksContext context(GetContext(), nullptr);
882 RenderTarget render_target =
883 context.GetContentContext().GetRenderTargetCache()->CreateOffscreen(
884 *context.GetContext(), {2400, 1800}, 1);
885
886 DisplayListBuilder builder;
887
888 builder.Scale(2.0, 2.0);
889 builder.Translate(-93.0, 0.0);
890
891 // clang-format off
893 0.8, -0.2, -0.1, -0.0,
894 0.0, 1.0, 0.0, 0.0,
895 1.4, 1.3, 1.0, 0.0,
896 63.2, 65.3, 48.6, 1.1
897 );
898 // clang-format on
899 builder.Translate(35.0, 75.0);
900 builder.DrawDisplayList(display_list, 1.0f);
901
902 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
903}
void TransformFullPerspective(DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) override

References flutter::DisplayListBuilder::Build(), context, flutter::DisplayListBuilder::DrawDisplayList(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Scale(), flutter::DisplayListBuilder::TransformFullPerspective(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [187/662]

impeller::testing::TEST_P ( AiksTest  ,
DisplayListToTextureAllocationFailure   
)

Definition at line 1116 of file aiks_dl_unittests.cc.

1116 {
1117 ScopedValidationDisable disable_validations;
1118 DisplayListBuilder builder;
1119
1120 AiksContext aiks_context(GetContext(), nullptr);
1121 // Use intentionally invalid dimensions that would trigger an allocation
1122 // failure.
1123 auto texture =
1124 DisplayListToTexture(builder.Build(), ISize{0, 0}, aiks_context);
1125
1126 EXPECT_EQ(texture, nullptr);
1127}

References flutter::DisplayListBuilder::Build(), impeller::DisplayListToTexture(), and texture.

◆ TEST_P() [188/662]

impeller::testing::TEST_P ( AiksTest  ,
DisplayListToTextureWithMipGeneration   
)

Definition at line 1129 of file aiks_dl_unittests.cc.

1129 {
1130 DisplayListBuilder builder;
1131
1132 std::shared_ptr<DlImageFilter> filter =
1133 DlImageFilter::MakeBlur(8, 8, DlTileMode::kClamp);
1134 builder.SaveLayer(std::nullopt, nullptr, filter.get());
1135 builder.Restore();
1136
1137 AiksContext aiks_context(GetContext(), nullptr);
1138 // Use intentionally invalid dimensions that would trigger an allocation
1139 // failure.
1140 auto texture =
1141 DisplayListToTexture(builder.Build(), ISize{10, 10}, aiks_context,
1142 /*reset_host_buffer=*/true, /*generate_mips=*/true);
1143
1144 EXPECT_FALSE(texture->NeedsMipmapGeneration());
1145}

References flutter::DisplayListBuilder::Build(), impeller::DisplayListToTexture(), flutter::DlImageFilter::MakeBlur(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and texture.

◆ TEST_P() [189/662]

impeller::testing::TEST_P ( AiksTest  ,
DlAtlasGeometryBlend   
)

Definition at line 208 of file aiks_dl_atlas_unittests.cc.

208 {
209 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
210
211 std::vector<DlColor> colors;
212 colors.reserve(texture_coordinates.size());
213 for (auto i = 0u; i < texture_coordinates.size(); i++) {
214 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
215 }
216 DlAtlasGeometry geom(atlas->GetImpellerTexture(GetContext()),
217 transforms.data(), texture_coordinates.data(),
218 colors.data(), transforms.size(), BlendMode::kSrcOver,
219 {}, std::nullopt);
220
221 EXPECT_TRUE(geom.ShouldUseBlend());
222 EXPECT_FALSE(geom.ShouldSkip());
223
224 ContentContext context(GetContext(), nullptr);
225 auto vertex_buffer =
226 geom.CreateBlendVertexBuffer(context.GetTransientsDataBuffer());
227
228 EXPECT_EQ(vertex_buffer.index_type, IndexType::kNone);
229 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
230}
A wrapper around data provided by a drawAtlas call.

References flutter::DlColor::ARGB(), context, impeller::DlAtlasGeometry::CreateBlendVertexBuffer(), i, impeller::kNone, impeller::kSrcOver, impeller::DlAtlasGeometry::ShouldSkip(), and impeller::DlAtlasGeometry::ShouldUseBlend().

◆ TEST_P() [190/662]

impeller::testing::TEST_P ( AiksTest  ,
DlAtlasGeometryColorButNoBlend   
)

Definition at line 232 of file aiks_dl_atlas_unittests.cc.

232 {
233 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
234
235 std::vector<DlColor> colors;
236 colors.reserve(texture_coordinates.size());
237 for (auto i = 0u; i < texture_coordinates.size(); i++) {
238 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
239 }
240 DlAtlasGeometry geom(atlas->GetImpellerTexture(GetContext()),
241 transforms.data(), texture_coordinates.data(),
242 colors.data(), transforms.size(), BlendMode::kSrc, {},
243 std::nullopt);
244
245 // Src blend mode means that colors would be ignored, even if provided.
246 EXPECT_FALSE(geom.ShouldUseBlend());
247 EXPECT_FALSE(geom.ShouldSkip());
248}

References flutter::DlColor::ARGB(), i, impeller::kSrc, impeller::DlAtlasGeometry::ShouldSkip(), and impeller::DlAtlasGeometry::ShouldUseBlend().

◆ TEST_P() [191/662]

impeller::testing::TEST_P ( AiksTest  ,
DlAtlasGeometryNoBlendRenamed   
)

Definition at line 189 of file aiks_dl_atlas_unittests.cc.

189 {
190 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
191
192 DlAtlasGeometry geom(atlas->GetImpellerTexture(GetContext()),
193 transforms.data(), texture_coordinates.data(), nullptr,
194 transforms.size(), BlendMode::kSrcOver, {},
195 std::nullopt);
196
197 EXPECT_FALSE(geom.ShouldUseBlend());
198 EXPECT_FALSE(geom.ShouldSkip());
199
200 ContentContext context(GetContext(), nullptr);
201 auto vertex_buffer =
202 geom.CreateSimpleVertexBuffer(context.GetTransientsDataBuffer());
203
204 EXPECT_EQ(vertex_buffer.index_type, IndexType::kNone);
205 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
206}

References context, impeller::DlAtlasGeometry::CreateSimpleVertexBuffer(), impeller::kNone, impeller::kSrcOver, impeller::DlAtlasGeometry::ShouldSkip(), and impeller::DlAtlasGeometry::ShouldUseBlend().

◆ TEST_P() [192/662]

impeller::testing::TEST_P ( AiksTest  ,
DlAtlasGeometrySkip   
)

Definition at line 250 of file aiks_dl_atlas_unittests.cc.

250 {
251 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
252
253 std::vector<DlColor> colors;
254 colors.reserve(texture_coordinates.size());
255 for (auto i = 0u; i < texture_coordinates.size(); i++) {
256 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
257 }
258 DlAtlasGeometry geom(atlas->GetImpellerTexture(GetContext()),
259 transforms.data(), texture_coordinates.data(),
260 colors.data(), transforms.size(), BlendMode::kClear, {},
261 std::nullopt);
262 EXPECT_TRUE(geom.ShouldSkip());
263}

References flutter::DlColor::ARGB(), i, impeller::kClear, and impeller::DlAtlasGeometry::ShouldSkip().

◆ TEST_P() [193/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawAdvancedBlendPartlyOffscreen   
)

Definition at line 142 of file aiks_dl_blend_unittests.cc.

142 {
143 DisplayListBuilder builder;
144
145 DlPaint draw_paint;
146 draw_paint.setColor(DlColor::kBlue());
147 builder.DrawPaint(draw_paint);
148 builder.Scale(2, 2);
149 builder.ClipRect(DlRect::MakeLTRB(0, 0, 200, 200));
150
151 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
152 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0)};
153 std::vector<Scalar> stops = {0.0, 1.0};
154
155 DlPaint paint;
156 DlMatrix matrix = DlMatrix::MakeScale({0.3, 0.3, 1.0});
157 paint.setColorSource(DlColorSource::MakeLinear(
158 /*start_point=*/{0, 0}, //
159 /*end_point=*/{100, 100}, //
160 /*stop_count=*/colors.size(), //
161 /*colors=*/colors.data(), //
162 /*stops=*/stops.data(), //
163 /*tile_mode=*/DlTileMode::kRepeat, //
164 /*matrix=*/&matrix //
165 ));
166 paint.setBlendMode(DlBlendMode::kLighten);
167
168 builder.DrawCircle(DlPoint(100, 100), 100, paint);
169 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
170}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kBlue(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeScale(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), and flutter::DlPaint::setColorSource().

◆ TEST_P() [194/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawAtlasAdvancedAndTransform   
)

Definition at line 137 of file aiks_dl_atlas_unittests.cc.

137 {
138 DisplayListBuilder builder;
139 // Draws the image as four squares stiched together.
140 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
141
142 builder.Scale(0.25, 0.25);
143 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
144 /*colors=*/nullptr, /*count=*/4, DlBlendMode::kModulate,
145 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
146
147 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
148}
void DrawAtlas(const sk_sp< DlImage > &atlas, const DlRSTransform xform[], const DlRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, const DlRect *cullRect, const DlPaint *paint=nullptr) override

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawAtlas(), and flutter::DisplayListBuilder::Scale().

◆ TEST_P() [195/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawAtlasNoColor   
)

Definition at line 60 of file aiks_dl_atlas_unittests.cc.

60 {
61 DisplayListBuilder builder;
62 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
63
64 builder.Scale(GetContentScale().x, GetContentScale().y);
65 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
66 /*colors=*/nullptr, /*count=*/4, DlBlendMode::kSrcOver,
67 DlImageSampling::kNearestNeighbor, nullptr);
68
69 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
70}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawAtlas(), flutter::DisplayListBuilder::Scale(), x, and y.

◆ TEST_P() [196/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawAtlasNoColorFullSize   
)

Definition at line 120 of file aiks_dl_atlas_unittests.cc.

120 {
121 auto atlas = DlImageImpeller::Make(CreateTextureForFixture("bay_bridge.jpg"));
122 auto size = atlas->GetImpellerTexture(GetContext())->GetSize();
123 std::vector<DlRect> texture_coordinates = {
124 DlRect::MakeLTRB(0, 0, size.width, size.height)};
125 std::vector<RSTransform> transforms = {MakeTranslation(0, 0)};
126
127 DisplayListBuilder builder;
128 builder.Scale(GetContentScale().x, GetContentScale().y);
129 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
130 /*colors=*/nullptr, /*count=*/1, DlBlendMode::kSrcOver,
131 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
132
133 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
134}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawAtlas(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DisplayListBuilder::Scale(), flutter::size, x, and y.

◆ TEST_P() [197/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawAtlasPlusWideGamut   
)

Definition at line 166 of file aiks_dl_atlas_unittests.cc.

166 {
167 // Must be called before any methods that use the context to ensure that
168 // this test is always run with wide gamut support.
169 if (!EnsureContextSupportsWideGamut()) {
170 GTEST_SKIP() << "This backend doesn't yet support wide gamut.";
171 }
172
173 DisplayListBuilder builder;
174 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
175 PixelFormat::kB10G10R10A10XR);
176
177 // Draws the image as four squares stiched together.
178 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
179 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
180 DlColor::kBlue(), DlColor::kYellow()};
181
182 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
183 colors.data(), /*count=*/4, DlBlendMode::kPlus,
184 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
185
186 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
187}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawAtlas(), impeller::kB10G10R10A10XR, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), and flutter::DlColor::kYellow().

◆ TEST_P() [198/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawAtlasWithColorAdvanced   
)

Definition at line 72 of file aiks_dl_atlas_unittests.cc.

72 {
73 DisplayListBuilder builder;
74 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
75
76 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
77 DlColor::kBlue(), DlColor::kYellow()};
78
79 builder.Scale(GetContentScale().x, GetContentScale().y);
80 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
81 colors.data(), /*count=*/4, DlBlendMode::kModulate,
82 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
83
84 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
85}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawAtlas(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), flutter::DisplayListBuilder::Scale(), x, and y.

◆ TEST_P() [199/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawAtlasWithColorAdvancedAndTransform   
)

Definition at line 151 of file aiks_dl_atlas_unittests.cc.

151 {
152 DisplayListBuilder builder;
153 // Draws the image as four squares stiched together.
154 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
155 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
156 DlColor::kBlue(), DlColor::kYellow()};
157
158 builder.Scale(0.25, 0.25);
159 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
160 colors.data(), /*count=*/4, DlBlendMode::kModulate,
161 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
162
163 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
164}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawAtlas(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), and flutter::DisplayListBuilder::Scale().

◆ TEST_P() [200/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawAtlasWithColorBurn   
)

Definition at line 330 of file aiks_dl_atlas_unittests.cc.

330 {
331 DisplayListBuilder builder;
332 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
333
334 std::vector<DlColor> colors = {DlColor::kDarkGrey(), DlColor::kBlack(),
335 DlColor::kLightGrey(), DlColor::kWhite()};
336
337 builder.Scale(GetContentScale().x, GetContentScale().y);
338 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
339 colors.data(), /*count=*/4, DlBlendMode::kColorBurn,
340 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
341
342 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
343}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawAtlas(), flutter::DlColor::kBlack(), flutter::DlColor::kDarkGrey(), flutter::DlColor::kLightGrey(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), x, and y.

◆ TEST_P() [201/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawAtlasWithColorSimple   
)

Definition at line 87 of file aiks_dl_atlas_unittests.cc.

87 {
88 DisplayListBuilder builder;
89 // Draws the image as four squares stiched together.
90 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
91
92 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
93 DlColor::kBlue(), DlColor::kYellow()};
94
95 builder.Scale(GetContentScale().x, GetContentScale().y);
96 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
97 colors.data(), /*count=*/4, DlBlendMode::kSrcATop,
98 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
99
100 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
101}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawAtlas(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), flutter::DisplayListBuilder::Scale(), x, and y.

◆ TEST_P() [202/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawAtlasWithOpacity   
)

Definition at line 103 of file aiks_dl_atlas_unittests.cc.

103 {
104 DisplayListBuilder builder;
105 // Draws the image as four squares stiched together slightly
106 // opaque
107 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
108
109 DlPaint paint;
110 paint.setAlpha(128);
111 builder.Scale(GetContentScale().x, GetContentScale().y);
112 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
113 /*colors=*/nullptr, 4, DlBlendMode::kSrcOver,
114 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr,
115 &paint);
116
117 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
118}
DlPaint & setAlpha(uint8_t alpha)
Definition dl_paint.h:76

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawAtlas(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setAlpha(), x, and y.

◆ TEST_P() [203/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawImageRectSrcOutsideBounds   
)

Definition at line 305 of file aiks_dl_basic_unittests.cc.

305 {
306 DisplayListBuilder builder;
307 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
308
309 // Use a source rect that is partially outside the bounds of the image.
310 auto source_rect = DlRect::MakeXYWH(
311 image->GetSize().width * 0.25f, image->GetSize().height * 0.4f,
312 image->GetSize().width, image->GetSize().height);
313
314 auto dest_rect = DlRect::MakeXYWH(100, 100, 600, 600);
315
316 DlPaint paint;
317 paint.setColor(DlColor::kMidGrey());
318 builder.DrawRect(dest_rect, paint);
319
320 builder.DrawImageRect(image, source_rect, dest_rect,
321 DlImageSampling::kNearestNeighbor);
322 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
323}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageRect(), flutter::DisplayListBuilder::DrawRect(), image, flutter::DlColor::kMidGrey(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeXYWH(), and flutter::DlPaint::setColor().

◆ TEST_P() [204/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawImageRectWithBlendColorFilter   
)

Definition at line 265 of file aiks_dl_atlas_unittests.cc.

265 {
266 sk_sp<DlImageImpeller> texture =
267 DlImageImpeller::Make(CreateTextureForFixture("bay_bridge.jpg"));
268
269 DisplayListBuilder builder;
270 DlPaint paint = DlPaint().setColorFilter(DlColorFilter::MakeBlend(
271 DlColor::kRed().withAlphaF(0.4), DlBlendMode::kSrcOver));
272
273 DlMatrix filter_matrix = DlMatrix();
274 auto filter = flutter::DlMatrixImageFilter(filter_matrix,
276 DlPaint paint_with_filter = paint;
277 paint_with_filter.setImageFilter(&filter);
278
279 // Compare porter-duff blend modes.
280 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
281 // Uses image filter to disable atlas conversion.
282 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
283 DlRect::MakeLTRB(0, 0, 500, 500), {},
284 &paint_with_filter);
285
286 // Uses atlas conversion.
287 builder.Translate(600, 0);
288 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
289 DlRect::MakeLTRB(0, 0, 500, 500), {}, &paint);
290
291 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
292}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageRect(), flutter::DisplayListBuilder::DrawPaint(), flutter::kLinear, flutter::DlColor::kRed(), flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeBlend(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeSize(), flutter::DlPaint::setColorFilter(), flutter::DlPaint::setImageFilter(), texture, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [205/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawImageRectWithMatrixColorFilter   
)

Definition at line 294 of file aiks_dl_atlas_unittests.cc.

294 {
295 sk_sp<DlImageImpeller> texture =
296 DlImageImpeller::Make(CreateTextureForFixture("bay_bridge.jpg"));
297
298 DisplayListBuilder builder;
299 static const constexpr ColorMatrix kColorInversion = {
300 .array = {
301 -1.0, 0, 0, 1.0, 0, //
302 0, -1.0, 0, 1.0, 0, //
303 0, 0, -1.0, 1.0, 0, //
304 1.0, 1.0, 1.0, 1.0, 0 //
305 }};
306 DlPaint paint = DlPaint().setColorFilter(
307 DlColorFilter::MakeMatrix(kColorInversion.array));
308
309 DlMatrix filter_matrix = DlMatrix();
310 auto filter = flutter::DlMatrixImageFilter(filter_matrix,
312 DlPaint paint_with_filter = paint;
313 paint_with_filter.setImageFilter(&filter);
314
315 // Compare inverting color matrix filter.
316 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
317 // Uses image filter to disable atlas conversion.
318 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
319 DlRect::MakeLTRB(0, 0, 500, 500), {},
320 &paint_with_filter);
321
322 // Uses atlas conversion.
323 builder.Translate(600, 0);
324 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
325 DlRect::MakeLTRB(0, 0, 500, 500), {}, &paint);
326
327 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
328}
Scalar array[20]
Definition color.h:118

References impeller::ColorMatrix::array, flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageRect(), flutter::DisplayListBuilder::DrawPaint(), impeller::kColorInversion, flutter::kLinear, flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlColorFilter::MakeMatrix(), impeller::TRect< Scalar >::MakeSize(), flutter::DlPaint::setColorFilter(), flutter::DlPaint::setImageFilter(), texture, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [206/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawLinesRenderCorrectly   
)

Definition at line 600 of file aiks_dl_path_unittests.cc.

600 {
601 DisplayListBuilder builder;
602 builder.Scale(GetContentScale().x, GetContentScale().y);
603
604 DlPaint paint;
605 paint.setColor(DlColor::kBlue());
606 paint.setStrokeWidth(10);
607
608 auto draw = [&builder](DlPaint& paint) {
609 for (auto cap :
610 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
611 paint.setStrokeCap(cap);
612 DlPoint origin = {100, 100};
613 builder.DrawLine(DlPoint(150, 100), DlPoint(250, 100), paint);
614 for (int d = 15; d < 90; d += 15) {
615 Matrix m = Matrix::MakeRotationZ(Degrees(d));
616 Point origin = {100, 100};
617 Point p0 = {50, 0};
618 Point p1 = {150, 0};
619 auto a = origin + m * p0;
620 auto b = origin + m * p1;
621
622 builder.DrawLine(a, b, paint);
623 }
624 builder.DrawLine(DlPoint(100, 150), DlPoint(100, 250), paint);
625 builder.DrawCircle(origin, 35, paint);
626
627 builder.DrawLine(DlPoint(250, 250), DlPoint(250, 250), paint);
628
629 builder.Translate(250, 0);
630 }
631 builder.Translate(-750, 250);
632 };
633
634 std::vector<DlColor> colors = {
635 DlColor::ARGB(1, 0x1f / 255.0, 0.0, 0x5c / 255.0),
636 DlColor::ARGB(1, 0x5b / 255.0, 0.0, 0x60 / 255.0),
637 DlColor::ARGB(1, 0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0),
638 DlColor::ARGB(1, 0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0),
639 DlColor::ARGB(1, 0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0),
640 DlColor::ARGB(1, 0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0),
641 DlColor::ARGB(1, 0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0)};
642 std::vector<Scalar> stops = {
643 0.0,
644 (1.0 / 6.0) * 1,
645 (1.0 / 6.0) * 2,
646 (1.0 / 6.0) * 3,
647 (1.0 / 6.0) * 4,
648 (1.0 / 6.0) * 5,
649 1.0,
650 };
651
652 auto texture = DlImageImpeller::Make(
653 CreateTextureForFixture("airplane.jpg",
654 /*enable_mipmapping=*/true));
655
656 draw(paint);
657
658 paint.setColorSource(DlColorSource::MakeRadial({100, 100}, 200, stops.size(),
659 colors.data(), stops.data(),
660 DlTileMode::kMirror));
661 draw(paint);
662
663 DlMatrix matrix = DlMatrix::MakeTranslation({-150, 75});
664 paint.setColorSource(DlColorSource::MakeImage(
665 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
666 DlImageSampling::kMipmapLinear, &matrix));
667 draw(paint);
668
669 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
670}
impeller::Matrix DlMatrix

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), d, flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawLine(), flutter::DlColor::kBlue(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), flutter::DlColorSource::MakeRadial(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeTranslation(), p1, flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), texture, flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [207/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawLinesWithDrawLine   
)

Definition at line 355 of file aiks_dl_path_unittests.cc.

355 {
356 DrawLinesTest(this, [](DisplayListBuilder& builder, const DlPaint& paint,
357 Point p0, Point p1, Scalar width) {
358 DlPaint stroke_paint = paint;
359 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
360 stroke_paint.setStrokeWidth(width);
361 builder.DrawLine(p0, p1, stroke_paint);
362 });
363}

References flutter::DisplayListBuilder::DrawLine(), p1, flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), and width.

◆ TEST_P() [208/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawLinesWithFilledRects   
)

Definition at line 365 of file aiks_dl_path_unittests.cc.

365 {
366 DrawLinesTest(this, [](DisplayListBuilder& builder, const DlPaint& paint,
367 Point p0, Point p1, Scalar width) {
368 DlPaint fill_paint = paint;
369 fill_paint.setDrawStyle(DlDrawStyle::kFill);
370 Scalar length = p0.GetDistance(p1);
371 Point center = {(p0.x + p1.x) * 0.5f, (p0.y + p1.y) * 0.5f};
372 builder.DrawRect(
373 DlRect::MakeEllipseBounds(center, Size(length, width) * 0.5f),
374 fill_paint);
375 });
376}

References flutter::DisplayListBuilder::DrawRect(), length, impeller::TRect< Scalar >::MakeEllipseBounds(), p1, flutter::DlPaint::setDrawStyle(), width, flutter::Point::x(), and flutter::Point::y().

◆ TEST_P() [209/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawLinesWithFilledRoundRects   
)

Definition at line 378 of file aiks_dl_path_unittests.cc.

378 {
379 DrawLinesTest(this, [](DisplayListBuilder& builder, const DlPaint& paint,
380 Point p0, Point p1, Scalar width) {
381 DlPaint fill_paint = paint;
382 fill_paint.setDrawStyle(DlDrawStyle::kFill);
383 Scalar length = p0.GetDistance(p1);
384 Point center = {(p0.x + p1.x) * 0.5f, (p0.y + p1.y) * 0.5f};
385 builder.DrawRoundRect(
386 DlRoundRect::MakeRectRadius(
387 DlRect::MakeEllipseBounds(center, Size(length, width) * 0.5f),
388 width * 0.5f),
389 fill_paint);
390 });
391}

References flutter::DisplayListBuilder::DrawRoundRect(), length, impeller::TRect< Scalar >::MakeEllipseBounds(), impeller::RoundRect::MakeRectRadius(), p1, flutter::DlPaint::setDrawStyle(), width, flutter::Point::x(), and flutter::Point::y().

◆ TEST_P() [210/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawLinesWithPath   
)

Definition at line 342 of file aiks_dl_path_unittests.cc.

342 {
343 DrawLinesTest(this, [](DisplayListBuilder& builder, const DlPaint& paint,
344 Point p0, Point p1, Scalar width) {
345 DlPaint stroke_paint = paint;
346 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
347 stroke_paint.setStrokeWidth(width);
348 DlPathBuilder path_builder;
349 path_builder.MoveTo(p0);
350 path_builder.LineTo(p1);
351 builder.DrawPath(path_builder.TakePath(), stroke_paint);
352 });
353}

References flutter::DisplayListBuilder::DrawPath(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), p1, flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), and width.

◆ TEST_P() [211/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawOpacityPeephole   
)

Definition at line 18 of file aiks_dl_opacity_unittests.cc.

18 {
19 DisplayListBuilder builder;
20
21 DlPaint green;
22 green.setColor(DlColor::kGreen().modulateOpacity(0.5));
23
24 DlPaint alpha;
25 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
26
27 builder.SaveLayer(std::nullopt, &alpha);
28 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), green);
29 builder.Restore();
30
31 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
32}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [212/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawPaintTransformsBounds   
)

Definition at line 86 of file aiks_dl_runtime_effect_unittests.cc.

86 {
87 struct FragUniforms {
88 Size size;
89 } frag_uniforms = {.size = Size::MakeWH(400, 400)};
90 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
91 uniform_data->resize(sizeof(FragUniforms));
92 memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
93
94 DlPaint paint;
95 auto effect = MakeRuntimeEffect(this, "gradient.frag.iplr", uniform_data);
96 ABSL_ASSERT_OK(effect);
97 paint.setColorSource(effect.value());
98
99 DisplayListBuilder builder;
100 builder.Save();
101 builder.Scale(GetContentScale().x, GetContentScale().y);
102 builder.DrawPaint(paint);
103 builder.Restore();
104
105 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
106}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), impeller::TSize< Scalar >::MakeWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColorSource(), flutter::size, x, and y.

◆ TEST_P() [213/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawPaintWithAdvancedBlendOverFilter   
)

Definition at line 125 of file aiks_dl_blend_unittests.cc.

125 {
126 DlPaint paint;
127 paint.setColor(DlColor::kBlack());
128 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 60));
129
130 DisplayListBuilder builder;
131 paint.setColor(DlColor::kWhite());
132 builder.DrawPaint(paint);
133 paint.setColor(DlColor::kBlack());
134 builder.DrawCircle(DlPoint(300, 300), 200, paint);
135 paint.setColor(DlColor::kGreen());
136 paint.setBlendMode(DlBlendMode::kScreen);
137 builder.DrawPaint(paint);
138
139 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
140}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kBlack(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), flutter::DlBlurMaskFilter::Make(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), and flutter::DlPaint::setMaskFilter().

◆ TEST_P() [214/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawRectStrokesRenderCorrectly   
)

Definition at line 672 of file aiks_dl_path_unittests.cc.

672 {
673 DisplayListBuilder builder;
674 DlPaint paint;
675 paint.setColor(DlColor::kRed());
676 paint.setDrawStyle(DlDrawStyle::kStroke);
677 paint.setStrokeWidth(10);
678
679 builder.Translate(100, 100);
680 builder.DrawPath(DlPath::MakeRect(DlRect::MakeSize(DlSize(100, 100))), paint);
681
682 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
683}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPath::MakeRect(), impeller::TRect< Scalar >::MakeSize(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [215/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawRectStrokesWithBevelJoinRenderCorrectly   
)

Definition at line 685 of file aiks_dl_path_unittests.cc.

685 {
686 DisplayListBuilder builder;
687 DlPaint paint;
688 paint.setColor(DlColor::kRed());
689 paint.setDrawStyle(DlDrawStyle::kStroke);
690 paint.setStrokeWidth(10);
691 paint.setStrokeJoin(DlStrokeJoin::kBevel);
692
693 builder.Translate(100, 100);
694 builder.DrawPath(DlPath::MakeRect(DlRect::MakeSize(DlSize(100, 100))), paint);
695
696 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
697}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPath::MakeRect(), impeller::TRect< Scalar >::MakeSize(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [216/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawScaledTextWithPerspectiveNoSaveLayer   
)

Definition at line 520 of file aiks_dl_text_unittests.cc.

520 {
521 DisplayListBuilder builder;
522
523 Matrix matrix = Matrix(1.0, 0.0, 0.0, 0.0, //
524 0.0, 1.0, 0.0, 0.0, //
525 0.0, 0.0, 1.0, 0.01, //
526 0.0, 0.0, 0.0, 1.0) * //
528
529 builder.Transform(matrix);
530
531 ASSERT_TRUE(RenderTextInCanvasSkia(GetContext(), builder, "Hello world",
532 "Roboto-Regular.ttf"));
533 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
534}
static Matrix MakeRotationY(Radians r)
Definition matrix.h:208

References flutter::DisplayListBuilder::Build(), impeller::Matrix::MakeRotationY(), RenderTextInCanvasSkia(), and flutter::DisplayListBuilder::Transform().

◆ TEST_P() [217/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawScaledTextWithPerspectiveSaveLayer   
)

Definition at line 536 of file aiks_dl_text_unittests.cc.

536 {
537 DisplayListBuilder builder;
538
539 Matrix matrix = Matrix(1.0, 0.0, 0.0, 0.0, //
540 0.0, 1.0, 0.0, 0.0, //
541 0.0, 0.0, 1.0, 0.01, //
542 0.0, 0.0, 0.0, 1.0) * //
544
545 DlPaint save_paint;
546 DlRect window_bounds =
547 DlRect::MakeXYWH(0, 0, GetWindowSize().width, GetWindowSize().height);
548 // Note: bounds were not needed by the AIKS version, which may indicate a bug.
549 builder.SaveLayer(window_bounds, &save_paint);
550 builder.Transform(matrix);
551
552 ASSERT_TRUE(RenderTextInCanvasSkia(GetContext(), builder, "Hello world",
553 "Roboto-Regular.ttf"));
554
555 builder.Restore();
556 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
557}

References flutter::DisplayListBuilder::Build(), height, impeller::Matrix::MakeRotationY(), impeller::TRect< Scalar >::MakeXYWH(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Transform(), and width.

◆ TEST_P() [218/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeClockwiseCircle   
)

Definition at line 429 of file aiks_dl_shadow_unittests.cc.

429 {
430 DisplayListBuilder builder;
431 builder.Clear(DlColor::kWhite());
432 builder.Scale(GetContentScale().x, GetContentScale().y);
433 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
434 Scalar elevation = 30.0f;
435
436 // A weight of sqrt(2) is how you really perform conic circular sections,
437 // but by tweaking it slightly the path will not be recognized as an oval
438 // and accelerated.
439 constexpr Scalar kWeight = kSqrt2Over2 - 0.0005f;
440
441 DlPathBuilder path_builder;
442 path_builder.MoveTo(DlPoint(200, 100));
443 path_builder.ConicCurveTo(DlPoint(300, 100), DlPoint(300, 200), kWeight);
444 path_builder.ConicCurveTo(DlPoint(300, 300), DlPoint(200, 300), kWeight);
445 path_builder.ConicCurveTo(DlPoint(100, 300), DlPoint(100, 200), kWeight);
446 path_builder.ConicCurveTo(DlPoint(100, 100), DlPoint(200, 100), kWeight);
447 path_builder.Close();
448 DlPath path = path_builder.TakePath();
449
450 // Path must be convex, but unrecognizable as a simple shape.
451 ASSERT_TRUE(path.IsConvex());
452 ASSERT_FALSE(path.IsRect());
453 ASSERT_FALSE(path.IsOval());
454 ASSERT_FALSE(path.IsRoundRect());
455
456 const DlPath simple_path = DlPath::MakeCircle(DlPoint(200, 200), 100);
457 DrawShadowAndCompareMeshes(builder, path, elevation, dpr, &simple_path);
458
459 auto dl = builder.Build();
460 ASSERT_TRUE(OpenPlaygroundHere(dl));
461}
constexpr float kSqrt2Over2
Definition constants.h:51

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), impeller::kSqrt2Over2, flutter::DlColor::kWhite(), flutter::DlPath::MakeCircle(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [219/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeClockwiseConic   
)

Definition at line 715 of file aiks_dl_shadow_unittests.cc.

715 {
716 DisplayListBuilder builder;
717 builder.Clear(DlColor::kWhite());
718 builder.Scale(GetContentScale().x, GetContentScale().y);
719 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
720 Scalar elevation = 30.0f;
721
722 DlPathBuilder path_builder;
723 path_builder.MoveTo(DlPoint(200, 100));
724 path_builder.ConicCurveTo(DlPoint(300, 100), DlPoint(300, 200), 0.4f);
725 path_builder.ConicCurveTo(DlPoint(300, 300), DlPoint(200, 300), 0.4f);
726 path_builder.ConicCurveTo(DlPoint(100, 300), DlPoint(100, 200), 0.4f);
727 path_builder.ConicCurveTo(DlPoint(100, 100), DlPoint(200, 100), 0.4f);
728 path_builder.Close();
729 DlPath path = path_builder.TakePath();
730
731 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
732
733 auto dl = builder.Build();
734 ASSERT_TRUE(OpenPlaygroundHere(dl));
735}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [220/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeClockwiseCubic   
)

Definition at line 759 of file aiks_dl_shadow_unittests.cc.

759 {
760 DisplayListBuilder builder;
761 builder.Clear(DlColor::kWhite());
762 builder.Scale(GetContentScale().x, GetContentScale().y);
763 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
764 Scalar elevation = 30.0f;
765
766 DlPathBuilder path_builder;
767 path_builder.MoveTo(DlPoint(200, 100));
768 path_builder.CubicCurveTo(DlPoint(280, 100), DlPoint(300, 120),
769 DlPoint(300, 200));
770 path_builder.CubicCurveTo(DlPoint(300, 280), DlPoint(280, 300),
771 DlPoint(200, 300));
772 path_builder.CubicCurveTo(DlPoint(120, 300), DlPoint(100, 280),
773 DlPoint(100, 200));
774 path_builder.CubicCurveTo(DlPoint(100, 120), DlPoint(120, 100),
775 DlPoint(200, 100));
776 path_builder.Close();
777 DlPath path = path_builder.TakePath();
778
779 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
780
781 auto dl = builder.Build();
782 ASSERT_TRUE(OpenPlaygroundHere(dl));
783}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::CubicCurveTo(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [221/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeClockwiseMultiRadiiRoundRect   
)

Definition at line 615 of file aiks_dl_shadow_unittests.cc.

615 {
616 DisplayListBuilder builder;
617 builder.Clear(DlColor::kWhite());
618 builder.Scale(GetContentScale().x, GetContentScale().y);
619 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
620 Scalar elevation = 30.0f;
621
623 .top_left = {80, 60},
624 .top_right = {20, 25},
625 .bottom_left = {60, 80},
626 .bottom_right = {25, 20},
627 };
628 DlPath path = MakeAlmostRoundRectPath(DlRect::MakeLTRB(100, 100, 300, 300),
629 radii, true);
630
631 // Path must be convex, but unrecognizable as a simple shape.
632 ASSERT_TRUE(path.IsConvex());
633 ASSERT_FALSE(path.IsRect());
634 ASSERT_FALSE(path.IsOval());
635 ASSERT_FALSE(path.IsRoundRect());
636
637 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
638
639 auto dl = builder.Build();
640 ASSERT_TRUE(OpenPlaygroundHere(dl));
641}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlColor::kWhite(), impeller::TRect< Scalar >::MakeLTRB(), flutter::path, flutter::DisplayListBuilder::Scale(), impeller::RoundingRadii::top_left, x, and y.

◆ TEST_P() [222/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeClockwiseOctagon   
)

Definition at line 811 of file aiks_dl_shadow_unittests.cc.

811 {
812 DisplayListBuilder builder;
813 builder.Clear(DlColor::kWhite());
814 builder.Scale(GetContentScale().x, GetContentScale().y);
815 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
816 Scalar elevation = 30.0f;
817
818 DlPathBuilder path_builder;
819 path_builder.MoveTo(DlPoint(100, 125));
820 path_builder.LineTo(DlPoint(125, 100));
821 path_builder.LineTo(DlPoint(275, 100));
822 path_builder.LineTo(DlPoint(300, 125));
823 path_builder.LineTo(DlPoint(300, 275));
824 path_builder.LineTo(DlPoint(275, 300));
825 path_builder.LineTo(DlPoint(125, 300));
826 path_builder.LineTo(DlPoint(100, 275));
827 path_builder.Close();
828 DlPath path = path_builder.TakePath();
829
830 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
831
832 auto dl = builder.Build();
833 ASSERT_TRUE(OpenPlaygroundHere(dl));
834}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [223/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeClockwiseOval   
)

Definition at line 497 of file aiks_dl_shadow_unittests.cc.

497 {
498 DisplayListBuilder builder;
499 builder.Clear(DlColor::kWhite());
500 builder.Scale(GetContentScale().x, GetContentScale().y);
501 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
502 Scalar elevation = 30.0f;
503
504 // A weight of sqrt(2) is how you really perform conic circular sections,
505 // but by tweaking it slightly the path will not be recognized as an oval
506 // and accelerated.
507 constexpr Scalar kWeight = kSqrt2Over2 - 0.0005f;
508
509 DlPathBuilder path_builder;
510 path_builder.MoveTo(DlPoint(200, 120));
511 path_builder.ConicCurveTo(DlPoint(300, 120), DlPoint(300, 200), kWeight);
512 path_builder.ConicCurveTo(DlPoint(300, 280), DlPoint(200, 280), kWeight);
513 path_builder.ConicCurveTo(DlPoint(100, 280), DlPoint(100, 200), kWeight);
514 path_builder.ConicCurveTo(DlPoint(100, 120), DlPoint(200, 120), kWeight);
515 path_builder.Close();
516 DlPath path = path_builder.TakePath();
517
518 // Path must be convex, but unrecognizable as a simple shape.
519 ASSERT_TRUE(path.IsConvex());
520 ASSERT_FALSE(path.IsRect());
521 ASSERT_FALSE(path.IsOval());
522 ASSERT_FALSE(path.IsRoundRect());
523
524 const DlPath simple_path = DlPath::MakeOvalLTRB(100, 120, 300, 280);
525 DrawShadowAndCompareMeshes(builder, path, elevation, dpr, &simple_path);
526
527 auto dl = builder.Build();
528 ASSERT_TRUE(OpenPlaygroundHere(dl));
529}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), impeller::kSqrt2Over2, flutter::DlColor::kWhite(), flutter::DlPath::MakeOvalLTRB(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [224/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeClockwiseQuadratic   
)

Definition at line 671 of file aiks_dl_shadow_unittests.cc.

671 {
672 DisplayListBuilder builder;
673 builder.Clear(DlColor::kWhite());
674 builder.Scale(GetContentScale().x, GetContentScale().y);
675 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
676 Scalar elevation = 30.0f;
677
678 DlPathBuilder path_builder;
679 path_builder.MoveTo(DlPoint(200, 100));
680 path_builder.QuadraticCurveTo(DlPoint(300, 100), DlPoint(300, 200));
681 path_builder.QuadraticCurveTo(DlPoint(300, 300), DlPoint(200, 300));
682 path_builder.QuadraticCurveTo(DlPoint(100, 300), DlPoint(100, 200));
683 path_builder.QuadraticCurveTo(DlPoint(100, 100), DlPoint(200, 100));
684 path_builder.Close();
685 DlPath path = path_builder.TakePath();
686
687 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
688
689 auto dl = builder.Build();
690 ASSERT_TRUE(OpenPlaygroundHere(dl));
691}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DlPathBuilder::QuadraticCurveTo(), flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [225/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeClockwiseRect   
)

Definition at line 369 of file aiks_dl_shadow_unittests.cc.

369 {
370 DisplayListBuilder builder;
371 builder.Clear(DlColor::kWhite());
372 builder.Scale(GetContentScale().x, GetContentScale().y);
373 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
374 Scalar elevation = 30.0f;
375
376 DlPathBuilder path_builder;
377 path_builder.MoveTo(DlPoint(100, 100));
378 // Tweak one corner by a sub-pixel amount to prevent recognition as
379 // a rectangle, but still generating a rectangular shadow.
380 path_builder.LineTo(DlPoint(299.9, 100));
381 path_builder.LineTo(DlPoint(300, 300));
382 path_builder.LineTo(DlPoint(100, 300));
383 path_builder.Close();
384 DlPath path = path_builder.TakePath();
385
386 // Path must be convex, but unrecognizable as a simple shape.
387 ASSERT_TRUE(path.IsConvex());
388 ASSERT_FALSE(path.IsRect());
389 ASSERT_FALSE(path.IsOval());
390 ASSERT_FALSE(path.IsRoundRect());
391
392 const DlPath simple_path = DlPath::MakeRectLTRB(100, 100, 300, 300);
393 DrawShadowAndCompareMeshes(builder, path, elevation, dpr, &simple_path);
394
395 auto dl = builder.Build();
396 ASSERT_TRUE(OpenPlaygroundHere(dl));
397}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPath::MakeRectLTRB(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [226/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeClockwiseTriangle   
)

Definition at line 329 of file aiks_dl_shadow_unittests.cc.

329 {
330 DisplayListBuilder builder;
331 builder.Clear(DlColor::kWhite());
332 builder.Scale(GetContentScale().x, GetContentScale().y);
333 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
334 Scalar elevation = 30.0f;
335
336 DlPathBuilder path_builder;
337 path_builder.MoveTo(DlPoint(200, 100));
338 path_builder.LineTo(DlPoint(300, 300));
339 path_builder.LineTo(DlPoint(100, 300));
340 path_builder.Close();
341 DlPath path = path_builder.TakePath();
342
343 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
344
345 auto dl = builder.Build();
346 ASSERT_TRUE(OpenPlaygroundHere(dl));
347}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [227/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeClockwiseUniformRoundRect   
)

Definition at line 565 of file aiks_dl_shadow_unittests.cc.

565 {
566 DisplayListBuilder builder;
567 builder.Clear(DlColor::kWhite());
568 builder.Scale(GetContentScale().x, GetContentScale().y);
569 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
570 Scalar elevation = 30.0f;
571
572 DlPath path = MakeAlmostRoundRectPath(DlRect::MakeLTRB(100, 100, 300, 300),
573 DlRoundingRadii::MakeRadius(30), true);
574
575 // Path must be convex, but unrecognizable as a simple shape.
576 ASSERT_TRUE(path.IsConvex());
577 ASSERT_FALSE(path.IsRect());
578 ASSERT_FALSE(path.IsOval());
579 ASSERT_FALSE(path.IsRoundRect());
580
581 const RoundRect round_rect =
582 RoundRect::MakeRectRadius(Rect::MakeLTRB(100, 100, 300, 300), 30);
583 const DlPath simple_path = DlPath::MakeRoundRect(round_rect);
584 DrawShadowAndCompareMeshes(builder, path, elevation, dpr, &simple_path);
585
586 auto dl = builder.Build();
587 ASSERT_TRUE(OpenPlaygroundHere(dl));
588}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlColor::kWhite(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundingRadii::MakeRadius(), impeller::RoundRect::MakeRectRadius(), flutter::DlPath::MakeRoundRect(), flutter::path, flutter::DisplayListBuilder::Scale(), x, and y.

◆ TEST_P() [228/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeClockwiseWithExtraColinearVertices   
)

Definition at line 886 of file aiks_dl_shadow_unittests.cc.

886 {
887 DisplayListBuilder builder;
888 builder.Clear(DlColor::kWhite());
889 builder.Scale(GetContentScale().x, GetContentScale().y);
890 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
891 Scalar elevation = 30.0f;
892
893 DlPathBuilder path_builder;
894 path_builder.MoveTo(DlPoint(200, 100));
895 path_builder.LineTo(DlPoint(250, 200));
896 path_builder.LineTo(DlPoint(300, 300));
897 path_builder.LineTo(DlPoint(200, 300));
898 path_builder.LineTo(DlPoint(100, 300));
899 path_builder.LineTo(DlPoint(150, 200));
900 path_builder.Close();
901 DlPath path = path_builder.TakePath();
902
903 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
904
905 auto dl = builder.Build();
906 ASSERT_TRUE(OpenPlaygroundHere(dl));
907}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [229/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeCounterClockwiseCircle   
)

Definition at line 463 of file aiks_dl_shadow_unittests.cc.

463 {
464 DisplayListBuilder builder;
465 builder.Clear(DlColor::kWhite());
466 builder.Scale(GetContentScale().x, GetContentScale().y);
467 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
468 Scalar elevation = 30.0f;
469
470 // A weight of sqrt(2)/2 is how you really perform conic circular sections,
471 // but by tweaking it slightly the path will not be recognized as an oval
472 // and accelerated.
473 constexpr Scalar kWeight = kSqrt2Over2 - 0.0005f;
474
475 DlPathBuilder path_builder;
476 path_builder.MoveTo(DlPoint(200, 100));
477 path_builder.ConicCurveTo(DlPoint(100, 100), DlPoint(100, 200), kWeight);
478 path_builder.ConicCurveTo(DlPoint(100, 300), DlPoint(200, 300), kWeight);
479 path_builder.ConicCurveTo(DlPoint(300, 300), DlPoint(300, 200), kWeight);
480 path_builder.ConicCurveTo(DlPoint(300, 100), DlPoint(200, 100), kWeight);
481 path_builder.Close();
482 DlPath path = path_builder.TakePath();
483
484 // Path must be convex, but unrecognizable as a simple shape.
485 ASSERT_TRUE(path.IsConvex());
486 ASSERT_FALSE(path.IsRect());
487 ASSERT_FALSE(path.IsOval());
488 ASSERT_FALSE(path.IsRoundRect());
489
490 const DlPath simple_path = DlPath::MakeCircle(DlPoint(200, 200), 100);
491 DrawShadowAndCompareMeshes(builder, path, elevation, dpr, &simple_path);
492
493 auto dl = builder.Build();
494 ASSERT_TRUE(OpenPlaygroundHere(dl));
495}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), impeller::kSqrt2Over2, flutter::DlColor::kWhite(), flutter::DlPath::MakeCircle(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [230/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeCounterClockwiseConic   
)

Definition at line 737 of file aiks_dl_shadow_unittests.cc.

737 {
738 DisplayListBuilder builder;
739 builder.Clear(DlColor::kWhite());
740 builder.Scale(GetContentScale().x, GetContentScale().y);
741 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
742 Scalar elevation = 30.0f;
743
744 DlPathBuilder path_builder;
745 path_builder.MoveTo(DlPoint(200, 100));
746 path_builder.ConicCurveTo(DlPoint(100, 100), DlPoint(100, 200), 0.4f);
747 path_builder.ConicCurveTo(DlPoint(100, 300), DlPoint(200, 300), 0.4f);
748 path_builder.ConicCurveTo(DlPoint(300, 300), DlPoint(300, 200), 0.4f);
749 path_builder.ConicCurveTo(DlPoint(300, 100), DlPoint(200, 100), 0.4f);
750 path_builder.Close();
751 DlPath path = path_builder.TakePath();
752
753 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
754
755 auto dl = builder.Build();
756 ASSERT_TRUE(OpenPlaygroundHere(dl));
757}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [231/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeCounterClockwiseCubic   
)

Definition at line 785 of file aiks_dl_shadow_unittests.cc.

785 {
786 DisplayListBuilder builder;
787 builder.Clear(DlColor::kWhite());
788 builder.Scale(GetContentScale().x, GetContentScale().y);
789 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
790 Scalar elevation = 30.0f;
791
792 DlPathBuilder path_builder;
793 path_builder.MoveTo(DlPoint(200, 100));
794 path_builder.CubicCurveTo(DlPoint(120, 100), DlPoint(100, 120),
795 DlPoint(100, 200));
796 path_builder.CubicCurveTo(DlPoint(100, 280), DlPoint(120, 300),
797 DlPoint(200, 300));
798 path_builder.CubicCurveTo(DlPoint(280, 300), DlPoint(300, 280),
799 DlPoint(300, 200));
800 path_builder.CubicCurveTo(DlPoint(300, 120), DlPoint(280, 100),
801 DlPoint(200, 100));
802 path_builder.Close();
803 DlPath path = path_builder.TakePath();
804
805 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
806
807 auto dl = builder.Build();
808 ASSERT_TRUE(OpenPlaygroundHere(dl));
809}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::CubicCurveTo(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [232/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeCounterClockwiseMultiRadiiRoundRect   
)

Definition at line 643 of file aiks_dl_shadow_unittests.cc.

643 {
644 DisplayListBuilder builder;
645 builder.Clear(DlColor::kWhite());
646 builder.Scale(GetContentScale().x, GetContentScale().y);
647 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
648 Scalar elevation = 30.0f;
649
651 .top_left = {80, 60},
652 .top_right = {20, 25},
653 .bottom_left = {60, 80},
654 .bottom_right = {25, 20},
655 };
656 DlPath path = MakeAlmostRoundRectPath(DlRect::MakeLTRB(100, 100, 300, 300),
657 radii, false);
658
659 // Path must be convex, but unrecognizable as a simple shape.
660 ASSERT_TRUE(path.IsConvex());
661 ASSERT_FALSE(path.IsRect());
662 ASSERT_FALSE(path.IsOval());
663 ASSERT_FALSE(path.IsRoundRect());
664
665 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
666
667 auto dl = builder.Build();
668 ASSERT_TRUE(OpenPlaygroundHere(dl));
669}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlColor::kWhite(), impeller::TRect< Scalar >::MakeLTRB(), flutter::path, flutter::DisplayListBuilder::Scale(), impeller::RoundingRadii::top_left, x, and y.

◆ TEST_P() [233/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeCounterClockwiseOctagon   
)

Definition at line 836 of file aiks_dl_shadow_unittests.cc.

836 {
837 DisplayListBuilder builder;
838 builder.Clear(DlColor::kWhite());
839 builder.Scale(GetContentScale().x, GetContentScale().y);
840 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
841 Scalar elevation = 30.0f;
842
843 DlPathBuilder path_builder;
844 path_builder.MoveTo(DlPoint(100, 125));
845 path_builder.LineTo(DlPoint(100, 275));
846 path_builder.LineTo(DlPoint(125, 300));
847 path_builder.LineTo(DlPoint(275, 300));
848 path_builder.LineTo(DlPoint(300, 275));
849 path_builder.LineTo(DlPoint(300, 125));
850 path_builder.LineTo(DlPoint(275, 100));
851 path_builder.LineTo(DlPoint(125, 100));
852 path_builder.Close();
853 DlPath path = path_builder.TakePath();
854
855 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
856
857 auto dl = builder.Build();
858 ASSERT_TRUE(OpenPlaygroundHere(dl));
859}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [234/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeCounterClockwiseOval   
)

Definition at line 531 of file aiks_dl_shadow_unittests.cc.

531 {
532 DisplayListBuilder builder;
533 builder.Clear(DlColor::kWhite());
534 builder.Scale(GetContentScale().x, GetContentScale().y);
535 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
536 Scalar elevation = 30.0f;
537
538 // A weight of sqrt(2)/2 is how you really perform conic circular sections,
539 // but by tweaking it slightly the path will not be recognized as an oval
540 // and accelerated.
541 constexpr Scalar kWeight = kSqrt2Over2 - 0.0005f;
542
543 DlPathBuilder path_builder;
544 path_builder.MoveTo(DlPoint(200, 120));
545 path_builder.ConicCurveTo(DlPoint(100, 120), DlPoint(100, 200), kWeight);
546 path_builder.ConicCurveTo(DlPoint(100, 280), DlPoint(200, 280), kWeight);
547 path_builder.ConicCurveTo(DlPoint(300, 280), DlPoint(300, 200), kWeight);
548 path_builder.ConicCurveTo(DlPoint(300, 120), DlPoint(200, 120), kWeight);
549 path_builder.Close();
550 DlPath path = path_builder.TakePath();
551
552 // Path must be convex, but unrecognizable as a simple shape.
553 ASSERT_TRUE(path.IsConvex());
554 ASSERT_FALSE(path.IsRect());
555 ASSERT_FALSE(path.IsOval());
556 ASSERT_FALSE(path.IsRoundRect());
557
558 const DlPath simple_path = DlPath::MakeOvalLTRB(100, 120, 300, 280);
559 DrawShadowAndCompareMeshes(builder, path, elevation, dpr, &simple_path);
560
561 auto dl = builder.Build();
562 ASSERT_TRUE(OpenPlaygroundHere(dl));
563}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlPathBuilder::ConicCurveTo(), impeller::kSqrt2Over2, flutter::DlColor::kWhite(), flutter::DlPath::MakeOvalLTRB(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [235/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeCounterClockwiseQuadratic   
)

Definition at line 693 of file aiks_dl_shadow_unittests.cc.

693 {
694 DisplayListBuilder builder;
695 builder.Clear(DlColor::kWhite());
696 builder.Scale(GetContentScale().x, GetContentScale().y);
697 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
698 Scalar elevation = 30.0f;
699
700 DlPathBuilder path_builder;
701 path_builder.MoveTo(DlPoint(200, 100));
702 path_builder.QuadraticCurveTo(DlPoint(100, 100), DlPoint(100, 200));
703 path_builder.QuadraticCurveTo(DlPoint(100, 300), DlPoint(200, 300));
704 path_builder.QuadraticCurveTo(DlPoint(300, 300), DlPoint(300, 200));
705 path_builder.QuadraticCurveTo(DlPoint(300, 100), DlPoint(200, 100));
706 path_builder.Close();
707 DlPath path = path_builder.TakePath();
708
709 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
710
711 auto dl = builder.Build();
712 ASSERT_TRUE(OpenPlaygroundHere(dl));
713}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DlPathBuilder::QuadraticCurveTo(), flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [236/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeCounterClockwiseRect   
)

Definition at line 399 of file aiks_dl_shadow_unittests.cc.

399 {
400 DisplayListBuilder builder;
401 builder.Clear(DlColor::kWhite());
402 builder.Scale(GetContentScale().x, GetContentScale().y);
403 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
404 Scalar elevation = 30.0f;
405
406 DlPathBuilder path_builder;
407 path_builder.MoveTo(DlPoint(100, 100));
408 path_builder.LineTo(DlPoint(100, 300));
409 path_builder.LineTo(DlPoint(300, 300));
410 // Tweak one corner by a sub-pixel amount to prevent recognition as
411 // a rectangle, but still generating a rectangular shadow.
412 path_builder.LineTo(DlPoint(299.9, 100));
413 path_builder.Close();
414 DlPath path = path_builder.TakePath();
415
416 // Path must be convex, but unrecognizable as a simple shape.
417 ASSERT_TRUE(path.IsConvex());
418 ASSERT_FALSE(path.IsRect());
419 ASSERT_FALSE(path.IsOval());
420 ASSERT_FALSE(path.IsRoundRect());
421
422 const DlPath simple_path = DlPath::MakeRectLTRB(100, 100, 300, 300);
423 DrawShadowAndCompareMeshes(builder, path, elevation, dpr, &simple_path);
424
425 auto dl = builder.Build();
426 ASSERT_TRUE(OpenPlaygroundHere(dl));
427}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPath::MakeRectLTRB(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [237/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeCounterClockwiseTriangle   
)

Definition at line 349 of file aiks_dl_shadow_unittests.cc.

349 {
350 DisplayListBuilder builder;
351 builder.Clear(DlColor::kWhite());
352 builder.Scale(GetContentScale().x, GetContentScale().y);
353 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
354 Scalar elevation = 30.0f;
355
356 DlPathBuilder path_builder;
357 path_builder.MoveTo(DlPoint(200, 100));
358 path_builder.LineTo(DlPoint(100, 300));
359 path_builder.LineTo(DlPoint(300, 300));
360 path_builder.Close();
361 DlPath path = path_builder.TakePath();
362
363 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
364
365 auto dl = builder.Build();
366 ASSERT_TRUE(OpenPlaygroundHere(dl));
367}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [238/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeCounterClockwiseUniformRoundRect   
)

Definition at line 590 of file aiks_dl_shadow_unittests.cc.

590 {
591 DisplayListBuilder builder;
592 builder.Clear(DlColor::kWhite());
593 builder.Scale(GetContentScale().x, GetContentScale().y);
594 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
595 Scalar elevation = 30.0f;
596
597 DlPath path = MakeAlmostRoundRectPath(DlRect::MakeLTRB(100, 100, 300, 300),
598 DlRoundingRadii::MakeRadius(30), false);
599
600 // Path must be convex, but unrecognizable as a simple shape.
601 ASSERT_TRUE(path.IsConvex());
602 ASSERT_FALSE(path.IsRect());
603 ASSERT_FALSE(path.IsOval());
604 ASSERT_FALSE(path.IsRoundRect());
605
606 const RoundRect round_rect =
607 RoundRect::MakeRectRadius(Rect::MakeLTRB(100, 100, 300, 300), 30);
608 const DlPath simple_path = DlPath::MakeRoundRect(round_rect);
609 DrawShadowAndCompareMeshes(builder, path, elevation, dpr, &simple_path);
610
611 auto dl = builder.Build();
612 ASSERT_TRUE(OpenPlaygroundHere(dl));
613}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlColor::kWhite(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundingRadii::MakeRadius(), impeller::RoundRect::MakeRectRadius(), flutter::DlPath::MakeRoundRect(), flutter::path, flutter::DisplayListBuilder::Scale(), x, and y.

◆ TEST_P() [239/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeCounterClockwiseWithExtraColinearVertices   
)

Definition at line 909 of file aiks_dl_shadow_unittests.cc.

910 {
911 DisplayListBuilder builder;
912 builder.Clear(DlColor::kWhite());
913 builder.Scale(GetContentScale().x, GetContentScale().y);
914 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
915 Scalar elevation = 30.0f;
916
917 DlPathBuilder path_builder;
918 path_builder.MoveTo(DlPoint(200, 100));
919 path_builder.LineTo(DlPoint(150, 200));
920 path_builder.LineTo(DlPoint(100, 300));
921 path_builder.LineTo(DlPoint(200, 300));
922 path_builder.LineTo(DlPoint(300, 300));
923 path_builder.LineTo(DlPoint(250, 200));
924 path_builder.Close();
925 DlPath path = path_builder.TakePath();
926
927 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
928
929 auto dl = builder.Build();
930 ASSERT_TRUE(OpenPlaygroundHere(dl));
931}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [240/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowCanOptimizeWithExtraneousMoveTos   
)

Definition at line 861 of file aiks_dl_shadow_unittests.cc.

861 {
862 DisplayListBuilder builder;
863 builder.Clear(DlColor::kWhite());
864 builder.Scale(GetContentScale().x, GetContentScale().y);
865 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
866 Scalar elevation = 30.0f;
867
868 DlPathBuilder path_builder;
869 path_builder.MoveTo(DlPoint(0, 0));
870 path_builder.MoveTo(DlPoint(1000, 1000));
871 path_builder.MoveTo(DlPoint(100, 50));
872 path_builder.MoveTo(DlPoint(200, 100));
873 path_builder.LineTo(DlPoint(300, 300));
874 path_builder.LineTo(DlPoint(100, 300));
875 path_builder.Close();
876 path_builder.MoveTo(DlPoint(1000, 1000));
877 path_builder.MoveTo(DlPoint(500, 300));
878 DlPath path = path_builder.TakePath();
879
880 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
881
882 auto dl = builder.Build();
883 ASSERT_TRUE(OpenPlaygroundHere(dl));
884}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [241/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowDoesNotOptimizeHourglass   
)

Definition at line 234 of file aiks_dl_shadow_unittests.cc.

234 {
235 DisplayListBuilder builder;
236 builder.Clear(DlColor::kWhite());
237 builder.Scale(GetContentScale().x, GetContentScale().y);
238 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
239 Scalar elevation = 30.0f;
240
241 DlPathBuilder path_builder;
242 path_builder.MoveTo(DlPoint(100, 100));
243 path_builder.LineTo(DlPoint(300, 300));
244 path_builder.LineTo(DlPoint(100, 300));
245 path_builder.LineTo(DlPoint(300, 100));
246 path_builder.Close();
247 DlPath path = path_builder.TakePath();
248
249 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
250
251 auto dl = builder.Build();
252 ASSERT_TRUE(OpenPlaygroundHere(dl));
253}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [242/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowDoesNotOptimizeInnerOuterSpiral   
)

Definition at line 255 of file aiks_dl_shadow_unittests.cc.

255 {
256 DisplayListBuilder builder;
257 builder.Clear(DlColor::kWhite());
258 builder.Scale(GetContentScale().x, GetContentScale().y);
259 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
260 Scalar elevation = 30.0f;
261 int step_count = 20;
262
263 DlPathBuilder path_builder;
264 path_builder.MoveTo(DlPoint(300, 200));
265 for (int i = 1; i < step_count * 2; i++) {
266 Scalar angle = (k2Pi * i) / step_count;
267 Scalar radius = 80.0f + std::abs(i - step_count);
268 path_builder.LineTo(DlPoint(200, 200) + DlPoint(std::cos(angle) * radius,
269 std::sin(angle) * radius));
270 }
271 path_builder.Close();
272 DlPath path = path_builder.TakePath();
273
274 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
275
276 auto dl = builder.Build();
277 ASSERT_TRUE(OpenPlaygroundHere(dl));
278}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), i, impeller::k2Pi, flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [243/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowDoesNotOptimizeMultipleContours   
)

Definition at line 305 of file aiks_dl_shadow_unittests.cc.

305 {
306 DisplayListBuilder builder;
307 builder.Clear(DlColor::kWhite());
308 builder.Scale(GetContentScale().x, GetContentScale().y);
309 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
310 Scalar elevation = 30.0f;
311
312 DlPathBuilder path_builder;
313 path_builder.MoveTo(DlPoint(150, 100));
314 path_builder.LineTo(DlPoint(200, 300));
315 path_builder.LineTo(DlPoint(100, 300));
316 path_builder.Close();
317 path_builder.MoveTo(DlPoint(250, 100));
318 path_builder.LineTo(DlPoint(300, 300));
319 path_builder.LineTo(DlPoint(200, 300));
320 path_builder.Close();
321 DlPath path = path_builder.TakePath();
322
323 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
324
325 auto dl = builder.Build();
326 ASSERT_TRUE(OpenPlaygroundHere(dl));
327}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [244/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawShadowDoesNotOptimizeOuterInnerSpiral   
)

Definition at line 280 of file aiks_dl_shadow_unittests.cc.

280 {
281 DisplayListBuilder builder;
282 builder.Clear(DlColor::kWhite());
283 builder.Scale(GetContentScale().x, GetContentScale().y);
284 Scalar dpr = std::max(GetContentScale().x, GetContentScale().y);
285 Scalar elevation = 30.0f;
286 int step_count = 20;
287
288 DlPathBuilder path_builder;
289 path_builder.MoveTo(DlPoint(280, 200));
290 for (int i = 1; i < step_count * 2; i++) {
291 Scalar angle = (k2Pi * i) / step_count;
292 Scalar radius = 100.0f - std::abs(i - step_count);
293 path_builder.LineTo(DlPoint(200, 200) + DlPoint(std::cos(angle) * radius,
294 std::sin(angle) * radius));
295 }
296 path_builder.Close();
297 DlPath path = path_builder.TakePath();
298
299 DrawShadowAndCompareMeshes(builder, path, elevation, dpr);
300
301 auto dl = builder.Build();
302 ASSERT_TRUE(OpenPlaygroundHere(dl));
303}

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DlPathBuilder::Close(), i, impeller::k2Pi, flutter::DlColor::kWhite(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [245/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawThinStrokedCircle   
)

Definition at line 734 of file aiks_dl_basic_unittests.cc.

734 {
735 auto callback = [&]() {
736 static float stroked_radius = 100.0;
737 static float stroke_width = 0.0;
738 static float stroke_width_fine = 2.0;
739 static float stroked_alpha = 255.0;
740 static float stroked_scale[2] = {1.0, 1.0};
741
742 if (IsPlaygroundEnabled()) {
743 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
744 ImGui::SliderFloat("Stroked Radius", &stroked_radius, 0, 500);
745 ImGui::SliderFloat("Stroked Width", &stroke_width, 0, 500);
746 ImGui::SliderFloat("Stroked Width Fine", &stroke_width_fine, 0, 5);
747 ImGui::SliderFloat("Stroked Alpha", &stroked_alpha, 0, 10.0);
748 ImGui::SliderFloat2("Stroked Scale", stroked_scale, 0, 10.0);
749 ImGui::End();
750 }
751
753
754 DlPaint background_paint;
755 background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
756 builder.DrawPaint(background_paint);
757
758 flutter::DlPaint paint;
759
760 paint.setColor(flutter::DlColor::kRed().withAlpha(stroked_alpha));
762 paint.setStrokeWidth(stroke_width + stroke_width_fine);
763 builder.Save();
764 builder.Translate(250, 250);
765 builder.Scale(stroked_scale[0], stroked_scale[1]);
766 builder.Translate(-250, -250);
767 builder.DrawCircle(DlPoint(250, 250), stroked_radius, paint);
768 builder.Restore();
769 return builder.Build();
770 };
771
772 ASSERT_TRUE(OpenPlaygroundHere(callback));
773}
@ kStroke
strokes boundary of shapes

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kRed(), flutter::kStroke, flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [246/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesImageSourceWithTextureCoordinates   
)

Definition at line 273 of file aiks_dl_vertices_unittests.cc.

273 {
274 auto texture = CreateTextureForFixture("embarcadero.jpg");
275 auto dl_image = DlImageImpeller::Make(texture);
276 std::vector<DlPoint> positions = {
277 DlPoint(100, 300),
278 DlPoint(200, 100),
279 DlPoint(300, 300),
280 };
281 std::vector<DlPoint> texture_coordinates = {
282 DlPoint(0, 0),
283 DlPoint(100, 200),
284 DlPoint(200, 100),
285 };
286
287 auto vertices = flutter::DlVertices::Make(
288 flutter::DlVertexMode::kTriangles, 3, positions.data(),
289 texture_coordinates.data(), /*colors=*/nullptr);
290
292 flutter::DlPaint paint;
293
294 auto image_source = flutter::DlColorSource::MakeImage(
296
297 paint.setColorSource(image_source);
298 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
299
300 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
301}
static std::shared_ptr< DlColorSource > MakeImage(const sk_sp< const DlImage > &image, DlTileMode horizontal_tile_mode, DlTileMode vertical_tile_mode, DlImageSampling sampling=DlImageSampling::kLinear, const DlMatrix *matrix=nullptr)
@ kTriangles
The vertices are taken 3 at a time to form a triangle.

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), flutter::kRepeat, flutter::kTriangles, flutter::DlVertices::Make(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), flutter::DlPaint::setColorSource(), and texture.

◆ TEST_P() [247/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesImageSourceWithTextureCoordinatesAndColorBlending   
)

Definition at line 303 of file aiks_dl_vertices_unittests.cc.

304 {
305 auto texture = CreateTextureForFixture("embarcadero.jpg");
306 auto dl_image = DlImageImpeller::Make(texture);
307 std::vector<DlPoint> positions = {
308 DlPoint(100, 300),
309 DlPoint(200, 100),
310 DlPoint(300, 300),
311 };
312 std::vector<flutter::DlColor> colors = {flutter::DlColor::kWhite(),
315 std::vector<DlPoint> texture_coordinates = {
316 DlPoint(0, 0),
317 DlPoint(100, 200),
318 DlPoint(200, 100),
319 };
320
321 auto vertices = flutter::DlVertices::Make(
322 flutter::DlVertexMode::kTriangles, 3, positions.data(),
323 texture_coordinates.data(), colors.data());
324
326 flutter::DlPaint paint;
327
328 auto image_source = flutter::DlColorSource::MakeImage(
330
331 paint.setColorSource(image_source);
332 builder.DrawVertices(vertices, flutter::DlBlendMode::kModulate, paint);
333
334 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
335}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), flutter::DlColor::kGreen(), flutter::kRepeat, flutter::kTriangles, flutter::DlColor::kWhite(), flutter::DlVertices::Make(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), flutter::DlPaint::setColorSource(), and texture.

◆ TEST_P() [248/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesLinearGradientWithEmptySize   
)

Definition at line 286 of file canvas_unittests.cc.

286 {
287 RenderCallback callback = [&](RenderTarget& render_target) {
288 ContentContext& context = GetContentContext();
289 Canvas canvas(context, render_target, true, false);
290
291 std::vector<flutter::DlPoint> vertex_coordinates = {
292 flutter::DlPoint(0, 0),
293 flutter::DlPoint(600, 0),
294 flutter::DlPoint(0, 600),
295 };
296 std::vector<flutter::DlPoint> texture_coordinates = {
297 flutter::DlPoint(0, 0),
298 flutter::DlPoint(500, 0),
299 flutter::DlPoint(0, 500),
300 };
301 std::vector<uint16_t> indices = {0, 1, 2};
302 flutter::DlVertices::Builder vertices_builder(
303 flutter::DlVertexMode::kTriangleStrip, vertex_coordinates.size(),
305 vertices_builder.store_vertices(vertex_coordinates.data());
306 vertices_builder.store_indices(indices.data());
307 vertices_builder.store_texture_coordinates(texture_coordinates.data());
308 auto vertices = vertices_builder.build();
309
310 // The start and end points of the gradient form an empty rectangle.
311 std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
313 std::vector<Scalar> stops = {0.0, 1.0};
315 {0, 0}, {0, 600}, 2, colors.data(), stops.data(),
317
318 Paint paint;
319 paint.color_source = gradient.get();
320 canvas.DrawVertices(std::make_shared<DlVerticesGeometry>(vertices, context),
321 BlendMode::kSrcOver, paint);
322
323 canvas.EndReplay();
324 return true;
325 };
326
327 ASSERT_TRUE(Playground::OpenPlaygroundHere(callback));
328}
A utility class to build up a |DlVertices| object one set of data at a time.
Definition dl_vertices.h:73
static constexpr Flags kHasTextureCoordinates
Definition dl_vertices.h:95

References flutter::DlVertices::Builder::build(), callback, impeller::Paint::color_source, context, impeller::Canvas::DrawVertices(), impeller::Canvas::EndReplay(), flutter::DlColor::kBlue(), flutter::kClamp, flutter::DlVertices::Builder::kHasTextureCoordinates, flutter::DlColor::kRed(), impeller::kSrcOver, flutter::kTriangleStrip, flutter::DlColorSource::MakeLinear(), impeller::Playground::OpenPlaygroundHere(), flutter::DlVertices::Builder::store_indices(), flutter::DlVertices::Builder::store_texture_coordinates(), and flutter::DlVertices::Builder::store_vertices().

◆ TEST_P() [249/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesLinearGradientWithoutIndices   
)

Definition at line 212 of file aiks_dl_vertices_unittests.cc.

212 {
213 std::vector<DlPoint> positions = {
214 DlPoint(100, 300),
215 DlPoint(200, 100),
216 DlPoint(300, 300),
217 };
218
219 auto vertices = flutter::DlVertices::Make(
220 flutter::DlVertexMode::kTriangles, 3, positions.data(),
221 /*texture_coordinates=*/nullptr, /*colors=*/nullptr);
222
223 std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
225 const float stops[2] = {0.0, 1.0};
226
228 {100.0, 100.0}, {300.0, 300.0}, 2, colors.data(), stops,
230
232 flutter::DlPaint paint;
233
234 paint.setColorSource(linear);
235 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
236
237 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
238}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::kRepeat, flutter::kTriangles, flutter::DlVertices::Make(), flutter::DlColorSource::MakeLinear(), and flutter::DlPaint::setColorSource().

◆ TEST_P() [250/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesLinearGradientWithTextureCoordinates   
)

Definition at line 240 of file aiks_dl_vertices_unittests.cc.

240 {
241 std::vector<DlPoint> positions = {
242 DlPoint(100, 300),
243 DlPoint(200, 100),
244 DlPoint(300, 300),
245 };
246 std::vector<DlPoint> texture_coordinates = {
247 DlPoint(300, 100),
248 DlPoint(100, 200),
249 DlPoint(300, 300),
250 };
251
252 auto vertices = flutter::DlVertices::Make(
253 flutter::DlVertexMode::kTriangles, 3, positions.data(),
254 texture_coordinates.data(), /*colors=*/nullptr);
255
256 std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
258 const float stops[2] = {0.0, 1.0};
259
261 {100.0, 100.0}, {300.0, 300.0}, 2, colors.data(), stops,
263
265 flutter::DlPaint paint;
266
267 paint.setColorSource(linear);
268 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
269
270 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
271}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::kRepeat, flutter::kTriangles, flutter::DlVertices::Make(), flutter::DlColorSource::MakeLinear(), and flutter::DlPaint::setColorSource().

◆ TEST_P() [251/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesPremultipliesColors   
)

Definition at line 360 of file aiks_dl_vertices_unittests.cc.

360 {
361 std::vector<DlPoint> positions = {
362 DlPoint(100, 300),
363 DlPoint(200, 100),
364 DlPoint(300, 300),
365 DlPoint(200, 500),
366 };
367 auto color = flutter::DlColor::kBlue().withAlpha(0x99);
368 std::vector<uint16_t> indices = {0, 1, 2, 0, 2, 3};
369 std::vector<flutter::DlColor> colors = {color, color, color, color};
370
371 auto vertices = flutter::DlVertices::Make(
372 flutter::DlVertexMode::kTriangles, positions.size(), positions.data(),
373 /*texture_coordinates=*/nullptr, colors.data(), indices.size(),
374 indices.data());
375
377 flutter::DlPaint paint;
378 paint.setBlendMode(flutter::DlBlendMode::kSrcOver);
380
381 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 400), paint);
382 builder.DrawVertices(vertices, flutter::DlBlendMode::kDst, paint);
383
384 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
385}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawVertices(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::kTriangles, flutter::DlVertices::Make(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), and flutter::DlColor::withAlpha().

◆ TEST_P() [252/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesSolidColorTrianglesWithIndices   
)

Definition at line 337 of file aiks_dl_vertices_unittests.cc.

337 {
338 std::vector<DlPoint> positions = {
339 DlPoint(100, 300),
340 DlPoint(200, 100),
341 DlPoint(300, 300),
342 DlPoint(200, 500),
343 };
344 std::vector<uint16_t> indices = {0, 1, 2, 0, 2, 3};
345
346 auto vertices = flutter::DlVertices::Make(
347 flutter::DlVertexMode::kTriangles, positions.size(), positions.data(),
348 /*texture_coordinates=*/nullptr, /*colors=*/nullptr, indices.size(),
349 indices.data());
350
352 flutter::DlPaint paint;
353
355 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
356
357 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
358}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), flutter::DlColor::kRed(), flutter::kTriangles, flutter::DlVertices::Make(), and flutter::DlPaint::setColor().

◆ TEST_P() [253/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesSolidColorTrianglesWithoutIndices   
)

Definition at line 186 of file aiks_dl_vertices_unittests.cc.

186 {
187 // Use negative coordinates and then scale the transform by -1, -1 to make
188 // sure coverage is taking the transform into account.
189 std::vector<DlPoint> positions = {
190 DlPoint(-100, -300),
191 DlPoint(-200, -100),
192 DlPoint(-300, -300),
193 };
194 std::vector<flutter::DlColor> colors = {flutter::DlColor::kWhite(),
197
198 auto vertices = flutter::DlVertices::Make(
199 flutter::DlVertexMode::kTriangles, 3, positions.data(),
200 /*texture_coordinates=*/nullptr, colors.data());
201
203 flutter::DlPaint paint;
204
205 paint.setColor(flutter::DlColor::kRed().modulateOpacity(0.5));
206 builder.Scale(-1, -1);
207 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
208
209 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
210}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::kTriangles, flutter::DlColor::kWhite(), flutter::DlVertices::Make(), flutter::DisplayListBuilder::Scale(), and flutter::DlPaint::setColor().

◆ TEST_P() [254/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesTextureCoordinatesWithFragmentShader   
)

Definition at line 419 of file aiks_dl_vertices_unittests.cc.

419 {
420 std::vector<DlPoint> positions_lt = {
421 DlPoint(0, 0), //
422 DlPoint(50, 0), //
423 DlPoint(0, 50), //
424 DlPoint(50, 50), //
425 };
426
427 auto vertices_lt = flutter::DlVertices::Make(
428 flutter::DlVertexMode::kTriangleStrip, positions_lt.size(),
429 positions_lt.data(),
430 /*texture_coordinates=*/positions_lt.data(), /*colors=*/nullptr,
431 /*index_count=*/0,
432 /*indices=*/nullptr);
433
434 std::vector<DlPoint> positions_rt = {
435 DlPoint(50, 0), //
436 DlPoint(100, 0), //
437 DlPoint(50, 50), //
438 DlPoint(100, 50), //
439 };
440
441 auto vertices_rt = flutter::DlVertices::Make(
442 flutter::DlVertexMode::kTriangleStrip, positions_rt.size(),
443 positions_rt.data(),
444 /*texture_coordinates=*/positions_rt.data(), /*colors=*/nullptr,
445 /*index_count=*/0,
446 /*indices=*/nullptr);
447
448 std::vector<DlPoint> positions_lb = {
449 DlPoint(0, 50), //
450 DlPoint(50, 50), //
451 DlPoint(0, 100), //
452 DlPoint(50, 100), //
453 };
454
455 auto vertices_lb = flutter::DlVertices::Make(
456 flutter::DlVertexMode::kTriangleStrip, positions_lb.size(),
457 positions_lb.data(),
458 /*texture_coordinates=*/positions_lb.data(), /*colors=*/nullptr,
459 /*index_count=*/0,
460 /*indices=*/nullptr);
461
462 std::vector<DlPoint> positions_rb = {
463 DlPoint(50, 50), //
464 DlPoint(100, 50), //
465 DlPoint(50, 100), //
466 DlPoint(100, 100), //
467 };
468
469 auto vertices_rb = flutter::DlVertices::Make(
470 flutter::DlVertexMode::kTriangleStrip, positions_rb.size(),
471 positions_rb.data(),
472 /*texture_coordinates=*/positions_rb.data(), /*colors=*/nullptr,
473 /*index_count=*/0,
474 /*indices=*/nullptr);
475
477 flutter::DlPaint paint;
478 flutter::DlPaint rect_paint;
479 rect_paint.setColor(DlColor::kBlue());
480
481 auto runtime_stages_result =
482 OpenAssetAsRuntimeStage("runtime_stage_simple.frag.iplr");
483 ABSL_ASSERT_OK(runtime_stages_result);
484 std::shared_ptr<RuntimeStage> runtime_stage =
485 runtime_stages_result.value()[GetRuntimeStageBackend()];
486 ASSERT_TRUE(runtime_stage);
487
488 auto runtime_effect = DlRuntimeEffectImpeller::Make(runtime_stage);
489 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
491 runtime_effect, {}, uniform_data);
492
493 paint.setColorSource(color_source);
494
495 builder.Scale(GetContentScale().x, GetContentScale().y);
496 builder.Save();
497 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), rect_paint);
498 builder.DrawVertices(vertices_lt, flutter::DlBlendMode::kSrcOver, paint);
499 builder.DrawVertices(vertices_rt, flutter::DlBlendMode::kSrcOver, paint);
500 builder.DrawVertices(vertices_lb, flutter::DlBlendMode::kSrcOver, paint);
501 builder.DrawVertices(vertices_rb, flutter::DlBlendMode::kSrcOver, paint);
502 builder.Restore();
503
504 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
505}
static std::shared_ptr< DlColorSource > MakeRuntimeEffect(sk_sp< DlRuntimeEffect > runtime_effect, std::vector< std::shared_ptr< DlColorSource > > samplers, std::shared_ptr< std::vector< uint8_t > > uniform_data)

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawVertices(), flutter::DlColor::kBlue(), flutter::kTriangleStrip, flutter::DlVertices::Make(), flutter::DlRuntimeEffectImpeller::Make(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlColorSource::MakeRuntimeEffect(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), x, and y.

◆ TEST_P() [255/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesTextureCoordinatesWithFragmentShaderNonZeroOrigin   
)

Definition at line 509 of file aiks_dl_vertices_unittests.cc.

510 {
511 std::vector<DlPoint> positions_lt = {
512 DlPoint(200, 200), //
513 DlPoint(250, 200), //
514 DlPoint(200, 250), //
515 DlPoint(250, 250), //
516 };
517
518 auto vertices = flutter::DlVertices::Make(
519 flutter::DlVertexMode::kTriangleStrip, positions_lt.size(),
520 positions_lt.data(),
521 /*texture_coordinates=*/positions_lt.data(), /*colors=*/nullptr,
522 /*index_count=*/0,
523 /*indices=*/nullptr);
524
526 flutter::DlPaint paint;
527 flutter::DlPaint rect_paint;
528 rect_paint.setColor(DlColor::kBlue());
529
530 auto runtime_stages_result =
531 OpenAssetAsRuntimeStage("runtime_stage_position.frag.iplr");
532 ABSL_ASSERT_OK(runtime_stages_result);
533 std::shared_ptr<RuntimeStage> runtime_stage =
534 runtime_stages_result.value()[GetRuntimeStageBackend()];
535 ASSERT_TRUE(runtime_stage);
536
537 auto runtime_effect = DlRuntimeEffectImpeller::Make(runtime_stage);
538 auto rect_data = std::vector<Rect>{Rect::MakeLTRB(200, 200, 250, 250)};
539
540 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
541 uniform_data->resize(rect_data.size() * sizeof(Rect));
542 memcpy(uniform_data->data(), rect_data.data(), uniform_data->size());
543
545 runtime_effect, {}, uniform_data);
546
547 paint.setColorSource(color_source);
548
549 builder.Scale(GetContentScale().x, GetContentScale().y);
550 builder.DrawRect(DlRect::MakeLTRB(200, 200, 250, 250), rect_paint);
551 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
552
553 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
554}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawVertices(), flutter::DlColor::kBlue(), flutter::kTriangleStrip, flutter::DlVertices::Make(), flutter::DlRuntimeEffectImpeller::Make(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlColorSource::MakeRuntimeEffect(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), x, and y.

◆ TEST_P() [256/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesWithEmptyTextureCoordinates   
)

Definition at line 330 of file canvas_unittests.cc.

330 {
331 auto runtime_stages_result =
332 OpenAssetAsRuntimeStage("runtime_stage_simple.frag.iplr");
333 ABSL_ASSERT_OK(runtime_stages_result);
334 std::shared_ptr<RuntimeStage> runtime_stage =
335 runtime_stages_result.value()[GetRuntimeStageBackend()];
336 ASSERT_TRUE(runtime_stage);
337
338 auto runtime_effect = flutter::DlRuntimeEffectImpeller::Make(runtime_stage);
339 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
341 runtime_effect, {}, uniform_data);
342
343 RenderCallback callback = [&](RenderTarget& render_target) {
344 ContentContext& context = GetContentContext();
345 Canvas canvas(context, render_target, true, false);
346
347 std::vector<flutter::DlPoint> vertex_coordinates = {
348 flutter::DlPoint(100, 100),
349 flutter::DlPoint(300, 100),
350 flutter::DlPoint(100, 300),
351 };
352 // The bounding box of the texture coordinates is empty.
353 std::vector<flutter::DlPoint> texture_coordinates = {
354 flutter::DlPoint(0, 0),
355 flutter::DlPoint(0, 100),
356 flutter::DlPoint(0, 0),
357 };
358 std::vector<uint16_t> indices = {0, 1, 2};
359 flutter::DlVertices::Builder vertices_builder(
360 flutter::DlVertexMode::kTriangleStrip, vertex_coordinates.size(),
362 vertices_builder.store_vertices(vertex_coordinates.data());
363 vertices_builder.store_indices(indices.data());
364 vertices_builder.store_texture_coordinates(texture_coordinates.data());
365 auto vertices = vertices_builder.build();
366
367 Paint paint;
368 paint.color_source = color_source.get();
369 canvas.DrawVertices(std::make_shared<DlVerticesGeometry>(vertices, context),
370 BlendMode::kSrcOver, paint);
371
372 canvas.EndReplay();
373 return true;
374 };
375
376 ASSERT_TRUE(Playground::OpenPlaygroundHere(callback));
377}
static sk_sp< DlRuntimeEffect > Make(std::shared_ptr< impeller::RuntimeStage > runtime_stage)

References flutter::DlVertices::Builder::build(), callback, impeller::Paint::color_source, context, impeller::Canvas::DrawVertices(), impeller::Canvas::EndReplay(), flutter::DlVertices::Builder::kHasTextureCoordinates, impeller::kSrcOver, flutter::kTriangleStrip, flutter::DlRuntimeEffectImpeller::Make(), flutter::DlColorSource::MakeRuntimeEffect(), impeller::Playground::OpenPlaygroundHere(), flutter::DlVertices::Builder::store_indices(), flutter::DlVertices::Builder::store_texture_coordinates(), and flutter::DlVertices::Builder::store_vertices().

◆ TEST_P() [257/662]

impeller::testing::TEST_P ( AiksTest  ,
DrawVerticesWithInvalidIndices   
)

Definition at line 387 of file aiks_dl_vertices_unittests.cc.

387 {
388 std::vector<DlPoint> positions = {
389 DlPoint(100, 300),
390 DlPoint(200, 100),
391 DlPoint(300, 300),
392 DlPoint(200, 500),
393 };
394 std::vector<uint16_t> indices = {0, 1, 2, 0, 2, 3, 99, 100, 101};
395
396 auto vertices = flutter::DlVertices::Make(
397 flutter::DlVertexMode::kTriangles, positions.size(), positions.data(),
398 /*texture_coordinates=*/nullptr, /*colors=*/nullptr, indices.size(),
399 indices.data());
400
401 EXPECT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(100, 100, 300, 500));
402
404 flutter::DlPaint paint;
405 paint.setBlendMode(flutter::DlBlendMode::kSrcOver);
407
408 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 400), paint);
409 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrc, paint);
410
411 AiksContext renderer(GetContext(), nullptr);
412 std::shared_ptr<Texture> image =
413 DisplayListToTexture(builder.Build(), {1024, 768}, renderer);
414 EXPECT_TRUE(image);
415}

References flutter::DisplayListBuilder::Build(), impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawVertices(), image, flutter::DlColor::kRed(), flutter::kTriangles, flutter::DlVertices::Make(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [258/662]

impeller::testing::TEST_P ( AiksTest  ,
EmptySaveLayerIgnoresPaint   
)

Definition at line 1853 of file aiks_dl_basic_unittests.cc.

1853 {
1854 DisplayListBuilder builder;
1855 builder.Scale(GetContentScale().x, GetContentScale().y);
1856
1857 DlPaint paint;
1858 paint.setColor(DlColor::kRed());
1859 builder.DrawPaint(paint);
1860 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1861 paint.setColor(DlColor::kBlue());
1862 builder.SaveLayer(std::nullopt, &paint);
1863 builder.Restore();
1864
1865 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1866}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [259/662]

impeller::testing::TEST_P ( AiksTest  ,
EmptySaveLayerRendersWithClear   
)

Definition at line 1868 of file aiks_dl_basic_unittests.cc.

1868 {
1869 DisplayListBuilder builder;
1870 builder.Scale(GetContentScale().x, GetContentScale().y);
1871 auto image = DlImageImpeller::Make(CreateTextureForFixture("airplane.jpg"));
1872 builder.DrawImage(image, DlPoint(10, 10), {});
1873 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1874
1875 DlPaint paint;
1876 paint.setBlendMode(DlBlendMode::kClear);
1877 builder.SaveLayer(std::nullopt, &paint);
1878 builder.Restore();
1879
1880 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1881}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawImage(), image, impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), x, and y.

◆ TEST_P() [260/662]

impeller::testing::TEST_P ( AiksTest  ,
EmulatedAdvancedBlendRestore   
)

Definition at line 937 of file aiks_dl_blend_unittests.cc.

937 {
938 DisplayListBuilder builder;
939
940 builder.DrawPaint(DlPaint(DlColor::kWhite()));
941 builder.Save();
942 builder.ClipRect(DlRect::MakeLTRB(100, 100, 400, 300));
943
944 // Draw should apply the clip, even though it is an advanced blend.
945 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 300),
946 DlPaint()
947 .setColor(DlColor::kRed())
948 .setBlendMode(DlBlendMode::kDifference));
949 // This color should not show if clip is still functional.
950 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100),
951 DlPaint().setColor(DlColor::kBlue()));
952 builder.Restore();
953
954 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
955}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DisplayListBuilder::Restore(), and flutter::DisplayListBuilder::Save().

◆ TEST_P() [261/662]

impeller::testing::TEST_P ( AiksTest  ,
FastEllipticalRRectMaskBlursRenderCorrectly   
)

Definition at line 2276 of file aiks_dl_basic_unittests.cc.

2276 {
2277 DisplayListBuilder builder;
2278
2279 builder.Scale(GetContentScale().x, GetContentScale().y);
2280 DlPaint paint;
2281 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1));
2282
2283 DlPaint save_paint;
2284 save_paint.setColor(DlColor::kWhite());
2285 builder.DrawPaint(save_paint);
2286
2287 paint.setColor(DlColor::kBlue());
2288 for (int i = 0; i < 5; i++) {
2289 Scalar y = i * 125;
2290 Scalar y_radius = i * 15;
2291 for (int j = 0; j < 5; j++) {
2292 Scalar x = j * 125;
2293 Scalar x_radius = j * 15;
2294 builder.DrawRoundRect(
2295 DlRoundRect::MakeRectXY(
2296 DlRect::MakeXYWH(x + 50, y + 50, 100.0f, 100.0f), //
2297 x_radius, y_radius),
2298 paint);
2299 }
2300 }
2301
2302 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2303}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRoundRect(), i, flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DlBlurMaskFilter::Make(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), x, and y.

◆ TEST_P() [262/662]

impeller::testing::TEST_P ( AiksTest  ,
FastGradientTestHorizontal   
)

Definition at line 845 of file aiks_dl_gradient_unittests.cc.

845 {
846 DisplayListBuilder builder;
847 DlPaint paint;
848 builder.Translate(100.0f, 0);
849
850 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue(),
852 std::vector<Scalar> stops = {0.0, 0.1, 1.0};
853
854 paint.setColorSource(DlColorSource::MakeLinear({0, 0}, {300, 0}, stops.size(),
855 colors.data(), stops.data(),
856 DlTileMode::kClamp));
857
858 paint.setColor(DlColor::kWhite());
859 builder.DrawRect(DlRect::MakeXYWH(0, 0, 300, 300), paint);
860 builder.Translate(400, 0);
861 builder.DrawRoundRect(
862 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(0, 0, 300, 300), 4, 4), paint);
863
864 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
865}
static RoundRect MakeRectXY(const Rect &rect, Scalar x_radius, Scalar y_radius)
Definition round_rect.h:31

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlColorSource::MakeLinear(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [263/662]

impeller::testing::TEST_P ( AiksTest  ,
FastGradientTestHorizontalReversed   
)

Definition at line 891 of file aiks_dl_gradient_unittests.cc.

891 {
892 DisplayListBuilder builder;
893 DlPaint paint;
894 builder.Translate(100.0f, 0);
895
896 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue(),
898 std::vector<Scalar> stops = {0.0, 0.1, 1.0};
899
900 paint.setColorSource(DlColorSource::MakeLinear({300, 0}, {0, 0}, stops.size(),
901 colors.data(), stops.data(),
902 DlTileMode::kClamp));
903
904 paint.setColor(DlColor::kWhite());
905 builder.DrawRect(DlRect::MakeXYWH(0, 0, 300, 300), paint);
906 builder.Translate(400, 0);
907 builder.DrawRoundRect(
908 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(0, 0, 300, 300), 4, 4), paint);
909
910 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
911}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlColorSource::MakeLinear(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [264/662]

impeller::testing::TEST_P ( AiksTest  ,
FastGradientTestVertical   
)

Definition at line 868 of file aiks_dl_gradient_unittests.cc.

868 {
869 DisplayListBuilder builder;
870 DlPaint paint;
871 builder.Translate(100.0f, 0);
872
873 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue(),
875 std::vector<Scalar> stops = {0.0, 0.1, 1.0};
876
877 paint.setColorSource(DlColorSource::MakeLinear({0, 0}, {0, 300}, stops.size(),
878 colors.data(), stops.data(),
879 DlTileMode::kClamp));
880
881 paint.setColor(DlColor::kWhite());
882 builder.DrawRect(DlRect::MakeXYWH(0, 0, 300, 300), paint);
883 builder.Translate(400, 0);
884 builder.DrawRoundRect(
885 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(0, 0, 300, 300), 4, 4), paint);
886
887 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
888}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlColorSource::MakeLinear(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [265/662]

impeller::testing::TEST_P ( AiksTest  ,
FastGradientTestVerticalReversed   
)

Definition at line 914 of file aiks_dl_gradient_unittests.cc.

914 {
915 DisplayListBuilder builder;
916 DlPaint paint;
917 builder.Translate(100.0f, 0);
918
919 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue(),
921 std::vector<Scalar> stops = {0.0, 0.1, 1.0};
922
923 paint.setColorSource(DlColorSource::MakeLinear({0, 300}, {0, 0}, stops.size(),
924 colors.data(), stops.data(),
925 DlTileMode::kClamp));
926
927 paint.setColor(DlColor::kWhite());
928 builder.DrawRect(DlRect::MakeXYWH(0, 0, 300, 300), paint);
929 builder.Translate(400, 0);
930 builder.DrawRoundRect(
931 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(0, 0, 300, 300), 4, 4), paint);
932
933 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
934}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlColorSource::MakeLinear(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [266/662]

impeller::testing::TEST_P ( AiksTest  ,
FatStrokeArc   
)

Definition at line 763 of file aiks_dl_path_unittests.cc.

763 {
764 DlScalar stroke_width = 300;
765 DlScalar aspect = 1.0;
766 DlScalar start_angle = 0;
767 DlScalar end_angle = 90;
768 auto callback = [&]() -> sk_sp<DisplayList> {
769 if (IsPlaygroundEnabled()) {
770 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
771 ImGui::SliderFloat("Stroke Width", &stroke_width, 1, 300);
772 ImGui::SliderFloat("Aspect", &aspect, 0.5, 2.0);
773 ImGui::SliderFloat("Start Angle", &start_angle, 0, 360);
774 ImGui::SliderFloat("End Angle", &end_angle, 0, 360);
775 ImGui::End();
776 }
777
778 DisplayListBuilder builder;
779 DlPaint grey_paint;
780 grey_paint.setColor(DlColor(0xff111111));
781 builder.DrawPaint(grey_paint);
782
783 DlPaint white_paint;
784 white_paint.setColor(DlColor::kWhite());
785 white_paint.setStrokeWidth(stroke_width);
786 white_paint.setDrawStyle(DlDrawStyle::kStroke);
787 DlPaint red_paint;
788 red_paint.setColor(DlColor::kRed());
789
790 Rect rect = Rect::MakeXYWH(100, 100, 100, aspect * 100);
791 builder.DrawRect(rect, red_paint);
792 builder.DrawArc(rect, start_angle, end_angle,
793 /*useCenter=*/false, white_paint);
794 DlScalar frontier = rect.GetRight() + stroke_width / 2.0;
795 builder.DrawLine(Point(frontier, 0), Point(frontier, 150), red_paint);
796
797 return builder.Build();
798 };
799 ASSERT_TRUE(OpenPlaygroundHere(callback));
800}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawArc(), flutter::DisplayListBuilder::DrawLine(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [267/662]

impeller::testing::TEST_P ( AiksTest  ,
FilledArcsRenderCorrectly   
)

Definition at line 1057 of file aiks_dl_basic_unittests.cc.

1057 {
1058 DisplayListBuilder builder;
1059 builder.Scale(GetContentScale().x, GetContentScale().y);
1060 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1061
1062 DlPaint paint;
1063 paint.setColor(DlColor::kBlue());
1064
1065 RenderArcFarm(builder, paint,
1066 {
1067 .use_center = false,
1068 .full_circles = false,
1069 });
1070
1071 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1072}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [268/662]

impeller::testing::TEST_P ( AiksTest  ,
FilledArcsRenderCorrectlyWithCenter   
)

Definition at line 1091 of file aiks_dl_basic_unittests.cc.

1091 {
1092 DisplayListBuilder builder;
1093 builder.Scale(GetContentScale().x, GetContentScale().y);
1094 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1095
1096 DlPaint paint;
1097 paint.setColor(DlColor::kBlue());
1098
1099 RenderArcFarm(builder, paint,
1100 {
1101 .use_center = true,
1102 .full_circles = false,
1103 });
1104
1105 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1106}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [269/662]

impeller::testing::TEST_P ( AiksTest  ,
FilledCirclesRenderCorrectly   
)

Definition at line 673 of file aiks_dl_basic_unittests.cc.

673 {
674 DisplayListBuilder builder;
675 builder.Scale(GetContentScale().x, GetContentScale().y);
676 DlPaint paint;
677 const int color_count = 3;
678 DlColor colors[color_count] = {
679 DlColor::kBlue(),
680 DlColor::kGreen(),
681 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
682 };
683
684 paint.setColor(DlColor::kWhite());
685 builder.DrawPaint(paint);
686
687 int c_index = 0;
688 int radius = 600;
689 while (radius > 0) {
690 paint.setColor(colors[(c_index++) % color_count]);
691 builder.DrawCircle(DlPoint(10, 10), radius, paint);
692 if (radius > 30) {
693 radius -= 10;
694 } else {
695 radius -= 2;
696 }
697 }
698
699 DlColor gradient_colors[7] = {
700 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
701 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
702 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
703 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
704 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
705 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
706 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
707 };
708 DlScalar stops[7] = {
709 0.0,
710 (1.0 / 6.0) * 1,
711 (1.0 / 6.0) * 2,
712 (1.0 / 6.0) * 3,
713 (1.0 / 6.0) * 4,
714 (1.0 / 6.0) * 5,
715 1.0,
716 };
717 auto texture = CreateTextureForFixture("airplane.jpg",
718 /*enable_mipmapping=*/true);
719 auto image = DlImageImpeller::Make(texture);
720
721 paint.setColorSource(DlColorSource::MakeRadial(
722 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
723 builder.DrawCircle(DlPoint(500, 600), 100, paint);
724
725 DlMatrix local_matrix = DlMatrix::MakeTranslation({700, 200});
726 paint.setColorSource(DlColorSource::MakeImage(
727 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
728 DlImageSampling::kNearestNeighbor, &local_matrix));
729 builder.DrawCircle(DlPoint(800, 300), 100, paint);
730
731 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
732}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), image, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), flutter::DlColorSource::MakeRadial(), impeller::Matrix::MakeTranslation(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), texture, x, and y.

◆ TEST_P() [270/662]

impeller::testing::TEST_P ( AiksTest  ,
FilledEllipsesRenderCorrectly   
)

Definition at line 936 of file aiks_dl_basic_unittests.cc.

936 {
937 DisplayListBuilder builder;
938 builder.Scale(GetContentScale().x, GetContentScale().y);
939 DlPaint paint;
940 const int color_count = 3;
941 DlColor colors[color_count] = {
942 DlColor::kBlue(),
943 DlColor::kGreen(),
944 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
945 };
946
947 paint.setColor(DlColor::kWhite());
948 builder.DrawPaint(paint);
949
950 int c_index = 0;
951 int long_radius = 600;
952 int short_radius = 600;
953 while (long_radius > 0 && short_radius > 0) {
954 paint.setColor(colors[(c_index++) % color_count]);
955 builder.DrawOval(
956 DlRect::MakeEllipseBounds({10, 10}, Size(long_radius, short_radius)),
957 paint);
958 builder.DrawOval(
959 DlRect::MakeEllipseBounds({1000, 750}, Size(short_radius, long_radius)),
960 paint);
961 if (short_radius > 30) {
962 short_radius -= 10;
963 long_radius -= 5;
964 } else {
965 short_radius -= 2;
966 long_radius -= 1;
967 }
968 }
969
970 DlColor gradient_colors[7] = {
971 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
972 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
973 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
974 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
975 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
976 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
977 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
978 };
979 DlScalar stops[7] = {
980 0.0,
981 (1.0 / 6.0) * 1,
982 (1.0 / 6.0) * 2,
983 (1.0 / 6.0) * 3,
984 (1.0 / 6.0) * 4,
985 (1.0 / 6.0) * 5,
986 1.0,
987 };
988 auto texture = CreateTextureForFixture("airplane.jpg",
989 /*enable_mipmapping=*/true);
990 auto image = DlImageImpeller::Make(texture);
991
992 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
993
994 paint.setColorSource(DlColorSource::MakeRadial(
995 DlPoint(300, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
996 builder.DrawOval(DlRect::MakeXYWH(200, 625, 200, 50), paint);
997 builder.DrawOval(DlRect::MakeXYWH(275, 550, 50, 200), paint);
998
999 DlMatrix local_matrix = DlMatrix::MakeTranslation({610, 15});
1000 paint.setColorSource(DlColorSource::MakeImage(
1001 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1002 DlImageSampling::kNearestNeighbor, &local_matrix));
1003 builder.DrawOval(DlRect::MakeXYWH(610, 90, 200, 50), paint);
1004 builder.DrawOval(DlRect::MakeXYWH(685, 15, 50, 200), paint);
1005
1006 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1007}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawOval(), flutter::DisplayListBuilder::DrawPaint(), image, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeEllipseBounds(), flutter::DlColorSource::MakeImage(), flutter::DlColorSource::MakeRadial(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), texture, x, and y.

◆ TEST_P() [271/662]

impeller::testing::TEST_P ( AiksTest  ,
FilledRoundRectPathsRenderCorrectly   
)

Definition at line 2010 of file aiks_dl_basic_unittests.cc.

2010 {
2011 DisplayListBuilder builder;
2012 builder.Scale(GetContentScale().x, GetContentScale().y);
2013
2014 DlPaint paint;
2015 const int color_count = 3;
2016 DlColor colors[color_count] = {
2017 DlColor::kBlue(),
2018 DlColor::kGreen(),
2019 DlColor::ARGB(1.0, 220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f),
2020 };
2021
2022 paint.setColor(DlColor::kWhite());
2023 builder.DrawPaint(paint);
2024
2025 auto draw_rrect_as_path = [&builder](const DlRect& rect, Scalar x, Scalar y,
2026 const DlPaint& paint) {
2027 builder.DrawPath(DlPath::MakeRoundRectXY(rect, x, y), paint);
2028 };
2029
2030 int c_index = 0;
2031 for (int i = 0; i < 4; i++) {
2032 for (int j = 0; j < 4; j++) {
2033 paint.setColor(colors[(c_index++) % color_count]);
2034 draw_rrect_as_path(DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
2035 i * 5 + 10, j * 5 + 10, paint);
2036 }
2037 }
2038 paint.setColor(colors[(c_index++) % color_count]);
2039 draw_rrect_as_path(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40, paint);
2040 paint.setColor(colors[(c_index++) % color_count]);
2041 draw_rrect_as_path(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40, paint);
2042
2043 std::vector<DlColor> gradient_colors = {
2044 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
2045 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
2046 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
2047 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
2048 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
2049 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
2050 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0)};
2051 std::vector<Scalar> stops = {
2052 0.0,
2053 (1.0 / 6.0) * 1,
2054 (1.0 / 6.0) * 2,
2055 (1.0 / 6.0) * 3,
2056 (1.0 / 6.0) * 4,
2057 (1.0 / 6.0) * 5,
2058 1.0,
2059 };
2060 auto texture = DlImageImpeller::Make(
2061 CreateTextureForFixture("airplane.jpg",
2062 /*enable_mipmapping=*/true));
2063
2064 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
2065 paint.setColorSource(DlColorSource::MakeRadial(
2066 /*center=*/DlPoint(550, 550),
2067 /*radius=*/75,
2068 /*stop_count=*/gradient_colors.size(),
2069 /*colors=*/gradient_colors.data(),
2070 /*stops=*/stops.data(),
2071 /*tile_mode=*/DlTileMode::kMirror));
2072 for (int i = 1; i <= 10; i++) {
2073 int j = 11 - i;
2074 draw_rrect_as_path(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20, //
2075 550 + i * 20, 550 + j * 20),
2076 i * 10, j * 10, paint);
2077 }
2078 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
2079 paint.setColorSource(DlColorSource::MakeRadial(
2080 /*center=*/DlPoint(200, 650),
2081 /*radius=*/75,
2082 /*stop_count=*/gradient_colors.size(),
2083 /*colors=*/gradient_colors.data(),
2084 /*stops=*/stops.data(),
2085 /*tile_mode=*/DlTileMode::kMirror));
2086 draw_rrect_as_path(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40, paint);
2087 draw_rrect_as_path(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40, paint);
2088
2089 auto matrix = DlMatrix::MakeTranslation({520, 20});
2090 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
2091 paint.setColorSource(DlColorSource::MakeImage(
2092 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
2093 DlImageSampling::kMipmapLinear, &matrix));
2094 for (int i = 1; i <= 10; i++) {
2095 int j = 11 - i;
2096 draw_rrect_as_path(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20, //
2097 720 + i * 20, 220 + j * 20),
2098 i * 10, j * 10, paint);
2099 }
2100 matrix = DlMatrix::MakeTranslation({800, 300});
2101 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
2102 paint.setColorSource(DlColorSource::MakeImage(
2103 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
2104 DlImageSampling::kMipmapLinear, &matrix));
2105
2106 draw_rrect_as_path(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40, paint);
2107 draw_rrect_as_path(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40, paint);
2108
2109 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2110}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), i, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlColorSource::MakeRadial(), flutter::DlPath::MakeRoundRectXY(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), texture, x, and y.

◆ TEST_P() [272/662]

impeller::testing::TEST_P ( AiksTest  ,
FilledRoundRectsRenderCorrectly   
)

Definition at line 1408 of file aiks_dl_basic_unittests.cc.

1408 {
1409 DisplayListBuilder builder;
1410 builder.Scale(GetContentScale().x, GetContentScale().y);
1411 DlPaint paint;
1412 const int color_count = 3;
1413 DlColor colors[color_count] = {
1414 DlColor::kBlue(),
1415 DlColor::kGreen(),
1416 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
1417 };
1418
1419 paint.setColor(DlColor::kWhite());
1420 builder.DrawPaint(paint);
1421
1422 int c_index = 0;
1423 for (int i = 0; i < 4; i++) {
1424 for (int j = 0; j < 4; j++) {
1425 paint.setColor(colors[(c_index++) % color_count]);
1426 builder.DrawRoundRect(
1427 DlRoundRect::MakeRectXY(
1428 DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80), //
1429 i * 5 + 10, j * 5 + 10),
1430 paint);
1431 }
1432 }
1433 paint.setColor(colors[(c_index++) % color_count]);
1434 builder.DrawRoundRect(
1435 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40),
1436 paint);
1437 paint.setColor(colors[(c_index++) % color_count]);
1438 builder.DrawRoundRect(
1439 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40),
1440 paint);
1441
1442 DlColor gradient_colors[7] = {
1443 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
1444 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
1445 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
1446 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
1447 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
1448 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
1449 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
1450 };
1451 DlScalar stops[7] = {
1452 0.0,
1453 (1.0 / 6.0) * 1,
1454 (1.0 / 6.0) * 2,
1455 (1.0 / 6.0) * 3,
1456 (1.0 / 6.0) * 4,
1457 (1.0 / 6.0) * 5,
1458 1.0,
1459 };
1460 auto texture = CreateTextureForFixture("airplane.jpg",
1461 /*enable_mipmapping=*/true);
1462 auto image = DlImageImpeller::Make(texture);
1463
1464 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1465 paint.setColorSource(DlColorSource::MakeRadial(
1466 DlPoint(550, 550), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1467 for (int i = 1; i <= 10; i++) {
1468 int j = 11 - i;
1469 builder.DrawRoundRect(
1470 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20, //
1471 550 + i * 20, 550 + j * 20),
1472 i * 10, j * 10),
1473 paint);
1474 }
1475
1476 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1477 paint.setColorSource(DlColorSource::MakeRadial(
1478 DlPoint(200, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1479 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1480 builder.DrawRoundRect(
1481 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40),
1482 paint);
1483 builder.DrawRoundRect(
1484 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40),
1485 paint);
1486
1487 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1488 DlMatrix local_matrix = DlMatrix::MakeTranslation({520, 20});
1489 paint.setColorSource(DlColorSource::MakeImage(
1490 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1491 DlImageSampling::kNearestNeighbor, &local_matrix));
1492 for (int i = 1; i <= 10; i++) {
1493 int j = 11 - i;
1494 builder.DrawRoundRect(
1495 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20, //
1496 720 + i * 20, 220 + j * 20),
1497 i * 10, j * 10),
1498 paint);
1499 }
1500
1501 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1502 local_matrix = DlMatrix::MakeTranslation({800, 300});
1503 paint.setColorSource(DlColorSource::MakeImage(
1504 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1505 DlImageSampling::kNearestNeighbor, &local_matrix));
1506 builder.DrawRoundRect(
1507 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40),
1508 paint);
1509 builder.DrawRoundRect(
1510 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40),
1511 paint);
1512
1513 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1514}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRoundRect(), i, image, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlColorSource::MakeRadial(), impeller::RoundRect::MakeRectXY(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), texture, x, and y.

◆ TEST_P() [273/662]

impeller::testing::TEST_P ( AiksTest  ,
ForegroundAdvancedBlendAppliesTransformCorrectly   
)

Definition at line 742 of file aiks_dl_blend_unittests.cc.

742 {
743 auto texture = CreateTextureForFixture("airplane.jpg",
744 /*enable_mipmapping=*/true);
745
746 DisplayListBuilder builder;
747 builder.Rotate(30);
748
749 DlPaint image_paint;
750 image_paint.setColorFilter(DlColorFilter::MakeBlend(
751 DlColor::RGBA(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f),
752 DlBlendMode::kColorDodge));
753
754 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(200, 200),
755 DlImageSampling::kMipmapLinear, &image_paint);
756
757 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
758}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeBlend(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Rotate(), flutter::DlPaint::setColorFilter(), and texture.

◆ TEST_P() [274/662]

impeller::testing::TEST_P ( AiksTest  ,
ForegroundBlendSubpassCollapseOptimization   
)

Definition at line 476 of file aiks_dl_blend_unittests.cc.

476 {
477 DisplayListBuilder builder;
478
479 DlPaint save_paint;
480 save_paint.setColorFilter(
481 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kColorDodge));
482 builder.SaveLayer(std::nullopt, &save_paint);
483
484 builder.Translate(500, 300);
485 builder.Rotate(120);
486
487 DlPaint paint;
488 paint.setColor(DlColor::kBlue());
489 builder.DrawRect(DlRect::MakeXYWH(100, 100, 200, 200), paint);
490
491 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
492}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColorFilter::MakeBlend(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [275/662]

impeller::testing::TEST_P ( AiksTest  ,
ForegroundPipelineBlendAppliesTransformCorrectly   
)

Definition at line 724 of file aiks_dl_blend_unittests.cc.

724 {
725 auto texture = CreateTextureForFixture("airplane.jpg",
726 /*enable_mipmapping=*/true);
727
728 DisplayListBuilder builder;
729 builder.Rotate(30);
730
731 DlPaint image_paint;
732 image_paint.setColorFilter(DlColorFilter::MakeBlend(
733 DlColor::RGBA(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f),
734 DlBlendMode::kSrcIn));
735
736 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(200, 200),
737 DlImageSampling::kMipmapLinear, &image_paint);
738
739 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
740}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeBlend(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Rotate(), flutter::DlPaint::setColorFilter(), and texture.

◆ TEST_P() [276/662]

impeller::testing::TEST_P ( AiksTest  ,
FormatSRGB   
)

Definition at line 1923 of file aiks_dl_basic_unittests.cc.

1923 {
1924 PixelFormat pixel_format =
1925 GetContext()->GetCapabilities()->GetDefaultColorFormat();
1926 EXPECT_TRUE(pixel_format == PixelFormat::kR8G8B8A8UNormInt ||
1927 pixel_format == PixelFormat::kB8G8R8A8UNormInt)
1928 << "pixel format: " << PixelFormatToString(pixel_format);
1929}
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:99
constexpr const char * PixelFormatToString(PixelFormat format)
Definition formats.h:292

References impeller::kB8G8R8A8UNormInt, impeller::kR8G8B8A8UNormInt, and impeller::PixelFormatToString().

◆ TEST_P() [277/662]

impeller::testing::TEST_P ( AiksTest  ,
FormatWideGamut   
)

Definition at line 1912 of file aiks_dl_basic_unittests.cc.

1912 {
1913 // Must be called before any methods that use the context to ensure that
1914 // this test is always run with wide gamut support.
1915 if (!EnsureContextSupportsWideGamut()) {
1916 GTEST_SKIP() << "This backend doesn't yet support wide gamut.";
1917 }
1918
1919 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
1920 PixelFormat::kB10G10R10A10XR);
1921}

References impeller::kB10G10R10A10XR.

◆ TEST_P() [278/662]

impeller::testing::TEST_P ( AiksTest  ,
FramebufferAdvancedBlendCoverage   
)

Definition at line 760 of file aiks_dl_blend_unittests.cc.

760 {
761 auto texture = CreateTextureForFixture("airplane.jpg",
762 /*enable_mipmapping=*/true);
763
764 // Draw with an advanced blend that can use FramebufferBlendContents and
765 // verify that the scale transform is correctly applied to the image.
766 DisplayListBuilder builder;
767
768 DlPaint paint;
769 paint.setColor(
770 DlColor::RGBA(169.0f / 255.0f, 169.0f / 255.0f, 169.0f / 255.0f, 1.0f));
771 builder.DrawPaint(paint);
772 builder.Scale(0.4, 0.4);
773
774 DlPaint image_paint;
775 image_paint.setBlendMode(DlBlendMode::kMultiply);
776
777 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(20, 20),
778 DlImageSampling::kMipmapLinear, &image_paint);
779
780 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
781}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawPaint(), impeller::DlImageImpeller::Make(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), and texture.

◆ TEST_P() [279/662]

impeller::testing::TEST_P ( AiksTest  ,
FramebufferBlendsRespectClips   
)

If correct, this test should draw a green circle. If any red is visible, there is a depth bug.

Definition at line 118 of file aiks_dl_clip_unittests.cc.

118 {
119 DisplayListBuilder builder;
120
121 // Clear the whole canvas with white.
122 DlPaint paint;
123 paint.setColor(DlColor::kWhite());
124 builder.DrawPaint(paint);
125
126 builder.ClipPath(DlPath::MakeCircle(DlPoint(150, 150), 50),
127 DlClipOp::kIntersect);
128
129 // Draw a red rectangle that should not show through the circle clip.
130 paint.setColor(DlColor::kRed());
131 paint.setBlendMode(DlBlendMode::kMultiply);
132 builder.DrawRect(DlRect::MakeXYWH(100, 100, 100, 100), paint);
133
134 // Draw a green circle that shows through the clip.
135 paint.setColor(DlColor::kGreen());
136 paint.setBlendMode(DlBlendMode::kSrcOver);
137 builder.DrawCircle(DlPoint(150, 150), 50, paint);
138
139 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
140}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipPath(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlPath::MakeCircle(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [280/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurAnimatedBackdrop   
)

Definition at line 949 of file aiks_dl_blur_unittests.cc.

949 {
950 // This test is for checking out how stable rendering is when content is
951 // translated underneath a blur. Animating under a blur can cause
952 // *shimmering* to happen as a result of pixel alignment.
953 // See also: https://github.com/flutter/flutter/issues/140193
954 auto boston =
955 CreateTextureForFixture("boston.jpg", /*enable_mipmapping=*/true);
956 ASSERT_TRUE(boston);
957 int64_t count = 0;
958 Scalar sigma = 20.0;
959 Scalar freq = 0.1;
960 Scalar amp = 50.0;
961 auto callback = [&]() -> sk_sp<DisplayList> {
962 if (IsPlaygroundEnabled()) {
963 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
964 ImGui::SliderFloat("Sigma", &sigma, 0, 200);
965 ImGui::SliderFloat("Frequency", &freq, 0.01, 2.0);
966 ImGui::SliderFloat("Amplitude", &amp, 1, 100);
967 ImGui::End();
968 }
969
970 DisplayListBuilder builder;
971 builder.Scale(GetContentScale().x, GetContentScale().y);
972 Scalar y = amp * sin(freq * 2.0 * M_PI * count / 60);
973 builder.DrawImage(DlImageImpeller::Make(boston),
974 DlPoint(1024 / 2 - boston->GetSize().width / 2,
975 (768 / 2 - boston->GetSize().height / 2) + y),
976 DlImageSampling::kMipmapLinear);
977 static PlaygroundPoint point_a(Point(100, 100), 20, Color::Red());
978 static PlaygroundPoint point_b(Point(900, 700), 20, Color::Red());
979 auto [handle_a, handle_b] = DrawPlaygroundLine(point_a, point_b);
980
981 builder.ClipRect(
982 DlRect::MakeLTRB(handle_a.x, handle_a.y, handle_b.x, handle_b.y));
983 builder.ClipRect(DlRect::MakeLTRB(100, 100, 900, 700));
984
985 DlPaint paint;
986 paint.setBlendMode(DlBlendMode::kSrc);
987
988 auto backdrop_filter =
989 DlImageFilter::MakeBlur(sigma, sigma, DlTileMode::kClamp);
990 builder.SaveLayer(std::nullopt, &paint, backdrop_filter.get());
991 count += 1;
992 return builder.Build();
993 };
994 ASSERT_TRUE(OpenPlaygroundHere(callback));
995}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawImage(), impeller::DrawPlaygroundLine(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Color::Red(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), x, and y.

◆ TEST_P() [281/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurAtPeripheryHorizontal   
)

Definition at line 920 of file aiks_dl_blur_unittests.cc.

920 {
921 DisplayListBuilder builder;
922
923 builder.Scale(GetContentScale().x, GetContentScale().y);
924 std::shared_ptr<Texture> boston = CreateTextureForFixture("boston.jpg");
925 builder.DrawImageRect(
926 DlImageImpeller::Make(boston),
927 DlRect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height),
928 DlRect::MakeLTRB(0, 0, GetWindowSize().width, 100),
929 DlImageSampling::kNearestNeighbor);
930
931 DlPaint paint;
932 paint.setColor(DlColor::kMagenta());
933
934 DlRoundRect rrect = DlRoundRect::MakeRectXY(
935 DlRect::MakeLTRB(0, 110, GetWindowSize().width, 210), 10, 10);
936 builder.DrawRoundRect(rrect, paint);
937 builder.ClipRect(DlRect::MakeLTRB(0, 50, GetWindowSize().width, 150));
938
939 DlPaint save_paint;
940 save_paint.setBlendMode(DlBlendMode::kSrc);
941
942 auto backdrop_filter = DlImageFilter::MakeBlur(20, 20, DlTileMode::kClamp);
943 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
944
945 builder.Restore();
946 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
947}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawImageRect(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kMagenta(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), width, x, and y.

◆ TEST_P() [282/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurAtPeripheryVertical   
)

Definition at line 892 of file aiks_dl_blur_unittests.cc.

892 {
893 DisplayListBuilder builder;
894
895 DlPaint paint;
896 builder.Scale(GetContentScale().x, GetContentScale().y);
897
898 paint.setColor(DlColor::kLimeGreen());
899 DlRoundRect rrect = DlRoundRect::MakeRectXY(
900 DlRect::MakeLTRB(0, 0, GetWindowSize().width, 100), 10, 10);
901 builder.DrawRoundRect(rrect, paint);
902
903 paint.setColor(DlColor::kMagenta());
904 rrect = DlRoundRect::MakeRectXY(
905 DlRect::MakeLTRB(0, 110, GetWindowSize().width, 210), 10, 10);
906 builder.DrawRoundRect(rrect, paint);
907 builder.ClipRect(DlRect::MakeLTRB(100, 0, 200, GetWindowSize().height));
908
909 DlPaint save_paint;
910 save_paint.setBlendMode(DlBlendMode::kSrc);
911
912 auto backdrop_filter = DlImageFilter::MakeBlur(20, 20, DlTileMode::kClamp);
913
914 builder.SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
915 builder.Restore();
916
917 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
918}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawRoundRect(), height, flutter::DlColor::kLimeGreen(), flutter::DlColor::kMagenta(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundRect::MakeRectXY(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), width, x, and y.

◆ TEST_P() [283/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurBackdropTinyMipMap   
)

Definition at line 1381 of file aiks_dl_blur_unittests.cc.

1381 {
1382 AiksContext renderer(GetContext(), nullptr);
1383 for (int32_t i = 1; i < 5; ++i) {
1384 DisplayListBuilder builder;
1385
1386 ISize clip_size = ISize(i, i);
1387 builder.Save();
1388 builder.ClipRect(
1389 DlRect::MakeXYWH(400, 400, clip_size.width, clip_size.height));
1390
1391 DlPaint paint;
1392 paint.setColor(DlColor::kGreen());
1393 auto blur_filter = DlImageFilter::MakeBlur(0.1, 0.1, DlTileMode::kDecal);
1394 paint.setImageFilter(blur_filter);
1395
1396 builder.DrawCircle(DlPoint(400, 400), 200, paint);
1397 builder.Restore();
1398
1399 auto image = DisplayListToTexture(builder.Build(), {1024, 768}, renderer);
1400 EXPECT_TRUE(image) << " length " << i;
1401 }
1402}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawCircle(), impeller::TSize< T >::height, i, image, flutter::DlColor::kGreen(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), and impeller::TSize< T >::width.

◆ TEST_P() [284/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurFlipped   
)

Definition at line 1516 of file aiks_dl_blur_unittests.cc.

1516 {
1517 DisplayListBuilder builder;
1518 builder.Scale(GetContentScale().x, GetContentScale().y);
1519
1520 builder.DrawRect(DlRect::MakeXYWH(0, 0, 350, 350),
1521 DlPaint().setColor(DlColor::kWhite()));
1522
1523 builder.Save();
1524 builder.Scale(-1, 1);
1525 DlPaint paint;
1526 paint.setImageFilter(DlBlurImageFilter::Make(10, 10, DlTileMode::kDecal));
1527 builder.SaveLayer(DlRect::MakeLTRB(-150, 100, 150, 200), &paint);
1528 builder.DrawRect(DlRect::MakeLTRB(-150, 0, 150, 300),
1529 DlPaint().setColor(DlColor::kRed()));
1530 builder.Restore();
1531 builder.Restore();
1532
1533 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1534}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlBlurImageFilter::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setImageFilter(), x, and y.

◆ TEST_P() [285/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurOneDimension   
)

Definition at line 1194 of file aiks_dl_blur_unittests.cc.

1194 {
1195 DisplayListBuilder builder;
1196
1197 builder.Scale(GetContentScale().x, GetContentScale().y);
1198 builder.Scale(0.5, 0.5);
1199
1200 std::shared_ptr<Texture> boston = CreateTextureForFixture("boston.jpg");
1201 builder.DrawImage(DlImageImpeller::Make(boston), DlPoint(100, 100), {});
1202
1203 DlPaint paint;
1204 paint.setBlendMode(DlBlendMode::kSrc);
1205
1206 auto backdrop_filter = DlImageFilter::MakeBlur(50, 0, DlTileMode::kClamp);
1207 builder.SaveLayer(std::nullopt, &paint, backdrop_filter.get());
1208 builder.Restore();
1209 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1210}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setBlendMode(), x, and y.

◆ TEST_P() [286/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurRotatedAndClipped   
)

Definition at line 1216 of file aiks_dl_blur_unittests.cc.

1216 {
1217 DisplayListBuilder builder;
1218
1219 std::shared_ptr<Texture> boston = CreateTextureForFixture("boston.jpg");
1220 Rect bounds =
1221 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
1222
1223 DlPaint paint;
1224 paint.setImageFilter(DlImageFilter::MakeBlur(20, 20, DlTileMode::kDecal));
1225
1226 Vector2 image_center = Vector2(bounds.GetSize() / 2);
1227 Vector2 clip_size = {150, 75};
1228 Vector2 center = Vector2(1024, 768) / 2;
1229 builder.Scale(GetContentScale().x, GetContentScale().y);
1230
1231 auto clip_bounds = Rect::MakeEllipseBounds(center, clip_size);
1232 builder.ClipRect(DlRect::MakeLTRB(clip_bounds.GetLeft(), clip_bounds.GetTop(),
1233 clip_bounds.GetRight(),
1234 clip_bounds.GetBottom()));
1235 builder.Translate(center.x, center.y);
1236 builder.Scale(0.6, 0.6);
1237 builder.Rotate(25);
1238
1239 auto dst_rect = bounds.Shift(-image_center);
1240 builder.DrawImageRect(
1241 DlImageImpeller::Make(boston), /*src=*/
1242 DlRect::MakeLTRB(bounds.GetLeft(), bounds.GetTop(), bounds.GetRight(),
1243 bounds.GetBottom()),
1244 /*dst=*/
1245 DlRect::MakeLTRB(dst_rect.GetLeft(), dst_rect.GetTop(),
1246 dst_rect.GetRight(), dst_rect.GetBottom()),
1247 DlImageSampling::kMipmapLinear, &paint);
1248
1249 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1250}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawImageRect(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeEllipseBounds(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setImageFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [287/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurRotatedAndClippedInteractive   
)

Definition at line 1139 of file aiks_dl_blur_unittests.cc.

1139 {
1140 std::shared_ptr<Texture> boston = CreateTextureForFixture("boston.jpg");
1141
1142 auto callback = [&]() -> sk_sp<DisplayList> {
1143 const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
1144 const DlTileMode tile_modes[] = {DlTileMode::kClamp, DlTileMode::kRepeat,
1145 DlTileMode::kMirror, DlTileMode::kDecal};
1146
1147 static float rotation = 0;
1148 static float scale = 0.6;
1149 static int selected_tile_mode = 3;
1150
1151 if (IsPlaygroundEnabled()) {
1152 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1153 ImGui::SliderFloat("Rotation (degrees)", &rotation, -180, 180);
1154 ImGui::SliderFloat("Scale", &scale, 0, 2.0);
1155 ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
1156 sizeof(tile_mode_names) / sizeof(char*));
1157 ImGui::End();
1158 }
1159
1160 DisplayListBuilder builder;
1161 Rect bounds =
1162 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
1163 Vector2 image_center = Vector2(bounds.GetSize() / 2);
1164 DlPaint paint;
1165 paint.setImageFilter(
1166 DlImageFilter::MakeBlur(20, 20, tile_modes[selected_tile_mode]));
1167
1168 static PlaygroundPoint point_a(Point(362, 309), 20, Color::Red());
1169 static PlaygroundPoint point_b(Point(662, 459), 20, Color::Red());
1170 auto [handle_a, handle_b] = DrawPlaygroundLine(point_a, point_b);
1171 Vector2 center = Vector2(1024, 768) / 2;
1172
1173 builder.Scale(GetContentScale().x, GetContentScale().y);
1174 builder.ClipRect(
1175 DlRect::MakeLTRB(handle_a.x, handle_a.y, handle_b.x, handle_b.y));
1176 builder.Translate(center.x, center.y);
1177 builder.Scale(scale, scale);
1178 builder.Rotate(rotation);
1179
1180 DlRect sk_bounds = DlRect::MakeLTRB(bounds.GetLeft(), bounds.GetTop(),
1181 bounds.GetRight(), bounds.GetBottom());
1182 Rect dest = bounds.Shift(-image_center);
1183 DlRect sk_dst = DlRect::MakeLTRB(dest.GetLeft(), dest.GetTop(),
1184 dest.GetRight(), dest.GetBottom());
1185 builder.DrawImageRect(DlImageImpeller::Make(boston), /*src=*/sk_bounds,
1186 /*dst=*/sk_dst, DlImageSampling::kNearestNeighbor,
1187 &paint);
1188 return builder.Build();
1189 };
1190
1191 ASSERT_TRUE(OpenPlaygroundHere(callback));
1192}
impeller::Rect DlRect
constexpr TPoint Rotate(const Radians &angle) const
Definition point.h:315
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
Definition rect.h:636

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawImageRect(), impeller::DrawPlaygroundLine(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeXYWH(), impeller::Color::Red(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setImageFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [288/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurRotatedNonUniform   
)

Definition at line 1252 of file aiks_dl_blur_unittests.cc.

1252 {
1253 auto callback = [&]() -> sk_sp<DisplayList> {
1254 const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
1255 const DlTileMode tile_modes[] = {DlTileMode::kClamp, DlTileMode::kRepeat,
1256 DlTileMode::kMirror, DlTileMode::kDecal};
1257
1258 static float rotation = 45;
1259 static float scale = 0.6;
1260 static int selected_tile_mode = 3;
1261
1262 if (IsPlaygroundEnabled()) {
1263 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1264 ImGui::SliderFloat("Rotation (degrees)", &rotation, -180, 180);
1265 ImGui::SliderFloat("Scale", &scale, 0, 2.0);
1266 ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
1267 sizeof(tile_mode_names) / sizeof(char*));
1268 ImGui::End();
1269 }
1270
1271 DisplayListBuilder builder;
1272
1273 DlPaint paint;
1274 paint.setColor(DlColor::kGreen());
1275 paint.setImageFilter(
1276 DlImageFilter::MakeBlur(50, 0, tile_modes[selected_tile_mode]));
1277
1278 Vector2 center = Vector2(1024, 768) / 2;
1279 builder.Scale(GetContentScale().x, GetContentScale().y);
1280 builder.Translate(center.x, center.y);
1281 builder.Scale(scale, scale);
1282 builder.Rotate(rotation);
1283
1284 DlRoundRect rrect =
1285 DlRoundRect::MakeRectXY(DlRect::MakeCircleBounds({0, 0}, 100), 10, 10);
1286 builder.DrawRoundRect(rrect, paint);
1287 return builder.Build();
1288 };
1289
1290 ASSERT_TRUE(OpenPlaygroundHere(callback));
1291}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kGreen(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeCircleBounds(), impeller::RoundRect::MakeRectXY(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [289/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurScaledAndClipped   
)

Definition at line 1107 of file aiks_dl_blur_unittests.cc.

1107 {
1108 DisplayListBuilder builder;
1109 std::shared_ptr<Texture> boston = CreateTextureForFixture("boston.jpg");
1110 Rect bounds =
1111 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
1112 Vector2 image_center = Vector2(bounds.GetSize() / 2);
1113
1114 DlPaint paint;
1115 paint.setImageFilter(DlImageFilter::MakeBlur(20, 20, DlTileMode::kDecal));
1116
1117 Vector2 clip_size = {150, 75};
1118 Vector2 center = Vector2(1024, 768) / 2;
1119 builder.Scale(GetContentScale().x, GetContentScale().y);
1120
1121 auto rect = Rect::MakeEllipseBounds(center, clip_size);
1122 builder.ClipRect(DlRect::MakeLTRB(rect.GetLeft(), rect.GetTop(),
1123 rect.GetRight(), rect.GetBottom()));
1124 builder.Translate(center.x, center.y);
1125 builder.Scale(0.6, 0.6);
1126
1127 DlRect sk_bounds = DlRect::MakeLTRB(bounds.GetLeft(), bounds.GetTop(),
1128 bounds.GetRight(), bounds.GetBottom());
1129 Rect dest = bounds.Shift(-image_center);
1130 DlRect sk_dst = DlRect::MakeLTRB(dest.GetLeft(), dest.GetTop(),
1131 dest.GetRight(), dest.GetBottom());
1132 builder.DrawImageRect(DlImageImpeller::Make(boston), /*src=*/sk_bounds,
1133 /*dst=*/sk_dst, DlImageSampling::kNearestNeighbor,
1134 &paint);
1135
1136 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1137}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawImageRect(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeEllipseBounds(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setImageFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [290/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurSolidColorTinyMipMap   
)

Definition at line 1356 of file aiks_dl_blur_unittests.cc.

1356 {
1357 AiksContext renderer(GetContext(), nullptr);
1358
1359 for (int32_t i = 1; i < 5; ++i) {
1360 DisplayListBuilder builder;
1361 Scalar fi = i;
1362 DlPathBuilder path_builder;
1363 path_builder.MoveTo(DlPoint(100, 100));
1364 path_builder.LineTo(DlPoint(100 + fi, 100 + fi));
1365
1366 DlPaint paint;
1367 paint.setColor(DlColor::kChartreuse());
1368 auto blur_filter = DlImageFilter::MakeBlur(0.1, 0.1, DlTileMode::kClamp);
1369 paint.setImageFilter(blur_filter);
1370
1371 builder.DrawPath(path_builder.TakePath(), paint);
1372
1373 auto image = DisplayListToTexture(builder.Build(), {1024, 768}, renderer);
1374 EXPECT_TRUE(image) << " length " << i;
1375 }
1376}

References flutter::DisplayListBuilder::Build(), impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawPath(), i, image, flutter::DlColor::kChartreuse(), flutter::DlPathBuilder::LineTo(), flutter::DlImageFilter::MakeBlur(), flutter::DlPathBuilder::MoveTo(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), and flutter::DlPathBuilder::TakePath().

◆ TEST_P() [291/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurStyleInner   
)

Definition at line 747 of file aiks_dl_blur_unittests.cc.

747 {
748 DisplayListBuilder builder;
749 builder.Scale(GetContentScale().x, GetContentScale().y);
750
751 DlPaint paint;
752 paint.setColor(DlColor::RGBA(0.1, 0.1, 0.1, 1));
753 builder.DrawPaint(paint);
754
755 paint.setColor(DlColor::kGreen());
756 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kInner, 30));
757
758 DlPathBuilder path_builder;
759 path_builder.MoveTo(DlPoint(200, 200));
760 path_builder.LineTo(DlPoint(300, 400));
761 path_builder.LineTo(DlPoint(100, 400));
762 path_builder.Close();
763
764 builder.DrawPath(path_builder.TakePath(), paint);
765
766 // Draw another thing to make sure the clip area is reset.
767 DlPaint red;
768 red.setColor(DlColor::kRed());
769 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), red);
770
771 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
772}

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), flutter::DlBlurMaskFilter::Make(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPathBuilder::MoveTo(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [292/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurStyleInnerGradient   
)

Definition at line 997 of file aiks_dl_blur_unittests.cc.

997 {
998 DisplayListBuilder builder;
999
1000 builder.Scale(GetContentScale().x, GetContentScale().y);
1001
1002 DlPaint paint;
1003 paint.setColor(DlColor::RGBA(0.1, 0.1, 0.1, 1.0));
1004 builder.DrawPaint(paint);
1005
1006 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
1007 DlColor::RGBA(0.7568, 0.2627, 0.2118, 1.0)};
1008 std::vector<Scalar> stops = {0.0, 1.0};
1009
1010 paint = DlPaint{};
1011 paint.setColorSource(DlColorSource::MakeLinear(
1012 /*start_point=*/{0, 0},
1013 /*end_point=*/{200, 200},
1014 /*stop_count=*/colors.size(),
1015 /*colors=*/colors.data(),
1016 /*stops=*/stops.data(),
1017 /*tile_mode=*/DlTileMode::kMirror));
1018 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kInner, 30));
1019
1020 DlPathBuilder path_builder;
1021 path_builder.MoveTo(DlPoint(200, 200));
1022 path_builder.LineTo(DlPoint(300, 400));
1023 path_builder.LineTo(DlPoint(100, 400));
1024 path_builder.Close();
1025 builder.DrawPath(path_builder.TakePath(), paint);
1026
1027 // Draw another thing to make sure the clip area is reset.
1028 DlPaint red;
1029 red.setColor(DlColor::kRed());
1030 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), red);
1031
1032 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1033}

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), flutter::DlBlurMaskFilter::Make(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPathBuilder::MoveTo(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setMaskFilter(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [293/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurStyleOuter   
)

Definition at line 774 of file aiks_dl_blur_unittests.cc.

774 {
775 DisplayListBuilder builder;
776 builder.Scale(GetContentScale().x, GetContentScale().y);
777
778 DlPaint paint;
779 paint.setColor(DlColor::RGBA(0.1, 0.1, 0.1, 1.0));
780 builder.DrawPaint(paint);
781
782 paint.setColor(DlColor::kGreen());
783 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kOuter, 30));
784
785 DlPathBuilder path_builder;
786 path_builder.MoveTo(DlPoint(200, 200));
787 path_builder.LineTo(DlPoint(300, 400));
788 path_builder.LineTo(DlPoint(100, 400));
789 path_builder.Close();
790
791 builder.DrawPath(path_builder.TakePath(), paint);
792
793 // Draw another thing to make sure the clip area is reset.
794 DlPaint red;
795 red.setColor(DlColor::kRed());
796 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), red);
797
798 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
799}

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), flutter::DlBlurMaskFilter::Make(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPathBuilder::MoveTo(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [294/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurStyleOuterGradient   
)

Definition at line 1071 of file aiks_dl_blur_unittests.cc.

1071 {
1072 DisplayListBuilder builder;
1073 builder.Scale(GetContentScale().x, GetContentScale().y);
1074
1075 DlPaint paint;
1076 paint.setColor(DlColor::RGBA(0.1, 0.1, 0.1, 1.0));
1077 builder.DrawPaint(paint);
1078
1079 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
1080 DlColor::RGBA(0.7568, 0.2627, 0.2118, 1.0)};
1081 std::vector<Scalar> stops = {0.0, 1.0};
1082
1083 paint = DlPaint{};
1084 paint.setColorSource(DlColorSource::MakeLinear(
1085 /*start_point=*/{0, 0},
1086 /*end_point=*/{200, 200},
1087 /*stop_count=*/colors.size(),
1088 /*colors=*/colors.data(),
1089 /*stops=*/stops.data(),
1090 /*tile_mode=*/DlTileMode::kMirror));
1091 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kOuter, 30));
1092
1093 DlPathBuilder path_builder;
1094 path_builder.MoveTo(DlPoint(200, 200));
1095 path_builder.LineTo(DlPoint(300, 400));
1096 path_builder.LineTo(DlPoint(100, 400));
1097 path_builder.Close();
1098 builder.DrawPath(path_builder.TakePath(), paint);
1099
1100 // Draw another thing to make sure the clip area is reset.
1101 DlPaint red;
1102 red.setColor(DlColor::kRed());
1103 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), red);
1104 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1105}

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), flutter::DlBlurMaskFilter::Make(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPathBuilder::MoveTo(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setMaskFilter(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [295/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurStyleSolid   
)

Definition at line 801 of file aiks_dl_blur_unittests.cc.

801 {
802 DisplayListBuilder builder;
803 builder.Scale(GetContentScale().x, GetContentScale().y);
804
805 DlPaint paint;
806 paint.setColor(DlColor::RGBA(0.1, 0.1, 0.1, 1.0));
807 builder.DrawPaint(paint);
808
809 paint.setColor(DlColor::kGreen());
810 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kSolid, 30));
811
812 DlPathBuilder path_builder;
813 path_builder.MoveTo(DlPoint(200, 200));
814 path_builder.LineTo(DlPoint(300, 400));
815 path_builder.LineTo(DlPoint(100, 400));
816 path_builder.Close();
817
818 builder.DrawPath(path_builder.TakePath(), paint);
819
820 // Draw another thing to make sure the clip area is reset.
821 DlPaint red;
822 red.setColor(DlColor::kRed());
823 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), red);
824
825 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
826}

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), flutter::DlBlurMaskFilter::Make(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPathBuilder::MoveTo(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [296/662]

impeller::testing::TEST_P ( AiksTest  ,
GaussianBlurStyleSolidGradient   
)

Definition at line 1035 of file aiks_dl_blur_unittests.cc.

1035 {
1036 DisplayListBuilder builder;
1037 builder.Scale(GetContentScale().x, GetContentScale().y);
1038
1039 DlPaint paint;
1040 paint.setColor(DlColor::RGBA(0.1, 0.1, 0.1, 1.0));
1041 builder.DrawPaint(paint);
1042
1043 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
1044 DlColor::RGBA(0.7568, 0.2627, 0.2118, 1.0)};
1045 std::vector<Scalar> stops = {0.0, 1.0};
1046
1047 paint = DlPaint{};
1048 paint.setColorSource(DlColorSource::MakeLinear(
1049 /*start_point=*/{0, 0},
1050 /*end_point=*/{200, 200},
1051 /*stop_count=*/colors.size(),
1052 /*colors=*/colors.data(),
1053 /*stops=*/stops.data(),
1054 /*tile_mode=*/DlTileMode::kMirror));
1055 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kSolid, 30));
1056
1057 DlPathBuilder path_builder;
1058 path_builder.MoveTo(DlPoint(200, 200));
1059 path_builder.LineTo(DlPoint(300, 400));
1060 path_builder.LineTo(DlPoint(100, 400));
1061 path_builder.Close();
1062 builder.DrawPath(path_builder.TakePath(), paint);
1063
1064 // Draw another thing to make sure the clip area is reset.
1065 DlPaint red;
1066 red.setColor(DlColor::kRed());
1067 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), red);
1068 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1069}

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), flutter::DlBlurMaskFilter::Make(), flutter::DlColorSource::MakeLinear(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPathBuilder::MoveTo(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setMaskFilter(), flutter::DlPathBuilder::TakePath(), x, and y.

◆ TEST_P() [297/662]

impeller::testing::TEST_P ( AiksTest  ,
GradientOvalStrokeMaskBlur   
)

Definition at line 104 of file aiks_dl_blur_unittests.cc.

104 {
105 ASSERT_TRUE(OpenPlaygroundHere(DoGradientOvalStrokeMaskBlur(
106 GetContentScale(), /*sigma=*/10, DlBlurStyle::kNormal)));
107}
sk_sp< flutter::DisplayList > DoGradientOvalStrokeMaskBlur(Vector2 content_Scale, Scalar sigma, DlBlurStyle style)

References DoGradientOvalStrokeMaskBlur().

◆ TEST_P() [298/662]

impeller::testing::TEST_P ( AiksTest  ,
GradientOvalStrokeMaskBlurInner   
)

Definition at line 119 of file aiks_dl_blur_unittests.cc.

119 {
120 ASSERT_TRUE(OpenPlaygroundHere(DoGradientOvalStrokeMaskBlur(
121 GetContentScale(), /*sigma=*/10, DlBlurStyle::kInner)));
122}

References DoGradientOvalStrokeMaskBlur().

◆ TEST_P() [299/662]

impeller::testing::TEST_P ( AiksTest  ,
GradientOvalStrokeMaskBlurOuter   
)

Definition at line 114 of file aiks_dl_blur_unittests.cc.

114 {
115 ASSERT_TRUE(OpenPlaygroundHere(DoGradientOvalStrokeMaskBlur(
116 GetContentScale(), /*sigma=*/10, DlBlurStyle::kOuter)));
117}

References DoGradientOvalStrokeMaskBlur().

◆ TEST_P() [300/662]

impeller::testing::TEST_P ( AiksTest  ,
GradientOvalStrokeMaskBlurSigmaZero   
)

Definition at line 109 of file aiks_dl_blur_unittests.cc.

109 {
110 ASSERT_TRUE(OpenPlaygroundHere(DoGradientOvalStrokeMaskBlur(
111 GetContentScale(), /*sigma=*/0, DlBlurStyle::kNormal)));
112}

References DoGradientOvalStrokeMaskBlur().

◆ TEST_P() [301/662]

impeller::testing::TEST_P ( AiksTest  ,
GradientOvalStrokeMaskBlurSolid   
)

Definition at line 124 of file aiks_dl_blur_unittests.cc.

124 {
125 ASSERT_TRUE(OpenPlaygroundHere(DoGradientOvalStrokeMaskBlur(
126 GetContentScale(), /*sigma=*/10, DlBlurStyle::kSolid)));
127}

References DoGradientOvalStrokeMaskBlur().

◆ TEST_P() [302/662]

impeller::testing::TEST_P ( AiksTest  ,
GradientStrokesRenderCorrectly   
)

Definition at line 754 of file aiks_dl_gradient_unittests.cc.

754 {
755 // Compare with https://fiddle.skia.org/c/027392122bec8ac2b5d5de00a4b9bbe2
756 auto callback = [&]() -> sk_sp<DisplayList> {
757 static float scale = 3;
758 static bool add_circle_clip = true;
759 const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
760 const DlTileMode tile_modes[] = {DlTileMode::kClamp, DlTileMode::kRepeat,
761 DlTileMode::kMirror, DlTileMode::kDecal};
762 static int selected_tile_mode = 0;
763 static float alpha = 1;
764
765 if (IsPlaygroundEnabled()) {
766 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
767 ImGui::SliderFloat("Scale", &scale, 0, 6);
768 ImGui::Checkbox("Circle clip", &add_circle_clip);
769 ImGui::SliderFloat("Alpha", &alpha, 0, 1);
770 ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
771 sizeof(tile_mode_names) / sizeof(char*));
772 ImGui::End();
773 }
774
775 DisplayListBuilder builder;
776 builder.Scale(GetContentScale().x, GetContentScale().y);
777 DlPaint paint;
778 paint.setColor(DlColor::kWhite());
779 builder.DrawPaint(paint);
780
781 paint.setDrawStyle(DlDrawStyle::kStroke);
782 paint.setColor(DlColor::kWhite().withAlpha(alpha * 255));
783 paint.setStrokeWidth(10);
784 auto tile_mode = tile_modes[selected_tile_mode];
785
786 std::vector<DlColor> colors = {
787 DlColor(Color{0.9568, 0.2627, 0.2118, 1.0}.ToARGB()),
788 DlColor(Color{0.1294, 0.5882, 0.9529, 1.0}.ToARGB())};
789 std::vector<Scalar> stops = {0.0, 1.0};
790
791 paint.setColorSource(DlColorSource::MakeLinear({0, 0}, {50, 50},
792 stops.size(), colors.data(),
793 stops.data(), tile_mode));
794
795 DlPathBuilder path_builder;
796 path_builder.MoveTo(DlPoint(20, 20));
797 path_builder.QuadraticCurveTo(DlPoint(60, 20), DlPoint(60, 60));
798 path_builder.Close();
799 path_builder.MoveTo(DlPoint(60, 20));
800 path_builder.QuadraticCurveTo(DlPoint(60, 60), DlPoint(20, 60));
801 DlPath path = path_builder.TakePath();
802
803 builder.Scale(scale, scale);
804
805 if (add_circle_clip) {
806 static PlaygroundPoint circle_clip_point_a(Point(60, 300), 20,
807 Color::Red());
808 static PlaygroundPoint circle_clip_point_b(Point(600, 300), 20,
809 Color::Red());
810 auto [handle_a, handle_b] =
811 DrawPlaygroundLine(circle_clip_point_a, circle_clip_point_b);
812
813 Matrix ip_matrix = builder.GetMatrix();
814 if (!ip_matrix.IsInvertible()) {
815 return nullptr;
816 }
817 ip_matrix = ip_matrix.Invert();
818 Point point_a = ip_matrix * handle_a * GetContentScale();
819 Point point_b = ip_matrix * handle_b * GetContentScale();
820
821 Point middle = (point_a + point_b) / 2;
822 auto radius = point_a.GetDistance(middle);
823 builder.ClipPath(DlPath::MakeCircle(middle, radius));
824 }
825
826 for (auto join :
827 {DlStrokeJoin::kBevel, DlStrokeJoin::kRound, DlStrokeJoin::kMiter}) {
828 paint.setStrokeJoin(join);
829 for (auto cap :
830 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
831 paint.setStrokeCap(cap);
832 builder.DrawPath(path, paint);
833 builder.Translate(80, 0);
834 }
835 builder.Translate(-240, 60);
836 }
837
838 return builder.Build();
839 };
840
841 ASSERT_TRUE(OpenPlaygroundHere(callback));
842}
DlMatrix GetMatrix() const override
Definition dl_builder.h:111
static DlPath MakeCircle(const DlPoint center, DlScalar radius)
Definition dl_path.cc:68
static constexpr Color Red()
Definition color.h:277
bool IsInvertible() const
Definition matrix.h:321

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::ClipPath(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), impeller::DrawPlaygroundLine(), flutter::DisplayListBuilder::GetMatrix(), impeller::Matrix::Invert(), impeller::Matrix::IsInvertible(), flutter::DlColor::kWhite(), flutter::DlPath::MakeCircle(), flutter::DlColorSource::MakeLinear(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DlPathBuilder::QuadraticCurveTo(), impeller::Color::Red(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), impeller::Color::ToARGB(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [303/662]

impeller::testing::TEST_P ( AiksTest  ,
ImageColorSourceEffectTransform   
)

Definition at line 1681 of file aiks_dl_basic_unittests.cc.

1681 {
1682 // Compare with https://fiddle.skia.org/c/6cdc5aefb291fda3833b806ca347a885
1683
1684 DisplayListBuilder builder;
1685 auto texture = DlImageImpeller::Make(CreateTextureForFixture("monkey.png"));
1686
1687 DlPaint paint;
1688 paint.setColor(DlColor::kWhite());
1689 builder.DrawPaint(paint);
1690
1691 // Translation
1692 {
1693 DlMatrix matrix = DlMatrix::MakeTranslation({50, 50});
1694 DlPaint paint;
1695 paint.setColorSource(DlColorSource::MakeImage(
1696 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1697 DlImageSampling::kNearestNeighbor, &matrix));
1698
1699 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
1700 }
1701
1702 // Rotation/skew
1703 {
1704 builder.Save();
1705 builder.Rotate(45);
1706 DlPaint paint;
1707
1708 Matrix matrix(1, -1, 0, 0, //
1709 1, 1, 0, 0, //
1710 0, 0, 1, 0, //
1711 0, 0, 0, 1);
1712 paint.setColorSource(DlColorSource::MakeImage(
1713 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1714 DlImageSampling::kNearestNeighbor, &matrix));
1715 builder.DrawRect(DlRect::MakeLTRB(100, 0, 200, 100), paint);
1716 builder.Restore();
1717 }
1718
1719 // Scale
1720 {
1721 builder.Save();
1722 builder.Translate(100, 0);
1723 builder.Scale(100, 100);
1724 DlPaint paint;
1725
1726 DlMatrix matrix = DlMatrix::MakeScale({0.005, 0.005, 1});
1727 paint.setColorSource(DlColorSource::MakeImage(
1728 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1729 DlImageSampling::kNearestNeighbor, &matrix));
1730
1731 builder.DrawRect(DlRect::MakeLTRB(0, 0, 1, 1), paint);
1732 builder.Restore();
1733 }
1734
1735 // Perspective
1736 {
1737 builder.Save();
1738 builder.Translate(150, 150);
1739 DlPaint paint;
1740
1741 DlMatrix matrix =
1742 DlMatrix::MakePerspective(Radians{0.5}, ISize{200, 200}, 0.05, 1);
1743 paint.setColorSource(DlColorSource::MakeImage(
1744 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1745 DlImageSampling::kNearestNeighbor, &matrix));
1746
1747 builder.DrawRect(DlRect::MakeLTRB(0, 0, 200, 200), paint);
1748 builder.Restore();
1749 }
1750
1751 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1752}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakePerspective(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), texture, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [304/662]

impeller::testing::TEST_P ( AiksTest  ,
ImageFilteredSaveLayerWithUnboundedContents   
)

Definition at line 665 of file aiks_dl_unittests.cc.

665 {
666 DisplayListBuilder builder;
667 builder.Scale(GetContentScale().x, GetContentScale().y);
668
669 auto test = [&builder](const std::shared_ptr<DlImageFilter>& filter) {
670 auto DrawLine = [&builder](const DlPoint& p0, const DlPoint& p1,
671 const DlPaint& p) {
672 DlPaint paint = p;
673 paint.setDrawStyle(DlDrawStyle::kStroke);
674 builder.DrawPath(DlPath::MakeLine(p0, p1), paint);
675 };
676 // Registration marks for the edge of the SaveLayer
677 DlPaint paint;
678 paint.setColor(DlColor::kWhite());
679 DrawLine(DlPoint(75, 100), DlPoint(225, 100), paint);
680 DrawLine(DlPoint(75, 200), DlPoint(225, 200), paint);
681 DrawLine(DlPoint(100, 75), DlPoint(100, 225), paint);
682 DrawLine(DlPoint(200, 75), DlPoint(200, 225), paint);
683
684 DlPaint save_paint;
685 save_paint.setImageFilter(filter);
686 DlRect bounds = DlRect::MakeLTRB(100, 100, 200, 200);
687 builder.SaveLayer(bounds, &save_paint);
688
689 {
690 // DrawPaint to verify correct behavior when the contents are unbounded.
691 DlPaint paint;
692 paint.setColor(DlColor::kYellow());
693 builder.DrawPaint(paint);
694
695 // Contrasting rectangle to see interior blurring
696 paint.setColor(DlColor::kBlue());
697 builder.DrawRect(DlRect::MakeLTRB(125, 125, 175, 175), paint);
698 }
699 builder.Restore();
700 };
701
702 test(DlImageFilter::MakeBlur(10.0, 10.0, DlTileMode::kDecal));
703
704 builder.Translate(200.0, 0.0);
705
706 test(DlImageFilter::MakeDilate(10.0, 10.0));
707
708 builder.Translate(200.0, 0.0);
709
710 test(DlImageFilter::MakeErode(10.0, 10.0));
711
712 builder.Translate(-400.0, 200.0);
713
714 DlMatrix matrix = DlMatrix::MakeRotationZ(DlDegrees(10));
715
716 auto rotate_filter =
717 DlImageFilter::MakeMatrix(matrix, DlImageSampling::kLinear);
718 test(rotate_filter);
719
720 builder.Translate(200.0, 0.0);
721
722 const float m[20] = {
723 0, 1, 0, 0, 0, //
724 0, 0, 1, 0, 0, //
725 1, 0, 0, 0, 0, //
726 0, 0, 0, 1, 0 //
727 };
728 auto rgb_swap_filter =
729 DlImageFilter::MakeColorFilter(DlColorFilter::MakeMatrix(m));
730 test(rgb_swap_filter);
731
732 builder.Translate(200.0, 0.0);
733
734 test(DlImageFilter::MakeCompose(rotate_filter, rgb_swap_filter));
735
736 builder.Translate(-400.0, 200.0);
737
738 test(rotate_filter->makeWithLocalMatrix(
739 DlMatrix::MakeTranslation({25.0, 25.0})));
740
741 builder.Translate(200.0, 0.0);
742
743 test(rgb_swap_filter->makeWithLocalMatrix(
744 DlMatrix::MakeTranslation({25.0, 25.0})));
745
746 builder.Translate(200.0, 0.0);
747
748 test(DlImageFilter::MakeCompose(rotate_filter, rgb_swap_filter)
749 ->makeWithLocalMatrix(DlMatrix::MakeTranslation({25.0, 25.0})));
750
751 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
752}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DlColor::kYellow(), flutter::DlImageFilter::MakeBlur(), flutter::DlImageFilter::MakeColorFilter(), flutter::DlImageFilter::MakeCompose(), flutter::DlImageFilter::MakeDilate(), flutter::DlImageFilter::MakeErode(), flutter::DlPath::MakeLine(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlImageFilter::MakeMatrix(), flutter::DlColorFilter::MakeMatrix(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeTranslation(), p1, flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setImageFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [305/662]

impeller::testing::TEST_P ( AiksTest  ,
ImageFilteredUnboundedSaveLayerWithUnboundedContents   
)

Definition at line 225 of file aiks_dl_unittests.cc.

225 {
226 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
227 builder.Scale(GetContentScale().x, GetContentScale().y);
228
229 DlPaint save_paint;
230 save_paint.setImageFilter(
231 DlImageFilter::MakeBlur(10.0, 10.0, DlTileMode::kDecal));
232 builder.SaveLayer(std::nullopt, &save_paint);
233
234 {
235 // DrawPaint to verify correct behavior when the contents are unbounded.
236 DlPaint draw_paint;
237 draw_paint.setColor(DlColor::kYellow());
238 builder.DrawPaint(draw_paint);
239
240 // Contrasting rectangle to see interior blurring
241 DlPaint draw_rect;
242 draw_rect.setColor(DlColor::kBlue());
243 builder.DrawRect(DlRect::MakeLTRB(125, 125, 175, 175), draw_rect);
244 }
245 builder.Restore();
246
247 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
248}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kYellow(), flutter::DlImageFilter::MakeBlur(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeSize(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), x, and y.

◆ TEST_P() [306/662]

impeller::testing::TEST_P ( AiksTest  ,
ImageTextureCacheBehavesCorrectly   
)

Definition at line 461 of file canvas_unittests.cc.

461 {
462 ContentContext& context = GetContentContext();
463
465 desc.size = {100, 100};
466 desc.format = context.GetDeviceCapabilities().GetDefaultColorFormat();
467 desc.usage = TextureUsage::kRenderTarget;
468 auto texture =
469 context.GetContext()->GetResourceAllocator()->CreateTexture(desc);
470
472
473 context.SetTextureCachingEnabled(true);
474 auto cached_tex1 = dl_image->GetCachedTexture(context);
475 ASSERT_EQ(cached_tex1, texture);
476
477 auto cached_tex2 = context.GetCachedTexture(dl_image.get());
478 ASSERT_EQ(cached_tex2, texture);
479
480 context.RemoveCachedTexture(dl_image.get());
481 auto cached_tex3 = context.GetCachedTexture(dl_image.get());
482 ASSERT_EQ(cached_tex3, nullptr);
483
484 auto cached_tex4 = dl_image->GetCachedTexture(context);
485 ASSERT_EQ(cached_tex4, texture);
486
487 context.ClearCachedTextures();
488 auto cached_tex5 = context.GetCachedTexture(dl_image.get());
489 ASSERT_EQ(cached_tex5, nullptr);
490
491 context.SetTextureCachingEnabled(false);
492}
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)

References context, impeller::TextureDescriptor::format, impeller::kRenderTarget, impeller::DlImageImpeller::Make(), impeller::TextureDescriptor::size, texture, and impeller::TextureDescriptor::usage.

◆ TEST_P() [307/662]

impeller::testing::TEST_P ( AiksTest  ,
LinearToSrgbFilterSubpassCollapseOptimization   
)

Definition at line 105 of file aiks_dl_unittests.cc.

105 {
106 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
107
108 DlPaint paint;
109 paint.setColorFilter(DlColorFilter::MakeLinearToSrgbGamma());
110 builder.SaveLayer(std::nullopt, &paint);
111
112 builder.Translate(500, 300);
113 builder.Rotate(120); // 120 deg.
114
115 DlPaint draw_paint;
116 draw_paint.setColor(DlColor::kBlue());
117 builder.DrawRect(DlRect::MakeXYWH(100, 100, 200, 200), draw_paint);
118
119 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
120}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColorFilter::MakeLinearToSrgbGamma(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [308/662]

impeller::testing::TEST_P ( AiksTest  ,
MaskBlurDoesntStretchContents   
)

Definition at line 857 of file aiks_dl_blur_unittests.cc.

857 {
858 Scalar sigma = 70;
859 auto callback = [&]() -> sk_sp<DisplayList> {
860 if (IsPlaygroundEnabled()) {
861 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
862 ImGui::SliderFloat("Sigma", &sigma, 0, 500);
863 ImGui::End();
864 }
865
866 DisplayListBuilder builder;
867 builder.Scale(GetContentScale().x, GetContentScale().y);
868
869 DlPaint paint;
870 paint.setColor(DlColor::RGBA(0.1, 0.1, 0.1, 1.0));
871 builder.DrawPaint(paint);
872
873 std::shared_ptr<Texture> boston = CreateTextureForFixture("boston.jpg");
874
875 builder.Transform(Matrix::MakeTranslation({100, 100}) *
876 Matrix::MakeScale({0.5, 0.5, 1.0f}));
877
878 paint.setColorSource(DlColorSource::MakeImage(
879 DlImageImpeller::Make(boston), DlTileMode::kRepeat, DlTileMode::kRepeat,
880 DlImageSampling::kMipmapLinear));
881 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, sigma));
882
883 builder.DrawRect(DlRect::MakeXYWH(0, 0, boston->GetSize().width,
884 boston->GetSize().height),
885 paint);
886
887 return builder.Build();
888 };
889 ASSERT_TRUE(OpenPlaygroundHere(callback));
890}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DlBlurMaskFilter::Make(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setMaskFilter(), flutter::DisplayListBuilder::Transform(), x, and y.

◆ TEST_P() [309/662]

impeller::testing::TEST_P ( AiksTest  ,
MaskBlurOnZeroDimensionIsSkippedWideGamut   
)

Definition at line 567 of file aiks_dl_blur_unittests.cc.

567 {
568 // Must be called before any methods that use the context to ensure that
569 // this test is always run with wide gamut support.
570 if (!EnsureContextSupportsWideGamut()) {
571 GTEST_SKIP() << "This backend doesn't yet support wide gamut.";
572 }
573
574 // Making sure this test is run on a wide gamut enabled backend
575 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
576 PixelFormat::kB10G10R10A10XR);
577
578 DisplayListBuilder builder;
579 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
580
581 DlPaint paint;
582 paint.setColor(DlColor::kBlue());
583 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 10));
584
585 // Zero height above
586 builder.DrawRect(DlRect::MakeLTRB(100, 250, 500, 250), paint);
587 // Regular rect
588 builder.DrawRect(DlRect::MakeLTRB(100, 300, 500, 600), paint);
589 // Zero width to the right
590 builder.DrawRect(DlRect::MakeLTRB(550, 300, 550, 600), paint);
591
592 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
593}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawRect(), impeller::kB10G10R10A10XR, flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DlBlurMaskFilter::Make(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPaint::setColor(), and flutter::DlPaint::setMaskFilter().

◆ TEST_P() [310/662]

impeller::testing::TEST_P ( AiksTest  ,
MaskBlurTexture   
)

Definition at line 828 of file aiks_dl_blur_unittests.cc.

828 {
829 Scalar sigma = 30;
830 auto callback = [&]() -> sk_sp<DisplayList> {
831 if (IsPlaygroundEnabled()) {
832 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
833 ImGui::SliderFloat("Sigma", &sigma, 0, 500);
834 ImGui::End();
835 }
836
837 DisplayListBuilder builder;
838 builder.Scale(GetContentScale().x, GetContentScale().y);
839
840 DlPaint paint;
841 paint.setColor(DlColor::kGreen());
842 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, sigma));
843
844 builder.DrawImage(
845 DlImageImpeller::Make(CreateTextureForFixture("boston.jpg")),
846 DlPoint(200, 200), DlImageSampling::kNearestNeighbor, &paint);
847
848 DlPaint red;
849 red.setColor(DlColor::kRed());
850 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), red);
851
852 return builder.Build();
853 };
854 ASSERT_TRUE(OpenPlaygroundHere(callback));
855}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlBlurMaskFilter::Make(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), x, and y.

◆ TEST_P() [311/662]

impeller::testing::TEST_P ( AiksTest  ,
MaskBlurWithZeroSigmaIsSkipped   
)

Definition at line 554 of file aiks_dl_blur_unittests.cc.

554 {
555 DisplayListBuilder builder;
556
557 DlPaint paint;
558 paint.setColor(DlColor::kBlue());
559 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 0));
560
561 builder.DrawCircle(DlPoint(300, 300), 200, paint);
562 builder.DrawRect(DlRect::MakeLTRB(100, 300, 500, 600), paint);
563
564 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
565}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlBlurMaskFilter::Make(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPaint::setColor(), and flutter::DlPaint::setMaskFilter().

◆ TEST_P() [312/662]

impeller::testing::TEST_P ( AiksTest  ,
MassiveScaleConvertToPath   
)

Definition at line 198 of file aiks_dl_text_unittests.cc.

198 {
199 Scalar scale = 16.0;
200 auto callback = [&]() -> sk_sp<DisplayList> {
201 if (IsPlaygroundEnabled()) {
202 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
203 ImGui::SliderFloat("Scale", &scale, 4, 20);
204 ImGui::End();
205 }
206
207 DisplayListBuilder builder;
208 DlPaint paint;
209 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
210 builder.DrawPaint(paint);
211
212 builder.Scale(scale, scale);
213 RenderTextInCanvasSkia(
214 GetContext(), builder, "HELLO", "Roboto-Regular.ttf",
215 TextRenderOptions{.font_size = 16,
216 .color = (16 * scale >= 250) ? DlColor::kYellow()
218 .position = DlPoint(0, 20)});
219 return builder.Build();
220 };
221
222 ASSERT_TRUE(OpenPlaygroundHere(callback));
223}
static constexpr DlColor kYellow()
Definition dl_color.h:76
static constexpr DlColor kOrange()
Definition dl_color.h:87

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawPaint(), impeller::testing::TextRenderOptions::font_size, flutter::DlColor::kOrange(), flutter::DlColor::kYellow(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), and flutter::DlPaint::setColor().

◆ TEST_P() [313/662]

impeller::testing::TEST_P ( AiksTest  ,
MassiveScalingMatrixImageFilter   
)

Definition at line 2331 of file aiks_dl_basic_unittests.cc.

2331 {
2332 switch (GetBackend()) {
2333 case PlaygroundBackend::kMetal:
2334 case PlaygroundBackend::kMetalSDF:
2335 break;
2336 case PlaygroundBackend::kOpenGLES:
2337 case PlaygroundBackend::kOpenGLESSDF:
2338 case PlaygroundBackend::kVulkan:
2339 GTEST_SKIP() << "Platform is running out of memory on this example "
2340 << "(see https://github.com/flutter/flutter/issues/189286).";
2341 }
2342
2343 DisplayListBuilder builder(DlRect::MakeSize(DlSize(1000, 1000)));
2344
2345 auto filter = DlImageFilter::MakeMatrix(
2346 DlMatrix::MakeScale({0.001, 0.001, 1}), DlImageSampling::kLinear);
2347
2348 DlPaint paint;
2349 paint.setImageFilter(filter);
2350 builder.SaveLayer(std::nullopt, &paint);
2351 {
2352 DlPaint paint;
2353 paint.setColor(DlColor::kRed());
2354 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100000, 100000), paint);
2355 }
2356 builder.Restore();
2357
2358 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2359}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), impeller::kMetal, impeller::kMetalSDF, impeller::kOpenGLES, impeller::kOpenGLESSDF, flutter::DlColor::kRed(), impeller::kVulkan, impeller::TRect< Scalar >::MakeLTRB(), flutter::DlImageFilter::MakeMatrix(), impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeSize(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), and flutter::DlPaint::setImageFilter().

◆ TEST_P() [314/662]

impeller::testing::TEST_P ( AiksTest  ,
MatrixBackdropFilter   
)

Definition at line 754 of file aiks_dl_unittests.cc.

754 {
755 DisplayListBuilder builder;
756
757 DlPaint paint;
758 paint.setColor(DlColor::kBlack());
759 builder.DrawPaint(paint);
760 builder.SaveLayer(std::nullopt, nullptr);
761 {
762 DlPaint paint;
763 paint.setColor(DlColor::kGreen().withAlpha(0.5 * 255));
764 paint.setBlendMode(DlBlendMode::kPlus);
765
766 DlPaint rect_paint;
767 rect_paint.setColor(DlColor::kRed());
768 rect_paint.setStrokeWidth(4);
769 rect_paint.setDrawStyle(DlDrawStyle::kStroke);
770 builder.DrawRect(DlRect::MakeLTRB(0, 0, 300, 300), rect_paint);
771 builder.DrawCircle(DlPoint(200, 200), 100, paint);
772 // Should render a second circle, centered on the bottom-right-most edge of
773 // the circle.
774 DlMatrix matrix = DlMatrix::MakeTranslation({(100 + 100 * k1OverSqrt2),
775 (100 + 100 * k1OverSqrt2)}) *
776 DlMatrix::MakeScale({0.5, 0.5, 1}) *
777 DlMatrix::MakeTranslation({-100, -100});
778 auto backdrop_filter =
779 DlImageFilter::MakeMatrix(matrix, DlImageSampling::kLinear);
780 builder.SaveLayer(std::nullopt, nullptr, backdrop_filter.get());
781 builder.Restore();
782 }
783 builder.Restore();
784
785 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
786}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), impeller::k1OverSqrt2, flutter::DlColor::kBlack(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlImageFilter::MakeMatrix(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [315/662]

impeller::testing::TEST_P ( AiksTest  ,
MatrixImageFilterDoesntCullWhenScaledAndTranslatedFromOffscreen   
)

Definition at line 1804 of file aiks_dl_basic_unittests.cc.

1805 {
1806 DisplayListBuilder builder;
1807 builder.Scale(GetContentScale().x, GetContentScale().y);
1808 builder.Translate(100, 100);
1809 // Draw a circle in a SaveLayer at -300, but move it back on-screen with a
1810 // +300 translation applied by a SaveLayer image filter.
1811
1812 DlPaint paint;
1813 paint.setImageFilter(DlImageFilter::MakeMatrix(
1814 DlMatrix::MakeTranslation({300, 0}) * DlMatrix::MakeScale({2, 2, 1}),
1815 DlImageSampling::kNearestNeighbor));
1816 builder.SaveLayer(std::nullopt, &paint);
1817
1818 DlPaint circle_paint;
1819 circle_paint.setColor(DlColor::kGreen());
1820 builder.DrawCircle(DlPoint(-150, 0), 50, circle_paint);
1821 builder.Restore();
1822
1823 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1824}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kGreen(), flutter::DlImageFilter::MakeMatrix(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [316/662]

impeller::testing::TEST_P ( AiksTest  ,
MatrixImageFilterDoesntCullWhenTranslatedFromOffscreen   
)

Definition at line 1783 of file aiks_dl_basic_unittests.cc.

1783 {
1784 DisplayListBuilder builder;
1785 builder.Scale(GetContentScale().x, GetContentScale().y);
1786 builder.Translate(100, 100);
1787 // Draw a circle in a SaveLayer at -300, but move it back on-screen with a
1788 // +300 translation applied by a SaveLayer image filter.
1789 DlPaint paint;
1790 DlMatrix translate = DlMatrix::MakeTranslation({300, 0});
1791 paint.setImageFilter(
1792 DlImageFilter::MakeMatrix(translate, DlImageSampling::kLinear));
1793 builder.SaveLayer(std::nullopt, &paint);
1794
1795 DlPaint circle_paint;
1796 circle_paint.setColor(DlColor::kGreen());
1797 builder.DrawCircle(DlPoint(-300, 0), 100, circle_paint);
1798 builder.Restore();
1799
1800 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1801}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kGreen(), flutter::DlImageFilter::MakeMatrix(), impeller::Matrix::MakeTranslation(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [317/662]

impeller::testing::TEST_P ( AiksTest  ,
MatrixImageFilterMagnify   
)

Definition at line 633 of file aiks_dl_unittests.cc.

633 {
634 Scalar scale = 2.0;
635 auto callback = [&]() -> sk_sp<DisplayList> {
636 if (IsPlaygroundEnabled()) {
637 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
638 ImGui::SliderFloat("Scale", &scale, 1, 2);
639 ImGui::End();
640 }
641 DisplayListBuilder builder;
642 builder.Scale(GetContentScale().x, GetContentScale().y);
643 auto image = DlImageImpeller::Make(CreateTextureForFixture("airplane.jpg"));
644
645 builder.Translate(600, -200);
646
647 DlMatrix matrix = DlMatrix::MakeScale({scale, scale, 1});
648 DlPaint paint;
649 paint.setImageFilter(
650 DlImageFilter::MakeMatrix(matrix, DlImageSampling::kLinear));
651 builder.SaveLayer(std::nullopt, &paint);
652
653 DlPaint rect_paint;
654 rect_paint.setAlpha(0.5 * 255);
655 builder.DrawImage(image, DlPoint(0, 0), DlImageSampling::kLinear,
656 &rect_paint);
657 builder.Restore();
658
659 return builder.Build();
660 };
661
662 ASSERT_TRUE(OpenPlaygroundHere(callback));
663}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawImage(), image, impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeMatrix(), impeller::Matrix::MakeScale(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setAlpha(), flutter::DlPaint::setImageFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [318/662]

impeller::testing::TEST_P ( AiksTest  ,
MatrixSaveLayerFilter   
)

Definition at line 788 of file aiks_dl_unittests.cc.

788 {
789 DisplayListBuilder builder;
790
791 DlPaint paint;
792 paint.setColor(DlColor::kBlack());
793 builder.DrawPaint(paint);
794 builder.SaveLayer(std::nullopt, nullptr);
795 {
796 paint.setColor(DlColor::kGreen().withAlpha(255 * 0.5));
797 paint.setBlendMode(DlBlendMode::kPlus);
798 builder.DrawCircle(DlPoint(200, 200), 100, paint);
799 // Should render a second circle, centered on the bottom-right-most edge of
800 // the circle.
801
802 DlMatrix matrix = DlMatrix::MakeTranslation({(200 + 100 * k1OverSqrt2),
803 (200 + 100 * k1OverSqrt2)}) *
804 DlMatrix::MakeScale({0.5, 0.5, 1}) *
805 DlMatrix::MakeTranslation({-200, -200});
806 DlPaint save_paint;
807 save_paint.setImageFilter(
808 DlImageFilter::MakeMatrix(matrix, DlImageSampling::kLinear));
809
810 builder.SaveLayer(std::nullopt, &save_paint);
811
812 DlPaint circle_paint;
813 circle_paint.setColor(DlColor::kGreen().withAlpha(255 * 0.5));
814 circle_paint.setBlendMode(DlBlendMode::kPlus);
815 builder.DrawCircle(DlPoint(200, 200), 100, circle_paint);
816 builder.Restore();
817 }
818 builder.Restore();
819
820 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
821}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), impeller::k1OverSqrt2, flutter::DlColor::kBlack(), flutter::DlColor::kGreen(), flutter::DlImageFilter::MakeMatrix(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), and flutter::DlColor::withAlpha().

◆ TEST_P() [319/662]

impeller::testing::TEST_P ( AiksTest  ,
MipmapGenerationWorksCorrectly   
)

Definition at line 481 of file aiks_dl_unittests.cc.

481 {
482 TextureDescriptor texture_descriptor;
483 texture_descriptor.size = ISize{1024, 1024};
484 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
485 texture_descriptor.storage_mode = StorageMode::kHostVisible;
486 texture_descriptor.mip_count = texture_descriptor.size.MipCount();
487
488 std::vector<uint8_t> bytes(4194304);
489 bool alternate = false;
490 for (auto i = 0u; i < 4194304; i += 4) {
491 if (alternate) {
492 bytes[i] = 255;
493 bytes[i + 1] = 0;
494 bytes[i + 2] = 0;
495 bytes[i + 3] = 255;
496 } else {
497 bytes[i] = 0;
498 bytes[i + 1] = 255;
499 bytes[i + 2] = 0;
500 bytes[i + 3] = 255;
501 }
502 alternate = !alternate;
503 }
504
505 ASSERT_EQ(texture_descriptor.GetByteSizeOfBaseMipLevel(), bytes.size());
506 auto mapping = std::make_shared<fml::NonOwnedMapping>(
507 bytes.data(), // data
508 texture_descriptor.GetByteSizeOfBaseMipLevel() // size
509 );
510 auto texture =
511 GetContext()->GetResourceAllocator()->CreateTexture(texture_descriptor);
512
513 auto device_buffer =
514 GetContext()->GetResourceAllocator()->CreateBufferWithCopy(*mapping);
515 auto command_buffer = GetContext()->CreateCommandBuffer();
516 auto blit_pass = command_buffer->CreateBlitPass();
517
518 blit_pass->AddCopy(DeviceBuffer::AsBufferView(std::move(device_buffer)),
519 texture);
520 blit_pass->GenerateMipmap(texture);
521 EXPECT_TRUE(blit_pass->EncodeCommands());
522 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({command_buffer}).ok());
523
524 auto image = DlImageImpeller::Make(texture);
525
526 DisplayListBuilder builder;
527 builder.DrawImageRect(
528 image,
529 DlRect::MakeWH(texture->GetSize().width, texture->GetSize().height),
530 DlRect::MakeLTRB(0, 0, 100, 100), DlImageSampling::kMipmapLinear);
531
532 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
533}

References impeller::DeviceBuffer::AsBufferView(), flutter::DisplayListBuilder::Build(), command_buffer, flutter::DisplayListBuilder::DrawImageRect(), impeller::TextureDescriptor::format, impeller::TextureDescriptor::GetByteSizeOfBaseMipLevel(), i, image, impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeWH(), impeller::TextureDescriptor::mip_count, impeller::TSize< T >::MipCount(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, and texture.

◆ TEST_P() [320/662]

impeller::testing::TEST_P ( AiksTest  ,
MultipleColorWithShadowCache   
)

Definition at line 886 of file aiks_dl_text_unittests.cc.

886 {
887 DisplayListBuilder builder;
888 builder.Scale(GetContentScale().x, GetContentScale().y);
889 DlPaint paint;
890 paint.setColor(DlColor::kWhite());
891 builder.DrawPaint(paint);
892
893 AiksContext aiks_context(GetContext(),
894 std::make_shared<TypographerContextSkia>());
895 // Cache empty
896 EXPECT_EQ(aiks_context.GetContentContext()
897 .GetTextShadowCache()
898 .GetCacheSizeForTesting(),
899 0u);
900
901 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
902
903 std::array<DlColor, 4> colors{DlColor::kRed(), DlColor::kGreen(),
905 for (const auto& color : colors) {
906 ASSERT_TRUE(RenderTextInCanvasSkia(
907 GetContext(), builder, "A", kFontFixture,
908 TextRenderOptions{
909 .color = color,
910 .filter = DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 4)},
911 sk_font));
912 }
913
914 DisplayListToTexture(builder.Build(), {400, 400}, aiks_context);
915
916 // The count of cache entries should match the number of distinct colors
917 // in the list. Repeated usage of a color should not add to the cache.
918 EXPECT_EQ(aiks_context.GetContentContext()
919 .GetTextShadowCache()
920 .GetCacheSizeForTesting(),
921 3u);
922}
SkFont CreateTestFontOfSize(DlScalar scalar)

References flutter::DisplayListBuilder::Build(), impeller::testing::TextRenderOptions::color, flutter::testing::CreateTestFontOfSize(), impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawPaint(), impeller::TextShadowCache::GetCacheSizeForTesting(), impeller::AiksContext::GetContentContext(), impeller::ContentContext::GetTextShadowCache(), flutter::DlColor::kBlue(), kFontFixture, flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlBlurMaskFilter::Make(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [321/662]

impeller::testing::TEST_P ( AiksTest  ,
MultipleTextWithShadowCache   
)

Definition at line 853 of file aiks_dl_text_unittests.cc.

853 {
854 DisplayListBuilder builder;
855 builder.Scale(GetContentScale().x, GetContentScale().y);
856 DlPaint paint;
857 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
858 builder.DrawPaint(paint);
859
860 AiksContext aiks_context(GetContext(),
861 std::make_shared<TypographerContextSkia>());
862 // Cache empty
863 EXPECT_EQ(aiks_context.GetContentContext()
864 .GetTextShadowCache()
865 .GetCacheSizeForTesting(),
866 0u);
867
868 for (auto i = 0; i < 5; i++) {
869 ASSERT_TRUE(RenderTextInCanvasSkia(
870 GetContext(), builder, "Hello World", kFontFixture,
873 .filter = DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 4)}));
874 }
875
876 DisplayListToTexture(builder.Build(), {400, 400}, aiks_context);
877
878 // Text should be cached. Each text gets its own entry as we don't analyze the
879 // strings.
880 EXPECT_EQ(aiks_context.GetContentContext()
881 .GetTextShadowCache()
882 .GetCacheSizeForTesting(),
883 5u);
884}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), impeller::testing::TextRenderOptions::color, impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawPaint(), impeller::TextShadowCache::GetCacheSizeForTesting(), impeller::AiksContext::GetContentContext(), impeller::ContentContext::GetTextShadowCache(), i, flutter::DlColor::kBlue(), kFontFixture, flutter::DlBlurMaskFilter::Make(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [322/662]

impeller::testing::TEST_P ( AiksTest  ,
NoDimplesInRRectPath   
)

Definition at line 2361 of file aiks_dl_basic_unittests.cc.

2361 {
2362 Scalar width = 200.f;
2363 Scalar height = 60.f;
2364 Scalar corner = 1.f;
2365 bool stroked = true;
2366 auto callback = [&]() -> sk_sp<DisplayList> {
2367 if (IsPlaygroundEnabled()) {
2368 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
2369 ImGui::SliderFloat("width", &width, 0, 200);
2370 ImGui::SliderFloat("height", &height, 0, 200);
2371 ImGui::SliderFloat("corner", &corner, 0, 1);
2372 ImGui::Checkbox("stroked", &stroked);
2373 ImGui::End();
2374 }
2375
2376 DisplayListBuilder builder;
2377 builder.Scale(GetContentScale().x, GetContentScale().y);
2378
2379 DlPaint background_paint;
2380 background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
2381 builder.DrawPaint(background_paint);
2382
2383 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue()};
2384 std::vector<Scalar> stops = {0.0, 1.0};
2385
2386 DlPaint paint;
2387 auto gradient = DlColorSource::MakeLinear(DlPoint(0, 0), DlPoint(200, 200),
2388 2, colors.data(), stops.data(),
2389 DlTileMode::kClamp);
2390 paint.setColorSource(gradient);
2391 paint.setColor(DlColor::kWhite());
2392 if (stroked) {
2393 paint.setDrawStyle(DlDrawStyle::kStroke);
2394 paint.setStrokeWidth(20);
2395 } else {
2396 paint.setDrawStyle(DlDrawStyle::kFill);
2397 }
2398
2399 builder.Save();
2400 builder.Translate(100, 100);
2401
2402 Scalar corner_x = ((1 - corner) * 50) + 50;
2403 Scalar corner_y = corner * 50 + 50;
2404 DlRoundRect rrect = DlRoundRect::MakeRectXY(
2405 DlRect::MakeXYWH(0, 0, width, height), corner_x, corner_y);
2406 builder.DrawRoundRect(rrect, paint);
2407 builder.Restore();
2408 return builder.Build();
2409 };
2410 ASSERT_TRUE(OpenPlaygroundHere(callback));
2411}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRoundRect(), height, flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlColorSource::MakeLinear(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), flutter::DisplayListBuilder::Translate(), width, x, and y.

◆ TEST_P() [323/662]

impeller::testing::TEST_P ( AiksTest  ,
NonSquareFilledArcsRenderCorrectly   
)

Definition at line 1108 of file aiks_dl_basic_unittests.cc.

1108 {
1109 DisplayListBuilder builder;
1110 builder.Scale(GetContentScale().x, GetContentScale().y);
1111 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1112
1113 DlPaint paint;
1114 paint.setColor(DlColor::kBlue());
1115
1116 RenderArcFarm(builder, paint,
1117 {
1118 .use_center = false,
1119 .full_circles = false,
1120 .vertical_scale = 0.8f,
1121 });
1122
1123 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1124}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [324/662]

impeller::testing::TEST_P ( AiksTest  ,
NonSquareFilledArcsRenderCorrectlyWithCenter   
)

Definition at line 1126 of file aiks_dl_basic_unittests.cc.

1126 {
1127 DisplayListBuilder builder;
1128 builder.Scale(GetContentScale().x, GetContentScale().y);
1129 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1130
1131 DlPaint paint;
1132 paint.setColor(DlColor::kBlue());
1133
1134 RenderArcFarm(builder, paint,
1135 {
1136 .use_center = true,
1137 .full_circles = false,
1138 .vertical_scale = 0.8f,
1139 });
1140
1141 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1142}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [325/662]

impeller::testing::TEST_P ( AiksTest  ,
PaintBlendModeIsRespected   
)

Definition at line 172 of file aiks_dl_blend_unittests.cc.

172 {
173 DlPaint paint;
174 DisplayListBuilder builder;
175 // Default is kSourceOver.
176
177 paint.setColor(DlColor::RGBA(1, 0, 0, 0.5));
178 builder.DrawCircle(DlPoint(150, 200), 100, paint);
179
180 paint.setColor(DlColor::RGBA(0, 1, 0, 0.5));
181 builder.DrawCircle(DlPoint(250, 200), 100, paint);
182
183 paint.setBlendMode(DlBlendMode::kPlus);
184
185 paint.setColor(DlColor::kRed());
186 builder.DrawCircle(DlPoint(450, 250), 100, paint);
187
188 paint.setColor(DlColor::kGreen());
189 builder.DrawCircle(DlPoint(550, 250), 100, paint);
190
191 paint.setColor(DlColor::kBlue());
192 builder.DrawCircle(DlPoint(500, 150), 100, paint);
193
194 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
195}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::RGBA(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [326/662]

impeller::testing::TEST_P ( AiksTest  ,
PerspectiveRectangle   
)

Definition at line 2441 of file aiks_dl_basic_unittests.cc.

2441 {
2442 int perspective = 58;
2443 bool use_clip = true;
2444 bool diff_clip = false;
2445
2446 auto callback = [&]() -> sk_sp<DisplayList> {
2447 if (IsPlaygroundEnabled()) {
2448 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
2449 ImGui::SliderInt("perspective%", &perspective, 0, 100);
2450 ImGui::Checkbox("use clip", &use_clip);
2451 if (use_clip) {
2452 ImGui::Checkbox("diff clip", &diff_clip);
2453 }
2454 ImGui::SetWindowPos("Controls", ImVec2(500, 100));
2455 ImGui::End();
2456 }
2457
2458 DisplayListBuilder builder;
2459
2460 Scalar val = perspective * -0.00005f;
2461 builder.TransformFullPerspective(
2462 // clang-format off
2463 1.0f, 0.0f, 0.0f, 400.0f,
2464 0.0f, 1.0f, 0.0f, 400.0f,
2465 0.0f, 0.0f, 1.0f, 0.0f,
2466 0.0f, val, 0.0f, 2.2f
2467 // clang-format on
2468 );
2469
2470 if (use_clip) {
2471 Rect clip = DlRect::MakeLTRB(0, 0, 400, 800);
2472 DlClipOp clip_op = DlClipOp::kIntersect;
2473 if (diff_clip) {
2474 clip = clip.Expand(-20);
2475 clip_op = DlClipOp::kDifference;
2476 }
2477 builder.ClipRect(clip, clip_op);
2478 }
2479
2480 DlPaint paint;
2481 paint.setColor(DlColor::kBlue());
2482 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 800), paint);
2483
2484 builder.DrawColor(DlColor::kWhite().withAlphaF(0.5f),
2485 DlBlendMode::kSrcOver);
2486
2487 return builder.Build();
2488 };
2489 ASSERT_TRUE(OpenPlaygroundHere(callback));
2490}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPaint::setColor(), and flutter::DisplayListBuilder::TransformFullPerspective().

◆ TEST_P() [327/662]

impeller::testing::TEST_P ( AiksTest  ,
PipelineBlendSingleParameter   
)

Definition at line 2305 of file aiks_dl_basic_unittests.cc.

2305 {
2306 DisplayListBuilder builder;
2307
2308 // Should render a green square in the middle of a blue circle.
2309 DlPaint paint;
2310 builder.SaveLayer(std::nullopt, &paint);
2311 {
2312 builder.Translate(100, 100);
2313 paint.setColor(DlColor::kBlue());
2314 builder.DrawCircle(DlPoint(200, 200), 200, paint);
2315 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
2316
2317 paint.setColor(DlColor::kGreen());
2318 paint.setBlendMode(DlBlendMode::kSrcOver);
2319 paint.setImageFilter(DlImageFilter::MakeColorFilter(
2320 DlColorFilter::MakeBlend(DlColor::kWhite(), DlBlendMode::kDst)));
2321 builder.DrawCircle(DlPoint(200, 200), 200, paint);
2322 builder.Restore();
2323 }
2324
2325 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2326}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), flutter::DlColorFilter::MakeBlend(), flutter::DlImageFilter::MakeColorFilter(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [328/662]

impeller::testing::TEST_P ( AiksTest  ,
PrimitiveShapePlayground   
)

Definition at line 147 of file aiks_dl_primitive_shape_unittests.cc.

147 {
148 if (!IsPlaygroundEnabled()) {
149 GTEST_SKIP() << "PrimitiveShapePlayground is only for on-screen use";
150 }
151 // In the odd case that we are being run with a playground and the
152 // golden flag set, we don't want to write out the golden either.
153 // Just do the playground part...
154 SetEnableWriteGolden(false);
155
156 RenderParameters params{
157 .render_type = RenderType::kRectangle,
158 .center = GetWindowBounds().GetCenter(),
159 };
160 // The ImGui controls need a pointer to an int and casting a pointer to
161 // an enum field to an int pointer is frowned upon, so we instead create
162 // an int variable and then fill in the params enum from it later.
163 int render_type_index = static_cast<int>(RenderType::kRectangle);
164
165 auto callback = [&]() -> sk_sp<DisplayList> {
166 FML_CHECK(IsPlaygroundEnabled());
167 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
168 ImGui::SliderFloat("Stroke", &params.stroke_width, 0.0f, 30.0f);
169 ImGui::SliderFloat("X Scale", &params.scale_x, 1.0f, 3.0f);
170 ImGui::SliderFloat("Y Scale", &params.scale_y, 1.0f, 3.0f);
171 ImGui::SliderFloat("X Skew", &params.skew_x, 0.0f, 1.0f);
172 ImGui::SliderFloat("Y Skew", &params.skew_y, 0.0f, 1.0f);
173 ImGui::SliderFloat("Rotation", &params.degrees, 0.0f, 360.0f);
174 ImGui::ListBox(
175 "Shape Type", &render_type_index,
176 [](void* data, int index) {
177 switch (static_cast<RenderType>(index)) {
178 case RenderType::kSquare:
179 return "Square";
180 case RenderType::kRectangle:
181 return "Rectangle";
182 case RenderType::kCircle:
183 return "Circle";
184 case RenderType::kOval:
185 return "Oval";
186 case RenderType::kLine:
187 return "Line";
188 case RenderType::kValidCount:
189 case RenderType::kInvalid:
191 }
192 },
193 nullptr, static_cast<int>(RenderType::kValidCount), -1);
194 ImGui::End();
195
196 // Translate our "Gui int variable" to the appropriate enum field value.
197 params.render_type = static_cast<RenderType>(render_type_index);
198
199 DisplayListBuilder builder;
200 builder.Scale(GetContentScale().x, GetContentScale().y);
201 builder.DrawColor(DlColor::kBlack(), DlBlendMode::kSrc);
202 RenderPrimitiveWithStroke(builder, params);
203 return builder.Build();
204 };
205
206 ASSERT_TRUE(OpenPlaygroundHere(callback));
207}
#define FML_UNREACHABLE()
Definition logging.h:128

References flutter::DisplayListBuilder::Build(), callback, flutter::data, flutter::DisplayListBuilder::DrawColor(), FML_CHECK, FML_UNREACHABLE, flutter::DlColor::kBlack(), params, and flutter::DisplayListBuilder::Scale().

◆ TEST_P() [329/662]

impeller::testing::TEST_P ( AiksTest  ,
ReleasesTextureOnTeardown   
)

Definition at line 594 of file aiks_dl_unittests.cc.

594 {
595 // Must be called before any methods that use the context to ensure that
596 // this test is always run with its own unique context.
597 EnsureContextIsUnique();
598
599 auto context = MakeContext();
600 std::weak_ptr<Texture> weak_texture;
601
602 {
603 auto texture = CreateTextureForFixture("table_mountain_nx.png");
604 weak_texture = texture;
605
606 DisplayListBuilder builder;
607 builder.Scale(GetContentScale().x, GetContentScale().y);
608 builder.Translate(100.0f, 100.0f);
609
610 DlPaint paint;
611 paint.setColorSource(DlColorSource::MakeImage(
612 DlImageImpeller::Make(texture), DlTileMode::kClamp, DlTileMode::kClamp,
613 DlImageSampling::kLinear, nullptr));
614
615 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
616
617 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
618 }
619
620 // See https://github.com/flutter/flutter/issues/134751.
621 //
622 // If the fence waiter was working this may not be released by the end of the
623 // scope above. Adding a manual shutdown so that future changes to the fence
624 // waiter will not flake this test.
625 context->Shutdown();
626
627 // The texture should be released by now.
628 ASSERT_TRUE(weak_texture.expired()) << "When the texture is no longer in use "
629 "by the backend, it should be "
630 "released.";
631}

References flutter::DisplayListBuilder::Build(), context, flutter::DisplayListBuilder::DrawRect(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColorSource(), texture, flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [330/662]

impeller::testing::TEST_P ( AiksTest  ,
RotateColorFilteredPath   
)

Definition at line 27 of file aiks_dl_path_unittests.cc.

27 {
28 DisplayListBuilder builder;
29 builder.Transform(DlMatrix::MakeTranslation(DlPoint(300, 300)) *
30 DlMatrix::MakeRotationZ(DlDegrees(90)));
31
32 DlPathBuilder arrow_stem;
33 DlPathBuilder arrow_head;
34
35 arrow_stem.MoveTo(DlPoint(120, 190)).LineTo(DlPoint(120, 50));
36 arrow_head.MoveTo(DlPoint(50, 120))
37 .LineTo(DlPoint(120, 190))
38 .LineTo(DlPoint(190, 120));
39
40 auto filter =
41 DlColorFilter::MakeBlend(DlColor::kAliceBlue(), DlBlendMode::kSrcIn);
42
43 DlPaint paint;
44 paint.setStrokeWidth(15.0);
45 paint.setStrokeCap(DlStrokeCap::kRound);
46 paint.setStrokeJoin(DlStrokeJoin::kRound);
47 paint.setDrawStyle(DlDrawStyle::kStroke);
48 paint.setColorFilter(filter);
49 paint.setColor(DlColor::kBlack());
50
51 builder.DrawPath(arrow_stem.TakePath(), paint);
52 builder.DrawPath(arrow_head.TakePath(), paint);
53
54 auto dl = builder.Build();
55 ASSERT_TRUE(OpenPlaygroundHere(dl));
56}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kAliceBlue(), flutter::DlColor::kBlack(), flutter::DlPathBuilder::LineTo(), flutter::DlColorFilter::MakeBlend(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeTranslation(), flutter::DlPathBuilder::MoveTo(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), and flutter::DisplayListBuilder::Transform().

◆ TEST_P() [331/662]

impeller::testing::TEST_P ( AiksTest  ,
RoundSuperellipseShadowComparison   
)

Definition at line 392 of file canvas_unittests.cc.

392 {
393 // Config
394 Size default_size(600, 400);
395 Point left_center(400, 700);
396 Point right_center(1300, 700);
397 Color color = Color::Red();
398
399 // Convert `color` to a `color_source`. This forces
400 // `canvas.DrawRoundSuperellipse` to use the regular shadow algorithm
401 // (blurring) instead of the fast shadow algorithm.
402 std::shared_ptr<flutter::DlColorSource> color_source;
403 {
404 flutter::DlColor dl_color = flutter::DlColor(color.ToARGB());
405 std::vector<flutter::DlColor> colors = {dl_color, dl_color};
406 std::vector<Scalar> stops = {0.0, 1.0};
408 {0, 0}, {1000, 1000}, 2, colors.data(), stops.data(),
410 }
411
412 RenderCallback callback = [&](RenderTarget& render_target) {
413 ContentContext& context = GetContentContext();
414 Canvas canvas(context, render_target, true, false);
415 // Somehow there's a scaling factor between PlaygroundPoint and Canvas.
416 Matrix ctm = Matrix::MakeScale(Vector2(1, 1) * 0.5);
417 Matrix i_ctm = ctm.Invert();
418
419 static Scalar sigma = 0.05;
420 static Scalar radius = 200;
421
422 // Define the ImGui
423 if (IsPlaygroundEnabled()) {
424 ImGui::Begin("Shadow", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
425 ImGui::SliderFloat("Sigma", &sigma, 0, 100);
426 ImGui::SliderFloat("Radius", &radius, 0, 1000);
427 ImGui::End();
428 }
429
430 static PlaygroundPoint right_reference_var(
431 ctm * (right_center + default_size / 2), 30, Color::White());
432 Point right_reference = i_ctm * DrawPlaygroundPoint(right_reference_var);
433 Point half_size = (right_reference - right_center).Abs();
434 Rect left_bounds = Rect::MakeEllipseBounds(left_center, half_size);
435 Rect right_bounds = Rect::MakeEllipseBounds(right_center, half_size);
436
437 Paint paint{
438 .color = color,
439 .mask_blur_descriptor =
440 Paint::MaskBlurDescriptor{
441 .sigma = Sigma(sigma),
442 },
443 };
444
445 // Left: Draw with canvas
446 canvas.DrawRoundSuperellipse(
447 RoundSuperellipse::MakeRectRadius(left_bounds, radius), paint);
448
449 // Right: Direct draw
450 paint.color_source = color_source.get();
451 canvas.DrawRoundSuperellipse(
452 RoundSuperellipse::MakeRectRadius(right_bounds, radius), paint);
453
454 canvas.EndReplay();
455 return true;
456 };
457
458 ASSERT_TRUE(Playground::OpenPlaygroundHere(callback));
459}

References callback, impeller::Paint::color, context, impeller::DrawPlaygroundPoint(), impeller::Canvas::DrawRoundSuperellipse(), impeller::Canvas::EndReplay(), impeller::Matrix::Invert(), flutter::kClamp, impeller::TRect< Scalar >::MakeEllipseBounds(), flutter::DlColorSource::MakeLinear(), impeller::RoundSuperellipse::MakeRectRadius(), impeller::Matrix::MakeScale(), impeller::Playground::OpenPlaygroundHere(), impeller::Color::Red(), impeller::Paint::MaskBlurDescriptor::sigma, impeller::Color::ToARGB(), and impeller::Color::White().

◆ TEST_P() [332/662]

impeller::testing::TEST_P ( AiksTest  ,
RuntimeEffectImageFilterRotated   
)

Definition at line 564 of file aiks_dl_runtime_effect_unittests.cc.

564 {
565 auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
566 auto size = image->GetBounds().GetSize();
567
568 struct FragUniforms {
569 Size size;
570 } frag_uniforms = {.size = Size(size.width, size.height)};
571 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
572 uniform_data->resize(sizeof(FragUniforms));
573 memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
574
575 auto runtime_stages_result = OpenAssetAsRuntimeStage("gradient.frag.iplr");
576 ABSL_ASSERT_OK(runtime_stages_result);
577 std::shared_ptr<RuntimeStage> runtime_stage =
578 runtime_stages_result.value()[GetRuntimeStageBackend()];
579 ASSERT_TRUE(runtime_stage);
580 ASSERT_TRUE(runtime_stage->IsDirty());
581
582 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
583 nullptr,
584 };
585
586 auto runtime_filter = DlImageFilter::MakeRuntimeEffect(
587 DlRuntimeEffectImpeller::Make(runtime_stage), sampler_inputs,
588 uniform_data);
589
590 Scalar rotation = 45;
591
592 auto callback = [&]() -> sk_sp<DisplayList> {
593 if (IsPlaygroundEnabled()) {
594 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
595 ImGui::SliderFloat("rotation", &rotation, 0, 360);
596 ImGui::End();
597 }
598 DisplayListBuilder builder;
599 builder.Translate(size.width * 0.5, size.height * 0.5);
600 builder.Rotate(rotation);
601 builder.Translate(-size.width * 0.5, -size.height * 0.5);
602
603 DlPaint paint;
604 paint.setImageFilter(runtime_filter);
605 builder.DrawImage(image, DlPoint(0.0, 0.0),
606 DlImageSampling::kNearestNeighbor, &paint);
607
608 return builder.Build();
609 };
610
611 ASSERT_TRUE(OpenPlaygroundHere(callback));
612}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawImage(), image, flutter::DlRuntimeEffectImpeller::Make(), impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeRuntimeEffect(), flutter::DisplayListBuilder::Rotate(), flutter::DlPaint::setImageFilter(), flutter::size, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [333/662]

impeller::testing::TEST_P ( AiksTest  ,
RuntimeEffectVectorArray   
)

Definition at line 614 of file aiks_dl_runtime_effect_unittests.cc.

614 {
615 constexpr float kDimension = 400.0f;
616 struct FragUniforms {
617 Vector2 iResolution;
618 Vector4 iValues;
619 } frag_uniforms = {.iResolution = Vector2(kDimension, kDimension),
620 .iValues = Vector4(0.25, 0.50, 0.75, 1.0)};
621 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
622 uniform_data->resize(sizeof(FragUniforms));
623 memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
624
625 DlPaint paint;
626 auto effect = MakeRuntimeEffect(this, "runtime_stage_vector_array.frag.iplr",
627 uniform_data);
628 ABSL_ASSERT_OK(effect);
629 paint.setColorSource(effect.value());
630
631 DisplayListBuilder builder;
632 builder.DrawRect(DlRect::MakeXYWH(0, 0, kDimension, kDimension), paint);
633
634 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
635}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), impeller::TRect< Scalar >::MakeXYWH(), and flutter::DlPaint::setColorSource().

◆ TEST_P() [334/662]

impeller::testing::TEST_P ( AiksTest  ,
RuntimeEffectWithInvalidSamplerDoesNotCrash   
)

Definition at line 135 of file aiks_dl_runtime_effect_unittests.cc.

135 {
136 ScopedValidationDisable disable_validation;
137
138 // Create a sampler that is not usable as an input to the runtime effect.
139 std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
141 const float stops[2] = {0.0, 1.0};
142 auto linear = flutter::DlColorSource::MakeLinear({0.0, 0.0}, {300.0, 300.0},
143 2, colors.data(), stops,
145 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
146 linear,
147 };
148
149 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
150 uniform_data->resize(sizeof(Vector2));
151
152 DlPaint paint;
153 auto effect =
154 MakeRuntimeEffect(this, "runtime_stage_filter_example.frag.iplr",
155 uniform_data, sampler_inputs);
156 ABSL_ASSERT_OK(effect);
157 paint.setColorSource(effect.value());
158
159 DisplayListBuilder builder;
160 builder.DrawPaint(paint);
161
162 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
163}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kBlue(), flutter::kClamp, flutter::DlColor::kRed(), flutter::DlColorSource::MakeLinear(), and flutter::DlPaint::setColorSource().

◆ TEST_P() [335/662]

impeller::testing::TEST_P ( AiksTest  ,
SaveLayerDrawsBehindSubsequentEntities   
)

Definition at line 2160 of file aiks_dl_basic_unittests.cc.

2160 {
2161 // Compare with https://fiddle.skia.org/c/9e03de8567ffb49e7e83f53b64bcf636
2162 DisplayListBuilder builder;
2163 DlPaint paint;
2164
2165 paint.setColor(DlColor::kBlack());
2166 DlRect rect = DlRect::MakeXYWH(25, 25, 25, 25);
2167 builder.DrawRect(rect, paint);
2168
2169 builder.Translate(10, 10);
2170
2171 DlPaint save_paint;
2172 builder.SaveLayer(std::nullopt, &save_paint);
2173
2174 paint.setColor(DlColor::kGreen());
2175 builder.DrawRect(rect, paint);
2176
2177 builder.Restore();
2178
2179 builder.Translate(10, 10);
2180 paint.setColor(DlColor::kRed());
2181 builder.DrawRect(rect, paint);
2182
2183 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2184}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlack(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [336/662]

impeller::testing::TEST_P ( AiksTest  ,
SaveLayerFiltersScaleWithTransform   
)

Definition at line 2252 of file aiks_dl_basic_unittests.cc.

2252 {
2253 DisplayListBuilder builder;
2254
2255 builder.Scale(GetContentScale().x, GetContentScale().y);
2256 builder.Translate(100, 100);
2257
2258 auto texture = DlImageImpeller::Make(CreateTextureForFixture("boston.jpg"));
2259 auto draw_image_layer = [&builder, &texture](const DlPaint& paint) {
2260 builder.SaveLayer(std::nullopt, &paint);
2261 builder.DrawImage(texture, DlPoint(), DlImageSampling::kLinear);
2262 builder.Restore();
2263 };
2264
2265 DlPaint effect_paint;
2266 effect_paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 6));
2267 draw_image_layer(effect_paint);
2268
2269 builder.Translate(300, 300);
2270 builder.Scale(3, 3);
2271 draw_image_layer(effect_paint);
2272
2273 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2274}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), flutter::DlBlurMaskFilter::Make(), impeller::DlImageImpeller::Make(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setMaskFilter(), texture, flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [337/662]

impeller::testing::TEST_P ( AiksTest  ,
ScaledK   
)

Definition at line 176 of file aiks_dl_text_unittests.cc.

176 {
177 DisplayListBuilder builder;
178 DlPaint paint;
179 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
180 builder.DrawPaint(paint);
181 for (int i = 0; i < 6; ++i) {
182 builder.Save();
183 builder.Translate(300 * i, 0);
184 Scalar scale = 0.445 - (i / 1000.f);
185 builder.Scale(scale, scale);
187 GetContext(), builder, "k", "Roboto-Regular.ttf",
188 TextRenderOptions{.font_size = 600, .position = DlPoint(10, 500)});
189 RenderTextInCanvasSkia(
190 GetContext(), builder, "k", "Roboto-Regular.ttf",
191 TextRenderOptions{.font_size = 300, .position = DlPoint(10, 800)});
192 builder.Restore();
193 }
194 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
195}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), impeller::testing::TextRenderOptions::font_size, i, RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [338/662]

impeller::testing::TEST_P ( AiksTest  ,
SetContentsWithRegion   
)

Definition at line 560 of file aiks_dl_unittests.cc.

560 {
561 auto bridge = CreateTextureForFixture("bay_bridge.jpg");
562
563 // Replace part of the texture with a red rectangle.
564 std::vector<uint8_t> bytes(100 * 100 * 4);
565 for (auto i = 0u; i < bytes.size(); i += 4) {
566 bytes[i] = 255;
567 bytes[i + 1] = 0;
568 bytes[i + 2] = 0;
569 bytes[i + 3] = 255;
570 }
571 auto mapping =
572 std::make_shared<fml::NonOwnedMapping>(bytes.data(), bytes.size());
573 auto device_buffer =
574 GetContext()->GetResourceAllocator()->CreateBufferWithCopy(*mapping);
575 auto cmd_buffer = GetContext()->CreateCommandBuffer();
576 auto blit_pass = cmd_buffer->CreateBlitPass();
577 blit_pass->AddCopy(DeviceBuffer::AsBufferView(device_buffer), bridge,
578 IRect::MakeLTRB(50, 50, 150, 150));
579
580 auto did_submit =
581 blit_pass->EncodeCommands() &&
582 GetContext()->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok();
583 ASSERT_TRUE(did_submit);
584
585 auto image = DlImageImpeller::Make(bridge);
586
587 DisplayListBuilder builder;
588 builder.DrawImage(image, DlPoint(0, 0), {});
589
590 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
591}

References impeller::DeviceBuffer::AsBufferView(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), i, image, impeller::DlImageImpeller::Make(), and impeller::TRect< T >::MakeLTRB().

◆ TEST_P() [339/662]

impeller::testing::TEST_P ( AiksTest  ,
SiblingSaveLayerBoundsAreRespected   
)

Definition at line 2186 of file aiks_dl_basic_unittests.cc.

2186 {
2187 DisplayListBuilder builder;
2188 DlPaint paint;
2189 DlRect rect = DlRect::MakeXYWH(0, 0, 1000, 1000);
2190
2191 // Black, green, and red squares offset by [10, 10].
2192 {
2193 DlPaint save_paint;
2194 DlRect bounds = DlRect::MakeXYWH(25, 25, 25, 25);
2195 builder.SaveLayer(bounds, &save_paint);
2196 paint.setColor(DlColor::kBlack());
2197 builder.DrawRect(rect, paint);
2198 builder.Restore();
2199 }
2200
2201 {
2202 DlPaint save_paint;
2203 DlRect bounds = DlRect::MakeXYWH(35, 35, 25, 25);
2204 builder.SaveLayer(bounds, &save_paint);
2205 paint.setColor(DlColor::kGreen());
2206 builder.DrawRect(rect, paint);
2207 builder.Restore();
2208 }
2209
2210 {
2211 DlPaint save_paint;
2212 DlRect bounds = DlRect::MakeXYWH(45, 45, 25, 25);
2213 builder.SaveLayer(bounds, &save_paint);
2214 paint.setColor(DlColor::kRed());
2215 builder.DrawRect(rect, paint);
2216 builder.Restore();
2217 }
2218
2219 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2220}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlack(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [340/662]

impeller::testing::TEST_P ( AiksTest  ,
SingleIconShadowTest   
)

Definition at line 924 of file aiks_dl_text_unittests.cc.

924 {
925 DisplayListBuilder builder;
926 builder.Scale(GetContentScale().x, GetContentScale().y);
927 DlPaint paint;
928 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
929 builder.DrawPaint(paint);
930
931 AiksContext aiks_context(GetContext(),
932 std::make_shared<TypographerContextSkia>());
933 // Cache empty
934 EXPECT_EQ(aiks_context.GetContentContext()
935 .GetTextShadowCache()
936 .GetCacheSizeForTesting(),
937 0u);
938
939 // Create font instance outside loop so all draws use identical font instance.
940 auto c_font_fixture = std::string(kFontFixture);
941 auto mapping = flutter::testing::OpenFixtureAsSkData(c_font_fixture.c_str());
942 ASSERT_TRUE(mapping);
943 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
944 SkFont sk_font(font_mgr->makeFromData(mapping), 50);
945
946 for (auto i = 0; i < 10; i++) {
947 ASSERT_TRUE(RenderTextInCanvasSkia(
948 GetContext(), builder, "A", kFontFixture,
951 .filter = DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 4)},
952 sk_font));
953 }
954
955 DisplayListToTexture(builder.Build(), {400, 400}, aiks_context);
956
957 // Text should be cached. All 10 glyphs use the same cache entry.
958 EXPECT_EQ(aiks_context.GetContentContext()
959 .GetTextShadowCache()
960 .GetCacheSizeForTesting(),
961 1u);
962}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), impeller::testing::TextRenderOptions::color, impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawPaint(), impeller::TextShadowCache::GetCacheSizeForTesting(), impeller::AiksContext::GetContentContext(), txt::GetDefaultFontManager(), impeller::ContentContext::GetTextShadowCache(), i, flutter::DlColor::kBlue(), kFontFixture, flutter::DlBlurMaskFilter::Make(), flutter::testing::OpenFixtureAsSkData(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [341/662]

impeller::testing::TEST_P ( AiksTest  ,
SolidColorCircleMaskBlurTinySigma   
)

Definition at line 129 of file aiks_dl_blur_unittests.cc.

129 {
130 DisplayListBuilder builder;
131 builder.Scale(GetContentScale().x, GetContentScale().y);
132
133 std::vector<float> sigmas = {0.0, 0.01, 1.0};
134 std::vector<DlColor> colors = {DlColor::kGreen(), DlColor::kYellow(),
135 DlColor::kRed()};
136 for (uint32_t i = 0; i < sigmas.size(); ++i) {
137 DlPaint paint;
138 paint.setColor(colors[i]);
139 paint.setMaskFilter(
140 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, sigmas[i]));
141
142 builder.Save();
143 builder.Translate(100 + (i * 100), 100);
144 DlRoundRect rrect = DlRoundRect::MakeRectXY(
145 DlRect::MakeXYWH(0, 0, 100.0f, 100.0f), 100, 100);
146 builder.DrawRoundRect(rrect, paint);
147 builder.Restore();
148 }
149
150 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
151}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRoundRect(), i, flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), flutter::DlBlurMaskFilter::Make(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [342/662]

impeller::testing::TEST_P ( AiksTest  ,
SolidColorCirclesOvalsRRectsMaskBlurCorrectly   
)

Definition at line 1516 of file aiks_dl_basic_unittests.cc.

1516 {
1517 DisplayListBuilder builder;
1518 builder.Scale(GetContentScale().x, GetContentScale().y);
1519 DlPaint paint;
1520 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1.0f));
1521
1522 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
1523
1524 paint.setColor(
1525 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f));
1526 Scalar y = 100.0f;
1527 for (int i = 0; i < 5; i++) {
1528 Scalar x = (i + 1) * 100;
1529 Scalar radius = x / 10.0f;
1530 builder.DrawRect(DlRect::MakeXYWH(x + 25 - radius / 2, y + radius / 2, //
1531 radius, 60.0f - radius),
1532 paint);
1533 }
1534
1535 paint.setColor(DlColor::kBlue());
1536 y += 100.0f;
1537 for (int i = 0; i < 5; i++) {
1538 Scalar x = (i + 1) * 100;
1539 Scalar radius = x / 10.0f;
1540 builder.DrawCircle(DlPoint(x + 25, y + 25), radius, paint);
1541 }
1542
1543 paint.setColor(DlColor::kGreen());
1544 y += 100.0f;
1545 for (int i = 0; i < 5; i++) {
1546 Scalar x = (i + 1) * 100;
1547 Scalar radius = x / 10.0f;
1548 builder.DrawOval(DlRect::MakeXYWH(x + 25 - radius / 2, y + radius / 2, //
1549 radius, 60.0f - radius),
1550 paint);
1551 }
1552
1553 paint.setColor(
1554 DlColor::RGBA(128.0f / 255.0f, 0.0f / 255.0f, 128.0f / 255.0f, 1.0f));
1555 y += 100.0f;
1556 for (int i = 0; i < 5; i++) {
1557 Scalar x = (i + 1) * 100;
1558 Scalar radius = x / 20.0f;
1559 builder.DrawRoundRect(
1560 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(x, y, 60.0f, 60.0f), //
1561 radius, radius),
1562 paint);
1563 }
1564
1565 paint.setColor(
1566 DlColor::RGBA(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f));
1567 y += 100.0f;
1568 for (int i = 0; i < 5; i++) {
1569 Scalar x = (i + 1) * 100;
1570 Scalar radius = x / 20.0f;
1571 builder.DrawRoundRect(
1572 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(x, y, 60.0f, 60.0f), //
1573 radius, 5.0f),
1574 paint);
1575 }
1576
1577 auto dl = builder.Build();
1578 ASSERT_TRUE(OpenPlaygroundHere(dl));
1579}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawOval(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawRoundRect(), i, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), flutter::DlBlurMaskFilter::Make(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), x, and y.

◆ TEST_P() [343/662]

impeller::testing::TEST_P ( AiksTest  ,
SolidColorOvalsMaskBlurTinySigma   
)

Definition at line 39 of file aiks_dl_blur_unittests.cc.

39 {
40 DisplayListBuilder builder;
41 builder.Scale(GetContentScale().x, GetContentScale().y);
42
43 std::vector<float> sigmas = {0.0, 0.01, 1.0};
44 std::vector<DlColor> colors = {DlColor::kGreen(), DlColor::kYellow(),
45 DlColor::kRed()};
46 for (uint32_t i = 0; i < sigmas.size(); ++i) {
47 DlPaint paint;
48 paint.setColor(colors[i]);
49 paint.setMaskFilter(
50 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, sigmas[i]));
51
52 builder.Save();
53 builder.Translate(100 + (i * 100), 100);
54 DlRoundRect rrect =
55 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(0, 0, 60.0f, 160.0f), 50, 100);
56 builder.DrawRoundRect(rrect, paint);
57 builder.Restore();
58 }
59
60 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
61}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRoundRect(), i, flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), flutter::DlBlurMaskFilter::Make(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [344/662]

impeller::testing::TEST_P ( AiksTest  ,
SolidStrokesRenderCorrectly   
)

Definition at line 520 of file aiks_dl_path_unittests.cc.

520 {
521 // Compare with https://fiddle.skia.org/c/027392122bec8ac2b5d5de00a4b9bbe2
522 auto callback = [&]() -> sk_sp<DisplayList> {
523 static Color color = Color::Black().WithAlpha(0.5);
524 static float scale = 3;
525 static bool add_circle_clip = true;
526
527 if (IsPlaygroundEnabled()) {
528 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
529 ImGui::ColorEdit4("Color", reinterpret_cast<float*>(&color));
530 ImGui::SliderFloat("Scale", &scale, 0, 6);
531 ImGui::Checkbox("Circle clip", &add_circle_clip);
532 ImGui::End();
533 }
534
535 DisplayListBuilder builder;
536 builder.Scale(GetContentScale().x, GetContentScale().y);
537 DlPaint paint;
538
539 paint.setColor(DlColor::kWhite());
540 builder.DrawPaint(paint);
541
542 paint.setColor(
543 DlColor::ARGB(color.alpha, color.red, color.green, color.blue));
544 paint.setDrawStyle(DlDrawStyle::kStroke);
545 paint.setStrokeWidth(10);
546
547 DlPathBuilder path_builder;
548 path_builder.MoveTo(DlPoint(20, 20));
549 path_builder.QuadraticCurveTo(DlPoint(60, 20), DlPoint(60, 60));
550 path_builder.Close();
551 path_builder.MoveTo(DlPoint(60, 20));
552 path_builder.QuadraticCurveTo(DlPoint(60, 60), DlPoint(20, 60));
553 DlPath path = path_builder.TakePath();
554
555 builder.Scale(scale, scale);
556
557 if (add_circle_clip) {
558 static PlaygroundPoint circle_clip_point_a(Point(60, 300), 20,
559 Color::Red());
560 static PlaygroundPoint circle_clip_point_b(Point(600, 300), 20,
561 Color::Red());
562 auto [handle_a, handle_b] =
563 DrawPlaygroundLine(circle_clip_point_a, circle_clip_point_b);
564
565 Matrix screen_to_canvas = builder.GetMatrix();
566 if (!screen_to_canvas.IsInvertible()) {
567 return nullptr;
568 }
569 screen_to_canvas = screen_to_canvas.Invert();
570
571 Point point_a = screen_to_canvas * handle_a;
572 Point point_b = screen_to_canvas * handle_b;
573
574 Point middle = point_a + point_b;
575 middle *= GetContentScale().x / 2;
576
577 auto radius = point_a.GetDistance(middle);
578
579 builder.ClipPath(DlPath::MakeCircle(middle, radius));
580 }
581
582 for (auto join :
583 {DlStrokeJoin::kBevel, DlStrokeJoin::kRound, DlStrokeJoin::kMiter}) {
584 paint.setStrokeJoin(join);
585 for (auto cap :
586 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
587 paint.setStrokeCap(cap);
588 builder.DrawPath(path, paint);
589 builder.Translate(80, 0);
590 }
591 builder.Translate(-240, 60);
592 }
593
594 return builder.Build();
595 };
596
597 ASSERT_TRUE(OpenPlaygroundHere(callback));
598}

References impeller::Color::alpha, flutter::DlColor::ARGB(), impeller::Color::Black(), impeller::Color::blue, flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::ClipPath(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), impeller::DrawPlaygroundLine(), flutter::DisplayListBuilder::GetMatrix(), impeller::Color::green, impeller::Matrix::Invert(), impeller::Matrix::IsInvertible(), flutter::DlColor::kWhite(), flutter::DlPath::MakeCircle(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DlPathBuilder::QuadraticCurveTo(), impeller::Color::red, impeller::Color::Red(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), flutter::DisplayListBuilder::Translate(), impeller::Color::WithAlpha(), x, flutter::Point::x(), and y.

◆ TEST_P() [345/662]

impeller::testing::TEST_P ( AiksTest  ,
SrgbToLinearFilterSubpassCollapseOptimization   
)

Definition at line 122 of file aiks_dl_unittests.cc.

122 {
123 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
124
125 DlPaint paint;
126 paint.setColorFilter(DlColorFilter::MakeLinearToSrgbGamma());
127 builder.SaveLayer(std::nullopt, &paint);
128
129 builder.Translate(500, 300);
130 builder.Rotate(120); // 120 deg
131
132 DlPaint draw_paint;
133 draw_paint.setColor(DlColor::kBlue());
134 builder.DrawRect(DlRect::MakeXYWH(100, 100, 200, 200), draw_paint);
135
136 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
137}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColorFilter::MakeLinearToSrgbGamma(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [346/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokeCapsAndJoins   
)

Definition at line 898 of file aiks_dl_path_unittests.cc.

898 {
899 DisplayListBuilder builder;
900 builder.Scale(GetContentScale().x, GetContentScale().y);
901
902 builder.Translate(100, 0);
903
904 builder.Save();
905 for (auto cap : std::vector<DlStrokeCap>{
906 DlStrokeCap::kButt, DlStrokeCap::kRound, DlStrokeCap::kSquare}) {
907 DlPathBuilder path_builder;
908 path_builder.MoveTo({20, 50});
909 path_builder.LineTo({50, 50});
910 path_builder.MoveTo({120, 50});
911 path_builder.LineTo({120, 80});
912 path_builder.MoveTo({180, 50});
913 path_builder.LineTo({180, 50});
914 DlPath path = path_builder.TakePath();
915
916 DlPaint paint;
917 paint.setColor(DlColor::kRed());
918 paint.setDrawStyle(DlDrawStyle::kStroke);
919 paint.setStrokeWidth(20.0f);
920 paint.setStrokeCap(cap);
921 paint.setStrokeJoin(DlStrokeJoin::kBevel);
922
923 builder.DrawPath(path, paint);
924
925 paint.setColor(DlColor::kYellow());
926 paint.setStrokeWidth(1.0f);
927 paint.setStrokeCap(DlStrokeCap::kButt);
928
929 builder.DrawPath(path, paint);
930
931 builder.Translate(250, 0);
932 }
933 builder.Restore();
934
935 builder.Translate(0, 100);
936
937 builder.Save();
938 for (auto join : std::vector<DlStrokeJoin>{
939 DlStrokeJoin::kBevel, DlStrokeJoin::kRound, DlStrokeJoin::kMiter}) {
940 DlPathBuilder path_builder;
941 path_builder.MoveTo({20, 50}); // 0 degree right turn
942 path_builder.LineTo({50, 50});
943 path_builder.LineTo({80, 50});
944 path_builder.MoveTo({20, 150}); // 90 degree right turn
945 path_builder.LineTo({50, 150});
946 path_builder.LineTo({50, 180});
947 path_builder.MoveTo({20, 250}); // 45 degree right turn
948 path_builder.LineTo({50, 250});
949 path_builder.LineTo({70, 270});
950 path_builder.MoveTo({20, 350}); // 135 degree right turn
951 path_builder.LineTo({50, 350});
952 path_builder.LineTo({30, 370});
953 path_builder.MoveTo({20, 450}); // 180 degree right turn
954 path_builder.LineTo({50, 450});
955 path_builder.LineTo({20, 450});
956 path_builder.MoveTo({120, 80}); // 0 degree left turn
957 path_builder.LineTo({150, 80});
958 path_builder.LineTo({180, 80});
959 path_builder.MoveTo({120, 180}); // 90 degree left turn
960 path_builder.LineTo({150, 180});
961 path_builder.LineTo({150, 150});
962 path_builder.MoveTo({120, 280}); // 45 degree left turn
963 path_builder.LineTo({150, 280});
964 path_builder.LineTo({170, 260});
965 path_builder.MoveTo({120, 380}); // 135 degree left turn
966 path_builder.LineTo({150, 380});
967 path_builder.LineTo({130, 360});
968 path_builder.MoveTo({120, 480}); // 180 degree left turn
969 path_builder.LineTo({150, 480});
970 path_builder.LineTo({120, 480});
971 DlPath path = path_builder.TakePath();
972
973 DlPaint paint;
974
975 paint.setColor(DlColor::kRed());
976 paint.setDrawStyle(DlDrawStyle::kStroke);
977 paint.setStrokeWidth(20.0f);
978 paint.setStrokeCap(DlStrokeCap::kSquare);
979 paint.setStrokeJoin(join);
980 builder.DrawPath(path, paint);
981
982 paint.setColor(DlColor::kYellow());
983 paint.setStrokeWidth(1.0f);
984 paint.setStrokeCap(DlStrokeCap::kButt);
985 builder.DrawPath(path, paint);
986
987 builder.Translate(250, 0);
988 }
989 builder.Restore();
990
991 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
992}
DlStrokeJoin
Definition dl_paint.h:37
DlStrokeCap
Definition dl_paint.h:28

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlColor::kYellow(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [347/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedArcsCoverFullArcWithButtEnds   
)

Definition at line 1367 of file aiks_dl_basic_unittests.cc.

1367 {
1368 // This test compares the rendering of a full circle arc against a partial
1369 // arc by drawing a one over the other in high contrast. If the partial
1370 // arc misses any pixels that were drawn by the full arc, there will be
1371 // some "pixel dirt" around the missing "erased" parts of the arcs. This
1372 // case arises while rendering a CircularProgressIndicator with a background
1373 // color where we want the rendering of the background full arc to hit the
1374 // same pixels around the edges as the partial arc that covers it.
1375 //
1376 // In this case we draw a full blue circle and then draw a partial arc
1377 // over it in the background color (white).
1378
1379 DisplayListBuilder builder;
1380 builder.Scale(GetContentScale().x, GetContentScale().y);
1381 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1382
1383 DlPaint paint;
1384 paint.setDrawStyle(DlDrawStyle::kStroke);
1385 paint.setStrokeWidth(6.0f);
1386 paint.setStrokeCap(DlStrokeCap::kButt);
1387 paint.setColor(DlColor::kBlue());
1388
1389 // First draw full circles in blue to establish the pixels to be erased
1390 RenderArcFarm(builder, paint,
1391 {
1392 .use_center = false,
1393 .full_circles = true,
1394 });
1395
1396 paint.setColor(DlColor::kWhite());
1397
1398 // Then draw partial arcs in white over the circles to "erase" them
1399 RenderArcFarm(builder, paint,
1400 {
1401 .use_center = false,
1402 .full_circles = false,
1403 });
1404
1405 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1406}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), x, and y.

◆ TEST_P() [348/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedArcsRenderCorrectlyWithBevelJoinsAndCenter   
)

Definition at line 1234 of file aiks_dl_basic_unittests.cc.

1234 {
1235 DisplayListBuilder builder;
1236 builder.Scale(GetContentScale().x, GetContentScale().y);
1237 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1238
1239 DlPaint paint;
1240 paint.setDrawStyle(DlDrawStyle::kStroke);
1241 paint.setStrokeWidth(6.0f);
1242 paint.setStrokeJoin(DlStrokeJoin::kBevel);
1243 paint.setColor(DlColor::kBlue());
1244
1245 RenderArcFarm(builder, paint,
1246 {
1247 .use_center = true,
1248 .full_circles = false,
1249 .sweeps_over_360 = true,
1250 });
1251
1252 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1253}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), x, and y.

◆ TEST_P() [349/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedArcsRenderCorrectlyWithButtEnds   
)

Definition at line 1144 of file aiks_dl_basic_unittests.cc.

1144 {
1145 DisplayListBuilder builder;
1146 builder.Scale(GetContentScale().x, GetContentScale().y);
1147 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1148
1149 DlPaint paint;
1150 paint.setDrawStyle(DlDrawStyle::kStroke);
1151 paint.setStrokeWidth(6.0f);
1152 paint.setStrokeCap(DlStrokeCap::kButt);
1153 paint.setColor(DlColor::kBlue());
1154
1155 RenderArcFarm(builder, paint,
1156 {
1157 .use_center = false,
1158 .full_circles = false,
1159 });
1160
1161 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1162}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), x, and y.

◆ TEST_P() [350/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedArcsRenderCorrectlyWithMiterJoinsAndCenter   
)

Definition at line 1255 of file aiks_dl_basic_unittests.cc.

1255 {
1256 DisplayListBuilder builder;
1257 builder.Scale(GetContentScale().x, GetContentScale().y);
1258 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1259
1260 DlPaint paint;
1261 paint.setDrawStyle(DlDrawStyle::kStroke);
1262 paint.setStrokeWidth(6.0f);
1263 paint.setStrokeJoin(DlStrokeJoin::kMiter);
1264 // Default miter of 4.0 does a miter on all of the centers, but
1265 // using 3.0 will show some bevels on the widest interior angles...
1266 paint.setStrokeMiter(3.0f);
1267 paint.setColor(DlColor::kBlue());
1268
1269 RenderArcFarm(builder, paint,
1270 {
1271 .use_center = true,
1272 .full_circles = false,
1273 .sweeps_over_360 = true,
1274 });
1275
1276 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1277}
DlPaint & setStrokeMiter(float miter)
Definition dl_paint.h:121

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeMiter(), flutter::DlPaint::setStrokeWidth(), x, and y.

◆ TEST_P() [351/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedArcsRenderCorrectlyWithRoundEnds   
)

Definition at line 1199 of file aiks_dl_basic_unittests.cc.

1199 {
1200 DisplayListBuilder builder;
1201 builder.Scale(GetContentScale().x, GetContentScale().y);
1202 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1203
1204 DlPaint paint;
1205 paint.setDrawStyle(DlDrawStyle::kStroke);
1206 paint.setStrokeWidth(6.0f);
1207 paint.setStrokeCap(DlStrokeCap::kRound);
1208 paint.setColor(DlColor::kBlue());
1209
1210 RenderArcFarm(builder, paint,
1211 {
1212 .use_center = false,
1213 .full_circles = false,
1214 });
1215
1216 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1217}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), x, and y.

◆ TEST_P() [352/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedArcsRenderCorrectlyWithRoundJoinsAndCenter   
)

Definition at line 1279 of file aiks_dl_basic_unittests.cc.

1279 {
1280 DisplayListBuilder builder;
1281 builder.Scale(GetContentScale().x, GetContentScale().y);
1282 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1283
1284 DlPaint paint;
1285 paint.setDrawStyle(DlDrawStyle::kStroke);
1286 paint.setStrokeWidth(6.0f);
1287 paint.setStrokeJoin(DlStrokeJoin::kRound);
1288 paint.setColor(DlColor::kBlue());
1289
1290 RenderArcFarm(builder, paint,
1291 {
1292 .use_center = true,
1293 .full_circles = false,
1294 .sweeps_over_360 = true,
1295 });
1296
1297 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1298}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), x, and y.

◆ TEST_P() [353/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedArcsRenderCorrectlyWithSquareAndButtAndRoundEnds   
)

Definition at line 1329 of file aiks_dl_basic_unittests.cc.

1329 {
1330 DisplayListBuilder builder;
1331 builder.Scale(GetContentScale().x, GetContentScale().y);
1332 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1333
1334 DlPaint paint;
1335 paint.setDrawStyle(DlDrawStyle::kStroke);
1336 paint.setStrokeWidth(8.0f);
1337 paint.setStrokeCap(DlStrokeCap::kSquare);
1338 paint.setColor(DlColor::kRed());
1339
1340 RenderArcFarm(builder, paint,
1341 {
1342 .use_center = false,
1343 .full_circles = false,
1344 });
1345
1346 paint.setStrokeCap(DlStrokeCap::kRound);
1347 paint.setColor(DlColor::kGreen());
1348
1349 RenderArcFarm(builder, paint,
1350 {
1351 .use_center = false,
1352 .full_circles = false,
1353 });
1354
1355 paint.setStrokeCap(DlStrokeCap::kButt);
1356 paint.setColor(DlColor::kBlue());
1357
1358 RenderArcFarm(builder, paint,
1359 {
1360 .use_center = false,
1361 .full_circles = false,
1362 });
1363
1364 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1365}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), x, and y.

◆ TEST_P() [354/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedArcsRenderCorrectlyWithSquareAndButtEnds   
)

Definition at line 1300 of file aiks_dl_basic_unittests.cc.

1300 {
1301 DisplayListBuilder builder;
1302 builder.Scale(GetContentScale().x, GetContentScale().y);
1303 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1304
1305 DlPaint paint;
1306 paint.setDrawStyle(DlDrawStyle::kStroke);
1307 paint.setStrokeWidth(8.0f);
1308 paint.setStrokeCap(DlStrokeCap::kSquare);
1309 paint.setColor(DlColor::kRed());
1310
1311 RenderArcFarm(builder, paint,
1312 {
1313 .use_center = false,
1314 .full_circles = false,
1315 });
1316
1317 paint.setStrokeCap(DlStrokeCap::kButt);
1318 paint.setColor(DlColor::kBlue());
1319
1320 RenderArcFarm(builder, paint,
1321 {
1322 .use_center = false,
1323 .full_circles = false,
1324 });
1325
1326 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1327}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), x, and y.

◆ TEST_P() [355/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedArcsRenderCorrectlyWithSquareEnds   
)

Definition at line 1164 of file aiks_dl_basic_unittests.cc.

1164 {
1165 DisplayListBuilder builder;
1166 builder.Scale(GetContentScale().x, GetContentScale().y);
1167 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1168
1169 DlPaint paint;
1170 paint.setDrawStyle(DlDrawStyle::kStroke);
1171 paint.setStrokeWidth(6.0f);
1172 paint.setStrokeCap(DlStrokeCap::kSquare);
1173 paint.setColor(DlColor::kBlue());
1174
1175 RenderArcFarm(builder, paint,
1176 {
1177 .use_center = false,
1178 .full_circles = false,
1179 });
1180
1181 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1182}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), x, and y.

◆ TEST_P() [356/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedArcsRenderCorrectlyWithTranslucencyAndRoundEnds   
)

Definition at line 1219 of file aiks_dl_basic_unittests.cc.

1219 {
1220 DisplayListBuilder builder;
1221 builder.Scale(GetContentScale().x, GetContentScale().y);
1222 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1223
1224 DlPaint paint;
1225 paint.setDrawStyle(DlDrawStyle::kStroke);
1226 paint.setStrokeCap(DlStrokeCap::kRound);
1227 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1228
1229 RenderArcFarmForOverlappingCapsTest(builder, paint);
1230
1231 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1232}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), x, and y.

◆ TEST_P() [357/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedArcsRenderCorrectlyWithTranslucencyAndSquareEnds   
)

Definition at line 1184 of file aiks_dl_basic_unittests.cc.

1184 {
1185 DisplayListBuilder builder;
1186 builder.Scale(GetContentScale().x, GetContentScale().y);
1187 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1188
1189 DlPaint paint;
1190 paint.setDrawStyle(DlDrawStyle::kStroke);
1191 paint.setStrokeCap(DlStrokeCap::kSquare);
1192 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1193
1194 RenderArcFarmForOverlappingCapsTest(builder, paint);
1195
1196 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1197}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), x, and y.

◆ TEST_P() [358/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedCirclesRenderCorrectly   
)

Definition at line 775 of file aiks_dl_basic_unittests.cc.

775 {
776 DisplayListBuilder builder;
777 builder.Scale(GetContentScale().x, GetContentScale().y);
778 DlPaint paint;
779 const int color_count = 3;
780 DlColor colors[color_count] = {
781 DlColor::kBlue(),
782 DlColor::kGreen(),
783 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
784 };
785
786 paint.setColor(DlColor::kWhite());
787 builder.DrawPaint(paint);
788
789 int c_index = 0;
790
791 auto draw = [&paint, &colors, &c_index](DlCanvas& canvas, DlPoint center,
792 Scalar r, Scalar dr, int n) {
793 for (int i = 0; i < n; i++) {
794 paint.setColor(colors[(c_index++) % color_count]);
795 canvas.DrawCircle(center, r, paint);
796 r += dr;
797 }
798 };
799
800 paint.setDrawStyle(DlDrawStyle::kStroke);
801 paint.setStrokeWidth(1);
802 draw(builder, DlPoint(10, 10), 2, 2, 14); // r = [2, 28], covers [1,29]
803 paint.setStrokeWidth(5);
804 draw(builder, DlPoint(10, 10), 35, 10, 56); // r = [35, 585], covers [30,590]
805
806 DlColor gradient_colors[7] = {
807 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
808 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
809 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
810 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
811 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
812 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
813 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
814 };
815 DlScalar stops[7] = {
816 0.0,
817 (1.0 / 6.0) * 1,
818 (1.0 / 6.0) * 2,
819 (1.0 / 6.0) * 3,
820 (1.0 / 6.0) * 4,
821 (1.0 / 6.0) * 5,
822 1.0,
823 };
824 auto texture = CreateTextureForFixture("airplane.jpg",
825 /*enable_mipmapping=*/true);
826 auto image = DlImageImpeller::Make(texture);
827
828 paint.setColorSource(DlColorSource::MakeRadial(
829 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
830 draw(builder, DlPoint(500, 600), 5, 10, 10);
831
832 DlMatrix local_matrix = DlMatrix::MakeTranslation({700, 200});
833 paint.setColorSource(DlColorSource::MakeImage(
834 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
835 DlImageSampling::kNearestNeighbor, &local_matrix));
836 draw(builder, DlPoint(800, 300), 5, 10, 10);
837
838 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
839}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), i, image, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kWhite(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), flutter::DlColorSource::MakeRadial(), impeller::Matrix::MakeTranslation(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), texture, x, and y.

◆ TEST_P() [359/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedPathWithLargeStrokeWidthRendersCorrectly   
)

Definition at line 931 of file aiks_dl_basic_unittests.cc.

931 {
932 DrawStrokedAndFilledCirclesWithZoom(this, /*zoom=*/1.0f, /*radius=*/1.0f,
933 /*stroke_width=*/5.0f);
934}

◆ TEST_P() [360/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedPathWithMoveToThenCloseDrawnCorrectly   
)

Definition at line 536 of file aiks_dl_unittests.cc.

536 {
537 DlPathBuilder path_builder;
538 path_builder.MoveTo(DlPoint(0, 400))
539 .LineTo(DlPoint(0, 0))
540 .LineTo(DlPoint(400, 0))
541 // MoveTo implicitly adds a contour, ensure that close doesn't
542 // add another nearly-empty contour.
543 .MoveTo(DlPoint(0, 400))
544 .Close();
545 DlPath path = path_builder.TakePath();
546
547 DisplayListBuilder builder;
548 builder.Translate(50, 50);
549
550 DlPaint paint;
551 paint.setColor(DlColor::kBlue());
552 paint.setStrokeCap(DlStrokeCap::kRound);
553 paint.setStrokeWidth(10);
554 paint.setDrawStyle(DlDrawStyle::kStroke);
555 builder.DrawPath(path, paint);
556
557 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
558}

References flutter::DisplayListBuilder::Build(), flutter::DlPathBuilder::Close(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kBlue(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [361/662]

impeller::testing::TEST_P ( AiksTest  ,
StrokedRectsRenderCorrectly   
)

Definition at line 538 of file aiks_dl_basic_unittests.cc.

538 {
539 DisplayListBuilder builder;
540 builder.Scale(GetContentScale().x, GetContentScale().y);
541
542 DlPaint paint;
543 paint.setColor(DlColor::kPurple());
544 paint.setDrawStyle(DlDrawStyle::kStroke);
545 paint.setStrokeWidth(20.0f);
546
547 DlPaint thin_paint = paint;
548 thin_paint.setColor(DlColor::kYellow());
549 thin_paint.setStrokeWidth(0.0f);
550
551 DlRect rect = DlRect::MakeLTRB(10, 10, 90, 90);
552 DlRect thin_tall_rect = DlRect::MakeLTRB(120, 10, 120, 90);
553 DlRect thin_wide_rect = DlRect::MakeLTRB(10, 120, 90, 120);
554 DlRect empty_rect = DlRect::MakeLTRB(120, 120, 120, 120);
555
556 // We draw the following sets of rectangles:
557 //
558 // A E X
559 // X
560 // B F X
561 // X
562 // C D G H X
563 //
564 // Purple A,B,C,D are all drawn with stroke width 20 (non-overflowing).
565 // Each of those sets has 4 rectangles of dimension 80x80, 80x0, 0x80,
566 // and 0,0 to demonstrate the basic behavior and also the behavior of
567 // empty dimensions.
568 //
569 // Blue E,F,G,H are the same 80x80 rectangles, but with an overflowing
570 // stroke width of 120 to show the behavior with degenerately large
571 // stroke widths.
572 //
573 // A,E are drawn with Bevel joins.
574 // B,F are drawn with Round joins.
575 // C,G are drawn with Miter joins and a large enough miter limit.
576 // D,H are drawn with Miter joins and a too small miter limit (== Bevel).
577 //
578 // All orange X rectangles are drawn with round joins and increasing stroke
579 // widths to demonstrate fidelity of the rounding code at various arc sizes.
580 // These X rectangles also help test that the variable sizing estimates in
581 // the round join code are accurate.
582
583 // rects (A)
584 paint.setStrokeJoin(DlStrokeJoin::kBevel);
585 builder.DrawRect(rect.Shift({100, 100}), paint);
586 builder.DrawRect(rect.Shift({100, 100}), thin_paint);
587 builder.DrawRect(thin_tall_rect.Shift({100, 100}), paint);
588 builder.DrawRect(thin_tall_rect.Shift({100, 100}), thin_paint);
589 builder.DrawRect(thin_wide_rect.Shift({100, 100}), paint);
590 builder.DrawRect(thin_wide_rect.Shift({100, 100}), thin_paint);
591 builder.DrawRect(empty_rect.Shift({100, 100}), paint);
592 builder.DrawRect(empty_rect.Shift({100, 100}), thin_paint);
593
594 // rects (B)
595 paint.setStrokeJoin(DlStrokeJoin::kRound);
596 builder.DrawRect(rect.Shift({100, 300}), paint);
597 builder.DrawRect(rect.Shift({100, 300}), thin_paint);
598 builder.DrawRect(thin_tall_rect.Shift({100, 300}), paint);
599 builder.DrawRect(thin_tall_rect.Shift({100, 300}), thin_paint);
600 builder.DrawRect(thin_wide_rect.Shift({100, 300}), paint);
601 builder.DrawRect(thin_wide_rect.Shift({100, 300}), thin_paint);
602 builder.DrawRect(empty_rect.Shift({100, 300}), paint);
603 builder.DrawRect(empty_rect.Shift({100, 300}), thin_paint);
604
605 // rects (C)
606 paint.setStrokeJoin(DlStrokeJoin::kMiter);
608 builder.DrawRect(rect.Shift({100, 500}), paint);
609 builder.DrawRect(rect.Shift({100, 500}), thin_paint);
610 builder.DrawRect(thin_tall_rect.Shift({100, 500}), paint);
611 builder.DrawRect(thin_tall_rect.Shift({100, 500}), thin_paint);
612 builder.DrawRect(thin_wide_rect.Shift({100, 500}), paint);
613 builder.DrawRect(thin_wide_rect.Shift({100, 500}), thin_paint);
614 builder.DrawRect(empty_rect.Shift({100, 500}), paint);
615 builder.DrawRect(empty_rect.Shift({100, 500}), thin_paint);
616
617 // rects (D)
618 paint.setStrokeJoin(DlStrokeJoin::kMiter);
620 builder.DrawRect(rect.Shift({300, 500}), paint);
621 builder.DrawRect(rect.Shift({300, 500}), thin_paint);
622 builder.DrawRect(thin_tall_rect.Shift({300, 500}), paint);
623 builder.DrawRect(thin_tall_rect.Shift({300, 500}), thin_paint);
624 builder.DrawRect(thin_wide_rect.Shift({300, 500}), paint);
625 builder.DrawRect(thin_wide_rect.Shift({300, 500}), thin_paint);
626 builder.DrawRect(empty_rect.Shift({300, 500}), paint);
627 builder.DrawRect(empty_rect.Shift({300, 500}), thin_paint);
628
629 paint.setStrokeWidth(120.0f);
630 paint.setColor(DlColor::kBlue());
631 rect = rect.Expand(-20);
632
633 // rect (E)
634 paint.setStrokeJoin(DlStrokeJoin::kBevel);
635 builder.DrawRect(rect.Shift({500, 100}), paint);
636 builder.DrawRect(rect.Shift({500, 100}), thin_paint);
637
638 // rect (F)
639 paint.setStrokeJoin(DlStrokeJoin::kRound);
640 builder.DrawRect(rect.Shift({500, 300}), paint);
641 builder.DrawRect(rect.Shift({500, 300}), thin_paint);
642
643 // rect (G)
644 paint.setStrokeJoin(DlStrokeJoin::kMiter);
646 builder.DrawRect(rect.Shift({500, 500}), paint);
647 builder.DrawRect(rect.Shift({500, 500}), thin_paint);
648
649 // rect (H)
650 paint.setStrokeJoin(DlStrokeJoin::kMiter);
652 builder.DrawRect(rect.Shift({700, 500}), paint);
653 builder.DrawRect(rect.Shift({700, 500}), thin_paint);
654
655 DlPaint round_mock_paint;
656 round_mock_paint.setColor(DlColor::kGreen());
657 round_mock_paint.setDrawStyle(DlDrawStyle::kFill);
658
659 // array of rects (X)
660 Scalar x = 900;
661 Scalar y = 50;
662 for (int i = 0; i < 15; i++) {
663 paint.setStrokeWidth(i);
664 paint.setColor(DlColor::kOrange());
665 paint.setStrokeJoin(DlStrokeJoin::kRound);
666 builder.DrawRect(DlRect::MakeXYWH(x, y, 30, 30), paint);
667 y += 32 + i;
668 }
669
670 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
671}
static constexpr DlScalar kEhCloseEnough

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), impeller::TRect< T >::Expand(), i, flutter::DlColor::kBlue(), flutter::kEhCloseEnough, flutter::DlColor::kGreen(), flutter::DlColor::kOrange(), flutter::DlColor::kPurple(), impeller::kSqrt2, flutter::DlColor::kYellow(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeMiter(), flutter::DlPaint::setStrokeWidth(), impeller::TRect< T >::Shift(), x, and y.

◆ TEST_P() [362/662]

impeller::testing::TEST_P ( AiksTest  ,
SubpassWithClearColorOptimization   
)

Definition at line 1754 of file aiks_dl_basic_unittests.cc.

1754 {
1755 DisplayListBuilder builder;
1756
1757 // Use a non-srcOver blend mode to ensure that we don't detect this as an
1758 // opacity peephole optimization.
1759 DlPaint paint;
1760 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1761 paint.setBlendMode(DlBlendMode::kSrc);
1762
1763 DlRect bounds = DlRect::MakeLTRB(0, 0, 200, 200);
1764 builder.SaveLayer(bounds, &paint);
1765
1766 paint.setColor(DlColor::kTransparent());
1767 paint.setBlendMode(DlBlendMode::kSrc);
1768 builder.DrawPaint(paint);
1769 builder.Restore();
1770
1771 paint.setColor(DlColor::kBlue());
1772 paint.setBlendMode(DlBlendMode::kDstOver);
1773 builder.SaveLayer(std::nullopt, &paint);
1774 builder.Restore();
1775
1776 // This playground should appear blank on CI since we are only drawing
1777 // transparent black. If the clear color optimization is broken, the texture
1778 // will be filled with NaNs and may produce a magenta texture on macOS or iOS.
1779 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1780}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kBlue(), flutter::DlColor::kTransparent(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [363/662]

impeller::testing::TEST_P ( AiksTest  ,
SupportsBlitToOnscreen   
)

Definition at line 379 of file canvas_unittests.cc.

379 {
380 ContentContext& context = GetContentContext();
381 auto canvas = CreateTestCanvas(context, Rect::MakeLTRB(0, 0, 100, 100),
382 /*requires_readback=*/true);
383
384 if (GetBackend() != PlaygroundBackend::kMetal &&
385 GetBackend() != PlaygroundBackend::kMetalSDF) {
386 EXPECT_FALSE(canvas->SupportsBlitToOnscreen());
387 } else {
388 EXPECT_TRUE(canvas->SupportsBlitToOnscreen());
389 }
390}

References context, CreateTestCanvas(), impeller::kMetal, impeller::kMetalSDF, and impeller::TRect< Scalar >::MakeLTRB().

◆ TEST_P() [364/662]

impeller::testing::TEST_P ( AiksTest  ,
TextContentsMismatchedTransformTest   
)

Definition at line 720 of file aiks_dl_text_unittests.cc.

720 {
721 AiksContext aiks_context(GetContext(),
722 std::make_shared<TypographerContextSkia>());
723
724 // Verifies that TextContents only use the scale/transform that is
725 // computed during preroll.
726 constexpr const char* font_fixture = "Roboto-Regular.ttf";
727
728 // Construct the text blob.
729 auto c_font_fixture = std::string(font_fixture);
730 auto mapping = flutter::testing::OpenFixtureAsSkData(c_font_fixture.c_str());
731 ASSERT_TRUE(mapping);
732
733 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
734 SkFont sk_font(font_mgr->makeFromData(mapping), 16);
735
736 auto blob = SkTextBlob::MakeFromString("Hello World", sk_font);
737 ASSERT_TRUE(blob);
738
739 auto text_frame = MakeTextFrameFromTextBlobSkia(blob);
740
741 // Simulate recording the text frame during preroll.
742 Matrix preroll_matrix =
743 Matrix::MakeTranslateScale({1.5, 1.5, 1}, {100, 50, 0});
744 Point preroll_point = Point{23, 45};
745 {
746 aiks_context.GetContentContext().GetLazyGlyphAtlas()->AddTextFrame(
747 text_frame, //
748 preroll_point, //
749 preroll_matrix, //
750 GlyphProperties{} //
751 );
752 }
753
754 // Now simulate rendering with a slightly different scale factor.
755 RenderTarget render_target =
756 aiks_context.GetContentContext()
757 .GetRenderTargetCache()
758 ->CreateOffscreenMSAA(*aiks_context.GetContext(), {100, 100}, 1);
759
760 TextContents text_contents;
761 text_contents.SetTextFrame(text_frame);
762 text_contents.SetPosition(preroll_point);
763 text_contents.SetScreenTransform(preroll_matrix);
764 text_contents.SetColor(Color::Aqua());
765
766 Matrix not_preroll_matrix =
767 preroll_matrix * Matrix::MakeScale({2.0f, 2.0f, 1.0f});
768
769 Entity entity;
770 entity.SetTransform(not_preroll_matrix);
771
772 std::shared_ptr<CommandBuffer> command_buffer =
773 aiks_context.GetContext()->CreateCommandBuffer();
774 std::shared_ptr<RenderPass> render_pass =
775 command_buffer->CreateRenderPass(render_target);
776
777 EXPECT_TRUE(text_contents.Render(aiks_context.GetContentContext(), entity,
778 *render_pass));
779}
void SetPosition(Point position)
void SetScreenTransform(const Matrix &transform)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void SetTextFrame(const std::shared_ptr< TextFrame > &frame)
void SetColor(Color color)
static constexpr Color Aqua()
Definition color.h:295
static constexpr Matrix MakeTranslateScale(const Vector3 &s, const Vector3 &t)
Definition matrix.h:113
static constexpr Matrix MakeScale(const Vector3 &s)
Definition matrix.h:104

References impeller::Color::Aqua(), command_buffer, impeller::AiksContext::GetContentContext(), impeller::AiksContext::GetContext(), txt::GetDefaultFontManager(), impeller::ContentContext::GetLazyGlyphAtlas(), impeller::ContentContext::GetRenderTargetCache(), impeller::Matrix::MakeScale(), impeller::MakeTextFrameFromTextBlobSkia(), impeller::Matrix::MakeTranslateScale(), flutter::testing::OpenFixtureAsSkData(), impeller::TextContents::Render(), render_pass, impeller::TextContents::SetColor(), impeller::TextContents::SetPosition(), impeller::TextContents::SetScreenTransform(), impeller::TextContents::SetTextFrame(), and impeller::Entity::SetTransform().

◆ TEST_P() [365/662]

impeller::testing::TEST_P ( AiksTest  ,
TextForegroundShaderWithTransform   
)

Definition at line 605 of file aiks_dl_text_unittests.cc.

605 {
606 auto mapping = flutter::testing::OpenFixtureAsSkData("Roboto-Regular.ttf");
607 ASSERT_NE(mapping, nullptr);
608
609 Scalar font_size = 100;
610 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
611 SkFont sk_font(font_mgr->makeFromData(mapping), font_size);
612
613 DlPaint text_paint;
614 text_paint.setColor(DlColor::kBlue());
615
616 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
617 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0)};
618 std::vector<Scalar> stops = {
619 0.0,
620 1.0,
621 };
623 /*start_point=*/DlPoint(0, 0), //
624 /*end_point=*/DlPoint(100, 100), //
625 /*stop_count=*/2, //
626 /*colors=*/colors.data(), //
627 /*stops=*/stops.data(), //
628 /*tile_mode=*/DlTileMode::kRepeat //
629 ));
630
631 DisplayListBuilder builder;
632 builder.Translate(100, 100);
633 builder.Rotate(45);
634
635 auto blob = SkTextBlob::MakeFromString("Hello", sk_font);
636 ASSERT_NE(blob, nullptr);
637 auto frame = MakeTextFrameFromTextBlobSkia(blob);
638 builder.DrawText(DlTextImpeller::Make(frame), 0, 0, text_paint);
639
640 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
641}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawText(), font_size, txt::GetDefaultFontManager(), flutter::DlColor::kBlue(), flutter::DlTextImpeller::Make(), flutter::DlColorSource::MakeLinear(), impeller::MakeTextFrameFromTextBlobSkia(), flutter::testing::OpenFixtureAsSkData(), flutter::DlColor::RGBA(), flutter::DisplayListBuilder::Rotate(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [366/662]

impeller::testing::TEST_P ( AiksTest  ,
TextFramesDoNotShareRenderDataBigSmall   
)

Definition at line 1054 of file aiks_dl_text_unittests.cc.

1054 {
1055 DrawTextFramesMultipleScalesWithReuse(this, //
1056 /*first_scale=*/4.0f, //
1057 /*second_scale=*/0.5f);
1058}

◆ TEST_P() [367/662]

impeller::testing::TEST_P ( AiksTest  ,
TextFramesDoNotShareRenderDataSmallBig   
)

Definition at line 1060 of file aiks_dl_text_unittests.cc.

1060 {
1061 DrawTextFramesMultipleScalesWithReuse(this, //
1062 /*first_scale=*/0.5f, //
1063 /*second_scale=*/4.0f);
1064}

◆ TEST_P() [368/662]

impeller::testing::TEST_P ( AiksTest  ,
TextFrameSubpixelAlignment   
)

Definition at line 319 of file aiks_dl_text_unittests.cc.

319 {
320 // "Random" numbers between 0 and 1. Hardcoded to avoid flakiness in goldens.
321 std::array<Scalar, 20> phase_offsets = {
322 7.82637e-06, 0.131538, 0.755605, 0.45865, 0.532767,
323 0.218959, 0.0470446, 0.678865, 0.679296, 0.934693,
324 0.383502, 0.519416, 0.830965, 0.0345721, 0.0534616,
325 0.5297, 0.671149, 0.00769819, 0.383416, 0.0668422};
326 auto callback = [&]() -> sk_sp<DisplayList> {
327 static float font_size = 20;
328 static float phase_variation = 0.2;
329 static float speed = 0.5;
330 static float magnitude = 100;
331 if (IsPlaygroundEnabled()) {
332 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
333 ImGui::SliderFloat("Font size", &font_size, 5, 50);
334 ImGui::SliderFloat("Phase variation", &phase_variation, 0, 1);
335 ImGui::SliderFloat("Oscillation speed", &speed, 0, 2);
336 ImGui::SliderFloat("Oscillation magnitude", &magnitude, 0, 300);
337 ImGui::End();
338 }
339
340 DisplayListBuilder builder;
341 builder.Scale(GetContentScale().x, GetContentScale().y);
342
343 for (size_t i = 0; i < phase_offsets.size(); i++) {
344 DlPoint position = DlPoint(
345 200 +
346 magnitude * std::sin((-phase_offsets[i] * k2Pi * phase_variation +
347 GetSecondsElapsed() * speed)), //
348 200 + i * font_size * 1.1 //
349 );
350 if (!RenderTextInCanvasSkia(
351 GetContext(), builder,
352 "the quick brown fox jumped over "
353 "the lazy dog!.?",
354 "Roboto-Regular.ttf",
355 {.font_size = font_size, .position = position})) {
356 return nullptr;
357 }
358 }
359 return builder.Build();
360 };
361
362 ASSERT_TRUE(OpenPlaygroundHere(callback));
363}

References flutter::DisplayListBuilder::Build(), callback, font_size, i, impeller::k2Pi, RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), x, and y.

◆ TEST_P() [369/662]

impeller::testing::TEST_P ( AiksTest  ,
TextGammaCorrectionGoldenTest   
)

Definition at line 1111 of file aiks_dl_text_unittests.cc.

1111 {
1112 constexpr const char* font_fixture = "Roboto-Regular.ttf";
1113 auto c_font_fixture = std::string(font_fixture);
1114 auto mapping = flutter::testing::OpenFixtureAsSkData(c_font_fixture.c_str());
1115 ASSERT_TRUE(mapping);
1116
1117 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
1118 SkFont sk_font(/*typeface=*/font_mgr->makeFromData(mapping), /*size=*/60);
1119 sk_font.setSubpixel(true);
1120
1121 auto blob_corrected =
1122 SkTextBlob::MakeFromString("Gamma Corrected (true)", sk_font);
1123 ASSERT_TRUE(blob_corrected);
1124 auto text_frame_corrected = MakeTextFrameFromTextBlobSkia(blob_corrected);
1125 text_frame_corrected->SetEnableGammaCorrection(true);
1126
1127 auto blob_uncorrected =
1128 SkTextBlob::MakeFromString("Gamma Corrected (false)", sk_font);
1129 ASSERT_TRUE(blob_uncorrected);
1130 auto text_frame_uncorrected = MakeTextFrameFromTextBlobSkia(blob_uncorrected);
1131 text_frame_uncorrected->SetEnableGammaCorrection(false);
1132
1133 auto callback = [&]() -> sk_sp<flutter::DisplayList> {
1134 DisplayListBuilder builder;
1135
1136 DlPaint bg_paint;
1137 bg_paint.setColor(DlColor::ARGB(1.0, 0.1, 0.1, 0.1));
1138 builder.DrawPaint(bg_paint);
1139
1140 DlPaint text_paint;
1141 text_paint.setColor(DlColor::kWhite());
1142
1143 builder.DrawText(/*text=*/DlTextImpeller::Make(text_frame_corrected),
1144 /*x=*/50, /*y=*/100, /*paint=*/text_paint);
1145 builder.DrawText(/*text=*/DlTextImpeller::Make(text_frame_uncorrected),
1146 /*x=*/50, /*y=*/200, /*paint=*/text_paint);
1147
1148 builder.DrawText(/*text=*/DlTextImpeller::Make(text_frame_corrected),
1149 /*x=*/50, /*y=*/300, /*paint=*/text_paint);
1150 DlPaint diff_paint = text_paint;
1151 diff_paint.setBlendMode(DlBlendMode::kDifference);
1152 builder.DrawText(/*text=*/DlTextImpeller::Make(text_frame_uncorrected),
1153 /*x=*/50, /*y=*/300, /*paint=*/diff_paint);
1154
1155 return builder.Build();
1156 };
1157
1158 ASSERT_TRUE(OpenPlaygroundHere(callback));
1159}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawText(), txt::GetDefaultFontManager(), flutter::DlColor::kWhite(), flutter::DlTextImpeller::Make(), impeller::MakeTextFrameFromTextBlobSkia(), flutter::testing::OpenFixtureAsSkData(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [370/662]

impeller::testing::TEST_P ( AiksTest  ,
TextRotated   
)

Definition at line 491 of file aiks_dl_text_unittests.cc.

491 {
492 // This test used to be intentionally excluded for impeller_golden_tests
493 // but when the SDF backend variants were added, the explicit exclusions
494 // for those backends were not added to the exclusion list. So it has
495 // actually been running just fine for a while now generating goldens
496 // for the SDF backends.
497 // We will let it run on all backends now in the playground-based golden
498 // mechanism as the underlying flakiness may have been resolved since the
499 // exclusion was added.
500 // https://github.com/flutter/flutter/blame/ad80825c24d770a19e33f67800fc0338a3b89ec7/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc#L107
501
502 DisplayListBuilder builder;
503
504 builder.Scale(GetContentScale().x, GetContentScale().y);
505 DlPaint paint;
506 paint.setColor(DlColor::ARGB(0.1, 0.1, 0.1, 1.0));
507 builder.DrawPaint(paint);
508
509 builder.Transform(Matrix(0.25, -0.3, 0, -0.002, //
510 0, 0.5, 0, 0, //
511 0, 0, 0.3, 0, //
512 100, 100, 0, 1.3));
513 ASSERT_TRUE(RenderTextInCanvasSkia(
514 GetContext(), builder, "the quick brown fox jumped over the lazy dog!.?",
515 "Roboto-Regular.ttf"));
516
517 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
518}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DisplayListBuilder::Transform(), x, and y.

◆ TEST_P() [371/662]

impeller::testing::TEST_P ( AiksTest  ,
TextRotated180Degrees   
)

Definition at line 282 of file aiks_dl_text_unittests.cc.

282 {
283 float fpivot[2] = {200 + 30, 200 - 20};
284 float rotation = 180;
285 float foffset[2] = {200, 200};
286
287 auto callback = [&]() -> sk_sp<DisplayList> {
288 if (IsPlaygroundEnabled()) {
289 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
290 ImGui::SliderFloat("pivotx", &fpivot[0], 0, 300);
291 ImGui::SliderFloat("pivoty", &fpivot[1], 0, 300);
292 ImGui::SliderFloat("rotation", &rotation, 0, 360);
293 ImGui::SliderFloat("foffsetx", &foffset[0], 0, 300);
294 ImGui::SliderFloat("foffsety", &foffset[1], 0, 300);
295 ImGui::End();
296 }
297 DisplayListBuilder builder;
298 builder.Scale(GetContentScale().x, GetContentScale().y);
299 builder.DrawPaint(DlPaint().setColor(DlColor(0xffffeeff)));
300
301 builder.Save();
302 DlPoint pivot = Point(fpivot[0], fpivot[1]);
303 builder.Translate(pivot.x, pivot.y);
304 builder.Rotate(rotation);
305 builder.Translate(-pivot.x, -pivot.y);
306
307 RenderTextInCanvasSkia(GetContext(), builder, "test", "Roboto-Regular.ttf",
308 TextRenderOptions{
309 .color = DlColor::kBlack(),
310 .position = DlPoint(foffset[0], foffset[1]),
311 });
312
313 builder.Restore();
314 return builder.Build();
315 };
316 ASSERT_TRUE(OpenPlaygroundHere(callback));
317}

References flutter::DisplayListBuilder::Build(), callback, impeller::testing::TextRenderOptions::color, flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kBlack(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Rotate(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DisplayListBuilder::Translate(), x, impeller::TPoint< T >::x, impeller::TPoint< T >::y, and y.

◆ TEST_P() [372/662]

impeller::testing::TEST_P ( AiksTest  ,
TextWithNonUniformScale   
)

Definition at line 1069 of file aiks_dl_text_unittests.cc.

1069 {
1070 DisplayListBuilder builder;
1071
1072 DlPaint paint;
1073 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
1074 builder.DrawPaint(paint);
1075
1076 // Row 1: Uniform scale (should use nearest-neighbor, pixel-perfect).
1077 builder.Save();
1078 builder.Scale(2, 2);
1079 ASSERT_TRUE(RenderTextInCanvasSkia(
1080 GetContext(), builder, "Uniform 2x2", "Roboto-Regular.ttf",
1081 TextRenderOptions{.font_size = 30, .position = DlPoint(20, 40)}));
1082 builder.Restore();
1083
1084 // Row 2: Non-uniform scale Y-only (ratio 2.0, triggers bilinear).
1085 builder.Save();
1086 builder.Scale(1, 2);
1087 ASSERT_TRUE(RenderTextInCanvasSkia(
1088 GetContext(), builder, "ScaleY 1x2", "Roboto-Regular.ttf",
1089 TextRenderOptions{.font_size = 30, .position = DlPoint(20, 140)}));
1090 builder.Restore();
1091
1092 // Row 3: Non-uniform scale X-only (ratio 3.0, triggers bilinear).
1093 builder.Save();
1094 builder.Scale(3, 1);
1095 ASSERT_TRUE(RenderTextInCanvasSkia(
1096 GetContext(), builder, "ScaleX 3x1", "Roboto-Regular.ttf",
1097 TextRenderOptions{.font_size = 30, .position = DlPoint(20, 300)}));
1098 builder.Restore();
1099
1100 // Row 4: Slightly non-uniform (ratio 1.1, below threshold, nearest).
1101 builder.Save();
1102 builder.Scale(2, 2.2);
1103 ASSERT_TRUE(RenderTextInCanvasSkia(
1104 GetContext(), builder, "Near-uniform 2x2.2", "Roboto-Regular.ttf",
1105 TextRenderOptions{.font_size = 30, .position = DlPoint(20, 200)}));
1106 builder.Restore();
1107
1108 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1109}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), impeller::testing::TextRenderOptions::font_size, RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), and flutter::DlPaint::setColor().

◆ TEST_P() [373/662]

impeller::testing::TEST_P ( AiksTest  ,
TextWithShadowAndPosition   
)

Definition at line 1161 of file aiks_dl_text_unittests.cc.

1161 {
1162 DisplayListBuilder builder;
1163 builder.Scale(GetContentScale().x, GetContentScale().y);
1164 builder.Clear(DlColor::kWhite());
1165
1166 auto frame = MakeDefaultTextFrame("Hello", 25.0f);
1167 auto text = DlTextImpeller::Make(frame);
1169 DlPaint shadow_paint_ctm = DlPaint().setMaskFilter(
1170 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 5.0f, true));
1171 DlPaint shadow_paint_no_ctm = DlPaint().setMaskFilter(
1172 DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 5.0f, false));
1173
1174 builder.Translate(100, 100);
1175 builder.Scale(4, 4);
1176 for (int x = 10; x <= 100; x += 30) {
1177 builder.DrawText(text, x, 20, shadow_paint_ctm);
1178 builder.DrawText(text, x, 20, paint);
1179
1180 builder.DrawText(text, x, 50, shadow_paint_no_ctm);
1181 builder.DrawText(text, x, 50, paint);
1182 }
1183
1184 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1185}
static constexpr DlColor kMagenta()
Definition dl_color.h:75

References flutter::DisplayListBuilder::Build(), flutter::DlCanvas::Clear(), flutter::DisplayListBuilder::DrawText(), flutter::DlColor::kMagenta(), flutter::DlColor::kWhite(), flutter::DlTextImpeller::Make(), flutter::DlBlurMaskFilter::Make(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), text, flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [374/662]

impeller::testing::TEST_P ( AiksTest  ,
TextWithShadowCache   
)

Definition at line 823 of file aiks_dl_text_unittests.cc.

823 {
824 DisplayListBuilder builder;
825 builder.Scale(GetContentScale().x, GetContentScale().y);
826 DlPaint paint;
827 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
828 builder.DrawPaint(paint);
829
830 AiksContext aiks_context(GetContext(),
831 std::make_shared<TypographerContextSkia>());
832 // Cache empty
833 EXPECT_EQ(aiks_context.GetContentContext()
834 .GetTextShadowCache()
835 .GetCacheSizeForTesting(),
836 0u);
837
838 ASSERT_TRUE(RenderTextInCanvasSkia(
839 GetContext(), builder, "Hello World", kFontFixture,
842 .filter = DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 4)}));
843
844 DisplayListToTexture(builder.Build(), {400, 400}, aiks_context);
845
846 // Text should be cached.
847 EXPECT_EQ(aiks_context.GetContentContext()
848 .GetTextShadowCache()
849 .GetCacheSizeForTesting(),
850 1u);
851}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), impeller::testing::TextRenderOptions::color, impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawPaint(), impeller::TextShadowCache::GetCacheSizeForTesting(), impeller::AiksContext::GetContentContext(), impeller::ContentContext::GetTextShadowCache(), flutter::DlColor::kBlue(), kFontFixture, flutter::DlBlurMaskFilter::Make(), RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [375/662]

impeller::testing::TEST_P ( AiksTest  ,
ToImageFromImage   
)

Definition at line 1046 of file aiks_dl_unittests.cc.

1046 {
1047 DisplayListBuilder builder;
1048 DlPath path = DlPath::MakeArc(DlRect::MakeLTRB(0, 0, 100, 100), DlDegrees(0),
1049 DlDegrees(90),
1050 /*use_center=*/true);
1051
1052 builder.DrawPath(path, DlPaint().setColor(DlColor::kRed()));
1053
1054 AiksContext renderer(GetContext(), nullptr);
1055 auto texture =
1056 DisplayListToTexture(builder.Build(), ISize(100, 100), renderer);
1057
1058 // First, Readback the texture data into a host buffer.
1060 desc.size = texture->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
1061 desc.readback = true;
1062 desc.storage_mode = StorageMode::kHostVisible;
1063
1064 auto device_buffer = GetContext()->GetResourceAllocator()->CreateBuffer(desc);
1065 {
1066 auto cmd_buffer = GetContext()->CreateCommandBuffer();
1067 auto blit_pass = cmd_buffer->CreateBlitPass();
1068
1069 blit_pass->AddCopy(texture, device_buffer);
1070 blit_pass->EncodeCommands();
1071
1072 auto latch = std::make_shared<fml::CountDownLatch>(1u);
1073 GetContext()->GetCommandQueue()->Submit(
1074 {cmd_buffer},
1075 [latch](CommandBuffer::Status status) { latch->CountDown(); });
1076 latch->Wait();
1077 }
1078
1079 impeller::TextureDescriptor tex_desc = texture->GetTextureDescriptor();
1080 auto reupload_texture =
1081 GetContext()->GetResourceAllocator()->CreateTexture(tex_desc);
1082
1083 // Next, Re-upload the data into a new texture.
1084 {
1085 auto cmd_buffer = GetContext()->CreateCommandBuffer();
1086 auto blit_pass = cmd_buffer->CreateBlitPass();
1087 blit_pass->AddCopy(DeviceBuffer::AsBufferView(device_buffer),
1088 reupload_texture);
1089 blit_pass->ConvertTextureToShaderRead(texture);
1090 blit_pass->EncodeCommands();
1091
1092 auto latch = std::make_shared<fml::CountDownLatch>(1u);
1093 GetContext()->GetCommandQueue()->Submit(
1094 {cmd_buffer},
1095 [latch](CommandBuffer::Status status) { latch->CountDown(); });
1096 latch->Wait();
1097 }
1098
1099 // Draw the results side by side. These should look the same.
1100 DisplayListBuilder canvas;
1101 DlPaint paint = DlPaint();
1102 canvas.DrawRect(
1103 DlRect::MakeLTRB(0, 0, 100, 100),
1104 DlPaint().setColor(DlColor::kBlue()).setDrawStyle(DlDrawStyle::kStroke));
1105 canvas.DrawImage(DlImageImpeller::Make(texture), DlPoint(0, 0),
1106 DlImageSampling::kNearestNeighbor, &paint);
1107
1108 canvas.DrawRect(
1109 DlRect::MakeLTRB(0, 100, 100, 200),
1110 DlPaint().setColor(DlColor::kRed()).setDrawStyle(DlDrawStyle::kStroke));
1111 canvas.DrawImage(DlImageImpeller::Make(reupload_texture), DlPoint(0, 100),
1112 DlImageSampling::kNearestNeighbor, &paint);
1113 OpenPlaygroundHere(canvas.Build());
1114}

References impeller::DeviceBuffer::AsBufferView(), flutter::DisplayListBuilder::Build(), impeller::DisplayListToTexture(), flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), impeller::kHostVisible, flutter::DlColor::kRed(), impeller::DlImageImpeller::Make(), flutter::DlPath::MakeArc(), impeller::TRect< Scalar >::MakeLTRB(), flutter::path, impeller::DeviceBufferDescriptor::readback, impeller::DeviceBufferDescriptor::size, impeller::DeviceBufferDescriptor::storage_mode, and texture.

◆ TEST_P() [376/662]

impeller::testing::TEST_P ( AiksTest  ,
TransformMultipliesCorrectly   
)

Definition at line 72 of file canvas_unittests.cc.

72 {
73 ContentContext& context = GetContentContext();
74 auto canvas = CreateTestCanvas(context);
75
76 ASSERT_MATRIX_NEAR(canvas->GetCurrentTransform(), Matrix());
77
78 // clang-format off
79 canvas->Translate(Vector3(100, 200));
81 canvas->GetCurrentTransform(),
82 Matrix( 1, 0, 0, 0,
83 0, 1, 0, 0,
84 0, 0, 1, 0,
85 100, 200, 0, 1));
86
87 canvas->Rotate(Radians(kPiOver2));
89 canvas->GetCurrentTransform(),
90 Matrix( 0, 1, 0, 0,
91 -1, 0, 0, 0,
92 0, 0, 1, 0,
93 100, 200, 0, 1));
94
95 canvas->Scale(Vector3(2, 3));
97 canvas->GetCurrentTransform(),
98 Matrix( 0, 2, 0, 0,
99 -3, 0, 0, 0,
100 0, 0, 0, 0,
101 100, 200, 0, 1));
102
103 canvas->Translate(Vector3(100, 200));
105 canvas->GetCurrentTransform(),
106 Matrix( 0, 2, 0, 0,
107 -3, 0, 0, 0,
108 0, 0, 0, 0,
109 -500, 400, 0, 1));
110 // clang-format on
111}

References ASSERT_MATRIX_NEAR, context, CreateTestCanvas(), and impeller::kPiOver2.

◆ TEST_P() [377/662]

impeller::testing::TEST_P ( AiksTest  ,
TranslucentFilledArcsRenderCorrectly   
)

Definition at line 1074 of file aiks_dl_basic_unittests.cc.

1074 {
1075 DisplayListBuilder builder;
1076 builder.Scale(GetContentScale().x, GetContentScale().y);
1077 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1078
1079 DlPaint paint;
1080 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1081
1082 RenderArcFarm(builder, paint,
1083 {
1084 .use_center = false,
1085 .full_circles = false,
1086 });
1087
1088 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1089}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DlColor::kBlue(), flutter::DlColor::kWhite(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [378/662]

impeller::testing::TEST_P ( AiksTest  ,
TranslucentSaveLayerDrawsCorrectly   
)

Definition at line 139 of file aiks_dl_unittests.cc.

139 {
140 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
141
142 DlPaint paint;
143 paint.setColor(DlColor::kBlue());
144 builder.DrawRect(DlRect::MakeXYWH(100, 100, 300, 300), paint);
145
146 DlPaint save_paint;
147 save_paint.setColor(DlColor::kBlack().withAlpha(128));
148 builder.SaveLayer(std::nullopt, &save_paint);
149 builder.DrawRect(DlRect::MakeXYWH(100, 500, 300, 300), paint);
150 builder.Restore();
151
152 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
153}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlack(), flutter::DlColor::kBlue(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [379/662]

impeller::testing::TEST_P ( AiksTest  ,
TranslucentSaveLayerImageDrawsCorrectly   
)

Definition at line 250 of file aiks_dl_unittests.cc.

250 {
251 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
252
253 auto image = DlImageImpeller::Make(CreateTextureForFixture("airplane.jpg"));
254 builder.DrawImage(image, DlPoint(100, 100), DlImageSampling::kMipmapLinear);
255
256 DlPaint paint;
257 paint.setColor(DlColor::kBlack().withAlpha(128));
258 builder.SaveLayer(std::nullopt, &paint);
259 builder.DrawImage(image, DlPoint(100, 500), DlImageSampling::kMipmapLinear);
260 builder.Restore();
261
262 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
263}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), image, flutter::DlColor::kBlack(), impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeSize(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setColor().

◆ TEST_P() [380/662]

impeller::testing::TEST_P ( AiksTest  ,
TranslucentSaveLayerWithAdvancedBlendModeDrawsCorrectly   
)

Definition at line 335 of file aiks_dl_unittests.cc.

335 {
336 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
337
338 DlPaint paint;
339 paint.setColor(DlColor::kRed());
340 builder.DrawRect(DlRect::MakeXYWH(0, 0, 400, 400), paint);
341
342 DlPaint save_paint;
343 save_paint.setAlpha(128);
344 save_paint.setBlendMode(DlBlendMode::kLighten);
345 builder.SaveLayer(std::nullopt, &save_paint);
346
347 DlPaint draw_paint;
348 draw_paint.setColor(DlColor::kGreen());
349 builder.DrawCircle(DlPoint(200, 200), 100, draw_paint);
350 builder.Restore();
351
352 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
353}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setAlpha(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColor().

◆ TEST_P() [381/662]

impeller::testing::TEST_P ( AiksTest  ,
TranslucentSaveLayerWithBlendColorFilterDrawsCorrectly   
)

Definition at line 155 of file aiks_dl_unittests.cc.

155 {
156 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
157
158 DlPaint paint;
159 paint.setColor(DlColor::kBlue());
160 builder.DrawRect(DlRect::MakeXYWH(100, 100, 300, 300), paint);
161
162 DlPaint save_paint;
163 paint.setColor(DlColor::kBlack().withAlpha(128));
164 paint.setColorFilter(
165 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kDstOver));
166 builder.Save();
167 builder.ClipRect(DlRect::MakeXYWH(100, 500, 300, 300));
168 builder.SaveLayer(std::nullopt, &paint);
169
170 DlPaint draw_paint;
171 draw_paint.setColor(DlColor::kBlue());
172 builder.DrawRect(DlRect::MakeXYWH(100, 500, 300, 300), draw_paint);
173 builder.Restore();
174 builder.Restore();
175
176 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
177}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlack(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColorFilter::MakeBlend(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), and flutter::DlPaint::setColorFilter().

◆ TEST_P() [382/662]

impeller::testing::TEST_P ( AiksTest  ,
TranslucentSaveLayerWithBlendImageFilterDrawsCorrectly   
)

Definition at line 179 of file aiks_dl_unittests.cc.

179 {
180 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
181
182 DlPaint paint;
183 paint.setColor(DlColor::kBlue());
184 builder.DrawRect(DlRect::MakeXYWH(100, 100, 300, 300), paint);
185
186 DlPaint save_paint;
187 save_paint.setColor(DlColor::kBlack().withAlpha(128));
188 save_paint.setImageFilter(DlImageFilter::MakeColorFilter(
189 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kDstOver)));
190
191 builder.SaveLayer(std::nullopt, &save_paint);
192
193 DlPaint draw_paint;
194 draw_paint.setColor(DlColor::kBlue());
195 builder.DrawRect(DlRect::MakeXYWH(100, 500, 300, 300), draw_paint);
196 builder.Restore();
197
198 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
199}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlack(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColorFilter::MakeBlend(), flutter::DlImageFilter::MakeColorFilter(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), and flutter::DlPaint::setImageFilter().

◆ TEST_P() [383/662]

impeller::testing::TEST_P ( AiksTest  ,
TranslucentSaveLayerWithColorAndImageFilterDrawsCorrectly   
)

Definition at line 201 of file aiks_dl_unittests.cc.

201 {
202 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
203
204 DlPaint paint;
205 paint.setColor(DlColor::kBlue());
206 builder.DrawRect(DlRect::MakeXYWH(100, 100, 300, 300), paint);
207
208 DlPaint save_paint;
209 save_paint.setColor(DlColor::kBlack().withAlpha(128));
210 save_paint.setColorFilter(
211 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kDstOver));
212 builder.Save();
213 builder.ClipRect(DlRect::MakeXYWH(100, 500, 300, 300));
214 builder.SaveLayer(std::nullopt, &save_paint);
215
216 DlPaint draw_paint;
217 draw_paint.setColor(DlColor::kBlue());
218 builder.DrawRect(DlRect::MakeXYWH(100, 500, 300, 300), draw_paint);
219 builder.Restore();
220 builder.Restore();
221
222 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
223}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlack(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), flutter::DlColorFilter::MakeBlend(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), and flutter::DlPaint::setColorFilter().

◆ TEST_P() [384/662]

impeller::testing::TEST_P ( AiksTest  ,
TranslucentSaveLayerWithColorFilterAndImageFilterDrawsCorrectly   
)

Definition at line 309 of file aiks_dl_unittests.cc.

310 {
311 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
312
313 auto image = DlImageImpeller::Make(CreateTextureForFixture("airplane.jpg"));
314 builder.DrawImage(image, DlPoint(100, 100), {});
315
316 const float matrix[20] = {
317 1, 0, 0, 0, 0, //
318 0, 1, 0, 0, 0, //
319 0, 0.2, 1, 0, 0, //
320 0, 0, 0, 0.5, 0 //
321 };
322 DlPaint paint;
323 paint.setColor(DlColor::kBlack().withAlpha(128));
324 paint.setImageFilter(
325 DlImageFilter::MakeColorFilter(DlColorFilter::MakeMatrix(matrix)));
326 paint.setColorFilter(
327 DlColorFilter::MakeBlend(DlColor::kGreen(), DlBlendMode::kModulate));
328 builder.SaveLayer(std::nullopt, &paint);
329 builder.DrawImage(image, DlPoint(100, 500), {});
330 builder.Restore();
331
332 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
333}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), image, flutter::DlColor::kBlack(), flutter::DlColor::kGreen(), impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeBlend(), flutter::DlImageFilter::MakeColorFilter(), flutter::DlColorFilter::MakeMatrix(), impeller::TRect< Scalar >::MakeSize(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), and flutter::DlPaint::setImageFilter().

◆ TEST_P() [385/662]

impeller::testing::TEST_P ( AiksTest  ,
TranslucentSaveLayerWithColorMatrixColorFilterDrawsCorrectly   
)

Definition at line 265 of file aiks_dl_unittests.cc.

265 {
266 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
267
268 auto image = DlImageImpeller::Make(CreateTextureForFixture("airplane.jpg"));
269 builder.DrawImage(image, DlPoint(100, 100), {});
270
271 const float matrix[20] = {
272 1, 0, 0, 0, 0, //
273 0, 1, 0, 0, 0, //
274 0, 0, 1, 0, 0, //
275 0, 0, 0, 2, 0 //
276 };
277 DlPaint paint;
278 paint.setColor(DlColor::kBlack().withAlpha(128));
279 paint.setColorFilter(DlColorFilter::MakeMatrix(matrix));
280 builder.SaveLayer(std::nullopt, &paint);
281 builder.DrawImage(image, DlPoint(100, 500), {});
282 builder.Restore();
283
284 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
285}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), image, flutter::DlColor::kBlack(), impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeMatrix(), impeller::TRect< Scalar >::MakeSize(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), and flutter::DlPaint::setColorFilter().

◆ TEST_P() [386/662]

impeller::testing::TEST_P ( AiksTest  ,
TranslucentSaveLayerWithColorMatrixImageFilterDrawsCorrectly   
)

Definition at line 287 of file aiks_dl_unittests.cc.

287 {
288 DisplayListBuilder builder(DlRect::MakeSize(GetWindowSize()));
289
290 auto image = DlImageImpeller::Make(CreateTextureForFixture("airplane.jpg"));
291 builder.DrawImage(image, DlPoint(100, 100), {});
292
293 const float matrix[20] = {
294 1, 0, 0, 0, 0, //
295 0, 1, 0, 0, 0, //
296 0, 0, 1, 0, 0, //
297 0, 0, 0, 2, 0 //
298 };
299 DlPaint paint;
300 paint.setColor(DlColor::kBlack().withAlpha(128));
301 paint.setColorFilter(DlColorFilter::MakeMatrix(matrix));
302 builder.SaveLayer(std::nullopt, &paint);
303 builder.DrawImage(image, DlPoint(100, 500), {});
304 builder.Restore();
305
306 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
307}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), image, flutter::DlColor::kBlack(), impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeMatrix(), impeller::TRect< Scalar >::MakeSize(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setColor(), and flutter::DlPaint::setColorFilter().

◆ TEST_P() [387/662]

impeller::testing::TEST_P ( AiksTest  ,
TransparentShadowProducesCorrectColor   
)

Definition at line 862 of file aiks_dl_unittests.cc.

862 {
863 DisplayListBuilder builder;
864 builder.Save();
865 builder.Scale(1.618, 1.618);
866 DlPath path = DlPath::MakeRect(DlRect::MakeXYWH(0, 0, 200, 100));
867
868 builder.DrawShadow(path, flutter::DlColor::kTransparent(), 15, false, 1);
869 builder.Restore();
870
871 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
872}
void DrawShadow(const DlPath &path, const DlColor color, const DlScalar elevation, bool transparent_occluder, DlScalar dpr) override
Draws the shadow of the given |path| rendered in the provided |color| (which is only consulted for it...
static constexpr DlColor kTransparent()
Definition dl_color.h:68

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawShadow(), flutter::DlColor::kTransparent(), flutter::DlPath::MakeRect(), impeller::TRect< Scalar >::MakeXYWH(), flutter::path, flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), and flutter::DisplayListBuilder::Scale().

◆ TEST_P() [388/662]

impeller::testing::TEST_P ( AiksTest  ,
TwoContourPathWithConnectingLines   
)

Definition at line 872 of file aiks_dl_path_unittests.cc.

872 {
873 DisplayListBuilder builder;
874
875 DlPaint paint;
876 paint.setColor(DlColor::kRed());
877 paint.setDrawStyle(DlDrawStyle::kStroke);
878 paint.setStrokeWidth(15.0);
879
880 builder.Translate(100, 0);
881 for (auto join : std::vector<DlStrokeJoin>{
882 DlStrokeJoin::kMiter, DlStrokeJoin::kRound, DlStrokeJoin::kBevel}) {
883 builder.Translate(0, 100);
884 paint.setStrokeJoin(join);
885
886 DlPathBuilder path_builder;
887 path_builder.MoveTo(DlPoint(0, 0));
888 path_builder.LineTo(DlPoint(50, 50));
889 path_builder.MoveTo(DlPoint(50, 50));
890 path_builder.LineTo(DlPoint(100, 0));
891
892 builder.DrawPath(path_builder.TakePath(), paint);
893 }
894
895 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
896}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [389/662]

impeller::testing::TEST_P ( AiksTest  ,
TwoContourPathWithSinglePointContour   
)

Definition at line 852 of file aiks_dl_path_unittests.cc.

852 {
853 DisplayListBuilder builder;
854
855 DlPaint paint;
856 paint.setColor(DlColor::kRed());
857 paint.setDrawStyle(DlDrawStyle::kStroke);
858 paint.setStrokeWidth(15.0);
859 paint.setStrokeCap(DlStrokeCap::kRound);
860
861 DlPathBuilder path_builder;
862 path_builder.MoveTo(DlPoint(100, 100));
863 path_builder.LineTo(DlPoint(150, 150));
864 path_builder.MoveTo(DlPoint(200, 200));
865 path_builder.LineTo(DlPoint(200, 200));
866
867 builder.DrawPath(path_builder.TakePath(), paint);
868
869 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
870}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), and flutter::DlPathBuilder::TakePath().

◆ TEST_P() [390/662]

impeller::testing::TEST_P ( AiksTest  ,
VarietyOfTextScalesShowingRasterAndPath   
)

Definition at line 964 of file aiks_dl_text_unittests.cc.

964 {
965 DisplayListBuilder builder;
966 DlPaint paint;
967 paint.setColor(DlColor::ARGB(1, 0.1, 0.1, 0.1));
968 builder.DrawPaint(paint);
969 builder.Scale(GetContentScale().x, GetContentScale().y);
970
971 std::vector<Scalar> scales = {4, 8, 16, 24, 32};
972 std::vector<Scalar> spacing = {8, 8, 8, 8, 8};
973 Scalar space = 16;
974 Scalar x = 0;
975 for (auto i = 0u; i < scales.size(); i++) {
976 builder.Save();
977 builder.Scale(scales[i], scales[i]);
978 RenderTextInCanvasSkia(
979 GetContext(), builder, "lo", "Roboto-Regular.ttf",
980 TextRenderOptions{.font_size = 16, .position = DlPoint(x, space)});
981 space += spacing[i];
982 if (i == 3) {
983 x = 10;
984 space = 16;
985 }
986 builder.Restore();
987 }
988 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
989}

References flutter::DlColor::ARGB(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), impeller::testing::TextRenderOptions::font_size, i, RenderTextInCanvasSkia(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), x, and y.

◆ TEST_P() [391/662]

impeller::testing::TEST_P ( AiksTest  ,
VerifyNonOptimizedGradient   
)

Definition at line 936 of file aiks_dl_gradient_unittests.cc.

936 {
937 DisplayListBuilder builder;
938 DlPaint paint;
939 builder.Translate(100.0f, 0);
940
941 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue(),
943 std::vector<Scalar> stops = {0.0, 0.1, 1.0};
944
945 // Inset the start and end point to verify that we do not apply
946 // the fast gradient condition.
947 paint.setColorSource(
948 DlColorSource::MakeLinear({0, 150}, {0, 100}, stops.size(), colors.data(),
949 stops.data(), DlTileMode::kRepeat));
950
951 paint.setColor(DlColor::kWhite());
952 builder.DrawRect(DlRect::MakeXYWH(0, 0, 300, 300), paint);
953 builder.Translate(400, 0);
954 builder.DrawRoundRect(
955 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(0, 0, 300, 300), 4, 4), paint);
956
957 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
958}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), flutter::DlColor::kWhite(), flutter::DlColorSource::MakeLinear(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorSource(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [392/662]

impeller::testing::TEST_P ( AiksTest  ,
VerticesGeometryColorUVPositionData   
)

Definition at line 99 of file aiks_dl_vertices_unittests.cc.

99 {
100 DisplayListBuilder builder;
101 DlPaint paint;
102 auto image =
103 DlImageImpeller::Make(CreateTextureForFixture("table_mountain_nx.png"));
104 auto size = image->GetImpellerTexture(GetContext())->GetSize();
105
106 paint.setColorSource(
107 DlColorSource::MakeImage(image, DlTileMode::kClamp, DlTileMode::kClamp));
108
109 std::vector<DlPoint> positions = {
110 DlPoint(0, 0), DlPoint(size.width, 0),
111 DlPoint(0, size.height), DlPoint(size.width, 0),
112 DlPoint(0, 0), DlPoint(size.width, size.height),
113 };
114 std::vector<DlColor> colors = {
115 DlColor::kRed().withAlpha(128), DlColor::kBlue().withAlpha(128),
116 DlColor::kGreen().withAlpha(128), DlColor::kRed().withAlpha(128),
117 DlColor::kBlue().withAlpha(128), DlColor::kGreen().withAlpha(128),
118 };
119
120 auto vertices =
121 MakeVertices(DlVertexMode::kTriangles, positions, {}, {}, colors);
122
123 builder.DrawVertices(vertices, DlBlendMode::kDstOver, paint);
124 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
125}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), image, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), flutter::DlPaint::setColorSource(), flutter::size, and flutter::DlColor::withAlpha().

◆ TEST_P() [393/662]

impeller::testing::TEST_P ( AiksTest  ,
VerticesGeometryColorUVPositionDataAdvancedBlend   
)

Definition at line 127 of file aiks_dl_vertices_unittests.cc.

127 {
128 DisplayListBuilder builder;
129 DlPaint paint;
130 auto image =
131 DlImageImpeller::Make(CreateTextureForFixture("table_mountain_nx.png"));
132 auto size = image->GetImpellerTexture(GetContext())->GetSize();
133
134 paint.setColorSource(
135 DlColorSource::MakeImage(image, DlTileMode::kClamp, DlTileMode::kClamp));
136
137 std::vector<DlPoint> positions = {
138 DlPoint(0, 0), DlPoint(size.width, 0),
139 DlPoint(0, size.height), DlPoint(size.width, 0),
140 DlPoint(0, 0), DlPoint(size.width, size.height),
141 };
142 std::vector<DlColor> colors = {
143 DlColor::kRed().modulateOpacity(0.5),
144 DlColor::kBlue().modulateOpacity(0.5),
145 DlColor::kGreen().modulateOpacity(0.5),
146 DlColor::kRed().modulateOpacity(0.5),
147 DlColor::kBlue().modulateOpacity(0.5),
148 DlColor::kGreen().modulateOpacity(0.5),
149 };
150
151 auto vertices =
152 MakeVertices(DlVertexMode::kTriangles, positions, {}, {}, colors);
153
154 builder.DrawVertices(vertices, DlBlendMode::kColorBurn, paint);
155 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
156}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), image, flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::DlColor::kRed(), impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), flutter::DlColor::modulateOpacity(), flutter::DlPaint::setColorSource(), and flutter::size.

◆ TEST_P() [394/662]

impeller::testing::TEST_P ( AiksTest  ,
VerticesGeometryUVPositionData   
)

Definition at line 51 of file aiks_dl_vertices_unittests.cc.

51 {
52 DisplayListBuilder builder;
53 DlPaint paint;
54 auto image =
55 DlImageImpeller::Make(CreateTextureForFixture("table_mountain_nx.png"));
56 auto size = image->GetImpellerTexture(GetContext())->GetSize();
57
58 paint.setColorSource(
59 DlColorSource::MakeImage(image, DlTileMode::kClamp, DlTileMode::kClamp));
60
61 std::vector<DlPoint> vertex_coordinates = {
62 DlPoint(0, 0),
63 DlPoint(size.width, 0),
64 DlPoint(0, size.height),
65 };
66 auto vertices = MakeVertices(DlVertexMode::kTriangleStrip, vertex_coordinates,
67 {0, 1, 2}, {}, {});
68
69 builder.DrawVertices(vertices, DlBlendMode::kSrcOver, paint);
70 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
71}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), image, impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), flutter::DlPaint::setColorSource(), and flutter::size.

◆ TEST_P() [395/662]

impeller::testing::TEST_P ( AiksTest  ,
VerticesGeometryUVPositionDataWithTranslate   
)

Definition at line 74 of file aiks_dl_vertices_unittests.cc.

74 {
75 DisplayListBuilder builder;
76 DlPaint paint;
77 auto image =
78 DlImageImpeller::Make(CreateTextureForFixture("table_mountain_nx.png"));
79 auto size = image->GetImpellerTexture(GetContext())->GetSize();
80
81 DlMatrix matrix = DlMatrix::MakeTranslation({100, 100});
82 paint.setColorSource(
83 DlColorSource::MakeImage(image, DlTileMode::kClamp, DlTileMode::kClamp,
84 DlImageSampling::kLinear, &matrix));
85
86 std::vector<DlPoint> positions = {
87 DlPoint(0, 0),
88 DlPoint(size.width, 0),
89 DlPoint(0, size.height),
90 };
91 auto vertices =
92 MakeVertices(DlVertexMode::kTriangleStrip, positions, {0, 1, 2}, {}, {});
93
94 builder.DrawVertices(vertices, DlBlendMode::kSrcOver, paint);
95 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
96}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), image, impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), impeller::Matrix::MakeTranslation(), flutter::DlPaint::setColorSource(), and flutter::size.

◆ TEST_P() [396/662]

impeller::testing::TEST_P ( AiksTest  ,
VerticesGeometryWithMaskFilter   
)

Definition at line 557 of file aiks_dl_vertices_unittests.cc.

557 {
558 DisplayListBuilder builder;
559 DlPaint paint;
560 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 10));
561
562 std::vector<DlPoint> vertex_coordinates = {
563 DlPoint(0, 0),
564 DlPoint(400, 0),
565 DlPoint(0, 400),
566 };
567 auto vertices = MakeVertices(DlVertexMode::kTriangleStrip, vertex_coordinates,
568 {0, 1, 2}, {}, {});
569
570 builder.DrawVertices(vertices, DlBlendMode::kSrcOver, paint);
571 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
572}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawVertices(), flutter::DlBlurMaskFilter::Make(), and flutter::DlPaint::setMaskFilter().

◆ TEST_P() [397/662]

impeller::testing::TEST_P ( AiksTest  ,
ZoomedStrokedPathRendersCorrectly   
)

Definition at line 926 of file aiks_dl_basic_unittests.cc.

926 {
927 DrawStrokedAndFilledCirclesWithZoom(this, /*zoom=*/80.0f, /*radius=*/2.0f,
928 /*stroke_width=*/0.05f);
929}

◆ TEST_P() [398/662]

impeller::testing::TEST_P ( AllocatorMTLTest  ,
DebugTraceMemoryStatistics   
)

Definition at line 28 of file allocator_mtl_unittests.mm.

28 {
29 auto& context_mtl = ContextMTL::Cast(*GetContext());
30 const auto& allocator = context_mtl.GetResourceAllocator();
31
32 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
33 0u);
34
35 // Memoryless texture does not increase allocated size.
36 {
38 desc.format = PixelFormat::kR8G8B8A8UNormInt;
39 desc.storage_mode = StorageMode::kDeviceTransient;
40 desc.size = {1024, 1024};
41 auto texture_1 = allocator->CreateTexture(desc);
42
43 // Private storage texture increases allocated size.
44 desc.storage_mode = StorageMode::kDevicePrivate;
45 auto texture_2 = allocator->CreateTexture(desc);
46
47#ifdef IMPELLER_DEBUG
48 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
49 4u);
50#else
51 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
52 0u);
53#endif // IMPELLER_DEBUG
54
55 // Host storage texture increases allocated size.
56 desc.storage_mode = StorageMode::kHostVisible;
57 auto texture_3 = allocator->CreateTexture(desc);
58
59#ifdef IMPELLER_DEBUG
60 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
61 8u);
62#else
63 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
64 0u);
65#endif // IMPELLER_DEBUG
66 }
67
68 // After all textures are out of scope, memory has been decremented.
69 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
70 0u);
71}

References allocator, impeller::BackendCast< ContextMTL, Context >::Cast(), impeller::TextureDescriptor::format, impeller::kDevicePrivate, impeller::kDeviceTransient, impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, impeller::TextureDescriptor::size, and impeller::TextureDescriptor::storage_mode.

◆ TEST_P() [399/662]

impeller::testing::TEST_P ( AllocatorMTLTest  ,
ManagedMemory   
)

Definition at line 73 of file allocator_mtl_unittests.mm.

73 {
74 auto& context_mtl = ContextMTL::Cast(*GetContext());
75 auto allocator = std::make_unique<AllocatorMTL>(context_mtl.GetMTLDevice(),
76 "test-allocator");
77 allocator->DebugSetSupportsUMA(false);
78
80 desc.size = 100;
81 desc.storage_mode = StorageMode::kHostVisible;
82
83 auto buffer = allocator->CreateBuffer(desc);
84 ASSERT_TRUE(buffer);
85
86 EXPECT_NE(buffer->OnGetContents(), nullptr);
87}

References allocator, flutter::buffer, impeller::BackendCast< ContextMTL, Context >::Cast(), impeller::kHostVisible, impeller::DeviceBufferDescriptor::size, and impeller::DeviceBufferDescriptor::storage_mode.

◆ TEST_P() [400/662]

impeller::testing::TEST_P ( BlendFilterContentsTest  ,
AdvancedBlendColorAlignsColorTo4   
)

Definition at line 45 of file blend_filter_contents_unittests.cc.

45 {
46 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
47 BlendFilterContents filter_contents;
48 filter_contents.SetInputs({FilterInput::Make(texture)});
49 filter_contents.SetForegroundColor(Color(1.0, 0.0, 0.0, 1.0));
50 filter_contents.SetBlendMode(BlendMode::kColorDodge);
51
52 ContentContext& renderer = GetContentContext();
53 // Add random byte to get the HostBuffer in a bad alignment.
54 uint8_t byte = 0xff;
55 BufferView buffer_view = renderer.GetTransientsDataBuffer().Emplace(
56 &byte, /*length=*/1, /*align=*/1);
57 EXPECT_EQ(buffer_view.GetRange().offset, 4u);
58 EXPECT_EQ(buffer_view.GetRange().length, 1u);
59 Entity entity;
60
61 std::optional<Entity> result = filter_contents.GetEntity(
62 renderer, entity, /*coverage_hint=*/std::nullopt);
63
64 EXPECT_TRUE(result.has_value());
65}
void SetBlendMode(BlendMode blend_mode)
void SetForegroundColor(std::optional< Color > color)
Sets a source color which is blended after all of the inputs have been blended.
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
std::optional< Entity > GetEntity(const ContentContext &renderer, const Entity &entity, const std::optional< Rect > &coverage_hint) const
Create an Entity that renders this filter's output.
void SetInputs(FilterInput::Vector inputs)
The input texture sources for this filter. Each input's emitted texture is expected to have premultip...
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.

References impeller::HostBuffer::Emplace(), impeller::FilterContents::GetEntity(), impeller::BufferView::GetRange(), impeller::ContentContext::GetTransientsDataBuffer(), impeller::kColorDodge, impeller::Range::length, impeller::FilterInput::Make(), impeller::Range::offset, impeller::BlendFilterContents::SetBlendMode(), impeller::BlendFilterContents::SetForegroundColor(), impeller::FilterContents::SetInputs(), and texture.

◆ TEST_P() [401/662]

impeller::testing::TEST_P ( BlitPassTest  ,
BlitAcrossDifferentPixelFormatsFails   
)

Definition at line 30 of file blit_pass_unittests.cc.

30 {
31 ScopedValidationDisable scope; // avoid noise in output.
32 auto context = GetContext();
33 auto cmd_buffer = context->CreateCommandBuffer();
34 auto blit_pass = cmd_buffer->CreateBlitPass();
35
36 TextureDescriptor src_desc;
37 src_desc.format = PixelFormat::kA8UNormInt;
38 src_desc.size = {100, 100};
39 src_desc.storage_mode = StorageMode::kHostVisible;
40 auto src = context->GetResourceAllocator()->CreateTexture(src_desc);
41
42 TextureDescriptor dst_format;
43 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
44 dst_format.size = {100, 100};
45 dst_format.storage_mode = StorageMode::kHostVisible;
46 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
47
48 EXPECT_FALSE(blit_pass->AddCopy(src, dst));
49}

References context, impeller::TextureDescriptor::format, impeller::kA8UNormInt, impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, impeller::TextureDescriptor::size, and impeller::TextureDescriptor::storage_mode.

◆ TEST_P() [402/662]

impeller::testing::TEST_P ( BlitPassTest  ,
BlitAcrossDifferentSampleCountsFails   
)

Definition at line 51 of file blit_pass_unittests.cc.

51 {
52 ScopedValidationDisable scope; // avoid noise in output.
53 auto context = GetContext();
54 auto cmd_buffer = context->CreateCommandBuffer();
55 auto blit_pass = cmd_buffer->CreateBlitPass();
56
57 TextureDescriptor src_desc;
58 src_desc.format = PixelFormat::kR8G8B8A8UNormInt;
59 src_desc.sample_count = SampleCount::kCount4;
60 src_desc.size = {100, 100};
61 auto src = context->GetResourceAllocator()->CreateTexture(src_desc);
62
63 TextureDescriptor dst_format;
64 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
65 dst_format.size = {100, 100};
66 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
67
68 EXPECT_FALSE(blit_pass->AddCopy(src, dst));
69}

References context, impeller::TextureDescriptor::format, impeller::kCount4, impeller::kR8G8B8A8UNormInt, impeller::TextureDescriptor::sample_count, and impeller::TextureDescriptor::size.

◆ TEST_P() [403/662]

impeller::testing::TEST_P ( BlitPassTest  ,
BlitPassesForMatchingFormats   
)

Definition at line 71 of file blit_pass_unittests.cc.

71 {
72 ScopedValidationDisable scope; // avoid noise in output.
73 auto context = GetContext();
74 auto cmd_buffer = context->CreateCommandBuffer();
75 auto blit_pass = cmd_buffer->CreateBlitPass();
76
77 TextureDescriptor src_desc;
78 src_desc.format = PixelFormat::kR8G8B8A8UNormInt;
79 src_desc.size = {100, 100};
80 src_desc.storage_mode = StorageMode::kHostVisible;
81 auto src = context->GetResourceAllocator()->CreateTexture(src_desc);
82
83 TextureDescriptor dst_format;
84 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
85 dst_format.size = {100, 100};
86 dst_format.storage_mode = StorageMode::kHostVisible;
87 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
88
89 EXPECT_TRUE(blit_pass->AddCopy(src, dst));
90}

References context, impeller::TextureDescriptor::format, impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, impeller::TextureDescriptor::size, and impeller::TextureDescriptor::storage_mode.

◆ TEST_P() [404/662]

impeller::testing::TEST_P ( BlitPassTest  ,
CanBlitSmallRegionToUninitializedTexture   
)

Definition at line 123 of file blit_pass_unittests.cc.

123 {
124 auto context = GetContext();
125 auto cmd_buffer = context->CreateCommandBuffer();
126 auto blit_pass = cmd_buffer->CreateBlitPass();
127
128 TextureDescriptor dst_format;
129 dst_format.storage_mode = StorageMode::kDevicePrivate;
130 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
131 dst_format.size = {1000, 1000};
132 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
133
134 DeviceBufferDescriptor src_format;
135 src_format.size = 4;
136 src_format.storage_mode = StorageMode::kHostVisible;
137 auto src = context->GetResourceAllocator()->CreateBuffer(src_format);
138
139 ASSERT_TRUE(dst);
140
141 EXPECT_TRUE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
142 IRect::MakeLTRB(0, 0, 1, 1), "",
143 /*mip_level=*/0, /*slice=*/0));
144 EXPECT_TRUE(blit_pass->EncodeCommands());
145 EXPECT_TRUE(context->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok());
146}

References impeller::DeviceBuffer::AsBufferView(), context, impeller::TextureDescriptor::format, impeller::kDevicePrivate, impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, impeller::TRect< T >::MakeLTRB(), impeller::DeviceBufferDescriptor::size, impeller::TextureDescriptor::size, impeller::DeviceBufferDescriptor::storage_mode, and impeller::TextureDescriptor::storage_mode.

◆ TEST_P() [405/662]

impeller::testing::TEST_P ( BlitPassTest  ,
CanBlitToHigherTextureMipLevels   
)

Definition at line 176 of file blit_pass_unittests.cc.

176 {
177 auto context = GetContext();
178 auto cmd_buffer = context->CreateCommandBuffer();
179 auto blit_pass = cmd_buffer->CreateBlitPass();
180
181 TextureDescriptor dst_format;
182 dst_format.storage_mode = StorageMode::kDevicePrivate;
183 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
184 dst_format.size = {1000, 1000};
185 dst_format.mip_count = 4;
186 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
187
188 DeviceBufferDescriptor src_format;
189 src_format.size = 4;
190 src_format.storage_mode = StorageMode::kHostVisible;
191 auto src = context->GetResourceAllocator()->CreateBuffer(src_format);
192
193 ASSERT_TRUE(dst);
194
195 EXPECT_TRUE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
196 IRect::MakeLTRB(0, 0, 1, 1), "",
197 /*mip_level=*/1, /*slice=*/0));
198 EXPECT_TRUE(blit_pass->EncodeCommands());
199 EXPECT_TRUE(context->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok());
200}

References impeller::DeviceBuffer::AsBufferView(), context, impeller::TextureDescriptor::format, impeller::kDevicePrivate, impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, impeller::TRect< T >::MakeLTRB(), impeller::TextureDescriptor::mip_count, impeller::DeviceBufferDescriptor::size, impeller::TextureDescriptor::size, impeller::DeviceBufferDescriptor::storage_mode, and impeller::TextureDescriptor::storage_mode.

◆ TEST_P() [406/662]

impeller::testing::TEST_P ( BlitPassTest  ,
CanResizeTextures   
)

Definition at line 202 of file blit_pass_unittests.cc.

202 {
203 auto context = GetContext();
204 auto cmd_buffer = context->CreateCommandBuffer();
205 auto blit_pass = cmd_buffer->CreateBlitPass();
206
207 TextureDescriptor dst_format;
208 dst_format.storage_mode = StorageMode::kDevicePrivate;
209 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
210 dst_format.size = {10, 10};
211 dst_format.usage = TextureUsage::kShaderRead | TextureUsage::kShaderWrite;
212 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
213
214 TextureDescriptor src_format;
215 src_format.storage_mode = StorageMode::kDevicePrivate;
216 src_format.format = PixelFormat::kR8G8B8A8UNormInt;
217 src_format.size = {100, 100};
218 auto src = context->GetResourceAllocator()->CreateTexture(src_format);
219
220 std::vector<uint8_t> bytes(src_format.GetByteSizeOfBaseMipLevel());
221 for (auto i = 0u; i < src_format.GetByteSizeOfBaseMipLevel(); i += 4) {
222 // RGBA
223 bytes[i + 0] = 255;
224 bytes[i + 1] = 0;
225 bytes[i + 2] = 0;
226 bytes[i + 3] = 255;
227 }
228 auto mapping = fml::DataMapping(bytes);
229 auto staging = context->GetResourceAllocator()->CreateBufferWithCopy(mapping);
230
231 ASSERT_TRUE(dst);
232 ASSERT_TRUE(src);
233 ASSERT_TRUE(staging);
234
235 EXPECT_TRUE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(staging), src));
236 EXPECT_TRUE(blit_pass->ResizeTexture(src, dst));
237 EXPECT_TRUE(blit_pass->EncodeCommands());
238 EXPECT_TRUE(context->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok());
239}

References impeller::DeviceBuffer::AsBufferView(), context, impeller::TextureDescriptor::format, impeller::TextureDescriptor::GetByteSizeOfBaseMipLevel(), i, impeller::kDevicePrivate, impeller::kR8G8B8A8UNormInt, impeller::kShaderRead, impeller::kShaderWrite, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, and impeller::TextureDescriptor::usage.

◆ TEST_P() [407/662]

impeller::testing::TEST_P ( BlitPassTest  ,
CanResizeTexturesPlayground   
)

Definition at line 241 of file blit_pass_unittests.cc.

241 {
242 auto context = GetContext();
243 auto cmd_buffer = context->CreateCommandBuffer();
244 auto blit_pass = cmd_buffer->CreateBlitPass();
245
246 std::shared_ptr<Texture> src = CreateTextureForFixture("kalimba.jpg");
247
248 TextureDescriptor dst_format;
249 dst_format.storage_mode = StorageMode::kDevicePrivate;
250 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
251 dst_format.size = {src->GetSize().width / 2, src->GetSize().height};
252 dst_format.usage = TextureUsage::kShaderRead | TextureUsage::kShaderWrite;
253 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
254
255 ASSERT_TRUE(dst);
256 ASSERT_TRUE(src);
257
258 EXPECT_TRUE(blit_pass->ResizeTexture(src, dst));
259 EXPECT_TRUE(blit_pass->EncodeCommands());
260 EXPECT_TRUE(context->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok());
261
262 DisplayListBuilder builder;
263 builder.Scale(GetContentScale().x, GetContentScale().y);
264 DlPaint paint;
265 paint.setColor(DlColor::kRed());
266 auto image = DlImageImpeller::Make(dst);
267 builder.DrawImage(image, flutter::DlPoint(100.0, 100.0),
268 DlImageSampling::kNearestNeighbor, &paint);
269 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
270}

References flutter::DisplayListBuilder::Build(), context, flutter::DisplayListBuilder::DrawImage(), impeller::TextureDescriptor::format, image, impeller::kDevicePrivate, impeller::kR8G8B8A8UNormInt, flutter::DlColor::kRed(), impeller::kShaderRead, impeller::kShaderWrite, impeller::DlImageImpeller::Make(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::TextureDescriptor::usage, impeller::TSize< T >::width, x, and y.

◆ TEST_P() [408/662]

impeller::testing::TEST_P ( BlitPassTest  ,
ChecksInvalidMipLevelParameter   
)

Definition at line 148 of file blit_pass_unittests.cc.

148 {
150 auto context = GetContext();
151 auto cmd_buffer = context->CreateCommandBuffer();
152 auto blit_pass = cmd_buffer->CreateBlitPass();
153
154 TextureDescriptor dst_format;
155 dst_format.storage_mode = StorageMode::kDevicePrivate;
156 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
157 dst_format.size = {1000, 1000};
158 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
159
160 DeviceBufferDescriptor src_format;
161 src_format.size = 4;
162 src_format.storage_mode = StorageMode::kHostVisible;
163 auto src = context->GetResourceAllocator()->CreateBuffer(src_format);
164
165 ASSERT_TRUE(dst);
166
167 EXPECT_FALSE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
168 IRect::MakeLTRB(0, 0, 1, 1), "",
169 /*mip_level=*/1, /*slice=*/0));
170
171 EXPECT_TRUE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
172 IRect::MakeLTRB(0, 0, 1, 1), "",
173 /*mip_level=*/0, /*slice=*/0));
174}

References impeller::DeviceBuffer::AsBufferView(), context, impeller::TextureDescriptor::format, impeller::kDevicePrivate, impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, impeller::TRect< T >::MakeLTRB(), impeller::DeviceBufferDescriptor::size, impeller::TextureDescriptor::size, impeller::DeviceBufferDescriptor::storage_mode, and impeller::TextureDescriptor::storage_mode.

◆ TEST_P() [409/662]

impeller::testing::TEST_P ( BlitPassTest  ,
ChecksInvalidSliceParameters   
)

Definition at line 92 of file blit_pass_unittests.cc.

92 {
93 ScopedValidationDisable scope; // avoid noise in output.
94 auto context = GetContext();
95 auto cmd_buffer = context->CreateCommandBuffer();
96 auto blit_pass = cmd_buffer->CreateBlitPass();
97
98 TextureDescriptor dst_format;
99 dst_format.storage_mode = StorageMode::kDevicePrivate;
100 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
101 dst_format.size = {100, 100};
102 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
103
104 DeviceBufferDescriptor src_format;
105 src_format.size = 40000;
106 src_format.storage_mode = StorageMode::kHostVisible;
107 auto src = context->GetResourceAllocator()->CreateBuffer(src_format);
108
109 ASSERT_TRUE(dst);
110 ASSERT_TRUE(src);
111
112 EXPECT_FALSE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
113 std::nullopt, "", /*mip_level=*/0,
114 /*slice=*/25));
115 EXPECT_FALSE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
116 std::nullopt, "", /*mip_level=*/0,
117 /*slice=*/6));
118 EXPECT_TRUE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
119 std::nullopt, "", /*mip_level=*/0,
120 /*slice=*/0));
121}

References impeller::DeviceBuffer::AsBufferView(), context, impeller::TextureDescriptor::format, impeller::kDevicePrivate, impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, impeller::DeviceBufferDescriptor::size, impeller::TextureDescriptor::size, impeller::DeviceBufferDescriptor::storage_mode, and impeller::TextureDescriptor::storage_mode.

◆ TEST_P() [410/662]

impeller::testing::TEST_P ( ComputeTest  ,
1DThreadgroupSizingIsCorrect   
)

Definition at line 200 of file compute_unittests.cc.

200 {
201 using CS = ThreadgroupSizingTestComputeShader;
202 auto context = GetContext();
203 ASSERT_TRUE(context);
204 ASSERT_TRUE(context->GetCapabilities()->SupportsCompute());
205
206 using SamplePipelineBuilder = ComputePipelineBuilder<CS>;
207 auto pipeline_desc =
208 SamplePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
209 ASSERT_TRUE(pipeline_desc.has_value());
210 auto compute_pipeline =
211 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
212 ASSERT_TRUE(compute_pipeline);
213
214 auto cmd_buffer = context->CreateCommandBuffer();
215 auto pass = cmd_buffer->CreateComputePass();
216 ASSERT_TRUE(pass && pass->IsValid());
217
218 static constexpr size_t kCount = 2048;
219
220 pass->SetPipeline(compute_pipeline);
221
222 auto output_buffer = CreateHostVisibleDeviceBuffer<CS::OutputData<kCount>>(
223 context, "Output Buffer");
224
225 CS::BindOutputData(*pass, DeviceBuffer::AsBufferView(output_buffer));
226
227 ASSERT_TRUE(
228 pass->Compute({WorkgroupCount(kCount, CS::kWorkgroupSize[0]), 1, 1})
229 .ok());
230 ASSERT_TRUE(pass->EncodeCommands());
231
233 ASSERT_TRUE(
234 context->GetCommandQueue()
235 ->Submit({cmd_buffer},
236 [&latch, output_buffer](CommandBuffer::Status status) {
237 EXPECT_EQ(status, CommandBuffer::Status::kCompleted);
238
239 auto view = DeviceBuffer::AsBufferView(output_buffer);
240 EXPECT_EQ(view.GetRange().length,
241 sizeof(CS::OutputData<kCount>));
242
243 CS::OutputData<kCount>* output =
244 reinterpret_cast<CS::OutputData<kCount>*>(
245 output_buffer->OnGetContents());
246 EXPECT_TRUE(output);
247 EXPECT_EQ(output->data[kCount - 1], kCount - 1);
248 latch.Signal();
249 })
250 .ok());
251
252 latch.Wait();
253}
An optional (but highly recommended) utility for creating pipelines from reflected shader information...

References context, and fml::AutoResetWaitableEvent::Wait().

◆ TEST_P() [411/662]

impeller::testing::TEST_P ( ComputeTest  ,
3DWorkgroupDispatchIsCorrect   
)

Definition at line 255 of file compute_unittests.cc.

255 {
256 using CS = Compute3dTestComputeShader;
257 auto context = GetContext();
258 ASSERT_TRUE(context);
259 ASSERT_TRUE(context->GetCapabilities()->SupportsCompute());
260
262 auto pipeline_desc = PipelineBuilder::MakeDefaultPipelineDescriptor(*context);
263 ASSERT_TRUE(pipeline_desc.has_value());
264 auto compute_pipeline =
265 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
266 ASSERT_TRUE(compute_pipeline);
267
268 auto cmd_buffer = context->CreateCommandBuffer();
269 auto pass = cmd_buffer->CreateComputePass();
270 ASSERT_TRUE(pass && pass->IsValid());
271
272 // The shader's local size is (2, 3, 4). Dispatching (3, 2, 1) workgroups
273 // covers a (6, 6, 4) invocation grid, which exercises all three dimensions
274 // and confirms the reflected local size is honored on every axis.
275 static_assert(CS::kWorkgroupSize[0] == 2 && CS::kWorkgroupSize[1] == 3 &&
276 CS::kWorkgroupSize[2] == 4);
277 constexpr std::array<uint32_t, 3> kWorkgroups = {3, 2, 1};
278 constexpr uint32_t kWidth = kWorkgroups[0] * CS::kWorkgroupSize[0];
279 constexpr uint32_t kHeight = kWorkgroups[1] * CS::kWorkgroupSize[1];
280 constexpr uint32_t kDepth = kWorkgroups[2] * CS::kWorkgroupSize[2];
281 constexpr size_t kCount = kWidth * kHeight * kDepth;
282
283 pass->SetPipeline(compute_pipeline);
284
285 auto output_buffer = CreateHostVisibleDeviceBuffer<CS::OutputData<kCount>>(
286 context, "Output Buffer");
287 CS::BindOutputData(*pass, DeviceBuffer::AsBufferView(output_buffer));
288
289 ASSERT_TRUE(pass->Compute(kWorkgroups).ok());
290 ASSERT_TRUE(pass->EncodeCommands());
291
293 ASSERT_TRUE(
294 context->GetCommandQueue()
295 ->Submit({cmd_buffer},
296 [&latch, output_buffer](CommandBuffer::Status status) {
297 EXPECT_EQ(status, CommandBuffer::Status::kCompleted);
298
299 CS::OutputData<kCount>* output =
300 reinterpret_cast<CS::OutputData<kCount>*>(
301 output_buffer->OnGetContents());
302 EXPECT_TRUE(output);
303 for (uint32_t i = 0; i < kCount; i++) {
304 EXPECT_EQ(output->data[i], i);
305 }
306 latch.Signal();
307 })
308 .ok());
309
310 latch.Wait();
311}

References context, and fml::AutoResetWaitableEvent::Signal().

◆ TEST_P() [412/662]

impeller::testing::TEST_P ( ComputeTest  ,
CanCompute1DimensionalData   
)

Definition at line 463 of file compute_unittests.cc.

463 {
464 using CS = SampleComputeShader;
465 auto context = GetContext();
466 auto host_buffer = CreateHostBufferFromContext(context);
467 ASSERT_TRUE(context);
468 ASSERT_TRUE(context->GetCapabilities()->SupportsCompute());
469
470 using SamplePipelineBuilder = ComputePipelineBuilder<CS>;
471 auto pipeline_desc =
472 SamplePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
473 ASSERT_TRUE(pipeline_desc.has_value());
474 auto compute_pipeline =
475 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
476 ASSERT_TRUE(compute_pipeline);
477
478 auto cmd_buffer = context->CreateCommandBuffer();
479 auto pass = cmd_buffer->CreateComputePass();
480 ASSERT_TRUE(pass && pass->IsValid());
481
482 static constexpr size_t kCount = 5;
483
484 pass->SetPipeline(compute_pipeline);
485
486 CS::Info info{.count = kCount};
487 CS::Input0<kCount> input_0;
488 CS::Input1<kCount> input_1;
489 for (size_t i = 0; i < kCount; i++) {
490 input_0.elements[i] = Vector4(2.0 + i, 3.0 + i, 4.0 + i, 5.0 * i);
491 input_1.elements[i] = Vector4(6.0, 7.0, 8.0, 9.0);
492 }
493
494 input_0.fixed_array[1] = IPoint32(2, 2);
495 input_1.fixed_array[0] = UintPoint32(3, 3);
496 input_0.some_int = 5;
497 input_1.some_struct = CS::SomeStruct{.vf = Point(3, 4), .i = 42};
498
499 auto output_buffer = CreateHostVisibleDeviceBuffer<CS::Output<kCount>>(
500 context, "Output Buffer");
501
502 CS::BindInfo(*pass, host_buffer->EmplaceUniform(info));
503 CS::BindInput0(*pass, host_buffer->EmplaceStorageBuffer(input_0));
504 CS::BindInput1(*pass, host_buffer->EmplaceStorageBuffer(input_1));
505 CS::BindOutput(*pass, DeviceBuffer::AsBufferView(output_buffer));
506
507 ASSERT_TRUE(
508 pass->Compute({WorkgroupCount(kCount, CS::kWorkgroupSize[0]), 1, 1})
509 .ok());
510 ASSERT_TRUE(pass->EncodeCommands());
511
513 ASSERT_TRUE(
514 context->GetCommandQueue()
515 ->Submit(
516 {cmd_buffer},
517 [&latch, output_buffer, &input_0,
518 &input_1](CommandBuffer::Status status) {
519 EXPECT_EQ(status, CommandBuffer::Status::kCompleted);
520
521 auto view = DeviceBuffer::AsBufferView(output_buffer);
522 EXPECT_EQ(view.GetRange().length, sizeof(CS::Output<kCount>));
523
524 CS::Output<kCount>* output =
525 reinterpret_cast<CS::Output<kCount>*>(
526 output_buffer->OnGetContents());
527 EXPECT_TRUE(output);
528 for (size_t i = 0; i < kCount; i++) {
529 Vector4 vector = output->elements[i];
530 Vector4 computed = input_0.elements[i] * input_1.elements[i];
531 EXPECT_EQ(vector,
532 Vector4(computed.x + 2 + input_1.some_struct.i,
533 computed.y + 3 + input_1.some_struct.vf.x,
534 computed.z + 5 + input_1.some_struct.vf.y,
535 computed.w));
536 }
537 latch.Signal();
538 })
539 .ok());
540
541 latch.Wait();
542}

References context, i, and fml::AutoResetWaitableEvent::Signal().

◆ TEST_P() [413/662]

impeller::testing::TEST_P ( ComputeTest  ,
CanComputePrefixSum   
)

Definition at line 132 of file compute_unittests.cc.

132 {
133 using CS = PrefixSumTestComputeShader;
134 auto context = GetContext();
135 auto host_buffer = CreateHostBufferFromContext(context);
136 ASSERT_TRUE(context);
137 ASSERT_TRUE(context->GetCapabilities()->SupportsCompute());
138
139 using SamplePipelineBuilder = ComputePipelineBuilder<CS>;
140 auto pipeline_desc =
141 SamplePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
142 ASSERT_TRUE(pipeline_desc.has_value());
143 auto compute_pipeline =
144 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
145 ASSERT_TRUE(compute_pipeline);
146
147 auto cmd_buffer = context->CreateCommandBuffer();
148 auto pass = cmd_buffer->CreateComputePass();
149 ASSERT_TRUE(pass && pass->IsValid());
150
151 static constexpr size_t kCount = 5;
152
153 pass->SetPipeline(compute_pipeline);
154
155 CS::InputData<kCount> input_data;
156 input_data.count = kCount;
157 for (size_t i = 0; i < kCount; i++) {
158 input_data.data[i] = 1 + i;
159 }
160
161 auto output_buffer = CreateHostVisibleDeviceBuffer<CS::OutputData<kCount>>(
162 context, "Output Buffer");
163
164 CS::BindInputData(*pass, host_buffer->EmplaceStorageBuffer(input_data));
165 CS::BindOutputData(*pass, DeviceBuffer::AsBufferView(output_buffer));
166
167 // The prefix sum is computed within a single workgroup whose size is sized to
168 // the device (a specialization constant), so dispatch exactly one.
169 ASSERT_TRUE(pass->Compute({1, 1, 1}).ok());
170 ASSERT_TRUE(pass->EncodeCommands());
171
173 ASSERT_TRUE(
174 context->GetCommandQueue()
175 ->Submit({cmd_buffer},
176 [&latch, output_buffer](CommandBuffer::Status status) {
177 EXPECT_EQ(status, CommandBuffer::Status::kCompleted);
178
179 auto view = DeviceBuffer::AsBufferView(output_buffer);
180 EXPECT_EQ(view.GetRange().length,
181 sizeof(CS::OutputData<kCount>));
182
183 CS::OutputData<kCount>* output =
184 reinterpret_cast<CS::OutputData<kCount>*>(
185 output_buffer->OnGetContents());
186 EXPECT_TRUE(output);
187
188 constexpr uint32_t expected[kCount] = {1, 3, 6, 10, 15};
189 for (size_t i = 0; i < kCount; i++) {
190 auto computed_sum = output->data[i];
191 EXPECT_EQ(computed_sum, expected[i]);
192 }
193 latch.Signal();
194 })
195 .ok());
196
197 latch.Wait();
198}

References impeller::DeviceBuffer::AsBufferView(), context, i, and fml::AutoResetWaitableEvent::Signal().

◆ TEST_P() [414/662]

impeller::testing::TEST_P ( ComputeTest  ,
CanComputePrefixSumLargeInteractive   
)

Definition at line 313 of file compute_unittests.cc.

313 {
314 using CS = PrefixSumTestComputeShader;
315
316 auto context = GetContext();
317 auto host_buffer = CreateHostBufferFromContext(context);
318
319 ASSERT_TRUE(context);
320 ASSERT_TRUE(context->GetCapabilities()->SupportsCompute());
321
322 auto callback = [&](RenderPass& render_pass) -> bool {
323 using SamplePipelineBuilder = ComputePipelineBuilder<CS>;
324 auto pipeline_desc =
325 SamplePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
326 auto compute_pipeline =
327 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
328
329 auto cmd_buffer = context->CreateCommandBuffer();
330 auto pass = cmd_buffer->CreateComputePass();
331
332 static constexpr size_t kCount = 1023;
333
334 pass->SetPipeline(compute_pipeline);
335
336 CS::InputData<kCount> input_data;
337 input_data.count = kCount;
338 for (size_t i = 0; i < kCount; i++) {
339 input_data.data[i] = 1 + i;
340 }
341
342 auto output_buffer = CreateHostVisibleDeviceBuffer<CS::OutputData<kCount>>(
343 context, "Output Buffer");
344
345 CS::BindInputData(*pass, host_buffer->EmplaceStorageBuffer(input_data));
346 CS::BindOutputData(*pass, DeviceBuffer::AsBufferView(output_buffer));
347
348 // Single workgroup; see CanComputePrefixSum.
349 pass->Compute({1, 1, 1});
350 pass->EncodeCommands();
351 host_buffer->Reset();
352 return context->GetCommandQueue()->Submit({cmd_buffer}).ok();
353 };
354 ASSERT_TRUE(OpenPlaygroundHere(callback));
355}
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:30

References callback, context, i, and render_pass.

◆ TEST_P() [415/662]

impeller::testing::TEST_P ( ComputeTest  ,
CanCreateComputePass   
)

Definition at line 51 of file compute_unittests.cc.

51 {
52 using CS = SampleComputeShader;
53 auto context = GetContext();
54 auto host_buffer = CreateHostBufferFromContext(context);
55 ASSERT_TRUE(context);
56 ASSERT_TRUE(context->GetCapabilities()->SupportsCompute());
57
58 using SamplePipelineBuilder = ComputePipelineBuilder<CS>;
59 auto pipeline_desc =
60 SamplePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
61 ASSERT_TRUE(pipeline_desc.has_value());
62 auto compute_pipeline =
63 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
64 ASSERT_TRUE(compute_pipeline);
65
66 auto cmd_buffer = context->CreateCommandBuffer();
67 auto pass = cmd_buffer->CreateComputePass();
68 ASSERT_TRUE(pass && pass->IsValid());
69
70 static constexpr size_t kCount = 5;
71
72 pass->SetPipeline(compute_pipeline);
73
74 CS::Info info{.count = kCount};
75 CS::Input0<kCount> input_0;
76 CS::Input1<kCount> input_1;
77 for (size_t i = 0; i < kCount; i++) {
78 input_0.elements[i] = Vector4(2.0 + i, 3.0 + i, 4.0 + i, 5.0 * i);
79 input_1.elements[i] = Vector4(6.0, 7.0, 8.0, 9.0);
80 }
81
82 input_0.fixed_array[1] = IPoint32(2, 2);
83 input_1.fixed_array[0] = UintPoint32(3, 3);
84 input_0.some_int = 5;
85 input_1.some_struct = CS::SomeStruct{.vf = Point(3, 4), .i = 42};
86
87 auto output_buffer = CreateHostVisibleDeviceBuffer<CS::Output<kCount>>(
88 context, "Output Buffer");
89
90 CS::BindInfo(*pass, host_buffer->EmplaceUniform(info));
91 CS::BindInput0(*pass, host_buffer->EmplaceStorageBuffer(input_0));
92 CS::BindInput1(*pass, host_buffer->EmplaceStorageBuffer(input_1));
93 CS::BindOutput(*pass, DeviceBuffer::AsBufferView(output_buffer));
94
95 ASSERT_TRUE(
96 pass->Compute({WorkgroupCount(kCount, CS::kWorkgroupSize[0]), 1, 1})
97 .ok());
98 ASSERT_TRUE(pass->EncodeCommands());
99
101 ASSERT_TRUE(
102 context->GetCommandQueue()
103 ->Submit(
104 {cmd_buffer},
105 [&latch, output_buffer, &input_0,
106 &input_1](CommandBuffer::Status status) {
107 EXPECT_EQ(status, CommandBuffer::Status::kCompleted);
108
109 auto view = DeviceBuffer::AsBufferView(output_buffer);
110 EXPECT_EQ(view.GetRange().length, sizeof(CS::Output<kCount>));
111
112 CS::Output<kCount>* output =
113 reinterpret_cast<CS::Output<kCount>*>(
114 output_buffer->OnGetContents());
115 EXPECT_TRUE(output);
116 for (size_t i = 0; i < kCount; i++) {
117 Vector4 vector = output->elements[i];
118 Vector4 computed = input_0.elements[i] * input_1.elements[i];
119 EXPECT_EQ(vector,
120 Vector4(computed.x + 2 + input_1.some_struct.i,
121 computed.y + 3 + input_1.some_struct.vf.x,
122 computed.z + 5 + input_1.some_struct.vf.y,
123 computed.w));
124 }
125 latch.Signal();
126 })
127 .ok());
128
129 latch.Wait();
130}

References impeller::DeviceBuffer::AsBufferView(), context, i, and fml::AutoResetWaitableEvent::Signal().

◆ TEST_P() [416/662]

impeller::testing::TEST_P ( ComputeTest  ,
CapabilitiesReportSupport   
)

Definition at line 45 of file compute_unittests.cc.

45 {
46 auto context = GetContext();
47 ASSERT_TRUE(context);
48 ASSERT_TRUE(context->GetCapabilities()->SupportsCompute());
49}

References context.

◆ TEST_P() [417/662]

impeller::testing::TEST_P ( ComputeTest  ,
MultiStageInputAndOutput   
)

Definition at line 357 of file compute_unittests.cc.

357 {
358 using CS1 = Stage1ComputeShader;
359 using Stage1PipelineBuilder = ComputePipelineBuilder<CS1>;
360 using CS2 = Stage2ComputeShader;
361 using Stage2PipelineBuilder = ComputePipelineBuilder<CS2>;
362
363 auto context = GetContext();
364 auto host_buffer = CreateHostBufferFromContext(context);
365 ASSERT_TRUE(context);
366 ASSERT_TRUE(context->GetCapabilities()->SupportsCompute());
367
368 auto pipeline_desc_1 =
369 Stage1PipelineBuilder::MakeDefaultPipelineDescriptor(*context);
370 ASSERT_TRUE(pipeline_desc_1.has_value());
371 auto compute_pipeline_1 =
372 context->GetPipelineLibrary()->GetPipeline(pipeline_desc_1).Get();
373 ASSERT_TRUE(compute_pipeline_1);
374
375 auto pipeline_desc_2 =
376 Stage2PipelineBuilder::MakeDefaultPipelineDescriptor(*context);
377 ASSERT_TRUE(pipeline_desc_2.has_value());
378 auto compute_pipeline_2 =
379 context->GetPipelineLibrary()->GetPipeline(pipeline_desc_2).Get();
380 ASSERT_TRUE(compute_pipeline_2);
381
382 auto cmd_buffer = context->CreateCommandBuffer();
383 auto pass = cmd_buffer->CreateComputePass();
384 ASSERT_TRUE(pass && pass->IsValid());
385
386 static constexpr size_t kCount1 = 5;
387 static constexpr size_t kCount2 = kCount1 * 2;
388
389 CS1::Input<kCount1> input_1;
390 input_1.count = kCount1;
391 for (size_t i = 0; i < kCount1; i++) {
392 input_1.elements[i] = i;
393 }
394
395 CS2::Input<kCount2> input_2;
396 input_2.count = kCount2;
397 for (size_t i = 0; i < kCount2; i++) {
398 input_2.elements[i] = i;
399 }
400
401 auto output_buffer_1 = CreateHostVisibleDeviceBuffer<CS1::Output<kCount2>>(
402 context, "Output Buffer Stage 1");
403 auto output_buffer_2 = CreateHostVisibleDeviceBuffer<CS2::Output<kCount2>>(
404 context, "Output Buffer Stage 2");
405
406 {
407 pass->SetPipeline(compute_pipeline_1);
408
409 CS1::BindInput(*pass, host_buffer->EmplaceStorageBuffer(input_1));
410 CS1::BindOutput(*pass, DeviceBuffer::AsBufferView(output_buffer_1));
411
412 ASSERT_TRUE(
413 pass->Compute({WorkgroupCount(kCount1, CS1::kWorkgroupSize[0]), 1, 1})
414 .ok());
415 pass->AddBufferMemoryBarrier();
416 }
417
418 {
419 pass->SetPipeline(compute_pipeline_2);
420
421 CS1::BindInput(*pass, DeviceBuffer::AsBufferView(output_buffer_1));
422 CS2::BindOutput(*pass, DeviceBuffer::AsBufferView(output_buffer_2));
423 ASSERT_TRUE(
424 pass->Compute({WorkgroupCount(kCount2, CS2::kWorkgroupSize[0]), 1, 1})
425 .ok());
426 }
427
428 ASSERT_TRUE(pass->EncodeCommands());
429
431 ASSERT_TRUE(
432 context->GetCommandQueue()
433 ->Submit({cmd_buffer},
434 [&latch, &output_buffer_1,
435 &output_buffer_2](CommandBuffer::Status status) {
436 EXPECT_EQ(status, CommandBuffer::Status::kCompleted);
437
438 CS1::Output<kCount2>* output_1 =
439 reinterpret_cast<CS1::Output<kCount2>*>(
440 output_buffer_1->OnGetContents());
441 EXPECT_TRUE(output_1);
442 EXPECT_EQ(output_1->count, 10u);
443 EXPECT_THAT(
444 output_1->elements,
445 ::testing::ElementsAre(0, 0, 2, 3, 4, 6, 6, 9, 8, 12));
446
447 CS2::Output<kCount2>* output_2 =
448 reinterpret_cast<CS2::Output<kCount2>*>(
449 output_buffer_2->OnGetContents());
450 EXPECT_TRUE(output_2);
451 EXPECT_EQ(output_2->count, 10u);
452 EXPECT_THAT(output_2->elements,
453 ::testing::ElementsAre(0, 0, 4, 6, 8, 12, 12,
454 18, 16, 24));
455
456 latch.Signal();
457 })
458 .ok());
459
460 latch.Wait();
461}

References context, i, impeller::kCount1, and fml::AutoResetWaitableEvent::Wait().

◆ TEST_P() [418/662]

impeller::testing::TEST_P ( ComputeTest  ,
ReturnsEarlyWhenAnyGridDimensionIsZero   
)

Definition at line 544 of file compute_unittests.cc.

544 {
545 using CS = SampleComputeShader;
546 auto context = GetContext();
547 auto host_buffer = CreateHostBufferFromContext(context);
548 ASSERT_TRUE(context);
549 ASSERT_TRUE(context->GetCapabilities()->SupportsCompute());
550
551 using SamplePipelineBuilder = ComputePipelineBuilder<CS>;
552 auto pipeline_desc =
553 SamplePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
554 ASSERT_TRUE(pipeline_desc.has_value());
555 auto compute_pipeline =
556 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
557 ASSERT_TRUE(compute_pipeline);
558
559 auto cmd_buffer = context->CreateCommandBuffer();
560 auto pass = cmd_buffer->CreateComputePass();
561 ASSERT_TRUE(pass && pass->IsValid());
562
563 static constexpr size_t kCount = 5;
564
565 pass->SetPipeline(compute_pipeline);
566
567 CS::Info info{.count = kCount};
568 CS::Input0<kCount> input_0;
569 CS::Input1<kCount> input_1;
570 for (size_t i = 0; i < kCount; i++) {
571 input_0.elements[i] = Vector4(2.0 + i, 3.0 + i, 4.0 + i, 5.0 * i);
572 input_1.elements[i] = Vector4(6.0, 7.0, 8.0, 9.0);
573 }
574
575 input_0.fixed_array[1] = IPoint32(2, 2);
576 input_1.fixed_array[0] = UintPoint32(3, 3);
577 input_0.some_int = 5;
578 input_1.some_struct = CS::SomeStruct{.vf = Point(3, 4), .i = 42};
579
580 auto output_buffer = CreateHostVisibleDeviceBuffer<CS::Output<kCount>>(
581 context, "Output Buffer");
582
583 CS::BindInfo(*pass, host_buffer->EmplaceUniform(info));
584 CS::BindInput0(*pass, host_buffer->EmplaceStorageBuffer(input_0));
585 CS::BindInput1(*pass, host_buffer->EmplaceStorageBuffer(input_1));
586 CS::BindOutput(*pass, DeviceBuffer::AsBufferView(output_buffer));
587
588 // Intentionally making the workgroup count zero in one dimension. No GPU will
589 // tolerate this.
590 auto status = pass->Compute({0, 1, 1});
591 EXPECT_FALSE(status.ok());
592 EXPECT_EQ(status.code(), fml::StatusCode::kCancelled);
593 pass->EncodeCommands();
594}

References context, i, and fml::kCancelled.

◆ TEST_P() [419/662]

impeller::testing::TEST_P ( ContextMTLTest  ,
FlushTask   
)

Definition at line 28 of file context_mtl_unittests.mm.

28 {
29 auto& context_mtl = ContextMTL::Cast(*GetContext());
30
31 int executed = 0;
32 int failed = 0;
33 context_mtl.StoreTaskForGPU([&]() { executed++; }, [&]() { failed++; });
34
35 context_mtl.FlushTasksAwaitingGPU();
36
37 EXPECT_EQ(executed, 1);
38 EXPECT_EQ(failed, 0);
39}

References impeller::BackendCast< ContextMTL, Context >::Cast().

◆ TEST_P() [420/662]

impeller::testing::TEST_P ( ContextMTLTest  ,
FlushTaskWithGPULoss   
)

Definition at line 41 of file context_mtl_unittests.mm.

41 {
42 auto& context_mtl = ContextMTL::Cast(*GetContext());
43
44 int executed = 0;
45 int failed = 0;
46 context_mtl.StoreTaskForGPU([&]() { executed++; }, [&]() { failed++; });
47
48 // If tasks are flushed while the GPU is disabled, then
49 // they should not be executed.
50 SetGPUDisabled(/*disabled=*/true);
51 context_mtl.FlushTasksAwaitingGPU();
52
53 EXPECT_EQ(executed, 0);
54 EXPECT_EQ(failed, 0);
55
56 // Toggling availibility should flush tasks.
57 SetGPUDisabled(/*disabled=*/false);
58
59 EXPECT_EQ(executed, 1);
60 EXPECT_EQ(failed, 0);
61}

References impeller::BackendCast< ContextMTL, Context >::Cast().

◆ TEST_P() [421/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanBlendDstOverAndDstCorrectly   
)

Definition at line 1288 of file dl_unittests.cc.

1288 {
1290
1291 {
1292 builder.SaveLayer(std::nullopt, nullptr);
1293 builder.Translate(100, 100);
1294 flutter::DlPaint paint;
1296 builder.DrawRect(DlRect::MakeWH(200, 200), paint);
1297 paint.setColor(flutter::DlColor::kBlue().withAlpha(127));
1298 paint.setBlendMode(flutter::DlBlendMode::kSrcOver);
1299 builder.DrawRect(DlRect::MakeWH(200, 200), paint);
1300 builder.Restore();
1301 }
1302 {
1303 builder.SaveLayer(std::nullopt, nullptr);
1304 builder.Translate(300, 100);
1305 flutter::DlPaint paint;
1306 paint.setColor(flutter::DlColor::kBlue().withAlpha(127));
1307 builder.DrawRect(DlRect::MakeWH(200, 200), paint);
1309 paint.setBlendMode(flutter::DlBlendMode::kDstOver);
1310 builder.DrawRect(DlRect::MakeWH(200, 200), paint);
1311 builder.Restore();
1312 }
1313 {
1314 builder.SaveLayer(std::nullopt, nullptr);
1315 builder.Translate(100, 300);
1316 flutter::DlPaint paint;
1318 builder.DrawRect(DlRect::MakeWH(200, 200), paint);
1319 paint.setColor(flutter::DlColor::kBlue().withAlpha(127));
1320 paint.setBlendMode(flutter::DlBlendMode::kSrc);
1321 builder.DrawRect(DlRect::MakeWH(200, 200), paint);
1322 builder.Restore();
1323 }
1324 {
1325 builder.SaveLayer(std::nullopt, nullptr);
1326 builder.Translate(300, 300);
1327 flutter::DlPaint paint;
1328 paint.setColor(flutter::DlColor::kBlue().withAlpha(127));
1329 builder.DrawRect(DlRect::MakeWH(200, 200), paint);
1331 paint.setBlendMode(flutter::DlBlendMode::kDst);
1332 builder.DrawRect(DlRect::MakeWH(200, 200), paint);
1333 builder.Restore();
1334 }
1335
1336 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1337}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kRed(), impeller::TRect< Scalar >::MakeWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setBlendMode(), flutter::DlPaint::setColor(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [422/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanClampTheResultingColorOfColorMatrixFilter   
)

Definition at line 637 of file dl_unittests.cc.

637 {
638 auto texture = CreateTextureForFixture("boston.jpg");
639 const float inner_color_matrix[20] = {
640 1, 0, 0, 0, 0, //
641 0, 1, 0, 0, 0, //
642 0, 0, 1, 0, 0, //
643 0, 0, 0, 2, 0, //
644 };
645 const float outer_color_matrix[20] = {
646 1, 0, 0, 0, 0, //
647 0, 1, 0, 0, 0, //
648 0, 0, 1, 0, 0, //
649 0, 0, 0, 0.5, 0, //
650 };
651 auto inner_color_filter =
652 flutter::DlColorFilter::MakeMatrix(inner_color_matrix);
653 auto outer_color_filter =
654 flutter::DlColorFilter::MakeMatrix(outer_color_matrix);
655 auto inner = flutter::DlImageFilter::MakeColorFilter(inner_color_filter);
656 auto outer = flutter::DlImageFilter::MakeColorFilter(outer_color_filter);
657 auto compose = std::make_shared<flutter::DlComposeImageFilter>(outer, inner);
658
660 flutter::DlPaint paint;
661 paint.setImageFilter(compose.get());
662 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(100, 100),
664 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
665}
static std::shared_ptr< const DlColorFilter > MakeMatrix(const float matrix[20])
static std::shared_ptr< DlImageFilter > MakeColorFilter(const std::shared_ptr< const DlColorFilter > &filter)

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), flutter::kNearestNeighbor, impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeColorFilter(), flutter::DlColorFilter::MakeMatrix(), flutter::DlPaint::setImageFilter(), and texture.

◆ TEST_P() [423/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawAnOpenPath   
)

Definition at line 424 of file dl_unittests.cc.

424 {
426 flutter::DlPaint paint;
427
430 paint.setStrokeWidth(10);
431
432 builder.Translate(300, 300);
433
434 // Move to (50, 50) and draw lines from:
435 // 1. (50, height)
436 // 2. (width, height)
437 // 3. (width, 50)
438 flutter::DlPathBuilder path_builder;
439 path_builder.MoveTo(DlPoint(50, 50));
440 path_builder.LineTo(DlPoint(50, 100));
441 path_builder.LineTo(DlPoint(100, 100));
442 path_builder.LineTo(DlPoint(100, 50));
443 builder.DrawPath(path_builder.TakePath(), paint);
444
445 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
446}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::DlColor::kRed(), flutter::kStroke, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [424/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawArc   
)

Definition at line 158 of file dl_unittests.cc.

158 {
159 auto callback = [&]() {
160 static float start_angle = 45;
161 static float sweep_angle = 270;
162 static float stroke_width = 10;
163 static bool use_center = true;
164
165 static int selected_cap = 0;
166 const char* cap_names[] = {"Butt", "Round", "Square"};
168
169 if (IsPlaygroundEnabled()) {
170 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
171 ImGui::SliderFloat("Start angle", &start_angle, -360, 360);
172 ImGui::SliderFloat("Sweep angle", &sweep_angle, -360, 360);
173 ImGui::SliderFloat("Stroke width", &stroke_width, 0, 300);
174 ImGui::Combo("Cap", &selected_cap, cap_names,
175 sizeof(cap_names) / sizeof(char*));
176 ImGui::Checkbox("Use center", &use_center);
177 ImGui::End();
178 }
179
180 switch (selected_cap) {
181 case 0:
183 break;
184 case 1:
186 break;
187 case 2:
189 break;
190 default:
192 break;
193 }
194
195 static PlaygroundPoint point_a(Point(200, 200), 20, Color::White());
196 static PlaygroundPoint point_b(Point(400, 400), 20, Color::White());
197 auto [p1, p2] = DrawPlaygroundLine(point_a, point_b);
198
200 flutter::DlPaint paint;
201
202 Vector2 scale = GetContentScale();
203 builder.Scale(scale.x, scale.y);
205 paint.setStrokeCap(cap);
207 paint.setStrokeMiter(10);
208 auto rect = DlRect::MakeLTRB(p1.x, p1.y, p2.x, p2.y);
210 paint.setStrokeWidth(2);
211 builder.DrawRect(rect, paint);
213 paint.setStrokeWidth(stroke_width);
214 builder.DrawArc(rect, start_angle, sweep_angle, use_center, paint);
215
216 return builder.Build();
217 };
218 ASSERT_TRUE(OpenPlaygroundHere(callback));
219}
void DrawArc(const DlRect &bounds, DlScalar start, DlScalar sweep, bool useCenter, const DlPaint &paint) override
@ kMiter
extends to miter limit

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawArc(), impeller::DrawPlaygroundLine(), flutter::DisplayListBuilder::DrawRect(), flutter::kButt, flutter::DlColor::kGreen(), flutter::kMiter, flutter::DlColor::kRed(), flutter::kRound, flutter::kSquare, flutter::kStroke, impeller::TRect< Scalar >::MakeLTRB(), p1, p2, flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeMiter(), flutter::DlPaint::setStrokeWidth(), use_center, impeller::Color::White(), impeller::TPoint< T >::x, flutter::Point::x(), impeller::TPoint< T >::y, and flutter::Point::y().

◆ TEST_P() [425/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawBackdropFilter   
)

Definition at line 667 of file dl_unittests.cc.

667 {
668 auto texture = CreateTextureForFixture("embarcadero.jpg");
669
670 auto callback = [&]() {
671 static float sigma[] = {10, 10};
672 static float ctm_scale = 1;
673 static bool use_bounds = true;
674 static bool draw_circle = true;
675 static bool add_clip = true;
676
677 if (IsPlaygroundEnabled()) {
678 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
679 ImGui::SliderFloat2("Sigma", sigma, 0, 100);
680 ImGui::SliderFloat("Scale", &ctm_scale, 0, 10);
681 ImGui::NewLine();
682 ImGui::TextWrapped(
683 "If everything is working correctly, none of the options below "
684 "should impact the filter's appearance.");
685 ImGui::Checkbox("Use SaveLayer bounds", &use_bounds);
686 ImGui::Checkbox("Draw child element", &draw_circle);
687 ImGui::Checkbox("Add pre-clip", &add_clip);
688 ImGui::End();
689 }
690
692
693 Vector2 scale = ctm_scale * GetContentScale();
694 builder.Scale(scale.x, scale.y);
695
696 auto filter = flutter::DlBlurImageFilter(sigma[0], sigma[1],
698
699 std::optional<DlRect> bounds;
700 if (use_bounds) {
701 static PlaygroundPoint point_a(Point(350, 150), 20, Color::White());
702 static PlaygroundPoint point_b(Point(800, 600), 20, Color::White());
703 auto [p1, p2] = DrawPlaygroundLine(point_a, point_b);
704 bounds = DlRect::MakeLTRB(p1.x, p1.y, p2.x, p2.y);
705 }
706
707 // Insert a clip to test that the backdrop filter handles stencil depths > 0
708 // correctly.
709 if (add_clip) {
710 builder.ClipRect(DlRect::MakeLTRB(0, 0, 99999, 99999),
712 }
713
714 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(200, 200),
716 builder.SaveLayer(bounds, nullptr, &filter);
717
718 if (draw_circle) {
719 static PlaygroundPoint center_point(Point(500, 400), 20, Color::Red());
720 auto circle_center = DrawPlaygroundPoint(center_point);
721
722 flutter::DlPaint paint;
726 paint.setStrokeWidth(10);
727 paint.setColor(flutter::DlColor::kRed().withAlpha(100));
728 builder.DrawCircle(DlPoint(circle_center.x, circle_center.y), 100, paint);
729 }
730
731 return builder.Build();
732 };
733
734 ASSERT_TRUE(OpenPlaygroundHere(callback));
735}
@ kBevel
connects outside edges

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawImage(), impeller::DrawPlaygroundLine(), impeller::DrawPlaygroundPoint(), flutter::kBevel, flutter::kButt, flutter::kClamp, flutter::kIntersect, flutter::kNearestNeighbor, flutter::DlColor::kRed(), flutter::kStroke, impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeLTRB(), p1, p2, impeller::Color::Red(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), texture, impeller::Color::White(), impeller::TPoint< T >::x, flutter::Point::x(), impeller::TPoint< T >::y, and flutter::Point::y().

◆ TEST_P() [426/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawBoundedBlur   
)

Definition at line 737 of file dl_unittests.cc.

737 {
738 auto texture = CreateTextureForFixture("kalimba.jpg");
739 const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
740 const flutter::DlTileMode tile_modes[] = {
743
744 auto callback = [&]() {
745 static float sigma = 20;
746 static float bg_scale = 2.1;
747 static float rotate_degree = 0;
748 static float bounds_scale = 1.0;
749 static bool use_bounds = true;
750 static int selected_tile_mode = 0;
751
752 if (IsPlaygroundEnabled()) {
753 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
754 ImGui::SliderFloat("Background scale", &bg_scale, 0, 10);
755 ImGui::SliderFloat("Sigma", &sigma, 0, 100);
756 ImGui::SliderFloat("Bounds rotate", &rotate_degree, -200, 200);
757 ImGui::SliderFloat("Bounds scale", &bounds_scale, 0.5f, 2.0f);
758 ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
759 sizeof(tile_mode_names) / sizeof(char*));
760 ImGui::NewLine();
761 ImGui::Checkbox("Bounded blur", &use_bounds);
762 ImGui::End();
763 }
764
765 // Draw from top right to bottom left.
766 static PlaygroundPoint blur_point_a(Point(410, 30), 10, Color::White());
767 static PlaygroundPoint blur_point_b(Point(150, 320), 10, Color::White());
768 auto [p1_raw, p2_raw] = DrawPlaygroundLine(blur_point_a, blur_point_b);
769 Matrix content_scale_transform = Matrix::MakeScale(GetContentScale());
770 Point p1_global = content_scale_transform * p1_raw;
771 Point p2_global = content_scale_transform * p2_raw;
772
774
775 builder.Save();
776 builder.Scale(bg_scale, bg_scale);
777 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(0, 0),
779 builder.Restore();
780
781 Matrix transform =
782 Matrix::MakeRotationZ(Radians(rotate_degree / 180.0f * kPi));
783 Matrix inverse_transform = transform.Invert();
784
785 builder.Transform(transform);
786
787 Point p1 = inverse_transform * p1_global;
788 Point p2 = inverse_transform * p2_global;
789 DlRect bounds =
790 DlRect::MakeLTRB(p2.x, p1.y, p1.x, p2.y).Scale(bounds_scale);
791
792 builder.ClipRect(bounds);
793 builder.Save();
794
795 flutter::DlPaint save_paint;
796 save_paint.setBlendMode(flutter::DlBlendMode::kSrcOver);
797
798 std::optional<DlRect> blur_bounds;
799 if (use_bounds) {
800 blur_bounds = bounds;
801 }
802 auto filter = flutter::DlBlurImageFilter(
803 sigma, sigma, tile_modes[selected_tile_mode], blur_bounds);
804 builder.SaveLayer(std::nullopt, &save_paint, &filter);
805 builder.Restore();
806 builder.Restore();
807
808 return builder.Build();
809 };
810
811 ASSERT_TRUE(OpenPlaygroundHere(callback));
812}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawImage(), impeller::DrawPlaygroundLine(), impeller::Matrix::Invert(), flutter::kClamp, flutter::kDecal, flutter::kMirror, flutter::kNearestNeighbor, flutter::kPi, flutter::kRepeat, impeller::DlImageImpeller::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), p1, p2, flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), impeller::TRect< T >::Scale(), flutter::DlPaint::setBlendMode(), texture, flutter::DisplayListBuilder::Transform(), transform, impeller::Color::White(), flutter::Point::x(), and flutter::Point::y().

◆ TEST_P() [427/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawCapsAndJoins   
)

Definition at line 109 of file dl_unittests.cc.

109 {
111 flutter::DlPaint paint;
112
114 paint.setStrokeWidth(30);
116
117 flutter::DlPathBuilder path_builder;
118 path_builder.MoveTo(DlPoint(-50, 0));
119 path_builder.LineTo(DlPoint(0, -50));
120 path_builder.LineTo(DlPoint(50, 0));
121 flutter::DlPath path = path_builder.TakePath();
122
123 builder.Translate(100, 100);
124 {
127 paint.setStrokeMiter(4);
128 builder.DrawPath(path, paint);
129 }
130
131 {
132 builder.Save();
133 builder.Translate(0, 100);
134 // The joint in the path is 45 degrees. A miter length of 1 convert to a
135 // bevel in this case.
136 paint.setStrokeMiter(1);
137 builder.DrawPath(path, paint);
138 builder.Restore();
139 }
140
141 builder.Translate(150, 0);
142 {
145 builder.DrawPath(path, paint);
146 }
147
148 builder.Translate(150, 0);
149 {
152 builder.DrawPath(path, paint);
153 }
154
155 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
156}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::kBevel, flutter::kButt, flutter::kMiter, flutter::DlColor::kRed(), flutter::kRound, flutter::kSquare, flutter::kStroke, flutter::DlPathBuilder::LineTo(), flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeMiter(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [428/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawCorrectlyWithColorFilterAndImageFilter   
)

Definition at line 1339 of file dl_unittests.cc.

1339 {
1341 const float green_color_matrix[20] = {
1342 0, 0, 0, 0, 0, //
1343 0, 0, 0, 0, 1, //
1344 0, 0, 0, 0, 0, //
1345 0, 0, 0, 1, 0, //
1346 };
1347 const float blue_color_matrix[20] = {
1348 0, 0, 0, 0, 0, //
1349 0, 0, 0, 0, 0, //
1350 0, 0, 0, 0, 1, //
1351 0, 0, 0, 1, 0, //
1352 };
1353 auto green_color_filter =
1354 flutter::DlColorFilter::MakeMatrix(green_color_matrix);
1355 auto blue_color_filter =
1356 flutter::DlColorFilter::MakeMatrix(blue_color_matrix);
1357 auto blue_image_filter =
1358 flutter::DlImageFilter::MakeColorFilter(blue_color_filter);
1359
1360 flutter::DlPaint paint;
1362 paint.setColorFilter(green_color_filter);
1363 paint.setImageFilter(blue_image_filter);
1364 builder.DrawRect(DlRect::MakeLTRB(100, 100, 500, 500), paint);
1365 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1366}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kRed(), flutter::DlImageFilter::MakeColorFilter(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlColorFilter::MakeMatrix(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), and flutter::DlPaint::setImageFilter().

◆ TEST_P() [429/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawImage   
)

Definition at line 101 of file dl_unittests.cc.

101 {
102 auto texture = CreateTextureForFixture("embarcadero.jpg");
104 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(100, 100),
106 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
107}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), flutter::kNearestNeighbor, impeller::DlImageImpeller::Make(), and texture.

◆ TEST_P() [430/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawNinePatchImage   
)

Definition at line 814 of file dl_unittests.cc.

814 {
815 // Image is drawn with corners to scale and center pieces stretched to fit.
816 auto texture = CreateTextureForFixture("embarcadero.jpg");
818 auto size = texture->GetSize();
819 builder.DrawImageNine(
820 DlImageImpeller::Make(texture),
821 DlIRect::MakeLTRB(size.width / 4, size.height / 4, size.width * 3 / 4,
822 size.height * 3 / 4),
823 DlRect::MakeLTRB(0, 0, size.width * 2, size.height * 2),
825 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
826}
void DrawImageNine(const sk_sp< DlImage > &image, const DlIRect &center, const DlRect &dst, DlFilterMode filter, const DlPaint *paint=nullptr) override

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageNine(), flutter::kNearest, impeller::DlImageImpeller::Make(), impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), flutter::size, and texture.

◆ TEST_P() [431/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawNinePatchImageCenterBiggerThanDest   
)

Definition at line 860 of file dl_unittests.cc.

860 {
861 // Edge case, the width and height of the corners does not leave any
862 // room for the center slices. Only the corners are displayed.
863 auto texture = CreateTextureForFixture("embarcadero.jpg");
865 auto size = texture->GetSize();
866 builder.DrawImageNine(
867 DlImageImpeller::Make(texture),
868 DlIRect::MakeLTRB(size.width / 4, size.height / 4, size.width * 3 / 4,
869 size.height * 3 / 4),
870 DlRect::MakeLTRB(0, 0, size.width / 2, size.height / 2),
872 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
873}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageNine(), flutter::kNearest, impeller::DlImageImpeller::Make(), impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), flutter::size, and texture.

◆ TEST_P() [432/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawNinePatchImageCenterHeightBiggerThanDest   
)

Definition at line 844 of file dl_unittests.cc.

844 {
845 // Edge case, the height of the corners does not leave any room for the
846 // center slice. The center (across the horizontal axis) is folded out of the
847 // resulting image.
848 auto texture = CreateTextureForFixture("embarcadero.jpg");
850 auto size = texture->GetSize();
851 builder.DrawImageNine(
852 DlImageImpeller::Make(texture),
853 DlIRect::MakeLTRB(size.width / 4, size.height / 4, size.width * 3 / 4,
854 size.height * 3 / 4),
855 DlRect::MakeLTRB(0, 0, size.width, size.height / 2),
857 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
858}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageNine(), flutter::kNearest, impeller::DlImageImpeller::Make(), impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), flutter::size, and texture.

◆ TEST_P() [433/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawNinePatchImageCenterWidthBiggerThanDest   
)

Definition at line 828 of file dl_unittests.cc.

828 {
829 // Edge case, the width of the corners does not leave any room for the
830 // center slice. The center (across the vertical axis) is folded out of the
831 // resulting image.
832 auto texture = CreateTextureForFixture("embarcadero.jpg");
834 auto size = texture->GetSize();
835 builder.DrawImageNine(
836 DlImageImpeller::Make(texture),
837 DlIRect::MakeLTRB(size.width / 4, size.height / 4, size.width * 3 / 4,
838 size.height * 3 / 4),
839 DlRect::MakeLTRB(0, 0, size.width / 2, size.height),
841 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
842}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageNine(), flutter::kNearest, impeller::DlImageImpeller::Make(), impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), flutter::size, and texture.

◆ TEST_P() [434/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawNinePatchImageCornersScaledDown   
)

Definition at line 875 of file dl_unittests.cc.

875 {
876 // Edge case, there is not enough room for the corners to be drawn
877 // without scaling them down.
878 auto texture = CreateTextureForFixture("embarcadero.jpg");
880 auto size = texture->GetSize();
881 builder.DrawImageNine(
882 DlImageImpeller::Make(texture),
883 DlIRect::MakeLTRB(size.width / 4, size.height / 4, size.width * 3 / 4,
884 size.height * 3 / 4),
885 DlRect::MakeLTRB(0, 0, size.width / 4, size.height / 4),
887 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
888}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageNine(), flutter::kNearest, impeller::DlImageImpeller::Make(), impeller::TRect< T >::MakeLTRB(), impeller::TRect< Scalar >::MakeLTRB(), flutter::size, and texture.

◆ TEST_P() [435/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawPaintWithColorSource   
)

Definition at line 1236 of file dl_unittests.cc.

1236 {
1237 const flutter::DlColor colors[2] = {
1238 flutter::DlColor(0xFFF44336),
1239 flutter::DlColor(0xFF2196F3),
1240 };
1241 const float stops[2] = {0.0, 1.0};
1242 flutter::DlPaint paint;
1244 auto clip_bounds = DlRect::MakeWH(300.0, 300.0);
1245 builder.Save();
1246 builder.Translate(100, 100);
1247 builder.ClipRect(clip_bounds, flutter::DlClipOp::kIntersect, false);
1248 auto linear =
1249 flutter::DlColorSource::MakeLinear({0.0, 0.0}, {100.0, 100.0}, 2, colors,
1251 paint.setColorSource(linear);
1252 builder.DrawPaint(paint);
1253 builder.Restore();
1254
1255 builder.Save();
1256 builder.Translate(500, 100);
1257 builder.ClipRect(clip_bounds, flutter::DlClipOp::kIntersect, false);
1259 {100.0, 100.0}, 100.0, 2, colors, stops, flutter::DlTileMode::kRepeat);
1260 paint.setColorSource(radial);
1261 builder.DrawPaint(paint);
1262 builder.Restore();
1263
1264 builder.Save();
1265 builder.Translate(100, 500);
1266 builder.ClipRect(clip_bounds, flutter::DlClipOp::kIntersect, false);
1267 auto sweep =
1268 flutter::DlColorSource::MakeSweep({100.0, 100.0}, 180.0, 270.0, 2, colors,
1270 paint.setColorSource(sweep);
1271 builder.DrawPaint(paint);
1272 builder.Restore();
1273
1274 builder.Save();
1275 builder.Translate(500, 500);
1276 builder.ClipRect(clip_bounds, flutter::DlClipOp::kIntersect, false);
1277 auto texture = CreateTextureForFixture("table_mountain_nx.png");
1278 auto image = flutter::DlColorSource::MakeImage(DlImageImpeller::Make(texture),
1281 paint.setColorSource(image);
1282 builder.DrawPaint(paint);
1283 builder.Restore();
1284
1285 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1286}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRect(), flutter::DisplayListBuilder::DrawPaint(), image, flutter::kIntersect, flutter::kRepeat, impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), flutter::DlColorSource::MakeLinear(), flutter::DlColorSource::MakeRadial(), flutter::DlColorSource::MakeSweep(), impeller::TRect< Scalar >::MakeWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColorSource(), texture, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [436/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawPoints   
)

Definition at line 918 of file dl_unittests.cc.

918 {
920 DlPoint points[7] = {
921 {0, 0}, //
922 {100, 100}, //
923 {100, 0}, //
924 {0, 100}, //
925 {0, 0}, //
926 {48, 48}, //
927 {52, 52}, //
928 };
929 std::vector<flutter::DlStrokeCap> caps = {
933 };
934 flutter::DlPaint paint =
936 .setColor(flutter::DlColor::kYellow().withAlpha(127)) //
937 .setStrokeWidth(20);
938 builder.Translate(50, 50);
939 for (auto cap : caps) {
940 paint.setStrokeCap(cap);
941 builder.Save();
943 builder.Translate(150, 0);
945 builder.Translate(150, 0);
947 builder.Restore();
948 builder.Translate(0, 150);
949 }
950 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
951}
@ kLines
draw each separate pair of points as a line segment
@ kPolygon
draw each pair of overlapping points as a line segment
@ kPoints
draw each point separately

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPoints(), flutter::kButt, flutter::kLines, flutter::kPoints, flutter::kPolygon, flutter::kRound, flutter::kSquare, flutter::DlColor::kYellow(), points, flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColor(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [437/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawRect   
)

Definition at line 48 of file dl_unittests.cc.

48 {
50 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100),
52 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
53}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST_P() [438/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawRectWithLinearToSrgbColorFilter   
)

Definition at line 1222 of file dl_unittests.cc.

1222 {
1223 flutter::DlPaint paint;
1224 paint.setColor(flutter::DlColor(0xFF2196F3).withAlpha(128));
1227 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), paint);
1228 builder.Translate(0, 200);
1229
1231 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), paint);
1232
1233 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1234}
static std::shared_ptr< const DlColorFilter > MakeLinearToSrgbGamma()
static std::shared_ptr< const DlColorFilter > MakeSrgbToLinearGamma()

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColorFilter::MakeLinearToSrgbGamma(), flutter::DlColorFilter::MakeSrgbToLinearGamma(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setColorFilter(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [439/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawShadow   
)

Definition at line 976 of file dl_unittests.cc.

976 {
978 flutter::DlPaint paint;
979
980 auto content_scale = GetContentScale() * 0.8;
981 builder.Scale(content_scale.x, content_scale.y);
982
983 constexpr size_t star_spikes = 5;
984 constexpr DlScalar half_spike_rotation = kPi / star_spikes;
985 constexpr DlScalar radius = 40;
986 constexpr DlScalar spike_size = 10;
987 constexpr DlScalar outer_radius = radius + spike_size;
988 constexpr DlScalar inner_radius = radius - spike_size;
989 std::array<DlPoint, star_spikes * 2> star;
990 for (size_t i = 0; i < star_spikes; i++) {
991 const DlScalar rotation = half_spike_rotation * i * 2;
992 star[i * 2] = DlPoint(50 + std::sin(rotation) * outer_radius,
993 50 - std::cos(rotation) * outer_radius);
994 star[i * 2 + 1] =
995 DlPoint(50 + std::sin(rotation + half_spike_rotation) * inner_radius,
996 50 - std::cos(rotation + half_spike_rotation) * inner_radius);
997 }
998
999 std::array<DlPath, 4> paths = {
1000 DlPath::MakeRect(DlRect::MakeXYWH(0, 0, 200, 100)),
1001 DlPath::MakeRoundRectXY(DlRect::MakeXYWH(20, 0, 200, 100), 30, 30),
1002 DlPath::MakeCircle(DlPoint(100, 50), 50),
1003 DlPath::MakePoly(star.data(), star.size(), true),
1004 };
1006 builder.DrawPaint(paint);
1008 builder.Translate(100, 50);
1009 for (size_t x = 0; x < paths.size(); x++) {
1010 builder.Save();
1011 for (size_t y = 0; y < 6; y++) {
1012 builder.DrawShadow(paths[x], flutter::DlColor::kBlack(), 3 + y * 8, false,
1013 1);
1014 builder.DrawPath(paths[x], paint);
1015 builder.Translate(0, 150);
1016 }
1017 builder.Restore();
1018 builder.Translate(250, 0);
1019 }
1020
1021 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1022}
static constexpr DlColor kCyan()
Definition dl_color.h:74

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawShadow(), i, flutter::DlColor::kBlack(), flutter::DlColor::kCyan(), flutter::kPi, flutter::DlColor::kWhite(), flutter::DlPath::MakeCircle(), flutter::DlPath::MakePoly(), flutter::DlPath::MakeRect(), flutter::DlPath::MakeRoundRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DisplayListBuilder::Translate(), x, and y.

◆ TEST_P() [440/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawStrokedText   
)

Definition at line 485 of file dl_unittests.cc.

485 {
487 flutter::DlPaint paint;
488
491 builder.DrawText(
492 flutter::DlTextImpeller::MakeFromBlob(SkTextBlob::MakeFromString(
493 "stoked about stroked text", CreateTestFont())),
494 250, 250, paint);
495
496 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
497}
static std::shared_ptr< DlTextImpeller > MakeFromBlob(const sk_sp< SkTextBlob > &blob)

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawText(), flutter::DlColor::kRed(), flutter::kStroke, flutter::DlTextImpeller::MakeFromBlob(), flutter::DlPaint::setColor(), and flutter::DlPaint::setDrawStyle().

◆ TEST_P() [441/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawTextBlob   
)

Definition at line 55 of file dl_unittests.cc.

55 {
58 SkTextBlob::MakeFromString("Hello", CreateTestFont())),
60 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
61}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawText(), flutter::DlColor::kBlue(), and flutter::DlTextImpeller::MakeFromBlob().

◆ TEST_P() [442/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawTextBlobWithGradient   
)

Definition at line 63 of file dl_unittests.cc.

63 {
65
66 std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
68 const float stops[2] = {0.0, 1.0};
69
71 {0.0, 0.0}, {300.0, 300.0}, 2, colors.data(), stops,
73 flutter::DlPaint paint;
74 paint.setColorSource(linear);
75
76 builder.DrawText(
78 SkTextBlob::MakeFromString("Hello World", CreateTestFont())),
79 100, 100, paint);
80 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
81}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawText(), flutter::DlColor::kBlue(), flutter::kMirror, flutter::DlColor::kRed(), flutter::DlTextImpeller::MakeFromBlob(), flutter::DlColorSource::MakeLinear(), and flutter::DlPaint::setColorSource().

◆ TEST_P() [443/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawTextWithSaveLayer   
)

Definition at line 83 of file dl_unittests.cc.

83 {
86 SkTextBlob::MakeFromString("Hello", CreateTestFont())),
88
89 flutter::DlPaint save_paint;
90 float alpha = 0.5;
91 save_paint.setAlpha(static_cast<uint8_t>(255 * alpha));
92 builder.SaveLayer(std::nullopt, &save_paint);
93 builder.DrawText(
94 flutter::DlTextImpeller::MakeFromBlob(SkTextBlob::MakeFromString(
95 "Hello with half alpha", CreateTestFontOfSize(100))),
97 builder.Restore();
98 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
99}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawText(), flutter::DlColor::kRed(), flutter::DlTextImpeller::MakeFromBlob(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), and flutter::DlPaint::setAlpha().

◆ TEST_P() [444/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawWithBlendColorFilter   
)

Definition at line 539 of file dl_unittests.cc.

539 {
540 auto texture = CreateTextureForFixture("embarcadero.jpg");
542 flutter::DlPaint paint;
543
544 // Pipeline blended image.
545 {
547 flutter::DlColor::kYellow(), flutter::DlBlendMode::kModulate);
548 paint.setColorFilter(filter);
549 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(100, 100),
551 }
552
553 // Advanced blended image.
554 {
556 flutter::DlColor::kRed(), flutter::DlBlendMode::kScreen);
557 paint.setColorFilter(filter);
558 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(250, 250),
560 }
561
562 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
563}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), flutter::kNearestNeighbor, flutter::DlColor::kRed(), flutter::DlColor::kYellow(), impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeBlend(), flutter::DlPaint::setColorFilter(), and texture.

◆ TEST_P() [445/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawWithColorFilterImageFilter   
)

Definition at line 565 of file dl_unittests.cc.

565 {
566 const float invert_color_matrix[20] = {
567 -1, 0, 0, 0, 1, //
568 0, -1, 0, 0, 1, //
569 0, 0, -1, 0, 1, //
570 0, 0, 0, 1, 0, //
571 };
572 auto texture = CreateTextureForFixture("boston.jpg");
574 flutter::DlPaint paint;
575
576 auto color_filter = flutter::DlColorFilter::MakeMatrix(invert_color_matrix);
577 auto image_filter = flutter::DlImageFilter::MakeColorFilter(color_filter);
578
579 paint.setImageFilter(image_filter);
580 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(100, 100),
582
583 builder.Translate(0, 700);
584 paint.setColorFilter(color_filter);
585 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(100, 100),
587 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
588}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), flutter::kNearestNeighbor, impeller::DlImageImpeller::Make(), flutter::DlImageFilter::MakeColorFilter(), flutter::DlColorFilter::MakeMatrix(), flutter::DlPaint::setColorFilter(), flutter::DlPaint::setImageFilter(), texture, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [446/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawWithComposeImageFilter   
)

Definition at line 617 of file dl_unittests.cc.

617 {
618 auto texture = CreateTextureForFixture("boston.jpg");
620 flutter::DlPaint paint;
621
622 auto dilate = std::make_shared<flutter::DlDilateImageFilter>(10.0, 10.0);
623 auto erode = std::make_shared<flutter::DlErodeImageFilter>(10.0, 10.0);
624 auto open = std::make_shared<flutter::DlComposeImageFilter>(dilate, erode);
625 auto close = std::make_shared<flutter::DlComposeImageFilter>(erode, dilate);
626
627 paint.setImageFilter(open.get());
628 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(100, 100),
630 builder.Translate(0, 700);
631 paint.setImageFilter(close.get());
632 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(100, 100),
634 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
635}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), flutter::kNearestNeighbor, impeller::DlImageImpeller::Make(), flutter::DlPaint::setImageFilter(), texture, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [447/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawWithImageBlurFilter   
)

Definition at line 590 of file dl_unittests.cc.

590 {
591 auto texture = CreateTextureForFixture("embarcadero.jpg");
592
593 auto callback = [&]() {
594 static float sigma[] = {10, 10};
595
596 if (IsPlaygroundEnabled()) {
597 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
598 ImGui::SliderFloat2("Sigma", sigma, 0, 100);
599 ImGui::End();
600 }
601
603 flutter::DlPaint paint;
604
605 auto filter = flutter::DlBlurImageFilter(sigma[0], sigma[1],
607 paint.setImageFilter(&filter);
608 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(200, 200),
610
611 return builder.Build();
612 };
613
614 ASSERT_TRUE(OpenPlaygroundHere(callback));
615}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawImage(), flutter::kClamp, flutter::kNearestNeighbor, impeller::DlImageImpeller::Make(), flutter::DlPaint::setImageFilter(), and texture.

◆ TEST_P() [448/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawWithMaskBlur   
)

Definition at line 448 of file dl_unittests.cc.

448 {
449 auto texture = CreateTextureForFixture("embarcadero.jpg");
451 flutter::DlPaint paint;
452
453 // Mask blurred image.
454 {
455 auto filter =
457 paint.setMaskFilter(&filter);
458 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(100, 100),
460 }
461
462 // Mask blurred filled path.
463 {
465 auto filter =
467 paint.setMaskFilter(&filter);
468 builder.DrawArc(DlRect::MakeXYWH(410, 110, 100, 100), 45, 270, true, paint);
469 }
470
471 // Mask blurred text.
472 {
473 auto filter =
475 paint.setMaskFilter(&filter);
476 builder.DrawText(
478 SkTextBlob::MakeFromString("Testing", CreateTestFont())),
479 220, 170, paint);
480 }
481
482 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
483}
@ kNormal
fuzzy inside and outside
@ kOuter
nothing inside, fuzzy outside
@ kSolid
solid inside, fuzzy outside

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawArc(), flutter::DisplayListBuilder::DrawImage(), flutter::DisplayListBuilder::DrawText(), flutter::kNearestNeighbor, flutter::kNormal, flutter::kOuter, flutter::kSolid, flutter::DlColor::kYellow(), impeller::DlImageImpeller::Make(), flutter::DlTextImpeller::MakeFromBlob(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setMaskFilter(), and texture.

◆ TEST_P() [449/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawWithMatrixFilter   
)

Definition at line 1058 of file dl_unittests.cc.

1058 {
1059 auto boston = CreateTextureForFixture("boston.jpg");
1060
1061 auto callback = [&]() {
1062 static int selected_matrix_type = 0;
1063 const char* matrix_type_names[] = {"Matrix", "Local Matrix"};
1064
1065 static float ctm_translation[2] = {200, 200};
1066 static float ctm_scale[2] = {0.65, 0.65};
1067 static float ctm_skew[2] = {0, 0};
1068
1069 static bool enable = true;
1070 static float translation[2] = {100, 100};
1071 static float scale[2] = {0.8, 0.8};
1072 static float skew[2] = {0.2, 0.2};
1073
1074 static bool enable_savelayer = true;
1075
1076 if (IsPlaygroundEnabled()) {
1077 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1078 ImGui::Combo("Filter type", &selected_matrix_type, matrix_type_names,
1079 sizeof(matrix_type_names) / sizeof(char*));
1080
1081 ImGui::TextWrapped("Current Transform");
1082 ImGui::SliderFloat2("CTM Translation", ctm_translation, 0, 1000);
1083 ImGui::SliderFloat2("CTM Scale", ctm_scale, 0, 3);
1084 ImGui::SliderFloat2("CTM Skew", ctm_skew, -3, 3);
1085
1086 ImGui::TextWrapped(
1087 "MatrixFilter and LocalMatrixFilter modify the CTM in the same way. "
1088 "The only difference is that MatrixFilter doesn't affect the effect "
1089 "transform, whereas LocalMatrixFilter does.");
1090 // Note: See this behavior in:
1091 // https://fiddle.skia.org/c/6cbb551ab36d06f163db8693972be954
1092 ImGui::Checkbox("Enable", &enable);
1093 ImGui::SliderFloat2("Filter Translation", translation, 0, 1000);
1094 ImGui::SliderFloat2("Filter Scale", scale, 0, 3);
1095 ImGui::SliderFloat2("Filter Skew", skew, -3, 3);
1096
1097 ImGui::TextWrapped(
1098 "Rendering the filtered image within a layer can expose bounds "
1099 "issues. If the rendered image gets cut off when this setting is "
1100 "enabled, there's a coverage bug in the filter.");
1101 ImGui::Checkbox("Render in layer", &enable_savelayer);
1102 ImGui::End();
1103 }
1104
1106 flutter::DlPaint paint;
1107
1108 if (enable_savelayer) {
1109 builder.SaveLayer(std::nullopt, nullptr);
1110 }
1111 {
1112 auto content_scale = GetContentScale();
1113 builder.Scale(content_scale.x, content_scale.y);
1114
1115 // Set the current transform
1116 auto ctm_matrix = Matrix::MakeRow(
1117 ctm_scale[0], ctm_skew[0], 0.0f, ctm_translation[0], //
1118 ctm_skew[1], ctm_scale[1], 0.0f, ctm_translation[1], //
1119 0, 0, 1, 0, //
1120 0, 0, 0, 1);
1121 builder.Transform(ctm_matrix);
1122
1123 // Set the matrix filter
1124 auto filter_matrix =
1125 Matrix::MakeRow(scale[0], skew[0], 0.0f, translation[0], //
1126 skew[1], scale[1], 0.0f, translation[1], //
1127 0.0f, 0.0f, 1.0f, 0.0f, //
1128 0.0f, 0.0f, 0.0f, 1.0f);
1129
1130 if (enable) {
1131 switch (selected_matrix_type) {
1132 case 0: {
1133 auto filter = flutter::DlMatrixImageFilter(
1134 filter_matrix, flutter::DlImageSampling::kLinear);
1135 paint.setImageFilter(&filter);
1136 break;
1137 }
1138 case 1: {
1139 auto internal_filter =
1141 .shared();
1142 auto filter = flutter::DlLocalMatrixImageFilter(filter_matrix,
1143 internal_filter);
1144 paint.setImageFilter(&filter);
1145 break;
1146 }
1147 }
1148 }
1149
1150 builder.DrawImage(DlImageImpeller::Make(boston), DlPoint(),
1152 }
1153 if (enable_savelayer) {
1154 builder.Restore();
1155 }
1156
1157 return builder.Build();
1158 };
1159
1160 ASSERT_TRUE(OpenPlaygroundHere(callback));
1161}
std::shared_ptr< DlImageFilter > shared() const override

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawImage(), flutter::kDecal, flutter::kLinear, impeller::DlImageImpeller::Make(), impeller::Matrix::MakeRow(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setImageFilter(), flutter::DlBlurImageFilter::shared(), and flutter::DisplayListBuilder::Transform().

◆ TEST_P() [450/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawWithMatrixFilterWhenSavingLayer   
)

Definition at line 1163 of file dl_unittests.cc.

1163 {
1164 auto callback = [&]() {
1165 static float translation[2] = {0, 0};
1166 static bool enable_save_layer = true;
1167
1168 if (IsPlaygroundEnabled()) {
1169 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1170 ImGui::SliderFloat2("Translation", translation, -130, 130);
1171 ImGui::Checkbox("Enable save layer", &enable_save_layer);
1172 ImGui::End();
1173 }
1174
1176 builder.Save();
1177 builder.Scale(2.0, 2.0);
1178 flutter::DlPaint paint;
1180 builder.DrawRect(DlRect::MakeWH(300, 300), paint);
1181 paint.setStrokeWidth(1.0);
1183 paint.setColor(flutter::DlColor::kBlack().withAlpha(0x80));
1184 builder.DrawLine(DlPoint(150, 0), DlPoint(150, 300), paint);
1185 builder.DrawLine(DlPoint(0, 150), DlPoint(300, 150), paint);
1186
1187 flutter::DlPaint save_paint;
1188 DlRect bounds = DlRect::MakeXYWH(100, 100, 100, 100);
1189 Matrix translate_matrix =
1190 Matrix::MakeTranslation({translation[0], translation[1]});
1191 if (enable_save_layer) {
1192 auto filter = flutter::DlMatrixImageFilter(
1194 save_paint.setImageFilter(filter.shared());
1195 builder.SaveLayer(bounds, &save_paint);
1196 } else {
1197 builder.Save();
1198 builder.Transform(translate_matrix);
1199 }
1200
1201 Matrix filter_matrix;
1202 filter_matrix.Translate({150, 150});
1203 filter_matrix.Scale({0.2f, 0.2f});
1204 filter_matrix.Translate({-150, -150});
1205 auto filter = flutter::DlMatrixImageFilter(
1207
1208 save_paint.setImageFilter(filter.shared());
1209
1210 builder.SaveLayer(bounds, &save_paint);
1211 flutter::DlPaint paint2;
1213 builder.DrawRect(bounds, paint2);
1214 builder.Restore();
1215 builder.Restore();
1216 return builder.Build();
1217 };
1218
1219 ASSERT_TRUE(OpenPlaygroundHere(callback));
1220}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawLine(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlack(), flutter::DlColor::kBlue(), flutter::kNearestNeighbor, flutter::kStroke, flutter::DlColor::kYellow(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeWH(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::SaveLayer(), impeller::Matrix::Scale(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setImageFilter(), flutter::DlPaint::setStrokeWidth(), flutter::DisplayListBuilder::Transform(), and impeller::Matrix::Translate().

◆ TEST_P() [451/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawWithOddPathWinding   
)

Definition at line 404 of file dl_unittests.cc.

404 {
406 flutter::DlPaint paint;
407
410
411 builder.Translate(300, 300);
412 flutter::DlPathBuilder path_builder;
413 path_builder.AddCircle(DlPoint(0, 0), 100);
414 path_builder.AddCircle(DlPoint(0, 0), 50);
415 path_builder.SetFillType(flutter::DlPathFillType::kOdd);
416 builder.DrawPath(path_builder.TakePath(), paint);
417
418 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
419}
DlPathBuilder & AddCircle(DlPoint center, DlScalar radius)
Append a closed circular contour to the path centered on the provided point at the provided radius.

References flutter::DlPathBuilder::AddCircle(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::kFill, flutter::DlColor::kRed(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPathBuilder::SetFillType(), flutter::DlPathBuilder::TakePath(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [452/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawZeroLengthLine   
)

◆ TEST_P() [453/662]

impeller::testing::TEST_P ( DisplayListTest  ,
CanDrawZeroWidthLine   
)

Definition at line 1024 of file dl_unittests.cc.

1024 {
1026 std::vector<flutter::DlStrokeCap> caps = {
1030 };
1031 flutter::DlPaint paint = //
1032 flutter::DlPaint() //
1035 .setStrokeWidth(0);
1036 flutter::DlPaint outline_paint = //
1037 flutter::DlPaint() //
1041 .setStrokeWidth(1);
1042 DlPath path = DlPath::MakeLine({150, 50}, {160, 50});
1043 for (auto cap : caps) {
1044 paint.setStrokeCap(cap);
1045 builder.DrawLine(DlPoint(50, 50), DlPoint(60, 50), paint);
1046 builder.DrawRect(DlRect::MakeLTRB(45, 45, 65, 55), outline_paint);
1047 builder.DrawLine(DlPoint{100, 50}, DlPoint{100, 50}, paint);
1048 if (cap != flutter::DlStrokeCap::kButt) {
1049 builder.DrawRect(DlRect::MakeLTRB(95, 45, 105, 55), outline_paint);
1050 }
1051 builder.DrawPath(path, paint);
1052 builder.DrawRect(path.GetBounds().Expand(5, 5), outline_paint);
1053 builder.Translate(0, 150);
1054 }
1055 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1056}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawLine(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::kButt, flutter::kRound, flutter::kSquare, flutter::kStroke, flutter::DlColor::kWhite(), flutter::DlColor::kYellow(), flutter::DlPath::MakeLine(), impeller::TRect< Scalar >::MakeLTRB(), flutter::path, flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeWidth(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [454/662]

impeller::testing::TEST_P ( DisplayListTest  ,
ClipDrawRRectWithNonCircularRadii   
)

Definition at line 1502 of file dl_unittests.cc.

1502 {
1504
1505 flutter::DlPaint fill_paint = //
1506 flutter::DlPaint() //
1509 .setStrokeWidth(10);
1510 flutter::DlPaint stroke_paint = //
1511 flutter::DlPaint() //
1514 .setStrokeWidth(10);
1515
1516 builder.DrawRoundRect(
1517 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(500, 100, 300, 300), 120, 40),
1518 fill_paint);
1519 builder.DrawRoundRect(
1520 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(500, 100, 300, 300), 120, 40),
1521 stroke_paint);
1522
1523 builder.DrawRoundRect(
1524 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(100, 500, 300, 300), 40, 120),
1525 fill_paint);
1526 builder.DrawRoundRect(
1527 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(100, 500, 300, 300), 40, 120),
1528 stroke_paint);
1529
1530 flutter::DlPaint reference_paint = //
1531 flutter::DlPaint() //
1534 .setStrokeWidth(10);
1535
1536 builder.DrawRoundRect(
1537 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(500, 500, 300, 300), 40, 40),
1538 reference_paint);
1539 builder.DrawRoundRect(
1540 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(100, 100, 300, 300), 120, 120),
1541 reference_paint);
1542
1543 flutter::DlPaint clip_fill_paint = //
1544 flutter::DlPaint() //
1547 .setStrokeWidth(10);
1548
1549 builder.Save();
1550 builder.ClipRoundRect(
1551 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(900, 100, 300, 300), 120, 40));
1552 builder.DrawPaint(clip_fill_paint);
1553 builder.Restore();
1554
1555 builder.Save();
1556 builder.ClipRoundRect(
1557 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(100, 900, 300, 300), 40, 120));
1558 builder.DrawPaint(clip_fill_paint);
1559 builder.Restore();
1560
1561 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1562}
static constexpr DlColor kMidGrey()
Definition dl_color.h:78

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::ClipRoundRect(), flutter::DisplayListBuilder::DrawPaint(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kBlue(), flutter::DlColor::kCyan(), flutter::kFill, flutter::DlColor::kGreen(), flutter::DlColor::kMidGrey(), flutter::kStroke, impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [455/662]

impeller::testing::TEST_P ( DisplayListTest  ,
DrawCirclesWithTransformations   
)

Definition at line 1455 of file dl_unittests.cc.

1455 {
1456 auto callback = [&]() {
1457 static float filled_radius = 100.0;
1458 static float filled_alpha = 255.0;
1459 static float filled_scale[2] = {1.0, 1.0};
1460 static float stroked_radius = 20.0;
1461 static float stroke_width = 10.0;
1462 static float stroke_width_fine = 0.0;
1463 static float stroked_alpha = 255.0;
1464 static float stroked_scale[2] = {1.0, 1.0};
1465
1466 if (IsPlaygroundEnabled()) {
1467 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1468 ImGui::SliderFloat("Filled Radius", &filled_radius, 0, 500);
1469 ImGui::SliderFloat("Filled Alpha", &filled_alpha, 0, 255);
1470 ImGui::SliderFloat2("Filled Scale", filled_scale, 0, 10.0);
1471 ImGui::SliderFloat("Stroked Radius", &stroked_radius, 0, 500);
1472 ImGui::SliderFloat("Stroked Width", &stroke_width, 0, 500);
1473 ImGui::SliderFloat("Stroked Width Fine", &stroke_width_fine, 0, 5);
1474 ImGui::SliderFloat("Stroked Alpha", &stroked_alpha, 0, 10.0);
1475 ImGui::SliderFloat2("Stroked Scale", stroked_scale, 0, 10.0);
1476 ImGui::End();
1477 }
1478
1480 flutter::DlPaint paint;
1481
1482 paint.setColor(flutter::DlColor::kBlue().withAlpha(filled_alpha));
1484 builder.Save();
1485 builder.Scale(filled_scale[0], filled_scale[1]);
1486 builder.DrawCircle(DlPoint(500, 750), filled_radius, paint);
1487 builder.Restore();
1488
1489 paint.setColor(flutter::DlColor::kRed().withAlpha(stroked_alpha));
1491 paint.setStrokeWidth(stroke_width + stroke_width_fine);
1492 builder.Save();
1493 builder.Scale(stroked_scale[0], stroked_scale[1]);
1494 builder.DrawCircle(DlPoint(1250, 750), stroked_radius, paint);
1495 builder.Restore();
1496 return builder.Build();
1497 };
1498
1499 ASSERT_TRUE(OpenPlaygroundHere(callback));
1500}

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawCircle(), flutter::DlColor::kBlue(), flutter::kFill, flutter::DlColor::kRed(), flutter::kStroke, flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and flutter::DlPaint::setStrokeWidth().

◆ TEST_P() [456/662]

impeller::testing::TEST_P ( DisplayListTest  ,
DrawMaskBlursThatMightUseSaveLayers   
)

Definition at line 1678 of file dl_unittests.cc.

1678 {
1680 builder.DrawColor(flutter::DlColor::kWhite(), flutter::DlBlendMode::kSrc);
1681 Vector2 scale = GetContentScale();
1682 builder.Scale(scale.x, scale.y);
1683
1684 builder.Save();
1685 // We need a small transform op to avoid a deferred save
1686 builder.Translate(1.0f, 1.0f);
1687 auto solid_filter =
1689 flutter::DlPaint solid_alpha_paint =
1690 flutter::DlPaint() //
1691 .setMaskFilter(solid_filter) //
1693 .setAlpha(0x7f);
1694 for (int x = 1; x <= 4; x++) {
1695 for (int y = 1; y <= 4; y++) {
1696 builder.DrawRect(DlRect::MakeXYWH(x * 100, y * 100, 80, 80),
1697 solid_alpha_paint);
1698 }
1699 }
1700 builder.Restore();
1701
1702 builder.Save();
1703 builder.Translate(500.0f, 0.0f);
1704 auto normal_filter =
1706 auto rotate_if = flutter::DlMatrixImageFilter::Make(
1707 Matrix::MakeRotationZ(Degrees(10)), flutter::DlImageSampling::kLinear);
1708 flutter::DlPaint normal_if_paint =
1709 flutter::DlPaint() //
1710 .setMaskFilter(solid_filter) //
1711 .setImageFilter(rotate_if) //
1713 .setAlpha(0x7f);
1714 for (int x = 1; x <= 4; x++) {
1715 for (int y = 1; y <= 4; y++) {
1716 builder.DrawRect(DlRect::MakeXYWH(x * 100, y * 100, 80, 80),
1717 normal_if_paint);
1718 }
1719 }
1720 builder.Restore();
1721
1722 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1723}
static std::shared_ptr< DlImageFilter > Make(const DlMatrix &matrix, DlImageSampling sampling)

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawColor(), flutter::DisplayListBuilder::DrawRect(), flutter::DlColor::kBlue(), flutter::DlColor::kGreen(), flutter::kLinear, flutter::kNormal, flutter::kSolid, flutter::DlColor::kWhite(), flutter::DlMatrixImageFilter::Make(), flutter::DlBlurMaskFilter::Make(), impeller::Matrix::MakeRotationZ(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setAlpha(), flutter::DlPaint::setColor(), flutter::DlPaint::setImageFilter(), flutter::DlPaint::setMaskFilter(), flutter::DisplayListBuilder::Translate(), x, impeller::TPoint< T >::x, impeller::TPoint< T >::y, and y.

◆ TEST_P() [457/662]

impeller::testing::TEST_P ( DisplayListTest  ,
DrawPaintIgnoresMaskFilter   
)

Definition at line 1655 of file dl_unittests.cc.

1655 {
1658
1660 builder.DrawCircle(DlPoint(300, 300), 200,
1661 flutter::DlPaint().setMaskFilter(&filter));
1662
1663 std::vector<flutter::DlColor> colors = {flutter::DlColor::kGreen(),
1665 const float stops[2] = {0.0, 1.0};
1667 {100.0, 100.0}, {300.0, 300.0}, 2, colors.data(), stops,
1669 flutter::DlPaint blend_paint =
1670 flutter::DlPaint() //
1671 .setColorSource(linear) //
1672 .setBlendMode(flutter::DlBlendMode::kScreen);
1673 builder.DrawPaint(blend_paint);
1674
1675 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1676}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawPaint(), flutter::DlColor::kGreen(), flutter::kNormal, flutter::kRepeat, flutter::DlColor::kWhite(), flutter::DlColorSource::MakeLinear(), flutter::DlPaint::setBlendMode(), and flutter::DlPaint::setColorSource().

◆ TEST_P() [458/662]

impeller::testing::TEST_P ( DisplayListTest  ,
DrawShapes   
)

Definition at line 1416 of file dl_unittests.cc.

1416 {
1418 std::vector<flutter::DlStrokeJoin> joins = {
1422 };
1423 flutter::DlPaint paint = //
1424 flutter::DlPaint() //
1427 .setStrokeWidth(10);
1428 flutter::DlPaint stroke_paint = //
1429 flutter::DlPaint() //
1432 .setStrokeWidth(10);
1433 DlPath path = DlPath::MakeLine({150, 50}, {160, 50});
1434
1435 builder.Translate(300, 50);
1436 builder.Scale(0.8, 0.8);
1437 for (auto join : joins) {
1438 paint.setStrokeJoin(join);
1439 stroke_paint.setStrokeJoin(join);
1440 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), paint);
1441 builder.DrawRect(DlRect::MakeXYWH(0, 150, 100, 100), stroke_paint);
1442 builder.DrawRoundRect(
1443 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(150, 0, 100, 100), 30, 30),
1444 paint);
1445 builder.DrawRoundRect(
1446 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(150, 150, 100, 100), 30, 30),
1447 stroke_paint);
1448 builder.DrawCircle(DlPoint(350, 50), 50, paint);
1449 builder.DrawCircle(DlPoint(350, 200), 50, stroke_paint);
1450 builder.Translate(0, 300);
1451 }
1452 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1453}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawCircle(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::kBevel, flutter::kFill, flutter::kMiter, flutter::kRound, flutter::kStroke, flutter::DlColor::kWhite(), flutter::DlPath::MakeLine(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeXYWH(), flutter::path, flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [459/662]

impeller::testing::TEST_P ( DisplayListTest  ,
DrawVerticesBlendModes   
)

Definition at line 1564 of file dl_unittests.cc.

1564 {
1565 std::vector<const char*> blend_mode_names;
1566 std::vector<flutter::DlBlendMode> blend_mode_values;
1567 {
1568 const std::vector<std::tuple<const char*, flutter::DlBlendMode>> blends = {
1569 // Pipeline blends (Porter-Duff alpha compositing)
1570 {"Clear", flutter::DlBlendMode::kClear},
1571 {"Source", flutter::DlBlendMode::kSrc},
1572 {"Destination", flutter::DlBlendMode::kDst},
1573 {"SourceOver", flutter::DlBlendMode::kSrcOver},
1574 {"DestinationOver", flutter::DlBlendMode::kDstOver},
1575 {"SourceIn", flutter::DlBlendMode::kSrcIn},
1576 {"DestinationIn", flutter::DlBlendMode::kDstIn},
1577 {"SourceOut", flutter::DlBlendMode::kSrcOut},
1578 {"DestinationOut", flutter::DlBlendMode::kDstOut},
1579 {"SourceATop", flutter::DlBlendMode::kSrcATop},
1580 {"DestinationATop", flutter::DlBlendMode::kDstATop},
1581 {"Xor", flutter::DlBlendMode::kXor},
1582 {"Plus", flutter::DlBlendMode::kPlus},
1583 {"Modulate", flutter::DlBlendMode::kModulate},
1584 // Advanced blends (color component blends)
1585 {"Screen", flutter::DlBlendMode::kScreen},
1586 {"Overlay", flutter::DlBlendMode::kOverlay},
1587 {"Darken", flutter::DlBlendMode::kDarken},
1588 {"Lighten", flutter::DlBlendMode::kLighten},
1589 {"ColorDodge", flutter::DlBlendMode::kColorDodge},
1590 {"ColorBurn", flutter::DlBlendMode::kColorBurn},
1591 {"HardLight", flutter::DlBlendMode::kHardLight},
1592 {"SoftLight", flutter::DlBlendMode::kSoftLight},
1593 {"Difference", flutter::DlBlendMode::kDifference},
1594 {"Exclusion", flutter::DlBlendMode::kExclusion},
1595 {"Multiply", flutter::DlBlendMode::kMultiply},
1596 {"Hue", flutter::DlBlendMode::kHue},
1597 {"Saturation", flutter::DlBlendMode::kSaturation},
1598 {"Color", flutter::DlBlendMode::kColor},
1599 {"Luminosity", flutter::DlBlendMode::kLuminosity},
1600 };
1601 assert(blends.size() ==
1602 static_cast<size_t>(flutter::DlBlendMode::kLastMode) + 1);
1603 for (const auto& [name, mode] : blends) {
1604 blend_mode_names.push_back(name);
1605 blend_mode_values.push_back(mode);
1606 }
1607 }
1608
1609 auto callback = [&]() {
1610 static int current_blend_index = 3;
1611 static float dst_alpha = 1;
1612 static float src_alpha = 1;
1613 static float color0[4] = {1.0f, 0.0f, 0.0f, 1.0f};
1614 static float color1[4] = {0.0f, 1.0f, 0.0f, 1.0f};
1615 static float color2[4] = {0.0f, 0.0f, 1.0f, 1.0f};
1616 static float src_color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
1617
1618 if (IsPlaygroundEnabled()) {
1619 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1620 ImGui::ListBox("Blending mode", &current_blend_index,
1621 blend_mode_names.data(), blend_mode_names.size());
1622 ImGui::SliderFloat("Source alpha", &src_alpha, 0, 1);
1623 ImGui::ColorEdit4("Color A", color0);
1624 ImGui::ColorEdit4("Color B", color1);
1625 ImGui::ColorEdit4("Color C", color2);
1626 ImGui::ColorEdit4("Source Color", src_color);
1627 ImGui::SliderFloat("Destination alpha", &dst_alpha, 0, 1);
1628 ImGui::End();
1629 }
1630
1631 std::vector<DlPoint> positions = {DlPoint(100, 300), //
1632 DlPoint(200, 100), //
1633 DlPoint(300, 300)};
1634 std::vector<flutter::DlColor> colors = {
1635 toColor(color0).modulateOpacity(dst_alpha),
1636 toColor(color1).modulateOpacity(dst_alpha),
1637 toColor(color2).modulateOpacity(dst_alpha)};
1638
1639 auto vertices = flutter::DlVertices::Make(
1640 flutter::DlVertexMode::kTriangles, 3, positions.data(),
1641 /*texture_coordinates=*/nullptr, colors.data());
1642
1644 flutter::DlPaint paint;
1645
1646 paint.setColor(toColor(src_color).modulateOpacity(src_alpha));
1647 builder.DrawVertices(vertices, blend_mode_values[current_blend_index],
1648 paint);
1649 return builder.Build();
1650 };
1651
1652 ASSERT_TRUE(OpenPlaygroundHere(callback));
1653}
flutter::DlColor toColor(const float *components)

References flutter::DisplayListBuilder::Build(), callback, flutter::DisplayListBuilder::DrawVertices(), flutter::kTriangles, flutter::DlVertices::Make(), flutter::mode, flutter::DlColor::modulateOpacity(), flutter::name, flutter::DlPaint::setColor(), and toColor().

◆ TEST_P() [460/662]

impeller::testing::TEST_P ( DisplayListTest  ,
IgnoreMaskFilterWhenSavingLayer   
)

Definition at line 526 of file dl_unittests.cc.

526 {
527 auto texture = CreateTextureForFixture("embarcadero.jpg");
530 flutter::DlPaint paint;
531 paint.setMaskFilter(&filter);
532 builder.SaveLayer(std::nullopt, &paint);
533 builder.DrawImage(DlImageImpeller::Make(texture), DlPoint(100, 100),
535 builder.Restore();
536 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
537}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImage(), flutter::kNearestNeighbor, flutter::kNormal, impeller::DlImageImpeller::Make(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::SaveLayer(), flutter::DlPaint::setMaskFilter(), and texture.

◆ TEST_P() [461/662]

impeller::testing::TEST_P ( DisplayListTest  ,
MaskBlursApplyCorrectlyToColorSources   
)

Definition at line 1368 of file dl_unittests.cc.

1368 {
1369 auto blur_filter = std::make_shared<flutter::DlBlurMaskFilter>(
1371
1373
1374 std::array<flutter::DlColor, 2> colors = {flutter::DlColor::kBlue(),
1376 std::array<float, 2> stops = {0, 1};
1377 auto texture = CreateTextureForFixture("airplane.jpg");
1378 auto matrix = flutter::DlMatrix::MakeTranslation({-300, -110});
1379 std::array<std::shared_ptr<flutter::DlColorSource>, 2> color_sources = {
1381 DlImageImpeller::Make(texture), flutter::DlTileMode::kRepeat,
1383 &matrix),
1385 flutter::DlPoint(0, 0), flutter::DlPoint(100, 50), 2, colors.data(),
1386 stops.data(), flutter::DlTileMode::kClamp),
1387 };
1388
1389 builder.Save();
1390 builder.Translate(0, 100);
1391 for (const auto& color_source : color_sources) {
1392 flutter::DlPaint paint;
1393 paint.setColorSource(color_source);
1394 paint.setMaskFilter(blur_filter);
1395
1396 builder.Save();
1397 builder.Translate(100, 0);
1399 builder.DrawRoundRect(
1400 DlRoundRect::MakeRectXY(DlRect::MakeWH(100, 50), 30, 30), paint);
1401
1403 paint.setStrokeWidth(10);
1404 builder.Translate(200, 0);
1405 builder.DrawRoundRect(
1406 DlRoundRect::MakeRectXY(DlRect::MakeWH(100, 50), 30, 30), paint);
1407
1408 builder.Restore();
1409 builder.Translate(0, 100);
1410 }
1411 builder.Restore();
1412
1413 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1414}
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition matrix.h:95

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::DlColor::kBlue(), flutter::kClamp, flutter::kFill, flutter::DlColor::kGreen(), flutter::kLinear, flutter::kNormal, flutter::kRepeat, flutter::kStroke, impeller::DlImageImpeller::Make(), flutter::DlColorSource::MakeImage(), flutter::DlColorSource::MakeLinear(), impeller::RoundRect::MakeRectXY(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeWH(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DlPaint::setColorSource(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setMaskFilter(), flutter::DlPaint::setStrokeWidth(), texture, and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [462/662]

impeller::testing::TEST_P ( DisplayListTest  ,
NinePatchImageColorFilter   
)

Definition at line 902 of file dl_unittests.cc.

902 {
903 auto texture = CreateTextureForFixture("nine_patch2.png");
904
906 flutter::DlBlendMode::kSrcIn);
907 flutter::DlPaint paint;
908 paint.setColorFilter(filter);
909
911 builder.DrawImageNine(DlImageImpeller::Make(texture),
912 DlIRect::MakeXYWH(10, 10, 1, 1),
913 DlRect::MakeXYWH(0, 0, 200, 100),
915 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
916}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageNine(), flutter::DlColor::kGreen(), flutter::kNearest, impeller::DlImageImpeller::Make(), flutter::DlColorFilter::MakeBlend(), impeller::TRect< T >::MakeXYWH(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColorFilter(), and texture.

◆ TEST_P() [463/662]

impeller::testing::TEST_P ( DisplayListTest  ,
NinePatchImagePrecision   
)

Definition at line 890 of file dl_unittests.cc.

890 {
891 // Draw a nine patch image with colored corners and verify that the corner
892 // color does not leak outside the intended region.
893 auto texture = CreateTextureForFixture("nine_patch_corners.png");
895 builder.DrawImageNine(DlImageImpeller::Make(texture),
896 DlIRect::MakeXYWH(10, 10, 1, 1),
897 DlRect::MakeXYWH(0, 0, 200, 100),
899 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
900}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawImageNine(), flutter::kNearest, impeller::DlImageImpeller::Make(), impeller::TRect< T >::MakeXYWH(), impeller::TRect< Scalar >::MakeXYWH(), and texture.

◆ TEST_P() [464/662]

impeller::testing::TEST_P ( DisplayListTest  ,
StrokedPathsDrawCorrectly   
)

Definition at line 221 of file dl_unittests.cc.

221 {
222 auto callback = [&]() {
224 flutter::DlPaint paint;
225
228
229 static float stroke_width = 10.0f;
230 static int selected_stroke_type = 0;
231 static int selected_join_type = 0;
232 const char* stroke_types[] = {"Butte", "Round", "Square"};
233 const char* join_type[] = {"kMiter", "Round", "kBevel"};
234
235 if (IsPlaygroundEnabled()) {
236 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
237 ImGui::Combo("Cap", &selected_stroke_type, stroke_types,
238 sizeof(stroke_types) / sizeof(char*));
239 ImGui::Combo("Join", &selected_join_type, join_type,
240 sizeof(join_type) / sizeof(char*));
241 ImGui::SliderFloat("Stroke Width", &stroke_width, 10.0f, 50.0f);
242 ImGui::End();
243 }
244
247 switch (selected_stroke_type) {
248 case 0:
250 break;
251 case 1:
253 break;
254 case 2:
256 break;
257 default:
259 break;
260 }
261 switch (selected_join_type) {
262 case 0:
264 break;
265 case 1:
267 break;
268 case 2:
270 break;
271 default:
273 break;
274 }
275 paint.setStrokeCap(cap);
276 paint.setStrokeJoin(join);
277 paint.setStrokeWidth(stroke_width);
278
279 // Make rendering better to watch.
280 builder.Scale(1.5f, 1.5f);
281
282 // Rectangle
283 builder.Translate(100, 100);
284 builder.DrawRect(DlRect::MakeWH(100, 100), paint);
285
286 // Rounded rectangle
287 builder.Translate(150, 0);
288 builder.DrawRoundRect(
289 DlRoundRect::MakeRectXY(DlRect::MakeWH(100, 50), 10, 10), paint);
290
291 // Double rounded rectangle
292 builder.Translate(150, 0);
293 builder.DrawDiffRoundRect(
294 DlRoundRect::MakeRectXY(DlRect::MakeWH(100, 50), 10, 10),
295 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(10, 10, 80, 30), 10, 10),
296 paint);
297
298 // Contour with duplicate join points
299 {
300 builder.Translate(150, 0);
301 flutter::DlPathBuilder path_builder;
302 path_builder.MoveTo(DlPoint(0, 0));
303 path_builder.LineTo(DlPoint(0, 0));
304 path_builder.LineTo(DlPoint(100, 0));
305 path_builder.LineTo(DlPoint(100, 0));
306 path_builder.LineTo(DlPoint(100, 100));
307 builder.DrawPath(path_builder.TakePath(), paint);
308 }
309
310 // Contour with duplicate start and end points
311
312 // Line.
313 builder.Translate(200, 0);
314 {
315 builder.Save();
316
317 flutter::DlPathBuilder line_path_builder;
318 line_path_builder.MoveTo(DlPoint(0, 0));
319 line_path_builder.MoveTo(DlPoint(0, 0));
320 line_path_builder.LineTo(DlPoint(0, 0));
321 line_path_builder.LineTo(DlPoint(0, 0));
322 line_path_builder.LineTo(DlPoint(50, 50));
323 line_path_builder.LineTo(DlPoint(50, 50));
324 line_path_builder.LineTo(DlPoint(100, 0));
325 line_path_builder.LineTo(DlPoint(100, 0));
326 DlPath line_path = line_path_builder.TakePath();
327 builder.DrawPath(line_path, paint);
328
329 builder.Translate(0, 100);
330 builder.DrawPath(line_path, paint);
331
332 builder.Translate(0, 100);
333 flutter::DlPathBuilder line_path_builder2;
334 line_path_builder2.MoveTo(DlPoint(0, 0));
335 line_path_builder2.LineTo(DlPoint(0, 0));
336 line_path_builder2.LineTo(DlPoint(0, 0));
337 builder.DrawPath(line_path_builder2.TakePath(), paint);
338
339 builder.Restore();
340 }
341
342 // Cubic.
343 builder.Translate(150, 0);
344 {
345 builder.Save();
346
347 flutter::DlPathBuilder cubic_path;
348 cubic_path.MoveTo(DlPoint(0, 0));
349 cubic_path.CubicCurveTo(DlPoint(0, 0), //
350 DlPoint(140.0, 100.0), //
351 DlPoint(140, 20));
352 builder.DrawPath(cubic_path.TakePath(), paint);
353
354 builder.Translate(0, 100);
355 flutter::DlPathBuilder cubic_path2;
356 cubic_path2.MoveTo(DlPoint(0, 0));
357 cubic_path2.CubicCurveTo(DlPoint(0, 0), //
358 DlPoint(0, 0), //
359 DlPoint(150, 150));
360 builder.DrawPath(cubic_path2.TakePath(), paint);
361
362 builder.Translate(0, 100);
363 flutter::DlPathBuilder cubic_path3;
364 cubic_path3.MoveTo(DlPoint(0, 0));
365 cubic_path3.CubicCurveTo(DlPoint(0, 0), //
366 DlPoint(0, 0), //
367 DlPoint(0, 0));
368 builder.DrawPath(cubic_path3.TakePath(), paint);
369
370 builder.Restore();
371 }
372
373 // Quad.
374 builder.Translate(200, 0);
375 {
376 builder.Save();
377
378 flutter::DlPathBuilder quad_path;
379 quad_path.MoveTo(DlPoint(0, 0));
380 quad_path.MoveTo(DlPoint(0, 0));
381 quad_path.QuadraticCurveTo(DlPoint(100, 40), DlPoint(50, 80));
382 builder.DrawPath(quad_path.TakePath(), paint);
383
384 builder.Translate(0, 150);
385 flutter::DlPathBuilder quad_path2;
386 quad_path2.MoveTo(DlPoint(0, 0));
387 quad_path2.MoveTo(DlPoint(0, 0));
388 quad_path2.QuadraticCurveTo(DlPoint(0, 0), DlPoint(100, 100));
389 builder.DrawPath(quad_path2.TakePath(), paint);
390
391 builder.Translate(0, 100);
392 flutter::DlPathBuilder quad_path3;
393 quad_path3.MoveTo(DlPoint(0, 0));
394 quad_path3.QuadraticCurveTo(DlPoint(0, 0), DlPoint(0, 0));
395 builder.DrawPath(quad_path3.TakePath(), paint);
396
397 builder.Restore();
398 }
399 return builder.Build();
400 };
401 ASSERT_TRUE(OpenPlaygroundHere(callback));
402}

References flutter::DisplayListBuilder::Build(), callback, flutter::DlPathBuilder::CubicCurveTo(), flutter::DisplayListBuilder::DrawDiffRoundRect(), flutter::DisplayListBuilder::DrawPath(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawRoundRect(), flutter::kBevel, flutter::kButt, flutter::kMiter, flutter::DlColor::kRed(), flutter::kRound, flutter::kSquare, flutter::kStroke, flutter::DlPathBuilder::LineTo(), impeller::RoundRect::MakeRectXY(), impeller::TRect< Scalar >::MakeWH(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPathBuilder::MoveTo(), flutter::DlPathBuilder::QuadraticCurveTo(), flutter::DisplayListBuilder::Restore(), flutter::DisplayListBuilder::Save(), flutter::DisplayListBuilder::Scale(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), flutter::DlPaint::setStrokeCap(), flutter::DlPaint::setStrokeJoin(), flutter::DlPaint::setStrokeWidth(), flutter::DlPathBuilder::TakePath(), and flutter::DisplayListBuilder::Translate().

◆ TEST_P() [465/662]

impeller::testing::TEST_P ( DisplayListTest  ,
StrokedTextNotOffsetFromNormalText   
)

Definition at line 500 of file dl_unittests.cc.

500 {
502 flutter::DlPaint paint;
503 auto const& text_blob = SkTextBlob::MakeFromString("00000", CreateTestFont());
505
506 // https://api.flutter.dev/flutter/material/Colors/blue-constant.html.
507 auto const& mat_blue = flutter::DlColor(0xFF2196f3);
508
509 // Draw a blue filled rectangle so the text is easier to see.
511 paint.setColor(mat_blue);
512 builder.DrawRect(DlRect::MakeXYWH(0, 0, 500, 500), paint);
513
514 // Draw stacked text, with stroked text on top.
517 builder.DrawText(text, 250, 250, paint);
518
521 builder.DrawText(text, 250, 250, paint);
522
523 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
524}

References flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawRect(), flutter::DisplayListBuilder::DrawText(), flutter::DlColor::kBlack(), flutter::kFill, flutter::kStroke, flutter::DlColor::kWhite(), flutter::DlTextImpeller::MakeFromBlob(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPaint::setColor(), flutter::DlPaint::setDrawStyle(), and text.

◆ TEST_P() [466/662]

impeller::testing::TEST_P ( DriverInfoVKTest  ,
CanDumpToLog   
)

Definition at line 30 of file driver_info_vk_unittests.cc.

30 {
31 ASSERT_TRUE(GetContext());
32 const auto& driver_info =
33 SurfaceContextVK::Cast(*GetContext()).GetParent()->GetDriverInfo();
34 ASSERT_NE(driver_info, nullptr);
36 driver_info->DumpToLog();
37 EXPECT_TRUE(log.str().find("Driver Information") != std::string::npos);
38}
std::string str() const
Definition logging.cc:102

References impeller::BackendCast< SurfaceContextVK, Context >::Cast(), impeller::SurfaceContextVK::GetParent(), and fml::testing::LogCapture::str().

◆ TEST_P() [467/662]

impeller::testing::TEST_P ( DriverInfoVKTest  ,
CanQueryDriverInfo   
)

Definition at line 17 of file driver_info_vk_unittests.cc.

17 {
18 ASSERT_TRUE(GetContext());
19 const auto& driver_info =
20 SurfaceContextVK::Cast(*GetContext()).GetParent()->GetDriverInfo();
21 ASSERT_NE(driver_info, nullptr);
22 // 1.1 is the base Impeller version. The driver can't be lower than that.
23 ASSERT_TRUE(driver_info->GetAPIVersion().IsAtLeast(Version{1, 1, 0}));
24 ASSERT_NE(driver_info->GetVendor(), VendorVK::kUnknown);
25 ASSERT_NE(driver_info->GetDeviceType(), DeviceTypeVK::kUnknown);
26 ASSERT_NE(driver_info->GetDriverName(), "");
27 EXPECT_FALSE(driver_info->IsKnownBadDriver());
28}

References impeller::BackendCast< SurfaceContextVK, Context >::Cast(), impeller::SurfaceContextVK::GetParent(), and impeller::kUnknown.

◆ TEST_P() [468/662]

impeller::testing::TEST_P ( EntityPassTargetTest  ,
SwapWithMSAAImplicitResolve   
)

Definition at line 46 of file entity_pass_target_unittests.cc.

46 {
47 ContentContext& content_context = GetContentContext();
48 auto buffer = content_context.GetContext()->CreateCommandBuffer();
49 auto context = content_context.GetContext();
50 auto& allocator = *context->GetResourceAllocator();
51
52 // Emulate implicit MSAA resolve by making color resolve and msaa texture the
53 // same.
54 RenderTarget render_target;
55 {
56 PixelFormat pixel_format =
57 context->GetCapabilities()->GetDefaultColorFormat();
58
59 // Create MSAA color texture.
60
61 TextureDescriptor color0_tex_desc;
62 color0_tex_desc.storage_mode = StorageMode::kDevicePrivate;
63 color0_tex_desc.type = TextureType::kTexture2DMultisample;
64 color0_tex_desc.sample_count = SampleCount::kCount4;
65 color0_tex_desc.format = pixel_format;
66 color0_tex_desc.size = ISize{100, 100};
67 color0_tex_desc.usage = TextureUsage::kRenderTarget;
68
69 auto color0_msaa_tex = allocator.CreateTexture(color0_tex_desc);
70
71 // Color attachment.
72
73 ColorAttachment color0;
74 color0.load_action = LoadAction::kDontCare;
75 color0.store_action = StoreAction::kStoreAndMultisampleResolve;
76 color0.texture = color0_msaa_tex;
77 color0.resolve_texture = color0_msaa_tex;
78
79 render_target.SetColorAttachment(color0, 0u);
80 render_target.SetStencilAttachment(std::nullopt);
81 }
82
83 auto entity_pass_target = EntityPassTarget(render_target, false, true);
84
85 auto color0 = entity_pass_target.GetRenderTarget().GetColorAttachment(0);
86 auto msaa_tex = color0.texture;
87 auto resolve_tex = color0.resolve_texture;
88
89 ASSERT_EQ(msaa_tex, resolve_tex);
90
91 entity_pass_target.Flip(content_context);
92
93 color0 = entity_pass_target.GetRenderTarget().GetColorAttachment(0);
94
95 ASSERT_NE(msaa_tex, color0.texture);
96 ASSERT_NE(resolve_tex, color0.resolve_texture);
97 ASSERT_EQ(color0.texture, color0.resolve_texture);
98}
std::shared_ptr< Context > GetContext() const
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)

References allocator, flutter::buffer, context, impeller::TextureDescriptor::format, impeller::ContentContext::GetContext(), impeller::kCount4, impeller::kDevicePrivate, impeller::kDontCare, impeller::kRenderTarget, impeller::kStoreAndMultisampleResolve, impeller::kTexture2DMultisample, impeller::Attachment::load_action, impeller::Attachment::resolve_texture, impeller::TextureDescriptor::sample_count, impeller::RenderTarget::SetColorAttachment(), impeller::RenderTarget::SetStencilAttachment(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::Attachment::store_action, impeller::Attachment::texture, impeller::TextureDescriptor::type, and impeller::TextureDescriptor::usage.

◆ TEST_P() [469/662]

impeller::testing::TEST_P ( EntityPassTargetTest  ,
SwapWithMSAATexture   
)

Definition at line 19 of file entity_pass_target_unittests.cc.

19 {
20 if (GetContentContext()
21 .GetDeviceCapabilities()
22 .SupportsImplicitResolvingMSAA()) {
23 GTEST_SKIP() << "Implicit MSAA is used on this device.";
24 }
25 ContentContext& content_context = GetContentContext();
26 auto buffer = content_context.GetContext()->CreateCommandBuffer();
27 auto render_target =
28 GetContentContext().GetRenderTargetCache()->CreateOffscreenMSAA(
29 *content_context.GetContext(), {100, 100},
30 /*mip_count=*/1);
31
32 auto entity_pass_target = EntityPassTarget(render_target, false, false);
33
34 auto color0 = entity_pass_target.GetRenderTarget().GetColorAttachment(0);
35 auto msaa_tex = color0.texture;
36 auto resolve_tex = color0.resolve_texture;
37
38 entity_pass_target.Flip(content_context);
39
40 color0 = entity_pass_target.GetRenderTarget().GetColorAttachment(0);
41
42 ASSERT_EQ(msaa_tex, color0.texture);
43 ASSERT_NE(resolve_tex, color0.resolve_texture);
44}

References flutter::buffer, and impeller::ContentContext::GetContext().

◆ TEST_P() [470/662]

impeller::testing::TEST_P ( EntityTest  ,
BezierCircleScaled   
)

Definition at line 873 of file entity_unittests.cc.

873 {
874 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
875 static float scale = 20;
876
877 if (IsPlaygroundEnabled()) {
878 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
879 ImGui::SliderFloat("Scale", &scale, 1, 100);
880 ImGui::End();
881 }
882
883 Entity entity;
884 entity.SetTransform(Matrix::MakeScale(GetContentScale()));
885 auto path = flutter::DlPathBuilder{}
886 .MoveTo({97.325, 34.818})
887 .CubicCurveTo({98.50862885295136, 34.81812293973836},
888 {99.46822048142015, 33.85863261475589},
889 {99.46822048142015, 32.67499810206613})
890 .CubicCurveTo({99.46822048142015, 31.491363589376355},
891 {98.50862885295136, 30.53187326439389},
892 {97.32499434685802, 30.531998226542708})
893 .CubicCurveTo({96.14153655073771, 30.532123170035373},
894 {95.18222070648729, 31.491540299350355},
895 {95.18222070648729, 32.67499810206613})
896 .CubicCurveTo({95.18222070648729, 33.85845590478189},
897 {96.14153655073771, 34.81787303409686},
898 {97.32499434685802, 34.81799797758954})
899 .Close()
900 .TakePath();
901 entity.SetTransform(
902 Matrix::MakeScale({scale, scale, 1.0}).Translate({-90, -20, 0}));
903
904 std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
905
906 auto contents = std::make_shared<SolidColorContents>(geom.get());
907 contents->SetColor(Color::Red());
908
909 entity.SetContents(contents);
910 return entity.Render(context, pass);
911 };
912 ASSERT_TRUE(OpenPlaygroundHere(callback));
913}
void SetContents(std::shared_ptr< Contents > contents)
Definition entity.cc:74
bool Render(const ContentContext &renderer, RenderPass &parent_pass) const
Definition entity.cc:145

References callback, impeller::Close(), context, impeller::Geometry::MakeFillPath(), impeller::Matrix::MakeScale(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), and flutter::DlPathBuilder::TakePath().

◆ TEST_P() [471/662]

impeller::testing::TEST_P ( EntityTest  ,
BlendingModeOptions   
)

Definition at line 739 of file entity_unittests.cc.

739 {
740 std::vector<const char*> blend_mode_names;
741 std::vector<BlendMode> blend_mode_values;
742 {
743 // Force an exhausiveness check with a switch. When adding blend modes,
744 // update this switch with a new name/value to make it selectable in the
745 // test GUI.
746
747 const BlendMode b{};
748 static_assert(b == BlendMode::kClear); // Ensure the first item in
749 // the switch is the first
750 // item in the enum.
751 static_assert(Entity::kLastPipelineBlendMode == BlendMode::kModulate);
752 switch (b) {
753 case BlendMode::kClear:
754 blend_mode_names.push_back("Clear");
755 blend_mode_values.push_back(BlendMode::kClear);
756 case BlendMode::kSrc:
757 blend_mode_names.push_back("Source");
758 blend_mode_values.push_back(BlendMode::kSrc);
759 case BlendMode::kDst:
760 blend_mode_names.push_back("Destination");
761 blend_mode_values.push_back(BlendMode::kDst);
762 case BlendMode::kSrcOver:
763 blend_mode_names.push_back("SourceOver");
764 blend_mode_values.push_back(BlendMode::kSrcOver);
765 case BlendMode::kDstOver:
766 blend_mode_names.push_back("DestinationOver");
767 blend_mode_values.push_back(BlendMode::kDstOver);
768 case BlendMode::kSrcIn:
769 blend_mode_names.push_back("SourceIn");
770 blend_mode_values.push_back(BlendMode::kSrcIn);
771 case BlendMode::kDstIn:
772 blend_mode_names.push_back("DestinationIn");
773 blend_mode_values.push_back(BlendMode::kDstIn);
774 case BlendMode::kSrcOut:
775 blend_mode_names.push_back("SourceOut");
776 blend_mode_values.push_back(BlendMode::kSrcOut);
777 case BlendMode::kDstOut:
778 blend_mode_names.push_back("DestinationOut");
779 blend_mode_values.push_back(BlendMode::kDstOut);
780 case BlendMode::kSrcATop:
781 blend_mode_names.push_back("SourceATop");
782 blend_mode_values.push_back(BlendMode::kSrcATop);
783 case BlendMode::kDstATop:
784 blend_mode_names.push_back("DestinationATop");
785 blend_mode_values.push_back(BlendMode::kDstATop);
786 case BlendMode::kXor:
787 blend_mode_names.push_back("Xor");
788 blend_mode_values.push_back(BlendMode::kXor);
789 case BlendMode::kPlus:
790 blend_mode_names.push_back("Plus");
791 blend_mode_values.push_back(BlendMode::kPlus);
792 case BlendMode::kModulate:
793 blend_mode_names.push_back("Modulate");
794 blend_mode_values.push_back(BlendMode::kModulate);
795 };
796 }
797
798 auto callback = [&](ContentContext& context, RenderPass& pass) {
799 auto world_matrix = Matrix::MakeScale(GetContentScale());
800 auto draw_rect = [&context, &pass, &world_matrix](
801 Rect rect, Color color, BlendMode blend_mode) -> bool {
802 using VS = SolidFillPipeline::VertexShader;
803 using FS = SolidFillPipeline::FragmentShader;
804
805 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
806 {
807 auto r = rect.GetLTRB();
808 vtx_builder.AddVertices({
809 {Point(r[0], r[1])},
810 {Point(r[2], r[1])},
811 {Point(r[2], r[3])},
812 {Point(r[0], r[1])},
813 {Point(r[2], r[3])},
814 {Point(r[0], r[3])},
815 });
816 }
817
818 pass.SetCommandLabel("Blended Rectangle");
819 auto options = OptionsFromPass(pass);
820 options.blend_mode = blend_mode;
821 options.primitive_type = PrimitiveType::kTriangle;
822 pass.SetPipeline(context.GetSolidFillPipeline(options));
823 pass.SetVertexBuffer(
824 vtx_builder.CreateVertexBuffer(context.GetTransientsDataBuffer(),
825 context.GetTransientsIndexesBuffer()));
826
827 VS::FrameInfo frame_info;
828 frame_info.mvp = pass.GetOrthographicTransform() * world_matrix;
829 VS::BindFrameInfo(
830 pass, context.GetTransientsDataBuffer().EmplaceUniform(frame_info));
831 FS::FragInfo frag_info;
832 frag_info.color = color.Premultiply();
833 FS::BindFragInfo(
834 pass, context.GetTransientsDataBuffer().EmplaceUniform(frag_info));
835 return pass.Draw().ok();
836 };
837
838 static Color color1(1, 0, 0, 0.5), color2(0, 1, 0, 0.5);
839 static int current_blend_index = 3;
840 if (IsPlaygroundEnabled()) {
841 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
842 ImGui::ColorEdit4("Color 1", reinterpret_cast<float*>(&color1));
843 ImGui::ColorEdit4("Color 2", reinterpret_cast<float*>(&color2));
844 ImGui::ListBox("Blending mode", &current_blend_index,
845 blend_mode_names.data(), blend_mode_names.size());
846 ImGui::End();
847 }
848
849 BlendMode selected_mode = blend_mode_values[current_blend_index];
850
851 Point a, b, c, d;
852 static PlaygroundPoint point_a(Point(400, 100), 20, Color::White());
853 static PlaygroundPoint point_b(Point(200, 300), 20, Color::White());
854 std::tie(a, b) = DrawPlaygroundLine(point_a, point_b);
855 static PlaygroundPoint point_c(Point(470, 190), 20, Color::White());
856 static PlaygroundPoint point_d(Point(270, 390), 20, Color::White());
857 std::tie(c, d) = DrawPlaygroundLine(point_c, point_d);
858
859 bool result = true;
860 result = result &&
861 draw_rect(Rect::MakeXYWH(0, 0, pass.GetRenderTargetSize().width,
862 pass.GetRenderTargetSize().height),
863 Color(), BlendMode::kClear);
864 result = result && draw_rect(Rect::MakeLTRB(a.x, a.y, b.x, b.y), color1,
865 BlendMode::kSrcOver);
866 result = result && draw_rect(Rect::MakeLTRB(c.x, c.y, d.x, d.y), color2,
867 selected_mode);
868 return result;
869 };
870 ASSERT_TRUE(OpenPlaygroundHere(callback));
871}
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition contents.cc:19

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), c, callback, context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), d, impeller::DrawPlaygroundLine(), impeller::kClear, impeller::kDst, impeller::kDstATop, impeller::kDstIn, impeller::kDstOut, impeller::kDstOver, impeller::Entity::kLastPipelineBlendMode, impeller::kModulate, impeller::kPlus, impeller::kSrc, impeller::kSrcATop, impeller::kSrcIn, impeller::kSrcOut, impeller::kSrcOver, impeller::kTriangle, impeller::kXor, impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeXYWH(), impeller::OptionsFromPass(), impeller::Color::White(), flutter::Point::x(), and flutter::Point::y().

◆ TEST_P() [472/662]

impeller::testing::TEST_P ( EntityTest  ,
BorderMaskBlurCoverageIsCorrect   
)

Definition at line 1370 of file entity_unittests.cc.

1370 {
1371 auto geom = Geometry::MakeFillPath(
1372 flutter::DlPath::MakeRect(Rect::MakeXYWH(0, 0, 300, 400)));
1373 auto fill = std::make_shared<SolidColorContents>(geom.get());
1374 fill->SetColor(Color::CornflowerBlue());
1375 auto border_mask_blur = FilterContents::MakeBorderMaskBlur(
1376 FilterInput::Make(fill), Radius{3}, Radius{4});
1377
1378 {
1379 Entity e;
1380 e.SetTransform(Matrix());
1381 auto actual = border_mask_blur->GetCoverage(e);
1382 auto expected = Rect::MakeXYWH(-3, -4, 306, 408);
1383 ASSERT_TRUE(actual.has_value());
1384 ASSERT_RECT_NEAR(actual.value(), expected);
1385 }
1386
1387 {
1388 Entity e;
1389 e.SetTransform(Matrix::MakeRotationZ(Radians{kPi / 4}));
1390 auto actual = border_mask_blur->GetCoverage(e);
1391 auto expected = Rect::MakeXYWH(-287.792, -4.94975, 504.874, 504.874);
1392 ASSERT_TRUE(actual.has_value());
1393 ASSERT_RECT_NEAR(actual.value(), expected);
1394 }
1395}

References ASSERT_RECT_NEAR, impeller::Color::CornflowerBlue(), flutter::kPi, impeller::FilterInput::Make(), impeller::FilterContents::MakeBorderMaskBlur(), impeller::Geometry::MakeFillPath(), flutter::DlPath::MakeRect(), impeller::Matrix::MakeRotationZ(), impeller::TRect< Scalar >::MakeXYWH(), and impeller::Entity::SetTransform().

◆ TEST_P() [473/662]

impeller::testing::TEST_P ( EntityTest  ,
CanComputeGeometryForEmptyPathsWithoutCrashing   
)

Definition at line 2467 of file entity_unittests.cc.

2467 {
2468 flutter::DlPath path = flutter::DlPath::MakeRect(Rect::MakeLTRB(0, 0, 0, 0));
2469
2470 EXPECT_TRUE(path.GetBounds().IsEmpty());
2471
2472 auto geom = Geometry::MakeFillPath(path);
2473
2474 Entity entity;
2476 GetContentContext().GetRenderTargetCache()->CreateOffscreen(*GetContext(),
2477 {1, 1}, 1u);
2479 auto position_result =
2480 geom->GetPositionBuffer(GetContentContext(), entity, render_pass);
2481
2482 EXPECT_EQ(position_result.vertex_buffer.vertex_count, 0u);
2483
2484 EXPECT_EQ(geom->GetResultMode(), GeometryResult::Mode::kNormal);
2485}

References impeller::GeometryResult::kNormal, impeller::Geometry::MakeFillPath(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRect(), flutter::path, render_pass, and target.

◆ TEST_P() [474/662]

impeller::testing::TEST_P ( EntityTest  ,
CanCreateEntity   
)

Definition at line 72 of file entity_unittests.cc.

72 {
73 Entity entity;
74 ASSERT_TRUE(entity.GetTransform().IsIdentity());
75}
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition entity.cc:46
constexpr bool IsIdentity() const
Definition matrix.h:475

References impeller::Entity::GetTransform(), and impeller::Matrix::IsIdentity().

◆ TEST_P() [475/662]

impeller::testing::TEST_P ( EntityTest  ,
CanDrawCorrectlyWithRotatedTransform   
)

Definition at line 391 of file entity_unittests.cc.

391 {
392 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
393 const char* input_axis[] = {"X", "Y", "Z"};
394 static int rotation_axis_index = 0;
395 static float rotation = 0;
396 if (IsPlaygroundEnabled()) {
397 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
398 ImGui::SliderFloat("Rotation", &rotation, -kPi, kPi);
399 ImGui::Combo("Rotation Axis", &rotation_axis_index, input_axis,
400 sizeof(input_axis) / sizeof(char*));
401 if (ImGui::Button("Reset")) {
402 rotation = 0;
403 }
404 ImGui::End();
405 }
406 Matrix rotation_matrix;
407 switch (rotation_axis_index) {
408 case 0:
409 rotation_matrix = Matrix::MakeRotationX(Radians(rotation));
410 break;
411 case 1:
412 rotation_matrix = Matrix::MakeRotationY(Radians(rotation));
413 break;
414 case 2:
415 rotation_matrix = Matrix::MakeRotationZ(Radians(rotation));
416 break;
417 default:
418 rotation_matrix = Matrix{};
419 break;
420 }
421
422 Matrix current_transform =
423 Matrix::MakeScale(GetContentScale())
424 .MakeTranslation(
425 Vector3(Point(pass.GetRenderTargetSize().width / 2.0,
426 pass.GetRenderTargetSize().height / 2.0)));
427 Matrix result_transform = current_transform * rotation_matrix;
429 flutter::DlPath::MakeRect(Rect::MakeXYWH(-300, -400, 600, 800));
430
431 Entity entity;
432 entity.SetTransform(result_transform);
433
434 std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
435
436 auto contents = std::make_shared<SolidColorContents>(geom.get());
437 contents->SetColor(Color::Red());
438
439 entity.SetContents(contents);
440 return entity.Render(context, pass);
441 };
442 ASSERT_TRUE(OpenPlaygroundHere(callback));
443}

References callback, context, flutter::kPi, impeller::Geometry::MakeFillPath(), flutter::DlPath::MakeRect(), impeller::Matrix::MakeRotationX(), impeller::Matrix::MakeRotationY(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), flutter::path, impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [476/662]

impeller::testing::TEST_P ( EntityTest  ,
CanDrawRoundSuperEllipseWithJustEnoughRadius   
)

Definition at line 2782 of file entity_unittests.cc.

2782 {
2783 // Regression test for https://github.com/flutter/flutter/issues/176894
2784 // Verify that a radius marginally above the minimum threshold can be
2785 // processed safely. The expectation is that the rounded corners are
2786 // drawn as rounded and that no NaNs or crashes occur.
2787 auto geom = Geometry::MakeRoundSuperellipse(
2788 Rect::MakeLTRB(200, 200, 300, 300), 1.1 * kEhCloseEnough);
2789
2790 ContentContext content_context(GetContext(), /*typographer_context=*/nullptr);
2791 Entity entity;
2792
2793 auto cmd_buffer = content_context.GetContext()->CreateCommandBuffer();
2794
2796 content_context.GetContext()->GetResourceAllocator());
2797
2798 auto render_target = allocator.CreateOffscreen(
2799 *content_context.GetContext(), /*size=*/{500, 500}, /*mip_count=*/1);
2800 auto pass = cmd_buffer->CreateRenderPass(render_target);
2801
2802 GeometryResult result =
2803 geom->GetPositionBuffer(content_context, entity, *pass);
2804
2805 EXPECT_EQ(result.vertex_buffer.vertex_count, 200u);
2806 Point* written_data = reinterpret_cast<Point*>(
2809
2810 std::vector<Point> expected_head = {Point(250.0, 200.0), Point(299.9, 200.0),
2811 Point(200.1, 200.0), Point(299.9, 200.0)};
2812
2813 for (size_t i = 0; i < expected_head.size(); i++) {
2814 const Point& point = written_data[i];
2815 EXPECT_NEAR(point.x, expected_head[i].x, 0.1);
2816 EXPECT_NEAR(point.y, expected_head[i].y, 0.1);
2817 }
2818}
VertexBuffer vertex_buffer
Definition geometry.h:38

References allocator, impeller::BufferView::GetBuffer(), impeller::ContentContext::GetContext(), impeller::BufferView::GetRange(), i, flutter::kEhCloseEnough, impeller::TRect< Scalar >::MakeLTRB(), impeller::Geometry::MakeRoundSuperellipse(), impeller::Range::offset, impeller::DeviceBuffer::OnGetContents(), impeller::VertexBuffer::vertex_buffer, impeller::GeometryResult::vertex_buffer, impeller::VertexBuffer::vertex_count, flutter::Point::x(), and flutter::Point::y().

◆ TEST_P() [477/662]

impeller::testing::TEST_P ( EntityTest  ,
CanDrawRoundSuperEllipseWithTinyRadius   
)

Definition at line 2744 of file entity_unittests.cc.

2744 {
2745 // Regression test for https://github.com/flutter/flutter/issues/176894
2746 // Verify that a radius marginally below the minimum threshold can be
2747 // processed safely. The expectation is that the rounded corners degenerate
2748 // into sharp corners (four corner points) and that no NaNs or crashes occur.
2749 auto geom = Geometry::MakeRoundSuperellipse(
2750 Rect::MakeLTRB(200, 200, 300, 300), 0.5 * kEhCloseEnough);
2751
2752 ContentContext content_context(GetContext(), /*typographer_context=*/nullptr);
2753 Entity entity;
2754
2755 auto cmd_buffer = content_context.GetContext()->CreateCommandBuffer();
2756
2758 content_context.GetContext()->GetResourceAllocator());
2759
2760 auto render_target = allocator.CreateOffscreen(
2761 *content_context.GetContext(), /*size=*/{500, 500}, /*mip_count=*/1);
2762 auto pass = cmd_buffer->CreateRenderPass(render_target);
2763
2764 GeometryResult result =
2765 geom->GetPositionBuffer(content_context, entity, *pass);
2766
2767 EXPECT_EQ(result.vertex_buffer.vertex_count, 4u);
2768 Point* written_data = reinterpret_cast<Point*>(
2771
2772 std::vector<Point> expected = {Point(300.0, 200.0), Point(300.0, 300.0),
2773 Point(200.0, 200.0), Point(200.0, 300.0)};
2774
2775 for (size_t i = 0; i < expected.size(); i++) {
2776 const Point& point = written_data[i];
2777 EXPECT_NEAR(point.x, expected[i].x, 0.1);
2778 EXPECT_NEAR(point.y, expected[i].y, 0.1);
2779 }
2780}

References allocator, impeller::BufferView::GetBuffer(), impeller::ContentContext::GetContext(), impeller::BufferView::GetRange(), i, flutter::kEhCloseEnough, impeller::TRect< Scalar >::MakeLTRB(), impeller::Geometry::MakeRoundSuperellipse(), impeller::Range::offset, impeller::DeviceBuffer::OnGetContents(), impeller::VertexBuffer::vertex_buffer, impeller::GeometryResult::vertex_buffer, impeller::VertexBuffer::vertex_count, flutter::Point::x(), and flutter::Point::y().

◆ TEST_P() [478/662]

impeller::testing::TEST_P ( EntityTest  ,
CanRenderEmptyPathsWithoutCrashing   
)

Definition at line 2487 of file entity_unittests.cc.

2487 {
2488 flutter::DlPath path = flutter::DlPath::MakeRect(Rect::MakeLTRB(0, 0, 0, 0));
2489
2490 EXPECT_TRUE(path.GetBounds().IsEmpty());
2491
2492 std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
2493 auto contents = std::make_shared<SolidColorContents>(geom.get());
2494 contents->SetColor(Color::Red());
2495
2496 Entity entity;
2497 entity.SetTransform(Matrix::MakeScale(GetContentScale()));
2498 entity.SetContents(contents);
2499
2500 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
2501}

References impeller::Geometry::MakeFillPath(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRect(), impeller::Matrix::MakeScale(), flutter::path, impeller::Color::Red(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [479/662]

impeller::testing::TEST_P ( EntityTest  ,
ColorFilterContentsWithLargeGeometry   
)

Definition at line 2202 of file entity_unittests.cc.

2202 {
2203 Entity entity;
2204 entity.SetTransform(Matrix::MakeScale(GetContentScale()));
2205 auto src_geom = Geometry::MakeRect(Rect::MakeLTRB(-300, -500, 30000, 50000));
2206 auto src_contents = std::make_shared<SolidColorContents>(src_geom.get());
2207 src_contents->SetColor(Color::Red());
2208
2209 auto dst_geom = Geometry::MakeRect(Rect::MakeLTRB(300, 500, 20000, 30000));
2210 auto dst_contents = std::make_shared<SolidColorContents>(dst_geom.get());
2211 dst_contents->SetColor(Color::Blue());
2212
2213 auto contents = ColorFilterContents::MakeBlend(
2214 BlendMode::kSrcOver, {FilterInput::Make(dst_contents, false),
2215 FilterInput::Make(src_contents, false)});
2216 entity.SetContents(std::move(contents));
2217 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
2218}

References impeller::Color::Blue(), impeller::kSrcOver, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeBlend(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Geometry::MakeRect(), impeller::Matrix::MakeScale(), impeller::Color::Red(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [480/662]

impeller::testing::TEST_P ( EntityTest  ,
ColorFilterWithForegroundColorAdvancedBlend   
)

Definition at line 1969 of file entity_unittests.cc.

1969 {
1970 auto image = CreateTextureForFixture("boston.jpg");
1971 auto filter = ColorFilterContents::MakeBlend(
1972 BlendMode::kColorBurn, FilterInput::Make({image}), Color::Red());
1973
1974 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
1975 Entity entity;
1976 entity.SetTransform(Matrix::MakeScale(GetContentScale()) *
1977 Matrix::MakeTranslation({500, 300}) *
1978 Matrix::MakeScale(Vector2{0.5, 0.5}));
1979 entity.SetContents(filter);
1980 return entity.Render(context, pass);
1981 };
1982 ASSERT_TRUE(OpenPlaygroundHere(callback));
1983}

References callback, context, image, impeller::kColorBurn, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeBlend(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [481/662]

impeller::testing::TEST_P ( EntityTest  ,
ColorFilterWithForegroundColorClearBlend   
)

Definition at line 1985 of file entity_unittests.cc.

1985 {
1986 auto image = CreateTextureForFixture("boston.jpg");
1987 auto filter = ColorFilterContents::MakeBlend(
1988 BlendMode::kClear, FilterInput::Make({image}), Color::Red());
1989
1990 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
1991 Entity entity;
1992 entity.SetTransform(Matrix::MakeScale(GetContentScale()) *
1993 Matrix::MakeTranslation({500, 300}) *
1994 Matrix::MakeScale(Vector2{0.5, 0.5}));
1995 entity.SetContents(filter);
1996 return entity.Render(context, pass);
1997 };
1998 ASSERT_TRUE(OpenPlaygroundHere(callback));
1999}

References callback, context, image, impeller::kClear, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeBlend(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [482/662]

impeller::testing::TEST_P ( EntityTest  ,
ColorFilterWithForegroundColorDstBlend   
)

Definition at line 2017 of file entity_unittests.cc.

2017 {
2018 auto image = CreateTextureForFixture("boston.jpg");
2019 auto filter = ColorFilterContents::MakeBlend(
2020 BlendMode::kDst, FilterInput::Make({image}), Color::Red());
2021
2022 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
2023 Entity entity;
2024 entity.SetTransform(Matrix::MakeScale(GetContentScale()) *
2025 Matrix::MakeTranslation({500, 300}) *
2026 Matrix::MakeScale(Vector2{0.5, 0.5}));
2027 entity.SetContents(filter);
2028 return entity.Render(context, pass);
2029 };
2030 ASSERT_TRUE(OpenPlaygroundHere(callback));
2031}

References callback, context, image, impeller::kDst, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeBlend(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [483/662]

impeller::testing::TEST_P ( EntityTest  ,
ColorFilterWithForegroundColorSrcBlend   
)

Definition at line 2001 of file entity_unittests.cc.

2001 {
2002 auto image = CreateTextureForFixture("boston.jpg");
2003 auto filter = ColorFilterContents::MakeBlend(
2004 BlendMode::kSrc, FilterInput::Make({image}), Color::Red());
2005
2006 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
2007 Entity entity;
2008 entity.SetTransform(Matrix::MakeScale(GetContentScale()) *
2009 Matrix::MakeTranslation({500, 300}) *
2010 Matrix::MakeScale(Vector2{0.5, 0.5}));
2011 entity.SetContents(filter);
2012 return entity.Render(context, pass);
2013 };
2014 ASSERT_TRUE(OpenPlaygroundHere(callback));
2015}

References callback, context, image, impeller::kSrc, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeBlend(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [484/662]

impeller::testing::TEST_P ( EntityTest  ,
ColorFilterWithForegroundColorSrcInBlend   
)

Definition at line 2033 of file entity_unittests.cc.

2033 {
2034 auto image = CreateTextureForFixture("boston.jpg");
2035 auto filter = ColorFilterContents::MakeBlend(
2036 BlendMode::kSrcIn, FilterInput::Make({image}), Color::Red());
2037
2038 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
2039 Entity entity;
2040 entity.SetTransform(Matrix::MakeScale(GetContentScale()) *
2041 Matrix::MakeTranslation({500, 300}) *
2042 Matrix::MakeScale(Vector2{0.5, 0.5}));
2043 entity.SetContents(filter);
2044 return entity.Render(context, pass);
2045 };
2046 ASSERT_TRUE(OpenPlaygroundHere(callback));
2047}

References callback, context, image, impeller::kSrcIn, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeBlend(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [485/662]

impeller::testing::TEST_P ( EntityTest  ,
ColorMatrixFilterCoverageIsCorrect   
)

Definition at line 1494 of file entity_unittests.cc.

1494 {
1495 // Set up a simple color background.
1496 auto geom = Geometry::MakeFillPath(
1497 flutter::DlPath::MakeRect(Rect::MakeXYWH(0, 0, 300, 400)));
1498 auto fill = std::make_shared<SolidColorContents>(geom.get());
1499 fill->SetColor(Color::Coral());
1500
1501 // Set the color matrix filter.
1502 ColorMatrix matrix = {
1503 1, 1, 1, 1, 1, //
1504 1, 1, 1, 1, 1, //
1505 1, 1, 1, 1, 1, //
1506 1, 1, 1, 1, 1, //
1507 };
1508
1509 auto filter =
1510 ColorFilterContents::MakeColorMatrix(FilterInput::Make(fill), matrix);
1511
1512 Entity e;
1513 e.SetTransform(Matrix());
1514
1515 // Confirm that the actual filter coverage matches the expected coverage.
1516 auto actual = filter->GetCoverage(e);
1517 auto expected = Rect::MakeXYWH(0, 0, 300, 400);
1518
1519 ASSERT_TRUE(actual.has_value());
1520 ASSERT_RECT_NEAR(actual.value(), expected);
1521}

References ASSERT_RECT_NEAR, impeller::Color::Coral(), impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeColorMatrix(), impeller::Geometry::MakeFillPath(), flutter::DlPath::MakeRect(), impeller::TRect< Scalar >::MakeXYWH(), and impeller::Entity::SetTransform().

◆ TEST_P() [486/662]

impeller::testing::TEST_P ( EntityTest  ,
ColorMatrixFilterEditable   
)

Definition at line 1523 of file entity_unittests.cc.

1523 {
1524 auto bay_bridge = CreateTextureForFixture("bay_bridge.jpg");
1525 ASSERT_TRUE(bay_bridge);
1526
1527 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
1528 // UI state.
1529 static ColorMatrix color_matrix = {
1530 1, 0, 0, 0, 0, //
1531 0, 3, 0, 0, 0, //
1532 0, 0, 1, 0, 0, //
1533 0, 0, 0, 1, 0, //
1534 };
1535 static float offset[2] = {500, 400};
1536 static float rotation = 0;
1537 static float scale[2] = {0.65, 0.65};
1538 static float skew[2] = {0, 0};
1539
1540 // Define the ImGui
1541 if (IsPlaygroundEnabled()) {
1542 ImGui::Begin("Color Matrix", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1543 std::string label = "##1";
1544 for (int i = 0; i < 20; i += 5) {
1545 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
1546 &(color_matrix.array[i]), 5, nullptr, nullptr,
1547 "%.2f", 0);
1548 label[2]++;
1549 }
1550
1551 ImGui::SliderFloat2("Translation", &offset[0], 0,
1552 pass.GetRenderTargetSize().width);
1553 ImGui::SliderFloat("Rotation", &rotation, 0, kPi * 2);
1554 ImGui::SliderFloat2("Scale", &scale[0], 0, 3);
1555 ImGui::SliderFloat2("Skew", &skew[0], -3, 3);
1556 ImGui::End();
1557 }
1558
1559 // Set the color matrix filter.
1560 auto filter = ColorFilterContents::MakeColorMatrix(
1561 FilterInput::Make(bay_bridge), color_matrix);
1562
1563 // Define the entity with the color matrix filter.
1564 Entity entity;
1565 entity.SetTransform(
1566 Matrix::MakeScale(GetContentScale()) *
1567 Matrix::MakeTranslation(Vector3(offset[0], offset[1])) *
1568 Matrix::MakeRotationZ(Radians(rotation)) *
1569 Matrix::MakeScale(Vector2(scale[0], scale[1])) *
1570 Matrix::MakeSkew(skew[0], skew[1]) *
1571 Matrix::MakeTranslation(-Point(bay_bridge->GetSize()) / 2));
1572 entity.SetContents(filter);
1573 entity.Render(context, pass);
1574
1575 return true;
1576 };
1577
1578 ASSERT_TRUE(OpenPlaygroundHere(callback));
1579}

References impeller::ColorMatrix::array, callback, context, i, flutter::kPi, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeColorMatrix(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeSkew(), impeller::Matrix::MakeTranslation(), impeller::Entity::Render(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [487/662]

impeller::testing::TEST_P ( EntityTest  ,
ConicalGradientContentsIsOpaque   
)

Definition at line 2093 of file entity_unittests.cc.

2093 {
2094 Matrix matrix;
2095 auto geom = Geometry::MakeRect(Rect::MakeLTRB(0, 0, 10, 10));
2096 ConicalGradientContents contents(geom.get());
2097
2098 contents.SetColors({Color::CornflowerBlue()});
2099 EXPECT_FALSE(contents.IsOpaque(matrix));
2100 contents.SetColors({Color::CornflowerBlue().WithAlpha(0.5)});
2101 EXPECT_FALSE(contents.IsOpaque(matrix));
2102
2103 // Create stroked path that required alpha coverage.
2104 auto geom2 = Geometry::MakeStrokePath(
2105 flutter::DlPathBuilder{}.MoveTo({0, 0}).LineTo({100, 100}).TakePath(),
2106 {.width = 0.05f});
2107 ConicalGradientContents contents2(geom2.get());
2108 contents2.SetColors({Color::CornflowerBlue()});
2109
2110 EXPECT_FALSE(contents2.IsOpaque(matrix));
2111}

References impeller::Color::CornflowerBlue(), impeller::Contents::IsOpaque(), impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Geometry::MakeRect(), impeller::Geometry::MakeStrokePath(), flutter::DlPathBuilder::MoveTo(), impeller::ConicalGradientContents::SetColors(), and impeller::Color::WithAlpha().

◆ TEST_P() [488/662]

impeller::testing::TEST_P ( EntityTest  ,
ContentContextOptionsHasReasonableHashFunctions   
)

Definition at line 2267 of file entity_unittests.cc.

2267 {
2269 auto hash_a = opts.ToKey();
2270
2271 opts.blend_mode = BlendMode::kColorBurn;
2272 auto hash_b = opts.ToKey();
2273
2274 opts.has_depth_stencil_attachments = false;
2275 auto hash_c = opts.ToKey();
2276
2277 opts.primitive_type = PrimitiveType::kPoint;
2278 auto hash_d = opts.ToKey();
2279
2280 EXPECT_NE(hash_a, hash_b);
2281 EXPECT_NE(hash_b, hash_c);
2282 EXPECT_NE(hash_c, hash_d);
2283}
constexpr uint64_t ToKey() const

References impeller::ContentContextOptions::blend_mode, impeller::ContentContextOptions::has_depth_stencil_attachments, impeller::kColorBurn, impeller::kPoint, impeller::ContentContextOptions::primitive_type, and impeller::ContentContextOptions::ToKey().

◆ TEST_P() [489/662]

impeller::testing::TEST_P ( EntityTest  ,
ContentsGetBoundsForEmptyPathReturnsNullopt   
)

Definition at line 1236 of file entity_unittests.cc.

1236 {
1237 Entity entity;
1238 entity.SetContents(std::make_shared<SolidColorContents>(nullptr));
1239 ASSERT_FALSE(entity.GetCoverage().has_value());
1240}

References impeller::Entity::GetCoverage(), and impeller::Entity::SetContents().

◆ TEST_P() [490/662]

impeller::testing::TEST_P ( EntityTest  ,
CoverageForStrokePathWithNegativeValuesInTransform   
)

Definition at line 2049 of file entity_unittests.cc.

2049 {
2050 auto arrow_head = flutter::DlPathBuilder{}
2051 .MoveTo({50, 120})
2052 .LineTo({120, 190})
2053 .LineTo({190, 120})
2054 .TakePath();
2055 auto geometry = Geometry::MakeStrokePath(arrow_head, //
2056 {
2057 .width = 15.0f,
2058 .cap = Cap::kRound,
2059 .join = Join::kRound,
2060 .miter_limit = 4.0f,
2061 });
2062
2063 auto transform = Matrix::MakeTranslation({300, 300}) *
2064 Matrix::MakeRotationZ(Radians(kPiOver2));
2065 // Note that e[0][0] used to be tested here, but it was -epsilon solely
2066 // due to floating point inaccuracy in the transcendental trig functions.
2067 // e[1][0] is the intended negative value that we care about (-1.0) as it
2068 // comes from the rotation of pi/2.
2069 EXPECT_LT(transform.e[1][0], 0.0f);
2070 auto coverage = geometry->GetCoverage(transform);
2071 ASSERT_RECT_NEAR(coverage.value(), Rect::MakeXYWH(102.5, 342.5, 85, 155));
2072}

References ASSERT_RECT_NEAR, impeller::Matrix::e, impeller::kPiOver2, impeller::kRound, impeller::LineTo(), impeller::Matrix::MakeRotationZ(), impeller::Geometry::MakeStrokePath(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), flutter::DlPathBuilder::MoveTo(), and transform.

◆ TEST_P() [491/662]

impeller::testing::TEST_P ( EntityTest  ,
CubicCurveAndOverlapTest   
)

Definition at line 445 of file entity_unittests.cc.

445 {
446 // Compare with https://fiddle.skia.org/c/7a05a3e186c65a8dfb732f68020aae06
449 .MoveTo({359.934, 96.6335})
450 .CubicCurveTo({358.189, 96.7055}, {356.436, 96.7908},
451 {354.673, 96.8895})
452 .CubicCurveTo({354.571, 96.8953}, {354.469, 96.9016},
453 {354.367, 96.9075})
454 .CubicCurveTo({352.672, 97.0038}, {350.969, 97.113},
455 {349.259, 97.2355})
456 .CubicCurveTo({349.048, 97.2506}, {348.836, 97.2678},
457 {348.625, 97.2834})
458 .CubicCurveTo({347.019, 97.4014}, {345.407, 97.5299},
459 {343.789, 97.6722})
460 .CubicCurveTo({343.428, 97.704}, {343.065, 97.7402},
461 {342.703, 97.7734})
462 .CubicCurveTo({341.221, 97.9086}, {339.736, 98.0505},
463 {338.246, 98.207})
464 .CubicCurveTo({337.702, 98.2642}, {337.156, 98.3292},
465 {336.612, 98.3894})
466 .CubicCurveTo({335.284, 98.5356}, {333.956, 98.6837},
467 {332.623, 98.8476})
468 .CubicCurveTo({332.495, 98.8635}, {332.366, 98.8818},
469 {332.237, 98.8982})
470 .LineTo({332.237, 102.601})
471 .LineTo({321.778, 102.601})
472 .LineTo({321.778, 100.382})
473 .CubicCurveTo({321.572, 100.413}, {321.367, 100.442},
474 {321.161, 100.476})
475 .CubicCurveTo({319.22, 100.79}, {317.277, 101.123},
476 {315.332, 101.479})
477 .CubicCurveTo({315.322, 101.481}, {315.311, 101.482},
478 {315.301, 101.484})
479 .LineTo({310.017, 105.94})
480 .LineTo({309.779, 105.427})
481 .LineTo({314.403, 101.651})
482 .CubicCurveTo({314.391, 101.653}, {314.379, 101.656},
483 {314.368, 101.658})
484 .CubicCurveTo({312.528, 102.001}, {310.687, 102.366},
485 {308.846, 102.748})
486 .CubicCurveTo({307.85, 102.955}, {306.855, 103.182}, {305.859, 103.4})
487 .CubicCurveTo({305.048, 103.579}, {304.236, 103.75},
488 {303.425, 103.936})
489 .LineTo({299.105, 107.578})
490 .LineTo({298.867, 107.065})
491 .LineTo({302.394, 104.185})
492 .LineTo({302.412, 104.171})
493 .CubicCurveTo({301.388, 104.409}, {300.366, 104.67},
494 {299.344, 104.921})
495 .CubicCurveTo({298.618, 105.1}, {297.89, 105.269}, {297.165, 105.455})
496 .CubicCurveTo({295.262, 105.94}, {293.36, 106.445},
497 {291.462, 106.979})
498 .CubicCurveTo({291.132, 107.072}, {290.802, 107.163},
499 {290.471, 107.257})
500 .CubicCurveTo({289.463, 107.544}, {288.455, 107.839},
501 {287.449, 108.139})
502 .CubicCurveTo({286.476, 108.431}, {285.506, 108.73},
503 {284.536, 109.035})
504 .CubicCurveTo({283.674, 109.304}, {282.812, 109.579},
505 {281.952, 109.859})
506 .CubicCurveTo({281.177, 110.112}, {280.406, 110.377},
507 {279.633, 110.638})
508 .CubicCurveTo({278.458, 111.037}, {277.256, 111.449},
509 {276.803, 111.607})
510 .CubicCurveTo({276.76, 111.622}, {276.716, 111.637},
511 {276.672, 111.653})
512 .CubicCurveTo({275.017, 112.239}, {273.365, 112.836},
513 {271.721, 113.463})
514 .LineTo({271.717, 113.449})
515 .CubicCurveTo({271.496, 113.496}, {271.238, 113.559},
516 {270.963, 113.628})
517 .CubicCurveTo({270.893, 113.645}, {270.822, 113.663},
518 {270.748, 113.682})
519 .CubicCurveTo({270.468, 113.755}, {270.169, 113.834},
520 {269.839, 113.926})
521 .CubicCurveTo({269.789, 113.94}, {269.732, 113.957},
522 {269.681, 113.972})
523 .CubicCurveTo({269.391, 114.053}, {269.081, 114.143},
524 {268.756, 114.239})
525 .CubicCurveTo({268.628, 114.276}, {268.5, 114.314},
526 {268.367, 114.354})
527 .CubicCurveTo({268.172, 114.412}, {267.959, 114.478},
528 {267.752, 114.54})
529 .CubicCurveTo({263.349, 115.964}, {258.058, 117.695},
530 {253.564, 119.252})
531 .CubicCurveTo({253.556, 119.255}, {253.547, 119.258},
532 {253.538, 119.261})
533 .CubicCurveTo({251.844, 119.849}, {250.056, 120.474},
534 {248.189, 121.131})
535 .CubicCurveTo({248, 121.197}, {247.812, 121.264}, {247.621, 121.331})
536 .CubicCurveTo({247.079, 121.522}, {246.531, 121.715},
537 {245.975, 121.912})
538 .CubicCurveTo({245.554, 122.06}, {245.126, 122.212},
539 {244.698, 122.364})
540 .CubicCurveTo({244.071, 122.586}, {243.437, 122.811},
541 {242.794, 123.04})
542 .CubicCurveTo({242.189, 123.255}, {241.58, 123.472},
543 {240.961, 123.693})
544 .CubicCurveTo({240.659, 123.801}, {240.357, 123.909},
545 {240.052, 124.018})
546 .CubicCurveTo({239.12, 124.351}, {238.18, 124.687}, {237.22, 125.032})
547 .LineTo({237.164, 125.003})
548 .CubicCurveTo({236.709, 125.184}, {236.262, 125.358},
549 {235.81, 125.538})
550 .CubicCurveTo({235.413, 125.68}, {234.994, 125.832},
551 {234.592, 125.977})
552 .CubicCurveTo({234.592, 125.977}, {234.591, 125.977},
553 {234.59, 125.977})
554 .CubicCurveTo({222.206, 130.435}, {207.708, 135.753},
555 {192.381, 141.429})
556 .CubicCurveTo({162.77, 151.336}, {122.17, 156.894}, {84.1123, 160})
557 .LineTo({360, 160})
558 .LineTo({360, 119.256})
559 .LineTo({360, 106.332})
560 .LineTo({360, 96.6307})
561 .CubicCurveTo({359.978, 96.6317}, {359.956, 96.6326},
562 {359.934, 96.6335})
563 .Close()
564 .MoveTo({337.336, 124.143})
565 .CubicCurveTo({337.274, 122.359}, {338.903, 121.511},
566 {338.903, 121.511})
567 .CubicCurveTo({338.903, 121.511}, {338.96, 123.303},
568 {337.336, 124.143})
569 .Close()
570 .MoveTo({340.082, 121.849})
571 .CubicCurveTo({340.074, 121.917}, {340.062, 121.992},
572 {340.046, 122.075})
573 .CubicCurveTo({340.039, 122.109}, {340.031, 122.142},
574 {340.023, 122.177})
575 .CubicCurveTo({340.005, 122.26}, {339.98, 122.346},
576 {339.952, 122.437})
577 .CubicCurveTo({339.941, 122.473}, {339.931, 122.507},
578 {339.918, 122.544})
579 .CubicCurveTo({339.873, 122.672}, {339.819, 122.804},
580 {339.75, 122.938})
581 .CubicCurveTo({339.747, 122.944}, {339.743, 122.949},
582 {339.74, 122.955})
583 .CubicCurveTo({339.674, 123.08}, {339.593, 123.205},
584 {339.501, 123.328})
585 .CubicCurveTo({339.473, 123.366}, {339.441, 123.401},
586 {339.41, 123.438})
587 .CubicCurveTo({339.332, 123.534}, {339.243, 123.625},
588 {339.145, 123.714})
589 .CubicCurveTo({339.105, 123.75}, {339.068, 123.786},
590 {339.025, 123.821})
591 .CubicCurveTo({338.881, 123.937}, {338.724, 124.048},
592 {338.539, 124.143})
593 .CubicCurveTo({338.532, 123.959}, {338.554, 123.79},
594 {338.58, 123.626})
595 .CubicCurveTo({338.58, 123.625}, {338.58, 123.625}, {338.58, 123.625})
596 .CubicCurveTo({338.607, 123.455}, {338.65, 123.299},
597 {338.704, 123.151})
598 .CubicCurveTo({338.708, 123.14}, {338.71, 123.127},
599 {338.714, 123.117})
600 .CubicCurveTo({338.769, 122.971}, {338.833, 122.838},
601 {338.905, 122.712})
602 .CubicCurveTo({338.911, 122.702}, {338.916, 122.69200000000001},
603 {338.922, 122.682})
604 .CubicCurveTo({338.996, 122.557}, {339.072, 122.444},
605 {339.155, 122.34})
606 .CubicCurveTo({339.161, 122.333}, {339.166, 122.326},
607 {339.172, 122.319})
608 .CubicCurveTo({339.256, 122.215}, {339.339, 122.12},
609 {339.425, 122.037})
610 .CubicCurveTo({339.428, 122.033}, {339.431, 122.03},
611 {339.435, 122.027})
612 .CubicCurveTo({339.785, 121.687}, {340.106, 121.511},
613 {340.106, 121.511})
614 .CubicCurveTo({340.106, 121.511}, {340.107, 121.645},
615 {340.082, 121.849})
616 .Close()
617 .MoveTo({340.678, 113.245})
618 .CubicCurveTo({340.594, 113.488}, {340.356, 113.655},
619 {340.135, 113.775})
620 .CubicCurveTo({339.817, 113.948}, {339.465, 114.059},
621 {339.115, 114.151})
622 .CubicCurveTo({338.251, 114.379}, {337.34, 114.516},
623 {336.448, 114.516})
624 .CubicCurveTo({335.761, 114.516}, {335.072, 114.527},
625 {334.384, 114.513})
626 .CubicCurveTo({334.125, 114.508}, {333.862, 114.462},
627 {333.605, 114.424})
628 .CubicCurveTo({332.865, 114.318}, {332.096, 114.184},
629 {331.41, 113.883})
630 .CubicCurveTo({330.979, 113.695}, {330.442, 113.34},
631 {330.672, 112.813})
632 .CubicCurveTo({331.135, 111.755}, {333.219, 112.946},
633 {334.526, 113.833})
634 .CubicCurveTo({334.54, 113.816}, {334.554, 113.8}, {334.569, 113.784})
635 .CubicCurveTo({333.38, 112.708}, {331.749, 110.985},
636 {332.76, 110.402})
637 .CubicCurveTo({333.769, 109.82}, {334.713, 111.93},
638 {335.228, 113.395})
639 .CubicCurveTo({334.915, 111.889}, {334.59, 109.636},
640 {335.661, 109.592})
641 .CubicCurveTo({336.733, 109.636}, {336.408, 111.889},
642 {336.07, 113.389})
643 .CubicCurveTo({336.609, 111.93}, {337.553, 109.82},
644 {338.563, 110.402})
645 .CubicCurveTo({339.574, 110.984}, {337.942, 112.708},
646 {336.753, 113.784})
647 .CubicCurveTo({336.768, 113.8}, {336.782, 113.816},
648 {336.796, 113.833})
649 .CubicCurveTo({338.104, 112.946}, {340.187, 111.755},
650 {340.65, 112.813})
651 .CubicCurveTo({340.71, 112.95}, {340.728, 113.102},
652 {340.678, 113.245})
653 .Close()
654 .MoveTo({346.357, 106.771})
655 .CubicCurveTo({346.295, 104.987}, {347.924, 104.139},
656 {347.924, 104.139})
657 .CubicCurveTo({347.924, 104.139}, {347.982, 105.931},
658 {346.357, 106.771})
659 .Close()
660 .MoveTo({347.56, 106.771})
661 .CubicCurveTo({347.498, 104.987}, {349.127, 104.139},
662 {349.127, 104.139})
663 .CubicCurveTo({349.127, 104.139}, {349.185, 105.931},
664 {347.56, 106.771})
665 .Close()
666 .TakePath();
667 Entity entity;
668 entity.SetTransform(Matrix::MakeScale(GetContentScale()));
669
670 std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
671
672 auto contents = std::make_shared<SolidColorContents>(geom.get());
673 contents->SetColor(Color::Red());
674
675 entity.SetContents(contents);
676 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
677}

References impeller::Close(), impeller::LineTo(), impeller::Geometry::MakeFillPath(), impeller::Matrix::MakeScale(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::Color::Red(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), and flutter::DlPathBuilder::TakePath().

◆ TEST_P() [492/662]

impeller::testing::TEST_P ( EntityTest  ,
CubicCurveTest   
)

Definition at line 363 of file entity_unittests.cc.

363 {
364 // Compare with https://fiddle.skia.org/c/b3625f26122c9de7afe7794fcf25ead3
367 .MoveTo({237.164, 125.003})
368 .CubicCurveTo({236.709, 125.184}, {236.262, 125.358},
369 {235.81, 125.538})
370 .CubicCurveTo({235.413, 125.68}, {234.994, 125.832},
371 {234.592, 125.977})
372 .CubicCurveTo({234.592, 125.977}, {234.591, 125.977},
373 {234.59, 125.977})
374 .CubicCurveTo({222.206, 130.435}, {207.708, 135.753},
375 {192.381, 141.429})
376 .CubicCurveTo({162.77, 151.336}, {122.17, 156.894}, {84.1123, 160})
377 .Close()
378 .TakePath();
379 Entity entity;
380 entity.SetTransform(Matrix::MakeScale(GetContentScale()));
381
382 std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(path);
383
384 auto contents = std::make_shared<SolidColorContents>(geom.get());
385 contents->SetColor(Color::Red());
386
387 entity.SetContents(contents);
388 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
389}

References impeller::Close(), impeller::Geometry::MakeFillPath(), impeller::Matrix::MakeScale(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::Color::Red(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), and flutter::DlPathBuilder::TakePath().

◆ TEST_P() [493/662]

impeller::testing::TEST_P ( EntityTest  ,
DecalSpecializationAppliedToMorphologyFilter   
)

Definition at line 2251 of file entity_unittests.cc.

2251 {
2252 ContentContext& content_context = GetContentContext();
2253 auto default_color_burn = content_context.GetMorphologyFilterPipeline({
2254 .color_attachment_pixel_format = PixelFormat::kR8G8B8A8UNormInt,
2255 });
2256
2257 auto decal_supported = static_cast<Scalar>(
2258 GetContext()->GetCapabilities()->SupportsDecalSamplerAddressMode());
2259 std::vector<Scalar> expected_constants = {decal_supported};
2260 ASSERT_EQ(default_color_burn->GetDescriptor().GetSpecializationConstants(),
2261 expected_constants);
2262}
PipelineRef GetMorphologyFilterPipeline(ContentContextOptions opts) const

References impeller::ContentContext::GetMorphologyFilterPipeline(), and impeller::kR8G8B8A8UNormInt.

◆ TEST_P() [494/662]

impeller::testing::TEST_P ( EntityTest  ,
DrawRoundSuperEllipse   
)

Definition at line 2537 of file entity_unittests.cc.

2537 {
2538 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
2539 // UI state.
2540 static int style_index = 0;
2541 static Point center = {830, 830};
2542 static Point size = {600, 600};
2543 static bool horizontal_symmetry = true;
2544 static bool vertical_symmetry = true;
2545 static bool corner_symmetry = true;
2546
2547 const char* style_options[] = {"Fill", "Stroke"};
2548
2549 // Initially radius_tl[0] will be mirrored to all 8 values since all 3
2550 // symmetries are enabled.
2551 static std::array<float, 2> radius_tl = {200};
2552 static std::array<float, 2> radius_tr;
2553 static std::array<float, 2> radius_bl;
2554 static std::array<float, 2> radius_br;
2555
2556 auto AddRadiusControl = [](std::array<float, 2>& radii, const char* tb_name,
2557 const char* lr_name) {
2558 std::string name = "Radius";
2559 if (!horizontal_symmetry || !vertical_symmetry) {
2560 name += ":";
2561 }
2562 if (!vertical_symmetry) {
2563 name = name + " " + tb_name;
2564 }
2565 if (!horizontal_symmetry) {
2566 name = name + " " + lr_name;
2567 }
2568 if (corner_symmetry) {
2569 ImGui::SliderFloat(name.c_str(), radii.data(), 0, 1000);
2570 } else {
2571 ImGui::SliderFloat2(name.c_str(), radii.data(), 0, 1000);
2572 }
2573 };
2574
2575 if (corner_symmetry) {
2576 radius_tl[1] = radius_tl[0];
2577 radius_tr[1] = radius_tr[0];
2578 radius_bl[1] = radius_bl[0];
2579 radius_br[1] = radius_br[0];
2580 }
2581
2582 if (IsPlaygroundEnabled()) {
2583 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
2584 ImGui::Combo("Style", &style_index, style_options,
2585 sizeof(style_options) / sizeof(char*));
2586 ImGui::SliderFloat2("Center", &center.x, 0, 1000);
2587 ImGui::SliderFloat2("Size", &size.x, 0, 1000);
2588 ImGui::Checkbox("Symmetry: Horizontal", &horizontal_symmetry);
2589 ImGui::Checkbox("Symmetry: Vertical", &vertical_symmetry);
2590 ImGui::Checkbox("Symmetry: Corners", &corner_symmetry);
2591 AddRadiusControl(radius_tl, "Top", "Left");
2592 if (!horizontal_symmetry) {
2593 AddRadiusControl(radius_tr, "Top", "Right");
2594 } else {
2595 radius_tr = radius_tl;
2596 }
2597 if (!vertical_symmetry) {
2598 AddRadiusControl(radius_bl, "Bottom", "Left");
2599 } else {
2600 radius_bl = radius_tl;
2601 }
2602 if (!horizontal_symmetry && !vertical_symmetry) {
2603 AddRadiusControl(radius_br, "Bottom", "Right");
2604 } else {
2605 if (horizontal_symmetry) {
2606 radius_br = radius_bl;
2607 } else {
2608 radius_br = radius_tr;
2609 }
2610 }
2611 ImGui::End();
2612 }
2613
2614 RoundingRadii radii{
2615 .top_left = {radius_tl[0], radius_tl[1]},
2616 .top_right = {radius_tr[0], radius_tr[1]},
2617 .bottom_left = {radius_bl[0], radius_bl[1]},
2618 .bottom_right = {radius_br[0], radius_br[1]},
2619 };
2620
2621 auto rse = RoundSuperellipse::MakeRectRadii(
2622 Rect::MakeEllipseBounds(center, size * 0.5f), radii);
2623
2625 std::unique_ptr<Geometry> geom;
2626 if (style_index == 0) {
2627 geom = std::make_unique<RoundSuperellipseGeometry>(
2628 Rect::MakeEllipseBounds(center, size * 0.5f), radii);
2629 } else {
2631 geom = Geometry::MakeStrokePath(path, {.width = 2.0f});
2632 }
2633
2634 auto contents = std::make_shared<SolidColorContents>(geom.get());
2635 contents->SetColor(Color::Red());
2636
2637 Entity entity;
2638 entity.SetContents(contents);
2639
2640 return entity.Render(context, pass);
2641 };
2642
2643 ASSERT_TRUE(OpenPlaygroundHere(callback));
2644}
static DlPath MakeRoundSuperellipse(const DlRoundSuperellipse &rse)
Definition dl_path.cc:85

References callback, context, impeller::TRect< Scalar >::MakeEllipseBounds(), impeller::RoundSuperellipse::MakeRectRadii(), flutter::DlPath::MakeRoundSuperellipse(), impeller::Geometry::MakeStrokePath(), flutter::name, flutter::path, impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), flutter::size, and impeller::RoundingRadii::top_left.

◆ TEST_P() [495/662]

impeller::testing::TEST_P ( EntityTest  ,
DrawRoundSuperEllipseWithLargeN   
)

Definition at line 2646 of file entity_unittests.cc.

2646 {
2647 // This playground shows the enlarged corner of a rounded superellipse to
2648 // compare pathing algorithm against the filling algorithm (benchmark) at very
2649 // large ratio.
2650 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
2651 constexpr float corner_radius = 100.0;
2652
2653 // UI state.
2654 static float logarithm_of_ratio = 1.5; // ratio = size / corner_radius
2655
2656 float ratio = std::exp(logarithm_of_ratio);
2657
2658 float rect_size = corner_radius * ratio;
2659 Rect rect = Rect::MakeLTRB(0, 0, rect_size, rect_size);
2660 constexpr float screen_canvas_padding = 200.0f;
2661 constexpr float screen_canvas_size = 1000.0f;
2662
2663 // Scale so that "corner radius" is as long as half the canvas.
2664 float scale = screen_canvas_size / 2 / corner_radius;
2665
2666 if (IsPlaygroundEnabled()) {
2667 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
2668 ImGui::SliderFloat("log(Ratio)", &logarithm_of_ratio, 1.0, 8.0);
2669 ImGui::LabelText("Ratio", "%.2g", static_cast<double>(ratio));
2670 ImGui::Text(" where Ratio = RectSize / CornerRadius");
2671 ImGui::End();
2672 }
2673
2674 auto top_right = Vector2(screen_canvas_size * 1.3f, screen_canvas_padding);
2675 auto transform = Matrix::MakeTranslation(top_right) *
2676 Matrix::MakeScale(Vector2(scale, scale)) *
2677 Matrix::MakeTranslation(Vector2(-rect_size, 0));
2678 bool success = true;
2679
2680 auto fill_geom =
2681 std::make_unique<RoundSuperellipseGeometry>(rect, corner_radius);
2682 // Fill
2683 {
2684 auto contents = std::make_shared<SolidColorContents>(fill_geom.get());
2685 contents->SetColor(Color::Red());
2686
2687 Entity entity;
2688 entity.SetContents(contents);
2689 entity.SetTransform(transform);
2690
2691 success = success && entity.Render(context, pass);
2692 }
2693
2694 // Stroke
2696 RoundSuperellipse::MakeRectRadius(rect, corner_radius));
2697 auto stroke_geom = Geometry::MakeStrokePath(path, {.width = 2 / scale});
2698 {
2699 auto contents = std::make_shared<SolidColorContents>(stroke_geom.get());
2700 contents->SetColor(Color::Blue());
2701
2702 Entity entity;
2703 entity.SetContents(contents);
2704 entity.SetTransform(transform);
2705
2706 success = success && entity.Render(context, pass);
2707 }
2708
2709 // Draw a ruler to show the length in portion of rect size.
2710 auto screen_top_right =
2711 Matrix::MakeScale(GetContentScale()).Invert() * top_right;
2712 constexpr float font_size = 13.0f;
2713 for (int i = -1; i < 100; i++) {
2714 float screen_offset_y = static_cast<float>(i) * 20.0f;
2715 std::string label;
2716 if (i == -1) {
2717 label = "Ruler: (in portion of rect size)";
2718 } else if (i == 0) {
2719 label = "- 0.0";
2720 } else {
2721 float portion_of_rect =
2722 screen_offset_y * GetContentScale().y / scale / rect_size;
2723 label = std::format("- {:.2g}", portion_of_rect);
2724 }
2725 if (IsPlaygroundEnabled()) {
2726 ImGui::GetBackgroundDrawList()->AddText(
2727 nullptr, font_size,
2728 // Draw the ruler at around the flat part of the curve, which is
2729 // somewhere to the left of the top right corner.
2730 //
2731 // Offset vertically by font_size/2 so that the hyphen aligns with
2732 // the top of shape.
2733 {screen_top_right.x - 500,
2734 screen_top_right.y + screen_offset_y - font_size / 2},
2735 IM_COL32_WHITE, label.c_str());
2736 }
2737 }
2738 return success;
2739 };
2740
2741 ASSERT_TRUE(OpenPlaygroundHere(callback));
2742}

References impeller::Color::Blue(), callback, context, font_size, i, impeller::Matrix::Invert(), impeller::TRect< Scalar >::MakeLTRB(), impeller::RoundSuperellipse::MakeRectRadius(), flutter::DlPath::MakeRoundSuperellipse(), impeller::Matrix::MakeScale(), impeller::Geometry::MakeStrokePath(), impeller::Matrix::MakeTranslation(), flutter::path, impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), and transform.

◆ TEST_P() [496/662]

impeller::testing::TEST_P ( EntityTest  ,
DrawSuperEllipse   
)

Definition at line 2503 of file entity_unittests.cc.

2503 {
2504 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
2505 // UI state.
2506 static float alpha = 10;
2507 static float beta = 10;
2508 static float radius = 40;
2509 static int degree = 4;
2510 static Color color = Color::Red();
2511
2512 if (IsPlaygroundEnabled()) {
2513 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
2514 ImGui::SliderFloat("Alpha", &alpha, 0, 100);
2515 ImGui::SliderFloat("Beta", &beta, 0, 100);
2516 ImGui::SliderInt("Degreee", &degree, 1, 20);
2517 ImGui::SliderFloat("Radius", &radius, 0, 400);
2518 ImGui::ColorEdit4("Color", reinterpret_cast<float*>(&color));
2519 ImGui::End();
2520 }
2521
2522 std::unique_ptr<SuperellipseGeometry> geom =
2523 std::make_unique<SuperellipseGeometry>(Point{400, 400}, radius, degree,
2524 alpha, beta);
2525 auto contents = std::make_shared<SolidColorContents>(geom.get());
2526 contents->SetColor(color);
2527
2528 Entity entity;
2529 entity.SetContents(contents);
2530
2531 return entity.Render(context, pass);
2532 };
2533
2534 ASSERT_TRUE(OpenPlaygroundHere(callback));
2535}

References callback, context, impeller::Color::Red(), impeller::Entity::Render(), and impeller::Entity::SetContents().

◆ TEST_P() [497/662]

impeller::testing::TEST_P ( EntityTest  ,
FailOnValidationError   
)

Definition at line 2453 of file entity_unittests.cc.

2453 {
2454 if (GetParam() != PlaygroundBackend::kVulkan) {
2455 GTEST_SKIP() << "Validation is only fatal on Vulkan backend.";
2456 }
2457 EXPECT_DEATH(
2458 // The easiest way to trigger a validation error is to try to compile
2459 // a shader with an unsupported pixel format.
2460 GetContentContext().GetBlendColorBurnPipeline({
2461 .color_attachment_pixel_format = PixelFormat::kUnknown,
2462 .has_depth_stencil_attachments = false,
2463 }),
2464 "");
2465}

References impeller::kUnknown, and impeller::kVulkan.

◆ TEST_P() [498/662]

impeller::testing::TEST_P ( EntityTest  ,
FillPathGeometryGetPositionBufferReturnsExpectedMode   
)

Definition at line 2311 of file entity_unittests.cc.

2311 {
2313 testing::MockRenderPass mock_pass(GetContext(), target);
2314
2315 auto get_result = [this, &mock_pass](const flutter::DlPath& path) {
2316 auto geometry = Geometry::MakeFillPath(
2317 path, /* inner rect */ Rect::MakeLTRB(0, 0, 100, 100));
2318 return geometry->GetPositionBuffer(GetContentContext(), {}, mock_pass);
2319 };
2320
2321 // Convex path
2322 {
2323 GeometryResult result =
2324 get_result(flutter::DlPath::MakeRect(Rect::MakeLTRB(0, 0, 100, 100)));
2325 EXPECT_EQ(result.mode, GeometryResult::Mode::kNormal);
2326 }
2327
2328 // Concave path
2329 {
2331 .MoveTo({0, 0})
2332 .LineTo({100, 0})
2333 .LineTo({100, 100})
2334 .LineTo({51, 50})
2335 .Close()
2336 .TakePath();
2337 GeometryResult result = get_result(path);
2338 EXPECT_EQ(result.mode, GeometryResult::Mode::kNonZero);
2339 }
2340}

References impeller::Close(), impeller::GeometryResult::kNonZero, impeller::GeometryResult::kNormal, impeller::LineTo(), impeller::Geometry::MakeFillPath(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRect(), impeller::GeometryResult::mode, flutter::DlPathBuilder::MoveTo(), flutter::path, flutter::DlPathBuilder::TakePath(), and target.

◆ TEST_P() [499/662]

impeller::testing::TEST_P ( EntityTest  ,
FilterCoverageRespectsCropRect   
)

Definition at line 77 of file entity_unittests.cc.

77 {
78 auto image = CreateTextureForFixture("boston.jpg");
79 auto filter = ColorFilterContents::MakeBlend(BlendMode::kSoftLight,
80 FilterInput::Make({image}));
81
82 // Without the crop rect (default behavior).
83 {
84 auto actual = filter->GetCoverage({});
85 auto expected = Rect::MakeSize(image->GetSize());
86
87 ASSERT_TRUE(actual.has_value());
88 ASSERT_RECT_NEAR(actual.value(), expected);
89 }
90
91 // With the crop rect.
92 {
93 auto expected = Rect::MakeLTRB(50, 50, 100, 100);
94 filter->SetCoverageHint(expected);
95 auto actual = filter->GetCoverage({});
96
97 ASSERT_TRUE(actual.has_value());
98 ASSERT_RECT_NEAR(actual.value(), expected);
99 }
100}

References ASSERT_RECT_NEAR, image, impeller::kSoftLight, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeBlend(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::TRect< Scalar >::MakeSize().

◆ TEST_P() [500/662]

impeller::testing::TEST_P ( EntityTest  ,
Filters   
)

Definition at line 915 of file entity_unittests.cc.

915 {
916 auto bridge = CreateTextureForFixture("bay_bridge.jpg");
917 auto boston = CreateTextureForFixture("boston.jpg");
918 auto kalimba = CreateTextureForFixture("kalimba.jpg");
919 ASSERT_TRUE(bridge && boston && kalimba);
920
921 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
922 auto fi_bridge = FilterInput::Make(bridge);
923 auto fi_boston = FilterInput::Make(boston);
924 auto fi_kalimba = FilterInput::Make(kalimba);
925
926 std::shared_ptr<FilterContents> blend0 = ColorFilterContents::MakeBlend(
927 BlendMode::kModulate, {fi_kalimba, fi_boston});
928
929 auto blend1 = ColorFilterContents::MakeBlend(
930 BlendMode::kScreen,
931 {FilterInput::Make(blend0), fi_bridge, fi_bridge, fi_bridge});
932
933 Entity entity;
934 entity.SetTransform(Matrix::MakeScale(GetContentScale()) *
935 Matrix::MakeTranslation({500, 300}) *
936 Matrix::MakeScale(Vector2{0.5, 0.5}));
937 entity.SetContents(blend1);
938 return entity.Render(context, pass);
939 };
940 ASSERT_TRUE(OpenPlaygroundHere(callback));
941}

References callback, context, impeller::kModulate, impeller::kScreen, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeBlend(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), and impeller::Entity::SetTransform().

◆ TEST_P() [501/662]

impeller::testing::TEST_P ( EntityTest  ,
GaussianBlurFilter   
)

Definition at line 943 of file entity_unittests.cc.

943 {
944 auto boston =
945 CreateTextureForFixture("boston.jpg", /*enable_mipmapping=*/true);
946 ASSERT_TRUE(boston);
947
948 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
949 const char* input_type_names[] = {"Texture", "Solid Color"};
950 const char* blur_type_names[] = {"Image blur", "Mask blur"};
951 const char* pass_variation_names[] = {"New"};
952 const char* blur_style_names[] = {"Normal", "Solid", "Outer", "Inner"};
953 const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
954 const FilterContents::BlurStyle blur_styles[] = {
955 FilterContents::BlurStyle::kNormal, FilterContents::BlurStyle::kSolid,
956 FilterContents::BlurStyle::kOuter, FilterContents::BlurStyle::kInner};
957 const Entity::TileMode tile_modes[] = {
958 Entity::TileMode::kClamp, Entity::TileMode::kRepeat,
959 Entity::TileMode::kMirror, Entity::TileMode::kDecal};
960
961 // UI state.
962 static int selected_input_type = 0;
963 static Color input_color = Color::Black();
964 static int selected_blur_type = 0;
965 static int selected_pass_variation = 0;
966 static bool combined_sigma = false;
967 static float blur_amount_coarse[2] = {0, 0};
968 static float blur_amount_fine[2] = {10, 10};
969 static int selected_blur_style = 0;
970 static int selected_tile_mode = 3;
971 static Color cover_color(1, 0, 0, 0.2);
972 static Color bounds_color(0, 1, 0, 0.1);
973 static float offset[2] = {500, 400};
974 static float rotation = 0;
975 static float scale[2] = {0.65, 0.65};
976 static float skew[2] = {0, 0};
977 static float path_rect[4] = {0, 0,
978 static_cast<float>(boston->GetSize().width),
979 static_cast<float>(boston->GetSize().height)};
980
981 if (IsPlaygroundEnabled()) {
982 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
983 ImGui::Combo("Input type", &selected_input_type, input_type_names,
984 sizeof(input_type_names) / sizeof(char*));
985 if (selected_input_type == 0) {
986 ImGui::SliderFloat("Input opacity", &input_color.alpha, 0, 1);
987 } else {
988 ImGui::ColorEdit4("Input color",
989 reinterpret_cast<float*>(&input_color));
990 }
991 ImGui::Combo("Blur type", &selected_blur_type, blur_type_names,
992 sizeof(blur_type_names) / sizeof(char*));
993 if (selected_blur_type == 0) {
994 ImGui::Combo("Pass variation", &selected_pass_variation,
995 pass_variation_names,
996 sizeof(pass_variation_names) / sizeof(char*));
997 }
998 ImGui::Checkbox("Combined sigma", &combined_sigma);
999 if (combined_sigma) {
1000 ImGui::SliderFloat("Sigma (coarse)", blur_amount_coarse, 0, 1000);
1001 ImGui::SliderFloat("Sigma (fine)", blur_amount_fine, 0, 10);
1002 blur_amount_coarse[1] = blur_amount_coarse[0];
1003 blur_amount_fine[1] = blur_amount_fine[0];
1004 } else {
1005 ImGui::SliderFloat2("Sigma (coarse)", blur_amount_coarse, 0, 1000);
1006 ImGui::SliderFloat2("Sigma (fine)", blur_amount_fine, 0, 10);
1007 }
1008 ImGui::Combo("Blur style", &selected_blur_style, blur_style_names,
1009 sizeof(blur_style_names) / sizeof(char*));
1010 ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
1011 sizeof(tile_mode_names) / sizeof(char*));
1012 ImGui::ColorEdit4("Cover color", reinterpret_cast<float*>(&cover_color));
1013 ImGui::ColorEdit4("Bounds color ",
1014 reinterpret_cast<float*>(&bounds_color));
1015 ImGui::SliderFloat2("Translation", offset, 0,
1016 pass.GetRenderTargetSize().width);
1017 ImGui::SliderFloat("Rotation", &rotation, 0, kPi * 2);
1018 ImGui::SliderFloat2("Scale", scale, 0, 3);
1019 ImGui::SliderFloat2("Skew", skew, -3, 3);
1020 ImGui::SliderFloat4("Path XYWH", path_rect, -1000, 1000);
1021 ImGui::End();
1022 }
1023
1024 auto blur_sigma_x = Sigma{blur_amount_coarse[0] + blur_amount_fine[0]};
1025 auto blur_sigma_y = Sigma{blur_amount_coarse[1] + blur_amount_fine[1]};
1026
1027 std::shared_ptr<Contents> input;
1028 Size input_size;
1029
1030 auto input_rect =
1031 Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]);
1032
1033 std::unique_ptr<Geometry> solid_color_input;
1034 if (selected_input_type == 0) {
1035 auto texture = std::make_shared<TextureContents>();
1036 texture->SetSourceRect(Rect::MakeSize(boston->GetSize()));
1037 texture->SetDestinationRect(input_rect);
1038 texture->SetTexture(boston);
1039 texture->SetOpacity(input_color.alpha);
1040
1041 input = texture;
1042 input_size = input_rect.GetSize();
1043 } else {
1044 solid_color_input =
1045 Geometry::MakeFillPath(flutter::DlPath::MakeRect(input_rect));
1046 auto fill = std::make_shared<SolidColorContents>(solid_color_input.get());
1047 fill->SetColor(input_color);
1048
1049 input = fill;
1050 input_size = input_rect.GetSize();
1051 }
1052
1053 std::shared_ptr<FilterContents> blur;
1054 switch (selected_pass_variation) {
1055 case 0:
1056 blur = std::make_shared<GaussianBlurFilterContents>(
1057 blur_sigma_x.sigma, blur_sigma_y.sigma,
1058 tile_modes[selected_tile_mode], /*bounds=*/std::nullopt,
1059 blur_styles[selected_blur_style],
1060 /*geometry=*/nullptr);
1061 blur->SetInputs({FilterInput::Make(input)});
1062 break;
1063 case 1:
1064 blur = FilterContents::MakeGaussianBlur(
1065 FilterInput::Make(input), blur_sigma_x, blur_sigma_y,
1066 tile_modes[selected_tile_mode],
1067 /*bounds=*/std::nullopt, blur_styles[selected_blur_style]);
1068 break;
1069 };
1070 FML_CHECK(blur);
1071
1072 auto mask_blur = FilterContents::MakeBorderMaskBlur(
1073 FilterInput::Make(input), blur_sigma_x, blur_sigma_y,
1074 blur_styles[selected_blur_style]);
1075
1076 auto ctm = Matrix::MakeScale(GetContentScale()) *
1077 Matrix::MakeTranslation(Vector3(offset[0], offset[1])) *
1078 Matrix::MakeRotationZ(Radians(rotation)) *
1079 Matrix::MakeScale(Vector2(scale[0], scale[1])) *
1080 Matrix::MakeSkew(skew[0], skew[1]) *
1081 Matrix::MakeTranslation(-Point(input_size) / 2);
1082
1083 auto target_contents = selected_blur_type == 0 ? blur : mask_blur;
1084
1085 Entity entity;
1086 entity.SetContents(target_contents);
1087 entity.SetTransform(ctm);
1088
1089 entity.Render(context, pass);
1090
1091 // Renders a red "cover" rectangle that shows the original position of the
1092 // unfiltered input.
1093 Entity cover_entity;
1094 auto geom = Geometry::MakeFillPath(flutter::DlPath::MakeRect(input_rect));
1095 auto contents = std::make_shared<SolidColorContents>(geom.get());
1096 contents->SetColor(cover_color);
1097 cover_entity.SetContents(std::move(contents));
1098 cover_entity.SetTransform(ctm);
1099 cover_entity.Render(context, pass);
1100
1101 // Renders a green bounding rect of the target filter.
1102 Entity bounds_entity;
1103 std::optional<Rect> target_contents_coverage =
1104 target_contents->GetCoverage(entity);
1105 if (target_contents_coverage.has_value()) {
1106 std::unique_ptr<Geometry> geom =
1107 Geometry::MakeFillPath(flutter::DlPath::MakeRect(
1108 target_contents->GetCoverage(entity).value()));
1109 auto contents = std::make_shared<SolidColorContents>(geom.get());
1110 contents->SetColor(bounds_color);
1111
1112 bounds_entity.SetContents(contents);
1113 bounds_entity.SetTransform(Matrix());
1114 bounds_entity.Render(context, pass);
1115 }
1116
1117 return true;
1118 };
1119 ASSERT_TRUE(OpenPlaygroundHere(callback));
1120}

References impeller::Color::alpha, impeller::Color::Black(), callback, context, FML_CHECK, impeller::Entity::GetCoverage(), input(), impeller::Entity::kClamp, impeller::Entity::kDecal, impeller::FilterContents::kInner, impeller::Entity::kMirror, impeller::FilterContents::kNormal, impeller::FilterContents::kOuter, flutter::kPi, impeller::Entity::kRepeat, impeller::FilterContents::kSolid, impeller::FilterInput::Make(), impeller::FilterContents::MakeBorderMaskBlur(), impeller::Geometry::MakeFillPath(), impeller::FilterContents::MakeGaussianBlur(), flutter::DlPath::MakeRect(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeSize(), impeller::Matrix::MakeSkew(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), impeller::Entity::Render(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), and texture.

◆ TEST_P() [502/662]

impeller::testing::TEST_P ( EntityTest  ,
GeometryBoundsAreTransformed   
)

Definition at line 102 of file entity_unittests.cc.

102 {
103 auto geometry = Geometry::MakeRect(Rect::MakeXYWH(100, 100, 100, 100));
104 auto transform = Matrix::MakeScale({2.0, 2.0, 2.0});
105
106 ASSERT_RECT_NEAR(geometry->GetCoverage(transform).value(),
107 Rect::MakeXYWH(200, 200, 200, 200));
108}

References ASSERT_RECT_NEAR, impeller::Geometry::MakeRect(), impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeXYWH(), and transform.

◆ TEST_P() [503/662]

impeller::testing::TEST_P ( EntityTest  ,
GiantStrokePathAllocation   
)

Definition at line 2852 of file entity_unittests.cc.

2852 {
2853 flutter::DlPathBuilder builder;
2854 for (int i = 0; i < 10000; i++) {
2855 builder.LineTo(Point(i, i));
2856 }
2857 flutter::DlPath path = builder.TakePath();
2858 auto geom = Geometry::MakeStrokePath(path, {.width = 10.0f});
2859
2860 ContentContext content_context(GetContext(), /*typographer_context=*/nullptr);
2861 Entity entity;
2862
2863 auto cmd_buffer = content_context.GetContext()->CreateCommandBuffer();
2864
2865 RenderTargetAllocator allocator(
2866 content_context.GetContext()->GetResourceAllocator());
2867
2868 auto render_target = allocator.CreateOffscreen(
2869 *content_context.GetContext(), /*size=*/{10, 10}, /*mip_count=*/1);
2870 auto pass = cmd_buffer->CreateRenderPass(render_target);
2871
2872 GeometryResult result =
2873 geom->GetPositionBuffer(content_context, entity, *pass);
2874
2875 // Validate the buffer data overflowed the small buffer
2876 EXPECT_GT(result.vertex_buffer.vertex_count, kPointArenaSize);
2877
2878 // Validate that there are no uninitialized points near the gap.
2879 Point* written_data = reinterpret_cast<Point*>(
2880 (result.vertex_buffer.vertex_buffer.GetBuffer()->OnGetContents() +
2881 result.vertex_buffer.vertex_buffer.GetRange().offset));
2882
2883 std::vector<Point> expected = {
2884 Point(2043.46, 2050.54), //
2885 Point(2050.54, 2043.46), //
2886 Point(2044.46, 2051.54), //
2887 Point(2051.54, 2044.46), //
2888 Point(2045.46, 2052.54) //
2889 };
2890
2891 Point point = written_data[kPointArenaSize - 2];
2892 EXPECT_NEAR(point.x, expected[0].x, 0.1);
2893 EXPECT_NEAR(point.y, expected[0].y, 0.1);
2894
2895 point = written_data[kPointArenaSize - 1];
2896 EXPECT_NEAR(point.x, expected[1].x, 0.1);
2897 EXPECT_NEAR(point.y, expected[1].y, 0.1);
2898
2899 point = written_data[kPointArenaSize];
2900 EXPECT_NEAR(point.x, expected[2].x, 0.1);
2901 EXPECT_NEAR(point.y, expected[2].y, 0.1);
2902
2903 point = written_data[kPointArenaSize + 1];
2904 EXPECT_NEAR(point.x, expected[3].x, 0.1);
2905 EXPECT_NEAR(point.y, expected[3].y, 0.1);
2906
2907 point = written_data[kPointArenaSize + 2];
2908 EXPECT_NEAR(point.x, expected[4].x, 0.1);
2909 EXPECT_NEAR(point.y, expected[4].y, 0.1);
2910}

References allocator, impeller::BufferView::GetBuffer(), impeller::BufferView::GetRange(), i, impeller::kPointArenaSize, flutter::DlPathBuilder::LineTo(), impeller::Geometry::MakeStrokePath(), impeller::Range::offset, impeller::DeviceBuffer::OnGetContents(), flutter::path, flutter::DlPathBuilder::TakePath(), impeller::VertexBuffer::vertex_buffer, impeller::GeometryResult::vertex_buffer, impeller::VertexBuffer::vertex_count, flutter::Point::x(), and flutter::Point::y().

◆ TEST_P() [504/662]

impeller::testing::TEST_P ( EntityTest  ,
LinearGradientContentsIsOpaque   
)

Definition at line 2113 of file entity_unittests.cc.

2113 {
2114 Matrix matrix;
2115 auto geom = Geometry::MakeRect(Rect::MakeLTRB(0, 0, 10, 10));
2116 LinearGradientContents contents(geom.get());
2117
2118 contents.SetColors({Color::CornflowerBlue()});
2119 EXPECT_TRUE(contents.IsOpaque(matrix));
2120 contents.SetColors({Color::CornflowerBlue().WithAlpha(0.5)});
2121 EXPECT_FALSE(contents.IsOpaque(matrix));
2122 contents.SetColors({Color::CornflowerBlue()});
2123 contents.SetTileMode(Entity::TileMode::kDecal);
2124 EXPECT_FALSE(contents.IsOpaque(matrix));
2125
2126 // Create stroked path that required alpha coverage.
2127 auto geom2 = Geometry::MakeStrokePath(
2128 flutter::DlPathBuilder{}.MoveTo({0, 0}).LineTo({100, 100}).TakePath(),
2129 {.width = 0.05f});
2130 LinearGradientContents contents2(geom2.get());
2131 contents2.SetColors({Color::CornflowerBlue()});
2132
2133 EXPECT_FALSE(contents2.IsOpaque(matrix));
2134}

References impeller::Color::CornflowerBlue(), impeller::LinearGradientContents::IsOpaque(), impeller::Entity::kDecal, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Geometry::MakeRect(), impeller::Geometry::MakeStrokePath(), flutter::DlPathBuilder::MoveTo(), impeller::LinearGradientContents::SetColors(), impeller::LinearGradientContents::SetTileMode(), and impeller::Color::WithAlpha().

◆ TEST_P() [505/662]

impeller::testing::TEST_P ( EntityTest  ,
LinearToSrgbFilter   
)

Definition at line 1602 of file entity_unittests.cc.

1602 {
1603 auto image = CreateTextureForFixture("kalimba.jpg");
1604 ASSERT_TRUE(image);
1605
1606 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
1607 auto filtered =
1608 ColorFilterContents::MakeLinearToSrgbFilter(FilterInput::Make(image));
1609
1610 // Define the entity that will serve as the control image as a Gaussian blur
1611 // filter with no filter at all.
1612 Entity entity_left;
1613 entity_left.SetTransform(Matrix::MakeScale(GetContentScale()) *
1614 Matrix::MakeTranslation({100, 300}) *
1615 Matrix::MakeScale(Vector2{0.5, 0.5}));
1616 auto unfiltered = FilterContents::MakeGaussianBlur(FilterInput::Make(image),
1617 Sigma{0}, Sigma{0});
1618 entity_left.SetContents(unfiltered);
1619
1620 // Define the entity that will be filtered from linear to sRGB.
1621 Entity entity_right;
1622 entity_right.SetTransform(Matrix::MakeScale(GetContentScale()) *
1623 Matrix::MakeTranslation({500, 300}) *
1624 Matrix::MakeScale(Vector2{0.5, 0.5}));
1625 entity_right.SetContents(filtered);
1626 return entity_left.Render(context, pass) &&
1627 entity_right.Render(context, pass);
1628 };
1629
1630 ASSERT_TRUE(OpenPlaygroundHere(callback));
1631}

References callback, context, image, impeller::FilterInput::Make(), impeller::FilterContents::MakeGaussianBlur(), impeller::ColorFilterContents::MakeLinearToSrgbFilter(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::Entity::Render(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [506/662]

impeller::testing::TEST_P ( EntityTest  ,
LinearToSrgbFilterCoverageIsCorrect   
)

Definition at line 1581 of file entity_unittests.cc.

1581 {
1582 // Set up a simple color background.
1583 auto geom = Geometry::MakeFillPath(
1584 flutter::DlPath::MakeRect(Rect::MakeXYWH(0, 0, 300, 400)));
1585 auto fill = std::make_shared<SolidColorContents>(geom.get());
1586 fill->SetColor(Color::MintCream());
1587
1588 auto filter =
1589 ColorFilterContents::MakeLinearToSrgbFilter(FilterInput::Make(fill));
1590
1591 Entity e;
1592 e.SetTransform(Matrix());
1593
1594 // Confirm that the actual filter coverage matches the expected coverage.
1595 auto actual = filter->GetCoverage(e);
1596 auto expected = Rect::MakeXYWH(0, 0, 300, 400);
1597
1598 ASSERT_TRUE(actual.has_value());
1599 ASSERT_RECT_NEAR(actual.value(), expected);
1600}

References ASSERT_RECT_NEAR, impeller::FilterInput::Make(), impeller::Geometry::MakeFillPath(), impeller::ColorFilterContents::MakeLinearToSrgbFilter(), flutter::DlPath::MakeRect(), impeller::TRect< Scalar >::MakeXYWH(), impeller::Color::MintCream(), and impeller::Entity::SetTransform().

◆ TEST_P() [507/662]

impeller::testing::TEST_P ( EntityTest  ,
MorphologyFilter   
)

Definition at line 1122 of file entity_unittests.cc.

1122 {
1123 auto boston = CreateTextureForFixture("boston.jpg");
1124 ASSERT_TRUE(boston);
1125
1126 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
1127 const char* morphology_type_names[] = {"Dilate", "Erode"};
1128 const FilterContents::MorphType morphology_types[] = {
1129 FilterContents::MorphType::kDilate, FilterContents::MorphType::kErode};
1130 static Color input_color = Color::Black();
1131 // UI state.
1132 static int selected_morphology_type = 0;
1133 static float radius[2] = {20, 20};
1134 static Color cover_color(1, 0, 0, 0.2);
1135 static Color bounds_color(0, 1, 0, 0.1);
1136 static float offset[2] = {500, 400};
1137 static float rotation = 0;
1138 static float scale[2] = {0.65, 0.65};
1139 static float skew[2] = {0, 0};
1140 static float path_rect[4] = {0, 0,
1141 static_cast<float>(boston->GetSize().width),
1142 static_cast<float>(boston->GetSize().height)};
1143 static float effect_transform_scale = 1;
1144
1145 if (IsPlaygroundEnabled()) {
1146 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1147 ImGui::Combo("Morphology type", &selected_morphology_type,
1148 morphology_type_names,
1149 sizeof(morphology_type_names) / sizeof(char*));
1150 ImGui::SliderFloat2("Radius", radius, 0, 200);
1151 ImGui::SliderFloat("Input opacity", &input_color.alpha, 0, 1);
1152 ImGui::ColorEdit4("Cover color", reinterpret_cast<float*>(&cover_color));
1153 ImGui::ColorEdit4("Bounds color ",
1154 reinterpret_cast<float*>(&bounds_color));
1155 ImGui::SliderFloat2("Translation", offset, 0,
1156 pass.GetRenderTargetSize().width);
1157 ImGui::SliderFloat("Rotation", &rotation, 0, kPi * 2);
1158 ImGui::SliderFloat2("Scale", scale, 0, 3);
1159 ImGui::SliderFloat2("Skew", skew, -3, 3);
1160 ImGui::SliderFloat4("Path XYWH", path_rect, -1000, 1000);
1161 ImGui::SliderFloat("Effect transform scale", &effect_transform_scale, 0,
1162 3);
1163 ImGui::End();
1164 }
1165
1166 std::shared_ptr<Contents> input;
1167 Size input_size;
1168
1169 auto input_rect =
1170 Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]);
1171 auto texture = std::make_shared<TextureContents>();
1172 texture->SetSourceRect(Rect::MakeSize(boston->GetSize()));
1173 texture->SetDestinationRect(input_rect);
1174 texture->SetTexture(boston);
1175 texture->SetOpacity(input_color.alpha);
1176
1177 input = texture;
1178 input_size = input_rect.GetSize();
1179
1180 auto contents = FilterContents::MakeMorphology(
1181 FilterInput::Make(input), Radius{radius[0]}, Radius{radius[1]},
1182 morphology_types[selected_morphology_type]);
1183 contents->SetEffectTransform(Matrix::MakeScale(
1184 Vector2{effect_transform_scale, effect_transform_scale}));
1185
1186 auto ctm = Matrix::MakeScale(GetContentScale()) *
1187 Matrix::MakeTranslation(Vector3(offset[0], offset[1])) *
1188 Matrix::MakeRotationZ(Radians(rotation)) *
1189 Matrix::MakeScale(Vector2(scale[0], scale[1])) *
1190 Matrix::MakeSkew(skew[0], skew[1]) *
1191 Matrix::MakeTranslation(-Point(input_size) / 2);
1192
1193 Entity entity;
1194 entity.SetContents(contents);
1195 entity.SetTransform(ctm);
1196
1197 entity.Render(context, pass);
1198
1199 // Renders a red "cover" rectangle that shows the original position of the
1200 // unfiltered input.
1201 Entity cover_entity;
1202 auto geom = Geometry::MakeFillPath(flutter::DlPath::MakeRect(input_rect));
1203 auto cover_contents = std::make_shared<SolidColorContents>(geom.get());
1204 cover_contents->SetColor(cover_color);
1205 cover_entity.SetContents(cover_contents);
1206 cover_entity.SetTransform(ctm);
1207 cover_entity.Render(context, pass);
1208
1209 // Renders a green bounding rect of the target filter.
1210 std::optional<Rect> contents_coverage = contents->GetCoverage(entity);
1211 if (contents_coverage.has_value()) {
1212 std::unique_ptr<Geometry> bounds_geom = Geometry::MakeFillPath(
1213 flutter::DlPath::MakeRect(contents_coverage.value()));
1214 auto bounds_contents =
1215 std::make_shared<SolidColorContents>(bounds_geom.get());
1216 bounds_contents->SetColor(bounds_color);
1217 Entity bounds_entity;
1218 bounds_entity.SetContents(std::move(bounds_contents));
1219 bounds_entity.SetTransform(Matrix());
1220
1221 bounds_entity.Render(context, pass);
1222 }
1223
1224 return true;
1225 };
1226 ASSERT_TRUE(OpenPlaygroundHere(callback));
1227}

References impeller::Color::alpha, impeller::Color::Black(), callback, context, input(), impeller::FilterContents::kDilate, impeller::FilterContents::kErode, flutter::kPi, impeller::FilterInput::Make(), impeller::Geometry::MakeFillPath(), impeller::FilterContents::MakeMorphology(), flutter::DlPath::MakeRect(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeSize(), impeller::Matrix::MakeSkew(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), impeller::Entity::Render(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), and texture.

◆ TEST_P() [508/662]

impeller::testing::TEST_P ( EntityTest  ,
PointFieldGeometryCoverage   
)

Definition at line 2194 of file entity_unittests.cc.

2194 {
2195 std::vector<Point> points = {{10, 20}, {100, 200}};
2196 PointFieldGeometry geometry(points.data(), 2, 5.0, false);
2197 ASSERT_EQ(geometry.GetCoverage(Matrix()), Rect::MakeLTRB(5, 15, 105, 205));
2198 ASSERT_EQ(geometry.GetCoverage(Matrix::MakeTranslation({30, 0, 0})),
2199 Rect::MakeLTRB(35, 15, 135, 205));
2200}

References impeller::PointFieldGeometry::GetCoverage(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeTranslation(), and points.

◆ TEST_P() [509/662]

impeller::testing::TEST_P ( EntityTest  ,
RadialGradientContentsIsOpaque   
)

Definition at line 2136 of file entity_unittests.cc.

2136 {
2137 Matrix matrix;
2138 auto geom = Geometry::MakeRect(Rect::MakeLTRB(0, 0, 10, 10));
2139 RadialGradientContents contents(geom.get());
2140
2141 contents.SetColors({Color::CornflowerBlue()});
2142 EXPECT_TRUE(contents.IsOpaque(matrix));
2143 contents.SetColors({Color::CornflowerBlue().WithAlpha(0.5)});
2144 EXPECT_FALSE(contents.IsOpaque(matrix));
2145 contents.SetColors({Color::CornflowerBlue()});
2146 contents.SetTileMode(Entity::TileMode::kDecal);
2147 EXPECT_FALSE(contents.IsOpaque(matrix));
2148
2149 // Create stroked path that required alpha coverage.
2150 auto geom2 = Geometry::MakeStrokePath(
2151 flutter::DlPathBuilder{}.MoveTo({0, 0}).LineTo({100, 100}).TakePath(),
2152 {.width = 0.05});
2153 RadialGradientContents contents2(geom2.get());
2154 contents2.SetColors({Color::CornflowerBlue()});
2155
2156 EXPECT_FALSE(contents2.IsOpaque(matrix));
2157}

References impeller::Color::CornflowerBlue(), impeller::RadialGradientContents::IsOpaque(), impeller::Entity::kDecal, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Geometry::MakeRect(), impeller::Geometry::MakeStrokePath(), flutter::DlPathBuilder::MoveTo(), impeller::RadialGradientContents::SetColors(), impeller::RadialGradientContents::SetTileMode(), and impeller::Color::WithAlpha().

◆ TEST_P() [510/662]

impeller::testing::TEST_P ( EntityTest  ,
RoundSuperellipseGetPositionBufferFlushes   
)

Definition at line 2973 of file entity_unittests.cc.

2973 {
2975 testing::MockRenderPass mock_pass(GetContext(), target);
2976
2977 auto content_context = std::make_shared<FlushTestContentContext>(
2978 GetContext(), GetTypographerContext(),
2979 std::make_shared<FlushTestAllocator>());
2980 auto geometry =
2981 Geometry::MakeRoundSuperellipse(Rect::MakeLTRB(0, 0, 100, 100), 5);
2982 auto result = geometry->GetPositionBuffer(*content_context, {}, mock_pass);
2983
2984 auto device_buffer = reinterpret_cast<const FlushTestDeviceBuffer*>(
2985 result.vertex_buffer.vertex_buffer.GetBuffer());
2986 EXPECT_TRUE(device_buffer->flush_called());
2987}

References impeller::TRect< Scalar >::MakeLTRB(), impeller::Geometry::MakeRoundSuperellipse(), and target.

◆ TEST_P() [511/662]

impeller::testing::TEST_P ( EntityTest  ,
RRectShadowTest   
)

Definition at line 1439 of file entity_unittests.cc.

1439 {
1440 auto callback = [&](ContentContext& context, RenderPass& pass) {
1441 static Color color = Color::Red();
1442 static float corner_radius = 100;
1443 static float blur_radius = 100;
1444 static bool show_coverage = false;
1445 static Color coverage_color = Color::Green().WithAlpha(0.2);
1446 static PlaygroundPoint top_left_point(Point(200, 200), 30, Color::White());
1447 static PlaygroundPoint bottom_right_point(Point(600, 400), 30,
1448 Color::White());
1449
1450 if (IsPlaygroundEnabled()) {
1451 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1452 ImGui::SliderFloat("Corner radius", &corner_radius, 0, 300);
1453 ImGui::SliderFloat("Blur radius", &blur_radius, 0, 300);
1454 ImGui::ColorEdit4("Color", reinterpret_cast<Scalar*>(&color));
1455 ImGui::Checkbox("Show coverage", &show_coverage);
1456 if (show_coverage) {
1457 ImGui::ColorEdit4("Coverage color",
1458 reinterpret_cast<Scalar*>(&coverage_color));
1459 }
1460 ImGui::End();
1461 }
1462
1463 auto [top_left, bottom_right] =
1464 DrawPlaygroundLine(top_left_point, bottom_right_point);
1465 auto rect =
1466 Rect::MakeLTRB(top_left.x, top_left.y, bottom_right.x, bottom_right.y);
1467
1468 auto contents = std::make_unique<SolidRRectBlurContents>();
1469 contents->SetShape(rect, corner_radius);
1470 contents->SetColor(color);
1471 contents->SetSigma(Radius(blur_radius));
1472
1473 Entity entity;
1474 entity.SetTransform(Matrix::MakeScale(GetContentScale()));
1475 entity.SetContents(std::move(contents));
1476 entity.Render(context, pass);
1477
1478 auto coverage = entity.GetCoverage();
1479 if (show_coverage && coverage.has_value()) {
1480 auto geom = Geometry::MakeFillPath(
1481 flutter::DlPath::MakeRect(entity.GetCoverage().value()));
1482 auto bounds_contents = std::make_unique<SolidColorContents>(geom.get());
1483 bounds_contents->SetColor(coverage_color.Premultiply());
1484 Entity bounds_entity;
1485 bounds_entity.SetContents(std::move(bounds_contents));
1486 bounds_entity.Render(context, pass);
1487 }
1488
1489 return true;
1490 };
1491 ASSERT_TRUE(OpenPlaygroundHere(callback));
1492}

References blur_radius, callback, context, impeller::DrawPlaygroundLine(), impeller::Entity::GetCoverage(), impeller::Color::Green(), impeller::Geometry::MakeFillPath(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRect(), impeller::Matrix::MakeScale(), impeller::Color::Premultiply(), impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), impeller::Color::White(), and impeller::Color::WithAlpha().

◆ TEST_P() [512/662]

impeller::testing::TEST_P ( EntityTest  ,
RuntimeEffect   
)

Definition at line 1800 of file entity_unittests.cc.

1800 {
1801 auto runtime_stages_result =
1802 OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr");
1803 ABSL_ASSERT_OK(runtime_stages_result);
1804 std::shared_ptr<RuntimeStage> runtime_stage =
1805 runtime_stages_result.value()[GetRuntimeStageBackend()];
1806 ASSERT_TRUE(runtime_stage);
1807 ASSERT_TRUE(runtime_stage->IsDirty());
1808
1809 bool expect_dirty = true;
1810
1811 PipelineRef first_pipeline;
1812 std::unique_ptr<Geometry> geom = Geometry::MakeCover();
1813
1814 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
1815 EXPECT_EQ(runtime_stage->IsDirty(), expect_dirty);
1816
1817 auto contents = std::make_shared<RuntimeEffectContents>(geom.get());
1818 contents->SetRuntimeStage(runtime_stage);
1819
1820 struct FragUniforms {
1821 Vector2 iResolution;
1822 Scalar iTime;
1823 } frag_uniforms = {
1824 .iResolution = Vector2(GetWindowSize().width, GetWindowSize().height),
1825 .iTime = static_cast<Scalar>(GetSecondsElapsed()),
1826 };
1827 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1828 uniform_data->resize(sizeof(FragUniforms));
1829 memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
1830 contents->SetUniformData(uniform_data);
1831
1832 Entity entity;
1833 entity.SetContents(contents);
1834 bool result = contents->Render(context, entity, pass);
1835
1836 if (expect_dirty) {
1837 first_pipeline = pass.GetCommands().back().pipeline;
1838 } else {
1839 EXPECT_EQ(pass.GetCommands().back().pipeline, first_pipeline);
1840 }
1841 expect_dirty = false;
1842 return result;
1843 };
1844
1845 // Simulate some renders and hot reloading of the shader.
1846 ContentContext& content_context = GetContentContext();
1847 {
1848 RenderTarget target =
1849 content_context.GetRenderTargetCache()->CreateOffscreen(
1850 *content_context.GetContext(), {1, 1}, 1u);
1851
1852 testing::MockRenderPass mock_pass(GetContext(), target);
1853 callback(content_context, mock_pass);
1854 callback(content_context, mock_pass);
1855
1856 // Dirty the runtime stage.
1857 auto runtime_stages_result =
1858 OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr");
1859 ABSL_ASSERT_OK(runtime_stages_result);
1860 runtime_stage = runtime_stages_result.value()[GetRuntimeStageBackend()];
1861
1862 ASSERT_TRUE(runtime_stage->IsDirty());
1863 expect_dirty = true;
1864
1865 callback(content_context, mock_pass);
1866 }
1867}

References callback, context, impeller::ContentContext::GetContext(), impeller::ContentContext::GetRenderTargetCache(), height, impeller::Geometry::MakeCover(), impeller::Entity::SetContents(), target, and width.

◆ TEST_P() [513/662]

impeller::testing::TEST_P ( EntityTest  ,
RuntimeEffectCanPrecache   
)

Definition at line 1915 of file entity_unittests.cc.

1915 {
1916 auto runtime_stages_result =
1917 OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr");
1918 ABSL_ASSERT_OK(runtime_stages_result);
1919 std::shared_ptr<RuntimeStage> runtime_stage =
1920 runtime_stages_result.value()[GetRuntimeStageBackend()];
1921 ASSERT_TRUE(runtime_stage);
1922 ASSERT_TRUE(runtime_stage->IsDirty());
1923
1924 auto geom = Geometry::MakeCover();
1925 auto contents = std::make_shared<RuntimeEffectContents>(geom.get());
1926 contents->SetRuntimeStage(runtime_stage);
1927
1928 EXPECT_TRUE(contents->BootstrapShader(GetContentContext()));
1929}

References impeller::Geometry::MakeCover().

◆ TEST_P() [514/662]

impeller::testing::TEST_P ( EntityTest  ,
RuntimeEffectCanSuccessfullyRender   
)

Definition at line 1869 of file entity_unittests.cc.

1869 {
1870 auto runtime_stages_result =
1871 OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr");
1872 ABSL_ASSERT_OK(runtime_stages_result);
1873 auto runtime_stage = runtime_stages_result.value()[GetRuntimeStageBackend()];
1874 ASSERT_TRUE(runtime_stage);
1875 ASSERT_TRUE(runtime_stage->IsDirty());
1876
1877 auto geom = Geometry::MakeCover();
1878 auto contents = std::make_shared<RuntimeEffectContents>(geom.get());
1879 contents->SetRuntimeStage(runtime_stage);
1880
1881 struct FragUniforms {
1882 Vector2 iResolution;
1883 Scalar iTime;
1884 } frag_uniforms = {
1885 .iResolution = Vector2(GetWindowSize().width, GetWindowSize().height),
1886 .iTime = static_cast<Scalar>(GetSecondsElapsed()),
1887 };
1888 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1889 uniform_data->resize(sizeof(FragUniforms));
1890 memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
1891 contents->SetUniformData(uniform_data);
1892
1893 Entity entity;
1894 entity.SetContents(contents);
1895
1896 // Create a render target with a depth-stencil, similar to how EntityPass
1897 // does.
1898 RenderTarget target =
1899 GetContentContext().GetRenderTargetCache()->CreateOffscreenMSAA(
1900 *GetContext(), {GetWindowSize().width, GetWindowSize().height}, 1,
1901 "RuntimeEffect Texture");
1902 testing::MockRenderPass pass(GetContext(), target);
1903
1904 ASSERT_TRUE(contents->Render(GetContentContext(), entity, pass));
1905 ASSERT_EQ(pass.GetCommands().size(), 1u);
1906 const auto& command = pass.GetCommands()[0];
1907 ASSERT_TRUE(command.pipeline->GetDescriptor()
1908 .GetDepthStencilAttachmentDescriptor()
1909 .has_value());
1910 ASSERT_TRUE(command.pipeline->GetDescriptor()
1911 .GetFrontStencilAttachmentDescriptor()
1912 .has_value());
1913}

References impeller::RenderPass::GetCommands(), height, impeller::Geometry::MakeCover(), impeller::Entity::SetContents(), target, and width.

◆ TEST_P() [515/662]

impeller::testing::TEST_P ( EntityTest  ,
RuntimeEffectSetsRightSizeWhenUniformIsStruct   
)

Definition at line 1931 of file entity_unittests.cc.

1931 {
1932 if (GetBackend() != PlaygroundBackend::kVulkan) {
1933 GTEST_SKIP() << "Test only applies to Vulkan";
1934 }
1935
1936 auto runtime_stages_result =
1937 OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr");
1938 ABSL_ASSERT_OK(runtime_stages_result);
1939 auto runtime_stage = runtime_stages_result.value()[GetRuntimeStageBackend()];
1940 ASSERT_TRUE(runtime_stage);
1941 ASSERT_TRUE(runtime_stage->IsDirty());
1942
1943 auto geom = Geometry::MakeCover();
1944 auto contents = std::make_shared<RuntimeEffectContents>(geom.get());
1945 contents->SetRuntimeStage(runtime_stage);
1946
1947 struct FragUniforms {
1948 Vector2 iResolution;
1949 Scalar iTime;
1950 } frag_uniforms = {
1951 .iResolution = Vector2(GetWindowSize().width, GetWindowSize().height),
1952 .iTime = static_cast<Scalar>(GetSecondsElapsed()),
1953 };
1954 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1955 uniform_data->resize(sizeof(FragUniforms));
1956 memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
1957
1958 auto buffer_view = RuntimeEffectContents::EmplaceUniform(
1959 uniform_data->data(), GetContentContext().GetTransientsDataBuffer(),
1960 runtime_stage->GetUniforms()[0]);
1961
1962 // 16 bytes:
1963 // 8 bytes for iResolution
1964 // 4 bytes for iTime
1965 // 4 bytes padding
1966 EXPECT_EQ(buffer_view.GetRange().length, 16u);
1967}

References impeller::RuntimeEffectContents::EmplaceUniform(), height, impeller::kVulkan, impeller::Geometry::MakeCover(), and width.

◆ TEST_P() [516/662]

impeller::testing::TEST_P ( EntityTest  ,
SetBlendMode   
)

Definition at line 1229 of file entity_unittests.cc.

1229 {
1230 Entity entity;
1231 ASSERT_EQ(entity.GetBlendMode(), BlendMode::kSrcOver);
1232 entity.SetBlendMode(BlendMode::kClear);
1233 ASSERT_EQ(entity.GetBlendMode(), BlendMode::kClear);
1234}
BlendMode GetBlendMode() const
Definition entity.cc:102
void SetBlendMode(BlendMode blend_mode)
Definition entity.cc:98

References impeller::Entity::GetBlendMode(), impeller::kClear, impeller::kSrcOver, and impeller::Entity::SetBlendMode().

◆ TEST_P() [517/662]

impeller::testing::TEST_P ( EntityTest  ,
SolidColorApplyColorFilter   
)

Definition at line 2820 of file entity_unittests.cc.

2820 {
2821 auto geom = Geometry::MakeCover();
2822 auto contents = SolidColorContents(geom.get());
2823 contents.SetColor(Color::CornflowerBlue().WithAlpha(0.75));
2824 auto result = contents.ApplyColorFilter([](const Color& color) {
2825 return color.Blend(Color::LimeGreen().WithAlpha(0.75), BlendMode::kScreen);
2826 });
2827 ASSERT_TRUE(result);
2828 ASSERT_COLOR_NEAR(contents.GetColor(),
2829 Color(0.424452, 0.828743, 0.79105, 0.9375));
2830}

References ASSERT_COLOR_NEAR, impeller::Color::Blend(), impeller::Color::CornflowerBlue(), impeller::kScreen, impeller::Color::LimeGreen(), and impeller::Geometry::MakeCover().

◆ TEST_P() [518/662]

impeller::testing::TEST_P ( EntityTest  ,
SolidColorContentsIsOpaque   
)

Definition at line 2074 of file entity_unittests.cc.

2074 {
2075 Matrix matrix;
2076 auto geom = Geometry::MakeRect(Rect::MakeLTRB(0, 0, 10, 10));
2077 SolidColorContents contents(geom.get());
2078
2079 contents.SetColor(Color::CornflowerBlue());
2080 EXPECT_TRUE(contents.IsOpaque(matrix));
2081 contents.SetColor(Color::CornflowerBlue().WithAlpha(0.5));
2082 EXPECT_FALSE(contents.IsOpaque(matrix));
2083
2084 // Create stroked path that required alpha coverage.
2085 auto geom2 = Geometry::MakeStrokePath(
2086 flutter::DlPath::MakeLine({0, 0}, {100, 100}), {.width = 0.05});
2087 SolidColorContents contents2(geom2.get());
2088 contents2.SetColor(Color::CornflowerBlue());
2089
2090 EXPECT_FALSE(contents2.IsOpaque(matrix));
2091}
static DlPath MakeLine(const DlPoint a, const DlPoint b)
Definition dl_path.cc:89

References impeller::Color::CornflowerBlue(), impeller::SolidColorContents::IsOpaque(), flutter::DlPath::MakeLine(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Geometry::MakeRect(), impeller::Geometry::MakeStrokePath(), and impeller::SolidColorContents::SetColor().

◆ TEST_P() [519/662]

impeller::testing::TEST_P ( EntityTest  ,
SolidColorContentsStrokeSetMiterLimit   
)

Definition at line 711 of file entity_unittests.cc.

711 {
712 {
713 auto geometry = Geometry::MakeStrokePath(flutter::DlPath{});
714 auto path_geometry = static_cast<StrokePathGeometry*>(geometry.get());
715 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 4);
716 }
717
718 {
719 auto geometry = Geometry::MakeStrokePath(flutter::DlPath{}, //
720 {
721 .width = 1.0f,
722 .miter_limit = 8.0f,
723 });
724 auto path_geometry = static_cast<StrokePathGeometry*>(geometry.get());
725 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 8);
726 }
727
728 {
729 auto geometry = Geometry::MakeStrokePath(flutter::DlPath{}, //
730 {
731 .width = 1.0f,
732 .miter_limit = -1.0f,
733 });
734 auto path_geometry = static_cast<StrokePathGeometry*>(geometry.get());
735 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 4);
736 }
737}
A Geometry that produces fillable vertices representing the stroked outline of a |DlPath| object usin...

References impeller::Geometry::MakeStrokePath().

◆ TEST_P() [520/662]

impeller::testing::TEST_P ( EntityTest  ,
SolidColorContentsStrokeSetStrokeCapsAndJoins   
)

Definition at line 679 of file entity_unittests.cc.

679 {
680 {
681 auto geometry = Geometry::MakeStrokePath(flutter::DlPath{});
682 auto path_geometry = static_cast<StrokePathGeometry*>(geometry.get());
683 // Defaults.
684 ASSERT_EQ(path_geometry->GetStrokeCap(), Cap::kButt);
685 ASSERT_EQ(path_geometry->GetStrokeJoin(), Join::kMiter);
686 }
687
688 {
689 auto geometry = Geometry::MakeStrokePath(flutter::DlPath{}, //
690 {
691 .width = 1.0f,
692 .cap = Cap::kSquare,
693 .miter_limit = 4.0f,
694 });
695 auto path_geometry = static_cast<StrokePathGeometry*>(geometry.get());
696 ASSERT_EQ(path_geometry->GetStrokeCap(), Cap::kSquare);
697 }
698
699 {
700 auto geometry = Geometry::MakeStrokePath(flutter::DlPath{}, //
701 {
702 .width = 1.0f,
703 .cap = Cap::kRound,
704 .miter_limit = 4.0f,
705 });
706 auto path_geometry = static_cast<StrokePathGeometry*>(geometry.get());
707 ASSERT_EQ(path_geometry->GetStrokeCap(), Cap::kRound);
708 }
709}

References impeller::kButt, impeller::kMiter, impeller::kRound, impeller::kSquare, and impeller::Geometry::MakeStrokePath().

◆ TEST_P() [521/662]

impeller::testing::TEST_P ( EntityTest  ,
SolidFillCoverageIsCorrect   
)

Definition at line 1397 of file entity_unittests.cc.

1397 {
1398 // No transform
1399 {
1400 auto expected = Rect::MakeLTRB(100, 110, 200, 220);
1401 auto geom = Geometry::MakeFillPath(flutter::DlPath::MakeRect(expected));
1402 auto fill = std::make_shared<SolidColorContents>(geom.get());
1403 fill->SetColor(Color::CornflowerBlue());
1404
1405 auto coverage = fill->GetCoverage({});
1406 ASSERT_TRUE(coverage.has_value());
1407 ASSERT_RECT_NEAR(coverage.value(), expected);
1408 }
1409
1410 // Entity transform
1411 {
1412 auto geom = Geometry::MakeFillPath(
1413 flutter::DlPath::MakeRect(Rect::MakeLTRB(100, 110, 200, 220)));
1414 auto fill = std::make_shared<SolidColorContents>(geom.get());
1415 fill->SetColor(Color::CornflowerBlue());
1416
1417 Entity entity;
1418 entity.SetTransform(Matrix::MakeTranslation(Vector2(4, 5)));
1419 entity.SetContents(std::move(fill));
1420
1421 auto coverage = entity.GetCoverage();
1422 auto expected = Rect::MakeLTRB(104, 115, 204, 225);
1423 ASSERT_TRUE(coverage.has_value());
1424 ASSERT_RECT_NEAR(coverage.value(), expected);
1425 }
1426
1427 // No coverage for fully transparent colors
1428 {
1429 auto geom = Geometry::MakeFillPath(
1430 flutter::DlPath::MakeRect(Rect::MakeLTRB(100, 110, 200, 220)));
1431 auto fill = std::make_shared<SolidColorContents>(geom.get());
1432 fill->SetColor(Color::WhiteTransparent());
1433
1434 auto coverage = fill->GetCoverage({});
1435 ASSERT_FALSE(coverage.has_value());
1436 }
1437}

References ASSERT_RECT_NEAR, impeller::Color::CornflowerBlue(), impeller::Entity::GetCoverage(), impeller::Geometry::MakeFillPath(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRect(), impeller::Matrix::MakeTranslation(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), and impeller::Color::WhiteTransparent().

◆ TEST_P() [522/662]

impeller::testing::TEST_P ( EntityTest  ,
SolidStrokeCoverageIsCorrect   
)

Definition at line 1302 of file entity_unittests.cc.

1302 {
1303 {
1304 auto geometry = Geometry::MakeStrokePath(
1305 flutter::DlPath::MakeLine({0, 0}, {10, 10}), //
1306 {
1307 .width = 4.0f,
1308 .cap = Cap::kButt,
1309 .join = Join::kBevel,
1310 .miter_limit = 4.0f,
1311 });
1312
1313 Entity entity;
1314 auto contents = std::make_unique<SolidColorContents>(geometry.get());
1315 contents->SetColor(Color::Black());
1316 entity.SetContents(std::move(contents));
1317 auto actual = entity.GetCoverage();
1318 auto expected = Rect::MakeLTRB(-2, -2, 12, 12);
1319
1320 ASSERT_TRUE(actual.has_value());
1321 ASSERT_RECT_NEAR(actual.value(), expected);
1322 }
1323
1324 // Cover the Cap::kSquare case.
1325 {
1326 auto geometry = Geometry::MakeStrokePath(
1327 flutter::DlPath::MakeLine({0, 0}, {10, 10}), //
1328 {
1329 .width = 4.0,
1330 .cap = Cap::kSquare,
1331 .join = Join::kBevel,
1332 .miter_limit = 4.0,
1333 });
1334
1335 Entity entity;
1336 auto contents = std::make_unique<SolidColorContents>(geometry.get());
1337 contents->SetColor(Color::Black());
1338 entity.SetContents(std::move(contents));
1339 auto actual = entity.GetCoverage();
1340 auto expected =
1341 Rect::MakeLTRB(-sqrt(8), -sqrt(8), 10 + sqrt(8), 10 + sqrt(8));
1342
1343 ASSERT_TRUE(actual.has_value());
1344 ASSERT_RECT_NEAR(actual.value(), expected);
1345 }
1346
1347 // Cover the Join::kMiter case.
1348 {
1349 auto geometry = Geometry::MakeStrokePath(
1350 flutter::DlPath::MakeLine({0, 0}, {10, 10}), //
1351 {
1352 .width = 4.0f,
1353 .cap = Cap::kSquare,
1354 .join = Join::kMiter,
1355 .miter_limit = 2.0f,
1356 });
1357
1358 Entity entity;
1359 auto contents = std::make_unique<SolidColorContents>(geometry.get());
1360 contents->SetColor(Color::Black());
1361 entity.SetContents(std::move(contents));
1362 auto actual = entity.GetCoverage();
1363 auto expected = Rect::MakeLTRB(-4, -4, 14, 14);
1364
1365 ASSERT_TRUE(actual.has_value());
1366 ASSERT_RECT_NEAR(actual.value(), expected);
1367 }
1368}

References ASSERT_RECT_NEAR, impeller::Color::Black(), impeller::kBevel, impeller::kButt, impeller::kMiter, impeller::kSquare, flutter::DlPath::MakeLine(), impeller::TRect< Scalar >::MakeLTRB(), and impeller::Geometry::MakeStrokePath().

◆ TEST_P() [523/662]

impeller::testing::TEST_P ( EntityTest  ,
SpecializationConstantsAreAppliedToVariants   
)

Definition at line 2228 of file entity_unittests.cc.

2228 {
2229 ContentContext& content_context = GetContentContext();
2230
2231 auto default_gyph = content_context.GetGlyphAtlasPipeline({
2232 .color_attachment_pixel_format = PixelFormat::kR8G8B8A8UNormInt,
2233 .has_depth_stencil_attachments = false,
2234 });
2235 auto alt_gyph = content_context.GetGlyphAtlasPipeline(
2236 {.color_attachment_pixel_format = PixelFormat::kR8G8B8A8UNormInt,
2237 .has_depth_stencil_attachments = true});
2238
2239 EXPECT_NE(default_gyph, alt_gyph);
2240 EXPECT_EQ(default_gyph->GetDescriptor().GetSpecializationConstants(),
2241 alt_gyph->GetDescriptor().GetSpecializationConstants());
2242
2243 auto use_a8 = GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() ==
2244 PixelFormat::kA8UNormInt;
2245
2246 std::vector<Scalar> expected_constants = {static_cast<Scalar>(use_a8)};
2247 EXPECT_EQ(default_gyph->GetDescriptor().GetSpecializationConstants(),
2248 expected_constants);
2249}
PipelineRef GetGlyphAtlasPipeline(ContentContextOptions opts) const

References impeller::ContentContext::GetGlyphAtlasPipeline(), impeller::kA8UNormInt, and impeller::kR8G8B8A8UNormInt.

◆ TEST_P() [524/662]

impeller::testing::TEST_P ( EntityTest  ,
SrgbToLinearFilter   
)

Definition at line 1654 of file entity_unittests.cc.

1654 {
1655 auto image = CreateTextureForFixture("embarcadero.jpg");
1656 ASSERT_TRUE(image);
1657
1658 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
1659 auto filtered =
1660 ColorFilterContents::MakeSrgbToLinearFilter(FilterInput::Make(image));
1661
1662 // Define the entity that will serve as the control image as a Gaussian blur
1663 // filter with no filter at all.
1664 Entity entity_left;
1665 entity_left.SetTransform(Matrix::MakeScale(GetContentScale()) *
1666 Matrix::MakeTranslation({100, 300}) *
1667 Matrix::MakeScale(Vector2{0.5, 0.5}));
1668 auto unfiltered = FilterContents::MakeGaussianBlur(FilterInput::Make(image),
1669 Sigma{0}, Sigma{0});
1670 entity_left.SetContents(unfiltered);
1671
1672 // Define the entity that will be filtered from sRGB to linear.
1673 Entity entity_right;
1674 entity_right.SetTransform(Matrix::MakeScale(GetContentScale()) *
1675 Matrix::MakeTranslation({500, 300}) *
1676 Matrix::MakeScale(Vector2{0.5, 0.5}));
1677 entity_right.SetContents(filtered);
1678 return entity_left.Render(context, pass) &&
1679 entity_right.Render(context, pass);
1680 };
1681
1682 ASSERT_TRUE(OpenPlaygroundHere(callback));
1683}

References callback, context, image, impeller::FilterInput::Make(), impeller::FilterContents::MakeGaussianBlur(), impeller::Matrix::MakeScale(), impeller::ColorFilterContents::MakeSrgbToLinearFilter(), impeller::Matrix::MakeTranslation(), impeller::Entity::Render(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [525/662]

impeller::testing::TEST_P ( EntityTest  ,
SrgbToLinearFilterCoverageIsCorrect   
)

Definition at line 1633 of file entity_unittests.cc.

1633 {
1634 // Set up a simple color background.
1635 auto geom = Geometry::MakeFillPath(
1636 flutter::DlPath::MakeRect(Rect::MakeXYWH(0, 0, 300, 400)));
1637 auto fill = std::make_shared<SolidColorContents>(geom.get());
1638 fill->SetColor(Color::DeepPink());
1639
1640 auto filter =
1641 ColorFilterContents::MakeSrgbToLinearFilter(FilterInput::Make(fill));
1642
1643 Entity e;
1644 e.SetTransform(Matrix());
1645
1646 // Confirm that the actual filter coverage matches the expected coverage.
1647 auto actual = filter->GetCoverage(e);
1648 auto expected = Rect::MakeXYWH(0, 0, 300, 400);
1649
1650 ASSERT_TRUE(actual.has_value());
1651 ASSERT_RECT_NEAR(actual.value(), expected);
1652}

References ASSERT_RECT_NEAR, impeller::Color::DeepPink(), impeller::FilterInput::Make(), impeller::Geometry::MakeFillPath(), flutter::DlPath::MakeRect(), impeller::ColorFilterContents::MakeSrgbToLinearFilter(), impeller::TRect< Scalar >::MakeXYWH(), and impeller::Entity::SetTransform().

◆ TEST_P() [526/662]

impeller::testing::TEST_P ( EntityTest  ,
StrokeArcGeometryGetPositionBufferReturnsExpectedMode   
)

Definition at line 2342 of file entity_unittests.cc.

2342 {
2344 testing::MockRenderPass mock_pass(GetContext(), target);
2345 Rect oval_bounds = Rect::MakeLTRB(100, 100, 200, 200);
2346
2347 // Butt caps never overlap
2348 {
2349 StrokeParameters stroke = {.width = 50.0f, .cap = Cap::kButt};
2350 for (auto start = 0; start < 360; start += 60) {
2351 for (auto sweep = 0; sweep < 360; sweep += 12) {
2352 auto geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
2353 Degrees(sweep), stroke);
2354
2355 GeometryResult result =
2356 geometry->GetPositionBuffer(GetContentContext(), {}, mock_pass);
2357
2358 EXPECT_EQ(result.mode, GeometryResult::Mode::kNormal)
2359 << "start: " << start << " sweep: " << sweep;
2360 }
2361 }
2362 }
2363
2364 // Round caps with 10 stroke width overlap starting at 348.6 degrees
2365 {
2366 StrokeParameters stroke = {.width = 10.0f, .cap = Cap::kRound};
2367 for (auto start = 0; start < 360; start += 60) {
2368 for (auto sweep = 0; sweep < 360; sweep += 12) {
2369 auto geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
2370 Degrees(sweep), stroke);
2371
2372 GeometryResult result =
2373 geometry->GetPositionBuffer(GetContentContext(), {}, mock_pass);
2374
2375 if (sweep < 348.6) {
2376 EXPECT_EQ(result.mode, GeometryResult::Mode::kNormal)
2377 << "start: " << start << " sweep: " << sweep;
2378 } else {
2379 EXPECT_EQ(result.mode, GeometryResult::Mode::kPreventOverdraw)
2380 << "start: " << start << " sweep: " << sweep;
2381 }
2382 }
2383 }
2384 }
2385
2386 // Round caps with 50 stroke width overlap starting at 300.1 degrees
2387 {
2388 StrokeParameters stroke = {.width = 50.0f, .cap = Cap::kRound};
2389 for (auto start = 0; start < 360; start += 60) {
2390 for (auto sweep = 0; sweep < 360; sweep += 12) {
2391 auto geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
2392 Degrees(sweep), stroke);
2393
2394 GeometryResult result =
2395 geometry->GetPositionBuffer(GetContentContext(), {}, mock_pass);
2396
2397 if (sweep < 300.0) {
2398 EXPECT_EQ(result.mode, GeometryResult::Mode::kNormal)
2399 << "start: " << start << " sweep: " << sweep;
2400 } else {
2401 EXPECT_EQ(result.mode, GeometryResult::Mode::kPreventOverdraw)
2402 << "start: " << start << " sweep: " << sweep;
2403 }
2404 }
2405 }
2406 }
2407
2408 // Square caps with 10 stroke width overlap starting at 347.4 degrees
2409 {
2410 StrokeParameters stroke = {.width = 10.0f, .cap = Cap::kSquare};
2411 for (auto start = 0; start < 360; start += 60) {
2412 for (auto sweep = 0; sweep < 360; sweep += 12) {
2413 auto geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
2414 Degrees(sweep), stroke);
2415
2416 GeometryResult result =
2417 geometry->GetPositionBuffer(GetContentContext(), {}, mock_pass);
2418
2419 if (sweep < 347.4) {
2420 EXPECT_EQ(result.mode, GeometryResult::Mode::kNormal)
2421 << "start: " << start << " sweep: " << sweep;
2422 } else {
2423 EXPECT_EQ(result.mode, GeometryResult::Mode::kPreventOverdraw)
2424 << "start: " << start << " sweep: " << sweep;
2425 }
2426 }
2427 }
2428 }
2429
2430 // Square caps with 50 stroke width overlap starting at 270.1 degrees
2431 {
2432 StrokeParameters stroke = {.width = 50.0f, .cap = Cap::kSquare};
2433 for (auto start = 0; start < 360; start += 60) {
2434 for (auto sweep = 0; sweep < 360; sweep += 12) {
2435 auto geometry = Geometry::MakeStrokedArc(oval_bounds, Degrees(start),
2436 Degrees(sweep), stroke);
2437
2438 GeometryResult result =
2439 geometry->GetPositionBuffer(GetContentContext(), {}, mock_pass);
2440
2441 if (sweep < 270.1) {
2442 EXPECT_EQ(result.mode, GeometryResult::Mode::kNormal)
2443 << "start: " << start << " sweep: " << sweep;
2444 } else {
2445 EXPECT_EQ(result.mode, GeometryResult::Mode::kPreventOverdraw)
2446 << "start: " << start << " sweep: " << sweep;
2447 }
2448 }
2449 }
2450 }
2451}

References impeller::kButt, impeller::GeometryResult::kNormal, impeller::GeometryResult::kPreventOverdraw, impeller::kRound, impeller::kSquare, impeller::TRect< Scalar >::MakeLTRB(), impeller::Geometry::MakeStrokedArc(), impeller::GeometryResult::mode, start, target, and impeller::StrokeParameters::width.

◆ TEST_P() [527/662]

impeller::testing::TEST_P ( EntityTest  ,
StrokeCapAndJoinTest   
)

Definition at line 196 of file entity_unittests.cc.

196 {
197 const Point padding(300, 250);
198 const Point margin(140, 180);
199
200 auto callback = [&](ContentContext& context, RenderPass& pass) {
201 // Slightly above sqrt(2) by default, so that right angles are just below
202 // the limit and acute angles are over the limit (causing them to get
203 // beveled).
204 static Scalar miter_limit = 1.41421357;
205 static Scalar width = 30;
206
207 if (IsPlaygroundEnabled()) {
208 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
209 ImGui::SliderFloat("Miter limit", &miter_limit, 0, 30);
210 ImGui::SliderFloat("Stroke width", &width, 0, 100);
211 if (ImGui::Button("Reset")) {
212 miter_limit = 1.41421357;
213 width = 30;
214 }
215 ImGui::End();
216 }
217
218 auto world_matrix = Matrix::MakeScale(GetContentScale());
219 auto render_path = [width = width, &context, &pass, &world_matrix](
220 const flutter::DlPath& path, Cap cap, Join join) {
221 std::unique_ptr<Geometry> geom =
222 Geometry::MakeStrokePath(path, {
223 .width = width,
224 .cap = cap,
225 .join = join,
226 .miter_limit = miter_limit,
227 });
228 auto contents = std::make_unique<SolidColorContents>(geom.get());
229 contents->SetColor(Color::Red());
230
231 Entity entity;
232 entity.SetTransform(world_matrix);
233 entity.SetContents(std::move(contents));
234
235 auto coverage = entity.GetCoverage();
236 if (coverage.has_value()) {
237 std::unique_ptr<Geometry> geom = Geometry::MakeFillPath(
238 flutter::DlPath::MakeRect(entity.GetCoverage().value()));
239
240 auto bounds_contents = std::make_unique<SolidColorContents>(geom.get());
241 bounds_contents->SetColor(Color::Green().WithAlpha(0.5));
242 Entity bounds_entity;
243 bounds_entity.SetContents(std::move(bounds_contents));
244 bounds_entity.Render(context, pass);
245 }
246
247 entity.Render(context, pass);
248 };
249
250 const Point a_def(0, 0), b_def(0, 100), c_def(150, 0), d_def(150, -100),
251 e_def(75, 75);
252 const Scalar r = 30;
253 // Cap::kButt demo.
254 {
255 Point off = Point(0, 0) * padding + margin;
256 static PlaygroundPoint point_a(off + a_def, r, Color::Black());
257 static PlaygroundPoint point_b(off + b_def, r, Color::White());
258 auto [a, b] = DrawPlaygroundLine(point_a, point_b);
259 static PlaygroundPoint point_c(off + c_def, r, Color::Black());
260 static PlaygroundPoint point_d(off + d_def, r, Color::White());
261 auto [c, d] = DrawPlaygroundLine(point_c, point_d);
262 render_path(flutter::DlPathBuilder{} //
263 .MoveTo(a)
264 .CubicCurveTo(b, d, c)
265 .TakePath(),
266 Cap::kButt, Join::kBevel);
267 }
268
269 // Cap::kSquare demo.
270 {
271 Point off = Point(1, 0) * padding + margin;
272 static PlaygroundPoint point_a(off + a_def, r, Color::Black());
273 static PlaygroundPoint point_b(off + b_def, r, Color::White());
274 auto [a, b] = DrawPlaygroundLine(point_a, point_b);
275 static PlaygroundPoint point_c(off + c_def, r, Color::Black());
276 static PlaygroundPoint point_d(off + d_def, r, Color::White());
277 auto [c, d] = DrawPlaygroundLine(point_c, point_d);
278 render_path(flutter::DlPathBuilder{} //
279 .MoveTo(a)
280 .CubicCurveTo(b, d, c)
281 .TakePath(),
282 Cap::kSquare, Join::kBevel);
283 }
284
285 // Cap::kRound demo.
286 {
287 Point off = Point(2, 0) * padding + margin;
288 static PlaygroundPoint point_a(off + a_def, r, Color::Black());
289 static PlaygroundPoint point_b(off + b_def, r, Color::White());
290 auto [a, b] = DrawPlaygroundLine(point_a, point_b);
291 static PlaygroundPoint point_c(off + c_def, r, Color::Black());
292 static PlaygroundPoint point_d(off + d_def, r, Color::White());
293 auto [c, d] = DrawPlaygroundLine(point_c, point_d);
294 render_path(flutter::DlPathBuilder{} //
295 .MoveTo(a)
296 .CubicCurveTo(b, d, c)
297 .TakePath(),
298 Cap::kRound, Join::kBevel);
299 }
300
301 // Join::kBevel demo.
302 {
303 Point off = Point(0, 1) * padding + margin;
304 static PlaygroundPoint point_a =
305 PlaygroundPoint(off + a_def, r, Color::White());
306 static PlaygroundPoint point_b =
307 PlaygroundPoint(off + e_def, r, Color::White());
308 static PlaygroundPoint point_c =
309 PlaygroundPoint(off + c_def, r, Color::White());
310 Point a = DrawPlaygroundPoint(point_a);
311 Point b = DrawPlaygroundPoint(point_b);
312 Point c = DrawPlaygroundPoint(point_c);
313 render_path(flutter::DlPathBuilder{} //
314 .MoveTo(a)
315 .LineTo(b)
316 .LineTo(c)
317 .Close()
318 .TakePath(),
319 Cap::kButt, Join::kBevel);
320 }
321
322 // Join::kMiter demo.
323 {
324 Point off = Point(1, 1) * padding + margin;
325 static PlaygroundPoint point_a(off + a_def, r, Color::White());
326 static PlaygroundPoint point_b(off + e_def, r, Color::White());
327 static PlaygroundPoint point_c(off + c_def, r, Color::White());
328 Point a = DrawPlaygroundPoint(point_a);
329 Point b = DrawPlaygroundPoint(point_b);
330 Point c = DrawPlaygroundPoint(point_c);
331 render_path(flutter::DlPathBuilder{} //
332 .MoveTo(a)
333 .LineTo(b)
334 .LineTo(c)
335 .Close()
336 .TakePath(),
337 Cap::kButt, Join::kMiter);
338 }
339
340 // Join::kRound demo.
341 {
342 Point off = Point(2, 1) * padding + margin;
343 static PlaygroundPoint point_a(off + a_def, r, Color::White());
344 static PlaygroundPoint point_b(off + e_def, r, Color::White());
345 static PlaygroundPoint point_c(off + c_def, r, Color::White());
346 Point a = DrawPlaygroundPoint(point_a);
347 Point b = DrawPlaygroundPoint(point_b);
348 Point c = DrawPlaygroundPoint(point_c);
349 render_path(flutter::DlPathBuilder{} //
350 .MoveTo(a)
351 .LineTo(b)
352 .LineTo(c)
353 .Close()
354 .TakePath(),
355 Cap::kButt, Join::kRound);
356 }
357
358 return true;
359 };
360 ASSERT_TRUE(OpenPlaygroundHere(callback));
361}
Vector2 padding
The halo padding in source space.

References impeller::Color::Black(), c, callback, impeller::Close(), context, d, impeller::DrawPlaygroundLine(), impeller::DrawPlaygroundPoint(), impeller::Entity::GetCoverage(), impeller::Color::Green(), impeller::kBevel, impeller::kButt, impeller::kMiter, impeller::kRound, impeller::kSquare, impeller::LineTo(), impeller::Geometry::MakeFillPath(), flutter::DlPath::MakeRect(), impeller::Matrix::MakeScale(), impeller::Geometry::MakeStrokePath(), flutter::DlPathBuilder::MoveTo(), padding, flutter::path, impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), impeller::Color::White(), and width.

◆ TEST_P() [528/662]

impeller::testing::TEST_P ( EntityTest  ,
StrokeWithTextureContents   
)

Definition at line 130 of file entity_unittests.cc.

130 {
131 auto bridge = CreateTextureForFixture("bay_bridge.jpg");
133 .MoveTo({100, 100})
134 .LineTo({100, 200})
135 .MoveTo({100, 300})
136 .LineTo({100, 400})
137 .MoveTo({100, 500})
138 .LineTo({100, 600})
139 .TakePath();
140
141 Entity entity;
142 entity.SetTransform(Matrix::MakeScale(GetContentScale()));
143 std::unique_ptr<Geometry> geom =
144 Geometry::MakeStrokePath(path, {.width = 100.0f});
145 auto contents = std::make_unique<TiledTextureContents>(geom.get());
146 contents->SetTexture(bridge);
147 contents->SetTileModes(Entity::TileMode::kClamp, Entity::TileMode::kClamp);
148 entity.SetContents(std::move(contents));
149 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
150}

References impeller::Entity::kClamp, impeller::LineTo(), impeller::Matrix::MakeScale(), impeller::Geometry::MakeStrokePath(), flutter::DlPathBuilder::MoveTo(), impeller::MoveTo(), flutter::path, impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [529/662]

impeller::testing::TEST_P ( EntityTest  ,
SweepGradientContentsIsOpaque   
)

Definition at line 2159 of file entity_unittests.cc.

2159 {
2160 Matrix matrix;
2161 auto geom = Geometry::MakeRect(Rect::MakeLTRB(0, 0, 10, 10));
2162 SweepGradientContents contents(geom.get());
2163
2164 contents.SetColors({Color::CornflowerBlue()});
2165 EXPECT_TRUE(contents.IsOpaque(matrix));
2166 contents.SetColors({Color::CornflowerBlue().WithAlpha(0.5)});
2167 EXPECT_FALSE(contents.IsOpaque(matrix));
2168 contents.SetColors({Color::CornflowerBlue()});
2169 contents.SetTileMode(Entity::TileMode::kDecal);
2170 EXPECT_FALSE(contents.IsOpaque(matrix));
2171
2172 // Create stroked path that required alpha coverage.
2173 auto geom2 = Geometry::MakeStrokePath(
2174 flutter::DlPathBuilder{}.MoveTo({0, 0}).LineTo({100, 100}).TakePath(),
2175 {.width = 0.05f});
2176 SweepGradientContents contents2(geom2.get());
2177 contents2.SetColors({Color::CornflowerBlue()});
2178
2179 EXPECT_FALSE(contents2.IsOpaque(matrix));
2180}

References impeller::Color::CornflowerBlue(), impeller::SweepGradientContents::IsOpaque(), impeller::Entity::kDecal, impeller::LineTo(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Geometry::MakeRect(), impeller::Geometry::MakeStrokePath(), flutter::DlPathBuilder::MoveTo(), impeller::SweepGradientContents::SetColors(), impeller::SweepGradientContents::SetTileMode(), and impeller::Color::WithAlpha().

◆ TEST_P() [530/662]

impeller::testing::TEST_P ( EntityTest  ,
TextContentsCeilsGlyphScaleToDecimal   
)

Definition at line 2220 of file entity_unittests.cc.

2220 {
2221 ASSERT_EQ(TextFrame::RoundScaledFontSize(0.4321111f), Rational(43, 100));
2222 ASSERT_EQ(TextFrame::RoundScaledFontSize(0.5321111f), Rational(53, 100));
2223 ASSERT_EQ(TextFrame::RoundScaledFontSize(2.1f), Rational(21, 10));
2224 ASSERT_EQ(TextFrame::RoundScaledFontSize(0.0f), Rational(0, 1));
2225 ASSERT_EQ(TextFrame::RoundScaledFontSize(100000000.0f), Rational(48, 1));
2226}

References impeller::TextFrame::RoundScaledFontSize().

◆ TEST_P() [531/662]

impeller::testing::TEST_P ( EntityTest  ,
ThreeStrokesInOnePath   
)

Definition at line 110 of file entity_unittests.cc.

110 {
112 .MoveTo({100, 100})
113 .LineTo({100, 200})
114 .MoveTo({100, 300})
115 .LineTo({100, 400})
116 .MoveTo({100, 500})
117 .LineTo({100, 600})
118 .TakePath();
119
120 Entity entity;
121 entity.SetTransform(Matrix::MakeScale(GetContentScale()));
122 std::unique_ptr<Geometry> geom =
123 Geometry::MakeStrokePath(path, {.width = 5.0f});
124 auto contents = std::make_unique<SolidColorContents>(geom.get());
125 contents->SetColor(Color::Red());
126 entity.SetContents(std::move(contents));
127 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
128}

References impeller::LineTo(), impeller::Matrix::MakeScale(), impeller::Geometry::MakeStrokePath(), flutter::DlPathBuilder::MoveTo(), impeller::MoveTo(), flutter::path, impeller::Color::Red(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [532/662]

impeller::testing::TEST_P ( EntityTest  ,
TiledTextureContentsIsOpaque   
)

Definition at line 2182 of file entity_unittests.cc.

2182 {
2183 Matrix matrix;
2184 auto bay_bridge = CreateTextureForFixture("bay_bridge.jpg");
2185 auto geom = Geometry::MakeCover();
2186 TiledTextureContents contents(geom.get());
2187 contents.SetTexture(bay_bridge);
2188 // This is a placeholder test. Images currently never decompress as opaque
2189 // (whether in Flutter or the playground), and so this should currently always
2190 // return false in practice.
2191 EXPECT_FALSE(contents.IsOpaque(matrix));
2192}

References impeller::TiledTextureContents::IsOpaque(), impeller::Geometry::MakeCover(), and impeller::TiledTextureContents::SetTexture().

◆ TEST_P() [533/662]

impeller::testing::TEST_P ( EntityTest  ,
TiledTextureContentsRendersWithCorrectPipeline   
)

Definition at line 21 of file tiled_texture_contents_unittests.cc.

21 {
22 TextureDescriptor texture_desc;
23 texture_desc.size = {100, 100};
24 texture_desc.type = TextureType::kTexture2D;
25 texture_desc.format = PixelFormat::kR8G8B8A8UNormInt;
26 texture_desc.storage_mode = StorageMode::kDevicePrivate;
27 auto texture =
28 GetContext()->GetResourceAllocator()->CreateTexture(texture_desc);
29
30 auto geom = Geometry::MakeCover();
31 TiledTextureContents contents(geom.get());
32 contents.SetTexture(texture);
33
34 ContentContext& content_context = GetContentContext();
35 auto buffer = content_context.GetContext()->CreateCommandBuffer();
36 auto render_target =
37 GetContentContext().GetRenderTargetCache()->CreateOffscreenMSAA(
38 *content_context.GetContext(), {100, 100},
39 /*mip_count=*/1);
40 auto render_pass = buffer->CreateRenderPass(render_target);
41 auto recording_pass = std::make_shared<RecordingRenderPass>(
42 render_pass, GetContext(), render_target);
43
44 ASSERT_TRUE(contents.Render(GetContentContext(), {}, *recording_pass));
45 const std::vector<Command>& commands = recording_pass->GetCommands();
46
47 ASSERT_EQ(commands.size(), 1u);
48#ifdef IMPELLER_DEBUG
49 EXPECT_TRUE(commands[0].pipeline->GetDescriptor().GetLabel().find(
50 "TextureFill Pipeline") != std::string::npos);
51#endif // IMPELLER_DEBUG
52 auto options = OptionsFromPassAndEntity(*recording_pass, {});
53 options.primitive_type = PrimitiveType::kTriangleStrip;
54 EXPECT_EQ(commands[0].pipeline,
55 GetContentContext().GetTiledTexturePipeline(options));
56
57 if (GetParam() == PlaygroundBackend::kMetal) {
58 recording_pass->EncodeCommands();
59 }
60}

References flutter::buffer, impeller::TextureDescriptor::format, impeller::ContentContext::GetContext(), impeller::kDevicePrivate, impeller::kMetal, impeller::kR8G8B8A8UNormInt, impeller::kTexture2D, impeller::kTriangleStrip, impeller::Geometry::MakeCover(), impeller::OptionsFromPassAndEntity(), pipeline, impeller::ContentContextOptions::primitive_type, impeller::TiledTextureContents::Render(), render_pass, impeller::TiledTextureContents::SetTexture(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, texture, and impeller::TextureDescriptor::type.

◆ TEST_P() [534/662]

impeller::testing::TEST_P ( EntityTest  ,
TiledTextureContentsRendersWithCorrectPipelineExternalOES   
)

Definition at line 64 of file tiled_texture_contents_unittests.cc.

64 {
65 if (GetParam() != PlaygroundBackend::kOpenGLES &&
66 GetParam() != PlaygroundBackend::kOpenGLESSDF) {
67 GTEST_SKIP()
68 << "External OES textures are only valid for the OpenGLES backend.";
69 }
70
71 TextureDescriptor texture_desc;
72 texture_desc.size = {100, 100};
73 texture_desc.type = TextureType::kTextureExternalOES;
74 texture_desc.format = PixelFormat::kR8G8B8A8UNormInt;
75 texture_desc.storage_mode = StorageMode::kDevicePrivate;
76 auto texture =
77 GetContext()->GetResourceAllocator()->CreateTexture(texture_desc);
78 auto contents = TextureContents::MakeRect(Rect::MakeSize(texture->GetSize()));
79 contents->SetTexture(texture);
80 contents->SetSourceRect(Rect::MakeSize(texture->GetSize()));
81 contents->SetStrictSourceRect(false);
82
83 ContentContext& content_context = GetContentContext();
84 auto buffer = content_context.GetContext()->CreateCommandBuffer();
85 auto render_target =
86 GetContentContext().GetRenderTargetCache()->CreateOffscreenMSAA(
87 *content_context.GetContext(), {100, 100},
88 /*mip_count=*/1);
89 auto render_pass = buffer->CreateRenderPass(render_target);
90
91 ASSERT_TRUE(contents->Render(GetContentContext(), {}, *render_pass));
92 const std::vector<Command>& commands = render_pass->GetCommands();
93
94 ASSERT_EQ(commands.size(), 1u);
95
96 auto options = OptionsFromPassAndEntity(*render_pass, {});
97 options.primitive_type = PrimitiveType::kTriangleStrip;
98 EXPECT_EQ(commands[0].pipeline,
99 GetContentContext().GetTiledTextureExternalPipeline(options));
100}
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition contents.cc:34

References flutter::buffer, impeller::TextureDescriptor::format, impeller::ContentContext::GetContext(), impeller::kDevicePrivate, impeller::kOpenGLES, impeller::kOpenGLESSDF, impeller::kR8G8B8A8UNormInt, impeller::kTextureExternalOES, impeller::kTriangleStrip, impeller::TextureContents::MakeRect(), impeller::TRect< Scalar >::MakeSize(), impeller::OptionsFromPassAndEntity(), pipeline, impeller::ContentContextOptions::primitive_type, render_pass, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, texture, and impeller::TextureDescriptor::type.

◆ TEST_P() [535/662]

impeller::testing::TEST_P ( EntityTest  ,
TriangleInsideASquare   
)

Definition at line 152 of file entity_unittests.cc.

152 {
153 auto callback = [&](ContentContext& context, RenderPass& pass) {
154 Point offset(100, 100);
155
156 static PlaygroundPoint point_a(Point(10, 10) + offset, 20, Color::White());
157 Point a = DrawPlaygroundPoint(point_a);
158 static PlaygroundPoint point_b(Point(210, 10) + offset, 20, Color::White());
159 Point b = DrawPlaygroundPoint(point_b);
160 static PlaygroundPoint point_c(Point(210, 210) + offset, 20,
161 Color::White());
162 Point c = DrawPlaygroundPoint(point_c);
163 static PlaygroundPoint point_d(Point(10, 210) + offset, 20, Color::White());
164 Point d = DrawPlaygroundPoint(point_d);
165 static PlaygroundPoint point_e(Point(50, 50) + offset, 20, Color::White());
166 Point e = DrawPlaygroundPoint(point_e);
167 static PlaygroundPoint point_f(Point(100, 50) + offset, 20, Color::White());
168 Point f = DrawPlaygroundPoint(point_f);
169 static PlaygroundPoint point_g(Point(50, 150) + offset, 20, Color::White());
170 Point g = DrawPlaygroundPoint(point_g);
172 .MoveTo(a)
173 .LineTo(b)
174 .LineTo(c)
175 .LineTo(d)
176 .Close()
177 .MoveTo(e)
178 .LineTo(f)
179 .LineTo(g)
180 .Close()
181 .TakePath();
182
183 Entity entity;
184 entity.SetTransform(Matrix::MakeScale(GetContentScale()));
185 std::unique_ptr<Geometry> geom =
186 Geometry::MakeStrokePath(path, {.width = 20.0});
187 auto contents = std::make_unique<SolidColorContents>(geom.get());
188 contents->SetColor(Color::Red());
189 entity.SetContents(std::move(contents));
190
191 return entity.Render(context, pass);
192 };
193 ASSERT_TRUE(OpenPlaygroundHere(callback));
194}

References c, callback, flutter::DlPathBuilder::Close(), context, d, impeller::DrawPlaygroundPoint(), flutter::DlPathBuilder::LineTo(), impeller::Matrix::MakeScale(), impeller::Geometry::MakeStrokePath(), flutter::DlPathBuilder::MoveTo(), flutter::path, impeller::Color::Red(), impeller::Entity::Render(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), flutter::DlPathBuilder::TakePath(), and impeller::Color::White().

◆ TEST_P() [536/662]

impeller::testing::TEST_P ( EntityTest  ,
YUVToRGBFilter   
)

Definition at line 1763 of file entity_unittests.cc.

1763 {
1764 if (GetParam() != PlaygroundBackend::kMetal &&
1765 GetParam() != PlaygroundBackend::kMetalSDF) {
1766 // @see (114588) : Support YUV to RGB filter on OpenGLES backend.
1767 // The issue was closed as low priority as the support is only really
1768 // needed for iOS. Also, Vulkan isn't supported either.
1769 GTEST_SKIP() << "YUV to RGB filter is only supported on Metal backends.";
1770 }
1771
1772 auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
1773 YUVColorSpace yuv_color_space_array[2]{YUVColorSpace::kBT601FullRange,
1774 YUVColorSpace::kBT601LimitedRange};
1775 for (int i = 0; i < 2; i++) {
1776 auto yuv_color_space = yuv_color_space_array[i];
1777 auto textures =
1778 CreateTestYUVTextures(GetContext().get(), yuv_color_space);
1779 auto filter_contents = FilterContents::MakeYUVToRGBFilter(
1780 textures[0], textures[1], yuv_color_space);
1781 Entity filter_entity;
1782 filter_entity.SetContents(filter_contents);
1783 auto snapshot =
1784 filter_contents->RenderToSnapshot(context, filter_entity, {});
1785
1786 Entity entity;
1787 auto contents = TextureContents::MakeRect(Rect::MakeLTRB(0, 0, 256, 256));
1788 contents->SetTexture(snapshot->texture);
1789 contents->SetSourceRect(Rect::MakeSize(snapshot->texture->GetSize()));
1790 entity.SetContents(contents);
1791 entity.SetTransform(
1792 Matrix::MakeTranslation({static_cast<Scalar>(100 + 400 * i), 300}));
1793 entity.Render(context, pass);
1794 }
1795 return true;
1796 };
1797 ASSERT_TRUE(OpenPlaygroundHere(callback));
1798}
YUVColorSpace
Definition color.h:54

References callback, context, CreateTestYUVTextures(), i, impeller::kBT601FullRange, impeller::kBT601LimitedRange, impeller::kMetal, impeller::kMetalSDF, impeller::TRect< Scalar >::MakeLTRB(), impeller::TextureContents::MakeRect(), impeller::TRect< Scalar >::MakeSize(), impeller::Matrix::MakeTranslation(), impeller::FilterContents::MakeYUVToRGBFilter(), impeller::Entity::Render(), impeller::Entity::SetContents(), and impeller::Entity::SetTransform().

◆ TEST_P() [537/662]

impeller::testing::TEST_P ( GaussianBlurFilterContentsTest  ,
CalculateUVsSimple   
)

Definition at line 364 of file gaussian_blur_filter_contents_unittests.cc.

364 {
365 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
366 auto filter_input = FilterInput::Make(texture);
367 Entity entity;
368 Quad uvs = GaussianBlurFilterContents::CalculateUVs(
369 filter_input, entity, Rect::MakeSize(ISize(100, 100)), ISize(100, 100));
370 std::optional<Rect> uvs_bounds = Rect::MakePointBounds(uvs);
371 EXPECT_TRUE(uvs_bounds.has_value());
372 if (uvs_bounds.has_value()) {
373 EXPECT_TRUE(RectNear(uvs_bounds.value(), Rect::MakeXYWH(0, 0, 1, 1)));
374 }
375}

References impeller::GaussianBlurFilterContents::CalculateUVs(), impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakePointBounds(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), RectNear(), texture, and uvs.

◆ TEST_P() [538/662]

impeller::testing::TEST_P ( GaussianBlurFilterContentsTest  ,
CoverageWithEffectTransform   
)

Definition at line 191 of file gaussian_blur_filter_contents_unittests.cc.

191 {
192 Matrix effect_transform = Matrix::MakeScale({2.0, 2.0, 1.0});
193 fml::StatusOr<Scalar> sigma_radius_1 =
194 CalculateSigmaForBlurRadius(1.0, effect_transform);
195 ASSERT_TRUE(sigma_radius_1.ok());
197 /*sigma_x=*/sigma_radius_1.value(),
198 /*sigma_y=*/sigma_radius_1.value(), Entity::TileMode::kDecal,
199 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
200 /*mask_geometry=*/nullptr);
201 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
202 FilterInput::Vector inputs = {FilterInput::Make(texture)};
203 Entity entity;
204 entity.SetTransform(Matrix::MakeTranslation({100, 100, 0}));
205 std::optional<Rect> coverage =
206 contents.GetFilterCoverage(inputs, entity, effect_transform);
207 EXPECT_TRUE(coverage.has_value());
208 if (coverage.has_value()) {
209 EXPECT_RECT_NEAR(coverage.value(),
210 Rect::MakeLTRB(100 - 1, 100 - 1, 200 + 1, 200 + 1));
211 }
212}

References EXPECT_RECT_NEAR, impeller::GaussianBlurFilterContents::GetFilterCoverage(), impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::Entity::SetTransform(), and texture.

◆ TEST_P() [539/662]

impeller::testing::TEST_P ( GaussianBlurFilterContentsTest  ,
CoverageWithTexture   
)

Definition at line 169 of file gaussian_blur_filter_contents_unittests.cc.

169 {
170 fml::StatusOr<Scalar> sigma_radius_1 =
171 CalculateSigmaForBlurRadius(1.0, Matrix());
172 ASSERT_TRUE(sigma_radius_1.ok());
174 /*sigma_X=*/sigma_radius_1.value(),
175 /*sigma_y=*/sigma_radius_1.value(), Entity::TileMode::kDecal,
176 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
177 /*mask_geometry=*/nullptr);
178 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
179 FilterInput::Vector inputs = {FilterInput::Make(texture)};
180 Entity entity;
181 entity.SetTransform(Matrix::MakeTranslation({100, 100, 0}));
182 std::optional<Rect> coverage =
183 contents.GetFilterCoverage(inputs, entity, /*effect_transform=*/Matrix());
184
185 EXPECT_TRUE(coverage.has_value());
186 if (coverage.has_value()) {
187 EXPECT_RECT_NEAR(coverage.value(), Rect::MakeLTRB(99, 99, 201, 201));
188 }
189}

References EXPECT_RECT_NEAR, impeller::GaussianBlurFilterContents::GetFilterCoverage(), impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeTranslation(), fml::StatusOr< T >::ok(), impeller::Entity::SetTransform(), texture, and fml::StatusOr< T >::value().

◆ TEST_P() [540/662]

impeller::testing::TEST_P ( GaussianBlurFilterContentsTest  ,
RenderCoverageMatchesGetCoverage   
)

Definition at line 265 of file gaussian_blur_filter_contents_unittests.cc.

265 {
266 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
267 fml::StatusOr<Scalar> sigma_radius_1 =
268 CalculateSigmaForBlurRadius(1.0, Matrix());
269 ASSERT_TRUE(sigma_radius_1.ok());
270 auto contents = std::make_unique<GaussianBlurFilterContents>(
271 sigma_radius_1.value(), sigma_radius_1.value(), Entity::TileMode::kDecal,
272 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
273 /*mask_geometry=*/nullptr);
274 contents->SetInputs({FilterInput::Make(texture)});
275 ContentContext& renderer = GetContentContext();
276
277 Entity entity;
278 std::optional<Entity> result =
279 contents->GetEntity(renderer, entity, /*coverage_hint=*/{});
280 EXPECT_TRUE(result.has_value());
281 if (result.has_value()) {
282 EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSrcOver);
283 std::optional<Rect> result_coverage = result.value().GetCoverage();
284 std::optional<Rect> contents_coverage = contents->GetCoverage(entity);
285 EXPECT_TRUE(result_coverage.has_value());
286 EXPECT_TRUE(contents_coverage.has_value());
287 if (result_coverage.has_value() && contents_coverage.has_value()) {
288 EXPECT_TRUE(RectNear(contents_coverage.value(),
289 Rect::MakeLTRB(-1, -1, 101, 101)));
290 EXPECT_TRUE(
291 RectNear(result_coverage.value(), Rect::MakeLTRB(-1, -1, 101, 101)));
292 }
293 }
294}

References impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::kSrcOver, impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), fml::StatusOr< T >::ok(), RectNear(), texture, and fml::StatusOr< T >::value().

◆ TEST_P() [541/662]

impeller::testing::TEST_P ( GaussianBlurFilterContentsTest  ,
RenderCoverageMatchesGetCoverageRotated   
)

Definition at line 330 of file gaussian_blur_filter_contents_unittests.cc.

331 {
332 std::shared_ptr<Texture> texture = MakeTexture(ISize(400, 300));
333 fml::StatusOr<Scalar> sigma_radius_1 =
334 CalculateSigmaForBlurRadius(1.0, Matrix());
335 auto contents = std::make_unique<GaussianBlurFilterContents>(
336 sigma_radius_1.value(), sigma_radius_1.value(), Entity::TileMode::kDecal,
337 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
338 /*mask_geometry=*/nullptr);
339 contents->SetInputs({FilterInput::Make(texture)});
340 ContentContext& renderer = GetContentContext();
341
342 Entity entity;
343 // Rotate around the top left corner, then push it over to (100, 100).
344 entity.SetTransform(Matrix::MakeTranslation({400, 100, 0}) *
345 Matrix::MakeRotationZ(Degrees(90.0)));
346 std::optional<Entity> result =
347 contents->GetEntity(renderer, entity, /*coverage_hint=*/{});
348 EXPECT_TRUE(result.has_value());
349 if (result.has_value()) {
350 EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSrcOver);
351 std::optional<Rect> result_coverage = result.value().GetCoverage();
352 std::optional<Rect> contents_coverage = contents->GetCoverage(entity);
353 EXPECT_TRUE(result_coverage.has_value());
354 EXPECT_TRUE(contents_coverage.has_value());
355 if (result_coverage.has_value() && contents_coverage.has_value()) {
356 EXPECT_TRUE(RectNear(contents_coverage.value(),
357 Rect::MakeLTRB(99, 99, 401, 501)));
358 EXPECT_TRUE(
359 RectNear(result_coverage.value(), Rect::MakeLTRB(99, 99, 401, 501)));
360 }
361 }
362}

References impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::kSrcOver, impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeTranslation(), RectNear(), impeller::Entity::SetTransform(), texture, and fml::StatusOr< T >::value().

◆ TEST_P() [542/662]

impeller::testing::TEST_P ( GaussianBlurFilterContentsTest  ,
RenderCoverageMatchesGetCoverageTranslate   
)

Definition at line 296 of file gaussian_blur_filter_contents_unittests.cc.

297 {
298 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
299 fml::StatusOr<Scalar> sigma_radius_1 =
300 CalculateSigmaForBlurRadius(1.0, Matrix());
301 ASSERT_TRUE(sigma_radius_1.ok());
302 auto contents = std::make_unique<GaussianBlurFilterContents>(
303 sigma_radius_1.value(), sigma_radius_1.value(), Entity::TileMode::kDecal,
304 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
305 /*mask_geometry=*/nullptr);
306 contents->SetInputs({FilterInput::Make(texture)});
307 ContentContext& renderer = GetContentContext();
308
309 Entity entity;
310 entity.SetTransform(Matrix::MakeTranslation({100, 200, 0}));
311 std::optional<Entity> result =
312 contents->GetEntity(renderer, entity, /*coverage_hint=*/{});
313
314 EXPECT_TRUE(result.has_value());
315 if (result.has_value()) {
316 EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSrcOver);
317 std::optional<Rect> result_coverage = result.value().GetCoverage();
318 std::optional<Rect> contents_coverage = contents->GetCoverage(entity);
319 EXPECT_TRUE(result_coverage.has_value());
320 EXPECT_TRUE(contents_coverage.has_value());
321 if (result_coverage.has_value() && contents_coverage.has_value()) {
322 EXPECT_TRUE(RectNear(contents_coverage.value(),
323 Rect::MakeLTRB(99, 199, 201, 301)));
324 EXPECT_TRUE(
325 RectNear(result_coverage.value(), Rect::MakeLTRB(99, 199, 201, 301)));
326 }
327 }
328}

References impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::kSrcOver, impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeTranslation(), fml::StatusOr< T >::ok(), RectNear(), impeller::Entity::SetTransform(), texture, and fml::StatusOr< T >::value().

◆ TEST_P() [543/662]

impeller::testing::TEST_P ( GaussianBlurFilterContentsTest  ,
TextureContentsWithDestinationRect   
)

Definition at line 377 of file gaussian_blur_filter_contents_unittests.cc.

377 {
378 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
379 auto texture_contents = std::make_shared<TextureContents>();
380 texture_contents->SetSourceRect(Rect::MakeSize(texture->GetSize()));
381 texture_contents->SetTexture(texture);
382 texture_contents->SetDestinationRect(Rect::MakeXYWH(
383 50, 40, texture->GetSize().width, texture->GetSize().height));
384
385 fml::StatusOr<Scalar> sigma_radius_1 =
386 CalculateSigmaForBlurRadius(1.0, Matrix());
387 auto contents = std::make_unique<GaussianBlurFilterContents>(
388 sigma_radius_1.value(), sigma_radius_1.value(), Entity::TileMode::kDecal,
389 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
390 /*mask_geometry=*/nullptr);
391 contents->SetInputs({FilterInput::Make(texture_contents)});
392 ContentContext& renderer = GetContentContext();
393
394 Entity entity;
395 std::optional<Entity> result =
396 contents->GetEntity(renderer, entity, /*coverage_hint=*/{});
397 EXPECT_TRUE(result.has_value());
398 if (result.has_value()) {
399 EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSrcOver);
400 std::optional<Rect> result_coverage = result.value().GetCoverage();
401 std::optional<Rect> contents_coverage = contents->GetCoverage(entity);
402 EXPECT_TRUE(result_coverage.has_value());
403 EXPECT_TRUE(contents_coverage.has_value());
404 if (result_coverage.has_value() && contents_coverage.has_value()) {
405 EXPECT_TRUE(RectNear(result_coverage.value(), contents_coverage.value()));
406 EXPECT_TRUE(RectNear(result_coverage.value(),
407 Rect::MakeLTRB(49.f, 39.f, 151.f, 141.f)));
408 }
409 }
410}

References impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::kSrcOver, impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), RectNear(), texture, and fml::StatusOr< T >::value().

◆ TEST_P() [544/662]

impeller::testing::TEST_P ( GaussianBlurFilterContentsTest  ,
TextureContentsWithDestinationRectScaled   
)

Definition at line 412 of file gaussian_blur_filter_contents_unittests.cc.

413 {
414 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
415 auto texture_contents = std::make_shared<TextureContents>();
416 texture_contents->SetSourceRect(Rect::MakeSize(texture->GetSize()));
417 texture_contents->SetTexture(texture);
418 texture_contents->SetDestinationRect(Rect::MakeXYWH(
419 50, 40, texture->GetSize().width, texture->GetSize().height));
420
421 fml::StatusOr<Scalar> sigma_radius_1 =
422 CalculateSigmaForBlurRadius(1.0, Matrix());
423 auto contents = std::make_unique<GaussianBlurFilterContents>(
424 sigma_radius_1.value(), sigma_radius_1.value(), Entity::TileMode::kDecal,
425 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
426 /*mask_geometry=*/nullptr);
427 contents->SetInputs({FilterInput::Make(texture_contents)});
428 ContentContext& renderer = GetContentContext();
429
430 Entity entity;
431 entity.SetTransform(Matrix::MakeScale({2.0, 2.0, 1.0}));
432 std::optional<Entity> result =
433 contents->GetEntity(renderer, entity, /*coverage_hint=*/{});
434 EXPECT_TRUE(result.has_value());
435 if (result.has_value()) {
436 EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSrcOver);
437 std::optional<Rect> result_coverage = result.value().GetCoverage();
438 std::optional<Rect> contents_coverage = contents->GetCoverage(entity);
439 EXPECT_TRUE(result_coverage.has_value());
440 EXPECT_TRUE(contents_coverage.has_value());
441 if (result_coverage.has_value() && contents_coverage.has_value()) {
442 EXPECT_TRUE(RectNear(result_coverage.value(), contents_coverage.value()));
443 // Scaling a blurred entity doesn't seem to scale the blur radius linearly
444 // when comparing results with rrect_blur. That's why this is not
445 // Rect::MakeXYWH(98.f, 78.f, 204.0f, 204.f).
446 EXPECT_TRUE(RectNear(contents_coverage.value(),
447 Rect::MakeXYWH(94.f, 74.f, 212.0f, 212.f)));
448 }
449 }
450}

References impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::kSrcOver, impeller::FilterInput::Make(), impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), RectNear(), impeller::Entity::SetTransform(), texture, and fml::StatusOr< T >::value().

◆ TEST_P() [545/662]

impeller::testing::TEST_P ( GaussianBlurFilterContentsTest  ,
TextureContentsWithEffectTransform   
)

Definition at line 452 of file gaussian_blur_filter_contents_unittests.cc.

452 {
453 Matrix effect_transform = Matrix::MakeScale({2.0, 2.0, 1.0});
454 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
455 auto texture_contents = std::make_shared<TextureContents>();
456 texture_contents->SetSourceRect(Rect::MakeSize(texture->GetSize()));
457 texture_contents->SetTexture(texture);
458 texture_contents->SetDestinationRect(Rect::MakeXYWH(
459 50, 40, texture->GetSize().width, texture->GetSize().height));
460
461 fml::StatusOr<Scalar> sigma_radius_1 =
462 CalculateSigmaForBlurRadius(1.0, effect_transform);
463 ASSERT_TRUE(sigma_radius_1.ok());
464 auto contents = std::make_unique<GaussianBlurFilterContents>(
465 sigma_radius_1.value(), sigma_radius_1.value(), Entity::TileMode::kDecal,
466 /*bounds=*/std::nullopt, FilterContents::BlurStyle::kNormal,
467 /*mask_geometry=*/nullptr);
468 contents->SetInputs({FilterInput::Make(texture_contents)});
469 contents->SetEffectTransform(effect_transform);
470 ContentContext& renderer = GetContentContext();
471
472 Entity entity;
473 std::optional<Entity> result =
474 contents->GetEntity(renderer, entity, /*coverage_hint=*/{});
475 EXPECT_TRUE(result.has_value());
476 if (result.has_value()) {
477 EXPECT_EQ(result.value().GetBlendMode(), BlendMode::kSrcOver);
478 std::optional<Rect> result_coverage = result.value().GetCoverage();
479 std::optional<Rect> contents_coverage = contents->GetCoverage(entity);
480 EXPECT_TRUE(result_coverage.has_value());
481 EXPECT_TRUE(contents_coverage.has_value());
482 if (result_coverage.has_value() && contents_coverage.has_value()) {
483 EXPECT_TRUE(RectNear(result_coverage.value(), contents_coverage.value()));
484 EXPECT_TRUE(RectNear(contents_coverage.value(),
485 Rect::MakeXYWH(49.f, 39.f, 102.f, 102.f)));
486 }
487 }
488}

References impeller::Entity::kDecal, impeller::FilterContents::kNormal, impeller::kSrcOver, impeller::FilterInput::Make(), impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeXYWH(), fml::StatusOr< T >::ok(), RectNear(), texture, and fml::StatusOr< T >::value().

◆ TEST_P() [546/662]

impeller::testing::TEST_P ( HostBufferTest  ,
CanEmplace   
)

Definition at line 36 of file host_buffer_unittests.cc.

36 {
37 struct Length2 {
38 uint8_t pad[2];
39 };
40 static_assert(sizeof(Length2) == 2u);
41
42 auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(),
43 GetContext()->GetIdleWaiter(), 256);
44
45 for (size_t i = 0; i < 12500; i++) {
46 auto view = buffer->Emplace(Length2{});
47 ASSERT_TRUE(view);
48 ASSERT_EQ(view.GetRange(), Range(i * sizeof(Length2), 2u));
49 }
50}
FlView * view

References flutter::buffer, impeller::HostBuffer::Create(), i, and view.

◆ TEST_P() [547/662]

impeller::testing::TEST_P ( HostBufferTest  ,
CanEmplaceWithAlignment   
)

Definition at line 52 of file host_buffer_unittests.cc.

52 {
53 struct Length2 {
54 uint8_t pad[2];
55 };
56 static_assert(sizeof(Length2) == 2);
57 struct alignas(16) Align16 {
58 uint8_t pad[2];
59 };
60 static_assert(alignof(Align16) == 16);
61 static_assert(sizeof(Align16) == 16);
62
63 auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(),
64 GetContext()->GetIdleWaiter(), 256);
65 ASSERT_TRUE(buffer);
66
67 {
68 auto view = buffer->Emplace(Length2{});
69 ASSERT_TRUE(view);
70 ASSERT_EQ(view.GetRange(), Range(0u, 2u));
71 }
72
73 {
74 auto view = buffer->Emplace(Align16{});
75 ASSERT_TRUE(view);
76 ASSERT_EQ(view.GetRange().offset, 16u);
77 ASSERT_EQ(view.GetRange().length, 16u);
78 }
79 {
80 auto view = buffer->Emplace(Length2{});
81 ASSERT_TRUE(view);
82 ASSERT_EQ(view.GetRange(), Range(32u, 2u));
83 }
84
85 {
86 auto view = buffer->Emplace(Align16{});
87 ASSERT_TRUE(view);
88 ASSERT_EQ(view.GetRange().offset, 48u);
89 ASSERT_EQ(view.GetRange().length, 16u);
90 }
91}

References flutter::buffer, impeller::HostBuffer::Create(), and view.

◆ TEST_P() [548/662]

impeller::testing::TEST_P ( HostBufferTest  ,
CompletedEntriesAreReusedWithoutTrackerChurn   
)

Definition at line 262 of file host_buffer_unittests.cc.

262 {
263 auto tracker = std::make_shared<GpuSubmissionTracker>();
264 auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(),
265 GetContext()->GetIdleWaiter(), 256, tracker);
266
267 // Simulate frames whose GPU work completes promptly. Entries must be
268 // reused, not replaced.
269 const DeviceBuffer* entry = buffer->EmplaceUniform(0.0f).GetBuffer();
270 for (size_t i = 0; i < kHostBufferArenaSize * 3; i++) {
271 tracker->RecordCompletion(tracker->RecordSubmission());
272 buffer->Reset();
273 }
274 EXPECT_EQ(buffer->EmplaceUniform(0.0f).GetBuffer(), entry);
275}

References flutter::buffer, impeller::HostBuffer::Create(), i, and impeller::kHostBufferArenaSize.

◆ TEST_P() [549/662]

impeller::testing::TEST_P ( HostBufferTest  ,
EmplaceWithFailingAllocationDoesntCrash   
)

Definition at line 277 of file host_buffer_unittests.cc.

277 {
279 std::shared_ptr<FailingAllocator> allocator =
280 std::make_shared<FailingAllocator>(GetContext()->GetResourceAllocator());
281 auto buffer =
282 HostBuffer::Create(allocator, GetContext()->GetIdleWaiter(), 256);
283
284 auto view = buffer->Emplace(nullptr, kMagicFailingAllocation, 0);
285
286 EXPECT_EQ(view.GetBuffer(), nullptr);
287 EXPECT_EQ(view.GetRange().offset, 0u);
288 EXPECT_EQ(view.GetRange().length, 0u);
289}

References allocator, flutter::buffer, impeller::HostBuffer::Create(), kMagicFailingAllocation, and view.

◆ TEST_P() [550/662]

impeller::testing::TEST_P ( HostBufferTest  ,
EmplaceWithProcIsAligned   
)

Definition at line 180 of file host_buffer_unittests.cc.

180 {
181 auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(),
182 GetContext()->GetIdleWaiter(), 256);
183
184 BufferView view = buffer->Emplace(std::array<char, 21>());
185 EXPECT_EQ(view.GetRange(), Range(0, 21));
186
187 view = buffer->Emplace(64, 16, [](uint8_t*) {});
188 EXPECT_EQ(view.GetRange(), Range(32, 64));
189}

References flutter::buffer, impeller::HostBuffer::Create(), and view.

◆ TEST_P() [551/662]

impeller::testing::TEST_P ( HostBufferTest  ,
EmplacingLargerThanBlockSizeCreatesOneOffBuffer   
)

Definition at line 135 of file host_buffer_unittests.cc.

135 {
136 auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(),
137 GetContext()->GetIdleWaiter(), 256);
138
139 // Emplace an amount larger than the block size, to verify that the host
140 // buffer does not create a buffer.
141 auto buffer_view = buffer->Emplace(nullptr, 1024000 + 10, 0);
142
143 EXPECT_EQ(buffer->GetStateForTest().current_buffer, 0u);
144 EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u);
145 EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 1u);
146}

References flutter::buffer, and impeller::HostBuffer::Create().

◆ TEST_P() [552/662]

impeller::testing::TEST_P ( HostBufferTest  ,
EmplacingLargerThanBlockSizeCreatesOneOffBufferCallback   
)

Definition at line 121 of file host_buffer_unittests.cc.

122 {
123 auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(),
124 GetContext()->GetIdleWaiter(), 256);
125
126 // Emplace an amount larger than the block size, to verify that the host
127 // buffer does not create a buffer.
128 auto buffer_view = buffer->Emplace(1024000 + 10, 0, [](uint8_t* data) {});
129
130 EXPECT_EQ(buffer->GetStateForTest().current_buffer, 0u);
131 EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u);
132 EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 1u);
133}

References flutter::buffer, impeller::HostBuffer::Create(), and flutter::data.

◆ TEST_P() [553/662]

impeller::testing::TEST_P ( HostBufferTest  ,
HostBufferInitialState   
)

Definition at line 93 of file host_buffer_unittests.cc.

93 {
94 auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(),
95 GetContext()->GetIdleWaiter(), 256);
96
97 EXPECT_EQ(buffer->GetStateForTest().current_buffer, 0u);
98 EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u);
99 EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 1u);
100}

References flutter::buffer, and impeller::HostBuffer::Create().

◆ TEST_P() [554/662]

impeller::testing::TEST_P ( HostBufferTest  ,
IdleWaiter   
)

Definition at line 27 of file host_buffer_unittests.cc.

27 {
28 auto mock_idle_waiter = std::make_shared<MockIdleWaiter>();
29 {
30 auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(),
31 mock_idle_waiter, 256);
32 EXPECT_CALL(*mock_idle_waiter, WaitIdle());
33 }
34}

References flutter::buffer, and impeller::HostBuffer::Create().

◆ TEST_P() [555/662]

impeller::testing::TEST_P ( HostBufferTest  ,
PendingEntriesAreReplacedNotReused   
)

Definition at line 238 of file host_buffer_unittests.cc.

238 {
239 auto tracker = std::make_shared<GpuSubmissionTracker>();
240 auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(),
241 GetContext()->GetIdleWaiter(), 256, tracker);
242
243 // Write to the first arena entry and pretend its GPU work never completes.
244 const DeviceBuffer* first_entry = buffer->EmplaceUniform(0.0f).GetBuffer();
245 uint64_t pending = tracker->RecordSubmission();
246 for (size_t i = 0; i < kHostBufferArenaSize; i++) {
247 buffer->Reset();
248 }
249
250 // The entry must be replaced with a fresh allocation.
251 EXPECT_NE(buffer->EmplaceUniform(0.0f).GetBuffer(), first_entry);
252
253 // Once completed, entries are reused in place.
254 tracker->RecordCompletion(pending);
255 const DeviceBuffer* second_entry = buffer->EmplaceUniform(0.0f).GetBuffer();
256 for (size_t i = 0; i < kHostBufferArenaSize; i++) {
257 buffer->Reset();
258 }
259 EXPECT_EQ(buffer->EmplaceUniform(0.0f).GetBuffer(), second_entry);
260}

References flutter::buffer, impeller::HostBuffer::Create(), i, and impeller::kHostBufferArenaSize.

◆ TEST_P() [556/662]

impeller::testing::TEST_P ( HostBufferTest  ,
ResetIncrementsFrameCounter   
)

Definition at line 102 of file host_buffer_unittests.cc.

102 {
103 auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(),
104 GetContext()->GetIdleWaiter(), 256);
105
106 EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u);
107
108 buffer->Reset();
109 EXPECT_EQ(buffer->GetStateForTest().current_frame, 1u);
110
111 buffer->Reset();
112 EXPECT_EQ(buffer->GetStateForTest().current_frame, 2u);
113
114 buffer->Reset();
115 EXPECT_EQ(buffer->GetStateForTest().current_frame, 3u);
116
117 buffer->Reset();
118 EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u);
119}

References flutter::buffer, and impeller::HostBuffer::Create().

◆ TEST_P() [557/662]

impeller::testing::TEST_P ( HostBufferTest  ,
UnusedBuffersAreDiscardedWhenResetting   
)

Definition at line 148 of file host_buffer_unittests.cc.

148 {
149 auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator(),
150 GetContext()->GetIdleWaiter(), 256);
151
152 // Emplace two large allocations to force the allocation of a second buffer.
153 auto buffer_view_a = buffer->Emplace(1020000, 0, [](uint8_t* data) {});
154 auto buffer_view_b = buffer->Emplace(1020000, 0, [](uint8_t* data) {});
155
156 EXPECT_EQ(buffer->GetStateForTest().current_buffer, 1u);
157 EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 2u);
158 EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u);
159
160 // Reset until we get back to this frame.
161 for (auto i = 0; i < 4; i++) {
162 buffer->Reset();
163 }
164
165 EXPECT_EQ(buffer->GetStateForTest().current_buffer, 0u);
166 EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 2u);
167 EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u);
168
169 // Now when we reset, the buffer should get dropped.
170 // Reset until we get back to this frame.
171 for (auto i = 0; i < 4; i++) {
172 buffer->Reset();
173 }
174
175 EXPECT_EQ(buffer->GetStateForTest().current_buffer, 0u);
176 EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 1u);
177 EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u);
178}

References flutter::buffer, impeller::HostBuffer::Create(), flutter::data, and i.

◆ TEST_P() [558/662]

impeller::testing::TEST_P ( MatrixFilterContentsTest  ,
RenderCoverageMatchesGetCoverageClippedSubpassScale   
)

Definition at line 175 of file matrix_filter_contents_unittests.cc.

176 {
177 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
178 MatrixFilterContents contents;
179 contents.SetInputs({FilterInput::Make(texture)});
180 contents.SetMatrix(Matrix::MakeScale({3, 3, 1}));
181 contents.SetEffectTransform(Matrix::MakeScale({2, 2, 1}));
182 contents.SetRenderingMode(
183 Entity::RenderingMode::kSubpassAppendSnapshotTransform);
184
185 Entity entity;
186 entity.SetTransform(Matrix::MakeTranslation({100, 200, 0}));
187
188 ContentContext& renderer = GetContentContext();
189 std::optional<Entity> result =
190 contents.GetEntity(renderer, entity, /*coverage_hint=*/{});
191 expectRenderCoverageEqual(result, contents.GetCoverage(entity),
192 Rect::MakeXYWH(100, 200, 300, 300));
193}
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
void SetEffectTransform(const Matrix &effect_transform)
Sets the transform which gets appended to the effect of this filter. Note that this is in addition to...
void SetRenderingMode(Entity::RenderingMode rendering_mode) override
Marks this filter chain as applying in a subpass scenario.

References impeller::FilterContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::Entity::kSubpassAppendSnapshotTransform, impeller::FilterInput::Make(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), impeller::FilterContents::SetEffectTransform(), impeller::FilterContents::SetInputs(), impeller::MatrixFilterContents::SetMatrix(), impeller::MatrixFilterContents::SetRenderingMode(), impeller::Entity::SetTransform(), and texture.

◆ TEST_P() [559/662]

impeller::testing::TEST_P ( MatrixFilterContentsTest  ,
RenderCoverageMatchesGetCoverageClippedSubpassTranslate   
)

Definition at line 138 of file matrix_filter_contents_unittests.cc.

139 {
140 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
141 MatrixFilterContents contents;
142 contents.SetInputs({FilterInput::Make(texture)});
143 contents.SetMatrix(Matrix::MakeTranslation({50, 100, 0}));
144 contents.SetEffectTransform(Matrix::MakeScale({2, 2, 1}));
145 contents.SetRenderingMode(
146 Entity::RenderingMode::kSubpassAppendSnapshotTransform);
147
148 Entity entity;
149 entity.SetTransform(Matrix::MakeTranslation({100, 200, 0}));
150
151 ContentContext& renderer = GetContentContext();
152 std::optional<Entity> result =
153 contents.GetEntity(renderer, entity, /*coverage_hint=*/{});
154 expectRenderCoverageEqual(result, contents.GetCoverage(entity),
155 Rect::MakeXYWH(200, 400, 100, 100));
156}

References impeller::FilterContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::Entity::kSubpassAppendSnapshotTransform, impeller::FilterInput::Make(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), impeller::FilterContents::SetEffectTransform(), impeller::FilterContents::SetInputs(), impeller::MatrixFilterContents::SetMatrix(), impeller::MatrixFilterContents::SetRenderingMode(), impeller::Entity::SetTransform(), and texture.

◆ TEST_P() [560/662]

impeller::testing::TEST_P ( MatrixFilterContentsTest  ,
RenderCoverageMatchesGetCoverageIdentity   
)

Definition at line 106 of file matrix_filter_contents_unittests.cc.

106 {
107 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
108 MatrixFilterContents contents;
109 contents.SetInputs({FilterInput::Make(texture)});
110
111 Entity entity;
112 entity.SetTransform(Matrix::MakeTranslation({100, 200, 0}));
113
114 ContentContext& renderer = GetContentContext();
115 std::optional<Entity> result =
116 contents.GetEntity(renderer, entity, /*coverage_hint=*/{});
117 expectRenderCoverageEqual(result, contents.GetCoverage(entity),
118 Rect::MakeXYWH(100, 200, 100, 100));
119}

References impeller::FilterContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::FilterInput::Make(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), impeller::FilterContents::SetInputs(), impeller::Entity::SetTransform(), and texture.

◆ TEST_P() [561/662]

impeller::testing::TEST_P ( MatrixFilterContentsTest  ,
RenderCoverageMatchesGetCoverageScale   
)

Definition at line 158 of file matrix_filter_contents_unittests.cc.

158 {
159 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
160 MatrixFilterContents contents;
161 contents.SetInputs({FilterInput::Make(texture)});
162 contents.SetMatrix(Matrix::MakeScale({3, 3, 1}));
163 contents.SetEffectTransform(Matrix::MakeScale({2, 2, 1}));
164
165 Entity entity;
166 entity.SetTransform(Matrix::MakeTranslation({100, 200, 0}));
167
168 ContentContext& renderer = GetContentContext();
169 std::optional<Entity> result =
170 contents.GetEntity(renderer, entity, /*coverage_hint=*/{});
171 expectRenderCoverageEqual(result, contents.GetCoverage(entity),
172 Rect::MakeXYWH(100, 200, 300, 300));
173}

References impeller::FilterContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::FilterInput::Make(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), impeller::FilterContents::SetEffectTransform(), impeller::FilterContents::SetInputs(), impeller::MatrixFilterContents::SetMatrix(), impeller::Entity::SetTransform(), and texture.

◆ TEST_P() [562/662]

impeller::testing::TEST_P ( MatrixFilterContentsTest  ,
RenderCoverageMatchesGetCoverageSubpassScale   
)

Definition at line 195 of file matrix_filter_contents_unittests.cc.

195 {
196 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
197 MatrixFilterContents contents;
198 contents.SetInputs({FilterInput::Make(texture)});
199 contents.SetMatrix(Matrix::MakeScale({3, 3, 1}));
200 contents.SetEffectTransform(Matrix::MakeScale({2, 2, 1}));
201 contents.SetRenderingMode(
202 Entity::RenderingMode::kSubpassPrependSnapshotTransform);
203
204 Entity entity;
205 entity.SetTransform(Matrix::MakeTranslation({100, 200, 0}));
206
207 ContentContext& renderer = GetContentContext();
208 std::optional<Entity> result =
209 contents.GetEntity(renderer, entity, /*coverage_hint=*/{});
210 expectRenderCoverageEqual(result, contents.GetCoverage(entity),
211 Rect::MakeXYWH(300, 600, 300, 300));
212}

References impeller::FilterContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::Entity::kSubpassPrependSnapshotTransform, impeller::FilterInput::Make(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), impeller::FilterContents::SetEffectTransform(), impeller::FilterContents::SetInputs(), impeller::MatrixFilterContents::SetMatrix(), impeller::MatrixFilterContents::SetRenderingMode(), impeller::Entity::SetTransform(), and texture.

◆ TEST_P() [563/662]

impeller::testing::TEST_P ( MatrixFilterContentsTest  ,
RenderCoverageMatchesGetCoverageTranslate   
)

Definition at line 121 of file matrix_filter_contents_unittests.cc.

121 {
122 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
123 MatrixFilterContents contents;
124 contents.SetInputs({FilterInput::Make(texture)});
125 contents.SetMatrix(Matrix::MakeTranslation({50, 100, 0}));
126 contents.SetEffectTransform(Matrix::MakeScale({2, 2, 1}));
127
128 Entity entity;
129 entity.SetTransform(Matrix::MakeTranslation({100, 200, 0}));
130
131 ContentContext& renderer = GetContentContext();
132 std::optional<Entity> result =
133 contents.GetEntity(renderer, entity, /*coverage_hint=*/{});
134 expectRenderCoverageEqual(result, contents.GetCoverage(entity),
135 Rect::MakeXYWH(150, 300, 100, 100));
136}

References impeller::FilterContents::GetCoverage(), impeller::FilterContents::GetEntity(), impeller::FilterInput::Make(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), impeller::TRect< Scalar >::MakeXYWH(), impeller::FilterContents::SetEffectTransform(), impeller::FilterContents::SetInputs(), impeller::MatrixFilterContents::SetMatrix(), impeller::Entity::SetTransform(), and texture.

◆ TEST_P() [564/662]

impeller::testing::TEST_P ( MorphologyFilterContentsTest  ,
RenderCoverageMatchesGetCoverage   
)

Definition at line 44 of file morphology_filter_contents_unittests.cc.

44 {
45 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
46 ASSERT_NE(texture, nullptr);
47 auto contents = FilterContents::MakeDirectionalMorphology(
48 FilterInput::Make(texture), Radius{2.0}, Vector2(1, 0),
49 FilterContents::MorphType::kDilate);
50
51 Entity entity;
52 ContentContext& renderer = GetContentContext();
53 std::optional<Entity> result =
54 contents->GetEntity(renderer, entity, /*coverage_hint=*/{});
55
56 ASSERT_TRUE(result.has_value());
57 if (result.has_value()) {
58 std::optional<Rect> result_coverage = result.value().GetCoverage();
59 std::optional<Rect> contents_coverage = contents->GetCoverage(entity);
60 Rect expected = Rect::MakeLTRB(-2, 0, 102, 100);
61 ASSERT_TRUE(result_coverage.has_value());
62 ASSERT_TRUE(contents_coverage.has_value());
63 if (result_coverage.has_value() && contents_coverage.has_value()) {
64 EXPECT_TRUE(RectNear(result_coverage.value(), expected));
65 EXPECT_TRUE(RectNear(contents_coverage.value(), expected));
66 }
67 }
68}

References impeller::FilterContents::kDilate, impeller::FilterInput::Make(), impeller::FilterContents::MakeDirectionalMorphology(), impeller::TRect< Scalar >::MakeLTRB(), RectNear(), and texture.

◆ TEST_P() [565/662]

impeller::testing::TEST_P ( MorphologyFilterContentsTest  ,
RenderDilateWithFractionalCoverageIsSymmetric   
)

Definition at line 70 of file morphology_filter_contents_unittests.cc.

71 {
72 // Non-integer scale and radius produce a fractional pixel expansion
73 // 1.5 * 2.625 = 3.9375, exercising the render target ceiling logic.
74 Scalar radius = 1.5;
75 Scalar scale = 2.625;
76
77 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
78 ASSERT_NE(texture, nullptr);
79 auto contents = FilterContents::MakeDirectionalMorphology(
80 FilterInput::Make(texture), Radius{radius}, Vector2(1, 0),
81 FilterContents::MorphType::kDilate);
82 contents->SetEffectTransform(Matrix::MakeScale(Vector2(scale, scale)));
83
84 Entity entity;
85 ContentContext& renderer = GetContentContext();
86 std::optional<Entity> result =
87 contents->GetEntity(renderer, entity, /*coverage_hint=*/{});
88
89 ASSERT_TRUE(result.has_value());
90 if (result.has_value()) {
91 std::optional<Rect> result_coverage = result->GetCoverage();
92 ASSERT_TRUE(result_coverage.has_value());
93 if (result_coverage.has_value()) {
94 Scalar expected_expansion = radius * scale;
95 EXPECT_TRUE(result_coverage->Contains(Rect::MakeLTRB(
96 -expected_expansion, 0, 100 + expected_expansion, 100)));
97 Scalar left_expansion = 0 - result_coverage->GetLeft();
98 Scalar right_expansion = result_coverage->GetRight() - 100;
99 EXPECT_NEAR(left_expansion, right_expansion, 0.5);
100 }
101 }
102}

References impeller::FilterContents::kDilate, impeller::FilterInput::Make(), impeller::FilterContents::MakeDirectionalMorphology(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeScale(), and texture.

◆ TEST_P() [566/662]

impeller::testing::TEST_P ( MorphologyFilterContentsTest  ,
RenderDilateYWithFractionalCoverageIsSymmetric   
)

Definition at line 104 of file morphology_filter_contents_unittests.cc.

105 {
106 // Non-integer scale and radius produce a fractional pixel expansion
107 // 1.5 * 2.625 = 3.9375, exercising the render target ceiling logic.
108 Scalar radius = 1.5;
109 Scalar scale = 2.625;
110
111 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
112 ASSERT_NE(texture, nullptr);
113 auto contents = FilterContents::MakeDirectionalMorphology(
114 FilterInput::Make(texture), Radius{radius}, Vector2(0, 1),
115 FilterContents::MorphType::kDilate);
116 contents->SetEffectTransform(Matrix::MakeScale(Vector2(scale, scale)));
117
118 Entity entity;
119 ContentContext& renderer = GetContentContext();
120 std::optional<Entity> result =
121 contents->GetEntity(renderer, entity, /*coverage_hint=*/{});
122
123 ASSERT_TRUE(result.has_value());
124 if (result.has_value()) {
125 std::optional<Rect> result_coverage = result->GetCoverage();
126 ASSERT_TRUE(result_coverage.has_value());
127 if (result_coverage.has_value()) {
128 Scalar expected_expansion = radius * scale;
129 EXPECT_TRUE(result_coverage->Contains(Rect::MakeLTRB(
130 0, -expected_expansion, 100, 100 + expected_expansion)));
131 Scalar top_expansion = 0 - result_coverage->GetTop();
132 Scalar bottom_expansion = result_coverage->GetBottom() - 100;
133 EXPECT_NEAR(top_expansion, bottom_expansion, 0.5);
134 }
135 }
136}

References impeller::FilterContents::kDilate, impeller::FilterInput::Make(), impeller::FilterContents::MakeDirectionalMorphology(), impeller::TRect< Scalar >::MakeLTRB(), impeller::Matrix::MakeScale(), and texture.

◆ TEST_P() [567/662]

impeller::testing::TEST_P ( PipelineCacheDataVKPlaygroundTest  ,
CanPersistAndRetrievePipelineCache   
)

Definition at line 117 of file pipeline_cache_data_vk_unittests.cc.

117 {
119 const auto& surface_context = SurfaceContextVK::Cast(*GetContext());
120 const auto& context_vk = ContextVK::Cast(*surface_context.GetParent());
121 const auto& caps = CapabilitiesVK::Cast(*context_vk.GetCapabilities());
122
123 {
124 auto cache = context_vk.GetDevice().createPipelineCacheUnique({});
125 ASSERT_EQ(cache.result, vk::Result::eSuccess);
126 ASSERT_FALSE(fml::FileExists(temp_dir.fd(), "flutter.impeller.vkcache"));
127 ASSERT_TRUE(PipelineCacheDataPersist(
128 temp_dir.fd(), caps.GetPhysicalDeviceProperties(), cache.value));
129 }
130 ASSERT_TRUE(fml::FileExists(temp_dir.fd(), "flutter.impeller.vkcache"));
131
132 auto mapping = PipelineCacheDataRetrieve(temp_dir.fd(),
133 caps.GetPhysicalDeviceProperties());
134 ASSERT_NE(mapping, nullptr);
135 // Assert that the utility has stripped away the cache header giving us clean
136 // pipeline cache bootstrap information.
137 vk::PipelineCacheHeaderVersionOne vk_cache_header;
138 ASSERT_GE(mapping->GetSize(), sizeof(vk_cache_header));
139 std::memcpy(&vk_cache_header, mapping->GetMapping(), sizeof(vk_cache_header));
140 ASSERT_EQ(vk_cache_header.headerVersion,
141 vk::PipelineCacheHeaderVersion::eOne);
142}
bool FileExists(const fml::UniqueFD &base_directory, const char *path)

References impeller::BackendCast< CapabilitiesVK, Capabilities >::Cast(), impeller::BackendCast< ContextVK, Context >::Cast(), impeller::BackendCast< SurfaceContextVK, Context >::Cast(), fml::ScopedTemporaryDirectory::fd(), fml::FileExists(), impeller::PipelineCacheDataPersist(), and impeller::PipelineCacheDataRetrieve().

◆ TEST_P() [568/662]

impeller::testing::TEST_P ( PipelineCacheDataVKPlaygroundTest  ,
IntegrityChecksArePerformedOnPersistedData   
)

Definition at line 144 of file pipeline_cache_data_vk_unittests.cc.

145 {
147 const auto& surface_context = SurfaceContextVK::Cast(*GetContext());
148 const auto& context_vk = ContextVK::Cast(*surface_context.GetParent());
149 const auto& caps = CapabilitiesVK::Cast(*context_vk.GetCapabilities());
150
151 {
152 auto cache = context_vk.GetDevice().createPipelineCacheUnique({});
153 ASSERT_EQ(cache.result, vk::Result::eSuccess);
154 ASSERT_FALSE(fml::FileExists(temp_dir.fd(), "flutter.impeller.vkcache"));
155 ASSERT_TRUE(PipelineCacheDataPersist(
156 temp_dir.fd(), caps.GetPhysicalDeviceProperties(), cache.value));
157 }
158 ASSERT_TRUE(fml::FileExists(temp_dir.fd(), "flutter.impeller.vkcache"));
159 auto incompatible_caps = caps.GetPhysicalDeviceProperties();
160 // Simulate a driver version bump.
161 incompatible_caps.driverVersion =
162 caps.GetPhysicalDeviceProperties().driverVersion + 1u;
163 auto mapping = PipelineCacheDataRetrieve(temp_dir.fd(), incompatible_caps);
164 ASSERT_EQ(mapping, nullptr);
165}

References impeller::BackendCast< CapabilitiesVK, Capabilities >::Cast(), impeller::BackendCast< ContextVK, Context >::Cast(), impeller::BackendCast< SurfaceContextVK, Context >::Cast(), fml::ScopedTemporaryDirectory::fd(), fml::FileExists(), impeller::PipelineCacheDataPersist(), and impeller::PipelineCacheDataRetrieve().

◆ TEST_P() [569/662]

impeller::testing::TEST_P ( PipelineLibraryGLESTest  ,
ChangingSpecConstantsCausesNewProgramObject   
)

Definition at line 46 of file pipeline_library_gles_unittests.cc.

46 {
47 using VS = SpecConstantVertexShader;
48 using FS = SpecConstantFragmentShader;
49 auto context = GetContext();
50 ASSERT_TRUE(context);
52 ASSERT_TRUE(desc.has_value());
53 desc->SetSpecializationConstants({2.0f});
54 auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).Get();
55 ASSERT_TRUE(pipeline && pipeline->IsValid());
56 auto new_desc = desc;
57 // Changing the spec. constants should result in a new program object.
58 new_desc->SetSpecializationConstants({4.0f});
59 auto new_pipeline =
60 context->GetPipelineLibrary()->GetPipeline(new_desc).Get();
61 ASSERT_TRUE(new_pipeline && new_pipeline->IsValid());
62 const auto& pipeline_gles = PipelineGLES::Cast(*pipeline);
63 const auto& new_pipeline_gles = PipelineGLES::Cast(*new_pipeline);
64 // The program handles should be live and equal.
65 ASSERT_FALSE(pipeline_gles.GetProgramHandle().IsDead());
66 ASSERT_FALSE(new_pipeline_gles.GetProgramHandle().IsDead());
67 ASSERT_FALSE(pipeline_gles.GetProgramHandle().GetName().value() ==
68 new_pipeline_gles.GetProgramHandle().GetName().value());
69}

References impeller::BackendCast< PipelineGLES, Pipeline< PipelineDescriptor > >::Cast(), context, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), and pipeline.

◆ TEST_P() [570/662]

impeller::testing::TEST_P ( PipelineLibraryGLESTest  ,
ClearingPipelineWillAlsoClearProgramHandle   
)

Definition at line 71 of file pipeline_library_gles_unittests.cc.

71 {
72 using VS = SpecConstantVertexShader;
73 using FS = SpecConstantFragmentShader;
74 std::shared_ptr<Context> context = GetContext();
75 std::optional<PipelineDescriptor> desc =
77
78 std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline =
79 context->GetPipelineLibrary()->GetPipeline(desc).Get();
80 ASSERT_TRUE(pipeline && pipeline->IsValid());
81 const auto& pipeline_gles = PipelineGLES::Cast(*pipeline);
82 HandleGLES handle = pipeline_gles.GetProgramHandle();
83
84 // Clear the pipeline descriptor.
85 auto entrypoint =
86 pipeline->GetDescriptor().GetEntrypointForStage(ShaderStage::kFragment);
87 context->GetPipelineLibrary()->RemovePipelinesWithEntryPoint(entrypoint);
88
89 // Re-create the pipeline
90 std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline_2 =
91 context->GetPipelineLibrary()->GetPipeline(desc).Get();
92 ASSERT_TRUE(pipeline && pipeline->IsValid());
93 const auto& pipeline_gles_2 = PipelineGLES::Cast(*pipeline_2);
94 HandleGLES handle_2 = pipeline_gles_2.GetProgramHandle();
95
96 EXPECT_FALSE(HandleGLES::Equal{}(handle, handle_2));
97}
A comparer used to test the equality of two handles.
Definition handle_gles.h:73

References impeller::BackendCast< PipelineGLES, Pipeline< PipelineDescriptor > >::Cast(), context, impeller::kFragment, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), and pipeline.

◆ TEST_P() [571/662]

impeller::testing::TEST_P ( PipelineLibraryGLESTest  ,
ProgramHandlesAreReused   
)

Definition at line 19 of file pipeline_library_gles_unittests.cc.

19 {
20 using VS = SpecConstantVertexShader;
21 using FS = SpecConstantFragmentShader;
22 auto context = GetContext();
23 ASSERT_TRUE(context);
25 ASSERT_TRUE(desc.has_value());
26 auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).Get();
27 ASSERT_TRUE(pipeline && pipeline->IsValid());
28 auto new_desc = desc;
29 // Changing the sample counts should not result in a new program object.
30 new_desc->SetSampleCount(SampleCount::kCount4);
31 // Make sure we don't hit the top-level descriptor cache. This will cause
32 // caching irrespective of backends.
33 ASSERT_FALSE(desc->IsEqual(new_desc.value()));
34 auto new_pipeline =
35 context->GetPipelineLibrary()->GetPipeline(new_desc).Get();
36 ASSERT_TRUE(new_pipeline && new_pipeline->IsValid());
37 const auto& pipeline_gles = PipelineGLES::Cast(*pipeline);
38 const auto& new_pipeline_gles = PipelineGLES::Cast(*new_pipeline);
39 // The program handles should be live and equal.
40 ASSERT_FALSE(pipeline_gles.GetProgramHandle().IsDead());
41 ASSERT_FALSE(new_pipeline_gles.GetProgramHandle().IsDead());
42 ASSERT_EQ(pipeline_gles.GetProgramHandle().GetName().value(),
43 new_pipeline_gles.GetProgramHandle().GetName().value());
44}

References impeller::BackendCast< PipelineGLES, Pipeline< PipelineDescriptor > >::Cast(), context, impeller::kCount4, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), and pipeline.

◆ TEST_P() [572/662]

impeller::testing::TEST_P ( RendererDartTest  ,
CanCreateRenderPassAndSubmit   
)

Definition at line 317 of file renderer_dart_unittests.cc.

317 {
318 ASSERT_TRUE(RenderDartToPlayground("canCreateRenderPassAndSubmit"));
319}

◆ TEST_P() [573/662]

impeller::testing::TEST_P ( RendererDartTest  ,
CanCreateShaderLibrary   
)

Definition at line 309 of file renderer_dart_unittests.cc.

309 {
310 ASSERT_TRUE(RunDartFunction("canCreateShaderLibrary"));
311}

◆ TEST_P() [574/662]

impeller::testing::TEST_P ( RendererDartTest  ,
CanInstantiateFlutterGPUContext   
)

These test entries correspond to Dart functions located in flutter/impeller/fixtures/dart_tests.dart

Definition at line 305 of file renderer_dart_unittests.cc.

305 {
306 ASSERT_TRUE(RunDartFunction("instantiateDefaultContext"));
307}

◆ TEST_P() [575/662]

impeller::testing::TEST_P ( RendererDartTest  ,
CanReflectUniformStructs   
)

Definition at line 313 of file renderer_dart_unittests.cc.

313 {
314 ASSERT_TRUE(RunDartFunction("canReflectUniformStructs"));
315}

◆ TEST_P() [576/662]

impeller::testing::TEST_P ( RendererDartTest  ,
CanRunDartInPlaygroundFrame   
)

Definition at line 288 of file renderer_dart_unittests.cc.

288 {
289 SinglePassCallback callback = [&](RenderPass& pass) {
290 if (IsPlaygroundEnabled()) {
291 ImGui::Begin("Dart test", nullptr);
292 ImGui::Text(
293 "This test executes Dart code during the playground frame callback.");
294 ImGui::End();
295 }
296
297 return RunDartFunction("sayHi");
298 };
299 ASSERT_TRUE(OpenPlaygroundHere(callback));
300}

References callback.

◆ TEST_P() [577/662]

impeller::testing::TEST_P ( RendererGoldenTest  ,
BabysFirstTriangle   
)

Definition at line 56 of file renderer_golden_unittests.cc.

56 {
57 using VS = BabyVertexShader;
58 using FS = BabyFragmentShader;
59
60 std::shared_ptr<Context> context = GetContext();
61 ASSERT_TRUE(context);
62
64 ASSERT_TRUE(desc.has_value());
65 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*desc));
66 auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).Get();
67 ASSERT_TRUE(pipeline);
68
69 VertexBufferBuilder<VS::PerVertexData> vertex_buffer_builder;
70 vertex_buffer_builder.AddVertices({
71 {{-0.5, -0.5}, Color::Red(), Color::Green()},
72 {{0.0, 0.5}, Color::Green(), Color::Blue()},
73 {{0.5, -0.5}, Color::Blue(), Color::Red()},
74 });
75 auto vertex_buffer = vertex_buffer_builder.CreateVertexBuffer(
76 *context->GetResourceAllocator());
77
78 auto host_buffer = HostBuffer::Create(
79 context->GetResourceAllocator(), context->GetIdleWaiter(),
80 context->GetCapabilities()->GetMinimumUniformAlignment());
81
82 ASSERT_TRUE(OpenPlaygroundHere([&](RenderPass& pass) -> bool {
83 // The harness runs the callback once per pass; start each from a clean
84 // host buffer.
85 host_buffer->Reset();
86 pass.SetPipeline(pipeline);
87 pass.SetVertexBuffer(vertex_buffer);
88
89 FS::FragInfo frag_info;
90 frag_info.time = 0.0f;
91 FS::BindFragInfo(pass, host_buffer->EmplaceUniform(frag_info));
92
93 return pass.Draw().ok();
94 }));
95}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), impeller::Color::Blue(), context, impeller::HostBuffer::Create(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::RenderPass::Draw(), impeller::Color::Green(), impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), fml::Status::ok(), pipeline, impeller::Color::Red(), impeller::RenderPass::SetPipeline(), and impeller::RenderPass::SetVertexBuffer().

◆ TEST_P() [578/662]

impeller::testing::TEST_P ( RendererGoldenTest  ,
CanRenderASTCCompressedTexture   
)

Definition at line 338 of file renderer_golden_unittests.cc.

338 {
339 std::shared_ptr<Context> context = GetContext();
340 ASSERT_TRUE(context);
341 if (!context->GetCapabilities()->SupportsTextureCompression(
342 CompressedTextureFamily::kASTC)) {
343 GTEST_SKIP() << "Backend does not support ASTC texture compression.";
344 }
345
346 // An ASTC void-extent block encodes one constant color directly: the 0xFC
347 // 0xFD header marks a 2D LDR void-extent with the "no extent" sentinel
348 // coordinates (all ones), followed by four little-endian UNORM16 channels
349 // (R, G, B, A). Alpha is opaque.
350 auto astc_solid_block = [](uint16_t r, uint16_t g,
351 uint16_t b) -> std::array<uint8_t, 16> {
352 return {{0xFC, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
353 static_cast<uint8_t>(r & 0xFF), static_cast<uint8_t>(r >> 8),
354 static_cast<uint8_t>(g & 0xFF), static_cast<uint8_t>(g >> 8),
355 static_cast<uint8_t>(b & 0xFF), static_cast<uint8_t>(b >> 8), 0xFF,
356 0xFF}};
357 };
358 // Red, green, blue, white.
359 const std::array<std::array<uint8_t, 16>, 4> blocks = {
360 {astc_solid_block(0xFFFF, 0, 0), astc_solid_block(0, 0xFFFF, 0),
361 astc_solid_block(0, 0, 0xFFFF),
362 astc_solid_block(0xFFFF, 0xFFFF, 0xFFFF)}};
363 std::vector<uint8_t> data;
364 for (const auto& block : blocks) {
365 data.insert(data.end(), block.begin(), block.end());
366 }
367
368 DrawCompressedTextureGolden(*this, PixelFormat::kASTC4x4LDR, data,
369 ISize{8, 8});
370}
static void DrawCompressedTextureGolden(RendererGoldenTest &test, PixelFormat format, const std::vector< uint8_t > &block_data, ISize size)

References context, flutter::data, DrawCompressedTextureGolden(), impeller::kASTC, and impeller::kASTC4x4LDR.

◆ TEST_P() [579/662]

impeller::testing::TEST_P ( RendererGoldenTest  ,
CanRenderBC1CompressedTexture   
)

Definition at line 270 of file renderer_golden_unittests.cc.

270 {
271 std::shared_ptr<Context> context = GetContext();
272 ASSERT_TRUE(context);
273 if (!context->GetCapabilities()->SupportsTextureCompression(
274 CompressedTextureFamily::kBC)) {
275 GTEST_SKIP() << "Backend does not support BC texture compression.";
276 }
277
278 // A solid-color BC1 block stores the color in both RGB565 endpoints with
279 // all-zero selector bits, which decodes to a single opaque color.
280 auto bc1_solid_block = [](uint16_t rgb565) -> std::array<uint8_t, 8> {
281 const auto lo = static_cast<uint8_t>(rgb565 & 0xFF);
282 const auto hi = static_cast<uint8_t>(rgb565 >> 8);
283 return {{lo, hi, lo, hi, 0, 0, 0, 0}};
284 };
285 // RGB565: red, green, blue, white.
286 const std::array<std::array<uint8_t, 8>, 4> blocks = {
287 {bc1_solid_block(0xF800), bc1_solid_block(0x07E0),
288 bc1_solid_block(0x001F), bc1_solid_block(0xFFFF)}};
289 std::vector<uint8_t> data;
290 for (const auto& block : blocks) {
291 data.insert(data.end(), block.begin(), block.end());
292 }
293
294 DrawCompressedTextureGolden(*this, PixelFormat::kBC1RGBAUNormInt, data,
295 ISize{8, 8});
296}

References context, flutter::data, DrawCompressedTextureGolden(), impeller::kBC, and impeller::kBC1RGBAUNormInt.

◆ TEST_P() [580/662]

impeller::testing::TEST_P ( RendererGoldenTest  ,
CanRenderETC2CompressedTexture   
)

Definition at line 302 of file renderer_golden_unittests.cc.

302 {
303 std::shared_ptr<Context> context = GetContext();
304 ASSERT_TRUE(context);
305 if (!context->GetCapabilities()->SupportsTextureCompression(
306 CompressedTextureFamily::kETC2)) {
307 GTEST_SKIP() << "Backend does not support ETC2 texture compression.";
308 }
309
310 // A solid-color ETC2 RGB8 block in "individual" mode (differential bit 0,
311 // which decodes like ETC1). The 64-bit block is laid out big-endian (byte 0
312 // most significant): byte 0 = R nibbles (R1,R2), byte 1 = G, byte 2 = B,
313 // byte 3 = codeword/diff/flip bits (all 0), bytes 4..7 = the two pixel-index
314 // bit planes. Both sub-blocks share the base color and every texel uses index
315 // 0 (all-zero planes), so the block is one flat color.
316 auto etc2_solid_block = [](uint8_t r, uint8_t g,
317 uint8_t b) -> std::array<uint8_t, 8> {
318 return {{r, g, b, 0x00, 0x00, 0x00, 0x00, 0x00}};
319 };
320 // Red, green, blue, white. Each channel byte is 0xFF (nibble 0xF, ~255) or
321 // 0x00.
322 const std::array<std::array<uint8_t, 8>, 4> blocks = {
323 {etc2_solid_block(0xFF, 0x00, 0x00), etc2_solid_block(0x00, 0xFF, 0x00),
324 etc2_solid_block(0x00, 0x00, 0xFF), etc2_solid_block(0xFF, 0xFF, 0xFF)}};
325 std::vector<uint8_t> data;
326 for (const auto& block : blocks) {
327 data.insert(data.end(), block.begin(), block.end());
328 }
329
330 DrawCompressedTextureGolden(*this, PixelFormat::kETC2RGB8UNormInt, data,
331 ISize{8, 8});
332}

References context, flutter::data, DrawCompressedTextureGolden(), impeller::kETC2, and impeller::kETC2RGB8UNormInt.

◆ TEST_P() [581/662]

impeller::testing::TEST_P ( RendererGoldenTest  ,
CanRenderInstancedWithVertexAttributes   
)

Definition at line 102 of file renderer_golden_unittests.cc.

102 {
103 using VS = InstancedAttributesVertexShader;
104 using FS = InstancedAttributesFragmentShader;
105
106 std::shared_ptr<Context> context = GetContext();
107 ASSERT_TRUE(context);
108
110 ASSERT_TRUE(desc.has_value());
111 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*desc));
112
113 // Per-instance data is laid out contiguously, one record per instance.
114 struct InstanceData {
115 Vector2 offset;
116 Vector4 color;
117 };
118
119 // Two vertex bindings: binding 0 carries per-vertex geometry and advances
120 // once per vertex; binding 1 carries per-instance data and advances once
121 // per instance.
122 auto vertex_desc = std::make_shared<VertexDescriptor>();
123 ShaderStageIOSlot position_slot = VS::kInputVertexPosition;
124 ShaderStageIOSlot offset_slot = VS::kInputInstanceOffset;
125 ShaderStageIOSlot color_slot = VS::kInputInstanceColor;
126 position_slot.binding = 0;
127 position_slot.offset = 0;
128 offset_slot.binding = 1;
129 offset_slot.offset = offsetof(InstanceData, offset);
130 color_slot.binding = 1;
131 color_slot.offset = offsetof(InstanceData, color);
132 const std::vector<ShaderStageIOSlot> io_slots = {position_slot, offset_slot,
133 color_slot};
134 const std::vector<ShaderStageBufferLayout> layouts = {
135 ShaderStageBufferLayout{.stride = sizeof(Vector2),
136 .binding = 0,
137 .input_rate = VertexInputRate::kVertex},
138 ShaderStageBufferLayout{.stride = sizeof(InstanceData),
139 .binding = 1,
140 .input_rate = VertexInputRate::kInstance},
141 };
142 vertex_desc->RegisterDescriptorSetLayouts(VS::kDescriptorSetLayouts);
143 vertex_desc->RegisterDescriptorSetLayouts(FS::kDescriptorSetLayouts);
144 vertex_desc->SetStageInputs(io_slots, layouts);
145 desc->SetVertexDescriptor(std::move(vertex_desc));
146 auto pipeline =
147 context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
148 ASSERT_TRUE(pipeline);
149
150 // A single triangle, drawn once per instance.
151 std::array<Vector2, 3> geometry = {
152 Vector2{0, 0},
153 Vector2{0, 100},
154 Vector2{100, 0},
155 };
156
157 static constexpr size_t kInstanceCount = 4u;
158 std::array<InstanceData, kInstanceCount> instances = {
159 InstanceData{Vector2{0, 0}, Vector4{1, 0, 0, 1}},
160 InstanceData{Vector2{120, 0}, Vector4{0, 1, 0, 1}},
161 InstanceData{Vector2{0, 120}, Vector4{0, 0, 1, 1}},
162 InstanceData{Vector2{120, 120}, Vector4{1, 1, 0, 1}},
163 };
164
165 auto geometry_buffer = context->GetResourceAllocator()->CreateBufferWithCopy(
166 reinterpret_cast<uint8_t*>(geometry.data()),
167 geometry.size() * sizeof(Vector2));
168 auto instance_buffer = context->GetResourceAllocator()->CreateBufferWithCopy(
169 reinterpret_cast<uint8_t*>(instances.data()),
170 instances.size() * sizeof(InstanceData));
171 ASSERT_TRUE(geometry_buffer && instance_buffer);
172
173 auto host_buffer = HostBuffer::Create(
174 context->GetResourceAllocator(), context->GetIdleWaiter(),
175 context->GetCapabilities()->GetMinimumUniformAlignment());
176
177 ASSERT_TRUE(OpenPlaygroundHere([&](RenderPass& pass) -> bool {
178 // The harness runs the callback once per pass; start each from a clean
179 // host buffer.
180 host_buffer->Reset();
181 pass.SetCommandLabel("InstancedAttributes");
182 pass.SetPipeline(pipeline);
183
184 std::array<BufferView, 2> vertex_buffers = {
185 BufferView(geometry_buffer,
186 Range(0, geometry.size() * sizeof(Vector2))),
187 BufferView(instance_buffer,
188 Range(0, instances.size() * sizeof(InstanceData))),
189 };
190 pass.SetVertexBuffer(vertex_buffers.data(), vertex_buffers.size());
191 pass.SetElementCount(geometry.size());
192 pass.SetInstanceCount(kInstanceCount);
193
194 VS::FrameInfo frame_info;
195 frame_info.mvp =
196 pass.GetOrthographicTransform() * Matrix::MakeScale(GetContentScale());
197 VS::BindFrameInfo(pass, host_buffer->EmplaceUniform(frame_info));
198
199 return pass.Draw().ok();
200 }));
201}

References impeller::ShaderStageIOSlot::binding, context, impeller::HostBuffer::Create(), impeller::RenderPass::Draw(), impeller::RenderPass::GetOrthographicTransform(), impeller::kInstance, impeller::kVertex, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::Matrix::MakeScale(), impeller::ShaderStageIOSlot::offset, fml::Status::ok(), pipeline, impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetElementCount(), impeller::RenderPass::SetInstanceCount(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetVertexBuffer(), and impeller::ShaderStageBufferLayout::stride.

◆ TEST_P() [582/662]

impeller::testing::TEST_P ( RendererGoldenTest  ,
CanSampleManuallyMippedTexture   
)

Definition at line 496 of file renderer_golden_unittests.cc.

496 {
497 DrawManuallyMippedTextureGolden(*this, /*lod=*/0.0f);
498}
static void DrawManuallyMippedTextureGolden(RendererGoldenTest &test, float lod)

References DrawManuallyMippedTextureGolden().

◆ TEST_P() [583/662]

impeller::testing::TEST_P ( RendererGoldenTest  ,
CanSampleManuallyMippedTextureLod1   
)

Definition at line 501 of file renderer_golden_unittests.cc.

501 {
502 DrawManuallyMippedTextureGolden(*this, /*lod=*/1.0f);
503}

References DrawManuallyMippedTextureGolden().

◆ TEST_P() [584/662]

impeller::testing::TEST_P ( RendererTest  ,
ArrayUniforms   
)

Definition at line 989 of file renderer_unittests.cc.

989 {
990 using VS = ArrayVertexShader;
991 using FS = ArrayFragmentShader;
992
993 auto context = GetContext();
994 auto pipeline_descriptor =
996 ASSERT_TRUE(pipeline_descriptor.has_value());
997 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*pipeline_descriptor));
998 auto pipeline =
999 context->GetPipelineLibrary()->GetPipeline(pipeline_descriptor).Get();
1000 ASSERT_TRUE(pipeline && pipeline->IsValid());
1001
1002 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
1003 SinglePassCallback callback = [&](RenderPass& pass) {
1004 auto size = pass.GetRenderTargetSize();
1005
1006 pass.SetPipeline(pipeline);
1007 pass.SetCommandLabel("Google Dots");
1009 builder.AddVertices({{Point()},
1010 {Point(0, size.height)},
1011 {Point(size.width, 0)},
1012 {Point(size.width, 0)},
1013 {Point(0, size.height)},
1014 {Point(size.width, size.height)}});
1015 pass.SetVertexBuffer(
1016 builder.CreateVertexBuffer(*data_host_buffer, *indexes_host_buffer));
1017
1018 VS::FrameInfo frame_info;
1019 EXPECT_EQ(pass.GetOrthographicTransform(), Matrix::MakeOrthographic(size));
1020 frame_info.mvp =
1021 pass.GetOrthographicTransform() * Matrix::MakeScale(GetContentScale());
1022 VS::BindFrameInfo(pass, data_host_buffer->EmplaceUniform(frame_info));
1023
1024 auto time = GetSecondsElapsed();
1025 auto y_pos = [&time](float x) {
1026 return 400 + 10 * std::cos(time * 5 + x / 6);
1027 };
1028
1029 FS::FragInfo fs_uniform = {
1030 .circle_positions = {Point(430, y_pos(0)), Point(480, y_pos(1)),
1031 Point(530, y_pos(2)), Point(580, y_pos(3))},
1032 .colors = {Color::MakeRGBA8(66, 133, 244, 255),
1033 Color::MakeRGBA8(219, 68, 55, 255),
1034 Color::MakeRGBA8(244, 180, 0, 255),
1035 Color::MakeRGBA8(15, 157, 88, 255)},
1036 };
1037 FS::BindFragInfo(pass, data_host_buffer->EmplaceUniform(fs_uniform));
1038
1039 pass.Draw();
1040 data_host_buffer->Reset();
1041 return true;
1042 };
1043 OpenPlaygroundHere(callback);
1044}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), callback, context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::Matrix::MakeOrthographic(), impeller::Color::MakeRGBA8(), impeller::Matrix::MakeScale(), pipeline, flutter::size, and x.

◆ TEST_P() [585/662]

impeller::testing::TEST_P ( RendererTest  ,
AttachmentRejectsOutOfRangeSubresource   
)

Definition at line 1691 of file renderer_unittests.cc.

1691 {
1692 auto context = GetContext();
1693 ASSERT_TRUE(context);
1694
1695 TextureDescriptor desc;
1696 desc.storage_mode = StorageMode::kDevicePrivate;
1697 desc.format = PixelFormat::kR8G8B8A8UNormInt;
1698 desc.size = {100, 100};
1699 desc.mip_count = 2u;
1700 desc.usage = TextureUsage::kRenderTarget;
1701 auto texture = context->GetResourceAllocator()->CreateTexture(desc);
1702 ASSERT_TRUE(texture);
1703
1704 ColorAttachment color0;
1705 color0.texture = texture;
1706 color0.load_action = LoadAction::kClear;
1707 color0.store_action = StoreAction::kStore;
1708 EXPECT_TRUE(color0.IsValid());
1709
1710 // The out-of-range cases log validation errors on purpose.
1711 ScopedValidationDisable disable_validation;
1712
1713 color0.mip_level = 2u; // Only levels 0 and 1 exist.
1714 EXPECT_FALSE(color0.IsValid());
1715
1716 color0.mip_level = 0u;
1717 color0.slice = 1u; // A 2D texture has a single slice.
1718 EXPECT_FALSE(color0.IsValid());
1719}
bool IsValid() const
Definition formats.cc:26

References context, impeller::TextureDescriptor::format, impeller::Attachment::IsValid(), impeller::kClear, impeller::kDevicePrivate, impeller::kR8G8B8A8UNormInt, impeller::kRenderTarget, impeller::kStore, impeller::Attachment::load_action, impeller::TextureDescriptor::mip_count, impeller::Attachment::mip_level, impeller::TextureDescriptor::size, impeller::Attachment::slice, impeller::TextureDescriptor::storage_mode, impeller::Attachment::store_action, impeller::Attachment::texture, texture, and impeller::TextureDescriptor::usage.

◆ TEST_P() [586/662]

impeller::testing::TEST_P ( RendererTest  ,
BindingNullTexturesDoesNotCrash   
)

Definition at line 1605 of file renderer_unittests.cc.

1605 {
1606 using FS = BoxFadeFragmentShader;
1607
1608 auto context = GetContext();
1609 raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
1610 auto command_buffer = context->CreateCommandBuffer();
1611
1612 RenderTargetAllocator allocator(context->GetResourceAllocator());
1613 RenderTarget target = allocator.CreateOffscreen(*context, {1, 1}, 1);
1614
1615 auto pass = command_buffer->CreateRenderPass(target);
1616 EXPECT_FALSE(FS::BindContents2(*pass, nullptr, sampler));
1617}

References allocator, command_buffer, context, and target.

◆ TEST_P() [587/662]

impeller::testing::TEST_P ( RendererTest  ,
CachesRenderPassAndFramebuffer   
)

Definition at line 18 of file render_pass_cache_unittests.cc.

18 {
19 if (GetBackend() != PlaygroundBackend::kVulkan) {
20 GTEST_SKIP() << "Test only applies to Vulkan";
21 }
22
23 auto allocator = std::make_shared<RenderTargetAllocator>(
24 GetContext()->GetResourceAllocator());
25
26 RenderTarget render_target =
27 allocator->CreateOffscreenMSAA(*GetContext(), {100, 100}, 1);
28 std::shared_ptr<Texture> resolve_texture =
29 render_target.GetColorAttachment(0).resolve_texture;
30 TextureVK& texture_vk = TextureVK::Cast(*resolve_texture);
31
32 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount4).framebuffer,
33 nullptr);
34 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount4).render_pass,
35 nullptr);
36
37 auto buffer = GetContext()->CreateCommandBuffer();
38 auto render_pass = buffer->CreateRenderPass(render_target);
39
40 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount4).framebuffer,
41 nullptr);
42 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount4).render_pass,
43 nullptr);
44
45 render_pass->EncodeCommands();
46 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer}).ok());
47
48 // Can be reused without error.
49 auto buffer_2 = GetContext()->CreateCommandBuffer();
50 auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
51
52 EXPECT_TRUE(render_pass_2->EncodeCommands());
53 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
54}

References allocator, flutter::buffer, impeller::BackendCast< TextureVK, Texture >::Cast(), impeller::FramebufferAndRenderPass::framebuffer, impeller::TextureVK::GetCachedFrameData(), impeller::RenderTarget::GetColorAttachment(), impeller::kCount4, impeller::kVulkan, render_pass, impeller::FramebufferAndRenderPass::render_pass, and impeller::Attachment::resolve_texture.

◆ TEST_P() [588/662]

impeller::testing::TEST_P ( RendererTest  ,
CachesRenderPassAndFramebufferMixed   
)

Definition at line 94 of file render_pass_cache_unittests.cc.

94 {
95 if (GetBackend() != PlaygroundBackend::kVulkan) {
96 GTEST_SKIP() << "Test only applies to Vulkan";
97 }
98
99 auto allocator = std::make_shared<RenderTargetAllocator>(
100 GetContext()->GetResourceAllocator());
101
102 RenderTarget render_target =
103 allocator->CreateOffscreenMSAA(*GetContext(), {100, 100}, 1);
104 std::shared_ptr<Texture> resolve_texture =
105 render_target.GetColorAttachment(0).resolve_texture;
106 TextureVK& texture_vk = TextureVK::Cast(*resolve_texture);
107
108 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount4).framebuffer,
109 nullptr);
110 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount4).render_pass,
111 nullptr);
112
113 auto buffer = GetContext()->CreateCommandBuffer();
114 auto render_pass = buffer->CreateRenderPass(render_target);
115
116 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount4).framebuffer,
117 nullptr);
118 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount4).render_pass,
119 nullptr);
120
121 render_pass->EncodeCommands();
122 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer}).ok());
123
124 // Can be reused without error.
125 auto buffer_2 = GetContext()->CreateCommandBuffer();
126 auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
127
128 EXPECT_TRUE(render_pass_2->EncodeCommands());
129 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
130
131 // Now switch to single sample count and demonstrate no validation errors.
132 {
133 RenderTarget other_target;
134 ColorAttachment color0;
135 color0.load_action = LoadAction::kLoad;
136 color0.store_action = StoreAction::kStore;
137 color0.texture = resolve_texture;
138 other_target.SetColorAttachment(color0, 0);
139 other_target.SetDepthAttachment(std::nullopt);
140 other_target.SetStencilAttachment(std::nullopt);
141
142 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount1).framebuffer,
143 nullptr);
144 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount1).render_pass,
145 nullptr);
146
147 auto buffer_3 = GetContext()->CreateCommandBuffer();
148 auto render_pass_3 = buffer_3->CreateRenderPass(other_target);
149
150 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount1).framebuffer,
151 nullptr);
152 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount1).render_pass,
153 nullptr);
154
155 EXPECT_TRUE(render_pass_3->EncodeCommands());
156 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_3}).ok());
157 }
158}

References allocator, flutter::buffer, impeller::BackendCast< TextureVK, Texture >::Cast(), impeller::FramebufferAndRenderPass::framebuffer, impeller::TextureVK::GetCachedFrameData(), impeller::RenderTarget::GetColorAttachment(), impeller::kCount1, impeller::kCount4, impeller::kLoad, impeller::kStore, impeller::kVulkan, impeller::Attachment::load_action, render_pass, impeller::FramebufferAndRenderPass::render_pass, impeller::Attachment::resolve_texture, impeller::RenderTarget::SetColorAttachment(), impeller::RenderTarget::SetDepthAttachment(), impeller::RenderTarget::SetStencilAttachment(), impeller::Attachment::store_action, and impeller::Attachment::texture.

◆ TEST_P() [589/662]

impeller::testing::TEST_P ( RendererTest  ,
CachesRenderPassAndFramebufferNonMSAA   
)

Definition at line 56 of file render_pass_cache_unittests.cc.

56 {
57 if (GetBackend() != PlaygroundBackend::kVulkan) {
58 GTEST_SKIP() << "Test only applies to Vulkan";
59 }
60
61 auto allocator = std::make_shared<RenderTargetAllocator>(
62 GetContext()->GetResourceAllocator());
63
64 RenderTarget render_target =
65 allocator->CreateOffscreen(*GetContext(), {100, 100}, 1);
66 std::shared_ptr<Texture> color_texture =
67 render_target.GetColorAttachment(0).texture;
68 TextureVK& texture_vk = TextureVK::Cast(*color_texture);
69
70 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount1).framebuffer,
71 nullptr);
72 EXPECT_EQ(texture_vk.GetCachedFrameData(SampleCount::kCount1).render_pass,
73 nullptr);
74
75 auto buffer = GetContext()->CreateCommandBuffer();
76 auto render_pass = buffer->CreateRenderPass(render_target);
77
78 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount1).framebuffer,
79 nullptr);
80 EXPECT_NE(texture_vk.GetCachedFrameData(SampleCount::kCount1).render_pass,
81 nullptr);
82
83 render_pass->EncodeCommands();
84 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer}).ok());
85
86 // Can be reused without error.
87 auto buffer_2 = GetContext()->CreateCommandBuffer();
88 auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
89
90 EXPECT_TRUE(render_pass_2->EncodeCommands());
91 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
92}

References allocator, flutter::buffer, impeller::BackendCast< TextureVK, Texture >::Cast(), impeller::FramebufferAndRenderPass::framebuffer, impeller::TextureVK::GetCachedFrameData(), impeller::RenderTarget::GetColorAttachment(), impeller::kCount1, impeller::kVulkan, render_pass, impeller::FramebufferAndRenderPass::render_pass, and impeller::Attachment::texture.

◆ TEST_P() [590/662]

impeller::testing::TEST_P ( RendererTest  ,
CanBlitTextureToBuffer   
)

Definition at line 607 of file renderer_unittests.cc.

607 {
608 if (GetBackend() == PlaygroundBackend::kOpenGLES ||
609 GetBackend() == PlaygroundBackend::kOpenGLESSDF) {
610 GTEST_SKIP() << "Mipmap test shader not supported on GLES.";
611 }
612 auto context = GetContext();
613 ASSERT_TRUE(context);
614
615 using VS = MipmapsVertexShader;
616 using FS = MipmapsFragmentShader;
618 ASSERT_TRUE(desc.has_value());
619 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*desc));
620 auto mipmaps_pipeline =
621 context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
622 ASSERT_TRUE(mipmaps_pipeline);
623
624 auto bridge = CreateTextureForFixture("bay_bridge.jpg");
625 auto boston = CreateTextureForFixture("boston.jpg");
626 ASSERT_TRUE(bridge && boston);
627 raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
628 ASSERT_TRUE(sampler);
629
630 TextureDescriptor texture_desc;
631 texture_desc.storage_mode = StorageMode::kHostVisible;
632 texture_desc.format = PixelFormat::kR8G8B8A8UNormInt;
633 texture_desc.size = bridge->GetTextureDescriptor().size;
634 texture_desc.mip_count = 1u;
635 texture_desc.usage = TextureUsage::kRenderTarget |
636 TextureUsage::kShaderWrite | TextureUsage::kShaderRead;
637 DeviceBufferDescriptor device_buffer_desc;
638 device_buffer_desc.storage_mode = StorageMode::kHostVisible;
639 device_buffer_desc.size =
640 bridge->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
641 auto device_buffer =
642 context->GetResourceAllocator()->CreateBuffer(device_buffer_desc);
643
644 // Vertex buffer.
645 VertexBufferBuilder<VS::PerVertexData> vertex_builder;
646 vertex_builder.SetLabel("Box");
647 auto size = Point(boston->GetSize());
648 vertex_builder.AddVertices({
649 {{0, 0}, {0.0, 0.0}}, // 1
650 {{size.x, 0}, {1.0, 0.0}}, // 2
651 {{size.x, size.y}, {1.0, 1.0}}, // 3
652 {{0, 0}, {0.0, 0.0}}, // 1
653 {{size.x, size.y}, {1.0, 1.0}}, // 3
654 {{0, size.y}, {0.0, 1.0}}, // 4
655 });
656 auto vertex_buffer =
657 vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator());
658 ASSERT_TRUE(vertex_buffer);
659
660 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
661 Playground::RenderCallback callback = [&](RenderTarget& render_target) {
662 {
663 auto buffer = context->CreateCommandBuffer();
664 if (!buffer) {
665 return false;
666 }
667 buffer->SetLabel("Playground Command Buffer");
668 auto pass = buffer->CreateBlitPass();
669 if (!pass) {
670 return false;
671 }
672 pass->SetLabel("Playground Blit Pass");
673
674 // Blit `bridge` to the top left corner of the texture.
675 pass->AddCopy(bridge, device_buffer);
676 pass->EncodeCommands();
677
678 if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
679 return false;
680 }
681 }
682
683 {
684 auto buffer = context->CreateCommandBuffer();
685 if (!buffer) {
686 return false;
687 }
688 buffer->SetLabel("Playground Command Buffer");
689
690 auto pass = buffer->CreateRenderPass(render_target);
691 if (!pass) {
692 return false;
693 }
694 pass->SetLabel("Playground Render Pass");
695 {
696 pass->SetCommandLabel("Image");
697 pass->SetPipeline(mipmaps_pipeline);
698 pass->SetVertexBuffer(vertex_buffer);
699
700 VS::FrameInfo frame_info;
701 EXPECT_EQ(pass->GetOrthographicTransform(),
702 Matrix::MakeOrthographic(pass->GetRenderTargetSize()));
703 frame_info.mvp = pass->GetOrthographicTransform() *
704 Matrix::MakeScale(GetContentScale());
705 VS::BindFrameInfo(*pass, data_host_buffer->EmplaceUniform(frame_info));
706
707 FS::FragInfo frag_info;
708 frag_info.lod = 0;
709 FS::BindFragInfo(*pass, data_host_buffer->EmplaceUniform(frag_info));
710
711 raw_ptr<const Sampler> sampler =
712 context->GetSamplerLibrary()->GetSampler({});
713 auto buffer_view = DeviceBuffer::AsBufferView(device_buffer);
714 auto texture =
715 context->GetResourceAllocator()->CreateTexture(texture_desc);
716 if (!texture->SetContents(device_buffer->OnGetContents(),
717 buffer_view.GetRange().length)) {
718 VALIDATION_LOG << "Could not upload texture to device memory";
719 return false;
720 }
721 FS::BindTex(*pass, texture, sampler);
722
723 pass->Draw().ok();
724 }
725 pass->EncodeCommands();
726 if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
727 return false;
728 }
729 }
730 data_host_buffer->Reset();
731 return true;
732 };
733 OpenPlaygroundHere(callback);
734}
#define VALIDATION_LOG
Definition validation.h:91

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), impeller::DeviceBuffer::AsBufferView(), flutter::buffer, callback, context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::TextureDescriptor::format, impeller::kHostVisible, impeller::kOpenGLES, impeller::kOpenGLESSDF, impeller::kR8G8B8A8UNormInt, impeller::kRenderTarget, impeller::kShaderRead, impeller::kShaderWrite, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::Matrix::MakeOrthographic(), impeller::Matrix::MakeScale(), impeller::TextureDescriptor::mip_count, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::SetLabel(), impeller::DeviceBufferDescriptor::size, impeller::TextureDescriptor::size, flutter::size, impeller::DeviceBufferDescriptor::storage_mode, impeller::TextureDescriptor::storage_mode, texture, impeller::TextureDescriptor::usage, and VALIDATION_LOG.

◆ TEST_P() [591/662]

impeller::testing::TEST_P ( RendererTest  ,
CanBlitTextureToTexture   
)

Definition at line 490 of file renderer_unittests.cc.

490 {
491 if (GetBackend() == PlaygroundBackend::kOpenGLES ||
492 GetBackend() == PlaygroundBackend::kOpenGLESSDF ||
493 GetBackend() == PlaygroundBackend::kVulkan) {
494 GTEST_SKIP() << "Mipmap test shader not supported on GLES or Vulkan.";
495 }
496 auto context = GetContext();
497 ASSERT_TRUE(context);
498
499 using VS = MipmapsVertexShader;
500 using FS = MipmapsFragmentShader;
502 ASSERT_TRUE(desc.has_value());
503 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*desc));
504 auto mipmaps_pipeline =
505 context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
506 ASSERT_TRUE(mipmaps_pipeline);
507
508 TextureDescriptor texture_desc;
509 texture_desc.storage_mode = StorageMode::kHostVisible;
510 texture_desc.format = PixelFormat::kR8G8B8A8UNormInt;
511 texture_desc.size = {800, 600};
512 texture_desc.mip_count = 1u;
513 texture_desc.usage = TextureUsage::kRenderTarget | TextureUsage::kShaderRead;
514 auto texture = context->GetResourceAllocator()->CreateTexture(texture_desc);
515 ASSERT_TRUE(texture);
516
517 auto bridge = CreateTextureForFixture("bay_bridge.jpg");
518 auto boston = CreateTextureForFixture("boston.jpg");
519 ASSERT_TRUE(bridge && boston);
520 raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
521 ASSERT_TRUE(sampler);
522
523 // Vertex buffer.
524 VertexBufferBuilder<VS::PerVertexData> vertex_builder;
525 vertex_builder.SetLabel("Box");
526 auto size = Point(boston->GetSize());
527 vertex_builder.AddVertices({
528 {{0, 0}, {0.0, 0.0}}, // 1
529 {{size.x, 0}, {1.0, 0.0}}, // 2
530 {{size.x, size.y}, {1.0, 1.0}}, // 3
531 {{0, 0}, {0.0, 0.0}}, // 1
532 {{size.x, size.y}, {1.0, 1.0}}, // 3
533 {{0, size.y}, {0.0, 1.0}}, // 4
534 });
535 auto vertex_buffer =
536 vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator());
537 ASSERT_TRUE(vertex_buffer);
538
539 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
540 Playground::RenderCallback callback = [&](RenderTarget& render_target) {
541 auto buffer = context->CreateCommandBuffer();
542 if (!buffer) {
543 return false;
544 }
545 buffer->SetLabel("Playground Command Buffer");
546
547 {
548 auto pass = buffer->CreateBlitPass();
549 if (!pass) {
550 return false;
551 }
552 pass->SetLabel("Playground Blit Pass");
553
554 // Blit `bridge` to the top left corner of the texture.
555 // The bridge image is larger than the texture which can fail
556 // if Metal validation is enabled as it is in run_tests.py.
557 IRect bridge_bounds = IRect::MakeSize(bridge->GetSize());
558 IRect texture_bounds = IRect::MakeSize(texture->GetSize());
559 std::optional<IRect> blit_bounds =
560 bridge_bounds.Intersection(texture_bounds);
561 pass->AddCopy(bridge, texture, blit_bounds);
562
563 if (!pass->EncodeCommands()) {
564 return false;
565 }
566 }
567
568 {
569 auto pass = buffer->CreateRenderPass(render_target);
570 if (!pass) {
571 return false;
572 }
573 pass->SetLabel("Playground Render Pass");
574 {
575 pass->SetCommandLabel("Image");
576 pass->SetPipeline(mipmaps_pipeline);
577 pass->SetVertexBuffer(vertex_buffer);
578
579 VS::FrameInfo frame_info;
580 EXPECT_EQ(pass->GetOrthographicTransform(),
581 Matrix::MakeOrthographic(pass->GetRenderTargetSize()));
582 frame_info.mvp = pass->GetOrthographicTransform() *
583 Matrix::MakeScale(GetContentScale());
584 VS::BindFrameInfo(*pass, data_host_buffer->EmplaceUniform(frame_info));
585
586 FS::FragInfo frag_info;
587 frag_info.lod = 0;
588 FS::BindFragInfo(*pass, data_host_buffer->EmplaceUniform(frag_info));
589
590 auto sampler = context->GetSamplerLibrary()->GetSampler({});
591 FS::BindTex(*pass, texture, sampler);
592
593 pass->Draw();
594 }
595 pass->EncodeCommands();
596 }
597
598 if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
599 return false;
600 }
601 data_host_buffer->Reset();
602 return true;
603 };
604 OpenPlaygroundHere(callback);
605}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), flutter::buffer, callback, context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::TextureDescriptor::format, impeller::TRect< T >::Intersection(), impeller::kHostVisible, impeller::kOpenGLES, impeller::kOpenGLESSDF, impeller::kR8G8B8A8UNormInt, impeller::kRenderTarget, impeller::kShaderRead, impeller::kVulkan, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::Matrix::MakeOrthographic(), impeller::Matrix::MakeScale(), impeller::TRect< T >::MakeSize(), impeller::TextureDescriptor::mip_count, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::SetLabel(), impeller::TextureDescriptor::size, flutter::size, impeller::TextureDescriptor::storage_mode, texture, and impeller::TextureDescriptor::usage.

◆ TEST_P() [592/662]

impeller::testing::TEST_P ( RendererTest  ,
CanCreateBoxPrimitive   
)

Definition at line 69 of file renderer_unittests.cc.

69 {
70 using VS = BoxFadeVertexShader;
71 using FS = BoxFadeFragmentShader;
72 auto context = GetContext();
73 ASSERT_TRUE(context);
74 using BoxPipelineBuilder = PipelineBuilder<VS, FS>;
75 auto desc = BoxPipelineBuilder::MakeDefaultPipelineDescriptor(*context);
76 ASSERT_TRUE(desc.has_value());
77 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*desc));
78 desc->SetSampleCount(SampleCount::kCount4);
79 desc->ClearStencilAttachments();
80 desc->ClearDepthAttachment();
81
82 // Vertex buffer.
84 vertex_builder.SetLabel("Box");
85 vertex_builder.AddVertices({
86 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
87 {{800, 100, 0.0}, {1.0, 0.0}}, // 2
88 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
89 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
90 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
91 {{100, 800, 0.0}, {0.0, 1.0}}, // 4
92 });
93 auto bridge = CreateTextureForFixture("bay_bridge.jpg");
94 auto boston = CreateTextureForFixture("boston.jpg");
95 ASSERT_TRUE(bridge && boston);
96 raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
97 ASSERT_TRUE(sampler);
98
99 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
100 SinglePassCallback callback = [&](RenderPass& pass) {
101 static bool wireframe;
102 if (IsPlaygroundEnabled()) {
103 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
104 ImGui::Checkbox("Wireframe", &wireframe);
105 ImGui::End();
106 }
107
108 desc->SetPolygonMode(wireframe ? PolygonMode::kLine : PolygonMode::kFill);
109 auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).Get();
110
111 assert(pipeline && pipeline->IsValid());
112
113 pass.SetCommandLabel("Box");
114 pass.SetPipeline(pipeline);
115 pass.SetVertexBuffer(
116 vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator()));
117
118 VS::UniformBuffer uniforms;
119 EXPECT_EQ(pass.GetOrthographicTransform(),
120 Matrix::MakeOrthographic(pass.GetRenderTargetSize()));
121 uniforms.mvp =
122 pass.GetOrthographicTransform() * Matrix::MakeScale(GetContentScale());
123 VS::BindUniformBuffer(pass, data_host_buffer->EmplaceUniform(uniforms));
124
125 FS::FrameInfo frame_info;
126 frame_info.current_time = GetSecondsElapsed();
127 frame_info.cursor_position = GetCursorPosition();
128 frame_info.window_size.x = GetWindowSize().width;
129 frame_info.window_size.y = GetWindowSize().height;
130
131 FS::BindFrameInfo(pass, data_host_buffer->EmplaceUniform(frame_info));
132 FS::BindContents1(pass, boston, sampler);
133 FS::BindContents2(pass, bridge, sampler);
134
135 data_host_buffer->Reset();
136 return pass.Draw().ok();
137 };
138 OpenPlaygroundHere(callback);
139}
void SetLabel(const std::string &label)

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), callback, context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::kCount4, impeller::kFill, impeller::kLine, impeller::Matrix::MakeOrthographic(), impeller::Matrix::MakeScale(), pipeline, and impeller::VertexBufferBuilder< VertexType_, IndexType_ >::SetLabel().

◆ TEST_P() [593/662]

impeller::testing::TEST_P ( RendererTest  ,
CanGenerateMipmaps   
)

Definition at line 736 of file renderer_unittests.cc.

736 {
737 if (GetBackend() == PlaygroundBackend::kOpenGLES ||
738 GetBackend() == PlaygroundBackend::kOpenGLESSDF) {
739 GTEST_SKIP() << "Mipmap test shader not supported on GLES.";
740 }
741 auto context = GetContext();
742 ASSERT_TRUE(context);
743
744 using VS = MipmapsVertexShader;
745 using FS = MipmapsFragmentShader;
747 ASSERT_TRUE(desc.has_value());
748 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*desc));
749 auto mipmaps_pipeline =
750 context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
751 ASSERT_TRUE(mipmaps_pipeline);
752
753 auto boston = CreateTextureForFixture("boston.jpg", true);
754 ASSERT_TRUE(boston);
755
756 // Vertex buffer.
758 vertex_builder.SetLabel("Box");
759 auto size = Point(boston->GetSize());
760 vertex_builder.AddVertices({
761 {{0, 0}, {0.0, 0.0}}, // 1
762 {{size.x, 0}, {1.0, 0.0}}, // 2
763 {{size.x, size.y}, {1.0, 1.0}}, // 3
764 {{0, 0}, {0.0, 0.0}}, // 1
765 {{size.x, size.y}, {1.0, 1.0}}, // 3
766 {{0, size.y}, {0.0, 1.0}}, // 4
767 });
768 auto vertex_buffer =
769 vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator());
770 ASSERT_TRUE(vertex_buffer);
771
772 bool first_frame = true;
773 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
774 Playground::RenderCallback callback = [&](RenderTarget& render_target) {
775 const char* mip_filter_names[] = {"Base", "Nearest", "Linear"};
776 const MipFilter mip_filters[] = {MipFilter::kBase, MipFilter::kNearest,
777 MipFilter::kLinear};
778 const char* min_filter_names[] = {"Nearest", "Linear"};
779 const MinMagFilter min_filters[] = {MinMagFilter::kNearest,
780 MinMagFilter::kLinear};
781
782 // UI state.
783 static int selected_mip_filter = 1;
784 static int selected_min_filter = 0;
785 static float lod = 4.5;
786
787 if (IsPlaygroundEnabled()) {
788 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
789 ImGui::Combo("Mip filter", &selected_mip_filter, mip_filter_names,
790 sizeof(mip_filter_names) / sizeof(char*));
791 ImGui::Combo("Min filter", &selected_min_filter, min_filter_names,
792 sizeof(min_filter_names) / sizeof(char*));
793 ImGui::SliderFloat("LOD", &lod, 0, boston->GetMipCount() - 1);
794 ImGui::End();
795 }
796
797 auto buffer = context->CreateCommandBuffer();
798 if (!buffer) {
799 return false;
800 }
801 buffer->SetLabel("Playground Command Buffer");
802
803 if (first_frame) {
804 auto pass = buffer->CreateBlitPass();
805 if (!pass) {
806 return false;
807 }
808 pass->SetLabel("Playground Blit Pass");
809
810 pass->GenerateMipmap(boston, "Boston Mipmap");
811
812 pass->EncodeCommands();
813 }
814
815 first_frame = false;
816
817 {
818 auto pass = buffer->CreateRenderPass(render_target);
819 if (!pass) {
820 return false;
821 }
822 pass->SetLabel("Playground Render Pass");
823 {
824 pass->SetCommandLabel("Image LOD");
825 pass->SetPipeline(mipmaps_pipeline);
826 pass->SetVertexBuffer(vertex_buffer);
827
828 VS::FrameInfo frame_info;
829 EXPECT_EQ(pass->GetOrthographicTransform(),
830 Matrix::MakeOrthographic(pass->GetRenderTargetSize()));
831 frame_info.mvp = pass->GetOrthographicTransform() *
832 Matrix::MakeScale(GetContentScale());
833 VS::BindFrameInfo(*pass, data_host_buffer->EmplaceUniform(frame_info));
834
835 FS::FragInfo frag_info;
836 frag_info.lod = lod;
837 FS::BindFragInfo(*pass, data_host_buffer->EmplaceUniform(frag_info));
838
839 SamplerDescriptor sampler_desc;
840 sampler_desc.mip_filter = mip_filters[selected_mip_filter];
841 sampler_desc.min_filter = min_filters[selected_min_filter];
842 raw_ptr<const Sampler> sampler =
843 context->GetSamplerLibrary()->GetSampler(sampler_desc);
844 FS::BindTex(*pass, boston, sampler);
845
846 pass->Draw();
847 }
848 pass->EncodeCommands();
849 }
850
851 if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
852 return false;
853 }
854 data_host_buffer->Reset();
855 return true;
856 };
857 OpenPlaygroundHere(callback);
858}
MipFilter
Options for selecting and filtering between mipmap levels.
Definition formats.h:602
MinMagFilter
Describes how the texture should be sampled when the texture is being shrunk (minified) or expanded (...
Definition formats.h:592

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), flutter::buffer, callback, context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::kBase, impeller::kLinear, impeller::kNearest, impeller::kOpenGLES, impeller::kOpenGLESSDF, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::Matrix::MakeOrthographic(), impeller::Matrix::MakeScale(), impeller::SamplerDescriptor::min_filter, impeller::SamplerDescriptor::mip_filter, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::SetLabel(), and flutter::size.

◆ TEST_P() [594/662]

impeller::testing::TEST_P ( RendererTest  ,
CanLookupRenderTargetProperties   
)

Definition at line 1340 of file renderer_unittests.cc.

1340 {
1341 auto context = GetContext();
1342 auto cmd_buffer = context->CreateCommandBuffer();
1343 auto render_target_cache = std::make_shared<RenderTargetAllocator>(
1344 GetContext()->GetResourceAllocator());
1345
1346 auto render_target = render_target_cache->CreateOffscreen(
1347 *context, {100, 100}, /*mip_count=*/1);
1348 auto render_pass = cmd_buffer->CreateRenderPass(render_target);
1349
1350 EXPECT_EQ(render_pass->GetSampleCount(), render_target.GetSampleCount());
1351 EXPECT_EQ(render_pass->GetRenderTargetPixelFormat(),
1352 render_target.GetRenderTargetPixelFormat());
1353 EXPECT_EQ(render_pass->HasStencilAttachment(),
1354 render_target.GetStencilAttachment().has_value());
1355 EXPECT_EQ(render_pass->GetRenderTargetSize(),
1356 render_target.GetRenderTargetSize());
1357 render_pass->EncodeCommands();
1358}

References context, and render_pass.

◆ TEST_P() [595/662]

impeller::testing::TEST_P ( RendererTest  ,
CanRenderInstanced   
)

Definition at line 427 of file renderer_unittests.cc.

427 {
428 if (GetParam() == PlaygroundBackend::kOpenGLES ||
429 GetParam() == PlaygroundBackend::kOpenGLESSDF) {
430 // This test drives instancing through gl_InstanceIndex and a storage
431 // buffer, both of which require OpenGL ES 3.1. The portable instance-rate
432 // vertex attribute path, which works down to OpenGL ES 2.0, is covered by
433 // CanRenderInstancedWithVertexAttributes.
434 GTEST_SKIP() << "This test's instance-ID mechanism requires OpenGL ES 3.1; "
435 "CanRenderInstancedWithVertexAttributes covers the "
436 "portable instance-rate path.";
437 }
438 using VS = InstancedDrawVertexShader;
439 using FS = InstancedDrawFragmentShader;
440
442 builder.AddVertices({
443 VS::PerVertexData{Point{10, 10}},
444 VS::PerVertexData{Point{10, 110}},
445 VS::PerVertexData{Point{110, 10}},
446 VS::PerVertexData{Point{10, 110}},
447 VS::PerVertexData{Point{110, 10}},
448 VS::PerVertexData{Point{110, 110}},
449 });
450
451 std::shared_ptr<Context> context = GetContext();
452 ASSERT_TRUE(context);
453 auto desc = PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor(*context);
454 ASSERT_TRUE(desc.has_value());
455 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*desc));
456 auto pipeline = GetContext()->GetPipelineLibrary()->GetPipeline(desc).Get();
457 ASSERT_TRUE(pipeline && pipeline->IsValid());
458
459 static constexpr size_t kInstancesCount = 5u;
460 VS::InstanceInfo<kInstancesCount> instances;
461 for (size_t i = 0; i < kInstancesCount; i++) {
462 instances.colors[i] = Color::Random();
463 }
464
465 auto [data_host_buffer, indexes_host_buffer] =
466 createHostBuffers(GetContext());
467 ASSERT_TRUE(OpenPlaygroundHere([&](RenderPass& pass) -> bool {
468 pass.SetPipeline(pipeline);
469 pass.SetCommandLabel("InstancedDraw");
470
471 VS::FrameInfo frame_info;
472 EXPECT_EQ(pass.GetOrthographicTransform(),
473 Matrix::MakeOrthographic(pass.GetRenderTargetSize()));
474 frame_info.mvp =
475 pass.GetOrthographicTransform() * Matrix::MakeScale(GetContentScale());
476 VS::BindFrameInfo(pass, data_host_buffer->EmplaceUniform(frame_info));
477 VS::BindInstanceInfo(pass,
478 data_host_buffer->EmplaceStorageBuffer(instances));
479 pass.SetVertexBuffer(
480 builder.CreateVertexBuffer(*data_host_buffer, *indexes_host_buffer));
481
482 pass.SetInstanceCount(kInstancesCount);
483 pass.Draw();
484
485 data_host_buffer->Reset();
486 return true;
487 }));
488}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::RenderPass::Draw(), impeller::RenderPass::GetOrthographicTransform(), impeller::RenderPass::GetRenderTargetSize(), i, impeller::kOpenGLES, impeller::kOpenGLESSDF, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::Matrix::MakeOrthographic(), impeller::Matrix::MakeScale(), pipeline, impeller::Color::Random(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetInstanceCount(), impeller::RenderPass::SetPipeline(), and impeller::RenderPass::SetVertexBuffer().

◆ TEST_P() [596/662]

impeller::testing::TEST_P ( RendererTest  ,
CanRenderMultiplePrimitives   
)

Definition at line 253 of file renderer_unittests.cc.

253 {
254 using VS = BoxFadeVertexShader;
255 using FS = BoxFadeFragmentShader;
256 auto context = GetContext();
257 ASSERT_TRUE(context);
258 using BoxPipelineBuilder = PipelineBuilder<VS, FS>;
259 auto desc = BoxPipelineBuilder::MakeDefaultPipelineDescriptor(*context);
260 ASSERT_TRUE(desc.has_value());
261 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*desc));
262 auto box_pipeline =
263 context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
264 ASSERT_TRUE(box_pipeline);
265
266 // Vertex buffer.
268 vertex_builder.SetLabel("Box");
269 vertex_builder.AddVertices({
270 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
271 {{800, 100, 0.0}, {1.0, 0.0}}, // 2
272 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
273 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
274 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
275 {{100, 800, 0.0}, {0.0, 1.0}}, // 4
276 });
277 auto vertex_buffer =
278 vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator());
279 ASSERT_TRUE(vertex_buffer);
280
281 auto bridge = CreateTextureForFixture("bay_bridge.jpg");
282 auto boston = CreateTextureForFixture("boston.jpg");
283 ASSERT_TRUE(bridge && boston);
284 raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
285 ASSERT_TRUE(sampler);
286
287 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
288 SinglePassCallback callback = [&](RenderPass& pass) {
289 for (size_t i = 0; i < 1; i++) {
290 for (size_t j = 0; j < 1; j++) {
291 pass.SetCommandLabel("Box");
292 pass.SetPipeline(box_pipeline);
293 pass.SetVertexBuffer(vertex_buffer);
294
295 FS::FrameInfo frame_info;
296 frame_info.current_time = GetSecondsElapsed();
297 frame_info.cursor_position = GetCursorPosition();
298 frame_info.window_size.x = GetWindowSize().width;
299 frame_info.window_size.y = GetWindowSize().height;
300
301 FS::BindFrameInfo(pass, data_host_buffer->EmplaceUniform(frame_info));
302 FS::BindContents1(pass, boston, sampler);
303 FS::BindContents2(pass, bridge, sampler);
304
305 VS::UniformBuffer uniforms;
306 EXPECT_EQ(pass.GetOrthographicTransform(),
307 Matrix::MakeOrthographic(pass.GetRenderTargetSize()));
308 uniforms.mvp = pass.GetOrthographicTransform() *
309 Matrix::MakeScale(GetContentScale()) *
310 Matrix::MakeTranslation({i * 50.0f, j * 50.0f, 0.0f});
311 VS::BindUniformBuffer(pass, data_host_buffer->EmplaceUniform(uniforms));
312 if (!pass.Draw().ok()) {
313 return false;
314 }
315 }
316 }
317
318 data_host_buffer->Reset();
319 return true;
320 };
321 OpenPlaygroundHere(callback);
322}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), callback, context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), i, impeller::Matrix::MakeOrthographic(), impeller::Matrix::MakeScale(), impeller::Matrix::MakeTranslation(), and impeller::VertexBufferBuilder< VertexType_, IndexType_ >::SetLabel().

◆ TEST_P() [597/662]

impeller::testing::TEST_P ( RendererTest  ,
CanRenderPerspectiveCube   
)

Definition at line 141 of file renderer_unittests.cc.

141 {
142 using VS = ColorsVertexShader;
143 using FS = ColorsFragmentShader;
144 auto context = GetContext();
145 ASSERT_TRUE(context);
147 ASSERT_TRUE(desc.has_value());
148 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*desc));
149 desc->SetCullMode(CullMode::kBackFace);
150 desc->SetWindingOrder(WindingOrder::kCounterClockwise);
151
152 // Setup the vertex layout to take two bindings. The first for positions and
153 // the second for colors.
154 auto vertex_desc = std::make_shared<VertexDescriptor>();
155 ShaderStageIOSlot position_slot = VS::kInputPosition;
156 ShaderStageIOSlot color_slot = VS::kInputColor;
157 position_slot.binding = 0;
158 position_slot.offset = 0;
159 color_slot.binding = 1;
160 color_slot.offset = 0;
161 const std::vector<ShaderStageIOSlot> io_slots = {position_slot, color_slot};
162 const std::vector<ShaderStageBufferLayout> layouts = {
163 ShaderStageBufferLayout{.stride = 12u, .binding = 0},
164 ShaderStageBufferLayout{.stride = 16u, .binding = 1}};
165 vertex_desc->RegisterDescriptorSetLayouts(VS::kDescriptorSetLayouts);
166 vertex_desc->RegisterDescriptorSetLayouts(FS::kDescriptorSetLayouts);
167 vertex_desc->SetStageInputs(io_slots, layouts);
168 desc->SetVertexDescriptor(std::move(vertex_desc));
169 auto pipeline =
170 context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
171 ASSERT_TRUE(pipeline);
172
173 struct Cube {
174 Vector3 positions[8] = {
175 // -Z
176 {-1, -1, -1},
177 {1, -1, -1},
178 {1, 1, -1},
179 {-1, 1, -1},
180 // +Z
181 {-1, -1, 1},
182 {1, -1, 1},
183 {1, 1, 1},
184 {-1, 1, 1},
185 };
186 Color colors[8] = {
187 Color::Red(), Color::Yellow(), Color::Green(), Color::Blue(),
188 Color::Green(), Color::Blue(), Color::Red(), Color::Yellow(),
189 };
190 uint16_t indices[36] = {
191 1, 5, 2, 2, 5, 6, // +X
192 4, 0, 7, 7, 0, 3, // -X
193 4, 5, 0, 0, 5, 1, // +Y
194 3, 2, 7, 7, 2, 6, // -Y
195 5, 4, 6, 6, 4, 7, // +Z
196 0, 1, 3, 3, 1, 2, // -Z
197 };
198 } cube;
199
200 auto device_buffer = context->GetResourceAllocator()->CreateBufferWithCopy(
201 reinterpret_cast<uint8_t*>(&cube), sizeof(cube));
202
203 raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
204 ASSERT_TRUE(sampler);
205
206 Vector3 euler_angles;
207 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
208 SinglePassCallback callback = [&](RenderPass& pass) {
209 static Degrees fov_y(60);
210 static Scalar distance = 10;
211
212 if (IsPlaygroundEnabled()) {
213 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
214 ImGui::SliderFloat("Field of view", &fov_y.degrees, 0, 180);
215 ImGui::SliderFloat("Camera distance", &distance, 0, 30);
216 ImGui::End();
217 }
218
219 pass.SetCommandLabel("Perspective Cube");
220 pass.SetPipeline(pipeline);
221
222 std::array<BufferView, 2> vertex_buffers = {
223 BufferView(device_buffer,
224 Range(offsetof(Cube, positions), sizeof(Cube::positions))),
225 BufferView(device_buffer,
226 Range(offsetof(Cube, colors), sizeof(Cube::colors))),
227 };
228
229 BufferView index_buffer(
230 device_buffer, Range(offsetof(Cube, indices), sizeof(Cube::indices)));
231 pass.SetVertexBuffer(vertex_buffers.data(), vertex_buffers.size());
232 pass.SetElementCount(36);
233 pass.SetIndexBuffer(index_buffer, IndexType::k16bit);
234
235 VS::UniformBuffer uniforms;
236 Scalar time = GetSecondsElapsed();
237 euler_angles = Vector3(0.19 * time, 0.7 * time, 0.43 * time);
238
239 uniforms.mvp =
240 Matrix::MakePerspective(fov_y, pass.GetRenderTargetSize(), 0, 10) *
241 Matrix::MakeTranslation({0, 0, distance}) *
242 Matrix::MakeRotationX(Radians(euler_angles.x)) *
243 Matrix::MakeRotationY(Radians(euler_angles.y)) *
244 Matrix::MakeRotationZ(Radians(euler_angles.z));
245 VS::BindUniformBuffer(pass, data_host_buffer->EmplaceUniform(uniforms));
246
247 data_host_buffer->Reset();
248 return pass.Draw().ok();
249 };
250 OpenPlaygroundHere(callback);
251}

References impeller::ShaderStageIOSlot::binding, callback, context, impeller::Degrees::degrees, impeller::k16bit, impeller::kBackFace, impeller::kCounterClockwise, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::Matrix::MakePerspective(), impeller::Matrix::MakeRotationX(), impeller::Matrix::MakeRotationY(), impeller::Matrix::MakeRotationZ(), impeller::Matrix::MakeTranslation(), impeller::ShaderStageIOSlot::offset, pipeline, impeller::ShaderStageBufferLayout::stride, impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

◆ TEST_P() [598/662]

impeller::testing::TEST_P ( RendererTest  ,
CanRenderToMipLevel   
)

Definition at line 1654 of file renderer_unittests.cc.

1654 {
1655 if (GetBackend() == PlaygroundBackend::kOpenGLES ||
1656 GetBackend() == PlaygroundBackend::kOpenGLESSDF) {
1657 GTEST_SKIP() << "Rendering to non-zero mip levels is gated on a GLES "
1658 "capability; covered by the Metal and Vulkan backends.";
1659 }
1660 auto context = GetContext();
1661 ASSERT_TRUE(context);
1662
1663 TextureDescriptor desc;
1664 desc.storage_mode = StorageMode::kDevicePrivate;
1665 desc.format = PixelFormat::kR8G8B8A8UNormInt;
1666 desc.size = {100, 100};
1667 desc.mip_count = 2u;
1668 desc.usage = TextureUsage::kRenderTarget | TextureUsage::kShaderRead;
1669 auto texture = context->GetResourceAllocator()->CreateTexture(desc);
1670 ASSERT_TRUE(texture);
1671
1672 ColorAttachment color0;
1673 color0.texture = texture;
1674 color0.mip_level = 1u;
1675 color0.load_action = LoadAction::kClear;
1676 color0.store_action = StoreAction::kStore;
1677 color0.clear_color = Color::Green();
1678 RenderTarget target;
1679 target.SetColorAttachment(color0, 0u);
1680 // The render area follows the mip level dimensions.
1681 EXPECT_EQ(target.GetRenderTargetSize(), ISize(50, 50));
1682
1683 auto buffer = context->CreateCommandBuffer();
1684 auto pass = buffer->CreateRenderPass(target);
1685 ASSERT_TRUE(pass && pass->IsValid());
1686 pass->EncodeCommands();
1687 EXPECT_TRUE(context->GetCommandQueue()->Submit({buffer}).ok());
1688}

References flutter::buffer, impeller::ColorAttachment::clear_color, context, impeller::TextureDescriptor::format, impeller::Color::Green(), impeller::kClear, impeller::kDevicePrivate, impeller::kOpenGLES, impeller::kOpenGLESSDF, impeller::kR8G8B8A8UNormInt, impeller::kRenderTarget, impeller::kShaderRead, impeller::kStore, impeller::Attachment::load_action, impeller::TextureDescriptor::mip_count, impeller::Attachment::mip_level, impeller::RenderTarget::SetColorAttachment(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::Attachment::store_action, target, impeller::Attachment::texture, texture, and impeller::TextureDescriptor::usage.

◆ TEST_P() [599/662]

impeller::testing::TEST_P ( RendererTest  ,
CanRenderToTexture   
)

Definition at line 324 of file renderer_unittests.cc.

324 {
325 using VS = BoxFadeVertexShader;
326 using FS = BoxFadeFragmentShader;
327 auto context = GetContext();
328 ASSERT_TRUE(context);
329 using BoxPipelineBuilder = PipelineBuilder<VS, FS>;
330 auto pipeline_desc =
331 BoxPipelineBuilder::MakeDefaultPipelineDescriptor(*context);
332 pipeline_desc->SetSampleCount(SampleCount::kCount1);
333 pipeline_desc->ClearDepthAttachment();
334 pipeline_desc->SetStencilPixelFormat(PixelFormat::kS8UInt);
335
336 ASSERT_TRUE(pipeline_desc.has_value());
337 auto box_pipeline =
338 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
339 ASSERT_TRUE(box_pipeline);
340 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
341
343 vertex_builder.SetLabel("Box");
344 vertex_builder.AddVertices({
345 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
346 {{800, 100, 0.0}, {1.0, 0.0}}, // 2
347 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
348 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
349 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
350 {{100, 800, 0.0}, {0.0, 1.0}}, // 4
351 });
352 auto vertex_buffer =
353 vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator());
354 ASSERT_TRUE(vertex_buffer);
355
356 auto bridge = CreateTextureForFixture("bay_bridge.jpg");
357 auto boston = CreateTextureForFixture("boston.jpg");
358 ASSERT_TRUE(bridge && boston);
359 raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
360 ASSERT_TRUE(sampler);
361
362 std::shared_ptr<RenderPass> r2t_pass;
363 auto cmd_buffer = context->CreateCommandBuffer();
364 ASSERT_TRUE(cmd_buffer);
365 {
366 ColorAttachment color0;
367 color0.load_action = LoadAction::kClear;
368 color0.store_action = StoreAction::kStore;
369
370 TextureDescriptor texture_descriptor;
371 ASSERT_NE(pipeline_desc->GetColorAttachmentDescriptor(0u), nullptr);
372 texture_descriptor.format =
373 pipeline_desc->GetColorAttachmentDescriptor(0u)->format;
374 texture_descriptor.storage_mode = StorageMode::kHostVisible;
375 texture_descriptor.size = {400, 400};
376 texture_descriptor.mip_count = 1u;
377 texture_descriptor.usage = TextureUsage::kRenderTarget;
378
379 color0.texture =
380 context->GetResourceAllocator()->CreateTexture(texture_descriptor);
381
382 ASSERT_TRUE(color0.IsValid());
383
384 color0.texture->SetLabel("r2t_target");
385
386 StencilAttachment stencil0;
387 stencil0.load_action = LoadAction::kClear;
388 stencil0.store_action = StoreAction::kDontCare;
389 TextureDescriptor stencil_texture_desc;
390 stencil_texture_desc.storage_mode = StorageMode::kDeviceTransient;
391 stencil_texture_desc.size = texture_descriptor.size;
392 stencil_texture_desc.format = PixelFormat::kS8UInt;
393 stencil_texture_desc.usage = TextureUsage::kRenderTarget;
394 stencil0.texture =
395 context->GetResourceAllocator()->CreateTexture(stencil_texture_desc);
396
397 RenderTarget r2t_desc;
398 r2t_desc.SetColorAttachment(color0, 0u);
399 r2t_desc.SetStencilAttachment(stencil0);
400 r2t_pass = cmd_buffer->CreateRenderPass(r2t_desc);
401 ASSERT_TRUE(r2t_pass && r2t_pass->IsValid());
402 }
403
404 r2t_pass->SetCommandLabel("Box");
405 r2t_pass->SetPipeline(box_pipeline);
406 r2t_pass->SetVertexBuffer(vertex_buffer);
407
408 FS::FrameInfo frame_info;
409 frame_info.current_time = GetSecondsElapsed();
410 frame_info.cursor_position = GetCursorPosition();
411 frame_info.window_size.x = GetWindowSize().width;
412 frame_info.window_size.y = GetWindowSize().height;
413
414 FS::BindFrameInfo(*r2t_pass, data_host_buffer->EmplaceUniform(frame_info));
415 FS::BindContents1(*r2t_pass, boston, sampler);
416 FS::BindContents2(*r2t_pass, bridge, sampler);
417
418 VS::UniformBuffer uniforms;
419 uniforms.mvp = Matrix::MakeOrthographic(ISize{1024, 768}) *
420 Matrix::MakeTranslation({50.0f, 50.0f, 0.0f});
421 VS::BindUniformBuffer(*r2t_pass, data_host_buffer->EmplaceUniform(uniforms));
422 ASSERT_TRUE(r2t_pass->Draw().ok());
423 ASSERT_TRUE(r2t_pass->EncodeCommands());
424 ASSERT_TRUE(context->FlushCommandBuffers());
425}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::TextureDescriptor::format, impeller::Attachment::IsValid(), impeller::kClear, impeller::kCount1, impeller::kDeviceTransient, impeller::kDontCare, impeller::kHostVisible, impeller::kRenderTarget, impeller::kS8UInt, impeller::kStore, impeller::Attachment::load_action, impeller::Matrix::MakeOrthographic(), impeller::Matrix::MakeTranslation(), impeller::TextureDescriptor::mip_count, impeller::RenderTarget::SetColorAttachment(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::SetLabel(), impeller::RenderTarget::SetStencilAttachment(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::Attachment::store_action, impeller::Attachment::texture, and impeller::TextureDescriptor::usage.

◆ TEST_P() [600/662]

impeller::testing::TEST_P ( RendererTest  ,
CanRenderToTextureSlice   
)

Definition at line 1622 of file renderer_unittests.cc.

1622 {
1623 auto context = GetContext();
1624 ASSERT_TRUE(context);
1625
1626 TextureDescriptor desc;
1627 desc.storage_mode = StorageMode::kDevicePrivate;
1628 desc.type = TextureType::kTextureCube;
1629 desc.format = PixelFormat::kR8G8B8A8UNormInt;
1630 desc.size = {100, 100};
1631 desc.usage = TextureUsage::kRenderTarget | TextureUsage::kShaderRead;
1632 auto texture = context->GetResourceAllocator()->CreateTexture(desc);
1633 ASSERT_TRUE(texture);
1634
1635 ColorAttachment color0;
1636 color0.texture = texture;
1637 color0.slice = 3u; // +Y face.
1638 color0.load_action = LoadAction::kClear;
1639 color0.store_action = StoreAction::kStore;
1640 color0.clear_color = Color::Green();
1642 target.SetColorAttachment(color0, 0u);
1643
1644 auto buffer = context->CreateCommandBuffer();
1645 auto pass = buffer->CreateRenderPass(target);
1646 ASSERT_TRUE(pass && pass->IsValid());
1647 pass->EncodeCommands();
1648 EXPECT_TRUE(context->GetCommandQueue()->Submit({buffer}).ok());
1649}

References flutter::buffer, impeller::ColorAttachment::clear_color, context, impeller::TextureDescriptor::format, impeller::Color::Green(), impeller::kClear, impeller::kDevicePrivate, impeller::kR8G8B8A8UNormInt, impeller::kRenderTarget, impeller::kShaderRead, impeller::kStore, impeller::kTextureCube, impeller::Attachment::load_action, impeller::RenderTarget::SetColorAttachment(), impeller::TextureDescriptor::size, impeller::Attachment::slice, impeller::TextureDescriptor::storage_mode, impeller::Attachment::store_action, target, impeller::Attachment::texture, texture, impeller::TextureDescriptor::type, and impeller::TextureDescriptor::usage.

◆ TEST_P() [601/662]

impeller::testing::TEST_P ( RendererTest  ,
CanSepiaToneThenSwizzleWithSubpasses   
)

Definition at line 1485 of file renderer_unittests.cc.

1485 {
1486 switch (GetBackend()) {
1487 case PlaygroundBackend::kMetal:
1488 case PlaygroundBackend::kMetalSDF:
1489 case PlaygroundBackend::kVulkan:
1490 break;
1491 case PlaygroundBackend::kOpenGLES:
1492 case PlaygroundBackend::kOpenGLESSDF:
1493 GTEST_SKIP() << "Platform is crashing in CI on this example "
1494 << "(see https://github.com/flutter/flutter/issues/189287).";
1495 }
1496 // Define shader types
1497 using TextureVS = TextureVertexShader;
1498 using TextureFS = TextureFragmentShader;
1499
1500 using SwizzleVS = SepiaVertexShader;
1501 using SwizzleFS = SwizzleFragmentShader;
1502
1503 using SepiaVS = SepiaVertexShader;
1504 using SepiaFS = SepiaFragmentShader;
1505
1506 auto context = GetContext();
1507 ASSERT_TRUE(context);
1508
1509 if (!context->GetCapabilities()->SupportsFramebufferFetch()) {
1510 GTEST_SKIP() << "This test uses framebuffer fetch and the backend doesn't "
1511 "support it.";
1512 return;
1513 }
1514
1515 // Create pipelines.
1516 auto texture_pipeline =
1517 CreateDefaultPipeline<TextureVS, TextureFS>(this, context);
1518 auto swizzle_pipeline =
1519 CreateDefaultPipeline<SwizzleVS, SwizzleFS>(this, context);
1520 auto sepia_pipeline = CreateDefaultPipeline<SepiaVS, SepiaFS>(this, context);
1521
1522 ASSERT_TRUE(texture_pipeline);
1523 ASSERT_TRUE(swizzle_pipeline);
1524 ASSERT_TRUE(sepia_pipeline);
1525
1526 // Vertex buffer builders.
1527 VertexBufferBuilder<TextureVS::PerVertexData> texture_vtx_builder;
1528 texture_vtx_builder.AddVertices({
1529 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
1530 {{800, 100, 0.0}, {1.0, 0.0}}, // 2
1531 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
1532 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
1533 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
1534 {{100, 800, 0.0}, {0.0, 1.0}}, // 4
1535 });
1536
1537 VertexBufferBuilder<SepiaVS::PerVertexData> sepia_vtx_builder;
1538 sepia_vtx_builder.AddVertices({
1539 {{100, 100, 0.0}}, // 1
1540 {{800, 100, 0.0}}, // 2
1541 {{800, 800, 0.0}}, // 3
1542 {{100, 100, 0.0}}, // 1
1543 {{800, 800, 0.0}}, // 3
1544 {{100, 800, 0.0}}, // 4
1545 });
1546
1547 auto boston = CreateTextureForFixture("boston.jpg");
1548 ASSERT_TRUE(boston);
1549
1550 const auto& sampler = context->GetSamplerLibrary()->GetSampler({});
1551 ASSERT_TRUE(sampler);
1552
1553 auto data_buffer = HostBuffer::Create(
1554 context->GetResourceAllocator(), context->GetIdleWaiter(),
1555 context->GetCapabilities()->GetMinimumUniformAlignment());
1556 SinglePassCallback callback = [&](RenderPass& pass) {
1557 // Draw the texture.
1558 {
1559 pass.SetPipeline(texture_pipeline);
1560 pass.SetVertexBuffer(texture_vtx_builder.CreateVertexBuffer(
1561 *context->GetResourceAllocator()));
1562 TextureVS::UniformBuffer uniforms;
1563 uniforms.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
1564 Matrix::MakeScale(GetContentScale());
1565 TextureVS::BindUniformBuffer(pass, data_buffer->EmplaceUniform(uniforms));
1566 TextureFS::BindTextureContents(pass, boston, sampler);
1567 if (!pass.Draw().ok()) {
1568 return false;
1569 }
1570 }
1571
1572 // Draw the sepia toner.
1573 {
1574 pass.SetPipeline(sepia_pipeline);
1575 pass.SetVertexBuffer(sepia_vtx_builder.CreateVertexBuffer(
1576 *context->GetResourceAllocator()));
1577 SepiaVS::UniformBuffer uniforms;
1578 uniforms.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
1579 Matrix::MakeScale(GetContentScale());
1580 SepiaVS::BindUniformBuffer(pass, data_buffer->EmplaceUniform(uniforms));
1581 if (!pass.Draw().ok()) {
1582 return false;
1583 }
1584 }
1585
1586 // Draw the swizzle.
1587 {
1588 pass.SetPipeline(swizzle_pipeline);
1589 pass.SetVertexBuffer(sepia_vtx_builder.CreateVertexBuffer(
1590 *context->GetResourceAllocator()));
1591 SwizzleVS::UniformBuffer uniforms;
1592 uniforms.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
1593 Matrix::MakeScale(GetContentScale());
1594 SwizzleVS::BindUniformBuffer(pass, data_buffer->EmplaceUniform(uniforms));
1595 if (!pass.Draw().ok()) {
1596 return false;
1597 }
1598 }
1599
1600 return true;
1601 };
1602 OpenPlaygroundHere(callback);
1603}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), callback, context, impeller::HostBuffer::Create(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::kMetal, impeller::kMetalSDF, impeller::kOpenGLES, impeller::kOpenGLESSDF, impeller::kVulkan, impeller::Matrix::MakeOrthographic(), and impeller::Matrix::MakeScale().

◆ TEST_P() [602/662]

impeller::testing::TEST_P ( RendererTest  ,
CanSepiaToneWithSubpasses   
)

Definition at line 1395 of file renderer_unittests.cc.

1395 {
1396 // Define shader types
1397 using TextureVS = TextureVertexShader;
1398 using TextureFS = TextureFragmentShader;
1399
1400 using SepiaVS = SepiaVertexShader;
1401 using SepiaFS = SepiaFragmentShader;
1402
1403 auto context = GetContext();
1404 ASSERT_TRUE(context);
1405
1406 if (!context->GetCapabilities()->SupportsFramebufferFetch()) {
1407 GTEST_SKIP() << "This test uses framebuffer fetch and the backend doesn't "
1408 "support it.";
1409 return;
1410 }
1411
1412 // Create pipelines.
1413 auto texture_pipeline =
1414 CreateDefaultPipeline<TextureVS, TextureFS>(this, context);
1415 auto sepia_pipeline = CreateDefaultPipeline<SepiaVS, SepiaFS>(this, context);
1416
1417 ASSERT_TRUE(texture_pipeline);
1418 ASSERT_TRUE(sepia_pipeline);
1419
1420 // Vertex buffer builders.
1422 texture_vtx_builder.AddVertices({
1423 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
1424 {{800, 100, 0.0}, {1.0, 0.0}}, // 2
1425 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
1426 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
1427 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
1428 {{100, 800, 0.0}, {0.0, 1.0}}, // 4
1429 });
1430
1431 VertexBufferBuilder<SepiaVS::PerVertexData> sepia_vtx_builder;
1432 sepia_vtx_builder.AddVertices({
1433 {{100, 100, 0.0}}, // 1
1434 {{800, 100, 0.0}}, // 2
1435 {{800, 800, 0.0}}, // 3
1436 {{100, 100, 0.0}}, // 1
1437 {{800, 800, 0.0}}, // 3
1438 {{100, 800, 0.0}}, // 4
1439 });
1440
1441 auto boston = CreateTextureForFixture("boston.jpg");
1442 ASSERT_TRUE(boston);
1443
1444 const auto& sampler = context->GetSamplerLibrary()->GetSampler({});
1445 ASSERT_TRUE(sampler);
1446
1447 auto buffer = HostBuffer::Create(
1448 context->GetResourceAllocator(), context->GetIdleWaiter(),
1449 context->GetCapabilities()->GetMinimumUniformAlignment());
1450 SinglePassCallback callback = [&](RenderPass& pass) {
1451 // Draw the texture.
1452 {
1453 pass.SetPipeline(texture_pipeline);
1454 pass.SetVertexBuffer(texture_vtx_builder.CreateVertexBuffer(
1455 *context->GetResourceAllocator()));
1456 TextureVS::UniformBuffer uniforms;
1457 uniforms.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
1458 Matrix::MakeScale(GetContentScale());
1459 TextureVS::BindUniformBuffer(pass, buffer->EmplaceUniform(uniforms));
1460 TextureFS::BindTextureContents(pass, boston, sampler);
1461 if (!pass.Draw().ok()) {
1462 return false;
1463 }
1464 }
1465
1466 // Draw the sepia toner.
1467 {
1468 pass.SetPipeline(sepia_pipeline);
1469 pass.SetVertexBuffer(sepia_vtx_builder.CreateVertexBuffer(
1470 *context->GetResourceAllocator()));
1471 SepiaVS::UniformBuffer uniforms;
1472 uniforms.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
1473 Matrix::MakeScale(GetContentScale());
1474 SepiaVS::BindUniformBuffer(pass, buffer->EmplaceUniform(uniforms));
1475 if (!pass.Draw().ok()) {
1476 return false;
1477 }
1478 }
1479
1480 return true;
1481 };
1482 OpenPlaygroundHere(callback);
1483}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), flutter::buffer, callback, context, impeller::HostBuffer::Create(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::Matrix::MakeOrthographic(), and impeller::Matrix::MakeScale().

◆ TEST_P() [603/662]

impeller::testing::TEST_P ( RendererTest  ,
DefaultIndexBehavior   
)

Definition at line 1103 of file renderer_unittests.cc.

1103 {
1104 using VS = BoxFadeVertexShader;
1105
1106 // Do not create any index buffer if no indices were provided.
1108 ASSERT_EQ(vertex_builder.GetIndexType(), IndexType::kNone);
1109}
constexpr impeller::IndexType GetIndexType() const

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::GetIndexType(), and impeller::kNone.

◆ TEST_P() [604/662]

impeller::testing::TEST_P ( RendererTest  ,
DefaultIndexSize   
)

Definition at line 1093 of file renderer_unittests.cc.

1093 {
1094 using VS = BoxFadeVertexShader;
1095
1096 // Default to 16bit index buffer size, as this is a reasonable default and
1097 // supported on all backends without extensions.
1099 vertex_builder.AppendIndex(0u);
1100 ASSERT_EQ(vertex_builder.GetIndexType(), IndexType::k16bit);
1101}
VertexBufferBuilder & AppendIndex(IndexType_ index)

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AppendIndex(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::GetIndexType(), and impeller::k16bit.

◆ TEST_P() [605/662]

impeller::testing::TEST_P ( RendererTest  ,
InactiveUniforms   
)

Definition at line 1046 of file renderer_unittests.cc.

1046 {
1047 using VS = InactiveUniformsVertexShader;
1048 using FS = InactiveUniformsFragmentShader;
1049
1050 auto context = GetContext();
1051 auto pipeline_descriptor =
1053 ASSERT_TRUE(pipeline_descriptor.has_value());
1054 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*pipeline_descriptor));
1055 auto pipeline =
1056 context->GetPipelineLibrary()->GetPipeline(pipeline_descriptor).Get();
1057 ASSERT_TRUE(pipeline && pipeline->IsValid());
1058
1059 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
1060 SinglePassCallback callback = [&](RenderPass& pass) {
1061 auto size = pass.GetRenderTargetSize();
1062
1063 pass.SetPipeline(pipeline);
1064 pass.SetCommandLabel("Inactive Uniform");
1065
1067 builder.AddVertices({{Point()},
1068 {Point(0, size.height)},
1069 {Point(size.width, 0)},
1070 {Point(size.width, 0)},
1071 {Point(0, size.height)},
1072 {Point(size.width, size.height)}});
1073 pass.SetVertexBuffer(
1074 builder.CreateVertexBuffer(*data_host_buffer, *indexes_host_buffer));
1075
1076 VS::FrameInfo frame_info;
1077 EXPECT_EQ(pass.GetOrthographicTransform(), Matrix::MakeOrthographic(size));
1078 frame_info.mvp =
1079 pass.GetOrthographicTransform() * Matrix::MakeScale(GetContentScale());
1080 VS::BindFrameInfo(pass, data_host_buffer->EmplaceUniform(frame_info));
1081
1082 FS::FragInfo fs_uniform = {.unused_color = Color::Red(),
1083 .color = Color::Green()};
1084 FS::BindFragInfo(pass, data_host_buffer->EmplaceUniform(fs_uniform));
1085
1086 pass.Draw().ok();
1087 data_host_buffer->Reset();
1088 return true;
1089 };
1090 OpenPlaygroundHere(callback);
1091}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), callback, context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::Color::Green(), impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::Matrix::MakeOrthographic(), impeller::Matrix::MakeScale(), pipeline, impeller::Color::Red(), and flutter::size.

◆ TEST_P() [606/662]

impeller::testing::TEST_P ( RendererTest  ,
Planet   
)

Definition at line 922 of file renderer_unittests.cc.

922 {
923 using VS = PlanetVertexShader;
924 using FS = PlanetFragmentShader;
925
926 auto context = GetContext();
927 auto pipeline_descriptor =
929 ASSERT_TRUE(pipeline_descriptor.has_value());
930 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*pipeline_descriptor));
931 auto pipeline =
932 context->GetPipelineLibrary()->GetPipeline(pipeline_descriptor).Get();
933 ASSERT_TRUE(pipeline && pipeline->IsValid());
934
935 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
936 SinglePassCallback callback = [&](RenderPass& pass) {
937 static Scalar speed = 0.1;
938 static Scalar planet_size = 550.0;
939 static bool show_normals = false;
940 static bool show_noise = false;
941 static Scalar seed_value = 42.0;
942
943 auto size = pass.GetRenderTargetSize();
944
945 if (IsPlaygroundEnabled()) {
946 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
947 ImGui::SliderFloat("Speed", &speed, 0.0, 10.0);
948 ImGui::SliderFloat("Planet Size", &planet_size, 0.1, 1000);
949 ImGui::Checkbox("Show Normals", &show_normals);
950 ImGui::Checkbox("Show Noise", &show_noise);
951 ImGui::InputFloat("Seed Value", &seed_value);
952 ImGui::End();
953 }
954
955 pass.SetPipeline(pipeline);
956 pass.SetCommandLabel("Planet scene");
958 builder.AddVertices({{Point()},
959 {Point(0, size.height)},
960 {Point(size.width, 0)},
961 {Point(size.width, 0)},
962 {Point(0, size.height)},
963 {Point(size.width, size.height)}});
964 pass.SetVertexBuffer(
965 builder.CreateVertexBuffer(*data_host_buffer, *indexes_host_buffer));
966
967 VS::FrameInfo frame_info;
968 EXPECT_EQ(pass.GetOrthographicTransform(), Matrix::MakeOrthographic(size));
969 frame_info.mvp = pass.GetOrthographicTransform();
970 VS::BindFrameInfo(pass, data_host_buffer->EmplaceUniform(frame_info));
971
972 FS::FragInfo fs_uniform;
973 fs_uniform.resolution = Point(size);
974 fs_uniform.time = GetSecondsElapsed();
975 fs_uniform.speed = speed;
976 fs_uniform.planet_size = planet_size;
977 fs_uniform.show_normals = show_normals ? 1.0 : 0.0;
978 fs_uniform.show_noise = show_noise ? 1.0 : 0.0;
979 fs_uniform.seed_value = seed_value;
980 FS::BindFragInfo(pass, data_host_buffer->EmplaceUniform(fs_uniform));
981
982 pass.Draw().ok();
983 data_host_buffer->Reset();
984 return true;
985 };
986 OpenPlaygroundHere(callback);
987}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), callback, context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::Matrix::MakeOrthographic(), pipeline, and flutter::size.

◆ TEST_P() [607/662]

impeller::testing::TEST_P ( RendererTest  ,
RenderTargetCreateOffscreenMSAASetsDefaultDepthStencilFormat   
)

Definition at line 1360 of file renderer_unittests.cc.

1361 {
1362 auto context = GetContext();
1363 auto render_target_cache = std::make_shared<RenderTargetAllocator>(
1364 GetContext()->GetResourceAllocator());
1365
1366 RenderTarget render_target = render_target_cache->CreateOffscreenMSAA(
1367 *context, {100, 100}, /*mip_count=*/1);
1368 EXPECT_EQ(render_target.GetDepthAttachment()
1369 ->texture->GetTextureDescriptor()
1370 .format,
1371 GetContext()->GetCapabilities()->GetDefaultDepthStencilFormat());
1372}

References context, and impeller::RenderTarget::GetDepthAttachment().

◆ TEST_P() [608/662]

impeller::testing::TEST_P ( RendererTest  ,
StencilMask   
)

Definition at line 1181 of file renderer_unittests.cc.

1181 {
1182 using VS = BoxFadeVertexShader;
1183 using FS = BoxFadeFragmentShader;
1184 auto context = GetContext();
1185 ASSERT_TRUE(context);
1186 using BoxFadePipelineBuilder = PipelineBuilder<VS, FS>;
1187 auto desc = BoxFadePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
1188 ASSERT_TRUE(desc.has_value());
1189
1190 // Vertex buffer.
1192 vertex_builder.SetLabel("Box");
1193 vertex_builder.AddVertices({
1194 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
1195 {{800, 100, 0.0}, {1.0, 0.0}}, // 2
1196 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
1197 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
1198 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
1199 {{100, 800, 0.0}, {0.0, 1.0}}, // 4
1200 });
1201 auto vertex_buffer =
1202 vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator());
1203 ASSERT_TRUE(vertex_buffer);
1204
1205 desc->SetSampleCount(SampleCount::kCount4);
1206 desc->SetStencilAttachmentDescriptors(std::nullopt);
1207
1208 auto bridge = CreateTextureForFixture("bay_bridge.jpg");
1209 auto boston = CreateTextureForFixture("boston.jpg");
1210 ASSERT_TRUE(bridge && boston);
1211 raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
1212 ASSERT_TRUE(sampler);
1213
1214 static bool mirror = false;
1215 static int stencil_reference_write = 0xFF;
1216 static int stencil_reference_read = 0x1;
1217 std::vector<uint8_t> stencil_contents;
1218 static int last_stencil_contents_reference_value = 0;
1219 static int current_front_compare =
1220 CompareFunctionUI().IndexOf(CompareFunction::kLessEqual);
1221 static int current_back_compare =
1222 CompareFunctionUI().IndexOf(CompareFunction::kLessEqual);
1223
1224 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
1225 Playground::RenderCallback callback = [&](RenderTarget& render_target) {
1226 auto buffer = context->CreateCommandBuffer();
1227 if (!buffer) {
1228 return false;
1229 }
1230 buffer->SetLabel("Playground Command Buffer");
1231
1232 {
1233 // Configure the stencil attachment for the test.
1234 RenderTarget::AttachmentConfig stencil_config;
1235 stencil_config.load_action = LoadAction::kLoad;
1236 stencil_config.store_action = StoreAction::kDontCare;
1237 stencil_config.storage_mode = StorageMode::kHostVisible;
1238 render_target.SetupDepthStencilAttachments(
1239 *context, *context->GetResourceAllocator(),
1240 render_target.GetRenderTargetSize(), true, "stencil", stencil_config);
1241 // Fill the stencil buffer with an checkerboard pattern.
1242 const auto target_width = render_target.GetRenderTargetSize().width;
1243 const auto target_height = render_target.GetRenderTargetSize().height;
1244 const size_t target_size = target_width * target_height;
1245 if (stencil_contents.size() != target_size ||
1246 last_stencil_contents_reference_value != stencil_reference_write) {
1247 stencil_contents.resize(target_size);
1248 last_stencil_contents_reference_value = stencil_reference_write;
1249 for (int y = 0; y < target_height; y++) {
1250 for (int x = 0; x < target_width; x++) {
1251 const auto index = y * target_width + x;
1252 const auto kCheckSize = 64;
1253 const auto value =
1254 (((y / kCheckSize) + (x / kCheckSize)) % 2 == 0) *
1255 stencil_reference_write;
1256 stencil_contents[index] = value;
1257 }
1258 }
1259 }
1260 if (!render_target.GetStencilAttachment()->texture->SetContents(
1261 stencil_contents.data(), stencil_contents.size(), 0, false)) {
1262 VALIDATION_LOG << "Could not upload stencil contents to device memory";
1263 return false;
1264 }
1265 auto pass = buffer->CreateRenderPass(render_target);
1266 if (!pass) {
1267 return false;
1268 }
1269 pass->SetLabel("Stencil Buffer");
1270 if (IsPlaygroundEnabled()) {
1271 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1272 ImGui::SliderInt("Stencil Write Value", &stencil_reference_write, 0,
1273 0xFF);
1274 ImGui::SliderInt("Stencil Compare Value", &stencil_reference_read, 0,
1275 0xFF);
1276 ImGui::Checkbox("Back face mode", &mirror);
1277 ImGui::ListBox("Front face compare function", &current_front_compare,
1278 CompareFunctionUI().labels(),
1280 ImGui::ListBox("Back face compare function", &current_back_compare,
1281 CompareFunctionUI().labels(),
1283 ImGui::End();
1284 }
1285
1286 StencilAttachmentDescriptor front;
1287 front.stencil_compare =
1288 CompareFunctionUI().FunctionOf(current_front_compare);
1289 StencilAttachmentDescriptor back;
1290 back.stencil_compare =
1291 CompareFunctionUI().FunctionOf(current_back_compare);
1292 desc->SetStencilAttachmentDescriptors(front, back);
1293 auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).Get();
1294
1295 assert(pipeline && pipeline->IsValid());
1296
1297 pass->SetCommandLabel("Box");
1298 pass->SetPipeline(pipeline);
1299 pass->SetStencilReference(stencil_reference_read);
1300 pass->SetVertexBuffer(vertex_buffer);
1301
1302 VS::UniformBuffer uniforms;
1303 EXPECT_EQ(pass->GetOrthographicTransform(),
1304 Matrix::MakeOrthographic(pass->GetRenderTargetSize()));
1305 uniforms.mvp = pass->GetOrthographicTransform() *
1306 Matrix::MakeScale(GetContentScale());
1307 if (mirror) {
1308 uniforms.mvp = Matrix::MakeScale(Vector2(-1, 1)) * uniforms.mvp;
1309 }
1310 VS::BindUniformBuffer(*pass, data_host_buffer->EmplaceUniform(uniforms));
1311
1312 FS::FrameInfo frame_info;
1313 frame_info.current_time = GetSecondsElapsed();
1314 frame_info.cursor_position = GetCursorPosition();
1315 frame_info.window_size.x = GetWindowSize().width;
1316 frame_info.window_size.y = GetWindowSize().height;
1317
1318 FS::BindFrameInfo(*pass, data_host_buffer->EmplaceUniform(frame_info));
1319 FS::BindContents1(*pass, boston, sampler);
1320 FS::BindContents2(*pass, bridge, sampler);
1321 if (!pass->Draw().ok()) {
1322 return false;
1323 }
1324 pass->EncodeCommands();
1325 }
1326
1327 if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
1328 return false;
1329 }
1330 data_host_buffer->Reset();
1331 return true;
1332 };
1333
1334 if ((true)) { // Disables trailing code without compiler warning.
1335 GTEST_SKIP() << "See: https://github.com/flutter/flutter/issues/188884";
1336 }
1337 OpenPlaygroundHere(callback);
1338}
CompareFunction FunctionOf(int index) const
int IndexOf(CompareFunction func) const
static const CompareFunctionUIData & CompareFunctionUI()

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), flutter::buffer, callback, CompareFunctionUI(), context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::testing::CompareFunctionUIData::FunctionOf(), impeller::testing::CompareFunctionUIData::IndexOf(), impeller::kCount4, impeller::kDontCare, impeller::kHostVisible, impeller::kLessEqual, impeller::kLoad, impeller::RenderTarget::AttachmentConfig::load_action, impeller::Matrix::MakeOrthographic(), impeller::Matrix::MakeScale(), pipeline, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::SetLabel(), flutter::size, impeller::StencilAttachmentDescriptor::stencil_compare, impeller::RenderTarget::AttachmentConfig::storage_mode, impeller::RenderTarget::AttachmentConfig::store_action, VALIDATION_LOG, value, x, and y.

◆ TEST_P() [609/662]

impeller::testing::TEST_P ( RendererTest  ,
TheImpeller   
)

Definition at line 860 of file renderer_unittests.cc.

860 {
861 using VS = ImpellerVertexShader;
862 using FS = ImpellerFragmentShader;
863
864 auto context = GetContext();
865 auto pipeline_descriptor =
867 ASSERT_TRUE(pipeline_descriptor.has_value());
868 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*pipeline_descriptor));
869 auto pipeline =
870 context->GetPipelineLibrary()->GetPipeline(pipeline_descriptor).Get();
871 ASSERT_TRUE(pipeline && pipeline->IsValid());
872
873 auto blue_noise = CreateTextureForFixture("blue_noise.png");
874 SamplerDescriptor noise_sampler_desc;
875 noise_sampler_desc.width_address_mode = SamplerAddressMode::kRepeat;
876 noise_sampler_desc.height_address_mode = SamplerAddressMode::kRepeat;
877 raw_ptr<const Sampler> noise_sampler =
878 context->GetSamplerLibrary()->GetSampler(noise_sampler_desc);
879
880 auto cube_map = CreateTextureCubeForFixture(
881 {"table_mountain_px.png", "table_mountain_nx.png",
882 "table_mountain_py.png", "table_mountain_ny.png",
883 "table_mountain_pz.png", "table_mountain_nz.png"});
884 raw_ptr<const Sampler> cube_map_sampler =
885 context->GetSamplerLibrary()->GetSampler({});
886
887 auto [data_host_buffer, indexes_host_buffer] = createHostBuffers(context);
888 SinglePassCallback callback = [&](RenderPass& pass) {
889 auto size = pass.GetRenderTargetSize();
890
891 pass.SetPipeline(pipeline);
892 pass.SetCommandLabel("Impeller SDF scene");
893 VertexBufferBuilder<VS::PerVertexData> builder;
894 builder.AddVertices({{Point()},
895 {Point(0, size.height)},
896 {Point(size.width, 0)},
897 {Point(size.width, 0)},
898 {Point(0, size.height)},
899 {Point(size.width, size.height)}});
900 pass.SetVertexBuffer(
901 builder.CreateVertexBuffer(*data_host_buffer, *indexes_host_buffer));
902
903 VS::FrameInfo frame_info;
904 EXPECT_EQ(pass.GetOrthographicTransform(), Matrix::MakeOrthographic(size));
905 frame_info.mvp = pass.GetOrthographicTransform();
906 VS::BindFrameInfo(pass, data_host_buffer->EmplaceUniform(frame_info));
907
908 FS::FragInfo fs_uniform;
909 fs_uniform.texture_size = Point(size);
910 fs_uniform.time = GetSecondsElapsed();
911 FS::BindFragInfo(pass, data_host_buffer->EmplaceUniform(fs_uniform));
912 FS::BindBlueNoise(pass, blue_noise, noise_sampler);
913 FS::BindCubeMap(pass, cube_map, cube_map_sampler);
914
915 pass.Draw().ok();
916 data_host_buffer->Reset();
917 return true;
918 };
919 OpenPlaygroundHere(callback);
920}
SamplerAddressMode width_address_mode
SamplerAddressMode height_address_mode

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), callback, context, impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::SamplerDescriptor::height_address_mode, impeller::kRepeat, impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor(), impeller::Matrix::MakeOrthographic(), pipeline, flutter::size, and impeller::SamplerDescriptor::width_address_mode.

◆ TEST_P() [610/662]

impeller::testing::TEST_P ( RendererTest  ,
VertexBufferBuilder   
)

Definition at line 1111 of file renderer_unittests.cc.

1111 {
1112 // Does not create index buffer if one is provided.
1113 using VS = BoxFadeVertexShader;
1115 vertex_builder.SetLabel("Box");
1116 vertex_builder.AddVertices({
1117 {{100, 100, 0.0}, {0.0, 0.0}}, // 1
1118 {{800, 100, 0.0}, {1.0, 0.0}}, // 2
1119 {{800, 800, 0.0}, {1.0, 1.0}}, // 3
1120 {{100, 800, 0.0}, {0.0, 1.0}}, // 4
1121 });
1122 vertex_builder.AppendIndex(0);
1123 vertex_builder.AppendIndex(1);
1124 vertex_builder.AppendIndex(2);
1125 vertex_builder.AppendIndex(1);
1126 vertex_builder.AppendIndex(2);
1127 vertex_builder.AppendIndex(3);
1128
1129 ASSERT_EQ(vertex_builder.GetIndexCount(), 6u);
1130 ASSERT_EQ(vertex_builder.GetVertexCount(), 4u);
1131}

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AppendIndex(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::GetIndexCount(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::GetVertexCount(), and impeller::VertexBufferBuilder< VertexType_, IndexType_ >::SetLabel().

◆ TEST_P() [611/662]

impeller::testing::TEST_P ( RenderPassGLESWithDiscardFrameBufferExtTest  ,
DiscardFramebufferExt   
)

Definition at line 83 of file render_pass_gles_unittests.cc.

83 {
84 auto mock_gl_impl = std::make_unique<NiceMock<MockGLESImpl>>();
85 auto& mock_gl_impl_ref = *mock_gl_impl;
86 auto mock_gl =
87 MockGLES::Init(std::move(mock_gl_impl), {{"GL_EXT_discard_framebuffer"}},
88 "OpenGL ES 2.0");
89
90 auto context = CreateFakeGLESContext();
91 auto dummy_worker = std::make_shared<MockWorker>();
92 context->AddReactorWorker(dummy_worker);
93 auto reactor = context->GetReactor();
94
95 const auto command_buffer =
96 std::static_pointer_cast<Context>(context)->CreateCommandBuffer();
97 auto render_target = RenderTarget{};
98 const auto description = TextureDescriptor{
99 .format = PixelFormat::kR8G8B8A8UNormInt, .size = {10, 10}};
100
101 const auto& test_params = GetParam();
102 auto framebuffer_texture =
103 TextureGLES::WrapFBO(reactor, description, test_params.frame_buffer_id);
104
105 auto color_attachment = ColorAttachment{Attachment{
106 .texture = framebuffer_texture, .store_action = StoreAction::kDontCare}};
107 render_target.SetColorAttachment(color_attachment, 0);
108 const auto render_pass = command_buffer->CreateRenderPass(render_target);
109
110 EXPECT_CALL(mock_gl_impl_ref, GetIntegerv(GL_FRAMEBUFFER_BINDING, _))
111 .WillOnce(SetArgPointee<1>(test_params.frame_buffer_id));
112
113 EXPECT_CALL(mock_gl_impl_ref, DiscardFramebufferEXT(GL_FRAMEBUFFER, _, _))
114 .With(Args<2, 1>(ElementsAreArray(test_params.expected_attachments)))
115 .Times(1);
116 ASSERT_TRUE(render_pass->EncodeCommands());
117 ASSERT_TRUE(reactor->React());
118}

References command_buffer, context, dummy_worker, impeller::TextureDescriptor::format, impeller::testing::MockGLES::Init(), impeller::kDontCare, impeller::kR8G8B8A8UNormInt, mock_gl, mock_gl_impl_ref, reactor, render_pass, impeller::Attachment::texture, and impeller::TextureGLES::WrapFBO().

◆ TEST_P() [612/662]

impeller::testing::TEST_P ( RenderPassGLESWithDiscardFrameBufferExtTest  ,
InvalidateFramebuffer   
)

Definition at line 133 of file render_pass_gles_unittests.cc.

133 {
134 auto mock_gl_impl = std::make_unique<NiceMock<MockGLESImpl>>();
135 auto& mock_gl_impl_ref = *mock_gl_impl;
136 auto mock_gl =
137 MockGLES::Init(std::move(mock_gl_impl), std::nullopt, "OpenGL ES 3.0");
138
139 auto context = CreateFakeGLESContext();
140 auto dummy_worker = std::make_shared<MockWorker>();
141 context->AddReactorWorker(dummy_worker);
142 auto reactor = context->GetReactor();
143
144 const auto command_buffer =
145 std::static_pointer_cast<Context>(context)->CreateCommandBuffer();
146 auto render_target = RenderTarget{};
147 const auto description = TextureDescriptor{
148 .format = PixelFormat::kR8G8B8A8UNormInt, .size = {10, 10}};
149
150 const auto& test_params = GetParam();
151 auto framebuffer_texture =
152 TextureGLES::WrapFBO(reactor, description, test_params.frame_buffer_id);
153
154 auto color_attachment = ColorAttachment{Attachment{
155 .texture = framebuffer_texture, .store_action = StoreAction::kDontCare}};
156 render_target.SetColorAttachment(color_attachment, 0);
157 const auto render_pass = command_buffer->CreateRenderPass(render_target);
158
159 EXPECT_CALL(mock_gl_impl_ref, GetIntegerv(GL_FRAMEBUFFER_BINDING, _))
160 .WillOnce(SetArgPointee<1>(test_params.frame_buffer_id));
161
162 // InvalidateFramebuffer should be called instead of DiscardFramebufferEXT
163 EXPECT_CALL(mock_gl_impl_ref, InvalidateFramebuffer(GL_FRAMEBUFFER, _, _))
164 .With(Args<2, 1>(ElementsAreArray(test_params.expected_attachments)))
165 .Times(1);
166 EXPECT_CALL(mock_gl_impl_ref, DiscardFramebufferEXT(GL_FRAMEBUFFER, _, _))
167 .Times(0);
168
169 ASSERT_TRUE(render_pass->EncodeCommands());
170 ASSERT_TRUE(reactor->React());
171}

References command_buffer, context, dummy_worker, impeller::TextureDescriptor::format, impeller::testing::MockGLES::Init(), impeller::kDontCare, impeller::kR8G8B8A8UNormInt, mock_gl, mock_gl_impl_ref, reactor, render_pass, impeller::Attachment::texture, and impeller::TextureGLES::WrapFBO().

◆ TEST_P() [613/662]

impeller::testing::TEST_P ( RenderTargetCacheTest  ,
CachedTextureGetsNewAttachmentConfig   
)

Definition at line 123 of file render_target_cache_unittests.cc.

123 {
124 auto render_target_cache = RenderTargetCache(
125 GetContext()->GetResourceAllocator(), /*keep_alive_frame_count=*/0);
126
127 render_target_cache.Start();
128 RenderTarget::AttachmentConfig color_attachment_config =
129 RenderTarget::kDefaultColorAttachmentConfig;
130 RenderTarget target1 = render_target_cache.CreateOffscreen(
131 *GetContext(), {100, 100}, 1, "Offscreen1", color_attachment_config);
132 render_target_cache.End();
133
134 render_target_cache.Start();
135 color_attachment_config.clear_color = Color::Red();
136 RenderTarget target2 = render_target_cache.CreateOffscreen(
137 *GetContext(), {100, 100}, 1, "Offscreen2", color_attachment_config);
138 render_target_cache.End();
139
140 ColorAttachment color1 = target1.GetColorAttachment(0);
141 ColorAttachment color2 = target2.GetColorAttachment(0);
142 // The second color attachment should reuse the first attachment's texture
143 // but with attributes from the second AttachmentConfig.
144 EXPECT_EQ(color2.texture, color1.texture);
145 EXPECT_EQ(color2.clear_color, Color::Red());
146}
An implementation of the [RenderTargetAllocator] that caches all allocated texture data for at least ...

References impeller::ColorAttachment::clear_color, impeller::RenderTarget::AttachmentConfig::clear_color, impeller::RenderTarget::GetColorAttachment(), impeller::RenderTarget::kDefaultColorAttachmentConfig, impeller::Color::Red(), and impeller::Attachment::texture.

◆ TEST_P() [614/662]

impeller::testing::TEST_P ( RenderTargetCacheTest  ,
CachesUsedTexturesAcrossFrames   
)

Definition at line 53 of file render_target_cache_unittests.cc.

53 {
54 auto render_target_cache = RenderTargetCache(
55 GetContext()->GetResourceAllocator(), /*keep_alive_frame_count=*/0);
56
57 render_target_cache.Start();
58 // Create two render targets of the same exact size/shape. Both should be
59 // marked as used this frame, so the cached data set will contain two.
60 render_target_cache.CreateOffscreen(*GetContext(), {100, 100}, 1);
61 render_target_cache.CreateOffscreen(*GetContext(), {100, 100}, 1);
62
63 EXPECT_EQ(render_target_cache.CachedTextureCount(), 2u);
64
65 render_target_cache.End();
66 render_target_cache.Start();
67
68 // Next frame, only create one texture. The set will still contain two,
69 // but one will be removed at the end of the frame.
70 render_target_cache.CreateOffscreen(*GetContext(), {100, 100}, 1);
71 EXPECT_EQ(render_target_cache.CachedTextureCount(), 2u);
72
73 render_target_cache.End();
74 EXPECT_EQ(render_target_cache.CachedTextureCount(), 1u);
75}

◆ TEST_P() [615/662]

impeller::testing::TEST_P ( RenderTargetCacheTest  ,
CachesUsedTexturesAcrossFramesWithKeepAlive   
)

Definition at line 77 of file render_target_cache_unittests.cc.

77 {
78 auto render_target_cache = RenderTargetCache(
79 GetContext()->GetResourceAllocator(), /*keep_alive_frame_count=*/3);
80
81 render_target_cache.Start();
82 // Create two render targets of the same exact size/shape. Both should be
83 // marked as used this frame, so the cached data set will contain two.
84 render_target_cache.CreateOffscreen(*GetContext(), {100, 100}, 1);
85 render_target_cache.CreateOffscreen(*GetContext(), {100, 100}, 1);
86
87 EXPECT_EQ(render_target_cache.CachedTextureCount(), 2u);
88
89 render_target_cache.End();
90 render_target_cache.Start();
91
92 // The unused texture is kept alive until the keep alive countdown
93 // reaches 0.
94 EXPECT_EQ(render_target_cache.CachedTextureCount(), 2u);
95
96 for (auto i = 0; i < 3; i++) {
97 render_target_cache.Start();
98 render_target_cache.End();
99 EXPECT_EQ(render_target_cache.CachedTextureCount(), 2u);
100 }
101 // After the countdown has elapsed the texture is removed.
102 render_target_cache.Start();
103 render_target_cache.End();
104 EXPECT_EQ(render_target_cache.CachedTextureCount(), 0u);
105}

References i.

◆ TEST_P() [616/662]

impeller::testing::TEST_P ( RenderTargetCacheTest  ,
CreateWithEmptySize   
)

Definition at line 148 of file render_target_cache_unittests.cc.

148 {
149 auto render_target_cache = RenderTargetCache(
150 GetContext()->GetResourceAllocator(), /*keep_alive_frame_count=*/0);
151
152 render_target_cache.Start();
153 RenderTarget empty_target =
154 render_target_cache.CreateOffscreen(*GetContext(), {100, 0}, 1);
155 RenderTarget empty_target_msaa =
156 render_target_cache.CreateOffscreenMSAA(*GetContext(), {0, 0}, 1);
157 render_target_cache.End();
158
159 {
160 ScopedValidationDisable disable_validation;
161 EXPECT_FALSE(empty_target.IsValid());
162 EXPECT_FALSE(empty_target_msaa.IsValid());
163 }
164}

References impeller::RenderTarget::IsValid().

◆ TEST_P() [617/662]

impeller::testing::TEST_P ( RenderTargetCacheTest  ,
DoesNotPersistFailedAllocations   
)

Definition at line 107 of file render_target_cache_unittests.cc.

107 {
109 auto allocator = std::make_shared<TestAllocator>();
110 auto render_target_cache =
111 RenderTargetCache(allocator, /*keep_alive_frame_count=*/0);
112
113 render_target_cache.Start();
114 allocator->should_fail = true;
115
116 auto render_target =
117 render_target_cache.CreateOffscreen(*GetContext(), {100, 100}, 1);
118
119 EXPECT_FALSE(render_target.IsValid());
120 EXPECT_EQ(render_target_cache.CachedTextureCount(), 0u);
121}

References allocator.

◆ TEST_P() [618/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
CanCreatePipelineFromRuntimeStage   
)

Definition at line 446 of file runtime_stage_unittests.cc.

446 {
447 auto stages_result = OpenAssetAsRuntimeStage("ink_sparkle.frag.iplr");
448 ABSL_ASSERT_OK(stages_result);
449 auto stage = stages_result.value()[GetRuntimeStageBackend()];
450
451 ASSERT_TRUE(stage);
452 ASSERT_NE(stage, nullptr);
453 ASSERT_TRUE(RegisterStage(*stage));
454 auto library = GetContext()->GetShaderLibrary();
455 using VS = RuntimeEffectVertexShader;
457 desc.SetLabel("Runtime Stage InkSparkle");
459 library->GetFunction(VS::kEntrypointName, ShaderStage::kVertex));
461 library->GetFunction(stage->GetEntrypoint(), ShaderStage::kFragment));
462 auto vertex_descriptor = std::make_shared<VertexDescriptor>();
463 vertex_descriptor->SetStageInputs(VS::kAllShaderStageInputs,
464 VS::kInterleavedBufferLayout);
465
466 std::array<DescriptorSetLayout, 2> descriptor_set_layouts = {
467 VS::kDescriptorSetLayouts[0],
469 .binding = 64u,
470 .descriptor_type = DescriptorType::kUniformBuffer,
471 .shader_stage = ShaderStage::kFragment,
472 },
473 };
474 vertex_descriptor->RegisterDescriptorSetLayouts(descriptor_set_layouts);
475
476 desc.SetVertexDescriptor(std::move(vertex_descriptor));
477 ColorAttachmentDescriptor color0;
478 color0.format = GetContext()->GetCapabilities()->GetDefaultColorFormat();
479 StencilAttachmentDescriptor stencil0;
480 stencil0.stencil_compare = CompareFunction::kEqual;
481 desc.SetColorAttachmentDescriptor(0u, color0);
482 desc.SetStencilAttachmentDescriptors(stencil0);
483 const auto stencil_fmt =
484 GetContext()->GetCapabilities()->GetDefaultStencilFormat();
485 desc.SetStencilPixelFormat(stencil_fmt);
486 auto pipeline = GetContext()->GetPipelineLibrary()->GetPipeline(desc).Get();
487 ASSERT_NE(pipeline, nullptr);
488}
PipelineDescriptor & SetStencilPixelFormat(PixelFormat format)
PipelineDescriptor & AddStageEntrypoint(std::shared_ptr< const ShaderFunction > function)
PipelineDescriptor & SetStencilAttachmentDescriptors(std::optional< StencilAttachmentDescriptor > front_and_back)
PipelineDescriptor & SetColorAttachmentDescriptor(size_t index, ColorAttachmentDescriptor desc)

References impeller::PipelineDescriptor::AddStageEntrypoint(), impeller::DescriptorSetLayout::binding, impeller::ColorAttachmentDescriptor::format, impeller::kEqual, impeller::kFragment, impeller::kUniformBuffer, impeller::kVertex, pipeline, impeller::PipelineDescriptor::SetColorAttachmentDescriptor(), impeller::PipelineDescriptor::SetLabel(), impeller::PipelineDescriptor::SetStencilAttachmentDescriptors(), impeller::PipelineDescriptor::SetStencilPixelFormat(), impeller::PipelineDescriptor::SetVertexDescriptor(), and impeller::StencilAttachmentDescriptor::stencil_compare.

◆ TEST_P() [619/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
CanReadUniforms   
)

Definition at line 96 of file runtime_stage_unittests.cc.

96 {
97 const std::shared_ptr<fml::Mapping> fixture =
99 "all_supported_uniforms.frag.iplr");
100 ASSERT_TRUE(fixture);
101 ASSERT_GT(fixture->GetSize(), 0u);
102 auto stages = RuntimeStage::DecodeRuntimeStages(fixture);
103 ABSL_ASSERT_OK(stages);
104 auto stage = stages.value()[GetRuntimeStageBackend()];
105
106 ASSERT_TRUE(stage);
107 switch (GetBackend()) {
108 case PlaygroundBackend::kMetal:
109 [[fallthrough]];
110 case PlaygroundBackend::kMetalSDF:
111 [[fallthrough]];
112 case PlaygroundBackend::kOpenGLES:
113 [[fallthrough]];
114 case PlaygroundBackend::kOpenGLESSDF: {
115 ASSERT_EQ(stage->GetUniforms().size(), 14u);
116 {
117 // uFloat
118 auto uni = stage->GetUniform("uFloat");
119 ASSERT_NE(uni, nullptr);
120 EXPECT_EQ(uni->dimensions.rows, 1u);
121 EXPECT_EQ(uni->dimensions.cols, 1u);
122 EXPECT_EQ(uni->location, 0u);
123 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
124 EXPECT_TRUE(uni->padding_layout.empty());
125 }
126 {
127 // uVec2
128 auto uni = stage->GetUniform("uVec2");
129 ASSERT_NE(uni, nullptr);
130 EXPECT_EQ(uni->dimensions.rows, 2u);
131 EXPECT_EQ(uni->dimensions.cols, 1u);
132 EXPECT_EQ(uni->location, 1u);
133 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
134 EXPECT_TRUE(uni->padding_layout.empty());
135 }
136 {
137 // uVec3
138 auto uni = stage->GetUniform("uVec3");
139 ASSERT_NE(uni, nullptr);
140 EXPECT_EQ(uni->dimensions.rows, 3u);
141 EXPECT_EQ(uni->dimensions.cols, 1u);
142 EXPECT_EQ(uni->location, 2u);
143 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
144 auto padding = uni->padding_layout;
145 if (GetBackend() == PlaygroundBackend::kMetal ||
146 GetBackend() == PlaygroundBackend::kMetalSDF) {
147 EXPECT_EQ(padding.size(), 4u);
148 EXPECT_EQ(padding[0], RuntimePaddingType::kFloat);
149 EXPECT_EQ(padding[1], RuntimePaddingType::kFloat);
150 EXPECT_EQ(padding[2], RuntimePaddingType::kFloat);
151 EXPECT_EQ(padding[3], RuntimePaddingType::kPadding);
152 } else {
153 EXPECT_TRUE(padding.empty());
154 }
155 }
156 {
157 // uVec4
158 auto uni = stage->GetUniform("uVec4");
159 ASSERT_NE(uni, nullptr);
160 EXPECT_EQ(uni->dimensions.rows, 4u);
161 EXPECT_EQ(uni->dimensions.cols, 1u);
162 EXPECT_EQ(uni->location, 3u);
163 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
164 EXPECT_TRUE(uni->padding_layout.empty());
165 }
166 {
167 // uMat2
168 auto uni = stage->GetUniform("uMat2");
169 ASSERT_NE(uni, nullptr);
170 EXPECT_EQ(uni->dimensions.rows, 2u);
171 EXPECT_EQ(uni->dimensions.cols, 2u);
172 EXPECT_EQ(uni->location, 4u);
173 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
174 EXPECT_TRUE(uni->padding_layout.empty());
175 }
176 {
177 // uMat3
178 auto uni = stage->GetUniform("uMat3");
179 ASSERT_NE(uni, nullptr);
180 EXPECT_EQ(uni->dimensions.rows, 3u);
181 EXPECT_EQ(uni->dimensions.cols, 3u);
182 EXPECT_EQ(uni->location, 5u);
183 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
184 }
185 {
186 // uMat4
187 auto uni = stage->GetUniform("uMat4");
188 ASSERT_NE(uni, nullptr);
189 EXPECT_EQ(uni->dimensions.rows, 4u);
190 EXPECT_EQ(uni->dimensions.cols, 4u);
191 EXPECT_EQ(uni->location, 6u);
192 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
193 EXPECT_TRUE(uni->padding_layout.empty());
194 }
195 {
196 // uFloatArray
197 auto uni = stage->GetUniform("uFloatArray");
198 ASSERT_NE(uni, nullptr);
199 EXPECT_EQ(uni->dimensions.rows, 1u);
200 EXPECT_EQ(uni->dimensions.cols, 1u);
201 EXPECT_EQ(uni->location, 7u);
202 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
203 EXPECT_TRUE(uni->padding_layout.empty());
204 }
205 {
206 auto uni = stage->GetUniform("uVec2Array");
207 ASSERT_NE(uni, nullptr);
208 EXPECT_EQ(uni->dimensions.rows, 2u);
209 EXPECT_EQ(uni->dimensions.cols, 1u);
210 EXPECT_EQ(uni->location, 9u);
211 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
212 EXPECT_TRUE(uni->padding_layout.empty());
213 }
214 {
215 // uVec3Array
216 auto uni = stage->GetUniform("uVec3Array");
217 ASSERT_NE(uni, nullptr);
218 EXPECT_EQ(uni->dimensions.rows, 3u);
219 EXPECT_EQ(uni->dimensions.cols, 1u);
220 EXPECT_EQ(uni->location, 11u);
221 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
222 }
223 {
224 // uVec4Array
225 auto uni = stage->GetUniform("uVec4Array");
226 ASSERT_NE(uni, nullptr);
227 EXPECT_EQ(uni->dimensions.rows, 4u);
228 EXPECT_EQ(uni->dimensions.cols, 1u);
229 EXPECT_EQ(uni->location, 13u);
230 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
231 EXPECT_TRUE(uni->padding_layout.empty());
232 }
233 {
234 // uMat2Array
235 auto uni = stage->GetUniform("uMat2Array");
236 ASSERT_NE(uni, nullptr);
237 EXPECT_EQ(uni->dimensions.rows, 2u);
238 EXPECT_EQ(uni->dimensions.cols, 2u);
239 EXPECT_EQ(uni->location, 15u);
240 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
241 EXPECT_TRUE(uni->padding_layout.empty());
242 }
243 {
244 // uMat3Array
245 auto uni = stage->GetUniform("uMat3Array");
246 ASSERT_NE(uni, nullptr);
247 EXPECT_EQ(uni->dimensions.rows, 3u);
248 EXPECT_EQ(uni->dimensions.cols, 3u);
249 EXPECT_EQ(uni->location, 17u);
250 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
251 }
252 {
253 // uMat4Array
254 auto uni = stage->GetUniform("uMat4Array");
255 ASSERT_NE(uni, nullptr);
256 EXPECT_EQ(uni->dimensions.rows, 4u);
257 EXPECT_EQ(uni->dimensions.cols, 4u);
258 EXPECT_EQ(uni->location, 19u);
259 EXPECT_EQ(uni->type, RuntimeUniformType::kFloat);
260 EXPECT_TRUE(uni->padding_layout.empty());
261 }
262 break;
263 }
264 case PlaygroundBackend::kVulkan: {
265 EXPECT_EQ(stage->GetUniforms().size(), 1u);
266 const RuntimeUniformDescription* uni =
267 stage->GetUniform(RuntimeStage::kVulkanUBOName);
268 ASSERT_TRUE(uni);
269 EXPECT_EQ(uni->type, RuntimeUniformType::kStruct);
270 EXPECT_EQ(uni->struct_float_count, 26u);
271
272 EXPECT_EQ(uni->GetGPUSize(), 640u);
273 std::vector<RuntimePaddingType> layout(uni->GetGPUSize() / sizeof(float),
274 RuntimePaddingType::kFloat);
275 // uFloat and uVec2 are packed into a vec4 with 1 byte of padding between.
276 layout[1] = RuntimePaddingType::kPadding;
277 // uVec3 is packed as a vec4 with 1 byte of padding.
278 layout[7] = RuntimePaddingType::kPadding;
279 // uMat2 is packed as two vec4s, with the last 2 bytes of each being
280 // padding.
281 layout[14] = RuntimePaddingType::kPadding;
282 layout[15] = RuntimePaddingType::kPadding;
283 layout[18] = RuntimePaddingType::kPadding;
284 layout[19] = RuntimePaddingType::kPadding;
285 // uMat3 is packed as 3 vec4s, with the last byte of each being padding
286 layout[23] = RuntimePaddingType::kPadding;
287 layout[27] = RuntimePaddingType::kPadding;
288 layout[31] = RuntimePaddingType::kPadding;
289 // uFloatArray is packed as 2 vec4s, with the last 3 bytes of each
290 // being padding.
291 layout[49] = RuntimePaddingType::kPadding;
292 layout[50] = RuntimePaddingType::kPadding;
293 layout[51] = RuntimePaddingType::kPadding;
294 layout[53] = RuntimePaddingType::kPadding;
295 layout[54] = RuntimePaddingType::kPadding;
296 layout[55] = RuntimePaddingType::kPadding;
297 // uVec2Array is packed as 2 vec4s, with 2 bytes of padding at the end of
298 // each.
299 layout[58] = RuntimePaddingType::kPadding;
300 layout[59] = RuntimePaddingType::kPadding;
301 layout[62] = RuntimePaddingType::kPadding;
302 layout[63] = RuntimePaddingType::kPadding;
303 // uVec3Array is packed as 2 vec4s, with the last byte of each as padding.
304 layout[67] = RuntimePaddingType::kPadding;
305 layout[71] = RuntimePaddingType::kPadding;
306 // uVec4Array has no padding.
307 // uMat2Array[2] is packed as 4 vec4s, With the last 2 bytes of each being
308 // padding.
309 layout[82] = RuntimePaddingType::kPadding;
310 layout[83] = RuntimePaddingType::kPadding;
311 layout[86] = RuntimePaddingType::kPadding;
312 layout[87] = RuntimePaddingType::kPadding;
313 layout[90] = RuntimePaddingType::kPadding;
314 layout[91] = RuntimePaddingType::kPadding;
315 layout[94] = RuntimePaddingType::kPadding;
316 layout[95] = RuntimePaddingType::kPadding;
317 // uMat3Array[2] is packed as 6 vec4s, with the last byte of each being
318 // padding.
319 layout[99] = RuntimePaddingType::kPadding;
320 layout[103] = RuntimePaddingType::kPadding;
321 layout[107] = RuntimePaddingType::kPadding;
322 layout[111] = RuntimePaddingType::kPadding;
323 layout[115] = RuntimePaddingType::kPadding;
324 layout[119] = RuntimePaddingType::kPadding;
325 // uMat4Array[2] is packed as 8 vec4s with no padding.
326 layout[152] = RuntimePaddingType::kPadding;
327 layout[153] = RuntimePaddingType::kPadding;
328 layout[154] = RuntimePaddingType::kPadding;
329 layout[155] = RuntimePaddingType::kPadding;
330 layout[156] = RuntimePaddingType::kPadding;
331 layout[157] = RuntimePaddingType::kPadding;
332 layout[158] = RuntimePaddingType::kPadding;
333 layout[159] = RuntimePaddingType::kPadding;
334
335 EXPECT_THAT(uni->padding_layout, ::testing::ElementsAreArray(layout));
336
337 std::vector<std::pair<std::string, unsigned int>> expected_uniforms = {
338 {"uFloat", 4}, {"uVec2", 8}, {"uVec3", 12},
339 {"uVec4", 16}, {"uMat2", 16}, {"uMat3", 36},
340 {"uMat4", 64}, {"uFloatArray", 8}, {"uVec2Array", 16},
341 {"uVec3Array", 24}, {"uVec4Array", 32}, {"uMat2Array", 32},
342 {"uMat3Array", 72}, {"uMat4Array", 128}};
343
344 ASSERT_EQ(uni->struct_fields.size(), expected_uniforms.size());
345
346 for (size_t i = 0; i < expected_uniforms.size(); ++i) {
347 const auto& element = uni->struct_fields[i];
348 const auto& expected = expected_uniforms[i];
349
350 EXPECT_EQ(element.name, expected.first) << "index: " << i;
351 EXPECT_EQ(element.byte_size, expected.second) << "index: " << i;
352 }
353 break;
354 }
355 }
356}

References impeller::RuntimeStage::DecodeRuntimeStages(), impeller::RuntimeUniformDescription::GetGPUSize(), i, impeller::kFloat, impeller::kMetal, impeller::kMetalSDF, impeller::kOpenGLES, impeller::kOpenGLESSDF, impeller::kPadding, impeller::kStruct, impeller::kVulkan, impeller::RuntimeStage::kVulkanUBOName, flutter::testing::OpenFixtureAsMapping(), padding, impeller::RuntimeUniformDescription::padding_layout, impeller::RuntimeUniformDescription::struct_fields, impeller::RuntimeUniformDescription::struct_float_count, and impeller::RuntimeUniformDescription::type.

◆ TEST_P() [620/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
CanReadUniformsSamplerAfterUBO   
)

Definition at line 384 of file runtime_stage_unittests.cc.

384 {
385 if (GetBackend() != PlaygroundBackend::kVulkan) {
386 GTEST_SKIP() << "Test only relevant for Vulkan";
387 }
388 const std::shared_ptr<fml::Mapping> fixture =
390 "uniforms_and_sampler_2.frag.iplr");
391 ASSERT_TRUE(fixture);
392 ASSERT_GT(fixture->GetSize(), 0u);
393 auto stages = RuntimeStage::DecodeRuntimeStages(fixture);
394 ABSL_ASSERT_OK(stages);
395 auto stage = stages.value()[GetRuntimeStageBackend()];
396
397 EXPECT_EQ(stage->GetUniforms().size(), 2u);
398 auto uni = stage->GetUniform(RuntimeStage::kVulkanUBOName);
399 ASSERT_TRUE(uni);
400 // Struct must be offset at 45.
401 EXPECT_EQ(uni->type, RuntimeUniformType::kStruct);
402 EXPECT_EQ(uni->binding, 64u);
403 // Sampler should be offset at 64 but due to current bug
404 // has offset of 0, the correct offset is computed at runtime.
405 auto sampler_uniform = stage->GetUniform("u_texture");
406 EXPECT_EQ(sampler_uniform->type, RuntimeUniformType::kSampledImage);
407 EXPECT_EQ(sampler_uniform->binding, 65u);
408}

References impeller::RuntimeStage::DecodeRuntimeStages(), impeller::kSampledImage, impeller::kStruct, impeller::kVulkan, impeller::RuntimeStage::kVulkanUBOName, and flutter::testing::OpenFixtureAsMapping().

◆ TEST_P() [621/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
CanReadUniformsSamplerBeforeUBO   
)

Definition at line 358 of file runtime_stage_unittests.cc.

358 {
359 if (GetBackend() != PlaygroundBackend::kVulkan) {
360 GTEST_SKIP() << "Test only relevant for Vulkan";
361 }
362 const std::shared_ptr<fml::Mapping> fixture =
364 "uniforms_and_sampler_1.frag.iplr");
365 ASSERT_TRUE(fixture);
366 ASSERT_GT(fixture->GetSize(), 0u);
367 auto stages = RuntimeStage::DecodeRuntimeStages(fixture);
368 ABSL_ASSERT_OK(stages);
369 auto stage = stages.value()[GetRuntimeStageBackend()];
370
371 EXPECT_EQ(stage->GetUniforms().size(), 2u);
372 auto uni = stage->GetUniform(RuntimeStage::kVulkanUBOName);
373 ASSERT_TRUE(uni);
374 // Struct must be offset at 65.
375 EXPECT_EQ(uni->type, RuntimeUniformType::kStruct);
376 EXPECT_EQ(uni->binding, 65u);
377 // Sampler should be offset at 64 but due to current bug
378 // has offset of 0, the correct offset is computed at runtime.
379 auto sampler_uniform = stage->GetUniform("u_texture");
380 EXPECT_EQ(sampler_uniform->type, RuntimeUniformType::kSampledImage);
381 EXPECT_EQ(sampler_uniform->binding, 64u);
382}

References impeller::RuntimeStage::DecodeRuntimeStages(), impeller::kSampledImage, impeller::kStruct, impeller::kVulkan, impeller::RuntimeStage::kVulkanUBOName, and flutter::testing::OpenFixtureAsMapping().

◆ TEST_P() [622/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
CanReadValidBlob   
)

Definition at line 34 of file runtime_stage_unittests.cc.

34 {
35 const std::shared_ptr<fml::Mapping> fixture =
36 flutter::testing::OpenFixtureAsMapping("ink_sparkle.frag.iplr");
37 ASSERT_TRUE(fixture);
38 ASSERT_GT(fixture->GetSize(), 0u);
39 auto stages = RuntimeStage::DecodeRuntimeStages(fixture);
40 ABSL_ASSERT_OK(stages);
41 auto stage = stages.value()[GetRuntimeStageBackend()];
42 ASSERT_TRUE(stage);
43 ASSERT_EQ(stage->GetShaderStage(), RuntimeShaderStage::kFragment);
44}

References impeller::RuntimeStage::DecodeRuntimeStages(), impeller::kFragment, and flutter::testing::OpenFixtureAsMapping().

◆ TEST_P() [623/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
CanRegisterStage   
)

Definition at line 410 of file runtime_stage_unittests.cc.

410 {
411 const std::shared_ptr<fml::Mapping> fixture =
412 flutter::testing::OpenFixtureAsMapping("ink_sparkle.frag.iplr");
413 ASSERT_TRUE(fixture);
414 ASSERT_GT(fixture->GetSize(), 0u);
415 auto stages = RuntimeStage::DecodeRuntimeStages(fixture);
416 ABSL_ASSERT_OK(stages);
417 auto stage = stages.value()[GetRuntimeStageBackend()];
418 ASSERT_TRUE(stage);
419 std::promise<bool> registration;
420 auto future = registration.get_future();
421 auto library = GetContext()->GetShaderLibrary();
422 library->RegisterFunction(
423 stage->GetEntrypoint(), //
424 ToShaderStage(stage->GetShaderStage()), //
425 stage->GetCodeMapping(), //
426 fml::MakeCopyable([reg = std::move(registration)](bool result) mutable {
427 reg.set_value(result);
428 }));
429 ASSERT_TRUE(future.get());
430 {
431 auto function =
432 library->GetFunction(stage->GetEntrypoint(), ShaderStage::kFragment);
433 ASSERT_NE(function, nullptr);
434 }
435
436 // Check if unregistering works.
437
438 library->UnregisterFunction(stage->GetEntrypoint(), ShaderStage::kFragment);
439 {
440 auto function =
441 library->GetFunction(stage->GetEntrypoint(), ShaderStage::kFragment);
442 ASSERT_EQ(function, nullptr);
443 }
444}
Dart_NativeFunction function
Definition fuchsia.cc:51
internal::CopyableLambda< T > MakeCopyable(T lambda)
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)

References impeller::RuntimeStage::DecodeRuntimeStages(), function, impeller::kFragment, fml::MakeCopyable(), flutter::testing::OpenFixtureAsMapping(), and impeller::ToShaderStage().

◆ TEST_P() [624/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
CanRejectInvalidBlob   
)

Definition at line 59 of file runtime_stage_unittests.cc.

59 {
60 ScopedValidationDisable disable_validation;
61 const std::shared_ptr<fml::Mapping> fixture =
62 flutter::testing::OpenFixtureAsMapping("ink_sparkle.frag.iplr");
63 ASSERT_TRUE(fixture);
64 auto junk_allocation = std::make_shared<Allocation>();
65 ASSERT_TRUE(junk_allocation->Truncate(Bytes{fixture->GetSize()}, false));
66 // Not meant to be secure. Just reject obviously bad blobs using magic
67 // numbers.
68 ::memset(junk_allocation->GetBuffer(), 127,
69 junk_allocation->GetLength().GetByteSize());
70 auto stages = RuntimeStage::DecodeRuntimeStages(
71 CreateMappingFromAllocation(junk_allocation));
72 ASSERT_FALSE(stages.ok());
73}
std::shared_ptr< fml::Mapping > CreateMappingFromAllocation(const std::shared_ptr< Allocation > &allocation)
Creates a mapping from allocation.

References impeller::CreateMappingFromAllocation(), impeller::RuntimeStage::DecodeRuntimeStages(), and flutter::testing::OpenFixtureAsMapping().

◆ TEST_P() [625/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
ContainsExpectedShaderTypes   
)

Definition at line 490 of file runtime_stage_unittests.cc.

490 {
491 auto stages_result = OpenAssetAsRuntimeStage("ink_sparkle.frag.iplr");
492 ABSL_ASSERT_OK(stages_result);
493 auto stages = stages_result.value();
494 EXPECT_TRUE(stages[RuntimeStageBackend::kSkSL]);
495 EXPECT_TRUE(stages[RuntimeStageBackend::kOpenGLES]);
496 EXPECT_TRUE(stages[RuntimeStageBackend::kMetal]);
497 EXPECT_TRUE(stages[RuntimeStageBackend::kVulkan]);
498}

References impeller::kMetal, impeller::kOpenGLES, impeller::kSkSL, and impeller::kVulkan.

◆ TEST_P() [626/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
ContainsExpectedShaderTypesNoSksl   
)

Definition at line 500 of file runtime_stage_unittests.cc.

500 {
501 auto stages_result =
502 OpenAssetAsRuntimeStage("runtime_stage_simple_no_sksl.frag.iplr");
503 ABSL_ASSERT_OK(stages_result);
504 auto stages = stages_result.value();
505 EXPECT_FALSE(stages[RuntimeStageBackend::kSkSL]);
506 EXPECT_TRUE(stages[RuntimeStageBackend::kOpenGLES]);
507 EXPECT_TRUE(stages[RuntimeStageBackend::kMetal]);
508 EXPECT_TRUE(stages[RuntimeStageBackend::kVulkan]);
509}

References impeller::kMetal, impeller::kOpenGLES, impeller::kSkSL, and impeller::kVulkan.

◆ TEST_P() [627/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
RejectInvalidFormatVersion   
)

Definition at line 46 of file runtime_stage_unittests.cc.

46 {
47 flatbuffers::FlatBufferBuilder builder;
48 fb::RuntimeStagesBuilder stages_builder(builder);
49 stages_builder.add_format_version(0);
50 auto stages = stages_builder.Finish();
51 builder.Finish(stages, fb::RuntimeStagesIdentifier());
52 auto mapping = std::make_shared<fml::NonOwnedMapping>(
53 builder.GetBufferPointer(), builder.GetSize());
54 auto runtime_stages = RuntimeStage::DecodeRuntimeStages(mapping);
55 EXPECT_FALSE(runtime_stages.ok());
56 EXPECT_EQ(runtime_stages.status().code(), absl::StatusCode::kInvalidArgument);
57}

References impeller::RuntimeStage::DecodeRuntimeStages().

◆ TEST_P() [628/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
RejectsCorruptBufferWithValidIdentifier   
)

Definition at line 75 of file runtime_stage_unittests.cc.

75 {
76 ScopedValidationDisable disable_validation;
77 // Construct a buffer with a valid "IPLR" file identifier at bytes 4-7
78 // but a root table offset that points beyond the buffer. This passes
79 // the identifier check but fails FlatBuffer structural verification.
80 auto data = std::make_shared<std::vector<uint8_t>>(32, 0);
81 (*data)[4] = 'I';
82 (*data)[5] = 'P';
83 (*data)[6] = 'L';
84 (*data)[7] = 'R';
85 // Root offset (little-endian uint32 at offset 0) pointing out of bounds.
86 (*data)[0] = 0xFF;
87 (*data)[1] = 0xFF;
88
89 auto mapping = std::make_shared<fml::NonOwnedMapping>(
90 data->data(), data->size(), [data](auto, auto) {});
91 auto stages = RuntimeStage::DecodeRuntimeStages(mapping);
92 ASSERT_FALSE(stages.ok());
93 EXPECT_EQ(stages.status().code(), absl::StatusCode::kInvalidArgument);
94}

References flutter::data, and impeller::RuntimeStage::DecodeRuntimeStages().

◆ TEST_P() [629/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
RuntimeStageHasUniqueLibraryIdByDefault   
)

Definition at line 571 of file runtime_stage_unittests.cc.

571 {
572 // Two stages decoded independently must get distinct fallback library ids
573 // so that programmatically-constructed stages cannot collide with each
574 // other in the shared shader library.
575 const std::shared_ptr<fml::Mapping> fixture =
576 flutter::testing::OpenFixtureAsMapping("ink_sparkle.frag.iplr");
577 ASSERT_TRUE(fixture);
578 auto stages_a = RuntimeStage::DecodeRuntimeStages(fixture);
579 ABSL_ASSERT_OK(stages_a);
580 auto stages_b = RuntimeStage::DecodeRuntimeStages(fixture);
581 ABSL_ASSERT_OK(stages_b);
582 auto stage_a = stages_a.value()[GetRuntimeStageBackend()];
583 auto stage_b = stages_b.value()[GetRuntimeStageBackend()];
584 ASSERT_TRUE(stage_a);
585 ASSERT_TRUE(stage_b);
586 EXPECT_FALSE(stage_a->GetLibraryId().empty());
587 EXPECT_FALSE(stage_b->GetLibraryId().empty());
588 EXPECT_NE(stage_a->GetLibraryId(), stage_b->GetLibraryId());
589}

References impeller::RuntimeStage::DecodeRuntimeStages(), and flutter::testing::OpenFixtureAsMapping().

◆ TEST_P() [630/662]

impeller::testing::TEST_P ( RuntimeStageTest  ,
RuntimeStageLibraryIdCanBeOverridden   
)

Definition at line 591 of file runtime_stage_unittests.cc.

591 {
592 // FragmentProgram::initFromAsset overrides the fallback id with the asset
593 // path so that hot reload of the same asset evicts and replaces the same
594 // registry slot rather than leaking a new one.
595 const std::shared_ptr<fml::Mapping> fixture =
596 flutter::testing::OpenFixtureAsMapping("ink_sparkle.frag.iplr");
597 ASSERT_TRUE(fixture);
598 auto stages = RuntimeStage::DecodeRuntimeStages(fixture);
599 ABSL_ASSERT_OK(stages);
600 auto stage = stages.value()[GetRuntimeStageBackend()];
601 ASSERT_TRUE(stage);
602 stage->SetLibraryId("packages/my_pkg/assets/shader.frag");
603 EXPECT_EQ(stage->GetLibraryId(), "packages/my_pkg/assets/shader.frag");
604}

References impeller::RuntimeStage::DecodeRuntimeStages(), and flutter::testing::OpenFixtureAsMapping().

◆ TEST_P() [631/662]

impeller::testing::TEST_P ( SurfaceGLESTest  ,
CanWrapNonZeroFBO   
)

Definition at line 16 of file surface_gles_unittests.cc.

16 {
17 const GLuint fbo = 1988;
18 auto surface =
19 SurfaceGLES::WrapFBO(GetContext(), []() { return true; }, fbo,
20 PixelFormat::kR8G8B8A8UNormInt, {100, 100});
21 ASSERT_TRUE(!!surface);
22 ASSERT_TRUE(surface->IsValid());
23 ASSERT_TRUE(surface->GetRenderTarget().HasColorAttachment(0));
24 const auto& texture = TextureGLES::Cast(
25 *(surface->GetRenderTarget().GetColorAttachment(0).texture));
26 auto wrapped = texture.GetFBO();
27 ASSERT_TRUE(wrapped.has_value());
28 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
29 ASSERT_EQ(wrapped.value(), fbo);
30}

References impeller::BackendCast< TextureGLES, Texture >::Cast(), impeller::kR8G8B8A8UNormInt, surface, texture, and impeller::SurfaceGLES::WrapFBO().

◆ TEST_P() [632/662]

impeller::testing::TEST_P ( SwapchainTransientsMTLTest  ,
CanAllocateSwapchainTextures   
)

Definition at line 27 of file swapchain_transients_mtl_unittests.mm.

27 {
28 const auto& transients = std::make_shared<SwapchainTransientsMTL>(
29 GetContext()->GetResourceAllocator());
30
31 transients->SetSizeAndFormat({1, 1}, PixelFormat::kB8G8R8A8UNormInt);
32
33 auto resolve = transients->GetResolveTexture();
34 EXPECT_NE(resolve, nullptr);
35 EXPECT_NE(transients->GetMSAATexture(), nullptr);
36 EXPECT_NE(transients->GetDepthStencilTexture(), nullptr);
37
38 // Texture properties are correct for resolve.
39 EXPECT_EQ(resolve->GetTextureDescriptor().size, ISize(1, 1));
40 EXPECT_EQ(resolve->GetTextureDescriptor().format,
41 PixelFormat::kB8G8R8A8UNormInt);
42 EXPECT_EQ(resolve->GetTextureDescriptor().sample_count, SampleCount::kCount1);
43 EXPECT_EQ(resolve->GetTextureDescriptor().storage_mode,
44 StorageMode::kDevicePrivate);
45
46 // Texture properties are correct for MSAA.
47 auto msaa = transients->GetMSAATexture();
48 EXPECT_EQ(msaa->GetTextureDescriptor().size, ISize(1, 1));
49 EXPECT_EQ(msaa->GetTextureDescriptor().format,
50 PixelFormat::kB8G8R8A8UNormInt);
51 EXPECT_EQ(msaa->GetTextureDescriptor().sample_count, SampleCount::kCount4);
52 EXPECT_EQ(msaa->GetTextureDescriptor().storage_mode,
53 StorageMode::kDeviceTransient);
54
55 // Texture properties are correct for Depth+Stencil.
56 auto depth_stencil = transients->GetDepthStencilTexture();
57 EXPECT_EQ(depth_stencil->GetTextureDescriptor().size, ISize(1, 1));
58 EXPECT_EQ(depth_stencil->GetTextureDescriptor().format,
59 PixelFormat::kD32FloatS8UInt);
60 EXPECT_EQ(depth_stencil->GetTextureDescriptor().sample_count,
61 SampleCount::kCount4);
62 EXPECT_EQ(depth_stencil->GetTextureDescriptor().storage_mode,
63 StorageMode::kDeviceTransient);
64
65 // Textures are cached.
66 EXPECT_EQ(transients->GetResolveTexture(), resolve);
67
68 // Texture cache is invalidated when size changes.
69 transients->SetSizeAndFormat({2, 2}, PixelFormat::kB8G8R8A8UNormInt);
70 EXPECT_NE(resolve, transients->GetResolveTexture());
71 resolve = transients->GetResolveTexture();
72
73 // Texture cache is invalidated when pixel format changes.
74 transients->SetSizeAndFormat({2, 2}, PixelFormat::kB10G10R10A10XR);
75 EXPECT_NE(resolve, transients->GetResolveTexture());
76}

References impeller::kB10G10R10A10XR, impeller::kB8G8R8A8UNormInt, impeller::kCount1, impeller::kCount4, impeller::kD32FloatS8UInt, impeller::kDevicePrivate, and impeller::kDeviceTransient.

◆ TEST_P() [633/662]

impeller::testing::TEST_P ( TessellatorPlaygroundTest  ,
TessellateConvex16or32Bit   
)

Definition at line 26 of file tessellator_playground_unittests.cc.

26 {
27 auto tessellator16 = std::make_shared<Tessellator>(false);
28 auto tessellator32 = std::make_shared<Tessellator>(true);
29
30 auto data_host_buffer = HostBuffer::Create(
31 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
32 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
33 auto indexes_host_buffer = HostBuffer::Create(
34 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
35 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
36
37 auto path = flutter::DlPath::MakeRect(Rect::MakeLTRB(0, 0, 10, 10));
38
39 auto vertex_buffer16 = tessellator16->TessellateConvex(
40 path, *data_host_buffer, *indexes_host_buffer, 1.0, false, false);
41 auto vertex_buffer32 = tessellator32->TessellateConvex(
42 path, *data_host_buffer, *indexes_host_buffer, 1.0, false, false);
43
44 const std::vector<Point> expected = {
45 {0, 0}, {10, 0}, {10, 10}, {0, 10}, {0, 0}};
46 const std::vector<uint16_t> expected_indices = {0, 1, 3, 2};
47
48 EXPECT_EQ(vertex_buffer16.index_type, IndexType::k16bit);
49 EXPECT_EQ(expected, CopyBufferView<Point>(vertex_buffer16.vertex_buffer));
50 EXPECT_EQ(expected_indices,
51 CopyBufferView<uint16_t>(vertex_buffer16.index_buffer));
52
53 EXPECT_EQ(vertex_buffer32.index_type, IndexType::k32bit);
54 EXPECT_EQ(expected, CopyBufferView<Point>(vertex_buffer32.vertex_buffer));
55 EXPECT_EQ(
56 std::vector<uint32_t>(expected_indices.begin(), expected_indices.end()),
57 CopyBufferView<uint32_t>(vertex_buffer32.index_buffer));
58}

References impeller::HostBuffer::Create(), impeller::k16bit, impeller::k32bit, impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRect(), and flutter::path.

◆ TEST_P() [634/662]

impeller::testing::TEST_P ( TextContentsTest  ,
MaintainsShape   
)

Definition at line 186 of file text_contents_unittests.cc.

186 {
187 std::shared_ptr<TextFrame> text_frame =
188 MakeTextFrame("th", "ahem.ttf", TextOptions{.font_size = 50});
189
190 std::shared_ptr<TypographerContext> context = TypographerContextSkia::Make();
191 std::shared_ptr<GlyphAtlasContext> atlas_context =
192 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
193 std::shared_ptr<HostBuffer> data_host_buffer = HostBuffer::Create(
194 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
195 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
196 ASSERT_TRUE(context && context->IsValid());
197
198 for (int i = 0; i <= 1000; ++i) {
199 Scalar scale = (440.0f + i) / 1000.0f;
200 Matrix transform = Matrix::MakeScale({scale, scale, 1.0f});
201 Rect position_rect[2];
202 Rect uv_rect[2];
203
204 {
205 std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(12);
206
207 std::shared_ptr<GlyphAtlas> atlas =
208 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
209 GlyphAtlas::Type::kAlphaBitmap, transform,
210 atlas_context, text_frame, /*offset=*/{0, 0});
211 ISize texture_size = atlas->GetTexture()->GetSize();
212
213 TextContents::ComputeVertexData(
214 /*vtx_contents=*/data.data(),
215 /*entity_transform=*/transform,
216 /*frame=*/text_frame,
217 /*position=*/Point(0, 0),
218 /*screen_transform=*/transform,
219 /*glyph_properties=*/GlyphProperties{},
220 /*atlas=*/atlas);
221 position_rect[0] = PerVertexDataPositionToRect(data.begin());
222 uv_rect[0] = PerVertexDataUVToRect(data.begin(), texture_size);
223 position_rect[1] = PerVertexDataPositionToRect(data.begin() + 4);
224 uv_rect[1] = PerVertexDataUVToRect(data.begin() + 4, texture_size);
225 }
226 EXPECT_NEAR(GetAspectRatio(position_rect[1]), GetAspectRatio(uv_rect[1]),
227 0.001)
228 << i;
229 }
230}

References impeller::TextContents::ComputeVertexData(), context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::data, i, impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), impeller::Matrix::MakeScale(), and transform.

◆ TEST_P() [635/662]

impeller::testing::TEST_P ( TextContentsTest  ,
SimpleComputeVertexData   
)

Definition at line 108 of file text_contents_unittests.cc.

108 {
109#ifndef FML_OS_MACOSX
110 GTEST_SKIP() << "Results aren't stable across linux and macos.";
111#endif
112
113 std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
114
115 std::shared_ptr<TextFrame> text_frame =
116 MakeTextFrame("1", "ahem.ttf", TextOptions{.font_size = 50});
117
118 std::shared_ptr<TypographerContext> context = TypographerContextSkia::Make();
119 std::shared_ptr<GlyphAtlasContext> atlas_context =
120 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
121 std::shared_ptr<HostBuffer> data_host_buffer = HostBuffer::Create(
122 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
123 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
124 ASSERT_TRUE(context && context->IsValid());
125 std::shared_ptr<GlyphAtlas> atlas =
126 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
127 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
128 text_frame, /*offset=*/{0, 0});
129
130 ISize texture_size = atlas->GetTexture()->GetSize();
131 TextContents::ComputeVertexData(data.data(),
132 /*entity_transform=*/Matrix(),
133 /*frame=*/text_frame,
134 /*position=*/Point(0, 0),
135 /*screen_transform=*/Matrix(),
136 /*glyph_properties=*/GlyphProperties{},
137 /*atlas=*/atlas);
138
139 Rect position_rect = PerVertexDataPositionToRect(data.begin());
140 Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
141 // The -1 offset comes from Skia in `ComputeGlyphSize`. So since the font size
142 // is 50, the math appears to be to get back a 50x50 rect and apply 1 pixel
143 // of padding.
144 EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -41, 52, 52));
145 EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 52, 52));
146}

References impeller::TextContents::ComputeVertexData(), context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::data, EXPECT_RECT_NEAR, impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST_P() [636/662]

impeller::testing::TEST_P ( TextContentsTest  ,
SimpleComputeVertexData2x   
)

Definition at line 148 of file text_contents_unittests.cc.

148 {
149#ifndef FML_OS_MACOSX
150 GTEST_SKIP() << "Results aren't stable across linux and macos.";
151#endif
152
153 std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
154 std::shared_ptr<TextFrame> text_frame =
155 MakeTextFrame("1", "ahem.ttf", TextOptions{.font_size = 50});
156
157 std::shared_ptr<TypographerContext> context = TypographerContextSkia::Make();
158 std::shared_ptr<GlyphAtlasContext> atlas_context =
159 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
160 std::shared_ptr<HostBuffer> data_host_buffer = HostBuffer::Create(
161 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
162 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
163 ASSERT_TRUE(context && context->IsValid());
164 Matrix render_transform = Matrix::MakeScale({2.0f, 2.0f, 1.0f});
165 std::shared_ptr<GlyphAtlas> atlas =
166 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
167 GlyphAtlas::Type::kAlphaBitmap, render_transform,
168 atlas_context, text_frame, /*offset=*/{0, 0});
169
170 ISize texture_size = atlas->GetTexture()->GetSize();
171 TextContents::ComputeVertexData(
172 /*vtx_contents=*/data.data(),
173 /*entity_transform=*/render_transform,
174 /*frame=*/text_frame,
175 /*position=*/Point(0, 0),
176 /*screen_transform=*/render_transform,
177 /*glyph_properties=*/GlyphProperties{},
178 /*atlas=*/atlas);
179
180 Rect position_rect = PerVertexDataPositionToRect(data.begin());
181 Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
182 EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -81, 102, 102));
183 EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 102, 102));
184}

References impeller::TextContents::ComputeVertexData(), context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::data, EXPECT_RECT_NEAR, impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), impeller::Matrix::MakeScale(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST_P() [637/662]

impeller::testing::TEST_P ( TextContentsTest  ,
SimpleSubpixel   
)

Definition at line 232 of file text_contents_unittests.cc.

232 {
233#ifndef FML_OS_MACOSX
234 GTEST_SKIP() << "Results aren't stable across linux and macos.";
235#endif
236
237 std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
238
239 std::shared_ptr<TextFrame> text_frame = MakeTextFrame(
240 "1", "ahem.ttf", TextOptions{.font_size = 50, .is_subpixel = true});
241
242 std::shared_ptr<TypographerContext> context = TypographerContextSkia::Make();
243 std::shared_ptr<GlyphAtlasContext> atlas_context =
244 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
245 std::shared_ptr<HostBuffer> data_host_buffer = HostBuffer::Create(
246 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
247 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
248 ASSERT_TRUE(context && context->IsValid());
249 Point offset = Point(0.5, 0);
250 std::shared_ptr<GlyphAtlas> atlas =
251 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
252 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
253 text_frame, offset);
254
255 ISize texture_size = atlas->GetTexture()->GetSize();
256 TextContents::ComputeVertexData(
257 /*vtx_contents=*/data.data(),
258 /*entity_transform=*/Matrix(),
259 /*frame=*/text_frame,
260 /*position=*/offset,
261 /*screen_transform=*/Matrix(),
262 /*glyph_properties=*/GlyphProperties{},
263 /*atlas=*/atlas);
264
265 Rect position_rect = PerVertexDataPositionToRect(data.begin());
266 Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
267 // The values at Point(0, 0).
268 // EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -41, 52, 52));
269 // EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 52, 52));
270 EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-2, -41, 54, 52));
271 EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 54, 52));
272}

References impeller::TextContents::ComputeVertexData(), context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::data, EXPECT_RECT_NEAR, impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST_P() [638/662]

impeller::testing::TEST_P ( TextContentsTest  ,
SimpleSubpixel26   
)

Definition at line 319 of file text_contents_unittests.cc.

319 {
320#ifndef FML_OS_MACOSX
321 GTEST_SKIP() << "Results aren't stable across linux and macos.";
322#endif
323
324 std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
325
326 std::shared_ptr<TextFrame> text_frame = MakeTextFrame(
327 "1", "ahem.ttf", TextOptions{.font_size = 50, .is_subpixel = true});
328
329 std::shared_ptr<TypographerContext> context = TypographerContextSkia::Make();
330 std::shared_ptr<GlyphAtlasContext> atlas_context =
331 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
332 std::shared_ptr<HostBuffer> data_host_buffer = HostBuffer::Create(
333 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
334 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
335 ASSERT_TRUE(context && context->IsValid());
336 Point offset = Point(0.26, 0);
337 std::shared_ptr<GlyphAtlas> atlas =
338 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
339 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
340 text_frame, offset);
341
342 ISize texture_size = atlas->GetTexture()->GetSize();
343 TextContents::ComputeVertexData(
344 /*vtx_contents=*/data.data(),
345 /*entity_transform=*/Matrix(),
346 /*frame=*/text_frame,
347 /*position=*/offset,
348 /*screen_transform=*/Matrix(),
349 /*glyph_properties=*/GlyphProperties{},
350 /*atlas=*/atlas);
351
352 Rect position_rect = PerVertexDataPositionToRect(data.begin());
353 Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
354 // The values without subpixel.
355 // EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -41, 52, 52));
356 // EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 52, 52));
357 EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-2, -41, 54, 52));
358 EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 54, 52));
359}

References impeller::TextContents::ComputeVertexData(), context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::data, EXPECT_RECT_NEAR, impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST_P() [639/662]

impeller::testing::TEST_P ( TextContentsTest  ,
SimpleSubpixel3x   
)

Definition at line 274 of file text_contents_unittests.cc.

274 {
275#ifndef FML_OS_MACOSX
276 GTEST_SKIP() << "Results aren't stable across linux and macos.";
277#endif
278
279 std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
280
281 std::shared_ptr<TextFrame> text_frame = MakeTextFrame(
282 "1", "ahem.ttf", TextOptions{.font_size = 50, .is_subpixel = true});
283
284 std::shared_ptr<TypographerContext> context = TypographerContextSkia::Make();
285 std::shared_ptr<GlyphAtlasContext> atlas_context =
286 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
287 std::shared_ptr<HostBuffer> data_host_buffer = HostBuffer::Create(
288 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
289 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
290 ASSERT_TRUE(context && context->IsValid());
291 Matrix transform = Matrix::MakeScale({3.0f, 3.0f, 1.0f});
292 Point offset = {0.16667, 0};
293 std::shared_ptr<GlyphAtlas> atlas =
294 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
295 GlyphAtlas::Type::kAlphaBitmap, transform, atlas_context,
296 text_frame, offset);
297
298 ISize texture_size = atlas->GetTexture()->GetSize();
299 TextContents::ComputeVertexData(
300 /*vtx_contents=*/data.data(),
301 /*entity_transform=*/transform,
302 /*frame=*/text_frame,
303 /*position=*/offset,
304 /*screen_transform=*/transform,
305 /*glyph_properties=*/GlyphProperties{},
306 /*atlas=*/atlas);
307
308 Rect position_rect = PerVertexDataPositionToRect(data.begin());
309 Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
310 // Values at Point(0, 0)
311 // EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -121, 152, 152));
312 // EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 152, 152));
313 EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-2, -121, 154, 152))
314 << "position size:" << position_rect.GetSize();
315 EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 154, 152))
316 << "position size:" << position_rect.GetSize();
317}

References impeller::TextContents::ComputeVertexData(), context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::data, EXPECT_RECT_NEAR, impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeXYWH(), and transform.

◆ TEST_P() [640/662]

impeller::testing::TEST_P ( TextContentsTest  ,
SimpleSubpixel80   
)

Definition at line 361 of file text_contents_unittests.cc.

361 {
362#ifndef FML_OS_MACOSX
363 GTEST_SKIP() << "Results aren't stable across linux and macos.";
364#endif
365
366 std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data(4);
367
368 std::shared_ptr<TextFrame> text_frame = MakeTextFrame(
369 "1", "ahem.ttf", TextOptions{.font_size = 50, .is_subpixel = true});
370
371 std::shared_ptr<TypographerContext> context = TypographerContextSkia::Make();
372 std::shared_ptr<GlyphAtlasContext> atlas_context =
373 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
374 std::shared_ptr<HostBuffer> data_host_buffer = HostBuffer::Create(
375 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
376 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
377 ASSERT_TRUE(context && context->IsValid());
378 Point offset = Point(0.80, 0);
379 std::shared_ptr<GlyphAtlas> atlas =
380 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
381 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
382 text_frame, offset);
383
384 ISize texture_size = atlas->GetTexture()->GetSize();
385 TextContents::ComputeVertexData(
386 /*vtx_contents=*/data.data(),
387 /*entity_transform=*/Matrix(),
388 /*frame=*/text_frame,
389 /*position=*/offset,
390 /*screen_transform=*/Matrix(),
391 /*glyph_properties=*/GlyphProperties{},
392 /*atlas=*/atlas);
393
394 Rect position_rect = PerVertexDataPositionToRect(data.begin());
395 Rect uv_rect = PerVertexDataUVToRect(data.begin(), texture_size);
396 // The values without subpixel.
397 // EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -41, 52, 52));
398 // EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 52, 52));
399 EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-2, -41, 54, 52));
400 EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 54, 52));
401}

References impeller::TextContents::ComputeVertexData(), context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::data, EXPECT_RECT_NEAR, impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), and impeller::TRect< Scalar >::MakeXYWH().

◆ TEST_P() [641/662]

impeller::testing::TEST_P ( TextureGLESTest  ,
Binds2DTexture   
)

Definition at line 102 of file texture_gles_unittests.cc.

102 {
104 desc.storage_mode = StorageMode::kDevicePrivate;
105 desc.size = {100, 100};
106 desc.format = PixelFormat::kR8G8B8A8UNormInt;
107 desc.type = TextureType::kTexture2DMultisample;
108 desc.sample_count = SampleCount::kCount4;
109
110 auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc);
111
112 ASSERT_TRUE(texture);
113
114 if (GetContext()->GetCapabilities()->SupportsImplicitResolvingMSAA()) {
115 EXPECT_EQ(
116 TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_READ_FRAMEBUFFER),
117 TextureGLES::Type::kTexture);
118 EXPECT_EQ(TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_FRAMEBUFFER),
119 TextureGLES::Type::kTextureMultisampled);
120 } else {
121 EXPECT_EQ(
122 TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_READ_FRAMEBUFFER),
123 TextureGLES::Type::kRenderBufferMultisampled);
124 EXPECT_EQ(TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_FRAMEBUFFER),
125 TextureGLES::Type::kRenderBufferMultisampled);
126 }
127}

References impeller::BackendCast< TextureGLES, Texture >::Cast(), impeller::TextureGLES::ComputeTypeForBinding(), impeller::TextureDescriptor::format, impeller::kCount4, impeller::kDevicePrivate, impeller::kR8G8B8A8UNormInt, impeller::TextureGLES::kRenderBufferMultisampled, impeller::TextureGLES::kTexture, impeller::kTexture2DMultisample, impeller::TextureGLES::kTextureMultisampled, impeller::TextureDescriptor::sample_count, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, texture, and impeller::TextureDescriptor::type.

◆ TEST_P() [642/662]

impeller::testing::TEST_P ( TextureGLESTest  ,
CanSetSyncFence   
)

Definition at line 22 of file texture_gles_unittests.cc.

22 {
23 ContextGLES& context_gles = ContextGLES::Cast(*GetContext());
24 if (!context_gles.GetReactor()
25 ->GetProcTable()
26 .GetDescription()
27 ->GetGlVersion()
28 .IsAtLeast(Version{3, 0, 0})) {
29 GTEST_SKIP() << "GL Version too low to test sync fence.";
30 }
31
33 desc.storage_mode = StorageMode::kDevicePrivate;
34 desc.size = {100, 100};
35 desc.format = PixelFormat::kR8G8B8A8UNormInt;
36
37 auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc);
38 ASSERT_TRUE(!!texture);
39
40 EXPECT_TRUE(GetContext()->AddTrackingFence(texture));
41 EXPECT_TRUE(context_gles.GetReactor()->React());
42
43 std::optional<HandleGLES> sync_fence =
44 TextureGLES::Cast(*texture).GetSyncFence();
45 ASSERT_TRUE(sync_fence.has_value());
46 if (!sync_fence.has_value()) {
47 return;
48 }
49 EXPECT_EQ(sync_fence.value().GetType(), HandleType::kFence);
50
51 std::optional<GLsync> sync =
52 context_gles.GetReactor()->GetGLFence(sync_fence.value());
53 ASSERT_TRUE(sync.has_value());
54 if (!sync.has_value()) {
55 return;
56 }
57
58 // Now queue up operation that binds texture to verify that sync fence is
59 // waited and removed.
60
61 EXPECT_TRUE(
62 context_gles.GetReactor()->AddOperation([&](const ReactorGLES& reactor) {
63 return TextureGLES::Cast(*texture).Bind();
64 }));
65
66 sync_fence = TextureGLES::Cast(*texture).GetSyncFence();
67 ASSERT_FALSE(sync_fence.has_value());
68}
const std::shared_ptr< ReactorGLES > & GetReactor() const

References impeller::BackendCast< ContextGLES, Context >::Cast(), impeller::BackendCast< TextureGLES, Texture >::Cast(), impeller::TextureDescriptor::format, impeller::ContextGLES::GetReactor(), impeller::TextureGLES::GetSyncFence(), impeller::kDevicePrivate, impeller::kFence, impeller::kR8G8B8A8UNormInt, reactor, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, and texture.

◆ TEST_P() [643/662]

impeller::testing::TEST_P ( TextureGLESTest  ,
CreatingAndBindingEmptyTexturesDoesNotCrash   
)

Definition at line 151 of file texture_gles_unittests.cc.

151 {
152 ContextGLES& context_gles = ContextGLES::Cast(*GetContext());
153 const ProcTableGLES& gl = context_gles.GetReactor()->GetProcTable();
154 GLuint texture_name;
155 gl.GenTextures(1, &texture_name);
156
157 TextureDescriptor texture_descriptor;
158 texture_descriptor.storage_mode = StorageMode::kDevicePrivate;
159 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
160 texture_descriptor.size = ISize(0, 0);
161 texture_descriptor.mip_count = 1u;
162
163 impeller::HandleGLES texture_handle = context_gles.GetReactor()->CreateHandle(
164 impeller::HandleType::kTexture, texture_name);
165 auto texture = TextureGLES::WrapTexture(context_gles.GetReactor(),
166 texture_descriptor, texture_handle);
167 // The texture descriptor is invalid because its size is empty, so WrapTexture
168 // will return null.
169 ASSERT_EQ(texture, nullptr);
170}

References impeller::BackendCast< ContextGLES, Context >::Cast(), impeller::TextureDescriptor::format, impeller::ContextGLES::GetReactor(), impeller::kDevicePrivate, impeller::kR8G8B8A8UNormInt, impeller::kTexture, impeller::TextureDescriptor::mip_count, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, texture, and impeller::TextureGLES::WrapTexture().

◆ TEST_P() [644/662]

impeller::testing::TEST_P ( TextureGLESTest  ,
Leak   
)

Definition at line 129 of file texture_gles_unittests.cc.

129 {
131 desc.storage_mode = StorageMode::kDevicePrivate;
132 desc.size = {100, 100};
133 desc.format = PixelFormat::kR8G8B8A8UNormInt;
134 desc.type = TextureType::kTexture2D;
135 desc.sample_count = SampleCount::kCount1;
136
137 auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc);
138
139 ASSERT_TRUE(texture);
140
141 std::optional<GLuint> handle = TextureGLES::Cast(*texture).GetGLHandle();
142 EXPECT_TRUE(handle.has_value());
143
144 TextureGLES::Cast(*texture).Leak();
145
146 ScopedValidationDisable disable_validation;
147 handle = TextureGLES::Cast(*texture).GetGLHandle();
148 EXPECT_FALSE(handle.has_value());
149}

References impeller::BackendCast< TextureGLES, Texture >::Cast(), impeller::TextureDescriptor::format, impeller::TextureGLES::GetGLHandle(), impeller::kCount1, impeller::kDevicePrivate, impeller::kR8G8B8A8UNormInt, impeller::kTexture2D, impeller::TextureGLES::Leak(), impeller::TextureDescriptor::sample_count, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, texture, and impeller::TextureDescriptor::type.

◆ TEST_P() [645/662]

impeller::testing::TEST_P ( TextureGLESTest  ,
TextureDtorDeletesFence   
)

Definition at line 70 of file texture_gles_unittests.cc.

70 {
71 ContextGLES& context_gles = ContextGLES::Cast(*GetContext());
72 if (!context_gles.GetReactor()
73 ->GetProcTable()
74 .GetDescription()
75 ->GetGlVersion()
76 .IsAtLeast(Version{3, 0, 0})) {
77 GTEST_SKIP() << "GL Version too low to test sync fence.";
78 }
79
81 desc.storage_mode = StorageMode::kDevicePrivate;
82 desc.size = {100, 100};
83 desc.format = PixelFormat::kR8G8B8A8UNormInt;
84
85 auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc);
86 ASSERT_TRUE(!!texture);
87
88 HandleGLES fence =
89 context_gles.GetReactor()->CreateHandle(HandleType::kFence);
90 bool fence_collected = false;
91 context_gles.GetReactor()->RegisterCleanupCallback(
92 fence, [&]() { fence_collected = true; });
93 TextureGLES::Cast(*texture).SetFence(fence);
94
95 texture.reset();
96 ASSERT_TRUE(context_gles.GetReactor()->AddOperation(
97 [](const ReactorGLES& reactor) {}));
98 ASSERT_TRUE(context_gles.GetReactor()->React());
99 EXPECT_TRUE(fence_collected);
100}

References impeller::BackendCast< ContextGLES, Context >::Cast(), impeller::BackendCast< TextureGLES, Texture >::Cast(), impeller::TextureDescriptor::format, impeller::ContextGLES::GetReactor(), impeller::kDevicePrivate, impeller::kFence, impeller::kR8G8B8A8UNormInt, reactor, impeller::TextureGLES::SetFence(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, and texture.

◆ TEST_P() [646/662]

impeller::testing::TEST_P ( TypographerTest  ,
AlphaBitmapAtlasSkiaBitmapIsA8   
)

Definition at line 595 of file typographer_unittests.cc.

595 {
596 auto context = TypographerContextSkia::Make();
597 auto atlas_context =
598 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
599 auto data_host_buffer = HostBuffer::Create(
600 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
601 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
602 ASSERT_TRUE(context && context->IsValid());
603 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
604 auto blob = SkTextBlob::MakeFromString("A", sk_font);
605 ASSERT_TRUE(blob);
606 auto atlas =
607 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
608 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
610
611 SkImageInfo image_info = TypographerContextSkia::GetImageInfo(
612 *atlas, Size{100, 100}, /*support_light_glyphs=*/false);
613 EXPECT_EQ(image_info.colorType(), kAlpha_8_SkColorType);
614}
static std::shared_ptr< GlyphAtlas > CreateGlyphAtlas(Context &context, const TypographerContext *typographer_context, HostBuffer &data_host_buffer, GlyphAtlas::Type type, const Matrix &transform, const std::shared_ptr< GlyphAtlasContext > &atlas_context, const std::shared_ptr< TextFrame > &frame)

References context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::testing::CreateTestFontOfSize(), impeller::TypographerContextSkia::GetImageInfo(), impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), and impeller::MakeTextFrameFromTextBlobSkia().

◆ TEST_P() [647/662]

impeller::testing::TEST_P ( TypographerTest  ,
AlphaBitmapAtlasWithLightGlyphsSkiaBitmapIsRGBA8888   
)

Definition at line 616 of file typographer_unittests.cc.

616 {
617 auto context = TypographerContextSkia::Make();
618 auto atlas_context =
619 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
620 auto data_host_buffer = HostBuffer::Create(
621 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
622 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
623 ASSERT_TRUE(context && context->IsValid());
624 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
625 auto blob = SkTextBlob::MakeFromString("A", sk_font);
626 ASSERT_TRUE(blob);
627 auto atlas =
628 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
629 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
631
632 SkImageInfo image_info = TypographerContextSkia::GetImageInfo(
633 *atlas, Size{100, 100}, /*support_light_glyphs=*/true);
634 EXPECT_EQ(image_info.colorType(), kRGBA_8888_SkColorType);
635}

References context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::testing::CreateTestFontOfSize(), impeller::TypographerContextSkia::GetImageInfo(), impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), and impeller::MakeTextFrameFromTextBlobSkia().

◆ TEST_P() [648/662]

impeller::testing::TEST_P ( TypographerTest  ,
CanConvertTextBlob   
)

Definition at line 68 of file typographer_unittests.cc.

68 {
70 auto blob = SkTextBlob::MakeFromString(
71 "the quick brown fox jumped over the lazy dog.", font);
72 ASSERT_TRUE(blob);
73 auto frame = MakeTextFrameFromTextBlobSkia(blob);
74 ASSERT_EQ(frame->GetRunCount(), 1u);
75 for (const auto& run : frame->GetRuns()) {
76 ASSERT_TRUE(run.IsValid());
77 ASSERT_EQ(run.GetGlyphCount(), 45u);
78 }
79}

References flutter::testing::CreateTestFontOfSize(), and impeller::MakeTextFrameFromTextBlobSkia().

◆ TEST_P() [649/662]

impeller::testing::TEST_P ( TypographerTest  ,
CanCreateGlyphAtlas   
)

Definition at line 86 of file typographer_unittests.cc.

86 {
87 auto context = TypographerContextSkia::Make();
88 auto atlas_context =
89 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
90 auto data_host_buffer = HostBuffer::Create(
91 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
92 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
93 ASSERT_TRUE(context && context->IsValid());
94 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
95 auto blob = SkTextBlob::MakeFromString("hello", sk_font);
96 ASSERT_TRUE(blob);
97 auto atlas =
98 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
99 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
101
102 ASSERT_NE(atlas, nullptr);
103 ASSERT_NE(atlas->GetTexture(), nullptr);
104 ASSERT_EQ(atlas->GetType(), GlyphAtlas::Type::kAlphaBitmap);
105 ASSERT_EQ(atlas->GetGlyphCount(), 4llu);
106
107 std::optional<impeller::ScaledFont> first_scaled_font;
108 std::optional<impeller::SubpixelGlyph> first_glyph;
109 Rect first_rect;
110 atlas->IterateGlyphs([&](const ScaledFont& scaled_font,
111 const SubpixelGlyph& glyph,
112 const Rect& rect) -> bool {
113 first_scaled_font = scaled_font;
114 first_glyph = glyph;
115 first_rect = rect;
116 return false;
117 });
118
119 ASSERT_TRUE(first_scaled_font.has_value());
120 ASSERT_TRUE(atlas
121 ->FindFontGlyphBounds(
122 {first_scaled_font.value(), first_glyph.value()})
123 .has_value());
124}
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
A glyph and its subpixel position.

References context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::testing::CreateTestFontOfSize(), impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), and impeller::MakeTextFrameFromTextBlobSkia().

◆ TEST_P() [650/662]

impeller::testing::TEST_P ( TypographerTest  ,
CanCreateRenderContext   
)

Definition at line 81 of file typographer_unittests.cc.

81 {
82 auto context = TypographerContextSkia::Make();
83 ASSERT_TRUE(context && context->IsValid());
84}

References context, and impeller::TypographerContextSkia::Make().

◆ TEST_P() [651/662]

impeller::testing::TEST_P ( TypographerTest  ,
ColorBitmapAtlasSkiaBitmapIsRGBA8888   
)

Definition at line 574 of file typographer_unittests.cc.

574 {
575 auto context = TypographerContextSkia::Make();
576 auto atlas_context =
577 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kColorBitmap);
578 auto data_host_buffer = HostBuffer::Create(
579 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
580 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
581 ASSERT_TRUE(context && context->IsValid());
582 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
583 auto blob = SkTextBlob::MakeFromString("A", sk_font);
584 ASSERT_TRUE(blob);
585 auto atlas =
586 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
587 GlyphAtlas::Type::kColorBitmap, Matrix(), atlas_context,
589
590 SkImageInfo image_info = TypographerContextSkia::GetImageInfo(
591 *atlas, Size{100, 100}, /*support_light_glyphs=*/false);
592 EXPECT_EQ(image_info.colorType(), kRGBA_8888_SkColorType);
593}

References context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::testing::CreateTestFontOfSize(), impeller::TypographerContextSkia::GetImageInfo(), impeller::GlyphAtlas::kColorBitmap, impeller::TypographerContextSkia::Make(), and impeller::MakeTextFrameFromTextBlobSkia().

◆ TEST_P() [652/662]

impeller::testing::TEST_P ( TypographerTest  ,
GlyphAtlasIsRecycledIfUnchanged   
)

Definition at line 189 of file typographer_unittests.cc.

189 {
190 auto context = TypographerContextSkia::Make();
191 auto atlas_context =
192 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
193 auto data_host_buffer = HostBuffer::Create(
194 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
195 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
196 ASSERT_TRUE(context && context->IsValid());
197 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
198 auto blob = SkTextBlob::MakeFromString("spooky skellingtons", sk_font);
199 ASSERT_TRUE(blob);
200 auto atlas =
201 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
202 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
204 ASSERT_NE(atlas, nullptr);
205 ASSERT_NE(atlas->GetTexture(), nullptr);
206 ASSERT_EQ(atlas, atlas_context->GetGlyphAtlas());
207
208 // now attempt to re-create an atlas with the same text blob.
209
210 auto next_atlas =
211 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
212 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
214 ASSERT_EQ(atlas, next_atlas);
215 ASSERT_EQ(atlas_context->GetGlyphAtlas(), atlas);
216}

References context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::testing::CreateTestFontOfSize(), impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), and impeller::MakeTextFrameFromTextBlobSkia().

◆ TEST_P() [653/662]

impeller::testing::TEST_P ( TypographerTest  ,
GlyphAtlasTextureIsRecycledIfUnchanged   
)

Definition at line 269 of file typographer_unittests.cc.

269 {
270 auto data_host_buffer = HostBuffer::Create(
271 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
272 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
273 auto context = TypographerContextSkia::Make();
274 auto atlas_context =
275 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
276 ASSERT_TRUE(context && context->IsValid());
277 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
278 auto blob = SkTextBlob::MakeFromString("spooky 1", sk_font);
279 ASSERT_TRUE(blob);
280 auto atlas =
281 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
282 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
284 auto old_packer = atlas_context->GetRectPacker();
285
286 ASSERT_NE(atlas, nullptr);
287 ASSERT_NE(atlas->GetTexture(), nullptr);
288 ASSERT_EQ(atlas, atlas_context->GetGlyphAtlas());
289
290 auto* first_texture = atlas->GetTexture().get();
291
292 // Now create a new glyph atlas with a nearly identical blob.
293
294 auto blob2 = SkTextBlob::MakeFromString("spooky 2", sk_font);
295 auto next_atlas =
296 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
297 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
299 ASSERT_EQ(atlas, next_atlas);
300 auto* second_texture = next_atlas->GetTexture().get();
301
302 auto new_packer = atlas_context->GetRectPacker();
303
304 ASSERT_EQ(second_texture, first_texture);
305 ASSERT_EQ(old_packer, new_packer);
306}

References context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::testing::CreateTestFontOfSize(), impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), and impeller::MakeTextFrameFromTextBlobSkia().

◆ TEST_P() [654/662]

impeller::testing::TEST_P ( TypographerTest  ,
GlyphAtlasTextureWillGrowTilMaxTextureSize   
)

Definition at line 477 of file typographer_unittests.cc.

477 {
478 if (GetBackend() == PlaygroundBackend::kOpenGLES ||
479 GetBackend() == PlaygroundBackend::kOpenGLESSDF) {
480 GTEST_SKIP() << "Atlas growth isn't supported for OpenGLES currently.";
481 }
482
483 auto data_host_buffer = HostBuffer::Create(
484 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
485 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
486 auto context = TypographerContextSkia::Make();
487 auto atlas_context =
488 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
489 ASSERT_TRUE(context && context->IsValid());
490 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
491 auto blob = SkTextBlob::MakeFromString("A", sk_font);
492 ASSERT_TRUE(blob);
493 auto atlas =
494 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
495 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
497
498 SkFont sk_font_small = flutter::testing::CreateTestFontOfSize(10);
499
500 ISize prev_atlas_size;
501 for (int i = 0; i < 100; i++) {
502 SkTextBlobBuilder builder;
503
504 auto add_char = [&](const SkFont& sk_font, char c) {
505 int count = sk_font.countText(&c, 1, SkTextEncoding::kUTF8);
506 auto buffer = builder.allocRunPos(sk_font, count);
507 sk_font.textToGlyphs(&c, 1, SkTextEncoding::kUTF8,
508 {buffer.glyphs, count});
509 sk_font.getPos({buffer.glyphs, count}, {buffer.points(), count},
510 {0, 0} /*=origin*/);
511 };
512
513 SkFont sk_font = flutter::testing::CreateTestFontOfSize(50 + i);
514 add_char(sk_font, 'A');
515 add_char(sk_font_small, 'B');
516 auto blob = builder.make();
517
518 Matrix transform = Matrix::MakeScale({50.0f + i, 50.0f + i, 1.0f});
519 atlas =
520 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
521 GlyphAtlas::Type::kAlphaBitmap, transform,
522 atlas_context, MakeTextFrameFromTextBlobSkia(blob));
523 ASSERT_TRUE(!!atlas);
524 ISize atlas_size = atlas->GetTexture()->GetTextureDescriptor().size;
525 if (atlas_size.width < prev_atlas_size.width ||
526 atlas_size.height < prev_atlas_size.height) {
527 // We've triggered an atlas flush and recreate. We're done.
528
529 // The final atlas should contain both the "A" glyph (which was not
530 // present in the previous atlas) and the "B" glyph (which existed
531 // in the previous atlas).
532 ASSERT_EQ(atlas->GetGlyphCount(), 2u);
533 return;
534 }
535 prev_atlas_size = atlas_size;
536 }
537
538 // We never triggered the atlas recreate after 100 text calls.
539 // Either something is wrong with the atlas code or we need to fix this test.
540 GTEST_FAIL() << "Test did not encounter an atlas growth situation";
541}

References flutter::buffer, c, context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::testing::CreateTestFontOfSize(), impeller::TSize< T >::height, i, impeller::GlyphAtlas::kAlphaBitmap, impeller::kOpenGLES, impeller::kOpenGLESSDF, impeller::TypographerContextSkia::Make(), impeller::Matrix::MakeScale(), impeller::MakeTextFrameFromTextBlobSkia(), transform, and impeller::TSize< T >::width.

◆ TEST_P() [655/662]

impeller::testing::TEST_P ( TypographerTest  ,
GlyphAtlasWithLotsOfdUniqueGlyphSize   
)

Definition at line 218 of file typographer_unittests.cc.

218 {
219 auto data_host_buffer = HostBuffer::Create(
220 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
221 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
222 auto context = TypographerContextSkia::Make();
223 auto atlas_context =
224 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
225 ASSERT_TRUE(context && context->IsValid());
226
227 const char* test_string =
228 "QWERTYUIOPASDFGHJKLZXCVBNMqewrtyuiopasdfghjklzxcvbnm,.<>[]{};':"
229 "2134567890-=!@#$%^&*()_+"
230 "œ∑´®†¥¨ˆøπ““‘‘åß∂ƒ©˙∆˚¬…æ≈ç√∫˜µ≤≥≥≥≥÷¡™£¢∞§¶•ªº–≠⁄€‹›fifl‡°·‚—±Œ„´‰Á¨Ø∏”’/"
231 "* Í˝ */¸˛Ç◊ı˜Â¯˘¿";
232
233 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
234 auto blob = SkTextBlob::MakeFromString(test_string, sk_font);
235 ASSERT_TRUE(blob);
236
237 size_t size_count = 8;
238 std::vector<RenderableText> render_frames;
239 for (size_t index = 0; index < size_count; index += 1) {
240 Scalar scale = 6.0f * index / 10.0f;
241 render_frames.emplace_back(MakeTextFrameFromTextBlobSkia(blob),
242 Matrix::MakeScale({scale, scale, 1.0f}),
244 };
245 auto atlas = context->CreateGlyphAtlas(
246 *GetContext(), GlyphAtlas::Type::kAlphaBitmap, *data_host_buffer,
247 atlas_context, render_frames);
248 ASSERT_NE(atlas, nullptr);
249 ASSERT_NE(atlas->GetTexture(), nullptr);
250
251 std::set<uint16_t> unique_glyphs;
252 std::vector<uint16_t> total_glyphs;
253 atlas->IterateGlyphs([&](const ScaledFont& scaled_font,
254 const SubpixelGlyph& glyph, const Rect& rect) {
255 unique_glyphs.insert(glyph.glyph.index);
256 total_glyphs.push_back(glyph.glyph.index);
257 return true;
258 });
259
260 // These numbers may be different due to subpixel positions.
261 EXPECT_LE(unique_glyphs.size() * size_count, atlas->GetGlyphCount());
262 EXPECT_EQ(total_glyphs.size(), atlas->GetGlyphCount());
263
264 EXPECT_TRUE(atlas->GetGlyphCount() > 0);
265 EXPECT_TRUE(atlas->GetTexture()->GetSize().width > 0);
266 EXPECT_TRUE(atlas->GetTexture()->GetSize().height > 0);
267}

References context, impeller::HostBuffer::Create(), flutter::testing::CreateTestFontOfSize(), impeller::SubpixelGlyph::glyph, impeller::Glyph::index, impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), impeller::Matrix::MakeScale(), and impeller::MakeTextFrameFromTextBlobSkia().

◆ TEST_P() [656/662]

impeller::testing::TEST_P ( TypographerTest  ,
GlyphAtlasWithOddUniqueGlyphSize   
)

Definition at line 167 of file typographer_unittests.cc.

167 {
168 auto context = TypographerContextSkia::Make();
169 auto atlas_context =
170 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
171 auto data_host_buffer = HostBuffer::Create(
172 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
173 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
174 ASSERT_TRUE(context && context->IsValid());
175 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
176 auto blob = SkTextBlob::MakeFromString("AGH", sk_font);
177 ASSERT_TRUE(blob);
178 auto atlas =
179 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
180 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
182 ASSERT_NE(atlas, nullptr);
183 ASSERT_NE(atlas->GetTexture(), nullptr);
184
185 EXPECT_EQ(atlas->GetTexture()->GetSize().width, 4096u);
186 EXPECT_EQ(atlas->GetTexture()->GetSize().height, 1024u);
187}

References context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::testing::CreateTestFontOfSize(), impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), and impeller::MakeTextFrameFromTextBlobSkia().

◆ TEST_P() [657/662]

impeller::testing::TEST_P ( TypographerTest  ,
GlyphColorIsIgnoredForNonEmojiFonts   
)

Definition at line 344 of file typographer_unittests.cc.

344 {
345 auto data_host_buffer = HostBuffer::Create(
346 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
347 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
348 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
349 sk_sp<SkTypeface> typeface =
350 font_mgr->matchFamilyStyle("Arial", SkFontStyle::Normal());
351 SkFont sk_font(typeface, 0.5f);
352
353 auto context = TypographerContextSkia::Make();
354 auto atlas_context =
355 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kColorBitmap);
356
357 // Create two frames with the same character and a different color, but as a
358 // non-emoji font the text frame constructor will ignore it.
359 auto frame =
360 MakeTextFrameFromTextBlobSkia(SkTextBlob::MakeFromString("A", sk_font));
361 auto frame_2 =
362 MakeTextFrameFromTextBlobSkia(SkTextBlob::MakeFromString("A", sk_font));
363 std::vector<GlyphProperties> properties = {
366 };
367
368 auto next_atlas =
369 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
370 GlyphAtlas::Type::kColorBitmap, Matrix(), atlas_context,
371 {frame, frame_2}, properties);
372
373 EXPECT_EQ(next_atlas->GetGlyphCount(), 1u);
374}

References context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), txt::GetDefaultFontManager(), impeller::GlyphAtlas::kColorBitmap, impeller::TypographerContextSkia::Make(), and impeller::MakeTextFrameFromTextBlobSkia().

◆ TEST_P() [658/662]

impeller::testing::TEST_P ( TypographerTest  ,
GlyphColorIsPartOfCacheKey   
)

Definition at line 308 of file typographer_unittests.cc.

308 {
309 auto data_host_buffer = HostBuffer::Create(
310 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
311 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
312#if FML_OS_MACOSX
313 auto mapping = flutter::testing::OpenFixtureAsSkData("Apple Color Emoji.ttc");
314#else
315 auto mapping = flutter::testing::OpenFixtureAsSkData("NotoColorEmoji.ttf");
316#endif
317 ASSERT_TRUE(mapping);
318 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
319 SkFont emoji_font(font_mgr->makeFromData(mapping), 50.0);
320
321 auto context = TypographerContextSkia::Make();
322 auto atlas_context =
323 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kColorBitmap);
324
325 // Create two frames with the same character and a different color, expect
326 // that it adds a character.
328 SkTextBlob::MakeFromString("😂", emoji_font));
329 auto frame_2 = MakeTextFrameFromTextBlobSkia(
330 SkTextBlob::MakeFromString("😂", emoji_font));
331 std::vector<GlyphProperties> properties = {
332 GlyphProperties{.tone_or_color = Color::Red()},
333 GlyphProperties{.tone_or_color = Color::Blue()},
334 };
335
336 auto next_atlas =
337 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
338 GlyphAtlas::Type::kColorBitmap, Matrix(), atlas_context,
339 {frame, frame_2}, properties);
340
341 EXPECT_EQ(next_atlas->GetGlyphCount(), 2u);
342}

References impeller::Color::Blue(), context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), txt::GetDefaultFontManager(), impeller::GlyphAtlas::kColorBitmap, impeller::TypographerContextSkia::Make(), impeller::MakeTextFrameFromTextBlobSkia(), flutter::testing::OpenFixtureAsSkData(), impeller::Color::Red(), and impeller::GlyphProperties::tone_or_color.

◆ TEST_P() [659/662]

impeller::testing::TEST_P ( TypographerTest  ,
GlyphIsLightIsPartOfCacheKey   
)

Definition at line 376 of file typographer_unittests.cc.

376 {
377 auto data_host_buffer = HostBuffer::Create(
378 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
379 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
380 auto context = TypographerContextSkia::Make();
381 auto atlas_context =
382 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
383
384 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
385 auto blob1 = SkTextBlob::MakeFromString("A", sk_font);
386 auto blob2 = SkTextBlob::MakeFromString("A", sk_font);
387 auto frame1 = MakeTextFrameFromTextBlobSkia(blob1);
388 auto frame2 = MakeTextFrameFromTextBlobSkia(blob2);
389
390 std::vector<GlyphProperties> properties = {
393 };
394 // One light color, one dark color
395 properties[0].tone_or_color = GlyphProperties::ComputeTone(Color::Beige());
396 properties[1].tone_or_color = GlyphProperties::ComputeTone(Color::Crimson());
397
398 auto next_atlas =
399 CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
400 GlyphAtlas::Type::kAlphaBitmap, Matrix(), atlas_context,
401 {frame1, frame2}, properties);
402
403#if defined(FML_OS_MACOSX)
404 // On Apple platforms, they should be separated into 2 entries
405 EXPECT_EQ(next_atlas->GetGlyphCount(), 2u);
406#else
407 // On other platforms, both are classified as "dark" (false) and share 1 entry
408 EXPECT_EQ(next_atlas->GetGlyphCount(), 1u);
409#endif
410}

References impeller::Color::Beige(), impeller::GlyphProperties::ComputeTone(), context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::testing::CreateTestFontOfSize(), impeller::Color::Crimson(), impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), impeller::MakeTextFrameFromTextBlobSkia(), and impeller::GlyphProperties::tone_or_color.

◆ TEST_P() [660/662]

impeller::testing::TEST_P ( TypographerTest  ,
InvalidAtlasForcesRepopulation   
)

Definition at line 543 of file typographer_unittests.cc.

543 {
545 auto blob = SkTextBlob::MakeFromString(
546 "the quick brown fox jumped over the lazy dog.", font);
547 ASSERT_TRUE(blob);
548 auto frame = MakeTextFrameFromTextBlobSkia(blob);
549
550 auto context = TypographerContextSkia::Make();
551 auto atlas_context =
552 context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
553 auto data_host_buffer = HostBuffer::Create(
554 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
555 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
556
557 auto atlas = CreateGlyphAtlas(*GetContext(), context.get(), *data_host_buffer,
558 GlyphAtlas::Type::kAlphaBitmap, Matrix(),
559 atlas_context, frame);
560
561 auto second_context = TypographerContextSkia::Make();
562 auto second_atlas_context =
563 second_context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
564
565 EXPECT_FALSE(second_atlas_context->GetGlyphAtlas()->IsValid());
566
567 atlas = CreateGlyphAtlas(*GetContext(), second_context.get(),
568 *data_host_buffer, GlyphAtlas::Type::kAlphaBitmap,
569 Matrix(), second_atlas_context, frame);
570
571 EXPECT_TRUE(second_atlas_context->GetGlyphAtlas()->IsValid());
572}

References context, impeller::HostBuffer::Create(), CreateGlyphAtlas(), flutter::testing::CreateTestFontOfSize(), impeller::GlyphAtlas::kAlphaBitmap, impeller::TypographerContextSkia::Make(), and impeller::MakeTextFrameFromTextBlobSkia().

◆ TEST_P() [661/662]

impeller::testing::TEST_P ( TypographerTest  ,
LazyAtlasTracksColor   
)

Definition at line 126 of file typographer_unittests.cc.

126 {
127 auto data_host_buffer = HostBuffer::Create(
128 GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
129 GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
130#if FML_OS_MACOSX
131 auto mapping = flutter::testing::OpenFixtureAsSkData("Apple Color Emoji.ttc");
132#else
133 auto mapping = flutter::testing::OpenFixtureAsSkData("NotoColorEmoji.ttf");
134#endif
135 ASSERT_TRUE(mapping);
136 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
137 SkFont emoji_font(font_mgr->makeFromData(mapping), 50.0);
138 SkFont sk_font = flutter::testing::CreateTestFontOfSize(12);
139
140 auto blob = SkTextBlob::MakeFromString("hello", sk_font);
141 ASSERT_TRUE(blob);
142 auto frame = MakeTextFrameFromTextBlobSkia(blob);
143
144 ASSERT_FALSE(frame->GetAtlasType() == GlyphAtlas::Type::kColorBitmap);
145
146 LazyGlyphAtlas lazy_atlas(TypographerContextSkia::Make());
147
148 lazy_atlas.AddTextFrame(frame, {0, 0}, Matrix(), {});
149
150 frame = MakeTextFrameFromTextBlobSkia(
151 SkTextBlob::MakeFromString("😀 ", emoji_font));
152
153 ASSERT_TRUE(frame->GetAtlasType() == GlyphAtlas::Type::kColorBitmap);
154
155 lazy_atlas.AddTextFrame(frame, {0, 0}, Matrix(), {});
156
157 // Creates different atlases for color and red bitmap.
158 auto color_atlas = lazy_atlas.CreateOrGetGlyphAtlas(
159 *GetContext(), *data_host_buffer, GlyphAtlas::Type::kColorBitmap);
160
161 auto bitmap_atlas = lazy_atlas.CreateOrGetGlyphAtlas(
162 *GetContext(), *data_host_buffer, GlyphAtlas::Type::kAlphaBitmap);
163
164 ASSERT_FALSE(color_atlas == bitmap_atlas);
165}

References impeller::LazyGlyphAtlas::AddTextFrame(), impeller::HostBuffer::Create(), impeller::LazyGlyphAtlas::CreateOrGetGlyphAtlas(), flutter::testing::CreateTestFontOfSize(), txt::GetDefaultFontManager(), impeller::GlyphAtlas::kAlphaBitmap, impeller::GlyphAtlas::kColorBitmap, impeller::TypographerContextSkia::Make(), impeller::MakeTextFrameFromTextBlobSkia(), and flutter::testing::OpenFixtureAsSkData().

◆ TEST_P() [662/662]

impeller::testing::TEST_P ( TypographerTest  ,
RectanglePackerAddsNonoverlapingRectangles   
)

Definition at line 412 of file typographer_unittests.cc.

412 {
413 auto packer = RectanglePacker::Factory(200, 100);
414 ASSERT_NE(packer, nullptr);
415 ASSERT_EQ(packer->PercentFull(), 0);
416
417 const SkIRect packer_area = SkIRect::MakeXYWH(0, 0, 200, 100);
418
419 IPoint16 first_output = {-1, -1}; // Fill with sentinel values
420 ASSERT_TRUE(packer->AddRect(20, 20, &first_output));
421 // Make sure the rectangle is placed such that it is inside the bounds of
422 // the packer's area.
423 const SkIRect first_rect =
424 SkIRect::MakeXYWH(first_output.x(), first_output.y(), 20, 20);
425 ASSERT_TRUE(SkIRect::Intersects(packer_area, first_rect));
426
427 // Initial area was 200 x 100 = 20_000
428 // We added 20x20 = 400. 400 / 20_000 == 0.02 == 2%
429 ASSERT_TRUE(flutter::testing::NumberNear(packer->PercentFull(), 0.02));
430
431 IPoint16 second_output = {-1, -1};
432 ASSERT_TRUE(packer->AddRect(140, 90, &second_output));
433 const SkIRect second_rect =
434 SkIRect::MakeXYWH(second_output.x(), second_output.y(), 140, 90);
435 // Make sure the rectangle is placed such that it is inside the bounds of
436 // the packer's area but not in the are of the first rectangle.
437 ASSERT_TRUE(SkIRect::Intersects(packer_area, second_rect));
438 ASSERT_FALSE(SkIRect::Intersects(first_rect, second_rect));
439
440 // We added another 90 x 140 = 12_600 units, now taking us to 13_000
441 // 13_000 / 20_000 == 0.65 == 65%
442 ASSERT_TRUE(flutter::testing::NumberNear(packer->PercentFull(), 0.65));
443
444 // There's enough area to add this rectangle, but no space big enough for
445 // the 50 units of width.
446 IPoint16 output;
447 ASSERT_FALSE(packer->AddRect(50, 50, &output));
448 // Should be unchanged.
449 ASSERT_TRUE(flutter::testing::NumberNear(packer->PercentFull(), 0.65));
450
451 packer->Reset();
452 // Should be empty now.
453 ASSERT_EQ(packer->PercentFull(), 0);
454}
bool NumberNear(double a, double b)
Definition assertions.h:12

References impeller::RectanglePacker::Factory(), flutter::testing::NumberNear(), impeller::IPoint16::x(), and impeller::IPoint16::y().

◆ toColor()

flutter::DlColor impeller::testing::toColor ( const float *  components)

Definition at line 40 of file dl_unittests.cc.

40 {
41 return flutter::DlColor(Color::ToIColor(
42 Color(components[0], components[1], components[2], components[3])));
43}

References impeller::Color::ToIColor().

Referenced by TEST_P().

Variable Documentation

◆ g_extensions

std::vector<const char*> impeller::testing::g_extensions
static

◆ g_extensions_string

std::string impeller::testing::g_extensions_string
static

◆ g_mock_gles

std::weak_ptr<MockGLES> impeller::testing::g_mock_gles
static

◆ g_test_lock

std::mutex impeller::testing::g_test_lock
static

◆ g_version

const char* impeller::testing::g_version
static

◆ golden_cubic_and_quad_points

std::vector<Point> impeller::testing::golden_cubic_and_quad_points

Definition at line 15 of file golden_paths.h.

15 {
16 {139.982, 19.5003}, {140.018, 20.4997}, {131.747, 19.8026},
17 {131.783, 20.802}, {131.715, 19.8048}, {131.815, 20.7998},
18 {123.622, 20.6102}, {123.721, 21.6053}, {123.59, 20.6145},
19 {123.753, 21.601}, {115.652, 21.9306}, {115.816, 22.9171},
20 {115.619, 21.9372}, {115.848, 22.9105}, {107.85, 23.7687},
21 {108.08, 24.742}, {107.817, 23.7777}, {108.113, 24.733},
22 {100.23, 26.1264}, {100.526, 27.0817}, {100.197, 26.1378},
23 {100.558, 27.0703}, {92.8037, 29.0025}, {93.165, 29.935},
24 {92.7736, 29.0154}, {93.1952, 29.9221}, {85.708, 32.3003},
25 {86.1296, 33.2071}, {85.68, 32.3144}, {86.1576, 33.193},
26 {78.8865, 36.008}, {79.3641, 36.8865}, {78.8588, 36.0242},
27 {79.3918, 36.8703}, {72.3485, 40.125}, {72.8815, 40.9711},
28 {72.3216, 40.1432}, {72.9084, 40.9529}, {66.1045, 44.6479},
29 {66.6913, 45.4577}, {66.0788, 44.6679}, {66.717, 45.4378},
30 {60.1632, 49.5711}, {60.8014, 50.341}, {60.139, 49.5924},
31 {60.8255, 50.3196}, {54.5317, 54.8864}, {55.2183, 55.6136},
32 {54.5094, 54.909}, {55.2406, 55.591}, {49.254, 60.5436},
33 {49.9853, 61.2257}, {49.2329, 60.5677}, {50.0063, 61.2016},
34 {44.3684, 66.5025}, {45.1418, 67.1364}, {44.3488, 66.5281},
35 {45.1614, 67.1108}, {39.8827, 72.7564}, {40.6954, 73.3391},
36 {39.8648, 72.7832}, {40.7133, 73.3123}, {35.8029, 79.297},
37 {36.6515, 79.8261}, {35.7869, 79.3246}, {36.6675, 79.7985},
38 {32.1328, 86.1144}, {33.0134, 86.5883}, {32.1188, 86.1424},
39 {33.0273, 86.5603}, {28.8739, 93.1973}, {29.7824, 93.6152},
40 {28.8613, 93.2272}, {29.795, 93.5853}, {26.0399, 100.583},
41 {26.9736, 100.941}, {26.0288, 100.615}, {26.9847, 100.908},
42 {23.7144, 108.15}, {24.6704, 108.444}, {23.7056, 108.183},
43 {24.6792, 108.411}, {21.9002, 115.886}, {22.8738, 116.115},
44 {21.8937, 115.919}, {22.8804, 116.082}, {20.5962, 123.779},
45 {21.5828, 123.942}, {20.592, 123.812}, {21.5871, 123.91},
46 {19.7985, 131.816}, {20.7936, 131.914}, {19.7964, 131.847},
47 {20.7957, 131.883}, {19.5003, 139.982}, {20.4997, 140.018},
48 {20.2883, 140.409}, {19.7117, 139.591}, {29.9421, 133.595},
49 {29.3655, 132.778}, {29.9544, 133.586}, {29.3532, 132.787},
50 {39.1905, 126.639}, {38.5894, 125.839}, {39.2039, 126.628},
51 {38.576, 125.85}, {47.9822, 119.545}, {47.3542, 118.767},
52 {47.9968, 119.533}, {47.3396, 118.779}, {56.2739, 112.316},
53 {55.6167, 111.562}, {56.2898, 112.302}, {55.6008, 111.577},
54 {64.0197, 104.952}, {63.3307, 104.228}, {64.0369, 104.935},
55 {63.3134, 104.245}, {71.1714, 97.4578}, {70.4479, 96.7675},
56 {71.1899, 97.4373}, {70.4294, 96.7879}, {77.6791, 89.8381},
57 {76.9187, 89.1887}, {77.6987, 89.8137}, {76.8991, 89.2131},
58 {83.4923, 82.1009}, {82.6928, 81.5003}, {83.5125, 82.0718},
59 {82.6725, 81.5293}, {88.5609, 74.2563}, {87.7209, 73.7138},
60 {88.5812, 74.2221}, {87.7007, 73.748}, {92.8369, 66.3173},
61 {91.9564, 65.8432}, {92.8562, 66.2772}, {91.9371, 65.8833},
62 {96.2756, 58.299}, {95.3564, 57.9051}, {96.2927, 58.253},
63 {95.3393, 57.951}, {98.8374, 50.2196}, {97.8841, 49.9176},
64 {98.8508, 50.1681}, {97.8708, 49.969}, {100.49, 42.0995},
65 {99.51, 41.9005}, {100.49, 42.0995}, {99.51, 41.9005},
66};

◆ kExtensions

auto const impeller::testing::kExtensions
Initial value:
= std::vector<const char*>{
"GL_KHR_debug"
}

Definition at line 38 of file mock_gles.cc.

38 {
39 "GL_KHR_debug" //
40};

Referenced by impeller::testing::MockGLES::Init(), and impeller::testing::MockGLES::Init().

◆ kFontFixture

constexpr std::string_view impeller::testing::kFontFixture
staticconstexpr
Initial value:
=
"NotoColorEmoji.ttf"

Definition at line 378 of file aiks_dl_text_unittests.cc.

Referenced by TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), TEST_P(), and TEST_P().

◆ kMagicFailingAllocation

constexpr const size_t impeller::testing::kMagicFailingAllocation = 1024000 * 2
staticconstexpr

◆ kMockResolverGLES

const ProcTableGLES::Resolver impeller::testing::kMockResolverGLES

Definition at line 459 of file mock_gles.cc.

459 {
460 if (strcmp(name, "glPopDebugGroupKHR") == 0) {
461 return reinterpret_cast<void*>(&mockPopDebugGroupKHR);
462 } else if (strcmp(name, "glPushDebugGroupKHR") == 0) {
463 return reinterpret_cast<void*>(&mockPushDebugGroupKHR);
464 } else if (strcmp(name, "glGetString") == 0) {
465 return reinterpret_cast<void*>(&mockGetString);
466 } else if (strcmp(name, "glGetStringi") == 0) {
467 return reinterpret_cast<void*>(&mockGetStringi);
468 } else if (strcmp(name, "glGetIntegerv") == 0) {
469 return reinterpret_cast<void*>(&mockGetIntegerv);
470 } else if (strcmp(name, "glGetError") == 0) {
471 return reinterpret_cast<void*>(&mockGetError);
472 } else if (strcmp(name, "glGenQueriesEXT") == 0) {
473 return reinterpret_cast<void*>(&mockGenQueriesEXT);
474 } else if (strcmp(name, "glBeginQueryEXT") == 0) {
475 return reinterpret_cast<void*>(&mockBeginQueryEXT);
476 } else if (strcmp(name, "glEndQueryEXT") == 0) {
477 return reinterpret_cast<void*>(&mockEndQueryEXT);
478 } else if (strcmp(name, "glDeleteQueriesEXT") == 0) {
479 return reinterpret_cast<void*>(&mockDeleteQueriesEXT);
480 } else if (strcmp(name, "glDeleteTextures") == 0) {
481 return reinterpret_cast<void*>(&mockDeleteTextures);
482 } else if (strcmp(name, "glGetQueryObjectui64vEXT") == 0) {
483 return reinterpret_cast<void*>(mockGetQueryObjectui64vEXT);
484 } else if (strcmp(name, "glGetQueryObjectuivEXT") == 0) {
485 return reinterpret_cast<void*>(mockGetQueryObjectuivEXT);
486 } else if (strcmp(name, "glUniform1fv") == 0) {
487 return reinterpret_cast<void*>(mockUniform1fv);
488 } else if (strcmp(name, "glUniform2fv") == 0) {
489 return reinterpret_cast<void*>(mockUniform2fv);
490 } else if (strcmp(name, "glUniform3fv") == 0) {
491 return reinterpret_cast<void*>(mockUniform3fv);
492 } else if (strcmp(name, "glUniform4fv") == 0) {
493 return reinterpret_cast<void*>(mockUniform4fv);
494 } else if (strcmp(name, "glUniformMatrix2fv") == 0) {
495 return reinterpret_cast<void*>(mockUniformMatrix2fv);
496 } else if (strcmp(name, "glUniformMatrix3fv") == 0) {
497 return reinterpret_cast<void*>(mockUniformMatrix3fv);
498 } else if (strcmp(name, "glUniformMatrix4fv") == 0) {
499 return reinterpret_cast<void*>(mockUniformMatrix4fv);
500 } else if (strcmp(name, "glGenTextures") == 0) {
501 return reinterpret_cast<void*>(mockGenTextures);
502 } else if (strcmp(name, "glTexSubImage2D") == 0) {
503 return reinterpret_cast<void*>(mockTexSubImage2D);
504 } else if (strcmp(name, "glTexImage2D") == 0) {
505 return reinterpret_cast<void*>(mockTexImage2D);
506 } else if (strcmp(name, "glBindTexture") == 0) {
507 return reinterpret_cast<void*>(mockBindTexture);
508 } else if (strcmp(name, "glObjectLabelKHR") == 0) {
509 return reinterpret_cast<void*>(mockObjectLabelKHR);
510 } else if (strcmp(name, "glGenBuffers") == 0) {
511 return reinterpret_cast<void*>(mockGenBuffers);
512 } else if (strcmp(name, "glBufferSubData") == 0) {
513 return reinterpret_cast<void*>(mockBufferSubData);
514 } else if (strcmp(name, "glIsTexture") == 0) {
515 return reinterpret_cast<void*>(mockIsTexture);
516 } else if (strcmp(name, "glCheckFramebufferStatus") == 0) {
517 return reinterpret_cast<void*>(mockCheckFramebufferStatus);
518 } else if (strcmp(name, "glReadPixels") == 0) {
519 return reinterpret_cast<void*>(mockReadPixels);
520 } else if (strcmp(name, "glGenFramebuffers") == 0) {
521 return reinterpret_cast<void*>(mockGenFramebuffers);
522 } else if (strcmp(name, "glBindFramebuffer") == 0) {
523 return reinterpret_cast<void*>(mockBindFramebuffer);
524 } else if (strcmp(name, "glDiscardFramebufferEXT") == 0) {
525 return reinterpret_cast<void*>(mockDiscardFramebufferEXT);
526 } else if (strcmp(name, "glInvalidateFramebuffer") == 0) {
527 return reinterpret_cast<void*>(mockInvalidateFramebuffer);
528 } else if (strcmp(name, "glViewport") == 0) {
529 return reinterpret_cast<void*>(mockViewport);
530 } else if (strcmp(name, "glDrawArrays") == 0) {
531 return reinterpret_cast<void*>(mockDrawArrays);
532 } else if (strcmp(name, "glDrawElements") == 0) {
533 return reinterpret_cast<void*>(mockDrawElements);
534 } else if (strcmp(name, "glDrawArraysInstanced") == 0) {
535 return reinterpret_cast<void*>(mockDrawArraysInstanced);
536 } else if (strcmp(name, "glDrawElementsInstanced") == 0) {
537 return reinterpret_cast<void*>(mockDrawElementsInstanced);
538 } else if (strcmp(name, "glVertexAttribDivisor") == 0) {
539 return reinterpret_cast<void*>(mockVertexAttribDivisor);
540 } else {
541 return reinterpret_cast<void*>(&doNothing);
542 }
543};
void mockDeleteQueriesEXT(GLsizei size, const GLuint *queries)
Definition mock_gles.cc:173
void mockGetQueryObjectuivEXT(GLuint id, GLenum target, GLuint *result)
Definition mock_gles.cc:159
GLenum mockGetError()
Definition mock_gles.cc:118
void mockDiscardFramebufferEXT(GLenum target, GLsizei numAttachments, const GLenum *attachments)
Definition mock_gles.cc:345
void mockPopDebugGroupKHR()
Definition mock_gles.cc:125
const unsigned char * mockGetStringi(GLenum name, GLuint index)
Definition mock_gles.cc:83
void mockUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
Definition mock_gles.cc:216
void mockGetIntegerv(GLenum name, int *value)
Definition mock_gles.cc:95
void mockGetQueryObjectui64vEXT(GLuint id, GLenum target, GLuint64 *result)
Definition mock_gles.cc:166
GLboolean mockIsTexture(GLuint texture)
Definition mock_gles.cc:306
void mockDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instancecount)
Definition mock_gles.cc:386
void mockReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data)
Definition mock_gles.cc:334
void mockUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
Definition mock_gles.cc:226
void mockTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)
Definition mock_gles.cc:285
void mockDrawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
Definition mock_gles.cc:376
void mockUniform4fv(GLint location, GLsizei count, const GLfloat *value)
Definition mock_gles.cc:200
void mockTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels)
Definition mock_gles.cc:270
void mockDeleteTextures(GLsizei size, const GLuint *queries)
Definition mock_gles.cc:177
void mockUniform2fv(GLint location, GLsizei count, const GLfloat *value)
Definition mock_gles.cc:188
GLenum mockCheckFramebufferStatus(GLenum target)
Definition mock_gles.cc:313
void mockUniform1fv(GLint location, GLsizei count, const GLfloat *value)
Definition mock_gles.cc:184
void mockObjectLabelKHR(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
Definition mock_gles.cc:260
void mockBindTexture(GLenum target, GLuint texture)
Definition mock_gles.cc:300
void mockDrawArrays(GLenum mode, GLint first, GLsizei count)
Definition mock_gles.cc:369
void mockUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
Definition mock_gles.cc:206
void mockUniform3fv(GLint location, GLsizei count, const GLfloat *value)
Definition mock_gles.cc:194
void mockBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Definition mock_gles.cc:247
void mockBindFramebuffer(GLenum target, GLuint framebuffer)
Definition mock_gles.cc:327
void mockEndQueryEXT(GLuint id)
Definition mock_gles.cc:152
void mockDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount)
Definition mock_gles.cc:397
void mockGenBuffers(GLsizei n, GLuint *buffers)
Definition mock_gles.cc:243
void mockInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
Definition mock_gles.cc:359
void mockGenFramebuffers(GLsizei n, GLuint *ids)
Definition mock_gles.cc:320
void mockGenQueriesEXT(GLsizei n, GLuint *ids)
Definition mock_gles.cc:138
void mockBeginQueryEXT(GLenum target, GLuint id)
Definition mock_gles.cc:145
void mockViewport(GLint x, GLint y, GLsizei width, GLsizei height)
Definition mock_gles.cc:352
void mockGenTextures(GLsizei n, GLuint *textures)
Definition mock_gles.cc:236
void mockVertexAttribDivisor(GLuint index, GLuint divisor)
Definition mock_gles.cc:409

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ kMockResolverGLESWithoutInstancing

const ProcTableGLES::Resolver impeller::testing::kMockResolverGLESWithoutInstancing
Initial value:
=
[](const char* name) -> void* {
if (strcmp(name, "glDrawArraysInstancedEXT") == 0 ||
strcmp(name, "glDrawArraysInstanced") == 0 ||
strcmp(name, "glDrawElementsInstancedEXT") == 0 ||
strcmp(name, "glDrawElementsInstanced") == 0 ||
strcmp(name, "glVertexAttribDivisorEXT") == 0 ||
strcmp(name, "glVertexAttribDivisor") == 0) {
return nullptr;
}
}

A resolver that behaves like |kMockResolverGLES| but hides the hardware instancing entry points, so the OpenGL ES backend exercises its instanced-draw emulation fallback.

Definition at line 545 of file mock_gles.cc.

546 {
547 // Hide the hardware instancing entry points so the OpenGL ES backend takes
548 // its emulation path. The proc table retries these names with the "EXT"
549 // suffix stripped, so both spellings are rejected here.
550 if (strcmp(name, "glDrawArraysInstancedEXT") == 0 ||
551 strcmp(name, "glDrawArraysInstanced") == 0 ||
552 strcmp(name, "glDrawElementsInstancedEXT") == 0 ||
553 strcmp(name, "glDrawElementsInstanced") == 0 ||
554 strcmp(name, "glVertexAttribDivisorEXT") == 0 ||
555 strcmp(name, "glVertexAttribDivisor") == 0) {
556 return nullptr;
557 }
558 return kMockResolverGLES(name);
559};

Referenced by TEST_F(), and TEST_F().

◆ kMockShadingLanguageVersion

const auto impeller::testing::kMockShadingLanguageVersion = "GLSL ES 1.0"

Definition at line 37 of file mock_gles.cc.

Referenced by mockGetString().

◆ kMockVendor

auto const impeller::testing::kMockVendor = "MockGLES"

Definition at line 36 of file mock_gles.cc.

Referenced by mockGetString().

◆ kPaintVariations

const std::map<std::string, MaskBlurTestConfig> impeller::testing::kPaintVariations
static

Definition at line 685 of file aiks_dl_blur_unittests.cc.

685 {
686 // 1. Normal style, translucent, zero sigma.
687 {"NormalTranslucentZeroSigma",
688 {.style = DlBlurStyle::kNormal, .sigma = 0.0f, .alpha = 0.5f}},
689 // 2. Normal style, translucent.
690 {"NormalTranslucent",
691 {.style = DlBlurStyle::kNormal, .sigma = 8.0f, .alpha = 0.5f}},
692 // 3. Solid style, translucent.
693 {"SolidTranslucent",
694 {.style = DlBlurStyle::kSolid, .sigma = 8.0f, .alpha = 0.5f}},
695 // 4. Solid style, opaque.
696 {"SolidOpaque", {.style = DlBlurStyle::kSolid, .sigma = 8.0f}},
697 // 5. Solid style, translucent, color & image filtered.
698 {"SolidTranslucentWithFilters",
699 {.style = DlBlurStyle::kSolid,
700 .sigma = 8.0f,
701 .alpha = 0.5f,
702 .image_filter = DlImageFilter::MakeBlur(3, 3, DlTileMode::kClamp),
703 .invert_colors = true}},
704 // 6. Solid style, translucent, exclusion blended.
705 {"SolidTranslucentExclusionBlend",
706 {.style = DlBlurStyle::kSolid,
707 .sigma = 8.0f,
708 .alpha = 0.5f,
709 .blend_mode = DlBlendMode::kExclusion}},
710 // 7. Inner style, translucent.
711 {"InnerTranslucent",
712 {.style = DlBlurStyle::kInner, .sigma = 8.0f, .alpha = 0.5f}},
713 // 8. Inner style, translucent, blurred.
714 {"InnerTranslucentWithBlurImageFilter",
715 {.style = DlBlurStyle::kInner,
716 .sigma = 8.0f,
717 .alpha = 0.5f,
718 .image_filter = DlImageFilter::MakeBlur(3, 3, DlTileMode::kClamp)}},
719 // 9. Outer style, translucent.
720 {"OuterTranslucent",
721 {.style = DlBlurStyle::kOuter, .sigma = 8.0f, .alpha = 0.5f}},
722 // 10. Outer style, opaque, image filtered.
723 {"OuterOpaqueWithBlurImageFilter",
724 {.style = DlBlurStyle::kOuter,
725 .sigma = 8.0f,
726 .image_filter = DlImageFilter::MakeBlur(3, 3, DlTileMode::kClamp)}}};