| OLD | NEW |
| 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 "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
| 10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
| 11 #include "GrGLStencilAttachment.h" | 11 #include "GrGLStencilAttachment.h" |
| 12 #include "GrGLTextureRenderTarget.h" | 12 #include "GrGLTextureRenderTarget.h" |
| 13 #include "GrGpuResourcePriv.h" | 13 #include "GrGpuResourcePriv.h" |
| 14 #include "GrPipeline.h" | 14 #include "GrPipeline.h" |
| 15 #include "GrPLSGeometryProcessor.h" | |
| 16 #include "GrRenderTargetPriv.h" | 15 #include "GrRenderTargetPriv.h" |
| 17 #include "GrSurfacePriv.h" | 16 #include "GrSurfacePriv.h" |
| 18 #include "GrTexturePriv.h" | 17 #include "GrTexturePriv.h" |
| 19 #include "GrTypes.h" | 18 #include "GrTypes.h" |
| 20 #include "GrVertices.h" | 19 #include "GrVertices.h" |
| 21 #include "builders/GrGLShaderStringBuilder.h" | 20 #include "builders/GrGLShaderStringBuilder.h" |
| 22 #include "glsl/GrGLSL.h" | 21 #include "glsl/GrGLSL.h" |
| 23 #include "glsl/GrGLSLCaps.h" | 22 #include "glsl/GrGLSLCaps.h" |
| 24 #include "glsl/GrGLSLPLSPathRendering.h" | |
| 25 #include "SkStrokeRec.h" | 23 #include "SkStrokeRec.h" |
| 26 #include "SkTemplates.h" | 24 #include "SkTemplates.h" |
| 27 | 25 |
| 28 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) | 26 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
| 29 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) | 27 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) |
| 30 | 28 |
| 31 #define SKIP_CACHE_CHECK true | 29 #define SKIP_CACHE_CHECK true |
| 32 | 30 |
| 33 #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR | 31 #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR |
| 34 #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) | 32 #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) |
| 35 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) | 33 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) |
| 36 #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) | 34 #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) |
| 37 #else | 35 #else |
| 38 #define CLEAR_ERROR_BEFORE_ALLOC(iface) | 36 #define CLEAR_ERROR_BEFORE_ALLOC(iface) |
| 39 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call) | 37 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call) |
| 40 #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR | 38 #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR |
| 41 #endif | 39 #endif |
| 42 | 40 |
| 41 |
| 43 /////////////////////////////////////////////////////////////////////////////// | 42 /////////////////////////////////////////////////////////////////////////////// |
| 44 | 43 |
| 45 | 44 |
| 46 static const GrGLenum gXfermodeEquation2Blend[] = { | 45 static const GrGLenum gXfermodeEquation2Blend[] = { |
| 47 // Basic OpenGL blend equations. | 46 // Basic OpenGL blend equations. |
| 48 GR_GL_FUNC_ADD, | 47 GR_GL_FUNC_ADD, |
| 49 GR_GL_FUNC_SUBTRACT, | 48 GR_GL_FUNC_SUBTRACT, |
| 50 GR_GL_FUNC_REVERSE_SUBTRACT, | 49 GR_GL_FUNC_REVERSE_SUBTRACT, |
| 51 | 50 |
| 52 // GL_KHR_blend_equation_advanced. | 51 // GL_KHR_blend_equation_advanced. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 fTempSrcFBOID = 0; | 217 fTempSrcFBOID = 0; |
| 219 fTempDstFBOID = 0; | 218 fTempDstFBOID = 0; |
| 220 fStencilClearFBOID = 0; | 219 fStencilClearFBOID = 0; |
| 221 | 220 |
| 222 if (this->glCaps().shaderCaps()->pathRenderingSupport()) { | 221 if (this->glCaps().shaderCaps()->pathRenderingSupport()) { |
| 223 fPathRendering.reset(new GrGLPathRendering(this)); | 222 fPathRendering.reset(new GrGLPathRendering(this)); |
| 224 } | 223 } |
| 225 this->createCopyPrograms(); | 224 this->createCopyPrograms(); |
| 226 fWireRectProgram.fProgram = 0; | 225 fWireRectProgram.fProgram = 0; |
| 227 fWireRectArrayBuffer = 0; | 226 fWireRectArrayBuffer = 0; |
| 228 if (this->glCaps().shaderCaps()->plsPathRenderingSupport()) { | |
| 229 this->createPLSSetupProgram(); | |
| 230 } | |
| 231 else { | |
| 232 memset(&fPLSSetupProgram, 0, sizeof(fPLSSetupProgram)); | |
| 233 } | |
| 234 fHWPLSEnabled = false; | |
| 235 fPLSHasBeenUsed = false; | |
| 236 } | 227 } |
| 237 | 228 |
| 238 GrGLGpu::~GrGLGpu() { | 229 GrGLGpu::~GrGLGpu() { |
| 239 // Delete the path rendering explicitly, since it will need working gpu obje
ct to release the | 230 // Delete the path rendering explicitly, since it will need working gpu obje
ct to release the |
| 240 // resources the object itself holds. | 231 // resources the object itself holds. |
| 241 fPathRendering.reset(); | 232 fPathRendering.reset(); |
| 242 | 233 |
| 243 if (0 != fHWProgramID) { | 234 if (0 != fHWProgramID) { |
| 244 // detach the current program so there is no confusion on OpenGL's part | 235 // detach the current program so there is no confusion on OpenGL's part |
| 245 // that we want it to be deleted | 236 // that we want it to be deleted |
| (...skipping 21 matching lines...) Expand all Loading... |
| 267 } | 258 } |
| 268 | 259 |
| 269 if (0 != fWireRectProgram.fProgram) { | 260 if (0 != fWireRectProgram.fProgram) { |
| 270 GL_CALL(DeleteProgram(fWireRectProgram.fProgram)); | 261 GL_CALL(DeleteProgram(fWireRectProgram.fProgram)); |
| 271 } | 262 } |
| 272 | 263 |
| 273 if (0 != fWireRectArrayBuffer) { | 264 if (0 != fWireRectArrayBuffer) { |
| 274 GL_CALL(DeleteBuffers(1, &fWireRectArrayBuffer)); | 265 GL_CALL(DeleteBuffers(1, &fWireRectArrayBuffer)); |
| 275 } | 266 } |
| 276 | 267 |
| 277 if (0 != fPLSSetupProgram.fArrayBuffer) { | |
| 278 GL_CALL(DeleteBuffers(1, &fPLSSetupProgram.fArrayBuffer)); | |
| 279 } | |
| 280 | |
| 281 if (0 != fPLSSetupProgram.fProgram) { | |
| 282 GL_CALL(DeleteProgram(fPLSSetupProgram.fProgram)); | |
| 283 } | |
| 284 | |
| 285 delete fProgramCache; | 268 delete fProgramCache; |
| 286 } | 269 } |
| 287 | 270 |
| 288 void GrGLGpu::createPLSSetupProgram() { | |
| 289 const char* version = this->glCaps().glslCaps()->versionDeclString(); | |
| 290 | |
| 291 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute
_TypeModifier); | |
| 292 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, | |
| 293 GrShaderVar::kUniform_TypeModifier); | |
| 294 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, GrShaderVar::kUnifo
rm_TypeModifier); | |
| 295 GrGLSLShaderVar uTexture("u_texture", kSampler2D_GrSLType, GrShaderVar::kUni
form_TypeModifier); | |
| 296 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, GrShaderVar::kVaryi
ngOut_TypeModifier); | |
| 297 | |
| 298 SkString vshaderTxt(version); | |
| 299 aVertex.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); | |
| 300 vshaderTxt.append(";"); | |
| 301 uTexCoordXform.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); | |
| 302 vshaderTxt.append(";"); | |
| 303 uPosXform.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); | |
| 304 vshaderTxt.append(";"); | |
| 305 vTexCoord.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); | |
| 306 vshaderTxt.append(";"); | |
| 307 | |
| 308 vshaderTxt.append( | |
| 309 "// PLS Setup Program VS\n" | |
| 310 "void main() {" | |
| 311 " gl_Position.xy = a_vertex * u_posXform.xy + u_posXform.zw;" | |
| 312 " gl_Position.zw = vec2(0, 1);" | |
| 313 "}" | |
| 314 ); | |
| 315 | |
| 316 SkString fshaderTxt(version); | |
| 317 fshaderTxt.append("#extension "); | |
| 318 fshaderTxt.append(this->glCaps().glslCaps()->fbFetchExtensionString()); | |
| 319 fshaderTxt.append(" : require\n"); | |
| 320 fshaderTxt.append("#extension GL_EXT_shader_pixel_local_storage : require\n"
); | |
| 321 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, | |
| 322 *this->glCaps().glslCaps(), | |
| 323 &fshaderTxt); | |
| 324 vTexCoord.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); | |
| 325 vTexCoord.appendDecl(this->glCaps().glslCaps(), &fshaderTxt); | |
| 326 fshaderTxt.append(";"); | |
| 327 uTexture.appendDecl(this->glCaps().glslCaps(), &fshaderTxt); | |
| 328 fshaderTxt.append(";"); | |
| 329 | |
| 330 fshaderTxt.appendf( | |
| 331 "// PLS Setup Program FS\n" | |
| 332 GR_GL_PLS_PATH_DATA_DECL | |
| 333 "void main() {\n" | |
| 334 " " GR_GL_PLS_DSTCOLOR_NAME " = gl_LastFragColorARM;\n" | |
| 335 " pls.windings = ivec4(0, 0, 0, 0);\n" | |
| 336 "}" | |
| 337 ); | |
| 338 GL_CALL_RET(fPLSSetupProgram.fProgram, CreateProgram()); | |
| 339 const char* str; | |
| 340 GrGLint length; | |
| 341 | |
| 342 str = vshaderTxt.c_str(); | |
| 343 length = SkToInt(vshaderTxt.size()); | |
| 344 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fPLSSetupProgram.
fProgram, | |
| 345 GR_GL_VERTEX_SHADER, &str, &le
ngth, 1, &fStats); | |
| 346 | |
| 347 str = fshaderTxt.c_str(); | |
| 348 length = SkToInt(fshaderTxt.size()); | |
| 349 GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fPLSSetupProgram.
fProgram, | |
| 350 GR_GL_FRAGMENT_SHADER, &str, &
length, 1, &fStats); | |
| 351 | |
| 352 GL_CALL(LinkProgram(fPLSSetupProgram.fProgram)); | |
| 353 | |
| 354 GL_CALL_RET(fPLSSetupProgram.fPosXformUniform, GetUniformLocation(fPLSSetupP
rogram.fProgram, | |
| 355 "u_posXform"))
; | |
| 356 | |
| 357 GL_CALL(BindAttribLocation(fPLSSetupProgram.fProgram, 0, "a_vertex")); | |
| 358 | |
| 359 GL_CALL(DeleteShader(vshader)); | |
| 360 GL_CALL(DeleteShader(fshader)); | |
| 361 | |
| 362 GL_CALL(GenBuffers(1, &fPLSSetupProgram.fArrayBuffer)); | |
| 363 fHWGeometryState.setVertexBufferID(this, fPLSSetupProgram.fArrayBuffer); | |
| 364 static const GrGLfloat vdata[] = { | |
| 365 0, 0, | |
| 366 0, 1, | |
| 367 1, 0, | |
| 368 1, 1 | |
| 369 }; | |
| 370 GL_ALLOC_CALL(this->glInterface(), | |
| 371 BufferData(GR_GL_ARRAY_BUFFER, | |
| 372 (GrGLsizeiptr) sizeof(vdata), | |
| 373 vdata, // data ptr | |
| 374 GR_GL_STATIC_DRAW)); | |
| 375 } | |
| 376 | |
| 377 void GrGLGpu::contextAbandoned() { | 271 void GrGLGpu::contextAbandoned() { |
| 378 INHERITED::contextAbandoned(); | 272 INHERITED::contextAbandoned(); |
| 379 fProgramCache->abandon(); | 273 fProgramCache->abandon(); |
| 380 fHWProgramID = 0; | 274 fHWProgramID = 0; |
| 381 fTempSrcFBOID = 0; | 275 fTempSrcFBOID = 0; |
| 382 fTempDstFBOID = 0; | 276 fTempDstFBOID = 0; |
| 383 fStencilClearFBOID = 0; | 277 fStencilClearFBOID = 0; |
| 384 fCopyProgramArrayBuffer = 0; | 278 fCopyProgramArrayBuffer = 0; |
| 385 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { | 279 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { |
| 386 fCopyPrograms[i].fProgram = 0; | 280 fCopyPrograms[i].fProgram = 0; |
| (...skipping 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2300 if (!flipY) { | 2194 if (!flipY) { |
| 2301 dst += rowBytes; | 2195 dst += rowBytes; |
| 2302 } else { | 2196 } else { |
| 2303 dst -= rowBytes; | 2197 dst -= rowBytes; |
| 2304 } | 2198 } |
| 2305 } | 2199 } |
| 2306 } | 2200 } |
| 2307 return true; | 2201 return true; |
| 2308 } | 2202 } |
| 2309 | 2203 |
| 2310 void GrGLGpu::performFlushWorkaround() { | 2204 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bound)
{ |
| 2311 if (fPLSHasBeenUsed) { | |
| 2312 /* There is an ARM driver bug where if we use PLS, and then draw a frame
which does not | |
| 2313 * use PLS, it leaves garbage all over the place. As a workaround, we us
e PLS in a | |
| 2314 * trivial way every frame. And since we use it every frame, there's nev
er a point at which | |
| 2315 * it becomes safe to stop using this workaround once we start. | |
| 2316 */ | |
| 2317 this->disableScissor(); | |
| 2318 // using PLS in the presence of MSAA results in GL_INVALID_OPERATION | |
| 2319 this->flushHWAAState(nullptr, false); | |
| 2320 SkASSERT(!fHWPLSEnabled); | |
| 2321 SkASSERT(fMSAAEnabled != kYes_TriState); | |
| 2322 GL_CALL(Enable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); | |
| 2323 this->stampRectUsingProgram(fPLSSetupProgram.fProgram, | |
| 2324 SkRect::MakeXYWH(-100.0f, -100.0f, 0.01f, 0.
01f), | |
| 2325 fPLSSetupProgram.fPosXformUniform, | |
| 2326 fPLSSetupProgram.fArrayBuffer); | |
| 2327 GL_CALL(Disable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); | |
| 2328 } | |
| 2329 } | |
| 2330 | 2205 |
| 2331 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bound)
{ | |
| 2332 SkASSERT(target); | 2206 SkASSERT(target); |
| 2333 | 2207 |
| 2334 uint32_t rtID = target->getUniqueID(); | 2208 uint32_t rtID = target->getUniqueID(); |
| 2335 if (fHWBoundRenderTargetUniqueID != rtID) { | 2209 if (fHWBoundRenderTargetUniqueID != rtID) { |
| 2336 fStats.incRenderTargetBinds(); | 2210 fStats.incRenderTargetBinds(); |
| 2337 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID())); | 2211 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID())); |
| 2338 #ifdef SK_DEBUG | 2212 #ifdef SK_DEBUG |
| 2339 // don't do this check in Chromium -- this is causing | 2213 // don't do this check in Chromium -- this is causing |
| 2340 // lots of repeated command buffer flushes when the compositor is | 2214 // lots of repeated command buffer flushes when the compositor is |
| 2341 // rendering with Ganesh, which is really slow; even too slow for | 2215 // rendering with Ganesh, which is really slow; even too slow for |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2404 } | 2278 } |
| 2405 } | 2279 } |
| 2406 #endif | 2280 #endif |
| 2407 #endif | 2281 #endif |
| 2408 | 2282 |
| 2409 void GrGLGpu::onDraw(const DrawArgs& args, const GrNonInstancedVertices& vertice
s) { | 2283 void GrGLGpu::onDraw(const DrawArgs& args, const GrNonInstancedVertices& vertice
s) { |
| 2410 if (!this->flushGLState(args)) { | 2284 if (!this->flushGLState(args)) { |
| 2411 return; | 2285 return; |
| 2412 } | 2286 } |
| 2413 | 2287 |
| 2414 GrPixelLocalStorageState plsState = args.fPrimitiveProcessor->getPixelLocalS
torageState(); | |
| 2415 if (!fHWPLSEnabled && plsState != | |
| 2416 GrPixelLocalStorageState::kDisabled_GrPixelLocalStorageState) { | |
| 2417 GL_CALL(Enable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); | |
| 2418 this->setupPixelLocalStorage(args); | |
| 2419 fHWPLSEnabled = true; | |
| 2420 } | |
| 2421 if (plsState == GrPixelLocalStorageState::kFinish_GrPixelLocalStorageState)
{ | |
| 2422 GrStencilSettings stencil; | |
| 2423 stencil.setDisabled(); | |
| 2424 this->flushStencil(stencil); | |
| 2425 } | |
| 2426 | |
| 2427 size_t indexOffsetInBytes = 0; | 2288 size_t indexOffsetInBytes = 0; |
| 2428 this->setupGeometry(*args.fPrimitiveProcessor, vertices, &indexOffsetInBytes
); | 2289 this->setupGeometry(*args.fPrimitiveProcessor, vertices, &indexOffsetInBytes
); |
| 2429 | 2290 |
| 2430 SkASSERT((size_t)vertices.primitiveType() < SK_ARRAY_COUNT(gPrimitiveType2GL
Mode)); | 2291 SkASSERT((size_t)vertices.primitiveType() < SK_ARRAY_COUNT(gPrimitiveType2GL
Mode)); |
| 2431 | 2292 |
| 2432 if (vertices.isIndexed()) { | 2293 if (vertices.isIndexed()) { |
| 2433 GrGLvoid* indices = | 2294 GrGLvoid* indices = |
| 2434 reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) * | 2295 reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) * |
| 2435 vertices.startIndex()); | 2296 vertices.startIndex()); |
| 2436 // info.startVertex() was accounted for by setupGeometry. | 2297 // info.startVertex() was accounted for by setupGeometry. |
| 2437 GL_CALL(DrawElements(gPrimitiveType2GLMode[vertices.primitiveType()], | 2298 GL_CALL(DrawElements(gPrimitiveType2GLMode[vertices.primitiveType()], |
| 2438 vertices.indexCount(), | 2299 vertices.indexCount(), |
| 2439 GR_GL_UNSIGNED_SHORT, | 2300 GR_GL_UNSIGNED_SHORT, |
| 2440 indices)); | 2301 indices)); |
| 2441 } else { | 2302 } else { |
| 2442 // Pass 0 for parameter first. We have to adjust glVertexAttribPointer()
to account for | 2303 // Pass 0 for parameter first. We have to adjust glVertexAttribPointer()
to account for |
| 2443 // startVertex in the DrawElements case. So we always rely on setupGeome
try to have | 2304 // startVertex in the DrawElements case. So we always rely on setupGeome
try to have |
| 2444 // accounted for startVertex. | 2305 // accounted for startVertex. |
| 2445 GL_CALL(DrawArrays(gPrimitiveType2GLMode[vertices.primitiveType()], 0, | 2306 GL_CALL(DrawArrays(gPrimitiveType2GLMode[vertices.primitiveType()], 0, |
| 2446 vertices.vertexCount())); | 2307 vertices.vertexCount())); |
| 2447 } | 2308 } |
| 2448 | |
| 2449 if (fHWPLSEnabled && plsState == GrPixelLocalStorageState::kFinish_GrPixelLo
calStorageState) { | |
| 2450 // PLS draws always involve multiple draws, finishing up with a non-PLS | |
| 2451 // draw that writes to the color buffer. That draw ends up here; we wait | |
| 2452 // until after it is complete to actually disable PLS. | |
| 2453 GL_CALL(Disable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); | |
| 2454 fHWPLSEnabled = false; | |
| 2455 this->disableScissor(); | |
| 2456 } | |
| 2457 | |
| 2458 #if SWAP_PER_DRAW | 2309 #if SWAP_PER_DRAW |
| 2459 glFlush(); | 2310 glFlush(); |
| 2460 #if defined(SK_BUILD_FOR_MAC) | 2311 #if defined(SK_BUILD_FOR_MAC) |
| 2461 aglSwapBuffers(aglGetCurrentContext()); | 2312 aglSwapBuffers(aglGetCurrentContext()); |
| 2462 int set_a_break_pt_here = 9; | 2313 int set_a_break_pt_here = 9; |
| 2463 aglSwapBuffers(aglGetCurrentContext()); | 2314 aglSwapBuffers(aglGetCurrentContext()); |
| 2464 #elif defined(SK_BUILD_FOR_WIN32) | 2315 #elif defined(SK_BUILD_FOR_WIN32) |
| 2465 SwapBuf(); | 2316 SwapBuf(); |
| 2466 int set_a_break_pt_here = 9; | 2317 int set_a_break_pt_here = 9; |
| 2467 SwapBuf(); | 2318 SwapBuf(); |
| 2468 #endif | 2319 #endif |
| 2469 #endif | 2320 #endif |
| 2470 } | 2321 } |
| 2471 | 2322 |
| 2472 void GrGLGpu::stampRectUsingProgram(GrGLuint program, const SkRect& bounds, GrGL
int posXformUniform, | |
| 2473 GrGLuint arrayBuffer) { | |
| 2474 GL_CALL(UseProgram(program)); | |
| 2475 this->fHWGeometryState.setVertexArrayID(this, 0); | |
| 2476 | |
| 2477 GrGLAttribArrayState* attribs = | |
| 2478 this->fHWGeometryState.bindArrayAndBufferToDraw(this, arrayBuffer); | |
| 2479 attribs->set(this, 0, arrayBuffer, 2, GR_GL_FLOAT, false, 2 * sizeof(GrGLflo
at), 0); | |
| 2480 attribs->disableUnusedArrays(this, 0x1); | |
| 2481 | |
| 2482 GL_CALL(Uniform4f(posXformUniform, bounds.width(), bounds.height(), bounds.l
eft(), | |
| 2483 bounds.top())); | |
| 2484 | |
| 2485 GrXferProcessor::BlendInfo blendInfo; | |
| 2486 blendInfo.reset(); | |
| 2487 this->flushBlend(blendInfo, GrSwizzle()); | |
| 2488 this->flushColorWrite(true); | |
| 2489 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); | |
| 2490 if (!fHWStencilSettings.isDisabled()) { | |
| 2491 GL_CALL(Disable(GR_GL_STENCIL_TEST)); | |
| 2492 } | |
| 2493 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); | |
| 2494 GL_CALL(UseProgram(fHWProgramID)); | |
| 2495 if (!fHWStencilSettings.isDisabled()) { | |
| 2496 GL_CALL(Enable(GR_GL_STENCIL_TEST)); | |
| 2497 } | |
| 2498 } | |
| 2499 | |
| 2500 void GrGLGpu::setupPixelLocalStorage(const DrawArgs& args) { | |
| 2501 fPLSHasBeenUsed = true; | |
| 2502 const SkRect& bounds = | |
| 2503 static_cast<const GrPLSGeometryProcessor*>(args.fPrimitiveProcessor)
->getBounds(); | |
| 2504 // setup pixel local storage -- this means capturing and storing the current
framebuffer color | |
| 2505 // and initializing the winding counts to zero | |
| 2506 GrRenderTarget* rt = args.fPipeline->getRenderTarget(); | |
| 2507 SkScalar width = SkIntToScalar(rt->width()); | |
| 2508 SkScalar height = SkIntToScalar(rt->height()); | |
| 2509 // dst rect edges in NDC (-1 to 1) | |
| 2510 // having some issues with rounding, just expand the bounds by 1 and trust t
he scissor to keep | |
| 2511 // it contained properly | |
| 2512 GrGLfloat dx0 = 2.0f * (bounds.left() - 1) / width - 1.0f; | |
| 2513 GrGLfloat dx1 = 2.0f * (bounds.right() + 1) / width - 1.0f; | |
| 2514 GrGLfloat dy0 = -2.0f * (bounds.top() - 1) / height + 1.0f; | |
| 2515 GrGLfloat dy1 = -2.0f * (bounds.bottom() + 1) / height + 1.0f; | |
| 2516 SkRect deviceBounds = SkRect::MakeXYWH(dx0, dy0, dx1 - dx0, dy1 - dy0); | |
| 2517 | |
| 2518 GL_CALL(Enable(GR_GL_FETCH_PER_SAMPLE_ARM)); | |
| 2519 this->stampRectUsingProgram(fPLSSetupProgram.fProgram, deviceBounds, | |
| 2520 fPLSSetupProgram.fPosXformUniform, fPLSSetupProg
ram.fArrayBuffer); | |
| 2521 } | |
| 2522 | |
| 2523 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { | 2323 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { |
| 2524 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); | 2324 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
| 2525 if (rt->needsResolve()) { | 2325 if (rt->needsResolve()) { |
| 2526 // Some extensions automatically resolves the texture when it is read. | 2326 // Some extensions automatically resolves the texture when it is read. |
| 2527 if (this->glCaps().usesMSAARenderBuffers()) { | 2327 if (this->glCaps().usesMSAARenderBuffers()) { |
| 2528 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); | 2328 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); |
| 2529 fStats.incRenderTargetBinds(); | 2329 fStats.incRenderTargetBinds(); |
| 2530 fStats.incRenderTargetBinds(); | 2330 fStats.incRenderTargetBinds(); |
| 2531 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); | 2331 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
| 2532 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; | 2332 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; |
| (...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3756 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 3556 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
| 3757 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 3557 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
| 3758 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 3558 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
| 3759 copyParams->fWidth = texture->width(); | 3559 copyParams->fWidth = texture->width(); |
| 3760 copyParams->fHeight = texture->height(); | 3560 copyParams->fHeight = texture->height(); |
| 3761 return true; | 3561 return true; |
| 3762 } | 3562 } |
| 3763 } | 3563 } |
| 3764 return false; | 3564 return false; |
| 3765 } | 3565 } |
| OLD | NEW |