Bryan Bernhart | 7ffd234 | 2019-08-27 23:36:26 +0000 | [diff] [blame] | 1 | // Copyright 2019 The Dawn Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "dawn_native/ResourceMemoryAllocation.h" |
| 16 | #include "common/Assert.h" |
| 17 | |
Bryan Bernhart | 7ffd234 | 2019-08-27 23:36:26 +0000 | [diff] [blame] | 18 | namespace dawn_native { |
| 19 | |
Bryan Bernhart | 7ffd234 | 2019-08-27 23:36:26 +0000 | [diff] [blame] | 20 | ResourceMemoryAllocation::ResourceMemoryAllocation() |
Bryan Bernhart | 21dfc91 | 2019-10-03 18:17:31 +0000 | [diff] [blame] | 21 | : mOffset(0), mResourceHeap(nullptr), mMappedPointer(nullptr) { |
Bryan Bernhart | 7ffd234 | 2019-08-27 23:36:26 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Bryan Bernhart | 21dfc91 | 2019-10-03 18:17:31 +0000 | [diff] [blame] | 24 | ResourceMemoryAllocation::ResourceMemoryAllocation(const AllocationInfo& info, |
| 25 | uint64_t offset, |
Bryan Bernhart | 7ffd234 | 2019-08-27 23:36:26 +0000 | [diff] [blame] | 26 | ResourceHeapBase* resourceHeap, |
Bryan Bernhart | 22c3ff7 | 2019-09-05 17:36:47 +0000 | [diff] [blame] | 27 | uint8_t* mappedPointer) |
Bryan Bernhart | 21dfc91 | 2019-10-03 18:17:31 +0000 | [diff] [blame] | 28 | : mInfo(info), mOffset(offset), mResourceHeap(resourceHeap), mMappedPointer(mappedPointer) { |
Bryan Bernhart | 7ffd234 | 2019-08-27 23:36:26 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | ResourceHeapBase* ResourceMemoryAllocation::GetResourceHeap() const { |
Bryan Bernhart | 21dfc91 | 2019-10-03 18:17:31 +0000 | [diff] [blame] | 32 | ASSERT(mInfo.mMethod != AllocationMethod::kInvalid); |
Bryan Bernhart | 7ffd234 | 2019-08-27 23:36:26 +0000 | [diff] [blame] | 33 | return mResourceHeap; |
| 34 | } |
| 35 | |
| 36 | uint64_t ResourceMemoryAllocation::GetOffset() const { |
Bryan Bernhart | 21dfc91 | 2019-10-03 18:17:31 +0000 | [diff] [blame] | 37 | ASSERT(mInfo.mMethod != AllocationMethod::kInvalid); |
Bryan Bernhart | 7ffd234 | 2019-08-27 23:36:26 +0000 | [diff] [blame] | 38 | return mOffset; |
| 39 | } |
| 40 | |
Bryan Bernhart | 21dfc91 | 2019-10-03 18:17:31 +0000 | [diff] [blame] | 41 | AllocationInfo ResourceMemoryAllocation::GetInfo() const { |
| 42 | return mInfo; |
Bryan Bernhart | 7ffd234 | 2019-08-27 23:36:26 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Bryan Bernhart | 22c3ff7 | 2019-09-05 17:36:47 +0000 | [diff] [blame] | 45 | uint8_t* ResourceMemoryAllocation::GetMappedPointer() const { |
| 46 | return mMappedPointer; |
| 47 | } |
| 48 | |
Bryan Bernhart | 7ffd234 | 2019-08-27 23:36:26 +0000 | [diff] [blame] | 49 | void ResourceMemoryAllocation::Invalidate() { |
| 50 | mResourceHeap = nullptr; |
Bryan Bernhart | 21dfc91 | 2019-10-03 18:17:31 +0000 | [diff] [blame] | 51 | mInfo = {}; |
Bryan Bernhart | 7ffd234 | 2019-08-27 23:36:26 +0000 | [diff] [blame] | 52 | } |
Kai Ninomiya | 6328356 | 2020-07-10 18:19:38 +0000 | [diff] [blame] | 53 | } // namespace dawn_native |