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 #include "GrGLGpu.h" | 8 #include "GrGLGpu.h" |
9 #include "GrGLBuffer.h" | 9 #include "GrGLBuffer.h" |
10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 if (glContext) { | 181 if (glContext) { |
182 return new GrGLGpu(glContext, context); | 182 return new GrGLGpu(glContext, context); |
183 } | 183 } |
184 return nullptr; | 184 return nullptr; |
185 } | 185 } |
186 | 186 |
187 static bool gPrintStartupSpew; | 187 static bool gPrintStartupSpew; |
188 | 188 |
189 GrGLGpu::GrGLGpu(GrGLContext* ctx, GrContext* context) | 189 GrGLGpu::GrGLGpu(GrGLContext* ctx, GrContext* context) |
190 : GrGpu(context) | 190 : GrGpu(context) |
191 , fGLContext(ctx) { | 191 , fGLContext(ctx) |
192 , fProgramCache(new ProgramCache(this)) | |
193 , fHWProgramID(0) | |
194 , fTempSrcFBOID(0) | |
195 , fTempDstFBOID(0) | |
196 , fStencilClearFBOID(0) | |
197 , fHWPLSEnabled(false) | |
198 , fPLSHasBeenUsed(false) | |
199 , fHWMinSampleShading(0.0) { | |
200 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { | |
201 fCopyPrograms[i].fProgram = 0; | |
202 } | |
203 fWireRectProgram.fProgram = 0; | |
204 fPLSSetupProgram.fProgram = 0; | |
205 | |
192 SkASSERT(ctx); | 206 SkASSERT(ctx); |
193 fCaps.reset(SkRef(ctx->caps())); | 207 fCaps.reset(SkRef(ctx->caps())); |
194 | 208 |
195 fHWBoundTextureUniqueIDs.reset(this->glCaps().glslCaps()->maxCombinedSampler s()); | 209 fHWBoundTextureUniqueIDs.reset(this->glCaps().glslCaps()->maxCombinedSampler s()); |
196 | 210 |
211 fHWBufferState[kVertex_GrBufferType].fGLTarget = GR_GL_ARRAY_BUFFER; | |
212 fHWBufferState[kIndex_GrBufferType].fGLTarget = GR_GL_ELEMENT_ARRAY_BUFFER; | |
213 fHWBufferState[kTexel_GrBufferType].fGLTarget = GR_GL_TEXTURE_BUFFER; | |
214 fHWBufferState[kDrawIndirect_GrBufferType].fGLTarget = GR_GL_DRAW_INDIRECT_B UFFER; | |
215 if (GrGLCaps::kChromium_TransferBufferType == this->glCaps().transferBufferT ype()) { | |
216 fHWBufferState[kXferCpuToGpu_GrBufferType].fGLTarget = | |
217 GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM; | |
218 fHWBufferState[kXferGpuToCpu_GrBufferType].fGLTarget = | |
219 GR_GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM; | |
220 } else { | |
221 fHWBufferState[kXferCpuToGpu_GrBufferType].fGLTarget = GR_GL_PIXEL_UNPAC K_BUFFER; | |
222 fHWBufferState[kXferGpuToCpu_GrBufferType].fGLTarget = GR_GL_PIXEL_PACK_ BUFFER; | |
223 } | |
224 GR_STATIC_ASSERT(6 == SK_ARRAY_COUNT(fHWBufferState)); | |
225 | |
226 if (this->glCaps().shaderCaps()->pathRenderingSupport()) { | |
227 fPathRendering.reset(new GrGLPathRendering(this)); | |
228 } | |
229 | |
197 GrGLClearErr(this->glInterface()); | 230 GrGLClearErr(this->glInterface()); |
198 if (gPrintStartupSpew) { | 231 if (gPrintStartupSpew) { |
199 const GrGLubyte* vendor; | 232 const GrGLubyte* vendor; |
200 const GrGLubyte* renderer; | 233 const GrGLubyte* renderer; |
201 const GrGLubyte* version; | 234 const GrGLubyte* version; |
202 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); | 235 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); |
203 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); | 236 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); |
204 GL_CALL_RET(version, GetString(GR_GL_VERSION)); | 237 GL_CALL_RET(version, GetString(GR_GL_VERSION)); |
205 SkDebugf("------------------------- create GrGLGpu %p --------------\n", | 238 SkDebugf("------------------------- create GrGLGpu %p --------------\n", |
206 this); | 239 this); |
207 SkDebugf("------ VENDOR %s\n", vendor); | 240 SkDebugf("------ VENDOR %s\n", vendor); |
208 SkDebugf("------ RENDERER %s\n", renderer); | 241 SkDebugf("------ RENDERER %s\n", renderer); |
209 SkDebugf("------ VERSION %s\n", version); | 242 SkDebugf("------ VERSION %s\n", version); |
210 SkDebugf("------ EXTENSIONS\n"); | 243 SkDebugf("------ EXTENSIONS\n"); |
211 this->glContext().extensions().print(); | 244 this->glContext().extensions().print(); |
212 SkDebugf("\n"); | 245 SkDebugf("\n"); |
213 SkDebugf("%s", this->glCaps().dump().c_str()); | 246 SkDebugf("%s", this->glCaps().dump().c_str()); |
214 } | 247 } |
215 | |
216 fProgramCache = new ProgramCache(this); | |
217 | |
218 fHWProgramID = 0; | |
219 fTempSrcFBOID = 0; | |
220 fTempDstFBOID = 0; | |
221 fStencilClearFBOID = 0; | |
222 | |
223 if (this->glCaps().shaderCaps()->pathRenderingSupport()) { | |
224 fPathRendering.reset(new GrGLPathRendering(this)); | |
225 } | |
226 this->createCopyPrograms(); | |
227 fWireRectProgram.fProgram = 0; | |
228 fWireRectArrayBuffer = 0; | |
229 if (this->glCaps().shaderCaps()->plsPathRenderingSupport()) { | |
230 this->createPLSSetupProgram(); | |
231 } | |
232 else { | |
233 memset(&fPLSSetupProgram, 0, sizeof(fPLSSetupProgram)); | |
234 } | |
235 fHWPLSEnabled = false; | |
236 fPLSHasBeenUsed = false; | |
237 fHWMinSampleShading = 0.0; | |
238 } | 248 } |
239 | 249 |
240 GrGLGpu::~GrGLGpu() { | 250 GrGLGpu::~GrGLGpu() { |
241 // Delete the path rendering explicitly, since it will need working gpu obje ct to release the | 251 // Ensure any GrGpuResource objects get deleted first, since they will requi re a working GrGpu |
242 // resources the object itself holds. | 252 // to release the resources held by the objects themselves. |
243 fPathRendering.reset(); | 253 fPathRendering.reset(); |
254 fCopyProgramArrayBuffer.reset(); | |
bsalomon
2016/04/05 15:17:28
Should we go ahead and declare GrGLGpu final? I do
Chris Dalton
2016/04/05 17:59:15
Done.
| |
255 fWireRectArrayBuffer.reset(); | |
256 fPLSSetupProgram.fArrayBuffer.reset(); | |
244 | 257 |
245 if (0 != fHWProgramID) { | 258 if (0 != fHWProgramID) { |
246 // detach the current program so there is no confusion on OpenGL's part | 259 // detach the current program so there is no confusion on OpenGL's part |
247 // that we want it to be deleted | 260 // that we want it to be deleted |
248 GL_CALL(UseProgram(0)); | 261 GL_CALL(UseProgram(0)); |
249 } | 262 } |
250 | 263 |
251 if (0 != fTempSrcFBOID) { | 264 if (0 != fTempSrcFBOID) { |
252 GL_CALL(DeleteFramebuffers(1, &fTempSrcFBOID)); | 265 GL_CALL(DeleteFramebuffers(1, &fTempSrcFBOID)); |
253 } | 266 } |
254 if (0 != fTempDstFBOID) { | 267 if (0 != fTempDstFBOID) { |
255 GL_CALL(DeleteFramebuffers(1, &fTempDstFBOID)); | 268 GL_CALL(DeleteFramebuffers(1, &fTempDstFBOID)); |
256 } | 269 } |
257 if (0 != fStencilClearFBOID) { | 270 if (0 != fStencilClearFBOID) { |
258 GL_CALL(DeleteFramebuffers(1, &fStencilClearFBOID)); | 271 GL_CALL(DeleteFramebuffers(1, &fStencilClearFBOID)); |
259 } | 272 } |
260 | 273 |
261 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { | 274 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { |
262 if (0 != fCopyPrograms[i].fProgram) { | 275 if (0 != fCopyPrograms[i].fProgram) { |
263 GL_CALL(DeleteProgram(fCopyPrograms[i].fProgram)); | 276 GL_CALL(DeleteProgram(fCopyPrograms[i].fProgram)); |
264 } | 277 } |
265 } | 278 } |
266 | 279 |
267 if (0 != fCopyProgramArrayBuffer) { | |
268 GL_CALL(DeleteBuffers(1, &fCopyProgramArrayBuffer)); | |
269 } | |
270 | |
271 if (0 != fWireRectProgram.fProgram) { | 280 if (0 != fWireRectProgram.fProgram) { |
272 GL_CALL(DeleteProgram(fWireRectProgram.fProgram)); | 281 GL_CALL(DeleteProgram(fWireRectProgram.fProgram)); |
273 } | 282 } |
274 | 283 |
275 if (0 != fWireRectArrayBuffer) { | |
276 GL_CALL(DeleteBuffers(1, &fWireRectArrayBuffer)); | |
277 } | |
278 | |
279 if (0 != fPLSSetupProgram.fArrayBuffer) { | |
280 GL_CALL(DeleteBuffers(1, &fPLSSetupProgram.fArrayBuffer)); | |
281 } | |
282 | |
283 if (0 != fPLSSetupProgram.fProgram) { | 284 if (0 != fPLSSetupProgram.fProgram) { |
284 GL_CALL(DeleteProgram(fPLSSetupProgram.fProgram)); | 285 GL_CALL(DeleteProgram(fPLSSetupProgram.fProgram)); |
285 } | 286 } |
286 | 287 |
287 delete fProgramCache; | 288 delete fProgramCache; |
288 } | 289 } |
289 | 290 |
291 void GrGLGpu::initGpuResources() { | |
bsalomon
2016/04/05 15:17:28
Could we eliminate the need for this deferred init
Chris Dalton
2016/04/05 17:59:15
Done.
| |
292 this->createCopyPrograms(); | |
293 | |
294 if (this->glCaps().shaderCaps()->plsPathRenderingSupport()) { | |
295 this->createPLSSetupProgram(); | |
296 } | |
297 } | |
298 | |
290 void GrGLGpu::createPLSSetupProgram() { | 299 void GrGLGpu::createPLSSetupProgram() { |
291 const GrGLSLCaps* glslCaps = this->glCaps().glslCaps(); | 300 const GrGLSLCaps* glslCaps = this->glCaps().glslCaps(); |
292 const char* version = glslCaps->versionDeclString(); | 301 const char* version = glslCaps->versionDeclString(); |
293 | 302 |
294 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute _TypeModifier); | 303 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute _TypeModifier); |
295 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, | 304 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, |
296 GrShaderVar::kUniform_TypeModifier); | 305 GrShaderVar::kUniform_TypeModifier); |
297 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, GrShaderVar::kUnifo rm_TypeModifier); | 306 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, GrShaderVar::kUnifo rm_TypeModifier); |
298 GrGLSLShaderVar uTexture("u_texture", kSampler2D_GrSLType, GrShaderVar::kUni form_TypeModifier); | 307 GrGLSLShaderVar uTexture("u_texture", kSampler2D_GrSLType, GrShaderVar::kUni form_TypeModifier); |
299 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, GrShaderVar::kVaryi ngOut_TypeModifier); | 308 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, GrShaderVar::kVaryi ngOut_TypeModifier); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 GL_CALL(LinkProgram(fPLSSetupProgram.fProgram)); | 373 GL_CALL(LinkProgram(fPLSSetupProgram.fProgram)); |
365 | 374 |
366 GL_CALL_RET(fPLSSetupProgram.fPosXformUniform, GetUniformLocation(fPLSSetupP rogram.fProgram, | 375 GL_CALL_RET(fPLSSetupProgram.fPosXformUniform, GetUniformLocation(fPLSSetupP rogram.fProgram, |
367 "u_posXform")) ; | 376 "u_posXform")) ; |
368 | 377 |
369 GL_CALL(BindAttribLocation(fPLSSetupProgram.fProgram, 0, "a_vertex")); | 378 GL_CALL(BindAttribLocation(fPLSSetupProgram.fProgram, 0, "a_vertex")); |
370 | 379 |
371 GL_CALL(DeleteShader(vshader)); | 380 GL_CALL(DeleteShader(vshader)); |
372 GL_CALL(DeleteShader(fshader)); | 381 GL_CALL(DeleteShader(fshader)); |
373 | 382 |
374 GL_CALL(GenBuffers(1, &fPLSSetupProgram.fArrayBuffer)); | 383 fPLSSetupProgram.fArrayBuffer.reset( |
375 fHWGeometryState.setVertexBufferID(this, fPLSSetupProgram.fArrayBuffer); | 384 GrGLBuffer::Create(this, 4 * 2 * sizeof(GrGLfloat), kVertex_GrBufferType , |
376 static const GrGLfloat vdata[] = { | 385 kStatic_GrAccessPattern, (const GrGLfloat[4 * 2]) { |
377 0, 0, | 386 0, 0, |
378 0, 1, | 387 0, 1, |
379 1, 0, | 388 1, 0, |
380 1, 1 | 389 1, 1 |
381 }; | 390 }) |
382 GL_ALLOC_CALL(this->glInterface(), | 391 ); |
383 BufferData(GR_GL_ARRAY_BUFFER, | |
384 (GrGLsizeiptr) sizeof(vdata), | |
385 vdata, // data ptr | |
386 GR_GL_STATIC_DRAW)); | |
387 } | 392 } |
388 | 393 |
389 void GrGLGpu::disconnect(DisconnectType type) { | 394 void GrGLGpu::disconnect(DisconnectType type) { |
390 INHERITED::disconnect(type); | 395 INHERITED::disconnect(type); |
391 if (DisconnectType::kCleanup == type) { | 396 if (DisconnectType::kCleanup == type) { |
392 if (fHWProgramID) { | 397 if (fHWProgramID) { |
393 GL_CALL(UseProgram(0)); | 398 GL_CALL(UseProgram(0)); |
394 } | 399 } |
395 if (fTempSrcFBOID) { | 400 if (fTempSrcFBOID) { |
396 GL_CALL(DeleteFramebuffers(1, &fTempSrcFBOID)); | 401 GL_CALL(DeleteFramebuffers(1, &fTempSrcFBOID)); |
397 } | 402 } |
398 if (fTempDstFBOID) { | 403 if (fTempDstFBOID) { |
399 GL_CALL(DeleteFramebuffers(1, &fTempDstFBOID)); | 404 GL_CALL(DeleteFramebuffers(1, &fTempDstFBOID)); |
400 } | 405 } |
401 if (fStencilClearFBOID) { | 406 if (fStencilClearFBOID) { |
402 GL_CALL(DeleteFramebuffers(1, &fStencilClearFBOID)); | 407 GL_CALL(DeleteFramebuffers(1, &fStencilClearFBOID)); |
403 } | 408 } |
404 if (fCopyProgramArrayBuffer) { | |
405 GL_CALL(DeleteBuffers(1, &fCopyProgramArrayBuffer)); | |
406 } | |
407 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { | 409 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { |
408 if (fCopyPrograms[i].fProgram) { | 410 if (fCopyPrograms[i].fProgram) { |
409 GL_CALL(DeleteProgram(fCopyPrograms[i].fProgram)); | 411 GL_CALL(DeleteProgram(fCopyPrograms[i].fProgram)); |
410 } | 412 } |
411 } | 413 } |
412 if (fWireRectProgram.fProgram) { | 414 if (fWireRectProgram.fProgram) { |
413 GL_CALL(DeleteProgram(fWireRectProgram.fProgram)); | 415 GL_CALL(DeleteProgram(fWireRectProgram.fProgram)); |
414 } | 416 } |
415 if (fWireRectArrayBuffer) { | |
416 GL_CALL(DeleteBuffers(1, &fWireRectArrayBuffer)); | |
417 } | |
418 | |
419 if (fPLSSetupProgram.fProgram) { | 417 if (fPLSSetupProgram.fProgram) { |
420 GL_CALL(DeleteProgram(fPLSSetupProgram.fProgram)); | 418 GL_CALL(DeleteProgram(fPLSSetupProgram.fProgram)); |
421 } | 419 } |
422 if (fPLSSetupProgram.fArrayBuffer) { | |
423 GL_CALL(DeleteBuffers(1, &fPLSSetupProgram.fArrayBuffer)); | |
424 } | |
425 } else { | 420 } else { |
426 if (fProgramCache) { | 421 if (fProgramCache) { |
427 fProgramCache->abandon(); | 422 fProgramCache->abandon(); |
428 } | 423 } |
424 if (fCopyProgramArrayBuffer) { | |
bsalomon
2016/04/05 15:17:28
We shouldn't ever call abandon outside of the cach
Chris Dalton
2016/04/05 17:59:15
Done.
| |
425 fCopyProgramArrayBuffer->abandon(); | |
426 } | |
427 if (fWireRectArrayBuffer) { | |
428 fWireRectArrayBuffer->abandon(); | |
429 } | |
430 if (fPLSSetupProgram.fArrayBuffer) { | |
431 fPLSSetupProgram.fArrayBuffer->abandon(); | |
432 } | |
429 } | 433 } |
430 | 434 |
431 delete fProgramCache; | 435 delete fProgramCache; |
432 fProgramCache = nullptr; | 436 fProgramCache = nullptr; |
433 | 437 |
434 fHWProgramID = 0; | 438 fHWProgramID = 0; |
435 fTempSrcFBOID = 0; | 439 fTempSrcFBOID = 0; |
436 fTempDstFBOID = 0; | 440 fTempDstFBOID = 0; |
437 fStencilClearFBOID = 0; | 441 fStencilClearFBOID = 0; |
438 fCopyProgramArrayBuffer = 0; | 442 fCopyProgramArrayBuffer.reset(); |
439 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { | 443 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { |
440 fCopyPrograms[i].fProgram = 0; | 444 fCopyPrograms[i].fProgram = 0; |
441 } | 445 } |
442 fWireRectProgram.fProgram = 0; | 446 fWireRectProgram.fProgram = 0; |
443 fWireRectArrayBuffer = 0; | 447 fWireRectArrayBuffer.reset(); |
444 fPLSSetupProgram.fProgram = 0; | 448 fPLSSetupProgram.fProgram = 0; |
445 fPLSSetupProgram.fArrayBuffer = 0; | 449 fPLSSetupProgram.fArrayBuffer.reset(); |
446 if (this->glCaps().shaderCaps()->pathRenderingSupport()) { | 450 if (this->glCaps().shaderCaps()->pathRenderingSupport()) { |
447 this->glPathRendering()->disconnect(type); | 451 this->glPathRendering()->disconnect(type); |
448 } | 452 } |
449 } | 453 } |
450 | 454 |
451 /////////////////////////////////////////////////////////////////////////////// | 455 /////////////////////////////////////////////////////////////////////////////// |
452 | 456 |
453 void GrGLGpu::onResetContext(uint32_t resetBits) { | 457 void GrGLGpu::onResetContext(uint32_t resetBits) { |
454 // we don't use the zb at all | 458 // we don't use the zb at all |
455 if (resetBits & kMisc_GrGLBackendState) { | 459 if (resetBits & kMisc_GrGLBackendState) { |
456 GL_CALL(Disable(GR_GL_DEPTH_TEST)); | 460 GL_CALL(Disable(GR_GL_DEPTH_TEST)); |
457 GL_CALL(DepthMask(GR_GL_FALSE)); | 461 GL_CALL(DepthMask(GR_GL_FALSE)); |
458 | 462 |
459 fHWBoundTextureBufferIDIsValid = false; | 463 fHWBufferState[kTexel_GrBufferType].invalidate(); |
460 fHWBoundDrawIndirectBufferIDIsValid = false; | 464 fHWBufferState[kDrawIndirect_GrBufferType].invalidate(); |
465 fHWBufferState[kXferCpuToGpu_GrBufferType].invalidate(); | |
466 fHWBufferState[kXferGpuToCpu_GrBufferType].invalidate(); | |
461 | 467 |
462 fHWDrawFace = GrPipelineBuilder::kInvalid_DrawFace; | 468 fHWDrawFace = GrPipelineBuilder::kInvalid_DrawFace; |
463 | 469 |
464 if (kGL_GrGLStandard == this->glStandard()) { | 470 if (kGL_GrGLStandard == this->glStandard()) { |
465 // Desktop-only state that we never change | 471 // Desktop-only state that we never change |
466 if (!this->glCaps().isCoreProfile()) { | 472 if (!this->glCaps().isCoreProfile()) { |
467 GL_CALL(Disable(GR_GL_POINT_SMOOTH)); | 473 GL_CALL(Disable(GR_GL_POINT_SMOOTH)); |
468 GL_CALL(Disable(GR_GL_LINE_SMOOTH)); | 474 GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
469 GL_CALL(Disable(GR_GL_POLYGON_SMOOTH)); | 475 GL_CALL(Disable(GR_GL_POLYGON_SMOOTH)); |
470 GL_CALL(Disable(GR_GL_POLYGON_STIPPLE)); | 476 GL_CALL(Disable(GR_GL_POLYGON_STIPPLE)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 fHWViewport.invalidate(); | 537 fHWViewport.invalidate(); |
532 } | 538 } |
533 | 539 |
534 if (resetBits & kStencil_GrGLBackendState) { | 540 if (resetBits & kStencil_GrGLBackendState) { |
535 fHWStencilSettings.invalidate(); | 541 fHWStencilSettings.invalidate(); |
536 fHWStencilTestEnabled = kUnknown_TriState; | 542 fHWStencilTestEnabled = kUnknown_TriState; |
537 } | 543 } |
538 | 544 |
539 // Vertex | 545 // Vertex |
540 if (resetBits & kVertex_GrGLBackendState) { | 546 if (resetBits & kVertex_GrGLBackendState) { |
541 fHWGeometryState.invalidate(); | 547 fHWVertexArrayState.invalidate(); |
548 fHWBufferState[kVertex_GrBufferType].invalidate(); | |
549 fHWBufferState[kIndex_GrBufferType].invalidate(); | |
542 } | 550 } |
543 | 551 |
544 if (resetBits & kRenderTarget_GrGLBackendState) { | 552 if (resetBits & kRenderTarget_GrGLBackendState) { |
545 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 553 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
546 fHWSRGBFramebuffer = kUnknown_TriState; | 554 fHWSRGBFramebuffer = kUnknown_TriState; |
547 } | 555 } |
548 | 556 |
549 if (resetBits & kPathRendering_GrGLBackendState) { | 557 if (resetBits & kPathRendering_GrGLBackendState) { |
550 if (this->caps()->shaderCaps()->pathRenderingSupport()) { | 558 if (this->caps()->shaderCaps()->pathRenderingSupport()) { |
551 this->glPathRendering()->resetContext(); | 559 this->glPathRendering()->resetContext(); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 } | 901 } |
894 | 902 |
895 // For the moment, can't transfer compressed data | 903 // For the moment, can't transfer compressed data |
896 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { | 904 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { |
897 return false; | 905 return false; |
898 } | 906 } |
899 | 907 |
900 this->setScratchTextureUnit(); | 908 this->setScratchTextureUnit(); |
901 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); | 909 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); |
902 | 910 |
903 SkASSERT(kXferCpuToGpu_GrBufferType == transferBuffer->type()); | |
904 SkASSERT(!transferBuffer->isMapped()); | 911 SkASSERT(!transferBuffer->isMapped()); |
905 SkASSERT(!transferBuffer->isCPUBacked()); | 912 SkASSERT(!transferBuffer->isCPUBacked()); |
906 const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer); | 913 const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer); |
907 this->bindBuffer(glBuffer->bufferID(), glBuffer->target()); | 914 this->bindBuffer(kXferCpuToGpu_GrBufferType, glBuffer); |
908 | 915 |
909 bool success = false; | 916 bool success = false; |
910 GrMipLevel mipLevel; | 917 GrMipLevel mipLevel; |
911 mipLevel.fPixels = transferBuffer; | 918 mipLevel.fPixels = transferBuffer; |
912 mipLevel.fRowBytes = rowBytes; | 919 mipLevel.fRowBytes = rowBytes; |
913 SkSTArray<1, GrMipLevel> texels; | 920 SkSTArray<1, GrMipLevel> texels; |
914 texels.push_back(mipLevel); | 921 texels.push_back(mipLevel); |
915 success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_Uplo adType, | 922 success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_Uplo adType, |
916 left, top, width, height, config, texels); | 923 left, top, width, height, config, texels); |
917 if (success) { | 924 if (success) { |
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1967 format); | 1974 format); |
1968 return stencil; | 1975 return stencil; |
1969 } | 1976 } |
1970 | 1977 |
1971 //////////////////////////////////////////////////////////////////////////////// | 1978 //////////////////////////////////////////////////////////////////////////////// |
1972 | 1979 |
1973 // GL_STREAM_DRAW triggers an optimization in Chromium's GPU process where a cli ent's vertex buffer | 1980 // GL_STREAM_DRAW triggers an optimization in Chromium's GPU process where a cli ent's vertex buffer |
1974 // objects are implemented as client-side-arrays on tile-deferred architectures. | 1981 // objects are implemented as client-side-arrays on tile-deferred architectures. |
1975 #define DYNAMIC_USAGE_PARAM GR_GL_STREAM_DRAW | 1982 #define DYNAMIC_USAGE_PARAM GR_GL_STREAM_DRAW |
1976 | 1983 |
1977 GrBuffer* GrGLGpu::onCreateBuffer(GrBufferType type, size_t size, GrAccessPatter n accessPattern) { | 1984 GrBuffer* GrGLGpu::onCreateBuffer(size_t size, GrBufferType intendedType, |
1978 return GrGLBuffer::Create(this, type, size, accessPattern); | 1985 GrAccessPattern accessPattern) { |
1986 return GrGLBuffer::Create(this, size, intendedType, accessPattern); | |
1979 } | 1987 } |
1980 | 1988 |
1981 void GrGLGpu::flushScissor(const GrScissorState& scissorState, | 1989 void GrGLGpu::flushScissor(const GrScissorState& scissorState, |
1982 const GrGLIRect& rtViewport, | 1990 const GrGLIRect& rtViewport, |
1983 GrSurfaceOrigin rtOrigin) { | 1991 GrSurfaceOrigin rtOrigin) { |
1984 if (scissorState.enabled()) { | 1992 if (scissorState.enabled()) { |
1985 GrGLIRect scissor; | 1993 GrGLIRect scissor; |
1986 scissor.setRelativeTo(rtViewport, | 1994 scissor.setRelativeTo(rtViewport, |
1987 scissorState.rect().fLeft, | 1995 scissorState.rect().fLeft, |
1988 scissorState.rect().fTop, | 1996 scissorState.rect().fTop, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2072 } | 2080 } |
2073 | 2081 |
2074 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, | 2082 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, |
2075 const GrNonInstancedMesh& mesh, | 2083 const GrNonInstancedMesh& mesh, |
2076 size_t* indexOffsetInBytes) { | 2084 size_t* indexOffsetInBytes) { |
2077 const GrGLBuffer* vbuf; | 2085 const GrGLBuffer* vbuf; |
2078 vbuf = static_cast<const GrGLBuffer*>(mesh.vertexBuffer()); | 2086 vbuf = static_cast<const GrGLBuffer*>(mesh.vertexBuffer()); |
2079 | 2087 |
2080 SkASSERT(vbuf); | 2088 SkASSERT(vbuf); |
2081 SkASSERT(!vbuf->isMapped()); | 2089 SkASSERT(!vbuf->isMapped()); |
2082 SkASSERT(kVertex_GrBufferType == vbuf->type()); | |
2083 | 2090 |
2084 const GrGLBuffer* ibuf = nullptr; | 2091 GrGLAttribArrayState* attribState; |
2085 if (mesh.isIndexed()) { | 2092 if (mesh.isIndexed()) { |
2086 SkASSERT(indexOffsetInBytes); | 2093 SkASSERT(indexOffsetInBytes); |
2087 | 2094 |
2088 *indexOffsetInBytes = 0; | 2095 *indexOffsetInBytes = 0; |
2089 ibuf = static_cast<const GrGLBuffer*>(mesh.indexBuffer()); | 2096 const GrGLBuffer* ibuf = static_cast<const GrGLBuffer*>(mesh.indexBuffer ()); |
2090 | 2097 |
2091 SkASSERT(ibuf); | 2098 SkASSERT(ibuf); |
2092 SkASSERT(!ibuf->isMapped()); | 2099 SkASSERT(!ibuf->isMapped()); |
2093 SkASSERT(kIndex_GrBufferType == ibuf->type()); | |
2094 *indexOffsetInBytes += ibuf->baseOffset(); | 2100 *indexOffsetInBytes += ibuf->baseOffset(); |
2101 attribState = fHWVertexArrayState.bindInternalVertexArray(this, ibuf); | |
2102 } else { | |
2103 attribState = fHWVertexArrayState.bindInternalVertexArray(this); | |
2095 } | 2104 } |
2096 GrGLAttribArrayState* attribState = | |
2097 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); | |
2098 | 2105 |
2099 int vaCount = primProc.numAttribs(); | 2106 int vaCount = primProc.numAttribs(); |
2100 if (vaCount > 0) { | 2107 if (vaCount > 0) { |
2101 | 2108 |
2102 GrGLsizei stride = static_cast<GrGLsizei>(primProc.getVertexStride()); | 2109 GrGLsizei stride = static_cast<GrGLsizei>(primProc.getVertexStride()); |
2103 | 2110 |
2104 size_t vertexOffsetInBytes = stride * mesh.startVertex(); | 2111 size_t vertexOffsetInBytes = stride * mesh.startVertex(); |
2105 | 2112 |
2106 vertexOffsetInBytes += vbuf->baseOffset(); | 2113 vertexOffsetInBytes += vbuf->baseOffset(); |
2107 | 2114 |
2108 uint32_t usedAttribArraysMask = 0; | 2115 uint32_t usedAttribArraysMask = 0; |
2109 size_t offset = 0; | 2116 size_t offset = 0; |
2110 | 2117 |
2111 for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) { | 2118 for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) { |
2112 const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(at tribIndex); | 2119 const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(at tribIndex); |
2113 usedAttribArraysMask |= (1 << attribIndex); | 2120 usedAttribArraysMask |= (1 << attribIndex); |
2114 GrVertexAttribType attribType = attrib.fType; | 2121 GrVertexAttribType attribType = attrib.fType; |
2115 attribState->set(this, | 2122 attribState->set(this, |
2116 attribIndex, | 2123 attribIndex, |
2117 vbuf->bufferID(), | 2124 vbuf, |
2118 attribType, | 2125 attribType, |
2119 stride, | 2126 stride, |
2120 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o ffset)); | 2127 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o ffset)); |
2121 offset += attrib.fOffset; | 2128 offset += attrib.fOffset; |
2122 } | 2129 } |
2123 attribState->disableUnusedArrays(this, usedAttribArraysMask); | 2130 attribState->disableUnusedArrays(this, usedAttribArraysMask); |
2124 } | 2131 } |
2125 } | 2132 } |
2126 | 2133 |
2127 void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) { | 2134 GrGLenum GrGLGpu::bindBuffer(GrBufferType type, const GrGLBuffer* buffer) { |
2128 this->handleDirtyContext(); | 2135 this->handleDirtyContext(); |
2129 switch (type) { | 2136 |
2130 case GR_GL_ARRAY_BUFFER: | 2137 // Index buffer state is tied to the vertex array. |
2131 this->bindVertexBuffer(id); | 2138 if (kIndex_GrBufferType == type) { |
2132 break; | 2139 this->bindVertexArray(0); |
2133 case GR_GL_ELEMENT_ARRAY_BUFFER: | |
2134 this->bindIndexBufferAndDefaultVertexArray(id); | |
2135 break; | |
2136 case GR_GL_TEXTURE_BUFFER: | |
2137 if (!fHWBoundTextureBufferIDIsValid || id != fHWBoundTextureBufferID ) { | |
2138 GR_GL_CALL(this->glInterface(), BindBuffer(type, id)); | |
2139 fHWBoundTextureBufferID = id; | |
2140 fHWBoundTextureBufferIDIsValid = true; | |
2141 } | |
2142 break; | |
2143 case GR_GL_DRAW_INDIRECT_BUFFER: | |
2144 if (!fHWBoundDrawIndirectBufferIDIsValid || id != fHWBoundDrawIndire ctBufferID) { | |
2145 GR_GL_CALL(this->glInterface(), BindBuffer(type, id)); | |
2146 fHWBoundDrawIndirectBufferID = id; | |
2147 fHWBoundDrawIndirectBufferIDIsValid = true; | |
2148 } | |
2149 break; | |
2150 default: | |
2151 SkDebugf("WARNING: buffer target 0x%x is not tracked by GrGLGpu.\n", type); | |
2152 GR_GL_CALL(this->glInterface(), BindBuffer(type, id)); | |
2153 break; | |
2154 } | 2140 } |
2155 } | |
2156 | 2141 |
2157 void GrGLGpu::releaseBuffer(GrGLuint id, GrGLenum type) { | 2142 SkASSERT(type >= 0 && type <= kLast_GrBufferType); |
2158 this->handleDirtyContext(); | 2143 auto& bufferState = fHWBufferState[type]; |
2159 GL_CALL(DeleteBuffers(1, &id)); | 2144 |
2160 switch (type) { | 2145 if (buffer->getUniqueID() != bufferState.fBoundBufferUniqueID) { |
2161 case GR_GL_ARRAY_BUFFER: | 2146 if (!buffer->isCPUBacked() || !bufferState.fBufferZeroKnownBound) { |
2162 this->notifyVertexBufferDelete(id); | 2147 GL_CALL(BindBuffer(bufferState.fGLTarget, buffer->bufferID())); |
2163 break; | 2148 bufferState.fBufferZeroKnownBound = buffer->isCPUBacked(); |
2164 case GR_GL_ELEMENT_ARRAY_BUFFER: | 2149 } |
2165 this->notifyIndexBufferDelete(id); | 2150 bufferState.fBoundBufferUniqueID = buffer->getUniqueID(); |
2166 break; | |
2167 case GR_GL_TEXTURE_BUFFER: | |
2168 if (fHWBoundTextureBufferIDIsValid && id == fHWBoundTextureBufferID) { | |
2169 fHWBoundTextureBufferID = 0; | |
2170 } | |
2171 break; | |
2172 case GR_GL_DRAW_INDIRECT_BUFFER: | |
2173 if (fHWBoundDrawIndirectBufferIDIsValid && id == fHWBoundDrawIndirec tBufferID) { | |
2174 fHWBoundDrawIndirectBufferID = 0; | |
2175 } | |
2176 break; | |
2177 } | 2151 } |
2152 | |
2153 return bufferState.fGLTarget; | |
2178 } | 2154 } |
2179 | 2155 |
2180 void GrGLGpu::disableScissor() { | 2156 void GrGLGpu::disableScissor() { |
2181 if (kNo_TriState != fHWScissorSettings.fEnabled) { | 2157 if (kNo_TriState != fHWScissorSettings.fEnabled) { |
2182 GL_CALL(Disable(GR_GL_SCISSOR_TEST)); | 2158 GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
2183 fHWScissorSettings.fEnabled = kNo_TriState; | 2159 fHWScissorSettings.fEnabled = kNo_TriState; |
2184 return; | 2160 return; |
2185 } | 2161 } |
2186 } | 2162 } |
2187 | 2163 |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2837 aglSwapBuffers(aglGetCurrentContext()); | 2813 aglSwapBuffers(aglGetCurrentContext()); |
2838 #elif defined(SK_BUILD_FOR_WIN32) | 2814 #elif defined(SK_BUILD_FOR_WIN32) |
2839 SwapBuf(); | 2815 SwapBuf(); |
2840 int set_a_break_pt_here = 9; | 2816 int set_a_break_pt_here = 9; |
2841 SwapBuf(); | 2817 SwapBuf(); |
2842 #endif | 2818 #endif |
2843 #endif | 2819 #endif |
2844 } | 2820 } |
2845 | 2821 |
2846 void GrGLGpu::stampRectUsingProgram(GrGLuint program, const SkRect& bounds, GrGL int posXformUniform, | 2822 void GrGLGpu::stampRectUsingProgram(GrGLuint program, const SkRect& bounds, GrGL int posXformUniform, |
2847 GrGLuint arrayBuffer) { | 2823 const GrGLBuffer* arrayBuffer) { |
2848 GL_CALL(UseProgram(program)); | 2824 GL_CALL(UseProgram(program)); |
2849 this->fHWGeometryState.setVertexArrayID(this, 0); | 2825 this->fHWVertexArrayState.setVertexArrayID(this, 0); |
2850 | 2826 |
2851 GrGLAttribArrayState* attribs = | 2827 GrGLAttribArrayState* attribs = this->fHWVertexArrayState.bindInternalVertex Array(this); |
2852 this->fHWGeometryState.bindArrayAndBufferToDraw(this, arrayBuffer); | |
2853 attribs->set(this, 0, arrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrG Lfloat), 0); | 2828 attribs->set(this, 0, arrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrG Lfloat), 0); |
2854 attribs->disableUnusedArrays(this, 0x1); | 2829 attribs->disableUnusedArrays(this, 0x1); |
2855 | 2830 |
2856 GL_CALL(Uniform4f(posXformUniform, bounds.width(), bounds.height(), bounds.l eft(), | 2831 GL_CALL(Uniform4f(posXformUniform, bounds.width(), bounds.height(), bounds.l eft(), |
2857 bounds.top())); | 2832 bounds.top())); |
2858 | 2833 |
2859 GrXferProcessor::BlendInfo blendInfo; | 2834 GrXferProcessor::BlendInfo blendInfo; |
2860 blendInfo.reset(); | 2835 blendInfo.reset(); |
2861 this->flushBlend(blendInfo, GrSwizzle()); | 2836 this->flushBlend(blendInfo, GrSwizzle()); |
2862 this->flushColorWrite(true); | 2837 this->flushColorWrite(true); |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3698 GL_CALL_RET(fCopyPrograms[i].fPosXformUniform, | 3673 GL_CALL_RET(fCopyPrograms[i].fPosXformUniform, |
3699 GetUniformLocation(fCopyPrograms[i].fProgram, "u_posXform")) ; | 3674 GetUniformLocation(fCopyPrograms[i].fProgram, "u_posXform")) ; |
3700 GL_CALL_RET(fCopyPrograms[i].fTexCoordXformUniform, | 3675 GL_CALL_RET(fCopyPrograms[i].fTexCoordXformUniform, |
3701 GetUniformLocation(fCopyPrograms[i].fProgram, "u_texCoordXfo rm")); | 3676 GetUniformLocation(fCopyPrograms[i].fProgram, "u_texCoordXfo rm")); |
3702 | 3677 |
3703 GL_CALL(BindAttribLocation(fCopyPrograms[i].fProgram, 0, "a_vertex")); | 3678 GL_CALL(BindAttribLocation(fCopyPrograms[i].fProgram, 0, "a_vertex")); |
3704 | 3679 |
3705 GL_CALL(DeleteShader(vshader)); | 3680 GL_CALL(DeleteShader(vshader)); |
3706 GL_CALL(DeleteShader(fshader)); | 3681 GL_CALL(DeleteShader(fshader)); |
3707 } | 3682 } |
3708 fCopyProgramArrayBuffer = 0; | 3683 fCopyProgramArrayBuffer.reset( |
3709 GL_CALL(GenBuffers(1, &fCopyProgramArrayBuffer)); | 3684 GrGLBuffer::Create(this, 4 * 2 * sizeof(GrGLfloat), kVertex_GrBufferType , |
3710 fHWGeometryState.setVertexBufferID(this, fCopyProgramArrayBuffer); | 3685 kStatic_GrAccessPattern, (const GrGLfloat[4 * 2]) { |
3711 static const GrGLfloat vdata[] = { | 3686 0, 0, |
3712 0, 0, | 3687 0, 1, |
3713 0, 1, | 3688 1, 0, |
3714 1, 0, | 3689 1, 1 |
3715 1, 1 | 3690 }) |
3716 }; | 3691 ); |
3717 GL_ALLOC_CALL(this->glInterface(), | |
3718 BufferData(GR_GL_ARRAY_BUFFER, | |
3719 (GrGLsizeiptr) sizeof(vdata), | |
3720 vdata, // data ptr | |
3721 GR_GL_STATIC_DRAW)); | |
3722 } | 3692 } |
3723 | 3693 |
3724 void GrGLGpu::createWireRectProgram() { | 3694 void GrGLGpu::createWireRectProgram() { |
3725 SkASSERT(!fWireRectProgram.fProgram); | 3695 SkASSERT(!fWireRectProgram.fProgram); |
3726 GrGLSLShaderVar uColor("u_color", kVec4f_GrSLType, GrShaderVar::kUniform_Typ eModifier); | 3696 GrGLSLShaderVar uColor("u_color", kVec4f_GrSLType, GrShaderVar::kUniform_Typ eModifier); |
3727 GrGLSLShaderVar uRect("u_rect", kVec4f_GrSLType, GrShaderVar::kUniform_TypeM odifier); | 3697 GrGLSLShaderVar uRect("u_rect", kVec4f_GrSLType, GrShaderVar::kUniform_TypeM odifier); |
3728 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute _TypeModifier); | 3698 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute _TypeModifier); |
3729 const char* version = this->glCaps().glslCaps()->versionDeclString(); | 3699 const char* version = this->glCaps().glslCaps()->versionDeclString(); |
3730 | 3700 |
3731 // The rect uniform specifies the rectangle in NDC space as a vec4 (left,top ,right,bottom). The | 3701 // The rect uniform specifies the rectangle in NDC space as a vec4 (left,top ,right,bottom). The |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3789 GL_CALL(LinkProgram(fWireRectProgram.fProgram)); | 3759 GL_CALL(LinkProgram(fWireRectProgram.fProgram)); |
3790 | 3760 |
3791 GL_CALL_RET(fWireRectProgram.fColorUniform, | 3761 GL_CALL_RET(fWireRectProgram.fColorUniform, |
3792 GetUniformLocation(fWireRectProgram.fProgram, "u_color")); | 3762 GetUniformLocation(fWireRectProgram.fProgram, "u_color")); |
3793 GL_CALL_RET(fWireRectProgram.fRectUniform, | 3763 GL_CALL_RET(fWireRectProgram.fRectUniform, |
3794 GetUniformLocation(fWireRectProgram.fProgram, "u_rect")); | 3764 GetUniformLocation(fWireRectProgram.fProgram, "u_rect")); |
3795 GL_CALL(BindAttribLocation(fWireRectProgram.fProgram, 0, "a_vertex")); | 3765 GL_CALL(BindAttribLocation(fWireRectProgram.fProgram, 0, "a_vertex")); |
3796 | 3766 |
3797 GL_CALL(DeleteShader(vshader)); | 3767 GL_CALL(DeleteShader(vshader)); |
3798 GL_CALL(DeleteShader(fshader)); | 3768 GL_CALL(DeleteShader(fshader)); |
3799 GL_CALL(GenBuffers(1, &fWireRectArrayBuffer)); | 3769 fWireRectArrayBuffer.reset( |
3800 fHWGeometryState.setVertexBufferID(this, fWireRectArrayBuffer); | 3770 GrGLBuffer::Create(this, 4 * 2 * sizeof(GrGLfloat), kVertex_GrBufferType , |
3801 static const GrGLfloat vdata[] = { | 3771 kStatic_GrAccessPattern, (const GrGLfloat[4 * 2]) { |
3802 0, 0, | 3772 0, 0, |
3803 0, 1, | 3773 0, 1, |
3804 1, 1, | 3774 1, 1, |
3805 1, 0, | 3775 1, 0 |
3806 }; | 3776 }) |
3807 GL_ALLOC_CALL(this->glInterface(), | 3777 ); |
3808 BufferData(GR_GL_ARRAY_BUFFER, | |
3809 (GrGLsizeiptr) sizeof(vdata), | |
3810 vdata, // data ptr | |
3811 GR_GL_STATIC_DRAW)); | |
3812 } | 3778 } |
3813 | 3779 |
3814 void GrGLGpu::drawDebugWireRect(GrRenderTarget* rt, const SkIRect& rect, GrColor color) { | 3780 void GrGLGpu::drawDebugWireRect(GrRenderTarget* rt, const SkIRect& rect, GrColor color) { |
3815 // TODO: This should swizzle the output to match dst's config, though it is a debugging | 3781 // TODO: This should swizzle the output to match dst's config, though it is a debugging |
3816 // visualization. | 3782 // visualization. |
3817 | 3783 |
3818 this->handleDirtyContext(); | 3784 this->handleDirtyContext(); |
3819 if (!fWireRectProgram.fProgram) { | 3785 if (!fWireRectProgram.fProgram) { |
3820 this->createWireRectProgram(); | 3786 this->createWireRectProgram(); |
3821 } | 3787 } |
(...skipping 24 matching lines...) Expand all Loading... | |
3846 channels[1] = GrColorUnpackG(color) * scale255; | 3812 channels[1] = GrColorUnpackG(color) * scale255; |
3847 channels[2] = GrColorUnpackB(color) * scale255; | 3813 channels[2] = GrColorUnpackB(color) * scale255; |
3848 channels[3] = GrColorUnpackA(color) * scale255; | 3814 channels[3] = GrColorUnpackA(color) * scale255; |
3849 | 3815 |
3850 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(rt->asRenderTarget() ); | 3816 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(rt->asRenderTarget() ); |
3851 this->flushRenderTarget(glRT, &rect); | 3817 this->flushRenderTarget(glRT, &rect); |
3852 | 3818 |
3853 GL_CALL(UseProgram(fWireRectProgram.fProgram)); | 3819 GL_CALL(UseProgram(fWireRectProgram.fProgram)); |
3854 fHWProgramID = fWireRectProgram.fProgram; | 3820 fHWProgramID = fWireRectProgram.fProgram; |
3855 | 3821 |
3856 fHWGeometryState.setVertexArrayID(this, 0); | 3822 fHWVertexArrayState.setVertexArrayID(this, 0); |
3857 | 3823 |
3858 GrGLAttribArrayState* attribs = | 3824 GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray( this); |
3859 fHWGeometryState.bindArrayAndBufferToDraw(this, fWireRectArrayBuffer); | |
3860 attribs->set(this, 0, fWireRectArrayBuffer, kVec2f_GrVertexAttribType, 2 * s izeof(GrGLfloat), | 3825 attribs->set(this, 0, fWireRectArrayBuffer, kVec2f_GrVertexAttribType, 2 * s izeof(GrGLfloat), |
3861 0); | 3826 0); |
3862 attribs->disableUnusedArrays(this, 0x1); | 3827 attribs->disableUnusedArrays(this, 0x1); |
3863 | 3828 |
3864 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges)); | 3829 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges)); |
3865 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels)); | 3830 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels)); |
3866 | 3831 |
3867 GrXferProcessor::BlendInfo blendInfo; | 3832 GrXferProcessor::BlendInfo blendInfo; |
3868 blendInfo.reset(); | 3833 blendInfo.reset(); |
3869 this->flushBlend(blendInfo, GrSwizzle::RGBA()); | 3834 this->flushBlend(blendInfo, GrSwizzle::RGBA()); |
(...skipping 25 matching lines...) Expand all Loading... | |
3895 this->flushViewport(dstVP); | 3860 this->flushViewport(dstVP); |
3896 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 3861 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
3897 | 3862 |
3898 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, w, h); | 3863 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, w, h); |
3899 | 3864 |
3900 int progIdx = TextureTargetToCopyProgramIdx(srcTex->target()); | 3865 int progIdx = TextureTargetToCopyProgramIdx(srcTex->target()); |
3901 | 3866 |
3902 GL_CALL(UseProgram(fCopyPrograms[progIdx].fProgram)); | 3867 GL_CALL(UseProgram(fCopyPrograms[progIdx].fProgram)); |
3903 fHWProgramID = fCopyPrograms[progIdx].fProgram; | 3868 fHWProgramID = fCopyPrograms[progIdx].fProgram; |
3904 | 3869 |
3905 fHWGeometryState.setVertexArrayID(this, 0); | 3870 fHWVertexArrayState.setVertexArrayID(this, 0); |
3906 | 3871 |
3907 GrGLAttribArrayState* attribs = | 3872 GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray( this); |
3908 fHWGeometryState.bindArrayAndBufferToDraw(this, fCopyProgramArrayBuffer) ; | |
3909 attribs->set(this, 0, fCopyProgramArrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrGLfloat), | 3873 attribs->set(this, 0, fCopyProgramArrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrGLfloat), |
3910 0); | 3874 0); |
3911 attribs->disableUnusedArrays(this, 0x1); | 3875 attribs->disableUnusedArrays(this, 0x1); |
3912 | 3876 |
3913 // dst rect edges in NDC (-1 to 1) | 3877 // dst rect edges in NDC (-1 to 1) |
3914 int dw = dst->width(); | 3878 int dw = dst->width(); |
3915 int dh = dst->height(); | 3879 int dh = dst->height(); |
3916 GrGLfloat dx0 = 2.f * dstPoint.fX / dw - 1.f; | 3880 GrGLfloat dx0 = 2.f * dstPoint.fX / dw - 1.f; |
3917 GrGLfloat dx1 = 2.f * (dstPoint.fX + w) / dw - 1.f; | 3881 GrGLfloat dx1 = 2.f * (dstPoint.fX + w) / dw - 1.f; |
3918 GrGLfloat dy0 = 2.f * dstPoint.fY / dh - 1.f; | 3882 GrGLfloat dy0 = 2.f * dstPoint.fY / dh - 1.f; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4191 #ifndef SK_IGNORE_GL_TEXTURE_TARGET | 4155 #ifndef SK_IGNORE_GL_TEXTURE_TARGET |
4192 delete info; | 4156 delete info; |
4193 #endif | 4157 #endif |
4194 } | 4158 } |
4195 | 4159 |
4196 void GrGLGpu::resetShaderCacheForTesting() const { | 4160 void GrGLGpu::resetShaderCacheForTesting() const { |
4197 fProgramCache->abandon(); | 4161 fProgramCache->abandon(); |
4198 } | 4162 } |
4199 | 4163 |
4200 /////////////////////////////////////////////////////////////////////////////// | 4164 /////////////////////////////////////////////////////////////////////////////// |
4201 GrGLAttribArrayState* GrGLGpu::HWGeometryState::bindArrayAndBuffersToDraw( | |
4202 GrGLGpu* gpu, | |
4203 const GrGLBuffer* vbuffer, | |
4204 const GrGLBuffer* ibuffer) { | |
4205 SkASSERT(vbuffer); | |
4206 GrGLuint vbufferID = vbuffer->bufferID(); | |
4207 GrGLuint* ibufferIDPtr = nullptr; | |
4208 GrGLuint ibufferID; | |
4209 if (ibuffer) { | |
4210 ibufferID = ibuffer->bufferID(); | |
4211 ibufferIDPtr = &ibufferID; | |
4212 } | |
4213 return this->internalBind(gpu, vbufferID, ibufferIDPtr); | |
4214 } | |
4215 | 4165 |
4216 GrGLAttribArrayState* GrGLGpu::HWGeometryState::bindArrayAndBufferToDraw(GrGLGpu * gpu, | 4166 GrGLAttribArrayState* GrGLGpu::HWVertexArrayState::bindInternalVertexArray(GrGLG pu* gpu, |
4217 GrGLuin t vbufferID) { | 4167 const GrGLBuffer* ibuf) { |
4218 return this->internalBind(gpu, vbufferID, nullptr); | |
4219 } | |
4220 | |
4221 GrGLAttribArrayState* GrGLGpu::HWGeometryState::bindArrayAndBuffersToDraw(GrGLGp u* gpu, | |
4222 GrGLui nt vbufferID, | |
4223 GrGLui nt ibufferID) { | |
4224 return this->internalBind(gpu, vbufferID, &ibufferID); | |
4225 } | |
4226 | |
4227 GrGLAttribArrayState* GrGLGpu::HWGeometryState::internalBind(GrGLGpu* gpu, | |
4228 GrGLuint vbufferID, | |
4229 GrGLuint* ibufferID ) { | |
4230 GrGLAttribArrayState* attribState; | 4168 GrGLAttribArrayState* attribState; |
4231 | 4169 |
4232 if (gpu->glCaps().isCoreProfile() && 0 != vbufferID) { | 4170 if (gpu->glCaps().isCoreProfile()) { |
4233 if (!fVBOVertexArray) { | 4171 if (!fCoreProfileVertexArray) { |
4234 GrGLuint arrayID; | 4172 GrGLuint arrayID; |
4235 GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID)); | 4173 GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID)); |
4236 int attrCount = gpu->glCaps().maxVertexAttributes(); | 4174 int attrCount = gpu->glCaps().maxVertexAttributes(); |
4237 fVBOVertexArray = new GrGLVertexArray(arrayID, attrCount); | 4175 fCoreProfileVertexArray = new GrGLVertexArray(arrayID, attrCount); |
4238 } | 4176 } |
4239 if (ibufferID) { | 4177 if (ibuf) { |
4240 attribState = fVBOVertexArray->bindWithIndexBuffer(gpu, *ibufferID); | 4178 attribState = fCoreProfileVertexArray->bindWithIndexBuffer(gpu, ibuf ); |
4241 } else { | 4179 } else { |
4242 attribState = fVBOVertexArray->bind(gpu); | 4180 attribState = fCoreProfileVertexArray->bind(gpu); |
4243 } | 4181 } |
4244 } else { | 4182 } else { |
4245 if (ibufferID) { | 4183 if (ibuf) { |
4246 this->setIndexBufferIDOnDefaultVertexArray(gpu, *ibufferID); | 4184 // bindBuffer implicitly binds VAO 0 when binding an index buffer. |
4185 gpu->bindBuffer(kIndex_GrBufferType, ibuf); | |
4247 } else { | 4186 } else { |
4248 this->setVertexArrayID(gpu, 0); | 4187 this->setVertexArrayID(gpu, 0); |
4249 } | 4188 } |
4250 int attrCount = gpu->glCaps().maxVertexAttributes(); | 4189 int attrCount = gpu->glCaps().maxVertexAttributes(); |
4251 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 4190 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
4252 fDefaultVertexArrayAttribState.resize(attrCount); | 4191 fDefaultVertexArrayAttribState.resize(attrCount); |
4253 } | 4192 } |
4254 attribState = &fDefaultVertexArrayAttribState; | 4193 attribState = &fDefaultVertexArrayAttribState; |
4255 } | 4194 } |
4256 return attribState; | 4195 return attribState; |
4257 } | 4196 } |
4258 | 4197 |
4259 bool GrGLGpu::onMakeCopyForTextureParams(GrTexture* texture, const GrTexturePara ms& textureParams, | 4198 bool GrGLGpu::onMakeCopyForTextureParams(GrTexture* texture, const GrTexturePara ms& textureParams, |
4260 GrTextureProducer::CopyParams* copyPara ms) const { | 4199 GrTextureProducer::CopyParams* copyPara ms) const { |
4261 if (textureParams.isTiled() || | 4200 if (textureParams.isTiled() || |
4262 GrTextureParams::kMipMap_FilterMode == textureParams.filterMode()) { | 4201 GrTextureParams::kMipMap_FilterMode == textureParams.filterMode()) { |
4263 GrGLTexture* glTexture = static_cast<GrGLTexture*>(texture); | 4202 GrGLTexture* glTexture = static_cast<GrGLTexture*>(texture); |
4264 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 4203 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
4265 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 4204 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
4266 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 4205 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
4267 copyParams->fWidth = texture->width(); | 4206 copyParams->fWidth = texture->width(); |
4268 copyParams->fHeight = texture->height(); | 4207 copyParams->fHeight = texture->height(); |
4269 return true; | 4208 return true; |
4270 } | 4209 } |
4271 } | 4210 } |
4272 return false; | 4211 return false; |
4273 } | 4212 } |
OLD | NEW |