From 153abc940342202777e48367ba3d7946e74d7f7e Mon Sep 17 00:00:00 2001 From: Dom Chen Date: Wed, 16 Feb 2022 17:31:59 +0800 Subject: [PATCH] Rename the namespace of the 2d rendering engine to tgfx. (#114) --- .idea/misc.xml | 7 +- CMakeLists.txt | 1 + include/pag/pag.h | 44 +- include/pag/types.h | 73 +- src/base/ByteData.cpp | 2 +- src/base/Matrix.cpp | 371 ++------- src/base/Rect.cpp | 101 +-- src/base/effects/BulgeEffect.cpp | 15 +- src/base/layerStyles/DropShadowStyle.cpp | 2 +- src/base/utils/Log.h | 12 +- .../TGFXTypes.h => base/utils/MathUtil.h} | 19 +- src/base/utils/MatrixUtil.cpp | 10 +- src/base/utils/MatrixUtil.h | 9 +- src/base/utils/TGFXCast.cpp | 144 ++++ src/base/utils/TGFXCast.h | 139 ++++ src/platform/Platform.cpp | 2 +- src/platform/Platform.h | 5 +- src/platform/android/GPUDrawable.cpp | 8 +- src/platform/android/GPUDrawable.h | 8 +- src/platform/android/JNIEnvironment.cpp | 2 +- src/platform/android/JNIHelper.cpp | 20 +- src/platform/android/JNIHelper.h | 2 +- src/platform/android/JPAGImage.cpp | 5 +- src/platform/android/JTraceImage.cpp | 8 +- src/platform/android/JTraceImage.h | 2 +- src/platform/android/NativePlatform.cpp | 2 +- src/platform/android/NativePlatform.h | 3 +- src/platform/android/VideoImage.cpp | 2 +- src/platform/android/VideoImage.h | 2 +- src/platform/android/VideoSurface.cpp | 20 +- src/platform/android/VideoSurface.h | 12 +- src/platform/cocoa/private/CocoaPlatform.h | 3 +- src/platform/cocoa/private/CocoaPlatform.mm | 2 +- src/platform/cocoa/private/PAGImageImpl.mm | 6 +- src/platform/cocoa/private/TraceImage.h | 2 +- src/platform/cocoa/private/TraceImage.mm | 8 +- src/platform/ios/private/GPUDecoder.h | 6 +- src/platform/ios/private/GPUDecoder.mm | 6 +- src/platform/ios/private/GPUDrawable.h | 10 +- src/platform/ios/private/GPUDrawable.mm | 12 +- src/platform/ios/private/VideoImage.h | 14 +- src/platform/ios/private/VideoImage.mm | 8 +- src/platform/mac/private/GPUDecoder.h | 2 +- src/platform/mac/private/GPUDecoder.mm | 2 +- src/platform/mac/private/GPUDrawable.h | 8 +- src/platform/mac/private/GPUDrawable.mm | 12 +- src/platform/mac/private/VideoImage.h | 4 +- src/platform/qt/GPUDrawable.cpp | 10 +- src/platform/qt/GPUDrawable.h | 14 +- src/platform/swiftshader/NativePlatform.cpp | 4 +- src/platform/swiftshader/NativePlatform.h | 3 +- src/platform/web/GPUDrawable.cpp | 6 +- src/platform/web/GPUDrawable.h | 10 +- src/platform/web/NativePlatform.cpp | 2 +- src/platform/web/NativePlatform.h | 3 +- src/platform/web/VideoSequenceReader.cpp | 9 +- src/platform/web/VideoSequenceReader.h | 4 +- src/platform/win/GPUDrawable.cpp | 10 +- src/platform/win/GPUDrawable.h | 12 +- src/rendering/Drawable.cpp | 25 +- src/rendering/Drawable.h | 42 +- src/rendering/FontManager.cpp | 44 +- src/rendering/FontManager.h | 27 +- src/rendering/GPUBackend.cpp | 136 ++++ src/rendering/PAGPlayer.cpp | 9 +- src/rendering/PAGSurface.cpp | 28 +- src/rendering/caches/GraphicContent.cpp | 2 +- src/rendering/caches/GraphicContent.h | 2 +- src/rendering/caches/ImageContentCache.cpp | 10 +- src/rendering/caches/ImageContentCache.h | 2 +- src/rendering/caches/LayerCache.cpp | 7 +- src/rendering/caches/LayerCache.h | 7 +- src/rendering/caches/MaskCache.cpp | 6 +- src/rendering/caches/MaskCache.h | 4 +- src/rendering/caches/RenderCache.cpp | 16 +- src/rendering/caches/RenderCache.h | 10 +- src/rendering/caches/SolidContentCache.cpp | 6 +- src/rendering/editing/ImageReplacement.cpp | 12 +- src/rendering/editing/ImageReplacement.h | 4 +- src/rendering/editing/StillImage.cpp | 30 +- src/rendering/editing/StillImage.h | 13 +- src/rendering/filters/BulgeFilter.cpp | 11 +- src/rendering/filters/BulgeFilter.h | 11 +- src/rendering/filters/CornerPinFilter.cpp | 43 +- src/rendering/filters/CornerPinFilter.h | 9 +- .../filters/DisplacementMapFilter.cpp | 17 +- src/rendering/filters/DisplacementMapFilter.h | 12 +- src/rendering/filters/Filter.h | 9 +- src/rendering/filters/FilterModifier.cpp | 6 +- src/rendering/filters/FilterModifier.h | 6 +- src/rendering/filters/LayerFilter.cpp | 84 ++- src/rendering/filters/LayerFilter.h | 43 +- src/rendering/filters/LayerStylesFilter.cpp | 13 +- src/rendering/filters/LayerStylesFilter.h | 17 +- .../filters/LevelsIndividualFilter.cpp | 6 +- .../filters/LevelsIndividualFilter.h | 6 +- src/rendering/filters/MosaicFilter.cpp | 6 +- src/rendering/filters/MosaicFilter.h | 6 +- src/rendering/filters/MotionBlurFilter.cpp | 23 +- src/rendering/filters/MotionBlurFilter.h | 17 +- src/rendering/filters/MotionTileFilter.cpp | 7 +- src/rendering/filters/MotionTileFilter.h | 6 +- src/rendering/filters/RadialBlurFilter.cpp | 7 +- src/rendering/filters/RadialBlurFilter.h | 6 +- .../filters/dropshadow/DropShadowFilter.cpp | 65 +- .../filters/dropshadow/DropShadowFilter.h | 34 +- .../dropshadow/DropShadowSpreadFilter.cpp | 36 +- .../dropshadow/DropShadowSpreadFilter.h | 11 +- .../filters/gaussblur/GaussBlurFilter.cpp | 21 +- .../filters/gaussblur/GaussBlurFilter.h | 11 +- .../gaussblur/SinglePassBlurFilter.cpp | 37 +- .../filters/gaussblur/SinglePassBlurFilter.h | 15 +- src/rendering/filters/glow/GlowBlurFilter.cpp | 6 +- src/rendering/filters/glow/GlowBlurFilter.h | 6 +- src/rendering/filters/glow/GlowFilter.cpp | 17 +- src/rendering/filters/glow/GlowFilter.h | 11 +- .../filters/glow/GlowMergeFilter.cpp | 8 +- src/rendering/filters/glow/GlowMergeFilter.h | 6 +- src/rendering/filters/utils/FilterBuffer.cpp | 28 +- src/rendering/filters/utils/FilterBuffer.h | 19 +- src/rendering/filters/utils/FilterHelper.cpp | 35 +- src/rendering/filters/utils/FilterHelper.h | 18 +- src/rendering/graphics/Glyph.cpp | 14 +- src/rendering/graphics/Glyph.h | 29 +- src/rendering/graphics/Graphic.cpp | 64 +- src/rendering/graphics/Graphic.h | 14 +- src/rendering/graphics/Modifier.cpp | 78 +- src/rendering/graphics/Modifier.h | 17 +- src/rendering/graphics/Picture.cpp | 108 +-- src/rendering/graphics/Picture.h | 10 +- src/rendering/graphics/Recorder.cpp | 28 +- src/rendering/graphics/Recorder.h | 14 +- src/rendering/graphics/Shape.cpp | 32 +- src/rendering/graphics/Shape.h | 16 +- src/rendering/graphics/Snapshot.cpp | 6 +- src/rendering/graphics/Snapshot.h | 12 +- src/rendering/graphics/Text.cpp | 74 +- src/rendering/graphics/Text.h | 24 +- src/rendering/graphics/TextureProxy.h | 2 +- src/rendering/layers/PAGComposition.cpp | 28 +- src/rendering/layers/PAGImageLayer.cpp | 2 +- src/rendering/layers/PAGLayer.cpp | 10 +- src/rendering/layers/PAGSolidLayer.cpp | 6 +- src/rendering/layers/PAGStage.cpp | 8 +- src/rendering/layers/PAGStage.h | 4 +- .../readers/BitmapSequenceReader.cpp | 15 +- src/rendering/readers/BitmapSequenceReader.h | 6 +- src/rendering/readers/SequenceReader.h | 2 +- .../renderers/CompositionRenderer.cpp | 8 +- src/rendering/renderers/FilterRenderer.cpp | 97 +-- src/rendering/renderers/FilterRenderer.h | 29 +- src/rendering/renderers/LayerRenderer.cpp | 14 +- src/rendering/renderers/LayerRenderer.h | 4 +- src/rendering/renderers/MaskRenderer.cpp | 22 +- src/rendering/renderers/MaskRenderer.h | 2 +- src/rendering/renderers/ShapeRenderer.cpp | 179 ++--- src/rendering/renderers/ShapeRenderer.h | 1 + .../renderers/TextAnimatorRenderer.cpp | 17 +- .../renderers/TextAnimatorRenderer.h | 16 +- src/rendering/renderers/TextRenderer.cpp | 59 +- .../renderers/TrackMatteRenderer.cpp | 4 +- src/rendering/renderers/TransformRenderer.cpp | 2 +- src/rendering/renderers/TransformRenderer.h | 1 + src/rendering/utils/MemoryCalculator.cpp | 23 +- src/rendering/utils/MemoryCalculator.h | 21 +- src/rendering/utils/PathUtil.cpp | 4 +- src/rendering/utils/PathUtil.h | 2 +- src/rendering/utils/SurfaceUtil.cpp | 11 +- src/rendering/utils/SurfaceUtil.h | 7 +- src/rendering/utils/TGFXTypes.cpp | 84 --- src/rendering/utils/Trace.cpp | 54 ++ .../UTF8Text.cpp => rendering/utils/Trace.h} | 51 +- src/rendering/utils/Transform.h | 6 +- src/video/I420Buffer.cpp | 8 +- src/video/I420Buffer.h | 8 +- src/video/SoftwareDecoderWrapper.cpp | 7 +- src/video/VideoBuffer.h | 4 +- src/video/VideoDecoder.h | 4 +- src/video/VideoSequenceReader.cpp | 5 +- src/video/VideoSequenceReader.h | 4 +- test/GLUtilTest.cpp | 2 + test/PAGBlendTest.cpp | 44 +- test/PAGCompareFrameTest.cpp | 1 + test/PAGImageTest.cpp | 7 +- test/PAGPlayerTest.cpp | 11 +- test/PAGRasterizerTest.cpp | 7 +- test/PAGReadPixelsTest.cpp | 59 +- test/PAGSurfaceTest.cpp | 21 +- test/framework/utils/Baseline.cpp | 9 +- test/framework/utils/Baseline.h | 5 +- test/framework/utils/LzmaUtil.cpp | 12 +- test/framework/utils/LzmaUtil.h | 4 +- test/framework/utils/PAGTestUtils.cpp | 4 +- test/framework/utils/PAGTestUtils.h | 3 +- tgfx/include/core/Bitmap.h | 9 +- tgfx/include/core/{Blend.h => BlendMode.h} | 6 +- .../core/utils => include/core}/BytesKey.h | 4 +- tgfx/include/core/{Color4f.h => Color.h} | 27 +- tgfx/include/core/Data.h | 4 +- tgfx/include/core/EncodedFormat.h | 4 +- tgfx/include/core/Font.h | 4 +- tgfx/include/core/FontMetrics.h | 4 +- tgfx/include/core/Image.h | 4 +- tgfx/include/core/ImageInfo.h | 57 +- tgfx/include/core/ImageOrigin.h | 39 + tgfx/include/core/Mask.h | 4 +- tgfx/include/core/Matrix.h | 707 ++++++++++++++++++ tgfx/include/core/Orientation.h | 6 +- tgfx/include/core/Path.h | 6 +- tgfx/include/core/PathEffect.h | 4 +- tgfx/include/core/PathMeasure.h | 4 +- tgfx/include/core/PathTypes.h | 7 +- tgfx/include/core/Performance.h | 31 + tgfx/include/core/PixelBuffer.h | 9 +- tgfx/include/core/Point.h | 126 ++++ tgfx/include/core/RGBAAALayout.h | 4 +- tgfx/include/core/Rect.h | 452 +++++++++++ tgfx/include/core/Stream.h | 5 +- tgfx/include/core/Stroke.h | 82 +- tgfx/include/core/TextBlob.h | 4 +- tgfx/include/core/Typeface.h | 6 +- tgfx/include/core/UTF.h | 41 + tgfx/include/core/YUVInfo.h | 4 +- tgfx/include/gpu/Backend.h | 212 ++++++ tgfx/include/gpu/Canvas.h | 12 +- tgfx/include/gpu/Context.h | 10 +- tgfx/include/gpu/Device.h | 7 +- tgfx/include/gpu/Paint.h | 21 +- tgfx/include/gpu/Resource.h | 14 +- tgfx/include/gpu/Shader.h | 14 +- tgfx/include/gpu/Surface.h | 6 +- tgfx/include/gpu/Texture.h | 14 +- tgfx/include/gpu/TextureBuffer.h | 4 +- tgfx/include/gpu/Window.h | 4 +- tgfx/include/gpu/YUVTexture.h | 4 +- tgfx/include/gpu/metal/MtlTypes.h | 32 + tgfx/include/gpu/opengl/GLDevice.h | 4 +- tgfx/include/gpu/opengl/GLTypes.h | 54 ++ tgfx/include/gpu/opengl/cgl/CGLDevice.h | 4 +- tgfx/include/gpu/opengl/cgl/CGLWindow.h | 4 +- tgfx/include/gpu/opengl/eagl/EAGLDevice.h | 4 +- tgfx/include/gpu/opengl/eagl/EAGLWindow.h | 4 +- tgfx/include/gpu/opengl/egl/EGLDevice.h | 4 +- tgfx/include/gpu/opengl/egl/EGLWindow.h | 4 +- tgfx/include/gpu/opengl/qt/QGLDevice.h | 4 +- tgfx/include/gpu/opengl/qt/QGLWindow.h | 4 +- tgfx/include/gpu/opengl/webgl/WebGLDevice.h | 4 +- tgfx/include/gpu/opengl/webgl/WebGLWindow.h | 4 +- tgfx/include/platform/Print.h | 4 +- tgfx/include/platform/android/SetJavaVM.h | 4 +- tgfx/src/core/Bitmap.cpp | 11 +- tgfx/src/core/{utils => }/BytesKey.cpp | 6 +- tgfx/src/core/Color.cpp | 39 +- tgfx/src/core/Data.cpp | 4 +- tgfx/src/core/Font.cpp | 4 +- tgfx/src/core/Image.cpp | 4 +- tgfx/src/core/ImageInfo.cpp | 4 +- tgfx/src/core/Mask.cpp | 4 +- tgfx/src/core/Matrix.cpp | 475 ++++++++++++ tgfx/src/core/Orientation.cpp | 4 +- tgfx/src/core/Path.cpp | 6 +- tgfx/src/core/PathEffect.cpp | 16 +- tgfx/src/core/PathMeasure.cpp | 4 +- tgfx/src/core/PathRef.cpp | 4 +- tgfx/src/core/PathRef.h | 4 +- tgfx/src/core/Performance.cpp | 28 + tgfx/src/core/PixelBuffer.cpp | 9 +- tgfx/src/core/Rect.cpp | 103 +++ tgfx/src/core/Stream.cpp | 4 +- tgfx/src/core/TextBlob.cpp | 4 +- tgfx/src/core/UTF.cpp | 110 +++ tgfx/src/core/images/jpeg/JpegImage.cpp | 4 +- tgfx/src/core/images/jpeg/JpegImage.h | 4 +- tgfx/src/core/images/png/PngImage.cpp | 4 +- tgfx/src/core/images/png/PngImage.h | 4 +- tgfx/src/core/images/webp/WebpImage.cpp | 8 +- tgfx/src/core/images/webp/WebpImage.h | 4 +- tgfx/src/core/images/webp/WebpUtility.cpp | 6 +- tgfx/src/core/images/webp/WebpUtility.h | 5 +- tgfx/src/core/utils/EnumHasher.h | 32 + tgfx/src/core/utils/Log.h | 57 ++ {src/base => tgfx/src/core}/utils/MathExtra.h | 13 +- tgfx/src/core/utils/OrientationHelper.h | 4 +- tgfx/src/core/utils/UniqueID.cpp | 28 + .../src/core/utils/UniqueID.h | 13 +- tgfx/src/core/vectors/coregraphics/CGMask.cpp | 4 +- tgfx/src/core/vectors/coregraphics/CGMask.h | 4 +- .../vectors/coregraphics/CGScalerContext.cpp | 12 +- .../vectors/coregraphics/CGScalerContext.h | 4 +- .../core/vectors/coregraphics/CGTextBlob.cpp | 4 +- .../core/vectors/coregraphics/CGTextBlob.h | 4 +- .../core/vectors/coregraphics/CGTypeface.cpp | 10 +- .../core/vectors/coregraphics/CGTypeface.h | 8 +- tgfx/src/core/vectors/freetype/FTFace.cpp | 6 +- tgfx/src/core/vectors/freetype/FTFace.h | 7 +- tgfx/src/core/vectors/freetype/FTFontData.h | 10 +- tgfx/src/core/vectors/freetype/FTMask.cpp | 4 +- tgfx/src/core/vectors/freetype/FTMask.h | 4 +- tgfx/src/core/vectors/freetype/FTPath.cpp | 4 +- tgfx/src/core/vectors/freetype/FTPath.h | 4 +- .../core/vectors/freetype/FTScalerContext.cpp | 8 +- .../core/vectors/freetype/FTScalerContext.h | 4 +- tgfx/src/core/vectors/freetype/FTTextBlob.cpp | 4 +- tgfx/src/core/vectors/freetype/FTTextBlob.h | 4 +- tgfx/src/core/vectors/freetype/FTTypeface.cpp | 17 +- tgfx/src/core/vectors/freetype/FTTypeface.h | 8 +- tgfx/src/core/vectors/freetype/FTUtil.cpp | 4 +- tgfx/src/core/vectors/freetype/FTUtil.h | 4 +- tgfx/src/core/vectors/web/WebMask.cpp | 4 +- tgfx/src/core/vectors/web/WebMask.h | 4 +- tgfx/src/core/vectors/web/WebTextBlob.cpp | 4 +- tgfx/src/core/vectors/web/WebTextBlob.h | 4 +- tgfx/src/core/vectors/web/WebTypeface.cpp | 6 +- tgfx/src/core/vectors/web/WebTypeface.h | 8 +- tgfx/src/gpu/AAType.h | 2 +- tgfx/src/gpu/AlphaFragmentProcessor.cpp | 6 +- tgfx/src/gpu/AlphaFragmentProcessor.h | 4 +- tgfx/src/gpu/Backend.cpp | 7 +- tgfx/src/gpu/BitmaskOperators.h | 4 +- tgfx/src/gpu/Canvas.cpp | 8 +- tgfx/src/gpu/Caps.h | 4 +- tgfx/src/gpu/ColorShader.cpp | 6 +- tgfx/src/gpu/ColorShader.h | 8 +- tgfx/src/gpu/ConstColorProcessor.cpp | 8 +- tgfx/src/gpu/ConstColorProcessor.h | 12 +- tgfx/src/gpu/Context.cpp | 6 +- tgfx/src/gpu/CoordTransform.h | 6 +- tgfx/src/gpu/Device.cpp | 8 +- tgfx/src/gpu/EllipseGeometryProcessor.cpp | 6 +- tgfx/src/gpu/EllipseGeometryProcessor.h | 4 +- tgfx/src/gpu/EmptyXferProcessor.cpp | 6 +- tgfx/src/gpu/EmptyXferProcessor.h | 4 +- tgfx/src/gpu/FragmentProcessor.cpp | 4 +- tgfx/src/gpu/FragmentProcessor.h | 4 +- tgfx/src/gpu/FragmentShaderBuilder.cpp | 4 +- tgfx/src/gpu/FragmentShaderBuilder.h | 6 +- tgfx/src/gpu/GLFragmentProcessor.cpp | 4 +- tgfx/src/gpu/GLFragmentProcessor.h | 4 +- tgfx/src/gpu/GLGeometryProcessor.cpp | 4 +- tgfx/src/gpu/GLGeometryProcessor.h | 4 +- tgfx/src/gpu/GLXferProcessor.h | 4 +- tgfx/src/gpu/GeometryProcessor.cpp | 4 +- tgfx/src/gpu/GeometryProcessor.h | 5 +- tgfx/src/gpu/GradientCache.cpp | 11 +- tgfx/src/gpu/GradientCache.h | 10 +- tgfx/src/gpu/Paint.cpp | 6 +- tgfx/src/gpu/Pipeline.cpp | 4 +- tgfx/src/gpu/Pipeline.h | 4 +- tgfx/src/gpu/PixelConfig.h | 4 +- tgfx/src/gpu/PorterDuffXferProcessor.cpp | 8 +- tgfx/src/gpu/PorterDuffXferProcessor.h | 14 +- tgfx/src/gpu/Processor.h | 6 +- tgfx/src/gpu/Program.h | 6 +- tgfx/src/gpu/ProgramBuilder.cpp | 4 +- tgfx/src/gpu/ProgramBuilder.h | 4 +- tgfx/src/gpu/ProgramCache.cpp | 4 +- tgfx/src/gpu/ProgramCache.h | 4 +- tgfx/src/gpu/ProgramDataManager.h | 6 +- .../gpu/QuadPerEdgeAAGeometryProcessor.cpp | 6 +- tgfx/src/gpu/QuadPerEdgeAAGeometryProcessor.h | 4 +- tgfx/src/gpu/ResourceCache.cpp | 14 +- tgfx/src/gpu/ResourceCache.h | 4 +- tgfx/src/gpu/ResourceHandle.h | 4 +- tgfx/src/gpu/ShaderBuilder.cpp | 6 +- tgfx/src/gpu/ShaderBuilder.h | 27 +- tgfx/src/gpu/ShaderVar.h | 6 +- tgfx/src/gpu/Surface.cpp | 4 +- tgfx/src/gpu/Swizzle.h | 4 +- tgfx/src/gpu/TextureFragmentProcessor.cpp | 8 +- tgfx/src/gpu/TextureFragmentProcessor.h | 4 +- tgfx/src/gpu/TextureMaskFragmentProcessor.cpp | 6 +- tgfx/src/gpu/TextureMaskFragmentProcessor.h | 4 +- tgfx/src/gpu/TextureSampler.h | 6 +- tgfx/src/gpu/UniformHandler.h | 6 +- tgfx/src/gpu/VaryingHandler.cpp | 4 +- tgfx/src/gpu/VaryingHandler.h | 4 +- tgfx/src/gpu/VertexShaderBuilder.cpp | 4 +- tgfx/src/gpu/VertexShaderBuilder.h | 4 +- tgfx/src/gpu/Window.cpp | 6 +- tgfx/src/gpu/XferProcessor.h | 6 +- tgfx/src/gpu/YUVTextureFragmentProcessor.cpp | 6 +- tgfx/src/gpu/YUVTextureFragmentProcessor.h | 4 +- .../gpu/gradients/ClampedGradientEffect.cpp | 10 +- .../src/gpu/gradients/ClampedGradientEffect.h | 17 +- .../DualIntervalGradientColorizer.cpp | 14 +- .../gradients/DualIntervalGradientColorizer.h | 20 +- tgfx/src/gpu/gradients/GradientShader.cpp | 19 +- tgfx/src/gpu/gradients/GradientShader.h | 13 +- .../gpu/gradients/LinearGradientLayout.cpp | 6 +- tgfx/src/gpu/gradients/LinearGradientLayout.h | 4 +- .../gpu/gradients/RadialGradientLayout.cpp | 6 +- tgfx/src/gpu/gradients/RadialGradientLayout.h | 4 +- .../SingleIntervalGradientColorizer.cpp | 10 +- .../SingleIntervalGradientColorizer.h | 14 +- .../gradients/TextureGradientColorizer.cpp | 6 +- .../gpu/gradients/TextureGradientColorizer.h | 4 +- .../UnrolledBinaryGradientColorizer.cpp | 18 +- .../UnrolledBinaryGradientColorizer.h | 42 +- .../gpu/opengl/GLAlphaFragmentProcessor.cpp | 4 +- .../src/gpu/opengl/GLAlphaFragmentProcessor.h | 4 +- .../gpu/opengl/GLAssembledGLESInterface.cpp | 4 +- .../src/gpu/opengl/GLAssembledGLESInterface.h | 4 +- .../src/gpu/opengl/GLAssembledGLInterface.cpp | 4 +- tgfx/src/gpu/opengl/GLAssembledGLInterface.h | 4 +- .../gpu/opengl/GLAssembledWebGLInterface.cpp | 4 +- .../gpu/opengl/GLAssembledWebGLInterface.h | 4 +- tgfx/src/gpu/opengl/GLBlend.cpp | 76 +- tgfx/src/gpu/opengl/GLBlend.h | 11 +- tgfx/src/gpu/opengl/GLBuffer.cpp | 6 +- tgfx/src/gpu/opengl/GLBuffer.h | 4 +- tgfx/src/gpu/opengl/GLCanvas.cpp | 8 +- tgfx/src/gpu/opengl/GLCanvas.h | 6 +- tgfx/src/gpu/opengl/GLCaps.cpp | 4 +- tgfx/src/gpu/opengl/GLCaps.h | 14 +- .../gpu/opengl/GLClampedGradientEffect.cpp | 4 +- tgfx/src/gpu/opengl/GLClampedGradientEffect.h | 10 +- tgfx/src/gpu/opengl/GLConstColorProcessor.cpp | 4 +- tgfx/src/gpu/opengl/GLConstColorProcessor.h | 8 +- tgfx/src/gpu/opengl/GLContext.cpp | 4 +- tgfx/src/gpu/opengl/GLContext.h | 4 +- tgfx/src/gpu/opengl/GLDevice.cpp | 4 +- tgfx/src/gpu/opengl/GLDrawer.cpp | 6 +- tgfx/src/gpu/opengl/GLDrawer.h | 8 +- .../GLDualIntervalGradientColorizer.cpp | 4 +- .../opengl/GLDualIntervalGradientColorizer.h | 14 +- .../gpu/opengl/GLEllipseGeometryProcessor.cpp | 4 +- .../gpu/opengl/GLEllipseGeometryProcessor.h | 4 +- tgfx/src/gpu/opengl/GLEmptyXferProcessor.cpp | 4 +- tgfx/src/gpu/opengl/GLEmptyXferProcessor.h | 4 +- tgfx/src/gpu/opengl/GLFillRectOp.cpp | 4 +- tgfx/src/gpu/opengl/GLFillRectOp.h | 4 +- .../gpu/opengl/GLFragmentShaderBuilder.cpp | 4 +- tgfx/src/gpu/opengl/GLFragmentShaderBuilder.h | 4 +- tgfx/src/gpu/opengl/GLFunctions.h | 4 +- tgfx/src/gpu/opengl/GLInterface.cpp | 4 +- tgfx/src/gpu/opengl/GLInterface.h | 4 +- .../src/gpu/opengl/GLLinearGradientLayout.cpp | 4 +- tgfx/src/gpu/opengl/GLLinearGradientLayout.h | 4 +- .../gpu/opengl/GLPorterDuffXferProcessor.cpp | 4 +- .../gpu/opengl/GLPorterDuffXferProcessor.h | 4 +- tgfx/src/gpu/opengl/GLProcGetter.h | 4 +- tgfx/src/gpu/opengl/GLProgram.cpp | 12 +- tgfx/src/gpu/opengl/GLProgram.h | 4 +- tgfx/src/gpu/opengl/GLProgramBuilder.cpp | 6 +- tgfx/src/gpu/opengl/GLProgramBuilder.h | 4 +- tgfx/src/gpu/opengl/GLProgramCreator.cpp | 4 +- tgfx/src/gpu/opengl/GLProgramCreator.h | 4 +- tgfx/src/gpu/opengl/GLProgramDataManager.cpp | 4 +- tgfx/src/gpu/opengl/GLProgramDataManager.h | 4 +- .../GLQuadPerEdgeAAGeometryProcessor.cpp | 4 +- .../opengl/GLQuadPerEdgeAAGeometryProcessor.h | 4 +- tgfx/src/gpu/opengl/GLRRectOp.cpp | 6 +- tgfx/src/gpu/opengl/GLRRectOp.h | 4 +- .../src/gpu/opengl/GLRadialGradientLayout.cpp | 4 +- tgfx/src/gpu/opengl/GLRadialGradientLayout.h | 4 +- tgfx/src/gpu/opengl/GLRenderTarget.cpp | 4 +- tgfx/src/gpu/opengl/GLRenderTarget.h | 4 +- .../GLSingleIntervalGradientColorizer.cpp | 4 +- .../GLSingleIntervalGradientColorizer.h | 10 +- tgfx/src/gpu/opengl/GLStandard.h | 2 +- tgfx/src/gpu/opengl/GLState.cpp | 4 +- tgfx/src/gpu/opengl/GLState.h | 7 +- tgfx/src/gpu/opengl/GLSurface.cpp | 4 +- tgfx/src/gpu/opengl/GLSurface.h | 4 +- tgfx/src/gpu/opengl/GLTexture.cpp | 27 +- tgfx/src/gpu/opengl/GLTexture.h | 4 +- .../gpu/opengl/GLTextureFragmentProcessor.cpp | 4 +- .../gpu/opengl/GLTextureFragmentProcessor.h | 4 +- .../gpu/opengl/GLTextureGradientColorizer.cpp | 4 +- .../gpu/opengl/GLTextureGradientColorizer.h | 4 +- .../opengl/GLTextureMaskFragmentProcessor.cpp | 4 +- .../opengl/GLTextureMaskFragmentProcessor.h | 4 +- tgfx/src/gpu/opengl/GLTextureSampler.cpp | 4 +- tgfx/src/gpu/opengl/GLTextureSampler.h | 4 +- tgfx/src/gpu/opengl/GLUniformHandler.cpp | 4 +- tgfx/src/gpu/opengl/GLUniformHandler.h | 4 +- .../GLUnrolledBinaryGradientColorizer.cpp | 6 +- .../GLUnrolledBinaryGradientColorizer.h | 36 +- tgfx/src/gpu/opengl/GLUtil.cpp | 25 +- tgfx/src/gpu/opengl/GLUtil.h | 26 +- tgfx/src/gpu/opengl/GLVertexShaderBuilder.cpp | 4 +- tgfx/src/gpu/opengl/GLVertexShaderBuilder.h | 4 +- tgfx/src/gpu/opengl/GLYUVTexture.cpp | 8 +- tgfx/src/gpu/opengl/GLYUVTexture.h | 4 +- .../opengl/GLYUVTextureFragmentProcessor.cpp | 4 +- .../opengl/GLYUVTextureFragmentProcessor.h | 4 +- tgfx/src/gpu/opengl/cgl/CGLDevice.mm | 4 +- tgfx/src/gpu/opengl/cgl/CGLHardwareBuffer.mm | 4 +- tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.h | 4 +- tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.mm | 4 +- tgfx/src/gpu/opengl/cgl/CGLProcGetter.h | 4 +- tgfx/src/gpu/opengl/cgl/CGLProcGetter.mm | 4 +- tgfx/src/gpu/opengl/cgl/CGLWindow.mm | 4 +- tgfx/src/gpu/opengl/eagl/EAGLDevice.mm | 8 +- .../src/gpu/opengl/eagl/EAGLHardwareBuffer.mm | 4 +- .../src/gpu/opengl/eagl/EAGLHardwareTexture.h | 4 +- .../gpu/opengl/eagl/EAGLHardwareTexture.mm | 4 +- tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.h | 4 +- tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.mm | 2 +- tgfx/src/gpu/opengl/eagl/EAGLProcGetter.h | 4 +- tgfx/src/gpu/opengl/eagl/EAGLProcGetter.mm | 4 +- tgfx/src/gpu/opengl/eagl/EAGLWindow.mm | 4 +- tgfx/src/gpu/opengl/egl/EGLDevice.cpp | 6 +- tgfx/src/gpu/opengl/egl/EGLGlobals.cpp | 4 +- tgfx/src/gpu/opengl/egl/EGLGlobals.h | 4 +- tgfx/src/gpu/opengl/egl/EGLHardwareBuffer.cpp | 4 +- .../src/gpu/opengl/egl/EGLHardwareTexture.cpp | 6 +- tgfx/src/gpu/opengl/egl/EGLHardwareTexture.h | 4 +- tgfx/src/gpu/opengl/egl/EGLProcGetter.cpp | 4 +- tgfx/src/gpu/opengl/egl/EGLProcGetter.h | 4 +- tgfx/src/gpu/opengl/egl/EGLWindow.cpp | 4 +- tgfx/src/gpu/opengl/qt/QGLDevice.cpp | 6 +- tgfx/src/gpu/opengl/qt/QGLHardwareBuffer.cpp | 4 +- tgfx/src/gpu/opengl/qt/QGLProcGetter.cpp | 4 +- tgfx/src/gpu/opengl/qt/QGLProcGetter.h | 4 +- tgfx/src/gpu/opengl/qt/QGLWindow.cpp | 4 +- tgfx/src/gpu/opengl/webgl/WebGLDevice.cpp | 6 +- .../gpu/opengl/webgl/WebGLHardwareBuffer.cpp | 4 +- tgfx/src/gpu/opengl/webgl/WebGLProcGetter.cpp | 4 +- tgfx/src/gpu/opengl/webgl/WebGLProcGetter.h | 4 +- tgfx/src/gpu/opengl/webgl/WebGLWindow.cpp | 6 +- tgfx/src/platform/NativeCodec.h | 4 +- tgfx/src/platform/Print.cpp | 4 +- tgfx/src/platform/android/HardwareBuffer.cpp | 4 +- tgfx/src/platform/android/HardwareBuffer.h | 4 +- .../android/HardwareBufferInterface.cpp | 4 +- .../android/HardwareBufferInterface.h | 4 +- tgfx/src/platform/android/JNIInit.cpp | 4 +- tgfx/src/platform/android/JNIInit.h | 4 +- tgfx/src/platform/android/JNIUtil.cpp | 6 +- tgfx/src/platform/android/JNIUtil.h | 4 +- tgfx/src/platform/android/NativeImage.cpp | 4 +- tgfx/src/platform/android/NativeImage.h | 4 +- tgfx/src/platform/android/Print.cpp | 4 +- tgfx/src/platform/apple/BitmapContextUtil.h | 5 +- tgfx/src/platform/apple/BitmapContextUtil.mm | 4 +- tgfx/src/platform/apple/HardwareBuffer.h | 4 +- tgfx/src/platform/apple/HardwareBuffer.mm | 2 +- tgfx/src/platform/apple/NativeImage.h | 4 +- tgfx/src/platform/apple/NativeImage.mm | 2 +- tgfx/src/platform/mock/NativeImage.cpp | 4 +- tgfx/src/platform/web/NativeImage.cpp | 4 +- tgfx/src/platform/web/NativeImage.h | 4 +- tgfx/src/platform/web/NativeTextureBuffer.cpp | 4 +- tgfx/src/platform/web/NativeTextureBuffer.h | 4 +- web/src/pag_wasm_bindings.cpp | 60 +- 546 files changed, 5749 insertions(+), 3105 deletions(-) rename src/{rendering/utils/TGFXTypes.h => base/utils/MathUtil.h} (76%) create mode 100644 src/base/utils/TGFXCast.cpp create mode 100644 src/base/utils/TGFXCast.h create mode 100644 src/rendering/GPUBackend.cpp delete mode 100644 src/rendering/utils/TGFXTypes.cpp create mode 100644 src/rendering/utils/Trace.cpp rename src/{base/utils/UTF8Text.cpp => rendering/utils/Trace.h} (53%) rename tgfx/include/core/{Blend.h => BlendMode.h} (98%) rename tgfx/{src/core/utils => include/core}/BytesKey.h (98%) rename tgfx/include/core/{Color4f.h => Color.h} (86%) create mode 100644 tgfx/include/core/ImageOrigin.h create mode 100644 tgfx/include/core/Matrix.h create mode 100644 tgfx/include/core/Performance.h create mode 100644 tgfx/include/core/Point.h create mode 100644 tgfx/include/core/Rect.h create mode 100644 tgfx/include/core/UTF.h create mode 100644 tgfx/include/gpu/Backend.h create mode 100644 tgfx/include/gpu/metal/MtlTypes.h create mode 100644 tgfx/include/gpu/opengl/GLTypes.h rename tgfx/src/core/{utils => }/BytesKey.cpp (96%) create mode 100644 tgfx/src/core/Matrix.cpp create mode 100644 tgfx/src/core/Performance.cpp create mode 100644 tgfx/src/core/Rect.cpp create mode 100644 tgfx/src/core/UTF.cpp create mode 100644 tgfx/src/core/utils/EnumHasher.h create mode 100644 tgfx/src/core/utils/Log.h rename {src/base => tgfx/src/core}/utils/MathExtra.h (87%) create mode 100644 tgfx/src/core/utils/UniqueID.cpp rename src/base/utils/UTF8Text.h => tgfx/src/core/utils/UniqueID.h (83%) diff --git a/.idea/misc.xml b/.idea/misc.xml index 8279ef6651..fc71b0b47d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,8 +8,13 @@ + - + + + + + diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b5a304061..d4205e4d07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ endif () if (MSVC) add_compile_options("/utf-8") + add_compile_options(/w44251 /w44275) endif (MSVC) # Sets flags diff --git a/include/pag/pag.h b/include/pag/pag.h index 2dc4ab48e6..bd8413a98a 100644 --- a/include/pag/pag.h +++ b/include/pag/pag.h @@ -24,11 +24,17 @@ #include "pag/gpu.h" #include "pag/types.h" +namespace tgfx { +struct Rect; +class Context; +class Surface; +class Device; +class Image; +} // namespace tgfx + namespace pag { class Recorder; -class Path; - class RenderCache; class Content { @@ -36,7 +42,7 @@ class Content { virtual ~Content() = default; protected: - virtual void measureBounds(Rect* bounds) = 0; + virtual void measureBounds(tgfx::Rect* bounds) = 0; virtual void draw(Recorder* recorder) = 0; @@ -57,8 +63,6 @@ class Content { friend class PAGTextLayer; }; -class Image; - /** * A still image used to replace the image contents in a PAGFile. */ @@ -135,9 +139,9 @@ class PAG_API PAGImage : public Content { protected: PAGImage(); - virtual Rect getContentSize() const = 0; + virtual tgfx::Rect getContentSize() const = 0; - virtual std::shared_ptr getImage() const { + virtual std::shared_ptr getImage() const { return nullptr; } @@ -426,7 +430,7 @@ class PAG_API PAGLayer : public Content { Frame globalToLocalFrame(Frame globalFrame) const; Point globalToLocalPoint(float stageX, float stageY); void draw(Recorder* recorder) override; - void measureBounds(Rect* bounds) override; + void measureBounds(tgfx::Rect* bounds) override; Matrix getTotalMatrixInternal(); virtual void setMatrixInternal(const Matrix& matrix); virtual float frameRateInternal() const; @@ -758,7 +762,7 @@ class PAG_API PAGImageLayer : public PAGLayer { static Frame ScaleTimeRemap(AnimatableProperty* property, const TimeRange& visibleRange, double frameScale, Frame fileEndFrame); Frame getFrameFromTimeRemap(Frame value); - void measureBounds(Rect* bounds) override; + void measureBounds(tgfx::Rect* bounds) override; friend class RenderCache; @@ -912,7 +916,7 @@ class PAG_API PAGComposition : public PAGLayer { int heightInternal() const; void setContentSizeInternal(int width, int height); void draw(Recorder* recorder) override; - void measureBounds(Rect* bounds) override; + void measureBounds(tgfx::Rect* bounds) override; bool hasClip() const; Frame frameDuration() const override; bool cacheFilters() const override; @@ -932,7 +936,7 @@ class PAG_API PAGComposition : public PAGLayer { static void FindLayers(std::function filterFunc, std::vector>* result, std::shared_ptr pagLayer); - static void MeasureChildLayer(Rect* bounds, PAGLayer* childLayer); + static void MeasureChildLayer(tgfx::Rect* bounds, PAGLayer* childLayer); static void DrawChildLayer(Recorder* recorder, PAGLayer* childLayer); static bool GetTrackMatteLayerAtPoint(PAGLayer* childLayer, float x, float y, std::vector>* results); @@ -1093,12 +1097,6 @@ class Composition; class PAGPlayer; -class Context; - -class Surface; - -class Device; - class Drawable { public: virtual ~Drawable() = default; @@ -1121,18 +1119,18 @@ class Drawable { /** * Returns the GPU device associated with this drawable. */ - virtual std::shared_ptr getDevice() = 0; + virtual std::shared_ptr getDevice() = 0; /** * Creates a new Surface from this drawable. */ - virtual std::shared_ptr createSurface(Context* context) = 0; + virtual std::shared_ptr createSurface(tgfx::Context* context) = 0; /** * Apply all pending changes to the drawable. * Note: The associated GPUDevice must be the current rendering device on the calling thread. */ - virtual void present(Context* context) = 0; + virtual void present(tgfx::Context* context) = 0; /** * Set the presenting timeStamp, used for android @@ -1212,15 +1210,15 @@ class PAG_API PAGSurface { PAGPlayer* pagPlayer = nullptr; std::shared_ptr rootLocker = nullptr; std::shared_ptr drawable = nullptr; - std::shared_ptr device = nullptr; - std::shared_ptr surface = nullptr; + std::shared_ptr device = nullptr; + std::shared_ptr surface = nullptr; explicit PAGSurface(std::shared_ptr drawable); bool draw(RenderCache* cache, std::shared_ptr graphic, BackendSemaphore* signalSemaphore, bool autoClear = true); bool hitTest(RenderCache* cache, std::shared_ptr graphic, float x, float y); - Context* lockContext(); + tgfx::Context* lockContext(); void unlockContext(); bool wait(const BackendSemaphore& waitSemaphore); diff --git a/include/pag/types.h b/include/pag/types.h index 47f8692e26..846a332ecd 100644 --- a/include/pag/types.h +++ b/include/pag/types.h @@ -501,24 +501,18 @@ struct PAG_API Rect { * Returns true if Rect intersects construction. * Returns false if either construction or Rect is empty, or do not intersect. */ - bool intersects(float l, float t, float r, float b) const { - return Intersects(left, top, right, bottom, l, t, r, b); - } + bool intersects(float l, float t, float r, float b) const; /** * Returns true if Rect intersects r. Returns false if either r or Rect is empty, or do not * intersect. */ - bool intersects(const Rect& r) const { - return Intersects(left, top, right, bottom, r.left, r.top, r.right, r.bottom); - } + bool intersects(const Rect& r) const; /** * Returns true if a intersects b. Returns false if either a or b is empty, or do not intersect. */ - static bool Intersects(const Rect& a, const Rect& b) { - return Intersects(a.left, a.top, a.right, a.bottom, b.left, b.top, b.right, b.bottom); - } + static bool Intersects(const Rect& a, const Rect& b); /** * Constructs Rect to intersect from (left, top, right, bottom). Does not sort construction. @@ -554,64 +548,25 @@ struct PAG_API Rect { * Sets Rect by discarding the fractional portion of left and top; and rounding up right and * bottom. */ - void roundOut() { - left = floorf(left); - top = floorf(top); - right = ceilf(right); - bottom = ceilf(bottom); - } + void roundOut(); /** * Sets Rect by rounding of left, top, right and bottom. */ - void round() { - left = roundf(left); - top = roundf(top); - right = roundf(right); - bottom = roundf(bottom); - } + void round(); /** * Swaps left and right if left is greater than right; and swaps top and bottom if top is * greater than bottom. Result may be empty; and width() and height() will be zero or positive. */ - void sort() { - if (left > right) { - std::swap(left, right); - } - - if (top > bottom) { - std::swap(top, bottom); - } - } + void sort(); /** * Returns Rect with left and right swapped if left is greater than right, and with top and * bottom swapped if top is greater than bottom. Result may be empty, and width() and height() * will be zero or positive. */ - Rect makeSorted() const { - return MakeLTRB(std::min(left, right), std::min(top, bottom), std::max(left, right), - std::max(top, bottom)); - } - - private: - static bool Intersects(float al, float at, float ar, float ab, float bl, float bt, float br, - float bb) { - float L = al > bl ? al : bl; - float R = ar < br ? ar : br; - float T = at > bt ? at : bt; - float B = ab < bb ? ab : bb; - return L < R && T < B; - } -}; - -/** - * Round Rect. - */ -struct RRect { - Rect rect = Rect::MakeEmpty(); - Point radii = Point::Zero(); + Rect makeSorted() const; }; /*** @@ -1090,15 +1045,7 @@ class PAG_API Matrix { * If this matrix can be inverted, return true and if inverse is not null, set inverse to be the * inverse of this matrix. If this matrix cannot be inverted, ignore inverse and return false. */ - bool invert(Matrix* inverse) const { - if (this->isIdentity()) { - if (inverse) { - inverse->reset(); - } - return true; - } - return this->invertNonIdentity(inverse); - } + bool invert(Matrix* inverse) const; bool invertible() const; @@ -1292,10 +1239,6 @@ class PAG_API Matrix { static constexpr int PERSP_0 = 6; //!< input x perspective factor static constexpr int PERSP_1 = 7; //!< input y perspective factor static constexpr int PERSP_2 = 8; //!< perspective bias - - void setScaleTranslate(float sx, float sy, float tx, float ty); - bool invertNonIdentity(Matrix* inverse) const; - bool getMinMaxScaleFactors(float results[2]) const; }; /** diff --git a/src/base/ByteData.cpp b/src/base/ByteData.cpp index c3da82a69e..80f299a5c0 100644 --- a/src/base/ByteData.cpp +++ b/src/base/ByteData.cpp @@ -21,7 +21,7 @@ namespace pag { std::unique_ptr ByteData::FromPath(const std::string& filePath) { - auto stream = Stream::MakeFromFile(filePath); + auto stream = tgfx::Stream::MakeFromFile(filePath); if (stream == nullptr) { return nullptr; } diff --git a/src/base/Matrix.cpp b/src/base/Matrix.cpp index d4e2a1a438..802814a70b 100644 --- a/src/base/Matrix.cpp +++ b/src/base/Matrix.cpp @@ -16,449 +16,162 @@ // ///////////////////////////////////////////////////////////////////////////////////////////////// -#include "base/utils/MathExtra.h" +#include "base/utils/TGFXCast.h" #include "pag/types.h" namespace pag { void Matrix::reset() { - values[SCALE_X] = values[SCALE_Y] = values[PERSP_2] = 1; - values[SKEW_X] = values[SKEW_Y] = values[TRANS_X] = values[TRANS_Y] = values[PERSP_0] = - values[PERSP_1] = 0; + ToTGFX(this)->reset(); } bool operator==(const Matrix& a, const Matrix& b) { - const float* ma = a.values; - const float* mb = b.values; - return ma[0] == mb[0] && ma[1] == mb[1] && ma[2] == mb[2] && ma[3] == mb[3] && ma[4] == mb[4] && - ma[5] == mb[5] && ma[6] == mb[6] && ma[7] == mb[7] && ma[8] == mb[8]; + return ToTGFX(a) == ToTGFX(b); } void Matrix::setAll(float scaleX, float skewX, float transX, float skewY, float scaleY, float transY, float persp0, float persp1, float persp2) { - values[SCALE_X] = scaleX; - values[SKEW_X] = skewX; - values[TRANS_X] = transX; - values[SKEW_Y] = skewY; - values[SCALE_Y] = scaleY; - values[TRANS_Y] = transY; - values[PERSP_0] = persp0; - values[PERSP_1] = persp1; - values[PERSP_2] = persp2; + ToTGFX(this)->setAll(scaleX, skewX, transX, skewY, scaleY, transY, persp0, persp1, persp2); } void Matrix::setAffine(float a, float b, float c, float d, float tx, float ty) { - values[SCALE_X] = a; - values[SKEW_X] = c; - values[TRANS_X] = tx; - values[SKEW_Y] = b; - values[SCALE_Y] = d; - values[TRANS_Y] = ty; - values[PERSP_0] = 0; - values[PERSP_1] = 0; - values[PERSP_2] = 1; + ToTGFX(this)->setAffine(a, b, c, d, tx, ty); } void Matrix::setTranslate(float dx, float dy) { - if ((dx != 0) | (dy != 0)) { - values[TRANS_X] = dx; - values[TRANS_Y] = dy; - - values[SCALE_X] = values[SCALE_Y] = values[PERSP_2] = 1; - values[SKEW_X] = values[SKEW_Y] = values[PERSP_0] = values[PERSP_1] = 0; - } else { - this->reset(); - } -} - -static inline float sdot(float a, float b, float c, float d) { - return a * b + c * d; + ToTGFX(this)->setTranslate(dx, dy); } void Matrix::preTranslate(float dx, float dy) { - values[TRANS_X] += sdot(values[SCALE_X], dx, values[SKEW_X], dy); - values[TRANS_Y] += sdot(values[SKEW_Y], dx, values[SCALE_Y], dy); + ToTGFX(this)->preTranslate(dx, dy); } void Matrix::postTranslate(float dx, float dy) { - values[TRANS_X] += dx; - values[TRANS_Y] += dy; -} - -void Matrix::setScaleTranslate(float sx, float sy, float tx, float ty) { - values[SCALE_X] = sx; - values[SKEW_X] = 0; - values[TRANS_X] = tx; - - values[SKEW_Y] = 0; - values[SCALE_Y] = sy; - values[TRANS_Y] = ty; - - values[PERSP_0] = 0; - values[PERSP_1] = 0; - values[PERSP_2] = 1; + ToTGFX(this)->postTranslate(dx, dy); } void Matrix::setScale(float sx, float sy, float px, float py) { - if (1 == sx && 1 == sy) { - this->reset(); - } else { - values[SCALE_X] = sx; - values[SKEW_X] = 0; - values[TRANS_X] = 0; - - values[SKEW_Y] = 0; - values[SCALE_Y] = sy; - values[TRANS_Y] = 0; - - values[PERSP_0] = 0; - values[PERSP_1] = 0; - values[PERSP_2] = 1; - this->setScaleTranslate(sx, sy, px - sx * px, py - sy * py); - } + ToTGFX(this)->setScale(sx, sy, px, py); } void Matrix::setScale(float sx, float sy) { - if (1 == sx && 1 == sy) { - this->reset(); - } else { - values[SCALE_X] = sx; - values[SCALE_Y] = sy; - values[PERSP_2] = 1; - - values[TRANS_X] = values[TRANS_Y] = values[SKEW_X] = values[SKEW_Y] = values[PERSP_0] = - values[PERSP_1] = 0; - } + ToTGFX(this)->setScale(sx, sy); } void Matrix::preScale(float sx, float sy, float px, float py) { - if (1 == sx && 1 == sy) { - return; - } - - Matrix m = {}; - m.setScale(sx, sy, px, py); - this->preConcat(m); + ToTGFX(this)->preScale(sx, sy, px, py); } void Matrix::preScale(float sx, float sy) { - if (1 == sx && 1 == sy) { - return; - } - values[SCALE_X] *= sx; - values[SKEW_Y] *= sx; - values[PERSP_0] *= sx; - - values[SKEW_X] *= sy; - values[SCALE_Y] *= sy; - values[PERSP_1] *= sy; + ToTGFX(this)->preScale(sx, sy); } void Matrix::postScale(float sx, float sy, float px, float py) { - if (1 == sx && 1 == sy) { - return; - } - Matrix m = {}; - m.setScale(sx, sy, px, py); - this->postConcat(m); + ToTGFX(this)->postScale(sx, sy, px, py); } void Matrix::postScale(float sx, float sy) { - if (1 == sx && 1 == sy) { - return; - } - Matrix m = {}; - m.setScale(sx, sy); - this->postConcat(m); + ToTGFX(this)->postScale(sx, sy); } void Matrix::setSinCos(float sinV, float cosV, float px, float py) { - const float oneMinusCosV = 1 - cosV; - - values[SCALE_X] = cosV; - values[SKEW_X] = -sinV; - values[TRANS_X] = sdot(sinV, py, oneMinusCosV, px); - - values[SKEW_Y] = sinV; - values[SCALE_Y] = cosV; - values[TRANS_Y] = sdot(-sinV, px, oneMinusCosV, py); - - values[PERSP_0] = values[PERSP_1] = 0; - values[PERSP_2] = 1; + ToTGFX(this)->setSinCos(sinV, cosV, px, py); } void Matrix::setSinCos(float sinV, float cosV) { - values[SCALE_X] = cosV; - values[SKEW_X] = -sinV; - values[TRANS_X] = 0; - - values[SKEW_Y] = sinV; - values[SCALE_Y] = cosV; - values[TRANS_Y] = 0; - - values[PERSP_0] = values[PERSP_1] = 0; - values[PERSP_2] = 1; + ToTGFX(this)->setSinCos(sinV, cosV); } void Matrix::setRotate(float degrees, float px, float py) { - float rad = DegreesToRadians(degrees); - this->setSinCos(SinSnapToZero(rad), CosSnapToZero(rad), px, py); + ToTGFX(this)->setRotate(degrees, px, py); } void Matrix::setRotate(float degrees) { - float rad = DegreesToRadians(degrees); - this->setSinCos(SinSnapToZero(rad), CosSnapToZero(rad)); + ToTGFX(this)->setRotate(degrees); } void Matrix::preRotate(float degrees, float px, float py) { - Matrix m = {}; - m.setRotate(degrees, px, py); - this->preConcat(m); + ToTGFX(this)->preRotate(degrees, px, py); } void Matrix::preRotate(float degrees) { - Matrix m = {}; - m.setRotate(degrees); - this->preConcat(m); + ToTGFX(this)->preRotate(degrees); } void Matrix::postRotate(float degrees, float px, float py) { - Matrix m = {}; - m.setRotate(degrees, px, py); - this->postConcat(m); + ToTGFX(this)->postRotate(degrees, px, py); } void Matrix::postRotate(float degrees) { - Matrix m = {}; - m.setRotate(degrees); - this->postConcat(m); + ToTGFX(this)->postRotate(degrees); } void Matrix::setSkew(float sx, float sy, float px, float py) { - values[SCALE_X] = 1; - values[SKEW_X] = sx; - values[TRANS_X] = -sx * py; - - values[SKEW_Y] = sy; - values[SCALE_Y] = 1; - values[TRANS_Y] = -sy * px; - - values[PERSP_0] = values[PERSP_1] = 0; - values[PERSP_2] = 1; + ToTGFX(this)->setSkew(sx, sy, px, py); } void Matrix::setSkew(float sx, float sy) { - values[SCALE_X] = 1; - values[SKEW_X] = sx; - values[TRANS_X] = 0; - - values[SKEW_Y] = sy; - values[SCALE_Y] = 1; - values[TRANS_Y] = 0; - - values[PERSP_0] = values[PERSP_1] = 0; - values[PERSP_2] = 1; + ToTGFX(this)->setSkew(sx, sy); } void Matrix::preSkew(float sx, float sy, float px, float py) { - Matrix m = {}; - m.setSkew(sx, sy, px, py); - this->preConcat(m); + ToTGFX(this)->preSkew(sx, sy, px, py); } void Matrix::preSkew(float sx, float sy) { - Matrix m = {}; - m.setSkew(sx, sy); - this->preConcat(m); + ToTGFX(this)->preSkew(sx, sy); } void Matrix::postSkew(float sx, float sy, float px, float py) { - Matrix m = {}; - m.setSkew(sx, sy, px, py); - this->postConcat(m); + ToTGFX(this)->postSkew(sx, sy, px, py); } void Matrix::postSkew(float sx, float sy) { - Matrix m = {}; - m.setSkew(sx, sy); - this->postConcat(m); + ToTGFX(this)->postSkew(sx, sy); } void Matrix::setConcat(const Matrix& first, const Matrix& second) { - auto& matA = first.values; - auto& matB = second.values; - auto a = matB[SCALE_X] * matA[SCALE_X]; - auto b = 0.0; - auto c = 0.0; - auto d = matB[SCALE_Y] * matA[SCALE_Y]; - auto tx = matB[TRANS_X] * matA[SCALE_X] + matA[TRANS_X]; - auto ty = matB[TRANS_Y] * matA[SCALE_Y] + matA[TRANS_Y]; - - if (matB[SKEW_Y] != 0.0 || matB[SKEW_X] != 0.0 || matA[SKEW_Y] != 0.0 || matA[SKEW_X] != 0.0) { - a += matB[SKEW_Y] * matA[SKEW_X]; - d += matB[SKEW_X] * matA[SKEW_Y]; - b += matB[SCALE_X] * matA[SKEW_Y] + matB[SKEW_Y] * matA[SCALE_Y]; - c += matB[SKEW_X] * matA[SCALE_X] + matB[SCALE_Y] * matA[SKEW_X]; - tx += matB[TRANS_Y] * matA[SKEW_X]; - ty += matB[TRANS_X] * matA[SKEW_Y]; - } - - values[SCALE_X] = a; - values[SKEW_Y] = b; - values[SKEW_X] = c; - values[SCALE_Y] = d; - values[TRANS_X] = tx; - values[TRANS_Y] = ty; - values[PERSP_0] = 0; - values[PERSP_1] = 0; - values[PERSP_2] = 1; + ToTGFX(this)->setConcat(ToTGFX(first), ToTGFX(second)); } void Matrix::preConcat(const Matrix& mat) { - // check for identity first, so we don't do a needless copy of ourselves - // to ourselves inside setConcat() - if (!mat.isIdentity()) { - this->setConcat(*this, mat); - } + ToTGFX(this)->preConcat(ToTGFX(mat)); } void Matrix::postConcat(const Matrix& mat) { - // check for identity first, so we don't do a needless copy of ourselves - // to ourselves inside setConcat() - if (!mat.isIdentity()) { - this->setConcat(mat, *this); - } + ToTGFX(this)->postConcat(ToTGFX(mat)); +} + +bool Matrix::invert(Matrix* inverse) const { + return ToTGFX(this)->invert(ToTGFX(inverse)); } bool Matrix::invertible() const { - float determinant = values[SCALE_X] * values[SCALE_Y] - values[SKEW_Y] * values[SKEW_X]; - return !(FloatNearlyZero(determinant, FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO)); -} - -bool Matrix::invertNonIdentity(Matrix* inverse) const { - auto a = values[SCALE_X]; - auto d = values[SCALE_Y]; - auto c = values[SKEW_X]; - auto b = values[SKEW_Y]; - auto tx = values[TRANS_X]; - auto ty = values[TRANS_Y]; - - if (b == 0 && c == 0) { - if (a == 0 || d == 0) { - return false; - } - a = 1 / a; - d = 1 / d; - tx = -a * tx; - ty = -d * ty; - inverse->setAffine(a, b, c, d, tx, ty); - return true; - } - float determinant = a * d - b * c; - if (FloatNearlyZero(determinant, FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO)) { - return false; - } - determinant = 1 / determinant; - a = d * determinant; - b = -b * determinant; - c = -c * determinant; - d = values[SCALE_X] * determinant; - tx = -(a * values[TRANS_X] + c * values[TRANS_Y]); - ty = -(b * values[TRANS_X] + d * values[TRANS_Y]); - inverse->setAffine(a, b, c, d, tx, ty); - return true; + return ToTGFX(this)->invertible(); } void Matrix::mapPoints(Point dst[], const Point src[], int count) const { - auto tx = values[TRANS_X]; - auto ty = values[TRANS_Y]; - auto sx = values[SCALE_X]; - auto sy = values[SCALE_Y]; - auto kx = values[SKEW_X]; - auto ky = values[SKEW_Y]; - for (int i = 0; i < count; i++) { - auto x = src[i].x * sx + src[i].y * kx + tx; - auto y = src[i].x * ky + src[i].y * sy + ty; - dst[i].set(x, y); - } + ToTGFX(this)->mapPoints(ToTGFX(dst), ToTGFX(src), count); } void Matrix::mapXY(float x, float y, Point* result) const { - auto tx = values[TRANS_X]; - auto ty = values[TRANS_Y]; - auto sx = values[SCALE_X]; - auto sy = values[SCALE_Y]; - auto kx = values[SKEW_X]; - auto ky = values[SKEW_Y]; - result->set(x * sx + y * kx + tx, x * ky + y * sy + ty); + ToTGFX(this)->mapXY(x, y, ToTGFX(result)); } void Matrix::mapRect(Rect* dst, const Rect& src) const { - Point quad[4]; - quad[0].set(src.left, src.top); - quad[1].set(src.right, src.top); - quad[2].set(src.right, src.bottom); - quad[3].set(src.left, src.bottom); - mapPoints(quad, quad, 4); - dst->setBounds(quad, 4); + ToTGFX(this)->mapRect(ToTGFX(dst), ToTGFX(src)); } float Matrix::getMinScale() const { - float results[2]; - if (getMinMaxScaleFactors(results)) { - return results[0]; - } - return -1.0f; + return ToTGFX(this)->getMinScale(); } float Matrix::getMaxScale() const { - float results[2]; - if (getMinMaxScaleFactors(results)) { - return results[1]; - } - return -1.0f; -} - -bool Matrix::getMinMaxScaleFactors(float* results) const { - float a = sdot(values[SCALE_X], values[SCALE_X], values[SKEW_Y], values[SKEW_Y]); - float b = sdot(values[SCALE_X], values[SKEW_X], values[SCALE_Y], values[SKEW_Y]); - float c = sdot(values[SKEW_X], values[SKEW_X], values[SCALE_Y], values[SCALE_Y]); - float bSqd = b * b; - if (bSqd <= FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO) { - results[0] = a; - results[1] = c; - if (results[0] > results[1]) { - using std::swap; - swap(results[0], results[1]); - } - } else { - float aminusc = a - c; - float apluscdiv2 = (a + c) * 0.5f; - float x = sqrtf(aminusc * aminusc + 4 * bSqd) * 0.5f; - results[0] = apluscdiv2 - x; - results[1] = apluscdiv2 + x; - } - auto isFinite = (results[0] * 0 == 0); - if (!isFinite) { - return false; - } - if (results[0] < 0) { - results[0] = 0; - } - results[0] = sqrtf(results[0]); - isFinite = (results[1] * 0 == 0); - if (!isFinite) { - return false; - } - if (results[1] < 0) { - results[1] = 0; - } - results[1] = sqrtf(results[1]); - return true; + return ToTGFX(this)->getMaxScale(); } bool Matrix::isFinite() const { - return FloatsAreFinite(values, 9); + return ToTGFX(this)->isFinite(); } const Matrix& Matrix::I() { diff --git a/src/base/Rect.cpp b/src/base/Rect.cpp index d85af84c6b..9e6bcfc616 100644 --- a/src/base/Rect.cpp +++ b/src/base/Rect.cpp @@ -16,89 +16,56 @@ // ///////////////////////////////////////////////////////////////////////////////////////////////// +#include "base/utils/TGFXCast.h" #include "pag/types.h" namespace pag { void Rect::scale(float scaleX, float scaleY) { - left *= scaleX; - right *= scaleY; - top *= scaleX; - bottom *= scaleY; + ToTGFX(this)->scale(scaleX, scaleY); } bool Rect::setBounds(const Point pts[], int count) { - if (count <= 0) { - this->setEmpty(); - return true; - } - float minX, maxX; - float minY, maxY; - minX = maxX = pts[0].x; - minY = maxY = pts[0].y; - - for (int i = 1; i < count; i++) { - auto x = pts[i].x; - auto y = pts[i].y; - auto isFinite = ((x + y) * 0 == 0); - if (!isFinite) { - setEmpty(); - return false; - } - if (x < minX) { - minX = x; - } - if (x > maxX) { - maxX = x; - } - if (y < minY) { - minY = y; - } - if (y > maxY) { - maxY = y; - } - } - setLTRB(minX, minY, maxX, maxY); - return true; + return ToTGFX(this)->setBounds(ToTGFX(pts), count); } -#define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \ - float L = al > bl ? al : bl; \ - float R = ar < br ? ar : br; \ - float T = at > bt ? at : bt; \ - float B = ab < bb ? ab : bb; \ - do { \ - if (!(L < R && T < B)) { \ - return false; \ - } \ - } while (0) -// do the !(opposite) check so we return false if either arg is NaN - bool Rect::intersect(float l, float t, float r, float b) { - CHECK_INTERSECT(l, t, r, b, left, top, right, bottom); - this->setLTRB(L, T, R, B); - return true; + return ToTGFX(this)->intersect(l, t, r, b); } bool Rect::intersect(const Rect& a, const Rect& b) { - CHECK_INTERSECT(a.left, a.top, a.right, a.bottom, b.left, b.top, b.right, b.bottom); - this->setLTRB(L, T, R, B); - return true; + return ToTGFX(this)->intersect(ToTGFX(a), ToTGFX(b)); } void Rect::join(float l, float t, float r, float b) { - // do nothing if the params are empty - if (l >= r || t >= b) { - return; - } - // if we are empty, just assign - if (left >= right || top >= bottom) { - this->setLTRB(l, t, r, b); - } else { - left = left < l ? left : l; - top = top < t ? top : t; - right = right > r ? right : r; - bottom = bottom > b ? bottom : b; - } + ToTGFX(this)->join(l, t, r, b); +} + +bool Rect::intersects(float l, float t, float r, float b) const { + return ToTGFX(this)->intersects(l, t, r, b); +} + +bool Rect::intersects(const Rect& r) const { + return ToTGFX(this)->intersects(ToTGFX(r)); +} + +bool Rect::Intersects(const Rect& a, const Rect& b) { + return tgfx::Rect::Intersects(ToTGFX(a), ToTGFX(b)); +} + +void Rect::roundOut() { + ToTGFX(this)->roundOut(); +} + +void Rect::round() { + ToTGFX(this)->round(); +} + +void Rect::sort() { + ToTGFX(this)->sort(); +} + +Rect Rect::makeSorted() const { + return ToPAG(ToTGFX(this)->makeSorted()); } } // namespace pag \ No newline at end of file diff --git a/src/base/effects/BulgeEffect.cpp b/src/base/effects/BulgeEffect.cpp index 980ffafdfc..b4cb0d83d3 100644 --- a/src/base/effects/BulgeEffect.cpp +++ b/src/base/effects/BulgeEffect.cpp @@ -16,16 +16,15 @@ // ///////////////////////////////////////////////////////////////////////////////////////////////// -#include "base/utils/MathExtra.h" #include "base/utils/Verify.h" #include "core/Path.h" #include "pag/file.h" namespace pag { -static void ConvertEllipseToPath(Path* path, float centerX, float centerY, float radiusX, +static void ConvertEllipseToPath(tgfx::Path* path, float centerX, float centerY, float radiusX, float radiusY) { - auto start = -M_PI_2_F; - auto endAngle = M_PI_F + M_PI_2_F; + auto start = -static_cast(M_PI_2); + auto endAngle = static_cast(M_PI + M_PI_2); auto end = 0; auto currentX = centerX + cosf(start) * radiusX; auto currentY = centerY + sinf(start) * radiusY; @@ -48,7 +47,7 @@ static void ConvertEllipseToPath(Path* path, float centerX, float centerY, float break; } start = end; - end = start + M_PI_2_F; + end = start + static_cast(M_PI_2); if (end > endAngle) { end = endAngle; } @@ -120,14 +119,14 @@ void BulgeEffect::transformBounds(Rect* contentBounds, const Point&, Frame layer auto right = contentBounds->right; auto bottom = contentBounds->bottom; - Path ellipsePath = {}; + tgfx::Path ellipsePath = {}; // radius 需要加 1,如果 2 者相交只有一个点时,intersectPath.isEmpty 为 true ConvertEllipseToPath(&ellipsePath, bulgeCenterValue.x, bulgeCenterValue.y, horizontalRadiusValue + 1, verticalRadiusValue + 1); - Path boundsPath = {}; + tgfx::Path boundsPath = {}; boundsPath.addRect(left, top, right, bottom); auto intersectPath = ellipsePath; - intersectPath.addPath(boundsPath, PathOp::Intersect); + intersectPath.addPath(boundsPath, tgfx::PathOp::Intersect); // 凸出效果的椭圆与内容 bounds 没有交集,不改变尺寸 if (intersectPath.isEmpty() && !intersectPath.isInverseFillType()) { return; diff --git a/src/base/layerStyles/DropShadowStyle.cpp b/src/base/layerStyles/DropShadowStyle.cpp index 6a87f8bade..87b7a9ef36 100644 --- a/src/base/layerStyles/DropShadowStyle.cpp +++ b/src/base/layerStyles/DropShadowStyle.cpp @@ -16,7 +16,7 @@ // ///////////////////////////////////////////////////////////////////////////////////////////////// -#include "base/utils/MathExtra.h" +#include "base/utils/MathUtil.h" #include "base/utils/Verify.h" #include "pag/file.h" diff --git a/src/base/utils/Log.h b/src/base/utils/Log.h index 8014bdc96b..947a86be49 100644 --- a/src/base/utils/Log.h +++ b/src/base/utils/Log.h @@ -22,10 +22,10 @@ #include "platform/Print.h" namespace pag { -#define ABORT(msg) \ - do { \ - pag::PrintError("%s:%d: fatal error: \"%s\"\n", __FILE__, __LINE__, #msg); \ - ::abort(); \ +#define ABORT(msg) \ + do { \ + tgfx::PrintError("%s:%d: fatal error: \"%s\"\n", __FILE__, __LINE__, #msg); \ + ::abort(); \ } while (false) #ifdef NO_LOG @@ -36,8 +36,8 @@ namespace pag { #else -#define LOGI(...) pag::PrintLog(__VA_ARGS__) -#define LOGE(...) pag::PrintError(__VA_ARGS__) +#define LOGI(...) tgfx::PrintLog(__VA_ARGS__) +#define LOGE(...) tgfx::PrintError(__VA_ARGS__) #define ASSERT(assertion) \ if (!(assertion)) { \ ABORT(#assertion); \ diff --git a/src/rendering/utils/TGFXTypes.h b/src/base/utils/MathUtil.h similarity index 76% rename from src/rendering/utils/TGFXTypes.h rename to src/base/utils/MathUtil.h index 05f3ab39e1..8c386a4253 100644 --- a/src/rendering/utils/TGFXTypes.h +++ b/src/base/utils/MathUtil.h @@ -18,19 +18,14 @@ #pragma once -#include "core/Blend.h" -#include "core/Color4f.h" -#include "core/Stroke.h" -#include "pag/file.h" +#include namespace pag { -Blend ToTGFXBlend(Enum blendMode); +static inline float DegreesToRadians(float degrees) { + return degrees * (static_cast(M_PI) / 180.0f); +} -Stroke::Cap ToTGFXCap(Enum cap); - -Stroke::Join ToTGFXJoin(Enum join); - -Color4f ToTGFXColor(Color color, Opacity opacity = Opaque); - -float ToAlpha(Opacity opacity); +static inline float RadiansToDegrees(float radians) { + return radians * (180.0f / static_cast(M_PI)); +} } // namespace pag diff --git a/src/base/utils/MatrixUtil.cpp b/src/base/utils/MatrixUtil.cpp index 53a103ac35..481928e535 100644 --- a/src/base/utils/MatrixUtil.cpp +++ b/src/base/utils/MatrixUtil.cpp @@ -19,8 +19,8 @@ #include "MatrixUtil.h" namespace pag { -bool MapPointInverted(const Matrix& matrix, Point* point) { - Matrix inverted = {}; +bool MapPointInverted(const tgfx::Matrix& matrix, tgfx::Point* point) { + tgfx::Matrix inverted = {}; bool canInvert = matrix.invert(&inverted); if (canInvert) { inverted.mapPoints(point, 1); @@ -29,13 +29,13 @@ bool MapPointInverted(const Matrix& matrix, Point* point) { return false; } -float GetMaxScaleFactor(const Matrix& matrix) { +float GetMaxScaleFactor(const tgfx::Matrix& matrix) { auto scale = GetScaleFactor(matrix); return std::max(fabsf(scale.x), fabsf(scale.y)); } -Point GetScaleFactor(const Matrix& matrix, float contentScale, bool inverted) { - Point scale = {}; +tgfx::Point GetScaleFactor(const tgfx::Matrix& matrix, float contentScale, bool inverted) { + tgfx::Point scale = {}; auto a = matrix.get(0); auto c = matrix.get(1); auto b = matrix.get(3); diff --git a/src/base/utils/MatrixUtil.h b/src/base/utils/MatrixUtil.h index 7623c72d38..0d9ae60c31 100644 --- a/src/base/utils/MatrixUtil.h +++ b/src/base/utils/MatrixUtil.h @@ -18,10 +18,11 @@ #pragma once -#include "pag/types.h" +#include "core/Matrix.h" namespace pag { -bool MapPointInverted(const Matrix& matrix, Point* point); -float GetMaxScaleFactor(const Matrix& matrix); -Point GetScaleFactor(const Matrix& matrix, float contentScale = 1.0f, bool inverted = false); +bool MapPointInverted(const tgfx::Matrix& matrix, tgfx::Point* point); +float GetMaxScaleFactor(const tgfx::Matrix& matrix); +tgfx::Point GetScaleFactor(const tgfx::Matrix& matrix, float contentScale = 1.0f, + bool inverted = false); } // namespace pag diff --git a/src/base/utils/TGFXCast.cpp b/src/base/utils/TGFXCast.cpp new file mode 100644 index 0000000000..28ad7a3050 --- /dev/null +++ b/src/base/utils/TGFXCast.cpp @@ -0,0 +1,144 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include "TGFXCast.h" + +namespace pag { +static constexpr std::pair kBlendModeMap[] = { + {BlendMode::Normal, tgfx::BlendMode::SrcOver}, + {BlendMode::Multiply, tgfx::BlendMode::Multiply}, + {BlendMode::Screen, tgfx::BlendMode::Screen}, + {BlendMode::Overlay, tgfx::BlendMode::Overlay}, + {BlendMode::Darken, tgfx::BlendMode::Darken}, + {BlendMode::Lighten, tgfx::BlendMode::Lighten}, + {BlendMode::ColorDodge, tgfx::BlendMode::ColorDodge}, + {BlendMode::ColorBurn, tgfx::BlendMode::ColorBurn}, + {BlendMode::HardLight, tgfx::BlendMode::HardLight}, + {BlendMode::SoftLight, tgfx::BlendMode::SoftLight}, + {BlendMode::Difference, tgfx::BlendMode::Difference}, + {BlendMode::Exclusion, tgfx::BlendMode::Exclusion}, + {BlendMode::Hue, tgfx::BlendMode::Hue}, + {BlendMode::Saturation, tgfx::BlendMode::Saturation}, + {BlendMode::Color, tgfx::BlendMode::Color}, + {BlendMode::Luminosity, tgfx::BlendMode::Luminosity}, + {BlendMode::Add, tgfx::BlendMode::Plus}}; + +tgfx::BlendMode ToTGFXBlend(Enum blendMode) { + for (const auto& pair : kBlendModeMap) { + if (pair.first == blendMode) { + return pair.second; + } + } + return tgfx::BlendMode::SrcOver; +} + +tgfx::LineCap ToTGFXCap(Enum cap) { + switch (cap) { + case LineCap::Round: + return tgfx::LineCap::Round; + case LineCap::Square: + return tgfx::LineCap::Square; + default: + return tgfx::LineCap::Butt; + } +} + +tgfx::LineJoin ToTGFXJoin(Enum join) { + switch (join) { + case LineJoin::Round: + return tgfx::LineJoin::Round; + case LineJoin::Bevel: + return tgfx::LineJoin::Bevel; + default: + return tgfx::LineJoin::Miter; + } +} + +tgfx::Color ToTGFX(Color color, Opacity opacity) { + return {static_cast(color.red) / 255.0f, static_cast(color.green) / 255.0f, + static_cast(color.blue) / 255.0f, ToAlpha(opacity)}; +} + +float ToAlpha(Opacity opacity) { + if (opacity == 255) { + return 1.0f; + } + return static_cast(opacity) / 255.0f; +} + +tgfx::ImageOrigin ToTGFX(ImageOrigin origin) { + return origin == ImageOrigin::TopLeft ? tgfx::ImageOrigin::TopLeft + : tgfx::ImageOrigin::BottomLeft; +} + +ImageOrigin ToPAG(tgfx::ImageOrigin origin) { + return origin == tgfx::ImageOrigin::TopLeft ? ImageOrigin::TopLeft : ImageOrigin::BottomLeft; +} + +tgfx::AlphaType ToTGFX(AlphaType alphaType) { + switch (alphaType) { + case AlphaType::Opaque: + return tgfx::AlphaType::Opaque; + case AlphaType::Premultiplied: + return tgfx::AlphaType::Premultiplied; + case AlphaType::Unpremultiplied: + return tgfx::AlphaType::Unpremultiplied; + default: + return tgfx::AlphaType::Unknown; + } +} + +AlphaType ToPAG(tgfx::AlphaType alphaType) { + switch (alphaType) { + case tgfx::AlphaType::Opaque: + return AlphaType::Opaque; + case tgfx::AlphaType::Premultiplied: + return AlphaType::Premultiplied; + case tgfx::AlphaType::Unpremultiplied: + return AlphaType::Unpremultiplied; + default: + return AlphaType::Unknown; + } +} + +tgfx::ColorType ToTGFX(ColorType colorType) { + switch (colorType) { + case ColorType::ALPHA_8: + return tgfx::ColorType::ALPHA_8; + case ColorType::RGBA_8888: + return tgfx::ColorType::RGBA_8888; + case ColorType::BGRA_8888: + return tgfx::ColorType::BGRA_8888; + default: + return tgfx::ColorType::Unknown; + } +} + +ColorType ToPAG(tgfx::ColorType colorType) { + switch (colorType) { + case tgfx::ColorType::ALPHA_8: + return ColorType::ALPHA_8; + case tgfx::ColorType::RGBA_8888: + return ColorType::RGBA_8888; + case tgfx::ColorType::BGRA_8888: + return ColorType::BGRA_8888; + default: + return ColorType::Unknown; + } +} +} // namespace pag diff --git a/src/base/utils/TGFXCast.h b/src/base/utils/TGFXCast.h new file mode 100644 index 0000000000..0ec25de4a5 --- /dev/null +++ b/src/base/utils/TGFXCast.h @@ -0,0 +1,139 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "core/BlendMode.h" +#include "core/Color.h" +#include "core/ImageInfo.h" +#include "core/ImageOrigin.h" +#include "core/Matrix.h" +#include "core/Stroke.h" +#include "gpu/Backend.h" +#include "pag/file.h" +#include "pag/gpu.h" + +namespace pag { + +tgfx::BlendMode ToTGFXBlend(Enum blendMode); + +tgfx::LineCap ToTGFXCap(Enum cap); + +tgfx::LineJoin ToTGFXJoin(Enum join); + +tgfx::Color ToTGFX(Color color, Opacity opacity = Opaque); + +float ToAlpha(Opacity opacity); + +tgfx::ImageOrigin ToTGFX(ImageOrigin origin); + +ImageOrigin ToPAG(tgfx::ImageOrigin origin); + +tgfx::AlphaType ToTGFX(AlphaType alphaType); + +AlphaType ToPAG(tgfx::AlphaType alphaType); + +tgfx::ColorType ToTGFX(ColorType colorType); + +ColorType ToPAG(tgfx::ColorType colorType); + +static inline tgfx::BackendTexture ToTGFX(const BackendTexture& texture) { + return *reinterpret_cast(&texture); +} + +static inline BackendTexture ToPAG(const tgfx::BackendTexture& texture) { + return *reinterpret_cast(&texture); +} + +static inline tgfx::BackendRenderTarget ToTGFX(const BackendRenderTarget& renderTarget) { + return *reinterpret_cast(&renderTarget); +} + +static inline BackendRenderTarget ToPAG(const tgfx::BackendRenderTarget& renderTarget) { + return *reinterpret_cast(&renderTarget); +} + +static inline tgfx::BackendSemaphore* ToTGFX(BackendSemaphore* semaphore) { + return reinterpret_cast(semaphore); +} + +static inline tgfx::BackendSemaphore ToTGFX(const BackendSemaphore& semaphore) { + return *reinterpret_cast(&semaphore); +} + +static inline const tgfx::Matrix* ToTGFX(const Matrix* matrix) { + return reinterpret_cast(matrix); +} + +static inline tgfx::Matrix* ToTGFX(Matrix* matrix) { + return reinterpret_cast(matrix); +} + +static inline tgfx::Matrix ToTGFX(const Matrix& matrix) { + return *ToTGFX(&matrix); +} + +static inline Matrix ToPAG(const tgfx::Matrix& matrix) { + return *reinterpret_cast(&matrix); +} + +static inline Matrix* ToPAG(tgfx::Matrix* matrix) { + return reinterpret_cast(matrix); +} + +static inline const tgfx::Rect* ToTGFX(const Rect* rect) { + return reinterpret_cast(rect); +} + +static inline tgfx::Rect* ToTGFX(Rect* rect) { + return reinterpret_cast(rect); +} + +static inline tgfx::Rect ToTGFX(const Rect& rect) { + return *ToTGFX(&rect); +} + +static inline const tgfx::Point* ToTGFX(const Point* point) { + return reinterpret_cast(point); +} + +static inline Rect ToPAG(const tgfx::Rect& rect) { + return *reinterpret_cast(&rect); +} + +static inline Rect* ToPAG(tgfx::Rect* rect) { + return reinterpret_cast(rect); +} + +static inline tgfx::Point* ToTGFX(Point* point) { + return reinterpret_cast(point); +} + +static inline tgfx::Point ToTGFX(const Point& point) { + return {point.x, point.y}; +} + +static inline Point ToPAG(const tgfx::Point& point) { + return {point.x, point.y}; +} + +static inline Point* ToPAG(tgfx::Point* point) { + return reinterpret_cast(point); +} + +} // namespace pag diff --git a/src/platform/Platform.cpp b/src/platform/Platform.cpp index 4a91d4dd04..97775eb2de 100644 --- a/src/platform/Platform.cpp +++ b/src/platform/Platform.cpp @@ -38,6 +38,6 @@ NALUType Platform::naluType() const { return NALUType::AnnexB; } -void Platform::traceImage(const ImageInfo&, const void*, const std::string&) const { +void Platform::traceImage(const tgfx::ImageInfo&, const void*, const std::string&) const { } } // namespace pag \ No newline at end of file diff --git a/src/platform/Platform.h b/src/platform/Platform.h index 8d9ae16c47..0b61512e73 100644 --- a/src/platform/Platform.h +++ b/src/platform/Platform.h @@ -23,12 +23,12 @@ #include #include #include "codec/NALUType.h" +#include "core/Data.h" #include "core/ImageInfo.h" namespace pag { struct VideoConfig; class VideoDecoder; -class Data; /** * Defines methods for native platforms to implement. @@ -68,6 +68,7 @@ class Platform { /** * Provides a utility to view the PixelMap data. */ - virtual void traceImage(const ImageInfo& info, const void* pixels, const std::string& tag) const; + virtual void traceImage(const tgfx::ImageInfo& info, const void* pixels, + const std::string& tag) const; }; } // namespace pag \ No newline at end of file diff --git a/src/platform/android/GPUDrawable.cpp b/src/platform/android/GPUDrawable.cpp index 809bdd7c0e..d0306fc8d3 100644 --- a/src/platform/android/GPUDrawable.cpp +++ b/src/platform/android/GPUDrawable.cpp @@ -46,21 +46,21 @@ void GPUDrawable::updateSize() { } } -std::shared_ptr GPUDrawable::getDevice() { +std::shared_ptr GPUDrawable::getDevice() { if (_width <= 0 || _height <= 0) { return nullptr; } if (window == nullptr) { - window = EGLWindow::MakeFrom(nativeWindow, sharedContext); + window = tgfx::EGLWindow::MakeFrom(nativeWindow, sharedContext); } return window ? window->getDevice() : nullptr; } -std::shared_ptr GPUDrawable::createSurface(Context* context) { +std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) { return window ? window->createSurface(context) : nullptr; } -void GPUDrawable::present(Context* context) { +void GPUDrawable::present(tgfx::Context* context) { if (window == nullptr) { return; } diff --git a/src/platform/android/GPUDrawable.h b/src/platform/android/GPUDrawable.h index 0e7cade712..d82e186b77 100644 --- a/src/platform/android/GPUDrawable.h +++ b/src/platform/android/GPUDrawable.h @@ -41,11 +41,11 @@ class GPUDrawable : public Drawable { void updateSize() override; - std::shared_ptr getDevice() override; + std::shared_ptr getDevice() override; - std::shared_ptr createSurface(Context* context) override; + std::shared_ptr createSurface(tgfx::Context* context) override; - void present(Context* context) override; + void present(tgfx::Context* context) override; void setTimeStamp(int64_t timeStamp) override; @@ -55,7 +55,7 @@ class GPUDrawable : public Drawable { ANativeWindow* nativeWindow = nullptr; EGLContext sharedContext = nullptr; int64_t currentTimeStamp = 0; - std::shared_ptr window = nullptr; + std::shared_ptr window = nullptr; explicit GPUDrawable(ANativeWindow* nativeWindow, EGLContext eglContext = EGL_NO_CONTEXT); }; diff --git a/src/platform/android/JNIEnvironment.cpp b/src/platform/android/JNIEnvironment.cpp index c73297fa26..a4718425f2 100644 --- a/src/platform/android/JNIEnvironment.cpp +++ b/src/platform/android/JNIEnvironment.cpp @@ -34,7 +34,7 @@ static void JNI_Thread_Destroy(void* value) { extern "C" jint JNI_OnLoad(JavaVM* vm, void*) { globalJavaVM = vm; - pag::SetJavaVM(vm); + tgfx::SetJavaVM(vm); pthread_key_create(&threadKey, JNI_Thread_Destroy); return JNI_VERSION_1_4; } diff --git a/src/platform/android/JNIHelper.cpp b/src/platform/android/JNIHelper.cpp index 34c5bd3916..57f3ea63fd 100644 --- a/src/platform/android/JNIHelper.cpp +++ b/src/platform/android/JNIHelper.cpp @@ -254,27 +254,27 @@ jobject ToPAGVideoRangeObject(JNIEnv* env, const pag::PAGVideoRange& range) { range.endTime(), range.playDuration(), range.reversed()); } -pag::ImageInfo GetImageInfo(JNIEnv* env, jobject bitmap) { +tgfx::ImageInfo GetImageInfo(JNIEnv* env, jobject bitmap) { AndroidBitmapInfo bitmapInfo = {}; if (bitmap == nullptr || AndroidBitmap_getInfo(env, bitmap, &bitmapInfo) != 0 || (bitmapInfo.flags & BITMAP_FLAGS_IS_HARDWARE)) { return {}; } - pag::AlphaType alphaType = (bitmapInfo.flags & BITMAP_FLAGS_ALPHA_UNPREMUL) - ? pag::AlphaType::Unpremultiplied - : pag::AlphaType::Premultiplied; - pag::ColorType colorType; + tgfx::AlphaType alphaType = (bitmapInfo.flags & BITMAP_FLAGS_ALPHA_UNPREMUL) + ? tgfx::AlphaType::Unpremultiplied + : tgfx::AlphaType::Premultiplied; + tgfx::ColorType colorType; switch (bitmapInfo.format) { case ANDROID_BITMAP_FORMAT_RGBA_8888: - colorType = pag::ColorType::RGBA_8888; + colorType = tgfx::ColorType::RGBA_8888; break; case ANDROID_BITMAP_FORMAT_A_8: - colorType = pag::ColorType::ALPHA_8; + colorType = tgfx::ColorType::ALPHA_8; break; default: - colorType = pag::ColorType::Unknown; + colorType = tgfx::ColorType::Unknown; break; } - return pag::ImageInfo::Make(bitmapInfo.width, bitmapInfo.height, colorType, alphaType, - bitmapInfo.stride); + return tgfx::ImageInfo::Make(bitmapInfo.width, bitmapInfo.height, colorType, alphaType, + bitmapInfo.stride); } \ No newline at end of file diff --git a/src/platform/android/JNIHelper.h b/src/platform/android/JNIHelper.h index 7274b827c0..83c5328213 100644 --- a/src/platform/android/JNIHelper.h +++ b/src/platform/android/JNIHelper.h @@ -59,4 +59,4 @@ jobject ToPAGMarkerObject(JNIEnv* env, const pag::Marker* marker); jobject ToPAGVideoRangeObject(JNIEnv* env, const pag::PAGVideoRange& range); -pag::ImageInfo GetImageInfo(JNIEnv* env, jobject bitmap); +tgfx::ImageInfo GetImageInfo(JNIEnv* env, jobject bitmap); diff --git a/src/platform/android/JPAGImage.cpp b/src/platform/android/JPAGImage.cpp index 08352a93db..f772917d0e 100644 --- a/src/platform/android/JPAGImage.cpp +++ b/src/platform/android/JPAGImage.cpp @@ -23,6 +23,7 @@ #include #include "JNIHelper.h" #include "NativePlatform.h" +#include "base/utils/TGFXCast.h" namespace pag { static jfieldID PAGImage_nativeContext; @@ -78,7 +79,7 @@ JNIEXPORT jlong Java_org_libpag_PAGImage_LoadFromBitmap(JNIEnv* env, jclass, job return 0; } auto pagImage = PAGImage::FromPixels(pixels, info.width(), info.height(), info.rowBytes(), - info.colorType(), info.alphaType()); + ToPAG(info.colorType()), ToPAG(info.alphaType())); AndroidBitmap_unlockPixels(env, bitmap); if (pagImage == nullptr) { LOGE("PAGImage.LoadFromPixels() Invalid pixels specified."); @@ -193,7 +194,7 @@ JNIEXPORT void Java_org_libpag_PAGImage_nativeGetMatrix(JNIEnv* env, jobject thi auto matrix = image->matrix(); matrix.get9(list); } else { - Matrix matrix = {}; + tgfx::Matrix matrix = {}; matrix.setIdentity(); matrix.get9(list); } diff --git a/src/platform/android/JTraceImage.cpp b/src/platform/android/JTraceImage.cpp index fdea798c90..f6e57cb4fa 100644 --- a/src/platform/android/JTraceImage.cpp +++ b/src/platform/android/JTraceImage.cpp @@ -30,7 +30,7 @@ void JTraceImage::InitJNI(JNIEnv* env) { "(Ljava/lang/String;Ljava/nio/ByteBuffer;II)V"); } -void JTraceImage::Trace(const ImageInfo& info, const void* pixels, const std::string& tag) { +void JTraceImage::Trace(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag) { auto env = JNIEnvironment::Current(); if (env == nullptr || info.isEmpty() || pixels == nullptr) { return; @@ -41,9 +41,9 @@ void JTraceImage::Trace(const ImageInfo& info, const void* pixels, const std::st if (dstPixels == nullptr) { return; } - auto dstInfo = ImageInfo::Make(info.width(), info.height(), ColorType::RGBA_8888, - AlphaType::Premultiplied, rowBytes); - Bitmap bitmap(dstInfo, dstPixels); + auto dstInfo = tgfx::ImageInfo::Make(info.width(), info.height(), tgfx::ColorType::RGBA_8888, + tgfx::AlphaType::Premultiplied, rowBytes); + tgfx::Bitmap bitmap(dstInfo, dstPixels); bitmap.writePixels(info, pixels); Local byteBuffer = {env, MakeByteBufferObject(env, dstPixels, dstInfo.byteSize())}; Local tagString = {env, SafeConvertToJString(env, tag.c_str())}; diff --git a/src/platform/android/JTraceImage.h b/src/platform/android/JTraceImage.h index 254a42b401..5a0d3994ad 100644 --- a/src/platform/android/JTraceImage.h +++ b/src/platform/android/JTraceImage.h @@ -25,6 +25,6 @@ class JTraceImage { public: static void InitJNI(JNIEnv* env); - static void Trace(const ImageInfo& info, const void* pixels, const std::string& tag); + static void Trace(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag); }; } // namespace pag diff --git a/src/platform/android/NativePlatform.cpp b/src/platform/android/NativePlatform.cpp index bde6a860ce..8d19dca760 100644 --- a/src/platform/android/NativePlatform.cpp +++ b/src/platform/android/NativePlatform.cpp @@ -62,7 +62,7 @@ bool NativePlatform::registerFallbackFonts() const { return FontConfigAndroid::RegisterFallbackFonts(); } -void NativePlatform::traceImage(const ImageInfo& info, const void* pixels, +void NativePlatform::traceImage(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag) const { JTraceImage::Trace(info, pixels, tag); } diff --git a/src/platform/android/NativePlatform.h b/src/platform/android/NativePlatform.h index bad50baa67..6556f58a0c 100644 --- a/src/platform/android/NativePlatform.h +++ b/src/platform/android/NativePlatform.h @@ -34,6 +34,7 @@ class NativePlatform : public Platform { bool registerFallbackFonts() const override; - void traceImage(const ImageInfo& info, const void* pixels, const std::string& tag) const override; + void traceImage(const tgfx::ImageInfo& info, const void* pixels, + const std::string& tag) const override; }; } // namespace pag diff --git a/src/platform/android/VideoImage.cpp b/src/platform/android/VideoImage.cpp index c197b9d32a..743a3c1c8b 100644 --- a/src/platform/android/VideoImage.cpp +++ b/src/platform/android/VideoImage.cpp @@ -34,7 +34,7 @@ VideoImage::VideoImage(std::shared_ptr videoSurface, int width, in this->videoSurface->markHasNewTextureImage(); } -std::shared_ptr VideoImage::makeTexture(Context* context) const { +std::shared_ptr VideoImage::makeTexture(tgfx::Context* context) const { std::lock_guard autoLock(locker); if (!videoSurface->attachToContext(context)) { return nullptr; diff --git a/src/platform/android/VideoImage.h b/src/platform/android/VideoImage.h index 022f59380f..28874109a7 100644 --- a/src/platform/android/VideoImage.h +++ b/src/platform/android/VideoImage.h @@ -33,7 +33,7 @@ class VideoImage : public VideoBuffer { } protected: - std::shared_ptr makeTexture(Context* context) const override; + std::shared_ptr makeTexture(tgfx::Context* context) const override; private: mutable std::mutex locker = {}; diff --git a/src/platform/android/VideoSurface.cpp b/src/platform/android/VideoSurface.cpp index c3059a8665..86312c263f 100644 --- a/src/platform/android/VideoSurface.cpp +++ b/src/platform/android/VideoSurface.cpp @@ -44,10 +44,10 @@ void VideoSurface::InitJNI(JNIEnv* env, const std::string& className) { VideoSurface_onRelease = env->GetMethodID(VideoSurfaceClass.get(), "onRelease", "()V"); } -OESTexture::OESTexture(GLTextureInfo info, int width, int height, bool hasAlpha) - : GLTexture(width, height, ImageOrigin::TopLeft), hasAlpha(hasAlpha) { +OESTexture::OESTexture(tgfx::GLTextureInfo info, int width, int height, bool hasAlpha) + : GLTexture(width, height, tgfx::ImageOrigin::TopLeft), hasAlpha(hasAlpha) { sampler.glInfo = info; - sampler.config = PixelConfig::RGBA_8888; + sampler.config = tgfx::PixelConfig::RGBA_8888; } void OESTexture::setTextureSize(int width, int height) { @@ -80,7 +80,7 @@ void OESTexture::computeTransform() { } } -Point OESTexture::getTextureCoord(float x, float y) const { +tgfx::Point OESTexture::getTextureCoord(float x, float y) const { if (hasAlpha) { // 如果有 alpha 通道,不需要缩小纹素 return {x / static_cast(textureWidth), y / static_cast(textureHeight)}; @@ -88,9 +88,9 @@ Point OESTexture::getTextureCoord(float x, float y) const { return {x / static_cast(width()) * sx + tx, y / static_cast(height()) * sy + ty}; } -void OESTexture::onRelease(pag::Context* context) { +void OESTexture::onRelease(tgfx::Context* context) { if (sampler.glInfo.id > 0) { - auto gl = GLContext::Unwrap(context); + auto gl = tgfx::GLContext::Unwrap(context); gl->deleteTextures(1, &sampler.glInfo.id); } } @@ -126,7 +126,7 @@ jobject VideoSurface::getOutputSurface(JNIEnv* env) const { return env->CallObjectMethod(videoSurface.get(), VideoSurface_getOutputSurface); } -bool VideoSurface::attachToContext(Context* context) { +bool VideoSurface::attachToContext(tgfx::Context* context) { if (oesTexture) { if (deviceID != context->device()->uniqueID()) { LOGE("VideoSurface::attachToGLContext(): VideoSurface has already attached to a Context!"); @@ -134,12 +134,12 @@ bool VideoSurface::attachToContext(Context* context) { } return true; } - auto gl = GLContext::Unwrap(context); - GLTextureInfo glInfo = {}; + auto gl = tgfx::GLContext::Unwrap(context); + tgfx::GLTextureInfo glInfo = {}; glInfo.target = GL::TEXTURE_EXTERNAL_OES; glInfo.format = GL::RGBA8; gl->genTextures(1, &glInfo.id); - oesTexture = Resource::Wrap(context, new OESTexture(glInfo, width, height, hasAlpha)); + oesTexture = tgfx::Resource::Wrap(context, new OESTexture(glInfo, width, height, hasAlpha)); auto env = JNIEnvironment::Current(); if (env == nullptr) { return false; diff --git a/src/platform/android/VideoSurface.h b/src/platform/android/VideoSurface.h index 80d960dd00..f3eeec80f6 100644 --- a/src/platform/android/VideoSurface.h +++ b/src/platform/android/VideoSurface.h @@ -22,18 +22,18 @@ #include "platform/android/Global.h" namespace pag { -class OESTexture : public GLTexture { +class OESTexture : public tgfx::GLTexture { public: - OESTexture(GLTextureInfo info, int width, int height, bool hasAlpha); + OESTexture(tgfx::GLTextureInfo info, int width, int height, bool hasAlpha); - Point getTextureCoord(float x, float y) const override; + tgfx::Point getTextureCoord(float x, float y) const override; size_t memoryUsage() const override { return 0; } protected: - void onRelease(Context* context) override; + void onRelease(tgfx::Context* context) override; private: void setTextureSize(int width, int height); @@ -63,7 +63,7 @@ class VideoSurface { jobject getOutputSurface(JNIEnv* env) const; - bool attachToContext(Context* context); + bool attachToContext(tgfx::Context* context); bool updateTexImage(); @@ -76,7 +76,7 @@ class VideoSurface { int width = 0; int height = 0; bool hasAlpha = false; - ID deviceID = 0; + uint32_t deviceID = 0; std::shared_ptr oesTexture = nullptr; mutable std::atomic_bool hasPendingTextureImage = {false}; diff --git a/src/platform/cocoa/private/CocoaPlatform.h b/src/platform/cocoa/private/CocoaPlatform.h index 4067430956..19d4653b3a 100644 --- a/src/platform/cocoa/private/CocoaPlatform.h +++ b/src/platform/cocoa/private/CocoaPlatform.h @@ -33,6 +33,7 @@ class CocoaPlatform : public Platform { return NALUType::AVCC; } - void traceImage(const ImageInfo& info, const void* pixels, const std::string& tag) const override; + void traceImage(const tgfx::ImageInfo& info, const void* pixels, + const std::string& tag) const override; }; } // namespace pag diff --git a/src/platform/cocoa/private/CocoaPlatform.mm b/src/platform/cocoa/private/CocoaPlatform.mm index 29590acc02..3edd1806f2 100644 --- a/src/platform/cocoa/private/CocoaPlatform.mm +++ b/src/platform/cocoa/private/CocoaPlatform.mm @@ -51,7 +51,7 @@ return true; } -void CocoaPlatform::traceImage(const ImageInfo& info, const void* pixels, +void CocoaPlatform::traceImage(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag) const { TraceImage(info, pixels, tag); } diff --git a/src/platform/cocoa/private/PAGImageImpl.mm b/src/platform/cocoa/private/PAGImageImpl.mm index f71577aecb..030a0649dc 100644 --- a/src/platform/cocoa/private/PAGImageImpl.mm +++ b/src/platform/cocoa/private/PAGImageImpl.mm @@ -62,7 +62,7 @@ + (PAGImageImpl*)FromPixelBuffer:(CVPixelBufferRef)pixelBuffer { #else + (PAGImageImpl*)FromPixelBuffer:(CVPixelBufferRef)pixelBuffer { - auto hardwareBuffer = pag::PixelBuffer::MakeFrom(pixelBuffer); + auto hardwareBuffer = tgfx::PixelBuffer::MakeFrom(pixelBuffer); auto image = pag::StillImage::FromPixelBuffer(hardwareBuffer); if (image == nullptr) { return nil; @@ -78,8 +78,8 @@ + (PAGImageImpl*)FromCGImage:(CGImageRef)cgImage { } auto width = static_cast(CGImageGetWidth(cgImage)); auto height = static_cast(CGImageGetHeight(cgImage)); - auto pixelBuffer = pag::PixelBuffer::Make(width, height); - pag::Bitmap bitmap(pixelBuffer); + auto pixelBuffer = tgfx::PixelBuffer::Make(width, height); + tgfx::Bitmap bitmap(pixelBuffer); if (bitmap.isEmpty()) { return nil; } diff --git a/src/platform/cocoa/private/TraceImage.h b/src/platform/cocoa/private/TraceImage.h index 8b27ebb9b7..d3d9ca130d 100644 --- a/src/platform/cocoa/private/TraceImage.h +++ b/src/platform/cocoa/private/TraceImage.h @@ -21,5 +21,5 @@ #include "core/ImageInfo.h" namespace pag { -void TraceImage(const ImageInfo& info, const void* pixels, const std::string& tag); +void TraceImage(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag); } diff --git a/src/platform/cocoa/private/TraceImage.mm b/src/platform/cocoa/private/TraceImage.mm index 979ac7fd44..9fc310cdc7 100644 --- a/src/platform/cocoa/private/TraceImage.mm +++ b/src/platform/cocoa/private/TraceImage.mm @@ -22,7 +22,7 @@ #include "core/Bitmap.h" namespace pag { -void TraceImage(const ImageInfo& info, const void* pixels, const std::string& tag) { +void TraceImage(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag) { if (info.isEmpty() || pixels == nullptr) { return; } @@ -34,9 +34,9 @@ void TraceImage(const ImageInfo& info, const void* pixels, const std::string& ta CVPixelBufferLockBaseAddress(pixelBuffer, 0); auto dstPixels = CVPixelBufferGetBaseAddress(pixelBuffer); auto rowBytes = CVPixelBufferGetBytesPerRow(pixelBuffer); - auto dstInfo = ImageInfo::Make(info.width(), info.height(), ColorType::BGRA_8888, - AlphaType::Premultiplied, rowBytes); - Bitmap bitmap(dstInfo, dstPixels); + auto dstInfo = tgfx::ImageInfo::Make(info.width(), info.height(), tgfx::ColorType::BGRA_8888, + tgfx::AlphaType::Premultiplied, rowBytes); + tgfx::Bitmap bitmap(dstInfo, dstPixels); bitmap.writePixels(info, pixels); CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); LOGI("%s : Image(width = %d, height = %d)", tag.c_str(), info.width(), info.height()); diff --git a/src/platform/ios/private/GPUDecoder.h b/src/platform/ios/private/GPUDecoder.h index ce43712c4f..39820ecc58 100644 --- a/src/platform/ios/private/GPUDecoder.h +++ b/src/platform/ios/private/GPUDecoder.h @@ -48,9 +48,9 @@ class GPUDecoder : public VideoDecoder { private: VTDecompressionSessionRef session = nullptr; CMFormatDescriptionRef videoFormatDescription = nullptr; - YUVColorSpace sourceColorSpace = YUVColorSpace::Rec601; - YUVColorSpace destinationColorSpace = YUVColorSpace::Rec601; - YUVColorRange colorRange = YUVColorRange::MPEG; + tgfx::YUVColorSpace sourceColorSpace = tgfx::YUVColorSpace::Rec601; + tgfx::YUVColorSpace destinationColorSpace = tgfx::YUVColorSpace::Rec601; + tgfx::YUVColorRange colorRange = tgfx::YUVColorRange::MPEG; bool initVideoToolBox(const std::vector>& headers, const std::string& mimeType); diff --git a/src/platform/ios/private/GPUDecoder.mm b/src/platform/ios/private/GPUDecoder.mm index d4f131f27e..e4b5d393e4 100644 --- a/src/platform/ios/private/GPUDecoder.mm +++ b/src/platform/ios/private/GPUDecoder.mm @@ -150,7 +150,7 @@ void initParameterSets(const std::vector>& headers, kCVPixelBufferIOSurfacePropertiesKey}; uint32_t openGLESCompatibility = true; - uint32_t pixelFormatType = colorRange == YUVColorRange::JPEG + uint32_t pixelFormatType = colorRange == tgfx::YUVColorRange::JPEG ? kCVPixelFormatType_420YpCbCr8BiPlanarFullRange : kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange; @@ -178,7 +178,7 @@ void initParameterSets(const std::vector>& headers, CFRelease(ioSurfaceParam); if (@available(iOS 10.0, *)) { - if (sourceColorSpace == YUVColorSpace::Rec2020) { + if (sourceColorSpace == tgfx::YUVColorSpace::Rec2020) { CFStringRef destinationColorPrimaries = CFStringCreateWithCString( kCFAllocatorDefault, "DestinationColorPrimaries", kCFStringEncodingUTF8); CFStringRef destinationTransferFunction = CFStringCreateWithCString( @@ -203,7 +203,7 @@ void initParameterSets(const std::vector>& headers, CFRelease(destinationYCbCrMatrix); CFRelease(pixelTransferProperties); - destinationColorSpace = YUVColorSpace::Rec709; + destinationColorSpace = tgfx::YUVColorSpace::Rec709; } } diff --git a/src/platform/ios/private/GPUDrawable.h b/src/platform/ios/private/GPUDrawable.h index 6e5f8c0a8d..9f50d7024e 100644 --- a/src/platform/ios/private/GPUDrawable.h +++ b/src/platform/ios/private/GPUDrawable.h @@ -41,11 +41,11 @@ class GPUDrawable : public Drawable { void updateSize() override; - std::shared_ptr getDevice() override; + std::shared_ptr getDevice() override; - std::shared_ptr createSurface(Context* context) override; + std::shared_ptr createSurface(tgfx::Context* context) override; - void present(Context* context) override; + void present(tgfx::Context* context) override; CVPixelBufferRef getCVPixelBuffer(); @@ -56,8 +56,8 @@ class GPUDrawable : public Drawable { CAEAGLLayer* layer = nil; CVPixelBufferRef pixelBuffer = nil; EAGLContext* eaglContext = nil; - std::shared_ptr window = nullptr; - std::shared_ptr surface = nullptr; + std::shared_ptr window = nullptr; + std::shared_ptr surface = nullptr; std::atomic bufferPreparing; static bool IsInMainThread(); diff --git a/src/platform/ios/private/GPUDrawable.mm b/src/platform/ios/private/GPUDrawable.mm index 7dc709988f..03f59c1cb0 100644 --- a/src/platform/ios/private/GPUDrawable.mm +++ b/src/platform/ios/private/GPUDrawable.mm @@ -88,22 +88,22 @@ surface = nullptr; } -std::shared_ptr GPUDrawable::getDevice() { +std::shared_ptr GPUDrawable::getDevice() { if (_width <= 0 || _height <= 0) { return nullptr; } if (window == nullptr) { - auto device = EAGLDevice::MakeAdopted(eaglContext); + auto device = tgfx::EAGLDevice::MakeAdopted(eaglContext); if (pixelBuffer) { - window = EAGLWindow::MakeFrom(pixelBuffer, device); + window = tgfx::EAGLWindow::MakeFrom(pixelBuffer, device); } else { - window = EAGLWindow::MakeFrom(layer, device); + window = tgfx::EAGLWindow::MakeFrom(layer, device); } } return window ? window->getDevice() : nullptr; } -std::shared_ptr GPUDrawable::createSurface(Context* context) { +std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) { if (window == nullptr || bufferPreparing) { return nullptr; } @@ -151,7 +151,7 @@ } } -void GPUDrawable::present(Context* context) { +void GPUDrawable::present(tgfx::Context* context) { if (window == nullptr) { return; } diff --git a/src/platform/ios/private/VideoImage.h b/src/platform/ios/private/VideoImage.h index 9076c58ca8..ef51d7b073 100644 --- a/src/platform/ios/private/VideoImage.h +++ b/src/platform/ios/private/VideoImage.h @@ -24,22 +24,24 @@ namespace pag { class VideoImage : public VideoBuffer { public: static std::shared_ptr MakeFrom(CVPixelBufferRef pixelBuffer, - YUVColorSpace colorSpace, YUVColorRange colorRange); + tgfx::YUVColorSpace colorSpace, + tgfx::YUVColorRange colorRange); ~VideoImage() override; size_t planeCount() const override; protected: - std::shared_ptr makeTexture(Context* context) const override { - return YUVTexture::MakeFrom(context, _colorSpace, _colorRange, pixelBuffer); + std::shared_ptr makeTexture(tgfx::Context* context) const override { + return tgfx::YUVTexture::MakeFrom(context, _colorSpace, _colorRange, pixelBuffer); } private: CVPixelBufferRef pixelBuffer = nullptr; - YUVColorSpace _colorSpace = YUVColorSpace::Rec601; - YUVColorRange _colorRange = YUVColorRange::MPEG; + tgfx::YUVColorSpace _colorSpace = tgfx::YUVColorSpace::Rec601; + tgfx::YUVColorRange _colorRange = tgfx::YUVColorRange::MPEG; - VideoImage(CVPixelBufferRef pixelBuffer, YUVColorSpace colorSpace, YUVColorRange colorRange); + VideoImage(CVPixelBufferRef pixelBuffer, tgfx::YUVColorSpace colorSpace, + tgfx::YUVColorRange colorRange); }; } // namespace pag diff --git a/src/platform/ios/private/VideoImage.mm b/src/platform/ios/private/VideoImage.mm index a1b38efa02..a9bab229d2 100644 --- a/src/platform/ios/private/VideoImage.mm +++ b/src/platform/ios/private/VideoImage.mm @@ -25,8 +25,8 @@ static std::unordered_map> videoImageMap = {}; std::shared_ptr VideoImage::MakeFrom(CVPixelBufferRef pixelBuffer, - YUVColorSpace colorSpace, - YUVColorRange colorRange) { + tgfx::YUVColorSpace colorSpace, + tgfx::YUVColorRange colorRange) { if (pixelBuffer == nil) { return nullptr; } @@ -50,8 +50,8 @@ return videoImage; } -VideoImage::VideoImage(CVPixelBufferRef pixelBuffer, YUVColorSpace colorSpace, - YUVColorRange colorRange) +VideoImage::VideoImage(CVPixelBufferRef pixelBuffer, tgfx::YUVColorSpace colorSpace, + tgfx::YUVColorRange colorRange) : VideoBuffer(static_cast(CVPixelBufferGetWidth(pixelBuffer)), static_cast(CVPixelBufferGetHeight(pixelBuffer))), pixelBuffer(pixelBuffer), diff --git a/src/platform/mac/private/GPUDecoder.h b/src/platform/mac/private/GPUDecoder.h index 96ab7150cc..367d6e7902 100644 --- a/src/platform/mac/private/GPUDecoder.h +++ b/src/platform/mac/private/GPUDecoder.h @@ -48,7 +48,7 @@ class GPUDecoder : public VideoDecoder { private: VTDecompressionSessionRef session = nullptr; CMFormatDescriptionRef videoFormatDescription = nullptr; - YUVColorSpace colorSpace = YUVColorSpace::Rec601; + tgfx::YUVColorSpace colorSpace = tgfx::YUVColorSpace::Rec601; bool initVideoToolBox(const std::vector>& headers, const std::string& mimeType); diff --git a/src/platform/mac/private/GPUDecoder.mm b/src/platform/mac/private/GPUDecoder.mm index bd76f62a67..5c2cea1238 100644 --- a/src/platform/mac/private/GPUDecoder.mm +++ b/src/platform/mac/private/GPUDecoder.mm @@ -167,7 +167,7 @@ void initParameterSets(const std::vector>& headers, CFRelease(openGLCompatibilityValue); CFRelease(ioSurfaceParam); - if (colorSpace == YUVColorSpace::Rec2020) { + if (colorSpace == tgfx::YUVColorSpace::Rec2020) { CFMutableDictionaryRef pixelTransferProperties = CFDictionaryCreateMutable( kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(pixelTransferProperties, diff --git a/src/platform/mac/private/GPUDrawable.h b/src/platform/mac/private/GPUDrawable.h index 92241f4659..21795e592c 100644 --- a/src/platform/mac/private/GPUDrawable.h +++ b/src/platform/mac/private/GPUDrawable.h @@ -40,18 +40,18 @@ class GPUDrawable : public Drawable { void updateSize() override; - std::shared_ptr getDevice() override; + std::shared_ptr getDevice() override; - std::shared_ptr createSurface(Context* context) override; + std::shared_ptr createSurface(tgfx::Context* context) override; - void present(Context* context) override; + void present(tgfx::Context* context) override; private: int _width = 0; int _height = 0; NSView* view = nil; CVPixelBufferRef pixelBuffer = nil; - std::shared_ptr window = nullptr; + std::shared_ptr window = nullptr; explicit GPUDrawable(NSView* view); explicit GPUDrawable(CVPixelBufferRef pixelBuffer); diff --git a/src/platform/mac/private/GPUDrawable.mm b/src/platform/mac/private/GPUDrawable.mm index 8d014342c6..5237868e7e 100644 --- a/src/platform/mac/private/GPUDrawable.mm +++ b/src/platform/mac/private/GPUDrawable.mm @@ -68,29 +68,29 @@ _height = static_cast(floor(height)); } -std::shared_ptr GPUDrawable::getDevice() { +std::shared_ptr GPUDrawable::getDevice() { if (_width <= 0 || _height <= 0) { return nullptr; } if (window == nullptr) { if (pixelBuffer) { - auto device = std::static_pointer_cast(GLDevice::Make()); - window = CGLWindow::MakeFrom(pixelBuffer, device); + auto device = std::static_pointer_cast(tgfx::GLDevice::Make()); + window = tgfx::CGLWindow::MakeFrom(pixelBuffer, device); } else { - window = CGLWindow::MakeFrom(view); + window = tgfx::CGLWindow::MakeFrom(view); } } return window ? window->getDevice() : nullptr; } -std::shared_ptr GPUDrawable::createSurface(Context* context) { +std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) { if (window == nullptr) { return nullptr; } return window->createSurface(context); } -void GPUDrawable::present(Context* context) { +void GPUDrawable::present(tgfx::Context* context) { if (window == nullptr) { return; } diff --git a/src/platform/mac/private/VideoImage.h b/src/platform/mac/private/VideoImage.h index 82ea45eef8..108c5780ef 100644 --- a/src/platform/mac/private/VideoImage.h +++ b/src/platform/mac/private/VideoImage.h @@ -30,8 +30,8 @@ class VideoImage : public VideoBuffer { size_t planeCount() const override; protected: - std::shared_ptr makeTexture(Context* context) const override { - return Texture::MakeFrom(context, pixelBuffer); + std::shared_ptr makeTexture(tgfx::Context* context) const override { + return tgfx::Texture::MakeFrom(context, pixelBuffer); } private: diff --git a/src/platform/qt/GPUDrawable.cpp b/src/platform/qt/GPUDrawable.cpp index 82c45c1aca..d072213e24 100644 --- a/src/platform/qt/GPUDrawable.cpp +++ b/src/platform/qt/GPUDrawable.cpp @@ -24,14 +24,14 @@ namespace pag { std::shared_ptr GPUDrawable::MakeFrom(QQuickItem* quickItem, QOpenGLContext* sharedContext) { - auto window = QGLWindow::MakeFrom(quickItem, sharedContext); + auto window = tgfx::QGLWindow::MakeFrom(quickItem, sharedContext); if (window == nullptr) { return nullptr; } return std::shared_ptr(new GPUDrawable(quickItem, std::move(window))); } -GPUDrawable::GPUDrawable(QQuickItem* quickItem, std::shared_ptr window) +GPUDrawable::GPUDrawable(QQuickItem* quickItem, std::shared_ptr window) : quickItem(quickItem), window(std::move(window)) { GPUDrawable::updateSize(); } @@ -43,18 +43,18 @@ void GPUDrawable::updateSize() { _height = static_cast(ceil(quickItem->height() * pixelRatio)); } -std::shared_ptr GPUDrawable::getDevice() { +std::shared_ptr GPUDrawable::getDevice() { if (_width <= 0 || _height <= 0) { return nullptr; } return window->getDevice(); } -std::shared_ptr GPUDrawable::createSurface(Context* context) { +std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) { return window->createSurface(context); } -void GPUDrawable::present(Context* context) { +void GPUDrawable::present(tgfx::Context* context) { window->present(context); } diff --git a/src/platform/qt/GPUDrawable.h b/src/platform/qt/GPUDrawable.h index be9ed0440f..87df32b02e 100644 --- a/src/platform/qt/GPUDrawable.h +++ b/src/platform/qt/GPUDrawable.h @@ -26,9 +26,11 @@ #pragma clang diagnostic pop #include "pag/pag.h" -namespace pag { +namespace tgfx { class QGLWindow; +} +namespace pag { class GPUDrawable : public Drawable { public: static std::shared_ptr MakeFrom(QQuickItem* quickItem, @@ -44,11 +46,11 @@ class GPUDrawable : public Drawable { void updateSize() override; - std::shared_ptr getDevice() override; + std::shared_ptr getDevice() override; - std::shared_ptr createSurface(Context* context) override; + std::shared_ptr createSurface(tgfx::Context* context) override; - void present(Context* context) override; + void present(tgfx::Context* context) override; void moveToThread(QThread* targetThread); @@ -58,8 +60,8 @@ class GPUDrawable : public Drawable { int _width = 0; int _height = 0; QQuickItem* quickItem = nullptr; - std::shared_ptr window = nullptr; + std::shared_ptr window = nullptr; - GPUDrawable(QQuickItem* quickItem, std::shared_ptr window); + GPUDrawable(QQuickItem* quickItem, std::shared_ptr window); }; } // namespace pag diff --git a/src/platform/swiftshader/NativePlatform.cpp b/src/platform/swiftshader/NativePlatform.cpp index c05220e986..f517ca8e0f 100644 --- a/src/platform/swiftshader/NativePlatform.cpp +++ b/src/platform/swiftshader/NativePlatform.cpp @@ -37,7 +37,7 @@ void NativePlatform::setNALUType(NALUType type) const { defaultType = type; } -void NativePlatform::traceImage(const ImageInfo& info, const void* pixels, +void NativePlatform::traceImage(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag) const { std::string path = tag; if (path.empty()) { @@ -45,7 +45,7 @@ void NativePlatform::traceImage(const ImageInfo& info, const void* pixels, } else if (path.rfind(".png") != path.size() - 4 && path.rfind(".PNG") != path.size() - 4) { path += ".png"; } - auto bytes = Bitmap(info, pixels).encode(EncodedFormat::PNG, 100); + auto bytes = tgfx::Bitmap(info, pixels).encode(tgfx::EncodedFormat::PNG, 100); if (bytes) { std::ofstream out(path); out.write(reinterpret_cast(bytes->data()), bytes->size()); diff --git a/src/platform/swiftshader/NativePlatform.h b/src/platform/swiftshader/NativePlatform.h index 9c99b65692..66ac42b7d3 100644 --- a/src/platform/swiftshader/NativePlatform.h +++ b/src/platform/swiftshader/NativePlatform.h @@ -27,6 +27,7 @@ class NativePlatform : public Platform { void setNALUType(NALUType type) const; - void traceImage(const ImageInfo& info, const void* pixels, const std::string& tag) const override; + void traceImage(const tgfx::ImageInfo& info, const void* pixels, + const std::string& tag) const override; }; } // namespace pag diff --git a/src/platform/web/GPUDrawable.cpp b/src/platform/web/GPUDrawable.cpp index 7b94b92867..eeacd540a1 100644 --- a/src/platform/web/GPUDrawable.cpp +++ b/src/platform/web/GPUDrawable.cpp @@ -40,17 +40,17 @@ void GPUDrawable::updateSize() { } } -std::shared_ptr GPUDrawable::getDevice() { +std::shared_ptr GPUDrawable::getDevice() { if (_width <= 0 || _height <= 0) { return nullptr; } if (window == nullptr) { - window = WebGLWindow::MakeFrom(canvasID); + window = tgfx::WebGLWindow::MakeFrom(canvasID); } return window->getDevice(); } -std::shared_ptr GPUDrawable::createSurface(Context* context) { +std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) { return window ? window->createSurface(context) : nullptr; } } // namespace pag diff --git a/src/platform/web/GPUDrawable.h b/src/platform/web/GPUDrawable.h index a5738282d5..cece968c7f 100644 --- a/src/platform/web/GPUDrawable.h +++ b/src/platform/web/GPUDrawable.h @@ -18,7 +18,7 @@ #pragma once -#include "gpu/opengl/webgl//WebGLWindow.h" +#include "gpu/opengl/webgl/WebGLWindow.h" #include "pag/pag.h" namespace pag { @@ -36,11 +36,11 @@ class GPUDrawable : public Drawable { void updateSize() override; - std::shared_ptr getDevice() override; + std::shared_ptr getDevice() override; - std::shared_ptr createSurface(Context* context) override; + std::shared_ptr createSurface(tgfx::Context* context) override; - void present(Context*) override { + void present(tgfx::Context*) override { } private: @@ -49,6 +49,6 @@ class GPUDrawable : public Drawable { std::string canvasID; int _width = 0; int _height = 0; - std::shared_ptr window = nullptr; + std::shared_ptr window = nullptr; }; } // namespace pag diff --git a/src/platform/web/NativePlatform.cpp b/src/platform/web/NativePlatform.cpp index 8015fcef01..3a1ef9cafa 100644 --- a/src/platform/web/NativePlatform.cpp +++ b/src/platform/web/NativePlatform.cpp @@ -27,7 +27,7 @@ const Platform* Platform::Current() { return &platform; } -void NativePlatform::traceImage(const ImageInfo& info, const void* pixels, +void NativePlatform::traceImage(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag) const { auto traceImage = val::module_property("traceImage"); auto bytes = val(typed_memory_view(info.byteSize(), static_cast(pixels))); diff --git a/src/platform/web/NativePlatform.h b/src/platform/web/NativePlatform.h index f8b1227f77..2ae7fe5e5a 100644 --- a/src/platform/web/NativePlatform.h +++ b/src/platform/web/NativePlatform.h @@ -23,6 +23,7 @@ namespace pag { class NativePlatform : public Platform { public: - void traceImage(const ImageInfo& info, const void* pixels, const std::string& tag) const override; + void traceImage(const tgfx::ImageInfo& info, const void* pixels, + const std::string& tag) const override; }; } // namespace pag diff --git a/src/platform/web/VideoSequenceReader.cpp b/src/platform/web/VideoSequenceReader.cpp index 1b9deddabd..d1d7d02ac1 100644 --- a/src/platform/web/VideoSequenceReader.cpp +++ b/src/platform/web/VideoSequenceReader.cpp @@ -73,18 +73,19 @@ void VideoSequenceReader::prepareAsync(Frame targetFrame) { } } -std::shared_ptr VideoSequenceReader::readTexture(Frame targetFrame, RenderCache* cache) { +std::shared_ptr VideoSequenceReader::readTexture(Frame targetFrame, + RenderCache* cache) { if (!videoReader.as()) { return nullptr; } if (targetFrame == lastFrame) { return texture; } - GLStateGuard stateGuard(cache->getContext()); + tgfx::GLStateGuard stateGuard(cache->getContext()); if (texture == nullptr) { - texture = GLTexture::MakeRGBA(cache->getContext(), width, height); + texture = tgfx::GLTexture::MakeRGBA(cache->getContext(), width, height); } - auto& glInfo = std::static_pointer_cast(texture)->getGLInfo(); + auto& glInfo = std::static_pointer_cast(texture)->getGLInfo(); videoReader.call("renderToTexture", val::module_property("GL"), glInfo.id); lastFrame = targetFrame; return texture; diff --git a/src/platform/web/VideoSequenceReader.h b/src/platform/web/VideoSequenceReader.h index d48f976a7a..a70b65035b 100644 --- a/src/platform/web/VideoSequenceReader.h +++ b/src/platform/web/VideoSequenceReader.h @@ -30,12 +30,12 @@ class VideoSequenceReader : public SequenceReader { void prepareAsync(Frame targetFrame) override; - std::shared_ptr readTexture(Frame targetFrame, RenderCache* cache) override; + std::shared_ptr readTexture(Frame targetFrame, RenderCache* cache) override; private: Frame lastFrame = -1; emscripten::val videoReader = emscripten::val::null(); - std::shared_ptr texture = nullptr; + std::shared_ptr texture = nullptr; int32_t width = 0; int32_t height = 0; }; diff --git a/src/platform/win/GPUDrawable.cpp b/src/platform/win/GPUDrawable.cpp index a329b6ddaf..040cb03c41 100644 --- a/src/platform/win/GPUDrawable.cpp +++ b/src/platform/win/GPUDrawable.cpp @@ -48,22 +48,22 @@ void GPUDrawable::updateSize() { } } -std::shared_ptr GPUDrawable::getDevice() { +std::shared_ptr GPUDrawable::getDevice() { if (_width <= 0 || _height <= 0) { return nullptr; } if (window == nullptr) { - window = - EGLWindow::MakeFrom(reinterpret_cast(nativeWindow), sharedContext); + window = tgfx::EGLWindow::MakeFrom(reinterpret_cast(nativeWindow), + sharedContext); } return window ? window->getDevice() : nullptr; } -std::shared_ptr GPUDrawable::createSurface(Context* context) { +std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) { return window ? window->createSurface(context) : nullptr; } -void GPUDrawable::present(Context* context) { +void GPUDrawable::present(tgfx::Context* context) { window->present(context); } } // namespace pag diff --git a/src/platform/win/GPUDrawable.h b/src/platform/win/GPUDrawable.h index 489f7a6e7b..7504898ca3 100644 --- a/src/platform/win/GPUDrawable.h +++ b/src/platform/win/GPUDrawable.h @@ -20,9 +20,11 @@ #include "pag/pag.h" -namespace pag { +namespace tgfx { class EGLWindow; +} +namespace pag { class GPUDrawable : public Drawable { public: static std::shared_ptr FromWindow(void* nativeWindow, void* sharedContext = nullptr); @@ -37,16 +39,16 @@ class GPUDrawable : public Drawable { void updateSize() override; - std::shared_ptr getDevice() override; + std::shared_ptr getDevice() override; - std::shared_ptr createSurface(Context* context) override; + std::shared_ptr createSurface(tgfx::Context* context) override; - void present(Context* context) override; + void present(tgfx::Context* context) override; private: int _width = 0; int _height = 0; - std::shared_ptr window = nullptr; + std::shared_ptr window = nullptr; void* nativeWindow = nullptr; void* sharedContext = nullptr; diff --git a/src/rendering/Drawable.cpp b/src/rendering/Drawable.cpp index 3be4787de0..0b899de9d0 100644 --- a/src/rendering/Drawable.cpp +++ b/src/rendering/Drawable.cpp @@ -17,32 +17,33 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "Drawable.h" +#include "base/utils/TGFXCast.h" namespace pag { -RenderTargetDrawable::RenderTargetDrawable(std::shared_ptr device, - const BackendRenderTarget& renderTarget, - ImageOrigin origin) +RenderTargetDrawable::RenderTargetDrawable(std::shared_ptr device, + const tgfx::BackendRenderTarget& renderTarget, + tgfx::ImageOrigin origin) : device(std::move(device)), renderTarget(renderTarget), origin(origin) { } -std::shared_ptr RenderTargetDrawable::createSurface(Context* context) { - return Surface::MakeFrom(context, renderTarget, origin); +std::shared_ptr RenderTargetDrawable::createSurface(tgfx::Context* context) { + return tgfx::Surface::MakeFrom(context, renderTarget, origin); } -TextureDrawable::TextureDrawable(std::shared_ptr device, const BackendTexture& texture, - ImageOrigin origin) +TextureDrawable::TextureDrawable(std::shared_ptr device, + const tgfx::BackendTexture& texture, tgfx::ImageOrigin origin) : device(std::move(device)), texture(texture), origin(origin) { } -std::shared_ptr TextureDrawable::createSurface(Context* context) { - return Surface::MakeFrom(context, texture, origin); +std::shared_ptr TextureDrawable::createSurface(tgfx::Context* context) { + return tgfx::Surface::MakeFrom(context, texture, origin); } -OffscreenDrawable::OffscreenDrawable(int width, int height, std::shared_ptr device) +OffscreenDrawable::OffscreenDrawable(int width, int height, std::shared_ptr device) : _width(width), _height(height), device(std::move(device)) { } -std::shared_ptr OffscreenDrawable::createSurface(Context* context) { - return Surface::Make(context, _width, _height); +std::shared_ptr OffscreenDrawable::createSurface(tgfx::Context* context) { + return tgfx::Surface::Make(context, _width, _height); } } // namespace pag \ No newline at end of file diff --git a/src/rendering/Drawable.h b/src/rendering/Drawable.h index 27dcfad125..b29bd5ffeb 100644 --- a/src/rendering/Drawable.h +++ b/src/rendering/Drawable.h @@ -24,8 +24,8 @@ namespace pag { class RenderTargetDrawable : public Drawable { public: - RenderTargetDrawable(std::shared_ptr device, const BackendRenderTarget& renderTarget, - ImageOrigin origin); + RenderTargetDrawable(std::shared_ptr device, + const tgfx::BackendRenderTarget& renderTarget, tgfx::ImageOrigin origin); int width() const override { return renderTarget.width(); @@ -38,25 +38,25 @@ class RenderTargetDrawable : public Drawable { void updateSize() override { } - std::shared_ptr getDevice() override { + std::shared_ptr getDevice() override { return device; } - std::shared_ptr createSurface(Context* context) override; + std::shared_ptr createSurface(tgfx::Context* context) override; - void present(Context*) override { + void present(tgfx::Context*) override { } private: - std::shared_ptr device = nullptr; - BackendRenderTarget renderTarget = {}; - ImageOrigin origin = ImageOrigin::TopLeft; + std::shared_ptr device = nullptr; + tgfx::BackendRenderTarget renderTarget = {}; + tgfx::ImageOrigin origin = tgfx::ImageOrigin::TopLeft; }; class TextureDrawable : public Drawable { public: - TextureDrawable(std::shared_ptr device, const BackendTexture& texture, - ImageOrigin origin); + TextureDrawable(std::shared_ptr device, const tgfx::BackendTexture& texture, + tgfx::ImageOrigin origin); int width() const override { return texture.width(); @@ -69,24 +69,24 @@ class TextureDrawable : public Drawable { void updateSize() override { } - std::shared_ptr getDevice() override { + std::shared_ptr getDevice() override { return device; } - std::shared_ptr createSurface(Context* context) override; + std::shared_ptr createSurface(tgfx::Context* context) override; - void present(Context*) override { + void present(tgfx::Context*) override { } private: - std::shared_ptr device = nullptr; - BackendTexture texture = {}; - ImageOrigin origin = ImageOrigin::TopLeft; + std::shared_ptr device = nullptr; + tgfx::BackendTexture texture = {}; + tgfx::ImageOrigin origin = tgfx::ImageOrigin::TopLeft; }; class OffscreenDrawable : public Drawable { public: - OffscreenDrawable(int width, int height, std::shared_ptr device); + OffscreenDrawable(int width, int height, std::shared_ptr device); int width() const override { return _width; @@ -99,18 +99,18 @@ class OffscreenDrawable : public Drawable { void updateSize() override { } - std::shared_ptr getDevice() override { + std::shared_ptr getDevice() override { return device; } - std::shared_ptr createSurface(Context* context) override; + std::shared_ptr createSurface(tgfx::Context* context) override; - void present(Context*) override { + void present(tgfx::Context*) override { } private: int _width = 0; int _height = 0; - std::shared_ptr device = nullptr; + std::shared_ptr device = nullptr; }; } // namespace pag diff --git a/src/rendering/FontManager.cpp b/src/rendering/FontManager.cpp index 0b7f73d734..6d7ea82cc9 100644 --- a/src/rendering/FontManager.cpp +++ b/src/rendering/FontManager.cpp @@ -38,12 +38,12 @@ std::shared_ptr TypefaceHolder::MakeFromFile(const std::string& return std::shared_ptr(holder); } -std::shared_ptr TypefaceHolder::getTypeface() { +std::shared_ptr TypefaceHolder::getTypeface() { if (typeface == nullptr) { if (!fontPath.empty()) { - typeface = Typeface::MakeFromPath(fontPath, ttcIndex); + typeface = tgfx::Typeface::MakeFromPath(fontPath, ttcIndex); } else { - typeface = Typeface::MakeFromName(fontFamily, fontStyle); + typeface = tgfx::Typeface::MakeFromName(fontFamily, fontStyle); } } return typeface; @@ -62,14 +62,14 @@ bool FontManager::hasFallbackFonts() { PAGFont FontManager::registerFont(const std::string& fontPath, int ttcIndex, const std::string& fontFamily, const std::string& fontStyle) { std::lock_guard autoLock(locker); - auto typeface = Typeface::MakeFromPath(fontPath, ttcIndex); + auto typeface = tgfx::Typeface::MakeFromPath(fontPath, ttcIndex); return registerFont(typeface, fontFamily, fontStyle); } PAGFont FontManager::registerFont(const void* data, size_t length, int ttcIndex, const std::string& fontFamily, const std::string& fontStyle) { std::lock_guard autoLock(locker); - auto typeface = Typeface::MakeFromBytes(data, length, ttcIndex); + auto typeface = tgfx::Typeface::MakeFromBytes(data, length, ttcIndex); return registerFont(typeface, fontFamily, fontStyle); } @@ -77,8 +77,8 @@ static std::string PAGFontRegisterKey(const std::string& fontFamily, const std:: return fontFamily + "|" + fontStyle; } -PAGFont FontManager::registerFont(std::shared_ptr typeface, const std::string& fontFamily, - const std::string& fontStyle) { +PAGFont FontManager::registerFont(std::shared_ptr typeface, + const std::string& fontFamily, const std::string& fontStyle) { if (typeface == nullptr) { return {"", ""}; } @@ -105,9 +105,9 @@ void FontManager::unregisterFont(const PAGFont& font) { registeredFontMap.erase(iter); } -static std::shared_ptr MakeTypefaceWithName(const std::string& fontFamily, - const std::string& fontStyle) { - auto typeface = Typeface::MakeFromName(fontFamily, fontStyle); +static std::shared_ptr MakeTypefaceWithName(const std::string& fontFamily, + const std::string& fontStyle) { + auto typeface = tgfx::Typeface::MakeFromName(fontFamily, fontStyle); if (typeface != nullptr) { if (fontFamily != typeface->fontFamily()) { typeface = nullptr; @@ -116,9 +116,9 @@ static std::shared_ptr MakeTypefaceWithName(const std::string& fontFam return typeface; } -std::shared_ptr FontManager::getTypefaceWithoutFallback(const std::string& fontFamily, - const std::string& fontStyle) { - std::shared_ptr typeface = getTypefaceFromCache(fontFamily, fontStyle); +std::shared_ptr FontManager::getTypefaceWithoutFallback( + const std::string& fontFamily, const std::string& fontStyle) { + std::shared_ptr typeface = getTypefaceFromCache(fontFamily, fontStyle); if (typeface == nullptr) { typeface = MakeTypefaceWithName(fontFamily, fontStyle); } @@ -133,8 +133,8 @@ std::shared_ptr FontManager::getTypefaceWithoutFallback(const std::str return typeface; } -std::shared_ptr FontManager::getFallbackTypeface(const std::string& name, - GlyphID* glyphID) { +std::shared_ptr FontManager::getFallbackTypeface(const std::string& name, + tgfx::GlyphID* glyphID) { std::lock_guard autoLock(locker); for (auto& holder : fallbackFontList) { auto typeface = holder->getTypeface(); @@ -145,7 +145,7 @@ std::shared_ptr FontManager::getFallbackTypeface(const std::string& na } } } - return Typeface::MakeDefault(); + return tgfx::Typeface::MakeDefault(); } void FontManager::setFallbackFontNames(const std::vector& fontNames) { @@ -169,8 +169,8 @@ void FontManager::setFallbackFontPaths(const std::vector& fontPaths } } -std::shared_ptr FontManager::getTypefaceFromCache(const std::string& fontFamily, - const std::string& fontStyle) { +std::shared_ptr FontManager::getTypefaceFromCache(const std::string& fontFamily, + const std::string& fontStyle) { std::lock_guard autoLock(locker); auto result = registeredFontMap.find(PAGFontRegisterKey(fontFamily, fontStyle)); if (result != registeredFontMap.end()) { @@ -181,8 +181,8 @@ std::shared_ptr FontManager::getTypefaceFromCache(const std::string& f static FontManager fontManager = {}; -std::shared_ptr FontManager::GetTypefaceWithoutFallback(const std::string& fontFamily, - const std::string& fontStyle) { +std::shared_ptr FontManager::GetTypefaceWithoutFallback( + const std::string& fontFamily, const std::string& fontStyle) { return fontManager.getTypefaceWithoutFallback(fontFamily, fontStyle); } @@ -193,8 +193,8 @@ static bool RegisterFallbackFonts() { return Platform::Current()->registerFallbackFonts(); } -std::shared_ptr FontManager::GetFallbackTypeface(const std::string& name, - GlyphID* glyphID) { +std::shared_ptr FontManager::GetFallbackTypeface(const std::string& name, + tgfx::GlyphID* glyphID) { static auto registered = RegisterFallbackFonts(); USE(registered); return fontManager.getFallbackTypeface(name, glyphID); diff --git a/src/rendering/FontManager.h b/src/rendering/FontManager.h index 9e74c2c140..a17d5eb8dd 100644 --- a/src/rendering/FontManager.h +++ b/src/rendering/FontManager.h @@ -23,7 +23,6 @@ #include "pag/pag.h" namespace pag { - class TypefaceHolder { public: static std::shared_ptr MakeFromName(const std::string& fontFamily, @@ -32,21 +31,22 @@ class TypefaceHolder { static std::shared_ptr MakeFromFile(const std::string& fontPath, int ttcIndex = 0); - std::shared_ptr getTypeface(); + std::shared_ptr getTypeface(); private: std::string fontFamily; std::string fontStyle; std::string fontPath; int ttcIndex = 0; - std::shared_ptr typeface = nullptr; + std::shared_ptr typeface = nullptr; }; class FontManager { public: - static std::shared_ptr GetTypefaceWithoutFallback(const std::string& fontFamily, - const std::string& fontStyle); - static std::shared_ptr GetFallbackTypeface(const std::string& name, GlyphID* glyphID); + static std::shared_ptr GetTypefaceWithoutFallback(const std::string& fontFamily, + const std::string& fontStyle); + static std::shared_ptr GetFallbackTypeface(const std::string& name, + tgfx::GlyphID* glyphID); static PAGFont RegisterFont(const std::string& fontPath, int ttcIndex, const std::string& fontFamily, const std::string& fontStyle); @@ -72,27 +72,28 @@ class FontManager { PAGFont registerFont(const void* data, size_t length, int ttcIndex = 0, const std::string& fontFamily = "", const std::string& fontStyle = ""); - PAGFont registerFont(std::shared_ptr typeface, const std::string& fontFamily = "", + PAGFont registerFont(std::shared_ptr typeface, const std::string& fontFamily = "", const std::string& fontStyle = ""); void unregisterFont(const PAGFont& font); - std::shared_ptr getTypefaceWithoutFallback(const std::string& fontFamily, - const std::string& fontStyle); + std::shared_ptr getTypefaceWithoutFallback(const std::string& fontFamily, + const std::string& fontStyle); - std::shared_ptr getFallbackTypeface(const std::string& name, GlyphID* glyphID); + std::shared_ptr getFallbackTypeface(const std::string& name, + tgfx::GlyphID* glyphID); void setFallbackFontNames(const std::vector& fontNames); void setFallbackFontPaths(const std::vector& fontPaths, const std::vector& ttcIndices); - std::unordered_map> registeredFontMap; + std::unordered_map> registeredFontMap; std::vector> fallbackFontList; std::mutex locker = {}; - std::shared_ptr getTypefaceFromCache(const std::string& fontFamily, - const std::string& fontStyle); + std::shared_ptr getTypefaceFromCache(const std::string& fontFamily, + const std::string& fontStyle); friend class PAGFont; }; diff --git a/src/rendering/GPUBackend.cpp b/src/rendering/GPUBackend.cpp new file mode 100644 index 0000000000..31fa2f3675 --- /dev/null +++ b/src/rendering/GPUBackend.cpp @@ -0,0 +1,136 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include "pag/gpu.h" + +namespace pag { +BackendTexture::BackendTexture(const GLTextureInfo& glInfo, int width, int height) + : _backend(Backend::OPENGL), _width(width), _height(height), glInfo(glInfo) { +} + +BackendTexture::BackendTexture(const MtlTextureInfo& mtlInfo, int width, int height) + : _backend(Backend::METAL), _width(width), _height(height), mtlInfo(mtlInfo) { +} + +BackendTexture::BackendTexture(const BackendTexture& that) { + *this = that; +} + +BackendTexture& BackendTexture::operator=(const BackendTexture& that) { + if (!that.isValid()) { + _width = _height = 0; + return *this; + } + _width = that._width; + _height = that._height; + _backend = that._backend; + switch (that._backend) { + case Backend::OPENGL: + glInfo = that.glInfo; + break; + case Backend::METAL: + mtlInfo = that.mtlInfo; + break; + default: + break; + } + return *this; +} + +bool BackendTexture::getGLTextureInfo(GLTextureInfo* glTextureInfo) const { + if (!isValid() || _backend != Backend::OPENGL) { + return false; + } + *glTextureInfo = glInfo; + return true; +} + +bool BackendTexture::getMtlTextureInfo(MtlTextureInfo* mtlTextureInfo) const { + if (!isValid() || _backend != Backend::METAL) { + return false; + } + *mtlTextureInfo = mtlInfo; + return true; +} + +BackendRenderTarget::BackendRenderTarget(const GLFrameBufferInfo& glInfo, int width, int height) + : _backend(Backend::OPENGL), _width(width), _height(height), glInfo(glInfo) { +} + +BackendRenderTarget::BackendRenderTarget(const MtlTextureInfo& mtlInfo, int width, int height) + : _backend(Backend::METAL), _width(width), _height(height), mtlInfo(mtlInfo) { +} + +BackendRenderTarget::BackendRenderTarget(const BackendRenderTarget& that) { + *this = that; +} + +BackendRenderTarget& BackendRenderTarget::operator=(const BackendRenderTarget& that) { + if (!that.isValid()) { + _width = _height = 0; + return *this; + } + _width = that._width; + _height = that._height; + _backend = that._backend; + switch (that._backend) { + case Backend::OPENGL: + glInfo = that.glInfo; + break; + case Backend::METAL: + mtlInfo = that.mtlInfo; + break; + default: + break; + } + return *this; +} + +bool BackendRenderTarget::getGLFramebufferInfo(GLFrameBufferInfo* glFrameBufferInfo) const { + if (!isValid() || _backend != Backend::OPENGL) { + return false; + } + *glFrameBufferInfo = glInfo; + return true; +} + +bool BackendRenderTarget::getMtlTextureInfo(MtlTextureInfo* mtlTextureInfo) const { + if (!isValid() || _backend != Backend::METAL) { + return false; + } + *mtlTextureInfo = mtlInfo; + return true; +} + +BackendSemaphore::BackendSemaphore() + : _backend(Backend::MOCK), _glSync(nullptr), _isInitialized(false) { +} + +void BackendSemaphore::initGL(void* sync) { + _backend = Backend::OPENGL; + _glSync = sync; + _isInitialized = true; +} + +void* BackendSemaphore::glSync() const { + if (!_isInitialized || _backend != Backend::OPENGL) { + return nullptr; + } + return _glSync; +} +} // namespace pag \ No newline at end of file diff --git a/src/rendering/PAGPlayer.cpp b/src/rendering/PAGPlayer.cpp index 75f288d9d7..c1c680eff9 100644 --- a/src/rendering/PAGPlayer.cpp +++ b/src/rendering/PAGPlayer.cpp @@ -301,7 +301,7 @@ Rect PAGPlayer::getBounds(std::shared_ptr pagLayer) { } LockGuard autoLock(rootLocker); updateStageSize(); - Rect bounds = {}; + tgfx::Rect bounds = {}; pagLayer->measureBounds(&bounds); auto layer = pagLayer.get(); bool contains = false; @@ -310,14 +310,15 @@ Rect PAGPlayer::getBounds(std::shared_ptr pagLayer) { contains = true; break; } - layer->getTotalMatrixInternal().mapRect(&bounds); + auto layerMatrix = ToTGFX(layer->getTotalMatrixInternal()); + layerMatrix.mapRect(&bounds); if (layer->_parent == nullptr && layer->trackMatteOwner) { layer = layer->trackMatteOwner->_parent; } else { layer = layer->_parent; } } - return contains ? bounds : Rect::MakeEmpty(); + return contains ? ToPAG(bounds) : Rect::MakeEmpty(); } std::vector> PAGPlayer::getLayersUnderPoint(float surfaceX, @@ -335,7 +336,7 @@ bool PAGPlayer::hitTestPoint(std::shared_ptr pagLayer, float surfaceX, updateStageSize(); auto local = pagLayer->globalToLocalPoint(surfaceX, surfaceY); if (!pixelHitTest) { - Rect bounds = {}; + tgfx::Rect bounds = {}; pagLayer->measureBounds(&bounds); return bounds.contains(local.x, local.y); } diff --git a/src/rendering/PAGSurface.cpp b/src/rendering/PAGSurface.cpp index c8d276b4d4..f8a26e9c75 100644 --- a/src/rendering/PAGSurface.cpp +++ b/src/rendering/PAGSurface.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "base/utils/GetTimer.h" +#include "base/utils/TGFXCast.h" #include "gpu/Canvas.h" #include "gpu/opengl/GLDevice.h" #include "pag/file.h" @@ -35,24 +36,25 @@ std::shared_ptr PAGSurface::MakeFrom(std::shared_ptr drawa return std::shared_ptr(new PAGSurface(std::move(drawable))); } -static std::shared_ptr GetCurrentDevice(bool forAsyncThread) { +static std::shared_ptr GetCurrentDevice(bool forAsyncThread) { if (forAsyncThread) { - auto sharedContext = GLDevice::CurrentNativeHandle(); - auto device = GLDevice::Make(sharedContext); + auto sharedContext = tgfx::GLDevice::CurrentNativeHandle(); + auto device = tgfx::GLDevice::Make(sharedContext); if (device) { return device; } } - return GLDevice::Current(); + return tgfx::GLDevice::Current(); } std::shared_ptr PAGSurface::MakeFrom(const BackendRenderTarget& renderTarget, ImageOrigin origin) { - auto device = GLDevice::Current(); + auto device = tgfx::GLDevice::Current(); if (device == nullptr || !renderTarget.isValid()) { return nullptr; } - auto drawable = std::make_shared(device, renderTarget, origin); + auto drawable = + std::make_shared(device, ToTGFX(renderTarget), ToTGFX(origin)); return MakeFrom(std::move(drawable)); } @@ -62,12 +64,12 @@ std::shared_ptr PAGSurface::MakeFrom(const BackendTexture& texture, if (device == nullptr || !texture.isValid()) { return nullptr; } - auto drawable = std::make_shared(device, texture, origin); + auto drawable = std::make_shared(device, ToTGFX(texture), ToTGFX(origin)); return MakeFrom(std::move(drawable)); } std::shared_ptr PAGSurface::MakeOffscreen(int width, int height) { - auto device = GLDevice::Make(); + auto device = tgfx::GLDevice::Make(); if (device == nullptr || width <= 0 || height <= 0) { return nullptr; } @@ -145,8 +147,8 @@ bool PAGSurface::readPixels(ColorType colorType, AlphaType alphaType, void* dstP if (surface == nullptr || !context) { return false; } - auto info = - ImageInfo::Make(surface->width(), surface->height(), colorType, alphaType, dstRowBytes); + auto info = tgfx::ImageInfo::Make(surface->width(), surface->height(), ToTGFX(colorType), + ToTGFX(alphaType), dstRowBytes); auto result = surface->readPixels(info, dstPixels); unlockContext(); return result; @@ -181,7 +183,7 @@ bool PAGSurface::draw(RenderCache* cache, std::shared_ptr graphic, if (graphic) { graphic->draw(canvas, cache); } - surface->flush(signalSemaphore); + surface->flush(ToTGFX(signalSemaphore)); cache->detachFromContext(); drawable->setTimeStamp(pagPlayer->getTimeStampInternal()); drawable->present(context); @@ -207,7 +209,7 @@ bool PAGSurface::wait(const BackendSemaphore& waitSemaphore) { unlockContext(); return false; } - auto ret = surface->wait(waitSemaphore); + auto ret = surface->wait(ToTGFX(waitSemaphore)); unlockContext(); return ret; } @@ -227,7 +229,7 @@ bool PAGSurface::hitTest(RenderCache* cache, std::shared_ptr graphic, f return result; } -Context* PAGSurface::lockContext() { +tgfx::Context* PAGSurface::lockContext() { if (device == nullptr) { return nullptr; } diff --git a/src/rendering/caches/GraphicContent.cpp b/src/rendering/caches/GraphicContent.cpp index bdf8917110..f628cc8fc3 100644 --- a/src/rendering/caches/GraphicContent.cpp +++ b/src/rendering/caches/GraphicContent.cpp @@ -24,7 +24,7 @@ namespace pag { GraphicContent::GraphicContent(std::shared_ptr graphic) : graphic(std::move(graphic)) { } -void GraphicContent::measureBounds(Rect* bounds) { +void GraphicContent::measureBounds(tgfx::Rect* bounds) { if (graphic) { graphic->measureBounds(bounds); } else { diff --git a/src/rendering/caches/GraphicContent.h b/src/rendering/caches/GraphicContent.h index c266d6fc8e..5735f3d674 100644 --- a/src/rendering/caches/GraphicContent.h +++ b/src/rendering/caches/GraphicContent.h @@ -26,7 +26,7 @@ namespace pag { class GraphicContent : public Content { public: explicit GraphicContent(std::shared_ptr graphic); - void measureBounds(Rect* bounds) override; + void measureBounds(tgfx::Rect* bounds) override; void draw(Recorder* recorder) override; std::shared_ptr graphic = nullptr; diff --git a/src/rendering/caches/ImageContentCache.cpp b/src/rendering/caches/ImageContentCache.cpp index e308b46709..728181e2ed 100644 --- a/src/rendering/caches/ImageContentCache.cpp +++ b/src/rendering/caches/ImageContentCache.cpp @@ -29,10 +29,10 @@ class ImageBytesCache : public Cache { } auto cache = new ImageBytesCache(); auto fileBytes = - Data::MakeWithoutCopy(imageBytes->fileBytes->data(), imageBytes->fileBytes->length()); - cache->image = Image::MakeFrom(std::move(fileBytes)); + tgfx::Data::MakeWithoutCopy(imageBytes->fileBytes->data(), imageBytes->fileBytes->length()); + cache->image = tgfx::Image::MakeFrom(std::move(fileBytes)); auto picture = Picture::MakeFrom(imageBytes->uniqueID, cache->image); - auto matrix = Matrix::MakeScale(1 / imageBytes->scaleFactor); + auto matrix = tgfx::Matrix::MakeScale(1 / imageBytes->scaleFactor); matrix.postTranslate(static_cast(-imageBytes->anchorX), static_cast(-imageBytes->anchorY)); cache->graphic = Graphic::MakeCompose(picture, matrix); @@ -40,11 +40,11 @@ class ImageBytesCache : public Cache { return cache; } - std::shared_ptr image = nullptr; + std::shared_ptr image = nullptr; std::shared_ptr graphic = nullptr; }; -std::shared_ptr ImageContentCache::GetImage(ImageBytes* imageBytes) { +std::shared_ptr ImageContentCache::GetImage(ImageBytes* imageBytes) { return ImageBytesCache::Get(imageBytes)->image; } diff --git a/src/rendering/caches/ImageContentCache.h b/src/rendering/caches/ImageContentCache.h index aa5a98183e..8e9d410441 100644 --- a/src/rendering/caches/ImageContentCache.h +++ b/src/rendering/caches/ImageContentCache.h @@ -23,7 +23,7 @@ namespace pag { class ImageContentCache : public ContentCache { public: - static std::shared_ptr GetImage(ImageBytes* imageBytes); + static std::shared_ptr GetImage(ImageBytes* imageBytes); explicit ImageContentCache(ImageLayer* layer); diff --git a/src/rendering/caches/LayerCache.cpp b/src/rendering/caches/LayerCache.cpp index f09d1db96e..5131fd3b1f 100644 --- a/src/rendering/caches/LayerCache.cpp +++ b/src/rendering/caches/LayerCache.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "LayerCache.h" +#include "base/utils/TGFXCast.h" #include "rendering/caches/ImageContentCache.h" #include "rendering/caches/PreComposeContentCache.h" #include "rendering/caches/ShapeContentCache.h" @@ -60,7 +61,7 @@ LayerCache::LayerCache(Layer* layer) : layer(layer) { maskCache = new MaskCache(layer); } updateStaticTimeRanges(); - maxScaleFactor = layer->getMaxScaleFactor(); + maxScaleFactor = ToTGFX(layer->getMaxScaleFactor()); } LayerCache::~LayerCache() { @@ -73,7 +74,7 @@ Transform* LayerCache::getTransform(Frame contentFrame) { return transformCache->getCache(contentFrame); } -Path* LayerCache::getMasks(Frame contentFrame) { +tgfx::Path* LayerCache::getMasks(Frame contentFrame) { auto mask = maskCache ? maskCache->getCache(contentFrame) : nullptr; if (mask && mask->isEmpty()) { return nullptr; @@ -89,7 +90,7 @@ Layer* LayerCache::getLayer() const { return layer; } -Point LayerCache::getMaxScaleFactor() const { +tgfx::Point LayerCache::getMaxScaleFactor() const { return maxScaleFactor; } diff --git a/src/rendering/caches/LayerCache.h b/src/rendering/caches/LayerCache.h index 2778c06190..8d4e1eca93 100644 --- a/src/rendering/caches/LayerCache.h +++ b/src/rendering/caches/LayerCache.h @@ -18,6 +18,7 @@ #pragma once +#include "base/utils/TGFXCast.h" #include "rendering/caches/ContentCache.h" #include "rendering/caches/MaskCache.h" #include "rendering/caches/TransformCache.h" @@ -31,13 +32,13 @@ class LayerCache : public Cache { Transform* getTransform(Frame contentFrame); - Path* getMasks(Frame contentFrame); + tgfx::Path* getMasks(Frame contentFrame); Content* getContent(Frame contentFrame); Layer* getLayer() const; - Point getMaxScaleFactor() const; + tgfx::Point getMaxScaleFactor() const; bool checkFrameChanged(Frame contentFrame, Frame lastContentFrame); @@ -64,7 +65,7 @@ class LayerCache : public Cache { TransformCache* transformCache = nullptr; MaskCache* maskCache = nullptr; ContentCache* contentCache = nullptr; - Point maxScaleFactor = {}; + tgfx::Point maxScaleFactor = {}; std::vector staticTimeRanges; explicit LayerCache(Layer* layer); diff --git a/src/rendering/caches/MaskCache.cpp b/src/rendering/caches/MaskCache.cpp index 1baef84e56..80c301bdc3 100644 --- a/src/rendering/caches/MaskCache.cpp +++ b/src/rendering/caches/MaskCache.cpp @@ -21,7 +21,7 @@ namespace pag { MaskCache::MaskCache(Layer* layer) - : FrameCache(layer->startTime, layer->duration), layer(layer) { + : FrameCache(layer->startTime, layer->duration), layer(layer) { std::vector timeRanges = {layer->visibleRange()}; for (auto& mask : layer->masks) { mask->excludeVaryingRanges(&timeRanges); @@ -29,8 +29,8 @@ MaskCache::MaskCache(Layer* layer) staticTimeRanges = OffsetTimeRanges(timeRanges, -layer->startTime); } -Path* MaskCache::createCache(Frame layerFrame) { - auto maskContent = new Path(); +tgfx::Path* MaskCache::createCache(Frame layerFrame) { + auto maskContent = new tgfx::Path(); RenderMasks(maskContent, layer->masks, layerFrame); return maskContent; } diff --git a/src/rendering/caches/MaskCache.h b/src/rendering/caches/MaskCache.h index 39d3932ce8..2973de288c 100644 --- a/src/rendering/caches/MaskCache.h +++ b/src/rendering/caches/MaskCache.h @@ -22,12 +22,12 @@ #include "core/Path.h" namespace pag { -class MaskCache : public FrameCache { +class MaskCache : public FrameCache { public: explicit MaskCache(Layer* layer); protected: - Path* createCache(Frame layerFrame) override; + tgfx::Path* createCache(Frame layerFrame) override; private: Layer* layer = nullptr; diff --git a/src/rendering/caches/RenderCache.cpp b/src/rendering/caches/RenderCache.cpp index 00b8e1b036..c85d9f0537 100644 --- a/src/rendering/caches/RenderCache.cpp +++ b/src/rendering/caches/RenderCache.cpp @@ -38,7 +38,7 @@ namespace pag { class ImageTask : public Executor { public: - static std::shared_ptr MakeAndRun(std::shared_ptr image) { + static std::shared_ptr MakeAndRun(std::shared_ptr image) { if (image == nullptr) { return nullptr; } @@ -48,15 +48,15 @@ class ImageTask : public Executor { return task; } - std::shared_ptr getBuffer() const { + std::shared_ptr getBuffer() const { return buffer; } private: - std::shared_ptr buffer = {}; - std::shared_ptr image = nullptr; + std::shared_ptr buffer = {}; + std::shared_ptr image = nullptr; - explicit ImageTask(std::shared_ptr image) : image(std::move(image)) { + explicit ImageTask(std::shared_ptr image) : image(std::move(image)) { } void execute() override { @@ -179,7 +179,7 @@ void RenderCache::prepareFrame() { } } -void RenderCache::attachToContext(Context* current, bool forHitTest) { +void RenderCache::attachToContext(tgfx::Context* current, bool forHitTest) { if (deviceID > 0 && deviceID != current->device()->uniqueID()) { // Context 改变需要清理内部所有缓存,这里用 uniqueID // 而不用指针比较,是因为指针析构后再创建可能会地址重合。 @@ -317,7 +317,7 @@ void RenderCache::clearExpiredSnapshots() { } } -void RenderCache::prepareImage(ID assetID, std::shared_ptr image) { +void RenderCache::prepareImage(ID assetID, std::shared_ptr image) { usedAssets.insert(assetID); if (imageTasks.count(assetID) != 0 || snapshotCaches.count(assetID) != 0) { return; @@ -328,7 +328,7 @@ void RenderCache::prepareImage(ID assetID, std::shared_ptr image) { } } -std::shared_ptr RenderCache::getImageBuffer(ID assetID) { +std::shared_ptr RenderCache::getImageBuffer(ID assetID) { usedAssets.insert(assetID); auto result = imageTasks.find(assetID); if (result != imageTasks.end()) { diff --git a/src/rendering/caches/RenderCache.h b/src/rendering/caches/RenderCache.h index 9b1a4a0993..d7a79adba6 100644 --- a/src/rendering/caches/RenderCache.h +++ b/src/rendering/caches/RenderCache.h @@ -46,7 +46,7 @@ class RenderCache : public Performance { void prepareFrame(); - void attachToContext(Context* current, bool forHitTest = false); + void attachToContext(tgfx::Context* current, bool forHitTest = false); void detachFromContext(); @@ -60,7 +60,7 @@ class RenderCache : public Performance { /** * Returns the GPU context associated with this cache. */ - Context* getContext() const { + tgfx::Context* getContext() const { return context; } @@ -102,13 +102,13 @@ class RenderCache : public Performance { /** * Prepares a bitmap task for next getImageBuffer() call. */ - void prepareImage(ID assetID, std::shared_ptr image); + void prepareImage(ID assetID, std::shared_ptr image); /** * Returns a texture buffer cache of specified asset id. Returns null if there is no associated * cache available. */ - std::shared_ptr getImageBuffer(ID assetID); + std::shared_ptr getImageBuffer(ID assetID); uint32_t getContentVersion() const; @@ -140,7 +140,7 @@ class RenderCache : public Performance { ID _uniqueID = 0; PAGStage* stage = nullptr; uint32_t deviceID = 0; - Context* context = nullptr; + tgfx::Context* context = nullptr; int64_t lastTimestamp = 0; bool hitTestOnly = false; size_t graphicsMemory = 0; diff --git a/src/rendering/caches/SolidContentCache.cpp b/src/rendering/caches/SolidContentCache.cpp index 1740d24385..a66b627c30 100644 --- a/src/rendering/caches/SolidContentCache.cpp +++ b/src/rendering/caches/SolidContentCache.cpp @@ -17,8 +17,8 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "SolidContentCache.h" +#include "base/utils/TGFXCast.h" #include "rendering/graphics/Shape.h" -#include "rendering/utils/TGFXTypes.h" namespace pag { SolidContentCache::SolidContentCache(SolidLayer* layer) : ContentCache(layer) { @@ -26,9 +26,9 @@ SolidContentCache::SolidContentCache(SolidLayer* layer) : ContentCache(layer) { GraphicContent* SolidContentCache::createContent(Frame) const { auto solidLayer = static_cast(layer); - Path path = {}; + tgfx::Path path = {}; path.addRect(0, 0, solidLayer->width, solidLayer->height); - auto graphic = Shape::MakeFrom(path, ToTGFXColor(solidLayer->solidColor)); + auto graphic = Shape::MakeFrom(path, ToTGFX(solidLayer->solidColor)); return new GraphicContent(graphic); } } // namespace pag diff --git a/src/rendering/editing/ImageReplacement.cpp b/src/rendering/editing/ImageReplacement.cpp index df72671e86..9436c8e728 100644 --- a/src/rendering/editing/ImageReplacement.cpp +++ b/src/rendering/editing/ImageReplacement.cpp @@ -32,12 +32,12 @@ ImageReplacement::ImageReplacement(ImageLayer* imageLayer, PAGImageHolder* image contentHeight = imageLayer->imageBytes->height; } -void ImageReplacement::measureBounds(Rect* bounds) { - Rect contentBounds = {}; +void ImageReplacement::measureBounds(tgfx::Rect* bounds) { + tgfx::Rect contentBounds = {}; auto pagImage = imageHolder->getImage(editableIndex); pagImage->measureBounds(&contentBounds); auto contentMatrix = pagImage->getContentMatrix(defaultScaleMode, contentWidth, contentHeight); - contentMatrix.mapRect(&contentBounds); + ToTGFX(contentMatrix).mapRect(&contentBounds); bounds->setXYWH(0, 0, contentWidth, contentHeight); if (!bounds->intersect(contentBounds)) { bounds->setEmpty(); @@ -48,16 +48,16 @@ void ImageReplacement::draw(Recorder* recorder) { recorder->saveClip(0, 0, static_cast(contentWidth), static_cast(contentHeight)); auto pagImage = imageHolder->getImage(editableIndex); auto contentMatrix = pagImage->getContentMatrix(defaultScaleMode, contentWidth, contentHeight); - recorder->concat(contentMatrix); + recorder->concat(ToTGFX(contentMatrix)); pagImage->draw(recorder); recorder->restore(); } -Point ImageReplacement::getScaleFactor() const { +tgfx::Point ImageReplacement::getScaleFactor() const { // TODO((domrjchen): // 当PAGImage的适配模式或者matrix发生改变时,需要补充一个通知机制让上层重置scaleFactor。 auto pagImage = imageHolder->getImage(editableIndex); auto contentMatrix = pagImage->getContentMatrix(defaultScaleMode, contentWidth, contentHeight); - return GetScaleFactor(contentMatrix); + return GetScaleFactor(ToTGFX(contentMatrix)); } } // namespace pag \ No newline at end of file diff --git a/src/rendering/editing/ImageReplacement.h b/src/rendering/editing/ImageReplacement.h index 32986eff7f..d990e89468 100644 --- a/src/rendering/editing/ImageReplacement.h +++ b/src/rendering/editing/ImageReplacement.h @@ -24,9 +24,9 @@ class ImageReplacement : public Content { public: ImageReplacement(ImageLayer* imageLayer, PAGImageHolder* imageHolder, int editableIndex); - void measureBounds(Rect* bounds) override; + void measureBounds(tgfx::Rect* bounds) override; void draw(Recorder* recorder) override; - Point getScaleFactor() const; + tgfx::Point getScaleFactor() const; private: PAGImageHolder* imageHolder = nullptr; diff --git a/src/rendering/editing/StillImage.cpp b/src/rendering/editing/StillImage.cpp index 649b4fff15..8cfd408e67 100644 --- a/src/rendering/editing/StillImage.cpp +++ b/src/rendering/editing/StillImage.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "StillImage.h" +#include "base/utils/TGFXCast.h" #include "base/utils/UniqueID.h" #include "gpu/opengl/GLDevice.h" #include "pag/pag.h" @@ -29,7 +30,7 @@ namespace pag { std::shared_ptr PAGImage::FromPath(const std::string& filePath) { auto pagImage = std::make_shared(); - pagImage->image = Image::MakeFrom(filePath); + pagImage->image = tgfx::Image::MakeFrom(filePath); auto picture = Picture::MakeFrom(pagImage->uniqueID(), pagImage->image); if (!picture) { return nullptr; @@ -40,8 +41,8 @@ std::shared_ptr PAGImage::FromPath(const std::string& filePath) { std::shared_ptr PAGImage::FromBytes(const void* bytes, size_t length) { auto pagImage = std::make_shared(); - auto fileBytes = Data::MakeWithCopy(bytes, length); - pagImage->image = Image::MakeFrom(std::move(fileBytes)); + auto fileBytes = tgfx::Data::MakeWithCopy(bytes, length); + pagImage->image = tgfx::Image::MakeFrom(std::move(fileBytes)); auto picture = Picture::MakeFrom(pagImage->uniqueID(), pagImage->image); if (!picture) { return nullptr; @@ -53,12 +54,12 @@ std::shared_ptr PAGImage::FromBytes(const void* bytes, size_t length) std::shared_ptr PAGImage::FromPixels(const void* pixels, int width, int height, size_t rowBytes, ColorType colorType, AlphaType alphaType) { - auto pixelBuffer = PixelBuffer::Make(width, height); - Bitmap bitmap(pixelBuffer); + auto pixelBuffer = tgfx::PixelBuffer::Make(width, height); + tgfx::Bitmap bitmap(pixelBuffer); if (bitmap.isEmpty()) { return nullptr; } - auto info = ImageInfo::Make(width, height, colorType, alphaType, rowBytes); + auto info = tgfx::ImageInfo::Make(width, height, ToTGFX(colorType), ToTGFX(alphaType), rowBytes); auto result = bitmap.writePixels(info, pixels); if (!result) { return nullptr; @@ -66,7 +67,8 @@ std::shared_ptr PAGImage::FromPixels(const void* pixels, int width, in return StillImage::FromPixelBuffer(pixelBuffer); } -std::shared_ptr StillImage::FromPixelBuffer(std::shared_ptr pixelBuffer) { +std::shared_ptr StillImage::FromPixelBuffer( + std::shared_ptr pixelBuffer) { if (pixelBuffer == nullptr) { return nullptr; } @@ -79,7 +81,7 @@ std::shared_ptr StillImage::FromPixelBuffer(std::shared_ptr StillImage::FromImage(std::shared_ptr image) { +std::shared_ptr StillImage::FromImage(std::shared_ptr image) { if (image == nullptr) { return nullptr; } @@ -94,13 +96,13 @@ std::shared_ptr StillImage::FromImage(std::shared_ptr image) } std::shared_ptr PAGImage::FromTexture(const BackendTexture& texture, ImageOrigin origin) { - auto context = GLDevice::CurrentNativeHandle(); + auto context = tgfx::GLDevice::CurrentNativeHandle(); if (context == nullptr) { LOGE("PAGImage.MakeFrom() There is no current GPU context on the calling thread."); return nullptr; } auto pagImage = std::make_shared(); - auto picture = Picture::MakeFrom(pagImage->uniqueID(), texture, origin); + auto picture = Picture::MakeFrom(pagImage->uniqueID(), ToTGFX(texture), ToTGFX(origin)); if (!picture) { LOGE("PAGImage.MakeFrom() The texture is invalid."); return nullptr; @@ -109,12 +111,12 @@ std::shared_ptr PAGImage::FromTexture(const BackendTexture& texture, I return pagImage; } -void StillImage::measureBounds(Rect* bounds) { +void StillImage::measureBounds(tgfx::Rect* bounds) { graphic->measureBounds(bounds); } -Rect StillImage::getContentSize() const { - return Rect::MakeWH(static_cast(width), static_cast(height)); +tgfx::Rect StillImage::getContentSize() const { + return tgfx::Rect::MakeWH(static_cast(width), static_cast(height)); } void StillImage::draw(Recorder* recorder) { @@ -122,7 +124,7 @@ void StillImage::draw(Recorder* recorder) { } void StillImage::reset(std::shared_ptr g) { - Rect bounds = {}; + tgfx::Rect bounds = {}; g->measureBounds(&bounds); width = static_cast(bounds.width()); height = static_cast(bounds.height()); diff --git a/src/rendering/editing/StillImage.h b/src/rendering/editing/StillImage.h index 5650385860..4ee6eec67d 100644 --- a/src/rendering/editing/StillImage.h +++ b/src/rendering/editing/StillImage.h @@ -25,23 +25,24 @@ namespace pag { class StillImage : public PAGImage { public: - static std::shared_ptr FromPixelBuffer(std::shared_ptr pixelBuffer); - static std::shared_ptr FromImage(std::shared_ptr image); + static std::shared_ptr FromPixelBuffer( + std::shared_ptr pixelBuffer); + static std::shared_ptr FromImage(std::shared_ptr image); - void measureBounds(Rect* bounds) override; + void measureBounds(tgfx::Rect* bounds) override; void draw(Recorder* recorder) override; protected: - Rect getContentSize() const override; + tgfx::Rect getContentSize() const override; - std::shared_ptr getImage() const override { + std::shared_ptr getImage() const override { return image; } private: int width = 0; int height = 0; - std::shared_ptr image = nullptr; + std::shared_ptr image = nullptr; std::shared_ptr graphic = nullptr; void reset(std::shared_ptr graphic); diff --git a/src/rendering/filters/BulgeFilter.cpp b/src/rendering/filters/BulgeFilter.cpp index ebfe8485f3..a26fb0d27c 100644 --- a/src/rendering/filters/BulgeFilter.cpp +++ b/src/rendering/filters/BulgeFilter.cpp @@ -17,7 +17,6 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "BulgeFilter.h" -#include "gpu/opengl/GLUtil.h" namespace pag { static const char BULGE_VERTEX_SHADER[] = R"( @@ -92,7 +91,7 @@ std::string BulgeFilter::onBuildFragmentShader() { return BULGE_FRAGMENT_SHADER; } -void BulgeFilter::onPrepareProgram(const GLInterface* gl, unsigned int program) { +void BulgeFilter::onPrepareProgram(const tgfx::GLInterface* gl, unsigned int program) { horizontalRadiusHandle = gl->getUniformLocation(program, "uHorizontalRadius"); verticalRadiusHandle = gl->getUniformLocation(program, "uVerticalRadius"); bulgeCenterHandle = gl->getUniformLocation(program, "uBulgeCenter"); @@ -100,7 +99,8 @@ void BulgeFilter::onPrepareProgram(const GLInterface* gl, unsigned int program) pinningHandle = gl->getUniformLocation(program, "uPinning"); } -void BulgeFilter::onUpdateParams(const GLInterface* gl, const Rect& contentBounds, const Point&) { +void BulgeFilter::onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point&) { auto* bulgeEffect = reinterpret_cast(effect); auto horizontalRadius = bulgeEffect->horizontalRadius->getValueAt(layerFrame); auto verticalRadius = bulgeEffect->verticalRadius->getValueAt(layerFrame); @@ -116,8 +116,9 @@ void BulgeFilter::onUpdateParams(const GLInterface* gl, const Rect& contentBound gl->uniform1i(pinningHandle, pinning); } -std::vector BulgeFilter::computeVertices(const Rect& inputBounds, const Rect& outputBounds, - const Point&) { +std::vector BulgeFilter::computeVertices(const tgfx::Rect& inputBounds, + const tgfx::Rect& outputBounds, + const tgfx::Point&) { return ComputeVerticesForMotionBlurAndBulge(inputBounds, outputBounds); } } // namespace pag diff --git a/src/rendering/filters/BulgeFilter.h b/src/rendering/filters/BulgeFilter.h index 13070e6d83..375213d993 100644 --- a/src/rendering/filters/BulgeFilter.h +++ b/src/rendering/filters/BulgeFilter.h @@ -31,13 +31,14 @@ class BulgeFilter : public LayerFilter { std::string onBuildFragmentShader() override; - void onPrepareProgram(const GLInterface* gl, unsigned program) override; + void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) override; - void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) override; + void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) override; - std::vector computeVertices(const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale) override; + std::vector computeVertices(const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale) override; private: Effect* effect = nullptr; diff --git a/src/rendering/filters/CornerPinFilter.cpp b/src/rendering/filters/CornerPinFilter.cpp index 167664bae6..12357c55f3 100644 --- a/src/rendering/filters/CornerPinFilter.cpp +++ b/src/rendering/filters/CornerPinFilter.cpp @@ -17,7 +17,6 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "CornerPinFilter.h" -#include "gpu/opengl/GLUtil.h" #include "rendering/filters/utils/FilterHelper.h" namespace pag { @@ -56,12 +55,13 @@ std::string CornerPinFilter::onBuildFragmentShader() { return CORNER_PIN_FRAGMENT_SHADER; } -static float calculateDistance(const Point& intersection, const Point& vertexPoint) { +static float calculateDistance(const tgfx::Point& intersection, const tgfx::Point& vertexPoint) { return std::sqrt(std::pow(fabs(intersection.x - vertexPoint.x), 2) + std::pow(fabs(intersection.y - vertexPoint.y), 2)); } -static bool PointIsBetween(const Point& point, const Point& start, const Point& end) { +static bool PointIsBetween(const tgfx::Point& point, const tgfx::Point& start, + const tgfx::Point& end) { auto minX = std::min(start.x, end.x); auto maxX = std::max(start.x, end.x); auto minY = std::min(start.y, end.y); @@ -73,15 +73,15 @@ void CornerPinFilter::calculateVertexQs() { // https://www.reedbeta.com/blog/quadrilateral-interpolation-part-1/ // 计算2条对角线的交点:y1 = k1 * x1 + b1; y2 = k2 * x2 + b2 auto* cornerPinEffect = reinterpret_cast(effect); - auto lowerLeft = cornerPinEffect->lowerLeft->getValueAt(layerFrame); - auto upperRight = cornerPinEffect->upperRight->getValueAt(layerFrame); - auto lowerRight = cornerPinEffect->lowerRight->getValueAt(layerFrame); - auto upperLeft = cornerPinEffect->upperLeft->getValueAt(layerFrame); + auto lowerLeft = ToTGFX(cornerPinEffect->lowerLeft->getValueAt(layerFrame)); + auto upperRight = ToTGFX(cornerPinEffect->upperRight->getValueAt(layerFrame)); + auto lowerRight = ToTGFX(cornerPinEffect->lowerRight->getValueAt(layerFrame)); + auto upperLeft = ToTGFX(cornerPinEffect->upperLeft->getValueAt(layerFrame)); auto ll2ur_k = (upperRight.y - lowerLeft.y) / (upperRight.x - lowerLeft.x); auto ul2lr_k = (lowerRight.y - upperLeft.y) / (lowerRight.x - upperLeft.x); auto ll2ur_b = lowerLeft.y - ll2ur_k * lowerLeft.x; auto ul2lr_b = upperLeft.y - ul2lr_k * upperLeft.x; - Point intersection = {0, 0}; + tgfx::Point intersection = {0, 0}; intersection.x = (ul2lr_b - ll2ur_b) / (ll2ur_k - ul2lr_k); intersection.y = ll2ur_k * intersection.x + ll2ur_b; // 计算对角线交点与4个顶点的距离 @@ -105,18 +105,18 @@ void CornerPinFilter::calculateVertexQs() { } } -std::vector CornerPinFilter::computeVertices(const Rect& contentBounds, const Rect&, - const Point&) { - std::vector vertices = {}; +std::vector CornerPinFilter::computeVertices(const tgfx::Rect& contentBounds, + const tgfx::Rect&, const tgfx::Point&) { + std::vector vertices = {}; auto* cornerPinEffect = reinterpret_cast(effect); - Point contentPoint[4] = {cornerPinEffect->lowerLeft->getValueAt(layerFrame), - cornerPinEffect->lowerRight->getValueAt(layerFrame), - cornerPinEffect->upperLeft->getValueAt(layerFrame), - cornerPinEffect->upperRight->getValueAt(layerFrame)}; - Point texturePoints[4] = {{0.0f, contentBounds.height()}, - {contentBounds.width(), contentBounds.height()}, - {0.0f, 0.0f}, - {contentBounds.width(), 0.0f}}; + tgfx::Point contentPoint[4] = {ToTGFX(cornerPinEffect->lowerLeft->getValueAt(layerFrame)), + ToTGFX(cornerPinEffect->lowerRight->getValueAt(layerFrame)), + ToTGFX(cornerPinEffect->upperLeft->getValueAt(layerFrame)), + ToTGFX(cornerPinEffect->upperRight->getValueAt(layerFrame))}; + tgfx::Point texturePoints[4] = {{0.0f, contentBounds.height()}, + {contentBounds.width(), contentBounds.height()}, + {0.0f, 0.0f}, + {contentBounds.width(), 0.0f}}; for (int ii = 0; ii < 4; ii++) { vertices.push_back(contentPoint[ii]); @@ -125,8 +125,9 @@ std::vector CornerPinFilter::computeVertices(const Rect& contentBounds, c return vertices; } -void CornerPinFilter::bindVertices(const GLInterface* gl, const FilterSource* source, - const FilterTarget* target, const std::vector& points) { +void CornerPinFilter::bindVertices(const tgfx::GLInterface* gl, const FilterSource* source, + const FilterTarget* target, + const std::vector& points) { std::vector vertices = {}; calculateVertexQs(); for (size_t i = 0, j = 0; i < points.size() && j < 4; j++) { diff --git a/src/rendering/filters/CornerPinFilter.h b/src/rendering/filters/CornerPinFilter.h index 93d6f30771..ec0eebb90a 100644 --- a/src/rendering/filters/CornerPinFilter.h +++ b/src/rendering/filters/CornerPinFilter.h @@ -31,11 +31,12 @@ class CornerPinFilter : public LayerFilter { std::string onBuildFragmentShader() override; - std::vector computeVertices(const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale) override; + std::vector computeVertices(const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale) override; - void bindVertices(const GLInterface* gl, const FilterSource* source, const FilterTarget* target, - const std::vector& points) override; + void bindVertices(const tgfx::GLInterface* gl, const FilterSource* source, + const FilterTarget* target, const std::vector& points) override; bool needsMSAA() const override { return true; diff --git a/src/rendering/filters/DisplacementMapFilter.cpp b/src/rendering/filters/DisplacementMapFilter.cpp index 10aad8cdb6..18264557f0 100644 --- a/src/rendering/filters/DisplacementMapFilter.cpp +++ b/src/rendering/filters/DisplacementMapFilter.cpp @@ -18,7 +18,6 @@ #include "DisplacementMapFilter.h" #include "gpu/Surface.h" -#include "gpu/opengl/GLUtil.h" #include "rendering/caches/LayerCache.h" #include "rendering/caches/RenderCache.h" #include "rendering/filters/utils/FilterHelper.h" @@ -97,7 +96,7 @@ std::string DisplacementMapFilter::onBuildFragmentShader() { return FRAGMENT_SHADER; } -void DisplacementMapFilter::onPrepareProgram(const GLInterface* gl, unsigned int program) { +void DisplacementMapFilter::onPrepareProgram(const tgfx::GLInterface* gl, unsigned int program) { useForDisplacementHandle = gl->getUniformLocation(program, "uUseForDisplacement"); maxDisplacementHandle = gl->getUniformLocation(program, "uMaxDisplacement"); displacementMapBehaviorHandle = gl->getUniformLocation(program, "uDisplacementMapBehavior"); @@ -108,21 +107,21 @@ void DisplacementMapFilter::onPrepareProgram(const GLInterface* gl, unsigned int } void DisplacementMapFilter::updateMapTexture(RenderCache* cache, const Graphic* mapGraphic, - const Rect& bounds) { + const tgfx::Rect& bounds) { if (mapSurface == nullptr || mapBounds.width() != bounds.width() || mapBounds.height() != bounds.height()) { - mapSurface = Surface::Make(cache->getContext(), static_cast(bounds.width()), - static_cast(bounds.height())); + mapSurface = tgfx::Surface::Make(cache->getContext(), static_cast(bounds.width()), + static_cast(bounds.height())); mapBounds = bounds; } mapGraphic->draw(mapSurface->getCanvas(), cache); } -void DisplacementMapFilter::onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point&) { +void DisplacementMapFilter::onUpdateParams(const tgfx::GLInterface* gl, + const tgfx::Rect& contentBounds, const tgfx::Point&) { auto* pagEffect = reinterpret_cast(effect); - auto mapTexture = GLTexture::Unwrap(mapSurface->getTexture().get()); - ActiveTexture(gl, GL::TEXTURE1, GL::TEXTURE_2D, mapTexture.id); + auto mapTexture = tgfx::GLTexture::Unwrap(mapSurface->getTexture().get()); + ActiveGLTexture(gl, GL::TEXTURE1, GL::TEXTURE_2D, mapTexture.id); gl->uniform2f(useForDisplacementHandle, pagEffect->useForHorizontalDisplacement->getValueAt(layerFrame), pagEffect->useForVerticalDisplacement->getValueAt(layerFrame)); diff --git a/src/rendering/filters/DisplacementMapFilter.h b/src/rendering/filters/DisplacementMapFilter.h index ae263888ec..8ca107747a 100644 --- a/src/rendering/filters/DisplacementMapFilter.h +++ b/src/rendering/filters/DisplacementMapFilter.h @@ -28,20 +28,20 @@ class DisplacementMapFilter : public LayerFilter { explicit DisplacementMapFilter(Effect* effect); ~DisplacementMapFilter() override = default; - void updateMapTexture(RenderCache* cache, const Graphic* mapGraphic, const Rect& bounds); + void updateMapTexture(RenderCache* cache, const Graphic* mapGraphic, const tgfx::Rect& bounds); protected: std::string onBuildFragmentShader() override; - void onPrepareProgram(const GLInterface* gl, unsigned program) override; + void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) override; - void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) override; + void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) override; private: Effect* effect = nullptr; - Rect mapBounds = {}; - std::shared_ptr mapSurface = nullptr; + tgfx::Rect mapBounds = {}; + std::shared_ptr mapSurface = nullptr; int useForDisplacementHandle = 0; int maxDisplacementHandle = 0; diff --git a/src/rendering/filters/Filter.h b/src/rendering/filters/Filter.h index e64384febd..50a5f728d3 100644 --- a/src/rendering/filters/Filter.h +++ b/src/rendering/filters/Filter.h @@ -19,8 +19,8 @@ #pragma once #include +#include "core/Matrix.h" #include "gpu/opengl/GLContext.h" -#include "pag/types.h" namespace pag { struct FilterSource { @@ -45,7 +45,7 @@ struct FilterSource { * example, a blur of 4 pixels should be interpreted as a blur of 2 pixels if the scale factor is * 1/2 in each direction. */ - Point scale = {}; + tgfx::Point scale = {}; /** * The 3x3 texture coordinate transform matrix. This transform matrix maps 2D texture coordinates @@ -84,12 +84,13 @@ class Filter { public: virtual ~Filter() = default; - virtual bool initialize(Context* context) = 0; + virtual bool initialize(tgfx::Context* context) = 0; /** * Apply this filter to a filter source and draw it to a filter target. */ - virtual void draw(Context* context, const FilterSource* source, const FilterTarget* target) = 0; + virtual void draw(tgfx::Context* context, const FilterSource* source, + const FilterTarget* target) = 0; virtual bool needsMSAA() const { return false; diff --git a/src/rendering/filters/FilterModifier.cpp b/src/rendering/filters/FilterModifier.cpp index 815e7efc7d..9c3e5087c2 100644 --- a/src/rendering/filters/FilterModifier.cpp +++ b/src/rendering/filters/FilterModifier.cpp @@ -43,12 +43,12 @@ std::shared_ptr FilterModifier::Make(Layer* layer, Frame layerFr return modifier; } -void FilterModifier::applyToBounds(Rect* bounds) const { +void FilterModifier::applyToBounds(tgfx::Rect* bounds) const { FilterRenderer::MeasureFilterBounds(bounds, this); } -void FilterModifier::applyToGraphic(Canvas* canvas, RenderCache* cache, +void FilterModifier::applyToGraphic(tgfx::Canvas* canvas, RenderCache* cache, std::shared_ptr graphic) const { - FilterRenderer::DrawWithFilter(static_cast(canvas), cache, this, graphic); + FilterRenderer::DrawWithFilter(canvas, cache, this, graphic); } } // namespace pag diff --git a/src/rendering/filters/FilterModifier.h b/src/rendering/filters/FilterModifier.h index 24494ee120..d89575965a 100644 --- a/src/rendering/filters/FilterModifier.h +++ b/src/rendering/filters/FilterModifier.h @@ -52,13 +52,13 @@ class FilterModifier : public Modifier { void prepare(RenderCache*) const override { } - void applyToBounds(Rect* bounds) const override; + void applyToBounds(tgfx::Rect* bounds) const override; - bool applyToPath(Path*) const override { + bool applyToPath(tgfx::Path*) const override { return false; } - void applyToGraphic(Canvas* canvas, RenderCache* cache, + void applyToGraphic(tgfx::Canvas* canvas, RenderCache* cache, std::shared_ptr graphic) const override; std::shared_ptr mergeWith(const Modifier*) const override { diff --git a/src/rendering/filters/LayerFilter.cpp b/src/rendering/filters/LayerFilter.cpp index b052c7d1bd..e0532db3d7 100644 --- a/src/rendering/filters/LayerFilter.cpp +++ b/src/rendering/filters/LayerFilter.cpp @@ -24,7 +24,6 @@ #include "MosaicFilter.h" #include "MotionTileFilter.h" #include "RadialBlurFilter.h" -#include "gpu/opengl/GLUtil.h" #include "rendering/filters/dropshadow/DropShadowFilter.h" #include "rendering/filters/gaussblur/GaussBlurFilter.h" #include "rendering/filters/glow/GlowFilter.h" @@ -57,19 +56,20 @@ static constexpr char FRAGMENT_SHADER[] = R"( } )"; -std::vector ComputeVerticesForMotionBlurAndBulge(const Rect& inputBounds, - const Rect& outputBounds) { - std::vector vertices = {}; - Point contentPoint[4] = {{outputBounds.left, outputBounds.bottom}, - {outputBounds.right, outputBounds.bottom}, - {outputBounds.left, outputBounds.top}, - {outputBounds.right, outputBounds.top}}; +std::vector ComputeVerticesForMotionBlurAndBulge(const tgfx::Rect& inputBounds, + const tgfx::Rect& outputBounds) { + std::vector vertices = {}; + tgfx::Point contentPoint[4] = {{outputBounds.left, outputBounds.bottom}, + {outputBounds.right, outputBounds.bottom}, + {outputBounds.left, outputBounds.top}, + {outputBounds.right, outputBounds.top}}; auto deltaX = outputBounds.left - inputBounds.left; auto deltaY = outputBounds.top - inputBounds.top; - Point texturePoints[4] = {{deltaX, (outputBounds.height() + deltaY)}, - {(outputBounds.width() + deltaX), (outputBounds.height() + deltaY)}, - {deltaX, deltaY}, - {(outputBounds.width() + deltaX), deltaY}}; + tgfx::Point texturePoints[4] = { + {deltaX, (outputBounds.height() + deltaY)}, + {(outputBounds.width() + deltaX), (outputBounds.height() + deltaY)}, + {deltaX, deltaY}, + {(outputBounds.width() + deltaX), deltaY}}; for (int ii = 0; ii < 4; ii++) { vertices.push_back(contentPoint[ii]); vertices.push_back(texturePoints[ii]); @@ -77,11 +77,11 @@ std::vector ComputeVerticesForMotionBlurAndBulge(const Rect& inputBounds, return vertices; } -std::shared_ptr FilterProgram::Make(Context* context, +std::shared_ptr FilterProgram::Make(tgfx::Context* context, const std::string& vertex, const std::string& fragment) { - auto gl = GLContext::Unwrap(context); - auto program = CreateProgram(gl, vertex, fragment); + auto gl = tgfx::GLContext::Unwrap(context); + auto program = tgfx::CreateGLProgram(gl, vertex, fragment); if (program == 0) { return nullptr; } @@ -94,8 +94,8 @@ std::shared_ptr FilterProgram::Make(Context* context, return Resource::Wrap(context, filterProgram); } -void FilterProgram::onRelease(Context* context) { - auto gl = GLContext::Unwrap(context); +void FilterProgram::onRelease(tgfx::Context* context) { + auto gl = tgfx::GLContext::Unwrap(context); if (program > 0) { gl->deleteProgram(program); program = 0; @@ -157,8 +157,8 @@ std::unique_ptr LayerFilter::Make(Effect* effect) { return std::unique_ptr(filter); } -bool LayerFilter::initialize(Context* context) { - auto gl = GLContext::Unwrap(context); +bool LayerFilter::initialize(tgfx::Context* context) { + auto gl = tgfx::GLContext::Unwrap(context); // 防止前面产生的GLError,导致后面CheckGLError逻辑返回错误结果 CheckGLError(gl); @@ -189,40 +189,41 @@ std::string LayerFilter::onBuildFragmentShader() { return FRAGMENT_SHADER; } -void LayerFilter::onPrepareProgram(const GLInterface*, unsigned) { +void LayerFilter::onPrepareProgram(const tgfx::GLInterface*, unsigned) { } -void LayerFilter::onUpdateParams(const GLInterface*, const Rect&, const Point&) { +void LayerFilter::onUpdateParams(const tgfx::GLInterface*, const tgfx::Rect&, const tgfx::Point&) { } -void LayerFilter::update(Frame frame, const Rect& inputBounds, const Rect& outputBounds, - const Point& extraScale) { +void LayerFilter::update(Frame frame, const tgfx::Rect& inputBounds, const tgfx::Rect& outputBounds, + const tgfx::Point& extraScale) { layerFrame = frame; contentBounds = inputBounds; transformedBounds = outputBounds; filterScale = extraScale; } -static void EnableMultisample(const GLInterface* gl, bool usesMSAA) { +static void EnableMultisample(const tgfx::GLInterface* gl, bool usesMSAA) { if (usesMSAA && gl->caps->multisampleDisableSupport) { gl->enable(GL::MULTISAMPLE); } } -static void DisableMultisample(const GLInterface* gl, bool usesMSAA) { +static void DisableMultisample(const tgfx::GLInterface* gl, bool usesMSAA) { if (usesMSAA && gl->caps->multisampleDisableSupport) { gl->disable(GL::MULTISAMPLE); } } -void LayerFilter::draw(Context* context, const FilterSource* source, const FilterTarget* target) { +void LayerFilter::draw(tgfx::Context* context, const FilterSource* source, + const FilterTarget* target) { if (source == nullptr || target == nullptr || !filterProgram) { LOGE( "LayerFilter::draw() can not draw filter, " "because the argument(source/target) is null"); return; } - auto gl = GLContext::Unwrap(context); + auto gl = tgfx::GLContext::Unwrap(context); EnableMultisample(gl, needsMSAA()); gl->useProgram(filterProgram->program); gl->enable(GL::BLEND); @@ -231,7 +232,7 @@ void LayerFilter::draw(Context* context, const FilterSource* source, const Filte gl->bindFramebuffer(GL::FRAMEBUFFER, target->frameBufferID); gl->viewport(0, 0, target->width, target->height); - ActiveTexture(gl, GL::TEXTURE0, GL::TEXTURE_2D, source->textureID); + ActiveGLTexture(gl, GL::TEXTURE0, GL::TEXTURE_2D, source->textureID); gl->uniformMatrix3fv(vertexMatrixHandle, 1, GL::FALSE, target->vertexMatrix.data()); gl->uniformMatrix3fv(textureMatrixHandle, 1, GL::FALSE, source->textureMatrix.data()); onUpdateParams(gl, contentBounds, filterScale); @@ -245,17 +246,18 @@ void LayerFilter::draw(Context* context, const FilterSource* source, const Filte CheckGLError(gl); } -std::vector LayerFilter::computeVertices(const Rect& bounds, const Rect& transformed, - const Point&) { - std::vector vertices = {}; - Point contentPoint[4] = {{transformed.left, transformed.bottom}, - {transformed.right, transformed.bottom}, - {transformed.left, transformed.top}, - {transformed.right, transformed.top}}; - Point texturePoints[4] = {{0.0f, bounds.height()}, - {bounds.width(), bounds.height()}, - {0.0f, 0.0f}, - {bounds.width(), 0.0f}}; +std::vector LayerFilter::computeVertices(const tgfx::Rect& bounds, + const tgfx::Rect& transformed, + const tgfx::Point&) { + std::vector vertices = {}; + tgfx::Point contentPoint[4] = {{transformed.left, transformed.bottom}, + {transformed.right, transformed.bottom}, + {transformed.left, transformed.top}, + {transformed.right, transformed.top}}; + tgfx::Point texturePoints[4] = {{0.0f, bounds.height()}, + {bounds.width(), bounds.height()}, + {0.0f, 0.0f}, + {bounds.width(), 0.0f}}; for (int ii = 0; ii < 4; ii++) { vertices.push_back(contentPoint[ii]); vertices.push_back(texturePoints[ii]); @@ -263,8 +265,8 @@ std::vector LayerFilter::computeVertices(const Rect& bounds, const Rect& return vertices; } -void LayerFilter::bindVertices(const GLInterface* gl, const FilterSource* source, - const FilterTarget* target, const std::vector& points) { +void LayerFilter::bindVertices(const tgfx::GLInterface* gl, const FilterSource* source, + const FilterTarget* target, const std::vector& points) { std::vector vertices = {}; for (size_t i = 0; i < points.size();) { auto vertexPoint = ToGLVertexPoint(target, source, contentBounds, points[i++]); diff --git a/src/rendering/filters/LayerFilter.h b/src/rendering/filters/LayerFilter.h index d21e1e70e3..c4631355ce 100644 --- a/src/rendering/filters/LayerFilter.h +++ b/src/rendering/filters/LayerFilter.h @@ -22,14 +22,16 @@ #include "gpu/Resource.h" #include "pag/file.h" #include "pag/pag.h" +#include "rendering/filters/utils/FilterHelper.h" namespace pag { -std::vector ComputeVerticesForMotionBlurAndBulge(const Rect& inputBounds, - const Rect& outputBounds); +std::vector ComputeVerticesForMotionBlurAndBulge(const tgfx::Rect& inputBounds, + const tgfx::Rect& outputBounds); -class FilterProgram : public Resource { +class FilterProgram : public tgfx::Resource { public: - static std::shared_ptr Make(Context* context, const std::string& vertex, + static std::shared_ptr Make(tgfx::Context* context, + const std::string& vertex, const std::string& fragment); unsigned program = 0; @@ -37,7 +39,7 @@ class FilterProgram : public Resource { unsigned int vertexBuffer = 0; protected: - void onRelease(Context* context) override; + void onRelease(tgfx::Context* context) override; private: FilterProgram() = default; @@ -49,7 +51,7 @@ class LayerFilter : public Filter { static std::unique_ptr Make(Effect* effect); - bool initialize(Context* context) override; + bool initialize(tgfx::Context* context) override; virtual bool needsMSAA() const override; @@ -61,7 +63,8 @@ class LayerFilter : public Filter { * 该参数里含有纹理的ID、像素级的宽高、纹理点的matrix、以及纹理相对于layer bounds的scale信息 * @param target : 滤镜的输出target,该参数里含有frame buffer的ID、像素级的宽高、顶点的matrix信息 */ - void draw(Context* context, const FilterSource* source, const FilterTarget* target) override; + void draw(tgfx::Context* context, const FilterSource* source, + const FilterTarget* target) override; /** * filter的刷新接口。 @@ -76,8 +79,8 @@ class LayerFilter : public Filter { * 该filterScale等于反向matrix的scale,不包含source.scale, * source.scale会整体应用到FilterTarget上屏的matrix里。 */ - virtual void update(Frame layerFrame, const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale); + virtual void update(Frame layerFrame, const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, const tgfx::Point& filterScale); protected: Frame layerFrame = 0; @@ -87,7 +90,7 @@ class LayerFilter : public Filter { virtual std::string onBuildFragmentShader(); - virtual void onPrepareProgram(const GLInterface* gl, unsigned program); + virtual void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program); /** * filter的给shader上传数据接口 @@ -96,8 +99,8 @@ class LayerFilter : public Filter { * bounds来计算shader中的参数,比如:bulge、MotionTile * @param filterScale : 滤镜效果的scale */ - virtual void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale); + virtual void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale); /** * filter的收集顶点数据的接口 @@ -108,17 +111,17 @@ class LayerFilter : public Filter { * @return : 返回顶点与纹理的point数组,顶点 + 纹理 + 顶点 + * 纹理的组合方式,所有的Point都是基于layer bounds尺寸的点 */ - virtual std::vector computeVertices(const Rect& contentBounds, - const Rect& transformedBounds, - const Point& filterScale); + virtual std::vector computeVertices(const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale); - virtual void bindVertices(const GLInterface* gl, const FilterSource* source, - const FilterTarget* target, const std::vector& points); + virtual void bindVertices(const tgfx::GLInterface* gl, const FilterSource* source, + const FilterTarget* target, const std::vector& points); private: - Rect contentBounds = {}; - Rect transformedBounds = {}; - Point filterScale = {}; + tgfx::Rect contentBounds = {}; + tgfx::Rect transformedBounds = {}; + tgfx::Point filterScale = {}; int vertexMatrixHandle = -1; int textureMatrixHandle = -1; diff --git a/src/rendering/filters/LayerStylesFilter.cpp b/src/rendering/filters/LayerStylesFilter.cpp index 65b481f31b..142539331e 100644 --- a/src/rendering/filters/LayerStylesFilter.cpp +++ b/src/rendering/filters/LayerStylesFilter.cpp @@ -21,10 +21,11 @@ #include "rendering/renderers/FilterRenderer.h" namespace pag { -void LayerStylesFilter::TransformBounds(Rect* bounds, const FilterList* filterList) { +void LayerStylesFilter::TransformBounds(tgfx::Rect* bounds, const FilterList* filterList) { for (auto& layerStyle : filterList->layerStyles) { auto rect = *bounds; - layerStyle->transformBounds(&rect, filterList->layerStyleScale, filterList->layerFrame); + layerStyle->transformBounds(ToPAG(&rect), ToPAG(filterList->layerStyleScale), + filterList->layerFrame); rect.roundOut(); bounds->join(rect); } @@ -38,19 +39,19 @@ LayerStylesFilter::~LayerStylesFilter() { delete drawFilter; } -bool LayerStylesFilter::initialize(Context* context) { +bool LayerStylesFilter::initialize(tgfx::Context* context) { return drawFilter->initialize(context); } -void LayerStylesFilter::update(const FilterList* list, const Rect& inputBounds, - const Rect& outputBounds, const Point& extraScale) { +void LayerStylesFilter::update(const FilterList* list, const tgfx::Rect& inputBounds, + const tgfx::Rect& outputBounds, const tgfx::Point& extraScale) { filterList = list; contentBounds = inputBounds; transformedBounds = outputBounds; filterScale = extraScale; } -void LayerStylesFilter::draw(Context* context, const FilterSource* source, +void LayerStylesFilter::draw(tgfx::Context* context, const FilterSource* source, const FilterTarget* target) { for (auto& layerStyle : filterList->layerStyles) { if (layerStyle->drawPosition() == LayerStylePosition::Blow) { diff --git a/src/rendering/filters/LayerStylesFilter.h b/src/rendering/filters/LayerStylesFilter.h index ad022f30a1..cd4f83322a 100644 --- a/src/rendering/filters/LayerStylesFilter.h +++ b/src/rendering/filters/LayerStylesFilter.h @@ -29,25 +29,26 @@ struct FilterList; class LayerStylesFilter : public Filter { public: - static void TransformBounds(Rect* bounds, const FilterList* filterList); + static void TransformBounds(tgfx::Rect* bounds, const FilterList* filterList); explicit LayerStylesFilter(RenderCache* renderCache); ~LayerStylesFilter() override; - bool initialize(Context* context) override; + bool initialize(tgfx::Context* context) override; - void update(const FilterList* filterList, const Rect& contentBounds, - const Rect& transformedBounds, const Point& filterScale); + void update(const FilterList* filterList, const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, const tgfx::Point& filterScale); - void draw(Context* context, const FilterSource* source, const FilterTarget* target) override; + void draw(tgfx::Context* context, const FilterSource* source, + const FilterTarget* target) override; private: const FilterList* filterList = nullptr; RenderCache* renderCache = nullptr; LayerFilter* drawFilter = nullptr; - Rect contentBounds = {}; - Rect transformedBounds = {}; - Point filterScale = {}; + tgfx::Rect contentBounds = {}; + tgfx::Rect transformedBounds = {}; + tgfx::Point filterScale = {}; }; } // namespace pag diff --git a/src/rendering/filters/LevelsIndividualFilter.cpp b/src/rendering/filters/LevelsIndividualFilter.cpp index 53d3b0d75b..8b7ddc43c4 100644 --- a/src/rendering/filters/LevelsIndividualFilter.cpp +++ b/src/rendering/filters/LevelsIndividualFilter.cpp @@ -17,7 +17,6 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "LevelsIndividualFilter.h" -#include "gpu/opengl/GLUtil.h" namespace pag { static const char FRAGMENT_SHADER[] = R"( @@ -87,7 +86,7 @@ std::string LevelsIndividualFilter::onBuildFragmentShader() { return FRAGMENT_SHADER; } -void LevelsIndividualFilter::onPrepareProgram(const GLInterface* gl, unsigned int program) { +void LevelsIndividualFilter::onPrepareProgram(const tgfx::GLInterface* gl, unsigned int program) { inputBlackHandle = gl->getUniformLocation(program, "inputBlack"); inputWhiteHandle = gl->getUniformLocation(program, "inputWhite"); gammaHandle = gl->getUniformLocation(program, "gamma"); @@ -113,7 +112,8 @@ void LevelsIndividualFilter::onPrepareProgram(const GLInterface* gl, unsigned in blueOutputWhiteHandle = gl->getUniformLocation(program, "blueOutputWhite"); } -void LevelsIndividualFilter::onUpdateParams(const GLInterface* gl, const Rect&, const Point&) { +void LevelsIndividualFilter::onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect&, + const tgfx::Point&) { auto* levelsIndividualFilter = reinterpret_cast(effect); gl->uniform1f(inputBlackHandle, levelsIndividualFilter->inputBlack->getValueAt(layerFrame)); gl->uniform1f(inputWhiteHandle, levelsIndividualFilter->inputWhite->getValueAt(layerFrame)); diff --git a/src/rendering/filters/LevelsIndividualFilter.h b/src/rendering/filters/LevelsIndividualFilter.h index 2d9a3b0985..555f4a231b 100644 --- a/src/rendering/filters/LevelsIndividualFilter.h +++ b/src/rendering/filters/LevelsIndividualFilter.h @@ -29,10 +29,10 @@ class LevelsIndividualFilter : public LayerFilter { protected: std::string onBuildFragmentShader() override; - void onPrepareProgram(const GLInterface* gl, unsigned program) override; + void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) override; - void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) override; + void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) override; private: Effect* effect = nullptr; diff --git a/src/rendering/filters/MosaicFilter.cpp b/src/rendering/filters/MosaicFilter.cpp index 714a50c6ab..b65f241c6e 100644 --- a/src/rendering/filters/MosaicFilter.cpp +++ b/src/rendering/filters/MosaicFilter.cpp @@ -17,7 +17,6 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "MosaicFilter.h" -#include "gpu/opengl/GLUtil.h" namespace pag { static const char FRAGMENT_SHADER[] = R"( @@ -44,13 +43,14 @@ std::string MosaicFilter::onBuildFragmentShader() { return FRAGMENT_SHADER; } -void MosaicFilter::onPrepareProgram(const GLInterface* gl, unsigned int program) { +void MosaicFilter::onPrepareProgram(const tgfx::GLInterface* gl, unsigned int program) { horizontalBlocksHandle = gl->getUniformLocation(program, "mHorizontalBlocks"); verticalBlocksHandle = gl->getUniformLocation(program, "mVerticalBlocks"); sharpColorsHandle = gl->getUniformLocation(program, "mSharpColors"); } -void MosaicFilter::onUpdateParams(const GLInterface* gl, const Rect& contentBounds, const Point&) { +void MosaicFilter::onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point&) { auto* mosaicEffect = reinterpret_cast(effect); horizontalBlocks = 1.0f / mosaicEffect->horizontalBlocks->getValueAt(layerFrame); verticalBlocks = 1.0f / mosaicEffect->verticalBlocks->getValueAt(layerFrame); diff --git a/src/rendering/filters/MosaicFilter.h b/src/rendering/filters/MosaicFilter.h index 820a5a7663..ad7106ea8f 100644 --- a/src/rendering/filters/MosaicFilter.h +++ b/src/rendering/filters/MosaicFilter.h @@ -29,10 +29,10 @@ class MosaicFilter : public LayerFilter { protected: std::string onBuildFragmentShader() override; - void onPrepareProgram(const GLInterface* gl, unsigned program) override; + void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) override; - void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) override; + void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) override; private: Effect* effect = nullptr; diff --git a/src/rendering/filters/MotionBlurFilter.cpp b/src/rendering/filters/MotionBlurFilter.cpp index 273348c513..aa3feef9e5 100644 --- a/src/rendering/filters/MotionBlurFilter.cpp +++ b/src/rendering/filters/MotionBlurFilter.cpp @@ -17,7 +17,6 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "MotionBlurFilter.h" -#include "gpu/opengl/GLUtil.h" #include "rendering/caches/LayerCache.h" #include "rendering/filters/utils/FilterHelper.h" @@ -82,7 +81,8 @@ static const char MOTIONBLUR_FRAGMENT_SHADER[] = R"( } )"; -void MotionBlurFilter::TransformBounds(Rect* bounds, const Point&, Layer* layer, Frame layerFrame) { +void MotionBlurFilter::TransformBounds(tgfx::Rect* bounds, const tgfx::Point&, Layer* layer, + Frame layerFrame) { auto contentFrame = layerFrame - layer->startTime; auto layerCache = LayerCache::Get(layer); auto previousMatrix = layerCache->getTransform(contentFrame > 0 ? contentFrame - 1 : 0)->matrix; @@ -107,7 +107,7 @@ std::string MotionBlurFilter::onBuildFragmentShader() { return MOTIONBLUR_FRAGMENT_SHADER; } -void MotionBlurFilter::onPrepareProgram(const GLInterface* gl, unsigned int program) { +void MotionBlurFilter::onPrepareProgram(const tgfx::GLInterface* gl, unsigned int program) { prevTransformHandle = gl->getUniformLocation(program, "uPrevTransform"); transformHandle = gl->getUniformLocation(program, "uTransform"); velCenterHandle = gl->getUniformLocation(program, "uVelCenter"); @@ -122,16 +122,18 @@ bool MotionBlurFilter::updateLayer(Layer* targetLayer, Frame layerFrame) { return previousMatrix != currentMatrix; } -void MotionBlurFilter::onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point&) { +void MotionBlurFilter::onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point&) { auto width = static_cast(contentBounds.width()); auto height = static_cast(contentBounds.height()); - auto origin = ImageOrigin::BottomLeft; + auto origin = tgfx::ImageOrigin::BottomLeft; previousMatrix.preTranslate(contentBounds.left, contentBounds.top); currentMatrix.preTranslate(contentBounds.left, contentBounds.top); - std::array previousGLMatrix = ToGLTextureMatrix(previousMatrix, width, height, origin); - std::array currentGLMatrix = ToGLTextureMatrix(currentMatrix, width, height, origin); + std::array previousGLMatrix = + tgfx::ToGLTextureMatrix(previousMatrix, width, height, origin); + std::array currentGLMatrix = + tgfx::ToGLTextureMatrix(currentMatrix, width, height, origin); auto scaling = (previousMatrix.getScaleX() != currentMatrix.getScaleX() || previousMatrix.getScaleY() != currentMatrix.getScaleY()); @@ -142,8 +144,9 @@ void MotionBlurFilter::onUpdateParams(const GLInterface* gl, const Rect& content gl->uniform1f(maxDistanceHandle, (MOTION_BLUR_SCALE_FACTOR - 1.0) * 0.5f); } -std::vector MotionBlurFilter::computeVertices(const Rect& inputBounds, - const Rect& outputBounds, const Point&) { +std::vector MotionBlurFilter::computeVertices(const tgfx::Rect& inputBounds, + const tgfx::Rect& outputBounds, + const tgfx::Point&) { return ComputeVerticesForMotionBlurAndBulge(inputBounds, outputBounds); } } // namespace pag diff --git a/src/rendering/filters/MotionBlurFilter.h b/src/rendering/filters/MotionBlurFilter.h index 607d68ac9a..620fa35696 100644 --- a/src/rendering/filters/MotionBlurFilter.h +++ b/src/rendering/filters/MotionBlurFilter.h @@ -23,7 +23,7 @@ namespace pag { class MotionBlurFilter : public LayerFilter { public: - static void TransformBounds(Rect* bounds, const Point& filterScale, Layer* layer, + static void TransformBounds(tgfx::Rect* bounds, const tgfx::Point& filterScale, Layer* layer, Frame layerFrame); MotionBlurFilter(); @@ -36,17 +36,18 @@ class MotionBlurFilter : public LayerFilter { std::string onBuildFragmentShader() override; - void onPrepareProgram(const GLInterface* gl, unsigned program) override; + void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) override; - void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) override; + void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) override; - std::vector computeVertices(const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale) override; + std::vector computeVertices(const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale) override; private: - Matrix previousMatrix = Matrix::I(); - Matrix currentMatrix = Matrix::I(); + tgfx::Matrix previousMatrix = tgfx::Matrix::I(); + tgfx::Matrix currentMatrix = tgfx::Matrix::I(); int prevTransformHandle = 0; int transformHandle = 0; diff --git a/src/rendering/filters/MotionTileFilter.cpp b/src/rendering/filters/MotionTileFilter.cpp index 24d489ac8c..e66954d9bb 100644 --- a/src/rendering/filters/MotionTileFilter.cpp +++ b/src/rendering/filters/MotionTileFilter.cpp @@ -17,7 +17,6 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "MotionTileFilter.h" -#include "gpu/opengl/GLUtil.h" #include "rendering/filters/utils/FilterHelper.h" namespace pag { @@ -99,7 +98,7 @@ std::string MotionTileFilter::onBuildFragmentShader() { return MOTIONTILE_FRAGMENT_SHADER; } -void MotionTileFilter::onPrepareProgram(const GLInterface* gl, unsigned int program) { +void MotionTileFilter::onPrepareProgram(const tgfx::GLInterface* gl, unsigned int program) { tileCenterHandle = gl->getUniformLocation(program, "uTileCenter"); tileWidthHandle = gl->getUniformLocation(program, "uTileWidth"); tileHeightHandle = gl->getUniformLocation(program, "uTileHeight"); @@ -110,8 +109,8 @@ void MotionTileFilter::onPrepareProgram(const GLInterface* gl, unsigned int prog isHorizontalPhaseShiftHandle = gl->getUniformLocation(program, "uIsHorizontalPhaseShift"); } -void MotionTileFilter::onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point&) { +void MotionTileFilter::onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point&) { auto* pagEffect = reinterpret_cast(effect); auto tileCenter = pagEffect->tileCenter->getValueAt(layerFrame); auto tileWidth = pagEffect->tileWidth->getValueAt(layerFrame); diff --git a/src/rendering/filters/MotionTileFilter.h b/src/rendering/filters/MotionTileFilter.h index 4dfc928283..dfdbe33f03 100644 --- a/src/rendering/filters/MotionTileFilter.h +++ b/src/rendering/filters/MotionTileFilter.h @@ -31,10 +31,10 @@ class MotionTileFilter : public LayerFilter { std::string onBuildFragmentShader() override; - void onPrepareProgram(const GLInterface* gl, unsigned program) override; + void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) override; - void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) override; + void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) override; private: Effect* effect = nullptr; diff --git a/src/rendering/filters/RadialBlurFilter.cpp b/src/rendering/filters/RadialBlurFilter.cpp index 17056db4bd..ed041eea2c 100644 --- a/src/rendering/filters/RadialBlurFilter.cpp +++ b/src/rendering/filters/RadialBlurFilter.cpp @@ -17,7 +17,6 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "RadialBlurFilter.h" -#include "gpu/opengl/GLUtil.h" namespace pag { @@ -62,13 +61,13 @@ std::string RadialBlurFilter::onBuildFragmentShader() { return RADIAL_BLUR_FRAGMENT_SHADER; } -void RadialBlurFilter::onPrepareProgram(const GLInterface* gl, unsigned int program) { +void RadialBlurFilter::onPrepareProgram(const tgfx::GLInterface* gl, unsigned int program) { amountHandle = gl->getUniformLocation(program, "uAmount"); centerHandle = gl->getUniformLocation(program, "uCenter"); } -void RadialBlurFilter::onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point&) { +void RadialBlurFilter::onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point&) { auto* radialBlurEffect = reinterpret_cast(effect); auto amount = radialBlurEffect->amount->getValueAt(layerFrame) * 0.00625; auto center = radialBlurEffect->center->getValueAt(layerFrame); diff --git a/src/rendering/filters/RadialBlurFilter.h b/src/rendering/filters/RadialBlurFilter.h index aeecab4732..0aaa4791e7 100644 --- a/src/rendering/filters/RadialBlurFilter.h +++ b/src/rendering/filters/RadialBlurFilter.h @@ -29,10 +29,10 @@ class RadialBlurFilter : public LayerFilter { protected: std::string onBuildFragmentShader() override; - void onPrepareProgram(const GLInterface* gl, unsigned program) override; + void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) override; - void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) override; + void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) override; private: Effect* effect = nullptr; diff --git a/src/rendering/filters/dropshadow/DropShadowFilter.cpp b/src/rendering/filters/dropshadow/DropShadowFilter.cpp index 2ed58a3583..551583fc1d 100644 --- a/src/rendering/filters/dropshadow/DropShadowFilter.cpp +++ b/src/rendering/filters/dropshadow/DropShadowFilter.cpp @@ -17,10 +17,9 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "DropShadowFilter.h" -#include "base/utils/MathExtra.h" -#include "gpu/opengl/GLUtil.h" +#include "base/utils/MathUtil.h" +#include "base/utils/TGFXCast.h" #include "rendering/filters/utils/FilterHelper.h" -#include "rendering/utils/TGFXTypes.h" namespace pag { DropShadowFilter::DropShadowFilter(DropShadowStyle* layerStyle) : layerStyle(layerStyle) { @@ -37,7 +36,7 @@ DropShadowFilter::~DropShadowFilter() { delete spreadThickFilter; } -bool DropShadowFilter::initialize(Context* context) { +bool DropShadowFilter::initialize(tgfx::Context* context) { if (!blurFilterV->initialize(context)) { return false; } @@ -53,11 +52,11 @@ bool DropShadowFilter::initialize(Context* context) { return true; } -void DropShadowFilter::update(Frame frame, const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale) { +void DropShadowFilter::update(Frame frame, const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, const tgfx::Point& filterScale) { LayerFilter::update(frame, contentBounds, transformedBounds, filterScale); - color = ToTGFXColor(layerStyle->color->getValueAt(layerFrame)); + color = ToTGFX(layerStyle->color->getValueAt(layerFrame)); alpha = ToAlpha(layerStyle->opacity->getValueAt(layerFrame)); spread = layerStyle->spread->getValueAt(layerFrame); auto size = layerStyle->size->getValueAt(layerFrame); @@ -76,7 +75,7 @@ void DropShadowFilter::update(Frame frame, const Rect& contentBounds, const Rect } } -void DropShadowFilter::draw(Context* context, const FilterSource* source, +void DropShadowFilter::draw(tgfx::Context* context, const FilterSource* source, const FilterTarget* target) { if (source == nullptr || target == nullptr) { return; @@ -90,8 +89,8 @@ void DropShadowFilter::draw(Context* context, const FilterSource* source, } } -void DropShadowFilter::updateParamModeNotSpread(Frame frame, const Rect& contentBounds, const Rect&, - const Point& filterScale) { +void DropShadowFilter::updateParamModeNotSpread(Frame frame, const tgfx::Rect& contentBounds, + const tgfx::Rect&, const tgfx::Point& filterScale) { auto angle = layerStyle->angle->getValueAt(layerFrame); auto distance = layerStyle->distance->getValueAt(layerFrame); auto radians = DegreesToRadians(angle - 180); @@ -112,8 +111,9 @@ void DropShadowFilter::updateParamModeNotSpread(Frame frame, const Rect& content filtersBounds.emplace_back(filterHBounds); } -void DropShadowFilter::updateParamModeNotFullSpread(Frame frame, const Rect& contentBounds, - const Rect&, const Point& filterScale) { +void DropShadowFilter::updateParamModeNotFullSpread(Frame frame, const tgfx::Rect& contentBounds, + const tgfx::Rect&, + const tgfx::Point& filterScale) { auto angle = layerStyle->angle->getValueAt(layerFrame); auto distance = layerStyle->distance->getValueAt(layerFrame); auto radians = DegreesToRadians(angle - 180); @@ -142,8 +142,9 @@ void DropShadowFilter::updateParamModeNotFullSpread(Frame frame, const Rect& con filtersBounds.emplace_back(filterBounds); } -void DropShadowFilter::updateParamModeFullSpread(Frame frame, const Rect& contentBounds, - const Rect&, const Point& filterScale) { +void DropShadowFilter::updateParamModeFullSpread(Frame frame, const tgfx::Rect& contentBounds, + const tgfx::Rect&, + const tgfx::Point& filterScale) { auto angle = layerStyle->angle->getValueAt(layerFrame); auto distance = layerStyle->distance->getValueAt(layerFrame); auto radians = DegreesToRadians(angle - 180); @@ -162,7 +163,7 @@ void DropShadowFilter::updateParamModeFullSpread(Frame frame, const Rect& conten filtersBounds.emplace_back(filterBounds); } -void DropShadowFilter::onDrawModeNotSpread(Context* context, const FilterSource* source, +void DropShadowFilter::onDrawModeNotSpread(tgfx::Context* context, const FilterSource* source, const FilterTarget* target) { auto contentBounds = filtersBounds[0]; auto filterBounds = filtersBounds[1]; @@ -175,11 +176,12 @@ void DropShadowFilter::onDrawModeNotSpread(Context* context, const FilterSource* if (blurFilterBuffer == nullptr) { return; } - auto gl = GLContext::Unwrap(context); + auto gl = tgfx::GLContext::Unwrap(context); blurFilterBuffer->clearColor(gl); - auto offsetMatrix = Matrix::MakeTrans((contentBounds.left - filterBounds.left) * source->scale.x, - (contentBounds.top - filterBounds.top) * source->scale.y); + auto offsetMatrix = + tgfx::Matrix::MakeTrans((contentBounds.left - filterBounds.left) * source->scale.x, + (contentBounds.top - filterBounds.top) * source->scale.y); auto targetV = blurFilterBuffer->toFilterTarget(offsetMatrix); blurFilterV->updateParams(blurSize, 1.0, false, BlurMode::Shadow); @@ -190,16 +192,16 @@ void DropShadowFilter::onDrawModeNotSpread(Context* context, const FilterSource* auto sourceH = blurFilterBuffer->toFilterSource(source->scale); blurFilterH->updateParams(blurSize, alpha, false, BlurMode::Shadow); - Matrix revertMatrix = - Matrix::MakeTrans((filterBounds.left - contentBounds.left) * source->scale.x, - (filterBounds.top - contentBounds.top) * source->scale.y); + tgfx::Matrix revertMatrix = + tgfx::Matrix::MakeTrans((filterBounds.left - contentBounds.left) * source->scale.x, + (filterBounds.top - contentBounds.top) * source->scale.y); auto targetH = *target; PreConcatMatrix(&targetH, revertMatrix); blurFilterH->draw(context, sourceH.get(), &targetH); } -void DropShadowFilter::onDrawModeNotFullSpread(Context* context, const FilterSource* source, +void DropShadowFilter::onDrawModeNotFullSpread(tgfx::Context* context, const FilterSource* source, const FilterTarget* target) { auto contentBounds = filtersBounds[0]; auto lastBounds = contentBounds; @@ -213,10 +215,11 @@ void DropShadowFilter::onDrawModeNotFullSpread(Context* context, const FilterSou if (spreadFilterBuffer == nullptr) { return; } - auto gl = GLContext::Unwrap(context); + auto gl = tgfx::GLContext::Unwrap(context); spreadFilterBuffer->clearColor(gl); - auto offsetMatrix = Matrix::MakeTrans((lastBounds.left - filterBounds.left) * source->scale.x, - (lastBounds.top - filterBounds.top) * source->scale.y); + auto offsetMatrix = + tgfx::Matrix::MakeTrans((lastBounds.left - filterBounds.left) * source->scale.x, + (lastBounds.top - filterBounds.top) * source->scale.y); auto targetSpread = spreadFilterBuffer->toFilterTarget(offsetMatrix); if (spreadSize < DROPSHADOW_SPREAD_MIN_THICK_SIZE) { spreadFilter->draw(context, source, targetSpread.get()); @@ -237,23 +240,23 @@ void DropShadowFilter::onDrawModeNotFullSpread(Context* context, const FilterSou return; } blurFilterBuffer->clearColor(gl); - offsetMatrix = Matrix::MakeTrans((lastBounds.left - filterBounds.left) * source->scale.x, - (lastBounds.top - filterBounds.top) * source->scale.y); + offsetMatrix = tgfx::Matrix::MakeTrans((lastBounds.left - filterBounds.left) * source->scale.x, + (lastBounds.top - filterBounds.top) * source->scale.y); auto targetV = blurFilterBuffer->toFilterTarget(offsetMatrix); blurFilterV->updateParams(blurSize, 1.0, false, BlurMode::Shadow); blurFilterV->draw(context, sourceV.get(), targetV.get()); auto sourceH = blurFilterBuffer->toFilterSource(source->scale); - Matrix revertMatrix = - Matrix::MakeTrans((filterBounds.left - contentBounds.left) * source->scale.x, - (filterBounds.top - contentBounds.top) * source->scale.y); + tgfx::Matrix revertMatrix = + tgfx::Matrix::MakeTrans((filterBounds.left - contentBounds.left) * source->scale.x, + (filterBounds.top - contentBounds.top) * source->scale.y); auto targetH = *target; PreConcatMatrix(&targetH, revertMatrix); blurFilterH->updateParams(blurSize, alpha, false, BlurMode::Shadow); blurFilterH->draw(context, sourceH.get(), &targetH); } -void DropShadowFilter::onDrawModeFullSpread(Context* context, const FilterSource* source, +void DropShadowFilter::onDrawModeFullSpread(tgfx::Context* context, const FilterSource* source, const FilterTarget* target) { if (spreadSize < DROPSHADOW_SPREAD_MIN_THICK_SIZE) { spreadFilter->draw(context, source, target); diff --git a/src/rendering/filters/dropshadow/DropShadowFilter.h b/src/rendering/filters/dropshadow/DropShadowFilter.h index 2eede1c7e8..8692dee8ba 100644 --- a/src/rendering/filters/dropshadow/DropShadowFilter.h +++ b/src/rendering/filters/dropshadow/DropShadowFilter.h @@ -29,12 +29,13 @@ class DropShadowFilter : public LayerFilter { explicit DropShadowFilter(DropShadowStyle* layerStyle); ~DropShadowFilter() override; - bool initialize(Context* context) override; + bool initialize(tgfx::Context* context) override; - void update(Frame frame, const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale) override; + void update(Frame frame, const tgfx::Rect& contentBounds, const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale) override; - void draw(Context* context, const FilterSource* source, const FilterTarget* target) override; + void draw(tgfx::Context* context, const FilterSource* source, + const FilterTarget* target) override; private: DropShadowStyle* layerStyle = nullptr; @@ -47,25 +48,28 @@ class DropShadowFilter : public LayerFilter { DropShadowSpreadFilter* spreadFilter = nullptr; DropShadowSpreadFilter* spreadThickFilter = nullptr; - Color4f color = Color4f::Black(); + tgfx::Color color = tgfx::Color::Black(); float alpha = 0.0f; float spread = 0.0f; float spreadSize = 0.0f; float blurSize = 0.0f; - std::vector filtersBounds = {}; + std::vector filtersBounds = {}; - void updateParamModeNotSpread(Frame frame, const Rect& contentBounds, - const Rect& transformedBounds, const Point& filterScale); - void updateParamModeNotFullSpread(Frame frame, const Rect& contentBounds, - const Rect& transformedBounds, const Point& filterScale); - void updateParamModeFullSpread(Frame frame, const Rect& contentBounds, - const Rect& transformedBounds, const Point& filterScale); + void updateParamModeNotSpread(Frame frame, const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale); + void updateParamModeNotFullSpread(Frame frame, const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale); + void updateParamModeFullSpread(Frame frame, const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale); - void onDrawModeNotSpread(Context* context, const FilterSource* source, + void onDrawModeNotSpread(tgfx::Context* context, const FilterSource* source, const FilterTarget* target); - void onDrawModeNotFullSpread(Context* context, const FilterSource* source, + void onDrawModeNotFullSpread(tgfx::Context* context, const FilterSource* source, const FilterTarget* target); - void onDrawModeFullSpread(Context* context, const FilterSource* source, + void onDrawModeFullSpread(tgfx::Context* context, const FilterSource* source, const FilterTarget* target); }; } // namespace pag diff --git a/src/rendering/filters/dropshadow/DropShadowSpreadFilter.cpp b/src/rendering/filters/dropshadow/DropShadowSpreadFilter.cpp index 59a5932e07..cd686336ae 100644 --- a/src/rendering/filters/dropshadow/DropShadowSpreadFilter.cpp +++ b/src/rendering/filters/dropshadow/DropShadowSpreadFilter.cpp @@ -17,9 +17,8 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "DropShadowSpreadFilter.h" -#include "gpu/opengl/GLUtil.h" +#include "base/utils/TGFXCast.h" #include "rendering/filters/utils/BlurTypes.h" -#include "rendering/utils/TGFXTypes.h" namespace pag { static const char DROPSHADOW_SPREAD_FRAGMENT_SHADER[] = R"( @@ -89,15 +88,16 @@ std::string DropShadowSpreadFilter::onBuildFragmentShader() { return DROPSHADOW_SPREAD_FRAGMENT_SHADER; } -void DropShadowSpreadFilter::onPrepareProgram(const GLInterface* gl, unsigned program) { +void DropShadowSpreadFilter::onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) { spreadColorHandle = gl->getUniformLocation(program, "uColor"); spreadAlphaHandle = gl->getUniformLocation(program, "uAlpha"); spreadSizeHandle = gl->getUniformLocation(program, "uSize"); } -void DropShadowSpreadFilter::onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) { - auto color = ToTGFXColor(layerStyle->color->getValueAt(layerFrame)); +void DropShadowSpreadFilter::onUpdateParams(const tgfx::GLInterface* gl, + const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) { + auto color = ToTGFX(layerStyle->color->getValueAt(layerFrame)); auto alpha = ToAlpha(layerStyle->opacity->getValueAt(layerFrame)); auto spread = layerStyle->spread->getValueAt(layerFrame); auto size = layerStyle->size->getValueAt(layerFrame); @@ -114,23 +114,25 @@ void DropShadowSpreadFilter::onUpdateParams(const GLInterface* gl, const Rect& c spreadSizeY / contentBounds.height()); } -std::vector DropShadowSpreadFilter::computeVertices(const Rect&, const Rect& outputBounds, - const Point& filterScale) { - std::vector vertices = {}; - Point contentPoint[4] = {{outputBounds.left, outputBounds.bottom}, - {outputBounds.right, outputBounds.bottom}, - {outputBounds.left, outputBounds.top}, - {outputBounds.right, outputBounds.top}}; +std::vector DropShadowSpreadFilter::computeVertices(const tgfx::Rect&, + const tgfx::Rect& outputBounds, + const tgfx::Point& filterScale) { + std::vector vertices = {}; + tgfx::Point contentPoint[4] = {{outputBounds.left, outputBounds.bottom}, + {outputBounds.right, outputBounds.bottom}, + {outputBounds.left, outputBounds.top}, + {outputBounds.right, outputBounds.top}}; auto spread = layerStyle->spread->getValueAt(layerFrame); auto size = layerStyle->size->getValueAt(layerFrame); auto deltaX = -size * spread * filterScale.x; auto deltaY = -size * spread * filterScale.y; - Point texturePoints[4] = {{deltaX, (outputBounds.height() + deltaY)}, - {(outputBounds.width() + deltaX), (outputBounds.height() + deltaY)}, - {deltaX, deltaY}, - {(outputBounds.width() + deltaX), deltaY}}; + tgfx::Point texturePoints[4] = { + {deltaX, (outputBounds.height() + deltaY)}, + {(outputBounds.width() + deltaX), (outputBounds.height() + deltaY)}, + {deltaX, deltaY}, + {(outputBounds.width() + deltaX), deltaY}}; for (int ii = 0; ii < 4; ii++) { vertices.push_back(contentPoint[ii]); vertices.push_back(texturePoints[ii]); diff --git a/src/rendering/filters/dropshadow/DropShadowSpreadFilter.h b/src/rendering/filters/dropshadow/DropShadowSpreadFilter.h index 7b1f5ee933..a0573217d6 100644 --- a/src/rendering/filters/dropshadow/DropShadowSpreadFilter.h +++ b/src/rendering/filters/dropshadow/DropShadowSpreadFilter.h @@ -31,13 +31,14 @@ class DropShadowSpreadFilter : public LayerFilter { protected: std::string onBuildFragmentShader() override; - void onPrepareProgram(const GLInterface* gl, unsigned program) override; + void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) override; - void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) override; + void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) override; - std::vector computeVertices(const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale) override; + std::vector computeVertices(const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale) override; private: DropShadowStyle* layerStyle = nullptr; diff --git a/src/rendering/filters/gaussblur/GaussBlurFilter.cpp b/src/rendering/filters/gaussblur/GaussBlurFilter.cpp index 2b2f4f293a..3948e935db 100644 --- a/src/rendering/filters/gaussblur/GaussBlurFilter.cpp +++ b/src/rendering/filters/gaussblur/GaussBlurFilter.cpp @@ -17,7 +17,6 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "GaussBlurFilter.h" -#include "gpu/opengl/GLUtil.h" #include "rendering/filters/utils/FilterHelper.h" namespace pag { @@ -31,7 +30,7 @@ GaussBlurFilter::~GaussBlurFilter() { delete blurFilterH; } -bool GaussBlurFilter::initialize(Context* context) { +bool GaussBlurFilter::initialize(tgfx::Context* context) { if (!blurFilterV->initialize(context)) { return false; } @@ -41,8 +40,8 @@ bool GaussBlurFilter::initialize(Context* context) { return true; } -void GaussBlurFilter::update(Frame frame, const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale) { +void GaussBlurFilter::update(Frame frame, const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, const tgfx::Point& filterScale) { LayerFilter::update(frame, contentBounds, transformedBounds, filterScale); auto* gaussBlurEffect = static_cast(effect); @@ -74,7 +73,7 @@ void GaussBlurFilter::update(Frame frame, const Rect& contentBounds, const Rect& filtersBounds.emplace_back(transformedBounds); } -void GaussBlurFilter::draw(Context* context, const FilterSource* source, +void GaussBlurFilter::draw(tgfx::Context* context, const FilterSource* source, const FilterTarget* target) { if (source == nullptr || target == nullptr) { LOGE("GaussFilter::draw() can not draw filter"); @@ -102,20 +101,20 @@ void GaussBlurFilter::draw(Context* context, const FilterSource* source, if (blurFilterBuffer == nullptr) { return; } - auto gl = GLContext::Unwrap(context); + auto gl = tgfx::GLContext::Unwrap(context); blurFilterBuffer->clearColor(gl); auto offsetMatrix = - Matrix::MakeTrans((contentBounds.left - blurVBounds.left) * source->scale.x, - (contentBounds.top - blurVBounds.top) * source->scale.y); + tgfx::Matrix::MakeTrans((contentBounds.left - blurVBounds.left) * source->scale.x, + (contentBounds.top - blurVBounds.top) * source->scale.y); auto targetV = blurFilterBuffer->toFilterTarget(offsetMatrix); blurFilterV->draw(context, source, targetV.get()); auto sourceH = blurFilterBuffer->toFilterSource(source->scale); blurFilterH->updateParams(blurriness, 1.0f, repeatEdge, BlurMode::Picture); - Matrix revertMatrix = - Matrix::MakeTrans((blurVBounds.left - contentBounds.left) * source->scale.x, - (blurVBounds.top - contentBounds.top) * source->scale.y); + tgfx::Matrix revertMatrix = + tgfx::Matrix::MakeTrans((blurVBounds.left - contentBounds.left) * source->scale.x, + (blurVBounds.top - contentBounds.top) * source->scale.y); auto targetH = *target; PreConcatMatrix(&targetH, revertMatrix); blurFilterH->draw(context, sourceH.get(), &targetH); diff --git a/src/rendering/filters/gaussblur/GaussBlurFilter.h b/src/rendering/filters/gaussblur/GaussBlurFilter.h index 8279cc44e8..5610289fd0 100644 --- a/src/rendering/filters/gaussblur/GaussBlurFilter.h +++ b/src/rendering/filters/gaussblur/GaussBlurFilter.h @@ -28,12 +28,13 @@ class GaussBlurFilter : public LayerFilter { explicit GaussBlurFilter(Effect* effect); ~GaussBlurFilter() override; - bool initialize(Context* context) override; + bool initialize(tgfx::Context* context) override; - void draw(Context* context, const FilterSource* source, const FilterTarget* target) override; + void draw(tgfx::Context* context, const FilterSource* source, + const FilterTarget* target) override; - void update(Frame frame, const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale) override; + void update(Frame frame, const tgfx::Rect& contentBounds, const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale) override; private: Effect* effect = nullptr; @@ -46,6 +47,6 @@ class GaussBlurFilter : public LayerFilter { bool repeatEdge = true; BlurDirection blurDirection = BlurDirection::Both; float blurriness = 0.0f; - std::vector filtersBounds = {}; + std::vector filtersBounds = {}; }; } // namespace pag diff --git a/src/rendering/filters/gaussblur/SinglePassBlurFilter.cpp b/src/rendering/filters/gaussblur/SinglePassBlurFilter.cpp index 74c9a39cc6..0150dcaf85 100644 --- a/src/rendering/filters/gaussblur/SinglePassBlurFilter.cpp +++ b/src/rendering/filters/gaussblur/SinglePassBlurFilter.cpp @@ -17,7 +17,6 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "SinglePassBlurFilter.h" -#include "gpu/opengl/GLUtil.h" #include "rendering/filters/utils/BlurTypes.h" namespace pag { @@ -84,7 +83,7 @@ std::string SinglePassBlurFilter::onBuildFragmentShader() { return BLUR_FRAGMENT_SHADER; } -void SinglePassBlurFilter::onPrepareProgram(const GLInterface* gl, unsigned int program) { +void SinglePassBlurFilter::onPrepareProgram(const tgfx::GLInterface* gl, unsigned int program) { radiusHandle = gl->getUniformLocation(program, "uRadius"); levelHandle = gl->getUniformLocation(program, "uLevel"); repeatEdgeHandle = gl->getUniformLocation(program, "uRepeatEdge"); @@ -112,18 +111,19 @@ void SinglePassBlurFilter::updateParams(float blurrinessValue, float blurAlphaVa } } -void SinglePassBlurFilter::enableBlurColor(Color4f blurColor) { +void SinglePassBlurFilter::enableBlurColor(tgfx::Color blurColor) { isColorValid = true; color = blurColor; } void SinglePassBlurFilter::disableBlurColor() { isColorValid = false; - color = Color4f::Black(); + color = tgfx::Color::Black(); } -void SinglePassBlurFilter::onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) { +void SinglePassBlurFilter::onUpdateParams(const tgfx::GLInterface* gl, + const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) { auto scale = direction == BlurDirection::Horizontal ? filterScale.x : filterScale.y; auto blurValue = std::min(blurriness * scale, BLUR_LIMIT_BLURRINESS); @@ -142,25 +142,26 @@ void SinglePassBlurFilter::onUpdateParams(const GLInterface* gl, const Rect& con gl->uniform1f(alphaHandle, alpha); } -std::vector SinglePassBlurFilter::computeVertices(const Rect& inputBounds, - const Rect& outputBounds, - const Point& filterScale) { +std::vector SinglePassBlurFilter::computeVertices(const tgfx::Rect& inputBounds, + const tgfx::Rect& outputBounds, + const tgfx::Point& filterScale) { if (repeatEdge) { return LayerFilter::computeVertices(inputBounds, outputBounds, filterScale); } - std::vector vertices = {}; - Point contentPoint[4] = {{outputBounds.left, outputBounds.bottom}, - {outputBounds.right, outputBounds.bottom}, - {outputBounds.left, outputBounds.top}, - {outputBounds.right, outputBounds.top}}; + std::vector vertices = {}; + tgfx::Point contentPoint[4] = {{outputBounds.left, outputBounds.bottom}, + {outputBounds.right, outputBounds.bottom}, + {outputBounds.left, outputBounds.top}, + {outputBounds.right, outputBounds.top}}; auto deltaX = direction == BlurDirection::Horizontal ? -blurriness * filterScale.x : 0; auto deltaY = direction == BlurDirection::Vertical ? -blurriness * filterScale.y : 0; - Point texturePoints[4] = {{deltaX, (outputBounds.height() + deltaY)}, - {(outputBounds.width() + deltaX), (outputBounds.height() + deltaY)}, - {deltaX, deltaY}, - {(outputBounds.width() + deltaX), deltaY}}; + tgfx::Point texturePoints[4] = { + {deltaX, (outputBounds.height() + deltaY)}, + {(outputBounds.width() + deltaX), (outputBounds.height() + deltaY)}, + {deltaX, deltaY}, + {(outputBounds.width() + deltaX), deltaY}}; for (int ii = 0; ii < 4; ii++) { vertices.push_back(contentPoint[ii]); vertices.push_back(texturePoints[ii]); diff --git a/src/rendering/filters/gaussblur/SinglePassBlurFilter.h b/src/rendering/filters/gaussblur/SinglePassBlurFilter.h index 0a108d3d1f..38cde6a267 100644 --- a/src/rendering/filters/gaussblur/SinglePassBlurFilter.h +++ b/src/rendering/filters/gaussblur/SinglePassBlurFilter.h @@ -29,19 +29,20 @@ class SinglePassBlurFilter : public LayerFilter { void updateParams(float blurriness, float alpha, bool repeatEdge, BlurMode mode); - void enableBlurColor(Color4f blurColor); + void enableBlurColor(tgfx::Color blurColor); void disableBlurColor(); protected: std::string onBuildFragmentShader() override; - void onPrepareProgram(const GLInterface* gl, unsigned program) override; + void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) override; - void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) override; + void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) override; - std::vector computeVertices(const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale) override; + std::vector computeVertices(const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale) override; private: int radiusHandle = -1; @@ -52,7 +53,7 @@ class SinglePassBlurFilter : public LayerFilter { int alphaHandle = -1; BlurDirection direction; - Color4f color = Color4f::Black(); + tgfx::Color color = tgfx::Color::Black(); bool isColorValid = false; float blurriness = 0.0; float alpha = 1.0f; diff --git a/src/rendering/filters/glow/GlowBlurFilter.cpp b/src/rendering/filters/glow/GlowBlurFilter.cpp index 526acb9894..ec95e6cce4 100644 --- a/src/rendering/filters/glow/GlowBlurFilter.cpp +++ b/src/rendering/filters/glow/GlowBlurFilter.cpp @@ -17,7 +17,6 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "GlowBlurFilter.h" -#include "gpu/opengl/GLUtil.h" namespace pag { static const char GLOW_BLUR_VERTEX_SHADER[] = R"( @@ -72,7 +71,7 @@ std::string GlowBlurFilter::onBuildFragmentShader() { return GLOW_BLUR_FRAGMENT_SHADER; } -void GlowBlurFilter::onPrepareProgram(const GLInterface* gl, unsigned int program) { +void GlowBlurFilter::onPrepareProgram(const tgfx::GLInterface* gl, unsigned int program) { textureOffsetHHandle = gl->getUniformLocation(program, "textureOffsetH"); textureOffsetVHandle = gl->getUniformLocation(program, "textureOffsetV"); } @@ -81,7 +80,8 @@ void GlowBlurFilter::updateOffset(float offset) { blurOffset = offset; } -void GlowBlurFilter::onUpdateParams(const GLInterface* gl, const Rect&, const Point&) { +void GlowBlurFilter::onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect&, + const tgfx::Point&) { auto textureOffsetH = blurDirection == BlurDirection::Horizontal ? blurOffset : 0; auto textureOffsetV = blurDirection == BlurDirection::Vertical ? blurOffset : 0; gl->uniform1f(textureOffsetHHandle, textureOffsetH); diff --git a/src/rendering/filters/glow/GlowBlurFilter.h b/src/rendering/filters/glow/GlowBlurFilter.h index 9356d05b18..b4f1edd412 100644 --- a/src/rendering/filters/glow/GlowBlurFilter.h +++ b/src/rendering/filters/glow/GlowBlurFilter.h @@ -34,10 +34,10 @@ class GlowBlurFilter : public LayerFilter { std::string onBuildFragmentShader() override; - void onPrepareProgram(const GLInterface* gl, unsigned program) override; + void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) override; - void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) override; + void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) override; private: int textureOffsetHHandle = -1; diff --git a/src/rendering/filters/glow/GlowFilter.cpp b/src/rendering/filters/glow/GlowFilter.cpp index 564f9cb7f3..fc3c0f0059 100644 --- a/src/rendering/filters/glow/GlowFilter.cpp +++ b/src/rendering/filters/glow/GlowFilter.cpp @@ -33,7 +33,7 @@ GlowFilter::~GlowFilter() { delete targetFilter; } -bool GlowFilter::initialize(Context* context) { +bool GlowFilter::initialize(tgfx::Context* context) { if (!blurFilterH->initialize(context)) { return false; } @@ -46,8 +46,8 @@ bool GlowFilter::initialize(Context* context) { return true; } -void GlowFilter::update(Frame frame, const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale) { +void GlowFilter::update(Frame frame, const tgfx::Rect& contentBounds, + const tgfx::Rect& transformedBounds, const tgfx::Point& filterScale) { LayerFilter::update(frame, contentBounds, transformedBounds, filterScale); auto glowEffect = static_cast(effect); @@ -62,7 +62,7 @@ void GlowFilter::update(Frame frame, const Rect& contentBounds, const Rect& tran targetFilter->update(frame, contentBounds, transformedBounds, filterScale); } -bool GlowFilter::checkBuffer(Context* context, int blurWidth, int blurHeight) { +bool GlowFilter::checkBuffer(tgfx::Context* context, int blurWidth, int blurHeight) { if (blurFilterBufferH == nullptr || blurFilterBufferH->width() != blurWidth || blurFilterBufferH->height() != blurHeight) { blurFilterBufferH = FilterBuffer::Make(context, blurWidth, blurHeight); @@ -81,7 +81,8 @@ bool GlowFilter::checkBuffer(Context* context, int blurWidth, int blurHeight) { return true; } -void GlowFilter::draw(Context* context, const FilterSource* source, const FilterTarget* target) { +void GlowFilter::draw(tgfx::Context* context, const FilterSource* source, + const FilterTarget* target) { if (source == nullptr || target == nullptr) { LOGE("GlowFilter::draw() can not draw filter"); return; @@ -92,16 +93,16 @@ void GlowFilter::draw(Context* context, const FilterSource* source, const Filter if (!checkBuffer(context, blurWidth, blurHeight)) { return; } - auto gl = GLContext::Unwrap(context); + auto gl = tgfx::GLContext::Unwrap(context); blurFilterBufferH->clearColor(gl); blurFilterBufferV->clearColor(gl); - auto targetH = blurFilterBufferH->toFilterTarget(Matrix::I()); + auto targetH = blurFilterBufferH->toFilterTarget(tgfx::Matrix::I()); blurFilterH->updateOffset(1.0f / blurWidth); blurFilterH->draw(context, source, targetH.get()); auto sourceV = blurFilterBufferH->toFilterSource(source->scale); - auto targetV = blurFilterBufferV->toFilterTarget(Matrix::I()); + auto targetV = blurFilterBufferV->toFilterTarget(tgfx::Matrix::I()); blurFilterV->updateOffset(1.0f / blurHeight); blurFilterV->draw(context, sourceV.get(), targetV.get()); diff --git a/src/rendering/filters/glow/GlowFilter.h b/src/rendering/filters/glow/GlowFilter.h index 8034775e60..ea56aaeb35 100644 --- a/src/rendering/filters/glow/GlowFilter.h +++ b/src/rendering/filters/glow/GlowFilter.h @@ -29,12 +29,13 @@ class GlowFilter : public LayerFilter { explicit GlowFilter(Effect* effect); ~GlowFilter() override; - bool initialize(Context* context) override; + bool initialize(tgfx::Context* context) override; - void draw(Context* context, const FilterSource* source, const FilterTarget* target) override; + void draw(tgfx::Context* context, const FilterSource* source, + const FilterTarget* target) override; - void update(Frame frame, const Rect& contentBounds, const Rect& transformedBounds, - const Point& filterScale) override; + void update(Frame frame, const tgfx::Rect& contentBounds, const tgfx::Rect& transformedBounds, + const tgfx::Point& filterScale) override; private: Effect* effect = nullptr; @@ -48,6 +49,6 @@ class GlowFilter : public LayerFilter { std::shared_ptr blurFilterBufferH = nullptr; std::shared_ptr blurFilterBufferV = nullptr; - bool checkBuffer(Context* context, int blurWidth, int blurHeight); + bool checkBuffer(tgfx::Context* context, int blurWidth, int blurHeight); }; } // namespace pag diff --git a/src/rendering/filters/glow/GlowMergeFilter.cpp b/src/rendering/filters/glow/GlowMergeFilter.cpp index 49d6a7f8ce..2912333f3e 100644 --- a/src/rendering/filters/glow/GlowMergeFilter.cpp +++ b/src/rendering/filters/glow/GlowMergeFilter.cpp @@ -17,7 +17,6 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "GlowMergeFilter.h" -#include "gpu/opengl/GLUtil.h" namespace pag { static const char GLOW_TARGET_FRAGMENT_SHADER[] = R"( @@ -50,7 +49,7 @@ std::string GlowMergeFilter::onBuildFragmentShader() { return GLOW_TARGET_FRAGMENT_SHADER; } -void GlowMergeFilter::onPrepareProgram(const GLInterface* gl, unsigned int program) { +void GlowMergeFilter::onPrepareProgram(const tgfx::GLInterface* gl, unsigned int program) { inputTextureHandle = gl->getUniformLocation(program, "inputImageTexture"); blurTextureHandle = gl->getUniformLocation(program, "blurImageTexture"); progressHandle = gl->getUniformLocation(program, "progress"); @@ -60,7 +59,8 @@ void GlowMergeFilter::updateTexture(unsigned blurTexture) { blurTextureID = blurTexture; } -void GlowMergeFilter::onUpdateParams(const GLInterface* gl, const Rect&, const Point&) { +void GlowMergeFilter::onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect&, + const tgfx::Point&) { auto glowEffect = static_cast(effect); auto glowThreshold = glowEffect->glowThreshold->getValueAt(layerFrame); gl->uniform1f(progressHandle, glowThreshold); @@ -68,6 +68,6 @@ void GlowMergeFilter::onUpdateParams(const GLInterface* gl, const Rect&, const P // TODO(domrjchen): 下面这行之前写成了 gl->uniform1i(progressHandle, 1), 会导致 glError, // 暂时注释掉。目前的发光效果跟 AE 也没有对齐,后面重写发光效果时时再修复。 // gl->uniform1i(blurTextureHandle, 1); - ActiveTexture(gl, GL::TEXTURE1, GL::TEXTURE_2D, blurTextureID); + ActiveGLTexture(gl, GL::TEXTURE1, GL::TEXTURE_2D, blurTextureID); } } // namespace pag diff --git a/src/rendering/filters/glow/GlowMergeFilter.h b/src/rendering/filters/glow/GlowMergeFilter.h index 3104b8df4e..5b5873c26e 100644 --- a/src/rendering/filters/glow/GlowMergeFilter.h +++ b/src/rendering/filters/glow/GlowMergeFilter.h @@ -31,10 +31,10 @@ class GlowMergeFilter : public LayerFilter { protected: std::string onBuildFragmentShader() override; - void onPrepareProgram(const GLInterface* gl, unsigned program) override; + void onPrepareProgram(const tgfx::GLInterface* gl, unsigned program) override; - void onUpdateParams(const GLInterface* gl, const Rect& contentBounds, - const Point& filterScale) override; + void onUpdateParams(const tgfx::GLInterface* gl, const tgfx::Rect& contentBounds, + const tgfx::Point& filterScale) override; private: Effect* effect = nullptr; diff --git a/src/rendering/filters/utils/FilterBuffer.cpp b/src/rendering/filters/utils/FilterBuffer.cpp index b2aa2c8fd5..f3fc1fd601 100644 --- a/src/rendering/filters/utils/FilterBuffer.cpp +++ b/src/rendering/filters/utils/FilterBuffer.cpp @@ -17,15 +17,14 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "FilterBuffer.h" -#include "gpu/opengl/GLUtil.h" namespace pag { -std::shared_ptr FilterBuffer::Make(Context* context, int width, int height, +std::shared_ptr FilterBuffer::Make(tgfx::Context* context, int width, int height, bool usesMSAA) { - auto texture = GLTexture::MakeRGBA(context, width, height); - auto gl = GLContext::Unwrap(context); - auto sampleCount = usesMSAA ? gl->caps->getSampleCount(4, PixelConfig::RGBA_8888) : 1; - auto renderTarget = GLRenderTarget::MakeFrom(context, texture.get(), sampleCount); + auto texture = tgfx::GLTexture::MakeRGBA(context, width, height); + auto gl = tgfx::GLContext::Unwrap(context); + auto sampleCount = usesMSAA ? gl->caps->getSampleCount(4, tgfx::PixelConfig::RGBA_8888) : 1; + auto renderTarget = tgfx::GLRenderTarget::MakeFrom(context, texture.get(), sampleCount); if (renderTarget == nullptr) { return nullptr; } @@ -35,33 +34,34 @@ std::shared_ptr FilterBuffer::Make(Context* context, int width, in return std::shared_ptr(buffer); } -void FilterBuffer::resolve(Context* context) { +void FilterBuffer::resolve(tgfx::Context* context) { renderTarget->resolve(context); } -void FilterBuffer::clearColor(const GLInterface* gl) const { +void FilterBuffer::clearColor(const tgfx::GLInterface* gl) const { renderTarget->clear(gl); } -std::unique_ptr FilterBuffer::toFilterSource(const Point& scale) const { +std::unique_ptr FilterBuffer::toFilterSource(const tgfx::Point& scale) const { auto filterSource = new FilterSource(); filterSource->textureID = getTexture().id; filterSource->width = texture->width(); filterSource->height = texture->height(); filterSource->scale = scale; // TODO(domrjchen): 这里的 ImageOrigin 是错的 - filterSource->textureMatrix = - ToGLTextureMatrix(Matrix::I(), texture->width(), texture->height(), ImageOrigin::BottomLeft); + filterSource->textureMatrix = tgfx::ToGLTextureMatrix( + tgfx::Matrix::I(), texture->width(), texture->height(), tgfx::ImageOrigin::BottomLeft); return std::unique_ptr(filterSource); } -std::unique_ptr FilterBuffer::toFilterTarget(const Matrix& drawingMatrix) const { +std::unique_ptr FilterBuffer::toFilterTarget( + const tgfx::Matrix& drawingMatrix) const { auto filterTarget = new FilterTarget(); filterTarget->frameBufferID = getFramebuffer().id; filterTarget->width = renderTarget->width(); filterTarget->height = renderTarget->height(); - filterTarget->vertexMatrix = ToGLVertexMatrix(drawingMatrix, renderTarget->width(), - renderTarget->height(), ImageOrigin::BottomLeft); + filterTarget->vertexMatrix = tgfx::ToGLVertexMatrix( + drawingMatrix, renderTarget->width(), renderTarget->height(), tgfx::ImageOrigin::BottomLeft); return std::unique_ptr(filterTarget); } } // namespace pag diff --git a/src/rendering/filters/utils/FilterBuffer.h b/src/rendering/filters/utils/FilterBuffer.h index a065ed5104..c5b8aaa027 100644 --- a/src/rendering/filters/utils/FilterBuffer.h +++ b/src/rendering/filters/utils/FilterBuffer.h @@ -19,6 +19,7 @@ #pragma once #include "gpu/opengl/GLRenderTarget.h" +#include "gpu/opengl/GLUtil.h" #include "pag/file.h" #include "pag/pag.h" #include "rendering/filters/Filter.h" @@ -26,14 +27,14 @@ namespace pag { class FilterBuffer { public: - static std::shared_ptr Make(Context* context, int width, int height, + static std::shared_ptr Make(tgfx::Context* context, int width, int height, bool usesMSAA = false); - void clearColor(const GLInterface* gl) const; + void clearColor(const tgfx::GLInterface* gl) const; - std::unique_ptr toFilterSource(const Point& scale) const; + std::unique_ptr toFilterSource(const tgfx::Point& scale) const; - std::unique_ptr toFilterTarget(const Matrix& drawingMatrix) const; + std::unique_ptr toFilterTarget(const tgfx::Matrix& drawingMatrix) const; int width() const { return renderTarget->width(); @@ -47,19 +48,19 @@ class FilterBuffer { return renderTarget->usesMSAA(); } - GLFrameBufferInfo getFramebuffer() const { + tgfx::GLFrameBufferInfo getFramebuffer() const { return renderTarget->getGLInfo(); } - GLTextureInfo getTexture() const { + tgfx::GLTextureInfo getTexture() const { return texture->getGLInfo(); } - void resolve(Context* context); + void resolve(tgfx::Context* context); private: - std::shared_ptr renderTarget = nullptr; - std::shared_ptr texture = nullptr; + std::shared_ptr renderTarget = nullptr; + std::shared_ptr texture = nullptr; FilterBuffer() = default; }; } // namespace pag diff --git a/src/rendering/filters/utils/FilterHelper.cpp b/src/rendering/filters/utils/FilterHelper.cpp index b9dff6637b..352bd2f7b9 100644 --- a/src/rendering/filters/utils/FilterHelper.cpp +++ b/src/rendering/filters/utils/FilterHelper.cpp @@ -19,18 +19,17 @@ #include "FilterHelper.h" #include "gpu/opengl/GLSurface.h" #include "gpu/opengl/GLTexture.h" -#include "gpu/opengl/GLUtil.h" namespace pag { -Matrix ToMatrix(const FilterTarget* target, bool flipY) { - Matrix matrix = {}; +tgfx::Matrix ToMatrix(const FilterTarget* target, bool flipY) { + tgfx::Matrix matrix = {}; auto values = target->vertexMatrix; matrix.setAll(values[0], values[3], values[6], values[1], values[4], values[7], values[2], values[5], values[8]); if (flipY) { matrix.postScale(1.0f, -1.0f); } - Matrix convertMatrix = {}; + tgfx::Matrix convertMatrix = {}; // 以下等价于: // convertMatrix.setScale(2f/width, 2f/height); // convertMatrix.postTranslate(-1.0f, -1.0f); @@ -44,26 +43,28 @@ Matrix ToMatrix(const FilterTarget* target, bool flipY) { return matrix; } -std::unique_ptr ToFilterSource(const Texture* texture, const Point& scale) { +std::unique_ptr ToFilterSource(const tgfx::Texture* texture, + const tgfx::Point& scale) { if (texture == nullptr) { return nullptr; } - auto textureInfo = GLTexture::Unwrap(texture); + auto textureInfo = tgfx::GLTexture::Unwrap(texture); auto filterSource = new FilterSource(); filterSource->textureID = textureInfo.id; filterSource->width = texture->width(); filterSource->height = texture->height(); filterSource->scale = scale; filterSource->textureMatrix = - ToGLTextureMatrix(Matrix::I(), texture->width(), texture->height(), texture->origin()); + ToGLTextureMatrix(tgfx::Matrix::I(), texture->width(), texture->height(), texture->origin()); return std::unique_ptr(filterSource); } -std::unique_ptr ToFilterTarget(const Surface* surface, const Matrix& drawingMatrix) { +std::unique_ptr ToFilterTarget(const tgfx::Surface* surface, + const tgfx::Matrix& drawingMatrix) { if (surface == nullptr) { return nullptr; } - auto renderTarget = static_cast(surface)->getRenderTarget(); + auto renderTarget = static_cast(surface)->getRenderTarget(); auto filterTarget = new FilterTarget(); filterTarget->frameBufferID = renderTarget->getGLInfo().id; filterTarget->width = surface->width(); @@ -73,24 +74,24 @@ std::unique_ptr ToFilterTarget(const Surface* surface, const Matri return std::unique_ptr(filterTarget); } -Point ToGLTexturePoint(const FilterSource* source, const Point& texturePoint) { +tgfx::Point ToGLTexturePoint(const FilterSource* source, const tgfx::Point& texturePoint) { return {texturePoint.x * source->scale.x / static_cast(source->width), (static_cast(source->height) - texturePoint.y * source->scale.y) / static_cast(source->height)}; } -Point ToGLVertexPoint(const FilterTarget* target, const FilterSource* source, - const Rect& contentBounds, const Point& contentPoint) { - Point vertexPoint = {(contentPoint.x - contentBounds.left) * source->scale.x, - (contentPoint.y - contentBounds.top) * source->scale.y}; +tgfx::Point ToGLVertexPoint(const FilterTarget* target, const FilterSource* source, + const tgfx::Rect& contentBounds, const tgfx::Point& contentPoint) { + tgfx::Point vertexPoint = {(contentPoint.x - contentBounds.left) * source->scale.x, + (contentPoint.y - contentBounds.top) * source->scale.y}; return {2.0f * vertexPoint.x / static_cast(target->width) - 1.0f, 1.0f - 2.0f * vertexPoint.y / static_cast(target->height)}; } -void PreConcatMatrix(FilterTarget* target, const Matrix& matrix) { +void PreConcatMatrix(FilterTarget* target, const tgfx::Matrix& matrix) { auto vertexMatrix = ToMatrix(target); vertexMatrix.preConcat(matrix); - target->vertexMatrix = - ToGLVertexMatrix(vertexMatrix, target->width, target->height, ImageOrigin::BottomLeft); + target->vertexMatrix = tgfx::ToGLVertexMatrix(vertexMatrix, target->width, target->height, + tgfx::ImageOrigin::BottomLeft); } } // namespace pag diff --git a/src/rendering/filters/utils/FilterHelper.h b/src/rendering/filters/utils/FilterHelper.h index 24b0a67241..6dbf4aee6a 100644 --- a/src/rendering/filters/utils/FilterHelper.h +++ b/src/rendering/filters/utils/FilterHelper.h @@ -18,22 +18,26 @@ #pragma once +#include "base/utils/TGFXCast.h" #include "gpu/Texture.h" +#include "gpu/opengl/GLUtil.h" #include "pag/file.h" #include "pag/pag.h" #include "rendering/filters/Filter.h" namespace pag { -Matrix ToMatrix(const FilterTarget* target, bool flipY = false); +tgfx::Matrix ToMatrix(const FilterTarget* target, bool flipY = false); -std::unique_ptr ToFilterSource(const Texture* texture, const Point& scale); +std::unique_ptr ToFilterSource(const tgfx::Texture* texture, + const tgfx::Point& scale); -std::unique_ptr ToFilterTarget(const Surface* surface, const Matrix& drawingMatrix); +std::unique_ptr ToFilterTarget(const tgfx::Surface* surface, + const tgfx::Matrix& drawingMatrix); -Point ToGLTexturePoint(const FilterSource* source, const Point& texturePoint); +tgfx::Point ToGLTexturePoint(const FilterSource* source, const tgfx::Point& texturePoint); -Point ToGLVertexPoint(const FilterTarget* target, const FilterSource* source, - const Rect& contentBounds, const Point& contentPoint); +tgfx::Point ToGLVertexPoint(const FilterTarget* target, const FilterSource* source, + const tgfx::Rect& contentBounds, const tgfx::Point& contentPoint); -void PreConcatMatrix(FilterTarget* target, const Matrix& matrix); +void PreConcatMatrix(FilterTarget* target, const tgfx::Matrix& matrix); } // namespace pag diff --git a/src/rendering/graphics/Glyph.cpp b/src/rendering/graphics/Glyph.cpp index 3d01b12841..5d58792a22 100644 --- a/src/rendering/graphics/Glyph.cpp +++ b/src/rendering/graphics/Glyph.cpp @@ -17,12 +17,12 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "Glyph.h" -#include "base/utils/UTF8Text.h" +#include "core/UTF.h" #include "rendering/FontManager.h" namespace pag { std::vector Glyph::BuildFromText(const std::string& text, const TextPaint& textPaint) { - Font textFont = {}; + tgfx::Font textFont = {}; textFont.setFauxBold(textPaint.fauxBold); textFont.setFauxItalic(textPaint.fauxItalic); textFont.setSize(textPaint.fontSize); @@ -34,10 +34,10 @@ std::vector Glyph::BuildFromText(const std::string& text, const Tex const char* textStop = textStart + text.size(); while (textStart < textStop) { auto oldPosition = textStart; - UTF8Text::NextChar(&textStart); + tgfx::UTF::NextUTF8(&textStart, textStop); auto length = textStart - oldPosition; auto name = std::string(oldPosition, length); - GlyphID glyphId = 0; + tgfx::GlyphID glyphId = 0; if (hasTypeface) { glyphId = typeface->getGlyphID(name); if (glyphId != 0) { @@ -54,7 +54,7 @@ std::vector Glyph::BuildFromText(const std::string& text, const Tex return glyphList; } -Glyph::Glyph(GlyphID glyphId, const std::string& charName, const Font& textFont, +Glyph::Glyph(tgfx::GlyphID glyphId, const std::string& charName, const tgfx::Font& textFont, const TextPaint& textPaint) : glyphId(glyphId), textFont(textFont) { name = charName; @@ -99,7 +99,7 @@ Glyph::Glyph(GlyphID glyphId, const std::string& charName, const Font& textFont, } } -void Glyph::computeStyleKey(BytesKey* styleKey) const { +void Glyph::computeStyleKey(tgfx::BytesKey* styleKey) const { auto m = getTotalMatrix(); styleKey->write(m.getScaleX()); styleKey->write(m.getSkewX()); @@ -119,7 +119,7 @@ bool Glyph::isVisible() const { return matrix.invertible() && alpha != 0.0f && !bounds.isEmpty(); } -Matrix Glyph::getTotalMatrix() const { +tgfx::Matrix Glyph::getTotalMatrix() const { auto m = extraMatrix; m.postConcat(matrix); return m; diff --git a/src/rendering/graphics/Glyph.h b/src/rendering/graphics/Glyph.h index 5cd666cb24..a437c2a757 100644 --- a/src/rendering/graphics/Glyph.h +++ b/src/rendering/graphics/Glyph.h @@ -18,8 +18,8 @@ #pragma once +#include "core/BytesKey.h" #include "core/Font.h" -#include "core/utils/BytesKey.h" #include "pag/types.h" namespace pag { @@ -64,19 +64,19 @@ class Glyph { * Called by the Text::MakeFrom() method to merge the draw calls of glyphs with the same style. * Return false if this glyph is not visible. */ - void computeStyleKey(BytesKey* styleKey) const; + void computeStyleKey(tgfx::BytesKey* styleKey) const; /** * Returns the Font object associated with this Glyph. */ - Font getFont() const { + tgfx::Font getFont() const { return textFont; } /** * Returns the id of this glyph in associated typeface. */ - GlyphID getGlyphID() const { + tgfx::GlyphID getGlyphID() const { return glyphId; } @@ -124,21 +124,21 @@ class Glyph { * Returns the bounding box relative to (0, 0) of this glyph. Returned bounds may be larger than * the exact bounds of this glyph. */ - const Rect& getBounds() const { + const tgfx::Rect& getBounds() const { return bounds; } /** * Returns the matrix for this glyph. */ - Matrix getMatrix() const { + tgfx::Matrix getMatrix() const { return matrix; } /** * Replaces transformation with specified matrix. */ - void setMatrix(const Matrix& m) { + void setMatrix(const tgfx::Matrix& m) { matrix = m; } @@ -222,29 +222,30 @@ class Glyph { /** * Returns the total matrix of this glyph which contains the style matrix. */ - Matrix getTotalMatrix() const; + tgfx::Matrix getTotalMatrix() const; private: - GlyphID glyphId = 0; - Font textFont = {}; + tgfx::GlyphID glyphId = 0; + tgfx::Font textFont = {}; // read only attributes: float advance = 0; float ascent = 0; float descent = 0; - Rect bounds = Rect::MakeEmpty(); + tgfx::Rect bounds = tgfx::Rect::MakeEmpty(); std::string name; bool _isVertical = false; bool strokeOverFill = true; - Matrix extraMatrix = Matrix::I(); // for vertical text or fauxItalic. + tgfx::Matrix extraMatrix = tgfx::Matrix::I(); // for vertical text or fauxItalic. // writable attributes: - Matrix matrix = Matrix::I(); + tgfx::Matrix matrix = tgfx::Matrix::I(); TextStyle textStyle = TextStyle::Fill; float alpha = 1.0f; Color fillColor = Black; Color strokeColor = Black; float strokeWidth = 0; - Glyph(GlyphID glyphId, const std::string& name, const Font& textFont, const TextPaint& textPaint); + Glyph(tgfx::GlyphID glyphId, const std::string& name, const tgfx::Font& textFont, + const TextPaint& textPaint); }; } // namespace pag diff --git a/src/rendering/graphics/Graphic.cpp b/src/rendering/graphics/Graphic.cpp index 8db9ba7c44..9610596fc2 100644 --- a/src/rendering/graphics/Graphic.cpp +++ b/src/rendering/graphics/Graphic.cpp @@ -27,7 +27,7 @@ class ComposeGraphic : public Graphic { return GraphicType::Compose; } - virtual std::shared_ptr mergeWith(const Matrix&) const { + virtual std::shared_ptr mergeWith(const tgfx::Matrix&) const { return nullptr; } @@ -39,24 +39,24 @@ class ComposeGraphic : public Graphic { //===================================== MatrixGraphic ============================================== class MatrixGraphic : public ComposeGraphic { public: - MatrixGraphic(std::shared_ptr graphic, const Matrix& matrix) + MatrixGraphic(std::shared_ptr graphic, const tgfx::Matrix& matrix) : graphic(std::move(graphic)), matrix(matrix) { } - void measureBounds(Rect* bounds) const override; + void measureBounds(tgfx::Rect* bounds) const override; bool hitTest(RenderCache* cache, float x, float y) override; - bool getPath(Path* path) const override; + bool getPath(tgfx::Path* path) const override; void prepare(RenderCache* cache) const override; - void draw(Canvas* canvas, RenderCache* cache) const override; - std::shared_ptr mergeWith(const Matrix& matrix) const override; + void draw(tgfx::Canvas* canvas, RenderCache* cache) const override; + std::shared_ptr mergeWith(const tgfx::Matrix& matrix) const override; protected: std::shared_ptr graphic = nullptr; - Matrix matrix = {}; + tgfx::Matrix matrix = {}; }; std::shared_ptr Graphic::MakeCompose(std::shared_ptr graphic, - const Matrix& matrix) { + const tgfx::Matrix& matrix) { if (graphic == nullptr || !matrix.invertible()) { return nullptr; } @@ -72,21 +72,21 @@ std::shared_ptr Graphic::MakeCompose(std::shared_ptr graphic, return std::make_shared(graphic, matrix); } -void MatrixGraphic::measureBounds(Rect* bounds) const { +void MatrixGraphic::measureBounds(tgfx::Rect* bounds) const { graphic->measureBounds(bounds); matrix.mapRect(bounds); } bool MatrixGraphic::hitTest(RenderCache* cache, float x, float y) { - Point local = {x, y}; + tgfx::Point local = {x, y}; if (!MapPointInverted(matrix, &local)) { return false; } return graphic->hitTest(cache, local.x, local.y); } -bool MatrixGraphic::getPath(Path* path) const { - Path fillPath = {}; +bool MatrixGraphic::getPath(tgfx::Path* path) const { + tgfx::Path fillPath = {}; if (!graphic->getPath(&fillPath)) { return false; } @@ -99,14 +99,14 @@ void MatrixGraphic::prepare(RenderCache* cache) const { graphic->prepare(cache); } -void MatrixGraphic::draw(Canvas* canvas, RenderCache* cache) const { +void MatrixGraphic::draw(tgfx::Canvas* canvas, RenderCache* cache) const { canvas->save(); canvas->concat(matrix); graphic->draw(canvas, cache); canvas->restore(); } -std::shared_ptr MatrixGraphic::mergeWith(const Matrix& m) const { +std::shared_ptr MatrixGraphic::mergeWith(const tgfx::Matrix& m) const { auto totalMatrix = matrix; totalMatrix.postConcat(m); if (totalMatrix.isIdentity()) { @@ -123,12 +123,12 @@ class LayerGraphic : public ComposeGraphic { : contents(std::move(contents)) { } - void measureBounds(Rect* bounds) const override; + void measureBounds(tgfx::Rect* bounds) const override; bool hitTest(RenderCache* cache, float x, float y) override; - bool getPath(Path* path) const override; + bool getPath(tgfx::Path* path) const override; void prepare(RenderCache* cache) const override; - void draw(Canvas* canvas, RenderCache* cache) const override; - std::shared_ptr mergeWith(const Matrix& matrix) const override; + void draw(tgfx::Canvas* canvas, RenderCache* cache) const override; + std::shared_ptr mergeWith(const tgfx::Matrix& matrix) const override; private: std::vector> contents = {}; @@ -151,10 +151,10 @@ std::shared_ptr Graphic::MakeCompose(std::vector(graphics); } -void LayerGraphic::measureBounds(Rect* bounds) const { +void LayerGraphic::measureBounds(tgfx::Rect* bounds) const { bounds->setEmpty(); for (auto& content : contents) { - Rect rect = Rect::MakeEmpty(); + tgfx::Rect rect = tgfx::Rect::MakeEmpty(); content->measureBounds(&rect); bounds->join(rect); } @@ -166,10 +166,10 @@ bool LayerGraphic::hitTest(RenderCache* cache, float x, float y) { }); } -bool LayerGraphic::getPath(Path* path) const { - Path fillPath = {}; +bool LayerGraphic::getPath(tgfx::Path* path) const { + tgfx::Path fillPath = {}; for (auto& content : contents) { - Path temp = {}; + tgfx::Path temp = {}; if (!content->getPath(&temp)) { return false; } @@ -185,7 +185,7 @@ void LayerGraphic::prepare(RenderCache* cache) const { } } -void LayerGraphic::draw(Canvas* canvas, RenderCache* cache) const { +void LayerGraphic::draw(tgfx::Canvas* canvas, RenderCache* cache) const { for (auto& content : contents) { canvas->save(); content->draw(canvas, cache); @@ -193,7 +193,7 @@ void LayerGraphic::draw(Canvas* canvas, RenderCache* cache) const { } } -std::shared_ptr LayerGraphic::mergeWith(const Matrix& m) const { +std::shared_ptr LayerGraphic::mergeWith(const tgfx::Matrix& m) const { std::vector> newContents = {}; for (auto& graphic : contents) { if (graphic->type() != GraphicType::Compose) { @@ -216,11 +216,11 @@ class ModifierGraphic : public ComposeGraphic { : graphic(std::move(graphic)), modifier(std::move(modifier)) { } - void measureBounds(Rect* bounds) const override; + void measureBounds(tgfx::Rect* bounds) const override; bool hitTest(RenderCache* cache, float x, float y) override; - bool getPath(Path* path) const override; + bool getPath(tgfx::Path* path) const override; void prepare(RenderCache* cache) const override; - void draw(Canvas* canvas, RenderCache* cache) const override; + void draw(tgfx::Canvas* canvas, RenderCache* cache) const override; std::shared_ptr mergeWith(const Modifier* target) const override; private: @@ -245,7 +245,7 @@ std::shared_ptr Graphic::MakeCompose(std::shared_ptr graphic, return std::make_shared(graphic, modifier); } -void ModifierGraphic::measureBounds(Rect* bounds) const { +void ModifierGraphic::measureBounds(tgfx::Rect* bounds) const { graphic->measureBounds(bounds); modifier->applyToBounds(bounds); } @@ -257,8 +257,8 @@ bool ModifierGraphic::hitTest(RenderCache* cache, float x, float y) { return graphic->hitTest(cache, x, y); } -bool ModifierGraphic::getPath(Path* path) const { - Path fillPath = {}; +bool ModifierGraphic::getPath(tgfx::Path* path) const { + tgfx::Path fillPath = {}; if (!graphic->getPath(&fillPath)) { return false; } @@ -274,7 +274,7 @@ void ModifierGraphic::prepare(RenderCache* cache) const { graphic->prepare(cache); } -void ModifierGraphic::draw(Canvas* canvas, RenderCache* cache) const { +void ModifierGraphic::draw(tgfx::Canvas* canvas, RenderCache* cache) const { canvas->save(); modifier->applyToGraphic(canvas, cache, graphic); canvas->restore(); diff --git a/src/rendering/graphics/Graphic.h b/src/rendering/graphics/Graphic.h index 7aff12b3cd..1763db84b8 100644 --- a/src/rendering/graphics/Graphic.h +++ b/src/rendering/graphics/Graphic.h @@ -30,9 +30,9 @@ namespace pag { */ struct GradientPaint { Enum gradientType; - Point startPoint; - Point endPoint; - std::vector colors; + tgfx::Point startPoint; + tgfx::Point endPoint; + std::vector colors; std::vector positions; }; @@ -57,7 +57,7 @@ class Graphic { * nullptr or matrix is invisible. */ static std::shared_ptr MakeCompose(std::shared_ptr graphic, - const Matrix& matrix); + const tgfx::Matrix& matrix); /** * Creates a compose Graphic with graphic contents. Returns nullptr if contents are emtpy. @@ -76,7 +76,7 @@ class Graphic { /** * Measures the bounds of this Graphic. */ - virtual void measureBounds(Rect* bounds) const = 0; + virtual void measureBounds(tgfx::Rect* bounds) const = 0; /** * Evaluates the Graphic to see if it overlaps or intersects with the specified point. The point @@ -95,7 +95,7 @@ class Graphic { * leaves the path unchanged if the Graphic contents are not opaque or can not be converted to * a path. */ - virtual bool getPath(Path* path) const = 0; + virtual bool getPath(tgfx::Path* path) const = 0; /** * Prepares this graphic for next draw() call. It collects all CPU tasks in this Graphic and run @@ -106,6 +106,6 @@ class Graphic { /** * Draw this Graphic into specified Canvas. */ - virtual void draw(Canvas* canvas, RenderCache* cache) const = 0; + virtual void draw(tgfx::Canvas* canvas, RenderCache* cache) const = 0; }; } // namespace pag diff --git a/src/rendering/graphics/Modifier.cpp b/src/rendering/graphics/Modifier.cpp index 756f939d3a..c1add7e254 100644 --- a/src/rendering/graphics/Modifier.cpp +++ b/src/rendering/graphics/Modifier.cpp @@ -19,16 +19,16 @@ #include "Modifier.h" #include "Graphic.h" #include "base/utils/MatrixUtil.h" +#include "base/utils/TGFXCast.h" #include "base/utils/UniqueID.h" -#include "core/Blend.h" +#include "core/BlendMode.h" #include "gpu/Surface.h" #include "rendering/utils/SurfaceUtil.h" -#include "rendering/utils/TGFXTypes.h" namespace pag { class BlendModifier : public Modifier { public: - BlendModifier(float alpha, Blend blendMode) : alpha(alpha), blendMode(blendMode) { + BlendModifier(float alpha, tgfx::BlendMode blendMode) : alpha(alpha), blendMode(blendMode) { } ID type() const override { @@ -45,25 +45,25 @@ class BlendModifier : public Modifier { void prepare(RenderCache*) const override { } - void applyToBounds(Rect*) const override{}; + void applyToBounds(tgfx::Rect*) const override{}; - bool applyToPath(Path*) const override { + bool applyToPath(tgfx::Path*) const override { return alpha == 1.0f; // blendMode 只影响颜色,不改变形状或透明度,不影响 getPath 结果。 } - void applyToGraphic(Canvas* canvas, RenderCache* cache, + void applyToGraphic(tgfx::Canvas* canvas, RenderCache* cache, std::shared_ptr graphic) const override; std::shared_ptr mergeWith(const Modifier* modifier) const override; private: float alpha = 1.0f; - Blend blendMode = Blend::SrcOver; + tgfx::BlendMode blendMode = tgfx::BlendMode::SrcOver; }; class ClipModifier : public Modifier { public: - explicit ClipModifier(Path clip) : clip(std::move(clip)) { + explicit ClipModifier(tgfx::Path clip) : clip(std::move(clip)) { } ID type() const override { @@ -82,17 +82,17 @@ class ClipModifier : public Modifier { void prepare(RenderCache*) const override { } - void applyToBounds(Rect* bounds) const override; + void applyToBounds(tgfx::Rect* bounds) const override; - bool applyToPath(Path* path) const override; + bool applyToPath(tgfx::Path* path) const override; - void applyToGraphic(Canvas* canvas, RenderCache* cache, + void applyToGraphic(tgfx::Canvas* canvas, RenderCache* cache, std::shared_ptr graphic) const override; std::shared_ptr mergeWith(const Modifier* modifier) const override; private: - Path clip = {}; + tgfx::Path clip = {}; }; class MaskModifier : public Modifier { @@ -114,13 +114,13 @@ class MaskModifier : public Modifier { void prepare(RenderCache* cache) const override; - void applyToBounds(Rect* bounds) const override; + void applyToBounds(tgfx::Rect* bounds) const override; - bool applyToPath(Path*) const override { + bool applyToPath(tgfx::Path*) const override { return false; } - void applyToGraphic(Canvas* canvas, RenderCache* cache, + void applyToGraphic(tgfx::Canvas* canvas, RenderCache* cache, std::shared_ptr graphic) const override; std::shared_ptr mergeWith(const Modifier*) const override { @@ -135,14 +135,14 @@ class MaskModifier : public Modifier { //================================================================================ -std::shared_ptr Modifier::MakeBlend(float alpha, Blend blendMode) { - if (alpha == 1.0f && blendMode == Blend::SrcOver) { +std::shared_ptr Modifier::MakeBlend(float alpha, tgfx::BlendMode blendMode) { + if (alpha == 1.0f && blendMode == tgfx::BlendMode::SrcOver) { return nullptr; } return std::make_shared(alpha, blendMode); } -std::shared_ptr Modifier::MakeClip(const Path& clip) { +std::shared_ptr Modifier::MakeClip(const tgfx::Path& clip) { if (clip.isEmpty() && clip.isInverseFillType()) { // is full. return nullptr; @@ -155,7 +155,7 @@ std::shared_ptr Modifier::MakeMask(std::shared_ptr graphic, b // 返回空,表示保留目标对象的全部内容。 return nullptr; } - Path clipPath = {}; + tgfx::Path clipPath = {}; if (graphic && graphic->getPath(&clipPath)) { if (inverted) { clipPath.toggleInverseFillType(); @@ -171,12 +171,12 @@ bool BlendModifier::hitTest(RenderCache*, float, float) const { return alpha != 0.0f; } -void BlendModifier::applyToGraphic(Canvas* canvas, RenderCache* cache, +void BlendModifier::applyToGraphic(tgfx::Canvas* canvas, RenderCache* cache, std::shared_ptr graphic) const { canvas->save(); auto newAlpha = canvas->getAlpha() * alpha; canvas->setAlpha(newAlpha); - if (blendMode != Blend::SrcOver) { + if (blendMode != tgfx::BlendMode::SrcOver) { canvas->setBlendMode(blendMode); } graphic->draw(canvas, cache); @@ -185,27 +185,27 @@ void BlendModifier::applyToGraphic(Canvas* canvas, RenderCache* cache, std::shared_ptr BlendModifier::mergeWith(const Modifier* modifier) const { auto target = static_cast(modifier); - if (target->blendMode != Blend::SrcOver && blendMode != Blend::SrcOver) { + if (target->blendMode != tgfx::BlendMode::SrcOver && blendMode != tgfx::BlendMode::SrcOver) { return nullptr; } - auto newBlendMode = blendMode != Blend::SrcOver ? blendMode : target->blendMode; + auto newBlendMode = blendMode != tgfx::BlendMode::SrcOver ? blendMode : target->blendMode; auto newAlpha = alpha * target->alpha; return std::make_shared(newAlpha, newBlendMode); } -void ClipModifier::applyToBounds(Rect* bounds) const { - Path boundsPath = {}; +void ClipModifier::applyToBounds(tgfx::Rect* bounds) const { + tgfx::Path boundsPath = {}; boundsPath.addRect(*bounds); - boundsPath.addPath(clip, PathOp::Intersect); + boundsPath.addPath(clip, tgfx::PathOp::Intersect); *bounds = boundsPath.getBounds(); } -bool ClipModifier::applyToPath(Path* path) const { - path->addPath(clip, PathOp::Intersect); +bool ClipModifier::applyToPath(tgfx::Path* path) const { + path->addPath(clip, tgfx::PathOp::Intersect); return true; } -void ClipModifier::applyToGraphic(Canvas* canvas, RenderCache* cache, +void ClipModifier::applyToGraphic(tgfx::Canvas* canvas, RenderCache* cache, std::shared_ptr graphic) const { canvas->save(); canvas->clipPath(clip); @@ -216,7 +216,7 @@ void ClipModifier::applyToGraphic(Canvas* canvas, RenderCache* cache, std::shared_ptr ClipModifier::mergeWith(const Modifier* modifier) const { auto target = static_cast(modifier); auto newClip = clip; - newClip.addPath(target->clip, PathOp::Intersect); + newClip.addPath(target->clip, tgfx::PathOp::Intersect); return std::make_shared(newClip); } @@ -234,13 +234,13 @@ void MaskModifier::prepare(RenderCache* cache) const { } } -void MaskModifier::applyToBounds(Rect* bounds) const { +void MaskModifier::applyToBounds(tgfx::Rect* bounds) const { if (mask == nullptr) { bounds->setEmpty(); return; } if (!inverted) { - Rect clipBounds = Rect::MakeEmpty(); + tgfx::Rect clipBounds = tgfx::Rect::MakeEmpty(); mask->measureBounds(&clipBounds); if (!bounds->intersect(clipBounds)) { bounds->setEmpty(); @@ -248,12 +248,12 @@ void MaskModifier::applyToBounds(Rect* bounds) const { } } -void MaskModifier::applyToGraphic(Canvas* canvas, RenderCache* cache, +void MaskModifier::applyToGraphic(tgfx::Canvas* canvas, RenderCache* cache, std::shared_ptr graphic) const { if (mask == nullptr) { return; } - Rect bounds = Rect::MakeEmpty(); + tgfx::Rect bounds = tgfx::Rect::MakeEmpty(); graphic->measureBounds(&bounds); applyToBounds(&bounds); if (bounds.isEmpty()) { @@ -267,11 +267,11 @@ void MaskModifier::applyToGraphic(Canvas* canvas, RenderCache* cache, auto contentCanvas = contentSurface->getCanvas(); auto contentMatrix = contentCanvas->getMatrix(); graphic->draw(contentCanvas, cache); - auto maskSurface = Surface::Make(contentSurface->getContext(), contentSurface->width(), - contentSurface->height(), true); + auto maskSurface = tgfx::Surface::Make(contentSurface->getContext(), contentSurface->width(), + contentSurface->height(), true); if (maskSurface == nullptr) { - maskSurface = Surface::Make(contentSurface->getContext(), contentSurface->width(), - contentSurface->height()); + maskSurface = tgfx::Surface::Make(contentSurface->getContext(), contentSurface->width(), + contentSurface->height()); } if (maskSurface == nullptr) { return; @@ -282,7 +282,7 @@ void MaskModifier::applyToGraphic(Canvas* canvas, RenderCache* cache, auto maskTexture = maskSurface->getTexture(); auto texture = contentSurface->getTexture(); auto scaleFactor = GetMaxScaleFactor(contentMatrix); - auto matrix = Matrix::MakeScale(1.0f / scaleFactor); + auto matrix = tgfx::Matrix::MakeScale(1.0f / scaleFactor); matrix.postTranslate(bounds.x(), bounds.y()); canvas->save(); canvas->concat(matrix); diff --git a/src/rendering/graphics/Modifier.h b/src/rendering/graphics/Modifier.h index e4d19dfdb5..f0aa33141e 100644 --- a/src/rendering/graphics/Modifier.h +++ b/src/rendering/graphics/Modifier.h @@ -18,20 +18,19 @@ #pragma once -#include "core/Blend.h" +#include "core/BlendMode.h" #include "core/Path.h" +#include "gpu/Canvas.h" namespace pag { class Graphic; -class Canvas; - class RenderCache; class Modifier { public: - static std::shared_ptr MakeBlend(float alpha, Blend blendMode); - static std::shared_ptr MakeClip(const Path& clip); + static std::shared_ptr MakeBlend(float alpha, tgfx::BlendMode blendMode); + static std::shared_ptr MakeClip(const tgfx::Path& clip); static std::shared_ptr MakeMask(std::shared_ptr graphic, bool inverted); virtual ~Modifier() = default; @@ -44,7 +43,7 @@ class Modifier { /** * Returns the type ID of this modifier. */ - virtual ID type() const = 0; + virtual uint32_t type() const = 0; /** * Return false if target content with modification applied does not overlap or intersect with @@ -61,17 +60,17 @@ class Modifier { /** * Applies the modification to content bounds. */ - virtual void applyToBounds(Rect* bounds) const = 0; + virtual void applyToBounds(tgfx::Rect* bounds) const = 0; /** * Returns false if this modifier can not process path. */ - virtual bool applyToPath(Path* path) const = 0; + virtual bool applyToPath(tgfx::Path* path) const = 0; /** * Draws the graphic to specified canvas with custom modification. */ - virtual void applyToGraphic(Canvas* canvas, RenderCache* cache, + virtual void applyToGraphic(tgfx::Canvas* canvas, RenderCache* cache, std::shared_ptr graphic) const = 0; /** diff --git a/src/rendering/graphics/Picture.cpp b/src/rendering/graphics/Picture.cpp index 87a562a90b..9e0d208b60 100644 --- a/src/rendering/graphics/Picture.cpp +++ b/src/rendering/graphics/Picture.cpp @@ -25,7 +25,8 @@ namespace pag { // 若当前直接绘制纹理性能是最好的,就直接绘制,否则返回 false。 -static bool TryDrawDirectly(Canvas* canvas, const Texture* texture, const RGBAAALayout* layout) { +static bool TryDrawDirectly(tgfx::Canvas* canvas, const tgfx::Texture* texture, + const tgfx::RGBAAALayout* layout) { if (texture == nullptr) { return false; } @@ -45,13 +46,14 @@ static bool TryDrawDirectly(Canvas* canvas, const Texture* texture, const RGBAAA } // 强制直接绘制纹理到 canvas。 -static void DrawDirectly(Canvas* canvas, const Texture* texture, const RGBAAALayout* layout) { +static void DrawDirectly(tgfx::Canvas* canvas, const tgfx::Texture* texture, + const tgfx::RGBAAALayout* layout) { if (texture == nullptr || TryDrawDirectly(canvas, texture, layout)) { return; } auto width = layout ? layout->width : texture->width(); auto height = layout ? layout->height : texture->height(); - auto surface = Surface::Make(canvas->getContext(), width, height); + auto surface = tgfx::Surface::Make(canvas->getContext(), width, height); if (surface == nullptr) { return; } @@ -62,19 +64,19 @@ static void DrawDirectly(Canvas* canvas, const Texture* texture, const RGBAAALay canvas->flush(); } -static std::shared_ptr RescaleTexture(Context* context, Texture* texture, - float scaleFactor) { +static std::shared_ptr RescaleTexture(tgfx::Context* context, tgfx::Texture* texture, + float scaleFactor) { if (texture == nullptr || scaleFactor == 0) { return nullptr; } auto width = static_cast(ceilf(texture->width() * scaleFactor)); auto height = static_cast(ceilf(texture->height() * scaleFactor)); - auto surface = Surface::Make(context, width, height); + auto surface = tgfx::Surface::Make(context, width, height); if (surface == nullptr) { return nullptr; } auto canvas = surface->getCanvas(); - canvas->setMatrix(Matrix::MakeScale(scaleFactor)); + canvas->setMatrix(tgfx::Matrix::MakeScale(scaleFactor)); canvas->drawTexture(texture); return surface->getTexture(); } @@ -90,7 +92,7 @@ class TextureProxyPicture : public Picture { delete proxy; } - void measureBounds(Rect* bounds) const override { + void measureBounds(tgfx::Rect* bounds) const override { bounds->setWH(static_cast(proxy->width()), static_cast(proxy->height())); } @@ -104,17 +106,17 @@ class TextureProxyPicture : public Picture { if (texture == nullptr) { return false; } - auto surface = Surface::Make(cache->getContext(), 1, 1); + auto surface = tgfx::Surface::Make(cache->getContext(), 1, 1); if (surface == nullptr) { return false; } auto canvas = surface->getCanvas(); - canvas->setMatrix(Matrix::MakeTrans(-x, -y)); + canvas->setMatrix(tgfx::Matrix::MakeTrans(-x, -y)); canvas->drawTexture(texture.get()); return surface->hitTest(0, 0); } - bool getPath(Path*) const override { + bool getPath(tgfx::Path*) const override { return false; } @@ -122,7 +124,7 @@ class TextureProxyPicture : public Picture { proxy->prepare(cache); } - void draw(Canvas* canvas, RenderCache* cache) const override { + void draw(tgfx::Canvas* canvas, RenderCache* cache) const override { auto oldMatrix = canvas->getMatrix(); canvas->concat(extraMatrix); if (proxy->cacheEnabled()) { @@ -145,7 +147,7 @@ class TextureProxyPicture : public Picture { private: TextureProxy* proxy = nullptr; bool externalMemory = false; - Matrix extraMatrix = Matrix::I(); + tgfx::Matrix extraMatrix = tgfx::Matrix::I(); float getScaleFactor(float maxScaleFactor) const override { if (externalMemory) { @@ -166,7 +168,7 @@ class TextureProxyPicture : public Picture { if (texture == nullptr) { return nullptr; } - auto snapshot = new Snapshot(texture, Matrix::MakeScale(1 / scaleFactor)); + auto snapshot = new Snapshot(texture, tgfx::Matrix::MakeScale(1 / scaleFactor)); return std::unique_ptr(snapshot); } @@ -177,7 +179,7 @@ class TextureProxyPicture : public Picture { //===================================== RGBAAAPicture ============================================== class RGBAAAPicture : public Picture { public: - RGBAAAPicture(ID assetID, TextureProxy* proxy, const RGBAAALayout& layout) + RGBAAAPicture(ID assetID, TextureProxy* proxy, const tgfx::RGBAAALayout& layout) : Picture(assetID), proxy(proxy), layout(layout) { } @@ -185,7 +187,7 @@ class RGBAAAPicture : public Picture { delete proxy; } - void measureBounds(Rect* bounds) const override { + void measureBounds(tgfx::Rect* bounds) const override { bounds->setWH(static_cast(layout.width), static_cast(layout.height)); } @@ -196,18 +198,18 @@ class RGBAAAPicture : public Picture { return snapshot->hitTest(cache, x, y); } auto texture = proxy->getTexture(cache); - auto surface = Surface::Make(cache->getContext(), 1, 1); + auto surface = tgfx::Surface::Make(cache->getContext(), 1, 1); if (surface == nullptr) { return false; } auto canvas = surface->getCanvas(); - auto matrix = Matrix::MakeTrans(static_cast(-x), static_cast(-y)); + auto matrix = tgfx::Matrix::MakeTrans(static_cast(-x), static_cast(-y)); canvas->setMatrix(matrix); canvas->drawTexture(texture.get(), &layout); return surface->hitTest(0, 0); } - bool getPath(Path*) const override { + bool getPath(tgfx::Path*) const override { return false; } @@ -215,7 +217,7 @@ class RGBAAAPicture : public Picture { proxy->prepare(cache); } - void draw(Canvas* canvas, RenderCache* cache) const override { + void draw(tgfx::Canvas* canvas, RenderCache* cache) const override { if (proxy->cacheEnabled()) { // proxy在纯静态视频序列帧中不会缓存解码器 // 如果将texture获取放在snapshot获取之前,会导致每帧都创建解码器 @@ -237,7 +239,7 @@ class RGBAAAPicture : public Picture { private: TextureProxy* proxy = nullptr; - RGBAAALayout layout = {}; + tgfx::RGBAAALayout layout = {}; float getScaleFactor(float maxScaleFactor) const override { // 视频帧缩放值不需要大于 1.0f,清晰度无法继续提高。 @@ -247,15 +249,15 @@ class RGBAAAPicture : public Picture { std::unique_ptr makeSnapshot(RenderCache* cache, float scaleFactor) const override { auto width = static_cast(ceilf(static_cast(layout.width) * scaleFactor)); auto height = static_cast(ceilf(static_cast(layout.height) * scaleFactor)); - auto surface = Surface::Make(cache->getContext(), width, height); + auto surface = tgfx::Surface::Make(cache->getContext(), width, height); if (surface == nullptr) { return nullptr; } auto texture = proxy->getTexture(cache); auto canvas = surface->getCanvas(); - canvas->setMatrix(Matrix::MakeScale(scaleFactor)); + canvas->setMatrix(tgfx::Matrix::MakeScale(scaleFactor)); canvas->drawTexture(texture.get(), &layout); - auto snapshot = new Snapshot(surface->getTexture(), Matrix::MakeScale(1 / scaleFactor)); + auto snapshot = new Snapshot(surface->getTexture(), tgfx::Matrix::MakeScale(1 / scaleFactor)); return std::unique_ptr(snapshot); } @@ -264,7 +266,7 @@ class RGBAAAPicture : public Picture { //====================================== RGBAAAPicture ============================================= //====================================== SnapshotPicture =========================================== -class SnapshotPictureOptions : public SurfaceOptions { +class SnapshotPictureOptions : public tgfx::SurfaceOptions { public: bool skipSnapshotPictureCache = false; }; @@ -275,7 +277,7 @@ class SnapshotPicture : public Picture { : Picture(assetID), graphic(std::move(graphic)) { } - void measureBounds(Rect* bounds) const override { + void measureBounds(tgfx::Rect* bounds) const override { graphic->measureBounds(bounds); } @@ -288,7 +290,7 @@ class SnapshotPicture : public Picture { return graphic->hitTest(cache, x, y); } - bool getPath(Path* path) const override { + bool getPath(tgfx::Path* path) const override { return graphic->getPath(path); } @@ -296,7 +298,7 @@ class SnapshotPicture : public Picture { graphic->prepare(cache); } - void draw(Canvas* canvas, RenderCache* cache) const override { + void draw(tgfx::Canvas* canvas, RenderCache* cache) const override { auto options = static_cast(canvas->surfaceOptions()); if (options && options->skipSnapshotPictureCache) { graphic->draw(canvas, cache); @@ -316,11 +318,11 @@ class SnapshotPicture : public Picture { } std::unique_ptr makeSnapshot(RenderCache* cache, float scaleFactor) const override { - Rect bounds = Rect::MakeEmpty(); + tgfx::Rect bounds = tgfx::Rect::MakeEmpty(); graphic->measureBounds(&bounds); auto width = static_cast(ceilf(bounds.width() * scaleFactor)); auto height = static_cast(ceilf(bounds.height() * scaleFactor)); - auto surface = Surface::Make(cache->getContext(), width, height); + auto surface = tgfx::Surface::Make(cache->getContext(), width, height); if (surface == nullptr) { return nullptr; } @@ -328,11 +330,11 @@ class SnapshotPicture : public Picture { options->skipSnapshotPictureCache = true; surface->setOptions(std::move(options)); auto canvas = surface->getCanvas(); - auto matrix = Matrix::MakeScale(scaleFactor); + auto matrix = tgfx::Matrix::MakeScale(scaleFactor); matrix.preTranslate(-bounds.x(), -bounds.y()); canvas->setMatrix(matrix); graphic->draw(canvas, cache); - auto drawingMatrix = Matrix::I(); + auto drawingMatrix = tgfx::Matrix::I(); matrix.invert(&drawingMatrix); auto snapshot = new Snapshot(surface->getTexture(), drawingMatrix); return std::unique_ptr(snapshot); @@ -346,7 +348,7 @@ class SnapshotPicture : public Picture { //==================================== Texture Proxies ============================================= class TextureBufferProxy : public TextureProxy { public: - explicit TextureBufferProxy(const std::shared_ptr buffer) + explicit TextureBufferProxy(const std::shared_ptr buffer) : TextureProxy(buffer->width(), buffer->height()), buffer(buffer) { } @@ -357,7 +359,7 @@ class TextureBufferProxy : public TextureProxy { void prepare(RenderCache*) const override { } - std::shared_ptr getTexture(RenderCache* cache) const override { + std::shared_ptr getTexture(RenderCache* cache) const override { auto startTime = GetTimer(); auto texture = buffer->makeTexture(cache->getContext()); cache->recordTextureUploadingTime(GetTimer() - startTime); @@ -365,12 +367,12 @@ class TextureBufferProxy : public TextureProxy { } private: - std::shared_ptr buffer = nullptr; + std::shared_ptr buffer = nullptr; }; class ImageTextureProxy : public TextureProxy { public: - explicit ImageTextureProxy(ID assetID, int width, int height, std::shared_ptr image) + explicit ImageTextureProxy(ID assetID, int width, int height, std::shared_ptr image) : TextureProxy(width, height), assetID(assetID), image(std::move(image)) { } @@ -382,7 +384,7 @@ class ImageTextureProxy : public TextureProxy { cache->prepareImage(assetID, image); } - std::shared_ptr getTexture(RenderCache* cache) const override { + std::shared_ptr getTexture(RenderCache* cache) const override { auto startTime = GetTimer(); auto buffer = cache->getImageBuffer(assetID); if (buffer == nullptr) { @@ -400,12 +402,13 @@ class ImageTextureProxy : public TextureProxy { private: ID assetID = 0; - std::shared_ptr image = nullptr; + std::shared_ptr image = nullptr; }; class BackendTextureProxy : public TextureProxy { public: - BackendTextureProxy(const BackendTexture& texture, ImageOrigin origin, void* sharedContext) + BackendTextureProxy(const tgfx::BackendTexture& texture, tgfx::ImageOrigin origin, + void* sharedContext) : TextureProxy(texture.width(), texture.height()), backendTexture(texture), origin(origin), sharedContext(sharedContext) { } @@ -417,21 +420,21 @@ class BackendTextureProxy : public TextureProxy { void prepare(RenderCache*) const override { } - std::shared_ptr getTexture(RenderCache* cache) const override { + std::shared_ptr getTexture(RenderCache* cache) const override { auto context = cache->getContext(); if (!checkContext(context)) { return nullptr; } - return Texture::MakeFrom(context, backendTexture, origin); + return tgfx::Texture::MakeFrom(context, backendTexture, origin); } private: - BackendTexture backendTexture = {}; - ImageOrigin origin = ImageOrigin::TopLeft; + tgfx::BackendTexture backendTexture = {}; + tgfx::ImageOrigin origin = tgfx::ImageOrigin::TopLeft; void* sharedContext = nullptr; - bool checkContext(Context* context) const { - auto glDevice = static_cast(context->device()); + bool checkContext(tgfx::Context* context) const { + auto glDevice = static_cast(context->device()); if (!glDevice->sharableWith(sharedContext)) { LOGE( "A Graphic which made from a texture can not be drawn on to a PAGSurface" @@ -448,12 +451,12 @@ static std::atomic_uint64_t IDCount = {1}; Picture::Picture(ID assetID) : assetID(assetID), uniqueKey(IDCount++) { } -std::shared_ptr Picture::MakeFrom(ID assetID, std::shared_ptr image) { +std::shared_ptr Picture::MakeFrom(ID assetID, std::shared_ptr image) { if (image == nullptr) { return nullptr; } auto extraMatrix = OrientationToMatrix(image->orientation(), image->width(), image->height()); - auto bounds = Rect::MakeWH(image->width(), image->height()); + auto bounds = tgfx::Rect::MakeWH(image->width(), image->height()); extraMatrix.mapRect(&bounds); auto textureProxy = new ImageTextureProxy(assetID, static_cast(bounds.width()), static_cast(bounds.height()), image); @@ -462,7 +465,8 @@ std::shared_ptr Picture::MakeFrom(ID assetID, std::shared_ptr im return picture; } -std::shared_ptr Picture::MakeFrom(ID assetID, std::shared_ptr buffer) { +std::shared_ptr Picture::MakeFrom(ID assetID, + std::shared_ptr buffer) { if (buffer == nullptr) { return nullptr; } @@ -470,12 +474,12 @@ std::shared_ptr Picture::MakeFrom(ID assetID, std::shared_ptr(new TextureProxyPicture(assetID, proxy, false)); } -std::shared_ptr Picture::MakeFrom(ID assetID, const BackendTexture& texture, - ImageOrigin origin) { +std::shared_ptr Picture::MakeFrom(ID assetID, const tgfx::BackendTexture& texture, + tgfx::ImageOrigin origin) { if (!texture.isValid()) { return nullptr; } - auto context = GLDevice::CurrentNativeHandle(); + auto context = tgfx::GLDevice::CurrentNativeHandle(); if (context == nullptr) { return nullptr; } @@ -491,7 +495,7 @@ std::shared_ptr Picture::MakeFrom(ID assetID, std::unique_ptr Picture::MakeFrom(ID assetID, std::unique_ptr proxy, - const RGBAAALayout& layout) { + const tgfx::RGBAAALayout& layout) { if (layout.alphaStartX == 0 && layout.alphaStartY == 0) { return Picture::MakeFrom(assetID, std::move(proxy)); } diff --git a/src/rendering/graphics/Picture.h b/src/rendering/graphics/Picture.h index 65f6ee47bc..48e1b9663d 100644 --- a/src/rendering/graphics/Picture.h +++ b/src/rendering/graphics/Picture.h @@ -37,18 +37,18 @@ class Picture : public Graphic { /** * Creates a new Picture with specified Image. Return null if the proxy is null. */ - static std::shared_ptr MakeFrom(ID assetID, std::shared_ptr image); + static std::shared_ptr MakeFrom(ID assetID, std::shared_ptr image); /** * Creates a new Picture with specified TextureBuffer. Returns null if the bitmap is empty. */ - static std::shared_ptr MakeFrom(ID assetID, std::shared_ptr buffer); + static std::shared_ptr MakeFrom(ID assetID, std::shared_ptr buffer); /** * Creates a new Picture with specified backend texture. Returns null if the texture is invalid. */ - static std::shared_ptr MakeFrom(ID assetID, const BackendTexture& texture, - ImageOrigin origin); + static std::shared_ptr MakeFrom(ID assetID, const tgfx::BackendTexture& texture, + tgfx::ImageOrigin origin); /* * Creates a new image with specified TextureProxy. Returns nullptr if the proxy is null. @@ -60,7 +60,7 @@ class Picture : public Graphic { * proxy is null or the layout is invalid. */ static std::shared_ptr MakeFrom(ID assetID, std::unique_ptr proxy, - const RGBAAALayout& layout); + const tgfx::RGBAAALayout& layout); /** * Creates a new Picture with specified graphic. If the assetID is valid (not 0), the returned diff --git a/src/rendering/graphics/Recorder.cpp b/src/rendering/graphics/Recorder.cpp index c669f7fd38..bd70260398 100644 --- a/src/rendering/graphics/Recorder.cpp +++ b/src/rendering/graphics/Recorder.cpp @@ -23,7 +23,7 @@ enum class RecordType { Matrix, Layer }; class Record { public: - explicit Record(const Matrix& matrix) : matrix(matrix) { + explicit Record(const tgfx::Matrix& matrix) : matrix(matrix) { } virtual ~Record() = default; @@ -32,12 +32,12 @@ class Record { return RecordType::Matrix; } - Matrix matrix = {}; + tgfx::Matrix matrix = {}; }; class LayerRecord : public Record { public: - LayerRecord(const Matrix& matrix, std::shared_ptr modifier, + LayerRecord(const tgfx::Matrix& matrix, std::shared_ptr modifier, std::vector> contents) : Record(matrix), modifier(std::move(modifier)), oldNodes(std::move(contents)) { } @@ -50,8 +50,8 @@ class LayerRecord : public Record { std::vector> oldNodes = {}; }; -Matrix Recorder::getMatrix() const { - Matrix totalMatrix = matrix; +tgfx::Matrix Recorder::getMatrix() const { + tgfx::Matrix totalMatrix = matrix; for (int i = static_cast(records.size() - 1); i >= 0; i--) { auto& record = records[i]; if (record->type() == RecordType::Layer) { @@ -61,11 +61,11 @@ Matrix Recorder::getMatrix() const { return totalMatrix; } -void Recorder::setMatrix(const Matrix& m) { +void Recorder::setMatrix(const tgfx::Matrix& m) { matrix = m; auto count = static_cast(records.size()); if (count > 0) { - auto totalMatrix = Matrix::I(); + auto totalMatrix = tgfx::Matrix::I(); for (auto i = count - 1; i >= 0; i--) { auto& record = records[i]; if (record->type() == RecordType::Layer) { @@ -78,22 +78,22 @@ void Recorder::setMatrix(const Matrix& m) { } } -void Recorder::concat(const Matrix& m) { +void Recorder::concat(const tgfx::Matrix& m) { matrix.preConcat(m); } void Recorder::saveClip(float x, float y, float width, float height) { - Path path = {}; - path.addRect(Rect::MakeXYWH(x, y, width, height)); + tgfx::Path path = {}; + path.addRect(tgfx::Rect::MakeXYWH(x, y, width, height)); saveClip(path); } -void Recorder::saveClip(const Path& path) { +void Recorder::saveClip(const tgfx::Path& path) { auto modifier = Modifier::MakeClip(path); saveLayer(modifier); } -void Recorder::saveLayer(float alpha, Blend blendMode) { +void Recorder::saveLayer(float alpha, tgfx::BlendMode blendMode) { auto modifier = Modifier::MakeBlend(alpha, blendMode); saveLayer(modifier); } @@ -105,7 +105,7 @@ void Recorder::saveLayer(std::shared_ptr modifier) { } auto record = std::make_shared(matrix, modifier, layerContents); records.push_back(record); - matrix = Matrix::I(); + matrix = tgfx::Matrix::I(); layerContents = {}; layerIndex++; } @@ -142,7 +142,7 @@ void Recorder::restoreToCount(size_t saveCount) { } } -void Recorder::drawGraphic(std::shared_ptr graphic, const Matrix& m) { +void Recorder::drawGraphic(std::shared_ptr graphic, const tgfx::Matrix& m) { auto oldMatrix = matrix; matrix.preConcat(m); drawGraphic(std::move(graphic)); diff --git a/src/rendering/graphics/Recorder.h b/src/rendering/graphics/Recorder.h index 713acd5388..857e87ba42 100644 --- a/src/rendering/graphics/Recorder.h +++ b/src/rendering/graphics/Recorder.h @@ -32,14 +32,14 @@ class Recorder { /** * Returns the current total matrix. */ - Matrix getMatrix() const; + tgfx::Matrix getMatrix() const; /** * Replaces transformation with specified matrix. Unlike concat(), any prior matrix state is * overwritten. * @param matrix matrix to copy, replacing existing Matrix */ - void setMatrix(const Matrix& matrix); + void setMatrix(const tgfx::Matrix& matrix); /** * Replaces transformation with specified matrix premultiplied with existing Matrix. This has the @@ -47,7 +47,7 @@ class Recorder { * existing Matrix. * @param matrix matrix to premultiply with existing Matrix */ - void concat(const Matrix& matrix); + void concat(const tgfx::Matrix& matrix); /** * Saves matrix, and allocates a layer for subsequent drawing. Calling restore() discards changes @@ -63,7 +63,7 @@ class Recorder { * a stack, multiple calls to saveLayer(), saveClip() and save() should be balance by an equal * number of calls to restore(). */ - void saveClip(const Path& path); + void saveClip(const tgfx::Path& path); /** * Saves matrix, and allocates a layer for subsequent drawing. Calling restore() discards changes @@ -71,7 +71,7 @@ class Recorder { * on a stack, multiple calls to saveLayer(), saveClip() and save() should be balance by an equal * number of calls to restore(). */ - void saveLayer(float alpha, Blend blendMode); + void saveLayer(float alpha, tgfx::BlendMode blendMode); /** * Saves matrix, and allocates a layer for subsequent drawing. Calling restore() discards changes @@ -113,7 +113,7 @@ class Recorder { /** * Draws a graphic using current clip and extra matrix. */ - void drawGraphic(std::shared_ptr graphic, const Matrix& matrix); + void drawGraphic(std::shared_ptr graphic, const tgfx::Matrix& matrix); /** * Returns a Graphic capturing recorder contents. Subsequent drawing to recorder contents are not @@ -124,7 +124,7 @@ class Recorder { private: std::vector> rootContents = {}; int layerIndex = 0; - Matrix matrix = Matrix::I(); + tgfx::Matrix matrix = tgfx::Matrix::I(); std::vector> layerContents = {}; std::vector> records = {}; }; diff --git a/src/rendering/graphics/Shape.cpp b/src/rendering/graphics/Shape.cpp index 0cf22f584f..9fa5ef5c3a 100644 --- a/src/rendering/graphics/Shape.cpp +++ b/src/rendering/graphics/Shape.cpp @@ -17,46 +17,46 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "Shape.h" +#include "base/utils/TGFXCast.h" #include "gpu/Canvas.h" #include "gpu/Shader.h" #include "pag/file.h" -#include "rendering/utils/TGFXTypes.h" namespace pag { -std::shared_ptr Shape::MakeFrom(const Path& path, Color4f color) { +std::shared_ptr Shape::MakeFrom(const tgfx::Path& path, tgfx::Color color) { if (path.isEmpty()) { return nullptr; } - Paint paint = {}; + tgfx::Paint paint = {}; paint.setColor(color); return std::shared_ptr(new Shape(path, paint)); } -std::shared_ptr Shape::MakeFrom(const Path& path, const GradientPaint& gradient) { +std::shared_ptr Shape::MakeFrom(const tgfx::Path& path, const GradientPaint& gradient) { if (path.isEmpty()) { return nullptr; } - std::shared_ptr shader; + std::shared_ptr shader; if (gradient.gradientType == GradientFillType::Linear) { - shader = Shader::MakeLinearGradient(gradient.startPoint, gradient.endPoint, gradient.colors, - gradient.positions); + shader = tgfx::Shader::MakeLinearGradient(gradient.startPoint, gradient.endPoint, + gradient.colors, gradient.positions); } else { - auto radius = Point::Distance(gradient.startPoint, gradient.endPoint); - shader = Shader::MakeRadialGradient(gradient.startPoint, radius, gradient.colors, - gradient.positions); + auto radius = tgfx::Point::Distance(gradient.startPoint, gradient.endPoint); + shader = tgfx::Shader::MakeRadialGradient(gradient.startPoint, radius, gradient.colors, + gradient.positions); } if (!shader) { - shader = Shader::MakeColorShader(gradient.colors.back()); + shader = tgfx::Shader::MakeColorShader(gradient.colors.back()); } - Paint paint = {}; + tgfx::Paint paint = {}; paint.setShader(shader); return std::shared_ptr(new Shape(path, paint)); } -Shape::Shape(Path path, Paint paint) : path(std::move(path)), paint(paint) { +Shape::Shape(tgfx::Path path, tgfx::Paint paint) : path(std::move(path)), paint(paint) { } -void Shape::measureBounds(Rect* bounds) const { +void Shape::measureBounds(tgfx::Rect* bounds) const { *bounds = path.getBounds(); } @@ -64,7 +64,7 @@ bool Shape::hitTest(RenderCache*, float x, float y) { return path.contains(x, y); } -bool Shape::getPath(Path* result) const { +bool Shape::getPath(tgfx::Path* result) const { if (paint.getAlpha() != 1.0f) { return false; } @@ -79,7 +79,7 @@ bool Shape::getPath(Path* result) const { void Shape::prepare(RenderCache*) const { } -void Shape::draw(Canvas* canvas, RenderCache*) const { +void Shape::draw(tgfx::Canvas* canvas, RenderCache*) const { canvas->drawPath(path, paint); } diff --git a/src/rendering/graphics/Shape.h b/src/rendering/graphics/Shape.h index ab214b309c..203f67f16d 100644 --- a/src/rendering/graphics/Shape.h +++ b/src/rendering/graphics/Shape.h @@ -26,27 +26,27 @@ class Shape : public Graphic { /** * Creates a shape Graphic with solid color fill. Returns nullptr if path is empty. */ - static std::shared_ptr MakeFrom(const Path& path, Color4f color); + static std::shared_ptr MakeFrom(const tgfx::Path& path, tgfx::Color color); /** * Creates a shape Graphic with gradient color fill. Returns nullptr if path is empty. */ - static std::shared_ptr MakeFrom(const Path& path, const GradientPaint& gradient); + static std::shared_ptr MakeFrom(const tgfx::Path& path, const GradientPaint& gradient); GraphicType type() const override { return GraphicType::Shape; } - void measureBounds(Rect* bounds) const override; + void measureBounds(tgfx::Rect* bounds) const override; bool hitTest(RenderCache* cache, float x, float y) override; - bool getPath(Path* result) const override; + bool getPath(tgfx::Path* result) const override; void prepare(RenderCache* cache) const override; - void draw(Canvas* canvas, RenderCache* cache) const override; + void draw(tgfx::Canvas* canvas, RenderCache* cache) const override; private: - Path path = {}; - Paint paint = {}; + tgfx::Path path = {}; + tgfx::Paint paint = {}; - Shape(Path path, Paint paint); + Shape(tgfx::Path path, tgfx::Paint paint); }; } // namespace pag diff --git a/src/rendering/graphics/Snapshot.cpp b/src/rendering/graphics/Snapshot.cpp index 79840c2dbf..a4144a21bc 100644 --- a/src/rendering/graphics/Snapshot.cpp +++ b/src/rendering/graphics/Snapshot.cpp @@ -23,16 +23,16 @@ namespace pag { bool Snapshot::hitTest(RenderCache* cache, float x, float y) const { - Point local = {x, y}; + tgfx::Point local = {x, y}; if (!MapPointInverted(matrix, &local)) { return false; } - auto surface = Surface::Make(cache->getContext(), 1, 1); + auto surface = tgfx::Surface::Make(cache->getContext(), 1, 1); if (surface == nullptr) { return false; } auto canvas = surface->getCanvas(); - canvas->setMatrix(Matrix::MakeTrans(-local.x, -local.y)); + canvas->setMatrix(tgfx::Matrix::MakeTrans(-local.x, -local.y)); canvas->drawTexture(texture.get()); return surface->hitTest(0, 0); } diff --git a/src/rendering/graphics/Snapshot.h b/src/rendering/graphics/Snapshot.h index 22b0f05a86..01e571663f 100644 --- a/src/rendering/graphics/Snapshot.h +++ b/src/rendering/graphics/Snapshot.h @@ -18,7 +18,9 @@ #pragma once +#include "core/Matrix.h" #include "gpu/Texture.h" +#include "pag/types.h" namespace pag { class RenderCache; @@ -32,7 +34,7 @@ class Snapshot { /** * Creates a new Snapshot with specified texture and matrix. */ - explicit Snapshot(std::shared_ptr texture, const Matrix& matrix) + explicit Snapshot(std::shared_ptr texture, const tgfx::Matrix& matrix) : texture(std::move(texture)), matrix(matrix) { } @@ -43,11 +45,11 @@ class Snapshot { return 1 / matrix.getScaleX(); } - Matrix getMatrix() const { + tgfx::Matrix getMatrix() const { return matrix; } - Texture* getTexture() const { + tgfx::Texture* getTexture() const { return texture.get(); } @@ -66,8 +68,8 @@ class Snapshot { bool hitTest(RenderCache* cache, float x, float y) const; private: - std::shared_ptr texture = nullptr; - Matrix matrix = Matrix::I(); + std::shared_ptr texture = nullptr; + tgfx::Matrix matrix = tgfx::Matrix::I(); ID assetID = 0; uint64_t makerKey = 0; Frame idleFrames = 0; diff --git a/src/rendering/graphics/Text.cpp b/src/rendering/graphics/Text.cpp index fd0988f328..f8861b3bd1 100644 --- a/src/rendering/graphics/Text.cpp +++ b/src/rendering/graphics/Text.cpp @@ -18,33 +18,33 @@ #include "Text.h" #include +#include "base/utils/TGFXCast.h" #include "core/PathEffect.h" #include "gpu/Canvas.h" #include "pag/file.h" -#include "rendering/utils/TGFXTypes.h" namespace pag { -static std::unique_ptr CreateFillPaint(const Glyph* glyph) { +static std::unique_ptr CreateFillPaint(const Glyph* glyph) { if (glyph->getStyle() != TextStyle::Fill && glyph->getStyle() != TextStyle::StrokeAndFill) { return nullptr; } - auto fillPaint = new Paint(); - fillPaint->setStyle(PaintStyle::Fill); - fillPaint->setColor(ToTGFXColor(glyph->getFillColor())); + auto fillPaint = new tgfx::Paint(); + fillPaint->setStyle(tgfx::PaintStyle::Fill); + fillPaint->setColor(ToTGFX(glyph->getFillColor())); fillPaint->setAlpha(glyph->getAlpha()); - return std::unique_ptr(fillPaint); + return std::unique_ptr(fillPaint); } -static std::unique_ptr CreateStrokePaint(const Glyph* glyph) { +static std::unique_ptr CreateStrokePaint(const Glyph* glyph) { if (glyph->getStyle() != TextStyle::Stroke && glyph->getStyle() != TextStyle::StrokeAndFill) { return nullptr; } - auto strokePaint = new Paint(); - strokePaint->setStyle(PaintStyle::Stroke); - strokePaint->setColor(ToTGFXColor(glyph->getStrokeColor())); + auto strokePaint = new tgfx::Paint(); + strokePaint->setStyle(tgfx::PaintStyle::Stroke); + strokePaint->setColor(ToTGFX(glyph->getStrokeColor())); strokePaint->setAlpha(glyph->getAlpha()); strokePaint->setStrokeWidth(glyph->getStrokeWidth()); - return std::unique_ptr(strokePaint); + return std::unique_ptr(strokePaint); } static std::unique_ptr MakeTextRun(const std::vector& glyphs) { @@ -67,8 +67,8 @@ static std::unique_ptr MakeTextRun(const std::vector& glyphs) { noTranslateMatrix.setTranslateY(0); textRun->matrix = noTranslateMatrix; noTranslateMatrix.invert(&noTranslateMatrix); - std::vector glyphIDs = {}; - std::vector positions = {}; + std::vector glyphIDs = {}; + std::vector positions = {}; for (auto& glyph : glyphs) { glyphIDs.push_back(glyph->getGlyphID()); auto m = glyph->getTotalMatrix(); @@ -82,19 +82,19 @@ static std::unique_ptr MakeTextRun(const std::vector& glyphs) { } std::shared_ptr Text::MakeFrom(const std::vector& glyphs, - const Rect* calculatedBounds) { + const tgfx::Rect* calculatedBounds) { if (glyphs.empty()) { return nullptr; } // 用 vector 存 key 的目的是让文字叠加顺序固定。 // 不固定的话叠加区域的像素会不一样,肉眼看不出来,但是测试用例的结果不稳定。 - std::vector styleKeys = {}; - std::unordered_map, BytesHasher> styleMap = {}; + std::vector styleKeys = {}; + std::unordered_map, tgfx::BytesHasher> styleMap = {}; for (auto& glyph : glyphs) { if (!glyph->isVisible()) { continue; } - BytesKey styleKey = {}; + tgfx::BytesKey styleKey = {}; glyph->computeStyleKey(&styleKey); auto size = styleMap.size(); styleMap[styleKey].push_back(glyph.get()); @@ -103,12 +103,12 @@ std::shared_ptr Text::MakeFrom(const std::vector& glyphs, } } bool hasAlpha = false; - Rect bounds = calculatedBounds ? *calculatedBounds : Rect::MakeEmpty(); + tgfx::Rect bounds = calculatedBounds ? *calculatedBounds : tgfx::Rect::MakeEmpty(); std::vector textRuns; float maxStrokeWidth = 0; for (auto& key : styleKeys) { auto& glyphList = styleMap[key]; - Rect textBounds = Rect::MakeEmpty(); + tgfx::Rect textBounds = tgfx::Rect::MakeEmpty(); for (auto glyph : glyphList) { auto glyphBounds = glyph->getBounds(); glyph->getMatrix().mapRect(&glyphBounds); @@ -137,7 +137,7 @@ std::shared_ptr Text::MakeFrom(const std::vector& glyphs, return std::shared_ptr(new Text(textRuns, bounds, hasAlpha)); } -Text::Text(const std::vector& textRuns, const Rect& bounds, bool hasAlpha) +Text::Text(const std::vector& textRuns, const tgfx::Rect& bounds, bool hasAlpha) : textRuns(textRuns), bounds(bounds), hasAlpha(hasAlpha) { } @@ -147,16 +147,16 @@ Text::~Text() { } } -void Text::measureBounds(Rect* rect) const { +void Text::measureBounds(tgfx::Rect* rect) const { *rect = bounds; } -static void ApplyPaintToPath(const Paint& paint, Path* path) { - if (paint.getStyle() == PaintStyle::Fill || path == nullptr) { +static void ApplyPaintToPath(const tgfx::Paint& paint, tgfx::Path* path) { + if (paint.getStyle() == tgfx::PaintStyle::Fill || path == nullptr) { return; } auto strokePath = *path; - auto strokeEffect = PathEffect::MakeStroke(*paint.getStroke()); + auto strokeEffect = tgfx::PathEffect::MakeStroke(*paint.getStroke()); if (strokeEffect) { strokeEffect->applyTo(&strokePath); } @@ -165,13 +165,13 @@ static void ApplyPaintToPath(const Paint& paint, Path* path) { bool Text::hitTest(RenderCache*, float x, float y) { for (auto& textRun : textRuns) { - auto local = Point::Make(x, y); - Matrix invertMatrix = {}; + auto local = tgfx::Point::Make(x, y); + tgfx::Matrix invertMatrix = {}; if (!textRun->matrix.invert(&invertMatrix)) { continue; } invertMatrix.mapPoints(&local, 1); - Path glyphPath = {}; + tgfx::Path glyphPath = {}; int index = 0; auto& textFont = textRun->textFont; for (auto& glyphID : textRun->glyphIDs) { @@ -194,27 +194,27 @@ bool Text::hitTest(RenderCache*, float x, float y) { return false; } -bool Text::getPath(Path* path) const { +bool Text::getPath(tgfx::Path* path) const { if (hasAlpha || path == nullptr) { return false; } - Path textPath = {}; + tgfx::Path textPath = {}; for (auto& textRun : textRuns) { - Path glyphPath = {}; + tgfx::Path glyphPath = {}; int index = 0; auto& textFont = textRun->textFont; for (auto& glyphID : textRun->glyphIDs) { - Path tempPath = {}; + tgfx::Path tempPath = {}; if (!textFont.getGlyphPath(glyphID, &tempPath)) { return false; } auto pos = textRun->positions[index]; - tempPath.transform(Matrix::MakeTrans(pos.x, pos.y)); + tempPath.transform(tgfx::Matrix::MakeTrans(pos.x, pos.y)); glyphPath.addPath(tempPath); index++; } glyphPath.transform(textRun->matrix); - Path tempPath = glyphPath; + tgfx::Path tempPath = glyphPath; auto firstPaint = textRun->paints[0]; auto secondPaint = textRun->paints[1]; ApplyPaintToPath(*firstPaint, &tempPath); @@ -232,12 +232,12 @@ bool Text::getPath(Path* path) const { void Text::prepare(RenderCache*) const { } -void Text::draw(Canvas* canvas, RenderCache*) const { - drawTextRuns(static_cast(canvas), 0); - drawTextRuns(static_cast(canvas), 1); +void Text::draw(tgfx::Canvas* canvas, RenderCache*) const { + drawTextRuns(static_cast(canvas), 0); + drawTextRuns(static_cast(canvas), 1); } -void Text::drawTextRuns(Canvas* canvas, int paintIndex) const { +void Text::drawTextRuns(tgfx::Canvas* canvas, int paintIndex) const { auto totalMatrix = canvas->getMatrix(); for (auto& textRun : textRuns) { auto textPaint = textRun->paints[paintIndex]; diff --git a/src/rendering/graphics/Text.h b/src/rendering/graphics/Text.h index 1ef98a21fe..6f467d9bbf 100644 --- a/src/rendering/graphics/Text.h +++ b/src/rendering/graphics/Text.h @@ -29,11 +29,11 @@ class TextRun { delete paints[1]; } - Matrix matrix = Matrix::I(); - Paint* paints[2] = {nullptr, nullptr}; - Font textFont = {}; - std::vector glyphIDs; - std::vector positions; + tgfx::Matrix matrix = tgfx::Matrix::I(); + tgfx::Paint* paints[2] = {nullptr, nullptr}; + tgfx::Font textFont = {}; + std::vector glyphIDs; + std::vector positions; }; class Text : public Graphic { @@ -43,7 +43,7 @@ class Text : public Graphic { * are invisible. */ static std::shared_ptr MakeFrom(const std::vector& glyphs, - const Rect* calculatedBounds = nullptr); + const tgfx::Rect* calculatedBounds = nullptr); ~Text() override; @@ -51,18 +51,18 @@ class Text : public Graphic { return GraphicType::Text; } - void measureBounds(Rect* rect) const override; + void measureBounds(tgfx::Rect* rect) const override; bool hitTest(RenderCache* cache, float x, float y) override; - bool getPath(Path* path) const override; + bool getPath(tgfx::Path* path) const override; void prepare(RenderCache* cache) const override; - void draw(Canvas* canvas, RenderCache* cache) const override; + void draw(tgfx::Canvas* canvas, RenderCache* cache) const override; private: std::vector textRuns; - Rect bounds = Rect::MakeEmpty(); + tgfx::Rect bounds = tgfx::Rect::MakeEmpty(); bool hasAlpha = false; - explicit Text(const std::vector& textRuns, const Rect& bounds, bool hasAlpha); - void drawTextRuns(Canvas* canvas, int paintIndex) const; + explicit Text(const std::vector& textRuns, const tgfx::Rect& bounds, bool hasAlpha); + void drawTextRuns(tgfx::Canvas* canvas, int paintIndex) const; }; } // namespace pag diff --git a/src/rendering/graphics/TextureProxy.h b/src/rendering/graphics/TextureProxy.h index 54016c2ac6..a264cc1c62 100644 --- a/src/rendering/graphics/TextureProxy.h +++ b/src/rendering/graphics/TextureProxy.h @@ -61,7 +61,7 @@ class TextureProxy { /** * Instantiates and returns the backing texture associated with this proxy. */ - virtual std::shared_ptr getTexture(RenderCache* cache) const = 0; + virtual std::shared_ptr getTexture(RenderCache* cache) const = 0; private: int _width = 0; diff --git a/src/rendering/layers/PAGComposition.cpp b/src/rendering/layers/PAGComposition.cpp index b2b488337d..fa8c49c654 100644 --- a/src/rendering/layers/PAGComposition.cpp +++ b/src/rendering/layers/PAGComposition.cpp @@ -435,13 +435,13 @@ void PAGComposition::draw(Recorder* recorder) { void PAGComposition::DrawChildLayer(Recorder* recorder, PAGLayer* childLayer) { auto filterModifier = childLayer->cacheFilters() ? nullptr : FilterModifier::Make(childLayer); auto trackMatte = TrackMatteRenderer::Make(childLayer); - Transform extraTransform = {childLayer->layerMatrix, childLayer->layerAlpha}; + Transform extraTransform = {ToTGFX(childLayer->layerMatrix), childLayer->layerAlpha}; LayerRenderer::DrawLayer(recorder, childLayer->layer, childLayer->contentFrame + childLayer->layer->startTime, filterModifier, trackMatte.get(), childLayer, &extraTransform); } -void PAGComposition::measureBounds(Rect* bounds) { +void PAGComposition::measureBounds(tgfx::Rect* bounds) { if (!contentModified() && layerCache->contentStatic()) { getContent()->measureBounds(bounds); return; @@ -456,34 +456,34 @@ void PAGComposition::measureBounds(Rect* bounds) { if (!childLayer->layerVisible) { continue; } - Rect layerBounds = {}; + tgfx::Rect layerBounds = {}; MeasureChildLayer(&layerBounds, childLayer.get()); bounds->join(layerBounds); } if (hasClip() && !bounds->isEmpty()) { - auto clipBounds = Rect::MakeXYWH(0, 0, _width, _height); + auto clipBounds = tgfx::Rect::MakeXYWH(0, 0, _width, _height); if (!bounds->intersect(clipBounds)) { bounds->setEmpty(); } } } -void PAGComposition::MeasureChildLayer(Rect* bounds, PAGLayer* childLayer) { - std::unique_ptr trackMatteBounds = nullptr; +void PAGComposition::MeasureChildLayer(tgfx::Rect* bounds, PAGLayer* childLayer) { + std::unique_ptr trackMatteBounds = nullptr; if (childLayer->_trackMatteLayer != nullptr) { - trackMatteBounds = std::unique_ptr(new Rect()); + trackMatteBounds = std::make_unique(); trackMatteBounds->setEmpty(); auto trackMatteLayer = childLayer->_trackMatteLayer; auto layerFrame = trackMatteLayer->contentFrame + trackMatteLayer->layer->startTime; auto filterModifier = FilterModifier::Make(trackMatteLayer.get()); - Transform extraTransform = {trackMatteLayer->layerMatrix, trackMatteLayer->layerAlpha}; + Transform extraTransform = {ToTGFX(trackMatteLayer->layerMatrix), trackMatteLayer->layerAlpha}; LayerRenderer::MeasureLayerBounds(trackMatteBounds.get(), trackMatteLayer->layer, layerFrame, filterModifier, nullptr, trackMatteLayer.get(), &extraTransform); } auto layerFrame = childLayer->contentFrame + childLayer->layer->startTime; auto filterModifier = FilterModifier::Make(childLayer->layer, layerFrame); - Transform extraTransform = {childLayer->layerMatrix, childLayer->layerAlpha}; + Transform extraTransform = {ToTGFX(childLayer->layerMatrix), childLayer->layerAlpha}; LayerRenderer::MeasureLayerBounds(bounds, childLayer->layer, layerFrame, filterModifier, trackMatteBounds.get(), childLayer, &extraTransform); } @@ -515,9 +515,9 @@ bool PAGComposition::GetTrackMatteLayerAtPoint(PAGLayer* childLayer, float x, fl Transform trackMatteTransform = {}; auto trackMatteLayer = childLayer->_trackMatteLayer.get(); if (trackMatteLayer->getTransform(&trackMatteTransform)) { - Point local = {x, y}; + tgfx::Point local = {x, y}; MapPointInverted(trackMatteTransform.matrix, &local); - Rect trackMatteBounds = {}; + tgfx::Rect trackMatteBounds = {}; trackMatteLayer->measureBounds(&trackMatteBounds); contains = trackMatteBounds.contains(local.x, local.y); if (contains) { @@ -536,7 +536,7 @@ bool PAGComposition::GetChildLayerAtPoint(PAGLayer* childLayer, float x, float y if (!childLayer->getTransform(&layerTransform)) { return false; } - Point localPoint = {x, y}; + tgfx::Point localPoint = {x, y}; MapPointInverted(layerTransform.matrix, &localPoint); auto mask = childLayer->layerCache->getMasks(childLayer->contentFrame); if (mask) { @@ -553,7 +553,7 @@ bool PAGComposition::GetChildLayerAtPoint(PAGLayer* childLayer, float x, float y ->getLayersUnderPointInternal(localPoint.x, localPoint.y, results); } if (!success) { - Rect childBounds = {}; + tgfx::Rect childBounds = {}; childLayer->measureBounds(&childBounds); success = childBounds.contains(localPoint.x, localPoint.y); } @@ -562,7 +562,7 @@ bool PAGComposition::GetChildLayerAtPoint(PAGLayer* childLayer, float x, float y bool PAGComposition::getLayersUnderPointInternal(float x, float y, std::vector>* results) { - auto bounds = Rect::MakeWH(static_cast(_width), static_cast(_height)); + auto bounds = tgfx::Rect::MakeWH(static_cast(_width), static_cast(_height)); if (hasClip() && !bounds.contains(x, y)) { return false; } diff --git a/src/rendering/layers/PAGImageLayer.cpp b/src/rendering/layers/PAGImageLayer.cpp index c00234ccc5..e8f12799e2 100644 --- a/src/rendering/layers/PAGImageLayer.cpp +++ b/src/rendering/layers/PAGImageLayer.cpp @@ -656,7 +656,7 @@ Frame PAGImageLayer::getFrameFromTimeRemap(pag::Frame value) { } // ImageBytesV3场景下,图片的透明区域会发生裁剪,不能从图片解码中获取宽高 -void PAGImageLayer::measureBounds(Rect* bounds) { +void PAGImageLayer::measureBounds(tgfx::Rect* bounds) { auto imageLayer = static_cast(layer); bounds->setWH(imageLayer->imageBytes->width, imageLayer->imageBytes->height); } diff --git a/src/rendering/layers/PAGLayer.cpp b/src/rendering/layers/PAGLayer.cpp index 286bffde01..7fdcdf8b2a 100644 --- a/src/rendering/layers/PAGLayer.cpp +++ b/src/rendering/layers/PAGLayer.cpp @@ -78,7 +78,7 @@ Matrix PAGLayer::getTotalMatrix() { } Matrix PAGLayer::getTotalMatrixInternal() { - auto matrix = layerCache->getTransform(contentFrame)->matrix; + auto matrix = ToPAG(layerCache->getTransform(contentFrame)->matrix); matrix.postConcat(layerMatrix); return matrix; } @@ -118,7 +118,7 @@ void PAGLayer::setVisibleInternal(bool value) { Rect PAGLayer::getBounds() { LockGuard autoLock(rootLocker); Rect bounds = {}; - measureBounds(&bounds); + measureBounds(ToTGFX(&bounds)); return bounds; } @@ -372,7 +372,7 @@ Point PAGLayer::globalToLocalPoint(float stageX, float stageY) { pagLayer = pagLayer->_parent; } Point localPoint = {stageX, stageY}; - MapPointInverted(totalMatrix, &localPoint); + MapPointInverted(ToTGFX(totalMatrix), ToTGFX(&localPoint)); return localPoint; } @@ -441,7 +441,7 @@ void PAGLayer::draw(Recorder* recorder) { getContent()->draw(recorder); } -void PAGLayer::measureBounds(Rect* bounds) { +void PAGLayer::measureBounds(tgfx::Rect* bounds) { getContent()->measureBounds(bounds); } @@ -547,7 +547,7 @@ bool PAGLayer::getTransform(Transform* transform) { return false; } *transform = *layerTransform; - transform->matrix.postConcat(layerMatrix); + transform->matrix.postConcat(ToTGFX(layerMatrix)); transform->alpha *= layerAlpha; return true; } diff --git a/src/rendering/layers/PAGSolidLayer.cpp b/src/rendering/layers/PAGSolidLayer.cpp index a7b5de4f4c..94ab770df8 100644 --- a/src/rendering/layers/PAGSolidLayer.cpp +++ b/src/rendering/layers/PAGSolidLayer.cpp @@ -17,12 +17,12 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include +#include "base/utils/TGFXCast.h" #include "pag/pag.h" #include "rendering/caches/LayerCache.h" #include "rendering/graphics/Shape.h" #include "rendering/layers/PAGStage.h" #include "rendering/utils/LockGuard.h" -#include "rendering/utils/TGFXTypes.h" namespace pag { std::shared_ptr PAGSolidLayer::Make(int64_t duration, int32_t width, int32_t height, @@ -83,9 +83,9 @@ void PAGSolidLayer::setSolidColor(const pag::Color& value) { } auto solidLayer = static_cast(layer); if (solidLayer->solidColor != _solidColor) { - Path path = {}; + tgfx::Path path = {}; path.addRect(0, 0, solidLayer->width, solidLayer->height); - auto solid = Shape::MakeFrom(path, ToTGFXColor(_solidColor)); + auto solid = Shape::MakeFrom(path, ToTGFX(_solidColor)); replacement = new GraphicContent(solid); } notifyModified(true); diff --git a/src/rendering/layers/PAGStage.cpp b/src/rendering/layers/PAGStage.cpp index 108372019c..ac2b81869d 100644 --- a/src/rendering/layers/PAGStage.cpp +++ b/src/rendering/layers/PAGStage.cpp @@ -328,8 +328,8 @@ float PAGStage::calcMaxScaleFactor(ID referenceID) { return maxScaleFactor; } -Point PAGStage::GetLayerContentScaleFactor(PAGLayer* pagLayer, bool isPAGImage) { - Point scale = {1, 1}; +tgfx::Point PAGStage::GetLayerContentScaleFactor(PAGLayer* pagLayer, bool isPAGImage) { + tgfx::Point scale = {1, 1}; if (pagLayer->layerType() == LayerType::Image) { if (isPAGImage) { scale = static_cast(pagLayer)->replacement->getScaleFactor(); @@ -350,13 +350,13 @@ Point PAGStage::GetLayerContentScaleFactor(PAGLayer* pagLayer, bool isPAGImage) return scale; } -float PAGStage::getLayerScaleFactor(PAGLayer* pagLayer, Point scale) { +float PAGStage::getLayerScaleFactor(PAGLayer* pagLayer, tgfx::Point scale) { auto parent = pagLayer; while (parent) { auto layerScaleFactor = parent->layerCache->getMaxScaleFactor(); scale.x *= fabs(layerScaleFactor.x); scale.y *= fabs(layerScaleFactor.y); - auto matrixScaleFactor = GetScaleFactor(parent->layerMatrix); + auto matrixScaleFactor = GetScaleFactor(ToTGFX(parent->layerMatrix)); scale.x *= fabs(matrixScaleFactor.x); scale.y *= fabs(matrixScaleFactor.y); if (parent->_parent) { diff --git a/src/rendering/layers/PAGStage.h b/src/rendering/layers/PAGStage.h index 36c0a4c48e..de6c20060c 100644 --- a/src/rendering/layers/PAGStage.h +++ b/src/rendering/layers/PAGStage.h @@ -114,14 +114,14 @@ class PAGStage : public PAGComposition { std::unordered_set invalidAssets = {}; std::unordered_map pagImageMap = {}; - static Point GetLayerContentScaleFactor(PAGLayer* pagLayer, bool isPAGImage); + static tgfx::Point GetLayerContentScaleFactor(PAGLayer* pagLayer, bool isPAGImage); PAGStage(int width, int height); std::shared_ptr getSequenceFile(Sequence* sequence); void addToReferenceMap(ID uniqueID, PAGLayer* pagLayer); bool removeFromReferenceMap(ID uniqueID, PAGLayer* pagLayer); float getMaxScaleFactor(ID referenceID); float calcMaxScaleFactor(ID referenceID); - float getLayerScaleFactor(PAGLayer* pagLayer, Point scale); + float getLayerScaleFactor(PAGLayer* pagLayer, tgfx::Point scale); void updateLayerStartTime(PAGLayer* pagLayer); void updateChildLayerStartTime(PAGComposition* pagComposition); diff --git a/src/rendering/readers/BitmapSequenceReader.cpp b/src/rendering/readers/BitmapSequenceReader.cpp index dd41b51fbb..f3a8d2b6d9 100644 --- a/src/rendering/readers/BitmapSequenceReader.cpp +++ b/src/rendering/readers/BitmapSequenceReader.cpp @@ -26,9 +26,9 @@ BitmapSequenceReader::BitmapSequenceReader(std::shared_ptr file, BitmapSeq : SequenceReader(std::move(file), sequence) { // 若内容非静态,强制使用非 hardware 的 Bitmap,否则纹理内容跟 bitmap // 内存是共享的,无法进行解码预测。 - pixelBuffer = PixelBuffer::Make(sequence->width, sequence->height, false, staticContent); + pixelBuffer = tgfx::PixelBuffer::Make(sequence->width, sequence->height, false, staticContent); // 必须清零,否则首帧是空帧的情况会绘制错误。 - Bitmap(pixelBuffer).eraseAll(); + tgfx::Bitmap(pixelBuffer).eraseAll(); } void BitmapSequenceReader::decodeFrame(Frame targetFrame) { // decodeBitmap 这里需要立即加锁,防止异步解码时线程冲突。 @@ -38,14 +38,14 @@ void BitmapSequenceReader::decodeFrame(Frame targetFrame) { } auto startFrame = findStartFrame(targetFrame); auto& bitmapFrames = static_cast(sequence)->frames; - Bitmap bitmap(pixelBuffer); + tgfx::Bitmap bitmap(pixelBuffer); for (Frame frame = startFrame; frame <= targetFrame; frame++) { auto bitmapFrame = bitmapFrames[frame]; auto firstRead = true; for (auto bitmapRect : bitmapFrame->bitmaps) { - auto imageBytes = - Data::MakeWithoutCopy(bitmapRect->fileBytes->data(), bitmapRect->fileBytes->length()); - auto image = Image::MakeFrom(imageBytes); + auto imageBytes = tgfx::Data::MakeWithoutCopy(bitmapRect->fileBytes->data(), + bitmapRect->fileBytes->length()); + auto image = tgfx::Image::MakeFrom(imageBytes); if (image != nullptr) { // 关键帧不是全屏的时候要清屏 if (firstRead && bitmapFrame->isKeyframe && @@ -84,7 +84,8 @@ void BitmapSequenceReader::prepareAsync(Frame targetFrame) { } } -std::shared_ptr BitmapSequenceReader::readTexture(Frame targetFrame, RenderCache* cache) { +std::shared_ptr BitmapSequenceReader::readTexture(Frame targetFrame, + RenderCache* cache) { if (lastTextureFrame == targetFrame || pixelBuffer == nullptr) { return lastTexture; } diff --git a/src/rendering/readers/BitmapSequenceReader.h b/src/rendering/readers/BitmapSequenceReader.h index 35bd61a58f..be2d0a2438 100644 --- a/src/rendering/readers/BitmapSequenceReader.h +++ b/src/rendering/readers/BitmapSequenceReader.h @@ -32,15 +32,15 @@ class BitmapSequenceReader : public SequenceReader { void prepareAsync(Frame targetFrame) override; - std::shared_ptr readTexture(Frame frame, RenderCache* cache) override; + std::shared_ptr readTexture(Frame frame, RenderCache* cache) override; private: std::mutex locker = {}; Frame lastDecodeFrame = -1; Frame lastTextureFrame = -1; Frame pendingFrame = -1; - std::shared_ptr pixelBuffer = nullptr; - std::shared_ptr lastTexture = nullptr; + std::shared_ptr pixelBuffer = nullptr; + std::shared_ptr lastTexture = nullptr; std::shared_ptr lastTask = nullptr; Frame findStartFrame(Frame targetFrame); diff --git a/src/rendering/readers/SequenceReader.h b/src/rendering/readers/SequenceReader.h index 84ce57396a..1acd89db1f 100644 --- a/src/rendering/readers/SequenceReader.h +++ b/src/rendering/readers/SequenceReader.h @@ -41,7 +41,7 @@ class SequenceReader { virtual void prepareAsync(Frame targetFrame) = 0; - virtual std::shared_ptr readTexture(Frame targetFrame, RenderCache* cache) = 0; + virtual std::shared_ptr readTexture(Frame targetFrame, RenderCache* cache) = 0; protected: // 持有 File 引用,防止在异步解码时 Sequence 被析构。 diff --git a/src/rendering/renderers/CompositionRenderer.cpp b/src/rendering/renderers/CompositionRenderer.cpp index a712e90530..da4b0447a0 100644 --- a/src/rendering/renderers/CompositionRenderer.cpp +++ b/src/rendering/renderers/CompositionRenderer.cpp @@ -43,7 +43,7 @@ class SequenceProxy : public TextureProxy { : DecodingPolicy::Hardware); } - std::shared_ptr getTexture(RenderCache* cache) const override { + std::shared_ptr getTexture(RenderCache* cache) const override { auto reader = static_cast(cache)->getSequenceReader(sequence); if (reader) { return reader->readTexture(frame, static_cast(cache)); @@ -69,8 +69,8 @@ static std::shared_ptr MakeVideoSequenceGraphic(VideoSequence* sequence videoHeight++; } auto proxy = new SequenceProxy(sequence, contentFrame, videoWidth, videoHeight); - RGBAAALayout layout = {sequence->width, sequence->height, sequence->alphaStartX, - sequence->alphaStartY}; + tgfx::RGBAAALayout layout = {sequence->width, sequence->height, sequence->alphaStartX, + sequence->alphaStartY}; return Picture::MakeFrom(sequence->composition->uniqueID, std::unique_ptr(proxy), layout); } @@ -120,6 +120,6 @@ std::shared_ptr RenderSequenceComposition(Composition* composition, } auto scaleX = static_cast(composition->width) / static_cast(sequence->width); auto scaleY = static_cast(composition->height) / static_cast(sequence->height); - return Graphic::MakeCompose(graphic, Matrix::MakeScale(scaleX, scaleY)); + return Graphic::MakeCompose(graphic, tgfx::Matrix::MakeScale(scaleX, scaleY)); } } // namespace pag \ No newline at end of file diff --git a/src/rendering/renderers/FilterRenderer.cpp b/src/rendering/renderers/FilterRenderer.cpp index efc4cb7153..ef0df63f82 100644 --- a/src/rendering/renderers/FilterRenderer.cpp +++ b/src/rendering/renderers/FilterRenderer.cpp @@ -87,7 +87,7 @@ std::unique_ptr FilterRenderer::MakeFilterList(const FilterModifier* return filterList; } -Rect FilterRenderer::GetParentBounds(const FilterList* filterList) { +tgfx::Rect FilterRenderer::GetParentBounds(const FilterList* filterList) { auto layer = filterList->layer; float width, height; switch (layer->type()) { @@ -113,12 +113,12 @@ Rect FilterRenderer::GetParentBounds(const FilterList* filterList) { width = height = 0; break; } - return Rect::MakeXYWH(0, 0, width, height); + return tgfx::Rect::MakeXYWH(0, 0, width, height); } -Rect FilterRenderer::GetContentBounds(const FilterList* filterList, - std::shared_ptr content) { - Rect contentBounds = Rect::MakeEmpty(); +tgfx::Rect FilterRenderer::GetContentBounds(const FilterList* filterList, + std::shared_ptr content) { + tgfx::Rect contentBounds = tgfx::Rect::MakeEmpty(); if (filterList->processVisibleAreaOnly) { content->measureBounds(&contentBounds); contentBounds.roundOut(); @@ -128,10 +128,11 @@ Rect FilterRenderer::GetContentBounds(const FilterList* filterList, return contentBounds; } -void TransformFilterBounds(Rect* filterBounds, const FilterList* filterList) { +void TransformFilterBounds(tgfx::Rect* filterBounds, const FilterList* filterList) { // 滤镜应用顺序:Effects->motionBlur->LayerStyles for (auto& effect : filterList->effects) { - effect->transformBounds(filterBounds, filterList->effectScale, filterList->layerFrame); + effect->transformBounds(ToPAG(filterBounds), ToPAG(filterList->effectScale), + filterList->layerFrame); filterBounds->roundOut(); } @@ -145,7 +146,7 @@ void TransformFilterBounds(Rect* filterBounds, const FilterList* filterList) { } } -void FilterRenderer::MeasureFilterBounds(Rect* bounds, const FilterModifier* modifier) { +void FilterRenderer::MeasureFilterBounds(tgfx::Rect* bounds, const FilterModifier* modifier) { auto filterList = MakeFilterList(modifier); if (filterList->processVisibleAreaOnly) { bounds->roundOut(); @@ -154,28 +155,28 @@ void FilterRenderer::MeasureFilterBounds(Rect* bounds, const FilterModifier* mod } TransformFilterBounds(bounds, filterList.get()); if (filterList->useParentSizeInput) { - Matrix inverted = Matrix::I(); + tgfx::Matrix inverted = tgfx::Matrix::I(); filterList->layerMatrix.invert(&inverted); inverted.mapRect(bounds); } } -Rect GetClipBounds(Canvas* canvas, const FilterList* filterList) { +tgfx::Rect GetClipBounds(tgfx::Canvas* canvas, const FilterList* filterList) { auto clip = canvas->getTotalClip(); auto matrix = canvas->getMatrix(); if (filterList->useParentSizeInput) { - Matrix inverted = Matrix::I(); + tgfx::Matrix inverted = tgfx::Matrix::I(); filterList->layerMatrix.invert(&inverted); matrix.preConcat(inverted); } - Matrix inverted = Matrix::I(); + tgfx::Matrix inverted = tgfx::Matrix::I(); matrix.invert(&inverted); clip.transform(inverted); return clip.getBounds(); } std::shared_ptr GetDisplacementMapGraphic(const FilterList* filterList, Layer* mapLayer, - Rect* mapBounds) { + tgfx::Rect* mapBounds) { // DisplacementMap只支持引用视频序列帧或者位图序列帧图层。 // TODO(domrjchen): DisplacementMap 支持所有图层 auto preComposeLayer = static_cast(mapLayer); @@ -188,9 +189,9 @@ std::shared_ptr GetDisplacementMapGraphic(const FilterList* filterList, return static_cast(content)->graphic; } -static bool MakeLayerStyleNode(std::vector& filterNodes, Rect& clipBounds, +static bool MakeLayerStyleNode(std::vector& filterNodes, tgfx::Rect& clipBounds, const FilterList* filterList, RenderCache* renderCache, - Rect& filterBounds) { + tgfx::Rect& filterBounds) { if (!filterList->layerStyles.empty()) { auto filter = renderCache->getLayerStylesFilter(filterList->layer); if (nullptr == filter) { @@ -209,9 +210,9 @@ static bool MakeLayerStyleNode(std::vector& filterNodes, Rect& clipB return true; } -static bool MakeMotionBlurNode(std::vector& filterNodes, Rect& clipBounds, +static bool MakeMotionBlurNode(std::vector& filterNodes, tgfx::Rect& clipBounds, const FilterList* filterList, RenderCache* renderCache, - Rect& filterBounds, Point& effectScale) { + tgfx::Rect& filterBounds, tgfx::Point& effectScale) { if (filterList->layer->motionBlur) { auto filter = renderCache->getMotionBlurFilter(); if (filter && filter->updateLayer(filterList->layer, filterList->layerFrame)) { @@ -229,21 +230,22 @@ static bool MakeMotionBlurNode(std::vector& filterNodes, Rect& clipB return true; } -bool FilterRenderer::MakeEffectNode(std::vector& filterNodes, Rect& clipBounds, +bool FilterRenderer::MakeEffectNode(std::vector& filterNodes, tgfx::Rect& clipBounds, const FilterList* filterList, RenderCache* renderCache, - Rect& filterBounds, Point& effectScale, int clipIndex) { + tgfx::Rect& filterBounds, tgfx::Point& effectScale, + int clipIndex) { auto effectIndex = 0; for (auto& effect : filterList->effects) { auto filter = renderCache->getFilterCache(effect); if (filter) { auto oldBounds = filterBounds; - effect->transformBounds(&filterBounds, effectScale, filterList->layerFrame); + effect->transformBounds(ToPAG(&filterBounds), ToPAG(effectScale), filterList->layerFrame); filterBounds.roundOut(); filter->update(filterList->layerFrame, oldBounds, filterBounds, effectScale); if (effect->type() == EffectType::DisplacementMap) { auto mapEffect = static_cast(effect); auto mapFilter = static_cast(filter); - auto mapBounds = Rect::MakeEmpty(); + auto mapBounds = tgfx::Rect::MakeEmpty(); auto graphic = GetDisplacementMapGraphic(filterList, mapEffect->displacementMapLayer, &mapBounds); mapBounds.roundOut(); @@ -261,7 +263,8 @@ bool FilterRenderer::MakeEffectNode(std::vector& filterNodes, Rect& std::vector FilterRenderer::MakeFilterNodes(const FilterList* filterList, RenderCache* renderCache, - Rect* contentBounds, const Rect& clipRect) { + tgfx::Rect* contentBounds, + const tgfx::Rect& clipRect) { // 滤镜应用顺序:Effects->PAGFilter->motionBlur->LayerStyles std::vector filterNodes = {}; int clipIndex = -1; @@ -302,10 +305,11 @@ std::vector FilterRenderer::MakeFilterNodes(const FilterList* filter return filterNodes; } -void ApplyFilters(Context* context, std::vector filterNodes, const Rect& contentBounds, - FilterSource* filterSource, FilterTarget* filterTarget) { - GLStateGuard stateGuard(context); - auto gl = GLContext::Unwrap(context); +void ApplyFilters(tgfx::Context* context, std::vector filterNodes, + const tgfx::Rect& contentBounds, FilterSource* filterSource, + FilterTarget* filterTarget) { + tgfx::GLStateGuard stateGuard(context); + auto gl = tgfx::GLContext::Unwrap(context); auto scale = filterSource->scale; std::shared_ptr freeBuffer = nullptr; std::shared_ptr lastBuffer = nullptr; @@ -333,8 +337,8 @@ void ApplyFilters(Context* context, std::vector filterNodes, const R return; } currentBuffer->clearColor(gl); - auto offsetMatrix = Matrix::MakeTrans((lastBounds.left - node.bounds.left) * scale.x, - (lastBounds.top - node.bounds.top) * scale.y); + auto offsetMatrix = tgfx::Matrix::MakeTrans((lastBounds.left - node.bounds.left) * scale.x, + (lastBounds.top - node.bounds.top) * scale.y); auto currentTarget = currentBuffer->toFilterTarget(offsetMatrix); node.filter->draw(context, source, currentTarget.get()); currentBuffer->resolve(context); @@ -346,19 +350,19 @@ void ApplyFilters(Context* context, std::vector filterNodes, const R } } -static bool HasComplexPaint(Canvas* parentCanvas, const Rect& drawingBounds) { +static bool HasComplexPaint(tgfx::Canvas* parentCanvas, const tgfx::Rect& drawingBounds) { if (parentCanvas->getAlpha() != 1.0f) { return true; } - if (parentCanvas->getBlendMode() != Blend::SrcOver) { + if (parentCanvas->getBlendMode() != tgfx::BlendMode::SrcOver) { return true; } auto bounds = drawingBounds; auto matrix = parentCanvas->getMatrix(); matrix.mapRect(&bounds); auto surface = parentCanvas->getSurface(); - auto surfaceBounds = - Rect::MakeWH(static_cast(surface->width()), static_cast(surface->height())); + auto surfaceBounds = tgfx::Rect::MakeWH(static_cast(surface->width()), + static_cast(surface->height())); bounds.intersect(surfaceBounds); auto clip = parentCanvas->getTotalClip(); if (!clip.contains(bounds)) { @@ -367,11 +371,11 @@ static bool HasComplexPaint(Canvas* parentCanvas, const Rect& drawingBounds) { return false; } -std::unique_ptr GetDirectFilterTarget(Canvas* parentCanvas, +std::unique_ptr GetDirectFilterTarget(tgfx::Canvas* parentCanvas, const FilterList* filterList, const std::vector& filterNodes, - const Rect& contentBounds, - const Point& sourceScale) { + const tgfx::Rect& contentBounds, + const tgfx::Point& sourceScale) { // 在高分辨率下,模糊滤镜的开销会增大,需要降采样降低开销;当模糊为最后一个滤镜时,需要离屏绘制 if (!filterList->effects.empty() && filterList->effects.back()->type() == EffectType::FastBlur) { return nullptr; @@ -398,22 +402,23 @@ std::unique_ptr GetDirectFilterTarget(Canvas* parentCanvas, return ToFilterTarget(surface, totalMatrix); } -std::unique_ptr GetOffscreenFilterTarget(Surface* surface, +std::unique_ptr GetOffscreenFilterTarget(tgfx::Surface* surface, const std::vector& filterNodes, - const Rect& contentBounds, - const Point& sourceScale) { + const tgfx::Rect& contentBounds, + const tgfx::Point& sourceScale) { auto finalBounds = filterNodes.back().bounds; auto secondToLastBounds = filterNodes.size() > 1 ? filterNodes[filterNodes.size() - 2].bounds : contentBounds; - auto totalMatrix = Matrix::MakeTrans((secondToLastBounds.left - finalBounds.left) * sourceScale.x, - (secondToLastBounds.top - finalBounds.top) * sourceScale.y); + auto totalMatrix = + tgfx::Matrix::MakeTrans((secondToLastBounds.left - finalBounds.left) * sourceScale.x, + (secondToLastBounds.top - finalBounds.top) * sourceScale.y); return ToFilterTarget(surface, totalMatrix); } -std::unique_ptr ToFilterSource(Canvas* canvas) { +std::unique_ptr ToFilterSource(tgfx::Canvas* canvas) { auto surface = canvas->getSurface(); auto texture = surface->getTexture(); - Point scale = {}; + tgfx::Point scale = {}; scale.x = scale.y = GetMaxScaleFactor(canvas->getMatrix()); return ToFilterSource(texture.get(), scale); } @@ -434,7 +439,7 @@ void FilterRenderer::ProcessFastBlur(FilterList* filterList) { } } -void FilterRenderer::DrawWithFilter(Canvas* parentCanvas, RenderCache* cache, +void FilterRenderer::DrawWithFilter(tgfx::Canvas* parentCanvas, RenderCache* cache, const FilterModifier* modifier, std::shared_ptr content) { auto filterList = MakeFilterList(modifier); @@ -447,7 +452,7 @@ void FilterRenderer::DrawWithFilter(Canvas* parentCanvas, RenderCache* cache, return; } if (filterList->useParentSizeInput) { - Matrix inverted = Matrix::I(); + tgfx::Matrix inverted = tgfx::Matrix::I(); filterList->layerMatrix.invert(&inverted); parentCanvas->concat(inverted); } @@ -463,7 +468,7 @@ void FilterRenderer::DrawWithFilter(Canvas* parentCanvas, RenderCache* cache, } content->draw(contentCanvas, cache); auto filterSource = ToFilterSource(contentCanvas); - std::shared_ptr targetSurface = nullptr; + std::shared_ptr targetSurface = nullptr; std::unique_ptr filterTarget = GetDirectFilterTarget( parentCanvas, filterList.get(), filterNodes, contentBounds, filterSource->scale); if (filterTarget == nullptr) { @@ -484,7 +489,7 @@ void FilterRenderer::DrawWithFilter(Canvas* parentCanvas, RenderCache* cache, ApplyFilters(context, filterNodes, contentBounds, filterSource.get(), filterTarget.get()); if (targetSurface) { - Matrix drawingMatrix = {}; + tgfx::Matrix drawingMatrix = {}; auto targetCanvas = targetSurface->getCanvas(); if (!targetCanvas->getMatrix().invert(&drawingMatrix)) { drawingMatrix.setIdentity(); diff --git a/src/rendering/renderers/FilterRenderer.h b/src/rendering/renderers/FilterRenderer.h index ad3f12a396..8828b4a3e5 100644 --- a/src/rendering/renderers/FilterRenderer.h +++ b/src/rendering/renderers/FilterRenderer.h @@ -18,7 +18,6 @@ #pragma once -#include "gpu/opengl/GLCanvas.h" #include "pag/pag.h" #include "rendering/filters/FilterModifier.h" #include "rendering/filters/LayerStylesFilter.h" @@ -26,48 +25,50 @@ namespace pag { struct FilterNode { - FilterNode(Filter* filter, const Rect& bounds) : filter(filter), bounds(bounds) { + FilterNode(Filter* filter, const tgfx::Rect& bounds) : filter(filter), bounds(bounds) { } Filter* filter; - Rect bounds; + tgfx::Rect bounds; }; struct FilterList { Layer* layer = nullptr; Frame layerFrame = 0; - Matrix layerMatrix = Matrix::I(); + tgfx::Matrix layerMatrix = tgfx::Matrix::I(); float scaleFactorLimit = FLT_MAX; bool processVisibleAreaOnly = true; // 是否使用父级Composition容器的尺寸作为滤镜输入源。 bool useParentSizeInput = false; - Point effectScale = {1.0f, 1.0f}; - Point layerStyleScale = {1.0f, 1.0f}; + tgfx::Point effectScale = {1.0f, 1.0f}; + tgfx::Point layerStyleScale = {1.0f, 1.0f}; std::vector effects = {}; std::vector layerStyles = {}; }; class FilterRenderer { public: - static void MeasureFilterBounds(Rect* bounds, const FilterModifier* modifier); + static void MeasureFilterBounds(tgfx::Rect* bounds, const FilterModifier* modifier); - static void DrawWithFilter(Canvas* parentCanvas, RenderCache* cache, + static void DrawWithFilter(tgfx::Canvas* parentCanvas, RenderCache* cache, const FilterModifier* modifier, std::shared_ptr content); static void ProcessFastBlur(FilterList* filterList); private: static std::unique_ptr MakeFilterList(const FilterModifier* modifier); - static Rect GetParentBounds(const FilterList* filterList); + static tgfx::Rect GetParentBounds(const FilterList* filterList); - static Rect GetContentBounds(const FilterList* filterList, std::shared_ptr content); + static tgfx::Rect GetContentBounds(const FilterList* filterList, + std::shared_ptr content); - static bool MakeEffectNode(std::vector& filterNodes, Rect& clipBounds, + static bool MakeEffectNode(std::vector& filterNodes, tgfx::Rect& clipBounds, const FilterList* filterList, RenderCache* renderCache, - Rect& filterBounds, Point& effectScale, int clipIndex); + tgfx::Rect& filterBounds, tgfx::Point& effectScale, int clipIndex); static std::vector MakeFilterNodes(const FilterList* filterList, - RenderCache* renderCache, Rect* contentBounds, - const Rect& clipRect); + RenderCache* renderCache, + tgfx::Rect* contentBounds, + const tgfx::Rect& clipRect); }; } // namespace pag \ No newline at end of file diff --git a/src/rendering/renderers/LayerRenderer.cpp b/src/rendering/renderers/LayerRenderer.cpp index ed2abc1b1b..2f3359c91a 100644 --- a/src/rendering/renderers/LayerRenderer.cpp +++ b/src/rendering/renderers/LayerRenderer.cpp @@ -18,9 +18,9 @@ #include "LayerRenderer.h" #include "base/utils/MatrixUtil.h" +#include "base/utils/TGFXCast.h" #include "rendering/caches/LayerCache.h" #include "rendering/editing/StillImage.h" -#include "rendering/utils/TGFXTypes.h" namespace pag { @@ -80,7 +80,7 @@ void LayerRenderer::DrawLayer(Recorder* recorder, Layer* layer, Frame layerFrame recorder->restore(); } -static void ApplyClipToBounds(const Path& clipPath, Rect* bounds) { +static void ApplyClipToBounds(const tgfx::Path& clipPath, tgfx::Rect* bounds) { if (!clipPath.isInverseFillType()) { auto clipBounds = clipPath.getBounds(); if (!bounds->intersect(clipBounds)) { @@ -88,19 +88,19 @@ static void ApplyClipToBounds(const Path& clipPath, Rect* bounds) { } return; } - Path boundsPath = {}; + tgfx::Path boundsPath = {}; boundsPath.addRect(*bounds); - boundsPath.addPath(clipPath, PathOp::Intersect); + boundsPath.addPath(clipPath, tgfx::PathOp::Intersect); *bounds = boundsPath.getBounds(); } -static bool boundsIsEmpty(Rect* bounds) { +static bool boundsIsEmpty(tgfx::Rect* bounds) { return bounds && bounds->isEmpty(); } -void LayerRenderer::MeasureLayerBounds(Rect* bounds, Layer* layer, Frame layerFrame, +void LayerRenderer::MeasureLayerBounds(tgfx::Rect* bounds, Layer* layer, Frame layerFrame, std::shared_ptr filterModifier, - Rect* trackMatteBounds, Content* layerContent, + tgfx::Rect* trackMatteBounds, Content* layerContent, Transform* extraTransform) { bounds->setEmpty(); if (TransformIllegal(extraTransform) || boundsIsEmpty(trackMatteBounds)) { diff --git a/src/rendering/renderers/LayerRenderer.h b/src/rendering/renderers/LayerRenderer.h index f4cb9380a9..df487ad7e4 100644 --- a/src/rendering/renderers/LayerRenderer.h +++ b/src/rendering/renderers/LayerRenderer.h @@ -29,9 +29,9 @@ class LayerRenderer { TrackMatte* trackMatte = nullptr, Content* layerContent = nullptr, Transform* extraTransform = nullptr); - static void MeasureLayerBounds(Rect* bounds, Layer* layer, Frame layerFrame, + static void MeasureLayerBounds(tgfx::Rect* bounds, Layer* layer, Frame layerFrame, std::shared_ptr filterModifier = nullptr, - Rect* trackMatteBounds = nullptr, Content* content = nullptr, + tgfx::Rect* trackMatteBounds = nullptr, Content* content = nullptr, Transform* extraTransform = nullptr); }; diff --git a/src/rendering/renderers/MaskRenderer.cpp b/src/rendering/renderers/MaskRenderer.cpp index 5e1e69317c..986a0050dd 100644 --- a/src/rendering/renderers/MaskRenderer.cpp +++ b/src/rendering/renderers/MaskRenderer.cpp @@ -22,38 +22,38 @@ #include "rendering/utils/PathUtil.h" namespace pag { -PathOp ToPathOp(Enum maskMode) { +tgfx::PathOp ToPathOp(Enum maskMode) { switch (maskMode) { case MaskMode::Subtract: - return PathOp::Difference; + return tgfx::PathOp::Difference; case MaskMode::Intersect: - return PathOp::Intersect; + return tgfx::PathOp::Intersect; case MaskMode::Difference: - return PathOp::XOR; + return tgfx::PathOp::XOR; case MaskMode::Darken: // without the opacity blending, haven't supported it - return PathOp::Intersect; + return tgfx::PathOp::Intersect; default: - return PathOp::Union; + return tgfx::PathOp::Union; } } -static void ExpandPath(Path* path, float expansion) { +static void ExpandPath(tgfx::Path* path, float expansion) { if (expansion == 0) { return; } auto strokePath = *path; - auto effect = PathEffect::MakeStroke(Stroke(fabsf(expansion) * 2)); + auto effect = tgfx::PathEffect::MakeStroke(tgfx::Stroke(fabsf(expansion) * 2)); if (effect) { effect->applyTo(&strokePath); } if (expansion < 0) { - path->addPath(strokePath, PathOp::Difference); + path->addPath(strokePath, tgfx::PathOp::Difference); } else { - path->addPath(strokePath, PathOp::Union); + path->addPath(strokePath, tgfx::PathOp::Union); } } -void RenderMasks(Path* maskContent, const std::vector& masks, Frame layerFrame) { +void RenderMasks(tgfx::Path* maskContent, const std::vector& masks, Frame layerFrame) { bool isFirst = true; for (auto& mask : masks) { auto path = mask->maskPath->getValueAt(layerFrame); diff --git a/src/rendering/renderers/MaskRenderer.h b/src/rendering/renderers/MaskRenderer.h index f1041bd8ae..df24b550fe 100644 --- a/src/rendering/renderers/MaskRenderer.h +++ b/src/rendering/renderers/MaskRenderer.h @@ -23,5 +23,5 @@ #include "pag/pag.h" namespace pag { -void RenderMasks(Path* maskContent, const std::vector& masks, Frame layerFrame); +void RenderMasks(tgfx::Path* maskContent, const std::vector& masks, Frame layerFrame); } diff --git a/src/rendering/renderers/ShapeRenderer.cpp b/src/rendering/renderers/ShapeRenderer.cpp index 0986446815..ee78fd56e4 100644 --- a/src/rendering/renderers/ShapeRenderer.cpp +++ b/src/rendering/renderers/ShapeRenderer.cpp @@ -21,13 +21,13 @@ #include #include "base/utils/EnumClassHash.h" #include "base/utils/Interpolate.h" -#include "base/utils/MathExtra.h" +#include "base/utils/MathUtil.h" +#include "base/utils/TGFXCast.h" #include "core/PathEffect.h" #include "core/PathMeasure.h" #include "rendering/graphics/Graphic.h" #include "rendering/graphics/Shape.h" #include "rendering/utils/PathUtil.h" -#include "rendering/utils/TGFXTypes.h" namespace pag { @@ -38,7 +38,7 @@ class ElementData { virtual ~ElementData() = default; virtual ElementDataType type() const = 0; virtual std::unique_ptr clone() = 0; - virtual void applyMatrix(const Matrix& matrix) = 0; + virtual void applyMatrix(const tgfx::Matrix& matrix) = 0; }; enum class PaintType { Fill, Stroke, GradientFill, GradientStroke }; @@ -47,8 +47,8 @@ enum class PaintType { Fill, Stroke, GradientFill, GradientStroke }; * Defines attributes for drawing strokes. */ struct StrokePaint { - Stroke getStroke() const { - return Stroke(strokeWidth, ToTGFXCap(lineCap), ToTGFXJoin(lineJoin), miterLimit); + tgfx::Stroke getStroke() const { + return tgfx::Stroke(strokeWidth, ToTGFXCap(lineCap), ToTGFXJoin(lineJoin), miterLimit); } float strokeWidth; @@ -80,7 +80,7 @@ class PaintElement : public ElementData { return std::unique_ptr(newPaint); } - void applyMatrix(const Matrix& matrix) override { + void applyMatrix(const tgfx::Matrix& matrix) override { if (paintType == PaintType::Fill || paintType == PaintType::GradientFill) { return; } @@ -88,11 +88,11 @@ class PaintElement : public ElementData { } PaintType paintType = PaintType::Fill; - Blend blendMode = Blend::SrcOver; + tgfx::BlendMode blendMode = tgfx::BlendMode::SrcOver; float alpha = 1.0f; Enum compositeOrder = CompositeOrder::BelowPreviousInSameGroup; - PathFillType pathFillType = PathFillType::Winding; - Color4f color = Color4f::White(); + tgfx::PathFillType pathFillType = tgfx::PathFillType::Winding; + tgfx::Color color = tgfx::Color::White(); GradientPaint gradient; StrokePaint stroke; }; @@ -109,11 +109,11 @@ class PathElement : public ElementData { return std::unique_ptr(newPath); } - void applyMatrix(const Matrix& matrix) override { + void applyMatrix(const tgfx::Matrix& matrix) override { path.transform(matrix); } - Path path; + tgfx::Path path; }; class GroupElement : public ElementData { @@ -139,14 +139,14 @@ class GroupElement : public ElementData { return std::unique_ptr(newGroup); } - void applyMatrix(const Matrix& matrix) override { + void applyMatrix(const tgfx::Matrix& matrix) override { for (auto& element : elements) { element->applyMatrix(matrix); } } - std::vector pathList() const { - std::vector list; + std::vector pathList() const { + std::vector list; for (auto& element : elements) { switch (element->type()) { case ElementDataType::Path: { @@ -172,12 +172,12 @@ class GroupElement : public ElementData { elements.clear(); } - Blend blendMode = Blend::SrcOver; + tgfx::BlendMode blendMode = tgfx::BlendMode::SrcOver; float alpha = 1.0f; std::vector elements; }; -void RectangleToPath(RectangleElement* rectangle, Path* path, Frame frame) { +void RectangleToPath(RectangleElement* rectangle, tgfx::Path* path, Frame frame) { auto size = rectangle->size->getValueAt(frame); auto position = rectangle->position->getValueAt(frame); auto radius = rectangle->roundness->getValueAt(frame); @@ -190,20 +190,21 @@ void RectangleToPath(RectangleElement* rectangle, Path* path, Frame frame) { radius = hh; } auto rect = - Rect::MakeXYWH(position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y); + tgfx::Rect::MakeXYWH(position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y); path->addRoundRect(rect, radius, radius, rectangle->reversed, 2); } -void EllipseToPath(EllipseElement* ellipse, Path* path, Frame frame) { +void EllipseToPath(EllipseElement* ellipse, tgfx::Path* path, Frame frame) { auto size = ellipse->size->getValueAt(frame); auto position = ellipse->position->getValueAt(frame); auto rect = - Rect::MakeXYWH(position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y); + tgfx::Rect::MakeXYWH(position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y); path->addOval(rect, ellipse->reversed); } -static void AddCurveToPath(Path* path, float centerX, float centerY, float angleDelta, float dx1, - float dy1, float roundness1, float dx2, float dy2, float roundness2) { +static void AddCurveToPath(tgfx::Path* path, float centerX, float centerY, float angleDelta, + float dx1, float dy1, float roundness1, float dx2, float dy2, + float roundness2) { auto control1X = dx1 - dy1 * roundness1 * angleDelta + centerX; auto control1Y = dy1 + dx1 * roundness1 * angleDelta + centerY; auto control2X = dx2 + dy2 * roundness2 * angleDelta + centerX; @@ -211,7 +212,7 @@ static void AddCurveToPath(Path* path, float centerX, float centerY, float angle path->cubicTo(control1X, control1Y, control2X, control2Y, dx2 + centerX, dy2 + centerY); } -static void ConvertPolyStartToPath(Path* path, float centerX, float centerY, float points, +static void ConvertPolyStartToPath(tgfx::Path* path, float centerX, float centerY, float points, float rotation, float innerRadius, float outerRadius, float innerRoundness, float outerRoundness, bool reversed) { float direction = reversed ? -1 : 1; @@ -262,7 +263,7 @@ static void ConvertPolyStartToPath(Path* path, float centerX, float centerY, flo path->close(); } -static void ConvertPolygonToPath(Path* path, float centerX, float centerY, float points, +static void ConvertPolygonToPath(tgfx::Path* path, float centerX, float centerY, float points, float rotation, float radius, float roundness, bool reversed) { auto numPoints = static_cast(floorf(points)); float direction = reversed ? -1 : 1; @@ -293,7 +294,7 @@ static void ConvertPolygonToPath(Path* path, float centerX, float centerY, float path->close(); } -void PolyStarToPath(PolyStarElement* polyStar, Path* path, Frame frame) { +void PolyStarToPath(PolyStarElement* polyStar, tgfx::Path* path, Frame frame) { auto points = polyStar->points->getValueAt(frame); auto position = polyStar->position->getValueAt(frame); auto rotation = polyStar->rotation->getValueAt(frame); @@ -310,7 +311,7 @@ void PolyStarToPath(PolyStarElement* polyStar, Path* path, Frame frame) { } } -void ShapePathToPath(ShapePathElement* shapePath, Path* path, Frame frame) { +void ShapePathToPath(ShapePathElement* shapePath, tgfx::Path* path, Frame frame) { auto pathData = shapePath->shapePath->getValueAt(frame); if (pathData == nullptr) { return; @@ -318,8 +319,8 @@ void ShapePathToPath(ShapePathElement* shapePath, Path* path, Frame frame) { path->addPath(ToPath(*pathData)); } -PathFillType ToPathFillType(Enum rule) { - return rule == FillRule::EvenOdd ? PathFillType::EvenOdd : PathFillType::Winding; +tgfx::PathFillType ToPathFillType(Enum rule) { + return rule == FillRule::EvenOdd ? tgfx::PathFillType::EvenOdd : tgfx::PathFillType::Winding; } PaintElement* FillToPaint(FillElement* fill, Frame frame) { @@ -329,7 +330,7 @@ PaintElement* FillToPaint(FillElement* fill, Frame frame) { auto paint = new PaintElement(PaintType::Fill); paint->blendMode = ToTGFXBlend(fill->blendMode); paint->alpha = ToAlpha(fill->opacity->getValueAt(frame)); - paint->color = ToTGFXColor(fill->color->getValueAt(frame)); + paint->color = ToTGFX(fill->color->getValueAt(frame)); paint->pathFillType = ToPathFillType(fill->fillRule); paint->compositeOrder = fill->composite; return paint; @@ -343,7 +344,7 @@ PaintElement* StrokeToPaint(StrokeElement* stroke, Frame frame) { paint->blendMode = ToTGFXBlend(stroke->blendMode); paint->alpha = ToAlpha(stroke->opacity->getValueAt(frame)); paint->compositeOrder = stroke->composite; - paint->color = ToTGFXColor(stroke->color->getValueAt(frame)); + paint->color = ToTGFX(stroke->color->getValueAt(frame)); paint->stroke.strokeWidth = stroke->strokeWidth->getValueAt(frame); paint->stroke.lineCap = stroke->lineCap; paint->stroke.lineJoin = stroke->lineJoin; @@ -392,8 +393,10 @@ void ConvertAlphaStop(const GradientColorHandle& gradientColor, std::vectoropacity->getValueAt(frame) <= 0) { return nullptr; } @@ -478,7 +482,7 @@ PaintElement* GradientFillToPaint(GradientFillElement* fill, const Matrix& matri return paint; } -PaintElement* GradientStrokeToPaint(GradientStrokeElement* stroke, const Matrix& matrix, +PaintElement* GradientStrokeToPaint(GradientStrokeElement* stroke, const tgfx::Matrix& matrix, Frame frame) { if (stroke->opacity->getValueAt(frame) <= 0 || stroke->strokeWidth->getValueAt(frame) <= 0) { return nullptr; @@ -508,12 +512,12 @@ struct TrimSegment { float end; }; -void ApplyTrimPathIndividually(const std::vector& pathList, +void ApplyTrimPathIndividually(const std::vector& pathList, std::vector segments) { float totalLength = 0; - std::vector> measureList; + std::vector> measureList; for (auto& path : pathList) { - auto pathMeasure = PathMeasure::MakeFrom(*path); + auto pathMeasure = tgfx::PathMeasure::MakeFrom(*path); totalLength += pathMeasure->getLength(); measureList.push_back(std::move(pathMeasure)); } @@ -523,7 +527,7 @@ void ApplyTrimPathIndividually(const std::vector& pathList, } float addedLength = 0; int index = 0; - Path tempPath = {}; + tgfx::Path tempPath = {}; for (auto& pathMeasure : measureList) { auto& path = pathList[index++]; auto pathLength = pathMeasure->getLength(); @@ -548,7 +552,7 @@ void ApplyTrimPathIndividually(const std::vector& pathList, } } -void ApplyTrimPaths(TrimPathsElement* trimPaths, std::vector& pathList, float start, +void ApplyTrimPaths(TrimPathsElement* trimPaths, std::vector& pathList, float start, float end, bool reversed) { if (start == 0 && end == 1) { return; @@ -567,9 +571,9 @@ void ApplyTrimPaths(TrimPathsElement* trimPaths, std::vector& pathList, f segments.push_back({start, end}); } if (trimPaths->trimType == TrimPathsType::Simultaneously) { - Path tempPath = {}; + tgfx::Path tempPath = {}; for (auto& path : pathList) { - auto pathMeasure = PathMeasure::MakeFrom(*path); + auto pathMeasure = tgfx::PathMeasure::MakeFrom(*path); auto length = pathMeasure->getLength(); if (length == 0) { continue; @@ -591,7 +595,7 @@ void ApplyTrimPaths(TrimPathsElement* trimPaths, std::vector& pathList, f } } -void ApplyTrimPaths(TrimPathsElement* trimPaths, std::vector pathList, Frame frame) { +void ApplyTrimPaths(TrimPathsElement* trimPaths, std::vector pathList, Frame frame) { auto start = trimPaths->start->getValueAt(frame); auto end = trimPaths->end->getValueAt(frame); auto offset = fmodf(trimPaths->offset->getValueAt(frame), 360.0f) / 360.0f; @@ -626,22 +630,22 @@ void ApplyMergePaths(MergePathsElement* mergePaths, GroupElement* group) { if (pathList.empty()) { return; } - PathOp pathOp; + tgfx::PathOp pathOp; switch (mergePaths->mode) { case MergePathsMode::Merge: - pathOp = PathOp::Append; + pathOp = tgfx::PathOp::Append; break; case MergePathsMode::Intersect: - pathOp = PathOp::Intersect; + pathOp = tgfx::PathOp::Intersect; break; case MergePathsMode::Subtract: - pathOp = PathOp::Difference; + pathOp = tgfx::PathOp::Difference; break; case MergePathsMode::ExcludeIntersections: - pathOp = PathOp::XOR; + pathOp = tgfx::PathOp::XOR; break; default: - pathOp = PathOp::Union; + pathOp = tgfx::PathOp::Union; break; } auto tempPath = *(pathList[0]); @@ -688,7 +692,7 @@ void ApplyRepeater(RepeaterElement* repeater, GroupElement* group, Frame frame) newGroup->alpha *= copies - i; } } - auto matrix = Matrix::I(); + auto matrix = tgfx::Matrix::I(); matrix.postTranslate(-anchorPoint.x, -anchorPoint.y); matrix.postScale(powf(scale.x, progress), powf(scale.y, progress)); matrix.postRotate(rotation * progress); @@ -703,10 +707,10 @@ void ApplyRepeater(RepeaterElement* repeater, GroupElement* group, Frame frame) group->elements = elements; } -void ApplyRoundCorners(RoundCornersElement* roundCorners, std::vector pathList, +void ApplyRoundCorners(RoundCornersElement* roundCorners, std::vector pathList, Frame frame) { auto radius = roundCorners->radius->getValueAt(frame); - auto effect = PathEffect::MakeCorner(radius); + auto effect = tgfx::PathEffect::MakeCorner(radius); if (effect == nullptr) { return; } @@ -715,13 +719,13 @@ void ApplyRoundCorners(RoundCornersElement* roundCorners, std::vector pat } } -void SkewFromAxis(Matrix* matrix, float skew, float skewAxis) { +void SkewFromAxis(tgfx::Matrix* matrix, float skew, float skewAxis) { if (skew == 0 && skewAxis == 0) { return; } auto u = cosf(skewAxis); auto v = sinf(skewAxis); - Matrix temp = {}; + tgfx::Matrix temp = {}; temp.setAll(u, -v, 0, v, u, 0, 0, 0, 1); matrix->postConcat(temp); auto w = tanf(skew); @@ -732,7 +736,7 @@ void SkewFromAxis(Matrix* matrix, float skew, float skewAxis) { } Transform ShapeTransformToTransform(const ShapeTransform* transform, Frame frame) { - auto matrix = Matrix::I(); + auto matrix = tgfx::Matrix::I(); auto anchorPoint = transform->anchorPoint->getValueAt(frame); auto scale = transform->scale->getValueAt(frame); auto position = transform->position->getValueAt(frame); @@ -750,10 +754,10 @@ Transform ShapeTransformToTransform(const ShapeTransform* transform, Frame frame return {matrix, alpha}; } -void RenderElements(const std::vector& list, const Matrix& parentMatrix, +void RenderElements(const std::vector& list, const tgfx::Matrix& parentMatrix, GroupElement* parentGroup, Frame frame); -void RenderElements_ShapeGroup(ShapeElement* element, const Matrix& parentMatrix, +void RenderElements_ShapeGroup(ShapeElement* element, const tgfx::Matrix& parentMatrix, GroupElement* parentGroup, Frame frame) { auto shape = reinterpret_cast(element); auto transform = ShapeTransformToTransform(shape->transform, frame); @@ -765,7 +769,7 @@ void RenderElements_ShapeGroup(ShapeElement* element, const Matrix& parentMatrix parentGroup->elements.push_back(group); } -void RenderElements_Rectangle(ShapeElement* element, const Matrix& parentMatrix, +void RenderElements_Rectangle(ShapeElement* element, const tgfx::Matrix& parentMatrix, GroupElement* parentGroup, Frame frame) { auto pathElement = new PathElement(); RectangleToPath(static_cast(element), &pathElement->path, frame); @@ -773,7 +777,7 @@ void RenderElements_Rectangle(ShapeElement* element, const Matrix& parentMatrix, parentGroup->elements.push_back(pathElement); } -void RenderElements_Ellipse(ShapeElement* element, const Matrix& parentMatrix, +void RenderElements_Ellipse(ShapeElement* element, const tgfx::Matrix& parentMatrix, GroupElement* parentGroup, Frame frame) { auto pathElement = new PathElement(); EllipseToPath(static_cast(element), &pathElement->path, frame); @@ -781,7 +785,7 @@ void RenderElements_Ellipse(ShapeElement* element, const Matrix& parentMatrix, parentGroup->elements.push_back(pathElement); } -void RenderElements_PolyStar(ShapeElement* element, const Matrix& parentMatrix, +void RenderElements_PolyStar(ShapeElement* element, const tgfx::Matrix& parentMatrix, GroupElement* parentGroup, Frame frame) { auto pathElement = new PathElement(); PolyStarToPath(static_cast(element), &pathElement->path, frame); @@ -789,7 +793,7 @@ void RenderElements_PolyStar(ShapeElement* element, const Matrix& parentMatrix, parentGroup->elements.push_back(pathElement); } -void RenderElements_ShapePath(ShapeElement* element, const Matrix& parentMatrix, +void RenderElements_ShapePath(ShapeElement* element, const tgfx::Matrix& parentMatrix, GroupElement* parentGroup, Frame frame) { auto pathElement = new PathElement(); ShapePathToPath(static_cast(element), &pathElement->path, frame); @@ -797,7 +801,7 @@ void RenderElements_ShapePath(ShapeElement* element, const Matrix& parentMatrix, parentGroup->elements.push_back(pathElement); } -void RenderElements_Fill(ShapeElement* element, const Matrix&, GroupElement* parentGroup, +void RenderElements_Fill(ShapeElement* element, const tgfx::Matrix&, GroupElement* parentGroup, Frame frame) { auto fill = static_cast(element); auto paint = FillToPaint(fill, frame); @@ -806,7 +810,7 @@ void RenderElements_Fill(ShapeElement* element, const Matrix&, GroupElement* par } } -void RenderElements_Stroke(ShapeElement* element, const Matrix&, GroupElement* parentGroup, +void RenderElements_Stroke(ShapeElement* element, const tgfx::Matrix&, GroupElement* parentGroup, Frame frame) { auto stroke = static_cast(element); auto paint = StrokeToPaint(stroke, frame); @@ -815,7 +819,7 @@ void RenderElements_Stroke(ShapeElement* element, const Matrix&, GroupElement* p } } -void RenderElements_GradientFill(ShapeElement* element, const Matrix& parentMatrix, +void RenderElements_GradientFill(ShapeElement* element, const tgfx::Matrix& parentMatrix, GroupElement* parentGroup, Frame frame) { auto fill = static_cast(element); auto paint = GradientFillToPaint(fill, parentMatrix, frame); @@ -824,7 +828,7 @@ void RenderElements_GradientFill(ShapeElement* element, const Matrix& parentMatr } } -void RenderElements_GradientStroke(ShapeElement* element, const Matrix& parentMatrix, +void RenderElements_GradientStroke(ShapeElement* element, const tgfx::Matrix& parentMatrix, GroupElement* parentGroup, Frame frame) { auto stroke = static_cast(element); auto paint = GradientStrokeToPaint(stroke, parentMatrix, frame); @@ -833,27 +837,27 @@ void RenderElements_GradientStroke(ShapeElement* element, const Matrix& parentMa } } -void RenderElements_MergePaths(ShapeElement* element, const Matrix&, GroupElement* parentGroup, - Frame) { +void RenderElements_MergePaths(ShapeElement* element, const tgfx::Matrix&, + GroupElement* parentGroup, Frame) { ApplyMergePaths(static_cast(element), parentGroup); } -void RenderElements_Repeater(ShapeElement* element, const Matrix&, GroupElement* parentGroup, +void RenderElements_Repeater(ShapeElement* element, const tgfx::Matrix&, GroupElement* parentGroup, Frame frame) { ApplyRepeater(static_cast(element), parentGroup, frame); } -void RenderElements_TrimPaths(ShapeElement* element, const Matrix&, GroupElement* parentGroup, +void RenderElements_TrimPaths(ShapeElement* element, const tgfx::Matrix&, GroupElement* parentGroup, Frame frame) { ApplyTrimPaths(static_cast(element), parentGroup->pathList(), frame); } -void RenderElements_RoundCorners(ShapeElement* element, const Matrix&, GroupElement* parentGroup, - Frame frame) { +void RenderElements_RoundCorners(ShapeElement* element, const tgfx::Matrix&, + GroupElement* parentGroup, Frame frame) { ApplyRoundCorners(static_cast(element), parentGroup->pathList(), frame); } -using RenderElementsHandler = void(ShapeElement* element, const Matrix& parentMatrix, +using RenderElementsHandler = void(ShapeElement* element, const tgfx::Matrix& parentMatrix, GroupElement* parentGroup, Frame frame); static const std::unordered_map, EnumClassHash> @@ -871,7 +875,7 @@ static const std::unordered_map, {ShapeType::TrimPaths, RenderElements_TrimPaths}, {ShapeType::RoundCorners, RenderElements_RoundCorners}}; -void RenderElements(const std::vector& list, const Matrix& parentMatrix, +void RenderElements(const std::vector& list, const tgfx::Matrix& parentMatrix, GroupElement* parentGroup, Frame frame) { for (auto& element : list) { auto iter = elementHandlers.find(element->type()); @@ -881,7 +885,8 @@ void RenderElements(const std::vector& list, const Matrix& parent } } -std::unique_ptr CreateDashEffect(const std::vector& dashes, float dashOffset) { +std::unique_ptr CreateDashEffect(const std::vector& dashes, + float dashOffset) { auto dashCount = dashes.size(); auto size = static_cast(dashCount); int times = 1; @@ -896,31 +901,31 @@ std::unique_ptr CreateDashEffect(const std::vector& dashes, f dashList[index++] = static_cast(dashes[j]); } } - auto dashEffect = PathEffect::MakeDash(dashList, size, dashOffset); + auto dashEffect = tgfx::PathEffect::MakeDash(dashList, size, dashOffset); delete[] dashList; return dashEffect; } -void ApplyStrokeToPath(Path* path, const StrokePaint& stroke) { +void ApplyStrokeToPath(tgfx::Path* path, const StrokePaint& stroke) { if (!stroke.dashes.empty()) { auto dashEffect = CreateDashEffect(stroke.dashes, stroke.dashOffset); if (dashEffect) { dashEffect->applyTo(path); } } - auto strokeEffect = PathEffect::MakeStroke(stroke.getStroke()); + auto strokeEffect = tgfx::PathEffect::MakeStroke(stroke.getStroke()); if (strokeEffect) { strokeEffect->applyTo(path); } } -std::shared_ptr RenderShape(PaintElement* paint, Path* path) { - Path shapePath = *path; +std::shared_ptr RenderShape(PaintElement* paint, tgfx::Path* path) { + tgfx::Path shapePath = *path; auto paintType = paint->paintType; if (paintType == PaintType::Stroke || paintType == PaintType::GradientStroke) { ApplyStrokeToPath(&shapePath, paint->stroke); } - if (shapePath.getFillType() == PathFillType::Winding) { + if (shapePath.getFillType() == tgfx::PathFillType::Winding) { shapePath.setFillType(paint->pathFillType); } std::shared_ptr shape = nullptr; @@ -933,7 +938,7 @@ std::shared_ptr RenderShape(PaintElement* paint, Path* path) { return Graphic::MakeCompose(shape, modifier); } -std::shared_ptr RenderShape(GroupElement* group, Path* path) { +std::shared_ptr RenderShape(GroupElement* group, tgfx::Path* path) { std::vector> contents = {}; for (auto& element : group->elements) { switch (element->type()) { @@ -953,7 +958,7 @@ std::shared_ptr RenderShape(GroupElement* group, Path* path) { } } break; case ElementDataType::Group: { - Path tempPath = {}; + tgfx::Path tempPath = {}; auto shape = RenderShape(static_cast(element), &tempPath); path->addPath(tempPath); if (shape) { @@ -970,9 +975,9 @@ std::shared_ptr RenderShape(GroupElement* group, Path* path) { std::shared_ptr RenderShapes(const std::vector& contents, Frame layerFrame) { GroupElement rootGroup; - auto matrix = Matrix::I(); + auto matrix = tgfx::Matrix::I(); RenderElements(contents, matrix, &rootGroup, layerFrame); - Path tempPath = {}; + tgfx::Path tempPath = {}; return RenderShape(&rootGroup, &tempPath); } } // namespace pag diff --git a/src/rendering/renderers/ShapeRenderer.h b/src/rendering/renderers/ShapeRenderer.h index 58bd9c733d..6e5ad9bcd3 100644 --- a/src/rendering/renderers/ShapeRenderer.h +++ b/src/rendering/renderers/ShapeRenderer.h @@ -18,6 +18,7 @@ #pragma once +#include "pag/file.h" #include "rendering/graphics/Recorder.h" #include "rendering/utils/Transform.h" diff --git a/src/rendering/renderers/TextAnimatorRenderer.cpp b/src/rendering/renderers/TextAnimatorRenderer.cpp index d0abf8b7f3..784b6a23d7 100644 --- a/src/rendering/renderers/TextAnimatorRenderer.cpp +++ b/src/rendering/renderers/TextAnimatorRenderer.cpp @@ -17,7 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "TextAnimatorRenderer.h" -#include "rendering/utils/TGFXTypes.h" +#include "base/utils/TGFXCast.h" namespace pag { @@ -86,11 +86,10 @@ bool TextAnimatorRenderer::ApplyToGlyphs(std::vector>& } // 根据序号获取文本动画位置(供AE导出插件在计算firstBaseLine时调用) -Point TextAnimatorRenderer::GetPositionFromAnimators(const std::vector* animators, - const TextDocument* textDocument, - Frame layerFrame, size_t index, - bool* pBiasFlag) { - Point ret = {0.0f, 0.0f}; +tgfx::Point TextAnimatorRenderer::GetPositionFromAnimators( + const std::vector* animators, const TextDocument* textDocument, Frame layerFrame, + size_t index, bool* pBiasFlag) { + tgfx::Point ret = {0.0f, 0.0f}; *pBiasFlag = false; if (animators != nullptr) { for (auto animator : *animators) { @@ -118,10 +117,10 @@ TextAnimatorRenderer::TextAnimatorRenderer(const TextAnimator* animator, readTackingInfo(animator, frame); // 字间距 if (typographyProperties->position != nullptr) { - position = typographyProperties->position->getValueAt(frame); // 位置 + position = ToTGFX(typographyProperties->position->getValueAt(frame)); // 位置 } if (typographyProperties->scale != nullptr) { - scale = typographyProperties->scale->getValueAt(frame); // 缩放 + scale = ToTGFX(typographyProperties->scale->getValueAt(frame)); // 缩放 } if (typographyProperties->rotation != nullptr) { rotation = typographyProperties->rotation->getValueAt(frame); // 旋转 @@ -238,7 +237,7 @@ float TextAnimatorRenderer::calculateFactorByIndex(size_t index, bool* pBiasFlag } // 根据序号获取位置(供AE导出插件在计算firstBaseLine时调用) -Point TextAnimatorRenderer::getPositionByIndex(size_t index, bool* pBiasFlag) { +tgfx::Point TextAnimatorRenderer::getPositionByIndex(size_t index, bool* pBiasFlag) { auto biasFlag = false; auto factor = calculateFactorByIndex(index, &biasFlag); if (biasFlag && (position.x != 0.0f || position.y != 0.0f)) { diff --git a/src/rendering/renderers/TextAnimatorRenderer.h b/src/rendering/renderers/TextAnimatorRenderer.h index eba24db011..96148254a5 100644 --- a/src/rendering/renderers/TextAnimatorRenderer.h +++ b/src/rendering/renderers/TextAnimatorRenderer.h @@ -31,9 +31,9 @@ class TextAnimatorRenderer { const std::vector* animators, const TextDocument* textDocument, Frame layerFrame); // 根据序号获取文本动画位置(供AE导出插件在计算firstBaseLine时调用) - static Point GetPositionFromAnimators(const std::vector* animators, - const TextDocument* textDocument, Frame layerFrame, - size_t index, bool* pBiasFlag); + static tgfx::Point GetPositionFromAnimators(const std::vector* animators, + const TextDocument* textDocument, Frame layerFrame, + size_t index, bool* pBiasFlag); TextAnimatorRenderer(const TextAnimator* animator, const TextDocument* textDocument, size_t textCount, Frame frame); ~TextAnimatorRenderer(); @@ -48,15 +48,15 @@ class TextAnimatorRenderer { // 读取字间距信息 void readTackingInfo(const TextAnimator* animator, Frame frame); // 根据序号获取位置(供AE导出插件在计算firstBaseLine时调用) - Point getPositionByIndex(size_t index, bool* pBiasFlag); + tgfx::Point getPositionByIndex(size_t index, bool* pBiasFlag); // // 动画属性:位置、缩放、旋转、不透明度、字间距 // - Point position = Point::Zero(); // 位置 - Point scale = Point::Make(1, 1); // 缩放 - float rotation = 0.0f; // 旋转 - float alpha = 1.0f; // 不透明度,默认不透明 + tgfx::Point position = tgfx::Point::Zero(); // 位置 + tgfx::Point scale = tgfx::Point::Make(1, 1); // 缩放 + float rotation = 0.0f; // 旋转 + float alpha = 1.0f; // 不透明度,默认不透明 float trackingBefore = 0.0f; // 字间距-之前 float trackingAfter = 0.0f; // 字间距-之后 diff --git a/src/rendering/renderers/TextRenderer.cpp b/src/rendering/renderers/TextRenderer.cpp index 300d000553..0d00a22b06 100644 --- a/src/rendering/renderers/TextRenderer.cpp +++ b/src/rendering/renderers/TextRenderer.cpp @@ -18,10 +18,10 @@ #include "TextRenderer.h" #include "TextAnimatorRenderer.h" +#include "base/utils/TGFXCast.h" #include "core/PathEffect.h" #include "rendering/graphics/Shape.h" #include "rendering/graphics/Text.h" -#include "rendering/utils/TGFXTypes.h" namespace pag { @@ -32,8 +32,8 @@ struct GlyphInfo { int glyphIndex = 0; std::string name; float advance = 0; - Point position = Point::Zero(); - Rect bounds = Rect::MakeEmpty(); + tgfx::Point position = tgfx::Point::Zero(); + tgfx::Rect bounds = tgfx::Rect::MakeEmpty(); }; struct TextLayout { @@ -44,9 +44,9 @@ struct TextLayout { float firstBaseLine = 0; float baselineShift = 0; Enum justification = 0; - Rect boxRect = Rect::MakeEmpty(); + tgfx::Rect boxRect = tgfx::Rect::MakeEmpty(); float glyphScale = 1.0f; - Matrix coordinateMatrix = Matrix::I(); + tgfx::Matrix coordinateMatrix = tgfx::Matrix::I(); }; TextPaint CreateTextPaint(const TextDocument* textDocument) { @@ -82,7 +82,7 @@ std::vector CreateGlyphInfos(const std::vector& glyphLis info.bounds = glyph->getBounds(); // 当文本为竖版时,需要先转换为横排进行布局计算 if (glyph->isVertical()) { - Matrix matrix = Matrix::I(); + tgfx::Matrix matrix = tgfx::Matrix::I(); matrix.setRotate(-90); matrix.mapRect(&info.bounds); } @@ -96,7 +96,7 @@ TextLayout CreateTextLayout(const TextDocument* textDocument, TextLayout layout = {}; auto isVertical = textDocument->direction == TextDirection::Vertical; if (!textDocument->boxText) { - layout.boxRect = Rect::MakeEmpty(); + layout.boxRect = tgfx::Rect::MakeEmpty(); if (isVertical) { layout.coordinateMatrix.setRotate(90); } @@ -104,13 +104,13 @@ TextLayout CreateTextLayout(const TextDocument* textDocument, if (isVertical) { auto boxRight = textDocument->boxTextPos.x + textDocument->boxTextSize.x; layout.boxRect = - Rect::MakeXYWH(0, 0, textDocument->boxTextSize.y, textDocument->boxTextSize.x); + tgfx::Rect::MakeXYWH(0, 0, textDocument->boxTextSize.y, textDocument->boxTextSize.x); layout.firstBaseLine = boxRight - textDocument->firstBaseLine; layout.coordinateMatrix.setRotate(90); layout.coordinateMatrix.postTranslate(boxRight, textDocument->boxTextPos.y); } else { layout.boxRect = - Rect::MakeXYWH(0, 0, textDocument->boxTextSize.x, textDocument->boxTextSize.y); + tgfx::Rect::MakeXYWH(0, 0, textDocument->boxTextSize.x, textDocument->boxTextSize.y); layout.firstBaseLine = textDocument->firstBaseLine - textDocument->boxTextPos.y; layout.coordinateMatrix.setTranslate(textDocument->boxTextPos.x, textDocument->boxTextPos.y); } @@ -225,7 +225,7 @@ static void AdjustToFitBox(TextLayout* layout, std::vector* glyphInfo } static float CalculateDrawX(Enum justification, float lineWidth, bool isLastLine, - const Rect& boxRect) { + const tgfx::Rect& boxRect) { float drawX; if (boxRect.isEmpty()) { @@ -272,7 +272,8 @@ static float CalculateDrawX(Enum justification, float lineWidth, bool isLastLine } static float CalculateLetterSpacing(Enum justification, float tracking, float lineWidth, - size_t lineGlyphCount, bool isLastLine, const Rect& boxRect) { + size_t lineGlyphCount, bool isLastLine, + const tgfx::Rect& boxRect) { if (boxRect.isEmpty()) { return tracking; } @@ -301,7 +302,7 @@ static float CalculateLetterSpacing(Enum justification, float tracking, float li } static std::vector> ApplyLayoutToGlyphInfos( - const TextLayout& layout, std::vector* glyphInfos, Rect* bounds) { + const TextLayout& layout, std::vector* glyphInfos, tgfx::Rect* bounds) { float maxWidth, maxY; if (layout.boxRect.isEmpty()) { maxWidth = std::numeric_limits::infinity(); @@ -347,8 +348,8 @@ static std::vector> ApplyLayoutToGlyphInfos( if (!glyphLine.empty()) { lineList.push_back(glyphLine); } else { - auto emptyLineBounds = Rect::MakeLTRB(drawX, drawY + layout.fontTop, drawX + EMPTY_LINE_WIDTH, - drawY + layout.fontBottom); + auto emptyLineBounds = tgfx::Rect::MakeLTRB( + drawX, drawY + layout.fontTop, drawX + EMPTY_LINE_WIDTH, drawY + layout.fontBottom); bounds->join(emptyLineBounds); } baseLine += layout.lineGap; @@ -366,7 +367,7 @@ static std::vector> ApplyMatrixToGlyphs( std::vector glyphLine = {}; for (auto& info : line) { auto& glyph = (*glyphList)[info->glyphIndex]; - auto matrix = Matrix::MakeScale(layout.glyphScale); + auto matrix = tgfx::Matrix::MakeScale(layout.glyphScale); auto pos = info->position; layout.coordinateMatrix.mapPoints(&pos, 1); matrix.postTranslate(pos.x, pos.y); @@ -380,18 +381,19 @@ static std::vector> ApplyMatrixToGlyphs( return glyphLines; } -static Path RenderBackgroundPath(const std::vector>& glyphLines, - float margin, float lineTop, float lineBottom, bool isVertical) { - Path backgroundPath = {}; - std::vector lineRectList = {}; +static tgfx::Path RenderBackgroundPath(const std::vector>& glyphLines, + float margin, float lineTop, float lineBottom, + bool isVertical) { + tgfx::Path backgroundPath = {}; + std::vector lineRectList = {}; for (auto& line : glyphLines) { - Rect lineRect = Rect::MakeEmpty(); + tgfx::Rect lineRect = tgfx::Rect::MakeEmpty(); for (auto& glyph : line) { - Rect textBounds = {}; + tgfx::Rect textBounds = {}; if (isVertical) { - textBounds = Rect::MakeLTRB(-lineBottom, 0, -lineTop, glyph->getAdvance()); + textBounds = tgfx::Rect::MakeLTRB(-lineBottom, 0, -lineTop, glyph->getAdvance()); } else { - textBounds = Rect::MakeLTRB(0, lineTop, glyph->getAdvance(), lineBottom); + textBounds = tgfx::Rect::MakeLTRB(0, lineTop, glyph->getAdvance(), lineBottom); } glyph->getMatrix().mapRect(&textBounds); lineRect.join(textBounds); @@ -427,7 +429,7 @@ static Path RenderBackgroundPath(const std::vector>& gl lineRect.bottom += bottomInset; topInset = bottomInset; // 下一行的topInset是上一行的bottomInset. rightInset = leftInset; - Path tempPath = {}; + tgfx::Path tempPath = {}; // 必须round一下避开浮点计算误差,规避 Path 合并的 Bug,否则得到中间断开的不连续矩形。 lineRect.round(); tempPath.addRect(lineRect); @@ -463,12 +465,13 @@ std::shared_ptr RenderTextBackground(const std::vector= 25.0f) { maxRadius = 25.0f; } - auto effect = PathEffect::MakeCorner(maxRadius); + auto effect = tgfx::PathEffect::MakeCorner(maxRadius); if (effect) { effect->applyTo(&backgroundPath); } - auto graphic = Shape::MakeFrom(backgroundPath, ToTGFXColor(textDocument->backgroundColor)); - auto modifier = Modifier::MakeBlend(ToAlpha(textDocument->backgroundAlpha), Blend::SrcOver); + auto graphic = Shape::MakeFrom(backgroundPath, ToTGFX(textDocument->backgroundColor)); + auto modifier = + Modifier::MakeBlend(ToAlpha(textDocument->backgroundAlpha), tgfx::BlendMode::SrcOver); return Graphic::MakeCompose(graphic, modifier); } @@ -486,7 +489,7 @@ std::unique_ptr RenderTexts(Property* sourceTex if (textDocument->boxText) { AdjustToFitBox(&textLayout, &glyphInfos, textDocument->fontSize); } - Rect textBounds = Rect::MakeEmpty(); + tgfx::Rect textBounds = tgfx::Rect::MakeEmpty(); auto glyphInfoLines = ApplyLayoutToGlyphInfos(textLayout, &glyphInfos, &textBounds); auto glyphLines = ApplyMatrixToGlyphs(textLayout, glyphInfoLines, &glyphList); textLayout.coordinateMatrix.mapRect(&textBounds); diff --git a/src/rendering/renderers/TrackMatteRenderer.cpp b/src/rendering/renderers/TrackMatteRenderer.cpp index 4206dcb40b..b86304a67b 100644 --- a/src/rendering/renderers/TrackMatteRenderer.cpp +++ b/src/rendering/renderers/TrackMatteRenderer.cpp @@ -17,11 +17,11 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "TrackMatteRenderer.h" +#include "base/utils/TGFXCast.h" #include "rendering/caches/LayerCache.h" #include "rendering/caches/RenderCache.h" #include "rendering/caches/TextContent.h" #include "rendering/renderers/LayerRenderer.h" -#include "rendering/utils/TGFXTypes.h" namespace pag { static std::shared_ptr RenderColorGlyphs(TextLayer* layer, Frame layerFrame, @@ -69,7 +69,7 @@ std::unique_ptr TrackMatteRenderer::Make(PAGLayer* trackMatteOwner) filterModifier = FilterModifier::Make(trackMatteLayer); } Recorder recorder = {}; - Transform extraTransform = {trackMatteLayer->layerMatrix, trackMatteLayer->layerAlpha}; + Transform extraTransform = {ToTGFX(trackMatteLayer->layerMatrix), trackMatteLayer->layerAlpha}; LayerRenderer::DrawLayer(&recorder, trackMatteLayer->layer, layerFrame, filterModifier, nullptr, trackMatteLayer, &extraTransform); content = recorder.makeGraphic(); diff --git a/src/rendering/renderers/TransformRenderer.cpp b/src/rendering/renderers/TransformRenderer.cpp index ee60010ae2..95afd080bc 100644 --- a/src/rendering/renderers/TransformRenderer.cpp +++ b/src/rendering/renderers/TransformRenderer.cpp @@ -17,7 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "TransformRenderer.h" -#include "rendering/utils/TGFXTypes.h" +#include "base/utils/TGFXCast.h" namespace pag { void RenderTransform(Transform* transform, Transform2D* transform2D, Frame layerFrame) { diff --git a/src/rendering/renderers/TransformRenderer.h b/src/rendering/renderers/TransformRenderer.h index bbdaa68615..92fb2aaec0 100644 --- a/src/rendering/renderers/TransformRenderer.h +++ b/src/rendering/renderers/TransformRenderer.h @@ -18,6 +18,7 @@ #pragma once +#include "pag/file.h" #include "rendering/utils/Transform.h" namespace pag { diff --git a/src/rendering/utils/MemoryCalculator.cpp b/src/rendering/utils/MemoryCalculator.cpp index e2784a05ea..5fef81f823 100644 --- a/src/rendering/utils/MemoryCalculator.cpp +++ b/src/rendering/utils/MemoryCalculator.cpp @@ -33,7 +33,7 @@ static void* GetCacheResourcesForLayer(Layer* layer) { } void MemoryCalculator::FillLayerGraphicsMemoriesPreFrame( - Layer* layer, std::unordered_map& resourcesScaleMap, + Layer* layer, std::unordered_map& resourcesScaleMap, std::unordered_map*>& resourcesTimeRangesMap, std::vector& memoriesPreFrame, std::unordered_set& cachedResources) { auto resources = GetCacheResourcesForLayer(layer); @@ -63,7 +63,7 @@ void MemoryCalculator::FillLayerGraphicsMemoriesPreFrame( break; } auto layerContent = layerCache->getContent(0); - Rect bounds = {}; + tgfx::Rect bounds = {}; layerContent->measureBounds(&bounds); auto scale = std::max(scaleIter->second.x, scaleIter->second.y); if (layerType == LayerType::Image) { @@ -105,7 +105,7 @@ void FillGraphicsMemories( } void MemoryCalculator::FillBitmapGraphicsMemories( - Composition* composition, std::unordered_map&, + Composition* composition, std::unordered_map&, std::unordered_map*>& resourcesTimeRangesMap, std::vector& memoriesPreFrame, int64_t& graphicsMemory) { // Just use the last one for best rendering quality, ignore all others. @@ -126,7 +126,7 @@ void MemoryCalculator::FillVideoGraphicsMemories( } void MemoryCalculator::FillVectorGraphicsMemories( - Composition* composition, std::unordered_map& resourcesScaleMap, + Composition* composition, std::unordered_map& resourcesScaleMap, std::unordered_map*>& resourcesTimeRangesMap, std::vector& memoriesPreFrame, std::unordered_set& cachedResources) { VectorComposition* vectorComposition = static_cast(composition); @@ -139,7 +139,7 @@ void MemoryCalculator::FillVectorGraphicsMemories( } int64_t MemoryCalculator::FillCompositionGraphicsMemories( - Composition* composition, std::unordered_map& resourcesScaleMap, + Composition* composition, std::unordered_map& resourcesScaleMap, std::unordered_map*>& resourcesTimeRangesMap, std::vector& memoriesPreFrame, std::unordered_set& cachedResources) { int64_t graphicsMemory = 0; @@ -166,7 +166,7 @@ int64_t MemoryCalculator::FillCompositionGraphicsMemories( } std::vector MemoryCalculator::GetRootLayerGraphicsMemoriesPreFrame( - PreComposeLayer* rootLayer, std::unordered_map& resourcesScaleMap, + PreComposeLayer* rootLayer, std::unordered_map& resourcesScaleMap, std::unordered_map*>& resourcesTimeRangesMap) { std::unordered_set cachedResources; if (static_cast(rootLayer->composition->duration) > std::vector().max_size()) { @@ -180,7 +180,8 @@ std::vector MemoryCalculator::GetRootLayerGraphicsMemoriesPreFrame( } bool MemoryCalculator::UpdateMaxScaleMapIfNeed( - void* resource, Point currentScale, std::unordered_map& resourcesMaxScaleMap) { + void* resource, tgfx::Point currentScale, + std::unordered_map& resourcesMaxScaleMap) { auto maxScale = currentScale; auto iter = resourcesMaxScaleMap.find(resource); bool hasChange = true; @@ -260,8 +261,8 @@ void MemoryCalculator::UpdateTimeRange( } void MemoryCalculator::UpdateMaxScaleAndTimeRange( - Layer* layer, Point referenceScale, Frame referenceStartTime, - std::unordered_map& resourcesMaxScaleMap, + Layer* layer, tgfx::Point referenceScale, Frame referenceStartTime, + std::unordered_map& resourcesMaxScaleMap, std::unordered_map*>& resourcesTimeRangesMap) { if (!layer->isActive) { return; @@ -303,7 +304,7 @@ void MemoryCalculator::UpdateMaxScaleAndTimeRange( } void MemoryCalculator::CaculateResourcesMaxScaleAndTimeRanges( - Layer* rootLayer, std::unordered_map& resourcesMaxScaleMap, + Layer* rootLayer, std::unordered_map& resourcesMaxScaleMap, std::unordered_map*>& resourcesTimeRangesMap) { UpdateMaxScaleAndTimeRange(rootLayer, {1, 1}, rootLayer->startTime, resourcesMaxScaleMap, resourcesTimeRangesMap); @@ -314,7 +315,7 @@ int64_t CalculateGraphicsMemory(std::shared_ptr file) { return 0; } auto rootLayer = file->getRootLayer(); - std::unordered_map resourcesMaxScaleMap; + std::unordered_map resourcesMaxScaleMap; std::unordered_map*> resourcesTimeRangesMap; MemoryCalculator::CaculateResourcesMaxScaleAndTimeRanges(rootLayer, resourcesMaxScaleMap, resourcesTimeRangesMap); diff --git a/src/rendering/utils/MemoryCalculator.h b/src/rendering/utils/MemoryCalculator.h index 0a8d690600..fde8eee976 100644 --- a/src/rendering/utils/MemoryCalculator.h +++ b/src/rendering/utils/MemoryCalculator.h @@ -19,6 +19,7 @@ #pragma once #include +#include "core/Point.h" #include "pag/file.h" #include "pag/pag.h" @@ -26,16 +27,16 @@ namespace pag { class MemoryCalculator { public: static void CaculateResourcesMaxScaleAndTimeRanges( - Layer* rootLayer, std::unordered_map& resourcesMaxScaleMap, + Layer* rootLayer, std::unordered_map& resourcesMaxScaleMap, std::unordered_map*>& resourcesTimeRangesMap); static std::vector GetRootLayerGraphicsMemoriesPreFrame( - PreComposeLayer* rootLayer, std::unordered_map& resourcesScaleMap, + PreComposeLayer* rootLayer, std::unordered_map& resourcesScaleMap, std::unordered_map*>& resourcesTimeRangesMap); private: static void FillBitmapGraphicsMemories( - Composition* composition, std::unordered_map& resourcesScaleMap, + Composition* composition, std::unordered_map& resourcesScaleMap, std::unordered_map*>& resourcesTimeRangesMap, std::vector& memoriesPreFrame, int64_t& graphicsMemory); @@ -45,22 +46,22 @@ class MemoryCalculator { std::vector& memoriesPreFrame, int64_t& graphicsMemory); static void FillVectorGraphicsMemories( - Composition* composition, std::unordered_map& resourcesScaleMap, + Composition* composition, std::unordered_map& resourcesScaleMap, std::unordered_map*>& resourcesTimeRangesMap, std::vector& memoriesPreFrame, std::unordered_set& cachedResources); static int64_t FillCompositionGraphicsMemories( - Composition* composition, std::unordered_map& resourcesScaleMap, + Composition* composition, std::unordered_map& resourcesScaleMap, std::unordered_map*>& resourcesTimeRangesMap, std::vector& memoriesPreFrame, std::unordered_set& cachedResources); static void FillLayerGraphicsMemoriesPreFrame( - Layer* layer, std::unordered_map& resourcesScaleMap, + Layer* layer, std::unordered_map& resourcesScaleMap, std::unordered_map*>& resourcesTimeRangesMap, std::vector& memoriesPreFrame, std::unordered_set& cachedResources); - static bool UpdateMaxScaleMapIfNeed(void* resource, Point currentScale, - std::unordered_map& resourcesMaxScaleMap); + static bool UpdateMaxScaleMapIfNeed(void* resource, tgfx::Point currentScale, + std::unordered_map& resourcesMaxScaleMap); static void UpdateTimeRangesMapIfNeed( void* resource, TimeRange timeRange, std::unordered_map*>& resourcesTimeRangesMap, @@ -71,8 +72,8 @@ class MemoryCalculator { std::unordered_map*>& resourcesTimeRangesMap); static void UpdateMaxScaleAndTimeRange( - Layer* layer, Point referenceScale, Frame referenceStartTime, - std::unordered_map& resourcesMaxScaleMap, + Layer* layer, tgfx::Point referenceScale, Frame referenceStartTime, + std::unordered_map& resourcesMaxScaleMap, std::unordered_map*>& resourcesTimeRangesMap); }; } // namespace pag diff --git a/src/rendering/utils/PathUtil.cpp b/src/rendering/utils/PathUtil.cpp index b3b1e6bd28..2fb1943546 100644 --- a/src/rendering/utils/PathUtil.cpp +++ b/src/rendering/utils/PathUtil.cpp @@ -19,8 +19,8 @@ #include "PathUtil.h" namespace pag { -Path ToPath(const PathData& pathData) { - Path path = {}; +tgfx::Path ToPath(const PathData& pathData) { + tgfx::Path path = {}; auto& points = pathData.points; uint32_t index = 0; Point control1 = {}, control2 = {}, point = {}; diff --git a/src/rendering/utils/PathUtil.h b/src/rendering/utils/PathUtil.h index 18f91aaa90..5881b013ee 100644 --- a/src/rendering/utils/PathUtil.h +++ b/src/rendering/utils/PathUtil.h @@ -23,6 +23,6 @@ namespace pag { -Path ToPath(const PathData& pathData); +tgfx::Path ToPath(const PathData& pathData); } // namespace pag \ No newline at end of file diff --git a/src/rendering/utils/SurfaceUtil.cpp b/src/rendering/utils/SurfaceUtil.cpp index a1e9991e4d..40343d3913 100644 --- a/src/rendering/utils/SurfaceUtil.cpp +++ b/src/rendering/utils/SurfaceUtil.cpp @@ -23,8 +23,10 @@ namespace pag { // 1/20 is the minimum precision for rendering pixels on most platforms. #define CONTENT_SCALE_STEP 20.0f -std::shared_ptr SurfaceUtil::MakeContentSurface(Canvas* parentCanvas, const Rect& bounds, - float scaleFactorLimit, bool usesMSAA) { +std::shared_ptr SurfaceUtil::MakeContentSurface(tgfx::Canvas* parentCanvas, + const tgfx::Rect& bounds, + float scaleFactorLimit, + bool usesMSAA) { auto maxScale = GetMaxScaleFactor(parentCanvas->getMatrix()); if (maxScale > scaleFactorLimit) { maxScale = scaleFactorLimit; @@ -36,12 +38,13 @@ std::shared_ptr SurfaceUtil::MakeContentSurface(Canvas* parentCanvas, c auto height = static_cast(ceil(bounds.height() * maxScale)); // LOGE("makeContentSurface: (width = %d, height = %d)", width, height); auto sampleCount = usesMSAA ? 4 : 1; - auto newSurface = Surface::Make(parentCanvas->getContext(), width, height, false, sampleCount); + auto newSurface = + tgfx::Surface::Make(parentCanvas->getContext(), width, height, false, sampleCount); if (newSurface == nullptr) { return nullptr; } auto newCanvas = newSurface->getCanvas(); - auto matrix = Matrix::MakeScale(maxScale); + auto matrix = tgfx::Matrix::MakeScale(maxScale); matrix.preTranslate(-bounds.x(), -bounds.y()); newCanvas->setMatrix(matrix); return newSurface; diff --git a/src/rendering/utils/SurfaceUtil.h b/src/rendering/utils/SurfaceUtil.h index ec75cfc6ef..e6dfec7eb0 100644 --- a/src/rendering/utils/SurfaceUtil.h +++ b/src/rendering/utils/SurfaceUtil.h @@ -23,8 +23,9 @@ namespace pag { class SurfaceUtil { public: - static std::shared_ptr MakeContentSurface(Canvas* parentCanvas, const Rect& bounds, - float scaleFactorLimit = FLT_MAX, - bool usesMSAA = false); + static std::shared_ptr MakeContentSurface(tgfx::Canvas* parentCanvas, + const tgfx::Rect& bounds, + float scaleFactorLimit = FLT_MAX, + bool usesMSAA = false); }; } // namespace pag diff --git a/src/rendering/utils/TGFXTypes.cpp b/src/rendering/utils/TGFXTypes.cpp deleted file mode 100644 index db4743e746..0000000000 --- a/src/rendering/utils/TGFXTypes.cpp +++ /dev/null @@ -1,84 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////////////// -// -// Tencent is pleased to support the open source community by making libpag available. -// -// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file -// except in compliance with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// unless required by applicable law or agreed to in writing, software distributed under the -// license is distributed on an "as is" basis, without warranties or conditions of any kind, -// either express or implied. see the license for the specific language governing permissions -// and limitations under the license. -// -///////////////////////////////////////////////////////////////////////////////////////////////// - -#include "TGFXTypes.h" - -namespace pag { -static constexpr std::pair kBlendModeMap[] = { - {BlendMode::Normal, Blend::SrcOver}, - {BlendMode::Multiply, Blend::Multiply}, - {BlendMode::Screen, Blend::Screen}, - {BlendMode::Overlay, Blend::Overlay}, - {BlendMode::Darken, Blend::Darken}, - {BlendMode::Lighten, Blend::Lighten}, - {BlendMode::ColorDodge, Blend::ColorDodge}, - {BlendMode::ColorBurn, Blend::ColorBurn}, - {BlendMode::HardLight, Blend::HardLight}, - {BlendMode::SoftLight, Blend::SoftLight}, - {BlendMode::Difference, Blend::Difference}, - {BlendMode::Exclusion, Blend::Exclusion}, - {BlendMode::Hue, Blend::Hue}, - {BlendMode::Saturation, Blend::Saturation}, - {BlendMode::Color, Blend::Color}, - {BlendMode::Luminosity, Blend::Luminosity}, - {BlendMode::Add, Blend::Plus}}; - -Blend ToTGFXBlend(Enum blendMode) { - for (const auto& pair : kBlendModeMap) { - if (pair.first == blendMode) { - return pair.second; - } - } - return Blend::SrcOver; -} - -Stroke::Cap ToTGFXCap(Enum cap) { - switch (cap) { - case LineCap::Round: - return Stroke::Cap::Round; - case LineCap::Square: - return Stroke::Cap::Square; - default: - return Stroke::Cap::Butt; - } -} - -Stroke::Join ToTGFXJoin(Enum join) { - switch (join) { - case LineJoin::Round: - return Stroke::Join::Round; - case LineJoin::Bevel: - return Stroke::Join::Bevel; - default: - return Stroke::Join::Miter; - } -} - -Color4f ToTGFXColor(Color color, Opacity opacity) { - return {static_cast(color.red) / 255.0f, static_cast(color.green) / 255.0f, - static_cast(color.blue) / 255.0f, ToAlpha(opacity)}; -} - -float ToAlpha(Opacity opacity) { - if (opacity == 255) { - return 1.0f; - } - return static_cast(opacity) / 255.0f; -} - -} // namespace pag diff --git a/src/rendering/utils/Trace.cpp b/src/rendering/utils/Trace.cpp new file mode 100644 index 0000000000..e7bc8fb185 --- /dev/null +++ b/src/rendering/utils/Trace.cpp @@ -0,0 +1,54 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include "Trace.h" +#include "gpu/Surface.h" +#include "platform/Platform.h" + +namespace pag { +void Trace(std::shared_ptr pixelBuffer, const std::string& tag) { + tgfx::Bitmap bitmap(pixelBuffer); + Trace(bitmap, tag); +} + +void Trace(const tgfx::Texture* texture, const std::string& path) { + if (texture == nullptr) { + return; + } + auto surface = tgfx::Surface::Make(texture->getContext(), texture->width(), texture->height()); + if (surface == nullptr) { + return; + } + auto canvas = surface->getCanvas(); + canvas->drawTexture(texture); + auto pixelBuffer = tgfx::PixelBuffer::Make(texture->width(), texture->height()); + tgfx::Bitmap bitmap(pixelBuffer); + if (bitmap.isEmpty()) { + return; + } + surface->readPixels(bitmap.info(), bitmap.writablePixels()); + Trace(bitmap, path); +} + +void Trace(const tgfx::Bitmap& bitmap, const std::string& tag) { + if (bitmap.isEmpty()) { + return; + } + Platform::Current()->traceImage(bitmap.info(), bitmap.pixels(), tag); +} +} // namespace pag diff --git a/src/base/utils/UTF8Text.cpp b/src/rendering/utils/Trace.h similarity index 53% rename from src/base/utils/UTF8Text.cpp rename to src/rendering/utils/Trace.h index b17395000f..a3de0cbd22 100644 --- a/src/base/utils/UTF8Text.cpp +++ b/src/rendering/utils/Trace.h @@ -16,41 +16,24 @@ // ///////////////////////////////////////////////////////////////////////////////////////////////// -#include "UTF8Text.h" +#pragma once + +#include "core/Bitmap.h" +#include "gpu/Texture.h" namespace pag { -int UTF8Text::Count(const std::string& string) { - if (string.empty()) { - return -1; - } - int count = 0; - const char* start = &(string[0]); - const char* stop = start + string.size(); - while (start < stop) { - NextChar(&start); - ++count; - } - return count; -} +/** + * Trace() provides a utility to view the PixelBuffer. + */ +void Trace(std::shared_ptr pixelBuffer, const std::string& tag = ""); -static inline int32_t LeftShift(int32_t value) { - return static_cast((static_cast(value) << 1)); -} +/** + * Trace() provides a utility to view the texture. + */ +void Trace(const tgfx::Texture* texture, const std::string& path = ""); -int32_t UTF8Text::NextChar(const char** ptr) { - auto p = (const uint8_t*)*ptr; - int c = *p; - int hic = c << 24; - if (hic < 0) { - auto mask = static_cast(~0x3F); - hic = LeftShift(hic); - do { - c = (c << 6) | (*++p & 0x3F); - mask <<= 5; - } while ((hic = LeftShift(hic)) < 0); - c &= ~mask; - } - *ptr = static_cast(static_cast(p + 1)); - return c; -} -} // namespace pag \ No newline at end of file +/** + * Trace() provides a utility to view the Bitmap. + */ +void Trace(const tgfx::Bitmap& bitmap, const std::string& tag = ""); +} // namespace pag diff --git a/src/rendering/utils/Transform.h b/src/rendering/utils/Transform.h index db00ea35ab..0fcd4cbc55 100644 --- a/src/rendering/utils/Transform.h +++ b/src/rendering/utils/Transform.h @@ -18,7 +18,7 @@ #pragma once -#include "pag/file.h" +#include "core/Matrix.h" namespace pag { class Transform { @@ -27,14 +27,14 @@ class Transform { matrix.setIdentity(); } - Transform(const Matrix& matrix, float alpha) : matrix(matrix), alpha(alpha) { + Transform(const tgfx::Matrix& matrix, float alpha) : matrix(matrix), alpha(alpha) { } bool visible() const { return matrix.invertible() && alpha > 0; } - Matrix matrix = {}; + tgfx::Matrix matrix = {}; float alpha = 1.0f; }; } // namespace pag diff --git a/src/video/I420Buffer.cpp b/src/video/I420Buffer.cpp index e23c385e95..58a9330316 100644 --- a/src/video/I420Buffer.cpp +++ b/src/video/I420Buffer.cpp @@ -22,7 +22,7 @@ namespace pag { #define I420_PLANE_COUNT 3 I420Buffer::I420Buffer(int width, int height, uint8_t** data, const int* lineSize, - YUVColorSpace colorSpace, YUVColorRange colorRange) + tgfx::YUVColorSpace colorSpace, tgfx::YUVColorRange colorRange) : VideoBuffer(width, height), colorSpace(colorSpace), colorRange(colorRange) { for (int i = 0; i < I420_PLANE_COUNT; i++) { pixelsPlane[i] = data[i]; @@ -34,11 +34,11 @@ size_t I420Buffer::planeCount() const { return I420_PLANE_COUNT; } -std::shared_ptr I420Buffer::makeTexture(Context* context) const { +std::shared_ptr I420Buffer::makeTexture(tgfx::Context* context) const { if (context == nullptr) { return nullptr; } - return YUVTexture::MakeI420(context, colorSpace, colorRange, width(), height(), - const_cast(pixelsPlane), rowBytesPlane); + return tgfx::YUVTexture::MakeI420(context, colorSpace, colorRange, width(), height(), + const_cast(pixelsPlane), rowBytesPlane); } } // namespace pag diff --git a/src/video/I420Buffer.h b/src/video/I420Buffer.h index 5f53d02c20..19eb45d3ce 100644 --- a/src/video/I420Buffer.h +++ b/src/video/I420Buffer.h @@ -25,15 +25,15 @@ class I420Buffer : public VideoBuffer { public: size_t planeCount() const override; - std::shared_ptr makeTexture(Context* context) const override; + std::shared_ptr makeTexture(tgfx::Context* context) const override; protected: I420Buffer(int width, int height, uint8_t* data[3], const int lineSize[3], - YUVColorSpace colorSpace, YUVColorRange colorRange); + tgfx::YUVColorSpace colorSpace, tgfx::YUVColorRange colorRange); private: - YUVColorSpace colorSpace = YUVColorSpace::Rec601; - YUVColorRange colorRange = YUVColorRange::MPEG; + tgfx::YUVColorSpace colorSpace = tgfx::YUVColorSpace::Rec601; + tgfx::YUVColorRange colorRange = tgfx::YUVColorRange::MPEG; uint8_t* pixelsPlane[3] = {}; int rowBytesPlane[3] = {}; }; diff --git a/src/video/SoftwareDecoderWrapper.cpp b/src/video/SoftwareDecoderWrapper.cpp index f9a3d824c8..f000b62d56 100644 --- a/src/video/SoftwareDecoderWrapper.cpp +++ b/src/video/SoftwareDecoderWrapper.cpp @@ -24,8 +24,9 @@ namespace pag { class SoftwareI420Buffer : public I420Buffer { public: static std::shared_ptr Make( - int width, int height, uint8_t* data[3], const int lineSize[3], YUVColorSpace colorSpace, - YUVColorRange colorRange, std::shared_ptr softwareDecoder) { + int width, int height, uint8_t* data[3], const int lineSize[3], + tgfx::YUVColorSpace colorSpace, tgfx::YUVColorRange colorRange, + std::shared_ptr softwareDecoder) { auto buffer = new SoftwareI420Buffer(width, height, data, lineSize, colorSpace, colorRange, std::move(softwareDecoder)); return std::shared_ptr(buffer); @@ -36,7 +37,7 @@ class SoftwareI420Buffer : public I420Buffer { std::shared_ptr softwareDecoder = nullptr; SoftwareI420Buffer(int width, int height, uint8_t* data[3], const int lineSize[3], - YUVColorSpace colorSpace, YUVColorRange colorRange, + tgfx::YUVColorSpace colorSpace, tgfx::YUVColorRange colorRange, std::shared_ptr softwareDecoder) : I420Buffer(width, height, data, lineSize, colorSpace, colorRange), softwareDecoder(std::move(softwareDecoder)) { diff --git a/src/video/VideoBuffer.h b/src/video/VideoBuffer.h index 0416959e3b..dffe6420f3 100644 --- a/src/video/VideoBuffer.h +++ b/src/video/VideoBuffer.h @@ -25,7 +25,7 @@ namespace pag { /** * VideoBuffer describes a two dimensional array of pixels from a decoded video frame. */ -class VideoBuffer : public TextureBuffer { +class VideoBuffer : public tgfx::TextureBuffer { public: /** * Returns number of planes in this video buffer. @@ -33,7 +33,7 @@ class VideoBuffer : public TextureBuffer { virtual size_t planeCount() const = 0; protected: - VideoBuffer(int width, int height) : TextureBuffer(width, height) { + VideoBuffer(int width, int height) : tgfx::TextureBuffer(width, height) { } }; } // namespace pag \ No newline at end of file diff --git a/src/video/VideoDecoder.h b/src/video/VideoDecoder.h index 045f605c50..104b098401 100644 --- a/src/video/VideoDecoder.h +++ b/src/video/VideoDecoder.h @@ -38,8 +38,8 @@ struct VideoConfig { float frameRate = 0.0; bool hasAlpha = false; std::vector> headers = {}; - YUVColorSpace colorSpace = YUVColorSpace::Rec601; - YUVColorRange colorRange = YUVColorRange::MPEG; + tgfx::YUVColorSpace colorSpace = tgfx::YUVColorSpace::Rec601; + tgfx::YUVColorRange colorRange = tgfx::YUVColorRange::MPEG; std::string mimeType = "video/avc"; }; diff --git a/src/video/VideoSequenceReader.cpp b/src/video/VideoSequenceReader.cpp index 4107a6483f..290e9af305 100644 --- a/src/video/VideoSequenceReader.cpp +++ b/src/video/VideoSequenceReader.cpp @@ -46,7 +46,7 @@ VideoSequenceReader::VideoSequenceReader(std::shared_ptr file, VideoSequen config.headers.push_back(std::move(bytes)); } config.mimeType = "video/avc"; - config.colorSpace = YUVColorSpace::Rec601; + config.colorSpace = tgfx::YUVColorSpace::Rec601; config.frameRate = sequence->frameRate; reader = std::make_unique(config, std::move(demuxer), policy); } @@ -65,7 +65,8 @@ void VideoSequenceReader::prepareAsync(Frame targetFrame) { } } -std::shared_ptr VideoSequenceReader::readTexture(Frame targetFrame, RenderCache* cache) { +std::shared_ptr VideoSequenceReader::readTexture(Frame targetFrame, + RenderCache* cache) { if (!reader) { return nullptr; } diff --git a/src/video/VideoSequenceReader.h b/src/video/VideoSequenceReader.h index 085c1c0f71..c5f7a64d3d 100644 --- a/src/video/VideoSequenceReader.h +++ b/src/video/VideoSequenceReader.h @@ -30,13 +30,13 @@ class VideoSequenceReader : public SequenceReader { void prepareAsync(Frame targetFrame) override; - std::shared_ptr readTexture(Frame targetFrame, RenderCache* cache) override; + std::shared_ptr readTexture(Frame targetFrame, RenderCache* cache) override; private: Frame lastFrame = -1; int64_t pendingTime = -1; std::shared_ptr reader = nullptr; - std::shared_ptr lastTexture = nullptr; + std::shared_ptr lastTexture = nullptr; std::shared_ptr lastTask = nullptr; }; } // namespace pag diff --git a/test/GLUtilTest.cpp b/test/GLUtilTest.cpp index ac53c757b4..b8ea453a56 100644 --- a/test/GLUtilTest.cpp +++ b/test/GLUtilTest.cpp @@ -22,6 +22,8 @@ #include "gpu/opengl/GLUtil.h" namespace pag { +using namespace tgfx; + PAG_TEST_SUIT(GLUtilTest) int i = 0; diff --git a/test/PAGBlendTest.cpp b/test/PAGBlendTest.cpp index b79a16d01b..8e882ab1b2 100644 --- a/test/PAGBlendTest.cpp +++ b/test/PAGBlendTest.cpp @@ -24,6 +24,8 @@ #include "rendering/Drawable.h" namespace pag { +using namespace tgfx; + PAG_TEST_CASE(PAGBlendTest) /** @@ -49,13 +51,13 @@ PAG_TEST_F(PAGBlendTest, Blend) { } } -GLTextureInfo GetBottomLeftImage(std::shared_ptr device, int width, int height) { +tgfx::GLTextureInfo GetBottomLeftImage(std::shared_ptr device, int width, int height) { auto context = device->lockContext(); auto gl = GLContext::Unwrap(context); - GLTextureInfo textureInfo; - CreateTexture(gl, width, height, &textureInfo); - auto surface = - PAGSurface::MakeFrom(BackendTexture(textureInfo, width, height), ImageOrigin::BottomLeft); + tgfx::GLTextureInfo textureInfo; + CreateGLTexture(gl, width, height, &textureInfo); + tgfx::BackendTexture backendTexture(textureInfo, width, height); + auto surface = PAGSurface::MakeFrom(ToPAG(backendTexture), ImageOrigin::BottomLeft); device->unlock(); auto composition = PAGComposition::Make(1080, 1920); auto imageLayer = PAGImageLayer::Make(1080, 1920, 1000000); @@ -78,10 +80,10 @@ PAG_TEST_F(PAGBlendTest, CopyDstTexture) { auto context = device->lockContext(); ASSERT_TRUE(context != nullptr); auto gl = GLContext::Unwrap(context); - GLTextureInfo textureInfo; - CreateTexture(gl, width, height, &textureInfo); - auto backendTexture = BackendTexture(textureInfo, width, height); - auto pagSurface = PAGSurface::MakeFrom(backendTexture, ImageOrigin::BottomLeft); + tgfx::GLTextureInfo textureInfo; + CreateGLTexture(gl, width, height, &textureInfo); + auto backendTexture = tgfx::BackendTexture(textureInfo, width, height); + auto pagSurface = PAGSurface::MakeFrom(ToPAG(backendTexture), ImageOrigin::BottomLeft); device->unlock(); auto pagPlayer = std::make_shared(); pagPlayer->setSurface(pagSurface); @@ -109,12 +111,12 @@ PAG_TEST_F(PAGBlendTest, TextureBottomLeft) { auto context = device->lockContext(); ASSERT_TRUE(context != nullptr); auto gl = GLContext::Unwrap(context); - auto replaceImage = PAGImage::FromTexture(BackendTexture(replaceTextureInfo, width, height), - ImageOrigin::BottomLeft); - GLTextureInfo textureInfo; - CreateTexture(gl, width, height, &textureInfo); - auto backendTexture = BackendTexture(textureInfo, width, height); - auto pagSurface = PAGSurface::MakeFrom(backendTexture, ImageOrigin::TopLeft); + auto backendTexture = tgfx::BackendTexture(replaceTextureInfo, width, height); + auto replaceImage = PAGImage::FromTexture(ToPAG(backendTexture), ImageOrigin::BottomLeft); + tgfx::GLTextureInfo textureInfo; + CreateGLTexture(gl, width, height, &textureInfo); + backendTexture = tgfx::BackendTexture(textureInfo, width, height); + auto pagSurface = PAGSurface::MakeFrom(ToPAG(backendTexture), ImageOrigin::TopLeft); device->unlock(); auto pagPlayer = std::make_shared(); @@ -144,15 +146,15 @@ PAG_TEST_F(PAGBlendTest, BothBottomLeft) { auto replaceTextureInfo = GetBottomLeftImage(device, width, height); auto context = device->lockContext(); ASSERT_TRUE(context != nullptr); - auto replaceImage = PAGImage::FromTexture( - BackendTexture(replaceTextureInfo, width / 2, height / 2), ImageOrigin::BottomLeft); + auto backendTexture = tgfx::BackendTexture(replaceTextureInfo, width / 2, height / 2); + auto replaceImage = PAGImage::FromTexture(ToPAG(backendTexture), ImageOrigin::BottomLeft); replaceImage->setMatrix( Matrix::MakeTrans(static_cast(width) * 0.1, static_cast(height) * 0.2)); auto gl = GLContext::Unwrap(context); - GLTextureInfo textureInfo; - CreateTexture(gl, width, height, &textureInfo); - auto backendTexture = BackendTexture(textureInfo, width, height); - auto pagSurface = PAGSurface::MakeFrom(backendTexture, ImageOrigin::BottomLeft); + tgfx::GLTextureInfo textureInfo; + CreateGLTexture(gl, width, height, &textureInfo); + backendTexture = tgfx::BackendTexture(textureInfo, width, height); + auto pagSurface = PAGSurface::MakeFrom(ToPAG(backendTexture), ImageOrigin::BottomLeft); device->unlock(); auto composition = PAGComposition::Make(width, height); diff --git a/test/PAGCompareFrameTest.cpp b/test/PAGCompareFrameTest.cpp index 6467c4922c..262cc98f6a 100644 --- a/test/PAGCompareFrameTest.cpp +++ b/test/PAGCompareFrameTest.cpp @@ -32,6 +32,7 @@ #include "rendering/caches/RenderCache.h" namespace pag { +using namespace tgfx; using nlohmann::json; static constexpr bool PrintPerformance = false; diff --git a/test/PAGImageTest.cpp b/test/PAGImageTest.cpp index 230953334d..926b303fab 100644 --- a/test/PAGImageTest.cpp +++ b/test/PAGImageTest.cpp @@ -25,6 +25,7 @@ #include "pag/pag.h" namespace pag { +using namespace tgfx; using nlohmann::json; PAG_TEST_SUIT(PAGImageTest) @@ -56,12 +57,12 @@ PAG_TEST_F(PAGImageTest, image) { ASSERT_TRUE(pixelBuffer == nullptr); pixelBuffer = PixelBuffer::Make(width, height, true); ASSERT_TRUE(pixelBuffer != nullptr); - EXPECT_EQ(pixelBuffer->colorType(), ColorType::ALPHA_8); + EXPECT_EQ(pixelBuffer->colorType(), tgfx::ColorType::ALPHA_8); pixelBuffer = PixelBuffer::Make(width, height); ASSERT_TRUE(pixelBuffer != nullptr); Bitmap bitmap(pixelBuffer); - auto info = - ImageInfo::Make(width, height, ColorType::RGBA_8888, AlphaType::Premultiplied, rowBytes); + auto info = ImageInfo::Make(width, height, tgfx::ColorType::RGBA_8888, + tgfx::AlphaType::Premultiplied, rowBytes); auto result = bitmap.writePixels(info, fileData->data()); ASSERT_TRUE(result); auto newFileData = ByteData::Make(fileData->length()); diff --git a/test/PAGPlayerTest.cpp b/test/PAGPlayerTest.cpp index 1cd7c07807..5d76e571dc 100644 --- a/test/PAGPlayerTest.cpp +++ b/test/PAGPlayerTest.cpp @@ -22,6 +22,7 @@ namespace pag { using nlohmann::json; +using namespace tgfx; PAG_TEST_CASE(PAGPlayerTest) @@ -111,21 +112,21 @@ PAG_TEST_F(PAGPlayerTest, autoClear) { auto pixelBuffer = PixelBuffer::Make(pagSurface->width(), pagSurface->height()); Bitmap bitmap(pixelBuffer); ASSERT_FALSE(bitmap.isEmpty()); - auto result = pagSurface->readPixels(bitmap.colorType(), bitmap.alphaType(), + auto result = pagSurface->readPixels(ToPAG(bitmap.colorType()), ToPAG(bitmap.alphaType()), bitmap.writablePixels(), bitmap.rowBytes()); ASSERT_TRUE(result); EXPECT_TRUE(Baseline::Compare(pagSurface, "PAGPlayerTest/autoClear_autoClear_false_flush0")); pagPlayer->flush(); - result = pagSurface->readPixels(bitmap.colorType(), bitmap.alphaType(), bitmap.writablePixels(), - bitmap.rowBytes()); + result = pagSurface->readPixels(ToPAG(bitmap.colorType()), ToPAG(bitmap.alphaType()), + bitmap.writablePixels(), bitmap.rowBytes()); ASSERT_TRUE(result); EXPECT_TRUE(Baseline::Compare(pagSurface, "PAGPlayerTest/autoClear_autoClear_false_flush1")); pagPlayer->setAutoClear(true); pagPlayer->flush(); - result = pagSurface->readPixels(bitmap.colorType(), bitmap.alphaType(), bitmap.writablePixels(), - bitmap.rowBytes()); + result = pagSurface->readPixels(ToPAG(bitmap.colorType()), ToPAG(bitmap.alphaType()), + bitmap.writablePixels(), bitmap.rowBytes()); ASSERT_TRUE(result); EXPECT_TRUE(Baseline::Compare(pagSurface, "PAGPlayerTest/autoClear_autoClear_true")); } diff --git a/test/PAGRasterizerTest.cpp b/test/PAGRasterizerTest.cpp index ea6a1ed0de..099e9fec64 100644 --- a/test/PAGRasterizerTest.cpp +++ b/test/PAGRasterizerTest.cpp @@ -28,6 +28,7 @@ namespace pag { using nlohmann::json; +using namespace tgfx; /** * 用例描述: 矢量栅格化相关功能测试 @@ -35,12 +36,12 @@ using nlohmann::json; PAG_TEST(PAGRasterizerTest, TestRasterizer) { Path path = {}; path.addRect(100, 100, 400, 400); - path.addRoundRect(Rect::MakeLTRB(150, 150, 350, 350), 30, 20, true); - path.addOval(Rect::MakeLTRB(200, 200, 300, 300)); + path.addRoundRect(tgfx::Rect::MakeLTRB(150, 150, 350, 350), 30, 20, true); + path.addOval(tgfx::Rect::MakeLTRB(200, 200, 300, 300)); // 501*501 是为了测试 GL_UNPACK_ALIGNMENT auto mask = Mask::Make(501, 501); ASSERT_TRUE(mask != nullptr); - auto matrix = Matrix::MakeTrans(50, 50); + auto matrix = tgfx::Matrix::MakeTrans(50, 50); mask->setMatrix(matrix); mask->fillPath(path); auto maskBuffer = std::static_pointer_cast(mask)->getBuffer(); diff --git a/test/PAGReadPixelsTest.cpp b/test/PAGReadPixelsTest.cpp index 5faac1dfb0..a37b43215a 100644 --- a/test/PAGReadPixelsTest.cpp +++ b/test/PAGReadPixelsTest.cpp @@ -27,6 +27,7 @@ #include "gpu/opengl/GLUtil.h" namespace pag { +using namespace tgfx; using nlohmann::json; #define CHECK_PIXELS(info, pixels, key) \ @@ -43,7 +44,8 @@ PAG_TEST(PAGReadPixelsTest, TestPixelMap) { EXPECT_TRUE(image != nullptr); auto width = image->width(); auto height = image->height(); - auto RGBAInfo = ImageInfo::Make(width, height, ColorType::RGBA_8888, AlphaType::Unpremultiplied); + auto RGBAInfo = + ImageInfo::Make(width, height, tgfx::ColorType::RGBA_8888, tgfx::AlphaType::Unpremultiplied); auto byteSize = RGBAInfo.byteSize(); auto pixelsA = new uint8_t[byteSize]; auto pixelsB = new uint8_t[byteSize]; @@ -62,7 +64,8 @@ PAG_TEST(PAGReadPixelsTest, TestPixelMap) { ASSERT_TRUE(result); CHECK_PIXELS(RGBAInfo, pixelsB, "PixelMap_RGBA_to_RGBA_100_100"); - auto RGBARectInfo = ImageInfo::Make(500, 500, ColorType::RGBA_8888, AlphaType::Premultiplied); + auto RGBARectInfo = + ImageInfo::Make(500, 500, tgfx::ColorType::RGBA_8888, tgfx::AlphaType::Premultiplied); memset(pixelsB, 0, RGBARectInfo.byteSize()); result = RGBAMap.readPixels(RGBARectInfo, pixelsB, -100, -100); ASSERT_TRUE(result); @@ -73,17 +76,17 @@ PAG_TEST(PAGReadPixelsTest, TestPixelMap) { ASSERT_TRUE(result); CHECK_PIXELS(RGBARectInfo, pixelsB, "PixelMap_RGBA_to_RGBA_100_-100"); - auto rgbAInfo = RGBAInfo.makeAlphaType(AlphaType::Premultiplied); + auto rgbAInfo = RGBAInfo.makeAlphaType(tgfx::AlphaType::Premultiplied); result = RGBAMap.readPixels(rgbAInfo, pixelsB); EXPECT_TRUE(result); CHECK_PIXELS(rgbAInfo, pixelsB, "PixelMap_RGBA_to_rgbA"); - auto bgrAInfo = rgbAInfo.makeColorType(ColorType::BGRA_8888); + auto bgrAInfo = rgbAInfo.makeColorType(tgfx::ColorType::BGRA_8888); result = RGBAMap.readPixels(bgrAInfo, pixelsB); EXPECT_TRUE(result); CHECK_PIXELS(bgrAInfo, pixelsB, "PixelMap_RGBA_to_bgrA"); - auto BGRAInfo = bgrAInfo.makeAlphaType(AlphaType::Unpremultiplied); + auto BGRAInfo = bgrAInfo.makeAlphaType(tgfx::AlphaType::Unpremultiplied); result = RGBAMap.readPixels(BGRAInfo, pixelsB); EXPECT_TRUE(result); CHECK_PIXELS(BGRAInfo, pixelsB, "PixelMap_RGBA_to_BGRA"); @@ -116,8 +119,9 @@ PAG_TEST(PAGReadPixelsTest, TestPixelMap) { EXPECT_TRUE(result); CHECK_PIXELS(bgrAInfo, pixelsB, "PixelMap_rgbA_to_bgrA"); - auto A8Info = ImageInfo::Make(width, height, ColorType::ALPHA_8, AlphaType::Unpremultiplied); - EXPECT_EQ(A8Info.alphaType(), AlphaType::Premultiplied); + auto A8Info = + ImageInfo::Make(width, height, tgfx::ColorType::ALPHA_8, tgfx::AlphaType::Unpremultiplied); + EXPECT_EQ(A8Info.alphaType(), tgfx::AlphaType::Premultiplied); auto alphaByteSize = A8Info.byteSize(); auto pixelsC = new uint8_t[alphaByteSize]; @@ -168,12 +172,14 @@ PAG_TEST(PAGReadPixelsTest, TestSurfaceReadPixels) { auto height = bitmap.height(); pixels = bitmap.writablePixels(); - auto RGBAInfo = ImageInfo::Make(width, height, ColorType::RGBA_8888, AlphaType::Premultiplied); + auto RGBAInfo = + ImageInfo::Make(width, height, tgfx::ColorType::RGBA_8888, tgfx::AlphaType::Premultiplied); result = surface->readPixels(RGBAInfo, pixels); ASSERT_TRUE(result); CHECK_PIXELS(RGBAInfo, pixels, "Surface_rgbA_to_rgbA"); - auto BGRAInfo = ImageInfo::Make(width, height, ColorType::BGRA_8888, AlphaType::Premultiplied); + auto BGRAInfo = + ImageInfo::Make(width, height, tgfx::ColorType::BGRA_8888, tgfx::AlphaType::Premultiplied); result = surface->readPixels(BGRAInfo, pixels); ASSERT_TRUE(result); CHECK_PIXELS(BGRAInfo, pixels, "Surface_rgbA_to_bgrA"); @@ -183,7 +189,8 @@ PAG_TEST(PAGReadPixelsTest, TestSurfaceReadPixels) { ASSERT_TRUE(result); CHECK_PIXELS(RGBAInfo, pixels, "Surface_rgbA_to_rgbA_100_100"); - auto RGBARectInfo = ImageInfo::Make(500, 500, ColorType::RGBA_8888, AlphaType::Premultiplied); + auto RGBARectInfo = + ImageInfo::Make(500, 500, tgfx::ColorType::RGBA_8888, tgfx::AlphaType::Premultiplied); memset(pixels, 0, RGBARectInfo.byteSize()); result = surface->readPixels(RGBARectInfo, pixels, -100, -100); ASSERT_TRUE(result); @@ -199,7 +206,8 @@ PAG_TEST(PAGReadPixelsTest, TestSurfaceReadPixels) { canvas = surface->getCanvas(); canvas->drawTexture(texture.get()); - auto A8Info = ImageInfo::Make(width, height, ColorType::ALPHA_8, AlphaType::Premultiplied); + auto A8Info = + ImageInfo::Make(width, height, tgfx::ColorType::ALPHA_8, tgfx::AlphaType::Premultiplied); result = surface->readPixels(A8Info, pixels); ASSERT_TRUE(result); CHECK_PIXELS(A8Info, pixels, "Surface_alpha_to_alpha"); @@ -208,18 +216,19 @@ PAG_TEST(PAGReadPixelsTest, TestSurfaceReadPixels) { ASSERT_TRUE(result); CHECK_PIXELS(RGBAInfo, pixels, "Surface_alpha_to_rgba"); - auto AlphaRectInfo = ImageInfo::Make(500, 500, ColorType::ALPHA_8, AlphaType::Premultiplied); + auto AlphaRectInfo = + ImageInfo::Make(500, 500, tgfx::ColorType::ALPHA_8, tgfx::AlphaType::Premultiplied); memset(pixels, 0, AlphaRectInfo.byteSize()); result = surface->readPixels(AlphaRectInfo, pixels, 100, -100); ASSERT_TRUE(result); CHECK_PIXELS(AlphaRectInfo, pixels, "Surface_alpha_to_alpha_100_-100"); auto gl = GLContext::Unwrap(context); - GLTextureInfo textureInfo = {}; - result = CreateTexture(gl, width, height, &textureInfo); + tgfx::GLTextureInfo textureInfo = {}; + result = CreateGLTexture(gl, width, height, &textureInfo); ASSERT_TRUE(result); - auto backendTexture = BackendTexture(textureInfo, width, height); - surface = Surface::MakeFrom(context, backendTexture, ImageOrigin::BottomLeft); + auto backendTexture = tgfx::BackendTexture(textureInfo, width, height); + surface = Surface::MakeFrom(context, backendTexture, tgfx::ImageOrigin::BottomLeft); ASSERT_TRUE(surface != nullptr); canvas = surface->getCanvas(); canvas->clear(); @@ -260,8 +269,8 @@ PAG_TEST(PAGReadPixelsTest, PngCodec) { auto rowBytes = image->width() * 4; auto pixels = new (std::nothrow) uint8_t[rowBytes * image->height()]; ASSERT_TRUE(pixels); - auto info = ImageInfo::Make(image->width(), image->height(), ColorType::RGBA_8888, - AlphaType::Premultiplied); + auto info = ImageInfo::Make(image->width(), image->height(), tgfx::ColorType::RGBA_8888, + tgfx::AlphaType::Premultiplied); ASSERT_TRUE(image->readPixels(info, pixels)); CHECK_PIXELS(info, pixels, "PngCodec_Decode"); Bitmap bitmap(info, pixels); @@ -283,8 +292,8 @@ PAG_TEST(PAGReadPixelsTest, WebpCodec) { ASSERT_EQ(image->width(), 110); ASSERT_EQ(image->height(), 110); ASSERT_EQ(static_cast(image->orientation()), static_cast(Orientation::TopLeft)); - auto info = ImageInfo::Make(image->width(), image->height(), ColorType::RGBA_8888, - AlphaType::Premultiplied); + auto info = ImageInfo::Make(image->width(), image->height(), tgfx::ColorType::RGBA_8888, + tgfx::AlphaType::Premultiplied); auto pixels = new (std::nothrow) uint8_t[info.byteSize()]; ASSERT_TRUE(pixels); ASSERT_TRUE(image->readPixels(info, pixels)); @@ -297,8 +306,8 @@ PAG_TEST(PAGReadPixelsTest, WebpCodec) { ASSERT_EQ(image->height(), 110); ASSERT_EQ(static_cast(image->orientation()), static_cast(Orientation::TopLeft)); - auto a8Info = ImageInfo::Make(image->width(), image->height(), ColorType::ALPHA_8, - AlphaType::Premultiplied); + auto a8Info = ImageInfo::Make(image->width(), image->height(), tgfx::ColorType::ALPHA_8, + tgfx::AlphaType::Premultiplied); auto a8Pixels = new (std::nothrow) uint8_t[a8Info.byteSize()]; ASSERT_TRUE(image->readPixels(a8Info, a8Pixels)); auto rgbaFromA8Data = Bitmap(a8Info, a8Pixels).encode(EncodedFormat::WEBP, 100); @@ -318,12 +327,12 @@ PAG_TEST(PAGReadPixelsTest, JpegCodec) { ASSERT_EQ(image->width(), 4032); ASSERT_EQ(image->height(), 3024); ASSERT_EQ(static_cast(image->orientation()), static_cast(Orientation::RightTop)); - ColorType outputColorType = ColorType::RGBA_8888; + auto outputColorType = tgfx::ColorType::RGBA_8888; auto pixels = new (std::nothrow) uint8_t[image->height() * image->width() * ImageInfo::GetBytesPerPixel(outputColorType)]; ASSERT_TRUE(pixels); - auto info = - ImageInfo::Make(image->width(), image->height(), outputColorType, AlphaType::Premultiplied); + auto info = ImageInfo::Make(image->width(), image->height(), outputColorType, + tgfx::AlphaType::Premultiplied); bool res = image->readPixels(info, pixels); CHECK_PIXELS(info, pixels, "JpegCodec_Decode"); Bitmap bitmap(info, pixels); diff --git a/test/PAGSurfaceTest.cpp b/test/PAGSurfaceTest.cpp index 43edf5b0a4..243b1b17ae 100644 --- a/test/PAGSurfaceTest.cpp +++ b/test/PAGSurfaceTest.cpp @@ -24,6 +24,8 @@ #include "rendering/Drawable.h" namespace pag { +using namespace tgfx; + PAG_TEST_SUIT(PAGSurfaceTest) /** @@ -38,16 +40,17 @@ PAG_TEST(PAGSurfaceTest, FromTexture) { ASSERT_TRUE(context != nullptr); auto gl = GLContext::Unwrap(context); auto glVersion = gl->caps->version; - GLTextureInfo textureInfo; - CreateTexture(gl, width, height, &textureInfo); - auto backendTexture = BackendTexture(textureInfo, width, height); - auto pagSurface = PAGSurface::MakeFrom(backendTexture, ImageOrigin::TopLeft); + tgfx::GLTextureInfo textureInfo; + CreateGLTexture(gl, width, height, &textureInfo); + auto backendTexture = tgfx::BackendTexture(textureInfo, width, height); + auto pagSurface = PAGSurface::MakeFrom(ToPAG(backendTexture), ImageOrigin::TopLeft); auto nativeHandle = GLDevice::CurrentNativeHandle(); device->unlock(); auto glDevice = std::static_pointer_cast(pagSurface->drawable->getDevice()); EXPECT_TRUE(glDevice->sharableWith(nativeHandle)); - auto drawable = std::make_shared(device, backendTexture, ImageOrigin::TopLeft); + auto drawable = + std::make_shared(device, backendTexture, tgfx::ImageOrigin::TopLeft); auto pagSurface2 = PAGSurface::MakeFrom(drawable); auto pagPlayer2 = std::make_shared(); pagPlayer2->setSurface(pagSurface2); @@ -89,10 +92,10 @@ PAG_TEST(PAGSurfaceTest, Mask) { auto context = device->lockContext(); ASSERT_TRUE(context != nullptr); auto gl = GLContext::Unwrap(context); - GLTextureInfo textureInfo; - CreateTexture(gl, width, height, &textureInfo); - auto backendTexture = BackendTexture(textureInfo, width, height); - auto pagSurface = PAGSurface::MakeFrom(backendTexture, ImageOrigin::BottomLeft); + tgfx::GLTextureInfo textureInfo; + CreateGLTexture(gl, width, height, &textureInfo); + auto backendTexture = tgfx::BackendTexture(textureInfo, width, height); + auto pagSurface = PAGSurface::MakeFrom(ToPAG(backendTexture), ImageOrigin::BottomLeft); device->unlock(); auto pagPlayer = std::make_shared(); diff --git a/test/framework/utils/Baseline.cpp b/test/framework/utils/Baseline.cpp index 34216bdaef..3aa1c265ce 100644 --- a/test/framework/utils/Baseline.cpp +++ b/test/framework/utils/Baseline.cpp @@ -21,10 +21,13 @@ #include #include #include "LzmaUtil.h" +#include "base/utils/TGFXCast.h" #include "core/Data.h" #include "core/Image.h" namespace pag { +using namespace tgfx; + #define BASELINE_ROOT "../test/baseline/" #define OUT_BASELINE_ROOT "../test/out/baseline/" #define OUT_COMPARE_ROOT "../test/out/compare/" @@ -33,7 +36,7 @@ namespace pag { #define MAX_DIFF_VALUE 5 static ImageInfo MakeInfo(int with, int height) { - return ImageInfo::Make(with, height, ColorType::RGBA_8888, AlphaType::Premultiplied); + return ImageInfo::Make(with, height, tgfx::ColorType::RGBA_8888, tgfx::AlphaType::Premultiplied); } static std::shared_ptr LoadImageData(const std::string& key) { @@ -142,8 +145,8 @@ bool Baseline::Compare(const std::shared_ptr& surface, const std::st auto info = MakeInfo(surface->width(), surface->height()); auto pixels = new uint8_t[info.byteSize()]; auto data = Data::MakeAdopted(pixels, info.byteSize(), Data::DeleteProc); - auto result = - surface->readPixels(info.colorType(), AlphaType::Premultiplied, pixels, info.rowBytes()); + auto result = surface->readPixels(ToPAG(info.colorType()), AlphaType::Premultiplied, pixels, + info.rowBytes()); if (!result) { return false; } diff --git a/test/framework/utils/Baseline.h b/test/framework/utils/Baseline.h index b3520b43e5..ed8f4f358d 100644 --- a/test/framework/utils/Baseline.h +++ b/test/framework/utils/Baseline.h @@ -25,9 +25,10 @@ namespace pag { class Baseline { public: - static bool Compare(const std::shared_ptr& pixelBuffer, const std::string& key); + static bool Compare(const std::shared_ptr& pixelBuffer, + const std::string& key); - static bool Compare(const Bitmap& bitmap, const std::string& key); + static bool Compare(const tgfx::Bitmap& bitmap, const std::string& key); static bool Compare(const std::shared_ptr& surface, const std::string& key); }; diff --git a/test/framework/utils/LzmaUtil.cpp b/test/framework/utils/LzmaUtil.cpp index ad158b74da..51153edb77 100644 --- a/test/framework/utils/LzmaUtil.cpp +++ b/test/framework/utils/LzmaUtil.cpp @@ -158,7 +158,7 @@ class Lzma2Encoder { Lzma2Enc_Destroy(encoder); } - std::shared_ptr code(const std::shared_ptr& inputData) { + std::shared_ptr code(const std::shared_ptr& inputData) { if (encoder == nullptr || inputData == nullptr || inputData->size() == 0) { return nullptr; } @@ -187,14 +187,14 @@ class Lzma2Encoder { if (status != SZ_OK) { return nullptr; } - return Data::MakeWithCopy(&outBuf[0], outBuf.size()); + return tgfx::Data::MakeWithCopy(&outBuf[0], outBuf.size()); } private: CLzma2EncHandle encoder = nullptr; }; -std::shared_ptr LzmaUtil::Compress(const std::shared_ptr& pixelData) { +std::shared_ptr LzmaUtil::Compress(const std::shared_ptr& pixelData) { Lzma2Encoder encoder; return encoder.code(pixelData); } @@ -211,7 +211,7 @@ class Lzma2Decoder { } } - std::shared_ptr code(const std::shared_ptr& inputData) { + std::shared_ptr code(const std::shared_ptr& inputData) { if (decoder == nullptr || inputData == nullptr || inputData->size() == 0) { return nullptr; } @@ -241,7 +241,7 @@ class Lzma2Decoder { auto res = Lzma2DecMt_Decode(decoder, prop, &props, &outWrap.vt, &outBufferSize, 1, &inWrap.vt, &inProcessed, &isMT, nullptr); if (res == SZ_OK && inputSize == inProcessed) { - return Data::MakeAdopted(outBuffer, outBufferSize, Data::DeleteProc); + return tgfx::Data::MakeAdopted(outBuffer, outBufferSize, tgfx::Data::DeleteProc); } delete[] outBuffer; return nullptr; @@ -251,7 +251,7 @@ class Lzma2Decoder { CLzma2DecMtHandle decoder = nullptr; }; -std::shared_ptr LzmaUtil::Decompress(const std::shared_ptr& data) { +std::shared_ptr LzmaUtil::Decompress(const std::shared_ptr& data) { Lzma2Decoder decoder; return decoder.code(data); } diff --git a/test/framework/utils/LzmaUtil.h b/test/framework/utils/LzmaUtil.h index 04ac701e3b..54d48b1916 100644 --- a/test/framework/utils/LzmaUtil.h +++ b/test/framework/utils/LzmaUtil.h @@ -24,8 +24,8 @@ namespace pag { class LzmaUtil { public: - static std::shared_ptr Compress(const std::shared_ptr& pixelData); + static std::shared_ptr Compress(const std::shared_ptr& pixelData); - static std::shared_ptr Decompress(const std::shared_ptr& data); + static std::shared_ptr Decompress(const std::shared_ptr& data); }; } // namespace pag diff --git a/test/framework/utils/PAGTestUtils.cpp b/test/framework/utils/PAGTestUtils.cpp index 1cf6066743..70ea8e7183 100644 --- a/test/framework/utils/PAGTestUtils.cpp +++ b/test/framework/utils/PAGTestUtils.cpp @@ -17,9 +17,11 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "PAGTestUtils.h" +#include "base/utils/TGFXCast.h" #include "core/Image.h" namespace pag { +using namespace tgfx; std::shared_ptr MakeSnapshot(std::shared_ptr pagSurface) { auto pixelBuffer = PixelBuffer::Make(pagSurface->width(), pagSurface->height(), false, false); @@ -27,7 +29,7 @@ std::shared_ptr MakeSnapshot(std::shared_ptr pagSurface return nullptr; } Bitmap bitmap(pixelBuffer); - auto result = pagSurface->readPixels(bitmap.colorType(), bitmap.alphaType(), + auto result = pagSurface->readPixels(ToPAG(bitmap.colorType()), ToPAG(bitmap.alphaType()), bitmap.writablePixels(), bitmap.rowBytes()); return result ? pixelBuffer : nullptr; } diff --git a/test/framework/utils/PAGTestUtils.h b/test/framework/utils/PAGTestUtils.h index 77ab924f85..102f20cce0 100644 --- a/test/framework/utils/PAGTestUtils.h +++ b/test/framework/utils/PAGTestUtils.h @@ -20,12 +20,13 @@ #include "Baseline.h" #include "base/utils/GetTimer.h" +#include "base/utils/TGFXCast.h" #include "core/Bitmap.h" #include "core/PixelBuffer.h" #include "pag/pag.h" namespace pag { -std::shared_ptr MakeSnapshot(std::shared_ptr pagSurface); +std::shared_ptr MakeSnapshot(std::shared_ptr pagSurface); std::shared_ptr GetLayer(std::shared_ptr root, LayerType type, int& targetIndex); diff --git a/tgfx/include/core/Bitmap.h b/tgfx/include/core/Bitmap.h index e92e33ce57..c6b4c20e9e 100644 --- a/tgfx/include/core/Bitmap.h +++ b/tgfx/include/core/Bitmap.h @@ -23,7 +23,7 @@ #include "core/ImageInfo.h" #include "core/PixelBuffer.h" -namespace pag { +namespace tgfx { /** * Bitmap is a low level class which provides convenience functions to access raster destinations, * which provides a utility to convert the format of pixels from one to another or compress the @@ -147,9 +147,4 @@ class Bitmap { void* _writablePixels = nullptr; std::shared_ptr pixelBuffer = nullptr; }; - -/** - * Trace() provides a utility to view the Bitmap. - */ -void Trace(const Bitmap& bitmap, const std::string& tag = ""); -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/include/core/Blend.h b/tgfx/include/core/BlendMode.h similarity index 98% rename from tgfx/include/core/Blend.h rename to tgfx/include/core/BlendMode.h index 2cc9e83dfb..830a1292c7 100644 --- a/tgfx/include/core/Blend.h +++ b/tgfx/include/core/BlendMode.h @@ -18,11 +18,11 @@ #pragma once -namespace pag { +namespace tgfx { /** * Defines constant values for visual blend mode effects. */ -enum class Blend { +enum class BlendMode { /** * Replaces destination with zero: fully transparent. */ @@ -140,4 +140,4 @@ enum class Blend { */ Luminosity }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/utils/BytesKey.h b/tgfx/include/core/BytesKey.h similarity index 98% rename from tgfx/src/core/utils/BytesKey.h rename to tgfx/include/core/BytesKey.h index 48bd2fee55..1755682b0b 100644 --- a/tgfx/src/core/utils/BytesKey.h +++ b/tgfx/include/core/BytesKey.h @@ -21,7 +21,7 @@ #include #include -namespace pag { +namespace tgfx { /** * A key used for hashing a byte stream. */ @@ -74,4 +74,4 @@ class BytesKey { struct BytesHasher { size_t operator()(const BytesKey& key) const; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/Color4f.h b/tgfx/include/core/Color.h similarity index 86% rename from tgfx/include/core/Color4f.h rename to tgfx/include/core/Color.h index 86f6c25bca..02200002d6 100644 --- a/tgfx/include/core/Color4f.h +++ b/tgfx/include/core/Color.h @@ -18,16 +18,17 @@ #pragma once +#include #include #include -namespace pag { +namespace tgfx { /** * RGBA color value, holding four floating point components. Color components are always in a known * order. */ -struct Color4f { +struct Color { /** * Red component. */ @@ -51,39 +52,39 @@ struct Color4f { /** * Returns an invalid Color. */ - static const Color4f& Invalid(); + static const Color& Invalid(); /** * Returns a fully transparent Color. */ - static const Color4f& Transparent(); + static const Color& Transparent(); /** * Returns a fully opaque black Color. */ - static const Color4f& Black(); + static const Color& Black(); /** * Returns a fully opaque white Color. */ - static const Color4f& White(); + static const Color& White(); /** * Returns color value from 8-bit component values. */ - static Color4f FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); + static Color FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); /** * Compares Color with other, and returns true if all components are equal. */ - bool operator==(const Color4f& other) const { + bool operator==(const Color& other) const { return alpha == other.alpha && red == other.red && green == other.green && blue == other.blue; } /** * Compares Color with other, and returns true if not all components are equal. */ - bool operator!=(const Color4f& other) const { + bool operator!=(const Color& other) const { return !(*this == other); } @@ -128,20 +129,20 @@ struct Color4f { /** * Returns a Color with alpha set to 1.0. */ - Color4f makeOpaque() const { + Color makeOpaque() const { return {red, green, blue, 1.0f}; } /** * Returns a Color premultiplied by alpha. */ - Color4f premultiply() const { + Color premultiply() const { return {red * alpha, green * alpha, blue * alpha, alpha}; } /** * Returns a Color unpremultiplied by alpha. */ - Color4f unpremultiply() const; + Color unpremultiply() const; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/Data.h b/tgfx/include/core/Data.h index c28702b61c..ccb41e5402 100644 --- a/tgfx/include/core/Data.h +++ b/tgfx/include/core/Data.h @@ -21,7 +21,7 @@ #include #include -namespace pag { +namespace tgfx { /** * Data holds an immutable data buffer. Not only is the data immutable, but the actual ptr that is * returned (by data() or bytes()) is guaranteed to always be the same for the life of this @@ -106,4 +106,4 @@ class Data { Data(const void* data, size_t length, ReleaseProc releaseProc, void* context); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/EncodedFormat.h b/tgfx/include/core/EncodedFormat.h index a8b5bdd57e..9ccee513dd 100644 --- a/tgfx/include/core/EncodedFormat.h +++ b/tgfx/include/core/EncodedFormat.h @@ -18,11 +18,11 @@ #pragma once -namespace pag { +namespace tgfx { /** * Describes the known formats a Bitmap can be encoded into. */ enum class EncodedFormat { JPEG, PNG, WEBP }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/Font.h b/tgfx/include/core/Font.h index f2772cef78..59d75b3bb9 100644 --- a/tgfx/include/core/Font.h +++ b/tgfx/include/core/Font.h @@ -20,7 +20,7 @@ #include "core/Typeface.h" -namespace pag { +namespace tgfx { /** * Font controls options applied when drawing and measuring text. */ @@ -155,4 +155,4 @@ class Font { bool fauxBold = false; bool fauxItalic = false; }; -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/include/core/FontMetrics.h b/tgfx/include/core/FontMetrics.h index 4beeb7bddb..76186452d3 100644 --- a/tgfx/include/core/FontMetrics.h +++ b/tgfx/include/core/FontMetrics.h @@ -18,7 +18,7 @@ #pragma once -namespace pag { +namespace tgfx { class FontMetrics { public: /** @@ -79,4 +79,4 @@ struct GlyphMetrics { float advanceX = 0; float advanceY = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/Image.h b/tgfx/include/core/Image.h index 56e1256363..3dd5f8dbfa 100644 --- a/tgfx/include/core/Image.h +++ b/tgfx/include/core/Image.h @@ -23,7 +23,7 @@ #include "core/ImageInfo.h" #include "core/Orientation.h" -namespace pag { +namespace tgfx { class TextureBuffer; @@ -101,4 +101,4 @@ class Image { friend class Bitmap; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/ImageInfo.h b/tgfx/include/core/ImageInfo.h index 8454490404..228efbfa83 100644 --- a/tgfx/include/core/ImageInfo.h +++ b/tgfx/include/core/ImageInfo.h @@ -18,9 +18,60 @@ #pragma once -#include "pag/types.h" +#include +#include +#include + +namespace tgfx { +/** + * Describes how to interpret the alpha component of a pixel. + */ +enum class AlphaType { + /** + * uninitialized. + */ + Unknown, + /** + * pixel is opaque. + */ + Opaque, + /** + * pixel components are premultiplied by alpha. + */ + Premultiplied, + /** + * pixel components are independent of alpha. + */ + Unpremultiplied, +}; + +/** + * Describes how pixel bits encode color. These values match up with the enum in Bitmap.Config on + * Android platform. + */ +enum class ColorType { + /** + * uninitialized. + */ + Unknown, + /** + * Each pixel is stored as a single translucency (alpha) channel. This is very useful to + * efficiently store masks for instance. No color information is stored. With this configuration, + * each pixel requires 1 byte of memory. + */ + ALPHA_8, + /** + * Each pixel is stored on 4 bytes. Each channel (RGB and alpha for translucency) is stored with 8 + * bits of precision (256 possible values). The channel order is: red, green, blue, alpha. + */ + RGBA_8888, + /** + * Each pixel is stored on 4 bytes. Each channel (RGB and alpha for translucency) is stored with 8 + * bits of precision (256 possible values). The channel order is: blue, green, red, alpha. + */ + BGRA_8888, +}; -namespace pag { /** * ImageInfo describes the properties for an area of pixels. */ @@ -164,4 +215,4 @@ class ImageInfo { AlphaType _alphaType = AlphaType::Unknown; size_t _rowBytes = 0; }; -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/include/core/ImageOrigin.h b/tgfx/include/core/ImageOrigin.h new file mode 100644 index 0000000000..b3584e9212 --- /dev/null +++ b/tgfx/include/core/ImageOrigin.h @@ -0,0 +1,39 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +namespace tgfx { +/** + * Textures and FrameBuffers can be stored such that (0, 0) in texture space may correspond to + * either the top-left or bottom-left content pixel. + */ +enum class ImageOrigin { + /** + * The default origin for all off-screen rendering. Use ImageOrigin::TopLeft origin for textures + * which are from HardwareBuffers (Android), CVPixelBuffers (iOS), or normally created by backend + * APIs. Note: ImageOrigin::TopLeft is actual bottom-left origin for OpenGL backend. + */ + TopLeft, + /** + * Use this origin to flip the content on y-axis if the GPU backend has different origin to your + * system views. It is usually used when on-screen rendering. + */ + BottomLeft +}; +} // namespace tgfx diff --git a/tgfx/include/core/Mask.h b/tgfx/include/core/Mask.h index 1f2dddc0db..2196d74cdf 100644 --- a/tgfx/include/core/Mask.h +++ b/tgfx/include/core/Mask.h @@ -24,7 +24,7 @@ #include "core/TextBlob.h" #include "gpu/TextureBuffer.h" -namespace pag { +namespace tgfx { /** * Mask is a utility that can take an image described in a vector graphics format (paths, glyphs) * and convert it into a raster image that can be used as a drawing mask. Mask is not thread safe, @@ -86,4 +86,4 @@ class Mask : public TextureBuffer { Mask(int width, int height) : TextureBuffer(width, height) { } }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/Matrix.h b/tgfx/include/core/Matrix.h new file mode 100644 index 0000000000..8c18072d3a --- /dev/null +++ b/tgfx/include/core/Matrix.h @@ -0,0 +1,707 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "core/Rect.h" + +namespace tgfx { +/*** + * Matrix holds a 3x3 matrix for transforming coordinates. This allows mapping Point and vectors + * with translation, scaling, skewing, rotation, and perspective. + * Matrix elements are in row major order. Matrix does not have a constructor, so it must be + * explicitly initialized. setIdentity() initializes Matrix so it has no effect. + * setTranslate(), setScale(), setSkew(), setRotate(), set9 and setAll() initializes all Matrix + * elements with the corresponding mapping. + */ +class Matrix { + public: + /** + * Sets Matrix to scale by (sx, sy). Returned matrix is: + * + * | sx 0 0 | + * | 0 sy 0 | + * | 0 0 1 | + * + * @param sx horizontal scale factor + * @param sy vertical scale factor + * @return Matrix with scale + */ + static Matrix MakeScale(float sx, float sy) { + Matrix m = {}; + m.setScale(sx, sy); + return m; + } + + /** + * Sets Matrix to scale by (scale, scale). Returned matrix is: + * + * | scale 0 0 | + * | 0 scale 0 | + * | 0 0 1 | + * + * @param scale horizontal and vertical scale factor + * @return Matrix with scale + */ + static Matrix MakeScale(float scale) { + Matrix m = {}; + m.setScale(scale, scale); + return m; + } + + /** + * Sets Matrix to translate by (dx, dy). Returned matrix is: + * + * | 1 0 dx | + * | 0 1 dy | + * | 0 0 1 | + * + * @param dx horizontal translation + * @param dy vertical translation + * @return Matrix with translation + */ + static Matrix MakeTrans(float dx, float dy) { + Matrix m = {}; + m.setTranslate(dx, dy); + return m; + } + + /** + * Sets Matrix to: + * + * | scaleX skewX transX | + * | skewY scaleY transY | + * | pers0 pers1 pers2 | + * + * @param scaleX horizontal scale factor + * @param skewX horizontal skew factor + * @param transX horizontal translation + * @param skewY vertical skew factor + * @param scaleY vertical scale factor + * @param transY vertical translation + * @param pers0 input x-axis perspective factor + * @param pers1 input y-axis perspective factor + * @param pers2 perspective scale factor + * @return Matrix constructed from parameters + */ + static Matrix MakeAll(float scaleX, float skewX, float transX, float skewY, float scaleY, + float transY, float pers0, float pers1, float pers2) { + Matrix m = {}; + m.setAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2); + return m; + } + + /** + * Returns true if Matrix is identity. Identity matrix is: + * + * | 1 0 0 | + * | 0 1 0 | + * | 0 0 1 | + * + * @return true if Matrix has no effect + */ + bool isIdentity() const { + return values[0] == 1 && values[1] == 0 && values[2] == 0 && values[3] == 0 && values[4] == 1 && + values[5] == 0 && values[6] == 0 && values[7] == 0 && values[8] == 1; + } + + /** + * Returns one matrix value. + */ + float operator[](int index) const { + return values[index]; + } + + /** + * Returns one matrix value. + */ + float get(int index) const { + return values[index]; + } + + /** + * Returns scale factor multiplied by x-axis input, contributing to x-axis output. With + * mapPoints(), scales Point along the x-axis. + * @return horizontal scale factor + */ + float getScaleX() const { + return values[SCALE_X]; + } + + /** + * Returns scale factor multiplied by y-axis input, contributing to y-axis output. With + * mapPoints(), scales Point along the y-axis. + * @return vertical scale factor + */ + float getScaleY() const { + return values[SCALE_Y]; + } + + /** + * Returns scale factor multiplied by x-axis input, contributing to y-axis output. With + * mapPoints(), skews Point along the y-axis. Skewing both axes can rotate Point. + * @return vertical skew factor + */ + float getSkewY() const { + return values[SKEW_Y]; + } + + /** + * Returns scale factor multiplied by y-axis input, contributing to x-axis output. With + * mapPoints(), skews Point along the x-axis. Skewing both axes can rotate Point. + * @return horizontal scale factor + */ + float getSkewX() const { + return values[SKEW_X]; + } + + /** + * Returns translation contributing to x-axis output. With mapPoints(), moves Point along the + * x-axis. + * @return horizontal translation factor + */ + float getTranslateX() const { + return values[TRANS_X]; + } + + /** + * Returns translation contributing to y-axis output. With mapPoints(), moves Point along the + * y-axis. + * @return vertical translation factor + */ + float getTranslateY() const { + return values[TRANS_Y]; + } + + /** + * Returns writable Matrix value. + */ + float& operator[](int index) { + return values[index]; + } + + /** + * Sets Matrix value. + */ + void set(int index, float value) { + values[index] = value; + } + + /** + * Sets horizontal scale factor. + * @param v horizontal scale factor to store + */ + void setScaleX(float v) { + this->set(SCALE_X, v); + } + + /** + * Sets vertical scale factor. + * @param v vertical scale factor to store + */ + void setScaleY(float v) { + this->set(SCALE_Y, v); + } + + /** + * Sets vertical skew factor. + * @param v vertical skew factor to store + */ + void setSkewY(float v) { + this->set(SKEW_Y, v); + } + + /** + * Sets horizontal skew factor. + * @param v horizontal skew factor to store + */ + void setSkewX(float v) { + this->set(SKEW_X, v); + } + + /** + * Sets horizontal translation. + * @param v horizontal translation to store + */ + void setTranslateX(float v) { + this->set(TRANS_X, v); + } + + /** + * Sets vertical translation. + * @param v vertical translation to store + */ + void setTranslateY(float v) { + this->set(TRANS_Y, v); + } + + /** + * Sets all values from parameters. Sets matrix to: + * + * | scaleX skewX transX | + * | skewY scaleY transY | + * | persp0 persp1 persp2 | + * + * @param scaleX horizontal scale factor to store + * @param skewX horizontal skew factor to store + * @param transX horizontal translation to store + * @param skewY vertical skew factor to store + * @param scaleY vertical scale factor to store + * @param transY vertical translation to store + * @param persp0 input x-axis values perspective factor to store + * @param persp1 input y-axis values perspective factor to store + * @param persp2 perspective scale factor to store + */ + void setAll(float scaleX, float skewX, float transX, float skewY, float scaleY, float transY, + float persp0, float persp1, float persp2); + + void setAffine(float a, float b, float c, float d, float tx, float ty); + + /** + * Copies nine scalar values contained by Matrix into buffer, in member value ascending order: + * ScaleX, SkewX, TransX, SkewY, ScaleY, TransY, Persp0, Persp1, Persp2. + * @param buffer storage for nine scalar values + */ + void get9(float buffer[9]) const { + memcpy(buffer, values, 9 * sizeof(float)); + } + + /** + * Sets Matrix to nine scalar values in buffer, in member value ascending order: ScaleX, + * SkewX, TransX, SkewY, ScaleY, TransY, Persp0, Persp1, Persp2. + * + * Sets matrix to: + * + * | buffer[0] buffer[1] buffer[2] | + * | buffer[3] buffer[4] buffer[5] | + * | buffer[6] buffer[7] buffer[8] | + * + * @param buffer nine scalar values + */ + void set9(const float buffer[9]) { + memcpy(values, buffer, 9 * sizeof(float)); + } + + /** + * Sets Matrix to identity; which has no effect on mapped Point. Sets Matrix to: + * + * | 1 0 0 | + * | 0 1 0 | + * | 0 0 1 | + * + * Also called setIdentity(); use the one that provides better inline documentation. + */ + void reset(); + + /** + * Sets Matrix to identity; which has no effect on mapped Point. Sets Matrix to: + * + * | 1 0 0 | + * | 0 1 0 | + * | 0 0 1 | + * + * Also called reset(); use the one that provides better inline documentation. + */ + void setIdentity() { + this->reset(); + } + + /** + * Sets Matrix to translate by (dx, dy). + * @param dx horizontal translation + * @param dy vertical translation + */ + void setTranslate(float dx, float dy); + + /** + * Sets Matrix to scale by sx and sy, about a pivot point at (px, py). The pivot point is + * unchanged when mapped with Matrix. + * @param sx horizontal scale factor + * @param sy vertical scale factor + * @param px pivot on x-axis + * @param py pivot on y-axis + */ + void setScale(float sx, float sy, float px, float py); + + /** + * Sets Matrix to scale by sx and sy about at pivot point at (0, 0). + * @param sx horizontal scale factor + * @param sy vertical scale factor + */ + void setScale(float sx, float sy); + + /** + * Sets Matrix to rotate by degrees about a pivot point at (px, py). The pivot point is + * unchanged when mapped with Matrix. Positive degrees rotates clockwise. + * @param degrees angle of axes relative to upright axes + * @param px pivot on x-axis + * @param py pivot on y-axis + */ + void setRotate(float degrees, float px, float py); + + /** + * Sets Matrix to rotate by degrees about a pivot point at (0, 0). Positive degrees rotates + * clockwise. + * @param degrees angle of axes relative to upright axes + */ + void setRotate(float degrees); + + /** + * Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (px, py). + * The pivot point is unchanged when mapped with Matrix. + * Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). + * Vector length specifies scale. + */ + void setSinCos(float sinV, float cosV, float px, float py); + + /** + * Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (0, 0). + * Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). + * Vector length specifies scale. + */ + void setSinCos(float sinV, float cosV); + + /** + * Sets Matrix to skew by kx and ky, about a pivot point at (px, py). The pivot point is + * unchanged when mapped with Matrix. + * @param kx horizontal skew factor + * @param ky vertical skew factor + * @param px pivot on x-axis + * @param py pivot on y-axis + */ + void setSkew(float kx, float ky, float px, float py); + + /** + * Sets Matrix to skew by kx and ky, about a pivot point at (0, 0). + * @param kx horizontal skew factor + * @param ky vertical skew factor + */ + void setSkew(float kx, float ky); + + /** + * Sets Matrix to Matrix a multiplied by Matrix b. Either a or b may be this. + * + * Given: + * + * | A B C | | J K L | + * a = | D E F |, b = | M N O | + * | G H I | | P Q R | + * + * sets Matrix to: + * + * | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | + * a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR | + * | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR | + * + * @param a Matrix on left side of multiply expression + * @param b Matrix on right side of multiply expression + */ + void setConcat(const Matrix& a, const Matrix& b); + + /** + * Preconcats the matrix with the specified scale. M' = M * S(sx, sy) + */ + void preTranslate(float dx, float dy); + + /** + * Postconcats the matrix with the specified scale. M' = S(sx, sy, px, py) * M + */ + void preScale(float sx, float sy, float px, float py); + + /** + * Preconcats the matrix with the specified scale. M' = M * S(sx, sy) + */ + void preScale(float sx, float sy); + + /** + * Preconcats the matrix with the specified rotation. M' = M * R(degrees, px, py) + */ + void preRotate(float degrees, float px, float py); + + /** + * Preconcats the matrix with the specified rotation. M' = M * R(degrees) + */ + void preRotate(float degrees); + + /** + * Preconcats the matrix with the specified skew. M' = M * K(kx, ky, px, py) + */ + void preSkew(float kx, float ky, float px, float py); + + /** + * Preconcats the matrix with the specified skew. M' = M * K(kx, ky) + */ + void preSkew(float kx, float ky); + + /** + * Preconcats the matrix with the specified matrix. M' = M * other + */ + void preConcat(const Matrix& other); + + /** + * Postconcats the matrix with the specified translation. M' = T(dx, dy) * M + */ + void postTranslate(float dx, float dy); + + /** + * Postconcats the matrix with the specified scale. M' = S(sx, sy, px, py) * M + */ + void postScale(float sx, float sy, float px, float py); + + /** + * Postconcats the matrix with the specified scale. M' = S(sx, sy) * M + */ + void postScale(float sx, float sy); + + /** + * Postconcats the matrix with the specified rotation. M' = R(degrees, px, py) * M + */ + void postRotate(float degrees, float px, float py); + + /** + * Postconcats the matrix with the specified rotation. M' = R(degrees) * M + */ + void postRotate(float degrees); + + /** + * Postconcats the matrix with the specified skew. M' = K(kx, ky, px, py) * M + */ + void postSkew(float kx, float ky, float px, float py); + + /** + * Postconcats the matrix with the specified skew. M' = K(kx, ky) * M + */ + void postSkew(float kx, float ky); + + /** + * Postconcats the matrix with the specified matrix. M' = other * M + */ + void postConcat(const Matrix& other); + + /** + * If this matrix can be inverted, return true and if inverse is not null, set inverse to be the + * inverse of this matrix. If this matrix cannot be inverted, ignore inverse and return false. + */ + bool invert(Matrix* inverse) const { + if (this->isIdentity()) { + if (inverse) { + inverse->reset(); + } + return true; + } + return this->invertNonIdentity(inverse); + } + + bool invertible() const; + + /** + * Maps src Point array of length count to dst Point array of equal or greater length. Point are + * mapped by multiplying each Point by Matrix. Given: + * + * | A B C | | x | + * Matrix = | D E F |, pt = | y | + * | G H I | | 1 | + * + * where + * + * for (i = 0; i < count; ++i) { + * x = src[i].fX + * y = src[i].fY + * } + * + * each dst Point is computed as: + * + * |A B C| |x| Ax+By+C Dx+Ey+F + * Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , ------- + * |G H I| |1| Gx+Hy+I Gx+Hy+I + * + * src and dst may point to the same storage. + * + * @param dst storage for mapped Point + * @param src Point to transform + * @param count number of Point to transform + */ + void mapPoints(Point dst[], const Point src[], int count) const; + + /** + * Maps pts Point array of length count in place. Point are mapped by multiplying each Point by + * Matrix. Given: + * + * | A B C | | x | + * Matrix = | D E F |, pt = | y | + * | G H I | | 1 | + * + * where + * + * for (i = 0; i < count; ++i) { + * x = pts[i].fX + * y = pts[i].fY + * } + * + * each resulting pts Point is computed as: + * + * |A B C| |x| Ax+By+C Dx+Ey+F + * Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , ------- + * |G H I| |1| Gx+Hy+I Gx+Hy+I + * + * @param pts storage for mapped Point + * @param count number of Point to transform + */ + void mapPoints(Point pts[], int count) const { + this->mapPoints(pts, pts, count); + } + + /** + * Maps Point (x, y) to result. Point is mapped by multiplying by Matrix. Given: + * + * | A B C | | x | + * Matrix = | D E F |, pt = | y | + * | G H I | | 1 | + * + * result is computed as: + * + * |A B C| |x| Ax+By+C Dx+Ey+F + * Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , ------- + * |G H I| |1| Gx+Hy+I Gx+Hy+I + * + * @param x x-axis value of Point to map + * @param y y-axis value of Point to map + * @param result storage for mapped Point + */ + void mapXY(float x, float y, Point* result) const; + + /** + * Returns Point (x, y) multiplied by Matrix. Given: + * + * | A B C | | x | + * Matrix = | D E F |, pt = | y | + * | G H I | | 1 | + * + * result is computed as: + * + * |A B C| |x| Ax+By+C Dx+Ey+F + * Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , ------- + * |G H I| |1| Gx+Hy+I Gx+Hy+I + * + * @param x x-axis value of Point to map + * @param y y-axis value of Point to map + * @return mapped Point + */ + Point mapXY(float x, float y) const { + Point result = {}; + this->mapXY(x, y, &result); + return result; + } + + /** + * Sets dst to bounds of src corners mapped by Matrix. + */ + void mapRect(Rect* dst, const Rect& src) const; + + /** + * Sets rect to bounds of rect corners mapped by Matrix. Returns true if mapped corners are + * computed rect corners. Returned value is the same as calling rectStaysRect(). + */ + void mapRect(Rect* rect) const { + mapRect(rect, *rect); + } + + /** + * Returns bounds of src corners mapped by Matrix. + */ + Rect mapRect(const Rect& src) const { + Rect dst = {}; + mapRect(&dst, src); + return dst; + } + + /** Compares a and b; returns true if a and b are numerically equal. Returns true even if sign + * of zero values are different. Returns false if either Matrix contains NaN, even if the other + * Matrix also contains NaN. + */ + friend bool operator==(const Matrix& a, const Matrix& b); + + /** + * Compares a and b; returns true if a and b are not numerically equal. Returns false even if + * sign of zero values are different. Returns true if either Matrix contains NaN, even if the + * other Matrix also contains NaN. + */ + friend bool operator!=(const Matrix& a, const Matrix& b) { + return !(a == b); + } + + /** + * Returns the minimum scaling factor of Matrix by decomposing the scaling and skewing elements. + * Returns -1 if scale factor overflows or Matrix contains perspective. + */ + float getMinScale() const; + + /** + * Returns the maximum scaling factor of Matrix by decomposing the scaling and skewing elements. + * Returns -1 if scale factor overflows or Matrix contains perspective. + */ + float getMaxScale() const; + + /** + * Returns true if all elements of the matrix are finite. Returns false if any + * element is infinity, or NaN. + */ + bool isFinite() const; + + /** + * Returns reference to const identity Matrix. Returned Matrix is set to: + * + * | 1 0 0 | + * | 0 1 0 | + * | 0 0 1 | + * + * @return const identity Matrix + */ + static const Matrix& I(); + + /** + * Returns reference to a const Matrix with invalid values. Returned Matrix is set to: + * + * | FLT_MAX FLT_MAX FLT_MAX | + * | FLT_MAX FLT_MAX FLT_MAX | + * | FLT_MAX FLT_MAX FLT_MAX | + * + * @return const invalid Matrix + */ + static const Matrix& Invalid(); + + private: + float values[9]; + /** + * Matrix organizes its values in row order. These members correspond to each value in Matrix. + */ + static constexpr int SCALE_X = 0; //!< horizontal scale factor + static constexpr int SKEW_X = 1; //!< horizontal skew factor + static constexpr int TRANS_X = 2; //!< horizontal translation + static constexpr int SKEW_Y = 3; //!< vertical skew factor + static constexpr int SCALE_Y = 4; //!< vertical scale factor + static constexpr int TRANS_Y = 5; //!< vertical translation + static constexpr int PERSP_0 = 6; //!< input x perspective factor + static constexpr int PERSP_1 = 7; //!< input y perspective factor + static constexpr int PERSP_2 = 8; //!< perspective bias + + void setScaleTranslate(float sx, float sy, float tx, float ty); + bool invertNonIdentity(Matrix* inverse) const; + bool getMinMaxScaleFactors(float results[2]) const; +}; +} // namespace tgfx diff --git a/tgfx/include/core/Orientation.h b/tgfx/include/core/Orientation.h index 801f111032..cde3ed2f97 100644 --- a/tgfx/include/core/Orientation.h +++ b/tgfx/include/core/Orientation.h @@ -18,9 +18,9 @@ #pragma once -#include "pag/types.h" +#include "core/Matrix.h" -namespace pag { +namespace tgfx { /** * These values match the orientation www.exif.org/Exif2-2.PDF. */ @@ -66,4 +66,4 @@ enum class Orientation { */ Matrix OrientationToMatrix(Orientation orientation, int width, int height); -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/Path.h b/tgfx/include/core/Path.h index 76371f1fac..799772c50f 100644 --- a/tgfx/include/core/Path.h +++ b/tgfx/include/core/Path.h @@ -18,10 +18,10 @@ #pragma once +#include "core/Matrix.h" #include "core/PathTypes.h" -#include "pag/types.h" -namespace pag { +namespace tgfx { class PathRef; /** @@ -244,4 +244,4 @@ class Path { friend class PathRef; }; -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/include/core/PathEffect.h b/tgfx/include/core/PathEffect.h index 71f8f29ca8..36d7ba8a55 100644 --- a/tgfx/include/core/PathEffect.h +++ b/tgfx/include/core/PathEffect.h @@ -21,7 +21,7 @@ #include "core/Path.h" #include "core/Stroke.h" -namespace pag { +namespace tgfx { /** * PathEffect applies transformation to a Path. */ @@ -57,4 +57,4 @@ class PathEffect { */ virtual bool applyTo(Path* path) const = 0; }; -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/include/core/PathMeasure.h b/tgfx/include/core/PathMeasure.h index bf554d98f9..4559979420 100644 --- a/tgfx/include/core/PathMeasure.h +++ b/tgfx/include/core/PathMeasure.h @@ -20,7 +20,7 @@ #include "core/Path.h" -namespace pag { +namespace tgfx { /** * PathMeasure calculates the length of a Path and cuts child segments from it. */ @@ -45,4 +45,4 @@ class PathMeasure { */ virtual bool getSegment(float startD, float stopD, Path* result) = 0; }; -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/include/core/PathTypes.h b/tgfx/include/core/PathTypes.h index a0e127fdae..35943d3aac 100644 --- a/tgfx/include/core/PathTypes.h +++ b/tgfx/include/core/PathTypes.h @@ -18,9 +18,10 @@ #pragma once -#include "pag/types.h" +#include +#include "core/Point.h" -namespace pag { +namespace tgfx { /** * PathFillType selects the rule used to fill Path. */ @@ -100,4 +101,4 @@ enum class PathVerb { */ using PathIterator = std::function; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/Performance.h b/tgfx/include/core/Performance.h new file mode 100644 index 0000000000..d1e68ab793 --- /dev/null +++ b/tgfx/include/core/Performance.h @@ -0,0 +1,31 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include + +namespace tgfx { +class Performance { + public: + /** + * Returns the number of microseconds since the runtime was initialized. + */ + static int64_t Now(); +}; +} // namespace tgfx diff --git a/tgfx/include/core/PixelBuffer.h b/tgfx/include/core/PixelBuffer.h index e3798be0ad..69e3c26579 100644 --- a/tgfx/include/core/PixelBuffer.h +++ b/tgfx/include/core/PixelBuffer.h @@ -21,7 +21,7 @@ #include "core/ImageInfo.h" #include "gpu/TextureBuffer.h" -namespace pag { +namespace tgfx { /** * PixelBuffer describes a two dimensional array of pixels which is optimized for creating textures. */ @@ -120,9 +120,4 @@ class PixelBuffer : public TextureBuffer { */ static std::shared_ptr MakeHardwareBuffer(int width, int height, bool alphaOnly); }; - -/** - * Trace() provides a utility to view the PixelBuffer. - */ -void Trace(std::shared_ptr pixelBuffer, const std::string& tag = ""); -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/include/core/Point.h b/tgfx/include/core/Point.h new file mode 100644 index 0000000000..0a73c51d6d --- /dev/null +++ b/tgfx/include/core/Point.h @@ -0,0 +1,126 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include + +namespace tgfx { +/** + * Point holds two 32-bit floating point coordinates. + */ +struct Point { + /** + * x-axis value. + */ + float x; + /** + * y-axis value. + */ + float y; + + /** + * Creates a Point set to (0, 0). + */ + static const Point& Zero() { + static const Point zero = Point::Make(0, 0); + return zero; + } + + /** + * Creates a Point with specified x and y value. + */ + static constexpr Point Make(float x, float y) { + return {x, y}; + } + + /** + * Returns true if fX and fY are both zero. + */ + bool isZero() const { + return (0 == x) & (0 == y); + } + + /** + * Sets fX to x and fY to y. + */ + void set(float xValue, float yValue) { + x = xValue; + y = yValue; + } + + /** + * Adds offset (dx, dy) to Point. + */ + void offset(float dx, float dy) { + x += dx; + y += dy; + } + + /** + * Returns the Euclidean distance from origin. + */ + float length() const { + return Point::Length(x, y); + } + + /** + * Returns true if a is equivalent to b. + */ + friend bool operator==(const Point& a, const Point& b) { + return a.x == b.x && a.y == b.y; + } + + /** + * Returns true if a is not equivalent to b. + */ + friend bool operator!=(const Point& a, const Point& b) { + return a.x != b.x || a.y != b.y; + } + + /** + * Returns a Point from b to a; computed as (a.fX - b.fX, a.fY - b.fY). + */ + friend Point operator-(const Point& a, const Point& b) { + return {a.x - b.x, a.y - b.y}; + } + + /** + * Returns Point resulting from Point a offset by Point b, computed as: + * (a.fX + b.fX, a.fY + b.fY). + */ + friend Point operator+(const Point& a, const Point& b) { + return {a.x + b.x, a.y + b.y}; + } + + /** + * Returns the Euclidean distance from origin. + */ + static float Length(float x, float y) { + return sqrt(x * x + y * y); + } + + /** + * Returns the Euclidean distance between a and b. + */ + static float Distance(const Point& a, const Point& b) { + return Length(a.x - b.x, a.y - b.y); + } +}; +} // namespace tgfx diff --git a/tgfx/include/core/RGBAAALayout.h b/tgfx/include/core/RGBAAALayout.h index dd218c5048..cd5d598b45 100644 --- a/tgfx/include/core/RGBAAALayout.h +++ b/tgfx/include/core/RGBAAALayout.h @@ -18,7 +18,7 @@ #pragma once -namespace pag { +namespace tgfx { /** * Defines the layout of a RGBAAA format image, which is half RGB, half AAA. */ @@ -40,4 +40,4 @@ struct RGBAAALayout { */ int alphaStartY; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/Rect.h b/tgfx/include/core/Rect.h new file mode 100644 index 0000000000..2a04eb818a --- /dev/null +++ b/tgfx/include/core/Rect.h @@ -0,0 +1,452 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include "core/Point.h" + +namespace tgfx { +/** + * Rect holds four float coordinates describing the upper and lower bounds of a rectangle. Rect may + * be created from outer bounds or from position, width, and height. Rect describes an area; if its + * right is less than or equal to its left, or if its bottom is less than or equal to its top, it is + * considered empty. + */ +struct Rect { + /** + * smaller x-axis bounds. + */ + float left; + /** + * smaller y-axis bounds. + */ + float top; + /** + * larger x-axis bounds. + */ + float right; + /** + * larger y-axis bounds. + */ + float bottom; + + /** + * Returns constructed Rect set to (0, 0, 0, 0). + */ + static constexpr Rect MakeEmpty() { + return {0, 0, 0, 0}; + } + + /** + * Returns constructed Rect set to float values (0, 0, w, h). Does not validate input; w or h may + * be negative. + */ + static constexpr Rect MakeWH(float w, float h) { + return {0, 0, w, h}; + } + + /** + * Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may result in left + * greater than right, or top greater than bottom. + */ + static constexpr Rect MakeLTRB(float l, float t, float r, float b) { + return {l, t, r, b}; + } + + /** + * Returns constructed Rect set to (x, y, x + w, y + h). Does not validate input; w or h may be + * negative. + */ + static constexpr Rect MakeXYWH(float x, float y, float w, float h) { + return {x, y, x + w, y + h}; + } + + /** + * Returns true if left is equal to or greater than right, or if top is equal to or greater + * than bottom. Call sort() to reverse rectangles with negative width() or height(). + */ + bool isEmpty() const { + // We write it as the NOT of a non-empty rect, so we will return true if any values + // are NaN. + return !(left < right && top < bottom); + } + + /** + * Returns true if left is equal to or less than right, or if top is equal to or less than + * bottom. Call sort() to reverse rectangles with negative width() or height(). + */ + bool isSorted() const { + return left <= right && top <= bottom; + } + + /** + * Returns left edge of Rect, if sorted. Call isSorted() to see if Rect is valid. Call sort() to + * reverse left and right if needed. + */ + float x() const { + return left; + } + + /** + * Returns top edge of Rect, if sorted. Call isEmpty() to see if Rect may be invalid, and sort() + * to reverse top and bottom if needed. + */ + float y() const { + return top; + } + + /** + * Returns span on the x-axis. This does not check if Rect is sorted, or if result fits in 32-bit + * float; result may be negative or infinity. + */ + float width() const { + return right - left; + } + + /** + * Returns span on the y-axis. This does not check if Rect is sorted, or if result fits in 32-bit + * float; result may be negative or infinity. + */ + float height() const { + return bottom - top; + } + + /** + * Returns average of left edge and right edge. Result does not change if Rect is sorted. + */ + float centerX() const { + // don't use (left + bottom) * 0.5f as that might overflow before the 0.5f + return left * 0.5f + right * 0.5f; + } + + /** + * Returns average of top edge and bottom edge. Result does not change if Rect is sorted. + */ + float centerY() const { + // don't use (top + bottom) * 0.5f as that might overflow before the 0.5f + return top * 0.5f + bottom * 0.5f; + } + + /** + * Returns true if all members in a: left, top, right, and bottom; are equal to the + * corresponding members in b. + * a and b are not equal if either contain NaN. a and b are equal if members contain zeroes with + * different signs. + */ + friend bool operator==(const Rect& a, const Rect& b) { + return a.left == b.left && a.right == b.right && a.top == b.top && a.bottom == b.bottom; + } + + /** + * Returns true if any in a: left, top, right, and bottom; does not equal the corresponding + * members in b. + * a and b are not equal if either contain NaN. a and b are equal if members contain zeroes with + * different signs. + */ + friend bool operator!=(const Rect& a, const Rect& b) { + return a.left != b.left || a.right != b.right || a.top != b.top || a.bottom != b.bottom; + } + + /** + * Sets Rect to (0, 0, 0, 0). + */ + void setEmpty() { + *this = MakeEmpty(); + } + + /** + * Sets Rect to (left, top, right, bottom). left and right are not sorted; left is not necessarily + * less than right. top and bottom are not sorted; top is not necessarily less than bottom. + */ + void setLTRB(float l, float t, float r, float b) { + left = l; + top = t; + right = r; + bottom = b; + } + + /** + * Sets to bounds of Point array with count entries. Returns false if count is zero or smaller, or + * if Point array contains an infinity or NaN; in these cases sets Rect to (0, 0, 0, 0). + * Result is either empty or sorted: left is less than or equal to right, and top is less than + * or equal to bottom. + */ + bool setBounds(const Point pts[], int count); + + /** + * Sets Rect to (x, y, x + width, y + height). Does not validate input; width or height may be + * negative. + */ + void setXYWH(float x, float y, float width, float height) { + left = x; + top = y; + right = x + width; + bottom = y + height; + } + + /** + * Sets Rect to (0, 0, width, height). Does not validate input, width or height may be negative. + */ + void setWH(float width, float height) { + left = 0; + top = 0; + right = width; + bottom = height; + } + + /** + * Returns Rect offset by (dx, dy). + * If dx is negative, Rect returned is moved to the left. + * If dx is positive, Rect returned is moved to the right. + * If dy is negative, Rect returned is moved upward. + * If dy is positive, Rect returned is moved downward. + */ + Rect makeOffset(float dx, float dy) const { + return MakeLTRB(left + dx, top + dy, right + dx, bottom + dy); + } + + /** + * Returns Rect, inset by (dx, dy). + * If dx is negative, Rect returned is wider. + * If dx is positive, Rect returned is narrower. + * If dy is negative, Rect returned is taller. + * If dy is positive, Rect returned is shorter. + */ + Rect makeInset(float dx, float dy) const { + return MakeLTRB(left + dx, top + dy, right - dx, bottom - dy); + } + + /** + * Returns Rect, outset by (dx, dy). + * If dx is negative, Rect returned is narrower. + * If dx is positive, Rect returned is wider. + * If dy is negative, Rect returned is shorter. + * If dy is positive, Rect returned is taller. + */ + Rect makeOutset(float dx, float dy) const { + return MakeLTRB(left - dx, top - dy, right + dx, bottom + dy); + } + + /** + * Offsets Rect by adding dx to left, right; and by adding dy to top, bottom. + * If dx is negative, moves Rect to the left. + * If dx is positive, moves Rect to the right. + * If dy is negative, moves Rect upward. + * If dy is positive, moves Rect downward. + */ + void offset(float dx, float dy) { + left += dx; + top += dy; + right += dx; + bottom += dy; + } + + /** + * Offsets Rect by adding delta.fX to left, right; and by adding delta.fY to top, bottom. + * If delta.fX is negative, moves Rect to the left. + * If delta.fX is positive, moves Rect to the right. + * If delta.fY is negative, moves Rect upward. + * If delta.fY is positive, moves Rect downward. + */ + void offset(const Point& delta) { + this->offset(delta.x, delta.y); + } + + /** + * Offsets Rect so that left equals newX, and top equals newY. width and height are unchanged. + */ + void offsetTo(float newX, float newY) { + right += newX - left; + bottom += newY - top; + left = newX; + top = newY; + } + + /** + * Insets Rect by (dx, dy). + * If dx is positive, makes Rect narrower. + * If dx is negative, makes Rect wider. + * If dy is positive, makes Rect shorter. + * If dy is negative, makes Rect taller. + */ + void inset(float dx, float dy) { + left += dx; + top += dy; + right -= dx; + bottom -= dy; + } + + /** + * Outsets Rect by (dx, dy). + * If dx is positive, makes Rect wider. + * If dx is negative, makes Rect narrower. + * If dy is positive, makes Rect taller. + * If dy is negative, makes Rect shorter. + */ + void outset(float dx, float dy) { + this->inset(-dx, -dy); + } + + /** + * Scale the rectangle by scaleX and scaleY. + */ + void scale(float scaleX, float scaleY); + + /** + * Returns true if Rect intersects r, and sets Rect to intersection. Returns false if Rect does + * not intersect r, and leaves Rect unchanged. Returns false if either r or Rect is empty, leaving + * Rect unchanged. + */ + bool intersect(const Rect& r) { + return this->intersect(r.left, r.top, r.right, r.bottom); + } + + /** + * Constructs Rect to intersect from (left, top, right, bottom). Does not sort construction. + * Returns true if Rect intersects construction, and sets Rect to intersection. + * Returns false if Rect does not intersect construction, and leaves Rect unchanged. + * Returns false if either construction or Rect is empty, leaving Rect unchanged. + */ + bool intersect(float l, float t, float r, float b); + + /** + * Returns true if a intersects b, and sets Rect to intersection. + * Returns false if a does not intersect b, and leaves Rect unchanged. + * Returns false if either a or b is empty, leaving Rect unchanged. + */ + bool intersect(const Rect& a, const Rect& b); + + /** + * Constructs Rect to intersect from (left, top, right, bottom). Does not sort construction. + * Returns true if Rect intersects construction. + * Returns false if either construction or Rect is empty, or do not intersect. + */ + bool intersects(float l, float t, float r, float b) const { + return Intersects(left, top, right, bottom, l, t, r, b); + } + + /** + * Returns true if Rect intersects r. Returns false if either r or Rect is empty, or do not + * intersect. + */ + bool intersects(const Rect& r) const { + return Intersects(left, top, right, bottom, r.left, r.top, r.right, r.bottom); + } + + /** + * Returns true if a intersects b. Returns false if either a or b is empty, or do not intersect. + */ + static bool Intersects(const Rect& a, const Rect& b) { + return Intersects(a.left, a.top, a.right, a.bottom, b.left, b.top, b.right, b.bottom); + } + + /** + * Constructs Rect to intersect from (left, top, right, bottom). Does not sort construction. + * Sets Rect to the union of itself and the construction. Has no effect if construction is empty. + * Otherwise, if Rect is empty, sets Rect to construction. + */ + void join(float l, float t, float r, float b); + + /** + * Sets Rect to the union of itself and r. Has no effect if r is empty. Otherwise, if Rect is + * empty, sets Rect to r. + */ + void join(const Rect& r) { + this->join(r.left, r.top, r.right, r.bottom); + } + + /** + * Returns true if: left <= x < right && top <= y < bottom. Returns false if Rect is empty. + */ + bool contains(float x, float y) const { + return x >= left && x < right && y >= top && y < bottom; + } + + /** + * Returns true if Rect contains r. Returns false if Rect is empty or r is empty. Rect contains r + * when Rect area completely includes r area. + */ + bool contains(const Rect& r) const { + return left <= r.left && top <= r.top && right >= r.right && bottom >= r.bottom; + } + + /** + * Sets Rect by discarding the fractional portion of left and top; and rounding up right and + * bottom. + */ + void roundOut() { + left = floorf(left); + top = floorf(top); + right = ceilf(right); + bottom = ceilf(bottom); + } + + /** + * Sets Rect by rounding of left, top, right and bottom. + */ + void round() { + left = roundf(left); + top = roundf(top); + right = roundf(right); + bottom = roundf(bottom); + } + + /** + * Swaps left and right if left is greater than right; and swaps top and bottom if top is + * greater than bottom. Result may be empty; and width() and height() will be zero or positive. + */ + void sort() { + if (left > right) { + std::swap(left, right); + } + + if (top > bottom) { + std::swap(top, bottom); + } + } + + /** + * Returns Rect with left and right swapped if left is greater than right, and with top and + * bottom swapped if top is greater than bottom. Result may be empty, and width() and height() + * will be zero or positive. + */ + Rect makeSorted() const { + return MakeLTRB(std::min(left, right), std::min(top, bottom), std::max(left, right), + std::max(top, bottom)); + } + + private: + static bool Intersects(float al, float at, float ar, float ab, float bl, float bt, float br, + float bb) { + float L = al > bl ? al : bl; + float R = ar < br ? ar : br; + float T = at > bt ? at : bt; + float B = ab < bb ? ab : bb; + return L < R && T < B; + } +}; + +/** + * Round Rect. + */ +struct RRect { + Rect rect = Rect::MakeEmpty(); + Point radii = Point::Zero(); +}; +} // namespace tgfx diff --git a/tgfx/include/core/Stream.h b/tgfx/include/core/Stream.h index 4ab72bb1e8..0f16b7ab0f 100644 --- a/tgfx/include/core/Stream.h +++ b/tgfx/include/core/Stream.h @@ -19,8 +19,9 @@ #pragma once #include +#include -namespace pag { +namespace tgfx { /** * Stream represents a source of bytes. Subclasses can be backed by memory, or a file, or something * else. Stream is not thread safe. @@ -64,4 +65,4 @@ class Stream { */ virtual bool rewind() = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/Stroke.h b/tgfx/include/core/Stroke.h index bbca542f0c..625499224e 100644 --- a/tgfx/include/core/Stroke.h +++ b/tgfx/include/core/Stroke.h @@ -18,57 +18,57 @@ #pragma once -namespace pag { +namespace tgfx { /** - * Stroke controls options applied when stroking geometries (paths, glyphs). + * Cap draws at the beginning and end of an open path contour. */ -class Stroke { - public: +enum class LineCap { + /** + * No stroke extension. + */ + Butt, /** - * Cap draws at the beginning and end of an open path contour. + * Adds circle */ - enum class Cap { - /** - * No stroke extension. - */ - Butt, - /** - * Adds circle - */ - Round, - /** - * Adds square - */ - Square - }; + Round, + /** + * Adds square + */ + Square +}; +/** + * Join specifies how corners are drawn when a shape is stroked. Join affects the four corners + * of a stroked rectangle, and the connected segments in a stroked path. Choose miter join to draw + * sharp corners. Choose round join to draw a circle with a radius equal to the stroke width on + * top of the corner. Choose bevel join to minimally connect the thick strokes. + */ +enum class LineJoin { /** - * Join specifies how corners are drawn when a shape is stroked. Join affects the four corners - * of a stroked rectangle, and the connected segments in a stroked path. Choose miter join to draw - * sharp corners. Choose round join to draw a circle with a radius equal to the stroke width on - * top of the corner. Choose bevel join to minimally connect the thick strokes. + * Extends to miter limit. */ - enum class Join { - /** - * Extends to miter limit. - */ - Miter, - /** - * Adds circle. - */ - Round, - /** - * Connects outside edges. - */ - Bevel - }; + Miter, + /** + * Adds circle. + */ + Round, + /** + * Connects outside edges. + */ + Bevel +}; +/** + * Stroke controls options applied when stroking geometries (paths, glyphs). + */ +class Stroke { + public: Stroke() = default; /** * Creates a new Stroke width specified options. */ - explicit Stroke(float width, Cap cap = Cap::Butt, Join join = Join::Miter, + explicit Stroke(float width, LineCap cap = LineCap::Butt, LineJoin join = LineJoin::Miter, float miterLimit = 4.0f) : width(width), cap(cap), join(join), miterLimit(miterLimit) { } @@ -81,16 +81,16 @@ class Stroke { /** * The geometry drawn at the beginning and end of strokes. */ - Cap cap = Cap::Butt; + LineCap cap = LineCap::Butt; /** * The geometry drawn at the corners of strokes. */ - Join join = Join::Miter; + LineJoin join = LineJoin::Miter; /** * The limit at which a sharp corner is drawn beveled. */ float miterLimit = 4.0f; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/TextBlob.h b/tgfx/include/core/TextBlob.h index de6eb2c357..2876a026d4 100644 --- a/tgfx/include/core/TextBlob.h +++ b/tgfx/include/core/TextBlob.h @@ -22,7 +22,7 @@ #include "core/Path.h" #include "core/Stroke.h" -namespace pag { +namespace tgfx { /** * TextBlob combines multiple glyphs, Font, and positions into an immutable container. */ @@ -66,4 +66,4 @@ class TextBlob { friend class Mask; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/Typeface.h b/tgfx/include/core/Typeface.h index 36efd4aa13..3478c6fadd 100644 --- a/tgfx/include/core/Typeface.h +++ b/tgfx/include/core/Typeface.h @@ -22,7 +22,7 @@ #include "core/Path.h" #include "gpu/TextureBuffer.h" -namespace pag { +namespace tgfx { /** * 16 bit unsigned integer to hold a glyph index */ @@ -63,7 +63,7 @@ class Typeface { /** * Returns the uniqueID for the specified typeface. */ - virtual ID uniqueID() const = 0; + virtual uint32_t uniqueID() const = 0; /** * Returns the family name of this typeface. @@ -141,4 +141,4 @@ class Typeface { friend class Font; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/core/UTF.h b/tgfx/include/core/UTF.h new file mode 100644 index 0000000000..d0cdcbea99 --- /dev/null +++ b/tgfx/include/core/UTF.h @@ -0,0 +1,41 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include + +namespace tgfx { +class UTF { + public: + /** + * Given a sequence of UTF-8 bytes, return the number of unicode codepoints. If the sequence is + * invalid UTF-8, return -1. + */ + static int CountUTF8(const char* utf8, size_t byteLength); + + /** + * Given a sequence of UTF-8 bytes, return the first unicode codepoint. The pointer will be + * incremented to point at the next codepoint's start. If invalid UTF-8 is encountered, set *ptr + * to end and return -1. + */ + static int32_t NextUTF8(const char** ptr, const char* end); +}; + +} // namespace tgfx diff --git a/tgfx/include/core/YUVInfo.h b/tgfx/include/core/YUVInfo.h index c995fd6ddb..1de5896944 100644 --- a/tgfx/include/core/YUVInfo.h +++ b/tgfx/include/core/YUVInfo.h @@ -18,7 +18,7 @@ #pragma once -namespace pag { +namespace tgfx { /** * Defines pixel formats for YUV pixels. */ @@ -78,4 +78,4 @@ enum class YUVColorRange { JPEG }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/Backend.h b/tgfx/include/gpu/Backend.h new file mode 100644 index 0000000000..8189429e59 --- /dev/null +++ b/tgfx/include/gpu/Backend.h @@ -0,0 +1,212 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "gpu/metal/MtlTypes.h" +#include "gpu/opengl/GLTypes.h" + +namespace tgfx { +/** + * Possible GPU backend APIs that may be used by TGFX. + */ +enum class Backend { + /** + * Mock is a backend that does not draw anything. It is used for unit tests and to measure CPU + * overhead. + */ + MOCK, + OPENGL, + METAL, + VULKAN, +}; + +/** + * Wrapper class for passing into and receiving data from TGFX about a backend texture object. + */ +class BackendTexture { + public: + /** + * Creates an invalid backend texture. + */ + BackendTexture() : _width(0), _height(0) { + } + + /** + * Creates an OpenGL backend texture. + */ + BackendTexture(const GLTextureInfo& glInfo, int width, int height); + + /** + * Creates an Metal backend texture. + */ + BackendTexture(const MtlTextureInfo& mtlInfo, int width, int height); + + BackendTexture(const BackendTexture& that); + + BackendTexture& operator=(const BackendTexture& that); + + /** + * Returns true if the backend texture has been initialized. + */ + bool isValid() const { + return _width > 0 && _height > 0; + } + + /** + * Returns the width of this texture. + */ + int width() const { + return _width; + } + + /** + * Returns the height of this texture. + */ + int height() const { + return _height; + } + + /** + * Returns the backend API of this texture. + */ + Backend backend() const { + return _backend; + } + + /** + * If the backend API is GL, copies a snapshot of the GLTextureInfo struct into the passed in + * pointer and returns true. Otherwise returns false if the backend API is not GL. + */ + bool getGLTextureInfo(GLTextureInfo* glTextureInfo) const; + + /** + * If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed + * in pointer and returns true. Otherwise returns false if the backend API is not Metal. + */ + bool getMtlTextureInfo(MtlTextureInfo* mtlTextureInfo) const; + + private: + Backend _backend = Backend::MOCK; + int _width = 0; + int _height = 0; + + union { + GLTextureInfo glInfo; + MtlTextureInfo mtlInfo; + }; +}; + +/** + * Wrapper class for passing into and receiving data from TGFX about a backend render target object. + */ +class BackendRenderTarget { + public: + /** + * Creates an invalid backend render target. + */ + BackendRenderTarget() : _width(0), _height(0) { + } + + /** + * Creates an OpenGL backend render target. + */ + BackendRenderTarget(const GLFrameBufferInfo& glInfo, int width, int height); + + /** + * Creates an Metal backend render target. + */ + BackendRenderTarget(const MtlTextureInfo& mtlInfo, int width, int height); + + BackendRenderTarget(const BackendRenderTarget& that); + + BackendRenderTarget& operator=(const BackendRenderTarget&); + + /** + * Returns true if the backend texture has been initialized. + */ + bool isValid() const { + return _width > 0 && _height > 0; + } + + /** + * Returns the width of this render target. + */ + int width() const { + return _width; + } + + /** + * Returns the height of this render target. + */ + int height() const { + return _height; + } + + /** + * Returns the backend API of this render target. + */ + Backend backend() const { + return _backend; + } + + /** + * If the backend API is GL, copies a snapshot of the GLFramebufferInfo struct into the passed + * in pointer and returns true. Otherwise returns false if the backend API is not GL. + */ + bool getGLFramebufferInfo(GLFrameBufferInfo* glFrameBufferInfo) const; + + /** + * If the backend API is Metal, copies a snapshot of the MtlTextureInfo struct into the passed + * in pointer and returns true. Otherwise returns false if the backend API is not Metal. + */ + bool getMtlTextureInfo(MtlTextureInfo* mtlTextureInfo) const; + + private: + Backend _backend = Backend::MOCK; + int _width = 0; + int _height = 0; + union { + GLFrameBufferInfo glInfo; + MtlTextureInfo mtlInfo; + }; +}; + +/** + * Wrapper class for passing into and receiving data from TGFX about a backend semaphore object. + */ +class BackendSemaphore { + public: + BackendSemaphore(); + + bool isInitialized() const { + return _isInitialized; + } + + void initGL(void* sync); + + void* glSync() const; + + private: + Backend _backend = Backend::MOCK; + union { + void* _glSync; + }; + bool _isInitialized; +}; +} // namespace tgfx diff --git a/tgfx/include/gpu/Canvas.h b/tgfx/include/gpu/Canvas.h index 1b5cfbcf44..6e3dd68064 100644 --- a/tgfx/include/gpu/Canvas.h +++ b/tgfx/include/gpu/Canvas.h @@ -18,21 +18,21 @@ #pragma once -#include "core/Blend.h" +#include "core/BlendMode.h" #include "core/Font.h" #include "core/Path.h" #include "core/RGBAAALayout.h" #include "gpu/Paint.h" #include "gpu/Texture.h" -namespace pag { +namespace tgfx { class Surface; class SurfaceOptions; struct CanvasPaint { float alpha = 1.0f; - Blend blendMode = Blend::SrcOver; + BlendMode blendMode = BlendMode::SrcOver; Matrix matrix = Matrix::I(); Path clip = {}; }; @@ -114,12 +114,12 @@ class Canvas { /** * Returns the current global blend mode. */ - Blend getBlendMode() const; + BlendMode getBlendMode() const; /** * Replaces the global blend mode with specified new blend mode. */ - void setBlendMode(Blend blendMode); + void setBlendMode(BlendMode blendMode); /** * Returns the current total clip. @@ -196,4 +196,4 @@ class Canvas { private: std::vector savedPaintList = {}; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/Context.h b/tgfx/include/gpu/Context.h index cf1d658ae9..43955e66c1 100644 --- a/tgfx/include/gpu/Context.h +++ b/tgfx/include/gpu/Context.h @@ -18,12 +18,12 @@ #pragma once -#include "core/Color4f.h" -#include "core/utils/BytesKey.h" +#include "core/BytesKey.h" +#include "core/Color.h" +#include "gpu/Backend.h" #include "gpu/Device.h" -#include "pag/gpu.h" -namespace pag { +namespace tgfx { class ProgramCache; class GradientCache; @@ -97,4 +97,4 @@ class Context { friend class Resource; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/Device.h b/tgfx/include/gpu/Device.h index d14627311f..4a9466de1f 100644 --- a/tgfx/include/gpu/Device.h +++ b/tgfx/include/gpu/Device.h @@ -18,9 +18,10 @@ #pragma once -#include "pag/types.h" +#include +#include "core/Matrix.h" -namespace pag { +namespace tgfx { class Context; /** * The GPU interface for drawing graphics. @@ -66,4 +67,4 @@ class Device { friend class ResourceCache; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/Paint.h b/tgfx/include/gpu/Paint.h index 486e8b1c76..caa0e9672f 100644 --- a/tgfx/include/gpu/Paint.h +++ b/tgfx/include/gpu/Paint.h @@ -18,12 +18,11 @@ #pragma once -#include "core/Color4f.h" +#include "core/Color.h" #include "core/Stroke.h" #include "gpu/Shader.h" -#include "pag/types.h" -namespace pag { +namespace tgfx { /** * Defines enumerations for Paint.setStyle(). */ @@ -66,7 +65,7 @@ class Paint { /** * Retrieves alpha and RGB, unpremultiplied, as four floating point values. */ - Color4f getColor() const { + Color getColor() const { return color; } @@ -74,7 +73,7 @@ class Paint { * Sets alpha and RGB used when stroking and filling. The color is four floating point values, * unpremultiplied. */ - void setColor(Color4f newColor) { + void setColor(Color newColor) { color = newColor; } @@ -112,28 +111,28 @@ class Paint { /** * Returns the geometry drawn at the beginning and end of strokes. */ - Stroke::Cap getLineCap() const { + LineCap getLineCap() const { return stroke.cap; } /** * Sets the geometry drawn at the beginning and end of strokes. */ - void setLineCap(Stroke::Cap cap) { + void setLineCap(LineCap cap) { stroke.cap = cap; } /** * Returns the geometry drawn at the corners of strokes. */ - Stroke::Join getLineJoin() const { + LineJoin getLineJoin() const { return stroke.join; } /** * Sets the geometry drawn at the corners of strokes. */ - void setLineJoin(Stroke::Join join) { + void setLineJoin(LineJoin join) { stroke.join = join; } @@ -182,8 +181,8 @@ class Paint { private: PaintStyle style = PaintStyle::Fill; - Color4f color = Color4f::Black(); + Color color = Color::Black(); Stroke stroke = Stroke(0); std::shared_ptr shader = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/Resource.h b/tgfx/include/gpu/Resource.h index 4bf801924c..bffe9d49fa 100644 --- a/tgfx/include/gpu/Resource.h +++ b/tgfx/include/gpu/Resource.h @@ -20,7 +20,7 @@ #include "gpu/ResourceCache.h" -namespace pag { +namespace tgfx { /** * The base class for GPU resource. Overrides the onRelease() method to to free all GPU resources. * No backend API calls should be made during destructuring since there may be no GPU context which @@ -39,9 +39,14 @@ class Resource { virtual ~Resource() = default; - protected: - Context* context = nullptr; + /** + * Retrieves the context associated with this Resource. + */ + Context* getContext() const { + return context; + } + protected: /** * Overridden to compute a recycleKey to make this Resource reusable. */ @@ -54,6 +59,7 @@ class Resource { virtual void onRelease(Context* context) = 0; private: + Context* context = nullptr; std::weak_ptr weakThis; BytesKey recycleKey = {}; size_t cacheArrayIndex = 0; @@ -61,4 +67,4 @@ class Resource { friend class ResourceCache; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/Shader.h b/tgfx/include/gpu/Shader.h index 46821be347..f6bb1b4ade 100644 --- a/tgfx/include/gpu/Shader.h +++ b/tgfx/include/gpu/Shader.h @@ -19,10 +19,10 @@ #pragma once #include -#include "core/Color4f.h" -#include "pag/types.h" +#include "core/Color.h" +#include "core/Point.h" -namespace pag { +namespace tgfx { struct FPArgs; class FragmentProcessor; @@ -37,7 +37,7 @@ class Shader { /** * Create a shader that draws the specified color. */ - static std::shared_ptr MakeColorShader(Color4f color); + static std::shared_ptr MakeColorShader(Color color); /** * Returns a shader that generates a linear gradient between the two specified points. @@ -50,7 +50,7 @@ class Shader { * be strictly increasing. */ static std::shared_ptr MakeLinearGradient(const Point& startPoint, const Point& endPoint, - const std::vector& colors, + const std::vector& colors, const std::vector& positions); /** @@ -64,7 +64,7 @@ class Shader { * be strictly increasing. */ static std::shared_ptr MakeRadialGradient(const Point& center, float radius, - const std::vector& colors, + const std::vector& colors, const std::vector& positions); virtual ~Shader() = default; @@ -80,4 +80,4 @@ class Shader { virtual std::unique_ptr asFragmentProcessor(const FPArgs& args) const = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/Surface.h b/tgfx/include/gpu/Surface.h index 7c996e5826..557a4e0f9e 100644 --- a/tgfx/include/gpu/Surface.h +++ b/tgfx/include/gpu/Surface.h @@ -20,10 +20,8 @@ #include "core/ImageInfo.h" #include "gpu/Canvas.h" -#include "pag/gpu.h" -#include "pag/types.h" -namespace pag { +namespace tgfx { /** * Describes options of a given Surface. The caller can add some custom options to its subclass and * parse them during drawing, which can sometimes optimize the rendering performance (e.g. disabling @@ -173,4 +171,4 @@ class Surface { Context* context = nullptr; std::unique_ptr surfaceOptions = nullptr; }; -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/include/gpu/Texture.h b/tgfx/include/gpu/Texture.h index 9504484259..14b2f09a82 100644 --- a/tgfx/include/gpu/Texture.h +++ b/tgfx/include/gpu/Texture.h @@ -19,9 +19,11 @@ #pragma once #include +#include "core/ImageOrigin.h" +#include "core/Point.h" #include "gpu/Resource.h" -namespace pag { +namespace tgfx { class TextureSampler; /** @@ -112,13 +114,5 @@ class Texture : public Resource { // Two texture types: Alpha, RGBA static std::shared_ptr Make(Context* context, int width, int height, void* pixels, size_t rowBytes, ImageOrigin origin, bool alphaOnly); - - friend void Trace(const Texture* texture, const std::string& path); }; - -/** - * Trace() provides a utility to view the texture. - */ -void Trace(const Texture* texture, const std::string& path = ""); - -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/TextureBuffer.h b/tgfx/include/gpu/TextureBuffer.h index 884b8db52e..4efe6f4e6f 100644 --- a/tgfx/include/gpu/TextureBuffer.h +++ b/tgfx/include/gpu/TextureBuffer.h @@ -20,7 +20,7 @@ #include "Texture.h" -namespace pag { +namespace tgfx { /** * A TextureBuffer contains an array of fully processed pixels, suitable for immediate texture * uploading on the GPU. @@ -55,4 +55,4 @@ class TextureBuffer { int _width = 0; int _height = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/Window.h b/tgfx/include/gpu/Window.h index 269ee657a0..c11a6ff1f3 100644 --- a/tgfx/include/gpu/Window.h +++ b/tgfx/include/gpu/Window.h @@ -21,7 +21,7 @@ #include "gpu/Context.h" #include "gpu/Surface.h" -namespace pag { +namespace tgfx { /** * Window represents a native displayable resource that can be rendered or written to by a Device. */ @@ -58,4 +58,4 @@ class Window { private: bool checkContext(Context* context); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/YUVTexture.h b/tgfx/include/gpu/YUVTexture.h index ae82b37bd8..a58d587e54 100644 --- a/tgfx/include/gpu/YUVTexture.h +++ b/tgfx/include/gpu/YUVTexture.h @@ -21,7 +21,7 @@ #include "Texture.h" #include "core/YUVInfo.h" -namespace pag { +namespace tgfx { /** * YUVTexture wraps separate textures in the GPU backend for Y, U, and V planes. @@ -100,4 +100,4 @@ class YUVTexture : public Texture { YUVColorSpace _colorSpace = YUVColorSpace::Rec601; YUVColorRange _colorRange = YUVColorRange::MPEG; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/metal/MtlTypes.h b/tgfx/include/gpu/metal/MtlTypes.h new file mode 100644 index 0000000000..f1f7f60f50 --- /dev/null +++ b/tgfx/include/gpu/metal/MtlTypes.h @@ -0,0 +1,32 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +namespace tgfx { +/** + * Types for interacting with Metal resources created externally to TGFX. Holds the MTLTexture as a + * const void*. + */ +struct MtlTextureInfo { + /** + * Pointer to MTLTexture. + */ + const void* texture = nullptr; +}; +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/GLDevice.h b/tgfx/include/gpu/opengl/GLDevice.h index 7f53f3ee59..1ab8033b36 100644 --- a/tgfx/include/gpu/opengl/GLDevice.h +++ b/tgfx/include/gpu/opengl/GLDevice.h @@ -20,7 +20,7 @@ #include "gpu/Device.h" -namespace pag { +namespace tgfx { /** * The OpenGL interface for drawing graphics. */ @@ -66,4 +66,4 @@ class GLDevice : public Device { friend class GLContext; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/GLTypes.h b/tgfx/include/gpu/opengl/GLTypes.h new file mode 100644 index 0000000000..01add8a7fe --- /dev/null +++ b/tgfx/include/gpu/opengl/GLTypes.h @@ -0,0 +1,54 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +namespace tgfx { +/** + * Types for interacting with GL textures created externally to TGFX. + */ +struct GLTextureInfo { + /** + * the id of this texture. + */ + unsigned id = 0; + /** + * The target of this texture. + */ + unsigned target = 0x0DE1; // GL_TEXTURE_2D; + /** + * The pixel format of this texture. + */ + unsigned format = 0x8058; // GL_RGBA8; +}; + +/** + * Types for interacting with GL frame buffers created externally to TGFX. + */ +struct GLFrameBufferInfo { + /** + * The id of this frame buffer. + */ + unsigned id = 0; + + /** + * The pixel format of this frame buffer. + */ + unsigned format = 0x8058; // GL_RGBA8; +}; +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/cgl/CGLDevice.h b/tgfx/include/gpu/opengl/cgl/CGLDevice.h index 5ef2c00808..c9fe510bf1 100644 --- a/tgfx/include/gpu/opengl/cgl/CGLDevice.h +++ b/tgfx/include/gpu/opengl/cgl/CGLDevice.h @@ -21,7 +21,7 @@ #include #include "gpu/opengl/GLDevice.h" -namespace pag { +namespace tgfx { class CGLDevice : public GLDevice { public: /** @@ -55,4 +55,4 @@ class CGLDevice : public GLDevice { friend class GLDevice; friend class CGLWindow; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/cgl/CGLWindow.h b/tgfx/include/gpu/opengl/cgl/CGLWindow.h index 2f0a8070f4..25cdd66c18 100644 --- a/tgfx/include/gpu/opengl/cgl/CGLWindow.h +++ b/tgfx/include/gpu/opengl/cgl/CGLWindow.h @@ -21,7 +21,7 @@ #include "CGLDevice.h" #include "gpu/Window.h" -namespace pag { +namespace tgfx { class CGLWindow : public Window { public: /** @@ -46,4 +46,4 @@ class CGLWindow : public Window { explicit CGLWindow(std::shared_ptr device); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/eagl/EAGLDevice.h b/tgfx/include/gpu/opengl/eagl/EAGLDevice.h index e8cbe29cd7..177fc455ec 100644 --- a/tgfx/include/gpu/opengl/eagl/EAGLDevice.h +++ b/tgfx/include/gpu/opengl/eagl/EAGLDevice.h @@ -21,7 +21,7 @@ #import #include "gpu/opengl/GLDevice.h" -namespace pag { +namespace tgfx { class EAGLDevice : public GLDevice { public: /** @@ -63,4 +63,4 @@ class EAGLDevice : public GLDevice { friend void ApplicationWillResignActive(); friend void ApplicationDidBecomeActive(); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/eagl/EAGLWindow.h b/tgfx/include/gpu/opengl/eagl/EAGLWindow.h index fa94de2040..1811399b48 100644 --- a/tgfx/include/gpu/opengl/eagl/EAGLWindow.h +++ b/tgfx/include/gpu/opengl/eagl/EAGLWindow.h @@ -21,7 +21,7 @@ #include "EAGLDevice.h" #include "gpu/Window.h" -namespace pag { +namespace tgfx { class EAGLWindow : public Window { public: /** @@ -49,4 +49,4 @@ class EAGLWindow : public Window { explicit EAGLWindow(std::shared_ptr device); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/egl/EGLDevice.h b/tgfx/include/gpu/opengl/egl/EGLDevice.h index fb7e85373e..a76ff97e01 100644 --- a/tgfx/include/gpu/opengl/egl/EGLDevice.h +++ b/tgfx/include/gpu/opengl/egl/EGLDevice.h @@ -22,7 +22,7 @@ #include #include "gpu/opengl/GLDevice.h" -namespace pag { +namespace tgfx { class EGLDevice : public GLDevice { public: /** @@ -68,4 +68,4 @@ class EGLDevice : public GLDevice { friend class EGLWindow; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/egl/EGLWindow.h b/tgfx/include/gpu/opengl/egl/EGLWindow.h index 35f0f7483c..f305944bff 100644 --- a/tgfx/include/gpu/opengl/egl/EGLWindow.h +++ b/tgfx/include/gpu/opengl/egl/EGLWindow.h @@ -21,7 +21,7 @@ #include "EGLDevice.h" #include "gpu/Window.h" -namespace pag { +namespace tgfx { class EGLWindow : public Window { public: /** @@ -43,4 +43,4 @@ class EGLWindow : public Window { private: explicit EGLWindow(std::shared_ptr device); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/qt/QGLDevice.h b/tgfx/include/gpu/opengl/qt/QGLDevice.h index dcd51d09ce..f632fe72ca 100644 --- a/tgfx/include/gpu/opengl/qt/QGLDevice.h +++ b/tgfx/include/gpu/opengl/qt/QGLDevice.h @@ -26,7 +26,7 @@ #pragma clang diagnostic pop #include "gpu/opengl/GLDevice.h" -namespace pag { +namespace tgfx { class QGLDevice : public GLDevice { public: /** @@ -81,4 +81,4 @@ class QGLDevice : public GLDevice { friend class GLDevice; friend class QGLWindow; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/qt/QGLWindow.h b/tgfx/include/gpu/opengl/qt/QGLWindow.h index 11f8a11b96..0a43686a4a 100644 --- a/tgfx/include/gpu/opengl/qt/QGLWindow.h +++ b/tgfx/include/gpu/opengl/qt/QGLWindow.h @@ -26,7 +26,7 @@ #include "QGLDevice.h" #include "gpu/Window.h" -namespace pag { +namespace tgfx { class GLTexture; class GLRenderTarget; @@ -72,4 +72,4 @@ class QGLWindow : public Window { QGLWindow(std::shared_ptr device, QQuickItem* quickItem); void invalidateTexture(); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/webgl/WebGLDevice.h b/tgfx/include/gpu/opengl/webgl/WebGLDevice.h index 7ff242271c..33702590e3 100644 --- a/tgfx/include/gpu/opengl/webgl/WebGLDevice.h +++ b/tgfx/include/gpu/opengl/webgl/WebGLDevice.h @@ -21,7 +21,7 @@ #include #include "gpu/opengl/GLDevice.h" -namespace pag { +namespace tgfx { class WebGLDevice : public GLDevice { public: /** @@ -49,4 +49,4 @@ class WebGLDevice : public GLDevice { friend class GLDevice; friend class WebGLWindow; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/gpu/opengl/webgl/WebGLWindow.h b/tgfx/include/gpu/opengl/webgl/WebGLWindow.h index 037063ea60..8676f36003 100644 --- a/tgfx/include/gpu/opengl/webgl/WebGLWindow.h +++ b/tgfx/include/gpu/opengl/webgl/WebGLWindow.h @@ -21,7 +21,7 @@ #include "WebGLDevice.h" #include "gpu/Window.h" -namespace pag { +namespace tgfx { class WebGLWindow : public Window { public: /** @@ -40,4 +40,4 @@ class WebGLWindow : public Window { explicit WebGLWindow(std::shared_ptr device); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/platform/Print.h b/tgfx/include/platform/Print.h index 0bb686bde6..2aed539494 100644 --- a/tgfx/include/platform/Print.h +++ b/tgfx/include/platform/Print.h @@ -18,7 +18,7 @@ #pragma once -namespace pag { +namespace tgfx { /** * Writes an output message pointed by format to the log facility of native platform. */ @@ -28,4 +28,4 @@ void PrintLog(const char format[], ...); * Writes an error message pointed by format to the log facility of native platform. */ void PrintError(const char format[], ...); -} // namespace pag +} // namespace tgfx diff --git a/tgfx/include/platform/android/SetJavaVM.h b/tgfx/include/platform/android/SetJavaVM.h index ab70d0dc87..fac52a5f74 100644 --- a/tgfx/include/platform/android/SetJavaVM.h +++ b/tgfx/include/platform/android/SetJavaVM.h @@ -18,7 +18,7 @@ #pragma once -namespace pag { +namespace tgfx { /* * Manually set a Java virtual machine which will be used by tgfx to retrieve the JNI environment. * Once a Java VM is set it cannot be changed afterwards, meaning you can call multiple times @@ -26,4 +26,4 @@ namespace pag { * Java VM. Returns true on success, false otherwise. */ bool SetJavaVM(void* javaVM); -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/Bitmap.cpp b/tgfx/src/core/Bitmap.cpp index e310595d5a..d894bfd8bf 100644 --- a/tgfx/src/core/Bitmap.cpp +++ b/tgfx/src/core/Bitmap.cpp @@ -21,7 +21,7 @@ #include "platform/Platform.h" #include "skcms.h" -namespace pag { +namespace tgfx { static inline void* AddOffset(void* pixels, size_t offset) { return reinterpret_cast(pixels) + offset; @@ -202,11 +202,4 @@ bool Bitmap::eraseAll() { } return true; } - -void Trace(const Bitmap& bitmap, const std::string& tag) { - if (bitmap.isEmpty()) { - return; - } - Platform::Current()->traceImage(bitmap.info(), bitmap.pixels(), tag); -} -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/utils/BytesKey.cpp b/tgfx/src/core/BytesKey.cpp similarity index 96% rename from tgfx/src/core/utils/BytesKey.cpp rename to tgfx/src/core/BytesKey.cpp index 30de3c1507..d18ec396d2 100644 --- a/tgfx/src/core/utils/BytesKey.cpp +++ b/tgfx/src/core/BytesKey.cpp @@ -16,10 +16,10 @@ // ///////////////////////////////////////////////////////////////////////////////////////////////// -#include "core/utils/BytesKey.h" +#include "core/BytesKey.h" #include -namespace pag { +namespace tgfx { union DataConverter { float floatValue; uint8_t bytes[4]; @@ -64,4 +64,4 @@ size_t BytesHasher::operator()(const BytesKey& key) const { } return hash; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/Color.cpp b/tgfx/src/core/Color.cpp index 1ccb1179da..d111cb7690 100644 --- a/tgfx/src/core/Color.cpp +++ b/tgfx/src/core/Color.cpp @@ -16,59 +16,58 @@ // ///////////////////////////////////////////////////////////////////////////////////////////////// -#include "base/utils/Log.h" -#include "core/Color4f.h" +#include "core/Color.h" +#include "core/utils/Log.h" -namespace pag { -const Color4f& Color4f::Invalid() { - static const Color4f color = { - std::numeric_limits::max(), std::numeric_limits::max(), - std::numeric_limits::max(), std::numeric_limits::max()}; +namespace tgfx { +const Color& Color::Invalid() { + static const Color color = {std::numeric_limits::max(), std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max()}; return color; } -const Color4f& Color4f::Transparent() { - static const Color4f color = {0.0f, 0.0f, 0.0f, 0.0f}; +const Color& Color::Transparent() { + static const Color color = {0.0f, 0.0f, 0.0f, 0.0f}; return color; } -const Color4f& Color4f::Black() { - static const Color4f color = {0.0f, 0.0f, 0.0f, 1.0f}; +const Color& Color::Black() { + static const Color color = {0.0f, 0.0f, 0.0f, 1.0f}; return color; } -const Color4f& Color4f::White() { - static const Color4f color = {1.0f, 1.0f, 1.0f, 1.0f}; +const Color& Color::White() { + static const Color color = {1.0f, 1.0f, 1.0f, 1.0f}; return color; } -Color4f Color4f::FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { +Color Color::FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { auto alpha = a == 255 ? 1.0f : static_cast(a) / 255.0f; return {static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f, alpha}; } -float Color4f::operator[](int index) const { +float Color::operator[](int index) const { DEBUG_ASSERT(index >= 0 && index < 4); return (&red)[index]; } -float& Color4f::operator[](int index) { +float& Color::operator[](int index) { DEBUG_ASSERT(index >= 0 && index < 4); return (&red)[index]; } -bool Color4f::isValid() const { +bool Color::isValid() const { return red >= 0.0f && red <= 1.0f && green >= 0.0f && green <= 1.0f && blue >= 0.0f && blue <= 1.0f && alpha >= 0.0f && alpha <= 1.0f; } -bool Color4f::isOpaque() const { +bool Color::isOpaque() const { DEBUG_ASSERT(alpha <= 1.0f && alpha >= 0.0f); return alpha == 1.0f; } -Color4f Color4f::unpremultiply() const { +Color Color::unpremultiply() const { if (alpha == 0.0f) { return {0, 0, 0, 0}; } else { @@ -77,4 +76,4 @@ Color4f Color4f::unpremultiply() const { } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/Data.cpp b/tgfx/src/core/Data.cpp index 22ca547ddc..5ba1d50556 100644 --- a/tgfx/src/core/Data.cpp +++ b/tgfx/src/core/Data.cpp @@ -19,7 +19,7 @@ #include "core/Data.h" #include "core/Stream.h" -namespace pag { +namespace tgfx { std::shared_ptr Data::MakeFromFile(const std::string& filePath) { auto stream = Stream::MakeFromFile(filePath); if (stream == nullptr) { @@ -91,4 +91,4 @@ Data::~Data() { } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/Font.cpp b/tgfx/src/core/Font.cpp index 63d70cad86..a23eaae0f4 100644 --- a/tgfx/src/core/Font.cpp +++ b/tgfx/src/core/Font.cpp @@ -18,7 +18,7 @@ #include "core/Font.h" -namespace pag { +namespace tgfx { Font::Font() : Font(nullptr) { } @@ -48,4 +48,4 @@ void Font::setSize(float newSize) { size = newSize; } } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/Image.cpp b/tgfx/src/core/Image.cpp index 453450b9a9..48fa1c76e8 100644 --- a/tgfx/src/core/Image.cpp +++ b/tgfx/src/core/Image.cpp @@ -38,7 +38,7 @@ #include "core/images/jpeg/JpegImage.h" #endif -namespace pag { +namespace tgfx { std::shared_ptr Image::MakeFrom(const std::string& filePath) { std::shared_ptr image = nullptr; auto stream = Stream::MakeFromFile(filePath); @@ -141,4 +141,4 @@ std::shared_ptr Image::makeBuffer() const { auto result = readPixels(pixelBuffer->info(), bitmap.writablePixels()); return result ? pixelBuffer : nullptr; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/ImageInfo.cpp b/tgfx/src/core/ImageInfo.cpp index cff3a249e9..2651fc16ed 100644 --- a/tgfx/src/core/ImageInfo.cpp +++ b/tgfx/src/core/ImageInfo.cpp @@ -18,7 +18,7 @@ #include "core/ImageInfo.h" -namespace pag { +namespace tgfx { static constexpr int MaxDimension = INT32_MAX >> 2; bool ImageInfo::IsValidSize(int width, int height) { @@ -99,4 +99,4 @@ void* ImageInfo::computeOffset(void* pixels, int x, int y) const { auto offset = y * _rowBytes + x * bytesPerPixel(); return reinterpret_cast(pixels) + offset; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/Mask.cpp b/tgfx/src/core/Mask.cpp index 9a45ab6edc..153b2b666b 100644 --- a/tgfx/src/core/Mask.cpp +++ b/tgfx/src/core/Mask.cpp @@ -19,7 +19,7 @@ #include "core/Mask.h" #include "core/PathEffect.h" -namespace pag { +namespace tgfx { bool Mask::CanUseAsMask(const TextBlob* textBlob) { if (textBlob == nullptr) { return false; @@ -64,4 +64,4 @@ bool Mask::strokeText(const TextBlob* textBlob, const Stroke& stroke) { fillPath(path); return true; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/Matrix.cpp b/tgfx/src/core/Matrix.cpp new file mode 100644 index 0000000000..ed2acb1149 --- /dev/null +++ b/tgfx/src/core/Matrix.cpp @@ -0,0 +1,475 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include "core/Matrix.h" +#include +#include "core/utils/MathExtra.h" + +namespace tgfx { + +void Matrix::reset() { + values[SCALE_X] = values[SCALE_Y] = values[PERSP_2] = 1; + values[SKEW_X] = values[SKEW_Y] = values[TRANS_X] = values[TRANS_Y] = values[PERSP_0] = + values[PERSP_1] = 0; +} + +bool operator==(const Matrix& a, const Matrix& b) { + const float* ma = a.values; + const float* mb = b.values; + return ma[0] == mb[0] && ma[1] == mb[1] && ma[2] == mb[2] && ma[3] == mb[3] && ma[4] == mb[4] && + ma[5] == mb[5] && ma[6] == mb[6] && ma[7] == mb[7] && ma[8] == mb[8]; +} + +void Matrix::setAll(float scaleX, float skewX, float transX, float skewY, float scaleY, + float transY, float persp0, float persp1, float persp2) { + values[SCALE_X] = scaleX; + values[SKEW_X] = skewX; + values[TRANS_X] = transX; + values[SKEW_Y] = skewY; + values[SCALE_Y] = scaleY; + values[TRANS_Y] = transY; + values[PERSP_0] = persp0; + values[PERSP_1] = persp1; + values[PERSP_2] = persp2; +} + +void Matrix::setAffine(float a, float b, float c, float d, float tx, float ty) { + values[SCALE_X] = a; + values[SKEW_X] = c; + values[TRANS_X] = tx; + values[SKEW_Y] = b; + values[SCALE_Y] = d; + values[TRANS_Y] = ty; + values[PERSP_0] = 0; + values[PERSP_1] = 0; + values[PERSP_2] = 1; +} + +void Matrix::setTranslate(float dx, float dy) { + if ((dx != 0) | (dy != 0)) { + values[TRANS_X] = dx; + values[TRANS_Y] = dy; + + values[SCALE_X] = values[SCALE_Y] = values[PERSP_2] = 1; + values[SKEW_X] = values[SKEW_Y] = values[PERSP_0] = values[PERSP_1] = 0; + } else { + this->reset(); + } +} + +static inline float sdot(float a, float b, float c, float d) { + return a * b + c * d; +} + +void Matrix::preTranslate(float dx, float dy) { + values[TRANS_X] += sdot(values[SCALE_X], dx, values[SKEW_X], dy); + values[TRANS_Y] += sdot(values[SKEW_Y], dx, values[SCALE_Y], dy); +} + +void Matrix::postTranslate(float dx, float dy) { + values[TRANS_X] += dx; + values[TRANS_Y] += dy; +} + +void Matrix::setScaleTranslate(float sx, float sy, float tx, float ty) { + values[SCALE_X] = sx; + values[SKEW_X] = 0; + values[TRANS_X] = tx; + + values[SKEW_Y] = 0; + values[SCALE_Y] = sy; + values[TRANS_Y] = ty; + + values[PERSP_0] = 0; + values[PERSP_1] = 0; + values[PERSP_2] = 1; +} + +void Matrix::setScale(float sx, float sy, float px, float py) { + if (1 == sx && 1 == sy) { + this->reset(); + } else { + values[SCALE_X] = sx; + values[SKEW_X] = 0; + values[TRANS_X] = 0; + + values[SKEW_Y] = 0; + values[SCALE_Y] = sy; + values[TRANS_Y] = 0; + + values[PERSP_0] = 0; + values[PERSP_1] = 0; + values[PERSP_2] = 1; + this->setScaleTranslate(sx, sy, px - sx * px, py - sy * py); + } +} + +void Matrix::setScale(float sx, float sy) { + if (1 == sx && 1 == sy) { + this->reset(); + } else { + values[SCALE_X] = sx; + values[SCALE_Y] = sy; + values[PERSP_2] = 1; + + values[TRANS_X] = values[TRANS_Y] = values[SKEW_X] = values[SKEW_Y] = values[PERSP_0] = + values[PERSP_1] = 0; + } +} + +void Matrix::preScale(float sx, float sy, float px, float py) { + if (1 == sx && 1 == sy) { + return; + } + + Matrix m = {}; + m.setScale(sx, sy, px, py); + this->preConcat(m); +} + +void Matrix::preScale(float sx, float sy) { + if (1 == sx && 1 == sy) { + return; + } + values[SCALE_X] *= sx; + values[SKEW_Y] *= sx; + values[PERSP_0] *= sx; + + values[SKEW_X] *= sy; + values[SCALE_Y] *= sy; + values[PERSP_1] *= sy; +} + +void Matrix::postScale(float sx, float sy, float px, float py) { + if (1 == sx && 1 == sy) { + return; + } + Matrix m = {}; + m.setScale(sx, sy, px, py); + this->postConcat(m); +} + +void Matrix::postScale(float sx, float sy) { + if (1 == sx && 1 == sy) { + return; + } + Matrix m = {}; + m.setScale(sx, sy); + this->postConcat(m); +} + +void Matrix::setSinCos(float sinV, float cosV, float px, float py) { + const float oneMinusCosV = 1 - cosV; + + values[SCALE_X] = cosV; + values[SKEW_X] = -sinV; + values[TRANS_X] = sdot(sinV, py, oneMinusCosV, px); + + values[SKEW_Y] = sinV; + values[SCALE_Y] = cosV; + values[TRANS_Y] = sdot(-sinV, px, oneMinusCosV, py); + + values[PERSP_0] = values[PERSP_1] = 0; + values[PERSP_2] = 1; +} + +void Matrix::setSinCos(float sinV, float cosV) { + values[SCALE_X] = cosV; + values[SKEW_X] = -sinV; + values[TRANS_X] = 0; + + values[SKEW_Y] = sinV; + values[SCALE_Y] = cosV; + values[TRANS_Y] = 0; + + values[PERSP_0] = values[PERSP_1] = 0; + values[PERSP_2] = 1; +} + +void Matrix::setRotate(float degrees, float px, float py) { + float rad = DegreesToRadians(degrees); + this->setSinCos(SinSnapToZero(rad), CosSnapToZero(rad), px, py); +} + +void Matrix::setRotate(float degrees) { + float rad = DegreesToRadians(degrees); + this->setSinCos(SinSnapToZero(rad), CosSnapToZero(rad)); +} + +void Matrix::preRotate(float degrees, float px, float py) { + Matrix m = {}; + m.setRotate(degrees, px, py); + this->preConcat(m); +} + +void Matrix::preRotate(float degrees) { + Matrix m = {}; + m.setRotate(degrees); + this->preConcat(m); +} + +void Matrix::postRotate(float degrees, float px, float py) { + Matrix m = {}; + m.setRotate(degrees, px, py); + this->postConcat(m); +} + +void Matrix::postRotate(float degrees) { + Matrix m = {}; + m.setRotate(degrees); + this->postConcat(m); +} + +void Matrix::setSkew(float sx, float sy, float px, float py) { + values[SCALE_X] = 1; + values[SKEW_X] = sx; + values[TRANS_X] = -sx * py; + + values[SKEW_Y] = sy; + values[SCALE_Y] = 1; + values[TRANS_Y] = -sy * px; + + values[PERSP_0] = values[PERSP_1] = 0; + values[PERSP_2] = 1; +} + +void Matrix::setSkew(float sx, float sy) { + values[SCALE_X] = 1; + values[SKEW_X] = sx; + values[TRANS_X] = 0; + + values[SKEW_Y] = sy; + values[SCALE_Y] = 1; + values[TRANS_Y] = 0; + + values[PERSP_0] = values[PERSP_1] = 0; + values[PERSP_2] = 1; +} + +void Matrix::preSkew(float sx, float sy, float px, float py) { + Matrix m = {}; + m.setSkew(sx, sy, px, py); + this->preConcat(m); +} + +void Matrix::preSkew(float sx, float sy) { + Matrix m = {}; + m.setSkew(sx, sy); + this->preConcat(m); +} + +void Matrix::postSkew(float sx, float sy, float px, float py) { + Matrix m = {}; + m.setSkew(sx, sy, px, py); + this->postConcat(m); +} + +void Matrix::postSkew(float sx, float sy) { + Matrix m = {}; + m.setSkew(sx, sy); + this->postConcat(m); +} + +void Matrix::setConcat(const Matrix& first, const Matrix& second) { + auto& matA = first.values; + auto& matB = second.values; + auto a = matB[SCALE_X] * matA[SCALE_X]; + auto b = 0.0; + auto c = 0.0; + auto d = matB[SCALE_Y] * matA[SCALE_Y]; + auto tx = matB[TRANS_X] * matA[SCALE_X] + matA[TRANS_X]; + auto ty = matB[TRANS_Y] * matA[SCALE_Y] + matA[TRANS_Y]; + + if (matB[SKEW_Y] != 0.0 || matB[SKEW_X] != 0.0 || matA[SKEW_Y] != 0.0 || matA[SKEW_X] != 0.0) { + a += matB[SKEW_Y] * matA[SKEW_X]; + d += matB[SKEW_X] * matA[SKEW_Y]; + b += matB[SCALE_X] * matA[SKEW_Y] + matB[SKEW_Y] * matA[SCALE_Y]; + c += matB[SKEW_X] * matA[SCALE_X] + matB[SCALE_Y] * matA[SKEW_X]; + tx += matB[TRANS_Y] * matA[SKEW_X]; + ty += matB[TRANS_X] * matA[SKEW_Y]; + } + + values[SCALE_X] = a; + values[SKEW_Y] = b; + values[SKEW_X] = c; + values[SCALE_Y] = d; + values[TRANS_X] = tx; + values[TRANS_Y] = ty; + values[PERSP_0] = 0; + values[PERSP_1] = 0; + values[PERSP_2] = 1; +} + +void Matrix::preConcat(const Matrix& mat) { + // check for identity first, so we don't do a needless copy of ourselves + // to ourselves inside setConcat() + if (!mat.isIdentity()) { + this->setConcat(*this, mat); + } +} + +void Matrix::postConcat(const Matrix& mat) { + // check for identity first, so we don't do a needless copy of ourselves + // to ourselves inside setConcat() + if (!mat.isIdentity()) { + this->setConcat(mat, *this); + } +} + +bool Matrix::invertible() const { + float determinant = values[SCALE_X] * values[SCALE_Y] - values[SKEW_Y] * values[SKEW_X]; + return !(FloatNearlyZero(determinant, FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO)); +} + +bool Matrix::invertNonIdentity(Matrix* inverse) const { + auto a = values[SCALE_X]; + auto d = values[SCALE_Y]; + auto c = values[SKEW_X]; + auto b = values[SKEW_Y]; + auto tx = values[TRANS_X]; + auto ty = values[TRANS_Y]; + + if (b == 0 && c == 0) { + if (a == 0 || d == 0) { + return false; + } + a = 1 / a; + d = 1 / d; + tx = -a * tx; + ty = -d * ty; + inverse->setAffine(a, b, c, d, tx, ty); + return true; + } + float determinant = a * d - b * c; + if (FloatNearlyZero(determinant, FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO)) { + return false; + } + determinant = 1 / determinant; + a = d * determinant; + b = -b * determinant; + c = -c * determinant; + d = values[SCALE_X] * determinant; + tx = -(a * values[TRANS_X] + c * values[TRANS_Y]); + ty = -(b * values[TRANS_X] + d * values[TRANS_Y]); + inverse->setAffine(a, b, c, d, tx, ty); + return true; +} + +void Matrix::mapPoints(Point dst[], const Point src[], int count) const { + auto tx = values[TRANS_X]; + auto ty = values[TRANS_Y]; + auto sx = values[SCALE_X]; + auto sy = values[SCALE_Y]; + auto kx = values[SKEW_X]; + auto ky = values[SKEW_Y]; + for (int i = 0; i < count; i++) { + auto x = src[i].x * sx + src[i].y * kx + tx; + auto y = src[i].x * ky + src[i].y * sy + ty; + dst[i].set(x, y); + } +} + +void Matrix::mapXY(float x, float y, Point* result) const { + auto tx = values[TRANS_X]; + auto ty = values[TRANS_Y]; + auto sx = values[SCALE_X]; + auto sy = values[SCALE_Y]; + auto kx = values[SKEW_X]; + auto ky = values[SKEW_Y]; + result->set(x * sx + y * kx + tx, x * ky + y * sy + ty); +} + +void Matrix::mapRect(Rect* dst, const Rect& src) const { + Point quad[4]; + quad[0].set(src.left, src.top); + quad[1].set(src.right, src.top); + quad[2].set(src.right, src.bottom); + quad[3].set(src.left, src.bottom); + mapPoints(quad, quad, 4); + dst->setBounds(quad, 4); +} + +float Matrix::getMinScale() const { + float results[2]; + if (getMinMaxScaleFactors(results)) { + return results[0]; + } + return -1.0f; +} + +float Matrix::getMaxScale() const { + float results[2]; + if (getMinMaxScaleFactors(results)) { + return results[1]; + } + return -1.0f; +} + +bool Matrix::getMinMaxScaleFactors(float* results) const { + float a = sdot(values[SCALE_X], values[SCALE_X], values[SKEW_Y], values[SKEW_Y]); + float b = sdot(values[SCALE_X], values[SKEW_X], values[SCALE_Y], values[SKEW_Y]); + float c = sdot(values[SKEW_X], values[SKEW_X], values[SCALE_Y], values[SCALE_Y]); + float bSqd = b * b; + if (bSqd <= FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO) { + results[0] = a; + results[1] = c; + if (results[0] > results[1]) { + using std::swap; + swap(results[0], results[1]); + } + } else { + float aminusc = a - c; + float apluscdiv2 = (a + c) * 0.5f; + float x = sqrtf(aminusc * aminusc + 4 * bSqd) * 0.5f; + results[0] = apluscdiv2 - x; + results[1] = apluscdiv2 + x; + } + auto isFinite = (results[0] * 0 == 0); + if (!isFinite) { + return false; + } + if (results[0] < 0) { + results[0] = 0; + } + results[0] = sqrtf(results[0]); + isFinite = (results[1] * 0 == 0); + if (!isFinite) { + return false; + } + if (results[1] < 0) { + results[1] = 0; + } + results[1] = sqrtf(results[1]); + return true; +} + +bool Matrix::isFinite() const { + return FloatsAreFinite(values, 9); +} + +const Matrix& Matrix::I() { + static const Matrix identity = Matrix::MakeAll(1, 0, 0, 0, 1, 0, 0, 0, 1); + return identity; +} + +const Matrix& Matrix::Invalid() { + static const Matrix invalid = Matrix::MakeAll(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, + FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX); + return invalid; +} +} // namespace tgfx diff --git a/tgfx/src/core/Orientation.cpp b/tgfx/src/core/Orientation.cpp index 95f16c13dd..763a17e294 100644 --- a/tgfx/src/core/Orientation.cpp +++ b/tgfx/src/core/Orientation.cpp @@ -18,7 +18,7 @@ #include "core/Orientation.h" -namespace pag { +namespace tgfx { Matrix OrientationToMatrix(Orientation orientation, int width, int height) { auto w = static_cast(width); auto h = static_cast(height); @@ -42,4 +42,4 @@ Matrix OrientationToMatrix(Orientation orientation, int width, int height) { } return Matrix::I(); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/Path.cpp b/tgfx/src/core/Path.cpp index c43ea54ce1..b3abb0c26b 100644 --- a/tgfx/src/core/Path.cpp +++ b/tgfx/src/core/Path.cpp @@ -17,10 +17,10 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "core/Path.h" -#include "base/utils/MathExtra.h" #include "core/PathRef.h" +#include "core/utils/MathExtra.h" -namespace pag { +namespace tgfx { using namespace pk; static SkPathDirection ToSkDirection(bool reversed) { @@ -393,4 +393,4 @@ PathRef* Path::writableRef() { } return pathRef.get(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/PathEffect.cpp b/tgfx/src/core/PathEffect.cpp index 07e3d15487..d30a1f8eef 100644 --- a/tgfx/src/core/PathEffect.cpp +++ b/tgfx/src/core/PathEffect.cpp @@ -20,7 +20,7 @@ #include "core/PathRef.h" #include "core/Stroke.h" -namespace pag { +namespace tgfx { using namespace pk; class PkPathEffect : public PathEffect { @@ -58,22 +58,22 @@ class StrokePathEffect : public PathEffect { SkPaint paint = {}; }; -static SkPaint::Cap ToSkLineCap(Stroke::Cap cap) { +static SkPaint::Cap ToSkLineCap(LineCap cap) { switch (cap) { - case Stroke::Cap::Round: + case LineCap::Round: return SkPaint::kRound_Cap; - case Stroke::Cap::Square: + case LineCap::Square: return SkPaint::kSquare_Cap; default: return SkPaint::kButt_Cap; } } -static SkPaint::Join ToSkLineJoin(Stroke::Join join) { +static SkPaint::Join ToSkLineJoin(LineJoin join) { switch (join) { - case Stroke::Join::Round: + case LineJoin::Round: return SkPaint::kRound_Join; - case Stroke::Join::Bevel: + case LineJoin::Bevel: return SkPaint::kBevel_Join; default: return SkPaint::kMiter_Join; @@ -108,4 +108,4 @@ std::unique_ptr PathEffect::MakeCorner(float radius) { } return std::unique_ptr(new PkPathEffect(std::move(effect))); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/PathMeasure.cpp b/tgfx/src/core/PathMeasure.cpp index d87f2b626d..7b1e63b9ce 100644 --- a/tgfx/src/core/PathMeasure.cpp +++ b/tgfx/src/core/PathMeasure.cpp @@ -19,7 +19,7 @@ #include "core/PathMeasure.h" #include "core/PathRef.h" -namespace pag { +namespace tgfx { using namespace pk; class PkPathMeasure : public PathMeasure { @@ -51,4 +51,4 @@ class PkPathMeasure : public PathMeasure { std::unique_ptr PathMeasure::MakeFrom(const Path& path) { return std::make_unique(PathRef::ReadAccess(path)); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/PathRef.cpp b/tgfx/src/core/PathRef.cpp index 62e79a0f0b..6c40573c84 100644 --- a/tgfx/src/core/PathRef.cpp +++ b/tgfx/src/core/PathRef.cpp @@ -19,7 +19,7 @@ #include "PathRef.h" #include "core/Path.h" -namespace pag { +namespace tgfx { using namespace pk; const SkPath& PathRef::ReadAccess(const Path& path) { @@ -29,4 +29,4 @@ const SkPath& PathRef::ReadAccess(const Path& path) { SkPath& PathRef::WriteAccess(Path& path) { return path.writableRef()->path; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/PathRef.h b/tgfx/src/core/PathRef.h index 4fcbc982f1..503efddfe7 100644 --- a/tgfx/src/core/PathRef.h +++ b/tgfx/src/core/PathRef.h @@ -20,7 +20,7 @@ #include "pathkit.h" -namespace pag { +namespace tgfx { class Path; class PathRef { @@ -41,4 +41,4 @@ class PathRef { friend bool operator==(const Path& a, const Path& b); friend bool operator!=(const Path& a, const Path& b); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/Performance.cpp b/tgfx/src/core/Performance.cpp new file mode 100644 index 0000000000..076fabff80 --- /dev/null +++ b/tgfx/src/core/Performance.cpp @@ -0,0 +1,28 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include "core/Performance.h" + +namespace tgfx { +int64_t Performance::Now() { + static const auto START_TIME = std::chrono::high_resolution_clock::now(); + auto now = std::chrono::high_resolution_clock::now(); + auto ns = std::chrono::duration_cast(now - START_TIME); + return static_cast(ns.count() * 1e-3); +} +} // namespace tgfx diff --git a/tgfx/src/core/PixelBuffer.cpp b/tgfx/src/core/PixelBuffer.cpp index feab6e2a92..71195fd7b5 100644 --- a/tgfx/src/core/PixelBuffer.cpp +++ b/tgfx/src/core/PixelBuffer.cpp @@ -21,7 +21,7 @@ #include "gpu/Device.h" #include "platform/Platform.h" -namespace pag { +namespace tgfx { class RasterPixelBuffer : public PixelBuffer { public: RasterPixelBuffer(const ImageInfo& info, uint8_t* pixels) : PixelBuffer(info), _pixels(pixels) { @@ -79,9 +79,4 @@ std::shared_ptr PixelBuffer::Make(int width, int height, bool alpha } return std::shared_ptr(new RasterPixelBuffer(info, pixels)); } - -void Trace(std::shared_ptr pixelBuffer, const std::string& tag) { - Bitmap bitmap(pixelBuffer); - Trace(bitmap, tag); -} -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/Rect.cpp b/tgfx/src/core/Rect.cpp new file mode 100644 index 0000000000..d11685ec5f --- /dev/null +++ b/tgfx/src/core/Rect.cpp @@ -0,0 +1,103 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include "core/Rect.h" + +namespace tgfx { +void Rect::scale(float scaleX, float scaleY) { + left *= scaleX; + right *= scaleY; + top *= scaleX; + bottom *= scaleY; +} + +bool Rect::setBounds(const Point pts[], int count) { + if (count <= 0) { + this->setEmpty(); + return true; + } + float minX, maxX; + float minY, maxY; + minX = maxX = pts[0].x; + minY = maxY = pts[0].y; + + for (int i = 1; i < count; i++) { + auto x = pts[i].x; + auto y = pts[i].y; + auto isFinite = ((x + y) * 0 == 0); + if (!isFinite) { + setEmpty(); + return false; + } + if (x < minX) { + minX = x; + } + if (x > maxX) { + maxX = x; + } + if (y < minY) { + minY = y; + } + if (y > maxY) { + maxY = y; + } + } + setLTRB(minX, minY, maxX, maxY); + return true; +} + +#define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \ + float L = al > bl ? al : bl; \ + float R = ar < br ? ar : br; \ + float T = at > bt ? at : bt; \ + float B = ab < bb ? ab : bb; \ + do { \ + if (!(L < R && T < B)) { \ + return false; \ + } \ + } while (0) +// do the !(opposite) check so we return false if either arg is NaN + +bool Rect::intersect(float l, float t, float r, float b) { + CHECK_INTERSECT(l, t, r, b, left, top, right, bottom); + this->setLTRB(L, T, R, B); + return true; +} + +bool Rect::intersect(const Rect& a, const Rect& b) { + CHECK_INTERSECT(a.left, a.top, a.right, a.bottom, b.left, b.top, b.right, b.bottom); + this->setLTRB(L, T, R, B); + return true; +} + +void Rect::join(float l, float t, float r, float b) { + // do nothing if the params are empty + if (l >= r || t >= b) { + return; + } + // if we are empty, just assign + if (left >= right || top >= bottom) { + this->setLTRB(l, t, r, b); + } else { + left = left < l ? left : l; + top = top < t ? top : t; + right = right > r ? right : r; + bottom = bottom > b ? bottom : b; + } +} +} // namespace tgfx diff --git a/tgfx/src/core/Stream.cpp b/tgfx/src/core/Stream.cpp index 579b20b25b..eb41b15159 100644 --- a/tgfx/src/core/Stream.cpp +++ b/tgfx/src/core/Stream.cpp @@ -18,7 +18,7 @@ #include "core/Stream.h" -namespace pag { +namespace tgfx { class FileStream : public Stream { public: @@ -69,4 +69,4 @@ std::unique_ptr Stream::MakeFromFile(const std::string& filePath) { return std::make_unique(file, length); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/TextBlob.cpp b/tgfx/src/core/TextBlob.cpp index 12d5a7536a..28077e795a 100644 --- a/tgfx/src/core/TextBlob.cpp +++ b/tgfx/src/core/TextBlob.cpp @@ -19,7 +19,7 @@ #include "core/TextBlob.h" #include "core/PathEffect.h" -namespace pag { +namespace tgfx { Rect TextBlob::getBounds(const Stroke* stroke) const { auto totalBounds = Rect::MakeEmpty(); int index = 0; @@ -62,4 +62,4 @@ bool TextBlob::getPath(Path* path, const Stroke* stroke) const { *path = totalPath; return true; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/UTF.cpp b/tgfx/src/core/UTF.cpp new file mode 100644 index 0000000000..dfdfdb2c00 --- /dev/null +++ b/tgfx/src/core/UTF.cpp @@ -0,0 +1,110 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include "core/UTF.h" + +namespace tgfx { +static int utf8_byte_type(uint8_t c) { + if (c < 0x80) { + return 1; + } else if (c < 0xC0) { + return 0; + } else if (c >= 0xF5 || (c & 0xFE) == 0xC0) { + return -1; + } else { + int value = (((0xe5 << 24) >> ((unsigned)c >> 4 << 1)) & 3) + 1; + return value; + } +} + +static bool utf8_type_is_valid_leading_byte(int type) { + return type > 0; +} + +static bool utf8_byte_is_continuation(uint8_t c) { + return utf8_byte_type(c) == 0; +} + +int UTF::CountUTF8(const char* utf8, size_t byteLength) { + if (!utf8) { + return -1; + } + int count = 0; + const char* stop = utf8 + byteLength; + while (utf8 < stop) { + int type = utf8_byte_type(*(const uint8_t*)utf8); + if (!utf8_type_is_valid_leading_byte(type) || utf8 + type > stop) { + return -1; + } + while (type-- > 1) { + ++utf8; + if (!utf8_byte_is_continuation(*(const uint8_t*)utf8)) { + return -1; + } + } + ++utf8; + ++count; + } + return count; +} + +template +static int32_t next_fail(const T** ptr, const T* end) { + *ptr = end; + return -1; +} + +static constexpr inline int32_t left_shift(int32_t value, int32_t shift) { + return (int32_t)((uint32_t)value << shift); +} + +int32_t UTF::NextUTF8(const char** ptr, const char* end) { + if (!ptr || !end) { + return -1; + } + const uint8_t* p = (const uint8_t*)*ptr; + if (!p || p >= (const uint8_t*)end) { + return next_fail(ptr, end); + } + int c = *p; + int hic = c << 24; + + if (!utf8_type_is_valid_leading_byte(utf8_byte_type(c))) { + return next_fail(ptr, end); + } + if (hic < 0) { + uint32_t mask = (uint32_t)~0x3F; + hic = left_shift(hic, 1); + do { + ++p; + if (p >= (const uint8_t*)end) { + return next_fail(ptr, end); + } + uint8_t nextByte = *p; + if (!utf8_byte_is_continuation(nextByte)) { + return next_fail(ptr, end); + } + c = (c << 6) | (nextByte & 0x3F); + mask <<= 5; + } while ((hic = left_shift(hic, 1)) < 0); + c &= ~mask; + } + *ptr = (char*)p + 1; + return c; +} +} // namespace tgfx diff --git a/tgfx/src/core/images/jpeg/JpegImage.cpp b/tgfx/src/core/images/jpeg/JpegImage.cpp index 821e5e7e8d..79ad37c33d 100644 --- a/tgfx/src/core/images/jpeg/JpegImage.cpp +++ b/tgfx/src/core/images/jpeg/JpegImage.cpp @@ -26,7 +26,7 @@ extern "C" { #include "jpeglib.h" } -namespace pag { +namespace tgfx { bool JpegImage::IsJpeg(const std::shared_ptr& data) { constexpr uint8_t jpegSig[] = {0xFF, 0xD8, 0xFF}; @@ -212,4 +212,4 @@ std::shared_ptr JpegImage::Encode(const ImageInfo& imageInfo, const void* } #endif -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/images/jpeg/JpegImage.h b/tgfx/src/core/images/jpeg/JpegImage.h index 9b55bd9d9a..e7f738856e 100644 --- a/tgfx/src/core/images/jpeg/JpegImage.h +++ b/tgfx/src/core/images/jpeg/JpegImage.h @@ -20,7 +20,7 @@ #include "core/Image.h" -namespace pag { +namespace tgfx { class JpegImage : public Image { public: static std::shared_ptr MakeFrom(const std::string& filePath); @@ -49,4 +49,4 @@ class JpegImage : public Image { } }; -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/images/png/PngImage.cpp b/tgfx/src/core/images/png/PngImage.cpp index 7873639649..15ca57dfea 100644 --- a/tgfx/src/core/images/png/PngImage.cpp +++ b/tgfx/src/core/images/png/PngImage.cpp @@ -20,7 +20,7 @@ #include "core/Bitmap.h" #include "png.h" -namespace pag { +namespace tgfx { std::shared_ptr PngImage::MakeFrom(const std::string& filePath) { return MakeFromData(filePath, nullptr); } @@ -350,4 +350,4 @@ std::shared_ptr PngImage::Encode(const ImageInfo& imageInfo, const void* p } #endif -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/images/png/PngImage.h b/tgfx/src/core/images/png/PngImage.h index ea45aca3e7..6644fa0c16 100644 --- a/tgfx/src/core/images/png/PngImage.h +++ b/tgfx/src/core/images/png/PngImage.h @@ -20,7 +20,7 @@ #include "core/Image.h" -namespace pag { +namespace tgfx { struct ReadInfo; @@ -52,4 +52,4 @@ class PngImage : public Image { } bool readPixelsInternal(const ImageInfo& dstInfo, void* dstPixels, ReadInfo& readInfo) const; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/images/webp/WebpImage.cpp b/tgfx/src/core/images/webp/WebpImage.cpp index 68bb333ea5..4098382027 100644 --- a/tgfx/src/core/images/webp/WebpImage.cpp +++ b/tgfx/src/core/images/webp/WebpImage.cpp @@ -20,7 +20,7 @@ #include "core/Bitmap.h" #include "core/images/webp/WebpUtility.h" -namespace pag { +namespace tgfx { bool WebpImage::IsWebp(const std::shared_ptr& data) { const char* bytes = static_cast(data->data()); @@ -30,8 +30,8 @@ bool WebpImage::IsWebp(const std::shared_ptr& data) { std::shared_ptr WebpImage::MakeFrom(const std::string& filePath) { auto info = WebpUtility::getDecodeInfo(filePath); if (info.width == 0 || info.height == 0) { - auto data = ByteData::FromPath(filePath); - info = WebpUtility::getDecodeInfo(data->data(), data->length()); + auto data = Data::MakeFromFile(filePath); + info = WebpUtility::getDecodeInfo(data->data(), data->size()); if (info.width == 0 || info.height == 0) { return nullptr; } @@ -207,4 +207,4 @@ std::shared_ptr WebpImage::Encode(const ImageInfo& imageInfo, const void* } #endif -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/images/webp/WebpImage.h b/tgfx/src/core/images/webp/WebpImage.h index a87f9e6e2c..2100634325 100644 --- a/tgfx/src/core/images/webp/WebpImage.h +++ b/tgfx/src/core/images/webp/WebpImage.h @@ -23,7 +23,7 @@ #include "webp/demux.h" #include "webp/encode.h" -namespace pag { +namespace tgfx { class WebpImage : public Image { public: static std::shared_ptr MakeFrom(const std::string& filePath); @@ -50,4 +50,4 @@ class WebpImage : public Image { } }; -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/images/webp/WebpUtility.cpp b/tgfx/src/core/images/webp/WebpUtility.cpp index 710c9bec7b..000360ffa1 100644 --- a/tgfx/src/core/images/webp/WebpUtility.cpp +++ b/tgfx/src/core/images/webp/WebpUtility.cpp @@ -19,13 +19,13 @@ #include "core/images/webp/WebpUtility.h" #include #include -#include "base/utils/Log.h" +#include "core/utils/Log.h" #include "core/utils/OrientationHelper.h" #include "webp/decode.h" #include "webp/demux.h" #include "webp/encode.h" -namespace pag { +namespace tgfx { #define VP8L_MAGIC_BYTE 0x2f // VP8L signature byte. #define VP8L_FRAME_HEADER_SIZE 5 // Size of the VP8L frame header. @@ -339,4 +339,4 @@ DecodeInfo WebpUtility::getDecodeInfo(const void* fileBytes, size_t byteLength) return {width, height, origin}; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/images/webp/WebpUtility.h b/tgfx/src/core/images/webp/WebpUtility.h index 9704f347dc..c1009d81bd 100644 --- a/tgfx/src/core/images/webp/WebpUtility.h +++ b/tgfx/src/core/images/webp/WebpUtility.h @@ -18,9 +18,10 @@ #pragma once +#include #include "core/Orientation.h" -namespace pag { +namespace tgfx { struct DecodeInfo { int width = 0; @@ -35,4 +36,4 @@ class WebpUtility { static DecodeInfo getDecodeInfo(const void* fileBytes, size_t byteLength); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/utils/EnumHasher.h b/tgfx/src/core/utils/EnumHasher.h new file mode 100644 index 0000000000..0653996c8b --- /dev/null +++ b/tgfx/src/core/utils/EnumHasher.h @@ -0,0 +1,32 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include + +namespace tgfx { + +struct EnumHasher { + template + size_t operator()(T t) const { + return static_cast(t); + } +}; + +} // namespace tgfx diff --git a/tgfx/src/core/utils/Log.h b/tgfx/src/core/utils/Log.h new file mode 100644 index 0000000000..e64d72c65e --- /dev/null +++ b/tgfx/src/core/utils/Log.h @@ -0,0 +1,57 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include "platform/Print.h" + +namespace tgfx { +#define ABORT(msg) \ + do { \ + tgfx::PrintError("%s:%d: fatal error: \"%s\"\n", __FILE__, __LINE__, #msg); \ + ::abort(); \ + } while (false) + +#ifdef NO_LOG + +#define LOGI(...) +#define LOGE(...) +#define ASSERT(assertion) + +#else + +#define LOGI(...) tgfx::PrintLog(__VA_ARGS__) +#define LOGE(...) tgfx::PrintError(__VA_ARGS__) +#define ASSERT(assertion) \ + if (!(assertion)) { \ + ABORT(#assertion); \ + } + +#endif + +#if DEBUG + +#define DEBUG_ASSERT(assertion) ASSERT(assertion) + +#else + +#define DEBUG_ASSERT(assertion) + +#endif +} // namespace tgfx diff --git a/src/base/utils/MathExtra.h b/tgfx/src/core/utils/MathExtra.h similarity index 87% rename from src/base/utils/MathExtra.h rename to tgfx/src/core/utils/MathExtra.h index dab868342d..a19d1ee250 100644 --- a/src/base/utils/MathExtra.h +++ b/tgfx/src/core/utils/MathExtra.h @@ -20,14 +20,19 @@ #include -namespace pag { +namespace tgfx { static constexpr float M_PI_F = static_cast(M_PI); static constexpr float M_PI_2_F = static_cast(M_PI_2); static constexpr float FLOAT_NEARLY_ZERO = 1.0f / (1 << 12); static constexpr float FLOAT_SQRT2 = 1.41421356f; -#define DegreesToRadians(degrees) ((degrees) * (M_PI_F / 180.0f)) -#define RadiansToDegrees(radians) ((radians) * (180.0f / M_PI_F)) +static inline float DegreesToRadians(float degrees) { + return degrees * (static_cast(M_PI) / 180.0f); +} + +static inline float RadiansToDegrees(float radians) { + return radians * (180.0f / static_cast(M_PI)); +} static inline bool FloatNearlyZero(float x, float tolerance = FLOAT_NEARLY_ZERO) { return fabsf(x) <= tolerance; @@ -54,4 +59,4 @@ static inline bool FloatsAreFinite(const float array[], int count) { } return prod == 0; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/utils/OrientationHelper.h b/tgfx/src/core/utils/OrientationHelper.h index 24e1be6e65..d6778bd9c5 100644 --- a/tgfx/src/core/utils/OrientationHelper.h +++ b/tgfx/src/core/utils/OrientationHelper.h @@ -20,7 +20,7 @@ #include "core/Orientation.h" -namespace pag { +namespace tgfx { /* * @param data Buffer to read bytes from * @param isLittleEndian Output parameter @@ -97,4 +97,4 @@ static bool is_orientation_marker(const uint8_t* data, size_t data_length, return false; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/utils/UniqueID.cpp b/tgfx/src/core/utils/UniqueID.cpp new file mode 100644 index 0000000000..893059f2df --- /dev/null +++ b/tgfx/src/core/utils/UniqueID.cpp @@ -0,0 +1,28 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include "UniqueID.h" + +namespace tgfx { + +static std::atomic_uint32_t IDCount = {1}; + +uint32_t UniqueID::Next() { + return IDCount++; +} +} // namespace tgfx \ No newline at end of file diff --git a/src/base/utils/UTF8Text.h b/tgfx/src/core/utils/UniqueID.h similarity index 83% rename from src/base/utils/UTF8Text.h rename to tgfx/src/core/utils/UniqueID.h index c4a842a6d6..e65b60c5f9 100644 --- a/src/base/utils/UTF8Text.h +++ b/tgfx/src/core/utils/UniqueID.h @@ -18,14 +18,11 @@ #pragma once -#include -#include +#include -namespace pag { -class UTF8Text { +namespace tgfx { +class UniqueID { public: - static int Count(const std::string& string); - - static int32_t NextChar(const char** ptr); + static uint32_t Next(); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/coregraphics/CGMask.cpp b/tgfx/src/core/vectors/coregraphics/CGMask.cpp index 8a774a8e31..26926b276a 100644 --- a/tgfx/src/core/vectors/coregraphics/CGMask.cpp +++ b/tgfx/src/core/vectors/coregraphics/CGMask.cpp @@ -21,7 +21,7 @@ #include "core/Mask.h" #include "platform/apple/BitmapContextUtil.h" -namespace pag { +namespace tgfx { static void Iterator(PathVerb verb, const Point points[4], void* info) { auto cgPath = reinterpret_cast(info); switch (verb) { @@ -106,4 +106,4 @@ void CGMask::fillPath(const Path& path) { CGPathRelease(cgPath); buffer->unlockPixels(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/coregraphics/CGMask.h b/tgfx/src/core/vectors/coregraphics/CGMask.h index 0a47eae473..71236c7a74 100644 --- a/tgfx/src/core/vectors/coregraphics/CGMask.h +++ b/tgfx/src/core/vectors/coregraphics/CGMask.h @@ -21,7 +21,7 @@ #include "core/Mask.h" #include "core/PixelBuffer.h" -namespace pag { +namespace tgfx { class CGMask : public Mask { public: explicit CGMask(std::shared_ptr buffer); @@ -39,4 +39,4 @@ class CGMask : public Mask { private: std::shared_ptr buffer = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/coregraphics/CGScalerContext.cpp b/tgfx/src/core/vectors/coregraphics/CGScalerContext.cpp index 5ca38a350e..a534d4b9a7 100644 --- a/tgfx/src/core/vectors/coregraphics/CGScalerContext.cpp +++ b/tgfx/src/core/vectors/coregraphics/CGScalerContext.cpp @@ -18,12 +18,16 @@ #include "core/vectors/coregraphics/CGScalerContext.h" #include "base/utils/Interpolate.h" -#include "base/utils/Log.h" -#include "base/utils/MathExtra.h" #include "core/PathEffect.h" +#include "core/utils/Log.h" +#include "core/utils/MathExtra.h" #include "platform/apple/BitmapContextUtil.h" -namespace pag { +namespace tgfx { +inline float Interpolate(const float& a, const float& b, const float& t) { + return a + (b - a) * t; +} + /** * Interpolate along the function described by (keys[length], values[length]) * for the passed searchKey. SearchKeys outside the range keys[0]-keys[Length] @@ -304,4 +308,4 @@ std::shared_ptr CGScalerContext::generateImage(GlyphID glyphID, M } return pixelBuffer; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/coregraphics/CGScalerContext.h b/tgfx/src/core/vectors/coregraphics/CGScalerContext.h index bd0db4400f..16c7917b2b 100644 --- a/tgfx/src/core/vectors/coregraphics/CGScalerContext.h +++ b/tgfx/src/core/vectors/coregraphics/CGScalerContext.h @@ -22,7 +22,7 @@ #include "core/ImageInfo.h" #include "core/PixelBuffer.h" -namespace pag { +namespace tgfx { class CGScalerContextRec { public: float textSize = 12.f; @@ -55,4 +55,4 @@ class CGScalerContext { CTFontRef ctFont = nullptr; CGAffineTransform transform = CGAffineTransformIdentity; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/coregraphics/CGTextBlob.cpp b/tgfx/src/core/vectors/coregraphics/CGTextBlob.cpp index c59bf39efd..40670cb6e3 100644 --- a/tgfx/src/core/vectors/coregraphics/CGTextBlob.cpp +++ b/tgfx/src/core/vectors/coregraphics/CGTextBlob.cpp @@ -18,7 +18,7 @@ #include "CGTextBlob.h" -namespace pag { +namespace tgfx { std::shared_ptr TextBlob::MakeFrom(const GlyphID glyphIDs[], const Point positions[], size_t glyphCount, const Font& font) { if (glyphCount == 0) { @@ -37,4 +37,4 @@ std::shared_ptr CGTextBlob::getImage(float /*resolutionScale*/, // completed GLCanvas.drawColorGlyphs(). return nullptr; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/coregraphics/CGTextBlob.h b/tgfx/src/core/vectors/coregraphics/CGTextBlob.h index 2119496b10..e348bc4ce5 100644 --- a/tgfx/src/core/vectors/coregraphics/CGTextBlob.h +++ b/tgfx/src/core/vectors/coregraphics/CGTextBlob.h @@ -20,9 +20,9 @@ #include "core/TextBlob.h" -namespace pag { +namespace tgfx { class CGTextBlob : public TextBlob { public: std::shared_ptr getImage(float resolutionScale, Matrix* matrix) const; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/coregraphics/CGTypeface.cpp b/tgfx/src/core/vectors/coregraphics/CGTypeface.cpp index 85d17a7134..c1f342636f 100644 --- a/tgfx/src/core/vectors/coregraphics/CGTypeface.cpp +++ b/tgfx/src/core/vectors/coregraphics/CGTypeface.cpp @@ -18,10 +18,10 @@ #include "CGTypeface.h" #include "CGScalerContext.h" -#include "base/utils/UTF8Text.h" -#include "base/utils/UniqueID.h" +#include "core/UTF.h" +#include "core/utils/UniqueID.h" -namespace pag { +namespace tgfx { std::string StringFromCFString(CFStringRef src) { static const CFIndex kCStringSize = 128; char temporaryCString[kCStringSize]; @@ -177,7 +177,7 @@ static size_t ToUTF16(int32_t uni, uint16_t utf16[2]) { GlyphID CGTypeface::getGlyphID(const std::string& name) const { const char* start = &(name[0]); - auto uni = UTF8Text::NextChar(&start); + auto uni = UTF::NextUTF8(&start, start + name.size()); UniChar utf16[2] = {0, 0}; auto srcCount = ToUTF16(uni, utf16); GlyphID macGlyphs[2] = {0, 0}; @@ -245,4 +245,4 @@ Point CGTypeface::getGlyphVerticalOffset(GlyphID glyphID, float size, bool fauxB } return scalerContext->getGlyphVerticalOffset(glyphID); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/coregraphics/CGTypeface.h b/tgfx/src/core/vectors/coregraphics/CGTypeface.h index aa0a2e153c..a0ee3e82dc 100644 --- a/tgfx/src/core/vectors/coregraphics/CGTypeface.h +++ b/tgfx/src/core/vectors/coregraphics/CGTypeface.h @@ -21,14 +21,14 @@ #include #include "core/Typeface.h" -namespace pag { +namespace tgfx { class CGTypeface : public Typeface { public: static std::shared_ptr Make(CTFontRef ctFont); ~CGTypeface() override; - ID uniqueID() const override { + uint32_t uniqueID() const override { return _uniqueID; } @@ -66,10 +66,10 @@ class CGTypeface : public Typeface { private: explicit CGTypeface(CTFontRef ctFont); - ID _uniqueID; + uint32_t _uniqueID = 0; CTFontRef ctFont = nullptr; std::weak_ptr weakThis; friend class CGScalerContext; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTFace.cpp b/tgfx/src/core/vectors/freetype/FTFace.cpp index 2d9d90bab5..52264c1c6a 100644 --- a/tgfx/src/core/vectors/freetype/FTFace.cpp +++ b/tgfx/src/core/vectors/freetype/FTFace.cpp @@ -19,7 +19,7 @@ #include "FTFace.h" #include "FTUtil.h" -namespace pag { +namespace tgfx { std::mutex& FTMutex() { static std::mutex& mutex = *new std::mutex; return mutex; @@ -64,7 +64,7 @@ std::unique_ptr FTFace::Make(const FTFontData& data) { if (data.path.empty()) { args.flags = FT_OPEN_MEMORY; args.memory_base = static_cast(data.data->data()); - args.memory_size = static_cast(data.data->length()); + args.memory_size = static_cast(data.data->size()); } else { args.flags = FT_OPEN_PATHNAME; args.pathname = const_cast(data.path.c_str()); @@ -78,4 +78,4 @@ std::unique_ptr FTFace::Make(const FTFontData& data) { } return face; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTFace.h b/tgfx/src/core/vectors/freetype/FTFace.h index 51b9e9bbcb..d22d33ee0c 100644 --- a/tgfx/src/core/vectors/freetype/FTFace.h +++ b/tgfx/src/core/vectors/freetype/FTFace.h @@ -19,13 +19,12 @@ #pragma once #include - +#include #include "FTFontData.h" - #include "ft2build.h" #include FT_FREETYPE_H -namespace pag { +namespace tgfx { std::mutex& FTMutex(); class FTFace { @@ -38,4 +37,4 @@ class FTFace { FT_Face face = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTFontData.h b/tgfx/src/core/vectors/freetype/FTFontData.h index 17b07ab6fa..14a2e5682a 100644 --- a/tgfx/src/core/vectors/freetype/FTFontData.h +++ b/tgfx/src/core/vectors/freetype/FTFontData.h @@ -19,19 +19,19 @@ #pragma once #include -#include "pag/types.h" +#include "core/Data.h" -namespace pag { +namespace tgfx { struct FTFontData { FTFontData(std::string path, int ttcIndex) : path(std::move(path)), ttcIndex(ttcIndex) { } FTFontData(const void* data, size_t length, int ttcIndex) - : data(ByteData::MakeCopy(data, length)), ttcIndex(ttcIndex) { + : data(Data::MakeWithCopy(data, length)), ttcIndex(ttcIndex) { } std::string path; - std::unique_ptr data; + std::shared_ptr data; int ttcIndex = -1; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTMask.cpp b/tgfx/src/core/vectors/freetype/FTMask.cpp index bd92068e43..eb804d5805 100644 --- a/tgfx/src/core/vectors/freetype/FTMask.cpp +++ b/tgfx/src/core/vectors/freetype/FTMask.cpp @@ -21,7 +21,7 @@ #include "core/Bitmap.h" #include FT_STROKER_H -namespace pag { +namespace tgfx { static const FTLibrary& GetLibrary() { static const auto& library = *new FTLibrary; return library; @@ -88,4 +88,4 @@ void FTMask::fillPath(const Path& path) { FT_Outline_Get_Bitmap(ftLibrary, &(outline->outline), &bitmap); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTMask.h b/tgfx/src/core/vectors/freetype/FTMask.h index c30e42bf55..5b6c525fbe 100644 --- a/tgfx/src/core/vectors/freetype/FTMask.h +++ b/tgfx/src/core/vectors/freetype/FTMask.h @@ -21,7 +21,7 @@ #include "core/Mask.h" #include "core/PixelBuffer.h" -namespace pag { +namespace tgfx { class FTMask : public Mask { public: explicit FTMask(std::shared_ptr buffer); @@ -39,4 +39,4 @@ class FTMask : public Mask { private: std::shared_ptr buffer = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTPath.cpp b/tgfx/src/core/vectors/freetype/FTPath.cpp index 941ad3c4dd..7a20ceac95 100644 --- a/tgfx/src/core/vectors/freetype/FTPath.cpp +++ b/tgfx/src/core/vectors/freetype/FTPath.cpp @@ -18,7 +18,7 @@ #include "FTPath.h" -namespace pag { +namespace tgfx { bool FTPath::isEmpty() const { return points.empty(); } @@ -127,4 +127,4 @@ bool FTPath::finalizeOutline(FreetypeOutline* outline, int startPointIndex) cons return true; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/core/vectors/freetype/FTPath.h b/tgfx/src/core/vectors/freetype/FTPath.h index e760525b77..3b87049186 100644 --- a/tgfx/src/core/vectors/freetype/FTPath.h +++ b/tgfx/src/core/vectors/freetype/FTPath.h @@ -22,7 +22,7 @@ #include "core/Path.h" #include FT_STROKER_H -namespace pag { +namespace tgfx { struct FreetypeOutline { FT_Outline outline = {}; std::vector contours = {}; @@ -55,4 +55,4 @@ class FTPath { std::vector contours = {}; PathFillType fillType = PathFillType::Winding; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTScalerContext.cpp b/tgfx/src/core/vectors/freetype/FTScalerContext.cpp index c4a4759465..600d88deb9 100644 --- a/tgfx/src/core/vectors/freetype/FTScalerContext.cpp +++ b/tgfx/src/core/vectors/freetype/FTScalerContext.cpp @@ -24,12 +24,12 @@ #include FT_SIZES_H #include FT_TRUETYPE_TABLES_H #include "FTUtil.h" -#include "base/utils/Log.h" -#include "base/utils/MathExtra.h" #include "core/Bitmap.h" +#include "core/utils/Log.h" +#include "core/utils/MathExtra.h" #include "skcms.h" -namespace pag { +namespace tgfx { static float FTFixedToFloat(FT_Fixed x) { return static_cast(x) * 1.52587890625e-5f; } @@ -672,4 +672,4 @@ std::shared_ptr FTScalerContext::generateImage(GlyphID glyphId, M } return pixelBuffer; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTScalerContext.h b/tgfx/src/core/vectors/freetype/FTScalerContext.h index 20454d7e56..d332b2ea5e 100644 --- a/tgfx/src/core/vectors/freetype/FTScalerContext.h +++ b/tgfx/src/core/vectors/freetype/FTScalerContext.h @@ -25,7 +25,7 @@ #include "FTTypeface.h" #include "core/PixelBuffer.h" -namespace pag { +namespace tgfx { class FTScalerContextRec { public: bool computeMatrices(Point* scale, Matrix* remaining) const; @@ -77,4 +77,4 @@ class FTScalerContext { Point scale = Point::Make(1.f, 1.f); FT_Int32 loadGlyphFlags = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTTextBlob.cpp b/tgfx/src/core/vectors/freetype/FTTextBlob.cpp index f22e85d4b1..b2355bcad1 100644 --- a/tgfx/src/core/vectors/freetype/FTTextBlob.cpp +++ b/tgfx/src/core/vectors/freetype/FTTextBlob.cpp @@ -18,7 +18,7 @@ #include "FTTextBlob.h" -namespace pag { +namespace tgfx { std::shared_ptr TextBlob::MakeFrom(const GlyphID glyphIDs[], const Point positions[], size_t glyphCount, const Font& font) { if (glyphCount == 0) { @@ -37,4 +37,4 @@ std::shared_ptr FTTextBlob::getImage(float /*resolutionScale*/, // completed GLCanvas.drawColorGlyphs(). return nullptr; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTTextBlob.h b/tgfx/src/core/vectors/freetype/FTTextBlob.h index 264af38b7c..eeb60258ad 100644 --- a/tgfx/src/core/vectors/freetype/FTTextBlob.h +++ b/tgfx/src/core/vectors/freetype/FTTextBlob.h @@ -20,9 +20,9 @@ #include "core/TextBlob.h" -namespace pag { +namespace tgfx { class FTTextBlob : public TextBlob { public: std::shared_ptr getImage(float resolutionScale, Matrix* matrix) const; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTTypeface.cpp b/tgfx/src/core/vectors/freetype/FTTypeface.cpp index e90ff16438..5edcd8742c 100644 --- a/tgfx/src/core/vectors/freetype/FTTypeface.cpp +++ b/tgfx/src/core/vectors/freetype/FTTypeface.cpp @@ -21,13 +21,13 @@ #include FT_TRUETYPE_TABLES_H #include "FTScalerContext.h" -#include "base/utils/UTF8Text.h" -#include "base/utils/UniqueID.h" +#include "core/UTF.h" +#include "core/utils/UniqueID.h" -namespace pag { +namespace tgfx { class EmptyTypeface : public Typeface { public: - ID uniqueID() const override { + uint32_t uniqueID() const override { return _uniqueID; } @@ -81,7 +81,7 @@ class EmptyTypeface : public Typeface { } private: - ID _uniqueID = UniqueID::Next(); + uint32_t _uniqueID = UniqueID::Next(); }; std::shared_ptr Typeface::MakeFromName(const std::string& /*fontFamily*/, @@ -148,12 +148,13 @@ GlyphID FTTypeface::getGlyphID(const std::string& name) const { if (name.empty()) { return 0; } - auto count = UTF8Text::Count(name); + auto count = tgfx::UTF::CountUTF8(name.c_str(), name.size()); if (count > 1 || count <= 0) { return 0; } const char* start = &(name[0]); - return FT_Get_Char_Index(_face->face, static_cast(UTF8Text::NextChar(&start))); + auto unichar = tgfx::UTF::NextUTF8(&start, start + name.size()); + return FT_Get_Char_Index(_face->face, static_cast(unichar)); } FontMetrics FTTypeface::getMetrics(float size) const { @@ -220,4 +221,4 @@ Point FTTypeface::getGlyphVerticalOffset(GlyphID glyphID, float size, bool fauxB auto glyphMetrics = scalerContext->generateGlyphMetrics(glyphID); return {-glyphMetrics.advanceX * 0.5f, offsetY}; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTTypeface.h b/tgfx/src/core/vectors/freetype/FTTypeface.h index 99d8fd1cbb..8e4f2532f4 100644 --- a/tgfx/src/core/vectors/freetype/FTTypeface.h +++ b/tgfx/src/core/vectors/freetype/FTTypeface.h @@ -26,14 +26,14 @@ #include "core/Font.h" #include "core/Typeface.h" -namespace pag { +namespace tgfx { class FTTypeface : public Typeface { public: static std::shared_ptr Make(FTFontData data); ~FTTypeface() override; - ID uniqueID() const override { + uint32_t uniqueID() const override { return _uniqueID; } @@ -75,11 +75,11 @@ class FTTypeface : public Typeface { private: FTTypeface(FTFontData data, std::unique_ptr face); - ID _uniqueID; + uint32_t _uniqueID = 0; FTFontData data; std::unique_ptr _face; std::weak_ptr weakThis; friend class FTScalerContext; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTUtil.cpp b/tgfx/src/core/vectors/freetype/FTUtil.cpp index 3eea46460e..e629d6107f 100644 --- a/tgfx/src/core/vectors/freetype/FTUtil.cpp +++ b/tgfx/src/core/vectors/freetype/FTUtil.cpp @@ -20,7 +20,7 @@ #include FT_MODULE_H -namespace pag { +namespace tgfx { FTLibrary::FTLibrary() { FT_Init_FreeType(&_library); } @@ -30,4 +30,4 @@ FTLibrary::~FTLibrary() { FT_Done_Library(_library); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/freetype/FTUtil.h b/tgfx/src/core/vectors/freetype/FTUtil.h index d3b7b1dfd4..31967e8e44 100644 --- a/tgfx/src/core/vectors/freetype/FTUtil.h +++ b/tgfx/src/core/vectors/freetype/FTUtil.h @@ -23,7 +23,7 @@ #include "ft2build.h" #include FT_FREETYPE_H -namespace pag { +namespace tgfx { inline FT_F26Dot6 FloatToFDot6(float x) { return static_cast(x * 64.f); } @@ -62,4 +62,4 @@ class FTLibrary { FT_Library _library = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/web/WebMask.cpp b/tgfx/src/core/vectors/web/WebMask.cpp index d6393197e2..64bec3e344 100644 --- a/tgfx/src/core/vectors/web/WebMask.cpp +++ b/tgfx/src/core/vectors/web/WebMask.cpp @@ -23,7 +23,7 @@ using namespace emscripten; -namespace pag { +namespace tgfx { std::shared_ptr Mask::Make(int width, int height) { auto webMaskClass = val::module_property("WebMask"); if (!webMaskClass.as()) { @@ -111,4 +111,4 @@ bool WebMask::drawText(const TextBlob* textBlob, const Stroke* stroke) { } return true; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/web/WebMask.h b/tgfx/src/core/vectors/web/WebMask.h index 2115cbe564..9646ed5468 100644 --- a/tgfx/src/core/vectors/web/WebMask.h +++ b/tgfx/src/core/vectors/web/WebMask.h @@ -21,7 +21,7 @@ #include #include "core/Mask.h" -namespace pag { +namespace tgfx { class WebMask : public Mask { public: explicit WebMask(int width, int height, emscripten::val webMask) @@ -41,4 +41,4 @@ class WebMask : public Mask { emscripten::val webMask = emscripten::val::null(); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/web/WebTextBlob.cpp b/tgfx/src/core/vectors/web/WebTextBlob.cpp index 59f923b565..8bb2e9f320 100644 --- a/tgfx/src/core/vectors/web/WebTextBlob.cpp +++ b/tgfx/src/core/vectors/web/WebTextBlob.cpp @@ -19,7 +19,7 @@ #include "WebTextBlob.h" #include "WebTypeface.h" -namespace pag { +namespace tgfx { std::shared_ptr TextBlob::MakeFrom(const GlyphID* glyphIDs, const Point* positions, size_t glyphCount, const Font& font) { if (glyphCount == 0) { @@ -47,4 +47,4 @@ std::shared_ptr WebTextBlob::getImage(float /*resolutionScale*/, // completed GLCanvas.drawColorGlyphs(). return nullptr; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/web/WebTextBlob.h b/tgfx/src/core/vectors/web/WebTextBlob.h index 163aad9722..6b4e3221a9 100644 --- a/tgfx/src/core/vectors/web/WebTextBlob.h +++ b/tgfx/src/core/vectors/web/WebTextBlob.h @@ -20,7 +20,7 @@ #include "core/TextBlob.h" -namespace pag { +namespace tgfx { class WebTextBlob : public TextBlob { public: const Font& getFont() const { @@ -31,4 +31,4 @@ class WebTextBlob : public TextBlob { std::shared_ptr getImage(float resolutionScale, Matrix* matrix) const override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/web/WebTypeface.cpp b/tgfx/src/core/vectors/web/WebTypeface.cpp index 445c311556..8480bd53c2 100644 --- a/tgfx/src/core/vectors/web/WebTypeface.cpp +++ b/tgfx/src/core/vectors/web/WebTypeface.cpp @@ -18,13 +18,13 @@ #include "WebTypeface.h" #include -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "platform/web/NativeTextureBuffer.h" #include "rendering/FontManager.h" using namespace emscripten; -namespace pag { +namespace tgfx { std::shared_ptr Typeface::MakeFromName(const std::string& name, const std::string&) { return WebTypeface::Make(name); } @@ -154,4 +154,4 @@ std::shared_ptr WebTypeface::getGlyphImage(GlyphID glyphID, float } return NativeTextureBuffer::Make(buffer.call("width"), buffer.call("height"), buffer); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/core/vectors/web/WebTypeface.h b/tgfx/src/core/vectors/web/WebTypeface.h index 659b773730..961177e8e3 100644 --- a/tgfx/src/core/vectors/web/WebTypeface.h +++ b/tgfx/src/core/vectors/web/WebTypeface.h @@ -24,14 +24,14 @@ #include "core/Font.h" #include "core/Typeface.h" -namespace pag { +namespace tgfx { class WebTypeface : public Typeface { public: static std::shared_ptr Make(const std::string& name); ~WebTypeface() override; - ID uniqueID() const override { + uint32_t uniqueID() const override { return _uniqueID; } @@ -76,10 +76,10 @@ class WebTypeface : public Typeface { private: explicit WebTypeface(std::string name); - ID _uniqueID; + uint32_t _uniqueID; std::unordered_map* fontMetricsMap = new std::unordered_map; emscripten::val scalerContextClass = emscripten::val::null(); std::string name; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/AAType.h b/tgfx/src/gpu/AAType.h index 3812bc0865..dfea3e2aaa 100644 --- a/tgfx/src/gpu/AAType.h +++ b/tgfx/src/gpu/AAType.h @@ -18,7 +18,7 @@ #pragma once -namespace pag { +namespace tgfx { enum class AAType { // No antialiasing. None, diff --git a/tgfx/src/gpu/AlphaFragmentProcessor.cpp b/tgfx/src/gpu/AlphaFragmentProcessor.cpp index 049bd014b2..bcefaa638c 100644 --- a/tgfx/src/gpu/AlphaFragmentProcessor.cpp +++ b/tgfx/src/gpu/AlphaFragmentProcessor.cpp @@ -17,10 +17,10 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "AlphaFragmentProcessor.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "opengl/GLAlphaFragmentProcessor.h" -namespace pag { +namespace tgfx { std::unique_ptr AlphaFragmentProcessor::Make(float alpha) { return std::unique_ptr(new AlphaFragmentProcessor(alpha)); } @@ -33,4 +33,4 @@ void AlphaFragmentProcessor::onComputeProcessorKey(BytesKey* bytesKey) const { std::unique_ptr AlphaFragmentProcessor::onCreateGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/AlphaFragmentProcessor.h b/tgfx/src/gpu/AlphaFragmentProcessor.h index 820d324f12..d621e3552d 100644 --- a/tgfx/src/gpu/AlphaFragmentProcessor.h +++ b/tgfx/src/gpu/AlphaFragmentProcessor.h @@ -20,7 +20,7 @@ #include "FragmentProcessor.h" -namespace pag { +namespace tgfx { class AlphaFragmentProcessor : public FragmentProcessor { public: static std::unique_ptr Make(float alpha); @@ -41,4 +41,4 @@ class AlphaFragmentProcessor : public FragmentProcessor { friend class GLAlphaFragmentProcessor; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/Backend.cpp b/tgfx/src/gpu/Backend.cpp index 51ed92a885..9542f55d34 100644 --- a/tgfx/src/gpu/Backend.cpp +++ b/tgfx/src/gpu/Backend.cpp @@ -16,10 +16,9 @@ // ///////////////////////////////////////////////////////////////////////////////////////////////// -#include -#include "pag/gpu.h" +#include "gpu/Backend.h" -namespace pag { +namespace tgfx { BackendTexture::BackendTexture(const GLTextureInfo& glInfo, int width, int height) : _backend(Backend::OPENGL), _width(width), _height(height), glInfo(glInfo) { } @@ -134,4 +133,4 @@ void* BackendSemaphore::glSync() const { } return _glSync; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/BitmaskOperators.h b/tgfx/src/gpu/BitmaskOperators.h index 6b48560f94..b9b645cfe3 100644 --- a/tgfx/src/gpu/BitmaskOperators.h +++ b/tgfx/src/gpu/BitmaskOperators.h @@ -20,7 +20,7 @@ #include -namespace pag { +namespace tgfx { #define TGFX_MARK_AS_BITMASK_ENUM(LargestValue) TGFX_BITMASK_LARGEST_ENUMERATOR = LargestValue /// Traits class to determine whether an enum has a @@ -87,4 +87,4 @@ E& operator^=(E& LHS, E RHS) { LHS = LHS ^ RHS; return LHS; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/Canvas.cpp b/tgfx/src/gpu/Canvas.cpp index c1b3800fad..5cc42869db 100644 --- a/tgfx/src/gpu/Canvas.cpp +++ b/tgfx/src/gpu/Canvas.cpp @@ -19,7 +19,7 @@ #include "gpu/Canvas.h" #include "gpu/Surface.h" -namespace pag { +namespace tgfx { Canvas::Canvas(Surface* surface) : surface(surface) { globalPaint.clip.addRect(0, 0, static_cast(surface->width()), static_cast(surface->height())); @@ -66,11 +66,11 @@ void Canvas::setAlpha(float newAlpha) { globalPaint.alpha = newAlpha; } -Blend Canvas::getBlendMode() const { +BlendMode Canvas::getBlendMode() const { return globalPaint.blendMode; } -void Canvas::setBlendMode(Blend blendMode) { +void Canvas::setBlendMode(BlendMode blendMode) { globalPaint.blendMode = blendMode; } @@ -113,4 +113,4 @@ Surface* Canvas::getSurface() const { const SurfaceOptions* Canvas::surfaceOptions() const { return surface->options(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/Caps.h b/tgfx/src/gpu/Caps.h index 2c8e9cc74b..8b37825c33 100644 --- a/tgfx/src/gpu/Caps.h +++ b/tgfx/src/gpu/Caps.h @@ -18,9 +18,9 @@ #pragma once -namespace pag { +namespace tgfx { class Caps { public: bool floatIs32Bits = true; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ColorShader.cpp b/tgfx/src/gpu/ColorShader.cpp index 5c42263924..2fd895d1fe 100644 --- a/tgfx/src/gpu/ColorShader.cpp +++ b/tgfx/src/gpu/ColorShader.cpp @@ -19,8 +19,8 @@ #include "ColorShader.h" #include "gpu/ConstColorProcessor.h" -namespace pag { -std::shared_ptr Shader::MakeColorShader(Color4f color) { +namespace tgfx { +std::shared_ptr Shader::MakeColorShader(Color color) { return std::make_shared(color); } @@ -32,4 +32,4 @@ std::unique_ptr ColorShader::asFragmentProcessor(const FPArgs return ConstColorProcessor::Make(color); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ColorShader.h b/tgfx/src/gpu/ColorShader.h index 342adea296..a85a0716a0 100644 --- a/tgfx/src/gpu/ColorShader.h +++ b/tgfx/src/gpu/ColorShader.h @@ -20,10 +20,10 @@ #include "gpu/Shader.h" -namespace pag { +namespace tgfx { class ColorShader : public Shader { public: - explicit ColorShader(Color4f color) : color(color) { + explicit ColorShader(Color color) : color(color) { } bool isOpaque() const override; @@ -31,6 +31,6 @@ class ColorShader : public Shader { std::unique_ptr asFragmentProcessor(const FPArgs& args) const override; private: - Color4f color; + Color color; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ConstColorProcessor.cpp b/tgfx/src/gpu/ConstColorProcessor.cpp index d1af49f036..e813162a19 100644 --- a/tgfx/src/gpu/ConstColorProcessor.cpp +++ b/tgfx/src/gpu/ConstColorProcessor.cpp @@ -17,11 +17,11 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "ConstColorProcessor.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "opengl/GLConstColorProcessor.h" -namespace pag { -std::unique_ptr ConstColorProcessor::Make(Color4f color) { +namespace tgfx { +std::unique_ptr ConstColorProcessor::Make(Color color) { return std::unique_ptr(new ConstColorProcessor(color)); } @@ -35,4 +35,4 @@ void ConstColorProcessor::onComputeProcessorKey(BytesKey* bytesKey) const { std::unique_ptr ConstColorProcessor::onCreateGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ConstColorProcessor.h b/tgfx/src/gpu/ConstColorProcessor.h index e07f549988..0ab87d4a5b 100644 --- a/tgfx/src/gpu/ConstColorProcessor.h +++ b/tgfx/src/gpu/ConstColorProcessor.h @@ -19,12 +19,12 @@ #pragma once #include "FragmentProcessor.h" -#include "core/Color4f.h" +#include "core/Color.h" -namespace pag { +namespace tgfx { class ConstColorProcessor : public FragmentProcessor { public: - static std::unique_ptr Make(Color4f color); + static std::unique_ptr Make(Color color); std::string name() const override { return "ConstColorProcessor"; @@ -35,11 +35,11 @@ class ConstColorProcessor : public FragmentProcessor { std::unique_ptr onCreateGLInstance() const override; private: - explicit ConstColorProcessor(Color4f color) : color(color) { + explicit ConstColorProcessor(Color color) : color(color) { } - Color4f color; + Color color; friend class GLConstColorProcessor; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/Context.cpp b/tgfx/src/gpu/Context.cpp index c3fffa78aa..04a91c7bee 100644 --- a/tgfx/src/gpu/Context.cpp +++ b/tgfx/src/gpu/Context.cpp @@ -18,13 +18,13 @@ #include "gpu/Context.h" #include "base/utils/GetTimer.h" -#include "base/utils/Log.h" +#include "core/utils/Log.h" #include "gpu/GradientCache.h" #include "gpu/Program.h" #include "gpu/ProgramCache.h" #include "gpu/ResourceCache.h" -namespace pag { +namespace tgfx { Context::Context(Device* device) : _device(device) { _gradientCache = new GradientCache(this); _programCache = new ProgramCache(this); @@ -59,4 +59,4 @@ void Context::releaseAll(bool releaseGPU) { _programCache->releaseAll(releaseGPU); _resourceCache->releaseAll(releaseGPU); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/CoordTransform.h b/tgfx/src/gpu/CoordTransform.h index 3709475ff4..c3510307dc 100644 --- a/tgfx/src/gpu/CoordTransform.h +++ b/tgfx/src/gpu/CoordTransform.h @@ -18,9 +18,9 @@ #pragma once -#include "pag/types.h" +#include "core/Matrix.h" -namespace pag { +namespace tgfx { struct CoordTransform { CoordTransform() = default; @@ -29,4 +29,4 @@ struct CoordTransform { Matrix matrix = Matrix::I(); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/Device.cpp b/tgfx/src/gpu/Device.cpp index 9f85a0fa20..379dbbac5c 100644 --- a/tgfx/src/gpu/Device.cpp +++ b/tgfx/src/gpu/Device.cpp @@ -17,11 +17,11 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "gpu/Device.h" -#include "base/utils/Log.h" -#include "base/utils/UniqueID.h" +#include "core/utils/Log.h" +#include "core/utils/UniqueID.h" #include "gpu/Context.h" -namespace pag { +namespace tgfx { Device::Device() : _uniqueID(UniqueID::Next()) { } @@ -72,4 +72,4 @@ bool Device::onLockContext() { void Device::onUnlockContext() { } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/EllipseGeometryProcessor.cpp b/tgfx/src/gpu/EllipseGeometryProcessor.cpp index fed6ce8886..1398d8565e 100644 --- a/tgfx/src/gpu/EllipseGeometryProcessor.cpp +++ b/tgfx/src/gpu/EllipseGeometryProcessor.cpp @@ -18,10 +18,10 @@ #include "EllipseGeometryProcessor.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "gpu/opengl/GLEllipseGeometryProcessor.h" -namespace pag { +namespace tgfx { std::unique_ptr EllipseGeometryProcessor::Make(int width, int height, bool stroke, bool useScale, const Matrix& localMatrix, @@ -59,4 +59,4 @@ void EllipseGeometryProcessor::onComputeProcessorKey(BytesKey* bytesKey) const { std::unique_ptr EllipseGeometryProcessor::createGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/EllipseGeometryProcessor.h b/tgfx/src/gpu/EllipseGeometryProcessor.h index fc6ac27814..284b9b8ae2 100644 --- a/tgfx/src/gpu/EllipseGeometryProcessor.h +++ b/tgfx/src/gpu/EllipseGeometryProcessor.h @@ -20,7 +20,7 @@ #include "GeometryProcessor.h" -namespace pag { +namespace tgfx { /** * Skia's sharing: * https://www.essentialmath.com/GDC2015/VanVerth_Jim_DrawingAntialiasedEllipse.pdf @@ -61,4 +61,4 @@ class EllipseGeometryProcessor : public GeometryProcessor { friend class GLEllipseGeometryProcessor; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/EmptyXferProcessor.cpp b/tgfx/src/gpu/EmptyXferProcessor.cpp index 3e252296b8..b1dc1c9ab9 100644 --- a/tgfx/src/gpu/EmptyXferProcessor.cpp +++ b/tgfx/src/gpu/EmptyXferProcessor.cpp @@ -17,10 +17,10 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "EmptyXferProcessor.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "opengl/GLEmptyXferProcessor.h" -namespace pag { +namespace tgfx { void EmptyXferProcessor::computeProcessorKey(Context*, BytesKey* bytesKey) const { static auto Type = UniqueID::Next(); bytesKey->write(Type); @@ -29,4 +29,4 @@ void EmptyXferProcessor::computeProcessorKey(Context*, BytesKey* bytesKey) const std::unique_ptr EmptyXferProcessor::createGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/EmptyXferProcessor.h b/tgfx/src/gpu/EmptyXferProcessor.h index a30e887ea8..a5eb175f04 100644 --- a/tgfx/src/gpu/EmptyXferProcessor.h +++ b/tgfx/src/gpu/EmptyXferProcessor.h @@ -20,7 +20,7 @@ #include "XferProcessor.h" -namespace pag { +namespace tgfx { class EmptyXferProcessor : public XferProcessor { public: EmptyXferProcessor() = default; @@ -33,4 +33,4 @@ class EmptyXferProcessor : public XferProcessor { std::unique_ptr createGLInstance() const override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/FragmentProcessor.cpp b/tgfx/src/gpu/FragmentProcessor.cpp index 5ca0b33282..43d5ec1dc1 100644 --- a/tgfx/src/gpu/FragmentProcessor.cpp +++ b/tgfx/src/gpu/FragmentProcessor.cpp @@ -20,7 +20,7 @@ #include "GLFragmentProcessor.h" #include "Pipeline.h" -namespace pag { +namespace tgfx { void FragmentProcessor::computeProcessorKey(Context* context, BytesKey* bytesKey) const { onComputeProcessorKey(bytesKey); for (size_t i = 0; i < textureSamplerCount; ++i) { @@ -81,4 +81,4 @@ const CoordTransform* FragmentProcessor::CoordTransformIter::next() { } return currFP->coordTransform(currentIndex++); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/FragmentProcessor.h b/tgfx/src/gpu/FragmentProcessor.h index 3ac9091d08..b2b1f2c10d 100644 --- a/tgfx/src/gpu/FragmentProcessor.h +++ b/tgfx/src/gpu/FragmentProcessor.h @@ -22,7 +22,7 @@ #include "Processor.h" #include "gpu/Texture.h" -namespace pag { +namespace tgfx { struct FPArgs { FPArgs(Context* context, const Matrix& localMatrix) : context(context), localMatrix(localMatrix) { } @@ -151,4 +151,4 @@ class FragmentProcessor : public Processor { std::vector> childProcessors; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/FragmentShaderBuilder.cpp b/tgfx/src/gpu/FragmentShaderBuilder.cpp index 3274d9f948..f9547b3230 100644 --- a/tgfx/src/gpu/FragmentShaderBuilder.cpp +++ b/tgfx/src/gpu/FragmentShaderBuilder.cpp @@ -19,7 +19,7 @@ #include "FragmentShaderBuilder.h" #include "ProgramBuilder.h" -namespace pag { +namespace tgfx { FragmentShaderBuilder::FragmentShaderBuilder(ProgramBuilder* program) : ShaderBuilder(program) { subStageIndices.push_back(0); } @@ -47,4 +47,4 @@ void FragmentShaderBuilder::onAfterChildProcEmitCode() { auto removeAt = _mangleString.rfind('_'); _mangleString.erase(removeAt, _mangleString.size() - removeAt); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/FragmentShaderBuilder.h b/tgfx/src/gpu/FragmentShaderBuilder.h index deb70945b2..aec47ee309 100644 --- a/tgfx/src/gpu/FragmentShaderBuilder.h +++ b/tgfx/src/gpu/FragmentShaderBuilder.h @@ -20,7 +20,7 @@ #include "ShaderBuilder.h" -namespace pag { +namespace tgfx { class FragmentShaderBuilder : public ShaderBuilder { public: explicit FragmentShaderBuilder(ProgramBuilder* program); @@ -41,7 +41,7 @@ class FragmentShaderBuilder : public ShaderBuilder { virtual std::string colorOutputName() = 0; static std::string CustomColorOutputName() { - return "pag_FragColor"; + return "tgfx_FragColor"; } void onFinalize() override; @@ -68,4 +68,4 @@ class FragmentShaderBuilder : public ShaderBuilder { friend class ProgramBuilder; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/GLFragmentProcessor.cpp b/tgfx/src/gpu/GLFragmentProcessor.cpp index 8f76729dab..02480401e7 100644 --- a/tgfx/src/gpu/GLFragmentProcessor.cpp +++ b/tgfx/src/gpu/GLFragmentProcessor.cpp @@ -18,7 +18,7 @@ #include "GLFragmentProcessor.h" -namespace pag { +namespace tgfx { void GLFragmentProcessor::setData(const ProgramDataManager& programDataManager, const FragmentProcessor& processor) { onSetData(programDataManager, processor); @@ -91,4 +91,4 @@ GLFragmentProcessor::BuilderInputProvider::childInputs(size_t childInd numToSkip += (processor->*COUNT)(); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/GLFragmentProcessor.h b/tgfx/src/gpu/GLFragmentProcessor.h index 65da7e2940..d9b07110a4 100644 --- a/tgfx/src/gpu/GLFragmentProcessor.h +++ b/tgfx/src/gpu/GLFragmentProcessor.h @@ -23,7 +23,7 @@ #include "ProgramDataManager.h" #include "UniformHandler.h" -namespace pag { +namespace tgfx { class GLFragmentProcessor { public: virtual ~GLFragmentProcessor() = default; @@ -170,4 +170,4 @@ class GLFragmentProcessor { friend class FragmentProcessor; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/GLGeometryProcessor.cpp b/tgfx/src/gpu/GLGeometryProcessor.cpp index 3f0e6266ed..366f3c13d7 100644 --- a/tgfx/src/gpu/GLGeometryProcessor.cpp +++ b/tgfx/src/gpu/GLGeometryProcessor.cpp @@ -18,7 +18,7 @@ #include "GLGeometryProcessor.h" -namespace pag { +namespace tgfx { void GLGeometryProcessor::setTransformDataHelper(const Matrix& localMatrix, const ProgramDataManager& programDataManager, FPCoordTransformIter* transformIter) { @@ -66,4 +66,4 @@ void GLGeometryProcessor::emitTransforms(VertexShaderBuilder* vertexBuilder, } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/GLGeometryProcessor.h b/tgfx/src/gpu/GLGeometryProcessor.h index a570ea1478..1eddc90202 100644 --- a/tgfx/src/gpu/GLGeometryProcessor.h +++ b/tgfx/src/gpu/GLGeometryProcessor.h @@ -26,7 +26,7 @@ #include "VaryingHandler.h" #include "VertexShaderBuilder.h" -namespace pag { +namespace tgfx { class GLGeometryProcessor { public: // Use only for easy-to-use aliases. @@ -126,4 +126,4 @@ class GLGeometryProcessor { std::vector installedTransforms; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/GLXferProcessor.h b/tgfx/src/gpu/GLXferProcessor.h index 6b2f77b739..e07324dc18 100644 --- a/tgfx/src/gpu/GLXferProcessor.h +++ b/tgfx/src/gpu/GLXferProcessor.h @@ -24,7 +24,7 @@ #include "gpu/UniformHandler.h" #include "gpu/XferProcessor.h" -namespace pag { +namespace tgfx { class GLXferProcessor { public: virtual ~GLXferProcessor() = default; @@ -63,4 +63,4 @@ class GLXferProcessor { const Point&) { } }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/GeometryProcessor.cpp b/tgfx/src/gpu/GeometryProcessor.cpp index ea398b3914..981efc42bd 100644 --- a/tgfx/src/gpu/GeometryProcessor.cpp +++ b/tgfx/src/gpu/GeometryProcessor.cpp @@ -18,7 +18,7 @@ #include "GeometryProcessor.h" -namespace pag { +namespace tgfx { /** * Returns the size of the attrib type in bytes. */ @@ -58,4 +58,4 @@ void GeometryProcessor::setVertexAttributes(const Attribute* attrs, int attrCoun attributes.push_back(attrs + i); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/GeometryProcessor.h b/tgfx/src/gpu/GeometryProcessor.h index 252257d7fd..fe0acb98a2 100644 --- a/tgfx/src/gpu/GeometryProcessor.h +++ b/tgfx/src/gpu/GeometryProcessor.h @@ -19,12 +19,11 @@ #pragma once #include - #include "Processor.h" #include "ShaderVar.h" #include "TextureSampler.h" -namespace pag { +namespace tgfx { class GLGeometryProcessor; class GeometryProcessor : public Processor { @@ -81,4 +80,4 @@ class GeometryProcessor : public Processor { std::vector attributes = {}; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/GradientCache.cpp b/tgfx/src/gpu/GradientCache.cpp index 2b96bac9ea..61827a3aae 100644 --- a/tgfx/src/gpu/GradientCache.cpp +++ b/tgfx/src/gpu/GradientCache.cpp @@ -20,7 +20,7 @@ #include -namespace pag { +namespace tgfx { // Each bitmap will be 256x1. static constexpr size_t kMaxNumCachedGradientBitmaps = 32; static constexpr int kGradientTextureSize = 256; @@ -45,8 +45,8 @@ void GradientCache::add(const BytesKey& bytesKey, std::shared_ptr textu } } -std::shared_ptr CreateGradient(const Color4f* colors, const float* positions, - int count, int resolution) { +std::shared_ptr CreateGradient(const Color* colors, const float* positions, int count, + int resolution) { auto pixelBuffer = PixelBuffer::Make(resolution, 1); Bitmap bitmap(pixelBuffer); if (bitmap.isEmpty()) { @@ -91,8 +91,7 @@ std::shared_ptr CreateGradient(const Color4f* colors, const float* return pixelBuffer; } -const Texture* GradientCache::getGradient(const Color4f* colors, const float* positions, - int count) { +const Texture* GradientCache::getGradient(const Color* colors, const float* positions, int count) { BytesKey bytesKey = {}; for (int i = 0; i < count; ++i) { bytesKey.write(colors[i].red); @@ -123,4 +122,4 @@ void GradientCache::releaseAll() { bool GradientCache::empty() const { return textures.empty() && keys.empty(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/GradientCache.h b/tgfx/src/gpu/GradientCache.h index 9513f95e1e..58080d91bd 100644 --- a/tgfx/src/gpu/GradientCache.h +++ b/tgfx/src/gpu/GradientCache.h @@ -22,10 +22,10 @@ #include #include "core/Bitmap.h" -#include "core/Color4f.h" -#include "core/utils/BytesKey.h" +#include "core/BytesKey.h" +#include "core/Color.h" -namespace pag { +namespace tgfx { class Context; class GradientCache { @@ -33,7 +33,7 @@ class GradientCache { explicit GradientCache(Context* context) : context(context) { } - const Texture* getGradient(const Color4f* colors, const float* positions, int count); + const Texture* getGradient(const Color* colors, const float* positions, int count); void releaseAll(); @@ -48,4 +48,4 @@ class GradientCache { std::list keys = {}; std::unordered_map, BytesHasher> textures = {}; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/Paint.cpp b/tgfx/src/gpu/Paint.cpp index df4f18ba47..773abc31f2 100644 --- a/tgfx/src/gpu/Paint.cpp +++ b/tgfx/src/gpu/Paint.cpp @@ -18,11 +18,11 @@ #include "gpu/Paint.h" -namespace pag { +namespace tgfx { void Paint::reset() { style = PaintStyle::Fill; - color = Color4f::Black(); + color = Color::Black(); stroke = Stroke(0); shader = nullptr; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/Pipeline.cpp b/tgfx/src/gpu/Pipeline.cpp index 7c9a8ac3a3..52097698ac 100644 --- a/tgfx/src/gpu/Pipeline.cpp +++ b/tgfx/src/gpu/Pipeline.cpp @@ -19,7 +19,7 @@ #include "Pipeline.h" #include "gpu/TextureSampler.h" -namespace pag { +namespace tgfx { Pipeline::Pipeline(std::vector> fragmentProcessors, size_t numColorProcessors, std::unique_ptr xferProcessor, std::shared_ptr dstTexture, Point dstTextureOffset, @@ -60,4 +60,4 @@ const Texture* Pipeline::getDstTexture(Point* offset) const { } return dstTexture.get(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/Pipeline.h b/tgfx/src/gpu/Pipeline.h index d2933f175d..9cfe57e1a2 100644 --- a/tgfx/src/gpu/Pipeline.h +++ b/tgfx/src/gpu/Pipeline.h @@ -22,7 +22,7 @@ #include "FragmentProcessor.h" #include "Swizzle.h" -namespace pag { +namespace tgfx { class Pipeline { public: Pipeline(std::vector> fragmentProcessors, @@ -65,4 +65,4 @@ class Pipeline { Point dstTextureOffset = Point::Zero(); const Swizzle* _outputSwizzle = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/PixelConfig.h b/tgfx/src/gpu/PixelConfig.h index 0b80393b37..d2e9c3acd3 100644 --- a/tgfx/src/gpu/PixelConfig.h +++ b/tgfx/src/gpu/PixelConfig.h @@ -18,6 +18,6 @@ #pragma once -namespace pag { +namespace tgfx { enum class PixelConfig { ALPHA_8, Gray_8, RG_88, RGBA_8888 }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/PorterDuffXferProcessor.cpp b/tgfx/src/gpu/PorterDuffXferProcessor.cpp index 409d9c0ba2..0926e916b0 100644 --- a/tgfx/src/gpu/PorterDuffXferProcessor.cpp +++ b/tgfx/src/gpu/PorterDuffXferProcessor.cpp @@ -17,11 +17,11 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "PorterDuffXferProcessor.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "opengl/GLPorterDuffXferProcessor.h" -namespace pag { -std::unique_ptr PorterDuffXferProcessor::Make(Blend blend) { +namespace tgfx { +std::unique_ptr PorterDuffXferProcessor::Make(BlendMode blend) { return std::unique_ptr(new PorterDuffXferProcessor(blend)); } @@ -34,4 +34,4 @@ void PorterDuffXferProcessor::computeProcessorKey(Context*, BytesKey* bytesKey) std::unique_ptr PorterDuffXferProcessor::createGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/PorterDuffXferProcessor.h b/tgfx/src/gpu/PorterDuffXferProcessor.h index a5e9688236..c4c7a3d65c 100644 --- a/tgfx/src/gpu/PorterDuffXferProcessor.h +++ b/tgfx/src/gpu/PorterDuffXferProcessor.h @@ -19,14 +19,14 @@ #pragma once #include "XferProcessor.h" -#include "core/Blend.h" +#include "core/BlendMode.h" -namespace pag { +namespace tgfx { class PorterDuffXferProcessor : public XferProcessor { public: - static std::unique_ptr Make(Blend blend); + static std::unique_ptr Make(BlendMode blend); - Blend getBlend() const { + BlendMode getBlend() const { return blend; } @@ -39,9 +39,9 @@ class PorterDuffXferProcessor : public XferProcessor { std::unique_ptr createGLInstance() const override; private: - explicit PorterDuffXferProcessor(Blend blend) : blend(blend) { + explicit PorterDuffXferProcessor(BlendMode blend) : blend(blend) { } - Blend blend; + BlendMode blend; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/Processor.h b/tgfx/src/gpu/Processor.h index e3ef2c5749..8a58339b73 100644 --- a/tgfx/src/gpu/Processor.h +++ b/tgfx/src/gpu/Processor.h @@ -18,10 +18,10 @@ #pragma once -#include "core/utils/BytesKey.h" +#include "core/BytesKey.h" #include "gpu/Context.h" -namespace pag { +namespace tgfx { class Processor { public: virtual ~Processor() = default; @@ -33,4 +33,4 @@ class Processor { virtual void computeProcessorKey(Context* context, BytesKey* bytesKey) const = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/Program.h b/tgfx/src/gpu/Program.h index 2caea15630..656529d254 100644 --- a/tgfx/src/gpu/Program.h +++ b/tgfx/src/gpu/Program.h @@ -18,10 +18,10 @@ #pragma once -#include "core/utils/BytesKey.h" +#include "core/BytesKey.h" #include "gpu/Context.h" -namespace pag { +namespace tgfx { /** * The base class for GPU program. Overrides the onRelease() method to to free all GPU resources. * No backend API calls should be made during destructuring since there may be no GPU context which @@ -56,4 +56,4 @@ class ProgramCreator { */ virtual std::unique_ptr createProgram(Context* context) const = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ProgramBuilder.cpp b/tgfx/src/gpu/ProgramBuilder.cpp index 62a563ca5c..20f254047e 100644 --- a/tgfx/src/gpu/ProgramBuilder.cpp +++ b/tgfx/src/gpu/ProgramBuilder.cpp @@ -21,7 +21,7 @@ #include "GLGeometryProcessor.h" #include "GLXferProcessor.h" -namespace pag { +namespace tgfx { ProgramBuilder::ProgramBuilder(const GeometryProcessor* geometryProcessor, const Pipeline* pipeline) : geometryProcessor(geometryProcessor), pipeline(pipeline) { } @@ -199,4 +199,4 @@ void ProgramBuilder::finalizeShaders() { vertexShaderBuilder()->finalize(ShaderFlags::Vertex); fragmentShaderBuilder()->finalize(ShaderFlags::Fragment); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ProgramBuilder.h b/tgfx/src/gpu/ProgramBuilder.h index c30630218e..f83604f012 100644 --- a/tgfx/src/gpu/ProgramBuilder.h +++ b/tgfx/src/gpu/ProgramBuilder.h @@ -25,7 +25,7 @@ #include "VaryingHandler.h" #include "VertexShaderBuilder.h" -namespace pag { +namespace tgfx { class ProgramBuilder { public: virtual ~ProgramBuilder() = default; @@ -111,4 +111,4 @@ class ProgramBuilder { const Pipeline* pipeline = nullptr; std::vector transformedCoordVars = {}; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ProgramCache.cpp b/tgfx/src/gpu/ProgramCache.cpp index c78e391640..2bc2845d4b 100644 --- a/tgfx/src/gpu/ProgramCache.cpp +++ b/tgfx/src/gpu/ProgramCache.cpp @@ -18,7 +18,7 @@ #include "ProgramCache.h" -namespace pag { +namespace tgfx { #define MAX_PROGRAM_COUNT 128 ProgramCache::ProgramCache(Context* context) : context(context) { @@ -66,4 +66,4 @@ void ProgramCache::releaseAll(bool releaseGPU) { removeOldestProgram(releaseGPU); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ProgramCache.h b/tgfx/src/gpu/ProgramCache.h index 4f16df28ba..7ec180e2dd 100644 --- a/tgfx/src/gpu/ProgramCache.h +++ b/tgfx/src/gpu/ProgramCache.h @@ -22,7 +22,7 @@ #include #include "Program.h" -namespace pag { +namespace tgfx { /** * Manages the lifetime of all Program instances. */ @@ -52,4 +52,4 @@ class ProgramCache { friend class Context; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ProgramDataManager.h b/tgfx/src/gpu/ProgramDataManager.h index acc86f0f07..7c80498a68 100644 --- a/tgfx/src/gpu/ProgramDataManager.h +++ b/tgfx/src/gpu/ProgramDataManager.h @@ -19,9 +19,9 @@ #pragma once #include "ResourceHandle.h" -#include "pag/types.h" +#include "core/Matrix.h" -namespace pag { +namespace tgfx { class ProgramDataManager { public: virtual ~ProgramDataManager() = default; @@ -37,4 +37,4 @@ class ProgramDataManager { // convenience method for uploading a Matrix to a 3x3 matrix uniform virtual void setMatrix(UniformHandle u, const Matrix& matrix) const = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/QuadPerEdgeAAGeometryProcessor.cpp b/tgfx/src/gpu/QuadPerEdgeAAGeometryProcessor.cpp index b0c5fd4250..d5b598cca3 100644 --- a/tgfx/src/gpu/QuadPerEdgeAAGeometryProcessor.cpp +++ b/tgfx/src/gpu/QuadPerEdgeAAGeometryProcessor.cpp @@ -17,11 +17,11 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "QuadPerEdgeAAGeometryProcessor.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "gpu/YUVTexture.h" #include "gpu/opengl/GLQuadPerEdgeAAGeometryProcessor.h" -namespace pag { +namespace tgfx { std::unique_ptr QuadPerEdgeAAGeometryProcessor::Make(int width, int height, Matrix matrix, @@ -52,4 +52,4 @@ void QuadPerEdgeAAGeometryProcessor::onComputeProcessorKey(BytesKey* bytesKey) c std::unique_ptr QuadPerEdgeAAGeometryProcessor::createGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/QuadPerEdgeAAGeometryProcessor.h b/tgfx/src/gpu/QuadPerEdgeAAGeometryProcessor.h index d7136fa31a..e8f9001014 100644 --- a/tgfx/src/gpu/QuadPerEdgeAAGeometryProcessor.h +++ b/tgfx/src/gpu/QuadPerEdgeAAGeometryProcessor.h @@ -22,7 +22,7 @@ #include "GeometryProcessor.h" #include "gpu/Paint.h" -namespace pag { +namespace tgfx { class QuadPerEdgeAAGeometryProcessor : public GeometryProcessor { public: static std::unique_ptr Make(int width, int height, Matrix matrix, @@ -49,4 +49,4 @@ class QuadPerEdgeAAGeometryProcessor : public GeometryProcessor { friend class GLQuadPerEdgeAAGeometryProcessor; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ResourceCache.cpp b/tgfx/src/gpu/ResourceCache.cpp index c1a16105cd..aac657e8b9 100644 --- a/tgfx/src/gpu/ResourceCache.cpp +++ b/tgfx/src/gpu/ResourceCache.cpp @@ -19,12 +19,12 @@ #include "ResourceCache.h" #include #include -#include "base/utils/GetTimer.h" -#include "base/utils/Log.h" -#include "core/utils/BytesKey.h" +#include "core/BytesKey.h" +#include "core/Performance.h" +#include "core/utils/Log.h" #include "gpu/Resource.h" -namespace pag { +namespace tgfx { static thread_local std::unordered_set currentThreadCaches = {}; class PurgeGuard { @@ -98,7 +98,7 @@ void ResourceCache::releaseAll(bool releaseGPU) { void ResourceCache::purgeNotUsedIn(int64_t usNotUsed) { PurgeGuard guard(this); - auto currentTime = GetTimer(); + auto currentTime = Performance::Now(); std::unordered_map, BytesHasher> recycledMap = {}; for (auto& item : recycledResources) { std::vector needToRecycle = {}; @@ -178,7 +178,7 @@ void ResourceCache::removeResource(Resource* resource) { DEBUG_ASSERT(context->device()->contextLocked); RemoveFromList(nonpurgeableResources, resource); if (resource->recycleKey.isValid()) { - resource->lastUsedTime = GetTimer(); + resource->lastUsedTime = Performance::Now(); recycledResources[resource->recycleKey].push_back(resource); } else { purgingResource = true; @@ -187,4 +187,4 @@ void ResourceCache::removeResource(Resource* resource) { delete resource; } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ResourceCache.h b/tgfx/src/gpu/ResourceCache.h index 88e9eba84a..0e739cb1ce 100644 --- a/tgfx/src/gpu/ResourceCache.h +++ b/tgfx/src/gpu/ResourceCache.h @@ -21,7 +21,7 @@ #include #include "gpu/Context.h" -namespace pag { +namespace tgfx { class Resource; /** @@ -69,4 +69,4 @@ class ResourceCache { friend class Context; friend class PurgeGuard; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ResourceHandle.h b/tgfx/src/gpu/ResourceHandle.h index d983fcd177..15d6997716 100644 --- a/tgfx/src/gpu/ResourceHandle.h +++ b/tgfx/src/gpu/ResourceHandle.h @@ -21,7 +21,7 @@ #include #include -namespace pag { +namespace tgfx { class ResourceHandle { public: ResourceHandle() = default; @@ -57,4 +57,4 @@ class SamplerHandle : public ResourceHandle { explicit SamplerHandle(size_t value) : ResourceHandle(value) { } }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ShaderBuilder.cpp b/tgfx/src/gpu/ShaderBuilder.cpp index 6a84f43db5..361d54fa00 100644 --- a/tgfx/src/gpu/ShaderBuilder.cpp +++ b/tgfx/src/gpu/ShaderBuilder.cpp @@ -21,7 +21,7 @@ #include "Swizzle.h" #include "stdarg.h" -namespace pag { +namespace tgfx { // number of bytes (on the stack) to receive the printf result static constexpr size_t kBufferSize = 1024; @@ -124,7 +124,7 @@ void ShaderBuilder::finalize(ShaderFlags visibility) { finalized = true; } -void ShaderBuilder::appendEnterIfNotEmpty(Enum type) { +void ShaderBuilder::appendEnterIfNotEmpty(uint8_t type) { if (shaderStrings[type].empty()) { return; } @@ -158,4 +158,4 @@ std::string ShaderBuilder::shaderString() { } return fragment; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ShaderBuilder.h b/tgfx/src/gpu/ShaderBuilder.h index fd55a546b6..060b051ade 100644 --- a/tgfx/src/gpu/ShaderBuilder.h +++ b/tgfx/src/gpu/ShaderBuilder.h @@ -20,9 +20,8 @@ #include "ResourceHandle.h" #include "ShaderVar.h" -#include "pag/types.h" -namespace pag { +namespace tgfx { class ProgramBuilder; /** @@ -68,16 +67,16 @@ class ShaderBuilder { protected: class Type { public: - static const Enum VersionDecl = 0; - static const Enum Extensions = 1; - static const Enum Definitions = 2; - static const Enum PrecisionQualifier = 3; - static const Enum Uniforms = 4; - static const Enum Inputs = 5; - static const Enum Outputs = 6; - static const Enum Functions = 7; - static const Enum Main = 8; - static const Enum Code = 9; + static const uint8_t VersionDecl = 0; + static const uint8_t Extensions = 1; + static const uint8_t Definitions = 2; + static const uint8_t PrecisionQualifier = 3; + static const uint8_t Uniforms = 4; + static const uint8_t Inputs = 5; + static const uint8_t Outputs = 6; + static const uint8_t Functions = 7; + static const uint8_t Main = 8; + static const uint8_t Code = 9; }; /** @@ -91,7 +90,7 @@ class ShaderBuilder { virtual void onFinalize() = 0; - void appendEnterIfNotEmpty(Enum type); + void appendEnterIfNotEmpty(uint8_t type); void appendIndentationIfNeeded(const std::string& code); @@ -111,4 +110,4 @@ class ShaderBuilder { friend class GLUniformHandler; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/ShaderVar.h b/tgfx/src/gpu/ShaderVar.h index 3f1b1ff987..fc60db8716 100644 --- a/tgfx/src/gpu/ShaderVar.h +++ b/tgfx/src/gpu/ShaderVar.h @@ -19,10 +19,10 @@ #pragma once #include - +#include #include "BitmaskOperators.h" -namespace pag { +namespace tgfx { enum class ShaderFlags : unsigned { None = 0, Vertex = 1 << 0, @@ -90,4 +90,4 @@ class ShaderVar { TypeModifier _typeModifier = TypeModifier::None; std::string _name; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/Surface.cpp b/tgfx/src/gpu/Surface.cpp index a054b7f561..56a0f66bbc 100644 --- a/tgfx/src/gpu/Surface.cpp +++ b/tgfx/src/gpu/Surface.cpp @@ -18,7 +18,7 @@ #include "gpu/Surface.h" -namespace pag { +namespace tgfx { Surface::Surface(Context* context) : context(context) { } @@ -32,4 +32,4 @@ bool Surface::hitTest(float x, float y) const { auto result = onReadPixels(info, pixel, static_cast(x), static_cast(y)); return result && pixel[3] > 0; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/Swizzle.h b/tgfx/src/gpu/Swizzle.h index ef443b8248..c38f90ca1b 100644 --- a/tgfx/src/gpu/Swizzle.h +++ b/tgfx/src/gpu/Swizzle.h @@ -20,7 +20,7 @@ #include -namespace pag { +namespace tgfx { class Swizzle { public: constexpr Swizzle() : Swizzle("rgba") { @@ -96,4 +96,4 @@ class Swizzle { key((CToI(c[0]) << 0) | (CToI(c[1]) << 4) | (CToI(c[2]) << 8) | (CToI(c[3]) << 12)) { } }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/TextureFragmentProcessor.cpp b/tgfx/src/gpu/TextureFragmentProcessor.cpp index a01fd0c2e4..d9a46d776b 100644 --- a/tgfx/src/gpu/TextureFragmentProcessor.cpp +++ b/tgfx/src/gpu/TextureFragmentProcessor.cpp @@ -17,12 +17,12 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "TextureFragmentProcessor.h" -#include "base/utils/Log.h" -#include "base/utils/UniqueID.h" +#include "core/utils/Log.h" +#include "core/utils/UniqueID.h" #include "gpu/YUVTextureFragmentProcessor.h" #include "opengl/GLTextureFragmentProcessor.h" -namespace pag { +namespace tgfx { std::unique_ptr TextureFragmentProcessor::Make(const Texture* texture, const RGBAAALayout* layout, const Matrix& localMatrix) { @@ -68,4 +68,4 @@ void TextureFragmentProcessor::onComputeProcessorKey(BytesKey* bytesKey) const { std::unique_ptr TextureFragmentProcessor::onCreateGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/TextureFragmentProcessor.h b/tgfx/src/gpu/TextureFragmentProcessor.h index 119ac0115d..96e3436e00 100644 --- a/tgfx/src/gpu/TextureFragmentProcessor.h +++ b/tgfx/src/gpu/TextureFragmentProcessor.h @@ -21,7 +21,7 @@ #include "core/RGBAAALayout.h" #include "gpu/FragmentProcessor.h" -namespace pag { +namespace tgfx { class TextureFragmentProcessor : public FragmentProcessor { public: static std::unique_ptr Make(const Texture* texture, const RGBAAALayout* layout, @@ -49,4 +49,4 @@ class TextureFragmentProcessor : public FragmentProcessor { friend class GLTextureFragmentProcessor; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/TextureMaskFragmentProcessor.cpp b/tgfx/src/gpu/TextureMaskFragmentProcessor.cpp index 163ca3841d..0710391d89 100644 --- a/tgfx/src/gpu/TextureMaskFragmentProcessor.cpp +++ b/tgfx/src/gpu/TextureMaskFragmentProcessor.cpp @@ -17,10 +17,10 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "TextureMaskFragmentProcessor.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "opengl/GLTextureMaskFragmentProcessor.h" -namespace pag { +namespace tgfx { std::unique_ptr TextureMaskFragmentProcessor::MakeUseLocalCoord( const Texture* texture, const Matrix& localMatrix, bool inverted) { if (texture == nullptr) { @@ -72,4 +72,4 @@ void TextureMaskFragmentProcessor::onComputeProcessorKey(BytesKey* bytesKey) con std::unique_ptr TextureMaskFragmentProcessor::onCreateGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/TextureMaskFragmentProcessor.h b/tgfx/src/gpu/TextureMaskFragmentProcessor.h index c714dd0c12..6ef9911d17 100644 --- a/tgfx/src/gpu/TextureMaskFragmentProcessor.h +++ b/tgfx/src/gpu/TextureMaskFragmentProcessor.h @@ -20,7 +20,7 @@ #include "FragmentProcessor.h" -namespace pag { +namespace tgfx { class TextureMaskFragmentProcessor : public FragmentProcessor { public: static std::unique_ptr MakeUseLocalCoord( @@ -54,4 +54,4 @@ class TextureMaskFragmentProcessor : public FragmentProcessor { friend class GLTextureMaskFragmentProcessor; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/TextureSampler.h b/tgfx/src/gpu/TextureSampler.h index 1dacf860a4..ca89a2ab64 100644 --- a/tgfx/src/gpu/TextureSampler.h +++ b/tgfx/src/gpu/TextureSampler.h @@ -18,11 +18,11 @@ #pragma once -#include "core/utils/BytesKey.h" +#include "core/BytesKey.h" #include "gpu/Context.h" #include "gpu/PixelConfig.h" -namespace pag { +namespace tgfx { class TextureSampler { public: TextureSampler() = default; @@ -36,4 +36,4 @@ class TextureSampler { PixelConfig config = PixelConfig::RGBA_8888; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/UniformHandler.h b/tgfx/src/gpu/UniformHandler.h index 81662c7078..b27a13fb39 100644 --- a/tgfx/src/gpu/UniformHandler.h +++ b/tgfx/src/gpu/UniformHandler.h @@ -23,8 +23,8 @@ #include "Swizzle.h" #include "TextureSampler.h" -namespace pag { -static constexpr char NO_MANGLE_PREFIX[] = "pag_"; +namespace tgfx { +static constexpr char NO_MANGLE_PREFIX[] = "tgfx_"; class ProgramBuilder; @@ -66,4 +66,4 @@ class UniformHandler { friend class ProgramBuilder; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/VaryingHandler.cpp b/tgfx/src/gpu/VaryingHandler.cpp index 6884417260..9fb7583960 100644 --- a/tgfx/src/gpu/VaryingHandler.cpp +++ b/tgfx/src/gpu/VaryingHandler.cpp @@ -19,7 +19,7 @@ #include "VaryingHandler.h" #include "ProgramBuilder.h" -namespace pag { +namespace tgfx { Varying VaryingHandler::addVarying(const std::string& name, ShaderVar::Type type) { Varying varying; varying._type = type; @@ -67,4 +67,4 @@ void VaryingHandler::getVertexDecls(std::string* inputDecls, std::string* output void VaryingHandler::getFragDecls(std::string* inputDecls) const { appendDecls(fragInputs, inputDecls, ShaderFlags::Fragment); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/VaryingHandler.h b/tgfx/src/gpu/VaryingHandler.h index 04ed4a003a..c86615d441 100644 --- a/tgfx/src/gpu/VaryingHandler.h +++ b/tgfx/src/gpu/VaryingHandler.h @@ -23,7 +23,7 @@ #include "GeometryProcessor.h" #include "ShaderVar.h" -namespace pag { +namespace tgfx { class ProgramBuilder; class Varying { @@ -82,4 +82,4 @@ class VaryingHandler { // This is not owned by the class ProgramBuilder* programBuilder; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/VertexShaderBuilder.cpp b/tgfx/src/gpu/VertexShaderBuilder.cpp index c21a70a33a..63509bbb69 100644 --- a/tgfx/src/gpu/VertexShaderBuilder.cpp +++ b/tgfx/src/gpu/VertexShaderBuilder.cpp @@ -19,9 +19,9 @@ #include "VertexShaderBuilder.h" #include "ProgramBuilder.h" -namespace pag { +namespace tgfx { void VertexShaderBuilder::onFinalize() { programBuilder->varyingHandler()->getVertexDecls(&shaderStrings[Type::Inputs], &shaderStrings[Type::Outputs]); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/VertexShaderBuilder.h b/tgfx/src/gpu/VertexShaderBuilder.h index 5ba6faa5b6..7e29e1dda7 100644 --- a/tgfx/src/gpu/VertexShaderBuilder.h +++ b/tgfx/src/gpu/VertexShaderBuilder.h @@ -20,7 +20,7 @@ #include "ShaderBuilder.h" -namespace pag { +namespace tgfx { class VertexShaderBuilder : public ShaderBuilder { public: explicit VertexShaderBuilder(ProgramBuilder* program) : ShaderBuilder(program) { @@ -31,4 +31,4 @@ class VertexShaderBuilder : public ShaderBuilder { private: void onFinalize() override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/Window.cpp b/tgfx/src/gpu/Window.cpp index 6ab8863a39..7a9857844a 100644 --- a/tgfx/src/gpu/Window.cpp +++ b/tgfx/src/gpu/Window.cpp @@ -17,10 +17,10 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "gpu/Window.h" -#include "base/utils/Log.h" +#include "core/utils/Log.h" #include "gpu/Device.h" -namespace pag { +namespace tgfx { Window::Window(std::shared_ptr device) : device(std::move(device)) { } @@ -48,4 +48,4 @@ bool Window::checkContext(Context* context) { } return true; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/XferProcessor.h b/tgfx/src/gpu/XferProcessor.h index 00a748a20b..fdbb0fd692 100644 --- a/tgfx/src/gpu/XferProcessor.h +++ b/tgfx/src/gpu/XferProcessor.h @@ -21,9 +21,9 @@ #include #include "Processor.h" -#include "core/utils/BytesKey.h" +#include "core/BytesKey.h" -namespace pag { +namespace tgfx { class GLXferProcessor; class XferProcessor : public Processor { @@ -34,4 +34,4 @@ class XferProcessor : public Processor { */ virtual std::unique_ptr createGLInstance() const = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/YUVTextureFragmentProcessor.cpp b/tgfx/src/gpu/YUVTextureFragmentProcessor.cpp index 765d562f38..441c995012 100644 --- a/tgfx/src/gpu/YUVTextureFragmentProcessor.cpp +++ b/tgfx/src/gpu/YUVTextureFragmentProcessor.cpp @@ -17,10 +17,10 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "YUVTextureFragmentProcessor.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "opengl/GLYUVTextureFragmentProcessor.h" -namespace pag { +namespace tgfx { YUVTextureFragmentProcessor::YUVTextureFragmentProcessor(const YUVTexture* texture, const RGBAAALayout* layout, const Matrix& localMatrix) @@ -41,4 +41,4 @@ void YUVTextureFragmentProcessor::onComputeProcessorKey(BytesKey* bytesKey) cons std::unique_ptr YUVTextureFragmentProcessor::onCreateGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/YUVTextureFragmentProcessor.h b/tgfx/src/gpu/YUVTextureFragmentProcessor.h index 25eb42b295..ec7b476e5b 100644 --- a/tgfx/src/gpu/YUVTextureFragmentProcessor.h +++ b/tgfx/src/gpu/YUVTextureFragmentProcessor.h @@ -22,7 +22,7 @@ #include "core/RGBAAALayout.h" #include "gpu/YUVTexture.h" -namespace pag { +namespace tgfx { class YUVTextureFragmentProcessor : public FragmentProcessor { public: std::string name() const override { @@ -49,4 +49,4 @@ class YUVTextureFragmentProcessor : public FragmentProcessor { friend class GLYUVTextureFragmentProcessor; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/ClampedGradientEffect.cpp b/tgfx/src/gpu/gradients/ClampedGradientEffect.cpp index fb06bc86b0..c3b60e373b 100644 --- a/tgfx/src/gpu/gradients/ClampedGradientEffect.cpp +++ b/tgfx/src/gpu/gradients/ClampedGradientEffect.cpp @@ -17,13 +17,13 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "ClampedGradientEffect.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "gpu/opengl/GLClampedGradientEffect.h" -namespace pag { +namespace tgfx { std::unique_ptr ClampedGradientEffect::Make( std::unique_ptr colorizer, std::unique_ptr gradLayout, - Color4f leftBorderColor, Color4f rightBorderColor, bool makePremultiply) { + Color leftBorderColor, Color rightBorderColor, bool makePremultiply) { return std::unique_ptr( new ClampedGradientEffect(std::move(colorizer), std::move(gradLayout), leftBorderColor, rightBorderColor, makePremultiply)); @@ -42,7 +42,7 @@ std::unique_ptr ClampedGradientEffect::onCreateGLInstance() ClampedGradientEffect::ClampedGradientEffect(std::unique_ptr colorizer, std::unique_ptr gradLayout, - Color4f leftBorderColor, Color4f rightBorderColor, + Color leftBorderColor, Color rightBorderColor, bool makePremultiplied) : leftBorderColor(leftBorderColor), rightBorderColor(rightBorderColor), @@ -50,4 +50,4 @@ ClampedGradientEffect::ClampedGradientEffect(std::unique_ptr colorizerIndex = registerChildProcessor(std::move(colorizer)); gradLayoutIndex = registerChildProcessor(std::move(gradLayout)); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/ClampedGradientEffect.h b/tgfx/src/gpu/gradients/ClampedGradientEffect.h index 081c0740af..65d0892a52 100644 --- a/tgfx/src/gpu/gradients/ClampedGradientEffect.h +++ b/tgfx/src/gpu/gradients/ClampedGradientEffect.h @@ -19,16 +19,15 @@ #pragma once #include -#include "core/Color4f.h" +#include "core/Color.h" #include "gpu/FragmentProcessor.h" -namespace pag { +namespace tgfx { class ClampedGradientEffect : public FragmentProcessor { public: static std::unique_ptr Make(std::unique_ptr colorizer, std::unique_ptr gradLayout, - Color4f leftBorderColor, - Color4f rightBorderColor, + Color leftBorderColor, Color rightBorderColor, bool makePremultiply); std::string name() const override { @@ -41,15 +40,15 @@ class ClampedGradientEffect : public FragmentProcessor { private: ClampedGradientEffect(std::unique_ptr colorizer, - std::unique_ptr gradLayout, Color4f leftBorderColor, - Color4f rightBorderColor, bool makePremultiplied); + std::unique_ptr gradLayout, Color leftBorderColor, + Color rightBorderColor, bool makePremultiplied); size_t colorizerIndex = ULONG_MAX; size_t gradLayoutIndex = ULONG_MAX; - Color4f leftBorderColor; - Color4f rightBorderColor; + Color leftBorderColor; + Color rightBorderColor; bool makePremultiply; friend class GLClampedGradientEffect; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/DualIntervalGradientColorizer.cpp b/tgfx/src/gpu/gradients/DualIntervalGradientColorizer.cpp index ad18234796..9f4bdf4a11 100644 --- a/tgfx/src/gpu/gradients/DualIntervalGradientColorizer.cpp +++ b/tgfx/src/gpu/gradients/DualIntervalGradientColorizer.cpp @@ -17,13 +17,13 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "DualIntervalGradientColorizer.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "gpu/opengl/GLDualIntervalGradientColorizer.h" -namespace pag { +namespace tgfx { std::unique_ptr DualIntervalGradientColorizer::Make( - Color4f c0, Color4f c1, Color4f c2, Color4f c3, float threshold) { - Color4f scale01; + Color c0, Color c1, Color c2, Color c3, float threshold) { + Color scale01; // Derive scale and biases from the 4 colors and threshold for (int i = 0; i < 4; ++i) { auto vc0 = c0[i]; @@ -32,8 +32,8 @@ std::unique_ptr DualIntervalGradientColorizer::Ma } // bias01 = c0 - Color4f scale23; - Color4f bias23; + Color scale23; + Color bias23; for (int i = 0; i < 4; ++i) { auto vc2 = c2[i]; auto vc3 = c3[i]; @@ -53,4 +53,4 @@ void DualIntervalGradientColorizer::onComputeProcessorKey(BytesKey* bytesKey) co std::unique_ptr DualIntervalGradientColorizer::onCreateGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/DualIntervalGradientColorizer.h b/tgfx/src/gpu/gradients/DualIntervalGradientColorizer.h index 70b5de1c6f..ae9d19718a 100644 --- a/tgfx/src/gpu/gradients/DualIntervalGradientColorizer.h +++ b/tgfx/src/gpu/gradients/DualIntervalGradientColorizer.h @@ -18,14 +18,14 @@ #pragma once -#include "core/Color4f.h" +#include "core/Color.h" #include "gpu/FragmentProcessor.h" -namespace pag { +namespace tgfx { class DualIntervalGradientColorizer : public FragmentProcessor { public: - static std::unique_ptr Make(Color4f c0, Color4f c1, Color4f c2, - Color4f c3, float threshold); + static std::unique_ptr Make(Color c0, Color c1, Color c2, Color c3, + float threshold); std::string name() const override { return "DualIntervalGradientColorizer"; @@ -36,17 +36,17 @@ class DualIntervalGradientColorizer : public FragmentProcessor { std::unique_ptr onCreateGLInstance() const override; private: - DualIntervalGradientColorizer(Color4f scale01, Color4f bias01, Color4f scale23, Color4f bias23, + DualIntervalGradientColorizer(Color scale01, Color bias01, Color scale23, Color bias23, float threshold) : scale01(scale01), bias01(bias01), scale23(scale23), bias23(bias23), threshold(threshold) { } - Color4f scale01; - Color4f bias01; - Color4f scale23; - Color4f bias23; + Color scale01; + Color bias01; + Color scale23; + Color bias23; float threshold; friend class GLDualIntervalGradientColorizer; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/GradientShader.cpp b/tgfx/src/gpu/gradients/GradientShader.cpp index cf23e83ce1..e71e7dd0c7 100644 --- a/tgfx/src/gpu/gradients/GradientShader.cpp +++ b/tgfx/src/gpu/gradients/GradientShader.cpp @@ -17,7 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "GradientShader.h" -#include "base/utils/MathExtra.h" +#include "core/utils/MathExtra.h" #include "gpu/Caps.h" #include "gpu/ColorShader.h" #include "gpu/ConstColorProcessor.h" @@ -30,7 +30,7 @@ #include "gpu/gradients/TextureGradientColorizer.h" #include "gpu/gradients/UnrolledBinaryGradientColorizer.h" -namespace pag { +namespace tgfx { // Intervals smaller than this (that aren't hard stops) on low-precision-only devices force us to // use the textured gradient static constexpr float LowPrecisionIntervalLimit = 0.01f; @@ -38,7 +38,7 @@ static constexpr float DegenerateThreshold = 1.0f / (1 << 15); // Analyze the shader's color stops and positions and chooses an appropriate colorizer to represent // the gradient. -static std::unique_ptr MakeColorizer(Context* context, const Color4f* colors, +static std::unique_ptr MakeColorizer(Context* context, const Color* colors, const float* positions, int count) { // If there are hard stops at the beginning or end, the first and/or last color should be // ignored by the colorizer since it should only be used in a clamped border color. By detecting @@ -109,7 +109,7 @@ static std::unique_ptr MakeColorizer(Context* context, const context->gradientCache()->getGradient(colors + offset, positions + offset, count)); } -GradientShaderBase::GradientShaderBase(const std::vector& colors, +GradientShaderBase::GradientShaderBase(const std::vector& colors, const std::vector& positions, const Matrix& pointsToUnit) : pointsToUnit(pointsToUnit) { @@ -200,7 +200,7 @@ static Matrix PointsToUnitMatrix(const Point& startPoint, const Point& endPoint) } LinearGradient::LinearGradient(const Point& startPoint, const Point& endPoint, - const std::vector& colors, + const std::vector& colors, const std::vector& positions) : GradientShaderBase(colors, positions, PointsToUnitMatrix(startPoint, endPoint)) { } @@ -218,8 +218,7 @@ static Matrix RadialToUnitMatrix(const Point& center, float radius) { return matrix; } -RadialGradient::RadialGradient(const Point& center, float radius, - const std::vector& colors, +RadialGradient::RadialGradient(const Point& center, float radius, const std::vector& colors, const std::vector& positions) : GradientShaderBase(colors, positions, RadialToUnitMatrix(center, radius)) { } @@ -231,7 +230,7 @@ std::unique_ptr RadialGradient::asFragmentProcessor(const FPA } std::shared_ptr Shader::MakeLinearGradient(const Point& startPoint, const Point& endPoint, - const std::vector& colors, + const std::vector& colors, const std::vector& positions) { if (!std::isfinite(Point::Distance(endPoint, startPoint))) { return nullptr; @@ -253,7 +252,7 @@ std::shared_ptr Shader::MakeLinearGradient(const Point& startPoint, cons } std::shared_ptr Shader::MakeRadialGradient(const Point& center, float radius, - const std::vector& colors, + const std::vector& colors, const std::vector& positions) { if (radius < 0) { return nullptr; @@ -271,4 +270,4 @@ std::shared_ptr Shader::MakeRadialGradient(const Point& center, float ra } return std::make_shared(center, radius, colors, positions); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/GradientShader.h b/tgfx/src/gpu/gradients/GradientShader.h index 5328fa10a5..0e0c5ed06b 100644 --- a/tgfx/src/gpu/gradients/GradientShader.h +++ b/tgfx/src/gpu/gradients/GradientShader.h @@ -18,20 +18,21 @@ #pragma once +#include "core/Matrix.h" #include "gpu/Shader.h" -namespace pag { +namespace tgfx { class GradientShaderBase : public Shader { public: - GradientShaderBase(const std::vector& colors, const std::vector& positions, + GradientShaderBase(const std::vector& colors, const std::vector& positions, const Matrix& pointsToUnit); bool isOpaque() const override { return colorsAreOpaque; } - std::vector originalColors = {}; + std::vector originalColors = {}; std::vector originalPositions = {}; protected: @@ -41,7 +42,7 @@ class GradientShaderBase : public Shader { class LinearGradient : public GradientShaderBase { public: - LinearGradient(const Point& startPoint, const Point& endPoint, const std::vector& colors, + LinearGradient(const Point& startPoint, const Point& endPoint, const std::vector& colors, const std::vector& positions); std::unique_ptr asFragmentProcessor(const FPArgs& args) const override; @@ -49,9 +50,9 @@ class LinearGradient : public GradientShaderBase { class RadialGradient : public GradientShaderBase { public: - RadialGradient(const Point& center, float radius, const std::vector& colors, + RadialGradient(const Point& center, float radius, const std::vector& colors, const std::vector& positions); std::unique_ptr asFragmentProcessor(const FPArgs& args) const override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/LinearGradientLayout.cpp b/tgfx/src/gpu/gradients/LinearGradientLayout.cpp index ca8d05948d..5873ffb507 100644 --- a/tgfx/src/gpu/gradients/LinearGradientLayout.cpp +++ b/tgfx/src/gpu/gradients/LinearGradientLayout.cpp @@ -17,10 +17,10 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "LinearGradientLayout.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "gpu/opengl/GLLinearGradientLayout.h" -namespace pag { +namespace tgfx { std::unique_ptr LinearGradientLayout::Make(Matrix matrix) { return std::unique_ptr(new LinearGradientLayout(matrix)); } @@ -37,4 +37,4 @@ LinearGradientLayout::LinearGradientLayout(Matrix matrix) : coordTransform(matri std::unique_ptr LinearGradientLayout::onCreateGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/LinearGradientLayout.h b/tgfx/src/gpu/gradients/LinearGradientLayout.h index bd98d75dc0..f77a92960d 100644 --- a/tgfx/src/gpu/gradients/LinearGradientLayout.h +++ b/tgfx/src/gpu/gradients/LinearGradientLayout.h @@ -20,7 +20,7 @@ #include "gpu/FragmentProcessor.h" -namespace pag { +namespace tgfx { class LinearGradientLayout : public FragmentProcessor { public: static std::unique_ptr Make(Matrix matrix); @@ -38,4 +38,4 @@ class LinearGradientLayout : public FragmentProcessor { CoordTransform coordTransform; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/RadialGradientLayout.cpp b/tgfx/src/gpu/gradients/RadialGradientLayout.cpp index 7411ca2c11..0d379d273e 100644 --- a/tgfx/src/gpu/gradients/RadialGradientLayout.cpp +++ b/tgfx/src/gpu/gradients/RadialGradientLayout.cpp @@ -17,10 +17,10 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "RadialGradientLayout.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "gpu/opengl/GLRadialGradientLayout.h" -namespace pag { +namespace tgfx { std::unique_ptr RadialGradientLayout::Make(Matrix matrix) { return std::unique_ptr(new RadialGradientLayout(matrix)); } @@ -37,4 +37,4 @@ RadialGradientLayout::RadialGradientLayout(Matrix matrix) : coordTransform(matri std::unique_ptr RadialGradientLayout::onCreateGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/RadialGradientLayout.h b/tgfx/src/gpu/gradients/RadialGradientLayout.h index 5bff34b5a8..e5680744d8 100644 --- a/tgfx/src/gpu/gradients/RadialGradientLayout.h +++ b/tgfx/src/gpu/gradients/RadialGradientLayout.h @@ -20,7 +20,7 @@ #include "gpu/FragmentProcessor.h" -namespace pag { +namespace tgfx { class RadialGradientLayout : public FragmentProcessor { public: static std::unique_ptr Make(Matrix matrix); @@ -38,4 +38,4 @@ class RadialGradientLayout : public FragmentProcessor { CoordTransform coordTransform; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/SingleIntervalGradientColorizer.cpp b/tgfx/src/gpu/gradients/SingleIntervalGradientColorizer.cpp index 34147592e4..783e704f44 100644 --- a/tgfx/src/gpu/gradients/SingleIntervalGradientColorizer.cpp +++ b/tgfx/src/gpu/gradients/SingleIntervalGradientColorizer.cpp @@ -17,12 +17,12 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "SingleIntervalGradientColorizer.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "gpu/opengl/GLSingleIntervalGradientColorizer.h" -namespace pag { -std::unique_ptr SingleIntervalGradientColorizer::Make( - Color4f start, Color4f end) { +namespace tgfx { +std::unique_ptr SingleIntervalGradientColorizer::Make(Color start, + Color end) { return std::unique_ptr( new SingleIntervalGradientColorizer(start, end)); } @@ -35,4 +35,4 @@ void SingleIntervalGradientColorizer::onComputeProcessorKey(BytesKey* bytesKey) std::unique_ptr SingleIntervalGradientColorizer::onCreateGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/SingleIntervalGradientColorizer.h b/tgfx/src/gpu/gradients/SingleIntervalGradientColorizer.h index ce060a647c..8c0a30954e 100644 --- a/tgfx/src/gpu/gradients/SingleIntervalGradientColorizer.h +++ b/tgfx/src/gpu/gradients/SingleIntervalGradientColorizer.h @@ -18,13 +18,13 @@ #pragma once -#include "core/Color4f.h" +#include "core/Color.h" #include "gpu/FragmentProcessor.h" -namespace pag { +namespace tgfx { class SingleIntervalGradientColorizer : public FragmentProcessor { public: - static std::unique_ptr Make(Color4f start, Color4f end); + static std::unique_ptr Make(Color start, Color end); std::string name() const override { return "SingleIntervalGradientColorizer"; @@ -35,12 +35,12 @@ class SingleIntervalGradientColorizer : public FragmentProcessor { std::unique_ptr onCreateGLInstance() const override; private: - SingleIntervalGradientColorizer(Color4f start, Color4f end) : start(start), end(end) { + SingleIntervalGradientColorizer(Color start, Color end) : start(start), end(end) { } - Color4f start; - Color4f end; + Color start; + Color end; friend class GLSingleIntervalGradientColorizer; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/TextureGradientColorizer.cpp b/tgfx/src/gpu/gradients/TextureGradientColorizer.cpp index 222960c4c4..934116e2f5 100644 --- a/tgfx/src/gpu/gradients/TextureGradientColorizer.cpp +++ b/tgfx/src/gpu/gradients/TextureGradientColorizer.cpp @@ -17,10 +17,10 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "TextureGradientColorizer.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "gpu/opengl/GLTextureGradientColorizer.h" -namespace pag { +namespace tgfx { std::unique_ptr TextureGradientColorizer::Make(const Texture* gradient) { return std::unique_ptr(new TextureGradientColorizer(gradient)); } @@ -33,4 +33,4 @@ void TextureGradientColorizer::onComputeProcessorKey(BytesKey* bytesKey) const { std::unique_ptr TextureGradientColorizer::onCreateGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/TextureGradientColorizer.h b/tgfx/src/gpu/gradients/TextureGradientColorizer.h index ef41465226..723cdd6f1f 100644 --- a/tgfx/src/gpu/gradients/TextureGradientColorizer.h +++ b/tgfx/src/gpu/gradients/TextureGradientColorizer.h @@ -22,7 +22,7 @@ #include "gpu/FragmentProcessor.h" -namespace pag { +namespace tgfx { class TextureGradientColorizer : public FragmentProcessor { public: static std::unique_ptr Make(const Texture* gradient); @@ -48,4 +48,4 @@ class TextureGradientColorizer : public FragmentProcessor { friend class GLTextureGradientColorizer; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/UnrolledBinaryGradientColorizer.cpp b/tgfx/src/gpu/gradients/UnrolledBinaryGradientColorizer.cpp index 95cdf2d876..656f8e3030 100644 --- a/tgfx/src/gpu/gradients/UnrolledBinaryGradientColorizer.cpp +++ b/tgfx/src/gpu/gradients/UnrolledBinaryGradientColorizer.cpp @@ -17,14 +17,14 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "UnrolledBinaryGradientColorizer.h" -#include "base/utils/MathExtra.h" -#include "base/utils/UniqueID.h" +#include "core/utils/MathExtra.h" +#include "core/utils/UniqueID.h" #include "gpu/opengl/GLUnrolledBinaryGradientColorizer.h" -namespace pag { +namespace tgfx { static constexpr int kMaxIntervals = 8; std::unique_ptr UnrolledBinaryGradientColorizer::Make( - const Color4f* colors, const float* positions, int count) { + const Color* colors, const float* positions, int count) { // Depending on how the positions resolve into hard stops or regular stops, the number of // intervals specified by the number of colors/positions can change. For instance, a plain // 3 color gradient is two intervals, but a 4 color gradient with a hard stop is also @@ -38,8 +38,8 @@ std::unique_ptr UnrolledBinaryGradientColorizer // The raster implementation also uses scales and biases, but since they must be calculated // after the dst color space is applied, it limits our ability to cache their values. - Color4f scales[kMaxIntervals]; - Color4f biases[kMaxIntervals]; + Color scales[kMaxIntervals]; + Color biases[kMaxIntervals]; float thresholds[kMaxIntervals]; int intervalCount = 0; @@ -75,8 +75,8 @@ std::unique_ptr UnrolledBinaryGradientColorizer // set the unused values to something consistent for (int i = intervalCount; i < kMaxIntervals; i++) { - scales[i] = Color4f::Transparent(); - biases[i] = Color4f::Transparent(); + scales[i] = Color::Transparent(); + biases[i] = Color::Transparent(); thresholds[i] = 0.0; } @@ -95,4 +95,4 @@ void UnrolledBinaryGradientColorizer::onComputeProcessorKey(BytesKey* bytesKey) std::unique_ptr UnrolledBinaryGradientColorizer::onCreateGLInstance() const { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/gradients/UnrolledBinaryGradientColorizer.h b/tgfx/src/gpu/gradients/UnrolledBinaryGradientColorizer.h index effff40161..b9f603579f 100644 --- a/tgfx/src/gpu/gradients/UnrolledBinaryGradientColorizer.h +++ b/tgfx/src/gpu/gradients/UnrolledBinaryGradientColorizer.h @@ -18,14 +18,14 @@ #pragma once -#include "core/Color4f.h" +#include "core/Color.h" #include "gpu/FragmentProcessor.h" -namespace pag { +namespace tgfx { class UnrolledBinaryGradientColorizer : public FragmentProcessor { public: static constexpr int kMaxColorCount = 16; - static std::unique_ptr Make(const Color4f* colors, + static std::unique_ptr Make(const Color* colors, const float* positions, int count); std::string name() const override { @@ -37,7 +37,7 @@ class UnrolledBinaryGradientColorizer : public FragmentProcessor { std::unique_ptr onCreateGLInstance() const override; private: - UnrolledBinaryGradientColorizer(int intervalCount, Color4f* scales, Color4f* biases, + UnrolledBinaryGradientColorizer(int intervalCount, Color* scales, Color* biases, Rect thresholds1_7, Rect thresholds9_13) : intervalCount(intervalCount), scale0_1(scales[0]), @@ -61,25 +61,25 @@ class UnrolledBinaryGradientColorizer : public FragmentProcessor { } int intervalCount; - Color4f scale0_1; - Color4f scale2_3; - Color4f scale4_5; - Color4f scale6_7; - Color4f scale8_9; - Color4f scale10_11; - Color4f scale12_13; - Color4f scale14_15; - Color4f bias0_1; - Color4f bias2_3; - Color4f bias4_5; - Color4f bias6_7; - Color4f bias8_9; - Color4f bias10_11; - Color4f bias12_13; - Color4f bias14_15; + Color scale0_1; + Color scale2_3; + Color scale4_5; + Color scale6_7; + Color scale8_9; + Color scale10_11; + Color scale12_13; + Color scale14_15; + Color bias0_1; + Color bias2_3; + Color bias4_5; + Color bias6_7; + Color bias8_9; + Color bias10_11; + Color bias12_13; + Color bias14_15; Rect thresholds1_7; Rect thresholds9_13; friend class GLUnrolledBinaryGradientColorizer; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLAlphaFragmentProcessor.cpp b/tgfx/src/gpu/opengl/GLAlphaFragmentProcessor.cpp index 94fcf3b571..2cfc0e7a0a 100644 --- a/tgfx/src/gpu/opengl/GLAlphaFragmentProcessor.cpp +++ b/tgfx/src/gpu/opengl/GLAlphaFragmentProcessor.cpp @@ -19,7 +19,7 @@ #include "GLAlphaFragmentProcessor.h" #include "gpu/AlphaFragmentProcessor.h" -namespace pag { +namespace tgfx { void GLAlphaFragmentProcessor::emitCode(EmitArgs& args) { auto* fragBuilder = args.fragBuilder; auto* uniformHandler = args.uniformHandler; @@ -39,4 +39,4 @@ void GLAlphaFragmentProcessor::onSetData(const ProgramDataManager& programDataMa programDataManager.set1f(alphaUniform, afp.alpha); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLAlphaFragmentProcessor.h b/tgfx/src/gpu/opengl/GLAlphaFragmentProcessor.h index 9b2d7bdb42..6551aaed03 100644 --- a/tgfx/src/gpu/opengl/GLAlphaFragmentProcessor.h +++ b/tgfx/src/gpu/opengl/GLAlphaFragmentProcessor.h @@ -20,7 +20,7 @@ #include "gpu/GLFragmentProcessor.h" -namespace pag { +namespace tgfx { class GLAlphaFragmentProcessor : public GLFragmentProcessor { public: void emitCode(EmitArgs& args) override; @@ -33,4 +33,4 @@ class GLAlphaFragmentProcessor : public GLFragmentProcessor { float alphaPrev = -1; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLAssembledGLESInterface.cpp b/tgfx/src/gpu/opengl/GLAssembledGLESInterface.cpp index 9c879e4ebb..a545aa2398 100644 --- a/tgfx/src/gpu/opengl/GLAssembledGLESInterface.cpp +++ b/tgfx/src/gpu/opengl/GLAssembledGLESInterface.cpp @@ -20,7 +20,7 @@ #include "GLInterface.h" -namespace pag { +namespace tgfx { static void InitFramebufferTexture2DMultisample(const GLProcGetter* getter, GLInterface* interface, const GLInfo& info) { if (info.hasExtension("GL_EXT_multisampled_render_to_texture")) { @@ -110,4 +110,4 @@ void GLAssembleGLESInterface(const GLProcGetter* getter, GLInterface* interface, InitFramebufferTexture2DMultisample(getter, interface, info); InitVertexArray(getter, interface, info); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLAssembledGLESInterface.h b/tgfx/src/gpu/opengl/GLAssembledGLESInterface.h index d19e93d63b..0b4bb0aed1 100644 --- a/tgfx/src/gpu/opengl/GLAssembledGLESInterface.h +++ b/tgfx/src/gpu/opengl/GLAssembledGLESInterface.h @@ -18,11 +18,11 @@ #pragma once -namespace pag { +namespace tgfx { class GLProcGetter; class GLInterface; class GLInfo; void GLAssembleGLESInterface(const GLProcGetter* getter, GLInterface* interface, const GLInfo& info); -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLAssembledGLInterface.cpp b/tgfx/src/gpu/opengl/GLAssembledGLInterface.cpp index 5a45522f08..720ec32003 100644 --- a/tgfx/src/gpu/opengl/GLAssembledGLInterface.cpp +++ b/tgfx/src/gpu/opengl/GLAssembledGLInterface.cpp @@ -20,7 +20,7 @@ #include "GLInterface.h" -namespace pag { +namespace tgfx { static void InitTextureBarrier(const GLProcGetter* getter, GLInterface* interface, const GLInfo& info) { if (info.version >= GL_VER(4, 5) || info.hasExtension("GL_ARB_texture_barrier")) { @@ -82,4 +82,4 @@ void GLAssembleGLInterface(const GLProcGetter* getter, GLInterface* interface, c InitRenderbufferStorageMultisample(getter, interface, info); InitVertexArray(getter, interface, info); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLAssembledGLInterface.h b/tgfx/src/gpu/opengl/GLAssembledGLInterface.h index a63b2a1c05..8c1a9131e3 100644 --- a/tgfx/src/gpu/opengl/GLAssembledGLInterface.h +++ b/tgfx/src/gpu/opengl/GLAssembledGLInterface.h @@ -18,10 +18,10 @@ #pragma once -namespace pag { +namespace tgfx { class GLProcGetter; class GLInterface; class GLInfo; void GLAssembleGLInterface(const GLProcGetter* getter, GLInterface* interface, const GLInfo& info); -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLAssembledWebGLInterface.cpp b/tgfx/src/gpu/opengl/GLAssembledWebGLInterface.cpp index 41912ecab5..f785ad4b57 100644 --- a/tgfx/src/gpu/opengl/GLAssembledWebGLInterface.cpp +++ b/tgfx/src/gpu/opengl/GLAssembledWebGLInterface.cpp @@ -20,7 +20,7 @@ #include "GLInterface.h" -namespace pag { +namespace tgfx { static unsigned GetErrorFake() { return GL::NO_ERROR; } @@ -62,4 +62,4 @@ void GLAssembleWebGLInterface(const GLProcGetter* getter, GLInterface* interface } InitVertexArray(getter, interface, info); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLAssembledWebGLInterface.h b/tgfx/src/gpu/opengl/GLAssembledWebGLInterface.h index 65517e0c66..35c434f25d 100644 --- a/tgfx/src/gpu/opengl/GLAssembledWebGLInterface.h +++ b/tgfx/src/gpu/opengl/GLAssembledWebGLInterface.h @@ -18,11 +18,11 @@ #pragma once -namespace pag { +namespace tgfx { class GLProcGetter; class GLInterface; class GLInfo; void GLAssembleWebGLInterface(const GLProcGetter* getter, GLInterface* interface, const GLInfo& info); -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLBlend.cpp b/tgfx/src/gpu/opengl/GLBlend.cpp index 54fcb36a2b..16a1178104 100644 --- a/tgfx/src/gpu/opengl/GLBlend.cpp +++ b/tgfx/src/gpu/opengl/GLBlend.cpp @@ -19,7 +19,7 @@ #include "GLBlend.h" #include "GLDefines.h" -namespace pag { +namespace tgfx { static void HardLight(FragmentShaderBuilder* fsBuilder, const char* final, const char* src, const char* dst) { static constexpr char kComponents[] = {'r', 'g', 'b'}; @@ -314,25 +314,25 @@ static void BlendHandler_Luminosity(FragmentShaderBuilder* fsBuilder, const char using BlendHandler = void (*)(FragmentShaderBuilder* fsBuilder, const char* srcColor, const char* dstColor, const char* outputColor); -static constexpr std::pair kBlendHandlers[] = { - {Blend::Overlay, BlendHandler_Overlay}, - {Blend::Darken, BlendHandler_Darken}, - {Blend::Lighten, BlendHandler_Lighten}, - {Blend::ColorDodge, BlendHandler_ColorDodge}, - {Blend::ColorBurn, BlendHandler_ColorBurn}, - {Blend::HardLight, BlendHandler_HardLight}, - {Blend::SoftLight, BlendHandler_SoftLight}, - {Blend::Difference, BlendHandler_Difference}, - {Blend::Exclusion, BlendHandler_Exclusion}, - {Blend::Multiply, BlendHandler_Multiply}, - {Blend::Hue, BlendHandler_Hue}, - {Blend::Saturation, BlendHandler_Saturation}, - {Blend::Color, BlendHandler_Color}, - {Blend::Luminosity, BlendHandler_Luminosity}}; +static constexpr std::pair kBlendHandlers[] = { + {BlendMode::Overlay, BlendHandler_Overlay}, + {BlendMode::Darken, BlendHandler_Darken}, + {BlendMode::Lighten, BlendHandler_Lighten}, + {BlendMode::ColorDodge, BlendHandler_ColorDodge}, + {BlendMode::ColorBurn, BlendHandler_ColorBurn}, + {BlendMode::HardLight, BlendHandler_HardLight}, + {BlendMode::SoftLight, BlendHandler_SoftLight}, + {BlendMode::Difference, BlendHandler_Difference}, + {BlendMode::Exclusion, BlendHandler_Exclusion}, + {BlendMode::Multiply, BlendHandler_Multiply}, + {BlendMode::Hue, BlendHandler_Hue}, + {BlendMode::Saturation, BlendHandler_Saturation}, + {BlendMode::Color, BlendHandler_Color}, + {BlendMode::Luminosity, BlendHandler_Luminosity}}; static void HandleBlendModes(FragmentShaderBuilder* fsBuilder, const std::string& srcColor, const std::string& dstColor, const std::string& outputColor, - Blend blendMode) { + BlendMode blendMode) { // These all perform src-over on the alpha channel. fsBuilder->codeAppendf("%s.a = %s.a + (1.0 - %s.a) * %s.a;", outputColor.c_str(), srcColor.c_str(), srcColor.c_str(), dstColor.c_str()); @@ -344,24 +344,24 @@ static void HandleBlendModes(FragmentShaderBuilder* fsBuilder, const std::string } } -static constexpr std::pair> kBlendCoeffMap[] = { - {Blend::Clear, {GL::ZERO, GL::ZERO}}, - {Blend::Src, {GL::ONE, GL::ZERO}}, - {Blend::Dst, {GL::ZERO, GL::ONE}}, - {Blend::SrcOver, {GL::ONE, GL::ONE_MINUS_SRC_ALPHA}}, - {Blend::DstOver, {GL::ONE_MINUS_DST_ALPHA, GL::ONE}}, - {Blend::SrcIn, {GL::DST_ALPHA, GL::ZERO}}, - {Blend::DstIn, {GL::ZERO, GL::SRC_ALPHA}}, - {Blend::SrcOut, {GL::ONE_MINUS_DST_ALPHA, GL::ZERO}}, - {Blend::DstOut, {GL::ZERO, GL::ONE_MINUS_SRC_ALPHA}}, - {Blend::SrcATop, {GL::DST_ALPHA, GL::ONE_MINUS_SRC_ALPHA}}, - {Blend::DstATop, {GL::ONE_MINUS_DST_ALPHA, GL::SRC_ALPHA}}, - {Blend::Xor, {GL::ONE_MINUS_DST_ALPHA, GL::ONE_MINUS_SRC_ALPHA}}, - {Blend::Plus, {GL::ONE, GL::ONE}}, - {Blend::Modulate, {GL::ZERO, GL::SRC_COLOR}}, - {Blend::Screen, {GL::ONE, GL::ONE_MINUS_SRC_COLOR}}}; - -bool BlendAsCoeff(Blend blendMode, unsigned* first, unsigned* second) { +static constexpr std::pair> kBlendCoeffMap[] = { + {BlendMode::Clear, {GL::ZERO, GL::ZERO}}, + {BlendMode::Src, {GL::ONE, GL::ZERO}}, + {BlendMode::Dst, {GL::ZERO, GL::ONE}}, + {BlendMode::SrcOver, {GL::ONE, GL::ONE_MINUS_SRC_ALPHA}}, + {BlendMode::DstOver, {GL::ONE_MINUS_DST_ALPHA, GL::ONE}}, + {BlendMode::SrcIn, {GL::DST_ALPHA, GL::ZERO}}, + {BlendMode::DstIn, {GL::ZERO, GL::SRC_ALPHA}}, + {BlendMode::SrcOut, {GL::ONE_MINUS_DST_ALPHA, GL::ZERO}}, + {BlendMode::DstOut, {GL::ZERO, GL::ONE_MINUS_SRC_ALPHA}}, + {BlendMode::SrcATop, {GL::DST_ALPHA, GL::ONE_MINUS_SRC_ALPHA}}, + {BlendMode::DstATop, {GL::ONE_MINUS_DST_ALPHA, GL::SRC_ALPHA}}, + {BlendMode::Xor, {GL::ONE_MINUS_DST_ALPHA, GL::ONE_MINUS_SRC_ALPHA}}, + {BlendMode::Plus, {GL::ONE, GL::ONE}}, + {BlendMode::Modulate, {GL::ZERO, GL::SRC_COLOR}}, + {BlendMode::Screen, {GL::ONE, GL::ONE_MINUS_SRC_COLOR}}}; + +bool BlendAsCoeff(BlendMode blendMode, unsigned* first, unsigned* second) { for (const auto& pair : kBlendCoeffMap) { if (pair.first == blendMode) { if (first) { @@ -454,11 +454,11 @@ static bool AppendPorterDuffTerm(FragmentShaderBuilder* fsBuilder, unsigned coef } void AppendMode(FragmentShaderBuilder* fsBuilder, const std::string& srcColor, - const std::string& dstColor, const std::string& outColor, Blend blendMode) { + const std::string& dstColor, const std::string& outColor, BlendMode blendMode) { unsigned srcCoeff, dstCoeff; if (BlendAsCoeff(blendMode, &srcCoeff, &dstCoeff)) { // The only coeff mode that can go out of range is plus. - bool clamp = blendMode == Blend::Plus; + bool clamp = blendMode == BlendMode::Plus; fsBuilder->codeAppendf("%s = ", outColor.c_str()); if (clamp) { @@ -478,4 +478,4 @@ void AppendMode(FragmentShaderBuilder* fsBuilder, const std::string& srcColor, HandleBlendModes(fsBuilder, srcColor, dstColor, outColor, blendMode); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLBlend.h b/tgfx/src/gpu/opengl/GLBlend.h index ed7eefe42e..f38d535955 100644 --- a/tgfx/src/gpu/opengl/GLBlend.h +++ b/tgfx/src/gpu/opengl/GLBlend.h @@ -18,15 +18,14 @@ #pragma once -#include "core/Blend.h" +#include "core/BlendMode.h" #include "gpu/FragmentShaderBuilder.h" -#include "pag/types.h" -namespace pag { -bool BlendAsCoeff(Blend blendMode, unsigned* first = nullptr, unsigned* second = nullptr); +namespace tgfx { +bool BlendAsCoeff(BlendMode blendMode, unsigned* first = nullptr, unsigned* second = nullptr); // Appends GLSL code to fragment that assigns a specified blend of the srcColor and dstColor // variables to the outColor variable. void AppendMode(FragmentShaderBuilder* fsBuilder, const std::string& srcColor, - const std::string& dstColor, const std::string& outColor, Blend blendMode); -} // namespace pag + const std::string& dstColor, const std::string& outColor, BlendMode blendMode); +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLBuffer.cpp b/tgfx/src/gpu/opengl/GLBuffer.cpp index 8164702641..efcd6a4aa4 100644 --- a/tgfx/src/gpu/opengl/GLBuffer.cpp +++ b/tgfx/src/gpu/opengl/GLBuffer.cpp @@ -19,9 +19,9 @@ #include "GLBuffer.h" #include "GLContext.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" -namespace pag { +namespace tgfx { static void ComputeRecycleKey(BytesKey* recycleKey, const void* uniqueKey, size_t length) { static const uint32_t Type = UniqueID::Next(); recycleKey->write(Type); @@ -61,4 +61,4 @@ void GLBuffer::onRelease(Context* context) { _bufferID = 0; } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLBuffer.h b/tgfx/src/gpu/opengl/GLBuffer.h index ff55d5e19b..14268c82eb 100644 --- a/tgfx/src/gpu/opengl/GLBuffer.h +++ b/tgfx/src/gpu/opengl/GLBuffer.h @@ -20,7 +20,7 @@ #include "gpu/Resource.h" -namespace pag { +namespace tgfx { class GLBuffer : public Resource { public: static std::shared_ptr Make(Context* context, const uint16_t* buffer, size_t length); @@ -46,4 +46,4 @@ class GLBuffer : public Resource { size_t _length = 0; unsigned _bufferID = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLCanvas.cpp b/tgfx/src/gpu/opengl/GLCanvas.cpp index 92c8e564f9..42f357e6c6 100644 --- a/tgfx/src/gpu/opengl/GLCanvas.cpp +++ b/tgfx/src/gpu/opengl/GLCanvas.cpp @@ -20,16 +20,16 @@ #include "GLFillRectOp.h" #include "GLRRectOp.h" #include "GLSurface.h" -#include "base/utils/MathExtra.h" #include "core/Mask.h" #include "core/PathEffect.h" #include "core/TextBlob.h" +#include "core/utils/MathExtra.h" #include "gpu/AlphaFragmentProcessor.h" #include "gpu/ColorShader.h" #include "gpu/TextureFragmentProcessor.h" #include "gpu/TextureMaskFragmentProcessor.h" -namespace pag { +namespace tgfx { GLCanvas::GLCanvas(Surface* surface) : Canvas(surface) { } @@ -82,7 +82,7 @@ std::unique_ptr GLCanvas::getClipMask(const Rect& deviceQuad, auto clipCanvas = clipSurface->getCanvas(); clipCanvas->clear(); Paint paint = {}; - paint.setColor(Color4f::Black()); + paint.setColor(Color::Black()); clipCanvas->drawPath(globalPaint.clip, paint); return TextureMaskFragmentProcessor::MakeUseDeviceCoord(clipSurface->getTexture().get(), surface->origin()); @@ -361,4 +361,4 @@ void GLCanvas::draw(const Rect& localQuad, const Rect& deviceQuad, std::unique_p args.rectToDraw = localQuad; drawer->draw(std::move(args), std::move(op)); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLCanvas.h b/tgfx/src/gpu/opengl/GLCanvas.h index a12fa25a1f..30d879bcd1 100644 --- a/tgfx/src/gpu/opengl/GLCanvas.h +++ b/tgfx/src/gpu/opengl/GLCanvas.h @@ -19,11 +19,11 @@ #pragma once #include "GLDrawer.h" -#include "core/Blend.h" +#include "core/BlendMode.h" #include "core/Mask.h" #include "gpu/Canvas.h" -namespace pag { +namespace tgfx { class GLCanvas : public Canvas { public: explicit GLCanvas(Surface* surface); @@ -75,4 +75,4 @@ class GLCanvas : public Canvas { std::unique_ptr color, std::unique_ptr mask = nullptr, bool aa = false); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLCaps.cpp b/tgfx/src/gpu/opengl/GLCaps.cpp index 2bfeea6cc3..8d3ac2fb60 100644 --- a/tgfx/src/gpu/opengl/GLCaps.cpp +++ b/tgfx/src/gpu/opengl/GLCaps.cpp @@ -19,7 +19,7 @@ #include "GLCaps.h" #include "GLUtil.h" -namespace pag { +namespace tgfx { static GLStandard GetGLStandard(const char* versionString) { if (versionString == nullptr) { return GLStandard::None; @@ -418,4 +418,4 @@ bool GLCaps::usesMSAARenderBuffers() const { bool GLCaps::usesImplicitMSAAResolve() const { return MSFBOType::ES_IMG_MsToTexture == msFBOType || MSFBOType::ES_EXT_MsToTexture == msFBOType; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLCaps.h b/tgfx/src/gpu/opengl/GLCaps.h index 54cb27fc0a..72f674bf61 100644 --- a/tgfx/src/gpu/opengl/GLCaps.h +++ b/tgfx/src/gpu/opengl/GLCaps.h @@ -18,20 +18,20 @@ #pragma once +#include #include - +#include #include "GLDefines.h" #include "GLFunctions.h" -#include "base/utils/EnumClassHash.h" -#include "base/utils/Log.h" +#include "core/utils/EnumHasher.h" +#include "core/utils/Log.h" #include "gpu/Caps.h" #include "gpu/PixelConfig.h" #include "gpu/Swizzle.h" -#include "pag/types.h" #define GL_VER(major, minor) ((static_cast(major) << 16) | static_cast(minor)) -namespace pag { +namespace tgfx { enum class GLStandard { None, GL, GLES, WebGL }; struct TextureFormat { @@ -153,7 +153,7 @@ class GLCaps : public Caps { bool usesImplicitMSAAResolve() const; private: - std::unordered_map configMap = {}; + std::unordered_map configMap = {}; void initConfigMap(const GLInfo& info); void initColorSampleCount(const GLInfo& info); @@ -162,4 +162,4 @@ class GLCaps : public Caps { void initWebGLSupport(const GLInfo& info); void initFSAASupport(const GLInfo& info); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLClampedGradientEffect.cpp b/tgfx/src/gpu/opengl/GLClampedGradientEffect.cpp index 7b4fa07aeb..30fef5ebf0 100644 --- a/tgfx/src/gpu/opengl/GLClampedGradientEffect.cpp +++ b/tgfx/src/gpu/opengl/GLClampedGradientEffect.cpp @@ -19,7 +19,7 @@ #include "GLClampedGradientEffect.h" #include "gpu/gradients/ClampedGradientEffect.h" -namespace pag { +namespace tgfx { void GLClampedGradientEffect::emitCode(EmitArgs& args) { auto* fragBuilder = args.fragBuilder; const auto* fp = static_cast(args.fragmentProcessor); @@ -63,4 +63,4 @@ void GLClampedGradientEffect::onSetData(const ProgramDataManager& programDataMan programDataManager.set4fv(rightBorderColorUniform, 1, fp.rightBorderColor.array()); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLClampedGradientEffect.h b/tgfx/src/gpu/opengl/GLClampedGradientEffect.h index 0b79d8a160..e5d4fb34c9 100644 --- a/tgfx/src/gpu/opengl/GLClampedGradientEffect.h +++ b/tgfx/src/gpu/opengl/GLClampedGradientEffect.h @@ -18,10 +18,10 @@ #pragma once -#include "core/Color4f.h" +#include "core/Color.h" #include "gpu/GLFragmentProcessor.h" -namespace pag { +namespace tgfx { class GLClampedGradientEffect : public GLFragmentProcessor { public: void emitCode(EmitArgs& args) override; @@ -30,9 +30,9 @@ class GLClampedGradientEffect : public GLFragmentProcessor { void onSetData(const ProgramDataManager& programDataManager, const FragmentProcessor& fragmentProcessor) override; - Color4f leftBorderColorPrev = Color4f::Invalid(); - Color4f rightBorderColorPrev = Color4f::Invalid(); + Color leftBorderColorPrev = Color::Invalid(); + Color rightBorderColorPrev = Color::Invalid(); UniformHandle leftBorderColorUniform; UniformHandle rightBorderColorUniform; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLConstColorProcessor.cpp b/tgfx/src/gpu/opengl/GLConstColorProcessor.cpp index 33fdd39139..e71e449fa7 100644 --- a/tgfx/src/gpu/opengl/GLConstColorProcessor.cpp +++ b/tgfx/src/gpu/opengl/GLConstColorProcessor.cpp @@ -19,7 +19,7 @@ #include "GLConstColorProcessor.h" #include "gpu/ConstColorProcessor.h" -namespace pag { +namespace tgfx { void GLConstColorProcessor::emitCode(EmitArgs& args) { auto* fragBuilder = args.fragBuilder; std::string colorName; @@ -40,4 +40,4 @@ void GLConstColorProcessor::onSetData(const ProgramDataManager& programDataManag programDataManager.set4fv(colorUniform, 1, fp.color.array()); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLConstColorProcessor.h b/tgfx/src/gpu/opengl/GLConstColorProcessor.h index 10283d27f3..ad9639dce7 100644 --- a/tgfx/src/gpu/opengl/GLConstColorProcessor.h +++ b/tgfx/src/gpu/opengl/GLConstColorProcessor.h @@ -18,10 +18,10 @@ #pragma once -#include "core/Color4f.h" +#include "core/Color.h" #include "gpu/GLFragmentProcessor.h" -namespace pag { +namespace tgfx { class GLConstColorProcessor : public GLFragmentProcessor { public: void emitCode(EmitArgs& args) override; @@ -30,7 +30,7 @@ class GLConstColorProcessor : public GLFragmentProcessor { void onSetData(const ProgramDataManager& programDataManager, const FragmentProcessor& fragmentProcessor) override; - Color4f colorPrev = Color4f::Invalid(); + Color colorPrev = Color::Invalid(); UniformHandle colorUniform; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLContext.cpp b/tgfx/src/gpu/opengl/GLContext.cpp index cf195cae4e..dba6d46d94 100644 --- a/tgfx/src/gpu/opengl/GLContext.cpp +++ b/tgfx/src/gpu/opengl/GLContext.cpp @@ -19,9 +19,9 @@ #include "gpu/opengl/GLContext.h" #include "gpu/opengl/GLDevice.h" -namespace pag { +namespace tgfx { GLContext::GLContext(Device* device, const GLInterface* glInterface) : Context(device) { glState = std::make_unique(glInterface); interface = GLInterface::HookWithState(glInterface, glState.get()); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLContext.h b/tgfx/src/gpu/opengl/GLContext.h index 9d7b5f6976..0d3ec84911 100644 --- a/tgfx/src/gpu/opengl/GLContext.h +++ b/tgfx/src/gpu/opengl/GLContext.h @@ -22,7 +22,7 @@ #include "GLState.h" #include "gpu/Context.h" -namespace pag { +namespace tgfx { class GLCaps; class GLContext : public Context { @@ -48,4 +48,4 @@ class GLContext : public Context { friend class GLStateGuard; friend class GLDevice; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLDevice.cpp b/tgfx/src/gpu/opengl/GLDevice.cpp index 674206bc84..8663122848 100644 --- a/tgfx/src/gpu/opengl/GLDevice.cpp +++ b/tgfx/src/gpu/opengl/GLDevice.cpp @@ -20,7 +20,7 @@ #include "gpu/opengl/GLContext.h" #include "gpu/opengl/GLUtil.h" -namespace pag { +namespace tgfx { static std::mutex deviceMapLocker = {}; static std::unordered_map deviceMap = {}; @@ -83,4 +83,4 @@ void GLDevice::onUnlockContext() { } onClearCurrent(); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/GLDrawer.cpp b/tgfx/src/gpu/opengl/GLDrawer.cpp index 0ab40121b7..8280ca73c4 100644 --- a/tgfx/src/gpu/opengl/GLDrawer.cpp +++ b/tgfx/src/gpu/opengl/GLDrawer.cpp @@ -21,11 +21,11 @@ #include "GLProgramBuilder.h" #include "GLProgramCreator.h" #include "GLUtil.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "gpu/PorterDuffXferProcessor.h" #include "gpu/ProgramCache.h" -namespace pag { +namespace tgfx { struct AttribLayout { bool normalized = false; // Only used by floating point types. int count = 0; @@ -237,4 +237,4 @@ void GLDrawer::draw(DrawArgs args, std::unique_ptr op) const { } CheckGLError(gl); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLDrawer.h b/tgfx/src/gpu/opengl/GLDrawer.h index 1a659ae227..908aa0628e 100644 --- a/tgfx/src/gpu/opengl/GLDrawer.h +++ b/tgfx/src/gpu/opengl/GLDrawer.h @@ -20,15 +20,15 @@ #include "GLBuffer.h" #include "GLRenderTarget.h" -#include "core/Blend.h" +#include "core/BlendMode.h" #include "gpu/AAType.h" #include "gpu/FragmentProcessor.h" #include "gpu/GeometryProcessor.h" -namespace pag { +namespace tgfx { struct DrawArgs { Context* context = nullptr; - Blend blendMode = Blend::SrcOver; + BlendMode blendMode = BlendMode::SrcOver; Matrix viewMatrix = Matrix::I(); const GLRenderTarget* renderTarget = nullptr; std::shared_ptr renderTargetTexture = nullptr; @@ -67,4 +67,4 @@ class GLDrawer : public Resource { unsigned vertexArray = 0; unsigned vertexBuffer = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLDualIntervalGradientColorizer.cpp b/tgfx/src/gpu/opengl/GLDualIntervalGradientColorizer.cpp index 8421b43296..e163e49acc 100644 --- a/tgfx/src/gpu/opengl/GLDualIntervalGradientColorizer.cpp +++ b/tgfx/src/gpu/opengl/GLDualIntervalGradientColorizer.cpp @@ -19,7 +19,7 @@ #include "GLDualIntervalGradientColorizer.h" #include "gpu/gradients/DualIntervalGradientColorizer.h" -namespace pag { +namespace tgfx { void GLDualIntervalGradientColorizer::emitCode(EmitArgs& args) { auto* fragBuilder = args.fragBuilder; std::string scale01Name; @@ -73,4 +73,4 @@ void GLDualIntervalGradientColorizer::onSetData(const ProgramDataManager& progra programDataManager.set1f(thresholdUniform, fp.threshold); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLDualIntervalGradientColorizer.h b/tgfx/src/gpu/opengl/GLDualIntervalGradientColorizer.h index 6a74714b0a..313037060e 100644 --- a/tgfx/src/gpu/opengl/GLDualIntervalGradientColorizer.h +++ b/tgfx/src/gpu/opengl/GLDualIntervalGradientColorizer.h @@ -18,10 +18,10 @@ #pragma once -#include "core/Color4f.h" +#include "core/Color.h" #include "gpu/GLFragmentProcessor.h" -namespace pag { +namespace tgfx { class GLDualIntervalGradientColorizer : public GLFragmentProcessor { public: void emitCode(EmitArgs& args) override; @@ -35,10 +35,10 @@ class GLDualIntervalGradientColorizer : public GLFragmentProcessor { UniformHandle bias23Uniform; UniformHandle thresholdUniform; - Color4f scale01Prev = Color4f::Invalid(); - Color4f bias01Prev = Color4f::Invalid(); - Color4f scale23Prev = Color4f::Invalid(); - Color4f bias23Prev = Color4f::Invalid(); + Color scale01Prev = Color::Invalid(); + Color bias01Prev = Color::Invalid(); + Color scale23Prev = Color::Invalid(); + Color bias23Prev = Color::Invalid(); float thresholdPrev = -1; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLEllipseGeometryProcessor.cpp b/tgfx/src/gpu/opengl/GLEllipseGeometryProcessor.cpp index 5011e094d1..043a4a1d96 100644 --- a/tgfx/src/gpu/opengl/GLEllipseGeometryProcessor.cpp +++ b/tgfx/src/gpu/opengl/GLEllipseGeometryProcessor.cpp @@ -20,7 +20,7 @@ #include "gpu/Caps.h" #include "gpu/EllipseGeometryProcessor.h" -namespace pag { +namespace tgfx { void GLEllipseGeometryProcessor::emitCode(EmitArgs& args) { const auto& egp = *static_cast(args.gp); auto* vertBuilder = args.vertBuilder; @@ -142,4 +142,4 @@ void GLEllipseGeometryProcessor::setData(const ProgramDataManager& programDataMa static_cast(egp.height)); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLEllipseGeometryProcessor.h b/tgfx/src/gpu/opengl/GLEllipseGeometryProcessor.h index 9ef15a7ef1..72d4aac9c0 100644 --- a/tgfx/src/gpu/opengl/GLEllipseGeometryProcessor.h +++ b/tgfx/src/gpu/opengl/GLEllipseGeometryProcessor.h @@ -20,7 +20,7 @@ #include "gpu/GLGeometryProcessor.h" -namespace pag { +namespace tgfx { class GLEllipseGeometryProcessor : public GLGeometryProcessor { public: void emitCode(EmitArgs& args) override; @@ -36,4 +36,4 @@ class GLEllipseGeometryProcessor : public GLGeometryProcessor { int widthPrev = -1; int heightPrev = -1; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLEmptyXferProcessor.cpp b/tgfx/src/gpu/opengl/GLEmptyXferProcessor.cpp index 8247107bef..f15532a816 100644 --- a/tgfx/src/gpu/opengl/GLEmptyXferProcessor.cpp +++ b/tgfx/src/gpu/opengl/GLEmptyXferProcessor.cpp @@ -18,9 +18,9 @@ #include "GLEmptyXferProcessor.h" -namespace pag { +namespace tgfx { void GLEmptyXferProcessor::emitCode(const EmitArgs& args) { args.fragBuilder->codeAppendf("%s = %s * %s;", args.outputColor.c_str(), args.inputColor.c_str(), args.inputCoverage.c_str()); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLEmptyXferProcessor.h b/tgfx/src/gpu/opengl/GLEmptyXferProcessor.h index cc0b71194b..7f7d44f7d3 100644 --- a/tgfx/src/gpu/opengl/GLEmptyXferProcessor.h +++ b/tgfx/src/gpu/opengl/GLEmptyXferProcessor.h @@ -20,9 +20,9 @@ #include "gpu/GLXferProcessor.h" -namespace pag { +namespace tgfx { class GLEmptyXferProcessor : public GLXferProcessor { public: void emitCode(const EmitArgs& args) override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLFillRectOp.cpp b/tgfx/src/gpu/opengl/GLFillRectOp.cpp index beff62cdf3..85f5cb8221 100644 --- a/tgfx/src/gpu/opengl/GLFillRectOp.cpp +++ b/tgfx/src/gpu/opengl/GLFillRectOp.cpp @@ -20,7 +20,7 @@ #include "gpu/QuadPerEdgeAAGeometryProcessor.h" -namespace pag { +namespace tgfx { std::unique_ptr GLFillRectOp::getGeometryProcessor(const DrawArgs& args) { return QuadPerEdgeAAGeometryProcessor::Make( args.renderTarget->width(), args.renderTarget->height(), args.viewMatrix, args.aa); @@ -83,4 +83,4 @@ std::shared_ptr GLFillRectOp::getIndexBuffer(const DrawArgs& args) { } return nullptr; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLFillRectOp.h b/tgfx/src/gpu/opengl/GLFillRectOp.h index b2fb6420e6..e6abeb3aec 100644 --- a/tgfx/src/gpu/opengl/GLFillRectOp.h +++ b/tgfx/src/gpu/opengl/GLFillRectOp.h @@ -22,7 +22,7 @@ #include "GLBuffer.h" -namespace pag { +namespace tgfx { class GLFillRectOp : public GLDrawOp { public: static std::unique_ptr Make(); @@ -33,4 +33,4 @@ class GLFillRectOp : public GLDrawOp { std::shared_ptr getIndexBuffer(const DrawArgs& args) override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLFragmentShaderBuilder.cpp b/tgfx/src/gpu/opengl/GLFragmentShaderBuilder.cpp index 1342140e29..ea16b2ff99 100644 --- a/tgfx/src/gpu/opengl/GLFragmentShaderBuilder.cpp +++ b/tgfx/src/gpu/opengl/GLFragmentShaderBuilder.cpp @@ -20,7 +20,7 @@ #include "GLContext.h" #include "GLProgramBuilder.h" -namespace pag { +namespace tgfx { static constexpr char kDstColorName[] = "_dstColor"; GLFragmentShaderBuilder::GLFragmentShaderBuilder(ProgramBuilder* program) @@ -41,4 +41,4 @@ std::string GLFragmentShaderBuilder::colorOutputName() { return static_cast(programBuilder)->isDesktopGL() ? CustomColorOutputName() : "gl_FragColor"; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLFragmentShaderBuilder.h b/tgfx/src/gpu/opengl/GLFragmentShaderBuilder.h index 17f627b899..529b7c7448 100644 --- a/tgfx/src/gpu/opengl/GLFragmentShaderBuilder.h +++ b/tgfx/src/gpu/opengl/GLFragmentShaderBuilder.h @@ -20,7 +20,7 @@ #include "gpu/FragmentShaderBuilder.h" -namespace pag { +namespace tgfx { class GLFragmentShaderBuilder : public FragmentShaderBuilder { public: explicit GLFragmentShaderBuilder(ProgramBuilder* program); @@ -30,4 +30,4 @@ class GLFragmentShaderBuilder : public FragmentShaderBuilder { private: std::string colorOutputName() override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLFunctions.h b/tgfx/src/gpu/opengl/GLFunctions.h index 1df7455da1..a1b4904aa7 100644 --- a/tgfx/src/gpu/opengl/GLFunctions.h +++ b/tgfx/src/gpu/opengl/GLFunctions.h @@ -19,7 +19,7 @@ #pragma once #include -namespace pag { +namespace tgfx { #if !defined(GL_FUNCTION_TYPE) #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) #define GL_FUNCTION_TYPE __stdcall @@ -203,4 +203,4 @@ class GLFunction { size_t buffer[4] = {}; }; -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/GLInterface.cpp b/tgfx/src/gpu/opengl/GLInterface.cpp index 222058578d..78b2aed064 100644 --- a/tgfx/src/gpu/opengl/GLInterface.cpp +++ b/tgfx/src/gpu/opengl/GLInterface.cpp @@ -27,7 +27,7 @@ #include "GLState.h" #include "GLUtil.h" -namespace pag { +namespace tgfx { static std::mutex interfaceLocker = {}; static std::unordered_map> glInterfaceMap = {}; @@ -257,4 +257,4 @@ std::unique_ptr GLInterface::MakeNativeInterface(const GLProc interface->caps = std::shared_ptr(new GLCaps(info)); return std::unique_ptr(interface); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLInterface.h b/tgfx/src/gpu/opengl/GLInterface.h index d12ce4827f..64f775302d 100644 --- a/tgfx/src/gpu/opengl/GLInterface.h +++ b/tgfx/src/gpu/opengl/GLInterface.h @@ -23,7 +23,7 @@ #include "GLFunctions.h" #include "GLProcGetter.h" -namespace pag { +namespace tgfx { class GLState; /** @@ -130,4 +130,4 @@ class GLInterface { friend class GLContext; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLLinearGradientLayout.cpp b/tgfx/src/gpu/opengl/GLLinearGradientLayout.cpp index 196ffbc9e7..af604407d3 100644 --- a/tgfx/src/gpu/opengl/GLLinearGradientLayout.cpp +++ b/tgfx/src/gpu/opengl/GLLinearGradientLayout.cpp @@ -18,11 +18,11 @@ #include "GLLinearGradientLayout.h" -namespace pag { +namespace tgfx { void GLLinearGradientLayout::emitCode(EmitArgs& args) { auto* fragBuilder = args.fragBuilder; fragBuilder->codeAppendf("float t = %s.x + 1.0000000000000001e-05;", (*args.transformedCoords)[0].name().c_str()); fragBuilder->codeAppendf("%s = vec4(t, 1.0, 0.0, 0.0);", args.outputColor.c_str()); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLLinearGradientLayout.h b/tgfx/src/gpu/opengl/GLLinearGradientLayout.h index 01023b4de2..7f985a383d 100644 --- a/tgfx/src/gpu/opengl/GLLinearGradientLayout.h +++ b/tgfx/src/gpu/opengl/GLLinearGradientLayout.h @@ -20,9 +20,9 @@ #include "gpu/GLFragmentProcessor.h" -namespace pag { +namespace tgfx { class GLLinearGradientLayout : public GLFragmentProcessor { public: void emitCode(EmitArgs& args) override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLPorterDuffXferProcessor.cpp b/tgfx/src/gpu/opengl/GLPorterDuffXferProcessor.cpp index 30ff902b3c..f8f7194b44 100644 --- a/tgfx/src/gpu/opengl/GLPorterDuffXferProcessor.cpp +++ b/tgfx/src/gpu/opengl/GLPorterDuffXferProcessor.cpp @@ -20,7 +20,7 @@ #include "GLBlend.h" #include "gpu/PorterDuffXferProcessor.h" -namespace pag { +namespace tgfx { void GLPorterDuffXferProcessor::emitCode(const EmitArgs& args) { auto* fragBuilder = args.fragBuilder; auto* uniformHandler = args.uniformHandler; @@ -84,4 +84,4 @@ void GLPorterDuffXferProcessor::setData(const ProgramDataManager& programDataMan } } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLPorterDuffXferProcessor.h b/tgfx/src/gpu/opengl/GLPorterDuffXferProcessor.h index bd09839e18..9830b89acb 100644 --- a/tgfx/src/gpu/opengl/GLPorterDuffXferProcessor.h +++ b/tgfx/src/gpu/opengl/GLPorterDuffXferProcessor.h @@ -20,7 +20,7 @@ #include "gpu/GLXferProcessor.h" -namespace pag { +namespace tgfx { class GLPorterDuffXferProcessor : public GLXferProcessor { public: void emitCode(const EmitArgs&) override; @@ -36,4 +36,4 @@ class GLPorterDuffXferProcessor : public GLXferProcessor { int widthPrev = -1; int heightPrev = -1; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLProcGetter.h b/tgfx/src/gpu/opengl/GLProcGetter.h index 59059ef5cb..1bb661ecee 100644 --- a/tgfx/src/gpu/opengl/GLProcGetter.h +++ b/tgfx/src/gpu/opengl/GLProcGetter.h @@ -20,7 +20,7 @@ #include -namespace pag { +namespace tgfx { class GLProcGetter { public: static std::unique_ptr Make(); @@ -29,4 +29,4 @@ class GLProcGetter { virtual void* getProcAddress(const char name[]) const = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLProgram.cpp b/tgfx/src/gpu/opengl/GLProgram.cpp index c2ede8d480..48d607bfd4 100644 --- a/tgfx/src/gpu/opengl/GLProgram.cpp +++ b/tgfx/src/gpu/opengl/GLProgram.cpp @@ -22,7 +22,7 @@ #include "GLUtil.h" #include "gpu/Pipeline.h" -namespace pag { +namespace tgfx { GLProgram::GLProgram(unsigned programID, const std::vector& uniforms, std::unique_ptr geometryProcessor, std::unique_ptr xferProcessor, @@ -59,9 +59,9 @@ void GLProgram::onRelease(Context* context) { } } -void BindTexture(const GLInterface* gl, int position, const TextureSampler* sampler) { +static void BindGLTexture(const GLInterface* gl, int position, const TextureSampler* sampler) { const auto& glInfo = static_cast(sampler)->glInfo; - ActiveTexture(gl, GL::TEXTURE0 + position, glInfo.target, glInfo.id, sampler->config); + ActiveGLTexture(gl, GL::TEXTURE0 + position, glInfo.target, glInfo.id, sampler->config); } void GLProgram::updateUniformsAndTextureBindings(const GLInterface* gl, @@ -82,7 +82,7 @@ void GLProgram::updateUniformsAndTextureBindings(const GLInterface* gl, const auto* dstTexture = pipeline.getDstTexture(&offset); if (dstTexture) { glXferProcessor->setData(programDataManager, *pipeline.getXferProcessor(), dstTexture, offset); - BindTexture(gl, nextTexSamplerIdx++, dstTexture->getSampler()); + BindGLTexture(gl, nextTexSamplerIdx++, dstTexture->getSampler()); } } @@ -96,10 +96,10 @@ void GLProgram::setFragmentData(const GLInterface* gl, while (fp && glslFP) { glslFP->setData(programDataManager, *fp); for (size_t i = 0; i < fp->numTextureSamplers(); ++i) { - BindTexture(gl, (*nextTexSamplerIdx)++, fp->textureSampler(i)); + BindGLTexture(gl, (*nextTexSamplerIdx)++, fp->textureSampler(i)); } fp = iter.next(); glslFP = glslIter.next(); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLProgram.h b/tgfx/src/gpu/opengl/GLProgram.h index 56d06252a9..d9bafec1f8 100644 --- a/tgfx/src/gpu/opengl/GLProgram.h +++ b/tgfx/src/gpu/opengl/GLProgram.h @@ -25,7 +25,7 @@ #include "gpu/GLXferProcessor.h" #include "gpu/Program.h" -namespace pag { +namespace tgfx { class GLProgram : public Program { public: struct Attribute { @@ -85,4 +85,4 @@ class GLProgram : public Program { int _vertexStride = 0; std::vector uniformLocations; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLProgramBuilder.cpp b/tgfx/src/gpu/opengl/GLProgramBuilder.cpp index 4127d9979e..5e394d986a 100644 --- a/tgfx/src/gpu/opengl/GLProgramBuilder.cpp +++ b/tgfx/src/gpu/opengl/GLProgramBuilder.cpp @@ -20,7 +20,7 @@ #include "GLContext.h" #include "GLUtil.h" -namespace pag { +namespace tgfx { static std::string TypeModifierString(bool isDesktopGL, ShaderVar::TypeModifier t, ShaderFlags flag) { switch (t) { @@ -112,7 +112,7 @@ std::unique_ptr GLProgramBuilder::finalize() { auto vertex = vertexShaderBuilder()->shaderString(); auto fragment = fragmentShaderBuilder()->shaderString(); - auto programID = pag::CreateProgram(_gl, vertex, fragment); + auto programID = CreateGLProgram(_gl, vertex, fragment); if (programID == 0) { return nullptr; } @@ -159,4 +159,4 @@ std::unique_ptr GLProgramBuilder::createProgram(unsigned programID) { bool GLProgramBuilder::isDesktopGL() const { return gl()->caps->standard == GLStandard::GL; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLProgramBuilder.h b/tgfx/src/gpu/opengl/GLProgramBuilder.h index 36fa0d0d9e..47e80dbce8 100644 --- a/tgfx/src/gpu/opengl/GLProgramBuilder.h +++ b/tgfx/src/gpu/opengl/GLProgramBuilder.h @@ -25,7 +25,7 @@ #include "GLVertexShaderBuilder.h" #include "gpu/ProgramBuilder.h" -namespace pag { +namespace tgfx { class GLProgramBuilder : public ProgramBuilder { public: /** @@ -96,4 +96,4 @@ class GLProgramBuilder : public ProgramBuilder { std::vector attributes; int vertexStride = 0; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLProgramCreator.cpp b/tgfx/src/gpu/opengl/GLProgramCreator.cpp index 59b702083a..ef9c4b2f5e 100644 --- a/tgfx/src/gpu/opengl/GLProgramCreator.cpp +++ b/tgfx/src/gpu/opengl/GLProgramCreator.cpp @@ -20,7 +20,7 @@ #include "GLContext.h" #include "GLProgramBuilder.h" -namespace pag { +namespace tgfx { GLProgramCreator::GLProgramCreator(const GeometryProcessor* geometryProcessor, const Pipeline* pipeline) : geometryProcessor(geometryProcessor), pipeline(pipeline) { @@ -35,4 +35,4 @@ std::unique_ptr GLProgramCreator::createProgram(Context* context) const const auto* gl = GLContext::Unwrap(context); return GLProgramBuilder::CreateProgram(gl, geometryProcessor, pipeline); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLProgramCreator.h b/tgfx/src/gpu/opengl/GLProgramCreator.h index b64d7c409f..b46051927e 100644 --- a/tgfx/src/gpu/opengl/GLProgramCreator.h +++ b/tgfx/src/gpu/opengl/GLProgramCreator.h @@ -22,7 +22,7 @@ #include "gpu/Pipeline.h" #include "gpu/Program.h" -namespace pag { +namespace tgfx { class GLProgramCreator : public ProgramCreator { public: GLProgramCreator(const GeometryProcessor* geometryProcessor, const Pipeline* pipeline); @@ -35,4 +35,4 @@ class GLProgramCreator : public ProgramCreator { const GeometryProcessor* geometryProcessor; const Pipeline* pipeline; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLProgramDataManager.cpp b/tgfx/src/gpu/opengl/GLProgramDataManager.cpp index 9b77740ea8..f689093cd3 100644 --- a/tgfx/src/gpu/opengl/GLProgramDataManager.cpp +++ b/tgfx/src/gpu/opengl/GLProgramDataManager.cpp @@ -22,7 +22,7 @@ #include "GLUniformHandler.h" #include "GLUtil.h" -namespace pag { +namespace tgfx { GLProgramDataManager::GLProgramDataManager(const GLInterface* gl, const std::vector* uniforms) : gl(gl), uniforms(uniforms) { } @@ -59,4 +59,4 @@ void GLProgramDataManager::setMatrix(UniformHandle u, const Matrix& matrix) cons auto values = ToGLMatrix(matrix); setMatrix3f(u, &(values[0])); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLProgramDataManager.h b/tgfx/src/gpu/opengl/GLProgramDataManager.h index 284f33ccf3..d66599f82e 100644 --- a/tgfx/src/gpu/opengl/GLProgramDataManager.h +++ b/tgfx/src/gpu/opengl/GLProgramDataManager.h @@ -21,7 +21,7 @@ #include "GLInterface.h" #include "gpu/ProgramDataManager.h" -namespace pag { +namespace tgfx { class GLProgramDataManager : public ProgramDataManager { public: GLProgramDataManager(const GLInterface* gl, const std::vector* uniforms); @@ -40,4 +40,4 @@ class GLProgramDataManager : public ProgramDataManager { const GLInterface* gl; const std::vector* uniforms; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLQuadPerEdgeAAGeometryProcessor.cpp b/tgfx/src/gpu/opengl/GLQuadPerEdgeAAGeometryProcessor.cpp index 00ba4c6d77..bd3bc3ace8 100644 --- a/tgfx/src/gpu/opengl/GLQuadPerEdgeAAGeometryProcessor.cpp +++ b/tgfx/src/gpu/opengl/GLQuadPerEdgeAAGeometryProcessor.cpp @@ -19,7 +19,7 @@ #include "GLQuadPerEdgeAAGeometryProcessor.h" #include "gpu/QuadPerEdgeAAGeometryProcessor.h" -namespace pag { +namespace tgfx { void GLQuadPerEdgeAAGeometryProcessor::emitCode(EmitArgs& args) { const auto* geometryProcessor = static_cast(args.gp); auto* vertBuilder = args.vertBuilder; @@ -77,4 +77,4 @@ void GLQuadPerEdgeAAGeometryProcessor::setData(const ProgramDataManager& program } updated = true; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLQuadPerEdgeAAGeometryProcessor.h b/tgfx/src/gpu/opengl/GLQuadPerEdgeAAGeometryProcessor.h index e0e459831b..5d60943c34 100644 --- a/tgfx/src/gpu/opengl/GLQuadPerEdgeAAGeometryProcessor.h +++ b/tgfx/src/gpu/opengl/GLQuadPerEdgeAAGeometryProcessor.h @@ -20,7 +20,7 @@ #include "gpu/GLGeometryProcessor.h" -namespace pag { +namespace tgfx { class GLQuadPerEdgeAAGeometryProcessor : public GLGeometryProcessor { public: void emitCode(EmitArgs& args) override; @@ -38,4 +38,4 @@ class GLQuadPerEdgeAAGeometryProcessor : public GLGeometryProcessor { int heightPrev = -1; bool updated = false; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLRRectOp.cpp b/tgfx/src/gpu/opengl/GLRRectOp.cpp index 2b2eb8f86f..4678736908 100644 --- a/tgfx/src/gpu/opengl/GLRRectOp.cpp +++ b/tgfx/src/gpu/opengl/GLRRectOp.cpp @@ -18,10 +18,10 @@ #include "GLRRectOp.h" -#include "base/utils/MathExtra.h" +#include "core/utils/MathExtra.h" #include "gpu/EllipseGeometryProcessor.h" -namespace pag { +namespace tgfx { // We have three possible cases for geometry for a round rect. // // In the case of a normal fill or a stroke, we draw the round rect as a 9-patch: @@ -214,4 +214,4 @@ std::vector GLRRectOp::vertices(const DrawArgs& args) { std::shared_ptr GLRRectOp::getIndexBuffer(const DrawArgs& args) { return GLBuffer::Make(args.context, gStandardRRectIndices, kIndicesPerFillRRect); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLRRectOp.h b/tgfx/src/gpu/opengl/GLRRectOp.h index 4a49301785..95e964eedd 100644 --- a/tgfx/src/gpu/opengl/GLRRectOp.h +++ b/tgfx/src/gpu/opengl/GLRRectOp.h @@ -22,7 +22,7 @@ #include "GLDrawer.h" #include "core/Path.h" -namespace pag { +namespace tgfx { class GLRRectOp : public GLDrawOp { public: static std::unique_ptr Make(RRect rRect); @@ -41,4 +41,4 @@ class GLRRectOp : public GLDrawOp { // bool stroked = false; // Point strokeWidths = Point::Zero(); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLRadialGradientLayout.cpp b/tgfx/src/gpu/opengl/GLRadialGradientLayout.cpp index 0ce1a38eb8..70005be30d 100644 --- a/tgfx/src/gpu/opengl/GLRadialGradientLayout.cpp +++ b/tgfx/src/gpu/opengl/GLRadialGradientLayout.cpp @@ -18,10 +18,10 @@ #include "GLRadialGradientLayout.h" -namespace pag { +namespace tgfx { void GLRadialGradientLayout::emitCode(EmitArgs& args) { auto* fragBuilder = args.fragBuilder; fragBuilder->codeAppendf("float t = length(%s);", (*args.transformedCoords)[0].name().c_str()); fragBuilder->codeAppendf("%s = vec4(t, 1.0, 0.0, 0.0);", args.outputColor.c_str()); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLRadialGradientLayout.h b/tgfx/src/gpu/opengl/GLRadialGradientLayout.h index 54c3ab1df3..a99949e3db 100644 --- a/tgfx/src/gpu/opengl/GLRadialGradientLayout.h +++ b/tgfx/src/gpu/opengl/GLRadialGradientLayout.h @@ -20,9 +20,9 @@ #include "gpu/GLFragmentProcessor.h" -namespace pag { +namespace tgfx { class GLRadialGradientLayout : public GLFragmentProcessor { public: void emitCode(EmitArgs& args) override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLRenderTarget.cpp b/tgfx/src/gpu/opengl/GLRenderTarget.cpp index 796c496e3d..5d993cda27 100644 --- a/tgfx/src/gpu/opengl/GLRenderTarget.cpp +++ b/tgfx/src/gpu/opengl/GLRenderTarget.cpp @@ -22,7 +22,7 @@ #include "GLUtil.h" #include "core/Bitmap.h" -namespace pag { +namespace tgfx { std::shared_ptr GLRenderTarget::MakeFrom(Context* context, const BackendRenderTarget& renderTarget, ImageOrigin origin) { @@ -295,4 +295,4 @@ void GLRenderTarget::onRelease(Context* context) { } ReleaseResource(context, &textureFBInfo, &renderTargetFBInfo, &msRenderBufferID); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLRenderTarget.h b/tgfx/src/gpu/opengl/GLRenderTarget.h index 470a716b6f..dfdd31f482 100644 --- a/tgfx/src/gpu/opengl/GLRenderTarget.h +++ b/tgfx/src/gpu/opengl/GLRenderTarget.h @@ -22,7 +22,7 @@ #include "GLTexture.h" #include "core/ImageInfo.h" -namespace pag { +namespace tgfx { /** * GLRenderTarget represents a 2D buffer of pixels that can be rendered to. */ @@ -110,4 +110,4 @@ class GLRenderTarget : public Resource { friend class GLSurface; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLSingleIntervalGradientColorizer.cpp b/tgfx/src/gpu/opengl/GLSingleIntervalGradientColorizer.cpp index e6e3c722a7..0b8fb89ae5 100644 --- a/tgfx/src/gpu/opengl/GLSingleIntervalGradientColorizer.cpp +++ b/tgfx/src/gpu/opengl/GLSingleIntervalGradientColorizer.cpp @@ -19,7 +19,7 @@ #include "GLSingleIntervalGradientColorizer.h" #include "gpu/gradients/SingleIntervalGradientColorizer.h" -namespace pag { +namespace tgfx { void GLSingleIntervalGradientColorizer::emitCode(EmitArgs& args) { auto* fragBuilder = args.fragBuilder; std::string startName; @@ -45,4 +45,4 @@ void GLSingleIntervalGradientColorizer::onSetData(const ProgramDataManager& prog programDataManager.set4fv(endUniform, 1, fp.end.array()); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLSingleIntervalGradientColorizer.h b/tgfx/src/gpu/opengl/GLSingleIntervalGradientColorizer.h index 3eb912870c..56ed2dbb67 100644 --- a/tgfx/src/gpu/opengl/GLSingleIntervalGradientColorizer.h +++ b/tgfx/src/gpu/opengl/GLSingleIntervalGradientColorizer.h @@ -18,10 +18,10 @@ #pragma once -#include "core/Color4f.h" +#include "core/Color.h" #include "gpu/GLFragmentProcessor.h" -namespace pag { +namespace tgfx { class GLSingleIntervalGradientColorizer : public GLFragmentProcessor { public: void emitCode(EmitArgs& args) override; @@ -32,7 +32,7 @@ class GLSingleIntervalGradientColorizer : public GLFragmentProcessor { UniformHandle startUniform; UniformHandle endUniform; - Color4f startPrev = Color4f::Invalid(); - Color4f endPrev = Color4f::Invalid(); + Color startPrev = Color::Invalid(); + Color endPrev = Color::Invalid(); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLStandard.h b/tgfx/src/gpu/opengl/GLStandard.h index 06aa03607e..5da957408b 100644 --- a/tgfx/src/gpu/opengl/GLStandard.h +++ b/tgfx/src/gpu/opengl/GLStandard.h @@ -18,6 +18,6 @@ #pragma once -namespace pag { +namespace tgfx { enum class GLStandard { None, GL, GLES, WebGL }; } diff --git a/tgfx/src/gpu/opengl/GLState.cpp b/tgfx/src/gpu/opengl/GLState.cpp index 5f2ca9be13..a1b7612a6d 100644 --- a/tgfx/src/gpu/opengl/GLState.cpp +++ b/tgfx/src/gpu/opengl/GLState.cpp @@ -20,7 +20,7 @@ #include "GLContext.h" -namespace pag { +namespace tgfx { #define PRIORITY_HIGH 3 #define PRIORITY_MEDIUM 2 #define PRIORITY_DEFAULT 1 @@ -1106,4 +1106,4 @@ GLStateGuard::~GLStateGuard() { state->restore(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLState.h b/tgfx/src/gpu/opengl/GLState.h index 5f61d67236..1185d20b17 100644 --- a/tgfx/src/gpu/opengl/GLState.h +++ b/tgfx/src/gpu/opengl/GLState.h @@ -22,7 +22,7 @@ #include #include "GLInterface.h" -namespace pag { +namespace tgfx { enum class GLAttributeType { ActiveTexture, BlendEquationSeparate, @@ -77,8 +77,7 @@ class StateRecord { std::list> defaultAttributes = {}; std::unordered_map> vertexMap = {}; std::unordered_map> textureMap = {}; - std::unordered_map, EnumClassHash> attributeMap = - {}; + std::unordered_map, EnumHasher> attributeMap = {}; }; // TODO(domrjchen): All GL methods that may modify the state should be hooked uniformly onto @@ -154,4 +153,4 @@ class GLStateGuard { private: GLState* state = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLSurface.cpp b/tgfx/src/gpu/opengl/GLSurface.cpp index 96a5e7ec88..268aa956c1 100644 --- a/tgfx/src/gpu/opengl/GLSurface.cpp +++ b/tgfx/src/gpu/opengl/GLSurface.cpp @@ -21,7 +21,7 @@ #include "GLContext.h" #include "GLUtil.h" -namespace pag { +namespace tgfx { std::shared_ptr Surface::MakeFrom(Context* context, const BackendRenderTarget& renderTarget, ImageOrigin origin) { @@ -153,4 +153,4 @@ bool GLSurface::onReadPixels(const ImageInfo& dstInfo, void* dstPixels, int srcX renderTarget->resolve(context); return renderTarget->readPixels(context, dstInfo, dstPixels, srcX, srcY); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLSurface.h b/tgfx/src/gpu/opengl/GLSurface.h index 387ae08ac8..2bb2d9ed22 100644 --- a/tgfx/src/gpu/opengl/GLSurface.h +++ b/tgfx/src/gpu/opengl/GLSurface.h @@ -23,7 +23,7 @@ #include "GLTexture.h" #include "gpu/Surface.h" -namespace pag { +namespace tgfx { class GLSurface : public Surface { public: static std::shared_ptr MakeFrom(Context* context, @@ -68,4 +68,4 @@ class GLSurface : public Surface { friend class Surface; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLTexture.cpp b/tgfx/src/gpu/opengl/GLTexture.cpp index 9a65151bbc..e6e0e9cd0d 100644 --- a/tgfx/src/gpu/opengl/GLTexture.cpp +++ b/tgfx/src/gpu/opengl/GLTexture.cpp @@ -18,11 +18,11 @@ #include "GLTexture.h" #include "GLUtil.h" -#include "base/utils/UniqueID.h" #include "core/Bitmap.h" +#include "core/utils/UniqueID.h" #include "gpu/Surface.h" -namespace pag { +namespace tgfx { class GLBackendTexture : public GLTexture { public: GLBackendTexture(GLTextureSampler textureSampler, int width, int height, ImageOrigin origin) @@ -170,7 +170,7 @@ std::shared_ptr Texture::Make(Context* context, int width, int height, } if (pixels != nullptr) { int bytesPerPixel = alphaOnly ? 1 : 4; - SubmitTexture(gl, glInfo, format, width, height, rowBytes, bytesPerPixel, pixels); + SubmitGLTexture(gl, glInfo, format, width, height, rowBytes, bytesPerPixel, pixels); } return texture; } @@ -216,23 +216,4 @@ GLTexture::GLTexture(int width, int height, ImageOrigin origin) : Texture(width, Point GLTexture::getTextureCoord(float x, float y) const { return {x / static_cast(width()), y / static_cast(height())}; } - -void Trace(const Texture* texture, const std::string& path) { - if (texture == nullptr) { - return; - } - auto surface = Surface::Make(texture->context, texture->width(), texture->height()); - if (surface == nullptr) { - return; - } - auto canvas = surface->getCanvas(); - canvas->drawTexture(texture); - auto pixelBuffer = PixelBuffer::Make(texture->width(), texture->height()); - Bitmap bitmap(pixelBuffer); - if (bitmap.isEmpty()) { - return; - } - surface->readPixels(bitmap.info(), bitmap.writablePixels()); - Trace(bitmap, path); -} -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLTexture.h b/tgfx/src/gpu/opengl/GLTexture.h index 363bd8bc20..e99c5f5c49 100644 --- a/tgfx/src/gpu/opengl/GLTexture.h +++ b/tgfx/src/gpu/opengl/GLTexture.h @@ -22,7 +22,7 @@ #include "GLTextureSampler.h" #include "gpu/Texture.h" -namespace pag { +namespace tgfx { class GLTexture : public Texture { public: static GLTextureInfo Unwrap(const Texture* texture); @@ -56,4 +56,4 @@ class GLTexture : public Texture { friend class Texture; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLTextureFragmentProcessor.cpp b/tgfx/src/gpu/opengl/GLTextureFragmentProcessor.cpp index c06c605b55..fcda2213b0 100644 --- a/tgfx/src/gpu/opengl/GLTextureFragmentProcessor.cpp +++ b/tgfx/src/gpu/opengl/GLTextureFragmentProcessor.cpp @@ -19,7 +19,7 @@ #include "GLTextureFragmentProcessor.h" #include "gpu/TextureFragmentProcessor.h" -namespace pag { +namespace tgfx { void GLTextureFragmentProcessor::emitCode(EmitArgs& args) { const auto* textureFP = static_cast(args.fragmentProcessor); auto* fragBuilder = args.fragBuilder; @@ -60,4 +60,4 @@ void GLTextureFragmentProcessor::onSetData(const ProgramDataManager& programData } } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLTextureFragmentProcessor.h b/tgfx/src/gpu/opengl/GLTextureFragmentProcessor.h index ed65ced1e0..59fcfdea02 100644 --- a/tgfx/src/gpu/opengl/GLTextureFragmentProcessor.h +++ b/tgfx/src/gpu/opengl/GLTextureFragmentProcessor.h @@ -20,7 +20,7 @@ #include "gpu/GLFragmentProcessor.h" -namespace pag { +namespace tgfx { class GLTextureFragmentProcessor : public GLFragmentProcessor { public: void emitCode(EmitArgs& args) override; @@ -33,4 +33,4 @@ class GLTextureFragmentProcessor : public GLFragmentProcessor { Point alphaStartPrev = Point::Make(-1, -1); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLTextureGradientColorizer.cpp b/tgfx/src/gpu/opengl/GLTextureGradientColorizer.cpp index 95f6b1b60c..1a46fe684a 100644 --- a/tgfx/src/gpu/opengl/GLTextureGradientColorizer.cpp +++ b/tgfx/src/gpu/opengl/GLTextureGradientColorizer.cpp @@ -18,7 +18,7 @@ #include "GLTextureGradientColorizer.h" -namespace pag { +namespace tgfx { void GLTextureGradientColorizer::emitCode(EmitArgs& args) { auto* fragBuilder = args.fragBuilder; fragBuilder->codeAppendf("vec2 coord = vec2(%s.x, 0.5);", args.inputColor.c_str()); @@ -26,4 +26,4 @@ void GLTextureGradientColorizer::emitCode(EmitArgs& args) { fragBuilder->appendTextureLookup((*args.textureSamplers)[0], "coord"); fragBuilder->codeAppend(";"); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLTextureGradientColorizer.h b/tgfx/src/gpu/opengl/GLTextureGradientColorizer.h index 2f44202c75..dde7f38bed 100644 --- a/tgfx/src/gpu/opengl/GLTextureGradientColorizer.h +++ b/tgfx/src/gpu/opengl/GLTextureGradientColorizer.h @@ -20,9 +20,9 @@ #include "gpu/GLFragmentProcessor.h" -namespace pag { +namespace tgfx { class GLTextureGradientColorizer : public GLFragmentProcessor { public: void emitCode(EmitArgs& args) override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLTextureMaskFragmentProcessor.cpp b/tgfx/src/gpu/opengl/GLTextureMaskFragmentProcessor.cpp index ee7f99c4bb..03cf4e41c5 100644 --- a/tgfx/src/gpu/opengl/GLTextureMaskFragmentProcessor.cpp +++ b/tgfx/src/gpu/opengl/GLTextureMaskFragmentProcessor.cpp @@ -19,7 +19,7 @@ #include "GLTextureMaskFragmentProcessor.h" #include "gpu/TextureMaskFragmentProcessor.h" -namespace pag { +namespace tgfx { void GLTextureMaskFragmentProcessor::emitCode(EmitArgs& args) { const auto* textureFP = static_cast(args.fragmentProcessor); auto* fragBuilder = args.fragBuilder; @@ -67,4 +67,4 @@ void GLTextureMaskFragmentProcessor::onSetData(const ProgramDataManager& program } } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLTextureMaskFragmentProcessor.h b/tgfx/src/gpu/opengl/GLTextureMaskFragmentProcessor.h index 6c38f8eb2c..fa44bb85ce 100644 --- a/tgfx/src/gpu/opengl/GLTextureMaskFragmentProcessor.h +++ b/tgfx/src/gpu/opengl/GLTextureMaskFragmentProcessor.h @@ -20,7 +20,7 @@ #include "gpu/GLFragmentProcessor.h" -namespace pag { +namespace tgfx { class GLTextureMaskFragmentProcessor : public GLFragmentProcessor { public: void emitCode(EmitArgs& args) override; @@ -36,4 +36,4 @@ class GLTextureMaskFragmentProcessor : public GLFragmentProcessor { int heightPrev = -1; Matrix deviceCoordMatrixPrev = Matrix::MakeScale(FLT_MAX); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLTextureSampler.cpp b/tgfx/src/gpu/opengl/GLTextureSampler.cpp index 8780b4cbc7..9c6cdec5b2 100644 --- a/tgfx/src/gpu/opengl/GLTextureSampler.cpp +++ b/tgfx/src/gpu/opengl/GLTextureSampler.cpp @@ -19,10 +19,10 @@ #include "GLTextureSampler.h" #include "GLContext.h" -namespace pag { +namespace tgfx { void GLTextureSampler::computeKey(Context* context, BytesKey* bytesKey) const { const auto* gl = GLContext::Unwrap(context); bytesKey->write(static_cast(gl->caps->configTextureSwizzle(config).asKey())); bytesKey->write(glInfo.target); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/GLTextureSampler.h b/tgfx/src/gpu/opengl/GLTextureSampler.h index 77eef84486..e592226dd6 100644 --- a/tgfx/src/gpu/opengl/GLTextureSampler.h +++ b/tgfx/src/gpu/opengl/GLTextureSampler.h @@ -20,7 +20,7 @@ #include "gpu/TextureSampler.h" -namespace pag { +namespace tgfx { class GLTextureSampler : public TextureSampler { public: GLTextureSampler() = default; @@ -33,4 +33,4 @@ class GLTextureSampler : public TextureSampler { GLTextureInfo glInfo = {}; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLUniformHandler.cpp b/tgfx/src/gpu/opengl/GLUniformHandler.cpp index 32e6feb18f..186984ff29 100644 --- a/tgfx/src/gpu/opengl/GLUniformHandler.cpp +++ b/tgfx/src/gpu/opengl/GLUniformHandler.cpp @@ -20,7 +20,7 @@ #include "GLProgramBuilder.h" #include "GLTexture.h" -namespace pag { +namespace tgfx { UniformHandle GLUniformHandler::internalAddUniform(ShaderFlags visibility, ShaderVar::Type type, const std::string& name, bool mangleName, std::string* outName) { @@ -98,4 +98,4 @@ void GLUniformHandler::resolveUniformLocations(unsigned programID) { sampler.location = gl->getUniformLocation(programID, sampler.variable.name().c_str()); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLUniformHandler.h b/tgfx/src/gpu/opengl/GLUniformHandler.h index de0c0ad1db..b096f0e083 100644 --- a/tgfx/src/gpu/opengl/GLUniformHandler.h +++ b/tgfx/src/gpu/opengl/GLUniformHandler.h @@ -21,7 +21,7 @@ #include "gpu/Swizzle.h" #include "gpu/UniformHandler.h" -namespace pag { +namespace tgfx { static constexpr int kUnusedUniform = -1; struct Uniform { @@ -59,4 +59,4 @@ class GLUniformHandler : public UniformHandler { friend class GLProgramBuilder; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLUnrolledBinaryGradientColorizer.cpp b/tgfx/src/gpu/opengl/GLUnrolledBinaryGradientColorizer.cpp index ca968ca4bd..e36f21e13a 100644 --- a/tgfx/src/gpu/opengl/GLUnrolledBinaryGradientColorizer.cpp +++ b/tgfx/src/gpu/opengl/GLUnrolledBinaryGradientColorizer.cpp @@ -19,7 +19,7 @@ #include "GLUnrolledBinaryGradientColorizer.h" #include "gpu/gradients/UnrolledBinaryGradientColorizer.h" -namespace pag { +namespace tgfx { UniformHandle AddUniform(UniformHandler* uniformHandler, const std::string& name, int intervalCount, int limit, std::string* out) { if (intervalCount > limit) { @@ -194,7 +194,7 @@ void GLUnrolledBinaryGradientColorizer::emitCode(EmitArgs& args) { } void SetUniformData(const ProgramDataManager& programDataManager, const UniformHandle& handle, - const Color4f& current, Color4f* previous) { + const Color& current, Color* previous) { if (handle.isValid() && current != *previous) { *previous = current; programDataManager.set4fv(handle, 1, current.array()); @@ -235,4 +235,4 @@ void GLUnrolledBinaryGradientColorizer::onSetData(const ProgramDataManager& prog reinterpret_cast(&(fp.thresholds9_13))); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLUnrolledBinaryGradientColorizer.h b/tgfx/src/gpu/opengl/GLUnrolledBinaryGradientColorizer.h index e7f1a304a0..bce1a9ff9d 100644 --- a/tgfx/src/gpu/opengl/GLUnrolledBinaryGradientColorizer.h +++ b/tgfx/src/gpu/opengl/GLUnrolledBinaryGradientColorizer.h @@ -20,7 +20,7 @@ #include "gpu/GLFragmentProcessor.h" -namespace pag { +namespace tgfx { /** * The 7 threshold positions that define the boundaries of the 8 intervals (excluding t = 0, and t = * 1) are packed into two vec4's instead of having up to 7 separate scalar uniforms. For low @@ -61,25 +61,25 @@ class GLUnrolledBinaryGradientColorizer : public GLFragmentProcessor { UniformHandle thresholds1_7Uniform; UniformHandle thresholds9_13Uniform; - Color4f scale0_1Prev = Color4f::Invalid(); - Color4f scale2_3Prev = Color4f::Invalid(); - Color4f scale4_5Prev = Color4f::Invalid(); - Color4f scale6_7Prev = Color4f::Invalid(); - Color4f scale8_9Prev = Color4f::Invalid(); - Color4f scale10_11Prev = Color4f::Invalid(); - Color4f scale12_13Prev = Color4f::Invalid(); - Color4f scale14_15Prev = Color4f::Invalid(); - Color4f bias0_1Prev = Color4f::Invalid(); - Color4f bias2_3Prev = Color4f::Invalid(); - Color4f bias4_5Prev = Color4f::Invalid(); - Color4f bias6_7Prev = Color4f::Invalid(); - Color4f bias8_9Prev = Color4f::Invalid(); - Color4f bias10_11Prev = Color4f::Invalid(); - Color4f bias12_13Prev = Color4f::Invalid(); - Color4f bias14_15Prev = Color4f::Invalid(); + Color scale0_1Prev = Color::Invalid(); + Color scale2_3Prev = Color::Invalid(); + Color scale4_5Prev = Color::Invalid(); + Color scale6_7Prev = Color::Invalid(); + Color scale8_9Prev = Color::Invalid(); + Color scale10_11Prev = Color::Invalid(); + Color scale12_13Prev = Color::Invalid(); + Color scale14_15Prev = Color::Invalid(); + Color bias0_1Prev = Color::Invalid(); + Color bias2_3Prev = Color::Invalid(); + Color bias4_5Prev = Color::Invalid(); + Color bias6_7Prev = Color::Invalid(); + Color bias8_9Prev = Color::Invalid(); + Color bias10_11Prev = Color::Invalid(); + Color bias12_13Prev = Color::Invalid(); + Color bias14_15Prev = Color::Invalid(); Rect thresholds1_7Prev = Rect::MakeWH(std::numeric_limits::max(), std::numeric_limits::max()); Rect thresholds9_13Prev = Rect::MakeWH(std::numeric_limits::max(), std::numeric_limits::max()); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLUtil.cpp b/tgfx/src/gpu/opengl/GLUtil.cpp index 698567e3a3..0059027586 100644 --- a/tgfx/src/gpu/opengl/GLUtil.cpp +++ b/tgfx/src/gpu/opengl/GLUtil.cpp @@ -18,7 +18,7 @@ #include "GLUtil.h" -namespace pag { +namespace tgfx { GLVersion GetGLVersion(const char* versionString) { if (versionString == nullptr) { return {}; @@ -50,7 +50,7 @@ GLVersion GetGLVersion(const char* versionString) { return {}; } -bool CreateTexture(const GLInterface* gl, int width, int height, GLTextureInfo* texture) { +bool CreateGLTexture(const GLInterface* gl, int width, int height, GLTextureInfo* texture) { texture->target = GL::TEXTURE_2D; texture->format = GL::RGBA8; gl->genTextures(1, &texture->id); @@ -94,8 +94,8 @@ static std::array GetGLSwizzleValues(const Swizzle& swizzle) { return {glValues[0], glValues[1], glValues[2], glValues[3]}; } -void ActiveTexture(const GLInterface* gl, unsigned textureUnit, unsigned target, unsigned textureID, - PixelConfig pixelConfig) { +void ActiveGLTexture(const GLInterface* gl, unsigned textureUnit, unsigned target, + unsigned textureID, PixelConfig pixelConfig) { gl->activeTexture(textureUnit); gl->bindTexture(target, textureID); gl->texParameteri(target, GL::TEXTURE_WRAP_S, GL::CLAMP_TO_EDGE); @@ -118,8 +118,9 @@ void ActiveTexture(const GLInterface* gl, unsigned textureUnit, unsigned target, } } -void SubmitTexture(const GLInterface* gl, const GLTextureInfo& glInfo, const TextureFormat& format, - int width, int height, size_t rowBytes, int bytesPerPixel, void* pixels) { +void SubmitGLTexture(const GLInterface* gl, const GLTextureInfo& glInfo, + const TextureFormat& format, int width, int height, size_t rowBytes, + int bytesPerPixel, void* pixels) { if (pixels == nullptr || rowBytes == 0) { return; } @@ -147,13 +148,13 @@ void SubmitTexture(const GLInterface* gl, const GLTextureInfo& glInfo, const Tex gl->bindTexture(glInfo.target, 0); } -unsigned CreateProgram(const GLInterface* gl, const std::string& vertex, - const std::string& fragment) { - auto vertexShader = LoadShader(gl, GL::VERTEX_SHADER, vertex); +unsigned CreateGLProgram(const GLInterface* gl, const std::string& vertex, + const std::string& fragment) { + auto vertexShader = LoadGLShader(gl, GL::VERTEX_SHADER, vertex); if (vertexShader == 0) { return 0; } - auto fragmentShader = LoadShader(gl, GL::FRAGMENT_SHADER, fragment); + auto fragmentShader = LoadGLShader(gl, GL::FRAGMENT_SHADER, fragment); if (fragmentShader == 0) { return 0; } @@ -173,7 +174,7 @@ unsigned CreateProgram(const GLInterface* gl, const std::string& vertex, return programHandle; } -unsigned LoadShader(const GLInterface* gl, unsigned shaderType, const std::string& source) { +unsigned LoadGLShader(const GLInterface* gl, unsigned shaderType, const std::string& source) { auto shader = gl->createShader(shaderType); const char* files[] = {source.c_str()}; gl->shaderSource(shader, 1, files, nullptr); @@ -249,4 +250,4 @@ std::array ToGLTextureMatrix(const Matrix& matrix, int width, int heig } return ToGLMatrix(result); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLUtil.h b/tgfx/src/gpu/opengl/GLUtil.h index 830738bf6f..b06b0c6fdf 100644 --- a/tgfx/src/gpu/opengl/GLUtil.h +++ b/tgfx/src/gpu/opengl/GLUtil.h @@ -20,13 +20,12 @@ #include #include - #include "GLInterface.h" +#include "core/ImageOrigin.h" +#include "core/Matrix.h" #include "gpu/opengl/GLContext.h" -#include "pag/gpu.h" -#include "pag/types.h" -namespace pag { +namespace tgfx { struct GLVersion { int majorVersion = -1; int minorVersion = -1; @@ -39,24 +38,25 @@ struct GLVersion { GLVersion GetGLVersion(const char* versionString); -unsigned CreateProgram(const GLInterface* gl, const std::string& vertex, - const std::string& fragment); +unsigned CreateGLProgram(const GLInterface* gl, const std::string& vertex, + const std::string& fragment); -unsigned LoadShader(const GLInterface* gl, unsigned shaderType, const std::string& source); +unsigned LoadGLShader(const GLInterface* gl, unsigned shaderType, const std::string& source); bool CheckGLError(const GLInterface* gl); -bool CreateTexture(const GLInterface* gl, int width, int height, GLTextureInfo* texture); +bool CreateGLTexture(const GLInterface* gl, int width, int height, GLTextureInfo* texture); -void ActiveTexture(const GLInterface* gl, unsigned textureUnit, unsigned target, unsigned textureID, - PixelConfig pixelConfig = PixelConfig::RGBA_8888); +void ActiveGLTexture(const GLInterface* gl, unsigned textureUnit, unsigned target, + unsigned textureID, PixelConfig pixelConfig = PixelConfig::RGBA_8888); -void SubmitTexture(const GLInterface* gl, const GLTextureInfo& glInfo, const TextureFormat& format, - int width, int height, size_t rowBytes, int bytesPerPixel, void* pixels); +void SubmitGLTexture(const GLInterface* gl, const GLTextureInfo& glInfo, + const TextureFormat& format, int width, int height, size_t rowBytes, + int bytesPerPixel, void* pixels); std::array ToGLMatrix(const Matrix& matrix); std::array ToGLVertexMatrix(const Matrix& matrix, int width, int height, ImageOrigin origin); std::array ToGLTextureMatrix(const Matrix& matrix, int width, int height, ImageOrigin origin); -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLVertexShaderBuilder.cpp b/tgfx/src/gpu/opengl/GLVertexShaderBuilder.cpp index aec7bbad54..8695fbf7f2 100644 --- a/tgfx/src/gpu/opengl/GLVertexShaderBuilder.cpp +++ b/tgfx/src/gpu/opengl/GLVertexShaderBuilder.cpp @@ -18,7 +18,7 @@ #include "GLVertexShaderBuilder.h" -namespace pag { +namespace tgfx { GLVertexShaderBuilder::GLVertexShaderBuilder(ProgramBuilder* program) : VertexShaderBuilder(program) { setPrecisionQualifier("precision mediump float;"); @@ -27,4 +27,4 @@ GLVertexShaderBuilder::GLVertexShaderBuilder(ProgramBuilder* program) void GLVertexShaderBuilder::emitNormalizedPosition(const std::string& devPos) { codeAppendf("gl_Position = vec4(%s, 0, 1);", devPos.c_str()); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLVertexShaderBuilder.h b/tgfx/src/gpu/opengl/GLVertexShaderBuilder.h index c14913de35..698d10dbb2 100644 --- a/tgfx/src/gpu/opengl/GLVertexShaderBuilder.h +++ b/tgfx/src/gpu/opengl/GLVertexShaderBuilder.h @@ -20,11 +20,11 @@ #include "gpu/VertexShaderBuilder.h" -namespace pag { +namespace tgfx { class GLVertexShaderBuilder : public VertexShaderBuilder { public: explicit GLVertexShaderBuilder(ProgramBuilder* program); void emitNormalizedPosition(const std::string& devPos) override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLYUVTexture.cpp b/tgfx/src/gpu/opengl/GLYUVTexture.cpp index 15689ca0ee..ba85148d0a 100644 --- a/tgfx/src/gpu/opengl/GLYUVTexture.cpp +++ b/tgfx/src/gpu/opengl/GLYUVTexture.cpp @@ -18,9 +18,9 @@ #include "GLYUVTexture.h" #include "GLUtil.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" -namespace pag { +namespace tgfx { #define I420_PLANE_COUNT 3 #define NV12_PLANE_COUNT 2 #define I420_PIXEL_BYTES 1.5 @@ -127,7 +127,7 @@ static void SubmitYUVTexture(const GLInterface* gl, const YUVConfig& yuvConfig, auto rowBytes = yuvConfig.rowBytes[index]; auto bytesPerPixel = yuvConfig.bytesPerPixel[index]; auto pixels = yuvConfig.pixelsPlane[index]; - SubmitTexture(gl, glInfo, format, w, h, rowBytes, bytesPerPixel, pixels); + SubmitGLTexture(gl, glInfo, format, w, h, rowBytes, bytesPerPixel, pixels); } } @@ -224,4 +224,4 @@ void GLYUVTexture::onRelease(Context* context) { gl->deleteTextures(1, &sampler.glInfo.id); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLYUVTexture.h b/tgfx/src/gpu/opengl/GLYUVTexture.h index 735e37cc9c..5d6d2d1d75 100644 --- a/tgfx/src/gpu/opengl/GLYUVTexture.h +++ b/tgfx/src/gpu/opengl/GLYUVTexture.h @@ -22,7 +22,7 @@ #include "GLTextureSampler.h" #include "gpu/YUVTexture.h" -namespace pag { +namespace tgfx { struct YUVConfig; class GLYUVTexture : public YUVTexture { public: @@ -47,4 +47,4 @@ class GLYUVTexture : public YUVTexture { friend class YUVTexture; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLYUVTextureFragmentProcessor.cpp b/tgfx/src/gpu/opengl/GLYUVTextureFragmentProcessor.cpp index cf344b6f8e..aa4471250c 100644 --- a/tgfx/src/gpu/opengl/GLYUVTextureFragmentProcessor.cpp +++ b/tgfx/src/gpu/opengl/GLYUVTextureFragmentProcessor.cpp @@ -19,7 +19,7 @@ #include "GLYUVTextureFragmentProcessor.h" #include "gpu/YUVTextureFragmentProcessor.h" -namespace pag { +namespace tgfx { void GLYUVTextureFragmentProcessor::emitCode(EmitArgs& args) { const auto* yuvFP = static_cast(args.fragmentProcessor); auto* fragBuilder = args.fragBuilder; @@ -144,4 +144,4 @@ void GLYUVTextureFragmentProcessor::onSetData(const ProgramDataManager& programD } } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/GLYUVTextureFragmentProcessor.h b/tgfx/src/gpu/opengl/GLYUVTextureFragmentProcessor.h index e80aa4fefb..3ef96e9fee 100644 --- a/tgfx/src/gpu/opengl/GLYUVTextureFragmentProcessor.h +++ b/tgfx/src/gpu/opengl/GLYUVTextureFragmentProcessor.h @@ -21,7 +21,7 @@ #include "gpu/GLFragmentProcessor.h" #include "gpu/YUVTexture.h" -namespace pag { +namespace tgfx { class GLYUVTextureFragmentProcessor : public GLFragmentProcessor { public: void emitCode(EmitArgs& args) override; @@ -37,4 +37,4 @@ class GLYUVTextureFragmentProcessor : public GLFragmentProcessor { YUVColorSpace colorSpacePrev = YUVColorSpace::Unknown; YUVColorRange colorRangePrev = YUVColorRange::Unknown; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/cgl/CGLDevice.mm b/tgfx/src/gpu/opengl/cgl/CGLDevice.mm index e670a71b82..b90b859d9e 100644 --- a/tgfx/src/gpu/opengl/cgl/CGLDevice.mm +++ b/tgfx/src/gpu/opengl/cgl/CGLDevice.mm @@ -20,7 +20,7 @@ #include "CGLProcGetter.h" #include "gpu/opengl/GLContext.h" -namespace pag { +namespace tgfx { void* GLDevice::CurrentNativeHandle() { return CGLGetCurrentContext(); } @@ -139,4 +139,4 @@ CGLSetCurrentContext(oldContext); CGLReleaseContext(oldContext); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/cgl/CGLHardwareBuffer.mm b/tgfx/src/gpu/opengl/cgl/CGLHardwareBuffer.mm index 3747314260..5d8f4fc5ba 100644 --- a/tgfx/src/gpu/opengl/cgl/CGLHardwareBuffer.mm +++ b/tgfx/src/gpu/opengl/cgl/CGLHardwareBuffer.mm @@ -20,7 +20,7 @@ #include "gpu/YUVTexture.h" #include "platform/apple/HardwareBuffer.h" -namespace pag { +namespace tgfx { std::shared_ptr PixelBuffer::MakeFrom(void* hardwareBuffer) { auto pixelBuffer = reinterpret_cast(hardwareBuffer); if (pixelBuffer == nullptr) { @@ -45,4 +45,4 @@ std::shared_ptr YUVTexture::MakeFrom(Context*, YUVColorSpace, YUVColorRange, void*) { return nullptr; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.h b/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.h index 641c57d10b..0fa33545d5 100644 --- a/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.h +++ b/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.h @@ -21,7 +21,7 @@ #import #include "gpu/opengl/GLTexture.h" -namespace pag { +namespace tgfx { class CGLHardwareTexture : public GLTexture { public: static std::shared_ptr MakeFrom(Context* context, @@ -43,4 +43,4 @@ class CGLHardwareTexture : public GLTexture { static void ComputeRecycleKey(BytesKey* recycleKey, CVPixelBufferRef pixelBuffer); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.mm b/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.mm index 2d346d2c7a..c9d57f88ff 100644 --- a/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.mm +++ b/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.mm @@ -18,9 +18,9 @@ #include "CGLHardwareTexture.h" #include "gpu/opengl/cgl/CGLDevice.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" -namespace pag { +namespace tgfx { std::shared_ptr CGLHardwareTexture::MakeFrom(Context* context, CVPixelBufferRef pixelBuffer) { BytesKey recycleKey = {}; diff --git a/tgfx/src/gpu/opengl/cgl/CGLProcGetter.h b/tgfx/src/gpu/opengl/cgl/CGLProcGetter.h index 238d1e83c1..ddede07469 100644 --- a/tgfx/src/gpu/opengl/cgl/CGLProcGetter.h +++ b/tgfx/src/gpu/opengl/cgl/CGLProcGetter.h @@ -20,7 +20,7 @@ #include "gpu/opengl/GLProcGetter.h" -namespace pag { +namespace tgfx { class CGLProcGetter : public GLProcGetter { public: CGLProcGetter(); @@ -32,4 +32,4 @@ class CGLProcGetter : public GLProcGetter { private: void* fLibrary; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/cgl/CGLProcGetter.mm b/tgfx/src/gpu/opengl/cgl/CGLProcGetter.mm index 1016239941..101be8bbf4 100644 --- a/tgfx/src/gpu/opengl/cgl/CGLProcGetter.mm +++ b/tgfx/src/gpu/opengl/cgl/CGLProcGetter.mm @@ -19,7 +19,7 @@ #include "CGLProcGetter.h" #include -namespace pag { +namespace tgfx { CGLProcGetter::CGLProcGetter() { fLibrary = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib", RTLD_LAZY); @@ -39,4 +39,4 @@ std::unique_ptr GLProcGetter::Make() { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/cgl/CGLWindow.mm b/tgfx/src/gpu/opengl/cgl/CGLWindow.mm index bcfb41ae6c..0e2378b133 100644 --- a/tgfx/src/gpu/opengl/cgl/CGLWindow.mm +++ b/tgfx/src/gpu/opengl/cgl/CGLWindow.mm @@ -21,7 +21,7 @@ #include "CGLHardwareTexture.h" #include "gpu/opengl/GLSurface.h" -namespace pag { +namespace tgfx { static std::mutex threadCacheLocker = {}; static std::unordered_map> threadCacheMap = {}; @@ -125,4 +125,4 @@ gl->flush(); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/eagl/EAGLDevice.mm b/tgfx/src/gpu/opengl/eagl/EAGLDevice.mm index b0e12bf70d..ab72fb67f4 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLDevice.mm +++ b/tgfx/src/gpu/opengl/eagl/EAGLDevice.mm @@ -21,7 +21,7 @@ #import #include "EAGLProcGetter.h" -namespace pag { +namespace tgfx { static std::mutex deviceLocker = {}; static std::vector deviceList = {}; static std::vector delayPurgeList = {}; @@ -224,18 +224,18 @@ void ApplicationDidBecomeActive() { clearCurrent(); } } -} // namespace pag +} // namespace tgfx @interface AppMonitor : NSObject @end @implementation AppMonitor + (void)applicationWillResignActive:(NSNotification*)notification { - pag::ApplicationWillResignActive(); + tgfx::ApplicationWillResignActive(); } + (void)applicationDidBecomeActive:(NSNotification*)notification { - pag::ApplicationDidBecomeActive(); + tgfx::ApplicationDidBecomeActive(); } @end diff --git a/tgfx/src/gpu/opengl/eagl/EAGLHardwareBuffer.mm b/tgfx/src/gpu/opengl/eagl/EAGLHardwareBuffer.mm index a9690be879..fd62c08311 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLHardwareBuffer.mm +++ b/tgfx/src/gpu/opengl/eagl/EAGLHardwareBuffer.mm @@ -20,7 +20,7 @@ #include "EAGLNV12Texture.h" #include "platform/apple/HardwareBuffer.h" -namespace pag { +namespace tgfx { std::shared_ptr PixelBuffer::MakeFrom(void* hardwareBuffer) { auto pixelBuffer = reinterpret_cast(hardwareBuffer); if (pixelBuffer == nullptr) { @@ -50,4 +50,4 @@ } return EAGLNV12Texture::MakeFrom(context, pixelBuffer, colorSpace, colorRange); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.h b/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.h index 4a96861afc..d71e7a1046 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.h +++ b/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.h @@ -21,7 +21,7 @@ #import #include "gpu/opengl/GLTexture.h" -namespace pag { +namespace tgfx { class EAGLHardwareTexture : public GLTexture { public: static std::shared_ptr MakeFrom(Context* context, @@ -42,4 +42,4 @@ class EAGLHardwareTexture : public GLTexture { static void ComputeRecycleKey(BytesKey* recycleKey, CVPixelBufferRef pixelBuffer); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.mm b/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.mm index 89b9556ae6..b5fea6d984 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.mm +++ b/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.mm @@ -18,9 +18,9 @@ #include "EAGLHardwareTexture.h" #include "gpu/opengl/eagl/EAGLDevice.h" -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" -namespace pag { +namespace tgfx { static CVOpenGLESTextureRef GetTextureRef(Context* context, CVPixelBufferRef pixelBuffer, CVOpenGLESTextureCacheRef textureCache, unsigned* sizedFormat) { diff --git a/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.h b/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.h index 5309ce60e5..b723b66cdd 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.h +++ b/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.h @@ -21,7 +21,7 @@ #import #include "gpu/opengl/GLYUVTexture.h" -namespace pag { +namespace tgfx { class EAGLNV12Texture : public GLYUVTexture { public: static std::shared_ptr MakeFrom(Context* context, CVPixelBufferRef pixelBuffer, @@ -46,4 +46,4 @@ class EAGLNV12Texture : public GLYUVTexture { CVOpenGLESTextureRef lumaTexture = nullptr; CVOpenGLESTextureRef chromaTexture = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.mm b/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.mm index 080ea50c27..2d3332ed4e 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.mm +++ b/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.mm @@ -19,7 +19,7 @@ #include "EAGLNV12Texture.h" #include "gpu/opengl/eagl/EAGLDevice.h" -namespace pag { +namespace tgfx { static GLTextureInfo ToGLTexture(CVOpenGLESTextureRef texture, unsigned format) { GLTextureInfo glInfo = {}; glInfo.target = CVOpenGLESTextureGetTarget(texture); diff --git a/tgfx/src/gpu/opengl/eagl/EAGLProcGetter.h b/tgfx/src/gpu/opengl/eagl/EAGLProcGetter.h index 342daa4987..e5aca1de08 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLProcGetter.h +++ b/tgfx/src/gpu/opengl/eagl/EAGLProcGetter.h @@ -20,7 +20,7 @@ #include "gpu/opengl/GLProcGetter.h" -namespace pag { +namespace tgfx { class EAGLProcGetter : public GLProcGetter { public: EAGLProcGetter(); @@ -32,4 +32,4 @@ class EAGLProcGetter : public GLProcGetter { private: void* fLibrary; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/eagl/EAGLProcGetter.mm b/tgfx/src/gpu/opengl/eagl/EAGLProcGetter.mm index 9a026e336b..a8a28e2df4 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLProcGetter.mm +++ b/tgfx/src/gpu/opengl/eagl/EAGLProcGetter.mm @@ -19,7 +19,7 @@ #include "EAGLProcGetter.h" #include -namespace pag { +namespace tgfx { EAGLProcGetter::EAGLProcGetter() { fLibrary = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib", RTLD_LAZY); @@ -39,4 +39,4 @@ std::unique_ptr GLProcGetter::Make() { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/eagl/EAGLWindow.mm b/tgfx/src/gpu/opengl/eagl/EAGLWindow.mm index 0994b786fe..7e7cf64421 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLWindow.mm +++ b/tgfx/src/gpu/opengl/eagl/EAGLWindow.mm @@ -22,7 +22,7 @@ #include "gpu/opengl/GLContext.h" #include "gpu/opengl/GLSurface.h" -namespace pag { +namespace tgfx { static std::mutex threadCacheLocker = {}; static std::unordered_map> threadCacheMap = {}; @@ -155,4 +155,4 @@ gl->flush(); } } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/egl/EGLDevice.cpp b/tgfx/src/gpu/opengl/egl/EGLDevice.cpp index c2439402d0..d6962f1504 100644 --- a/tgfx/src/gpu/opengl/egl/EGLDevice.cpp +++ b/tgfx/src/gpu/opengl/egl/EGLDevice.cpp @@ -17,11 +17,11 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "gpu/opengl/egl/EGLDevice.h" -#include "base/utils/Log.h" +#include "core/utils/Log.h" #include "gpu/opengl/egl/EGLGlobals.h" #include "gpu/opengl/egl/EGLProcGetter.h" -namespace pag { +namespace tgfx { static EGLContext CreateContext(EGLContext sharedContext, EGLConfig eglConfig) { static auto eglGlobals = EGLGlobals::Get(); static const EGLint context3Attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE}; @@ -199,4 +199,4 @@ void EGLDevice::swapBuffers(int64_t timestamp) { } eglSwapBuffers(eglDisplay, eglSurface); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/egl/EGLGlobals.cpp b/tgfx/src/gpu/opengl/egl/EGLGlobals.cpp index 9d511b07fc..b82a5d4374 100644 --- a/tgfx/src/gpu/opengl/egl/EGLGlobals.cpp +++ b/tgfx/src/gpu/opengl/egl/EGLGlobals.cpp @@ -19,7 +19,7 @@ #include "EGLGlobals.h" #include -namespace pag { +namespace tgfx { EGLGlobals InitializeEGL() { EGLGlobals globals = {}; globals.display = eglGetDisplay(EGL_DEFAULT_DISPLAY); @@ -68,4 +68,4 @@ const EGLGlobals* EGLGlobals::Get() { static const EGLGlobals globals = InitializeEGL(); return &globals; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/egl/EGLGlobals.h b/tgfx/src/gpu/opengl/egl/EGLGlobals.h index 17142743a4..cd32bf5007 100644 --- a/tgfx/src/gpu/opengl/egl/EGLGlobals.h +++ b/tgfx/src/gpu/opengl/egl/EGLGlobals.h @@ -21,7 +21,7 @@ #include #include -namespace pag { +namespace tgfx { class EGLGlobals { public: static const EGLGlobals* Get(); @@ -30,4 +30,4 @@ class EGLGlobals { EGLConfig windowConfig = nullptr; EGLConfig pbufferConfig = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/egl/EGLHardwareBuffer.cpp b/tgfx/src/gpu/opengl/egl/EGLHardwareBuffer.cpp index 4bbedff9ae..49fedcf1e4 100644 --- a/tgfx/src/gpu/opengl/egl/EGLHardwareBuffer.cpp +++ b/tgfx/src/gpu/opengl/egl/EGLHardwareBuffer.cpp @@ -24,7 +24,7 @@ #include "platform/android/HardwareBuffer.h" #endif -namespace pag { +namespace tgfx { #if defined(__ANDROID__) || defined(ANDROID) std::shared_ptr PixelBuffer::MakeFrom(void* hardwareBuffer) { @@ -67,4 +67,4 @@ std::shared_ptr Texture::MakeFrom(Context*, void*) { std::shared_ptr YUVTexture::MakeFrom(Context*, YUVColorSpace, YUVColorRange, void*) { return nullptr; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.cpp b/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.cpp index 6b3f81d205..1fb5944266 100644 --- a/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.cpp +++ b/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.cpp @@ -22,12 +22,12 @@ #include #include #include -#include "base/utils/UniqueID.h" +#include "core/utils/UniqueID.h" #include "gpu/opengl/egl/EGLDevice.h" #include "platform/android/HardwareBuffer.h" #include "platform/android/HardwareBufferInterface.h" -namespace pag { +namespace tgfx { namespace eglext { static PFNEGLGETNATIVECLIENTBUFFERANDROIDPROC eglGetNativeClientBufferANDROID = nullptr; static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = nullptr; @@ -115,6 +115,6 @@ void EGLHardwareTexture::onRelease(Context* context) { auto display = static_cast(context->device())->getDisplay(); eglext::eglDestroyImageKHR(display, eglImage); } -} // namespace pag +} // namespace tgfx #endif \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.h b/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.h index 3c998a0b51..1d4d7ef372 100644 --- a/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.h +++ b/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.h @@ -25,7 +25,7 @@ #include "gpu/opengl/GLTexture.h" #include "platform/android/HardwareBufferInterface.h" -namespace pag { +namespace tgfx { class EGLHardwareTexture : public GLTexture { public: static std::shared_ptr MakeFrom(Context* context, @@ -47,6 +47,6 @@ class EGLHardwareTexture : public GLTexture { void onRelease(Context* context) override; }; -} // namespace pag +} // namespace tgfx #endif \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/egl/EGLProcGetter.cpp b/tgfx/src/gpu/opengl/egl/EGLProcGetter.cpp index fc08081f94..d76a8c0073 100644 --- a/tgfx/src/gpu/opengl/egl/EGLProcGetter.cpp +++ b/tgfx/src/gpu/opengl/egl/EGLProcGetter.cpp @@ -21,7 +21,7 @@ #include #include -namespace pag { +namespace tgfx { static void* egl_get_gl_proc(void*, const char name[]) { // https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_get_all_proc_addresses.txt @@ -149,4 +149,4 @@ void* EGLProcGetter::getProcAddress(const char* name) const { std::unique_ptr GLProcGetter::Make() { return std::make_unique(); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/egl/EGLProcGetter.h b/tgfx/src/gpu/opengl/egl/EGLProcGetter.h index 6a1836f78d..d43a2f75d8 100644 --- a/tgfx/src/gpu/opengl/egl/EGLProcGetter.h +++ b/tgfx/src/gpu/opengl/egl/EGLProcGetter.h @@ -20,9 +20,9 @@ #include "gpu/opengl/GLProcGetter.h" -namespace pag { +namespace tgfx { class EGLProcGetter : public GLProcGetter { public: void* getProcAddress(const char name[]) const override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/egl/EGLWindow.cpp b/tgfx/src/gpu/opengl/egl/EGLWindow.cpp index 00375d1750..24ef68cb9d 100644 --- a/tgfx/src/gpu/opengl/egl/EGLWindow.cpp +++ b/tgfx/src/gpu/opengl/egl/EGLWindow.cpp @@ -20,7 +20,7 @@ #include #include -namespace pag { +namespace tgfx { std::shared_ptr EGLWindow::Current() { auto device = EGLDevice::Current(); if (device == nullptr) { @@ -63,4 +63,4 @@ std::shared_ptr EGLWindow::onCreateSurface(Context* context) { void EGLWindow::onPresent(Context*, int64_t presentationTime) { std::static_pointer_cast(device)->swapBuffers(presentationTime); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/qt/QGLDevice.cpp b/tgfx/src/gpu/opengl/qt/QGLDevice.cpp index 9d59960fdd..4906ccb030 100644 --- a/tgfx/src/gpu/opengl/qt/QGLDevice.cpp +++ b/tgfx/src/gpu/opengl/qt/QGLDevice.cpp @@ -20,9 +20,9 @@ #include #include #include "QGLProcGetter.h" -#include "base/utils/Log.h" +#include "core/utils/Log.h" -namespace pag { +namespace tgfx { void* GLDevice::CurrentNativeHandle() { return QOpenGLContext::currentContext(); } @@ -152,4 +152,4 @@ void QGLDevice::onClearCurrent() { oldSurface = nullptr; } } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/qt/QGLHardwareBuffer.cpp b/tgfx/src/gpu/opengl/qt/QGLHardwareBuffer.cpp index 1abedcf988..79f23a6ce0 100644 --- a/tgfx/src/gpu/opengl/qt/QGLHardwareBuffer.cpp +++ b/tgfx/src/gpu/opengl/qt/QGLHardwareBuffer.cpp @@ -19,7 +19,7 @@ #include "core/PixelBuffer.h" #include "gpu/YUVTexture.h" -namespace pag { +namespace tgfx { std::shared_ptr PixelBuffer::MakeHardwareBuffer(int, int, bool) { return nullptr; } @@ -35,4 +35,4 @@ std::shared_ptr Texture::MakeFrom(Context*, void*) { std::shared_ptr YUVTexture::MakeFrom(Context*, YUVColorSpace, YUVColorRange, void*) { return nullptr; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/qt/QGLProcGetter.cpp b/tgfx/src/gpu/opengl/qt/QGLProcGetter.cpp index 0e0727e69c..9adde1fd46 100644 --- a/tgfx/src/gpu/opengl/qt/QGLProcGetter.cpp +++ b/tgfx/src/gpu/opengl/qt/QGLProcGetter.cpp @@ -18,7 +18,7 @@ #include "QGLProcGetter.h" -namespace pag { +namespace tgfx { void* QGLProcGetter::getProcAddress(const char* name) const { return reinterpret_cast(glContext->getProcAddress(name)); } @@ -30,4 +30,4 @@ std::unique_ptr GLProcGetter::Make() { } return std::make_unique(context); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/qt/QGLProcGetter.h b/tgfx/src/gpu/opengl/qt/QGLProcGetter.h index 0b43809071..c4c997a87a 100644 --- a/tgfx/src/gpu/opengl/qt/QGLProcGetter.h +++ b/tgfx/src/gpu/opengl/qt/QGLProcGetter.h @@ -21,7 +21,7 @@ #include #include "gpu/opengl/GLProcGetter.h" -namespace pag { +namespace tgfx { class QGLProcGetter : public GLProcGetter { public: explicit QGLProcGetter(QOpenGLContext* glContext) : glContext(glContext) { @@ -32,4 +32,4 @@ class QGLProcGetter : public GLProcGetter { private: QOpenGLContext* glContext = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/qt/QGLWindow.cpp b/tgfx/src/gpu/opengl/qt/QGLWindow.cpp index ae4e184648..1a671f061d 100644 --- a/tgfx/src/gpu/opengl/qt/QGLWindow.cpp +++ b/tgfx/src/gpu/opengl/qt/QGLWindow.cpp @@ -26,7 +26,7 @@ #include "gpu/opengl/GLSurface.h" #include "gpu/opengl/GLTexture.h" -namespace pag { +namespace tgfx { std::shared_ptr QGLWindow::MakeFrom(QQuickItem* quickItem, QOpenGLContext* sharedContext) { @@ -116,4 +116,4 @@ void QGLWindow::onPresent(Context* context, int64_t) { gl->bindFramebuffer(GL_FRAMEBUFFER, 0); invalidateTexture(); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/webgl/WebGLDevice.cpp b/tgfx/src/gpu/opengl/webgl/WebGLDevice.cpp index 5fab5fcba3..8848159541 100644 --- a/tgfx/src/gpu/opengl/webgl/WebGLDevice.cpp +++ b/tgfx/src/gpu/opengl/webgl/WebGLDevice.cpp @@ -18,9 +18,9 @@ #include "gpu/opengl/webgl/WebGLDevice.h" #include "WebGLProcGetter.h" -#include "base/utils/Log.h" +#include "core/utils/Log.h" -namespace pag { +namespace tgfx { void* GLDevice::CurrentNativeHandle() { return reinterpret_cast(emscripten_webgl_get_current_context()); @@ -132,4 +132,4 @@ void WebGLDevice::onClearCurrent() { bool WebGLDevice::sharableWith(void*) const { return false; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/webgl/WebGLHardwareBuffer.cpp b/tgfx/src/gpu/opengl/webgl/WebGLHardwareBuffer.cpp index 1abedcf988..79f23a6ce0 100644 --- a/tgfx/src/gpu/opengl/webgl/WebGLHardwareBuffer.cpp +++ b/tgfx/src/gpu/opengl/webgl/WebGLHardwareBuffer.cpp @@ -19,7 +19,7 @@ #include "core/PixelBuffer.h" #include "gpu/YUVTexture.h" -namespace pag { +namespace tgfx { std::shared_ptr PixelBuffer::MakeHardwareBuffer(int, int, bool) { return nullptr; } @@ -35,4 +35,4 @@ std::shared_ptr Texture::MakeFrom(Context*, void*) { std::shared_ptr YUVTexture::MakeFrom(Context*, YUVColorSpace, YUVColorRange, void*) { return nullptr; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/gpu/opengl/webgl/WebGLProcGetter.cpp b/tgfx/src/gpu/opengl/webgl/WebGLProcGetter.cpp index f0508c6112..a508f01ad6 100644 --- a/tgfx/src/gpu/opengl/webgl/WebGLProcGetter.cpp +++ b/tgfx/src/gpu/opengl/webgl/WebGLProcGetter.cpp @@ -21,7 +21,7 @@ #include #include -namespace pag { +namespace tgfx { static void emscripten_glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) { uint32_t timeoutLo = timeout; uint32_t timeoutHi = timeout >> 32; @@ -153,4 +153,4 @@ void* WebGLProcGetter::getProcAddress(const char* name) const { std::unique_ptr GLProcGetter::Make() { return std::make_unique(); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/webgl/WebGLProcGetter.h b/tgfx/src/gpu/opengl/webgl/WebGLProcGetter.h index d5857bcbe8..bf21ce7042 100644 --- a/tgfx/src/gpu/opengl/webgl/WebGLProcGetter.h +++ b/tgfx/src/gpu/opengl/webgl/WebGLProcGetter.h @@ -20,9 +20,9 @@ #include "gpu/opengl/GLProcGetter.h" -namespace pag { +namespace tgfx { class WebGLProcGetter : public GLProcGetter { public: void* getProcAddress(const char name[]) const override; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/gpu/opengl/webgl/WebGLWindow.cpp b/tgfx/src/gpu/opengl/webgl/WebGLWindow.cpp index a1537ff498..3b541fbca9 100644 --- a/tgfx/src/gpu/opengl/webgl/WebGLWindow.cpp +++ b/tgfx/src/gpu/opengl/webgl/WebGLWindow.cpp @@ -17,10 +17,10 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "gpu/opengl/webgl/WebGLWindow.h" -#include "base/utils/Log.h" +#include "core/utils/Log.h" #include "gpu/opengl/GLDefines.h" -namespace pag { +namespace tgfx { std::shared_ptr WebGLWindow::MakeFrom(const std::string& canvasID) { if (canvasID.empty()) { return nullptr; @@ -51,4 +51,4 @@ std::shared_ptr WebGLWindow::onCreateSurface(Context* context) { BackendRenderTarget renderTarget(glInfo, width, height); return Surface::MakeFrom(context, renderTarget, ImageOrigin::BottomLeft); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/NativeCodec.h b/tgfx/src/platform/NativeCodec.h index aedefba8ba..ec1a81d1cd 100644 --- a/tgfx/src/platform/NativeCodec.h +++ b/tgfx/src/platform/NativeCodec.h @@ -20,7 +20,7 @@ #include "core/Image.h" -namespace pag { +namespace tgfx { class NativeCodec { public: /** @@ -35,4 +35,4 @@ class NativeCodec { */ static std::shared_ptr MakeImage(std::shared_ptr imageBytes); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/Print.cpp b/tgfx/src/platform/Print.cpp index 9c88b1a868..e7469a0e3a 100644 --- a/tgfx/src/platform/Print.cpp +++ b/tgfx/src/platform/Print.cpp @@ -22,7 +22,7 @@ #include #include -namespace pag { +namespace tgfx { void PrintLog(const char format[], ...) { va_list args; va_start(args, format); @@ -38,6 +38,6 @@ void PrintError(const char format[], ...) { va_end(args); fprintf(stderr, "\n"); } -} // namespace pag +} // namespace tgfx #endif \ No newline at end of file diff --git a/tgfx/src/platform/android/HardwareBuffer.cpp b/tgfx/src/platform/android/HardwareBuffer.cpp index c3cf6e3820..194e7c86ca 100644 --- a/tgfx/src/platform/android/HardwareBuffer.cpp +++ b/tgfx/src/platform/android/HardwareBuffer.cpp @@ -19,7 +19,7 @@ #include "HardwareBuffer.h" #include "HardwareBufferInterface.h" -namespace pag { +namespace tgfx { std::shared_ptr HardwareBuffer::MakeFrom(AHardwareBuffer* hardwareBuffer) { if (!hardwareBuffer || !HardwareBufferInterface::Available()) { @@ -83,4 +83,4 @@ void HardwareBuffer::unlockPixels() { HardwareBuffer::~HardwareBuffer() { HardwareBufferInterface::Release(hardwareBuffer); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/android/HardwareBuffer.h b/tgfx/src/platform/android/HardwareBuffer.h index f05e894d02..74b4b9d55c 100644 --- a/tgfx/src/platform/android/HardwareBuffer.h +++ b/tgfx/src/platform/android/HardwareBuffer.h @@ -22,7 +22,7 @@ #include "HardwareBufferInterface.h" #include "core/PixelBuffer.h" -namespace pag { +namespace tgfx { class HardwareBuffer : public PixelBuffer { public: static std::shared_ptr Make(int width, int height, bool alphaOnly); @@ -42,4 +42,4 @@ class HardwareBuffer : public PixelBuffer { private: AHardwareBuffer* hardwareBuffer = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/android/HardwareBufferInterface.cpp b/tgfx/src/platform/android/HardwareBufferInterface.cpp index 2d03eedab2..9c378c382f 100644 --- a/tgfx/src/platform/android/HardwareBufferInterface.cpp +++ b/tgfx/src/platform/android/HardwareBufferInterface.cpp @@ -21,7 +21,7 @@ #include #include -namespace pag { +namespace tgfx { template static void LoadSymbol(T*& function, const char* symbol) { function = (T*)dlsym(RTLD_DEFAULT, symbol); @@ -88,4 +88,4 @@ int HardwareBufferInterface::Lock(AHardwareBuffer* buffer, uint64_t usage, int32 int HardwareBufferInterface::Unlock(AHardwareBuffer* buffer, int32_t* fence) { return GetFunctions()->unlock(buffer, fence); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/platform/android/HardwareBufferInterface.h b/tgfx/src/platform/android/HardwareBufferInterface.h index e43a80293e..a7cca9bba4 100644 --- a/tgfx/src/platform/android/HardwareBufferInterface.h +++ b/tgfx/src/platform/android/HardwareBufferInterface.h @@ -20,7 +20,7 @@ #include -namespace pag { +namespace tgfx { /** * This utility class allows us to use AHardwareBuffer interfaces without compiling for API 26 * (Oreo) and above. @@ -95,4 +95,4 @@ class HardwareBufferInterface { */ static int Unlock(AHardwareBuffer* buffer, int32_t* fence); }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/android/JNIInit.cpp b/tgfx/src/platform/android/JNIInit.cpp index feb60176e5..1c13f6c23c 100644 --- a/tgfx/src/platform/android/JNIInit.cpp +++ b/tgfx/src/platform/android/JNIInit.cpp @@ -19,8 +19,8 @@ #include "JNIInit.h" #include "NativeImage.h" -namespace pag { +namespace tgfx { void JNIInit(JNIEnv* env) { NativeImage::JNIInit(env); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/android/JNIInit.h b/tgfx/src/platform/android/JNIInit.h index 78108b1ce1..81262de33a 100644 --- a/tgfx/src/platform/android/JNIInit.h +++ b/tgfx/src/platform/android/JNIInit.h @@ -20,8 +20,8 @@ #include -namespace pag { +namespace tgfx { void JNIInit(JNIEnv* env); -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/android/JNIUtil.cpp b/tgfx/src/platform/android/JNIUtil.cpp index 3f28431af1..f2ddd60769 100644 --- a/tgfx/src/platform/android/JNIUtil.cpp +++ b/tgfx/src/platform/android/JNIUtil.cpp @@ -20,10 +20,10 @@ #include #include #include "JNIInit.h" -#include "base/utils/Log.h" +#include "core/utils/Log.h" #include "platform/android/SetJavaVM.h" -namespace pag { +namespace tgfx { static std::mutex globalLocker = {}; static JavaVM* globalJavaVM = nullptr; static pthread_key_t envKey = 0; @@ -91,4 +91,4 @@ jstring SafeToJString(JNIEnv* env, const std::string& text) { return (jstring)env->NewObject(StringClass.get(), StringConstructID, array.get(), stringUTF.get()); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/android/JNIUtil.h b/tgfx/src/platform/android/JNIUtil.h index 981542b8f1..d2f4c8fd11 100644 --- a/tgfx/src/platform/android/JNIUtil.h +++ b/tgfx/src/platform/android/JNIUtil.h @@ -21,7 +21,7 @@ #include #include -namespace pag { +namespace tgfx { /** * Attach permanently a JNI environment to the current thread and retrieve it. If successfully * attached, the JNI environment will automatically be detached at thread destruction. @@ -126,4 +126,4 @@ class Local { T _ref = nullptr; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/android/NativeImage.cpp b/tgfx/src/platform/android/NativeImage.cpp index 02edaefdb1..339c3cc8f5 100644 --- a/tgfx/src/platform/android/NativeImage.cpp +++ b/tgfx/src/platform/android/NativeImage.cpp @@ -21,7 +21,7 @@ #include "core/Bitmap.h" #include "platform/NativeCodec.h" -namespace pag { +namespace tgfx { static constexpr int BITMAP_FLAGS_ALPHA_UNPREMUL = 2; static Global BitmapFactoryOptionsClass; @@ -247,4 +247,4 @@ bool NativeImage::readPixels(const ImageInfo& dstInfo, void* dstPixels) const { AndroidBitmap_unlockPixels(env, bitmap.get()); return result; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/android/NativeImage.h b/tgfx/src/platform/android/NativeImage.h index 25aac503ea..7f50328273 100644 --- a/tgfx/src/platform/android/NativeImage.h +++ b/tgfx/src/platform/android/NativeImage.h @@ -21,7 +21,7 @@ #include "JNIUtil.h" #include "core/Image.h" -namespace pag { +namespace tgfx { class NativeImage : public Image { public: static void JNIInit(JNIEnv* env); @@ -38,4 +38,4 @@ class NativeImage : public Image { friend class NativeCodec; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/android/Print.cpp b/tgfx/src/platform/android/Print.cpp index 37c4a32756..4e1985cbfb 100644 --- a/tgfx/src/platform/android/Print.cpp +++ b/tgfx/src/platform/android/Print.cpp @@ -19,7 +19,7 @@ #include "platform/Print.h" #include -namespace pag { +namespace tgfx { #define LOG_TAG "Log" void PrintLog(const char format[], ...) { @@ -35,4 +35,4 @@ void PrintError(const char format[], ...) { __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, args); va_end(args); } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/platform/apple/BitmapContextUtil.h b/tgfx/src/platform/apple/BitmapContextUtil.h index cbb6969b85..370456320f 100644 --- a/tgfx/src/platform/apple/BitmapContextUtil.h +++ b/tgfx/src/platform/apple/BitmapContextUtil.h @@ -20,8 +20,7 @@ #include #include "core/ImageInfo.h" -#include "pag/types.h" -namespace pag { +namespace tgfx { CGContextRef CreateBitmapContext(const ImageInfo& info, void* pixels); -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/apple/BitmapContextUtil.mm b/tgfx/src/platform/apple/BitmapContextUtil.mm index 36a31a480e..6b9b3f610c 100644 --- a/tgfx/src/platform/apple/BitmapContextUtil.mm +++ b/tgfx/src/platform/apple/BitmapContextUtil.mm @@ -18,7 +18,7 @@ #include "BitmapContextUtil.h" -namespace pag { +namespace tgfx { static uint32_t GetBitmapInfo(AlphaType alphaType, ColorType colorType) { CGBitmapInfo bitmapInfo = 0; auto premultiplied = alphaType == AlphaType::Premultiplied; @@ -58,4 +58,4 @@ CGContextRef CreateBitmapContext(const ImageInfo& info, void* pixels) { } return cgContext; } -} // namespace pag \ No newline at end of file +} // namespace tgfx \ No newline at end of file diff --git a/tgfx/src/platform/apple/HardwareBuffer.h b/tgfx/src/platform/apple/HardwareBuffer.h index ceace94917..34cf46af45 100644 --- a/tgfx/src/platform/apple/HardwareBuffer.h +++ b/tgfx/src/platform/apple/HardwareBuffer.h @@ -21,7 +21,7 @@ #import #include "core/PixelBuffer.h" -namespace pag { +namespace tgfx { class HardwareBuffer : public PixelBuffer { public: static std::shared_ptr Make(int width, int height, bool alphaOnly = false); @@ -44,4 +44,4 @@ class HardwareBuffer : public PixelBuffer { friend class CocoaPlatform; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/apple/HardwareBuffer.mm b/tgfx/src/platform/apple/HardwareBuffer.mm index 5cc1ce1c75..0454362b42 100644 --- a/tgfx/src/platform/apple/HardwareBuffer.mm +++ b/tgfx/src/platform/apple/HardwareBuffer.mm @@ -19,7 +19,7 @@ #include "HardwareBuffer.h" #include "base/utils/USE.h" -namespace pag { +namespace tgfx { static std::mutex cacheLocker = {}; static std::unordered_map> hardwareBufferMap = {}; diff --git a/tgfx/src/platform/apple/NativeImage.h b/tgfx/src/platform/apple/NativeImage.h index 100b8ad18d..357ff97b1e 100644 --- a/tgfx/src/platform/apple/NativeImage.h +++ b/tgfx/src/platform/apple/NativeImage.h @@ -21,7 +21,7 @@ #include #include "core/Image.h" -namespace pag { +namespace tgfx { class NativeImage : public Image { public: bool readPixels(const ImageInfo& dstInfo, void* dstPixels) const override; @@ -35,4 +35,4 @@ class NativeImage : public Image { friend class NativeCodec; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/apple/NativeImage.mm b/tgfx/src/platform/apple/NativeImage.mm index 647b52c7bc..1f280d6612 100644 --- a/tgfx/src/platform/apple/NativeImage.mm +++ b/tgfx/src/platform/apple/NativeImage.mm @@ -20,7 +20,7 @@ #include "BitmapContextUtil.h" #include "platform/NativeCodec.h" -namespace pag { +namespace tgfx { static CGImagePropertyOrientation GetOrientationFromProperties(CFDictionaryRef imageProperties) { CGImagePropertyOrientation orientation = kCGImagePropertyOrientationUp; if (imageProperties != NULL) { diff --git a/tgfx/src/platform/mock/NativeImage.cpp b/tgfx/src/platform/mock/NativeImage.cpp index 3ea981f304..49609c88ba 100644 --- a/tgfx/src/platform/mock/NativeImage.cpp +++ b/tgfx/src/platform/mock/NativeImage.cpp @@ -18,7 +18,7 @@ #include "platform/NativeCodec.h" -namespace pag { +namespace tgfx { std::shared_ptr NativeCodec::MakeImage(const std::string&) { return nullptr; } @@ -26,4 +26,4 @@ std::shared_ptr NativeCodec::MakeImage(const std::string&) { std::shared_ptr NativeCodec::MakeImage(std::shared_ptr) { return nullptr; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/web/NativeImage.cpp b/tgfx/src/platform/web/NativeImage.cpp index 58e9ad019d..2744198268 100644 --- a/tgfx/src/platform/web/NativeImage.cpp +++ b/tgfx/src/platform/web/NativeImage.cpp @@ -22,7 +22,7 @@ using namespace emscripten; -namespace pag { +namespace tgfx { std::shared_ptr NativeCodec::MakeImage(const std::string&) { return nullptr; } @@ -55,4 +55,4 @@ std::shared_ptr NativeImage::MakeFrom(emscripten::val nativeImage) std::shared_ptr NativeImage::makeBuffer() const { return NativeTextureBuffer::Make(width(), height(), nativeImage); } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/web/NativeImage.h b/tgfx/src/platform/web/NativeImage.h index 929bcea1c9..9b36c68206 100644 --- a/tgfx/src/platform/web/NativeImage.h +++ b/tgfx/src/platform/web/NativeImage.h @@ -21,7 +21,7 @@ #include #include "core/Image.h" -namespace pag { +namespace tgfx { class NativeImage : public Image { public: static std::shared_ptr MakeFrom(emscripten::val nativeImage); @@ -40,4 +40,4 @@ class NativeImage : public Image { friend class NativeCodec; }; -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/web/NativeTextureBuffer.cpp b/tgfx/src/platform/web/NativeTextureBuffer.cpp index a0e527c54f..ec9147ae24 100644 --- a/tgfx/src/platform/web/NativeTextureBuffer.cpp +++ b/tgfx/src/platform/web/NativeTextureBuffer.cpp @@ -21,7 +21,7 @@ using namespace emscripten; -namespace pag { +namespace tgfx { std::shared_ptr NativeTextureBuffer::Make(int width, int height, val source) { if (!source.as()) { return nullptr; @@ -41,4 +41,4 @@ std::shared_ptr NativeTextureBuffer::makeTexture(Context* context) cons source.call("upload", val::module_property("GL")); return texture; } -} // namespace pag +} // namespace tgfx diff --git a/tgfx/src/platform/web/NativeTextureBuffer.h b/tgfx/src/platform/web/NativeTextureBuffer.h index b7a2ba9032..04a9c4f2d5 100644 --- a/tgfx/src/platform/web/NativeTextureBuffer.h +++ b/tgfx/src/platform/web/NativeTextureBuffer.h @@ -21,7 +21,7 @@ #include #include "gpu/TextureBuffer.h" -namespace pag { +namespace tgfx { class NativeTextureBuffer : public TextureBuffer { public: static std::shared_ptr Make(int width, int height, emscripten::val source); @@ -35,4 +35,4 @@ class NativeTextureBuffer : public TextureBuffer { emscripten::val source = emscripten::val::null(); }; -} // namespace pag +} // namespace tgfx diff --git a/web/src/pag_wasm_bindings.cpp b/web/src/pag_wasm_bindings.cpp index 4ce66ac23b..fde1ee5de1 100644 --- a/web/src/pag_wasm_bindings.cpp +++ b/web/src/pag_wasm_bindings.cpp @@ -97,7 +97,7 @@ EMSCRIPTEN_BINDINGS(pag) { })) .function("_getLayersByName", &PAGComposition::getLayersByName) .function("_getLayersUnderPoint", &PAGComposition::getLayersUnderPoint); - + class_>("_PAGFile") .smart_ptr>("_PAGFile") .class_function("_Load", optional_override([](uintptr_t bytes, size_t length) { @@ -154,7 +154,7 @@ EMSCRIPTEN_BINDINGS(pag) { })) .class_function("_FromNativeImage", optional_override([](val nativeImage) { return std::static_pointer_cast( - StillImage::FromImage(NativeImage::MakeFrom(nativeImage))); + StillImage::FromImage(tgfx::NativeImage::MakeFrom(nativeImage))); })) .function("_width", &PAGImage::width) .function("_height", &PAGImage::height); @@ -186,11 +186,11 @@ EMSCRIPTEN_BINDINGS(pag) { pagPlayer.setComposition(std::move(pagFile)); })); - class_("ImageInfo") - .property("width", &ImageInfo::width) - .property("height", &ImageInfo::height) - .property("rowBytes", &ImageInfo::rowBytes) - .property("colorType", &ImageInfo::colorType); + class_("ImageInfo") + .property("width", &tgfx::ImageInfo::width) + .property("height", &tgfx::ImageInfo::height) + .property("rowBytes", &tgfx::ImageInfo::rowBytes) + .property("colorType", &tgfx::ImageInfo::colorType); class_("Matrix") .property("a", &Matrix::getScaleX) @@ -226,17 +226,17 @@ EMSCRIPTEN_BINDINGS(pag) { .property("backgroundAlpha", &TextDocument::backgroundAlpha) .property("direction", &TextDocument::direction); - class_("Stroke") - .property("width", &Stroke::width) - .property("cap", &Stroke::cap) - .property("join", &Stroke::join) - .property("miterLimit", &Stroke::miterLimit); + class_("Stroke") + .property("width", &tgfx::Stroke::width) + .property("cap", &tgfx::Stroke::cap) + .property("join", &tgfx::Stroke::join) + .property("miterLimit", &tgfx::Stroke::miterLimit); - value_object("FontMetrics") - .field("ascent", &FontMetrics::ascent) - .field("descent", &FontMetrics::descent) - .field("xHeight", &FontMetrics::xHeight) - .field("capHeight", &FontMetrics::capHeight); + value_object("FontMetrics") + .field("ascent", &tgfx::FontMetrics::ascent) + .field("descent", &tgfx::FontMetrics::descent) + .field("xHeight", &tgfx::FontMetrics::xHeight) + .field("capHeight", &tgfx::FontMetrics::capHeight); value_object("Rect") .field("left", &Rect::left) @@ -256,11 +256,11 @@ EMSCRIPTEN_BINDINGS(pag) { .field("duration", &Marker::duration) .field("comment", &Marker::comment); - enum_("PathFillType") - .value("WINDING", PathFillType::Winding) - .value("EVEN_ODD", PathFillType::EvenOdd) - .value("INVERSE_WINDING", PathFillType::InverseWinding) - .value("INVERSE_EVEN_ODD", PathFillType::InverseEvenOdd); + enum_("PathFillType") + .value("WINDING", tgfx::PathFillType::Winding) + .value("EVEN_ODD", tgfx::PathFillType::EvenOdd) + .value("INVERSE_WINDING", tgfx::PathFillType::InverseWinding) + .value("INVERSE_EVEN_ODD", tgfx::PathFillType::InverseEvenOdd); enum_("ColorType") .value("Unknown", ColorType::Unknown) @@ -277,15 +277,15 @@ EMSCRIPTEN_BINDINGS(pag) { .value("Image", LayerType::Image) .value("PreCompose", LayerType::PreCompose); - enum_("Cap") - .value("Miter", Stroke::Cap::Butt) - .value("Round", Stroke::Cap::Round) - .value("Bevel", Stroke::Cap::Square); + enum_("Cap") + .value("Miter", tgfx::LineCap::Butt) + .value("Round", tgfx::LineCap::Round) + .value("Bevel", tgfx::LineCap::Square); - enum_("Join") - .value("Miter", Stroke::Join::Miter) - .value("Round", Stroke::Join::Round) - .value("Bevel", Stroke::Join::Bevel); + enum_("Join") + .value("Miter", tgfx::LineJoin::Miter) + .value("Round", tgfx::LineJoin::Round) + .value("Bevel", tgfx::LineJoin::Bevel); register_vector>("VectorPAGLayer"); register_vector("VectorString");