|
| 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 | +#include "flutter/fml/message_loop.h" |
| 7 | +#include "flutter/fml/synchronization/waitable_event.h" |
| 8 | +#include "flutter/fml/task_runner.h" |
| 9 | +#include "flutter/testing/thread_test.h" |
| 10 | +#include "gtest/gtest.h" |
| 11 | +#include "third_party/skia/include/core/SkRefCnt.h" |
| 12 | + |
| 13 | +namespace flutter { |
| 14 | +namespace testing { |
| 15 | + |
| 16 | +using SkiaGpuObjectTest = flutter::testing::ThreadTest; |
| 17 | + |
| 18 | +class TestSkObject : public SkRefCnt { |
| 19 | + public: |
| 20 | + TestSkObject(std::shared_ptr<fml::AutoResetWaitableEvent> latch, |
| 21 | + fml::TaskQueueId* dtor_task_queue_id) |
| 22 | + : latch_(latch), dtor_task_queue_id_(dtor_task_queue_id) {} |
| 23 | + |
| 24 | + ~TestSkObject() { |
| 25 | + *dtor_task_queue_id_ = fml::MessageLoop::GetCurrentTaskQueueId(); |
| 26 | + latch_->Signal(); |
| 27 | + } |
| 28 | + |
| 29 | + private: |
| 30 | + std::shared_ptr<fml::AutoResetWaitableEvent> latch_; |
| 31 | + fml::TaskQueueId* dtor_task_queue_id_; |
| 32 | +}; |
| 33 | + |
| 34 | +TEST_F(SkiaGpuObjectTest, UnrefQueue) { |
| 35 | + fml::RefPtr<fml::TaskRunner> task_runner = CreateNewThread(); |
| 36 | + fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>( |
| 37 | + task_runner, fml::TimeDelta::FromSeconds(0)); |
| 38 | + |
| 39 | + std::shared_ptr<fml::AutoResetWaitableEvent> latch = |
| 40 | + std::make_shared<fml::AutoResetWaitableEvent>(); |
| 41 | + fml::TaskQueueId dtor_task_queue_id(0); |
| 42 | + SkRefCnt* ref_object = new TestSkObject(latch, &dtor_task_queue_id); |
| 43 | + |
| 44 | + queue->Unref(ref_object); |
| 45 | + latch->Wait(); |
| 46 | + ASSERT_EQ(dtor_task_queue_id, task_runner->GetTaskQueueId()); |
| 47 | +} |
| 48 | + |
| 49 | +} // namespace testing |
| 50 | +} // namespace flutter |
0 commit comments