1 /* 2 * Copyright (C) 2023 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 16 #ifndef FRAMEWORKS_INNERKITSIMPL_EGL_IMAGE_INCLUDE_PIXELMAP_FROM_SURFACE_H 17 #define FRAMEWORKS_INNERKITSIMPL_EGL_IMAGE_INCLUDE_PIXELMAP_FROM_SURFACE_H 18 19 #include "render_context.h" 20 21 #include "pixel_map.h" 22 #include "surface_buffer.h" 23 #include "surface_utils.h" 24 #include "window.h" 25 26 namespace OHOS { 27 namespace Media { 28 // we use this helper to make pixelmap from a surface, and will construct this object 29 // in every PixelMap::CreateFromSurface() call. 30 class PixelMapFromSurface { 31 public: 32 PixelMapFromSurface(); 33 ~PixelMapFromSurface() noexcept; 34 35 std::unique_ptr<PixelMap> Create(uint64_t surfaceId, const Rect &srcRect); 36 37 // disallow copy and move 38 PixelMapFromSurface(const PixelMapFromSurface &) = delete; 39 void operator=(const PixelMapFromSurface &) = delete; 40 PixelMapFromSurface(const PixelMapFromSurface &&) = delete; 41 void operator=(const PixelMapFromSurface &&) = delete; 42 43 private: 44 bool GetNativeWindowBufferFromSurface(const sptr<Surface> &surface, const Rect &srcRect); 45 bool CreateEGLImage(); 46 bool DrawImage(const Rect &srcRect); 47 void Clear() noexcept; 48 49 sptr<SurfaceBuffer> surfaceBuffer_; 50 OHNativeWindowBuffer *nativeWindowBuffer_ = nullptr; 51 std::unique_ptr<RenderContext> renderContext_; 52 GLuint texId_ = 0U; 53 EGLImageKHR eglImage_ = EGL_NO_IMAGE_KHR; 54 sk_sp<SkSurface> targetSurface_; // a tmp surface(renderTarget) to draw surfacebuffer and get the result. 55 }; 56 57 std::unique_ptr<PixelMap> CreatePixelMapFromSurfaceId(uint64_t surfaceId, const Rect &srcRect); 58 } // namespace Media 59 } // namespace OHOS 60 61 #endif // FRAMEWORKS_INNERKITSIMPL_EGL_IMAGE_INCLUDE_PIXELMAP_FROM_SURFACE_H 62