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

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
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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 // texels in the resampled image are copies of texels from 351 // texels in the resampled image are copies of texels from
352 // the original. 352 // the original.
353 GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering); 353 GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering);
354 drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params) ; 354 drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params) ;
355 355
356 // position + texture coordinate 356 // position + texture coordinate
357 static const GrVertexAttrib kVertexAttribs[] = { 357 static const GrVertexAttrib kVertexAttribs[] = {
358 {kVec2f_GrVertexAttribType, 0}, 358 {kVec2f_GrVertexAttribType, 0},
359 {kVec2f_GrVertexAttribType, sizeof(GrPoint)} 359 {kVec2f_GrVertexAttribType, sizeof(GrPoint)}
360 }; 360 };
361 static const GrAttribBindings kAttribBindings = GrDrawState::ExplicitTex CoordAttribBindingsBit(0); 361 static const GrAttribBindings kAttribBindings = GrDrawState::kLocalCoord s_AttribBindingsBit;
362 drawState->setAttribBindings(kAttribBindings); 362 drawState->setAttribBindings(kAttribBindings);
363 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttrib s)); 363 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttrib s));
364 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); 364 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
365 drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, 1); 365 drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, 1);
366 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); 366 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0);
367 367
368 if (arg.succeeded()) { 368 if (arg.succeeded()) {
369 GrPoint* verts = (GrPoint*) arg.vertices(); 369 GrPoint* verts = (GrPoint*) arg.vertices();
370 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(GrPoint)); 370 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(GrPoint));
371 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint)); 371 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint));
372 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); 372 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
373 } 373 }
374 texture->releaseRenderTarget(); 374 texture->releaseRenderTarget();
375 } else { 375 } else {
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 837
838 target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); 838 target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
839 #else 839 #else
840 target->drawSimpleRect(rect, matrix); 840 target->drawSimpleRect(rect, matrix);
841 #endif 841 #endif
842 } 842 }
843 } 843 }
844 844
845 void GrContext::drawRectToRect(const GrPaint& paint, 845 void GrContext::drawRectToRect(const GrPaint& paint,
846 const GrRect& dstRect, 846 const GrRect& dstRect,
847 const GrRect& srcRect, 847 const GrRect& localRect,
848 const SkMatrix* dstMatrix, 848 const SkMatrix* dstMatrix,
849 const SkMatrix* srcMatrix) { 849 const SkMatrix* localMatrix) {
850 SK_TRACE_EVENT0("GrContext::drawRectToRect"); 850 SK_TRACE_EVENT0("GrContext::drawRectToRect");
851 851
852 // srcRect refers to paint's first color stage
853 if (!paint.isColorStageEnabled(0)) {
854 drawRect(paint, dstRect, -1, dstMatrix);
855 return;
856 }
857
858 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); 852 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW);
853 GrDrawState::AutoStageDisable atr(fDrawState);
859 854
860 #if GR_STATIC_RECT_VB 855 #if GR_STATIC_RECT_VB
861 GrDrawState::AutoStageDisable atr(fDrawState);
862 GrDrawState* drawState = target->drawState(); 856 GrDrawState* drawState = target->drawState();
863 857
864 SkMatrix m; 858 SkMatrix m;
865 859
866 m.setAll(dstRect.width(), 0, dstRect.fLeft, 860 m.setAll(dstRect.width(), 0, dstRect.fLeft,
867 0, dstRect.height(), dstRect.fTop, 861 0, dstRect.height(), dstRect.fTop,
868 0, 0, SkMatrix::I()[8]); 862 0, 0, SkMatrix::I()[8]);
869 if (NULL != dstMatrix) { 863 if (NULL != dstMatrix) {
870 m.postConcat(*dstMatrix); 864 m.postConcat(*dstMatrix);
871 } 865 }
872 866
873 // The first color stage's coords come from srcRect rather than applying a m atrix to dstRect. 867 // This code path plays a little fast and loose with the notion of local coo rds and coord
874 // We explicitly compute a matrix for that stage below, no need to adjust he re. 868 // change matrices in order to account for localRect and localMatrix. The un it square VB only
875 static const uint32_t kExplicitCoordMask = 1 << GrPaint::kFirstColorStage; 869 // has one set of coords. Rather than using AutoViewMatrixRestore we instead directly set concat
876 GrDrawState::AutoViewMatrixRestore avmr(drawState, m, kExplicitCoordMask); 870 // with m and then call GrDrawState::localCoordChange() with a matrix that a ccounts for
871 // localRect and localMatrix. This code path is preventing some encapsulatio n in GrDrawState.
robertphillips 2013/03/19 15:09:38 matrix -> savedMatrix, origMatrix?
bsalomon 2013/03/19 19:34:43 Done. (savedViewMatrix)
872 SkMatrix matrix = drawState->getViewMatrix();
873 drawState->preConcatViewMatrix(m);
877 874
878 m.setAll(srcRect.width(), 0, srcRect.fLeft, 875 m.setAll(localRect.width(), 0, localRect.fLeft,
879 0, srcRect.height(), srcRect.fTop, 876 0, localRect.height(), localRect.fTop,
880 0, 0, SkMatrix::I()[8]); 877 0, 0, SkMatrix::I()[8]);
881 if (NULL != srcMatrix) { 878 if (NULL != localMatrix) {
882 m.postConcat(*srcMatrix); 879 m.postConcat(*localMatrix);
883 } 880 }
884 881 drawState->localCoordChange(m);
885 drawState->preConcatStageMatrices(kExplicitCoordMask, m);
886 882
887 const GrVertexBuffer* sqVB = fGpu->getUnitSquareVertexBuffer(); 883 const GrVertexBuffer* sqVB = fGpu->getUnitSquareVertexBuffer();
888 if (NULL == sqVB) { 884 if (NULL == sqVB) {
889 GrPrintf("Failed to create static rect vb.\n"); 885 GrPrintf("Failed to create static rect vb.\n");
890 return; 886 return;
891 } 887 }
892 drawState->setDefaultVertexAttribs(); 888 drawState->setDefaultVertexAttribs();
893 target->setVertexSourceToBuffer(sqVB); 889 target->setVertexSourceToBuffer(sqVB);
894 target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); 890 target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
891 drawState->setViewMatrix(matrix);
895 #else 892 #else
896 GrDrawState::AutoStageDisable atr(fDrawState); 893 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix);
897
898 target->drawRect(dstRect, dstMatrix, &srcRect, srcMatrix, 0);
899 #endif 894 #endif
900 } 895 }
901 896
902 void GrContext::drawVertices(const GrPaint& paint, 897 void GrContext::drawVertices(const GrPaint& paint,
903 GrPrimitiveType primitiveType, 898 GrPrimitiveType primitiveType,
904 int vertexCount, 899 int vertexCount,
905 const GrPoint positions[], 900 const GrPoint positions[],
906 const GrPoint texCoords[], 901 const GrPoint texCoords[],
907 const GrColor colors[], 902 const GrColor colors[],
908 const uint16_t indices[], 903 const uint16_t indices[],
(...skipping 13 matching lines...) Expand all
922 GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings; 917 GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings;
923 918
924 // set position attribute 919 // set position attribute
925 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count( )); 920 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count( ));
926 GrVertexAttrib currAttrib = {kVec2f_GrVertexAttribType, currentOffset}; 921 GrVertexAttrib currAttrib = {kVec2f_GrVertexAttribType, currentOffset};
927 attribs.push_back(currAttrib); 922 attribs.push_back(currAttrib);
928 currentOffset += sizeof(GrPoint); 923 currentOffset += sizeof(GrPoint);
929 924
930 // set up optional texture coordinate attributes 925 // set up optional texture coordinate attributes
931 if (NULL != texCoords) { 926 if (NULL != texCoords) {
932 bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(0); 927 bindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
933 drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, attribs.co unt()); 928 drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, attribs .count());
934 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset); 929 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset);
935 attribs.push_back(currAttrib); 930 attribs.push_back(currAttrib);
936 texOffset = currentOffset; 931 texOffset = currentOffset;
937 currentOffset += sizeof(GrPoint); 932 currentOffset += sizeof(GrPoint);
938 } 933 }
939 934
940 // set up optional color attributes 935 // set up optional color attributes
941 if (NULL != colors) { 936 if (NULL != colors) {
942 bindings |= GrDrawState::kColor_AttribBindingsBit; 937 bindings |= GrDrawState::kColor_AttribBindingsBit;
943 drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count ()); 938 drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count ());
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 return srcTexture; 1984 return srcTexture;
1990 } 1985 }
1991 } 1986 }
1992 1987
1993 /////////////////////////////////////////////////////////////////////////////// 1988 ///////////////////////////////////////////////////////////////////////////////
1994 #if GR_CACHE_STATS 1989 #if GR_CACHE_STATS
1995 void GrContext::printCacheStats() const { 1990 void GrContext::printCacheStats() const {
1996 fTextureCache->printStats(); 1991 fTextureCache->printStats();
1997 } 1992 }
1998 #endif 1993 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698