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

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

Issue 1854283004: Track GL buffer state based on unique resource ID (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix for GR_GL_USE_BUFFER_DATA_NULL_HINT=0 Created 4 years, 8 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
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLVertexArray.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * 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
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 may requir e a working GrGLGpu
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();
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
290 void GrGLGpu::createPLSSetupProgram() { 291 bool GrGLGpu::createPLSSetupProgram() {
292 if (!fPLSSetupProgram.fArrayBuffer) {
293 static const GrGLfloat vdata[] = {
294 0, 0,
295 0, 1,
296 1, 0,
297 1, 1
298 };
299 fPLSSetupProgram.fArrayBuffer.reset(GrGLBuffer::Create(this, sizeof(vdat a),
300 kVertex_GrBufferT ype,
301 kStatic_GrAccessP attern, vdata));
302 if (!fPLSSetupProgram.fArrayBuffer) {
303 return false;
304 }
305 }
306
307 SkASSERT(!fPLSSetupProgram.fProgram);
308 GL_CALL_RET(fPLSSetupProgram.fProgram, CreateProgram());
309 if (!fPLSSetupProgram.fProgram) {
310 return false;
311 }
312
291 const GrGLSLCaps* glslCaps = this->glCaps().glslCaps(); 313 const GrGLSLCaps* glslCaps = this->glCaps().glslCaps();
292 const char* version = glslCaps->versionDeclString(); 314 const char* version = glslCaps->versionDeclString();
293 315
294 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute _TypeModifier); 316 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute _TypeModifier);
295 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, 317 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType,
296 GrShaderVar::kUniform_TypeModifier); 318 GrShaderVar::kUniform_TypeModifier);
297 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, GrShaderVar::kUnifo rm_TypeModifier); 319 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, GrShaderVar::kUnifo rm_TypeModifier);
298 GrGLSLShaderVar uTexture("u_texture", kSampler2D_GrSLType, GrShaderVar::kUni form_TypeModifier); 320 GrGLSLShaderVar uTexture("u_texture", kSampler2D_GrSLType, GrShaderVar::kUni form_TypeModifier);
299 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, GrShaderVar::kVaryi ngOut_TypeModifier); 321 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, GrShaderVar::kVaryi ngOut_TypeModifier);
300 322
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 fshaderTxt.append(";"); 362 fshaderTxt.append(";");
341 363
342 fshaderTxt.appendf( 364 fshaderTxt.appendf(
343 "// PLS Setup Program FS\n" 365 "// PLS Setup Program FS\n"
344 GR_GL_PLS_PATH_DATA_DECL 366 GR_GL_PLS_PATH_DATA_DECL
345 "void main() {\n" 367 "void main() {\n"
346 " " GR_GL_PLS_DSTCOLOR_NAME " = gl_LastFragColorARM;\n" 368 " " GR_GL_PLS_DSTCOLOR_NAME " = gl_LastFragColorARM;\n"
347 " pls.windings = ivec4(0, 0, 0, 0);\n" 369 " pls.windings = ivec4(0, 0, 0, 0);\n"
348 "}" 370 "}"
349 ); 371 );
350 GL_CALL_RET(fPLSSetupProgram.fProgram, CreateProgram()); 372
351 const char* str; 373 const char* str;
352 GrGLint length; 374 GrGLint length;
353 375
354 str = vshaderTxt.c_str(); 376 str = vshaderTxt.c_str();
355 length = SkToInt(vshaderTxt.size()); 377 length = SkToInt(vshaderTxt.size());
356 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fPLSSetupProgram. fProgram, 378 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fPLSSetupProgram. fProgram,
357 GR_GL_VERTEX_SHADER, &str, &le ngth, 1, &fStats); 379 GR_GL_VERTEX_SHADER, &str, &le ngth, 1, &fStats);
358 380
359 str = fshaderTxt.c_str(); 381 str = fshaderTxt.c_str();
360 length = SkToInt(fshaderTxt.size()); 382 length = SkToInt(fshaderTxt.size());
361 GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fPLSSetupProgram. fProgram, 383 GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fPLSSetupProgram. fProgram,
362 GR_GL_FRAGMENT_SHADER, &str, & length, 1, &fStats); 384 GR_GL_FRAGMENT_SHADER, &str, & length, 1, &fStats);
363 385
364 GL_CALL(LinkProgram(fPLSSetupProgram.fProgram)); 386 GL_CALL(LinkProgram(fPLSSetupProgram.fProgram));
365 387
366 GL_CALL_RET(fPLSSetupProgram.fPosXformUniform, GetUniformLocation(fPLSSetupP rogram.fProgram, 388 GL_CALL_RET(fPLSSetupProgram.fPosXformUniform, GetUniformLocation(fPLSSetupP rogram.fProgram,
367 "u_posXform")) ; 389 "u_posXform")) ;
368 390
369 GL_CALL(BindAttribLocation(fPLSSetupProgram.fProgram, 0, "a_vertex")); 391 GL_CALL(BindAttribLocation(fPLSSetupProgram.fProgram, 0, "a_vertex"));
370 392
371 GL_CALL(DeleteShader(vshader)); 393 GL_CALL(DeleteShader(vshader));
372 GL_CALL(DeleteShader(fshader)); 394 GL_CALL(DeleteShader(fshader));
373 395
374 GL_CALL(GenBuffers(1, &fPLSSetupProgram.fArrayBuffer)); 396 return true;
375 fHWGeometryState.setVertexBufferID(this, fPLSSetupProgram.fArrayBuffer);
376 static const GrGLfloat vdata[] = {
377 0, 0,
378 0, 1,
379 1, 0,
380 1, 1
381 };
382 GL_ALLOC_CALL(this->glInterface(),
383 BufferData(GR_GL_ARRAY_BUFFER,
384 (GrGLsizeiptr) sizeof(vdata),
385 vdata, // data ptr
386 GR_GL_STATIC_DRAW));
387 } 397 }
388 398
389 void GrGLGpu::disconnect(DisconnectType type) { 399 void GrGLGpu::disconnect(DisconnectType type) {
390 INHERITED::disconnect(type); 400 INHERITED::disconnect(type);
391 if (DisconnectType::kCleanup == type) { 401 if (DisconnectType::kCleanup == type) {
392 if (fHWProgramID) { 402 if (fHWProgramID) {
393 GL_CALL(UseProgram(0)); 403 GL_CALL(UseProgram(0));
394 } 404 }
395 if (fTempSrcFBOID) { 405 if (fTempSrcFBOID) {
396 GL_CALL(DeleteFramebuffers(1, &fTempSrcFBOID)); 406 GL_CALL(DeleteFramebuffers(1, &fTempSrcFBOID));
397 } 407 }
398 if (fTempDstFBOID) { 408 if (fTempDstFBOID) {
399 GL_CALL(DeleteFramebuffers(1, &fTempDstFBOID)); 409 GL_CALL(DeleteFramebuffers(1, &fTempDstFBOID));
400 } 410 }
401 if (fStencilClearFBOID) { 411 if (fStencilClearFBOID) {
402 GL_CALL(DeleteFramebuffers(1, &fStencilClearFBOID)); 412 GL_CALL(DeleteFramebuffers(1, &fStencilClearFBOID));
403 } 413 }
404 if (fCopyProgramArrayBuffer) {
405 GL_CALL(DeleteBuffers(1, &fCopyProgramArrayBuffer));
406 }
407 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { 414 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) {
408 if (fCopyPrograms[i].fProgram) { 415 if (fCopyPrograms[i].fProgram) {
409 GL_CALL(DeleteProgram(fCopyPrograms[i].fProgram)); 416 GL_CALL(DeleteProgram(fCopyPrograms[i].fProgram));
410 } 417 }
411 } 418 }
412 if (fWireRectProgram.fProgram) { 419 if (fWireRectProgram.fProgram) {
413 GL_CALL(DeleteProgram(fWireRectProgram.fProgram)); 420 GL_CALL(DeleteProgram(fWireRectProgram.fProgram));
414 } 421 }
415 if (fWireRectArrayBuffer) {
416 GL_CALL(DeleteBuffers(1, &fWireRectArrayBuffer));
417 }
418
419 if (fPLSSetupProgram.fProgram) { 422 if (fPLSSetupProgram.fProgram) {
420 GL_CALL(DeleteProgram(fPLSSetupProgram.fProgram)); 423 GL_CALL(DeleteProgram(fPLSSetupProgram.fProgram));
421 } 424 }
422 if (fPLSSetupProgram.fArrayBuffer) {
423 GL_CALL(DeleteBuffers(1, &fPLSSetupProgram.fArrayBuffer));
424 }
425 } else { 425 } else {
426 if (fProgramCache) { 426 if (fProgramCache) {
427 fProgramCache->abandon(); 427 fProgramCache->abandon();
428 } 428 }
429 } 429 }
430 430
431 delete fProgramCache; 431 delete fProgramCache;
432 fProgramCache = nullptr; 432 fProgramCache = nullptr;
433 433
434 fHWProgramID = 0; 434 fHWProgramID = 0;
435 fTempSrcFBOID = 0; 435 fTempSrcFBOID = 0;
436 fTempDstFBOID = 0; 436 fTempDstFBOID = 0;
437 fStencilClearFBOID = 0; 437 fStencilClearFBOID = 0;
438 fCopyProgramArrayBuffer = 0; 438 fCopyProgramArrayBuffer.reset();
439 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { 439 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) {
440 fCopyPrograms[i].fProgram = 0; 440 fCopyPrograms[i].fProgram = 0;
441 } 441 }
442 fWireRectProgram.fProgram = 0; 442 fWireRectProgram.fProgram = 0;
443 fWireRectArrayBuffer = 0; 443 fWireRectArrayBuffer.reset();
444 fPLSSetupProgram.fProgram = 0; 444 fPLSSetupProgram.fProgram = 0;
445 fPLSSetupProgram.fArrayBuffer = 0; 445 fPLSSetupProgram.fArrayBuffer.reset();
446 if (this->glCaps().shaderCaps()->pathRenderingSupport()) { 446 if (this->glCaps().shaderCaps()->pathRenderingSupport()) {
447 this->glPathRendering()->disconnect(type); 447 this->glPathRendering()->disconnect(type);
448 } 448 }
449 } 449 }
450 450
451 /////////////////////////////////////////////////////////////////////////////// 451 ///////////////////////////////////////////////////////////////////////////////
452 452
453 void GrGLGpu::onResetContext(uint32_t resetBits) { 453 void GrGLGpu::onResetContext(uint32_t resetBits) {
454 // we don't use the zb at all 454 // we don't use the zb at all
455 if (resetBits & kMisc_GrGLBackendState) { 455 if (resetBits & kMisc_GrGLBackendState) {
456 GL_CALL(Disable(GR_GL_DEPTH_TEST)); 456 GL_CALL(Disable(GR_GL_DEPTH_TEST));
457 GL_CALL(DepthMask(GR_GL_FALSE)); 457 GL_CALL(DepthMask(GR_GL_FALSE));
458 458
459 fHWBoundTextureBufferIDIsValid = false; 459 fHWBufferState[kTexel_GrBufferType].invalidate();
460 fHWBoundDrawIndirectBufferIDIsValid = false; 460 fHWBufferState[kDrawIndirect_GrBufferType].invalidate();
461 fHWBufferState[kXferCpuToGpu_GrBufferType].invalidate();
462 fHWBufferState[kXferGpuToCpu_GrBufferType].invalidate();
461 463
462 fHWDrawFace = GrPipelineBuilder::kInvalid_DrawFace; 464 fHWDrawFace = GrPipelineBuilder::kInvalid_DrawFace;
463 465
464 if (kGL_GrGLStandard == this->glStandard()) { 466 if (kGL_GrGLStandard == this->glStandard()) {
465 // Desktop-only state that we never change 467 // Desktop-only state that we never change
466 if (!this->glCaps().isCoreProfile()) { 468 if (!this->glCaps().isCoreProfile()) {
467 GL_CALL(Disable(GR_GL_POINT_SMOOTH)); 469 GL_CALL(Disable(GR_GL_POINT_SMOOTH));
468 GL_CALL(Disable(GR_GL_LINE_SMOOTH)); 470 GL_CALL(Disable(GR_GL_LINE_SMOOTH));
469 GL_CALL(Disable(GR_GL_POLYGON_SMOOTH)); 471 GL_CALL(Disable(GR_GL_POLYGON_SMOOTH));
470 GL_CALL(Disable(GR_GL_POLYGON_STIPPLE)); 472 GL_CALL(Disable(GR_GL_POLYGON_STIPPLE));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 fHWViewport.invalidate(); 533 fHWViewport.invalidate();
532 } 534 }
533 535
534 if (resetBits & kStencil_GrGLBackendState) { 536 if (resetBits & kStencil_GrGLBackendState) {
535 fHWStencilSettings.invalidate(); 537 fHWStencilSettings.invalidate();
536 fHWStencilTestEnabled = kUnknown_TriState; 538 fHWStencilTestEnabled = kUnknown_TriState;
537 } 539 }
538 540
539 // Vertex 541 // Vertex
540 if (resetBits & kVertex_GrGLBackendState) { 542 if (resetBits & kVertex_GrGLBackendState) {
541 fHWGeometryState.invalidate(); 543 fHWVertexArrayState.invalidate();
544 fHWBufferState[kVertex_GrBufferType].invalidate();
545 fHWBufferState[kIndex_GrBufferType].invalidate();
542 } 546 }
543 547
544 if (resetBits & kRenderTarget_GrGLBackendState) { 548 if (resetBits & kRenderTarget_GrGLBackendState) {
545 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; 549 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
546 fHWSRGBFramebuffer = kUnknown_TriState; 550 fHWSRGBFramebuffer = kUnknown_TriState;
547 } 551 }
548 552
549 if (resetBits & kPathRendering_GrGLBackendState) { 553 if (resetBits & kPathRendering_GrGLBackendState) {
550 if (this->caps()->shaderCaps()->pathRenderingSupport()) { 554 if (this->caps()->shaderCaps()->pathRenderingSupport()) {
551 this->glPathRendering()->resetContext(); 555 this->glPathRendering()->resetContext();
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 } 897 }
894 898
895 // For the moment, can't transfer compressed data 899 // For the moment, can't transfer compressed data
896 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { 900 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) {
897 return false; 901 return false;
898 } 902 }
899 903
900 this->setScratchTextureUnit(); 904 this->setScratchTextureUnit();
901 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); 905 GL_CALL(BindTexture(glTex->target(), glTex->textureID()));
902 906
903 SkASSERT(kXferCpuToGpu_GrBufferType == transferBuffer->type());
904 SkASSERT(!transferBuffer->isMapped()); 907 SkASSERT(!transferBuffer->isMapped());
905 SkASSERT(!transferBuffer->isCPUBacked()); 908 SkASSERT(!transferBuffer->isCPUBacked());
906 const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer); 909 const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer);
907 this->bindBuffer(glBuffer->bufferID(), glBuffer->target()); 910 this->bindBuffer(kXferCpuToGpu_GrBufferType, glBuffer);
908 911
909 bool success = false; 912 bool success = false;
910 GrMipLevel mipLevel; 913 GrMipLevel mipLevel;
911 mipLevel.fPixels = transferBuffer; 914 mipLevel.fPixels = transferBuffer;
912 mipLevel.fRowBytes = rowBytes; 915 mipLevel.fRowBytes = rowBytes;
913 SkSTArray<1, GrMipLevel> texels; 916 SkSTArray<1, GrMipLevel> texels;
914 texels.push_back(mipLevel); 917 texels.push_back(mipLevel);
915 success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_Uplo adType, 918 success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_Uplo adType,
916 left, top, width, height, config, texels); 919 left, top, width, height, config, texels);
917 if (success) { 920 if (success) {
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 format); 1970 format);
1968 return stencil; 1971 return stencil;
1969 } 1972 }
1970 1973
1971 //////////////////////////////////////////////////////////////////////////////// 1974 ////////////////////////////////////////////////////////////////////////////////
1972 1975
1973 // GL_STREAM_DRAW triggers an optimization in Chromium's GPU process where a cli ent's vertex buffer 1976 // 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. 1977 // objects are implemented as client-side-arrays on tile-deferred architectures.
1975 #define DYNAMIC_USAGE_PARAM GR_GL_STREAM_DRAW 1978 #define DYNAMIC_USAGE_PARAM GR_GL_STREAM_DRAW
1976 1979
1977 GrBuffer* GrGLGpu::onCreateBuffer(GrBufferType type, size_t size, GrAccessPatter n accessPattern) { 1980 GrBuffer* GrGLGpu::onCreateBuffer(size_t size, GrBufferType intendedType,
1978 return GrGLBuffer::Create(this, type, size, accessPattern); 1981 GrAccessPattern accessPattern) {
1982 return GrGLBuffer::Create(this, size, intendedType, accessPattern);
1979 } 1983 }
1980 1984
1981 void GrGLGpu::flushScissor(const GrScissorState& scissorState, 1985 void GrGLGpu::flushScissor(const GrScissorState& scissorState,
1982 const GrGLIRect& rtViewport, 1986 const GrGLIRect& rtViewport,
1983 GrSurfaceOrigin rtOrigin) { 1987 GrSurfaceOrigin rtOrigin) {
1984 if (scissorState.enabled()) { 1988 if (scissorState.enabled()) {
1985 GrGLIRect scissor; 1989 GrGLIRect scissor;
1986 scissor.setRelativeTo(rtViewport, 1990 scissor.setRelativeTo(rtViewport,
1987 scissorState.rect().fLeft, 1991 scissorState.rect().fLeft,
1988 scissorState.rect().fTop, 1992 scissorState.rect().fTop,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 } 2076 }
2073 2077
2074 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, 2078 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc,
2075 const GrNonInstancedMesh& mesh, 2079 const GrNonInstancedMesh& mesh,
2076 size_t* indexOffsetInBytes) { 2080 size_t* indexOffsetInBytes) {
2077 const GrGLBuffer* vbuf; 2081 const GrGLBuffer* vbuf;
2078 vbuf = static_cast<const GrGLBuffer*>(mesh.vertexBuffer()); 2082 vbuf = static_cast<const GrGLBuffer*>(mesh.vertexBuffer());
2079 2083
2080 SkASSERT(vbuf); 2084 SkASSERT(vbuf);
2081 SkASSERT(!vbuf->isMapped()); 2085 SkASSERT(!vbuf->isMapped());
2082 SkASSERT(kVertex_GrBufferType == vbuf->type());
2083 2086
2084 const GrGLBuffer* ibuf = nullptr; 2087 GrGLAttribArrayState* attribState;
2085 if (mesh.isIndexed()) { 2088 if (mesh.isIndexed()) {
2086 SkASSERT(indexOffsetInBytes); 2089 SkASSERT(indexOffsetInBytes);
2087 2090
2088 *indexOffsetInBytes = 0; 2091 *indexOffsetInBytes = 0;
2089 ibuf = static_cast<const GrGLBuffer*>(mesh.indexBuffer()); 2092 const GrGLBuffer* ibuf = static_cast<const GrGLBuffer*>(mesh.indexBuffer ());
2090 2093
2091 SkASSERT(ibuf); 2094 SkASSERT(ibuf);
2092 SkASSERT(!ibuf->isMapped()); 2095 SkASSERT(!ibuf->isMapped());
2093 SkASSERT(kIndex_GrBufferType == ibuf->type());
2094 *indexOffsetInBytes += ibuf->baseOffset(); 2096 *indexOffsetInBytes += ibuf->baseOffset();
2097 attribState = fHWVertexArrayState.bindInternalVertexArray(this, ibuf);
2098 } else {
2099 attribState = fHWVertexArrayState.bindInternalVertexArray(this);
2095 } 2100 }
2096 GrGLAttribArrayState* attribState =
2097 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf);
2098 2101
2099 int vaCount = primProc.numAttribs(); 2102 int vaCount = primProc.numAttribs();
2100 if (vaCount > 0) { 2103 if (vaCount > 0) {
2101 2104
2102 GrGLsizei stride = static_cast<GrGLsizei>(primProc.getVertexStride()); 2105 GrGLsizei stride = static_cast<GrGLsizei>(primProc.getVertexStride());
2103 2106
2104 size_t vertexOffsetInBytes = stride * mesh.startVertex(); 2107 size_t vertexOffsetInBytes = stride * mesh.startVertex();
2105 2108
2106 vertexOffsetInBytes += vbuf->baseOffset(); 2109 vertexOffsetInBytes += vbuf->baseOffset();
2107 2110
2108 uint32_t usedAttribArraysMask = 0; 2111 uint32_t usedAttribArraysMask = 0;
2109 size_t offset = 0; 2112 size_t offset = 0;
2110 2113
2111 for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) { 2114 for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) {
2112 const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(at tribIndex); 2115 const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(at tribIndex);
2113 usedAttribArraysMask |= (1 << attribIndex); 2116 usedAttribArraysMask |= (1 << attribIndex);
2114 GrVertexAttribType attribType = attrib.fType; 2117 GrVertexAttribType attribType = attrib.fType;
2115 attribState->set(this, 2118 attribState->set(this,
2116 attribIndex, 2119 attribIndex,
2117 vbuf->bufferID(), 2120 vbuf,
2118 attribType, 2121 attribType,
2119 stride, 2122 stride,
2120 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o ffset)); 2123 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o ffset));
2121 offset += attrib.fOffset; 2124 offset += attrib.fOffset;
2122 } 2125 }
2123 attribState->disableUnusedArrays(this, usedAttribArraysMask); 2126 attribState->disableUnusedArrays(this, usedAttribArraysMask);
2124 } 2127 }
2125 } 2128 }
2126 2129
2127 void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) { 2130 GrGLenum GrGLGpu::bindBuffer(GrBufferType type, const GrGLBuffer* buffer) {
2128 this->handleDirtyContext(); 2131 this->handleDirtyContext();
2129 switch (type) { 2132
2130 case GR_GL_ARRAY_BUFFER: 2133 // Index buffer state is tied to the vertex array.
2131 this->bindVertexBuffer(id); 2134 if (kIndex_GrBufferType == type) {
2132 break; 2135 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 } 2136 }
2155 }
2156 2137
2157 void GrGLGpu::releaseBuffer(GrGLuint id, GrGLenum type) { 2138 SkASSERT(type >= 0 && type <= kLast_GrBufferType);
2158 this->handleDirtyContext(); 2139 auto& bufferState = fHWBufferState[type];
2159 GL_CALL(DeleteBuffers(1, &id)); 2140
2160 switch (type) { 2141 if (buffer->getUniqueID() != bufferState.fBoundBufferUniqueID) {
2161 case GR_GL_ARRAY_BUFFER: 2142 if (!buffer->isCPUBacked() || !bufferState.fBufferZeroKnownBound) {
2162 this->notifyVertexBufferDelete(id); 2143 GL_CALL(BindBuffer(bufferState.fGLTarget, buffer->bufferID()));
2163 break; 2144 bufferState.fBufferZeroKnownBound = buffer->isCPUBacked();
2164 case GR_GL_ELEMENT_ARRAY_BUFFER: 2145 }
2165 this->notifyIndexBufferDelete(id); 2146 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 } 2147 }
2148
2149 return bufferState.fGLTarget;
2178 } 2150 }
2179 2151
2180 void GrGLGpu::disableScissor() { 2152 void GrGLGpu::disableScissor() {
2181 if (kNo_TriState != fHWScissorSettings.fEnabled) { 2153 if (kNo_TriState != fHWScissorSettings.fEnabled) {
2182 GL_CALL(Disable(GR_GL_SCISSOR_TEST)); 2154 GL_CALL(Disable(GR_GL_SCISSOR_TEST));
2183 fHWScissorSettings.fEnabled = kNo_TriState; 2155 fHWScissorSettings.fEnabled = kNo_TriState;
2184 return; 2156 return;
2185 } 2157 }
2186 } 2158 }
2187 2159
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2665 * use PLS, it leaves garbage all over the place. As a workaround, we us e PLS in a 2637 * use PLS, it leaves garbage all over the place. As a workaround, we us e PLS in a
2666 * trivial way every frame. And since we use it every frame, there's nev er a point at which 2638 * trivial way every frame. And since we use it every frame, there's nev er a point at which
2667 * it becomes safe to stop using this workaround once we start. 2639 * it becomes safe to stop using this workaround once we start.
2668 */ 2640 */
2669 this->disableScissor(); 2641 this->disableScissor();
2670 // using PLS in the presence of MSAA results in GL_INVALID_OPERATION 2642 // using PLS in the presence of MSAA results in GL_INVALID_OPERATION
2671 this->flushHWAAState(nullptr, false, false); 2643 this->flushHWAAState(nullptr, false, false);
2672 SkASSERT(!fHWPLSEnabled); 2644 SkASSERT(!fHWPLSEnabled);
2673 SkASSERT(fMSAAEnabled != kYes_TriState); 2645 SkASSERT(fMSAAEnabled != kYes_TriState);
2674 GL_CALL(Enable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); 2646 GL_CALL(Enable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE));
2675 this->stampRectUsingProgram(fPLSSetupProgram.fProgram, 2647 this->stampPLSSetupRect(SkRect::MakeXYWH(-100.0f, -100.0f, 0.01f, 0.01f) );
2676 SkRect::MakeXYWH(-100.0f, -100.0f, 0.01f, 0. 01f),
2677 fPLSSetupProgram.fPosXformUniform,
2678 fPLSSetupProgram.fArrayBuffer);
2679 GL_CALL(Disable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); 2648 GL_CALL(Disable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE));
2680 } 2649 }
2681 } 2650 }
2682 2651
2683 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bounds, bool disableSRGB) { 2652 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bounds, bool disableSRGB) {
2684 SkASSERT(target); 2653 SkASSERT(target);
2685 2654
2686 uint32_t rtID = target->getUniqueID(); 2655 uint32_t rtID = target->getUniqueID();
2687 if (fHWBoundRenderTargetUniqueID != rtID) { 2656 if (fHWBoundRenderTargetUniqueID != rtID) {
2688 fStats.incRenderTargetBinds(); 2657 fStats.incRenderTargetBinds();
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2836 int set_a_break_pt_here = 9; 2805 int set_a_break_pt_here = 9;
2837 aglSwapBuffers(aglGetCurrentContext()); 2806 aglSwapBuffers(aglGetCurrentContext());
2838 #elif defined(SK_BUILD_FOR_WIN32) 2807 #elif defined(SK_BUILD_FOR_WIN32)
2839 SwapBuf(); 2808 SwapBuf();
2840 int set_a_break_pt_here = 9; 2809 int set_a_break_pt_here = 9;
2841 SwapBuf(); 2810 SwapBuf();
2842 #endif 2811 #endif
2843 #endif 2812 #endif
2844 } 2813 }
2845 2814
2846 void GrGLGpu::stampRectUsingProgram(GrGLuint program, const SkRect& bounds, GrGL int posXformUniform, 2815 void GrGLGpu::stampPLSSetupRect(const SkRect& bounds) {
2847 GrGLuint arrayBuffer) { 2816 SkASSERT(this->glCaps().glslCaps()->plsPathRenderingSupport())
2848 GL_CALL(UseProgram(program));
2849 this->fHWGeometryState.setVertexArrayID(this, 0);
2850 2817
2851 GrGLAttribArrayState* attribs = 2818 if (!fPLSSetupProgram.fProgram) {
2852 this->fHWGeometryState.bindArrayAndBufferToDraw(this, arrayBuffer); 2819 if (!this->createPLSSetupProgram()) {
2853 attribs->set(this, 0, arrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrG Lfloat), 0); 2820 SkDebugf("Failed to create PLS setup program.\n");
2821 return;
2822 }
2823 }
2824
2825 GL_CALL(UseProgram(fPLSSetupProgram.fProgram));
2826 this->fHWVertexArrayState.setVertexArrayID(this, 0);
2827
2828 GrGLAttribArrayState* attribs = this->fHWVertexArrayState.bindInternalVertex Array(this);
2829 attribs->set(this, 0, fPLSSetupProgram.fArrayBuffer, kVec2f_GrVertexAttribTy pe,
2830 2 * sizeof(GrGLfloat), 0);
2854 attribs->disableUnusedArrays(this, 0x1); 2831 attribs->disableUnusedArrays(this, 0x1);
2855 2832
2856 GL_CALL(Uniform4f(posXformUniform, bounds.width(), bounds.height(), bounds.l eft(), 2833 GL_CALL(Uniform4f(fPLSSetupProgram.fPosXformUniform, bounds.width(), bounds. height(),
2857 bounds.top())); 2834 bounds.left(), bounds.top()));
2858 2835
2859 GrXferProcessor::BlendInfo blendInfo; 2836 GrXferProcessor::BlendInfo blendInfo;
2860 blendInfo.reset(); 2837 blendInfo.reset();
2861 this->flushBlend(blendInfo, GrSwizzle()); 2838 this->flushBlend(blendInfo, GrSwizzle());
2862 this->flushColorWrite(true); 2839 this->flushColorWrite(true);
2863 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); 2840 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace);
2864 if (!fHWStencilSettings.isDisabled()) { 2841 if (!fHWStencilSettings.isDisabled()) {
2865 GL_CALL(Disable(GR_GL_STENCIL_TEST)); 2842 GL_CALL(Disable(GR_GL_STENCIL_TEST));
2866 } 2843 }
2867 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); 2844 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4));
(...skipping 16 matching lines...) Expand all
2884 // dst rect edges in NDC (-1 to 1) 2861 // dst rect edges in NDC (-1 to 1)
2885 // having some issues with rounding, just expand the bounds by 1 and trust t he scissor to keep 2862 // having some issues with rounding, just expand the bounds by 1 and trust t he scissor to keep
2886 // it contained properly 2863 // it contained properly
2887 GrGLfloat dx0 = 2.0f * (bounds.left() - 1) / width - 1.0f; 2864 GrGLfloat dx0 = 2.0f * (bounds.left() - 1) / width - 1.0f;
2888 GrGLfloat dx1 = 2.0f * (bounds.right() + 1) / width - 1.0f; 2865 GrGLfloat dx1 = 2.0f * (bounds.right() + 1) / width - 1.0f;
2889 GrGLfloat dy0 = -2.0f * (bounds.top() - 1) / height + 1.0f; 2866 GrGLfloat dy0 = -2.0f * (bounds.top() - 1) / height + 1.0f;
2890 GrGLfloat dy1 = -2.0f * (bounds.bottom() + 1) / height + 1.0f; 2867 GrGLfloat dy1 = -2.0f * (bounds.bottom() + 1) / height + 1.0f;
2891 SkRect deviceBounds = SkRect::MakeXYWH(dx0, dy0, dx1 - dx0, dy1 - dy0); 2868 SkRect deviceBounds = SkRect::MakeXYWH(dx0, dy0, dx1 - dx0, dy1 - dy0);
2892 2869
2893 GL_CALL(Enable(GR_GL_FETCH_PER_SAMPLE_ARM)); 2870 GL_CALL(Enable(GR_GL_FETCH_PER_SAMPLE_ARM));
2894 this->stampRectUsingProgram(fPLSSetupProgram.fProgram, deviceBounds, 2871 this->stampPLSSetupRect(deviceBounds);
2895 fPLSSetupProgram.fPosXformUniform, fPLSSetupProg ram.fArrayBuffer);
2896 } 2872 }
2897 2873
2898 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { 2874 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) {
2899 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); 2875 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target);
2900 if (rt->needsResolve()) { 2876 if (rt->needsResolve()) {
2901 // Some extensions automatically resolves the texture when it is read. 2877 // Some extensions automatically resolves the texture when it is read.
2902 if (this->glCaps().usesMSAARenderBuffers()) { 2878 if (this->glCaps().usesMSAARenderBuffers()) {
2903 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); 2879 SkASSERT(rt->textureFBOID() != rt->renderFBOID());
2904 fStats.incRenderTargetBinds(); 2880 fStats.incRenderTargetBinds();
2905 fStats.incRenderTargetBinds(); 2881 fStats.incRenderTargetBinds();
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
3557 const SkIPoint& dstPoint) { 3533 const SkIPoint& dstPoint) {
3558 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDr aw handle the 3534 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDr aw handle the
3559 // swizzle. 3535 // swizzle.
3560 if (this->glCaps().glslCaps()->configOutputSwizzle(src->config()) != 3536 if (this->glCaps().glslCaps()->configOutputSwizzle(src->config()) !=
3561 this->glCaps().glslCaps()->configOutputSwizzle(dst->config())) { 3537 this->glCaps().glslCaps()->configOutputSwizzle(dst->config())) {
3562 return false; 3538 return false;
3563 } 3539 }
3564 // Don't prefer copying as a draw if the dst doesn't already have a FBO obje ct. 3540 // Don't prefer copying as a draw if the dst doesn't already have a FBO obje ct.
3565 bool preferCopy = SkToBool(dst->asRenderTarget()); 3541 bool preferCopy = SkToBool(dst->asRenderTarget());
3566 if (preferCopy && src->asTexture()) { 3542 if (preferCopy && src->asTexture()) {
3567 this->copySurfaceAsDraw(dst, src, srcRect, dstPoint); 3543 if (this->copySurfaceAsDraw(dst, src, srcRect, dstPoint)) {
3568 return true; 3544 return true;
3545 }
3569 } 3546 }
3570 3547
3571 if (can_copy_texsubimage(dst, src, this)) { 3548 if (can_copy_texsubimage(dst, src, this)) {
3572 this->copySurfaceAsCopyTexSubImage(dst, src, srcRect, dstPoint); 3549 this->copySurfaceAsCopyTexSubImage(dst, src, srcRect, dstPoint);
3573 return true; 3550 return true;
3574 } 3551 }
3575 3552
3576 if (can_blit_framebuffer(dst, src, this)) { 3553 if (can_blit_framebuffer(dst, src, this)) {
3577 return this->copySurfaceAsBlitFramebuffer(dst, src, srcRect, dstPoint); 3554 return this->copySurfaceAsBlitFramebuffer(dst, src, srcRect, dstPoint);
3578 } 3555 }
3579 3556
3580 if (!preferCopy && src->asTexture()) { 3557 if (!preferCopy && src->asTexture()) {
3581 this->copySurfaceAsDraw(dst, src, srcRect, dstPoint); 3558 if (this->copySurfaceAsDraw(dst, src, srcRect, dstPoint)) {
3582 return true; 3559 return true;
3560 }
3583 } 3561 }
3584 3562
3585 return false; 3563 return false;
3586 } 3564 }
3587 3565
3588 void GrGLGpu::createCopyPrograms() { 3566 bool GrGLGpu::createCopyProgram(int progIdx) {
3589 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) {
3590 fCopyPrograms[i].fProgram = 0;
3591 }
3592 const GrGLSLCaps* glslCaps = this->glCaps().glslCaps(); 3567 const GrGLSLCaps* glslCaps = this->glCaps().glslCaps();
3593 const char* version = glslCaps->versionDeclString();
3594 static const GrSLType kSamplerTypes[3] = { kSampler2D_GrSLType, kSamplerExte rnal_GrSLType, 3568 static const GrSLType kSamplerTypes[3] = { kSampler2D_GrSLType, kSamplerExte rnal_GrSLType,
3595 kSampler2DRect_GrSLType }; 3569 kSampler2DRect_GrSLType };
3596 SkASSERT(3 == SK_ARRAY_COUNT(fCopyPrograms)); 3570 if (kSamplerExternal_GrSLType == kSamplerTypes[progIdx] &&
3597 for (int i = 0; i < 3; ++i) { 3571 !this->glCaps().glslCaps()->externalTextureSupport()) {
3598 if (kSamplerExternal_GrSLType == kSamplerTypes[i] && 3572 return false;
3599 !this->glCaps().glslCaps()->externalTextureSupport()) { 3573 }
3600 continue; 3574 if (kSampler2DRect_GrSLType == kSamplerTypes[progIdx] &&
3575 !this->glCaps().rectangleTextureSupport()) {
3576 return false;
3577 }
3578
3579 if (!fCopyProgramArrayBuffer) {
3580 static const GrGLfloat vdata[] = {
3581 0, 0,
3582 0, 1,
3583 1, 0,
3584 1, 1
3585 };
3586 fCopyProgramArrayBuffer.reset(GrGLBuffer::Create(this, sizeof(vdata), kV ertex_GrBufferType,
3587 kStatic_GrAccessPattern , vdata));
3588 }
3589 if (!fCopyProgramArrayBuffer) {
3590 return false;
3591 }
3592
3593 SkASSERT(!fCopyPrograms[progIdx].fProgram);
3594 GL_CALL_RET(fCopyPrograms[progIdx].fProgram, CreateProgram());
3595 if (!fCopyPrograms[progIdx].fProgram) {
3596 return false;
3597 }
3598
3599 const char* version = glslCaps->versionDeclString();
3600 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute _TypeModifier);
3601 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType,
3602 GrShaderVar::kUniform_TypeModifier);
3603 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType,
3604 GrShaderVar::kUniform_TypeModifier);
3605 GrGLSLShaderVar uTexture("u_texture", kSamplerTypes[progIdx],
3606 GrShaderVar::kUniform_TypeModifier);
3607 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType,
3608 GrShaderVar::kVaryingOut_TypeModifier);
3609 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType,
3610 GrShaderVar::kOut_TypeModifier);
3611
3612 SkString vshaderTxt(version);
3613 if (glslCaps->noperspectiveInterpolationSupport()) {
3614 if (const char* extension = glslCaps->noperspectiveInterpolationExtensio nString()) {
3615 vshaderTxt.appendf("#extension %s : require\n", extension);
3601 } 3616 }
3602 if (kSampler2DRect_GrSLType == kSamplerTypes[i] && 3617 vTexCoord.addModifier("noperspective");
3603 !this->glCaps().rectangleTextureSupport()) { 3618 }
3604 continue; 3619
3620 aVertex.appendDecl(glslCaps, &vshaderTxt);
3621 vshaderTxt.append(";");
3622 uTexCoordXform.appendDecl(glslCaps, &vshaderTxt);
3623 vshaderTxt.append(";");
3624 uPosXform.appendDecl(glslCaps, &vshaderTxt);
3625 vshaderTxt.append(";");
3626 vTexCoord.appendDecl(glslCaps, &vshaderTxt);
3627 vshaderTxt.append(";");
3628
3629 vshaderTxt.append(
3630 "// Copy Program VS\n"
3631 "void main() {"
3632 " v_texCoord = a_vertex.xy * u_texCoordXform.xy + u_texCoordXform.zw;"
3633 " gl_Position.xy = a_vertex * u_posXform.xy + u_posXform.zw;"
3634 " gl_Position.zw = vec2(0, 1);"
3635 "}"
3636 );
3637
3638 SkString fshaderTxt(version);
3639 if (glslCaps->noperspectiveInterpolationSupport()) {
3640 if (const char* extension = glslCaps->noperspectiveInterpolationExtensio nString()) {
3641 fshaderTxt.appendf("#extension %s : require\n", extension);
3605 } 3642 }
3606 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttri bute_TypeModifier); 3643 }
3607 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, 3644 if (kSamplerTypes[progIdx] == kSamplerExternal_GrSLType) {
3608 GrShaderVar::kUniform_TypeModifier); 3645 fshaderTxt.appendf("#extension %s : require\n",
3609 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, 3646 glslCaps->externalTextureExtensionString());
3610 GrShaderVar::kUniform_TypeModifier); 3647 }
3611 GrGLSLShaderVar uTexture("u_texture", kSamplerTypes[i], 3648 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *glslCa ps,
3612 GrShaderVar::kUniform_TypeModifier); 3649 &fshaderTxt);
3613 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, 3650 vTexCoord.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier);
3614 GrShaderVar::kVaryingOut_TypeModifier); 3651 vTexCoord.appendDecl(glslCaps, &fshaderTxt);
3615 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, 3652 fshaderTxt.append(";");
3616 GrShaderVar::kOut_TypeModifier); 3653 uTexture.appendDecl(glslCaps, &fshaderTxt);
3654 fshaderTxt.append(";");
3655 const char* fsOutName;
3656 if (glslCaps->mustDeclareFragmentShaderOutput()) {
3657 oFragColor.appendDecl(glslCaps, &fshaderTxt);
3658 fshaderTxt.append(";");
3659 fsOutName = oFragColor.c_str();
3660 } else {
3661 fsOutName = "gl_FragColor";
3662 }
3663 fshaderTxt.appendf(
3664 "// Copy Program FS\n"
3665 "void main() {"
3666 " %s = %s(u_texture, v_texCoord);"
3667 "}",
3668 fsOutName,
3669 GrGLSLTexture2DFunctionName(kVec2f_GrSLType, kSamplerTypes[progIdx], thi s->glslGeneration())
3670 );
3617 3671
3618 SkString vshaderTxt(version); 3672 const char* str;
3619 if (glslCaps->noperspectiveInterpolationSupport()) { 3673 GrGLint length;
3620 if (const char* extension = glslCaps->noperspectiveInterpolationExte nsionString()) {
3621 vshaderTxt.appendf("#extension %s : require\n", extension);
3622 }
3623 vTexCoord.addModifier("noperspective");
3624 }
3625 3674
3626 aVertex.appendDecl(glslCaps, &vshaderTxt); 3675 str = vshaderTxt.c_str();
3627 vshaderTxt.append(";"); 3676 length = SkToInt(vshaderTxt.size());
3628 uTexCoordXform.appendDecl(glslCaps, &vshaderTxt); 3677 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms[pro gIdx].fProgram,
3629 vshaderTxt.append(";"); 3678 GR_GL_VERTEX_SHADER, &str, &le ngth, 1,
3630 uPosXform.appendDecl(glslCaps, &vshaderTxt); 3679 &fStats);
3631 vshaderTxt.append(";");
3632 vTexCoord.appendDecl(glslCaps, &vshaderTxt);
3633 vshaderTxt.append(";");
3634 3680
3635 vshaderTxt.append( 3681 str = fshaderTxt.c_str();
3636 "// Copy Program VS\n" 3682 length = SkToInt(fshaderTxt.size());
3637 "void main() {" 3683 GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms[pro gIdx].fProgram,
3638 " v_texCoord = a_vertex.xy * u_texCoordXform.xy + u_texCoordXform.z w;" 3684 GR_GL_FRAGMENT_SHADER, &str, & length, 1,
3639 " gl_Position.xy = a_vertex * u_posXform.xy + u_posXform.zw;" 3685 &fStats);
3640 " gl_Position.zw = vec2(0, 1);"
3641 "}"
3642 );
3643 3686
3644 SkString fshaderTxt(version); 3687 GL_CALL(LinkProgram(fCopyPrograms[progIdx].fProgram));
3645 if (glslCaps->noperspectiveInterpolationSupport()) {
3646 if (const char* extension = glslCaps->noperspectiveInterpolationExte nsionString()) {
3647 fshaderTxt.appendf("#extension %s : require\n", extension);
3648 }
3649 }
3650 if (kSamplerTypes[i] == kSamplerExternal_GrSLType) {
3651 fshaderTxt.appendf("#extension %s : require\n",
3652 glslCaps->externalTextureExtensionString());
3653 }
3654 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *gl slCaps,
3655 &fshaderTxt);
3656 vTexCoord.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier);
3657 vTexCoord.appendDecl(glslCaps, &fshaderTxt);
3658 fshaderTxt.append(";");
3659 uTexture.appendDecl(glslCaps, &fshaderTxt);
3660 fshaderTxt.append(";");
3661 const char* fsOutName;
3662 if (glslCaps->mustDeclareFragmentShaderOutput()) {
3663 oFragColor.appendDecl(glslCaps, &fshaderTxt);
3664 fshaderTxt.append(";");
3665 fsOutName = oFragColor.c_str();
3666 } else {
3667 fsOutName = "gl_FragColor";
3668 }
3669 fshaderTxt.appendf(
3670 "// Copy Program FS\n"
3671 "void main() {"
3672 " %s = %s(u_texture, v_texCoord);"
3673 "}",
3674 fsOutName,
3675 GrGLSLTexture2DFunctionName(kVec2f_GrSLType, kSamplerTypes[i], this- >glslGeneration())
3676 );
3677 3688
3678 GL_CALL_RET(fCopyPrograms[i].fProgram, CreateProgram()); 3689 GL_CALL_RET(fCopyPrograms[progIdx].fTextureUniform,
3679 const char* str; 3690 GetUniformLocation(fCopyPrograms[progIdx].fProgram, "u_texture") );
3680 GrGLint length; 3691 GL_CALL_RET(fCopyPrograms[progIdx].fPosXformUniform,
3692 GetUniformLocation(fCopyPrograms[progIdx].fProgram, "u_posXform" ));
3693 GL_CALL_RET(fCopyPrograms[progIdx].fTexCoordXformUniform,
3694 GetUniformLocation(fCopyPrograms[progIdx].fProgram, "u_texCoordX form"));
3681 3695
3682 str = vshaderTxt.c_str(); 3696 GL_CALL(BindAttribLocation(fCopyPrograms[progIdx].fProgram, 0, "a_vertex"));
3683 length = SkToInt(vshaderTxt.size());
3684 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms [i].fProgram,
3685 GR_GL_VERTEX_SHADER, &str, &length, 1,
3686 &fStats);
3687 3697
3688 str = fshaderTxt.c_str(); 3698 GL_CALL(DeleteShader(vshader));
3689 length = SkToInt(fshaderTxt.size()); 3699 GL_CALL(DeleteShader(fshader));
3690 GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms [i].fProgram,
3691 GR_GL_FRAGMENT_SHADER, &st r, &length, 1,
3692 &fStats);
3693 3700
3694 GL_CALL(LinkProgram(fCopyPrograms[i].fProgram)); 3701 return true;
3695
3696 GL_CALL_RET(fCopyPrograms[i].fTextureUniform,
3697 GetUniformLocation(fCopyPrograms[i].fProgram, "u_texture"));
3698 GL_CALL_RET(fCopyPrograms[i].fPosXformUniform,
3699 GetUniformLocation(fCopyPrograms[i].fProgram, "u_posXform")) ;
3700 GL_CALL_RET(fCopyPrograms[i].fTexCoordXformUniform,
3701 GetUniformLocation(fCopyPrograms[i].fProgram, "u_texCoordXfo rm"));
3702
3703 GL_CALL(BindAttribLocation(fCopyPrograms[i].fProgram, 0, "a_vertex"));
3704
3705 GL_CALL(DeleteShader(vshader));
3706 GL_CALL(DeleteShader(fshader));
3707 }
3708 fCopyProgramArrayBuffer = 0;
3709 GL_CALL(GenBuffers(1, &fCopyProgramArrayBuffer));
3710 fHWGeometryState.setVertexBufferID(this, fCopyProgramArrayBuffer);
3711 static const GrGLfloat vdata[] = {
3712 0, 0,
3713 0, 1,
3714 1, 0,
3715 1, 1
3716 };
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 } 3702 }
3723 3703
3724 void GrGLGpu::createWireRectProgram() { 3704 bool GrGLGpu::createWireRectProgram() {
3705 if (!fWireRectArrayBuffer) {
3706 static const GrGLfloat vdata[] = {
3707 0, 0,
3708 0, 1,
3709 1, 1,
3710 1, 0
3711 };
3712 fWireRectArrayBuffer.reset(GrGLBuffer::Create(this, sizeof(vdata), kVert ex_GrBufferType,
3713 kStatic_GrAccessPattern, v data));
3714 if (!fWireRectArrayBuffer) {
3715 return false;
3716 }
3717 }
3718
3725 SkASSERT(!fWireRectProgram.fProgram); 3719 SkASSERT(!fWireRectProgram.fProgram);
3720 GL_CALL_RET(fWireRectProgram.fProgram, CreateProgram());
3721 if (!fWireRectProgram.fProgram) {
3722 return false;
3723 }
3724
3726 GrGLSLShaderVar uColor("u_color", kVec4f_GrSLType, GrShaderVar::kUniform_Typ eModifier); 3725 GrGLSLShaderVar uColor("u_color", kVec4f_GrSLType, GrShaderVar::kUniform_Typ eModifier);
3727 GrGLSLShaderVar uRect("u_rect", kVec4f_GrSLType, GrShaderVar::kUniform_TypeM odifier); 3726 GrGLSLShaderVar uRect("u_rect", kVec4f_GrSLType, GrShaderVar::kUniform_TypeM odifier);
3728 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute _TypeModifier); 3727 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute _TypeModifier);
3729 const char* version = this->glCaps().glslCaps()->versionDeclString(); 3728 const char* version = this->glCaps().glslCaps()->versionDeclString();
3730 3729
3731 // The rect uniform specifies the rectangle in NDC space as a vec4 (left,top ,right,bottom). The 3730 // The rect uniform specifies the rectangle in NDC space as a vec4 (left,top ,right,bottom). The
3732 // program is used with a vbo containing the unit square. Vertices are compu ted from the rect 3731 // program is used with a vbo containing the unit square. Vertices are compu ted from the rect
3733 // uniform using the 4 vbo vertices. 3732 // uniform using the 4 vbo vertices.
3734 SkString vshaderTxt(version); 3733 SkString vshaderTxt(version);
3735 aVertex.appendDecl(this->glCaps().glslCaps(), &vshaderTxt); 3734 aVertex.appendDecl(this->glCaps().glslCaps(), &vshaderTxt);
(...skipping 27 matching lines...) Expand all
3763 } 3762 }
3764 fshaderTxt.appendf( 3763 fshaderTxt.appendf(
3765 "// Write Rect Program FS\n" 3764 "// Write Rect Program FS\n"
3766 "void main() {" 3765 "void main() {"
3767 " %s = %s;" 3766 " %s = %s;"
3768 "}", 3767 "}",
3769 fsOutName, 3768 fsOutName,
3770 uColor.c_str() 3769 uColor.c_str()
3771 ); 3770 );
3772 3771
3773 GL_CALL_RET(fWireRectProgram.fProgram, CreateProgram());
3774 const char* str; 3772 const char* str;
3775 GrGLint length; 3773 GrGLint length;
3776 3774
3777 str = vshaderTxt.c_str(); 3775 str = vshaderTxt.c_str();
3778 length = SkToInt(vshaderTxt.size()); 3776 length = SkToInt(vshaderTxt.size());
3779 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fWireRectProgram. fProgram, 3777 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fWireRectProgram. fProgram,
3780 GR_GL_VERTEX_SHADER, &str, &le ngth, 1, 3778 GR_GL_VERTEX_SHADER, &str, &le ngth, 1,
3781 &fStats); 3779 &fStats);
3782 3780
3783 str = fshaderTxt.c_str(); 3781 str = fshaderTxt.c_str();
3784 length = SkToInt(fshaderTxt.size()); 3782 length = SkToInt(fshaderTxt.size());
3785 GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fWireRectProgram. fProgram, 3783 GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fWireRectProgram. fProgram,
3786 GR_GL_FRAGMENT_SHADER, &str, & length, 1, 3784 GR_GL_FRAGMENT_SHADER, &str, & length, 1,
3787 &fStats); 3785 &fStats);
3788 3786
3789 GL_CALL(LinkProgram(fWireRectProgram.fProgram)); 3787 GL_CALL(LinkProgram(fWireRectProgram.fProgram));
3790 3788
3791 GL_CALL_RET(fWireRectProgram.fColorUniform, 3789 GL_CALL_RET(fWireRectProgram.fColorUniform,
3792 GetUniformLocation(fWireRectProgram.fProgram, "u_color")); 3790 GetUniformLocation(fWireRectProgram.fProgram, "u_color"));
3793 GL_CALL_RET(fWireRectProgram.fRectUniform, 3791 GL_CALL_RET(fWireRectProgram.fRectUniform,
3794 GetUniformLocation(fWireRectProgram.fProgram, "u_rect")); 3792 GetUniformLocation(fWireRectProgram.fProgram, "u_rect"));
3795 GL_CALL(BindAttribLocation(fWireRectProgram.fProgram, 0, "a_vertex")); 3793 GL_CALL(BindAttribLocation(fWireRectProgram.fProgram, 0, "a_vertex"));
3796 3794
3797 GL_CALL(DeleteShader(vshader)); 3795 GL_CALL(DeleteShader(vshader));
3798 GL_CALL(DeleteShader(fshader)); 3796 GL_CALL(DeleteShader(fshader));
3799 GL_CALL(GenBuffers(1, &fWireRectArrayBuffer)); 3797
3800 fHWGeometryState.setVertexBufferID(this, fWireRectArrayBuffer); 3798 return true;
3801 static const GrGLfloat vdata[] = {
3802 0, 0,
3803 0, 1,
3804 1, 1,
3805 1, 0,
3806 };
3807 GL_ALLOC_CALL(this->glInterface(),
3808 BufferData(GR_GL_ARRAY_BUFFER,
3809 (GrGLsizeiptr) sizeof(vdata),
3810 vdata, // data ptr
3811 GR_GL_STATIC_DRAW));
3812 } 3799 }
3813 3800
3814 void GrGLGpu::drawDebugWireRect(GrRenderTarget* rt, const SkIRect& rect, GrColor color) { 3801 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 3802 // TODO: This should swizzle the output to match dst's config, though it is a debugging
3816 // visualization. 3803 // visualization.
3817 3804
3818 this->handleDirtyContext(); 3805 this->handleDirtyContext();
3819 if (!fWireRectProgram.fProgram) { 3806 if (!fWireRectProgram.fProgram) {
3820 this->createWireRectProgram(); 3807 if (!this->createWireRectProgram()) {
3808 SkDebugf("Failed to create wire rect program.\n");
3809 return;
3810 }
3821 } 3811 }
3822 3812
3823 int w = rt->width(); 3813 int w = rt->width();
3824 int h = rt->height(); 3814 int h = rt->height();
3825 3815
3826 // Compute the edges of the rectangle (top,left,right,bottom) in NDC space. Must consider 3816 // Compute the edges of the rectangle (top,left,right,bottom) in NDC space. Must consider
3827 // whether the render target is flipped or not. 3817 // whether the render target is flipped or not.
3828 GrGLfloat edges[4]; 3818 GrGLfloat edges[4];
3829 edges[0] = SkIntToScalar(rect.fLeft) + 0.5f; 3819 edges[0] = SkIntToScalar(rect.fLeft) + 0.5f;
3830 edges[2] = SkIntToScalar(rect.fRight) - 0.5f; 3820 edges[2] = SkIntToScalar(rect.fRight) - 0.5f;
(...skipping 15 matching lines...) Expand all
3846 channels[1] = GrColorUnpackG(color) * scale255; 3836 channels[1] = GrColorUnpackG(color) * scale255;
3847 channels[2] = GrColorUnpackB(color) * scale255; 3837 channels[2] = GrColorUnpackB(color) * scale255;
3848 channels[3] = GrColorUnpackA(color) * scale255; 3838 channels[3] = GrColorUnpackA(color) * scale255;
3849 3839
3850 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(rt->asRenderTarget() ); 3840 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(rt->asRenderTarget() );
3851 this->flushRenderTarget(glRT, &rect); 3841 this->flushRenderTarget(glRT, &rect);
3852 3842
3853 GL_CALL(UseProgram(fWireRectProgram.fProgram)); 3843 GL_CALL(UseProgram(fWireRectProgram.fProgram));
3854 fHWProgramID = fWireRectProgram.fProgram; 3844 fHWProgramID = fWireRectProgram.fProgram;
3855 3845
3856 fHWGeometryState.setVertexArrayID(this, 0); 3846 fHWVertexArrayState.setVertexArrayID(this, 0);
3857 3847
3858 GrGLAttribArrayState* attribs = 3848 GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray( this);
3859 fHWGeometryState.bindArrayAndBufferToDraw(this, fWireRectArrayBuffer);
3860 attribs->set(this, 0, fWireRectArrayBuffer, kVec2f_GrVertexAttribType, 2 * s izeof(GrGLfloat), 3849 attribs->set(this, 0, fWireRectArrayBuffer, kVec2f_GrVertexAttribType, 2 * s izeof(GrGLfloat),
3861 0); 3850 0);
3862 attribs->disableUnusedArrays(this, 0x1); 3851 attribs->disableUnusedArrays(this, 0x1);
3863 3852
3864 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges)); 3853 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges));
3865 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels)); 3854 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels));
3866 3855
3867 GrXferProcessor::BlendInfo blendInfo; 3856 GrXferProcessor::BlendInfo blendInfo;
3868 blendInfo.reset(); 3857 blendInfo.reset();
3869 this->flushBlend(blendInfo, GrSwizzle::RGBA()); 3858 this->flushBlend(blendInfo, GrSwizzle::RGBA());
3870 this->flushColorWrite(true); 3859 this->flushColorWrite(true);
3871 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); 3860 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace);
3872 this->flushHWAAState(glRT, false, false); 3861 this->flushHWAAState(glRT, false, false);
3873 this->disableScissor(); 3862 this->disableScissor();
3874 GrStencilSettings stencil; 3863 GrStencilSettings stencil;
3875 stencil.setDisabled(); 3864 stencil.setDisabled();
3876 this->flushStencil(stencil); 3865 this->flushStencil(stencil);
3877 3866
3878 GL_CALL(DrawArrays(GR_GL_LINE_LOOP, 0, 4)); 3867 GL_CALL(DrawArrays(GR_GL_LINE_LOOP, 0, 4));
3879 } 3868 }
3880 3869
3881 3870
3882 void GrGLGpu::copySurfaceAsDraw(GrSurface* dst, 3871 bool GrGLGpu::copySurfaceAsDraw(GrSurface* dst,
3883 GrSurface* src, 3872 GrSurface* src,
3884 const SkIRect& srcRect, 3873 const SkIRect& srcRect,
3885 const SkIPoint& dstPoint) { 3874 const SkIPoint& dstPoint) {
3875 GrGLTexture* srcTex = static_cast<GrGLTexture*>(src->asTexture());
3876 int progIdx = TextureTargetToCopyProgramIdx(srcTex->target());
3877
3878 if (!fCopyPrograms[progIdx].fProgram) {
3879 if (!this->createCopyProgram(progIdx)) {
3880 SkDebugf("Failed to create copy program.\n");
3881 return false;
3882 }
3883 }
3884
3886 int w = srcRect.width(); 3885 int w = srcRect.width();
3887 int h = srcRect.height(); 3886 int h = srcRect.height();
3888 3887
3889 GrGLTexture* srcTex = static_cast<GrGLTexture*>(src->asTexture());
3890 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone_Fil terMode); 3888 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone_Fil terMode);
3891 this->bindTexture(0, params, true, srcTex); 3889 this->bindTexture(0, params, true, srcTex);
3892 3890
3893 GrGLIRect dstVP; 3891 GrGLIRect dstVP;
3894 this->bindSurfaceFBOForCopy(dst, GR_GL_FRAMEBUFFER, &dstVP, kDst_TempFBOTarg et); 3892 this->bindSurfaceFBOForCopy(dst, GR_GL_FRAMEBUFFER, &dstVP, kDst_TempFBOTarg et);
3895 this->flushViewport(dstVP); 3893 this->flushViewport(dstVP);
3896 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; 3894 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
3897 3895
3898 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, w, h); 3896 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, w, h);
3899 3897
3900 int progIdx = TextureTargetToCopyProgramIdx(srcTex->target());
3901
3902 GL_CALL(UseProgram(fCopyPrograms[progIdx].fProgram)); 3898 GL_CALL(UseProgram(fCopyPrograms[progIdx].fProgram));
3903 fHWProgramID = fCopyPrograms[progIdx].fProgram; 3899 fHWProgramID = fCopyPrograms[progIdx].fProgram;
3904 3900
3905 fHWGeometryState.setVertexArrayID(this, 0); 3901 fHWVertexArrayState.setVertexArrayID(this, 0);
3906 3902
3907 GrGLAttribArrayState* attribs = 3903 GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray( this);
3908 fHWGeometryState.bindArrayAndBufferToDraw(this, fCopyProgramArrayBuffer) ;
3909 attribs->set(this, 0, fCopyProgramArrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrGLfloat), 3904 attribs->set(this, 0, fCopyProgramArrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrGLfloat),
3910 0); 3905 0);
3911 attribs->disableUnusedArrays(this, 0x1); 3906 attribs->disableUnusedArrays(this, 0x1);
3912 3907
3913 // dst rect edges in NDC (-1 to 1) 3908 // dst rect edges in NDC (-1 to 1)
3914 int dw = dst->width(); 3909 int dw = dst->width();
3915 int dh = dst->height(); 3910 int dh = dst->height();
3916 GrGLfloat dx0 = 2.f * dstPoint.fX / dw - 1.f; 3911 GrGLfloat dx0 = 2.f * dstPoint.fX / dw - 1.f;
3917 GrGLfloat dx1 = 2.f * (dstPoint.fX + w) / dw - 1.f; 3912 GrGLfloat dx1 = 2.f * (dstPoint.fX + w) / dw - 1.f;
3918 GrGLfloat dy0 = 2.f * dstPoint.fY / dh - 1.f; 3913 GrGLfloat dy0 = 2.f * dstPoint.fY / dh - 1.f;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3954 this->flushHWAAState(nullptr, false, false); 3949 this->flushHWAAState(nullptr, false, false);
3955 this->disableScissor(); 3950 this->disableScissor();
3956 GrStencilSettings stencil; 3951 GrStencilSettings stencil;
3957 stencil.setDisabled(); 3952 stencil.setDisabled();
3958 this->flushStencil(stencil); 3953 this->flushStencil(stencil);
3959 3954
3960 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); 3955 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4));
3961 this->unbindTextureFBOForCopy(GR_GL_FRAMEBUFFER, dst); 3956 this->unbindTextureFBOForCopy(GR_GL_FRAMEBUFFER, dst);
3962 this->didWriteToSurface(dst, &dstRect); 3957 this->didWriteToSurface(dst, &dstRect);
3963 3958
3959 return true;
3964 } 3960 }
3965 3961
3966 void GrGLGpu::copySurfaceAsCopyTexSubImage(GrSurface* dst, 3962 void GrGLGpu::copySurfaceAsCopyTexSubImage(GrSurface* dst,
3967 GrSurface* src, 3963 GrSurface* src,
3968 const SkIRect& srcRect, 3964 const SkIRect& srcRect,
3969 const SkIPoint& dstPoint) { 3965 const SkIPoint& dstPoint) {
3970 SkASSERT(can_copy_texsubimage(dst, src, this)); 3966 SkASSERT(can_copy_texsubimage(dst, src, this));
3971 GrGLIRect srcVP; 3967 GrGLIRect srcVP;
3972 this->bindSurfaceFBOForCopy(src, GR_GL_FRAMEBUFFER, &srcVP, kSrc_TempFBOTarg et); 3968 this->bindSurfaceFBOForCopy(src, GR_GL_FRAMEBUFFER, &srcVP, kSrc_TempFBOTarg et);
3973 GrGLTexture* dstTex = static_cast<GrGLTexture *>(dst->asTexture()); 3969 GrGLTexture* dstTex = static_cast<GrGLTexture *>(dst->asTexture());
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4191 #ifndef SK_IGNORE_GL_TEXTURE_TARGET 4187 #ifndef SK_IGNORE_GL_TEXTURE_TARGET
4192 delete info; 4188 delete info;
4193 #endif 4189 #endif
4194 } 4190 }
4195 4191
4196 void GrGLGpu::resetShaderCacheForTesting() const { 4192 void GrGLGpu::resetShaderCacheForTesting() const {
4197 fProgramCache->abandon(); 4193 fProgramCache->abandon();
4198 } 4194 }
4199 4195
4200 /////////////////////////////////////////////////////////////////////////////// 4196 ///////////////////////////////////////////////////////////////////////////////
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 4197
4216 GrGLAttribArrayState* GrGLGpu::HWGeometryState::bindArrayAndBufferToDraw(GrGLGpu * gpu, 4198 GrGLAttribArrayState* GrGLGpu::HWVertexArrayState::bindInternalVertexArray(GrGLG pu* gpu,
4217 GrGLuin t vbufferID) { 4199 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; 4200 GrGLAttribArrayState* attribState;
4231 4201
4232 if (gpu->glCaps().isCoreProfile() && 0 != vbufferID) { 4202 if (gpu->glCaps().isCoreProfile()) {
4233 if (!fVBOVertexArray) { 4203 if (!fCoreProfileVertexArray) {
4234 GrGLuint arrayID; 4204 GrGLuint arrayID;
4235 GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID)); 4205 GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID));
4236 int attrCount = gpu->glCaps().maxVertexAttributes(); 4206 int attrCount = gpu->glCaps().maxVertexAttributes();
4237 fVBOVertexArray = new GrGLVertexArray(arrayID, attrCount); 4207 fCoreProfileVertexArray = new GrGLVertexArray(arrayID, attrCount);
4238 } 4208 }
4239 if (ibufferID) { 4209 if (ibuf) {
4240 attribState = fVBOVertexArray->bindWithIndexBuffer(gpu, *ibufferID); 4210 attribState = fCoreProfileVertexArray->bindWithIndexBuffer(gpu, ibuf );
4241 } else { 4211 } else {
4242 attribState = fVBOVertexArray->bind(gpu); 4212 attribState = fCoreProfileVertexArray->bind(gpu);
4243 } 4213 }
4244 } else { 4214 } else {
4245 if (ibufferID) { 4215 if (ibuf) {
4246 this->setIndexBufferIDOnDefaultVertexArray(gpu, *ibufferID); 4216 // bindBuffer implicitly binds VAO 0 when binding an index buffer.
4217 gpu->bindBuffer(kIndex_GrBufferType, ibuf);
4247 } else { 4218 } else {
4248 this->setVertexArrayID(gpu, 0); 4219 this->setVertexArrayID(gpu, 0);
4249 } 4220 }
4250 int attrCount = gpu->glCaps().maxVertexAttributes(); 4221 int attrCount = gpu->glCaps().maxVertexAttributes();
4251 if (fDefaultVertexArrayAttribState.count() != attrCount) { 4222 if (fDefaultVertexArrayAttribState.count() != attrCount) {
4252 fDefaultVertexArrayAttribState.resize(attrCount); 4223 fDefaultVertexArrayAttribState.resize(attrCount);
4253 } 4224 }
4254 attribState = &fDefaultVertexArrayAttribState; 4225 attribState = &fDefaultVertexArrayAttribState;
4255 } 4226 }
4256 return attribState; 4227 return attribState;
4257 } 4228 }
4258 4229
4259 bool GrGLGpu::onMakeCopyForTextureParams(GrTexture* texture, const GrTexturePara ms& textureParams, 4230 bool GrGLGpu::onMakeCopyForTextureParams(GrTexture* texture, const GrTexturePara ms& textureParams,
4260 GrTextureProducer::CopyParams* copyPara ms) const { 4231 GrTextureProducer::CopyParams* copyPara ms) const {
4261 if (textureParams.isTiled() || 4232 if (textureParams.isTiled() ||
4262 GrTextureParams::kMipMap_FilterMode == textureParams.filterMode()) { 4233 GrTextureParams::kMipMap_FilterMode == textureParams.filterMode()) {
4263 GrGLTexture* glTexture = static_cast<GrGLTexture*>(texture); 4234 GrGLTexture* glTexture = static_cast<GrGLTexture*>(texture);
4264 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || 4235 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() ||
4265 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { 4236 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) {
4266 copyParams->fFilter = GrTextureParams::kNone_FilterMode; 4237 copyParams->fFilter = GrTextureParams::kNone_FilterMode;
4267 copyParams->fWidth = texture->width(); 4238 copyParams->fWidth = texture->width();
4268 copyParams->fHeight = texture->height(); 4239 copyParams->fHeight = texture->height();
4269 return true; 4240 return true;
4270 } 4241 }
4271 } 4242 }
4272 return false; 4243 return false;
4273 } 4244 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLVertexArray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698