1 
2 /*
3  * Copyright 2016 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 #ifndef GrVkTypes_DEFINED
10 #define GrVkTypes_DEFINED
11 
12 #include "GrExternalTextureData.h"
13 #include "GrTypes.h"
14 #include "vk/GrVkDefines.h"
15 
16 /**
17  * KHR_debug
18  */
19 /*typedef void (GR_GL_FUNCTION_TYPE* GrVkDEBUGPROC)(GrVkenum source,
20                                                   GrVkenum type,
21                                                   GrVkuint id,
22                                                   GrVkenum severity,
23                                                   GrVksizei length,
24                                                   const GrVkchar* message,
25                                                   const void* userParam);*/
26 
27 
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 /**
31  * Types for interacting with Vulkan resources created externally to Skia. GrBackendObjects for
32  * Vulkan textures are really const GrVkImageInfo*
33  */
34 struct GrVkAlloc {
35     VkDeviceMemory fMemory;  // can be VK_NULL_HANDLE iff Tex is an RT and uses borrow semantics
36     VkDeviceSize   fOffset;
37     VkDeviceSize   fSize;    // this can be indeterminate iff Tex uses borrow semantics
38     uint32_t       fFlags;
39 
40     enum Flag {
41         kNoncoherent_Flag = 0x1,   // memory must be flushed to device after mapping
42     };
43 };
44 
45 struct GrVkImageInfo {
46     /**
47      * If the image's format is sRGB (GrVkFormatIsSRGB returns true), then the image must have
48      * been created with VkImageCreateFlags containing VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT.
49      */
50     VkImage        fImage;
51     GrVkAlloc      fAlloc;
52     VkImageTiling  fImageTiling;
53     VkImageLayout  fImageLayout;
54     VkFormat       fFormat;
55     uint32_t       fLevelCount;
56 
57     // This gives a way for a client to update the layout of the Image if they change the layout
58     // while we're still holding onto the wrapped texture. They will first need to get a handle
59     // to our internal GrVkImageInfo by calling getTextureHandle on a GrVkTexture.
updateImageLayoutGrVkImageInfo60     void updateImageLayout(VkImageLayout layout) { fImageLayout = layout; }
61 };
62 
63 class GrVkExternalTextureData : public GrExternalTextureData {
64 public:
GrVkExternalTextureData(const GrVkImageInfo & info)65     GrVkExternalTextureData(const GrVkImageInfo& info) : fInfo(info) {}
getBackend()66     GrBackend getBackend() const override { return kVulkan_GrBackend; }
67 
68 protected:
getBackendObject()69     GrBackendObject getBackendObject() const override {
70         return reinterpret_cast<GrBackendObject>(&fInfo);
71     }
attachToContext(GrContext *)72     void attachToContext(GrContext*) override {
73         // TODO: Implement this
74     }
75 
76     GrVkImageInfo fInfo;
77 
78     typedef GrExternalTextureData INHERITED;
79 };
80 
81 GR_STATIC_ASSERT(sizeof(GrBackendObject) >= sizeof(const GrVkImageInfo*));
82 
83 #endif
84