Flutter Engine
skia_gpu_object.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/flow/skia_gpu_object.h"
6 
7 #include "flutter/fml/message_loop.h"
8 #include "flutter/fml/trace_event.h"
9 
10 namespace flutter {
11 
12 SkiaUnrefQueue::SkiaUnrefQueue(fml::RefPtr<fml::TaskRunner> task_runner,
13  fml::TimeDelta delay,
15  : task_runner_(std::move(task_runner)),
16  drain_delay_(delay),
17  drain_pending_(false),
18  context_(context) {}
19 
20 SkiaUnrefQueue::~SkiaUnrefQueue() {
21  FML_DCHECK(objects_.empty());
22 }
23 
24 void SkiaUnrefQueue::Unref(SkRefCnt* object) {
25  std::scoped_lock lock(mutex_);
26  objects_.push_back(object);
27  if (!drain_pending_) {
28  drain_pending_ = true;
29  task_runner_->PostDelayedTask(
30  [strong = fml::Ref(this)]() { strong->Drain(); }, drain_delay_);
31  }
32 }
33 
35  TRACE_EVENT0("flutter", "SkiaUnrefQueue::Drain");
36  std::deque<SkRefCnt*> skia_objects;
37  {
38  std::scoped_lock lock(mutex_);
39  objects_.swap(skia_objects);
40  drain_pending_ = false;
41  }
42 
43  for (SkRefCnt* skia_object : skia_objects) {
44  skia_object->unref();
45  }
46 
47  if (context_ && skia_objects.size() > 0) {
48  context_->performDeferredCleanup(std::chrono::milliseconds(0));
49  }
50 }
51 
52 } // namespace flutter
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
#define FML_DCHECK(condition)
Definition: logging.h:86
void Unref(SkRefCnt *object)
Definition: ref_ptr.h:252
RefPtr< T > Ref(T *ptr)
Definition: ref_ptr.h:233