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

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

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

Powered by Google App Engine
This is Rietveld 408576698