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

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

Issue 12531015: Adds local coords to GrEffect system. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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/GrClipMaskManager.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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // texels in the resampled image are copies of texels from 353 // texels in the resampled image are copies of texels from
354 // the original. 354 // the original.
355 GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering); 355 GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering);
356 drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params) ; 356 drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params) ;
357 357
358 // position + texture coordinate 358 // position + texture coordinate
359 static const GrVertexAttrib kVertexAttribs[] = { 359 static const GrVertexAttrib kVertexAttribs[] = {
360 {kVec2f_GrVertexAttribType, 0}, 360 {kVec2f_GrVertexAttribType, 0},
361 {kVec2f_GrVertexAttribType, sizeof(GrPoint)} 361 {kVec2f_GrVertexAttribType, sizeof(GrPoint)}
362 }; 362 };
363 static const GrAttribBindings kAttribBindings = 363
364 GrDrawState::ExplicitTexCoordAttribBindingsBit(0); 364 static const GrAttribBindings kAttribBindings = GrDrawState::kLocalCoord s_AttribBindingsBit;
365 drawState->setAttribBindings(kAttribBindings); 365 drawState->setAttribBindings(kAttribBindings);
366 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttrib s)); 366 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttrib s));
367 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); 367 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
368 drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, 1); 368 drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, 1);
369 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); 369 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0);
370 370
371 if (arg.succeeded()) { 371 if (arg.succeeded()) {
372 GrPoint* verts = (GrPoint*) arg.vertices(); 372 GrPoint* verts = (GrPoint*) arg.vertices();
373 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(GrPoint)); 373 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(GrPoint));
374 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint)); 374 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint));
375 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); 375 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
376 } 376 }
377 texture->releaseRenderTarget(); 377 texture->releaseRenderTarget();
378 } else { 378 } else {
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 845
846 target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); 846 target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
847 #else 847 #else
848 target->drawSimpleRect(rect, matrix); 848 target->drawSimpleRect(rect, matrix);
849 #endif 849 #endif
850 } 850 }
851 } 851 }
852 852
853 void GrContext::drawRectToRect(const GrPaint& paint, 853 void GrContext::drawRectToRect(const GrPaint& paint,
854 const GrRect& dstRect, 854 const GrRect& dstRect,
855 const GrRect& srcRect, 855 const GrRect& localRect,
856 const SkMatrix* dstMatrix, 856 const SkMatrix* dstMatrix,
857 const SkMatrix* srcMatrix) { 857 const SkMatrix* localMatrix) {
858 SK_TRACE_EVENT0("GrContext::drawRectToRect"); 858 SK_TRACE_EVENT0("GrContext::drawRectToRect");
859 859
860 // srcRect refers to paint's first color stage
861 if (!paint.isColorStageEnabled(0)) {
862 drawRect(paint, dstRect, -1, dstMatrix);
863 return;
864 }
865
866 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); 860 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW);
861 GrDrawState::AutoStageDisable atr(fDrawState);
867 862
868 #if GR_STATIC_RECT_VB 863 #if GR_STATIC_RECT_VB
869 GrDrawState::AutoStageDisable atr(fDrawState);
870 GrDrawState* drawState = target->drawState(); 864 GrDrawState* drawState = target->drawState();
871 865
872 SkMatrix m; 866 SkMatrix m;
873 867
874 m.setAll(dstRect.width(), 0, dstRect.fLeft, 868 m.setAll(dstRect.width(), 0, dstRect.fLeft,
875 0, dstRect.height(), dstRect.fTop, 869 0, dstRect.height(), dstRect.fTop,
876 0, 0, SkMatrix::I()[8]); 870 0, 0, SkMatrix::I()[8]);
877 if (NULL != dstMatrix) { 871 if (NULL != dstMatrix) {
878 m.postConcat(*dstMatrix); 872 m.postConcat(*dstMatrix);
879 } 873 }
880 874
881 // The first color stage's coords come from srcRect rather than applying a m atrix to dstRect. 875 // This code path plays a little fast and loose with the notion of local coo rds and coord
882 // We explicitly compute a matrix for that stage below, no need to adjust he re. 876 // change matrices in order to account for localRect and localMatrix. The un it square VB only
883 static const uint32_t kExplicitCoordMask = 1 << GrPaint::kFirstColorStage; 877 // has one set of coords. Rather than using AutoViewMatrixRestore we instead directly set concat
884 GrDrawState::AutoViewMatrixRestore avmr(drawState, m, kExplicitCoordMask); 878 // with m and then call GrDrawState::localCoordChange() with a matrix that a ccounts for
879 // localRect and localMatrix. This code path is preventing some encapsulatio n in GrDrawState.
880 SkMatrix savedViewMatrix = drawState->getViewMatrix();
881 drawState->preConcatViewMatrix(m);
885 882
886 m.setAll(srcRect.width(), 0, srcRect.fLeft, 883 m.setAll(localRect.width(), 0, localRect.fLeft,
887 0, srcRect.height(), srcRect.fTop, 884 0, localRect.height(), localRect.fTop,
888 0, 0, SkMatrix::I()[8]); 885 0, 0, SkMatrix::I()[8]);
889 if (NULL != srcMatrix) { 886 if (NULL != localMatrix) {
890 m.postConcat(*srcMatrix); 887 m.postConcat(*localMatrix);
891 } 888 }
892 889 drawState->localCoordChange(m);
893 drawState->preConcatStageMatrices(kExplicitCoordMask, m);
894 890
895 const GrVertexBuffer* sqVB = fGpu->getUnitSquareVertexBuffer(); 891 const GrVertexBuffer* sqVB = fGpu->getUnitSquareVertexBuffer();
896 if (NULL == sqVB) { 892 if (NULL == sqVB) {
897 GrPrintf("Failed to create static rect vb.\n"); 893 GrPrintf("Failed to create static rect vb.\n");
898 return; 894 return;
899 } 895 }
900 drawState->setDefaultVertexAttribs(); 896 drawState->setDefaultVertexAttribs();
901 target->setVertexSourceToBuffer(sqVB); 897 target->setVertexSourceToBuffer(sqVB);
902 target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); 898 target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
899 drawState->setViewMatrix(savedViewMatrix);
903 #else 900 #else
904 GrDrawState::AutoStageDisable atr(fDrawState); 901 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix);
905
906 target->drawRect(dstRect, dstMatrix, &srcRect, srcMatrix, 0);
907 #endif 902 #endif
908 } 903 }
909 904
910 void GrContext::drawVertices(const GrPaint& paint, 905 void GrContext::drawVertices(const GrPaint& paint,
911 GrPrimitiveType primitiveType, 906 GrPrimitiveType primitiveType,
912 int vertexCount, 907 int vertexCount,
913 const GrPoint positions[], 908 const GrPoint positions[],
914 const GrPoint texCoords[], 909 const GrPoint texCoords[],
915 const GrColor colors[], 910 const GrColor colors[],
916 const uint16_t indices[], 911 const uint16_t indices[],
(...skipping 13 matching lines...) Expand all
930 GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings; 925 GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings;
931 926
932 // set position attribute 927 // set position attribute
933 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count( )); 928 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count( ));
934 GrVertexAttrib currAttrib = {kVec2f_GrVertexAttribType, currentOffset}; 929 GrVertexAttrib currAttrib = {kVec2f_GrVertexAttribType, currentOffset};
935 attribs.push_back(currAttrib); 930 attribs.push_back(currAttrib);
936 currentOffset += sizeof(GrPoint); 931 currentOffset += sizeof(GrPoint);
937 932
938 // set up optional texture coordinate attributes 933 // set up optional texture coordinate attributes
939 if (NULL != texCoords) { 934 if (NULL != texCoords) {
940 bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(0); 935 bindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
941 drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, attribs.co unt()); 936 drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, attribs .count());
942 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset); 937 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset);
943 attribs.push_back(currAttrib); 938 attribs.push_back(currAttrib);
944 texOffset = currentOffset; 939 texOffset = currentOffset;
945 currentOffset += sizeof(GrPoint); 940 currentOffset += sizeof(GrPoint);
946 } 941 }
947 942
948 // set up optional color attributes 943 // set up optional color attributes
949 if (NULL != colors) { 944 if (NULL != colors) {
950 bindings |= GrDrawState::kColor_AttribBindingsBit; 945 bindings |= GrDrawState::kColor_AttribBindingsBit;
951 drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count ()); 946 drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count ());
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 return srcTexture; 2088 return srcTexture;
2094 } 2089 }
2095 } 2090 }
2096 2091
2097 /////////////////////////////////////////////////////////////////////////////// 2092 ///////////////////////////////////////////////////////////////////////////////
2098 #if GR_CACHE_STATS 2093 #if GR_CACHE_STATS
2099 void GrContext::printCacheStats() const { 2094 void GrContext::printCacheStats() const {
2100 fTextureCache->printStats(); 2095 fTextureCache->printStats();
2101 } 2096 }
2102 #endif 2097 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrClipMaskManager.cpp ('k') | src/gpu/GrDrawState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698