#ifndef SERVICES_SCREEN_AI_SCREEN_AI_LIBRARY_WRAPPER_IMPL_H_
#define SERVICES_SCREEN_AI_SCREEN_AI_LIBRARY_WRAPPER_IMPL_H_
#include <stdint.h>
#include <cstdint>
#include <optional>
#include <vector>
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/scoped_native_library.h"
#include "build/build_config.h"
#include "services/screen_ai/proto/chrome_screen_ai.pb.h"
#include "services/screen_ai/screen_ai_library_wrapper.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace screen_ai {
class ScreenAILibraryWrapperImpl : public ScreenAILibraryWrapper {
public:
ScreenAILibraryWrapperImpl();
ScreenAILibraryWrapperImpl(const ScreenAILibraryWrapperImpl&) = delete;
ScreenAILibraryWrapperImpl& operator=(const ScreenAILibraryWrapperImpl&) =
delete;
~ScreenAILibraryWrapperImpl() override = default;
bool Load(const base::FilePath& library_path) override;
void EnableDebugMode() override;
void GetLibraryVersion(uint32_t& major, uint32_t& minor) override;
void SetFileContentFunctions(
uint32_t (*get_file_content_size)(const char* relative_file_path),
void (*get_file_content)(const char* relative_file_path,
uint32_t buffer_size,
char* buffer)) override;
#if BUILDFLAG(IS_CHROMEOS)
void SetLogger() override;
#endif
bool InitMainContentExtraction() override;
std::optional<std::vector<int32_t>> ExtractMainContent(
const std::string& serialized_view_hierarchy) override;
bool InitOCR() override;
void SetOCRLightMode(bool enabled) override;
uint32_t GetMaxImageDimension() override;
std::optional<chrome_screen_ai::VisualAnnotation> PerformOcr(
const SkBitmap& image) override;
private:
template <typename T>
bool LoadFunction(T& function_variable, const char* function_name);
typedef void (*FreeLibraryAllocatedInt32ArrayFn)(int32_t* );
FreeLibraryAllocatedInt32ArrayFn free_library_allocated_int32_array_ =
nullptr;
typedef void (*FreeLibraryAllocatedCharArrayFn)(char* );
FreeLibraryAllocatedCharArrayFn free_library_allocated_char_array_ = nullptr;
typedef void (*EnableDebugModeFn)();
EnableDebugModeFn enable_debug_mode_ = nullptr;
typedef void (*GetLibraryVersionFn)(uint32_t& major, uint32_t& minor);
GetLibraryVersionFn get_library_version_ = nullptr;
typedef void (*SetFileContentFunctionsFn)(
uint32_t (*get_file_content_size)(const char* ),
void (*get_file_content)(const char* ,
uint32_t ,
char* ));
SetFileContentFunctionsFn set_file_content_functions_ = nullptr;
#if BUILDFLAG(IS_CHROMEOS)
typedef void (*SetLoggerFn)(void (*logger_func)(int ,
const char* ));
SetLoggerFn set_logger_ = nullptr;
#endif
typedef bool (*InitMainContentExtractionFn)();
InitMainContentExtractionFn init_main_content_extraction_ = nullptr;
typedef int32_t* (*ExtractMainContentFn)(
const char* ,
uint32_t ,
uint32_t& );
ExtractMainContentFn extract_main_content_ = nullptr;
typedef bool (*InitOCRFn)();
InitOCRFn init_ocr_ = nullptr;
typedef void (*SetOCRLightModeFn)(bool );
SetOCRLightModeFn set_ocr_light_mode_ = nullptr;
typedef uint32_t (*GetMaxImageDimensionFn)();
GetMaxImageDimensionFn get_max_image_dimension_ = nullptr;
typedef char* (*PerformOcrFn)(
const SkBitmap& ,
uint32_t& );
PerformOcrFn perform_ocr_ = nullptr;
base::ScopedNativeLibrary library_;
};
}
#endif