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

Side by Side Diff: src/gpu/GrDrawState.cpp

Issue 25023003: Implement color filter as GrGLEffect (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 #include "GrDrawState.h" 8 #include "GrDrawState.h"
9 #include "GrPaint.h" 9 #include "GrPaint.h"
10 10
11 bool GrDrawState::setIdentityViewMatrix() { 11 bool GrDrawState::setIdentityViewMatrix() {
12 if (fColorStages.count() || fCoverageStages.count()) { 12 if (fColorStages.count() || fCoverageStages.count()) {
13 SkMatrix invVM; 13 SkMatrix invVM;
14 if (!fCommon.fViewMatrix.invert(&invVM)) { 14 if (!fCommon.fViewMatrix.invert(&invVM)) {
15 // sad trombone sound 15 // sad trombone sound
16 return false; 16 return false;
17 } 17 }
18 for (int s = 0; s < fColorStages.count(); ++s) { 18 for (int s = 0; s < fColorStages.count(); ++s) {
19 fColorStages[s].localCoordChange(invVM); 19 fColorStages[s].localCoordChange(invVM);
20 } 20 }
21 for (int s = 0; s < fCoverageStages.count(); ++s) { 21 for (int s = 0; s < fCoverageStages.count(); ++s) {
22 fCoverageStages[s].localCoordChange(invVM); 22 fCoverageStages[s].localCoordChange(invVM);
23 } 23 }
24 } 24 }
25 fCommon.fViewMatrix.reset(); 25 fCommon.fViewMatrix.reset();
26 return true; 26 return true;
27 } 27 }
28 28
29 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende rTarget* rt) { 29 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende rTarget* rt) {
30 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); 30 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->totalStageCount());
31 31
32 fColorStages.reset(); 32 fColorStages.reset();
33 fCoverageStages.reset(); 33 fCoverageStages.reset();
34 34
35 for (int i = 0; i < paint.numColorStages(); ++i) { 35 for (int i = 0; i < paint.numColorStages(); ++i) {
36 fColorStages.push_back(paint.getColorStage(i)); 36 fColorStages.appendStage(paint.getColorStage(i));
37 } 37 }
38 38
39 for (int i = 0; i < paint.numCoverageStages(); ++i) { 39 for (int i = 0; i < paint.numCoverageStages(); ++i) {
40 fCoverageStages.push_back(paint.getCoverageStage(i)); 40 fCoverageStages.appendStage(paint.getCoverageStage(i));
41 } 41 }
42 42
43 this->setRenderTarget(rt); 43 this->setRenderTarget(rt);
44 44
45 fCommon.fViewMatrix = vm; 45 fCommon.fViewMatrix = vm;
46 46
47 // These have no equivalent in GrPaint, set them to defaults 47 // These have no equivalent in GrPaint, set them to defaults
48 fCommon.fBlendConstant = 0x0; 48 fCommon.fBlendConstant = 0x0;
49 fCommon.fDrawFace = kBoth_DrawFace; 49 fCommon.fDrawFace = kBoth_DrawFace;
50 fCommon.fStencilSettings.setDisabled(); 50 fCommon.fStencilSettings.setDisabled();
51 this->resetStateFlags(); 51 this->resetStateFlags();
52 52
53 // Enable the clip bit 53 // Enable the clip bit
54 this->enableState(GrDrawState::kClip_StateBit); 54 this->enableState(GrDrawState::kClip_StateBit);
55 55
56 this->setColor(paint.getColor()); 56 this->setColor(paint.getColor());
57 this->setCoverage4(paint.getCoverage()); 57 this->setCoverage4(paint.getCoverage());
58 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); 58 this->setState(GrDrawState::kDither_StateBit, paint.isDither());
59 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); 59 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias());
60 60
61 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); 61 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff());
62 this->setColorFilter(paint.getColorFilterColor(), paint.getColorFilterMode() );
63 this->setCoverage(paint.getCoverage()); 62 this->setCoverage(paint.getCoverage());
64 } 63 }
65 64
66 //////////////////////////////////////////////////////////////////////////////// 65 ////////////////////////////////////////////////////////////////////////////////
67 66
68 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { 67 static size_t vertex_size(const GrVertexAttrib* attribs, int count) {
69 // this works as long as we're 4 byte-aligned 68 // this works as long as we're 4 byte-aligned
70 #ifdef SK_DEBUG 69 #ifdef SK_DEBUG
71 uint32_t overlapCheck = 0; 70 uint32_t overlapCheck = 0;
72 #endif 71 #endif
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 validComponentFlags = kRGBA_GrColorComponentFlags; 211 validComponentFlags = kRGBA_GrColorComponentFlags;
213 color = this->getColor(); 212 color = this->getColor();
214 } 213 }
215 214
216 // Run through the color stages 215 // Run through the color stages
217 for (int s = 0; s < fColorStages.count(); ++s) { 216 for (int s = 0; s < fColorStages.count(); ++s) {
218 const GrEffectRef* effect = fColorStages[s].getEffect(); 217 const GrEffectRef* effect = fColorStages[s].getEffect();
219 (*effect)->getConstantColorComponents(&color, &validComponentFlags); 218 (*effect)->getConstantColorComponents(&color, &validComponentFlags);
220 } 219 }
221 220
222 // Check if the color filter could introduce an alpha.
223 // We could skip the above work when this is true, but it is rare and the ri ght fix is to make
224 // the color filter a GrEffect and implement getConstantColorComponents() fo r it.
225 if (SkXfermode::kDst_Mode != this->getColorFilterMode()) {
226 validComponentFlags = 0;
227 }
228
229 // Check whether coverage is treated as color. If so we run through the cove rage computation. 221 // Check whether coverage is treated as color. If so we run through the cove rage computation.
230 if (this->isCoverageDrawing()) { 222 if (this->isCoverageDrawing()) {
231 GrColor coverageColor = this->getCoverage(); 223 GrColor coverageColor = this->getCoverage();
232 GrColor oldColor = color; 224 GrColor oldColor = color;
233 color = 0; 225 color = 0;
234 for (int c = 0; c < 4; ++c) { 226 for (int c = 0; c < 4; ++c) {
235 if (validComponentFlags & (1 << c)) { 227 if (validComponentFlags & (1 << c)) {
236 U8CPU a = (oldColor >> (c * 8)) & 0xff; 228 U8CPU a = (oldColor >> (c * 8)) & 0xff;
237 U8CPU b = (coverageColor >> (c * 8)) & 0xff; 229 U8CPU b = (coverageColor >> (c * 8)) & 0xff;
238 color |= (SkMulDiv255Round(a, b) << (c * 8)); 230 color |= (SkMulDiv255Round(a, b) << (c * 8));
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 387 }
396 return kNone_BlendOpt; 388 return kNone_BlendOpt;
397 } 389 }
398 390
399 //////////////////////////////////////////////////////////////////////////////// 391 ////////////////////////////////////////////////////////////////////////////////
400 392
401 void GrDrawState::AutoViewMatrixRestore::restore() { 393 void GrDrawState::AutoViewMatrixRestore::restore() {
402 if (NULL != fDrawState) { 394 if (NULL != fDrawState) {
403 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) 395 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
404 fDrawState->fCommon.fViewMatrix = fViewMatrix; 396 fDrawState->fCommon.fViewMatrix = fViewMatrix;
405 SkASSERT(fDrawState->numColorStages() >= fNumColorStages); 397 SkASSERT(fDrawState->fColorStages.count() >= fNumColorStages);
406 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; 398 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages;
407 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages); 399 SkASSERT(fDrawState->fCoverageStages.count() >= numCoverageStages);
408 400
409 int i = 0; 401 int i = 0;
410 for (int s = 0; s < fNumColorStages; ++s, ++i) { 402 for (int s = 0; s < fNumColorStages; ++s, ++i) {
411 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i] ); 403 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i] );
412 } 404 }
413 for (int s = 0; s < numCoverageStages; ++s, ++i) { 405 for (int s = 0; s < numCoverageStages; ++s, ++i) {
414 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges [i]); 406 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges [i]);
415 } 407 }
416 fDrawState = NULL; 408 fDrawState = NULL;
417 } 409 }
(...skipping 21 matching lines...) Expand all
439 431
440 if (NULL == drawState) { 432 if (NULL == drawState) {
441 return false; 433 return false;
442 } 434 }
443 435
444 if (drawState->getViewMatrix().isIdentity()) { 436 if (drawState->getViewMatrix().isIdentity()) {
445 return true; 437 return true;
446 } 438 }
447 439
448 fViewMatrix = drawState->getViewMatrix(); 440 fViewMatrix = drawState->getViewMatrix();
449 if (0 == drawState->numTotalStages()) { 441 if (0 == drawState->totalStageCount()) {
450 drawState->fCommon.fViewMatrix.reset(); 442 drawState->fCommon.fViewMatrix.reset();
451 fDrawState = drawState; 443 fDrawState = drawState;
452 fNumColorStages = 0; 444 fNumColorStages = 0;
453 fSavedCoordChanges.reset(0); 445 fSavedCoordChanges.reset(0);
454 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) 446 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
455 return true; 447 return true;
456 } else { 448 } else {
457 SkMatrix inv; 449 SkMatrix inv;
458 if (!fViewMatrix.invert(&inv)) { 450 if (!fViewMatrix.invert(&inv)) {
459 return false; 451 return false;
460 } 452 }
461 drawState->fCommon.fViewMatrix.reset(); 453 drawState->fCommon.fViewMatrix.reset();
462 fDrawState = drawState; 454 fDrawState = drawState;
463 this->doEffectCoordChanges(inv); 455 this->doEffectCoordChanges(inv);
464 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) 456 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
465 return true; 457 return true;
466 } 458 }
467 } 459 }
468 460
469 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co ordChangeMatrix) { 461 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co ordChangeMatrix) {
470 fSavedCoordChanges.reset(fDrawState->numTotalStages()); 462 fSavedCoordChanges.reset(fDrawState->totalStageCount());
471 int i = 0; 463 int i = 0;
472 464
473 fNumColorStages = fDrawState->numColorStages(); 465 fNumColorStages = fDrawState->fColorStages.count();
474 for (int s = 0; s < fNumColorStages; ++s, ++i) { 466 for (int s = 0; s < fNumColorStages; ++s, ++i) {
475 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); 467 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]);
476 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); 468 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix);
477 } 469 }
478 470
479 int numCoverageStages = fDrawState->numCoverageStages(); 471 int numCoverageStages = fDrawState->fCoverageStages.count();
480 for (int s = 0; s < numCoverageStages; ++s, ++i) { 472 for (int s = 0; s < numCoverageStages; ++s, ++i) {
481 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); 473 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]);
482 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); 474 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix);
483 } 475 }
484 } 476 }
OLDNEW
« src/gpu/GrDrawState.h ('K') | « src/gpu/GrDrawState.h ('k') | src/gpu/GrDrawTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698