gfx/skia/trunk/src/gpu/GrGpu.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2010 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "GrGpu.h"
michael@0 11
michael@0 12 #include "GrBufferAllocPool.h"
michael@0 13 #include "GrContext.h"
michael@0 14 #include "GrDrawTargetCaps.h"
michael@0 15 #include "GrIndexBuffer.h"
michael@0 16 #include "GrStencilBuffer.h"
michael@0 17 #include "GrVertexBuffer.h"
michael@0 18
michael@0 19 // probably makes no sense for this to be less than a page
michael@0 20 static const size_t VERTEX_POOL_VB_SIZE = 1 << 18;
michael@0 21 static const int VERTEX_POOL_VB_COUNT = 4;
michael@0 22 static const size_t INDEX_POOL_IB_SIZE = 1 << 16;
michael@0 23 static const int INDEX_POOL_IB_COUNT = 4;
michael@0 24
michael@0 25 ////////////////////////////////////////////////////////////////////////////////
michael@0 26
michael@0 27 #define DEBUG_INVAL_BUFFER 0xdeadcafe
michael@0 28 #define DEBUG_INVAL_START_IDX -1
michael@0 29
michael@0 30 GrGpu::GrGpu(GrContext* context)
michael@0 31 : GrDrawTarget(context)
michael@0 32 , fResetTimestamp(kExpiredTimestamp+1)
michael@0 33 , fResetBits(kAll_GrBackendState)
michael@0 34 , fVertexPool(NULL)
michael@0 35 , fIndexPool(NULL)
michael@0 36 , fVertexPoolUseCnt(0)
michael@0 37 , fIndexPoolUseCnt(0)
michael@0 38 , fQuadIndexBuffer(NULL) {
michael@0 39
michael@0 40 fClipMaskManager.setGpu(this);
michael@0 41
michael@0 42 fGeomPoolStateStack.push_back();
michael@0 43 #ifdef SK_DEBUG
michael@0 44 GeometryPoolState& poolState = fGeomPoolStateStack.back();
michael@0 45 poolState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
michael@0 46 poolState.fPoolStartVertex = DEBUG_INVAL_START_IDX;
michael@0 47 poolState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
michael@0 48 poolState.fPoolStartIndex = DEBUG_INVAL_START_IDX;
michael@0 49 #endif
michael@0 50 }
michael@0 51
michael@0 52 GrGpu::~GrGpu() {
michael@0 53 this->releaseResources();
michael@0 54 }
michael@0 55
michael@0 56 void GrGpu::abandonResources() {
michael@0 57
michael@0 58 fClipMaskManager.releaseResources();
michael@0 59
michael@0 60 while (NULL != fResourceList.head()) {
michael@0 61 fResourceList.head()->abandon();
michael@0 62 }
michael@0 63
michael@0 64 SkASSERT(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
michael@0 65 SkSafeSetNull(fQuadIndexBuffer);
michael@0 66 delete fVertexPool;
michael@0 67 fVertexPool = NULL;
michael@0 68 delete fIndexPool;
michael@0 69 fIndexPool = NULL;
michael@0 70 }
michael@0 71
michael@0 72 void GrGpu::releaseResources() {
michael@0 73
michael@0 74 fClipMaskManager.releaseResources();
michael@0 75
michael@0 76 while (NULL != fResourceList.head()) {
michael@0 77 fResourceList.head()->release();
michael@0 78 }
michael@0 79
michael@0 80 SkASSERT(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
michael@0 81 SkSafeSetNull(fQuadIndexBuffer);
michael@0 82 delete fVertexPool;
michael@0 83 fVertexPool = NULL;
michael@0 84 delete fIndexPool;
michael@0 85 fIndexPool = NULL;
michael@0 86 }
michael@0 87
michael@0 88 void GrGpu::insertResource(GrResource* resource) {
michael@0 89 SkASSERT(NULL != resource);
michael@0 90 SkASSERT(this == resource->getGpu());
michael@0 91
michael@0 92 fResourceList.addToHead(resource);
michael@0 93 }
michael@0 94
michael@0 95 void GrGpu::removeResource(GrResource* resource) {
michael@0 96 SkASSERT(NULL != resource);
michael@0 97 SkASSERT(this == resource->getGpu());
michael@0 98
michael@0 99 fResourceList.remove(resource);
michael@0 100 }
michael@0 101
michael@0 102
michael@0 103 void GrGpu::unimpl(const char msg[]) {
michael@0 104 #ifdef SK_DEBUG
michael@0 105 GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg);
michael@0 106 #endif
michael@0 107 }
michael@0 108
michael@0 109 ////////////////////////////////////////////////////////////////////////////////
michael@0 110
michael@0 111 GrTexture* GrGpu::createTexture(const GrTextureDesc& desc,
michael@0 112 const void* srcData, size_t rowBytes) {
michael@0 113 if (kUnknown_GrPixelConfig == desc.fConfig) {
michael@0 114 return NULL;
michael@0 115 }
michael@0 116 if ((desc.fFlags & kRenderTarget_GrTextureFlagBit) &&
michael@0 117 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
michael@0 118 return NULL;
michael@0 119 }
michael@0 120
michael@0 121 this->handleDirtyContext();
michael@0 122 GrTexture* tex = this->onCreateTexture(desc, srcData, rowBytes);
michael@0 123 if (NULL != tex &&
michael@0 124 (kRenderTarget_GrTextureFlagBit & desc.fFlags) &&
michael@0 125 !(kNoStencil_GrTextureFlagBit & desc.fFlags)) {
michael@0 126 SkASSERT(NULL != tex->asRenderTarget());
michael@0 127 // TODO: defer this and attach dynamically
michael@0 128 if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget())) {
michael@0 129 tex->unref();
michael@0 130 return NULL;
michael@0 131 }
michael@0 132 }
michael@0 133 return tex;
michael@0 134 }
michael@0 135
michael@0 136 bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) {
michael@0 137 SkASSERT(NULL == rt->getStencilBuffer());
michael@0 138 GrStencilBuffer* sb =
michael@0 139 this->getContext()->findStencilBuffer(rt->width(),
michael@0 140 rt->height(),
michael@0 141 rt->numSamples());
michael@0 142 if (NULL != sb) {
michael@0 143 rt->setStencilBuffer(sb);
michael@0 144 bool attached = this->attachStencilBufferToRenderTarget(sb, rt);
michael@0 145 if (!attached) {
michael@0 146 rt->setStencilBuffer(NULL);
michael@0 147 }
michael@0 148 return attached;
michael@0 149 }
michael@0 150 if (this->createStencilBufferForRenderTarget(rt,
michael@0 151 rt->width(), rt->height())) {
michael@0 152 // Right now we're clearing the stencil buffer here after it is
michael@0 153 // attached to an RT for the first time. When we start matching
michael@0 154 // stencil buffers with smaller color targets this will no longer
michael@0 155 // be correct because it won't be guaranteed to clear the entire
michael@0 156 // sb.
michael@0 157 // We used to clear down in the GL subclass using a special purpose
michael@0 158 // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported
michael@0 159 // FBO status.
michael@0 160 GrDrawState::AutoRenderTargetRestore artr(this->drawState(), rt);
michael@0 161 this->clearStencil();
michael@0 162 return true;
michael@0 163 } else {
michael@0 164 return false;
michael@0 165 }
michael@0 166 }
michael@0 167
michael@0 168 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc) {
michael@0 169 this->handleDirtyContext();
michael@0 170 GrTexture* tex = this->onWrapBackendTexture(desc);
michael@0 171 if (NULL == tex) {
michael@0 172 return NULL;
michael@0 173 }
michael@0 174 // TODO: defer this and attach dynamically
michael@0 175 GrRenderTarget* tgt = tex->asRenderTarget();
michael@0 176 if (NULL != tgt &&
michael@0 177 !this->attachStencilBufferToRenderTarget(tgt)) {
michael@0 178 tex->unref();
michael@0 179 return NULL;
michael@0 180 } else {
michael@0 181 return tex;
michael@0 182 }
michael@0 183 }
michael@0 184
michael@0 185 GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) {
michael@0 186 this->handleDirtyContext();
michael@0 187 return this->onWrapBackendRenderTarget(desc);
michael@0 188 }
michael@0 189
michael@0 190 GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) {
michael@0 191 this->handleDirtyContext();
michael@0 192 return this->onCreateVertexBuffer(size, dynamic);
michael@0 193 }
michael@0 194
michael@0 195 GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) {
michael@0 196 this->handleDirtyContext();
michael@0 197 return this->onCreateIndexBuffer(size, dynamic);
michael@0 198 }
michael@0 199
michael@0 200 GrPath* GrGpu::createPath(const SkPath& path, const SkStrokeRec& stroke) {
michael@0 201 SkASSERT(this->caps()->pathRenderingSupport());
michael@0 202 this->handleDirtyContext();
michael@0 203 return this->onCreatePath(path, stroke);
michael@0 204 }
michael@0 205
michael@0 206 void GrGpu::clear(const SkIRect* rect,
michael@0 207 GrColor color,
michael@0 208 bool canIgnoreRect,
michael@0 209 GrRenderTarget* renderTarget) {
michael@0 210 GrDrawState::AutoRenderTargetRestore art;
michael@0 211 if (NULL != renderTarget) {
michael@0 212 art.set(this->drawState(), renderTarget);
michael@0 213 }
michael@0 214 if (NULL == this->getDrawState().getRenderTarget()) {
michael@0 215 SkASSERT(0);
michael@0 216 return;
michael@0 217 }
michael@0 218 this->handleDirtyContext();
michael@0 219 this->onClear(rect, color, canIgnoreRect);
michael@0 220 }
michael@0 221
michael@0 222 void GrGpu::forceRenderTargetFlush() {
michael@0 223 this->handleDirtyContext();
michael@0 224 this->onForceRenderTargetFlush();
michael@0 225 }
michael@0 226
michael@0 227 bool GrGpu::readPixels(GrRenderTarget* target,
michael@0 228 int left, int top, int width, int height,
michael@0 229 GrPixelConfig config, void* buffer,
michael@0 230 size_t rowBytes) {
michael@0 231 this->handleDirtyContext();
michael@0 232 return this->onReadPixels(target, left, top, width, height,
michael@0 233 config, buffer, rowBytes);
michael@0 234 }
michael@0 235
michael@0 236 bool GrGpu::writeTexturePixels(GrTexture* texture,
michael@0 237 int left, int top, int width, int height,
michael@0 238 GrPixelConfig config, const void* buffer,
michael@0 239 size_t rowBytes) {
michael@0 240 this->handleDirtyContext();
michael@0 241 return this->onWriteTexturePixels(texture, left, top, width, height,
michael@0 242 config, buffer, rowBytes);
michael@0 243 }
michael@0 244
michael@0 245 void GrGpu::resolveRenderTarget(GrRenderTarget* target) {
michael@0 246 SkASSERT(target);
michael@0 247 this->handleDirtyContext();
michael@0 248 this->onResolveRenderTarget(target);
michael@0 249 }
michael@0 250
michael@0 251 static const GrStencilSettings& winding_path_stencil_settings() {
michael@0 252 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
michael@0 253 kIncClamp_StencilOp,
michael@0 254 kIncClamp_StencilOp,
michael@0 255 kAlwaysIfInClip_StencilFunc,
michael@0 256 0xFFFF, 0xFFFF, 0xFFFF);
michael@0 257 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
michael@0 258 }
michael@0 259
michael@0 260 static const GrStencilSettings& even_odd_path_stencil_settings() {
michael@0 261 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
michael@0 262 kInvert_StencilOp,
michael@0 263 kInvert_StencilOp,
michael@0 264 kAlwaysIfInClip_StencilFunc,
michael@0 265 0xFFFF, 0xFFFF, 0xFFFF);
michael@0 266 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
michael@0 267 }
michael@0 268
michael@0 269 void GrGpu::getPathStencilSettingsForFillType(SkPath::FillType fill, GrStencilSettings* outStencilSettings) {
michael@0 270
michael@0 271 switch (fill) {
michael@0 272 default:
michael@0 273 GrCrash("Unexpected path fill.");
michael@0 274 /* fallthrough */;
michael@0 275 case SkPath::kWinding_FillType:
michael@0 276 case SkPath::kInverseWinding_FillType:
michael@0 277 *outStencilSettings = winding_path_stencil_settings();
michael@0 278 break;
michael@0 279 case SkPath::kEvenOdd_FillType:
michael@0 280 case SkPath::kInverseEvenOdd_FillType:
michael@0 281 *outStencilSettings = even_odd_path_stencil_settings();
michael@0 282 break;
michael@0 283 }
michael@0 284 fClipMaskManager.adjustPathStencilParams(outStencilSettings);
michael@0 285 }
michael@0 286
michael@0 287
michael@0 288 ////////////////////////////////////////////////////////////////////////////////
michael@0 289
michael@0 290 static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1;
michael@0 291
michael@0 292 GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535);
michael@0 293
michael@0 294 static inline void fill_indices(uint16_t* indices, int quadCount) {
michael@0 295 for (int i = 0; i < quadCount; ++i) {
michael@0 296 indices[6 * i + 0] = 4 * i + 0;
michael@0 297 indices[6 * i + 1] = 4 * i + 1;
michael@0 298 indices[6 * i + 2] = 4 * i + 2;
michael@0 299 indices[6 * i + 3] = 4 * i + 0;
michael@0 300 indices[6 * i + 4] = 4 * i + 2;
michael@0 301 indices[6 * i + 5] = 4 * i + 3;
michael@0 302 }
michael@0 303 }
michael@0 304
michael@0 305 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const {
michael@0 306 if (NULL == fQuadIndexBuffer) {
michael@0 307 static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS;
michael@0 308 GrGpu* me = const_cast<GrGpu*>(this);
michael@0 309 fQuadIndexBuffer = me->createIndexBuffer(SIZE, false);
michael@0 310 if (NULL != fQuadIndexBuffer) {
michael@0 311 uint16_t* indices = (uint16_t*)fQuadIndexBuffer->lock();
michael@0 312 if (NULL != indices) {
michael@0 313 fill_indices(indices, MAX_QUADS);
michael@0 314 fQuadIndexBuffer->unlock();
michael@0 315 } else {
michael@0 316 indices = (uint16_t*)sk_malloc_throw(SIZE);
michael@0 317 fill_indices(indices, MAX_QUADS);
michael@0 318 if (!fQuadIndexBuffer->updateData(indices, SIZE)) {
michael@0 319 fQuadIndexBuffer->unref();
michael@0 320 fQuadIndexBuffer = NULL;
michael@0 321 GrCrash("Can't get indices into buffer!");
michael@0 322 }
michael@0 323 sk_free(indices);
michael@0 324 }
michael@0 325 }
michael@0 326 }
michael@0 327
michael@0 328 return fQuadIndexBuffer;
michael@0 329 }
michael@0 330
michael@0 331 ////////////////////////////////////////////////////////////////////////////////
michael@0 332
michael@0 333 bool GrGpu::setupClipAndFlushState(DrawType type, const GrDeviceCoordTexture* dstCopy,
michael@0 334 GrDrawState::AutoRestoreEffects* are,
michael@0 335 const SkRect* devBounds) {
michael@0 336 if (!fClipMaskManager.setupClipping(this->getClip(), are, devBounds)) {
michael@0 337 return false;
michael@0 338 }
michael@0 339
michael@0 340 if (!this->flushGraphicsState(type, dstCopy)) {
michael@0 341 return false;
michael@0 342 }
michael@0 343
michael@0 344 return true;
michael@0 345 }
michael@0 346
michael@0 347 ////////////////////////////////////////////////////////////////////////////////
michael@0 348
michael@0 349 void GrGpu::geometrySourceWillPush() {
michael@0 350 const GeometrySrcState& geoSrc = this->getGeomSrc();
michael@0 351 if (kArray_GeometrySrcType == geoSrc.fVertexSrc ||
michael@0 352 kReserved_GeometrySrcType == geoSrc.fVertexSrc) {
michael@0 353 this->finalizeReservedVertices();
michael@0 354 }
michael@0 355 if (kArray_GeometrySrcType == geoSrc.fIndexSrc ||
michael@0 356 kReserved_GeometrySrcType == geoSrc.fIndexSrc) {
michael@0 357 this->finalizeReservedIndices();
michael@0 358 }
michael@0 359 GeometryPoolState& newState = fGeomPoolStateStack.push_back();
michael@0 360 #ifdef SK_DEBUG
michael@0 361 newState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
michael@0 362 newState.fPoolStartVertex = DEBUG_INVAL_START_IDX;
michael@0 363 newState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
michael@0 364 newState.fPoolStartIndex = DEBUG_INVAL_START_IDX;
michael@0 365 #else
michael@0 366 (void) newState; // silence compiler warning
michael@0 367 #endif
michael@0 368 }
michael@0 369
michael@0 370 void GrGpu::geometrySourceWillPop(const GeometrySrcState& restoredState) {
michael@0 371 // if popping last entry then pops are unbalanced with pushes
michael@0 372 SkASSERT(fGeomPoolStateStack.count() > 1);
michael@0 373 fGeomPoolStateStack.pop_back();
michael@0 374 }
michael@0 375
michael@0 376 void GrGpu::onDraw(const DrawInfo& info) {
michael@0 377 this->handleDirtyContext();
michael@0 378 GrDrawState::AutoRestoreEffects are;
michael@0 379 if (!this->setupClipAndFlushState(PrimTypeToDrawType(info.primitiveType()),
michael@0 380 info.getDstCopy(), &are, info.getDevBounds())) {
michael@0 381 return;
michael@0 382 }
michael@0 383 this->onGpuDraw(info);
michael@0 384 }
michael@0 385
michael@0 386 void GrGpu::onStencilPath(const GrPath* path, SkPath::FillType fill) {
michael@0 387 this->handleDirtyContext();
michael@0 388
michael@0 389 GrDrawState::AutoRestoreEffects are;
michael@0 390 if (!this->setupClipAndFlushState(kStencilPath_DrawType, NULL, &are, NULL)) {
michael@0 391 return;
michael@0 392 }
michael@0 393
michael@0 394 this->onGpuStencilPath(path, fill);
michael@0 395 }
michael@0 396
michael@0 397
michael@0 398 void GrGpu::onDrawPath(const GrPath* path, SkPath::FillType fill,
michael@0 399 const GrDeviceCoordTexture* dstCopy) {
michael@0 400 this->handleDirtyContext();
michael@0 401
michael@0 402 drawState()->setDefaultVertexAttribs();
michael@0 403
michael@0 404 GrDrawState::AutoRestoreEffects are;
michael@0 405 if (!this->setupClipAndFlushState(kDrawPath_DrawType, dstCopy, &are, NULL)) {
michael@0 406 return;
michael@0 407 }
michael@0 408
michael@0 409 this->onGpuDrawPath(path, fill);
michael@0 410 }
michael@0 411
michael@0 412 void GrGpu::finalizeReservedVertices() {
michael@0 413 SkASSERT(NULL != fVertexPool);
michael@0 414 fVertexPool->unlock();
michael@0 415 }
michael@0 416
michael@0 417 void GrGpu::finalizeReservedIndices() {
michael@0 418 SkASSERT(NULL != fIndexPool);
michael@0 419 fIndexPool->unlock();
michael@0 420 }
michael@0 421
michael@0 422 void GrGpu::prepareVertexPool() {
michael@0 423 if (NULL == fVertexPool) {
michael@0 424 SkASSERT(0 == fVertexPoolUseCnt);
michael@0 425 fVertexPool = SkNEW_ARGS(GrVertexBufferAllocPool, (this, true,
michael@0 426 VERTEX_POOL_VB_SIZE,
michael@0 427 VERTEX_POOL_VB_COUNT));
michael@0 428 fVertexPool->releaseGpuRef();
michael@0 429 } else if (!fVertexPoolUseCnt) {
michael@0 430 // the client doesn't have valid data in the pool
michael@0 431 fVertexPool->reset();
michael@0 432 }
michael@0 433 }
michael@0 434
michael@0 435 void GrGpu::prepareIndexPool() {
michael@0 436 if (NULL == fIndexPool) {
michael@0 437 SkASSERT(0 == fIndexPoolUseCnt);
michael@0 438 fIndexPool = SkNEW_ARGS(GrIndexBufferAllocPool, (this, true,
michael@0 439 INDEX_POOL_IB_SIZE,
michael@0 440 INDEX_POOL_IB_COUNT));
michael@0 441 fIndexPool->releaseGpuRef();
michael@0 442 } else if (!fIndexPoolUseCnt) {
michael@0 443 // the client doesn't have valid data in the pool
michael@0 444 fIndexPool->reset();
michael@0 445 }
michael@0 446 }
michael@0 447
michael@0 448 bool GrGpu::onReserveVertexSpace(size_t vertexSize,
michael@0 449 int vertexCount,
michael@0 450 void** vertices) {
michael@0 451 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
michael@0 452
michael@0 453 SkASSERT(vertexCount > 0);
michael@0 454 SkASSERT(NULL != vertices);
michael@0 455
michael@0 456 this->prepareVertexPool();
michael@0 457
michael@0 458 *vertices = fVertexPool->makeSpace(vertexSize,
michael@0 459 vertexCount,
michael@0 460 &geomPoolState.fPoolVertexBuffer,
michael@0 461 &geomPoolState.fPoolStartVertex);
michael@0 462 if (NULL == *vertices) {
michael@0 463 return false;
michael@0 464 }
michael@0 465 ++fVertexPoolUseCnt;
michael@0 466 return true;
michael@0 467 }
michael@0 468
michael@0 469 bool GrGpu::onReserveIndexSpace(int indexCount, void** indices) {
michael@0 470 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
michael@0 471
michael@0 472 SkASSERT(indexCount > 0);
michael@0 473 SkASSERT(NULL != indices);
michael@0 474
michael@0 475 this->prepareIndexPool();
michael@0 476
michael@0 477 *indices = fIndexPool->makeSpace(indexCount,
michael@0 478 &geomPoolState.fPoolIndexBuffer,
michael@0 479 &geomPoolState.fPoolStartIndex);
michael@0 480 if (NULL == *indices) {
michael@0 481 return false;
michael@0 482 }
michael@0 483 ++fIndexPoolUseCnt;
michael@0 484 return true;
michael@0 485 }
michael@0 486
michael@0 487 void GrGpu::releaseReservedVertexSpace() {
michael@0 488 const GeometrySrcState& geoSrc = this->getGeomSrc();
michael@0 489 SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc);
michael@0 490 size_t bytes = geoSrc.fVertexCount * geoSrc.fVertexSize;
michael@0 491 fVertexPool->putBack(bytes);
michael@0 492 --fVertexPoolUseCnt;
michael@0 493 }
michael@0 494
michael@0 495 void GrGpu::releaseReservedIndexSpace() {
michael@0 496 const GeometrySrcState& geoSrc = this->getGeomSrc();
michael@0 497 SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc);
michael@0 498 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t);
michael@0 499 fIndexPool->putBack(bytes);
michael@0 500 --fIndexPoolUseCnt;
michael@0 501 }
michael@0 502
michael@0 503 void GrGpu::onSetVertexSourceToArray(const void* vertexArray, int vertexCount) {
michael@0 504 this->prepareVertexPool();
michael@0 505 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
michael@0 506 #ifdef SK_DEBUG
michael@0 507 bool success =
michael@0 508 #endif
michael@0 509 fVertexPool->appendVertices(this->getVertexSize(),
michael@0 510 vertexCount,
michael@0 511 vertexArray,
michael@0 512 &geomPoolState.fPoolVertexBuffer,
michael@0 513 &geomPoolState.fPoolStartVertex);
michael@0 514 ++fVertexPoolUseCnt;
michael@0 515 GR_DEBUGASSERT(success);
michael@0 516 }
michael@0 517
michael@0 518 void GrGpu::onSetIndexSourceToArray(const void* indexArray, int indexCount) {
michael@0 519 this->prepareIndexPool();
michael@0 520 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
michael@0 521 #ifdef SK_DEBUG
michael@0 522 bool success =
michael@0 523 #endif
michael@0 524 fIndexPool->appendIndices(indexCount,
michael@0 525 indexArray,
michael@0 526 &geomPoolState.fPoolIndexBuffer,
michael@0 527 &geomPoolState.fPoolStartIndex);
michael@0 528 ++fIndexPoolUseCnt;
michael@0 529 GR_DEBUGASSERT(success);
michael@0 530 }
michael@0 531
michael@0 532 void GrGpu::releaseVertexArray() {
michael@0 533 // if vertex source was array, we stowed data in the pool
michael@0 534 const GeometrySrcState& geoSrc = this->getGeomSrc();
michael@0 535 SkASSERT(kArray_GeometrySrcType == geoSrc.fVertexSrc);
michael@0 536 size_t bytes = geoSrc.fVertexCount * geoSrc.fVertexSize;
michael@0 537 fVertexPool->putBack(bytes);
michael@0 538 --fVertexPoolUseCnt;
michael@0 539 }
michael@0 540
michael@0 541 void GrGpu::releaseIndexArray() {
michael@0 542 // if index source was array, we stowed data in the pool
michael@0 543 const GeometrySrcState& geoSrc = this->getGeomSrc();
michael@0 544 SkASSERT(kArray_GeometrySrcType == geoSrc.fIndexSrc);
michael@0 545 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t);
michael@0 546 fIndexPool->putBack(bytes);
michael@0 547 --fIndexPoolUseCnt;
michael@0 548 }

mercurial