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

Side by Side Diff: include/gpu/GrXferProcessor.h

Issue 1132093004: Move DstCoordTexture to GrXP, rename and remove the word "copy" from dstcopytexture names. (Closed) Base URL: https://skia.googlesource.com/skia.git@copy
Patch Set: remove asserts Created 5 years, 6 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
« no previous file with comments | « include/gpu/GrTexture.h ('k') | include/gpu/effects/GrCoverageSetOpXP.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 GrXferProcessor_DEFINED 8 #ifndef GrXferProcessor_DEFINED
9 #define GrXferProcessor_DEFINED 9 #define GrXferProcessor_DEFINED
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 * seconday fragment shader output color. When allowed by the backend API, the G rXferProcessor may 101 * seconday fragment shader output color. When allowed by the backend API, the G rXferProcessor may
102 * read the destination color. The GrXferProcessor is responsible for setting th e blend coefficients 102 * read the destination color. The GrXferProcessor is responsible for setting th e blend coefficients
103 * and blend constant color. 103 * and blend constant color.
104 * 104 *
105 * A GrXferProcessor is never installed directly into our draw state, but instea d is created from a 105 * A GrXferProcessor is never installed directly into our draw state, but instea d is created from a
106 * GrXPFactory once we have finalized the state of our draw. 106 * GrXPFactory once we have finalized the state of our draw.
107 */ 107 */
108 class GrXferProcessor : public GrProcessor { 108 class GrXferProcessor : public GrProcessor {
109 public: 109 public:
110 /** 110 /**
111 * A texture that contains the dst pixel values and an integer coord offset from device space
112 * to the space of the texture. Depending on GPU capabilities a DstTexture m ay be used by a
113 * GrXferProcessor for blending in the fragment shader.
114 */
115 class DstTexture {
116 public:
117 DstTexture() { fOffset.set(0, 0); }
118
119 DstTexture(const DstTexture& other) {
120 *this = other;
121 }
122
123 DstTexture(GrTexture* texture, const SkIPoint& offset)
124 : fTexture(SkSafeRef(texture))
125 , fOffset(offset) {
126 }
127
128 DstTexture& operator=(const DstTexture& other) {
129 fTexture.reset(SkSafeRef(other.fTexture.get()));
130 fOffset = other.fOffset;
131 return *this;
132 }
133
134 const SkIPoint& offset() const { return fOffset; }
135
136 void setOffset(const SkIPoint& offset) { fOffset = offset; }
137 void setOffset(int ox, int oy) { fOffset.set(ox, oy); }
138
139 GrTexture* texture() const { return fTexture.get(); }
140
141 GrTexture* setTexture(GrTexture* texture) {
142 fTexture.reset(SkSafeRef(texture));
143 return texture;
144 }
145
146 private:
147 SkAutoTUnref<GrTexture> fTexture;
148 SkIPoint fOffset;
149 };
150
151 /**
111 * Sets a unique key on the GrProcessorKeyBuilder calls onGetGLProcessorKey( ...) to get the 152 * Sets a unique key on the GrProcessorKeyBuilder calls onGetGLProcessorKey( ...) to get the
112 * specific subclass's key. 153 * specific subclass's key.
113 */ 154 */
114 void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) con st; 155 void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) con st;
115 156
116 /** Returns a new instance of the appropriate *GL* implementation class 157 /** Returns a new instance of the appropriate *GL* implementation class
117 for the given GrXferProcessor; caller is responsible for deleting 158 for the given GrXferProcessor; caller is responsible for deleting
118 the object. */ 159 the object. */
119 virtual GrGLXferProcessor* createGLInstance() const = 0; 160 virtual GrGLXferProcessor* createGLInstance() const = 0;
120 161
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 this->onGetBlendInfo(blendInfo); 241 this->onGetBlendInfo(blendInfo);
201 } 242 }
202 243
203 bool willReadDstColor() const { return fWillReadDstColor; } 244 bool willReadDstColor() const { return fWillReadDstColor; }
204 245
205 /** 246 /**
206 * Returns the texture to be used as the destination when reading the dst in the fragment 247 * Returns the texture to be used as the destination when reading the dst in the fragment
207 * shader. If the returned texture is NULL then the XP is either not reading the dst or we have 248 * shader. If the returned texture is NULL then the XP is either not reading the dst or we have
208 * extentions that support framebuffer fetching and thus don't need a copy o f the dst texture. 249 * extentions that support framebuffer fetching and thus don't need a copy o f the dst texture.
209 */ 250 */
210 const GrTexture* getDstCopyTexture() const { return fDstCopy.getTexture(); } 251 const GrTexture* getDstTexture() const { return fDstTexture.getTexture(); }
211 252
212 /** 253 /**
213 * Returns the offset into the DstCopyTexture to use when reading it in the shader. This value 254 * Returns the offset in device coords to use when accessing the dst texture to get the dst
214 * is only valid if getDstCopyTexture() != NULL. 255 * pixel color in the shader. This value is only valid if getDstTexture() != NULL.
215 */ 256 */
216 const SkIPoint& dstCopyTextureOffset() const { 257 const SkIPoint& dstTextureOffset() const {
217 SkASSERT(this->getDstCopyTexture()); 258 SkASSERT(this->getDstTexture());
218 return fDstCopyTextureOffset; 259 return fDstTextureOffset;
219 } 260 }
220 261
221 /** 262 /**
222 * Returns whether or not the XP will look at coverage when doing its blendi ng. 263 * Returns whether or not the XP will look at coverage when doing its blendi ng.
223 */ 264 */
224 bool readsCoverage() const { return fReadsCoverage; } 265 bool readsCoverage() const { return fReadsCoverage; }
225 266
226 /** 267 /**
227 * Returns whether or not this xferProcossor will set a secondary output to be used with dual 268 * Returns whether or not this xferProcossor will set a secondary output to be used with dual
228 * source blending. 269 * source blending.
(...skipping 10 matching lines...) Expand all
239 bool isEqual(const GrXferProcessor& that) const { 280 bool isEqual(const GrXferProcessor& that) const {
240 if (this->classID() != that.classID()) { 281 if (this->classID() != that.classID()) {
241 return false; 282 return false;
242 } 283 }
243 if (this->fWillReadDstColor != that.fWillReadDstColor) { 284 if (this->fWillReadDstColor != that.fWillReadDstColor) {
244 return false; 285 return false;
245 } 286 }
246 if (this->fReadsCoverage != that.fReadsCoverage) { 287 if (this->fReadsCoverage != that.fReadsCoverage) {
247 return false; 288 return false;
248 } 289 }
249 if (this->fDstCopy.getTexture() != that.fDstCopy.getTexture()) { 290 if (this->fDstTexture.getTexture() != that.fDstTexture.getTexture()) {
250 return false; 291 return false;
251 } 292 }
252 if (this->fDstCopyTextureOffset != that.fDstCopyTextureOffset) { 293 if (this->fDstTextureOffset != that.fDstTextureOffset) {
253 return false; 294 return false;
254 } 295 }
255 return this->onIsEqual(that); 296 return this->onIsEqual(that);
256 } 297 }
257 298
258 protected: 299 protected:
259 GrXferProcessor(); 300 GrXferProcessor();
260 GrXferProcessor(const GrDeviceCoordTexture* dstCopy, bool willReadDstColor); 301 GrXferProcessor(const DstTexture*, bool willReadDstColor);
261 302
262 private: 303 private:
263 virtual OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, 304 virtual OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI,
264 const GrProcOptInfo& coveragePOI, 305 const GrProcOptInfo& coveragePOI,
265 bool doesStencilWrite, 306 bool doesStencilWrite,
266 GrColor* overrideColor, 307 GrColor* overrideColor,
267 const GrCaps& caps) = 0; 308 const GrCaps& caps) = 0;
268 309
269 /** 310 /**
270 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate d with this xfer 311 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate d with this xfer
(...skipping 16 matching lines...) Expand all
287 * Retrieves the hardware blend state required by this Xfer processor. The B lendInfo struct 328 * Retrieves the hardware blend state required by this Xfer processor. The B lendInfo struct
288 * comes initialized to default values, so the Xfer processor only needs to set the state it 329 * comes initialized to default values, so the Xfer processor only needs to set the state it
289 * needs. It may not even need to override this method at all. 330 * needs. It may not even need to override this method at all.
290 */ 331 */
291 virtual void onGetBlendInfo(BlendInfo*) const {} 332 virtual void onGetBlendInfo(BlendInfo*) const {}
292 333
293 virtual bool onIsEqual(const GrXferProcessor&) const = 0; 334 virtual bool onIsEqual(const GrXferProcessor&) const = 0;
294 335
295 bool fWillReadDstColor; 336 bool fWillReadDstColor;
296 bool fReadsCoverage; 337 bool fReadsCoverage;
297 SkIPoint fDstCopyTextureOffset; 338 SkIPoint fDstTextureOffset;
298 GrTextureAccess fDstCopy; 339 GrTextureAccess fDstTexture;
299 340
300 typedef GrFragmentProcessor INHERITED; 341 typedef GrFragmentProcessor INHERITED;
301 }; 342 };
302 343
303 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); 344 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags);
304 345
305 /////////////////////////////////////////////////////////////////////////////// 346 ///////////////////////////////////////////////////////////////////////////////
306 347
307 /** 348 /**
308 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is 349 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is
309 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the 350 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the
310 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the 351 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the
311 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for 352 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for
312 * the draw. 353 * the draw.
313 * 354 *
314 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it 355 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it
315 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP 356 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP
316 * blend with the destination color. 357 * blend with the destination color.
317 */ 358 */
318 class GrXPFactory : public SkRefCnt { 359 class GrXPFactory : public SkRefCnt {
319 public: 360 public:
361 typedef GrXferProcessor::DstTexture DstTexture;
320 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, 362 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI,
321 const GrProcOptInfo& coveragePOI, 363 const GrProcOptInfo& coveragePOI,
322 const GrDeviceCoordTexture* dstCopy, 364 const DstTexture*,
323 const GrCaps& caps) const; 365 const GrCaps& caps) const;
324 366
325 /** 367 /**
326 * This function returns true if the GrXferProcessor generated from this fac tory will be able to 368 * This function returns true if the GrXferProcessor generated from this fac tory will be able to
327 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the 369 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the
328 * final computed color from the color stages. 370 * final computed color from the color stages.
329 */ 371 */
330 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0; 372 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0;
331 373
332 struct InvariantOutput { 374 struct InvariantOutput {
333 bool fWillBlendWithDst; 375 bool fWillBlendWithDst;
334 GrColor fBlendedColor; 376 GrColor fBlendedColor;
335 uint32_t fBlendedColorFlags; 377 uint32_t fBlendedColorFlags;
336 }; 378 };
337 379
338 /** 380 /**
339 * This function returns known information about the output of the xfer proc essor produced by 381 * This function returns known information about the output of the xfer proc essor produced by
340 * this xp factory. The invariant color information returned by this functio n refers to the 382 * this xp factory. The invariant color information returned by this functio n refers to the
341 * final color produced after all blending. 383 * final color produced after all blending.
342 */ 384 */
343 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO ptInfo& coveragePOI, 385 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO ptInfo& coveragePOI,
344 InvariantOutput*) const = 0; 386 InvariantOutput*) const = 0;
345 387
346 bool willNeedDstCopy(const GrCaps& caps, const GrProcOptInfo& colorPOI, 388 bool willNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& colorPOI,
347 const GrProcOptInfo& coveragePOI) const; 389 const GrProcOptInfo& coveragePOI) const;
348 390
349 bool isEqual(const GrXPFactory& that) const { 391 bool isEqual(const GrXPFactory& that) const {
350 if (this->classID() != that.classID()) { 392 if (this->classID() != that.classID()) {
351 return false; 393 return false;
352 } 394 }
353 return this->onIsEqual(that); 395 return this->onIsEqual(that);
354 } 396 }
355 397
356 /** 398 /**
357 * Helper for down-casting to a GrXPFactory subclass 399 * Helper for down-casting to a GrXPFactory subclass
358 */ 400 */
359 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } 401 template <typename T> const T& cast() const { return *static_cast<const T*>( this); }
360 402
361 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; } 403 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; }
362 404
363 protected: 405 protected:
364 GrXPFactory() : fClassID(kIllegalXPFClassID) {} 406 GrXPFactory() : fClassID(kIllegalXPFClassID) {}
365 407
366 template <typename XPF_SUBCLASS> void initClassID() { 408 template <typename XPF_SUBCLASS> void initClassID() {
367 static uint32_t kClassID = GenClassID(); 409 static uint32_t kClassID = GenClassID();
368 fClassID = kClassID; 410 fClassID = kClassID;
369 } 411 }
370 412
371 uint32_t fClassID; 413 uint32_t fClassID;
372 414
373 private: 415 private:
374 virtual GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, 416 virtual GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
375 const GrProcOptInfo& colorPOI , 417 const GrProcOptInfo& colorPOI ,
376 const GrProcOptInfo& coverage POI, 418 const GrProcOptInfo& coverage POI,
377 const GrDeviceCoordTexture* d stCopy) const = 0; 419 const DstTexture*) const = 0;
378 /** 420 /**
379 * Returns true if the XP generated by this factory will explicitly read ds t in the fragment 421 * Returns true if the XP generated by this factory will explicitly read ds t in the fragment
380 * shader. 422 * shader.
381 */ 423 */
382 virtual bool willReadDstColor(const GrCaps& caps, 424 virtual bool willReadDstColor(const GrCaps& caps,
383 const GrProcOptInfo& colorPOI, 425 const GrProcOptInfo& colorPOI,
384 const GrProcOptInfo& coveragePOI) const = 0; 426 const GrProcOptInfo& coveragePOI) const = 0;
385 427
386 virtual bool onIsEqual(const GrXPFactory&) const = 0; 428 virtual bool onIsEqual(const GrXPFactory&) const = 0;
387 429
(...skipping 12 matching lines...) Expand all
400 enum { 442 enum {
401 kIllegalXPFClassID = 0, 443 kIllegalXPFClassID = 0,
402 }; 444 };
403 static int32_t gCurrXPFClassID; 445 static int32_t gCurrXPFClassID;
404 446
405 typedef GrProgramElement INHERITED; 447 typedef GrProgramElement INHERITED;
406 }; 448 };
407 449
408 #endif 450 #endif
409 451
OLDNEW
« no previous file with comments | « include/gpu/GrTexture.h ('k') | include/gpu/effects/GrCoverageSetOpXP.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698