5#ifndef FLUTTER_FLOW_SKIA_GPU_OBJECT_H_
6#define FLUTTER_FLOW_SKIA_GPU_OBJECT_H_
11#include "flutter/common/macros.h"
12#include "flutter/fml/memory/ref_counted.h"
13#include "flutter/fml/memory/weak_ptr.h"
14#include "flutter/fml/task_runner.h"
15#include "flutter/fml/trace_event.h"
31 if (drain_immediate_) {
35 std::scoped_lock lock(mutex_);
36 objects_.push_back(
object);
37 if (!drain_pending_) {
38 drain_pending_ =
true;
40 [strong =
fml::Ref(
this)]() { strong->Drain(); }, drain_delay_);
48 std::scoped_lock lock(mutex_);
50 if (!drain_pending_) {
51 drain_pending_ =
true;
53 [strong =
fml::Ref(
this)]() { strong->Drain(); }, drain_delay_);
65 std::deque<SkRefCnt*> skia_objects;
67 NOT_SLIMPELLER(std::deque<GrBackendTexture> textures);
70 std::scoped_lock lock(mutex_);
71 objects_.swap(skia_objects);
72 NOT_SLIMPELLER(textures_.swap(textures));
73 drain_pending_ =
false;
90 std::deque<SkRefCnt*> objects_;
91 NOT_SLIMPELLER(std::deque<GrBackendTexture> textures_);
92 bool drain_pending_ =
false;
96 bool drain_immediate_;
104 bool drain_immediate =
false)
105 : task_runner_(
std::move(task_runner)),
108 drain_immediate_(drain_immediate) {}
116 task_runner_, [objects = std::move(objects_),
118 textures = std::move(textures_),
120 raw_context]()
mutable {
132 static void DoDrain(
const std::deque<SkRefCnt*>& skia_objects,
134 const std::deque<GrBackendTexture>& textures,
137 for (
SkRefCnt* skia_object : skia_objects) {
138 skia_object->unref();
144 context->deleteBackendTexture(
texture);
147 if (!skia_objects.empty()) {
148 context->performDeferredCleanup(std::chrono::milliseconds(0));
156 FML_FRIEND_REF_COUNTED_THREAD_SAFE(UnrefQueue);
157 FML_FRIEND_MAKE_REF_COUNTED(UnrefQueue);
158 FML_DISALLOW_COPY_AND_ASSIGN(UnrefQueue);
172 : object_(
std::move(object)), queue_(
std::move(
queue)) {
183 if (object_ && queue_) {
184 queue_->Unref(object_.
release());
sk_sp< SkiaObjectType > skia_object() const
SkiaGPUObject(SkiaGPUObject &&)=default
SkiaGPUObject(sk_sp< SkiaObjectType > object, fml::RefPtr< SkiaUnrefQueue > queue)
SkiaGPUObject & operator=(SkiaGPUObject &&)=default
void DeleteTexture(const GrBackendTexture &texture)
void UpdateResourceContext(sk_sp< ResourceContext > context)
void Unref(SkRefCnt *object)
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
virtual void PostDelayedTask(const fml::closure &task, fml::TimeDelta delay)
#define FML_DCHECK(condition)
#define TRACE_EVENT0(category_group, name)