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 SKIABITMAP_H 17 #define SKIABITMAP_H 18 19 #include "include/core/SkBitmap.h" 20 21 #include "impl_interface/bitmap_impl.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 namespace Drawing { 26 class DRAWING_API SkiaBitmap : public BitmapImpl { 27 public: 28 static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER; 29 30 SkiaBitmap(); ~SkiaBitmap()31 ~SkiaBitmap() override {} 32 GetType()33 AdapterType GetType() const override 34 { 35 return AdapterType::SKIA_ADAPTER; 36 } 37 38 bool Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride = 0, 39 std::shared_ptr<Drawing::ColorSpace> colorSpace = nullptr) override; 40 bool Build(const ImageInfo& imageInfo, int32_t stride) override; 41 int GetWidth() const override; 42 int GetHeight() const override; 43 int GetRowBytes() const override; 44 ColorType GetColorType() const override; 45 AlphaType GetAlphaType() const override; 46 bool ExtractSubset(Bitmap& dst, const Rect& subset) const override; 47 bool ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, 48 int32_t srcX, int32_t srcY) const override; 49 void* GetPixels() const override; 50 void SetPixels(void* pixels) override; 51 bool InstallPixels(const ImageInfo& info, void* pixels, size_t rowBytes, 52 ReleaseProc releaseProc, void* context) override; 53 bool PeekPixels(Pixmap& pixmap) const override; 54 size_t ComputeByteSize() const override; 55 const SkBitmap& ExportSkiaBitmap() const; 56 void CopyPixels(Bitmap& dst, int srcLeft, int srcTop) const override; 57 bool IsImmutable() override; 58 void SetImmutable() override; 59 void ClearWithColor(const ColorQuad& color) const override; 60 ColorQuad GetColor(int x, int y) const override; 61 void Free() override; 62 bool IsValid() const override; 63 bool IsEmpty() const override; 64 Pixmap GetPixmap() const override; 65 std::shared_ptr<Image> MakeImage() const override; 66 void SetInfo(const ImageInfo& info) override; 67 bool TryAllocPixels(const ImageInfo& info) override; 68 void SetSkBitmap(const SkBitmap& skBitmap); 69 SkBitmap& GetSkBitmap(); 70 71 std::shared_ptr<Data> Serialize() const override; 72 bool Deserialize(std::shared_ptr<Data> data) override; 73 ImageInfo GetImageInfo() override; 74 private: 75 SkBitmap skiaBitmap_; 76 }; 77 } // namespace Drawing 78 } // namespace Rosen 79 } // namespace OHOS 80 #endif 81