Skip to content

Commit dd393ff

Browse files
authored
[Impeller] Add implementations for concurrent work-queues. (flutter#35355)
1 parent fc9d020 commit dd393ff

File tree

15 files changed

+271
-10
lines changed

15 files changed

+271
-10
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ FILE: ../../../flutter/impeller/base/base_unittests.cc
450450
FILE: ../../../flutter/impeller/base/comparable.cc
451451
FILE: ../../../flutter/impeller/base/comparable.h
452452
FILE: ../../../flutter/impeller/base/config.h
453+
FILE: ../../../flutter/impeller/base/platform/darwin/work_queue_darwin.cc
454+
FILE: ../../../flutter/impeller/base/platform/darwin/work_queue_darwin.h
453455
FILE: ../../../flutter/impeller/base/promise.cc
454456
FILE: ../../../flutter/impeller/base/promise.h
455457
FILE: ../../../flutter/impeller/base/strings.cc
@@ -462,6 +464,10 @@ FILE: ../../../flutter/impeller/base/validation.cc
462464
FILE: ../../../flutter/impeller/base/validation.h
463465
FILE: ../../../flutter/impeller/base/version.cc
464466
FILE: ../../../flutter/impeller/base/version.h
467+
FILE: ../../../flutter/impeller/base/work_queue.cc
468+
FILE: ../../../flutter/impeller/base/work_queue.h
469+
FILE: ../../../flutter/impeller/base/work_queue_common.cc
470+
FILE: ../../../flutter/impeller/base/work_queue_common.h
465471
FILE: ../../../flutter/impeller/blobcat/blob.cc
466472
FILE: ../../../flutter/impeller/blobcat/blob.h
467473
FILE: ../../../flutter/impeller/blobcat/blob_library.cc

impeller/base/BUILD.gn

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,19 @@ impeller_component("base") {
2424
"validation.h",
2525
"version.cc",
2626
"version.h",
27+
"work_queue.cc",
28+
"work_queue.h",
29+
"work_queue_common.cc",
30+
"work_queue_common.h",
2731
]
2832

33+
if (is_ios || is_mac) {
34+
sources += [
35+
"platform/darwin/work_queue_darwin.cc",
36+
"platform/darwin/work_queue_darwin.h",
37+
]
38+
}
39+
2940
deps = [ "//flutter/fml" ]
3041
}
3142

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 "impeller/base/platform/darwin/work_queue_darwin.h"
6+
7+
namespace impeller {
8+
9+
std::shared_ptr<WorkQueueDarwin> WorkQueueDarwin::Create() {
10+
auto queue = std::shared_ptr<WorkQueueDarwin>(new WorkQueueDarwin());
11+
if (!queue->IsValid()) {
12+
return nullptr;
13+
}
14+
return queue;
15+
}
16+
17+
WorkQueueDarwin::WorkQueueDarwin()
18+
: queue_(::dispatch_queue_create(
19+
"io.flutter.impeller.wq",
20+
::dispatch_queue_attr_make_with_qos_class(
21+
DISPATCH_QUEUE_CONCURRENT_WITH_AUTORELEASE_POOL,
22+
QOS_CLASS_USER_INITIATED,
23+
-1))) {}
24+
25+
WorkQueueDarwin::~WorkQueueDarwin() = default;
26+
27+
bool WorkQueueDarwin::IsValid() const {
28+
return queue_ != NULL;
29+
}
30+
31+
// |WorkQueue|
32+
void WorkQueueDarwin::PostTask(fml::closure task) {
33+
dispatch_async(queue_, ^() {
34+
task();
35+
});
36+
}
37+
38+
} // namespace impeller
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
#pragma once
6+
7+
#include <dispatch/dispatch.h>
8+
9+
#include <memory>
10+
11+
#include "flutter/fml/macros.h"
12+
#include "impeller/base/work_queue.h"
13+
14+
namespace impeller {
15+
16+
class WorkQueueDarwin final : public WorkQueue {
17+
public:
18+
static std::shared_ptr<WorkQueueDarwin> Create();
19+
20+
// |WorkQueue|
21+
~WorkQueueDarwin();
22+
23+
bool IsValid() const;
24+
25+
private:
26+
dispatch_queue_t queue_ = NULL;
27+
28+
WorkQueueDarwin();
29+
30+
// |WorkQueue|
31+
void PostTask(fml::closure task) override;
32+
33+
FML_DISALLOW_COPY_AND_ASSIGN(WorkQueueDarwin);
34+
};
35+
36+
} // namespace impeller

impeller/base/work_queue.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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/impeller/base/work_queue.h"
6+
7+
namespace impeller {
8+
9+
WorkQueue::WorkQueue() = default;
10+
11+
WorkQueue::~WorkQueue() = default;
12+
13+
} // namespace impeller

impeller/base/work_queue.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
#pragma once
6+
7+
#include <memory>
8+
9+
#include "flutter/fml/closure.h"
10+
#include "flutter/fml/macros.h"
11+
12+
namespace impeller {
13+
14+
class WorkQueue : public std::enable_shared_from_this<WorkQueue> {
15+
public:
16+
virtual ~WorkQueue();
17+
18+
virtual void PostTask(fml::closure task) = 0;
19+
20+
protected:
21+
WorkQueue();
22+
23+
private:
24+
FML_DISALLOW_COPY_AND_ASSIGN(WorkQueue);
25+
};
26+
27+
} // namespace impeller

