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

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

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