180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2012 Google Inc. 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "GrBufferObj.h" 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1158190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergervoid GrBufferObj::allocate(GrGLsizeiptr size, const GrGLchar *dataPtr) { 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrAlwaysAssert(size >= 0); 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // delete pre-existing data 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru delete[] fDataPtr; 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fSize = size; 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDataPtr = new GrGLchar[size]; 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (dataPtr) { 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru memcpy(fDataPtr, dataPtr, fSize); 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // TODO: w/ no dataPtr the data is unitialized - this could be tracked 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid GrBufferObj::deleteAction() { 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // buffers are automatically unmapped when deleted 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->resetMapped(); 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->INHERITED::deleteAction(); 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 32