Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 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 "GrProgramResource.h" | |
| 9 #include "GrGpuResource.h" | |
| 10 | |
| 11 GrProgramResource::GrProgramResource() { | |
| 12 fResource = NULL; | |
| 13 fOwnRef = false; | |
| 14 fPendingIO = false; | |
| 15 fIOType = kNone_IOType; | |
| 16 } | |
| 17 | |
| 18 GrProgramResource::GrProgramResource(GrGpuResource* resource, IOType ioType) { | |
| 19 fResource = NULL; | |
| 20 fOwnRef = false; | |
| 21 fPendingIO = false; | |
| 22 this->setResource(resource, ioType); | |
| 23 } | |
| 24 | |
| 25 GrProgramResource::~GrProgramResource() { | |
| 26 if (fOwnRef) { | |
| 27 SkASSERT(NULL != fResource); | |
| 28 fResource->unref(); | |
| 29 } | |
| 30 if (fPendingIO) { | |
| 31 switch (fIOType) { | |
| 32 case kNone_IOType: | |
| 33 SkFAIL("Shouldn't get here if fIOType is kNone."); | |
| 34 break; | |
| 35 case kRead_IOType: | |
| 36 fResource->completedRead(); | |
| 37 break; | |
| 38 case kWrite_IOType: | |
| 39 fResource->completedWrite(); | |
| 40 break; | |
| 41 case kRW_IOType: | |
| 42 fResource->completedRead(); | |
| 43 fResource->completedWrite(); | |
| 44 break; | |
| 45 } | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 void GrProgramResource::reset() { | |
| 50 SkASSERT(!fPendingIO); | |
| 51 SkASSERT((NULL != fResource) == fOwnRef); | |
| 52 if (fOwnRef) { | |
| 53 fResource->unref(); | |
| 54 fOwnRef = false; | |
| 55 fResource = NULL; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 void GrProgramResource::setResource(GrGpuResource* resource, IOType ioType) { | |
| 60 SkASSERT(!fPendingIO); | |
| 61 SkASSERT((NULL != fResource) == fOwnRef); | |
| 62 SkSafeUnref(fResource); | |
| 63 if (NULL == resource) { | |
| 64 fResource = NULL; | |
| 65 fOwnRef = false; | |
|
robertphillips
2014/09/04 19:48:57
fIOType = kNone_IOType; ?
bsalomon
2014/09/04 20:03:17
Done (here and in reset()).
| |
| 66 } else { | |
| 67 SkASSERT(kNone_IOType != ioType); | |
| 68 fResource = resource; | |
| 69 fOwnRef = true; | |
| 70 fIOType = ioType; | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 void GrProgramResource::markPendingIO() const { | |
| 75 // This should only be called once, when the owning GrProgramElement gets it s first | |
| 76 // pendingExecution ref. | |
| 77 SkASSERT(!fPendingIO); | |
| 78 SkASSERT(NULL != fResource); | |
| 79 fPendingIO = true; | |
| 80 switch (fIOType) { | |
| 81 case kNone_IOType: | |
| 82 SkFAIL("GrProgramResource with neither reads nor writes?"); | |
| 83 break; | |
| 84 case kRead_IOType: | |
| 85 fResource->addPendingRead(); | |
| 86 break; | |
| 87 case kWrite_IOType: | |
| 88 fResource->addPendingWrite(); | |
| 89 break; | |
| 90 case kRW_IOType: | |
| 91 fResource->addPendingRead(); | |
| 92 fResource->addPendingWrite(); | |
| 93 break; | |
| 94 | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 void GrProgramResource::removeRef() const { | |
| 99 // This should only be called once, when the owners last ref goes away and | |
| 100 // there is a pending execution. | |
| 101 SkASSERT(fOwnRef); | |
| 102 SkASSERT(fPendingIO); | |
| 103 SkASSERT(kNone_IOType != fIOType); | |
| 104 SkASSERT(NULL != fResource); | |
| 105 fResource->unref(); | |
| 106 fOwnRef = false; | |
| 107 } | |
| OLD | NEW |