| 1 |
/* |
| 2 |
* Copyright 2021 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 |
#include "src/gpu/graphite/Buffer.h" |
| 8 |
|
| 9 |
#include "include/gpu/GpuTypes.h" |
| 10 |
#include "include/private/base/SkAssert.h" |
| 11 |
#include "src/gpu/graphite/Caps.h" |
| 12 |
#include "src/gpu/graphite/SharedContext.h" |
| 13 |
|
| 14 |
namespace skgpu::graphite { |
| 15 |
|
| 16 |
void* Buffer::map() { |
| 17 |
SkASSERT(this->isUnmappable() || !this->sharedContext()->caps()->bufferMapsAreAsync()); |
| 18 |
SkASSERT(this->isProtected() == Protected::kNo); |
| 19 |
if (!this->isMapped()) { |
| 20 |
this->onMap(); |
| 21 |
} |
| 22 |
return fMapPtr; |
| 23 |
} |
| 24 |
|
| 25 |
void Buffer::asyncMap(GpuFinishedProc proc, GpuFinishedContext ctx) { |
| 26 |
SkASSERT(this->sharedContext()->caps()->bufferMapsAreAsync()); |
| 27 |
SkASSERT(this->isProtected() == Protected::kNo); |
| 28 |
this->onAsyncMap(proc, ctx); |
| 29 |
} |
| 30 |
|
| 31 |
void Buffer::unmap() { |
| 32 |
SkASSERT(this->isUnmappable()); |
| 33 |
this->onUnmap(); |
| 34 |
fMapPtr = nullptr; |
| 35 |
} |
| 36 |
|
| 37 |
bool Buffer::isUnmappable() const { return isMapped(); } |
| 38 |
|
| 39 |
void Buffer::onAsyncMap(skgpu::graphite::GpuFinishedProc, skgpu::graphite::GpuFinishedContext) { |
| 40 |
SkASSERT(!this->sharedContext()->caps()->bufferMapsAreAsync()); |
| 41 |
SK_ABORT("Async buffer mapping not supported"); |
| 42 |
} |
| 43 |
|
| 44 |
} // namespace skgpu::graphite |
| 45 |
|