| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include <android-base/unique_fd.h> |
| 19 |
#include <system/graphics.h> |
| 20 |
#include <system/window.h> |
| 21 |
#include <vulkan/vulkan.h> |
| 22 |
|
| 23 |
#include <SkRefCnt.h> |
| 24 |
#include <SkSize.h> |
| 25 |
|
| 26 |
#include "IRenderPipeline.h" |
| 27 |
|
| 28 |
class SkSurface; |
| 29 |
|
| 30 |
namespace android { |
| 31 |
namespace uirenderer { |
| 32 |
namespace renderthread { |
| 33 |
|
| 34 |
class VulkanManager; |
| 35 |
|
| 36 |
class VulkanSurface { |
| 37 |
public: |
| 38 |
static VulkanSurface* Create(ANativeWindow* window, ColorMode colorMode, SkColorType colorType, |
| 39 |
sk_sp<SkColorSpace> colorSpace, GrDirectContext* grContext, |
| 40 |
const VulkanManager& vkManager, uint32_t extraBuffers); |
| 41 |
~VulkanSurface(); |
| 42 |
|
| 43 |
sk_sp<SkSurface> getCurrentSkSurface() { |
| 44 |
return mCurrentBufferInfo ? mCurrentBufferInfo->skSurface : nullptr; |
| 45 |
} |
| 46 |
const SkMatrix& getCurrentPreTransform() { return mWindowInfo.preTransform; } |
| 47 |
|
| 48 |
private: |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
friend VulkanManager; |
| 54 |
struct NativeBufferInfo { |
| 55 |
sk_sp<SkSurface> skSurface; |
| 56 |
sp<ANativeWindowBuffer> buffer; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
base::unique_fd dequeue_fence; |
| 62 |
bool dequeued = false; |
| 63 |
uint32_t lastPresentedCount = 0; |
| 64 |
bool hasValidContents = false; |
| 65 |
}; |
| 66 |
|
| 67 |
NativeBufferInfo* dequeueNativeBuffer(); |
| 68 |
NativeBufferInfo* getCurrentBufferInfo() { return mCurrentBufferInfo; } |
| 69 |
bool presentCurrentBuffer(const SkRect& dirtyRect, int semaphoreFd); |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
int logicalWidth() const { return mWindowInfo.size.width(); } |
| 75 |
int logicalHeight() const { return mWindowInfo.size.height(); } |
| 76 |
int getCurrentBuffersAge(); |
| 77 |
|
| 78 |
private: |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
static constexpr uint32_t sTargetBufferCount = 2; |
| 90 |
|
| 91 |
struct WindowInfo { |
| 92 |
SkISize size; |
| 93 |
uint32_t bufferFormat; |
| 94 |
android_dataspace dataspace; |
| 95 |
sk_sp<SkColorSpace> colorspace; |
| 96 |
int transform; |
| 97 |
size_t bufferCount; |
| 98 |
uint64_t windowUsageFlags; |
| 99 |
|
| 100 |
|
| 101 |
SkISize actualSize; |
| 102 |
|
| 103 |
SkMatrix preTransform; |
| 104 |
}; |
| 105 |
|
| 106 |
VulkanSurface(ANativeWindow* window, const WindowInfo& windowInfo, GrDirectContext* grContext); |
| 107 |
static bool InitializeWindowInfoStruct(ANativeWindow* window, ColorMode colorMode, |
| 108 |
SkColorType colorType, sk_sp<SkColorSpace> colorSpace, |
| 109 |
const VulkanManager& vkManager, uint32_t extraBuffers, |
| 110 |
WindowInfo* outWindowInfo); |
| 111 |
static bool UpdateWindow(ANativeWindow* window, const WindowInfo& windowInfo); |
| 112 |
void releaseBuffers(); |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
static constexpr size_t kNumBufferSlots = 64; |
| 119 |
|
| 120 |
NativeBufferInfo mNativeBuffers[kNumBufferSlots]; |
| 121 |
|
| 122 |
sp<ANativeWindow> mNativeWindow; |
| 123 |
WindowInfo mWindowInfo; |
| 124 |
GrDirectContext* mGrContext; |
| 125 |
|
| 126 |
uint32_t mPresentCount = 0; |
| 127 |
NativeBufferInfo* mCurrentBufferInfo = nullptr; |
| 128 |
}; |
| 129 |
|
| 130 |
} |
| 131 |
} |
| 132 |
} |