• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) override;
39     bool Build(const ImageInfo& imageInfo, int32_t stride) override;
40     int GetWidth() const override;
41     int GetHeight() const override;
42     int GetRowBytes() const override;
43     ColorType GetColorType() const override;
44     AlphaType GetAlphaType() const override;
45     bool ExtractSubset(Bitmap& dst, const Rect& subset) const override;
46     bool ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
47                     int32_t srcX, int32_t srcY) const override;
48     void* GetPixels() const override;
49     void SetPixels(void* pixels) override;
50     bool InstallPixels(const ImageInfo& info, void* pixels, size_t rowBytes,
51                        ReleaseProc releaseProc, void* context) override;
52     bool PeekPixels(Pixmap& pixmap) const override;
53     size_t ComputeByteSize() const override;
54     const SkBitmap& ExportSkiaBitmap() const;
55     void CopyPixels(Bitmap& dst, int srcLeft, int srcTop) const override;
56     bool IsImmutable() override;
57     void SetImmutable() override;
58     void ClearWithColor(const ColorQuad& color) const override;
59     ColorQuad GetColor(int x, int y) const override;
60     void Free() override;
61     bool IsValid() const override;
62     bool IsEmpty() const override;
63     Pixmap GetPixmap() const override;
64     std::shared_ptr<Image> MakeImage() const override;
65     void SetInfo(const ImageInfo& info) override;
66     bool TryAllocPixels(const ImageInfo& info) override;
67     void SetSkBitmap(const SkBitmap& skBitmap);
68     SkBitmap& GetSkBitmap();
69 
70     std::shared_ptr<Data> Serialize() const override;
71     bool Deserialize(std::shared_ptr<Data> data) override;
72     ImageInfo GetImageInfo() override;
73 private:
74     SkBitmap skiaBitmap_;
75 };
76 } // namespace Drawing
77 } // namespace Rosen
78 } // namespace OHOS
79 #endif
80