• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 Google LLC
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 #ifndef GrD3DBuffer_DEFINED
9 
10 #define GrD3DBuffer_DEFINED
11 
12 #include "include/gpu/d3d/GrD3DTypes.h"
13 #include "src/gpu/GrGpuBuffer.h"
14 #include "src/gpu/GrManagedResource.h"
15 
16 class GrD3DGpu;
17 
18 class GrD3DBuffer : public GrGpuBuffer {
19 public:
20     static sk_sp<GrD3DBuffer> Make(GrD3DGpu*, size_t size, GrGpuBufferType, GrAccessPattern);
21 
~GrD3DBuffer()22     ~GrD3DBuffer() override {}
23 
d3dResource()24     ID3D12Resource* d3dResource() const {
25         SkASSERT(fD3DResource);
26         return fD3DResource.get();
27     }
28 
29     void setResourceState(const GrD3DGpu* gpu, D3D12_RESOURCE_STATES newResourceState);
30 
31 protected:
32     GrD3DBuffer(GrD3DGpu*, size_t size, GrGpuBufferType, GrAccessPattern, gr_cp<ID3D12Resource>,
33                 sk_sp<GrD3DAlloc>, D3D12_RESOURCE_STATES);
34 
35     void onAbandon() override;
36     void onRelease() override;
37 
38     D3D12_RESOURCE_STATES fResourceState;
39 
40 private:
41     void releaseResource();
42 
43     void onMap() override;
44     void onUnmap() override;
45     bool onUpdateData(const void* src, size_t srcSizeInBytes) override;
46 
47     void internalMap(size_t size);
48     void internalUnmap(size_t size);
49 
50     void validate() const;
51 
getD3DGpu()52     GrD3DGpu* getD3DGpu() const {
53         SkASSERT(!this->wasDestroyed());
54         return reinterpret_cast<GrD3DGpu*>(this->getGpu());
55     }
56 
57     gr_cp<ID3D12Resource> fD3DResource;
58     sk_sp<GrD3DAlloc> fAlloc;
59     ID3D12Resource* fStagingBuffer = nullptr;
60     size_t fStagingOffset = 0;
61 
62     using INHERITED = GrGpuBuffer;
63 };
64 
65 #endif
66