| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#pragma once |
| 18 |
|
| 19 |
#include <SkColorFilter.h> |
| 20 |
#include <SkImage.h> |
| 21 |
#include <SkMatrix.h> |
| 22 |
#include <android/hardware_buffer.h> |
| 23 |
#include <android/surface_texture.h> |
| 24 |
#include <cutils/compiler.h> |
| 25 |
#include <utils/Errors.h> |
| 26 |
|
| 27 |
#include <EGL/egl.h> |
| 28 |
#include <EGL/eglext.h> |
| 29 |
#include <map> |
| 30 |
#include <memory> |
| 31 |
|
| 32 |
#include "Layer.h" |
| 33 |
#include "Rect.h" |
| 34 |
#include "renderstate/RenderState.h" |
| 35 |
|
| 36 |
namespace android { |
| 37 |
namespace uirenderer { |
| 38 |
|
| 39 |
class AutoBackendTextureRelease; |
| 40 |
class RenderState; |
| 41 |
|
| 42 |
typedef std::unique_ptr<ASurfaceTexture, decltype(&ASurfaceTexture_release)> AutoTextureRelease; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
class DeferredLayerUpdater : public VirtualLightRefBase, public IGpuContextCallback { |
| 47 |
public: |
| 48 |
|
| 49 |
|
| 50 |
explicit DeferredLayerUpdater(RenderState& renderState); |
| 51 |
|
| 52 |
~DeferredLayerUpdater(); |
| 53 |
|
| 54 |
bool setSize(int width, int height) { |
| 55 |
if (mWidth != width || mHeight != height) { |
| 56 |
mWidth = width; |
| 57 |
mHeight = height; |
| 58 |
return true; |
| 59 |
} |
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
int getWidth() { return mWidth; } |
| 64 |
int getHeight() { return mHeight; } |
| 65 |
|
| 66 |
bool setBlend(bool blend) { |
| 67 |
if (blend != mBlend) { |
| 68 |
mBlend = blend; |
| 69 |
return true; |
| 70 |
} |
| 71 |
return false; |
| 72 |
} |
| 73 |
|
| 74 |
void setSurfaceTexture(AutoTextureRelease&& consumer); |
| 75 |
|
| 76 |
void updateTexImage() { mUpdateTexImage = true; } |
| 77 |
|
| 78 |
void setTransform(const SkMatrix* matrix) { |
| 79 |
delete mTransform; |
| 80 |
mTransform = matrix ? new SkMatrix(*matrix) : nullptr; |
| 81 |
} |
| 82 |
|
| 83 |
SkMatrix* getTransform() { return mTransform; } |
| 84 |
|
| 85 |
void setPaint(const SkPaint* paint); |
| 86 |
|
| 87 |
void apply(); |
| 88 |
|
| 89 |
Layer* backingLayer() { return mLayer; } |
| 90 |
|
| 91 |
void detachSurfaceTexture(); |
| 92 |
|
| 93 |
void updateLayer(bool forceFilter, const sk_sp<SkImage>& layerImage, const uint32_t transform, |
| 94 |
SkRect currentCrop, float maxLuminanceNits = -1.f); |
| 95 |
|
| 96 |
void destroyLayer(); |
| 97 |
|
| 98 |
protected: |
| 99 |
void onContextDestroyed() override; |
| 100 |
|
| 101 |
private: |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
class ImageSlot { |
| 108 |
public: |
| 109 |
~ImageSlot() {} |
| 110 |
|
| 111 |
sk_sp<SkImage> createIfNeeded(AHardwareBuffer* buffer, android_dataspace dataspace, |
| 112 |
bool forceCreate, GrDirectContext* context); |
| 113 |
|
| 114 |
void releaseQueueOwnership(GrDirectContext* context); |
| 115 |
|
| 116 |
void clear(GrDirectContext* context); |
| 117 |
|
| 118 |
private: |
| 119 |
|
| 120 |
|
| 121 |
android_dataspace mDataspace = HAL_DATASPACE_UNKNOWN; |
| 122 |
|
| 123 |
AHardwareBuffer* mBuffer = nullptr; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
AutoBackendTextureRelease* mTextureRelease = nullptr; |
| 130 |
}; |
| 131 |
|
| 132 |
static status_t createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence, EGLDisplay* display, |
| 133 |
int* releaseFence, void* handle); |
| 134 |
static status_t fenceWait(int fence, void* handle); |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
std::map<int, ImageSlot> mImageSlots; |
| 141 |
|
| 142 |
RenderState& mRenderState; |
| 143 |
|
| 144 |
|
| 145 |
int mWidth = 0; |
| 146 |
int mHeight = 0; |
| 147 |
bool mBlend = false; |
| 148 |
sk_sp<SkColorFilter> mColorFilter; |
| 149 |
int mAlpha = 255; |
| 150 |
SkBlendMode mMode = SkBlendMode::kSrcOver; |
| 151 |
AutoTextureRelease mSurfaceTexture; |
| 152 |
SkMatrix* mTransform; |
| 153 |
bool mGLContextAttached; |
| 154 |
bool mUpdateTexImage; |
| 155 |
int mCurrentSlot = -1; |
| 156 |
|
| 157 |
Layer* mLayer; |
| 158 |
}; |
| 159 |
|
| 160 |
} |
| 161 |
} |