Exposes a handle to AHardwareBuffers through a new GpuBuffer view
PiperOrigin-RevId: 580754933
This commit is contained in:
		
							parent
							
								
									252c7eef25
								
							
						
					
					
						commit
						7c5c216652
					
				| 
						 | 
					@ -124,6 +124,15 @@ cc_library(
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cc_library(
 | 
				
			||||||
 | 
					    name = "ahwb_view",
 | 
				
			||||||
 | 
					    hdrs = ["ahwb_view.h"],
 | 
				
			||||||
 | 
					    deps = [
 | 
				
			||||||
 | 
					        "//mediapipe/framework:port",
 | 
				
			||||||
 | 
					        "//mediapipe/gpu:gpu_buffer_storage",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cc_library(
 | 
					cc_library(
 | 
				
			||||||
    name = "affine_transform",
 | 
					    name = "affine_transform",
 | 
				
			||||||
    srcs = ["affine_transform.cc"],
 | 
					    srcs = ["affine_transform.cc"],
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										54
									
								
								mediapipe/framework/formats/ahwb_view.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								mediapipe/framework/formats/ahwb_view.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,54 @@
 | 
				
			||||||
 | 
					#ifndef MEDIAPIPE_FRAMEWORK_FORMATS_AHWB_VIEW_H_
 | 
				
			||||||
 | 
					#define MEDIAPIPE_FRAMEWORK_FORMATS_AHWB_VIEW_H_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "mediapipe/framework/port.h"
 | 
				
			||||||
 | 
					#ifdef MEDIAPIPE_GPU_BUFFER_USE_AHWB
 | 
				
			||||||
 | 
					#include <android/hardware_buffer.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "mediapipe/gpu/gpu_buffer_storage.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace mediapipe {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Wrapper to facilitate short lived access to Android Hardware Buffer objects.
 | 
				
			||||||
 | 
					// Intended use cases:
 | 
				
			||||||
 | 
					// - Extracting an AHWB for processing in another library after it's produced by
 | 
				
			||||||
 | 
					// MediaPipe.
 | 
				
			||||||
 | 
					// - Sending AHWBs to compute devices that are able to map the memory for their
 | 
				
			||||||
 | 
					// own usage.
 | 
				
			||||||
 | 
					// The AHWB abstractions in GpuBuffer and Tensor are likely more suitable for
 | 
				
			||||||
 | 
					// other CPU/GPU uses of AHWBs.
 | 
				
			||||||
 | 
					class AhwbView {
 | 
				
			||||||
 | 
					 public:
 | 
				
			||||||
 | 
					  explicit AhwbView(AHardwareBuffer* handle) : handle_(handle) {}
 | 
				
			||||||
 | 
					  // Non-copyable
 | 
				
			||||||
 | 
					  AhwbView(const AhwbView&) = delete;
 | 
				
			||||||
 | 
					  AhwbView& operator=(const AhwbView&) = delete;
 | 
				
			||||||
 | 
					  // Non-movable
 | 
				
			||||||
 | 
					  AhwbView(AhwbView&&) = delete;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Only supports synchronous usage. All users of GetHandle must finish
 | 
				
			||||||
 | 
					  // accessing the buffer before this view object is destroyed to avoid race
 | 
				
			||||||
 | 
					  // conditions.
 | 
				
			||||||
 | 
					  // TODO: Support asynchronous usage.
 | 
				
			||||||
 | 
					  const AHardwareBuffer* GetHandle() const { return handle_; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 private:
 | 
				
			||||||
 | 
					  const AHardwareBuffer* handle_;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace internal {
 | 
				
			||||||
 | 
					// Makes this class available as a GpuBuffer view.
 | 
				
			||||||
 | 
					template <>
 | 
				
			||||||
 | 
					class ViewProvider<AhwbView> {
 | 
				
			||||||
 | 
					 public:
 | 
				
			||||||
 | 
					  virtual ~ViewProvider() = default;
 | 
				
			||||||
 | 
					  virtual const AhwbView GetReadView(types<AhwbView>) const = 0;
 | 
				
			||||||
 | 
					  virtual AhwbView GetWriteView(types<AhwbView>) = 0;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}  // namespace internal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}  // namespace mediapipe
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  // MEDIAPIPE_GPU_BUFFER_USE_AHWB
 | 
				
			||||||
 | 
					#endif  // MEDIAPIPE_FRAMEWORK_FORMATS_AHWB_VIEW_H_
 | 
				
			||||||
| 
						 | 
					@ -104,4 +104,9 @@
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#endif  // MEDIAPIPE_HAS_RTTI
 | 
					#endif  // MEDIAPIPE_HAS_RTTI
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// AHardware buffers are only available since Android API 26.
 | 
				
			||||||
 | 
					#if (__ANDROID_API__ >= 26)
 | 
				
			||||||
 | 
					#define MEDIAPIPE_GPU_BUFFER_USE_AHWB 1
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif  // MEDIAPIPE_FRAMEWORK_PORT_H_
 | 
					#endif  // MEDIAPIPE_FRAMEWORK_PORT_H_
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -511,12 +511,19 @@ cc_library(
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
    }),
 | 
					    }),
 | 
				
			||||||
    deps = [
 | 
					    deps = [
 | 
				
			||||||
 | 
					        ":gl_base_hdr",
 | 
				
			||||||
 | 
					        ":gl_context",
 | 
				
			||||||
        ":gl_texture_buffer",
 | 
					        ":gl_texture_buffer",
 | 
				
			||||||
 | 
					        ":gl_texture_view",
 | 
				
			||||||
        ":gpu_buffer_format",
 | 
					        ":gpu_buffer_format",
 | 
				
			||||||
        ":gpu_buffer_storage",
 | 
					        ":gpu_buffer_storage",
 | 
				
			||||||
        ":image_frame_view",
 | 
					        ":image_frame_view",
 | 
				
			||||||
 | 
					        "//mediapipe/framework:port",
 | 
				
			||||||
 | 
					        "//mediapipe/framework/formats:ahwb_view",
 | 
				
			||||||
        "//mediapipe/framework/formats:image_frame",
 | 
					        "//mediapipe/framework/formats:image_frame",
 | 
				
			||||||
        "//mediapipe/framework/port:ret_check",
 | 
					        "//mediapipe/framework/port:ret_check",
 | 
				
			||||||
 | 
					        "//third_party/GL:EGL_headers",
 | 
				
			||||||
 | 
					        "@com_google_absl//absl/log:absl_check",
 | 
				
			||||||
        "@com_google_absl//absl/strings:str_format",
 | 
					        "@com_google_absl//absl/strings:str_format",
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user