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

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

Issue 14328009: Vertex Attrib configurations now handled as pointers vs. SkSTArrays (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Added "extern const" & removed comment Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrAARectRenderer.cpp ('k') | src/gpu/GrDrawState.h » ('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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 for (int i = 0; i < dstXLimit; i += bpp) { 315 for (int i = 0; i < dstXLimit; i += bpp) {
316 memcpy((uint8_t*) dstRow + i, 316 memcpy((uint8_t*) dstRow + i,
317 (uint8_t*) srcRow + (x>>16)*bpp, 317 (uint8_t*) srcRow + (x>>16)*bpp,
318 bpp); 318 bpp);
319 x += dx; 319 x += dx;
320 } 320 }
321 y += dy; 321 y += dy;
322 } 322 }
323 } 323 }
324 324
325 namespace {
326
327 // position + local coordinate
328 extern const GrVertexAttrib gVertexAttribs[] = {
329 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
330 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBindi ng}
331 };
332
333 };
334
325 // The desired texture is NPOT and tiled but that isn't supported by 335 // The desired texture is NPOT and tiled but that isn't supported by
326 // the current hardware. Resize the texture to be a POT 336 // the current hardware. Resize the texture to be a POT
327 GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc, 337 GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc,
328 const GrCacheID& cacheID, 338 const GrCacheID& cacheID,
329 void* srcData, 339 void* srcData,
330 size_t rowBytes, 340 size_t rowBytes,
331 bool needsFiltering) { 341 bool needsFiltering) {
332 SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID , NULL)); 342 SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID , NULL));
333 if (NULL == clampedTexture) { 343 if (NULL == clampedTexture) {
334 clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, r owBytes)); 344 clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, r owBytes));
(...skipping 16 matching lines...) Expand all
351 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); 361 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit);
352 GrDrawState* drawState = fGpu->drawState(); 362 GrDrawState* drawState = fGpu->drawState();
353 drawState->setRenderTarget(texture->asRenderTarget()); 363 drawState->setRenderTarget(texture->asRenderTarget());
354 364
355 // if filtering is not desired then we want to ensure all 365 // if filtering is not desired then we want to ensure all
356 // texels in the resampled image are copies of texels from 366 // texels in the resampled image are copies of texels from
357 // the original. 367 // the original.
358 GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering); 368 GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering);
359 drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params) ; 369 drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params) ;
360 370
361 // position + local coordinate 371 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib s));
362 static const GrVertexAttrib kVertexAttribs[] = {
363 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttri bBinding},
364 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAtt ribBinding}
365 };
366 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttrib s));
367 372
368 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); 373 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0);
369 374
370 if (arg.succeeded()) { 375 if (arg.succeeded()) {
371 GrPoint* verts = (GrPoint*) arg.vertices(); 376 GrPoint* verts = (GrPoint*) arg.vertices();
372 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(GrPoint)); 377 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(GrPoint));
373 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint)); 378 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint));
374 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); 379 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
375 } 380 }
376 } else { 381 } else {
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 } 930 }
926 drawState->setDefaultVertexAttribs(); 931 drawState->setDefaultVertexAttribs();
927 target->setVertexSourceToBuffer(sqVB); 932 target->setVertexSourceToBuffer(sqVB);
928 target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); 933 target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
929 drawState->setViewMatrix(savedViewMatrix); 934 drawState->setViewMatrix(savedViewMatrix);
930 #else 935 #else
931 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); 936 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix);
932 #endif 937 #endif
933 } 938 }
934 939
940 namespace {
941
942 extern const GrVertexAttrib gPosUVColorAttribs[] = {
943 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
944 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBind ing },
945 {kVec4ub_GrVertexAttribType, 2*sizeof(GrPoint), kColor_GrVertexAttribBinding }
946 };
947
948 extern const GrVertexAttrib gPosColorAttribs[] = {
949 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
950 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kColor_GrVertexAttribBinding},
951 };
952
953 static void set_vertex_attributes(GrDrawState* drawState,
954 const GrPoint* texCoords,
955 const GrColor* colors,
956 int* colorOffset,
957 int* texOffset) {
958 *texOffset = -1;
959 *colorOffset = -1;
960
961 if (NULL != texCoords && NULL != colors) {
962 *texOffset = sizeof(GrPoint);
963 *colorOffset = 2*sizeof(GrPoint);
964 drawState->setVertexAttribs<gPosUVColorAttribs>(3);
965 } else if (NULL != texCoords) {
966 *texOffset = sizeof(GrPoint);
967 drawState->setVertexAttribs<gPosUVColorAttribs>(2);
968 } else if (NULL != colors) {
969 *colorOffset = sizeof(GrPoint);
970 drawState->setVertexAttribs<gPosColorAttribs>(2);
971 } else {
972 drawState->setVertexAttribs<gPosColorAttribs>(1);
973 }
974 }
975
976 };
977
935 void GrContext::drawVertices(const GrPaint& paint, 978 void GrContext::drawVertices(const GrPaint& paint,
936 GrPrimitiveType primitiveType, 979 GrPrimitiveType primitiveType,
937 int vertexCount, 980 int vertexCount,
938 const GrPoint positions[], 981 const GrPoint positions[],
939 const GrPoint texCoords[], 982 const GrPoint texCoords[],
940 const GrColor colors[], 983 const GrColor colors[],
941 const uint16_t indices[], 984 const uint16_t indices[],
942 int indexCount) { 985 int indexCount) {
943 SK_TRACE_EVENT0("GrContext::drawVertices"); 986 SK_TRACE_EVENT0("GrContext::drawVertices");
944 987
945 GrDrawTarget::AutoReleaseGeometry geo; 988 GrDrawTarget::AutoReleaseGeometry geo;
946 989
947 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); 990 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW);
948 GrDrawState::AutoStageDisable atr(fDrawState); 991 GrDrawState::AutoStageDisable atr(fDrawState);
949 992
950 GrDrawState* drawState = target->drawState(); 993 GrDrawState* drawState = target->drawState();
951 994
952 GrVertexAttribArray<3> attribs;
953 size_t currentOffset = 0;
954 int colorOffset = -1, texOffset = -1; 995 int colorOffset = -1, texOffset = -1;
955 996 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset );
956 // set position attribute
957 GrVertexAttrib currAttrib =
958 {kVec2f_GrVertexAttribType, currentOffset, kPosition_GrVertexAttribBindi ng};
959 attribs.push_back(currAttrib);
960 currentOffset += sizeof(GrPoint);
961
962 // set up optional texture coordinate attributes
963 if (NULL != texCoords) {
964 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset, kLocalCoord_GrV ertexAttribBinding);
965 attribs.push_back(currAttrib);
966 texOffset = currentOffset;
967 currentOffset += sizeof(GrPoint);
968 }
969
970 // set up optional color attributes
971 if (NULL != colors) {
972 currAttrib.set(kVec4ub_GrVertexAttribType, currentOffset, kColor_GrVerte xAttribBinding);
973 attribs.push_back(currAttrib);
974 colorOffset = currentOffset;
975 currentOffset += sizeof(GrColor);
976 }
977
978 drawState->setVertexAttribs(attribs.begin(), attribs.count());
979 997
980 size_t vertexSize = drawState->getVertexSize(); 998 size_t vertexSize = drawState->getVertexSize();
981 GrAssert(vertexSize == currentOffset);
982 if (sizeof(GrPoint) != vertexSize) { 999 if (sizeof(GrPoint) != vertexSize) {
983 if (!geo.set(target, vertexCount, 0)) { 1000 if (!geo.set(target, vertexCount, 0)) {
984 GrPrintf("Failed to get space for vertices!\n"); 1001 GrPrintf("Failed to get space for vertices!\n");
985 return; 1002 return;
986 } 1003 }
987 void* curVertex = geo.vertices(); 1004 void* curVertex = geo.vertices();
988 1005
989 for (int i = 0; i < vertexCount; ++i) { 1006 for (int i = 0; i < vertexCount; ++i) {
990 *((GrPoint*)curVertex) = positions[i]; 1007 *((GrPoint*)curVertex) = positions[i];
991 1008
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 return srcTexture; 1847 return srcTexture;
1831 } 1848 }
1832 } 1849 }
1833 1850
1834 /////////////////////////////////////////////////////////////////////////////// 1851 ///////////////////////////////////////////////////////////////////////////////
1835 #if GR_CACHE_STATS 1852 #if GR_CACHE_STATS
1836 void GrContext::printCacheStats() const { 1853 void GrContext::printCacheStats() const {
1837 fTextureCache->printStats(); 1854 fTextureCache->printStats();
1838 } 1855 }
1839 #endif 1856 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAARectRenderer.cpp ('k') | src/gpu/GrDrawState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698