Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| 11 #include "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
| 12 #include "GrContext.h" | 12 #include "GrContext.h" |
| 13 #include "GrDrawTargetCaps.h" | 13 #include "GrDrawTargetCaps.h" |
| 14 #include "GrPath.h" | 14 #include "GrPath.h" |
| 15 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
| 16 #include "GrTexture.h" | 16 #include "GrTexture.h" |
| 17 #include "GrVertexBuffer.h" | 17 #include "GrVertexBuffer.h" |
| 18 | 18 |
| 19 #include "SkStrokeRec.h" | 19 #include "SkStrokeRec.h" |
| 20 #include "SkTSort.h" | |
| 20 | 21 |
| 21 //////////////////////////////////////////////////////////////////////////////// | 22 //////////////////////////////////////////////////////////////////////////////// |
| 22 | 23 |
| 23 GrDrawTarget::DrawInfo& GrDrawTarget::DrawInfo::operator =(const DrawInfo& di) { | 24 GrDrawTarget::DrawInfo& GrDrawTarget::DrawInfo::operator =(const DrawInfo& di) { |
| 24 fPrimitiveType = di.fPrimitiveType; | 25 fPrimitiveType = di.fPrimitiveType; |
| 25 fStartVertex = di.fStartVertex; | 26 fStartVertex = di.fStartVertex; |
| 26 fStartIndex = di.fStartIndex; | 27 fStartIndex = di.fStartIndex; |
| 27 fVertexCount = di.fVertexCount; | 28 fVertexCount = di.fVertexCount; |
| 28 fIndexCount = di.fIndexCount; | 29 fIndexCount = di.fIndexCount; |
| 29 | 30 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 } | 83 } |
| 83 | 84 |
| 84 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
| 85 | 86 |
| 86 #define DEBUG_INVAL_BUFFER 0xdeadcafe | 87 #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 87 #define DEBUG_INVAL_START_IDX -1 | 88 #define DEBUG_INVAL_START_IDX -1 |
| 88 | 89 |
| 89 GrDrawTarget::GrDrawTarget(GrContext* context) | 90 GrDrawTarget::GrDrawTarget(GrContext* context) |
| 90 : fClip(NULL) | 91 : fClip(NULL) |
| 91 , fContext(context) | 92 , fContext(context) |
| 92 , fPushGpuTraceCount(0) { | 93 , fGpuTraceMarkerCount(0) { |
| 93 SkASSERT(NULL != context); | 94 SkASSERT(NULL != context); |
| 94 | 95 |
| 95 fDrawState = &fDefaultDrawState; | 96 fDrawState = &fDefaultDrawState; |
| 96 // We assume that fDrawState always owns a ref to the object it points at. | 97 // We assume that fDrawState always owns a ref to the object it points at. |
| 97 fDefaultDrawState.ref(); | 98 fDefaultDrawState.ref(); |
| 98 GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back(); | 99 GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back(); |
| 99 #ifdef SK_DEBUG | 100 #ifdef SK_DEBUG |
| 100 geoSrc.fVertexCount = DEBUG_INVAL_START_IDX; | 101 geoSrc.fVertexCount = DEBUG_INVAL_START_IDX; |
| 101 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; | 102 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 102 geoSrc.fIndexCount = DEBUG_INVAL_START_IDX; | 103 geoSrc.fIndexCount = DEBUG_INVAL_START_IDX; |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 viewM.mapRect(&devBounds); | 542 viewM.mapRect(&devBounds); |
| 542 | 543 |
| 543 GrDeviceCoordTexture dstCopy; | 544 GrDeviceCoordTexture dstCopy; |
| 544 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) { | 545 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) { |
| 545 return; | 546 return; |
| 546 } | 547 } |
| 547 | 548 |
| 548 this->onDrawPath(path, fill, dstCopy.texture() ? &dstCopy : NULL); | 549 this->onDrawPath(path, fill, dstCopy.texture() ? &dstCopy : NULL); |
| 549 } | 550 } |
| 550 | 551 |
| 551 void GrDrawTarget::instantGpuTraceEvent(const char* marker) { | 552 SkString GrDrawTarget::getTraceString(SkTDArray<GpuTraceMarker>* markerArray, |
| 553 int startIdx, int numMarkers) { | |
| 554 SkTQSort<GpuTraceMarker>(markerArray->begin() + startIdx, | |
| 555 markerArray->begin() + startIdx + numMarkers - 1); | |
| 556 SkString marker_string; | |
| 557 const char* currBaseCmd = ""; | |
|
bsalomon
2014/03/17 17:50:38
It took me a little bit to understand what this is
egdaniel
2014/03/17 19:49:12
Agree.
On 2014/03/17 17:50:38, bsalomon wrote:
| |
| 558 int counter = 0; | |
| 559 | |
| 560 // check used for GrGpuGL device after we've already collapsed all markers | |
| 561 if (1 == numMarkers && -1 == (*markerArray)[0].fID) { | |
| 562 marker_string.append((*markerArray)[0].fMarker); | |
| 563 return marker_string; | |
| 564 } | |
| 565 | |
| 566 for (int i = startIdx; counter < numMarkers; ++i ) { | |
| 567 GpuTraceMarker& currMarker = markerArray->getAt(i); | |
| 568 const char* currCmd = currMarker.fMarker; | |
| 569 if (currCmd != currBaseCmd) { | |
| 570 if (counter != 0) { | |
| 571 marker_string.append("):"); | |
| 572 } | |
| 573 marker_string.append(currCmd); | |
| 574 marker_string.append("("); | |
| 575 marker_string.appendS32(currMarker.fID); | |
| 576 currBaseCmd = currCmd; | |
| 577 } else { | |
| 578 marker_string.append(", "); | |
| 579 marker_string.appendS32(currMarker.fID); | |
| 580 } | |
| 581 ++counter; | |
| 582 } | |
| 583 if (counter > 0) { | |
| 584 marker_string.append(")"); | |
| 585 } | |
| 586 return marker_string; | |
| 587 } | |
| 588 | |
| 589 void GrDrawTarget::addTraceMarkerActiveSet(GpuTraceMarker* marker) { | |
| 590 this->fActiveTraceMarkers.push(*marker); | |
| 591 } | |
| 592 | |
| 593 void GrDrawTarget::removeTraceMarkerActiveSet(GpuTraceMarker* marker) { | |
| 594 SkASSERT(-1 != this->fActiveTraceMarkers.find(*marker)); | |
| 595 int index = this->fActiveTraceMarkers.find(*marker); | |
| 596 this->fActiveTraceMarkers.remove(index); | |
| 597 } | |
| 598 | |
| 599 void GrDrawTarget::addGpuTraceMarker(GpuTraceMarker* marker) { | |
| 552 if (this->caps()->gpuTracingSupport()) { | 600 if (this->caps()->gpuTracingSupport()) { |
| 553 this->onInstantGpuTraceEvent(marker); | 601 SkASSERT(fGpuTraceMarkerCount >= 0); |
| 602 this->addTraceMarkerActiveSet(marker); | |
| 603 this->onAddGpuTraceMarker(); | |
| 604 ++fGpuTraceMarkerCount; | |
| 554 } | 605 } |
| 555 } | 606 } |
| 556 | 607 |
| 557 void GrDrawTarget::pushGpuTraceEvent(const char* marker) { | 608 void GrDrawTarget::removeGpuTraceMarker(GpuTraceMarker* marker) { |
| 558 SkASSERT(fPushGpuTraceCount >= 0); | |
| 559 if (this->caps()->gpuTracingSupport()) { | 609 if (this->caps()->gpuTracingSupport()) { |
| 560 this->onPushGpuTraceEvent(marker); | 610 SkASSERT(fGpuTraceMarkerCount >= 1); |
| 561 ++fPushGpuTraceCount; | 611 this->removeTraceMarkerActiveSet(marker); |
| 612 this->onRemoveGpuTraceMarker(); | |
| 613 --fGpuTraceMarkerCount; | |
| 562 } | 614 } |
| 563 } | 615 } |
| 564 | 616 |
| 565 void GrDrawTarget::popGpuTraceEvent() { | 617 bool GrDrawTarget::gpuTracingEnabled() const { |
| 566 SkASSERT(fPushGpuTraceCount >= 1); | 618 return this->getContext()->gpuTracingEnabled(); |
| 567 if (this->caps()->gpuTracingSupport()) { | |
| 568 this->onPopGpuTraceEvent(); | |
| 569 --fPushGpuTraceCount; | |
| 570 } | |
| 571 } | 619 } |
| 572 | |
| 573 //////////////////////////////////////////////////////////////////////////////// | 620 //////////////////////////////////////////////////////////////////////////////// |
| 574 | 621 |
| 575 bool GrDrawTarget::willUseHWAALines() const { | 622 bool GrDrawTarget::willUseHWAALines() const { |
| 576 // There is a conflict between using smooth lines and our use of premultipli ed alpha. Smooth | 623 // There is a conflict between using smooth lines and our use of premultipli ed alpha. Smooth |
| 577 // lines tweak the incoming alpha value but not in a premul-alpha way. So we only use them when | 624 // lines tweak the incoming alpha value but not in a premul-alpha way. So we only use them when |
| 578 // our alpha is 0xff and tweaking the color for partial coverage is OK | 625 // our alpha is 0xff and tweaking the color for partial coverage is OK |
| 579 if (!this->caps()->hwAALineSupport() || | 626 if (!this->caps()->hwAALineSupport() || |
| 580 !this->getDrawState().isHWAntialiasState()) { | 627 !this->getDrawState().isHWAntialiasState()) { |
| 581 return false; | 628 return false; |
| 582 } | 629 } |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1072 for (size_t i = 0; i < SK_ARRAY_COUNT(kConfigNames); ++i) { | 1119 for (size_t i = 0; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 1073 if (i != kUnknown_GrPixelConfig) { | 1120 if (i != kUnknown_GrPixelConfig) { |
| 1074 r.appendf("%s is renderable: %s, with MSAA: %s\n", | 1121 r.appendf("%s is renderable: %s, with MSAA: %s\n", |
| 1075 kConfigNames[i], | 1122 kConfigNames[i], |
| 1076 gNY[fConfigRenderSupport[i][0]], | 1123 gNY[fConfigRenderSupport[i][0]], |
| 1077 gNY[fConfigRenderSupport[i][1]]); | 1124 gNY[fConfigRenderSupport[i][1]]); |
| 1078 } | 1125 } |
| 1079 } | 1126 } |
| 1080 return r; | 1127 return r; |
| 1081 } | 1128 } |
| OLD | NEW |