1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef IMAGE_CREATOR_IMPL_H 16 #define IMAGE_CREATOR_IMPL_H 17 18 #include "cj_ffi/cj_common_ffi.h" 19 #include "ffi_remote_data.h" 20 #include "image_creator.h" 21 22 namespace OHOS { 23 namespace Media { 24 class ImageCreatorImpl : public OHOS::FFI::FFIData { 25 DECL_TYPE(ImageCreatorImpl, OHOS::FFI::FFIData) 26 public: 27 ImageCreatorImpl(int32_t width, int32_t height, int32_t format, int32_t capacity); 28 ~ImageCreatorImpl(); 29 std::shared_ptr<ImageCreator> GetImageCreator(); 30 void Release(); 31 uint32_t CjOn(std::string name, std::function<void()> callBack); 32 #ifdef IMAGE_DEBUG_FLAG 33 bool isCallBackTest = false; 34 #endif 35 36 private: 37 void release(); 38 bool isRelease = false; 39 std::shared_ptr<ImageCreator> imageCreator_ = nullptr; 40 }; 41 42 class CJImageCreatorReleaseListener : public SurfaceBufferReleaseListener { 43 public: ~CJImageCreatorReleaseListener()44 ~CJImageCreatorReleaseListener() override 45 { 46 callBack = nullptr; 47 } OnSurfaceBufferRelease()48 void OnSurfaceBufferRelease() override 49 { 50 if (callBack != nullptr) { 51 callBack(); 52 } 53 } 54 std::string name; 55 std::function<void()> callBack = nullptr; 56 }; 57 } // namespace Media 58 } // namespace OHOS 59 #endif // IMAGE_CREATOR_IMPL_H 60