12#if defined(SK_GANESH) && defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
68 intptr_t pixels =
reinterpret_cast<intptr_t
>(bmp.
getPixels());
85 const uint32_t srcPixel = *expectedBitmap.
getAddr32(
x,
y);
86 const uint32_t dstPixel = *actualBitmap.
getAddr32(
x,
y);
87 if (srcPixel != dstPixel) {
88 ERRORF(
reporter,
"Expected readback pixel (%d, %d) value 0x%08x, got 0x%08x.",
89 x,
y, srcPixel, dstPixel);
102 AHardwareBuffer_release(
buffer);
110 auto context =
info.directContext();
111 if (!context->priv().caps()->supportsAHardwareBufferImages()) {
119 const SkBitmap srcBitmap = make_src_bitmap();
127 AHardwareBuffer_Desc hwbDesc;
128 hwbDesc.width =
DEV_W;
129 hwbDesc.height =
DEV_H;
131 hwbDesc.usage = AHARDWAREBUFFER_USAGE_CPU_READ_NEVER |
132 AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
133 AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
134 hwbDesc.format = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
140 if (
int error = AHardwareBuffer_allocate(&hwbDesc, &
buffer)) {
142 cleanup_resources(
buffer);
147 AHardwareBuffer_describe(
buffer, &hwbDesc);
149 uint32_t* bufferAddr;
150 if (AHardwareBuffer_lock(
buffer, AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, -1,
nullptr,
151 reinterpret_cast<void**
>(&bufferAddr))) {
153 cleanup_resources(
buffer);
159 int nextLineStep =
DEV_W;
161 nextLineStep = -nextLineStep;
164 uint32_t*
dst = bufferAddr;
166 memcpy(dst, src,
DEV_W * bbp);
168 dst += hwbDesc.stride;
170 AHardwareBuffer_unlock(
buffer,
nullptr);
209 cleanup_resources(
buffer);
226 auto context =
info.directContext();
227 if (!context->priv().caps()->supportsAHardwareBufferImages()) {
231 bool isProtected = context->priv().caps()->supportsProtectedContent();
237 const SkBitmap srcBitmap = make_src_bitmap();
245 AHardwareBuffer_Desc hwbDesc;
246 hwbDesc.width =
DEV_W;
247 hwbDesc.height =
DEV_H;
249 hwbDesc.usage = AHARDWAREBUFFER_USAGE_CPU_READ_NEVER |
250 AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER |
251 AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
252 AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT |
253 (isProtected ? AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT : 0);
255 hwbDesc.format = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
261 if (
int error = AHardwareBuffer_allocate(&hwbDesc, &
buffer)) {
263 cleanup_resources(
buffer);
271 cleanup_resources(
buffer);
287 cleanup_resources(
buffer);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
struct AHardwareBuffer AHardwareBuffer
static bool check_read(skiatest::Reporter *reporter, const SkBitmap &bitmap)
@ kBottomLeft_GrSurfaceOrigin
@ kTopLeft_GrSurfaceOrigin
static SkPMColor get_src_color(int x, int y)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
static SkPMColor SkPremultiplyARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
#define REPORTER_ASSERT(r, cond,...)
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
sk_sp< SkImage > asImage() const
int bytesPerPixel() const
void allocN32Pixels(int width, int height, bool isOpaque=false)
uint32_t * getAddr32(int x, int y) const
void reset(T *ptr=nullptr)
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
SK_API sk_sp< SkImage > DeferredFromAHardwareBuffer(AHardwareBuffer *hardwareBuffer, SkAlphaType alphaType=kPremul_SkAlphaType)
SK_API sk_sp< SkSurface > WrapAndroidHardwareBuffer(skgpu::graphite::Recorder *recorder, AHardwareBuffer *hardwareBuffer, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, BufferReleaseProc=nullptr, ReleaseContext=nullptr, bool fromWindow=false)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)