1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef RSOV_CONTEXT_H
18 #define RSOV_CONTEXT_H
19 
20 #include <vulkan/vulkan.h>
21 #include <mutex>
22 
23 namespace android {
24 namespace renderscript {
25 
26 namespace rsov {
27 
28 class RSoVContext {
29  public:
30   static RSoVContext* create();
31   ~RSoVContext();
32 
getDevice()33   VkDevice getDevice() const { return mDevice; }
getQueue()34   VkQueue getQueue() const { return mQueue; }
getCmdPool()35   VkCommandPool getCmdPool() const { return mCmdPool; }
36 
37   bool MemoryTypeFromProperties(uint32_t typeBits, VkFlags requirements_mask,
38                                 uint32_t* typeIndex);
39 
40  private:
41   RSoVContext();
42 
43   bool Initialize(char const* const name);
44 
45   static RSoVContext* mContext;
46   static std::once_flag mInitFlag;
47 
48   VkInstance mInstance;
49   VkPhysicalDevice mGPU;
50   VkDevice mDevice;
51   VkPhysicalDeviceMemoryProperties mMemoryProperties;
52   VkQueue mQueue;
53   VkCommandPool mCmdPool;
54 };
55 
56 }  // namespace rsov
57 }  // namespace renderscript
58 }  // namespace android
59 
60 #endif  // RSOV_CONTEXT_H
61