| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); | 351 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); |
| 352 GrDrawState* drawState = fGpu->drawState(); | 352 GrDrawState* drawState = fGpu->drawState(); |
| 353 drawState->setRenderTarget(texture->asRenderTarget()); | 353 drawState->setRenderTarget(texture->asRenderTarget()); |
| 354 | 354 |
| 355 // if filtering is not desired then we want to ensure all | 355 // if filtering is not desired then we want to ensure all |
| 356 // texels in the resampled image are copies of texels from | 356 // texels in the resampled image are copies of texels from |
| 357 // the original. | 357 // the original. |
| 358 GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering); | 358 GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering); |
| 359 drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params)
; | 359 drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params)
; |
| 360 | 360 |
| 361 // position + texture coordinate | 361 // position + local coordinate |
| 362 static const GrVertexAttrib kVertexAttribs[] = { | 362 static const GrVertexAttrib kVertexAttribs[] = { |
| 363 {kVec2f_GrVertexAttribType, 0}, | 363 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttri
bBinding}, |
| 364 {kVec2f_GrVertexAttribType, sizeof(GrPoint)} | 364 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAtt
ribBinding} |
| 365 }; | 365 }; |
| 366 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttrib
s)); |
| 366 | 367 |
| 367 static const GrAttribBindings kAttribBindings = GrDrawState::kLocalCoord
s_AttribBindingsBit; | |
| 368 drawState->setAttribBindings(kAttribBindings); | |
| 369 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttrib
s)); | |
| 370 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); | |
| 371 drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, 1); | |
| 372 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); | 368 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); |
| 373 | 369 |
| 374 if (arg.succeeded()) { | 370 if (arg.succeeded()) { |
| 375 GrPoint* verts = (GrPoint*) arg.vertices(); | 371 GrPoint* verts = (GrPoint*) arg.vertices(); |
| 376 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(GrPoint)); | 372 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(GrPoint)); |
| 377 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint)); | 373 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint)); |
| 378 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); | 374 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); |
| 379 } | 375 } |
| 380 texture->releaseRenderTarget(); | 376 texture->releaseRenderTarget(); |
| 381 } else { | 377 } else { |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 GrDrawTarget::AutoReleaseGeometry geo; | 914 GrDrawTarget::AutoReleaseGeometry geo; |
| 919 | 915 |
| 920 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 916 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); |
| 921 GrDrawState::AutoStageDisable atr(fDrawState); | 917 GrDrawState::AutoStageDisable atr(fDrawState); |
| 922 | 918 |
| 923 GrDrawState* drawState = target->drawState(); | 919 GrDrawState* drawState = target->drawState(); |
| 924 | 920 |
| 925 GrVertexAttribArray<3> attribs; | 921 GrVertexAttribArray<3> attribs; |
| 926 size_t currentOffset = 0; | 922 size_t currentOffset = 0; |
| 927 int colorOffset = -1, texOffset = -1; | 923 int colorOffset = -1, texOffset = -1; |
| 928 GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings; | |
| 929 | 924 |
| 930 // set position attribute | 925 // set position attribute |
| 931 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count(
)); | 926 GrVertexAttrib currAttrib = |
| 932 GrVertexAttrib currAttrib = {kVec2f_GrVertexAttribType, currentOffset}; | 927 {kVec2f_GrVertexAttribType, currentOffset, kPosition_GrVertexAttribBindi
ng}; |
| 933 attribs.push_back(currAttrib); | 928 attribs.push_back(currAttrib); |
| 934 currentOffset += sizeof(GrPoint); | 929 currentOffset += sizeof(GrPoint); |
| 935 | 930 |
| 936 // set up optional texture coordinate attributes | 931 // set up optional texture coordinate attributes |
| 937 if (NULL != texCoords) { | 932 if (NULL != texCoords) { |
| 938 bindings |= GrDrawState::kLocalCoords_AttribBindingsBit; | 933 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset, kLocalCoord_GrV
ertexAttribBinding); |
| 939 drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, attribs
.count()); | |
| 940 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset); | |
| 941 attribs.push_back(currAttrib); | 934 attribs.push_back(currAttrib); |
| 942 texOffset = currentOffset; | 935 texOffset = currentOffset; |
| 943 currentOffset += sizeof(GrPoint); | 936 currentOffset += sizeof(GrPoint); |
| 944 } | 937 } |
| 945 | 938 |
| 946 // set up optional color attributes | 939 // set up optional color attributes |
| 947 if (NULL != colors) { | 940 if (NULL != colors) { |
| 948 bindings |= GrDrawState::kColor_AttribBindingsBit; | 941 currAttrib.set(kVec4ub_GrVertexAttribType, currentOffset, kColor_GrVerte
xAttribBinding); |
| 949 drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count
()); | |
| 950 currAttrib.set(kVec4ub_GrVertexAttribType, currentOffset); | |
| 951 attribs.push_back(currAttrib); | 942 attribs.push_back(currAttrib); |
| 952 colorOffset = currentOffset; | 943 colorOffset = currentOffset; |
| 953 currentOffset += sizeof(GrColor); | 944 currentOffset += sizeof(GrColor); |
| 954 } | 945 } |
| 955 | 946 |
| 956 drawState->setVertexAttribs(attribs.begin(), attribs.count()); | 947 drawState->setVertexAttribs(attribs.begin(), attribs.count()); |
| 957 drawState->setAttribBindings(bindings); | |
| 958 | 948 |
| 959 size_t vertexSize = drawState->getVertexSize(); | 949 size_t vertexSize = drawState->getVertexSize(); |
| 960 GrAssert(vertexSize == currentOffset); | 950 GrAssert(vertexSize == currentOffset); |
| 961 if (sizeof(GrPoint) != vertexSize) { | 951 if (sizeof(GrPoint) != vertexSize) { |
| 962 if (!geo.set(target, vertexCount, 0)) { | 952 if (!geo.set(target, vertexCount, 0)) { |
| 963 GrPrintf("Failed to get space for vertices!\n"); | 953 GrPrintf("Failed to get space for vertices!\n"); |
| 964 return; | 954 return; |
| 965 } | 955 } |
| 966 void* curVertex = geo.vertices(); | 956 void* curVertex = geo.vertices(); |
| 967 | 957 |
| (...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1808 return srcTexture; | 1798 return srcTexture; |
| 1809 } | 1799 } |
| 1810 } | 1800 } |
| 1811 | 1801 |
| 1812 /////////////////////////////////////////////////////////////////////////////// | 1802 /////////////////////////////////////////////////////////////////////////////// |
| 1813 #if GR_CACHE_STATS | 1803 #if GR_CACHE_STATS |
| 1814 void GrContext::printCacheStats() const { | 1804 void GrContext::printCacheStats() const { |
| 1815 fTextureCache->printStats(); | 1805 fTextureCache->printStats(); |
| 1816 } | 1806 } |
| 1817 #endif | 1807 #endif |
| OLD | NEW |