• 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 #include "image/image.h"
17 
18 #include "impl_factory.h"
19 #include "skia_adapter/skia_image.h"
20 #include "static_factory.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
BackendTexture()25 BackendTexture::BackendTexture() noexcept
26     : isValid_(false) {}
27 
BackendTexture(bool isValid)28 BackendTexture::BackendTexture(bool isValid) noexcept
29     : isValid_(isValid) {}
30 
IsValid() const31 bool BackendTexture::IsValid() const
32 {
33     return isValid_;
34 }
35 
SetTextureInfo(const TextureInfo & textureInfo)36 void BackendTexture::SetTextureInfo(const TextureInfo& textureInfo)
37 {
38     textureInfo_ = textureInfo;
39 }
40 
GetTextureInfo() const41 const TextureInfo& BackendTexture::GetTextureInfo() const
42 {
43     return textureInfo_;
44 }
45 
Image()46 Image::Image() noexcept : imageImplPtr(ImplFactory::CreateImageImpl()) {}
47 
Image(std::shared_ptr<ImageImpl> imageImpl)48 Image::Image(std::shared_ptr<ImageImpl> imageImpl) : imageImplPtr(imageImpl) {}
49 
Image(void * rawImg)50 Image::Image(void* rawImg) noexcept : imageImplPtr(ImplFactory::CreateImageImpl(rawImg)) {}
51 
BuildFromBitmap(const Bitmap & bitmap)52 bool Image::BuildFromBitmap(const Bitmap& bitmap)
53 {
54     return imageImplPtr->BuildFromBitmap(bitmap);
55 }
56 
MakeFromRaster(const Pixmap & pixmap,RasterReleaseProc rasterReleaseProc,ReleaseContext releaseContext)57 std::shared_ptr<Image> Image::MakeFromRaster(const Pixmap& pixmap,
58     RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
59 {
60     return StaticFactory::MakeFromRaster(pixmap, rasterReleaseProc, releaseContext);
61 }
62 
MakeRasterData(const ImageInfo & info,std::shared_ptr<Data> pixels,size_t rowBytes)63 std::shared_ptr<Image> Image::MakeRasterData(const ImageInfo& info, std::shared_ptr<Data> pixels,
64     size_t rowBytes)
65 {
66     return StaticFactory::MakeRasterData(info, pixels, rowBytes);
67 }
68 
69 #ifdef RS_ENABLE_GPU
MakeFromYUVAPixmaps(GPUContext & gpuContext,const YUVInfo & info,void * memory)70 std::shared_ptr<Image> Image::MakeFromYUVAPixmaps(GPUContext& gpuContext, const YUVInfo& info, void* memory)
71 {
72     return StaticFactory::MakeFromYUVAPixmaps(gpuContext, info, memory);
73 }
74 
BuildFromBitmap(GPUContext & gpuContext,const Bitmap & bitmap)75 bool Image::BuildFromBitmap(GPUContext& gpuContext, const Bitmap& bitmap)
76 {
77     return imageImplPtr->BuildFromBitmap(gpuContext, bitmap);
78 }
79 #endif
80 
MakeFromEncoded(const std::shared_ptr<Data> & data)81 bool Image::MakeFromEncoded(const std::shared_ptr<Data>& data)
82 {
83 #ifdef RS_ENABLE_GPU
84     return imageImplPtr->MakeFromEncoded(data);
85 #else
86     return false;
87 #endif
88 }
89 
90 #ifdef RS_ENABLE_GPU
BuildFromCompressed(GPUContext & gpuContext,const std::shared_ptr<Data> & data,int width,int height,CompressedType type,const std::shared_ptr<ColorSpace> & colorSpace)91 bool Image::BuildFromCompressed(GPUContext& gpuContext, const std::shared_ptr<Data>& data, int width, int height,
92     CompressedType type, const std::shared_ptr<ColorSpace>& colorSpace)
93 {
94     return imageImplPtr->BuildFromCompressed(gpuContext, data, width, height, type, colorSpace);
95 }
96 
BuildFromSurface(GPUContext & gpuContext,Surface & surface,TextureOrigin origin,BitmapFormat bitmapFormat,const std::shared_ptr<ColorSpace> & colorSpace)97 bool Image::BuildFromSurface(GPUContext& gpuContext, Surface& surface, TextureOrigin origin,
98     BitmapFormat bitmapFormat, const std::shared_ptr<ColorSpace>& colorSpace)
99 {
100     return imageImplPtr->BuildFromSurface(gpuContext, surface, origin, bitmapFormat, colorSpace);
101 }
102 
BuildFromTexture(GPUContext & gpuContext,const TextureInfo & info,TextureOrigin origin,BitmapFormat bitmapFormat,const std::shared_ptr<ColorSpace> & colorSpace,void (* deleteFunc)(void *),void * cleanupHelper)103 bool Image::BuildFromTexture(GPUContext& gpuContext, const TextureInfo& info, TextureOrigin origin,
104     BitmapFormat bitmapFormat, const std::shared_ptr<ColorSpace>& colorSpace,
105     void (*deleteFunc)(void*), void* cleanupHelper)
106 {
107     return imageImplPtr->BuildFromTexture(gpuContext, info, origin, bitmapFormat,
108         colorSpace, deleteFunc, cleanupHelper);
109 }
110 
BuildSubset(const std::shared_ptr<Image> & image,const RectI & rect,GPUContext & gpuContext)111 bool Image::BuildSubset(const std::shared_ptr<Image>& image, const RectI& rect, GPUContext& gpuContext)
112 {
113     return imageImplPtr->BuildSubset(image, rect, gpuContext);
114 }
115 
GetBackendTexture(bool flushPendingGrContextIO,TextureOrigin * origin) const116 BackendTexture Image::GetBackendTexture(bool flushPendingGrContextIO, TextureOrigin* origin) const
117 {
118     return imageImplPtr->GetBackendTexture(flushPendingGrContextIO, origin);
119 }
120 
IsValid(GPUContext * context) const121 bool Image::IsValid(GPUContext* context) const
122 {
123     return imageImplPtr->IsValid(context);
124 }
125 #endif
126 
AsLegacyBitmap(Bitmap & bitmap) const127 bool Image::AsLegacyBitmap(Bitmap& bitmap) const
128 {
129     return imageImplPtr->AsLegacyBitmap(bitmap);
130 }
131 
GetWidth() const132 int Image::GetWidth() const
133 {
134     return imageImplPtr->GetWidth();
135 }
136 
GetHeight() const137 int Image::GetHeight() const
138 {
139     return imageImplPtr->GetHeight();
140 }
141 
GetColorType() const142 ColorType Image::GetColorType() const
143 {
144     return imageImplPtr->GetColorType();
145 }
146 
GetAlphaType() const147 AlphaType Image::GetAlphaType() const
148 {
149     return imageImplPtr->GetAlphaType();
150 }
151 
GetColorSpace() const152 std::shared_ptr<ColorSpace> Image::GetColorSpace() const
153 {
154     return imageImplPtr->GetColorSpace();
155 }
156 
GetUniqueID() const157 uint32_t Image::GetUniqueID() const
158 {
159     return imageImplPtr->GetUniqueID();
160 }
161 
GetImageInfo()162 ImageInfo Image::GetImageInfo()
163 {
164     return imageImplPtr->GetImageInfo();
165 }
166 
ReadPixels(Bitmap & bitmap,int x,int y)167 bool Image::ReadPixels(Bitmap& bitmap, int x, int y)
168 {
169     return imageImplPtr->ReadPixels(bitmap, x, y);
170 }
171 
ReadPixels(Pixmap & pixmap,int x,int y)172 bool Image::ReadPixels(Pixmap& pixmap, int x, int y)
173 {
174     return imageImplPtr->ReadPixels(pixmap, x, y);
175 }
176 
ReadPixels(const ImageInfo & dstInfo,void * dstPixels,size_t dstRowBytes,int32_t srcX,int32_t srcY) const177 bool Image::ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
178     int32_t srcX, int32_t srcY) const
179 {
180     return imageImplPtr->ReadPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
181 }
182 
IsTextureBacked() const183 bool Image::IsTextureBacked() const
184 {
185     return imageImplPtr->IsTextureBacked();
186 }
187 
ScalePixels(const Bitmap & bitmap,const SamplingOptions & sampling,bool allowCachingHint) const188 bool Image::ScalePixels(const Bitmap& bitmap, const SamplingOptions& sampling, bool allowCachingHint) const
189 {
190     return imageImplPtr->ScalePixels(bitmap, sampling, allowCachingHint);
191 }
192 
EncodeToData(EncodedImageFormat encodedImageFormat,int quality) const193 std::shared_ptr<Data> Image::EncodeToData(EncodedImageFormat encodedImageFormat, int quality) const
194 {
195     return imageImplPtr->EncodeToData(encodedImageFormat, quality);
196 }
197 
IsLazyGenerated() const198 bool Image::IsLazyGenerated() const
199 {
200     return imageImplPtr->IsLazyGenerated();
201 }
202 
GetROPixels(Bitmap & bitmap) const203 bool Image::GetROPixels(Bitmap& bitmap) const
204 {
205     return imageImplPtr->GetROPixels(bitmap);
206 }
207 
MakeRasterImage() const208 std::shared_ptr<Image> Image::MakeRasterImage() const
209 {
210     return imageImplPtr->MakeRasterImage();
211 }
212 
CanPeekPixels() const213 bool Image::CanPeekPixels() const
214 {
215     return imageImplPtr->CanPeekPixels();
216 }
217 
IsOpaque() const218 bool Image::IsOpaque() const
219 {
220     return imageImplPtr->IsOpaque();
221 }
222 
HintCacheGpuResource() const223 void Image::HintCacheGpuResource() const
224 {
225     imageImplPtr->HintCacheGpuResource();
226 }
227 
Serialize() const228 std::shared_ptr<Data> Image::Serialize() const
229 {
230     return imageImplPtr->Serialize();
231 }
232 
Deserialize(std::shared_ptr<Data> data)233 bool Image::Deserialize(std::shared_ptr<Data> data)
234 {
235     return imageImplPtr->Deserialize(data);
236 }
237 } // namespace Drawing
238 } // namespace Rosen
239 } // namespace OHOS
240