GrGLBuffer::GrGLBuffer(GrGLGpu* gpu, size_t size, GrGpuBufferType intendedType, GrAccessPattern accessPattern, const void* data) : INHERITED(gpu, size, intendedType, accessPattern) , fIntendedType(intendedType) , fBufferID(0) , fUsage(gr_to_gl_access_pattern(intendedType, accessPattern)) , fGLSizeInBytes(0) , fHasAttachedToTexture(false) { GL_CALL(GenBuffers(1, &fBufferID)); if (fBufferID) { GrGLenum target = gpu->bindBuffer(fIntendedType, this); CLEAR_ERROR_BEFORE_ALLOC(gpu->glInterface()); // make sure driver can allocate memory for this buffer GL_ALLOC_CALL(gpu->glInterface(), BufferData(target, (GrGLsizeiptr) size, data, fUsage)); if (CHECK_ALLOC_ERROR(gpu->glInterface()) != GR_GL_NO_ERROR) { GL_CALL(DeleteBuffers(1, &fBufferID)); fBufferID = 0; } else { fGLSizeInBytes = size; } } VALIDATE(); this->registerWithCache(SkBudgeted::kYes); if (!fBufferID) { this->resourcePriv().removeScratchKey(); } }
GrGLBuffer::GrGLBuffer(GrGLGpu* gpu, size_t size, GrBufferType intendedType, GrAccessPattern accessPattern, bool cpuBacked, const void* data) : INHERITED(gpu, size, intendedType, accessPattern, cpuBacked), fCPUData(nullptr), fIntendedType(intendedType), fBufferID(0), fSizeInBytes(size), fUsage(gr_to_gl_access_pattern(intendedType, accessPattern)), fGLSizeInBytes(0), fHasAttachedToTexture(false) { if (this->isCPUBacked()) { // Core profile uses vertex array objects, which disallow client side arrays. SkASSERT(!gpu->glCaps().isCoreProfile()); if (gpu->caps()->mustClearUploadedBufferData()) { fCPUData = sk_calloc_throw(fSizeInBytes); } else { fCPUData = sk_malloc_flags(fSizeInBytes, SK_MALLOC_THROW); } if (data) { memcpy(fCPUData, data, fSizeInBytes); } } else { GL_CALL(GenBuffers(1, &fBufferID)); if (fBufferID) { GrGLenum target = gpu->bindBuffer(fIntendedType, this); CLEAR_ERROR_BEFORE_ALLOC(gpu->glInterface()); // make sure driver can allocate memory for this buffer GL_ALLOC_CALL(gpu->glInterface(), BufferData(target, (GrGLsizeiptr) fSizeInBytes, data, fUsage)); if (CHECK_ALLOC_ERROR(gpu->glInterface()) != GR_GL_NO_ERROR) { GL_CALL(DeleteBuffers(1, &fBufferID)); fBufferID = 0; } else { fGLSizeInBytes = fSizeInBytes; } } } VALIDATE(); this->registerWithCache(SkBudgeted::kYes); }