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

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

Issue 15715012: Decrease GPU drawn brightness for < 1 pixel wide/high rects (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Address code review comment Created 7 years, 7 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
« no previous file with comments | « no previous file | no next file » | 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 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 "GrAARectRenderer.h" 8 #include "GrAARectRenderer.h"
9 #include "GrRefCnt.h" 9 #include "GrRefCnt.h"
10 #include "GrGpu.h" 10 #include "GrGpu.h"
11 #include "gl/GrGLEffect.h" 11 #include "gl/GrGLEffect.h"
12 #include "GrTBackendEffectFactory.h" 12 #include "GrTBackendEffectFactory.h"
13 #include "SkColorPriv.h"
13 14
14 SK_DEFINE_INST_COUNT(GrAARectRenderer) 15 SK_DEFINE_INST_COUNT(GrAARectRenderer)
15 16
16 /////////////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////////////
17 class GrGLAlignedRectEffect; 18 class GrGLAlignedRectEffect;
18 19
19 // Axis Aligned special case 20 // Axis Aligned special case
20 class GrAlignedRectEffect : public GrEffect { 21 class GrAlignedRectEffect : public GrEffect {
21 public: 22 public:
22 static GrEffectRef* Create() { 23 static GrEffectRef* Create() {
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 return; 383 return;
383 } 384 }
384 385
385 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); 386 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
386 size_t vsize = drawState->getVertexSize(); 387 size_t vsize = drawState->getVertexSize();
387 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize); 388 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize);
388 389
389 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); 390 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts);
390 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); 391 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize);
391 392
393 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1);
394 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height());
395
392 if (combinedMatrix.rectStaysRect()) { 396 if (combinedMatrix.rectStaysRect()) {
393 // Temporarily #if'ed out. We don't want to pass in the devRect but 397 // Temporarily #if'ed out. We don't want to pass in the devRect but
394 // right now it is computed in GrContext::apply_aa_to_rect and we don't 398 // right now it is computed in GrContext::apply_aa_to_rect and we don't
395 // want to throw away the work 399 // want to throw away the work
396 #if 0 400 #if 0
397 SkRect devRect; 401 SkRect devRect;
398 combinedMatrix.mapRect(&devRect, rect); 402 combinedMatrix.mapRect(&devRect, rect);
399 #endif 403 #endif
400 404
401 set_inset_fan(fan0Pos, vsize, devRect, -SK_ScalarHalf, -SK_ScalarHalf); 405 set_inset_fan(fan0Pos, vsize, devRect, -SK_ScalarHalf, -SK_ScalarHalf);
402 set_inset_fan(fan1Pos, vsize, devRect, SK_ScalarHalf, SK_ScalarHalf); 406 set_inset_fan(fan1Pos, vsize, devRect, inset, inset);
403 } else { 407 } else {
404 // compute transformed (1, 0) and (0, 1) vectors 408 // compute transformed (1, 0) and (0, 1) vectors
405 SkVector vec[2] = { 409 SkVector vec[2] = {
406 { combinedMatrix[SkMatrix::kMScaleX], combinedMatrix[SkMatrix::kMSkewY ] }, 410 { combinedMatrix[SkMatrix::kMScaleX], combinedMatrix[SkMatrix::kMSkewY ] },
407 { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix::kMScale Y] } 411 { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix::kMScale Y] }
408 }; 412 };
409 413
410 vec[0].normalize(); 414 vec[0].normalize();
411 vec[0].scale(SK_ScalarHalf); 415 vec[0].scale(SK_ScalarHalf);
412 vec[1].normalize(); 416 vec[1].normalize();
(...skipping 23 matching lines...) Expand all
436 *((SkPoint*)((intptr_t)fan1Pos + 3 * vsize)) = 440 *((SkPoint*)((intptr_t)fan1Pos + 3 * vsize)) =
437 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) - vec[0] + vec[1]; 441 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) - vec[0] + vec[1];
438 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) += vec[0] - vec[1]; 442 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) += vec[0] - vec[1];
439 } 443 }
440 444
441 verts += sizeof(GrPoint); 445 verts += sizeof(GrPoint);
442 for (int i = 0; i < 4; ++i) { 446 for (int i = 0; i < 4; ++i) {
443 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; 447 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
444 } 448 }
445 449
450 int scale;
451 if (inset < SK_ScalarHalf) {
452 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf));
453 SkASSERT(scale >= 0 && scale <= 255);
454 } else {
455 scale = 0xff;
456 }
457
446 GrColor innerColor; 458 GrColor innerColor;
447 if (useVertexCoverage) { 459 if (useVertexCoverage) {
448 innerColor = 0xffffffff; 460 innerColor = scale | (scale << 8) | (scale << 16) | (scale << 24);
449 } else { 461 } else {
450 innerColor = target->getDrawState().getColor(); 462 if (0xff == scale) {
463 innerColor = target->getDrawState().getColor();
464 } else {
465 innerColor = SkAlphaMulQ(target->getDrawState().getColor(), scale);
466 }
451 } 467 }
452 468
453 verts += 4 * vsize; 469 verts += 4 * vsize;
454 for (int i = 0; i < 4; ++i) { 470 for (int i = 0; i < 4; ++i) {
455 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor; 471 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor;
456 } 472 }
457 473
458 target->setIndexSourceToBuffer(indexBuffer); 474 target->setIndexSourceToBuffer(indexBuffer);
459 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 475 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1,
460 kVertsPerAAFillRect, 476 kVertsPerAAFillRect,
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 // can't call mapRect for devInside since it calls sort 778 // can't call mapRect for devInside since it calls sort
763 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 779 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
764 780
765 if (devInside.isEmpty()) { 781 if (devInside.isEmpty()) {
766 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage); 782 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage);
767 return; 783 return;
768 } 784 }
769 785
770 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage); 786 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage);
771 } 787 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698