diff --git a/.github/workflows/autotest.yml b/.github/workflows/autotest.yml index 0ade8bde..3daf9d21 100644 --- a/.github/workflows/autotest.yml +++ b/.github/workflows/autotest.yml @@ -63,6 +63,8 @@ jobs: run: | chmod +x autotest.sh ./autotest.sh + env: + TRACY_NO_INVARIANT_CHECK: 1 - name: Run Codecov run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 39ccb244..0c6ed545 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,9 @@ option(TGFX_BUILD_SVG "Allow build the svg module" OFF) option(TGFX_BUILD_DRAWERS "Build the tgfx-drawers library" OFF) option(EMSCRIPTEN_PTHREADS "Allow the use of threads on the web platform" OFF) +if (CMAKE_BUILD_TYPE MATCHES "Debug") + option(TGFX_ENABLE_PROFILING "Enable Profiling" ON) +endif () if (APPLE OR (WEB AND NOT EMSCRIPTEN_PTHREADS)) option(TGFX_USE_FREETYPE "Allow the use of embedded freetype library" OFF) @@ -72,6 +75,7 @@ message("TGFX_USE_JPEG_ENCODE: ${TGFX_USE_JPEG_ENCODE}") message("TGFX_USE_WEBP_DECODE: ${TGFX_USE_WEBP_DECODE}") message("TGFX_USE_WEBP_ENCODE: ${TGFX_USE_WEBP_ENCODE}") message("TGFX_BUILD_TESTS: ${TGFX_BUILD_TESTS}") +message("TGFX_ENABLE_PROFILING: ${TGFX_ENABLE_PROFILING}") message("EMSCRIPTEN_PTHREADS: ${EMSCRIPTEN_PTHREADS}") if (NOT CMAKE_OSX_DEPLOYMENT_TARGET) @@ -260,6 +264,12 @@ else () set(TGFX_USE_NATIVE_GL ON) endif () +if (TGFX_ENABLE_PROFILING) + list(APPEND TGFX_STATIC_VENDORS tracy) + list(APPEND TGFX_INCLUDES third_party/tracy) + list(APPEND TGFX_DEFINES TGFX_ENABLE_PROFILING) +endif () + list(APPEND TGFX_STATIC_VENDORS pathkit) list(APPEND TGFX_INCLUDES third_party/pathkit) list(APPEND TGFX_STATIC_VENDORS skcms) @@ -478,6 +488,10 @@ if (TGFX_BUILD_TESTS) endif () endif () + if (TGFX_ENABLE_PROFILING) + list(APPEND TGFX_TEST_INCLUDES third_party/tracy) + endif () + file(GLOB_RECURSE TGFX_TEST_FILES test/src/*.*) list(APPEND TGFX_TEST_LIBS tgfx-drawers tgfx ${TGFX_SHARED_LIBS}) list(APPEND TGFX_TEST_INCLUDES src test/src third_party/json/include) diff --git a/DEPS b/DEPS index ff07b0a2..d627da2a 100644 --- a/DEPS +++ b/DEPS @@ -64,6 +64,11 @@ "url": "https://github.com/libexpat/libexpat.git", "commit": "88b3ed553d8ad335559254863a33360d55b9f1d6", "dir": "third_party/expat" + }, + { + "url": "https://github.com/wolfpld/tracy.git", + "commit": "759b4c3bfe207ab382c01080f0417aca5af4411a", + "dir": "third_party/tracy" } ] }, diff --git a/src/core/Canvas.cpp b/src/core/Canvas.cpp index 1d80efd7..068c8cdd 100644 --- a/src/core/Canvas.cpp +++ b/src/core/Canvas.cpp @@ -21,6 +21,7 @@ #include "core/LayerUnrollContext.h" #include "core/Records.h" #include "core/utils/Log.h" +#include "core/utils/Profiling.h" #include "tgfx/core/PathEffect.h" #include "tgfx/core/Surface.h" @@ -166,6 +167,7 @@ static FillStyle CreateFillStyle(const Paint* paint) { } void Canvas::drawLine(float x0, float y0, float x1, float y1, const Paint& paint) { + TRACE_EVENT; Path path = {}; path.moveTo(x0, y0); path.lineTo(x1, y1); @@ -175,6 +177,7 @@ void Canvas::drawLine(float x0, float y0, float x1, float y1, const Paint& paint } void Canvas::drawRect(const Rect& rect, const Paint& paint) { + TRACE_EVENT; if (paint.getStroke()) { Path path = {}; path.addRect(rect); @@ -189,24 +192,28 @@ void Canvas::drawRect(const Rect& rect, const Paint& paint) { } void Canvas::drawOval(const Rect& oval, const Paint& paint) { + TRACE_EVENT; RRect rRect = {}; rRect.setOval(oval); drawRRect(rRect, paint); } void Canvas::drawCircle(float centerX, float centerY, float radius, const Paint& paint) { + TRACE_EVENT; Rect rect = Rect::MakeLTRB(centerX - radius, centerY - radius, centerX + radius, centerY + radius); drawOval(rect, paint); } void Canvas::drawRoundRect(const Rect& rect, float radiusX, float radiusY, const Paint& paint) { + TRACE_EVENT; RRect rRect = {}; rRect.setRectXY(rect, radiusX, radiusY); drawRRect(rRect, paint); } void Canvas::drawRRect(const RRect& rRect, const Paint& paint) { + TRACE_EVENT; if (rRect.radii.isZero()) { drawRect(rRect.rect, paint); return; @@ -225,11 +232,13 @@ void Canvas::drawRRect(const RRect& rRect, const Paint& paint) { } void Canvas::drawPath(const Path& path, const Paint& paint) { + TRACE_EVENT; auto shape = Shape::MakeFrom(path); drawShape(std::move(shape), paint); } void Canvas::drawShape(std::shared_ptr shape, const Paint& paint) { + TRACE_EVENT; if (shape == nullptr || paint.nothingToDraw()) { return; } @@ -286,6 +295,7 @@ void Canvas::drawImage(std::shared_ptr image, const SamplingOptions& samp void Canvas::drawImage(std::shared_ptr image, const SamplingOptions& sampling, const Paint* paint, const Matrix* extraMatrix) { + TRACE_EVENT; if (image == nullptr || (paint && paint->nothingToDraw())) { return; } @@ -309,6 +319,7 @@ void Canvas::drawImage(std::shared_ptr image, const SamplingOptions& samp void Canvas::drawSimpleText(const std::string& text, float x, float y, const Font& font, const Paint& paint) { + TRACE_EVENT; if (text.empty()) { return; } @@ -318,6 +329,7 @@ void Canvas::drawSimpleText(const std::string& text, float x, float y, const Fon void Canvas::drawGlyphs(const GlyphID glyphs[], const Point positions[], size_t glyphCount, const Font& font, const Paint& paint) { + TRACE_EVENT; if (glyphCount == 0 || paint.nothingToDraw()) { return; } @@ -329,6 +341,7 @@ void Canvas::drawGlyphs(const GlyphID glyphs[], const Point positions[], size_t void Canvas::drawTextBlob(std::shared_ptr textBlob, float x, float y, const Paint& paint) { + TRACE_EVENT; if (textBlob == nullptr || paint.nothingToDraw()) { return; } @@ -341,11 +354,13 @@ void Canvas::drawTextBlob(std::shared_ptr textBlob, float x, float y, } void Canvas::drawPicture(std::shared_ptr picture) { + TRACE_EVENT; drawContext->drawPicture(std::move(picture), *mcState); } void Canvas::drawPicture(std::shared_ptr picture, const Matrix* matrix, const Paint* paint) { + TRACE_EVENT; if (picture == nullptr) { return; } @@ -363,6 +378,7 @@ void Canvas::drawPicture(std::shared_ptr picture, const Matrix* matrix, void Canvas::drawLayer(std::shared_ptr picture, const MCState& state, const FillStyle& style, std::shared_ptr imageFilter) { + TRACE_EVENT; if (imageFilter == nullptr && picture->records.size() == 1 && style.maskFilter == nullptr) { LayerUnrollContext layerContext(drawContext, style); picture->playback(&layerContext, state); @@ -376,6 +392,7 @@ void Canvas::drawLayer(std::shared_ptr picture, const MCState& state, void Canvas::drawAtlas(std::shared_ptr atlas, const Matrix matrix[], const Rect tex[], const Color colors[], size_t count, const SamplingOptions& sampling, const Paint* paint) { + TRACE_EVENT; // TODO: Support blend mode, atlas as source, colors as destination, colors can be nullptr. if (atlas == nullptr || count == 0 || (paint && paint->nothingToDraw())) { return; diff --git a/src/core/DataProvider.cpp b/src/core/DataProvider.cpp index 7c63c0a7..9e05dfbf 100644 --- a/src/core/DataProvider.cpp +++ b/src/core/DataProvider.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "DataProvider.h" +#include "core/utils/Profiling.h" namespace tgfx { class DataWrapper : public DataProvider { diff --git a/src/core/GlyphRasterizer.cpp b/src/core/GlyphRasterizer.cpp index 5609cadc..4378c2bb 100644 --- a/src/core/GlyphRasterizer.cpp +++ b/src/core/GlyphRasterizer.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "GlyphRasterizer.h" +#include "core/utils/Profiling.h" #include "tgfx/core/Mask.h" namespace tgfx { @@ -34,6 +35,7 @@ GlyphRasterizer::~GlyphRasterizer() { } std::shared_ptr GlyphRasterizer::onMakeBuffer(bool tryHardware) const { + TRACE_EVENT; auto mask = Mask::Make(width(), height(), tryHardware); if (!mask) { return nullptr; diff --git a/src/core/ImageCodec.cpp b/src/core/ImageCodec.cpp index f83d222a..8c53390d 100644 --- a/src/core/ImageCodec.cpp +++ b/src/core/ImageCodec.cpp @@ -18,6 +18,7 @@ #include "tgfx/core/ImageCodec.h" #include "core/PixelBuffer.h" +#include "core/utils/Profiling.h" #include "core/utils/USE.h" #include "tgfx/core/Buffer.h" #include "tgfx/core/ImageInfo.h" @@ -40,6 +41,7 @@ namespace tgfx { std::shared_ptr ImageCodec::MakeFrom(const std::string& filePath) { + TRACE_EVENT; std::shared_ptr codec = nullptr; auto stream = Stream::MakeFromFile(filePath); if (stream == nullptr || stream->size() <= 14) { @@ -135,6 +137,7 @@ std::shared_ptr ImageCodec::Encode(const Pixmap& pixmap, EncodedFormat for } std::shared_ptr ImageCodec::onMakeBuffer(bool tryHardware) const { + TRACE_EVENT; auto pixelBuffer = PixelBuffer::Make(width(), height(), isAlphaOnly(), tryHardware); if (pixelBuffer == nullptr) { return nullptr; diff --git a/src/core/ImageDecoder.cpp b/src/core/ImageDecoder.cpp index 04e90765..3f4aacfc 100644 --- a/src/core/ImageDecoder.cpp +++ b/src/core/ImageDecoder.cpp @@ -18,6 +18,7 @@ #include "ImageDecoder.h" #include "core/utils/DataTask.h" +#include "core/utils/Profiling.h" namespace tgfx { diff --git a/src/core/ShapeRasterizer.cpp b/src/core/ShapeRasterizer.cpp index 7c15f8f4..6990255e 100644 --- a/src/core/ShapeRasterizer.cpp +++ b/src/core/ShapeRasterizer.cpp @@ -18,6 +18,7 @@ #include "ShapeRasterizer.h" #include "core/PathTriangulator.h" +#include "core/utils/Profiling.h" #include "tgfx/core/Mask.h" #include "utils/Log.h" @@ -28,6 +29,7 @@ ShapeRasterizer::ShapeRasterizer(int width, int height, std::shared_ptr s } std::shared_ptr ShapeRasterizer::makeRasterized(bool tryHardware) const { + TRACE_EVENT; auto finalPath = shape->getPath(); if (PathTriangulator::ShouldTriangulatePath(finalPath)) { return ShapeBuffer::MakeFrom(makeTriangles(finalPath)); @@ -36,6 +38,7 @@ std::shared_ptr ShapeRasterizer::makeRasterized(bool tryHardware) c } std::shared_ptr ShapeRasterizer::onMakeBuffer(bool tryHardware) const { + TRACE_EVENT; auto finalPath = shape->getPath(); return makeImageBuffer(finalPath, tryHardware); } diff --git a/src/core/SolidLayer.cpp b/src/core/SolidLayer.cpp index d3add9f8..2bc9d999 100644 --- a/src/core/SolidLayer.cpp +++ b/src/core/SolidLayer.cpp @@ -22,6 +22,7 @@ namespace tgfx { std::shared_ptr SolidLayer::Make() { + TRACE_EVENT; auto layer = std::shared_ptr(new SolidLayer()); layer->weakThis = layer; return layer; diff --git a/src/core/images/Image.cpp b/src/core/images/Image.cpp index 54b92b7d..1ed8deac 100644 --- a/src/core/images/Image.cpp +++ b/src/core/images/Image.cpp @@ -27,6 +27,7 @@ #include "core/images/ScaleImage.h" #include "core/images/SubsetImage.h" #include "core/images/TextureImage.h" +#include "core/utils/Profiling.h" #include "gpu/OpContext.h" #include "gpu/ProxyProvider.h" #include "gpu/TPArgs.h" @@ -63,6 +64,7 @@ class PixelDataConverter : public ImageGenerator { }; std::shared_ptr Image::MakeFromFile(const std::string& filePath) { + TRACE_EVENT; auto codec = ImageCodec::MakeFrom(filePath); auto image = MakeFrom(codec); if (image == nullptr) { @@ -72,6 +74,7 @@ std::shared_ptr Image::MakeFromFile(const std::string& filePath) { } std::shared_ptr Image::MakeFromEncoded(std::shared_ptr encodedData) { + TRACE_EVENT; auto codec = ImageCodec::MakeFrom(std::move(encodedData)); auto image = MakeFrom(codec); if (image == nullptr) { @@ -81,6 +84,7 @@ std::shared_ptr Image::MakeFromEncoded(std::shared_ptr encodedData) } std::shared_ptr Image::MakeFrom(NativeImageRef nativeImage) { + TRACE_EVENT; auto codec = ImageCodec::MakeFrom(nativeImage); auto image = MakeFrom(codec); if (image == nullptr) { @@ -90,6 +94,7 @@ std::shared_ptr Image::MakeFrom(NativeImageRef nativeImage) { } std::shared_ptr Image::MakeFrom(const ImageInfo& info, std::shared_ptr pixels) { + TRACE_EVENT; if (info.isEmpty() || pixels == nullptr || info.byteSize() > pixels->size()) { return nullptr; } @@ -102,26 +107,31 @@ std::shared_ptr Image::MakeFrom(const ImageInfo& info, std::shared_ptr Image::MakeFrom(const Bitmap& bitmap) { + TRACE_EVENT; return MakeFrom(bitmap.makeBuffer()); } std::shared_ptr Image::MakeFrom(HardwareBufferRef hardwareBuffer, YUVColorSpace colorSpace) { + TRACE_EVENT; auto buffer = ImageBuffer::MakeFrom(hardwareBuffer, colorSpace); return MakeFrom(std::move(buffer)); } std::shared_ptr Image::MakeI420(std::shared_ptr yuvData, YUVColorSpace colorSpace) { + TRACE_EVENT; auto buffer = ImageBuffer::MakeI420(std::move(yuvData), colorSpace); return MakeFrom(std::move(buffer)); } std::shared_ptr Image::MakeNV12(std::shared_ptr yuvData, YUVColorSpace colorSpace) { + TRACE_EVENT; auto buffer = ImageBuffer::MakeNV12(std::move(yuvData), colorSpace); return MakeFrom(std::move(buffer)); } std::shared_ptr Image::MakeFrom(Context* context, const BackendTexture& backendTexture, ImageOrigin origin) { + TRACE_EVENT; if (context == nullptr) { return nullptr; } @@ -131,6 +141,7 @@ std::shared_ptr Image::MakeFrom(Context* context, const BackendTexture& b std::shared_ptr Image::MakeAdopted(Context* context, const BackendTexture& backendTexture, ImageOrigin origin) { + TRACE_EVENT; if (context == nullptr) { return nullptr; } @@ -144,16 +155,19 @@ BackendTexture Image::getBackendTexture(Context*, ImageOrigin*) const { std::shared_ptr Image::makeRasterized(bool mipmapped, const SamplingOptions& sampling) const { + TRACE_EVENT; return RasterImage::MakeFrom(weakThis.lock(), mipmapped, sampling); } std::shared_ptr Image::makeTextureImage(Context* context, const SamplingOptions& sampling) const { + TRACE_EVENT; TPArgs args(context, 0, hasMipmaps()); return TextureImage::Wrap(lockTextureProxy(args, sampling)); } std::shared_ptr Image::makeDecoded(Context* context) const { + TRACE_EVENT; if (isFullyDecoded()) { return weakThis.lock(); } @@ -169,6 +183,7 @@ std::shared_ptr Image::onMakeDecoded(Context*, bool) const { } std::shared_ptr Image::makeMipmapped(bool enabled) const { + TRACE_EVENT; if (hasMipmaps() == enabled) { return weakThis.lock(); } @@ -176,6 +191,7 @@ std::shared_ptr Image::makeMipmapped(bool enabled) const { } std::shared_ptr Image::makeSubset(const Rect& subset) const { + TRACE_EVENT; auto rect = subset; rect.round(); auto bounds = Rect::MakeWH(width(), height()); @@ -189,6 +205,7 @@ std::shared_ptr Image::makeSubset(const Rect& subset) const { } std::shared_ptr Image::makeScaled(float scaleX, float scaleY) const { + TRACE_EVENT; auto w = width(); auto h = height(); auto scaledWidth = ScaleImage::GetSize(w, scaleX); @@ -200,10 +217,12 @@ std::shared_ptr Image::makeScaled(float scaleX, float scaleY) const { } std::shared_ptr Image::onMakeSubset(const Rect& subset) const { + TRACE_EVENT; return SubsetImage::MakeFrom(weakThis.lock(), subset); } std::shared_ptr Image::makeOriented(Orientation orientation) const { + TRACE_EVENT; if (orientation == Orientation::TopLeft) { return weakThis.lock(); } @@ -211,25 +230,30 @@ std::shared_ptr Image::makeOriented(Orientation orientation) const { } std::shared_ptr Image::onMakeOriented(Orientation orientation) const { + TRACE_EVENT; return OrientImage::MakeFrom(weakThis.lock(), orientation); } std::shared_ptr Image::onMakeScaled(float scaleX, float scaleY) const { + TRACE_EVENT; return ScaleImage::MakeFrom(weakThis.lock(), Point::Make(scaleX, scaleY)); } std::shared_ptr Image::makeWithFilter(std::shared_ptr filter, Point* offset, const Rect* clipRect) const { + TRACE_EVENT; return onMakeWithFilter(std::move(filter), offset, clipRect); } std::shared_ptr Image::onMakeWithFilter(std::shared_ptr filter, Point* offset, const Rect* clipRect) const { + TRACE_EVENT; return FilterImage::MakeFrom(weakThis.lock(), std::move(filter), offset, clipRect); } std::shared_ptr Image::makeRGBAAA(int displayWidth, int displayHeight, int alphaStartX, int alphaStartY) const { + TRACE_EVENT; if (alphaStartX == 0 && alphaStartY == 0) { return makeSubset(Rect::MakeWH(displayWidth, displayHeight)); } diff --git a/src/core/images/ResourceImage.cpp b/src/core/images/ResourceImage.cpp index 1f2d6184..c4945635 100644 --- a/src/core/images/ResourceImage.cpp +++ b/src/core/images/ResourceImage.cpp @@ -18,6 +18,7 @@ #include "ResourceImage.h" #include "core/images/MipmapImage.h" +#include "core/utils/Profiling.h" #include "gpu/ops/RectDrawOp.h" #include "gpu/processors/TiledTextureEffect.h" @@ -27,6 +28,7 @@ ResourceImage::ResourceImage(UniqueKey uniqueKey) : uniqueKey(std::move(uniqueKe std::shared_ptr ResourceImage::lockTextureProxy(const TPArgs& args, const SamplingOptions&) const { + TRACE_EVENT; if (args.context == nullptr) { return nullptr; } @@ -37,6 +39,7 @@ std::shared_ptr ResourceImage::lockTextureProxy(const TPArgs& args } std::shared_ptr ResourceImage::onMakeMipmapped(bool enabled) const { + TRACE_EVENT; auto source = std::static_pointer_cast(weakThis.lock()); return enabled ? MipmapImage::MakeFrom(std::move(source)) : source; } @@ -48,6 +51,7 @@ std::shared_ptr ResourceImage::makeRasterized(bool, const SamplingOptions std::unique_ptr ResourceImage::asFragmentProcessor( const FPArgs& args, TileMode tileModeX, TileMode tileModeY, const SamplingOptions& sampling, const Matrix* uvMatrix) const { + TRACE_EVENT; TPArgs tpArgs(args.context, args.renderFlags, hasMipmaps(), uniqueKey); auto proxy = onLockTextureProxy(tpArgs); return TiledTextureEffect::Make(std::move(proxy), tileModeX, tileModeY, sampling, uvMatrix, diff --git a/src/core/images/TransformImage.cpp b/src/core/images/TransformImage.cpp index 70f082d1..1427dea8 100644 --- a/src/core/images/TransformImage.cpp +++ b/src/core/images/TransformImage.cpp @@ -17,12 +17,14 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "TransformImage.h" +#include "core/utils/Profiling.h" namespace tgfx { TransformImage::TransformImage(std::shared_ptr source) : source(std::move(source)) { } std::shared_ptr TransformImage::onMakeDecoded(Context* context, bool tryHardware) const { + TRACE_EVENT; auto newSource = source->onMakeDecoded(context, tryHardware); if (newSource == nullptr) { return nullptr; @@ -31,6 +33,7 @@ std::shared_ptr TransformImage::onMakeDecoded(Context* context, bool tryH } std::shared_ptr TransformImage::onMakeMipmapped(bool enabled) const { + TRACE_EVENT; auto newSource = source->makeMipmapped(enabled); if (newSource == nullptr) { return nullptr; diff --git a/src/core/utils/Profiling.h b/src/core/utils/Profiling.h new file mode 100644 index 00000000..63af6575 --- /dev/null +++ b/src/core/utils/Profiling.h @@ -0,0 +1,49 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making tgfx available. +// +// Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// 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 +#ifdef TGFX_ENABLE_PROFILING +#define TRACY_ENABLE + +#include "public/common/TracySystem.hpp" +#include "public/tracy/Tracy.hpp" + +#if defined(_MSC_VER) +#define TRACE_FUNC __FUNCSIG__ +#else +#define TRACE_FUNC __PRETTY_FUNCTION__ +#endif + +#define TRACE_EVENT ZoneScopedN(TRACE_FUNC) +#define TRACE_EVENT_COLOR(color) ZoneScopedNC(TRACE_FUNC, color) + +#define FRAME_MARK FrameMark + +#define TRACE_THREAD_NAME(name) tracy::SetThreadName(name) + +#define TRACY_COLOR_YELLOW tracy::Color::ColorType::Yellow +#define TRACY_COLOR_GREEN tracy::Color::ColorType::Green +#define TRACY_COLOR_GREENYELLOW tracy::Color::ColorType::GreenYellow + +#else +#define TRACE_EVENT +#define TRACE_EVENT_COLOR(color) + +#define FRAME_MARK + +#define TRACE_THREAD_NAME(name) +#endif \ No newline at end of file diff --git a/src/core/utils/TaskGroup.cpp b/src/core/utils/TaskGroup.cpp index 9310c85a..c70426b0 100644 --- a/src/core/utils/TaskGroup.cpp +++ b/src/core/utils/TaskGroup.cpp @@ -18,8 +18,10 @@ #include "TaskGroup.h" #include +#include #include #include "core/utils/Log.h" +#include "core/utils/Profiling.h" #ifdef __APPLE__ #include @@ -27,6 +29,7 @@ namespace tgfx { static constexpr auto THREAD_TIMEOUT = std::chrono::seconds(10); +static constexpr uint32_t InvalidThreadNumber = 0; int GetCPUCores() { int cpuCores = 0; @@ -43,12 +46,28 @@ int GetCPUCores() { return cpuCores; } +uint32_t GetThreadNumber() { + static std::atomic nextID{1}; + uint32_t number; + do { + number = nextID.fetch_add(1, std::memory_order_relaxed); + } while (number == InvalidThreadNumber); + return number; +} + +std::string GetThreadName() { + char threadName[10] = {'\0'}; + snprintf(threadName, 10, "Thread_%d", GetThreadNumber()); + return threadName; +} + TaskGroup* TaskGroup::GetInstance() { static auto& taskGroup = *new TaskGroup(); return &taskGroup; } void TaskGroup::RunLoop(TaskGroup* taskGroup) { + TRACE_THREAD_NAME(GetThreadName().c_str()); while (true) { auto task = taskGroup->popTask(); if (!task) { diff --git a/src/gpu/Device.cpp b/src/gpu/Device.cpp index a2c0f521..cd51736b 100644 --- a/src/gpu/Device.cpp +++ b/src/gpu/Device.cpp @@ -18,6 +18,7 @@ #include "tgfx/gpu/Device.h" #include "core/utils/Log.h" +#include "core/utils/Profiling.h" #include "core/utils/UniqueID.h" #include "tgfx/gpu/Context.h" @@ -32,6 +33,7 @@ Device::~Device() { } Context* Device::lockContext() { + TRACE_EVENT_COLOR(TRACY_COLOR_GREENYELLOW); locker.lock(); contextLocked = onLockContext(); if (!contextLocked) { diff --git a/src/gpu/DrawingManager.cpp b/src/gpu/DrawingManager.cpp index b6dda54a..19c0f7a0 100644 --- a/src/gpu/DrawingManager.cpp +++ b/src/gpu/DrawingManager.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "DrawingManager.h" +#include "core/utils/Profiling.h" #include "gpu/Gpu.h" #include "gpu/proxies/RenderTargetProxy.h" #include "gpu/proxies/TextureProxy.h" @@ -81,7 +82,9 @@ void DrawingManager::addResourceTask(std::shared_ptr resourceTask) } bool DrawingManager::flush() { + TRACE_EVENT; if (resourceTasks.empty() && renderTasks.empty()) { + FRAME_MARK; return false; } if (activeOpsTask) { @@ -107,6 +110,7 @@ bool DrawingManager::flush() { task->execute(context->gpu()); } renderTasks = {}; + FRAME_MARK; return true; } diff --git a/src/gpu/ProxyProvider.cpp b/src/gpu/ProxyProvider.cpp index d37213c7..d3d016de 100644 --- a/src/gpu/ProxyProvider.cpp +++ b/src/gpu/ProxyProvider.cpp @@ -19,6 +19,7 @@ #include "ProxyProvider.h" #include "core/ShapeRasterizer.h" #include "core/utils/DataTask.h" +#include "core/utils/Profiling.h" #include "core/utils/UniqueID.h" #include "gpu/DrawingManager.h" #include "gpu/PlainTexture.h" diff --git a/src/gpu/ResourceProvider.cpp b/src/gpu/ResourceProvider.cpp index 0225361e..ab98c780 100644 --- a/src/gpu/ResourceProvider.cpp +++ b/src/gpu/ResourceProvider.cpp @@ -19,6 +19,7 @@ #include "ResourceProvider.h" #include "GradientCache.h" #include "core/utils/Log.h" +#include "core/utils/Profiling.h" #include "tgfx/core/Buffer.h" namespace tgfx { @@ -30,6 +31,7 @@ class PatternedIndexBufferProvider : public DataProvider { } std::shared_ptr getData() const override { + TRACE_EVENT; auto size = static_cast(reps * patternSize * sizeof(uint16_t)); Buffer buffer(size); if (buffer.isEmpty()) { diff --git a/src/gpu/Surface.cpp b/src/gpu/Surface.cpp index 90d78519..f54ce088 100644 --- a/src/gpu/Surface.cpp +++ b/src/gpu/Surface.cpp @@ -21,11 +21,13 @@ #include "core/images/TextureImage.h" #include "core/utils/Log.h" #include "core/utils/PixelFormatUtil.h" +#include "core/utils/Profiling.h" #include "gpu/RenderContext.h" namespace tgfx { std::shared_ptr Surface::Make(Context* context, int width, int height, bool alphaOnly, int sampleCount, bool mipmapped, uint32_t renderFlags) { + TRACE_EVENT_COLOR(TRACY_COLOR_YELLOW); return Make(context, width, height, alphaOnly ? ColorType::ALPHA_8 : ColorType::RGBA_8888, sampleCount, mipmapped, renderFlags); } diff --git a/src/gpu/ops/RRectDrawOp.cpp b/src/gpu/ops/RRectDrawOp.cpp index 7fb6b8ee..cf0673f7 100644 --- a/src/gpu/ops/RRectDrawOp.cpp +++ b/src/gpu/ops/RRectDrawOp.cpp @@ -18,6 +18,7 @@ #include "RRectDrawOp.h" #include "core/utils/MathExtra.h" +#include "core/utils/Profiling.h" #include "gpu/Gpu.h" #include "gpu/GpuBuffer.h" #include "gpu/processors/EllipseGeometryProcessor.h" @@ -130,6 +131,7 @@ class RRectVerticesProvider : public DataProvider { } std::shared_ptr getData() const override { + TRACE_EVENT; auto floatCount = rRectPaints.size() * 4 * 48; if (useScale) { floatCount += rRectPaints.size() * 4 * 4; @@ -260,6 +262,7 @@ class RRectIndicesProvider : public DataProvider { } std::shared_ptr getData() const override { + TRACE_EVENT; auto bufferSize = rRectPaints.size() * kIndicesPerFillRRect * sizeof(uint16_t); Buffer buffer(bufferSize); auto indices = reinterpret_cast(buffer.data()); @@ -279,6 +282,7 @@ class RRectIndicesProvider : public DataProvider { std::unique_ptr RRectDrawOp::Make(Color color, const RRect& rRect, const Matrix& viewMatrix) { + TRACE_EVENT; Matrix matrix = Matrix::I(); if (!viewMatrix.invert(&matrix)) { return nullptr; @@ -314,6 +318,7 @@ static bool UseScale(Context* context) { } void RRectDrawOp::prepare(Context* context, uint32_t renderFlags) { + TRACE_EVENT; auto indexProvider = std::make_shared(rRectPaints); indexBufferProxy = GpuBufferProxy::MakeFrom(context, std::move(indexProvider), BufferType::Index, renderFlags); @@ -329,6 +334,7 @@ void RRectDrawOp::prepare(Context* context, uint32_t renderFlags) { } void RRectDrawOp::execute(RenderPass* renderPass) { + TRACE_EVENT; if (indexBufferProxy == nullptr) { return; } diff --git a/src/gpu/ops/RectDrawOp.cpp b/src/gpu/ops/RectDrawOp.cpp index dbab750b..d7f874bd 100644 --- a/src/gpu/ops/RectDrawOp.cpp +++ b/src/gpu/ops/RectDrawOp.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "RectDrawOp.h" +#include "core/utils/Profiling.h" #include "gpu/Gpu.h" #include "gpu/Quad.h" #include "gpu/ResourceProvider.h" @@ -46,6 +47,7 @@ class RectCoverageVerticesProvider : public DataProvider { } std::shared_ptr getData() const override { + TRACE_EVENT; auto floatCount = rectPaints.size() * 2 * 4 * (hasColor ? 9 : 5); Buffer buffer(floatCount * sizeof(float)); auto vertices = reinterpret_cast(buffer.data()); @@ -101,6 +103,7 @@ class RectNonCoverageVerticesProvider : public DataProvider { } std::shared_ptr getData() const override { + TRACE_EVENT; auto floatCount = rectPaints.size() * 4 * (hasColor ? 8 : 4); Buffer buffer(floatCount * sizeof(float)); auto vertices = reinterpret_cast(buffer.data()); @@ -135,6 +138,7 @@ class RectNonCoverageVerticesProvider : public DataProvider { std::unique_ptr RectDrawOp::Make(std::optional color, const Rect& rect, const Matrix& viewMatrix, const Matrix* uvMatrix) { + TRACE_EVENT; return std::unique_ptr(new RectDrawOp(color, rect, viewMatrix, uvMatrix)); } @@ -168,6 +172,7 @@ bool RectDrawOp::needsIndexBuffer() const { } void RectDrawOp::prepare(Context* context, uint32_t renderFlags) { + TRACE_EVENT; if (needsIndexBuffer()) { if (aa == AAType::Coverage) { indexBufferProxy = context->resourceProvider()->aaQuadIndexBuffer(); @@ -191,6 +196,7 @@ void RectDrawOp::prepare(Context* context, uint32_t renderFlags) { } void RectDrawOp::execute(RenderPass* renderPass) { + TRACE_EVENT; std::shared_ptr indexBuffer; if (needsIndexBuffer()) { if (indexBufferProxy == nullptr) { diff --git a/src/gpu/ops/ShapeDrawOp.cpp b/src/gpu/ops/ShapeDrawOp.cpp index 43b8215e..36a2739e 100644 --- a/src/gpu/ops/ShapeDrawOp.cpp +++ b/src/gpu/ops/ShapeDrawOp.cpp @@ -20,6 +20,7 @@ #include "core/PathTriangulator.h" #include "core/shapes/MatrixShape.h" #include "core/utils/Log.h" +#include "core/utils/Profiling.h" #include "gpu/ProxyProvider.h" #include "gpu/Quad.h" #include "gpu/processors/DefaultGeometryProcessor.h" @@ -29,6 +30,7 @@ namespace tgfx { std::unique_ptr ShapeDrawOp::Make(Color color, std::shared_ptr shape, const Matrix& viewMatrix) { + TRACE_EVENT; if (shape == nullptr) { return nullptr; } @@ -60,6 +62,7 @@ bool ShapeDrawOp::onCombineIfPossible(Op*) { } void ShapeDrawOp::prepare(Context* context, uint32_t renderFlags) { + TRACE_EVENT; auto matrix = viewMatrix; auto scales = viewMatrix.getAxisScales(); if (scales.x == scales.y) { @@ -112,6 +115,7 @@ static std::shared_ptr MakeAAVertexData(const Rect& rect) { } void ShapeDrawOp::execute(RenderPass* renderPass) { + TRACE_EVENT; if (shapeProxy == nullptr) { return; } diff --git a/src/gpu/tasks/GpuBufferUploadTask.cpp b/src/gpu/tasks/GpuBufferUploadTask.cpp index c218418d..155c4415 100644 --- a/src/gpu/tasks/GpuBufferUploadTask.cpp +++ b/src/gpu/tasks/GpuBufferUploadTask.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "GpuBufferUploadTask.h" +#include "core/utils/Profiling.h" #include "tgfx/core/Task.h" namespace tgfx { @@ -35,6 +36,7 @@ GpuBufferUploadTask::GpuBufferUploadTask(UniqueKey uniqueKey, BufferType bufferT } std::shared_ptr GpuBufferUploadTask::onMakeResource(Context* context) { + TRACE_EVENT; if (provider == nullptr) { return nullptr; } diff --git a/src/gpu/tasks/OpsRenderTask.cpp b/src/gpu/tasks/OpsRenderTask.cpp index 2cdfd785..85a808f6 100644 --- a/src/gpu/tasks/OpsRenderTask.cpp +++ b/src/gpu/tasks/OpsRenderTask.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "OpsRenderTask.h" +#include "core/utils/Profiling.h" #include "gpu/Gpu.h" #include "gpu/RenderPass.h" @@ -29,6 +30,7 @@ void OpsRenderTask::addOp(std::unique_ptr op) { } void OpsRenderTask::prepare(Context* context) { + TRACE_EVENT_COLOR(TRACY_COLOR_GREEN); renderPass = context->gpu()->getRenderPass(); for (auto& op : ops) { op->prepare(context, renderFlags); @@ -36,6 +38,7 @@ void OpsRenderTask::prepare(Context* context) { } bool OpsRenderTask::execute(Gpu* gpu) { + TRACE_EVENT; if (ops.empty()) { return false; } diff --git a/src/gpu/tasks/RenderTargetCreateTask.cpp b/src/gpu/tasks/RenderTargetCreateTask.cpp index d8cc669d..b6f38427 100644 --- a/src/gpu/tasks/RenderTargetCreateTask.cpp +++ b/src/gpu/tasks/RenderTargetCreateTask.cpp @@ -18,6 +18,7 @@ #include "RenderTargetCreateTask.h" #include "core/utils/Log.h" +#include "core/utils/Profiling.h" #include "gpu/RenderTarget.h" #include "gpu/Texture.h" @@ -39,6 +40,7 @@ RenderTargetCreateTask::RenderTargetCreateTask(UniqueKey uniqueKey, UniqueKey te } std::shared_ptr RenderTargetCreateTask::onMakeResource(Context* context) { + TRACE_EVENT; auto texture = Resource::Find(context, textureKey); if (texture == nullptr) { LOGE("RenderTargetCreateTask::onMakeResource() Failed to get the associated texture!"); diff --git a/src/gpu/tasks/ResourceTask.cpp b/src/gpu/tasks/ResourceTask.cpp index db79e9cc..b069c0ec 100644 --- a/src/gpu/tasks/ResourceTask.cpp +++ b/src/gpu/tasks/ResourceTask.cpp @@ -17,12 +17,14 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "ResourceTask.h" +#include "core/utils/Profiling.h" namespace tgfx { ResourceTask::ResourceTask(UniqueKey uniqueKey) : uniqueKey(std::move(uniqueKey)) { } bool ResourceTask::execute(Context* context) { + TRACE_EVENT; if (uniqueKey.strongCount() <= 0) { // Skip the resource creation if there is no proxy is referencing it. return false; diff --git a/src/gpu/tasks/ShapeBufferUploadTask.cpp b/src/gpu/tasks/ShapeBufferUploadTask.cpp index b1d117c2..d3466bab 100644 --- a/src/gpu/tasks/ShapeBufferUploadTask.cpp +++ b/src/gpu/tasks/ShapeBufferUploadTask.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "ShapeBufferUploadTask.h" +#include "core/utils/Profiling.h" #include "gpu/GpuBuffer.h" #include "gpu/Texture.h" @@ -37,6 +38,7 @@ ShapeBufferUploadTask::ShapeBufferUploadTask(UniqueKey trianglesKey, UniqueKey t } bool ShapeBufferUploadTask::execute(Context* context) { + TRACE_EVENT; if (uniqueKey.strongCount() <= 0) { // Skip the resource creation if there is no proxy is referencing it. return false; diff --git a/src/gpu/tasks/TextureCreateTask.cpp b/src/gpu/tasks/TextureCreateTask.cpp index 1bc816ca..d76beab0 100644 --- a/src/gpu/tasks/TextureCreateTask.cpp +++ b/src/gpu/tasks/TextureCreateTask.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "TextureCreateTask.h" +#include "core/utils/Profiling.h" #include "gpu/Texture.h" namespace tgfx { @@ -37,6 +38,7 @@ TextureCreateTask::TextureCreateTask(UniqueKey uniqueKey, int width, int height, } std::shared_ptr TextureCreateTask::onMakeResource(Context* context) { + TRACE_EVENT; auto texture = Texture::MakeFormat(context, width, height, format, mipmapped, origin); if (texture == nullptr) { LOGE("TextureCreateTask::onMakeResource() Failed to create the texture!"); diff --git a/src/gpu/tasks/TextureUploadTask.cpp b/src/gpu/tasks/TextureUploadTask.cpp index 0d60bb67..d063809a 100644 --- a/src/gpu/tasks/TextureUploadTask.cpp +++ b/src/gpu/tasks/TextureUploadTask.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "TextureUploadTask.h" +#include "core/utils/Profiling.h" #include "gpu/Texture.h" namespace tgfx { @@ -35,6 +36,7 @@ TextureUploadTask::TextureUploadTask(UniqueKey uniqueKey, std::shared_ptr TextureUploadTask::onMakeResource(Context* context) { + TRACE_EVENT; if (decoder == nullptr) { return nullptr; } diff --git a/src/layers/DisplayList.cpp b/src/layers/DisplayList.cpp index 503edee1..a3cb23de 100644 --- a/src/layers/DisplayList.cpp +++ b/src/layers/DisplayList.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "tgfx/layers/DisplayList.h" +#include "core/utils/Profiling.h" #include "layers/DrawArgs.h" namespace tgfx { @@ -30,6 +31,7 @@ Layer* DisplayList::root() const { } bool DisplayList::render(Surface* surface, bool replaceAll) { + TRACE_EVENT; if (!surface || (replaceAll && surface->_uniqueID == surfaceID && surface->contentVersion() == surfaceContentVersion && !_root->bitFields.childrenDirty)) { diff --git a/src/layers/ImageLayer.cpp b/src/layers/ImageLayer.cpp index 4970da3a..2e82b743 100644 --- a/src/layers/ImageLayer.cpp +++ b/src/layers/ImageLayer.cpp @@ -17,10 +17,12 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "tgfx/layers/ImageLayer.h" +#include "core/utils/Profiling.h" #include "layers/contents/ImageContent.h" namespace tgfx { std::shared_ptr ImageLayer::Make() { + TRACE_EVENT; auto layer = std::shared_ptr(new ImageLayer()); layer->weakThis = layer; return layer; diff --git a/src/layers/Layer.cpp b/src/layers/Layer.cpp index aba1ea8a..525ce14f 100644 --- a/src/layers/Layer.cpp +++ b/src/layers/Layer.cpp @@ -21,6 +21,7 @@ #include "core/images/PictureImage.h" #include "core/utils/Log.h" #include "core/utils/MathExtra.h" +#include "core/utils/Profiling.h" #include "layers/DrawArgs.h" #include "layers/contents/RasterizedContent.h" #include "tgfx/core/Recorder.h" @@ -47,6 +48,7 @@ void Layer::SetDefaultAllowsGroupOpacity(bool value) { } std::shared_ptr Layer::Make() { + TRACE_EVENT_COLOR(TRACY_COLOR_YELLOW); auto layer = std::shared_ptr(new Layer()); layer->weakThis = layer; return layer; @@ -517,6 +519,7 @@ Matrix Layer::getMatrixWithScrollRect() const { } LayerContent* Layer::getContent() { + TRACE_EVENT; if (bitFields.contentDirty) { layerContent = onUpdateContent(); bitFields.contentDirty = false; @@ -613,6 +616,7 @@ std::shared_ptr Layer::getLayerContents(const DrawArgs& args, float con } void Layer::drawLayer(const DrawArgs& args, Canvas* canvas, float alpha, BlendMode blendMode) { + TRACE_EVENT; DEBUG_ASSERT(canvas != nullptr); if (auto rasterizedCache = getRasterizedCache(args)) { rasterizedCache->draw(canvas, getLayerPaint(alpha, blendMode)); @@ -684,6 +688,7 @@ void Layer::drawOffscreen(const DrawArgs& args, Canvas* canvas, float alpha, Ble } void Layer::drawContents(const DrawArgs& args, Canvas* canvas, float alpha) { + TRACE_EVENT; if (auto content = getContent()) { content->draw(canvas, getLayerPaint(alpha, BlendMode::SrcOver)); } diff --git a/src/layers/ShapeLayer.cpp b/src/layers/ShapeLayer.cpp index 389e754a..4fb7f4e0 100644 --- a/src/layers/ShapeLayer.cpp +++ b/src/layers/ShapeLayer.cpp @@ -17,12 +17,14 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "tgfx/layers/ShapeLayer.h" +#include "core/utils/Profiling.h" #include "layers/contents/ShapeContent.h" #include "tgfx/core/PathEffect.h" #include "tgfx/core/PathMeasure.h" namespace tgfx { std::shared_ptr ShapeLayer::Make() { + TRACE_EVENT; auto layer = std::shared_ptr(new ShapeLayer()); layer->weakThis = layer; return layer; diff --git a/src/layers/TextLayer.cpp b/src/layers/TextLayer.cpp index 759a2402..45c6a1ac 100644 --- a/src/layers/TextLayer.cpp +++ b/src/layers/TextLayer.cpp @@ -18,6 +18,7 @@ #include "tgfx/layers/TextLayer.h" #include "core/utils/Log.h" +#include "core/utils/Profiling.h" #include "layers/contents/TextContent.h" #include "tgfx/core/UTF.h" @@ -37,6 +38,7 @@ std::vector> GetFallbackTypefaces() { } std::shared_ptr TextLayer::Make() { + TRACE_EVENT; auto layer = std::shared_ptr(new TextLayer()); layer->weakThis = layer; return layer; @@ -168,6 +170,7 @@ std::unique_ptr TextLayer::onUpdateContent() { if (nullptr == textBlob) { return nullptr; } + return std::make_unique(std::move(textBlob), _textColor); } diff --git a/src/layers/contents/ComposeContent.cpp b/src/layers/contents/ComposeContent.cpp index 2c7e0b14..46d08af3 100644 --- a/src/layers/contents/ComposeContent.cpp +++ b/src/layers/contents/ComposeContent.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "ComposeContent.h" +#include "core/utils/Profiling.h" namespace tgfx { std::unique_ptr LayerContent::Compose( @@ -31,6 +32,7 @@ std::unique_ptr LayerContent::Compose( } Rect ComposeContent::getBounds() const { + TRACE_EVENT; auto bounds = Rect::MakeEmpty(); for (const auto& content : contents) { bounds.join(content->getBounds()); @@ -39,12 +41,14 @@ Rect ComposeContent::getBounds() const { } void ComposeContent::draw(Canvas* canvas, const Paint& paint) const { + TRACE_EVENT; for (const auto& content : contents) { content->draw(canvas, paint); } } bool ComposeContent::hitTestPoint(float localX, float localY, bool pixelHitTest) { + TRACE_EVENT; for (const auto& content : contents) { if (content->hitTestPoint(localX, localY, pixelHitTest)) { return true; diff --git a/src/layers/contents/ImageContent.cpp b/src/layers/contents/ImageContent.cpp index 893b13bf..2fb1c347 100644 --- a/src/layers/contents/ImageContent.cpp +++ b/src/layers/contents/ImageContent.cpp @@ -17,19 +17,22 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "ImageContent.h" +#include "core/utils/Profiling.h" namespace tgfx { Rect ImageContent::getBounds() const { + TRACE_EVENT; return Rect::MakeXYWH(0, 0, image->width(), image->height()); } void ImageContent::draw(Canvas* canvas, const Paint& paint) const { + TRACE_EVENT; canvas->drawImage(image, sampling, &paint); } bool ImageContent::hitTestPoint(float localX, float localY, bool /*pixelHitTest*/) { // The pixelHitTest flag is ignored because we cannot read pixels from images before they are drawn. - + TRACE_EVENT; const auto imageBounds = Rect::MakeXYWH(0, 0, image->width(), image->height()); return imageBounds.contains(localX, localY); } diff --git a/src/layers/contents/RasterizedContent.cpp b/src/layers/contents/RasterizedContent.cpp index 6582bf75..9ced4d2f 100644 --- a/src/layers/contents/RasterizedContent.cpp +++ b/src/layers/contents/RasterizedContent.cpp @@ -17,19 +17,23 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// #include "RasterizedContent.h" +#include "core/utils/Profiling.h" namespace tgfx { Rect RasterizedContent::getBounds() const { + TRACE_EVENT; auto bounds = Rect::MakeWH(image->width(), image->height()); matrix.mapRect(&bounds); return bounds; } void RasterizedContent::draw(Canvas* canvas, const Paint& paint) const { + TRACE_EVENT; canvas->drawImage(image, matrix, &paint); } bool RasterizedContent::hitTestPoint(float localX, float localY, bool) { + TRACE_EVENT; const auto imageBounds = Rect::MakeXYWH(0, 0, image->width(), image->height()); return imageBounds.contains(localX, localY); } diff --git a/src/layers/contents/ShapeContent.cpp b/src/layers/contents/ShapeContent.cpp index 345f832f..b6c4470f 100644 --- a/src/layers/contents/ShapeContent.cpp +++ b/src/layers/contents/ShapeContent.cpp @@ -24,12 +24,14 @@ ShapeContent::ShapeContent(std::shared_ptr shape, std::shared_ptr } void ShapeContent::draw(Canvas* canvas, const Paint& paint) const { + TRACE_EVENT; auto shapePaint = paint; shapePaint.setShader(shader); canvas->drawShape(shape, shapePaint); } bool ShapeContent::hitTestPoint(float localX, float localY, bool pixelHitTest) { + TRACE_EVENT; if (pixelHitTest) { auto path = shape->getPath(); return path.contains(localX, localY); diff --git a/src/layers/contents/ShapeContent.h b/src/layers/contents/ShapeContent.h index 02290d15..f8b48873 100644 --- a/src/layers/contents/ShapeContent.h +++ b/src/layers/contents/ShapeContent.h @@ -18,6 +18,7 @@ #pragma once +#include "core/utils/Profiling.h" #include "tgfx/core/Path.h" #include "tgfx/layers/LayerContent.h" @@ -27,6 +28,7 @@ class ShapeContent : public LayerContent { ShapeContent(std::shared_ptr shape, std::shared_ptr shader); Rect getBounds() const override { + TRACE_EVENT; return shape->getBounds(); } diff --git a/src/layers/contents/SolidContent.cpp b/src/layers/contents/SolidContent.cpp index ca74b42a..ebf81863 100644 --- a/src/layers/contents/SolidContent.cpp +++ b/src/layers/contents/SolidContent.cpp @@ -24,6 +24,7 @@ SolidContent::SolidContent(const RRect& rRect, const Color& color) : _rRect(rRec } void SolidContent::draw(Canvas* canvas, const Paint& paint) const { + TRACE_EVENT; auto solidPaint = paint; auto color = _color; color.alpha *= paint.getAlpha(); @@ -32,6 +33,7 @@ void SolidContent::draw(Canvas* canvas, const Paint& paint) const { } bool SolidContent::hitTestPoint(float localX, float localY, bool /*pixelHitTest*/) { + TRACE_EVENT; return _rRect.rect.contains(localX, localY); } diff --git a/src/layers/contents/SolidContent.h b/src/layers/contents/SolidContent.h index 347ded8f..54eb6f2a 100644 --- a/src/layers/contents/SolidContent.h +++ b/src/layers/contents/SolidContent.h @@ -18,6 +18,7 @@ #pragma once +#include "core/utils/Profiling.h" #include "tgfx/layers/LayerContent.h" namespace tgfx { diff --git a/src/layers/contents/TextContent.cpp b/src/layers/contents/TextContent.cpp index b57dead5..1313dee2 100644 --- a/src/layers/contents/TextContent.cpp +++ b/src/layers/contents/TextContent.cpp @@ -18,13 +18,16 @@ #include "TextContent.h" #include "core/GlyphRunList.h" +#include "core/utils/Profiling.h" namespace tgfx { Rect TextContent::getBounds() const { + TRACE_EVENT; return textBlob->getBounds(); } void TextContent::draw(Canvas* canvas, const Paint& paint) const { + TRACE_EVENT; auto textPaint = paint; auto color = textColor; color.alpha *= paint.getAlpha(); @@ -33,6 +36,7 @@ void TextContent::draw(Canvas* canvas, const Paint& paint) const { } bool TextContent::hitTestPoint(float localX, float localY, bool pixelHitTest) { + TRACE_EVENT; if (pixelHitTest) { const auto glyphRunLists = GlyphRunList::Unwrap(textBlob.get()); diff --git a/src/platform/android/NativeCodec.cpp b/src/platform/android/NativeCodec.cpp index 04292e6d..0a03c2d1 100644 --- a/src/platform/android/NativeCodec.cpp +++ b/src/platform/android/NativeCodec.cpp @@ -20,6 +20,7 @@ #include #include "NativeImageBuffer.h" #include "core/utils/Log.h" +#include "core/utils/Profiling.h" #include "platform/android/AHardwareBufferFunctions.h" #include "tgfx/core/Pixmap.h" #include "tgfx/platform/android/AndroidBitmap.h" @@ -321,6 +322,7 @@ bool NativeCodec::readPixels(const ImageInfo& dstInfo, void* dstPixels) const { } std::shared_ptr NativeCodec::onMakeBuffer(bool tryHardware) const { + TRACE_EVENT; JNIEnvironment environment; auto env = environment.current(); if (env == nullptr) { diff --git a/test/src/CanvasTest.cpp b/test/src/CanvasTest.cpp index 57032241..f85e96be 100644 --- a/test/src/CanvasTest.cpp +++ b/test/src/CanvasTest.cpp @@ -70,6 +70,7 @@ TGFX_TEST(CanvasTest, clip) { EXPECT_TRUE(Baseline::Compare(surface, "CanvasTest/Clip")); auto gl = GLFunctions::Get(context); gl->deleteTextures(1, &textureInfo.id); + device->unlock(); } diff --git a/test/src/LayerTest.cpp b/test/src/LayerTest.cpp index 6f5bc070..8adc2532 100644 --- a/test/src/LayerTest.cpp +++ b/test/src/LayerTest.cpp @@ -19,6 +19,7 @@ #include #include #include "core/filters/BlurImageFilter.h" +#include "core/utils/Profiling.h" #include "tgfx/core/PathEffect.h" #include "tgfx/layers/DisplayList.h" #include "tgfx/layers/Gradient.h" diff --git a/test/src/utils/Baseline.cpp b/test/src/utils/Baseline.cpp index 15ff7747..ccab6f61 100644 --- a/test/src/utils/Baseline.cpp +++ b/test/src/utils/Baseline.cpp @@ -23,6 +23,7 @@ #include #include #include "base/TGFXTest.h" +#include "core/utils/Profiling.h" #include "nlohmann/json.hpp" #include "tgfx/core/Data.h" #include "tgfx/core/ImageCodec.h" @@ -112,6 +113,7 @@ bool Baseline::Compare(std::shared_ptr pixelBuffer, const std::stri } bool Baseline::Compare(const std::shared_ptr surface, const std::string& key) { + TRACE_EVENT; if (surface == nullptr) { return false; } diff --git a/test/src/utils/DevicePool.cpp b/test/src/utils/DevicePool.cpp index 6d12a8f3..42e59499 100644 --- a/test/src/utils/DevicePool.cpp +++ b/test/src/utils/DevicePool.cpp @@ -19,11 +19,13 @@ #include "DevicePool.h" #include #include +#include "core/utils/Profiling.h" namespace tgfx { thread_local std::shared_ptr cachedDevice = nullptr; std::shared_ptr DevicePool::Make() { + TRACE_EVENT_COLOR(TRACY_COLOR_GREEN); auto device = cachedDevice; if (device == nullptr) { device = tgfx::GLDevice::Make(); diff --git a/vendor.json b/vendor.json index 7e607a55..1d3e53ca 100644 --- a/vendor.json +++ b/vendor.json @@ -24,6 +24,17 @@ ] } }, + { + "name": "tracy", + "cmake": { + "targets": [ + "TracyClient" + ], + "arguments": [ + "-DCMAKE_CXX_FLAGS=\"-w\"" + ] + } + }, { "name": "zlib", "cmake": {