blob: b1c35d41727e8b502bb78cc1c5f5e34781c8cebb [file] [log] [blame]
Bryan Bernhart7ffd2342019-08-27 23:36:26 +00001// 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 Bernhart7ffd2342019-08-27 23:36:26 +000018namespace dawn_native {
19
Bryan Bernhart7ffd2342019-08-27 23:36:26 +000020 ResourceMemoryAllocation::ResourceMemoryAllocation()
Bryan Bernhart21dfc912019-10-03 18:17:31 +000021 : mOffset(0), mResourceHeap(nullptr), mMappedPointer(nullptr) {
Bryan Bernhart7ffd2342019-08-27 23:36:26 +000022 }
23
Bryan Bernhart21dfc912019-10-03 18:17:31 +000024 ResourceMemoryAllocation::ResourceMemoryAllocation(const AllocationInfo& info,
25 uint64_t offset,
Bryan Bernhart7ffd2342019-08-27 23:36:26 +000026 ResourceHeapBase* resourceHeap,
Bryan Bernhart22c3ff72019-09-05 17:36:47 +000027 uint8_t* mappedPointer)
Bryan Bernhart21dfc912019-10-03 18:17:31 +000028 : mInfo(info), mOffset(offset), mResourceHeap(resourceHeap), mMappedPointer(mappedPointer) {
Bryan Bernhart7ffd2342019-08-27 23:36:26 +000029 }
30
31 ResourceHeapBase* ResourceMemoryAllocation::GetResourceHeap() const {
Bryan Bernhart21dfc912019-10-03 18:17:31 +000032 ASSERT(mInfo.mMethod != AllocationMethod::kInvalid);
Bryan Bernhart7ffd2342019-08-27 23:36:26 +000033 return mResourceHeap;
34 }
35
36 uint64_t ResourceMemoryAllocation::GetOffset() const {
Bryan Bernhart21dfc912019-10-03 18:17:31 +000037 ASSERT(mInfo.mMethod != AllocationMethod::kInvalid);
Bryan Bernhart7ffd2342019-08-27 23:36:26 +000038 return mOffset;
39 }
40
Bryan Bernhart21dfc912019-10-03 18:17:31 +000041 AllocationInfo ResourceMemoryAllocation::GetInfo() const {
42 return mInfo;
Bryan Bernhart7ffd2342019-08-27 23:36:26 +000043 }
44
Bryan Bernhart22c3ff72019-09-05 17:36:47 +000045 uint8_t* ResourceMemoryAllocation::GetMappedPointer() const {
46 return mMappedPointer;
47 }
48
Bryan Bernhart7ffd2342019-08-27 23:36:26 +000049 void ResourceMemoryAllocation::Invalidate() {
50 mResourceHeap = nullptr;
Bryan Bernhart21dfc912019-10-03 18:17:31 +000051 mInfo = {};
Bryan Bernhart7ffd2342019-08-27 23:36:26 +000052 }
Kai Ninomiya63283562020-07-10 18:19:38 +000053} // namespace dawn_native