1 /* 2 * Copyright (c) 2021-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 IMAGEIMPL_H 17 #define IMAGEIMPL_H 18 19 #include "base_impl.h" 20 21 #include "draw/brush.h" 22 #include "effect/color_space.h" 23 #include "image/bitmap.h" 24 #include "image/pixmap.h" 25 #include "image/picture.h" 26 #include "image/image_info.h" 27 #include "utils/matrix.h" 28 #include "utils/size.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 namespace Drawing { 33 class Data; 34 #ifdef RS_ENABLE_GPU 35 class GPUContext; 36 enum class CompressedType; 37 class BackendTexture; 38 class TextureInfo; 39 enum class TextureOrigin; 40 #ifdef RS_ENABLE_VK 41 struct VKTextureInfo; 42 #endif 43 #endif 44 enum class BitDepth; 45 class Surface; 46 47 /** Caller data passed to RasterReleaseProc; may be nullptr. 48 */ 49 typedef void* ReleaseContext; 50 51 /** Function called when SkImage no longer shares pixels. ReleaseContext is 52 provided by caller when SkImage is created, and may be nullptr. 53 */ 54 typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext); 55 56 class ImageImpl : public BaseImpl { 57 public: ImageImpl()58 ImageImpl() noexcept {} ~ImageImpl()59 ~ImageImpl() override {} 60 61 virtual bool BuildFromBitmap(const Bitmap& bitmap) = 0; 62 #ifdef RS_ENABLE_GPU 63 virtual bool BuildFromBitmap(GPUContext& gpuContext, const Bitmap& bitmap) = 0; 64 virtual bool MakeFromEncoded(const std::shared_ptr<Data>& data) = 0; 65 virtual bool BuildSubset(const std::shared_ptr<Image> image, const RectI& rect, GPUContext& gpuContext); 66 virtual bool BuildFromCompressed(GPUContext& gpuContext, const std::shared_ptr<Data>& data, int width, int height, 67 CompressedType type, const std::shared_ptr<ColorSpace>& colorSpace = nullptr) = 0; 68 virtual bool BuildFromTexture(GPUContext& gpuContext, const TextureInfo& info, TextureOrigin origin, 69 BitmapFormat bitmapFormat, const std::shared_ptr<ColorSpace>& colorSpace, 70 void (*deleteFunc)(void*) = nullptr, void* cleanupHelper = nullptr) = 0; 71 virtual bool BuildFromSurface(GPUContext& gpuContext, Surface& surface, TextureOrigin origin, 72 BitmapFormat bitmapFormat, const std::shared_ptr<ColorSpace>& colorSpace) = 0; 73 virtual BackendTexture GetBackendTexture(bool flushPendingGrContextIO, TextureOrigin* origin) = 0; 74 virtual bool IsValid(GPUContext* context) const = 0; 75 #endif 76 virtual bool AsLegacyBitmap(Bitmap& bitmap) const = 0; 77 virtual int GetWidth() const = 0; 78 virtual int GetHeight() const = 0; 79 virtual ColorType GetColorType() const = 0; 80 virtual AlphaType GetAlphaType() const = 0; 81 virtual std::shared_ptr<ColorSpace> GetColorSpace() const = 0; 82 virtual uint32_t GetUniqueID() const = 0; 83 virtual ImageInfo GetImageInfo() = 0; 84 virtual bool ReadPixels(Bitmap& bitmap, int x, int y) = 0; 85 virtual bool ReadPixels(Pixmap& pixmap, int x, int y) = 0; 86 virtual bool ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, 87 int32_t srcX, int32_t srcY) const = 0; 88 virtual bool IsTextureBacked() const = 0; 89 virtual bool ScalePixels(const Bitmap& bitmap, const SamplingOptions& sampling, 90 bool allowCachingHint = true) const = 0; 91 virtual std::shared_ptr<Data> EncodeToData(EncodedImageFormat encodedImageFormat, int quality) const = 0; 92 virtual bool IsLazyGenerated() const = 0; 93 virtual bool GetROPixels(Bitmap& bitmap) const = 0; 94 virtual std::shared_ptr<Image> MakeRasterImage() const = 0; 95 virtual bool CanPeekPixels() const = 0; 96 virtual bool IsOpaque() const = 0; 97 virtual void HintCacheGpuResource() const = 0; 98 99 // using for recording, should to remove after using shared memory 100 virtual std::shared_ptr<Data> Serialize() const = 0; 101 virtual bool Deserialize(std::shared_ptr<Data> data) = 0; 102 }; 103 } // namespace Drawing 104 } // namespace Rosen 105 } // namespace OHOS 106 #endif 107