impeller/base/work_queue_common.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 "impeller/base/work_queue_common.h"
6+
7+
namespace impeller {
8+
9+
std::shared_ptr<WorkQueueCommon> WorkQueueCommon::Create() {
10+
return std::shared_ptr<WorkQueueCommon>(new WorkQueueCommon());
11+
}
12+
13+
WorkQueueCommon::WorkQueueCommon()
14+
: loop_(fml::ConcurrentMessageLoop::Create(2u)) {}
15+
16+
WorkQueueCommon::~WorkQueueCommon() {
17+
loop_->Terminate();
18+
}
19+
20+
// |WorkQueue|
21+
void WorkQueueCommon::PostTask(fml::closure task) {
22+
loop_->GetTaskRunner()->PostTask(std::move(task));
23+
}
24+
25+
} // namespace impeller

impeller/base/work_queue_common.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
#pragma once
6+
7+
#include <memory>
8+
9+
#include "flutter/fml/concurrent_message_loop.h"
10+
#include "flutter/fml/macros.h"
11+
#include "impeller/base/work_queue.h"
12+
13+
namespace impeller {
14+
15+
class WorkQueueCommon : public WorkQueue {
16+
public:
17+
static std::shared_ptr<WorkQueueCommon> Create();
18+
19+
// |WorkQueue|
20+
~WorkQueueCommon();
21+
22+
private:
23+
std::shared_ptr<fml::ConcurrentMessageLoop> loop_;
24+
25+
WorkQueueCommon();
26+
27+
// |WorkQueue|
28+
void PostTask(fml::closure task) override;
29+
30+
FML_DISALLOW_COPY_AND_ASSIGN(WorkQueueCommon);
31+
};
32+
33+
} // namespace impeller

impeller/renderer/backend/gles/context_gles.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "impeller/base/config.h"
88
#include "impeller/base/validation.h"
9+
#include "impeller/base/work_queue_common.h"
910

1011
namespace impeller {
1112

@@ -52,12 +53,21 @@ ContextGLES::ContextGLES(
5253
}
5354
}
5455

55-
// Create the sampler library
56+
// Create the sampler library.
5657
{
5758
sampler_library_ =
5859
std::shared_ptr<SamplerLibraryGLES>(new SamplerLibraryGLES());
5960
}
6061

62+
// Create the work queue.
63+
{
64+
work_queue_ = WorkQueueCommon::Create();
65+
if (!work_queue_) {
66+
VALIDATION_LOG << "Could not create work queue.";
67+
return;
68+
}
69+
}
70+
6171
is_valid_ = true;
6272
}
6373

@@ -86,27 +96,37 @@ bool ContextGLES::IsValid() const {
8696
return is_valid_;
8797
}
8898

99+
// |Context|
89100
std::shared_ptr<Allocator> ContextGLES::GetResourceAllocator() const {
90101
return resource_allocator_;
91102
}
92103

104+
// |Context|
93105
std::shared_ptr<ShaderLibrary> ContextGLES::GetShaderLibrary() const {
94106
return shader_library_;
95107
}
96108

109+
// |Context|
97110
std::shared_ptr<SamplerLibrary> ContextGLES::GetSamplerLibrary() const {
98111
return sampler_library_;
99112
}
100113

114+
// |Context|
101115
std::shared_ptr<PipelineLibrary> ContextGLES::GetPipelineLibrary() const {
102116
return pipeline_library_;
103117
}
104118

119+
// |Context|
105120
std::shared_ptr<CommandBuffer> ContextGLES::CreateCommandBuffer() const {
106121
return std::shared_ptr<CommandBufferGLES>(
107122
new CommandBufferGLES(weak_from_this(), reactor_));
108123
}
109124

125+
// |Context|
126+
std::shared_ptr<WorkQueue> ContextGLES::GetWorkQueue() const {
127+
return work_queue_;
128+
}
129+
110130
// |Context|
111131
bool ContextGLES::HasThreadingRestrictions() const {
112132
return true;

impeller/renderer/backend/gles/context_gles.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ContextGLES final : public Context,
3838
std::shared_ptr<ShaderLibraryGLES> shader_library_;
3939
std::shared_ptr<PipelineLibraryGLES> pipeline_library_;
4040
std::shared_ptr<SamplerLibraryGLES> sampler_library_;
41+
std::shared_ptr<WorkQueue> work_queue_;
4142
std::shared_ptr<AllocatorGLES> resource_allocator_;
4243
bool is_valid_ = false;
4344

@@ -62,6 +63,9 @@ class ContextGLES final : public Context,
6263
// |Context|
6364
std::shared_ptr<CommandBuffer> CreateCommandBuffer() const override;
6465

66+
// |Context|
67+
std::shared_ptr<WorkQueue> GetWorkQueue() const override;
68+
6569
// |Context|
6670
bool HasThreadingRestrictions() const override;
6771

0 commit comments

Comments
 (0)