Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: src/core/SkSpecialImage.h

Issue 1845283003: Gamma-correctness pushed into Skia, top-down. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file 5 * found in the LICENSE file
6 */ 6 */
7 7
8 #ifndef SkSpecialImage_DEFINED 8 #ifndef SkSpecialImage_DEFINED
9 #define SkSpecialImage_DEFINED 9 #define SkSpecialImage_DEFINED
10 10
11 #include "SkNextID.h" 11 #include "SkNextID.h"
12 #include "SkRefCnt.h" 12 #include "SkRefCnt.h"
13 #include "SkSurfaceProps.h"
13 14
14 // remove this when internal_getProxy goes away (see skbug.com/4965) 15 // remove this when internal_getProxy goes away (see skbug.com/4965)
15 #include "SkImageFilter.h" 16 #include "SkImageFilter.h"
16 17
17 #include "SkImageInfo.h" // for SkAlphaType 18 #include "SkImageInfo.h" // for SkAlphaType
18 19
19 class GrContext; 20 class GrContext;
20 class GrTexture; 21 class GrTexture;
21 class SkBitmap; 22 class SkBitmap;
22 class SkCanvas; 23 class SkCanvas;
(...skipping 17 matching lines...) Expand all
40 * - it can't be drawn with MIPMAPs 41 * - it can't be drawn with MIPMAPs
41 * It is similar to SkImage in that it abstracts how the pixels are stored/repre sented. 42 * It is similar to SkImage in that it abstracts how the pixels are stored/repre sented.
42 * 43 *
43 * Note: the contents of the backing storage outside of the subset rect are unde fined. 44 * Note: the contents of the backing storage outside of the subset rect are unde fined.
44 */ 45 */
45 class SkSpecialImage : public SkRefCnt { 46 class SkSpecialImage : public SkRefCnt {
46 public: 47 public:
47 typedef void* ReleaseContext; 48 typedef void* ReleaseContext;
48 typedef void(*RasterReleaseProc)(void* pixels, ReleaseContext); 49 typedef void(*RasterReleaseProc)(void* pixels, ReleaseContext);
49 50
51 const SkSurfaceProps& props() const { return fProps; }
52
50 int width() const { return fSubset.width(); } 53 int width() const { return fSubset.width(); }
51 int height() const { return fSubset.height(); } 54 int height() const { return fSubset.height(); }
52 const SkIRect& subset() const { return fSubset; } 55 const SkIRect& subset() const { return fSubset; }
53 56
54 uint32_t uniqueID() const { return fUniqueID; } 57 uint32_t uniqueID() const { return fUniqueID; }
55 virtual bool isOpaque() const { return false; } 58 virtual bool isOpaque() const { return false; }
56 virtual size_t getSize() const = 0; 59 virtual size_t getSize() const = 0;
57 60
58 /** 61 /**
59 * Ensures that a special image is backed by a texture (when GrContext is n on-null). If no 62 * Ensures that a special image is backed by a texture (when GrContext is n on-null). If no
60 * transformation is required, the returned image may be the same as this s pecial image. 63 * transformation is required, the returned image may be the same as this s pecial image.
61 * If this special image is from a different GrContext, this will fail. 64 * If this special image is from a different GrContext, this will fail.
62 */ 65 */
63 sk_sp<SkSpecialImage> makeTextureImage(SkImageFilter::Proxy*, GrContext*); 66 sk_sp<SkSpecialImage> makeTextureImage(SkImageFilter::Proxy*, GrContext*);
64 67
65 /** 68 /**
66 * Draw this SpecialImage into the canvas. 69 * Draw this SpecialImage into the canvas.
67 */ 70 */
68 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const; 71 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const;
69 72
70 static sk_sp<SkSpecialImage> MakeFromImage(SkImageFilter::Proxy*, 73 static sk_sp<SkSpecialImage> MakeFromImage(SkImageFilter::Proxy*,
71 const SkIRect& subset, 74 const SkIRect& subset,
72 sk_sp<SkImage>); 75 sk_sp<SkImage>,
76 const SkSurfaceProps* = nullptr);
73 static sk_sp<SkSpecialImage> MakeFromRaster(SkImageFilter::Proxy*, 77 static sk_sp<SkSpecialImage> MakeFromRaster(SkImageFilter::Proxy*,
74 const SkIRect& subset, 78 const SkIRect& subset,
75 const SkBitmap&); 79 const SkBitmap&,
80 const SkSurfaceProps* = nullptr) ;
76 static sk_sp<SkSpecialImage> MakeFromGpu(SkImageFilter::Proxy*, 81 static sk_sp<SkSpecialImage> MakeFromGpu(SkImageFilter::Proxy*,
77 const SkIRect& subset, 82 const SkIRect& subset,
78 uint32_t uniqueID, 83 uint32_t uniqueID,
79 GrTexture*, 84 GrTexture*,
85 const SkSurfaceProps* = nullptr,
80 SkAlphaType at = kPremul_SkAlphaTyp e); 86 SkAlphaType at = kPremul_SkAlphaTyp e);
81 static sk_sp<SkSpecialImage> MakeFromPixmap(SkImageFilter::Proxy*, 87 static sk_sp<SkSpecialImage> MakeFromPixmap(SkImageFilter::Proxy*,
82 const SkIRect& subset, 88 const SkIRect& subset,
83 const SkPixmap&, 89 const SkPixmap&,
84 RasterReleaseProc, 90 RasterReleaseProc,
85 ReleaseContext); 91 ReleaseContext,
92 const SkSurfaceProps* = nullptr) ;
86 93
87 /** 94 /**
88 * Create a new special surface with a backend that is compatible with this special image. 95 * Create a new special surface with a backend that is compatible with this special image.
89 */ 96 */
90 sk_sp<SkSpecialSurface> makeSurface(const SkImageInfo&) const; 97 sk_sp<SkSpecialSurface> makeSurface(const SkImageInfo&) const;
91 98
92 /** 99 /**
93 * Create a new surface with a backend that is compatible with this special image. 100 * Create a new surface with a backend that is compatible with this special image.
94 * TODO: switch this to makeSurface once we resolved the naming issue 101 * TODO: switch this to makeSurface once we resolved the naming issue
95 */ 102 */
96 sk_sp<SkSurface> makeTightSurface(const SkImageInfo&) const; 103 sk_sp<SkSurface> makeTightSurface(const SkImageInfo&) const;
97 104
98 /** 105 /**
99 * Extract a subset of this special image and return it as a special image. 106 * Extract a subset of this special image and return it as a special image.
100 * It may or may not point to the same backing memory. 107 * It may or may not point to the same backing memory.
101 */ 108 */
102 sk_sp<SkSpecialImage> makeSubset(const SkIRect& subset) const; 109 sk_sp<SkSpecialImage> makeSubset(const SkIRect& subset) const;
103 110
104 /** 111 /**
105 * Extract a subset of this special image and return it as an SkImage. 112 * Extract a subset of this special image and return it as an SkImage.
106 * It may or may not point to the same backing memory. 113 * It may or may not point to the same backing memory.
107 * TODO: switch this to makeSurface once we resolved the naming issue 114 * TODO: switch this to makeSurface once we resolved the naming issue
108 */ 115 */
109 sk_sp<SkImage> makeTightSubset(const SkIRect& subset) const; 116 sk_sp<SkImage> makeTightSubset(const SkIRect& subset) const;
110 117
111 // These three internal methods will go away (see skbug.com/4965) 118 // These three internal methods will go away (see skbug.com/4965)
112 bool internal_getBM(SkBitmap* result); 119 bool internal_getBM(SkBitmap* result);
113 static sk_sp<SkSpecialImage> internal_fromBM(SkImageFilter::Proxy*, const Sk Bitmap&); 120 static sk_sp<SkSpecialImage> internal_fromBM(SkImageFilter::Proxy*, const Sk Bitmap&,
121 const SkSurfaceProps*);
114 SkImageFilter::Proxy* internal_getProxy() const; 122 SkImageFilter::Proxy* internal_getProxy() const;
115 123
116 // TODO: hide this when GrLayerHoister uses SkSpecialImages more fully (see skbug.com/5063) 124 // TODO: hide this when GrLayerHoister uses SkSpecialImages more fully (see skbug.com/5063)
117 /** 125 /**
118 * If the SpecialImage is backed by a gpu texture, return that texture. 126 * If the SpecialImage is backed by a gpu texture, return that texture.
119 * The active portion of the texture can be retrieved via 'subset'. 127 * The active portion of the texture can be retrieved via 'subset'.
120 */ 128 */
121 GrTexture* peekTexture() const; 129 GrTexture* peekTexture() const;
122 130
123 // TODO: hide this whe the imagefilter all have a consistent draw path (see skbug.com/5063) 131 // TODO: hide this whe the imagefilter all have a consistent draw path (see skbug.com/5063)
124 /** 132 /**
125 * If the SpecialImage is backed by cpu pixels, return the const address 133 * If the SpecialImage is backed by cpu pixels, return the const address
126 * of those pixels and, if not null, the ImageInfo, rowBytes, and, if prese nt, 134 * of those pixels and, if not null, the ImageInfo, rowBytes, and, if prese nt,
127 * the color table. The returned address(es) is/are only valid while the im age object 135 * the color table. The returned address(es) is/are only valid while the im age object
128 * is in scope. 136 * is in scope.
129 * 137 *
130 * The returned ImageInfo represents the backing memory. Use 'subset' 138 * The returned ImageInfo represents the backing memory. Use 'subset'
131 * to get the active portion's dimensions. 139 * to get the active portion's dimensions.
132 * 140 *
133 * On failure, return false and ignore the pixmap parameter. 141 * On failure, return false and ignore the pixmap parameter.
134 */ 142 */
135 bool peekPixels(SkPixmap*) const; 143 bool peekPixels(SkPixmap*) const;
136 144
137 protected: 145 protected:
138 SkSpecialImage(SkImageFilter::Proxy* proxy, const SkIRect& subset, uint32_t uniqueID) 146 SkSpecialImage(SkImageFilter::Proxy*, const SkIRect& subset, uint32_t unique ID,
139 : fSubset(subset) 147 const SkSurfaceProps*);
140 , fUniqueID(kNeedNewImageUniqueID_SpecialImage == uniqueID ? SkNextID::I mageID()
141 : uniqueID)
142 , fProxy(proxy) {
143 }
144 148
145 // The following 2 are for testing and shouldn't be used. 149 // The following 2 are for testing and shouldn't be used.
146 friend class TestingSpecialImageAccess; 150 friend class TestingSpecialImageAccess;
147 friend class TestingSpecialSurfaceAccess; 151 friend class TestingSpecialSurfaceAccess;
148 152
149 // This entry point is for testing only. It does a readback from VRAM for 153 // This entry point is for testing only. It does a readback from VRAM for
150 // GPU-backed special images. 154 // GPU-backed special images.
151 bool testingOnlyGetROPixels(SkBitmap*) const; 155 bool testingOnlyGetROPixels(SkBitmap*) const;
152 156
153 // TODO: remove this ASAP (see skbug.com/4965) 157 // TODO: remove this ASAP (see skbug.com/4965)
154 SkImageFilter::Proxy* proxy() const { return fProxy; } 158 SkImageFilter::Proxy* proxy() const { return fProxy; }
155 159
156 private: 160 private:
157 const SkIRect fSubset; 161 const SkSurfaceProps fProps;
158 const uint32_t fUniqueID; 162 const SkIRect fSubset;
163 const uint32_t fUniqueID;
159 164
160 // TODO: remove this ASAP (see skbug.com/4965) 165 // TODO: remove this ASAP (see skbug.com/4965)
161 SkImageFilter::Proxy* fProxy; 166 SkImageFilter::Proxy* fProxy;
162 167
163 typedef SkRefCnt INHERITED; 168 typedef SkRefCnt INHERITED;
164 }; 169 };
165 170
166 #endif 171 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698