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)); | |
370 | 369 |
371 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); | 370 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); |
372 | 371 |
373 if (arg.succeeded()) { | 372 if (arg.succeeded()) { |
374 SkPoint* verts = (SkPoint*) arg.vertices(); | 373 SkPoint* verts = (SkPoint*) arg.vertices(); |
375 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(SkPoint)); | 374 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(SkPoint)); |
376 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); | 375 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); |
377 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); | 376 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); |
378 } | 377 } |
379 } else { | 378 } else { |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 } | 928 } |
930 | 929 |
931 namespace { | 930 namespace { |
932 | 931 |
933 extern const GrVertexAttrib gPosUVColorAttribs[] = { | 932 extern const GrVertexAttrib gPosUVColorAttribs[] = { |
934 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, | 933 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, |
935 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBind
ing }, | 934 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBind
ing }, |
936 {kVec4ub_GrVertexAttribType, 2*sizeof(SkPoint), kColor_GrVertexAttribBinding
} | 935 {kVec4ub_GrVertexAttribType, 2*sizeof(SkPoint), kColor_GrVertexAttribBinding
} |
937 }; | 936 }; |
938 | 937 |
939 static const size_t kPosUVAttribsSize = 2 * sizeof(SkPoint); | |
940 static const size_t kPosUVColorAttribsSize = 2 * sizeof(SkPoint) + sizeof(GrColo
r); | |
941 | |
942 extern const GrVertexAttrib gPosColorAttribs[] = { | 938 extern const GrVertexAttrib gPosColorAttribs[] = { |
943 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, | 939 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
944 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding}, | 940 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding}, |
945 }; | 941 }; |
946 | 942 |
947 static const size_t kPosAttribsSize = sizeof(SkPoint); | |
948 static const size_t kPosColorAttribsSize = sizeof(SkPoint) + sizeof(GrColor); | |
949 | |
950 static void set_vertex_attributes(GrDrawState* drawState, | 943 static void set_vertex_attributes(GrDrawState* drawState, |
951 const SkPoint* texCoords, | 944 const SkPoint* texCoords, |
952 const GrColor* colors, | 945 const GrColor* colors, |
953 int* colorOffset, | 946 int* colorOffset, |
954 int* texOffset) { | 947 int* texOffset) { |
955 *texOffset = -1; | 948 *texOffset = -1; |
956 *colorOffset = -1; | 949 *colorOffset = -1; |
957 | 950 |
958 if (NULL != texCoords && NULL != colors) { | 951 if (NULL != texCoords && NULL != colors) { |
959 *texOffset = sizeof(SkPoint); | 952 *texOffset = sizeof(SkPoint); |
960 *colorOffset = 2*sizeof(SkPoint); | 953 *colorOffset = 2*sizeof(SkPoint); |
961 drawState->setVertexAttribs<gPosUVColorAttribs>(3, kPosUVColorAttribsSiz
e); | 954 drawState->setVertexAttribs<gPosUVColorAttribs>(3); |
962 } else if (NULL != texCoords) { | 955 } else if (NULL != texCoords) { |
963 *texOffset = sizeof(SkPoint); | 956 *texOffset = sizeof(SkPoint); |
964 drawState->setVertexAttribs<gPosUVColorAttribs>(2, kPosUVAttribsSize); | 957 drawState->setVertexAttribs<gPosUVColorAttribs>(2); |
965 } else if (NULL != colors) { | 958 } else if (NULL != colors) { |
966 *colorOffset = sizeof(SkPoint); | 959 *colorOffset = sizeof(SkPoint); |
967 drawState->setVertexAttribs<gPosColorAttribs>(2, kPosColorAttribsSize); | 960 drawState->setVertexAttribs<gPosColorAttribs>(2); |
968 } else { | 961 } else { |
969 drawState->setVertexAttribs<gPosColorAttribs>(1, kPosAttribsSize); | 962 drawState->setVertexAttribs<gPosColorAttribs>(1); |
970 } | 963 } |
971 } | 964 } |
972 | 965 |
973 }; | 966 }; |
974 | 967 |
975 void GrContext::drawVertices(const GrPaint& paint, | 968 void GrContext::drawVertices(const GrPaint& paint, |
976 GrPrimitiveType primitiveType, | 969 GrPrimitiveType primitiveType, |
977 int vertexCount, | 970 int vertexCount, |
978 const SkPoint positions[], | 971 const SkPoint positions[], |
979 const SkPoint texCoords[], | 972 const SkPoint texCoords[], |
980 const GrColor colors[], | 973 const GrColor colors[], |
981 const uint16_t indices[], | 974 const uint16_t indices[], |
982 int indexCount) { | 975 int indexCount) { |
983 AutoRestoreEffects are; | 976 AutoRestoreEffects are; |
984 AutoCheckFlush acf(this); | 977 AutoCheckFlush acf(this); |
985 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e | 978 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e |
986 | 979 |
987 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 980 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
988 if (NULL == target) { | 981 if (NULL == target) { |
989 return; | 982 return; |
990 } | 983 } |
991 GrDrawState* drawState = target->drawState(); | 984 GrDrawState* drawState = target->drawState(); |
992 | 985 |
993 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); | 986 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
994 | 987 |
995 int colorOffset = -1, texOffset = -1; | 988 int colorOffset = -1, texOffset = -1; |
996 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset
); | 989 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset
); |
997 | 990 |
998 size_t VertexStride = drawState->getVertexStride(); | 991 size_t vertexSize = drawState->getVertexSize(); |
999 if (sizeof(SkPoint) != VertexStride) { | 992 if (sizeof(SkPoint) != vertexSize) { |
1000 if (!geo.set(target, vertexCount, 0)) { | 993 if (!geo.set(target, vertexCount, 0)) { |
1001 GrPrintf("Failed to get space for vertices!\n"); | 994 GrPrintf("Failed to get space for vertices!\n"); |
1002 return; | 995 return; |
1003 } | 996 } |
1004 void* curVertex = geo.vertices(); | 997 void* curVertex = geo.vertices(); |
1005 | 998 |
1006 for (int i = 0; i < vertexCount; ++i) { | 999 for (int i = 0; i < vertexCount; ++i) { |
1007 *((SkPoint*)curVertex) = positions[i]; | 1000 *((SkPoint*)curVertex) = positions[i]; |
1008 | 1001 |
1009 if (texOffset >= 0) { | 1002 if (texOffset >= 0) { |
1010 *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i]; | 1003 *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i]; |
1011 } | 1004 } |
1012 if (colorOffset >= 0) { | 1005 if (colorOffset >= 0) { |
1013 *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i]; | 1006 *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i]; |
1014 } | 1007 } |
1015 curVertex = (void*)((intptr_t)curVertex + VertexStride); | 1008 curVertex = (void*)((intptr_t)curVertex + vertexSize); |
1016 } | 1009 } |
1017 } else { | 1010 } else { |
1018 target->setVertexSourceToArray(positions, vertexCount); | 1011 target->setVertexSourceToArray(positions, vertexCount); |
1019 } | 1012 } |
1020 | 1013 |
1021 // we don't currently apply offscreen AA to this path. Need improved | 1014 // we don't currently apply offscreen AA to this path. Need improved |
1022 // management of GrDrawTarget's geometry to avoid copying points per-tile. | 1015 // management of GrDrawTarget's geometry to avoid copying points per-tile. |
1023 | 1016 |
1024 if (NULL != indices) { | 1017 if (NULL != indices) { |
1025 target->setIndexSourceToArray(indices, indexCount); | 1018 target->setIndexSourceToArray(indices, indexCount); |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1949 fDrawBuffer->removeGpuTraceMarker(marker); | 1942 fDrawBuffer->removeGpuTraceMarker(marker); |
1950 } | 1943 } |
1951 } | 1944 } |
1952 | 1945 |
1953 /////////////////////////////////////////////////////////////////////////////// | 1946 /////////////////////////////////////////////////////////////////////////////// |
1954 #if GR_CACHE_STATS | 1947 #if GR_CACHE_STATS |
1955 void GrContext::printCacheStats() const { | 1948 void GrContext::printCacheStats() const { |
1956 fResourceCache->printStats(); | 1949 fResourceCache->printStats(); |
1957 } | 1950 } |
1958 #endif | 1951 #endif |
OLD | NEW |