1 /* 2 * Copyright 2023 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkSurfaceAndroid_DEFINED 9 #define SkSurfaceAndroid_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/core/SkSurface.h" 13 #include "include/gpu/ganesh/GrTypes.h" 14 15 class SkColorSpace; 16 class GrDirectContext; 17 class SkPixmap; 18 struct AHardwareBuffer; 19 20 namespace SkSurfaces { 21 22 /** Private; only to be used by Android Framework. 23 Creates SkSurface from Android hardware buffer. 24 Returned SkSurface takes a reference on the buffer. The ref on the buffer will be released 25 when the SkSurface is destroyed and there is no pending work on the GPU involving the 26 buffer. 27 28 Currently this is only supported for buffers that can be textured as well as rendered to. 29 In other words that must have both AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT and 30 AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage bits. 31 32 @param context GPU context 33 @param hardwareBuffer AHardwareBuffer Android hardware buffer 34 @param colorSpace range of colors; may be nullptr 35 @param surfaceProps LCD striping orientation and setting for device independent 36 fonts; may be nullptr 37 @param fromWindow Whether or not the AHardwareBuffer is part of an Android Window. 38 Currently only used with Vulkan backend. 39 @return created SkSurface, or nullptr 40 */ 41 SK_API sk_sp<SkSurface> WrapAndroidHardwareBuffer(GrDirectContext* context, 42 AHardwareBuffer* hardwareBuffer, 43 GrSurfaceOrigin origin, 44 sk_sp<SkColorSpace> colorSpace, 45 const SkSurfaceProps* surfaceProps, 46 bool fromWindow = false); 47 48 } // namespace SkSurfaces 49 50 #endif 51