Reland "Reland "cache the creation of one GrAtlasTextOp""
This is a reland of dc3d67871202ce55ecbfbee761fe1d981254a3a1
All previous attempts tried to use variants of
thread_local std::unique_ptr<char> gCache;
This did not work on Android or Flutter because thread_local
variables with dtors failed in various ways.
This CL keep the cache from leaking bytes by clearing the
cache in the GrRecordingContext's destructor.
Original change's description:
> Reland "cache the creation of one GrAtlasTextOp"
>
> This is a reland of 4b1fb7ca90a589260bf8044393a6970f947302a0
>
> Original change's description:
> > cache the creation of one GrAtlasTextOp
> >
> > GrAtlasTextOp has a high probability of being merged with the
> > previous op. This cache keeps using the same op to merge with
> > keeping memory warm.
> >
> > This show about 5.75% improvement in skpbench on desk_nytimes.
> >
> > When compiling for ios 9 or earlier, this optimization is
> > disabled.
> >
> > Change-Id: I13ccbef6dcd4b9d82103bf20bba7d94f3e4fb6f4
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/376718
> > Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Herb Derby <herb@google.com>
>
> Change-Id: I935a2965062b1fddb28806e85eb0fe055ba46ec2
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380320
> Commit-Queue: Herb Derby <herb@google.com>
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Change-Id: I62f572583524c506488ba982f5047a8f0126f3dc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/382701
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp
index fcb28c6..3b037ba 100644
--- a/src/gpu/ops/GrAtlasTextOp.cpp
+++ b/src/gpu/ops/GrAtlasTextOp.cpp
@@ -31,7 +31,33 @@
#include "src/gpu/GrDrawOpTest.h"
#endif
-///////////////////////////////////////////////////////////////////////////////////////////////////
+#include <new>
+#include <utility>
+
+// If we have thread local, then cache memory for a single GrAtlasTextOp.
+#if !defined(GR_OP_ALLOCATE_USE_POOL) && defined(GR_HAS_THREAD_LOCAL)
+static thread_local void* gCache = nullptr;
+void* GrAtlasTextOp::operator new(size_t s) {
+ if (gCache != nullptr) {
+ return std::exchange(gCache, nullptr);
+ }
+
+ return ::operator new(s);
+}
+
+void GrAtlasTextOp::operator delete(void* bytes) noexcept {
+ if (gCache == nullptr) {
+ gCache = bytes;
+ return;
+ }
+ ::operator delete(bytes);
+}
+
+void GrAtlasTextOp::ClearCache() {
+ ::operator delete(gCache);
+ gCache = nullptr;
+}
+#endif
GrAtlasTextOp::GrAtlasTextOp(MaskType maskType,
bool needsTransform,