/src/skia/src/gpu/ganesh/GrPixmap.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2020 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 GrPixmap_DEFINED |
9 | | #define GrPixmap_DEFINED |
10 | | |
11 | | #include "include/core/SkData.h" |
12 | | #include "include/core/SkPixmap.h" |
13 | | #include "include/core/SkPoint.h" |
14 | | #include "include/core/SkRect.h" |
15 | | #include "include/core/SkRefCnt.h" |
16 | | #include "include/core/SkSize.h" |
17 | | #include "include/private/base/SkTLogic.h" |
18 | | #include "include/private/base/SkTo.h" |
19 | | #include "src/gpu/ganesh/GrImageInfo.h" |
20 | | |
21 | | #include <cstddef> |
22 | | #include <utility> |
23 | | |
24 | | class GrColorInfo; |
25 | | class SkColorSpace; |
26 | | enum SkAlphaType : int; |
27 | | enum class GrColorType; |
28 | | |
29 | | template <typename T, typename DERIVED> class GrPixmapBase { |
30 | | public: |
31 | 772 | const GrImageInfo& info() const { return fInfo; } GrPixmapBase<void, GrPixmap>::info() const Line | Count | Source | 31 | 386 | const GrImageInfo& info() const { return fInfo; } |
GrPixmapBase<void const, GrCPixmap>::info() const Line | Count | Source | 31 | 386 | const GrImageInfo& info() const { return fInfo; } |
|
32 | 0 | const GrColorInfo& colorInfo() const { return fInfo.colorInfo(); } |
33 | | |
34 | 772 | T* addr() const { return fAddr; } GrPixmapBase<void, GrPixmap>::addr() const Line | Count | Source | 34 | 386 | T* addr() const { return fAddr; } |
GrPixmapBase<void const, GrCPixmap>::addr() const Line | Count | Source | 34 | 386 | T* addr() const { return fAddr; } |
|
35 | 772 | size_t rowBytes() const { return fRowBytes; } GrPixmapBase<void, GrPixmap>::rowBytes() const Line | Count | Source | 35 | 386 | size_t rowBytes() const { return fRowBytes; } |
GrPixmapBase<void const, GrCPixmap>::rowBytes() const Line | Count | Source | 35 | 386 | size_t rowBytes() const { return fRowBytes; } |
|
36 | | |
37 | 772 | bool hasPixels() const { return SkToBool(fAddr); } GrPixmapBase<void, GrPixmap>::hasPixels() const Line | Count | Source | 37 | 386 | bool hasPixels() const { return SkToBool(fAddr); } |
GrPixmapBase<void const, GrCPixmap>::hasPixels() const Line | Count | Source | 37 | 386 | bool hasPixels() const { return SkToBool(fAddr); } |
|
38 | 0 | bool ownsPixels() const { return SkToBool(fPixelStorage); } |
39 | 0 | sk_sp<SkData> pixelStorage() const { return fPixelStorage; } Unexecuted instantiation: GrPixmapBase<void, GrPixmap>::pixelStorage() const Unexecuted instantiation: GrPixmapBase<void const, GrCPixmap>::pixelStorage() const |
40 | | |
41 | 386 | int width() const { return fInfo.width(); } GrPixmapBase<void, GrPixmap>::width() const Line | Count | Source | 41 | 386 | int width() const { return fInfo.width(); } |
Unexecuted instantiation: GrPixmapBase<void const, GrCPixmap>::width() const |
42 | 386 | int height() const { return fInfo.height(); } Unexecuted instantiation: GrPixmapBase<void, GrPixmap>::height() const GrPixmapBase<void const, GrCPixmap>::height() const Line | Count | Source | 42 | 386 | int height() const { return fInfo.height(); } |
|
43 | 1.54k | SkISize dimensions() const { return fInfo.dimensions(); } GrPixmapBase<void const, GrCPixmap>::dimensions() const Line | Count | Source | 43 | 772 | SkISize dimensions() const { return fInfo.dimensions(); } |
GrPixmapBase<void, GrPixmap>::dimensions() const Line | Count | Source | 43 | 772 | SkISize dimensions() const { return fInfo.dimensions(); } |
|
44 | 2.31k | GrColorType colorType() const { return fInfo.colorType(); } GrPixmapBase<void const, GrCPixmap>::colorType() const Line | Count | Source | 44 | 1.15k | GrColorType colorType() const { return fInfo.colorType(); } |
GrPixmapBase<void, GrPixmap>::colorType() const Line | Count | Source | 44 | 1.15k | GrColorType colorType() const { return fInfo.colorType(); } |
|
45 | 772 | SkAlphaType alphaType() const { return fInfo.alphaType(); } Unexecuted instantiation: GrPixmapBase<void, GrPixmap>::alphaType() const GrPixmapBase<void const, GrCPixmap>::alphaType() const Line | Count | Source | 45 | 772 | SkAlphaType alphaType() const { return fInfo.alphaType(); } |
|
46 | 772 | SkColorSpace* colorSpace() const { return fInfo.colorSpace(); } GrPixmapBase<void const, GrCPixmap>::colorSpace() const Line | Count | Source | 46 | 386 | SkColorSpace* colorSpace() const { return fInfo.colorSpace(); } |
GrPixmapBase<void, GrPixmap>::colorSpace() const Line | Count | Source | 46 | 386 | SkColorSpace* colorSpace() const { return fInfo.colorSpace(); } |
|
47 | | sk_sp<SkColorSpace> refColorSpace() const { return fInfo.refColorSpace(); } |
48 | | |
49 | | /** |
50 | | * Map this pixmap to a rect in a surface of indicated dimensions at offset surfacePt. Clip the |
51 | | * logical rectangle to the bounds of the surface. If the rect does not intersect the surface |
52 | | * bounds or is empty then return a default GrPixmap. Otherwise, surfacePt is updated to refer |
53 | | * to the upper left of the clipped rectangle. The returned pixmap will refer to the portion |
54 | | * of the original pixmap inside the surface bounds. |
55 | | */ |
56 | 0 | DERIVED clip(SkISize surfaceDims, SkIPoint* surfacePt) { |
57 | 0 | auto bounds = SkIRect::MakeSize(surfaceDims); |
58 | 0 | auto rect = SkIRect::MakePtSize(*surfacePt, this->dimensions()); |
59 | 0 | if (!rect.intersect(bounds)) { |
60 | 0 | return {}; |
61 | 0 | } |
62 | 0 | T* addr = static_cast<sknonstd::copy_const_t<char, T>*>(fAddr) + |
63 | 0 | (rect.fTop - surfacePt->fY) * fRowBytes + |
64 | 0 | (rect.fLeft - surfacePt->fX) * fInfo.bpp(); |
65 | 0 | surfacePt->fX = rect.fLeft; |
66 | 0 | surfacePt->fY = rect.fTop; |
67 | 0 | return DERIVED{this->info().makeDimensions(rect.size()), addr, fRowBytes}; |
68 | 0 | } Unexecuted instantiation: GrPixmapBase<void, GrPixmap>::clip(SkISize, SkIPoint*) Unexecuted instantiation: GrPixmapBase<void const, GrCPixmap>::clip(SkISize, SkIPoint*) |
69 | | |
70 | | protected: |
71 | 0 | GrPixmapBase() = default; Unexecuted instantiation: GrPixmapBase<void, GrPixmap>::GrPixmapBase() Unexecuted instantiation: GrPixmapBase<void const, GrCPixmap>::GrPixmapBase() |
72 | 0 | GrPixmapBase(const GrPixmapBase& that) = default; Unexecuted instantiation: GrPixmapBase<void const, GrCPixmap>::GrPixmapBase(GrPixmapBase<void const, GrCPixmap> const&) Unexecuted instantiation: GrPixmapBase<void, GrPixmap>::GrPixmapBase(GrPixmapBase<void, GrPixmap> const&) |
73 | | GrPixmapBase(GrPixmapBase&& that) = default; |
74 | | GrPixmapBase& operator=(const GrPixmapBase& that) = default; |
75 | 0 | GrPixmapBase& operator=(GrPixmapBase&& that) = default; Unexecuted instantiation: GrPixmapBase<void, GrPixmap>::operator=(GrPixmapBase<void, GrPixmap>&&) Unexecuted instantiation: GrPixmapBase<void const, GrCPixmap>::operator=(GrPixmapBase<void const, GrCPixmap>&&) |
76 | | |
77 | | GrPixmapBase(GrImageInfo info, T* addr, size_t rowBytes) |
78 | 772 | : fAddr(addr), fRowBytes(rowBytes), fInfo(std::move(info)) { |
79 | 772 | if (fRowBytes < fInfo.minRowBytes() || !addr) { |
80 | 0 | *this = {}; |
81 | 0 | } |
82 | 772 | } GrPixmapBase<void, GrPixmap>::GrPixmapBase(GrImageInfo, void*, unsigned long) Line | Count | Source | 78 | 386 | : fAddr(addr), fRowBytes(rowBytes), fInfo(std::move(info)) { | 79 | 386 | if (fRowBytes < fInfo.minRowBytes() || !addr) { | 80 | 0 | *this = {}; | 81 | 0 | } | 82 | 386 | } |
GrPixmapBase<void const, GrCPixmap>::GrPixmapBase(GrImageInfo, void const*, unsigned long) Line | Count | Source | 78 | 386 | : fAddr(addr), fRowBytes(rowBytes), fInfo(std::move(info)) { | 79 | 386 | if (fRowBytes < fInfo.minRowBytes() || !addr) { | 80 | 0 | *this = {}; | 81 | 0 | } | 82 | 386 | } |
|
83 | | |
84 | | GrPixmapBase(GrImageInfo info, sk_sp<SkData> storage, size_t rowBytes) |
85 | 0 | : GrPixmapBase(std::move(info), const_cast<void*>(storage->data()), rowBytes) { |
86 | 0 | fPixelStorage = std::move(storage); |
87 | 0 | } Unexecuted instantiation: GrPixmapBase<void const, GrCPixmap>::GrPixmapBase(GrImageInfo, sk_sp<SkData>, unsigned long) Unexecuted instantiation: GrPixmapBase<void, GrPixmap>::GrPixmapBase(GrImageInfo, sk_sp<SkData>, unsigned long) |
88 | | |
89 | | private: |
90 | | T* fAddr = nullptr; |
91 | | size_t fRowBytes = 0; |
92 | | GrImageInfo fInfo; |
93 | | sk_sp<SkData> fPixelStorage; |
94 | | }; |
95 | | |
96 | | /** A pixmap with mutable pixels. */ |
97 | | class GrPixmap : public GrPixmapBase<void, GrPixmap> { |
98 | | public: |
99 | 0 | GrPixmap() = default; |
100 | 0 | GrPixmap(const GrPixmap&) = default; |
101 | | GrPixmap(GrPixmap&&) = default; |
102 | | GrPixmap& operator=(const GrPixmap&) = default; |
103 | 0 | GrPixmap& operator=(GrPixmap&&) = default; |
104 | | |
105 | | GrPixmap(GrImageInfo info, void* addr, size_t rowBytes) |
106 | 386 | : GrPixmapBase(std::move(info), addr, rowBytes) {} |
107 | | |
108 | | /* implicit */ GrPixmap(const SkPixmap& pixmap) |
109 | 0 | : GrPixmapBase(pixmap.info(), pixmap.writable_addr(), pixmap.rowBytes()) {} |
110 | | |
111 | | /** |
112 | | * Returns a GrPixmap that owns its backing store. Copies of the pixmap (as GrPixmap or |
113 | | * GrCPixmap) will share ownership. |
114 | | */ |
115 | 0 | static GrPixmap Allocate(const GrImageInfo& info) { |
116 | 0 | size_t rb = info.minRowBytes(); |
117 | 0 | size_t size = info.height()*rb; |
118 | 0 | if (!size) { |
119 | 0 | return {}; |
120 | 0 | } |
121 | 0 | return GrPixmap(info, SkData::MakeUninitialized(size), rb); |
122 | 0 | } |
123 | | |
124 | | private: |
125 | | GrPixmap(GrImageInfo info, sk_sp<SkData> storage, size_t rowBytes) |
126 | 0 | : GrPixmapBase(std::move(info), std::move(storage), rowBytes) {} |
127 | | }; |
128 | | |
129 | | /** |
130 | | * A pixmap with immutable pixels. Note that this pixmap need not be the unique owner of the pixels |
131 | | * and thus it is context-dependent whether the pixels could be manipulated externally. |
132 | | */ |
133 | | class GrCPixmap : public GrPixmapBase<const void, GrCPixmap> { |
134 | | public: |
135 | 0 | GrCPixmap() = default; |
136 | 0 | GrCPixmap(const GrCPixmap&) = default; |
137 | | GrCPixmap(GrCPixmap&&) = default; |
138 | | GrCPixmap& operator=(const GrCPixmap&) = default; |
139 | 0 | GrCPixmap& operator=(GrCPixmap&&) = default; |
140 | | |
141 | 0 | /* implicit*/ GrCPixmap(const GrPixmap& pixmap) { |
142 | 0 | if (auto storage = pixmap.pixelStorage()) { |
143 | 0 | *this = GrCPixmap(pixmap.info(), std::move(storage), pixmap.rowBytes()); |
144 | 0 | } else { |
145 | 0 | *this = GrCPixmap(pixmap.info(), pixmap.addr(), pixmap.rowBytes()); |
146 | 0 | } |
147 | 0 | } |
148 | | |
149 | | /* implicit */ GrCPixmap(const SkPixmap& pixmap) |
150 | 0 | : GrPixmapBase(pixmap.info(), pixmap.addr(), pixmap.rowBytes()) {} |
151 | | |
152 | | GrCPixmap(GrImageInfo info, const void* addr, size_t rowBytes) |
153 | 386 | : GrPixmapBase(std::move(info), addr, rowBytes) {} |
154 | | |
155 | | private: |
156 | | GrCPixmap(GrImageInfo info, sk_sp<SkData> storage, size_t rowBytes) |
157 | 0 | : GrPixmapBase(std::move(info), std::move(storage), rowBytes) {} |
158 | | }; |
159 | | |
160 | | #endif |