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 10#include "GrGpu.h" 11#include "GrOpFlushState.h" 12 13class GrSignalSemaphoreOp final : public GrSemaphoreOp { 14public: 15 DEFINE_OP_CLASS_ID 16 17 static std::unique_ptr<GrSignalSemaphoreOp> Make(sk_sp<GrSemaphore> semaphore, 18 GrRenderTargetProxy* proxy, 19 bool forceFlush) { 20 return std::unique_ptr<GrSignalSemaphoreOp>(new GrSignalSemaphoreOp(std::move(semaphore), 21 proxy, 22 forceFlush)); 23 } 24 25 const char* name() const override { return "SignalSemaphore"; } 26 27private: 28 explicit GrSignalSemaphoreOp(sk_sp<GrSemaphore> semaphore, GrRenderTargetProxy* proxy, 29 bool forceFlush) 30 : INHERITED(ClassID(), std::move(semaphore), proxy), fForceFlush(forceFlush) {} 31 32 void onExecute(GrOpFlushState* state) override { 33 state->gpu()->insertSemaphore(fSemaphore, fForceFlush); 34 } 35 36 bool fForceFlush; 37 38 typedef GrSemaphoreOp INHERITED; 39}; 40 41class GrWaitSemaphoreOp final : public GrSemaphoreOp { 42public: 43 DEFINE_OP_CLASS_ID 44 45 static std::unique_ptr<GrWaitSemaphoreOp> Make(sk_sp<GrSemaphore> semaphore, 46 GrRenderTargetProxy* proxy) { 47 return std::unique_ptr<GrWaitSemaphoreOp>(new GrWaitSemaphoreOp(std::move(semaphore), 48 proxy)); 49 } 50 51 const char* name() const override { return "WaitSemaphore"; } 52 53private: 54 explicit GrWaitSemaphoreOp(sk_sp<GrSemaphore> semaphore, GrRenderTargetProxy* proxy) 55 : INHERITED(ClassID(), std::move(semaphore), proxy) {} 56 57 void onExecute(GrOpFlushState* state) override { 58 state->gpu()->waitSemaphore(fSemaphore); 59 } 60 61 typedef GrSemaphoreOp INHERITED; 62}; 63 64//////////////////////////////////////////////////////////////////////////////// 65 66std::unique_ptr<GrSemaphoreOp> GrSemaphoreOp::MakeSignal(sk_sp<GrSemaphore> semaphore, 67 GrRenderTargetProxy* proxy, 68 bool forceFlush) { 69 return GrSignalSemaphoreOp::Make(std::move(semaphore), proxy, forceFlush); 70} 71 72std::unique_ptr<GrSemaphoreOp> GrSemaphoreOp::MakeWait(sk_sp<GrSemaphore> semaphore, 73 GrRenderTargetProxy* proxy) { 74 return GrWaitSemaphoreOp::Make(std::move(semaphore), proxy); 75} 76 77 78