blob: 9beb2a606b991d9cb14e30635305d82f8a36ad9b [file] [log] [blame]
Greg Danielfe71b9d2017-03-09 10:41:31 -05001/*
2 * Copyright 2017 Google Inc.
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 "GrSemaphoreOp.h"
9
Robert Phillips7c525e62018-06-12 10:11:12 -040010#include "GrContext.h"
11#include "GrContextPriv.h"
Greg Danielfe71b9d2017-03-09 10:41:31 -050012#include "GrGpu.h"
Robert Phillips7c525e62018-06-12 10:11:12 -040013#include "GrMemoryPool.h"
Greg Danielfe71b9d2017-03-09 10:41:31 -050014#include "GrOpFlushState.h"
15
16class GrSignalSemaphoreOp final : public GrSemaphoreOp {
17public:
18 DEFINE_OP_CLASS_ID
19
Robert Phillips7c525e62018-06-12 10:11:12 -040020 static std::unique_ptr<GrOp> Make(GrContext* context,
21 sk_sp<GrSemaphore> semaphore,
22 GrRenderTargetProxy* proxy,
23 bool forceFlush) {
Robert Phillipsc994a932018-06-19 13:09:54 -040024 GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
25
26 return pool->allocate<GrSignalSemaphoreOp>(std::move(semaphore), proxy, forceFlush);
Greg Danielfe71b9d2017-03-09 10:41:31 -050027 }
28
29 const char* name() const override { return "SignalSemaphore"; }
30
31private:
Robert Phillips7c525e62018-06-12 10:11:12 -040032 friend class GrOpMemoryPool; // for ctor
33
Greg Daniela2cebd82017-06-21 16:09:50 -040034 explicit GrSignalSemaphoreOp(sk_sp<GrSemaphore> semaphore, GrRenderTargetProxy* proxy,
35 bool forceFlush)
36 : INHERITED(ClassID(), std::move(semaphore), proxy), fForceFlush(forceFlush) {}
Greg Danielfe71b9d2017-03-09 10:41:31 -050037
38 void onExecute(GrOpFlushState* state) override {
Greg Daniela2cebd82017-06-21 16:09:50 -040039 state->gpu()->insertSemaphore(fSemaphore, fForceFlush);
Greg Danielfe71b9d2017-03-09 10:41:31 -050040 }
41
Greg Daniela2cebd82017-06-21 16:09:50 -040042 bool fForceFlush;
43
Greg Danielfe71b9d2017-03-09 10:41:31 -050044 typedef GrSemaphoreOp INHERITED;
45};
46
47class GrWaitSemaphoreOp final : public GrSemaphoreOp {
48public:
49 DEFINE_OP_CLASS_ID
50
Robert Phillips7c525e62018-06-12 10:11:12 -040051 static std::unique_ptr<GrOp> Make(GrContext* context,
52 sk_sp<GrSemaphore> semaphore,
53 GrRenderTargetProxy* proxy) {
Robert Phillipsc994a932018-06-19 13:09:54 -040054 GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
55
56 return pool->allocate<GrWaitSemaphoreOp>(std::move(semaphore), proxy);
Greg Danielfe71b9d2017-03-09 10:41:31 -050057 }
58
59 const char* name() const override { return "WaitSemaphore"; }
60
61private:
Robert Phillips7c525e62018-06-12 10:11:12 -040062 friend class GrOpMemoryPool; // for ctor
63
Greg Daniela5cb7812017-06-16 09:45:32 -040064 explicit GrWaitSemaphoreOp(sk_sp<GrSemaphore> semaphore, GrRenderTargetProxy* proxy)
65 : INHERITED(ClassID(), std::move(semaphore), proxy) {}
Greg Danielfe71b9d2017-03-09 10:41:31 -050066
67 void onExecute(GrOpFlushState* state) override {
68 state->gpu()->waitSemaphore(fSemaphore);
69 }
70
71 typedef GrSemaphoreOp INHERITED;
72};
73
74////////////////////////////////////////////////////////////////////////////////
75
Robert Phillips7c525e62018-06-12 10:11:12 -040076std::unique_ptr<GrOp> GrSemaphoreOp::MakeSignal(GrContext* context,
77 sk_sp<GrSemaphore> semaphore,
78 GrRenderTargetProxy* proxy,
79 bool forceFlush) {
80 return GrSignalSemaphoreOp::Make(context, std::move(semaphore), proxy, forceFlush);
Greg Danielfe71b9d2017-03-09 10:41:31 -050081}
82
Robert Phillips7c525e62018-06-12 10:11:12 -040083std::unique_ptr<GrOp> GrSemaphoreOp::MakeWait(GrContext* context,
84 sk_sp<GrSemaphore> semaphore,
85 GrRenderTargetProxy* proxy) {
86 return GrWaitSemaphoreOp::Make(context, std::move(semaphore), proxy);
Greg Danielfe71b9d2017-03-09 10:41:31 -050087}
88
89