xref: /aosp_15_r20/external/skia/src/gpu/ganesh/GrImageInfo.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2019 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef GrImageInfo_DEFINED
9 #define GrImageInfo_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkSize.h"
13 #include "include/private/gpu/ganesh/GrTypesPriv.h"
14 #include "src/gpu/ganesh/GrColorInfo.h"
15 
16 #include <cstddef>
17 
18 class SkColorSpace;
19 enum SkAlphaType : int;
20 struct SkImageInfo;
21 
22 class GrImageInfo {
23 public:
24     GrImageInfo();
25     GrImageInfo(const SkImageInfo& info);
26     GrImageInfo(GrColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs, int w, int h);
27     GrImageInfo(GrColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs, const SkISize& dimensions);
28     GrImageInfo(const GrColorInfo& info, const SkISize& dimensions);
29     GrImageInfo(GrColorInfo&& info, const SkISize& dimensions);
30 
31     GrImageInfo(const GrImageInfo&);
32     GrImageInfo(GrImageInfo&&);
33     GrImageInfo& operator=(const GrImageInfo&);
34     GrImageInfo& operator=(GrImageInfo&&);
35 
36     GrImageInfo makeColorType(GrColorType ct) const;
37     GrImageInfo makeAlphaType(SkAlphaType at) const;
38     GrImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const;
39     GrImageInfo makeDimensions(SkISize dimensions) const ;
40     GrImageInfo makeWH(int width, int height) const;
41 
colorInfo()42     const GrColorInfo& colorInfo() const { return fColorInfo; }
43 
colorType()44     GrColorType colorType() const { return fColorInfo.colorType(); }
45 
alphaType()46     SkAlphaType alphaType() const { return fColorInfo.alphaType(); }
47 
colorSpace()48     SkColorSpace* colorSpace() const { return fColorInfo.colorSpace(); }
49 
50     sk_sp<SkColorSpace> refColorSpace() const;
51 
dimensions()52     SkISize dimensions() const { return fDimensions; }
53 
width()54     int width() const { return fDimensions.width(); }
55 
height()56     int height() const { return fDimensions.height(); }
57 
bpp()58     size_t bpp() const { return GrColorTypeBytesPerPixel(this->colorType()); }
59 
minRowBytes()60     size_t minRowBytes() const { return this->bpp() * this->width(); }
61 
isValid()62     bool isValid() const { return fColorInfo.isValid() && this->width() > 0 && this->height() > 0; }
63 
64 private:
65     GrColorInfo fColorInfo = {};
66     SkISize fDimensions;
67 };
68 
69 #endif
70