Greg Daniel | fe71b9d | 2017-03-09 10:41:31 -0500 | [diff] [blame] | 1 | /* |
| 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 Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 10 | #include "GrContext.h" |
| 11 | #include "GrContextPriv.h" |
Greg Daniel | fe71b9d | 2017-03-09 10:41:31 -0500 | [diff] [blame] | 12 | #include "GrGpu.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 13 | #include "GrMemoryPool.h" |
Greg Daniel | fe71b9d | 2017-03-09 10:41:31 -0500 | [diff] [blame] | 14 | #include "GrOpFlushState.h" |
| 15 | |
| 16 | class GrSignalSemaphoreOp final : public GrSemaphoreOp { |
| 17 | public: |
| 18 | DEFINE_OP_CLASS_ID |
| 19 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 20 | static std::unique_ptr<GrOp> Make(GrContext* context, |
| 21 | sk_sp<GrSemaphore> semaphore, |
| 22 | GrRenderTargetProxy* proxy, |
| 23 | bool forceFlush) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 24 | GrOpMemoryPool* pool = context->contextPriv().opMemoryPool(); |
| 25 | |
| 26 | return pool->allocate<GrSignalSemaphoreOp>(std::move(semaphore), proxy, forceFlush); |
Greg Daniel | fe71b9d | 2017-03-09 10:41:31 -0500 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | const char* name() const override { return "SignalSemaphore"; } |
| 30 | |
| 31 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 32 | friend class GrOpMemoryPool; // for ctor |
| 33 | |
Greg Daniel | a2cebd8 | 2017-06-21 16:09:50 -0400 | [diff] [blame] | 34 | explicit GrSignalSemaphoreOp(sk_sp<GrSemaphore> semaphore, GrRenderTargetProxy* proxy, |
| 35 | bool forceFlush) |
| 36 | : INHERITED(ClassID(), std::move(semaphore), proxy), fForceFlush(forceFlush) {} |
Greg Daniel | fe71b9d | 2017-03-09 10:41:31 -0500 | [diff] [blame] | 37 | |
| 38 | void onExecute(GrOpFlushState* state) override { |
Greg Daniel | a2cebd8 | 2017-06-21 16:09:50 -0400 | [diff] [blame] | 39 | state->gpu()->insertSemaphore(fSemaphore, fForceFlush); |
Greg Daniel | fe71b9d | 2017-03-09 10:41:31 -0500 | [diff] [blame] | 40 | } |
| 41 | |
Greg Daniel | a2cebd8 | 2017-06-21 16:09:50 -0400 | [diff] [blame] | 42 | bool fForceFlush; |
| 43 | |
Greg Daniel | fe71b9d | 2017-03-09 10:41:31 -0500 | [diff] [blame] | 44 | typedef GrSemaphoreOp INHERITED; |
| 45 | }; |
| 46 | |
| 47 | class GrWaitSemaphoreOp final : public GrSemaphoreOp { |
| 48 | public: |
| 49 | DEFINE_OP_CLASS_ID |
| 50 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 51 | static std::unique_ptr<GrOp> Make(GrContext* context, |
| 52 | sk_sp<GrSemaphore> semaphore, |
| 53 | GrRenderTargetProxy* proxy) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 54 | GrOpMemoryPool* pool = context->contextPriv().opMemoryPool(); |
| 55 | |
| 56 | return pool->allocate<GrWaitSemaphoreOp>(std::move(semaphore), proxy); |
Greg Daniel | fe71b9d | 2017-03-09 10:41:31 -0500 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | const char* name() const override { return "WaitSemaphore"; } |
| 60 | |
| 61 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 62 | friend class GrOpMemoryPool; // for ctor |
| 63 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 64 | explicit GrWaitSemaphoreOp(sk_sp<GrSemaphore> semaphore, GrRenderTargetProxy* proxy) |
| 65 | : INHERITED(ClassID(), std::move(semaphore), proxy) {} |
Greg Daniel | fe71b9d | 2017-03-09 10:41:31 -0500 | [diff] [blame] | 66 | |
| 67 | void onExecute(GrOpFlushState* state) override { |
| 68 | state->gpu()->waitSemaphore(fSemaphore); |
| 69 | } |
| 70 | |
| 71 | typedef GrSemaphoreOp INHERITED; |
| 72 | }; |
| 73 | |
| 74 | //////////////////////////////////////////////////////////////////////////////// |
| 75 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 76 | std::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 Daniel | fe71b9d | 2017-03-09 10:41:31 -0500 | [diff] [blame] | 81 | } |
| 82 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 83 | std::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 Daniel | fe71b9d | 2017-03-09 10:41:31 -0500 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | |