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

Side by Side Diff: src/gpu/gl/GrGpuGL.cpp

Issue 367643004: Implement NVPR on GLES (Closed) Base URL: https://skia.googlesource.com/skia.git@02-path-program-fragment
Patch Set: rebase Created 6 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "GrGpuGL.h" 9 #include "GrGpuGL.h"
10 #include "GrGLStencilBuffer.h" 10 #include "GrGLStencilBuffer.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 static bool gPrintStartupSpew; 130 static bool gPrintStartupSpew;
131 131
132 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) 132 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context)
133 : GrGpu(context) 133 : GrGpu(context)
134 , fGLContext(ctx) { 134 , fGLContext(ctx) {
135 135
136 SkASSERT(ctx.isInitialized()); 136 SkASSERT(ctx.isInitialized());
137 fCaps.reset(SkRef(ctx.caps())); 137 fCaps.reset(SkRef(ctx.caps()));
138 138
139 if (this->glCaps().pathRenderingSupport()) {
140 fPathRendering.reset(GrGLPathRendering::Create(glInterface()));
141 }
142
139 fHWBoundTextureUniqueIDs.reset(this->glCaps().maxFragmentTextureUnits()); 143 fHWBoundTextureUniqueIDs.reset(this->glCaps().maxFragmentTextureUnits());
140 fHWPathTexGenSettings.reset(this->glCaps().maxFixedFunctionTextureCoords()); 144 if (this->glCaps().pathRenderingSupport() &&
145 !this->pathRendering()->caps().fragmentInputGenSupport) {
bsalomon 2014/08/07 21:02:52 Maybe we should move the hw path tex gen settings
Chris Dalton 2014/08/07 23:02:55 The original idea for GrGLPathRendering was to mir
146 fHWPathTexGenSettings.reset(this->glCaps().maxFixedFunctionTextureCoords ());
147 }
141 148
142 GrGLClearErr(fGLContext.interface()); 149 GrGLClearErr(fGLContext.interface());
143 if (gPrintStartupSpew) { 150 if (gPrintStartupSpew) {
144 const GrGLubyte* vendor; 151 const GrGLubyte* vendor;
145 const GrGLubyte* renderer; 152 const GrGLubyte* renderer;
146 const GrGLubyte* version; 153 const GrGLubyte* version;
147 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); 154 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR));
148 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); 155 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER));
149 GL_CALL_RET(version, GetString(GR_GL_VERSION)); 156 GL_CALL_RET(version, GetString(GR_GL_VERSION));
150 GrPrintf("------------------------- create GrGpuGL %p --------------\n", 157 GrPrintf("------------------------- create GrGpuGL %p --------------\n",
151 this); 158 this);
152 GrPrintf("------ VENDOR %s\n", vendor); 159 GrPrintf("------ VENDOR %s\n", vendor);
153 GrPrintf("------ RENDERER %s\n", renderer); 160 GrPrintf("------ RENDERER %s\n", renderer);
154 GrPrintf("------ VERSION %s\n", version); 161 GrPrintf("------ VERSION %s\n", version);
155 GrPrintf("------ EXTENSIONS\n"); 162 GrPrintf("------ EXTENSIONS\n");
156 ctx.extensions().print(); 163 ctx.extensions().print();
157 GrPrintf("\n"); 164 GrPrintf("\n");
158 GrPrintf(this->glCaps().dump().c_str()); 165 GrPrintf(this->glCaps().dump().c_str());
159 } 166 }
160 167
161 fProgramCache = SkNEW_ARGS(ProgramCache, (this)); 168 fProgramCache = SkNEW_ARGS(ProgramCache, (this));
162 169
163 SkASSERT(this->glCaps().maxVertexAttributes() >= GrDrawState::kMaxVertexAttr ibCnt); 170 SkASSERT(this->glCaps().maxVertexAttributes() >= GrDrawState::kMaxVertexAttr ibCnt);
164 171
165 fLastSuccessfulStencilFmtIdx = 0; 172 fLastSuccessfulStencilFmtIdx = 0;
166 fHWProgramID = 0; 173 fHWProgramID = 0;
167
168 if (this->glCaps().pathRenderingSupport()) {
169 fPathRendering.reset(GrGLPathRendering::Create(glInterface()));
170 }
171 } 174 }
172 175
173 GrGpuGL::~GrGpuGL() { 176 GrGpuGL::~GrGpuGL() {
174 if (0 != fHWProgramID) { 177 if (0 != fHWProgramID) {
175 // detach the current program so there is no confusion on OpenGL's part 178 // detach the current program so there is no confusion on OpenGL's part
176 // that we want it to be deleted 179 // that we want it to be deleted
177 SkASSERT(fHWProgramID == fCurrentProgram->programID()); 180 SkASSERT(fHWProgramID == fCurrentProgram->programID());
178 GL_CALL(UseProgram(0)); 181 GL_CALL(UseProgram(0));
179 } 182 }
180 183
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 fHWGeometryState.invalidate(); 325 fHWGeometryState.invalidate();
323 } 326 }
324 327
325 if (resetBits & kRenderTarget_GrGLBackendState) { 328 if (resetBits & kRenderTarget_GrGLBackendState) {
326 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; 329 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
327 } 330 }
328 331
329 if (resetBits & kPathRendering_GrGLBackendState) { 332 if (resetBits & kPathRendering_GrGLBackendState) {
330 if (this->caps()->pathRenderingSupport()) { 333 if (this->caps()->pathRenderingSupport()) {
331 fHWProjectionMatrixState.invalidate(); 334 fHWProjectionMatrixState.invalidate();
332 // we don't use the model view matrix. 335 // we don't use the model view matrix.
bsalomon 2014/08/07 21:02:52 Again, I think we should move this state tracking
333 GL_CALL(MatrixLoadIdentity(GR_GL_MODELVIEW)); 336 GrGLenum matrixMode =
337 this->glStandard() == kGLES_GrGLStandard ? GR_GL_PATH_MODELVIEW : GR_GL_MODELVIEW;
334 338
335 for (int i = 0; i < this->glCaps().maxFixedFunctionTextureCoords(); ++i) { 339 GL_CALL(MatrixLoadIdentity(matrixMode));
336 fPathRendering->pathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NU LL); 340
337 fHWPathTexGenSettings[i].fMode = GR_GL_NONE; 341 if (!this->pathRendering()->caps().fragmentInputGenSupport) {
338 fHWPathTexGenSettings[i].fNumComponents = 0; 342 for (int i = 0; i < this->glCaps().maxFixedFunctionTextureCoords (); ++i) {
343 fPathRendering->pathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0 , NULL);
344 fHWPathTexGenSettings[i].fMode = GR_GL_NONE;
345 fHWPathTexGenSettings[i].fNumComponents = 0;
346 }
347 fHWActivePathTexGenSets = 0;
339 } 348 }
340 fHWActivePathTexGenSets = 0;
341 } 349 }
342 fHWPathStencilSettings.invalidate(); 350 fHWPathStencilSettings.invalidate();
343 } 351 }
344 352
345 // we assume these values 353 // we assume these values
346 if (resetBits & kPixelStore_GrGLBackendState) { 354 if (resetBits & kPixelStore_GrGLBackendState) {
347 if (this->glCaps().unpackRowLengthSupport()) { 355 if (this->glCaps().unpackRowLengthSupport()) {
348 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); 356 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
349 } 357 }
350 if (this->glCaps().packRowLengthSupport()) { 358 if (this->glCaps().packRowLengthSupport()) {
(...skipping 1536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro nt_Face); 1895 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro nt_Face);
1888 fPathRendering->stencilFillPath(id, fillMode, writeMask); 1896 fPathRendering->stencilFillPath(id, fillMode, writeMask);
1889 } 1897 }
1890 1898
1891 void GrGpuGL::onGpuDrawPath(const GrPath* path, SkPath::FillType fill) { 1899 void GrGpuGL::onGpuDrawPath(const GrPath* path, SkPath::FillType fill) {
1892 SkASSERT(this->caps()->pathRenderingSupport()); 1900 SkASSERT(this->caps()->pathRenderingSupport());
1893 1901
1894 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); 1902 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID();
1895 SkASSERT(NULL != this->drawState()->getRenderTarget()); 1903 SkASSERT(NULL != this->drawState()->getRenderTarget());
1896 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer()); 1904 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer());
1897 SkASSERT(!fCurrentProgram->hasVertexShader());
1898 1905
1899 flushPathStencilSettings(fill); 1906 flushPathStencilSettings(fill);
1900 const SkStrokeRec& stroke = path->getStroke(); 1907 const SkStrokeRec& stroke = path->getStroke();
1901 1908
1902 SkPath::FillType nonInvertedFill = SkPath::ConvertToNonInverseFillType(fill) ; 1909 SkPath::FillType nonInvertedFill = SkPath::ConvertToNonInverseFillType(fill) ;
1903 SkASSERT(!fHWPathStencilSettings.isTwoSided()); 1910 SkASSERT(!fHWPathStencilSettings.isTwoSided());
1904 GrGLenum fillMode = 1911 GrGLenum fillMode =
1905 gr_stencil_op_to_gl_path_rendering_fill_mode(fHWPathStencilSettings.pass Op(GrStencilSettings::kFront_Face)); 1912 gr_stencil_op_to_gl_path_rendering_fill_mode(fHWPathStencilSettings.pass Op(GrStencilSettings::kFront_Face));
1906 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro nt_Face); 1913 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro nt_Face);
1907 1914
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 } 1947 }
1941 1948
1942 this->drawSimpleRect(bounds); 1949 this->drawSimpleRect(bounds);
1943 } 1950 }
1944 } 1951 }
1945 1952
1946 void GrGpuGL::onGpuDrawPaths(const GrPathRange* pathRange, 1953 void GrGpuGL::onGpuDrawPaths(const GrPathRange* pathRange,
1947 const uint32_t indices[], int count, 1954 const uint32_t indices[], int count,
1948 const float transforms[], PathTransformType transfo rmsType, 1955 const float transforms[], PathTransformType transfo rmsType,
1949 SkPath::FillType fill) { 1956 SkPath::FillType fill) {
1950 SkASSERT(this->caps()->pathRenderingSupport()); 1957 SkASSERT(this->caps()->pathRenderingSupport());
bsalomon 2014/08/07 21:02:52 Move whole impl to path rendering class?
1951 SkASSERT(NULL != this->drawState()->getRenderTarget()); 1958 SkASSERT(NULL != this->drawState()->getRenderTarget());
1952 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer()); 1959 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer());
1953 SkASSERT(!fCurrentProgram->hasVertexShader());
1954 1960
1955 GrGLuint baseID = static_cast<const GrGLPathRange*>(pathRange)->basePathID() ; 1961 GrGLuint baseID = static_cast<const GrGLPathRange*>(pathRange)->basePathID() ;
1956 1962
1957 flushPathStencilSettings(fill); 1963 flushPathStencilSettings(fill);
1958 const SkStrokeRec& stroke = pathRange->getStroke(); 1964 const SkStrokeRec& stroke = pathRange->getStroke();
1959 1965
1960 SkPath::FillType nonInvertedFill = 1966 SkPath::FillType nonInvertedFill =
1961 SkPath::ConvertToNonInverseFillType(fill); 1967 SkPath::ConvertToNonInverseFillType(fill);
1962 1968
1963 SkASSERT(!fHWPathStencilSettings.isTwoSided()); 1969 SkASSERT(!fHWPathStencilSettings.isTwoSided());
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
2379 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { 2385 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) {
2380 return; 2386 return;
2381 } 2387 }
2382 2388
2383 fHWProjectionMatrixState.fViewMatrix = matrix; 2389 fHWProjectionMatrixState.fViewMatrix = matrix;
2384 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; 2390 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize;
2385 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; 2391 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin;
2386 2392
2387 GrGLfloat glMatrix[4 * 4]; 2393 GrGLfloat glMatrix[4 * 4];
2388 fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix); 2394 fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix);
2389 GL_CALL(MatrixLoadf(GR_GL_PROJECTION, glMatrix)); 2395
2396 GrGLenum matrixMode =
bsalomon 2014/08/07 21:02:52 Move to PR class?
2397 this->glStandard() == kGLES_GrGLStandard ? GR_GL_PATH_PROJECTION : GR_GL _PROJECTION;
2398
2399 GL_CALL(MatrixLoadf(matrixMode, glMatrix));
2390 } 2400 }
2391 2401
2392 void GrGpuGL::enablePathTexGen(int unitIdx, 2402 void GrGpuGL::enablePathTexGen(int unitIdx,
2393 PathTexGenComponents components, 2403 PathTexGenComponents components,
2394 const GrGLfloat* coefficients) { 2404 const GrGLfloat* coefficients) {
2395 SkASSERT(this->glCaps().pathRenderingSupport()); 2405 SkASSERT(this->glCaps().pathRenderingSupport());
2396 SkASSERT(components >= kS_PathTexGenComponents && 2406 SkASSERT(components >= kS_PathTexGenComponents &&
2397 components <= kSTR_PathTexGenComponents); 2407 components <= kSTR_PathTexGenComponents);
2398 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= unitIdx); 2408 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= unitIdx);
2399 2409
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
2967 this->setVertexArrayID(gpu, 0); 2977 this->setVertexArrayID(gpu, 0);
2968 } 2978 }
2969 int attrCount = gpu->glCaps().maxVertexAttributes(); 2979 int attrCount = gpu->glCaps().maxVertexAttributes();
2970 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2980 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2971 fDefaultVertexArrayAttribState.resize(attrCount); 2981 fDefaultVertexArrayAttribState.resize(attrCount);
2972 } 2982 }
2973 attribState = &fDefaultVertexArrayAttribState; 2983 attribState = &fDefaultVertexArrayAttribState;
2974 } 2984 }
2975 return attribState; 2985 return attribState;
2976 } 2986 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698