2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "GrProgramElement.h"
9 #include "GrGpuResourceRef.h"
11 uint32_t GrProgramElement::CreateUniqueID() {
12 static int32_t gUniqueID = SK_InvalidUniqueID;
15 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
16 } while (id == SK_InvalidUniqueID);
20 void GrProgramElement::convertRefToPendingExecution() const {
21 // This function makes it so that all the GrGpuResourceRefs own a single ref to their
22 // underlying GrGpuResource if there are any refs to the GrProgramElement and a single
23 // pending read/write if there are any pending executions of the GrProgramElement. The
24 // GrGpuResourceRef will give up its single ref and/or pending read/write in its destructor.
25 SkASSERT(fRefCnt > 0);
26 if (0 == fPendingExecutions) {
27 for (int i = 0; i < fGpuResources.count(); ++i) {
28 fGpuResources[i]->markPendingIO();
34 for (int i = 0; i < fGpuResources.count(); ++i) {
35 fGpuResources[i]->removeRef();
40 void GrProgramElement::completedExecution() const {
43 if (0 == fPendingExecutions) {
47 // Now our pending executions have ocurred and we still have refs. Convert
48 // ownership of our resources back to regular refs.
49 for (int i = 0; i < fGpuResources.count(); ++i) {
50 fGpuResources[i]->pendingIOComplete();