• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "experimental/graphite/src/Recorder.h"
9 
10 #include "experimental/graphite/include/Context.h"
11 #include "experimental/graphite/src/CommandBuffer.h"
12 #include "experimental/graphite/src/ContextPriv.h"
13 #include "experimental/graphite/src/DrawBufferManager.h"
14 #include "experimental/graphite/src/Gpu.h"
15 #include "experimental/graphite/src/ProgramCache.h"
16 #include "experimental/graphite/src/Recording.h"
17 #include "experimental/graphite/src/ResourceProvider.h"
18 #include "experimental/graphite/src/UniformCache.h"
19 
20 namespace skgpu {
21 
Recorder(sk_sp<Context> context)22 Recorder::Recorder(sk_sp<Context> context)
23     : fContext(std::move(context))
24     , fProgramCache(new ProgramCache)
25     , fUniformCache(new UniformCache)
26     // TODO: Is '4' the correct initial alignment?
27     , fDrawBufferManager(new DrawBufferManager(fContext->priv().gpu()->resourceProvider(), 4)) {
28 }
29 
~Recorder()30 Recorder::~Recorder() {}
31 
context() const32 Context* Recorder::context() const {
33     return fContext.get();
34 }
35 
programCache()36 ProgramCache* Recorder::programCache() {
37     return fProgramCache.get();
38 }
39 
uniformCache()40 UniformCache* Recorder::uniformCache() {
41     return fUniformCache.get();
42 }
43 
drawBufferManager()44 DrawBufferManager* Recorder::drawBufferManager() {
45     return fDrawBufferManager.get();
46 }
47 
add(sk_sp<Task> task)48 void Recorder::add(sk_sp<Task> task) {
49     fGraph.add(std::move(task));
50 }
51 
snap()52 std::unique_ptr<Recording> Recorder::snap() {
53     auto gpu = fContext->priv().gpu();
54     auto commandBuffer = gpu->resourceProvider()->createCommandBuffer();
55 
56     fGraph.addCommands(gpu->resourceProvider(), commandBuffer.get());
57     fDrawBufferManager->transferToCommandBuffer(commandBuffer.get());
58 
59     fGraph.reset();
60     return std::unique_ptr<Recording>(new Recording(std::move(commandBuffer)));
61 }
62 
63 } // namespace skgpu
64