Chromium Code Reviews| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 GrDrawState* drawState = fGpu->drawState(); | 358 GrDrawState* drawState = fGpu->drawState(); |
| 359 drawState->setRenderTarget(texture->asRenderTarget()); | 359 drawState->setRenderTarget(texture->asRenderTarget()); |
| 360 | 360 |
| 361 // if filtering is not desired then we want to ensure all | 361 // if filtering is not desired then we want to ensure all |
| 362 // texels in the resampled image are copies of texels from | 362 // texels in the resampled image are copies of texels from |
| 363 // the original. | 363 // the original. |
| 364 GrTextureParams params(SkShader::kClamp_TileMode, filter ? GrTexturePara ms::kBilerp_FilterMode : | 364 GrTextureParams params(SkShader::kClamp_TileMode, filter ? GrTexturePara ms::kBilerp_FilterMode : |
| 365 GrTexturePara ms::kNone_FilterMode); | 365 GrTexturePara ms::kNone_FilterMode); |
| 366 drawState->addColorTextureEffect(clampedTexture, SkMatrix::I(), params); | 366 drawState->addColorTextureEffect(clampedTexture, SkMatrix::I(), params); |
| 367 | 367 |
| 368 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib s)); | 368 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib s), |
| 369 2 * sizeof(SkPoint)); | |
| 369 | 370 |
| 370 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); | 371 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); |
| 371 | 372 |
| 372 if (arg.succeeded()) { | 373 if (arg.succeeded()) { |
| 373 SkPoint* verts = (SkPoint*) arg.vertices(); | 374 SkPoint* verts = (SkPoint*) arg.vertices(); |
| 374 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(SkPoint)); | 375 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(SkPoint)); |
| 375 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); | 376 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); |
| 376 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); | 377 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); |
| 377 } | 378 } |
| 378 } else { | 379 } else { |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 943 static void set_vertex_attributes(GrDrawState* drawState, | 944 static void set_vertex_attributes(GrDrawState* drawState, |
| 944 const SkPoint* texCoords, | 945 const SkPoint* texCoords, |
| 945 const GrColor* colors, | 946 const GrColor* colors, |
| 946 int* colorOffset, | 947 int* colorOffset, |
| 947 int* texOffset) { | 948 int* texOffset) { |
| 948 *texOffset = -1; | 949 *texOffset = -1; |
| 949 *colorOffset = -1; | 950 *colorOffset = -1; |
| 950 | 951 |
| 951 if (NULL != texCoords && NULL != colors) { | 952 if (NULL != texCoords && NULL != colors) { |
| 952 *texOffset = sizeof(SkPoint); | 953 *texOffset = sizeof(SkPoint); |
| 953 *colorOffset = 2*sizeof(SkPoint); | 954 *colorOffset = 2*sizeof(SkPoint); |
|
bsalomon
2014/08/27 17:46:27
static consts?
egdaniel
2014/08/27 18:33:55
Done.
| |
| 954 drawState->setVertexAttribs<gPosUVColorAttribs>(3); | 955 drawState->setVertexAttribs<gPosUVColorAttribs>(3, 2 * sizeof(SkPoint) + sizeof(SkColor)); |
| 955 } else if (NULL != texCoords) { | 956 } else if (NULL != texCoords) { |
| 956 *texOffset = sizeof(SkPoint); | 957 *texOffset = sizeof(SkPoint); |
| 957 drawState->setVertexAttribs<gPosUVColorAttribs>(2); | 958 drawState->setVertexAttribs<gPosUVColorAttribs>(2, 2 * sizeof(SkPoint)); |
| 958 } else if (NULL != colors) { | 959 } else if (NULL != colors) { |
| 959 *colorOffset = sizeof(SkPoint); | 960 *colorOffset = sizeof(SkPoint); |
| 960 drawState->setVertexAttribs<gPosColorAttribs>(2); | 961 drawState->setVertexAttribs<gPosColorAttribs>(2, sizeof(SkPoint) + sizeo f(SkColor)); |
| 961 } else { | 962 } else { |
| 962 drawState->setVertexAttribs<gPosColorAttribs>(1); | 963 drawState->setVertexAttribs<gPosColorAttribs>(1, sizeof(SkPoint)); |
| 963 } | 964 } |
| 964 } | 965 } |
| 965 | 966 |
| 966 }; | 967 }; |
| 967 | 968 |
| 968 void GrContext::drawVertices(const GrPaint& paint, | 969 void GrContext::drawVertices(const GrPaint& paint, |
| 969 GrPrimitiveType primitiveType, | 970 GrPrimitiveType primitiveType, |
| 970 int vertexCount, | 971 int vertexCount, |
| 971 const SkPoint positions[], | 972 const SkPoint positions[], |
| 972 const SkPoint texCoords[], | 973 const SkPoint texCoords[], |
| 973 const GrColor colors[], | 974 const GrColor colors[], |
| 974 const uint16_t indices[], | 975 const uint16_t indices[], |
| 975 int indexCount) { | 976 int indexCount) { |
| 976 AutoRestoreEffects are; | 977 AutoRestoreEffects are; |
| 977 AutoCheckFlush acf(this); | 978 AutoCheckFlush acf(this); |
| 978 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e | 979 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e |
| 979 | 980 |
| 980 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); | 981 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); |
| 981 if (NULL == target) { | 982 if (NULL == target) { |
| 982 return; | 983 return; |
| 983 } | 984 } |
| 984 GrDrawState* drawState = target->drawState(); | 985 GrDrawState* drawState = target->drawState(); |
| 985 | 986 |
| 986 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); | 987 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
| 987 | 988 |
| 988 int colorOffset = -1, texOffset = -1; | 989 int colorOffset = -1, texOffset = -1; |
| 989 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset ); | 990 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset ); |
| 990 | 991 |
| 991 size_t vertexSize = drawState->getVertexSize(); | 992 size_t VertexStride = drawState->getVertexStride(); |
| 992 if (sizeof(SkPoint) != vertexSize) { | 993 if (sizeof(SkPoint) != VertexStride) { |
| 993 if (!geo.set(target, vertexCount, 0)) { | 994 if (!geo.set(target, vertexCount, 0)) { |
| 994 GrPrintf("Failed to get space for vertices!\n"); | 995 GrPrintf("Failed to get space for vertices!\n"); |
| 995 return; | 996 return; |
| 996 } | 997 } |
| 997 void* curVertex = geo.vertices(); | 998 void* curVertex = geo.vertices(); |
| 998 | 999 |
| 999 for (int i = 0; i < vertexCount; ++i) { | 1000 for (int i = 0; i < vertexCount; ++i) { |
| 1000 *((SkPoint*)curVertex) = positions[i]; | 1001 *((SkPoint*)curVertex) = positions[i]; |
| 1001 | 1002 |
| 1002 if (texOffset >= 0) { | 1003 if (texOffset >= 0) { |
| 1003 *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i]; | 1004 *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i]; |
| 1004 } | 1005 } |
| 1005 if (colorOffset >= 0) { | 1006 if (colorOffset >= 0) { |
| 1006 *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i]; | 1007 *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i]; |
| 1007 } | 1008 } |
| 1008 curVertex = (void*)((intptr_t)curVertex + vertexSize); | 1009 curVertex = (void*)((intptr_t)curVertex + VertexStride); |
| 1009 } | 1010 } |
| 1010 } else { | 1011 } else { |
| 1011 target->setVertexSourceToArray(positions, vertexCount); | 1012 target->setVertexSourceToArray(positions, vertexCount); |
| 1012 } | 1013 } |
| 1013 | 1014 |
| 1014 // we don't currently apply offscreen AA to this path. Need improved | 1015 // we don't currently apply offscreen AA to this path. Need improved |
| 1015 // management of GrDrawTarget's geometry to avoid copying points per-tile. | 1016 // management of GrDrawTarget's geometry to avoid copying points per-tile. |
| 1016 | 1017 |
| 1017 if (NULL != indices) { | 1018 if (NULL != indices) { |
| 1018 target->setIndexSourceToArray(indices, indexCount); | 1019 target->setIndexSourceToArray(indices, indexCount); |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1946 fDrawBuffer->removeGpuTraceMarker(marker); | 1947 fDrawBuffer->removeGpuTraceMarker(marker); |
| 1947 } | 1948 } |
| 1948 } | 1949 } |
| 1949 | 1950 |
| 1950 /////////////////////////////////////////////////////////////////////////////// | 1951 /////////////////////////////////////////////////////////////////////////////// |
| 1951 #if GR_CACHE_STATS | 1952 #if GR_CACHE_STATS |
| 1952 void GrContext::printCacheStats() const { | 1953 void GrContext::printCacheStats() const { |
| 1953 fResourceCache->printStats(); | 1954 fResourceCache->printStats(); |
| 1954 } | 1955 } |
| 1955 #endif | 1956 #endif |
| OLD | NEW |