GrIndexBuffer* GrResourceProvider::createIndexBuffer(size_t size, BufferUsage usage, uint32_t flags) { if (this->isAbandoned()) { return nullptr; } bool noPendingIO = SkToBool(flags & kNoPendingIO_Flag); bool dynamic = kDynamic_BufferUsage == usage; if (dynamic) { // bin by pow2 with a reasonable min static const uint32_t MIN_SIZE = 1 << 12; size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); GrScratchKey key; GrIndexBuffer::ComputeScratchKey(size, true, &key); uint32_t scratchFlags = 0; if (noPendingIO) { scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; } else { scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; } GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, size, scratchFlags); if (resource) { return static_cast<GrIndexBuffer*>(resource); } } return this->gpu()->createIndexBuffer(size, dynamic); }
GrBuffer* GrResourceProvider::createBuffer(size_t size, GrBufferType intendedType, GrAccessPattern accessPattern, uint32_t flags, const void* data) { if (this->isAbandoned()) { return nullptr; } if (kDynamic_GrAccessPattern != accessPattern) { return this->gpu()->createBuffer(size, intendedType, accessPattern, data); } // bin by pow2 with a reasonable min static const uint32_t MIN_SIZE = 1 << 12; size_t allocSize = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); GrScratchKey key; GrBuffer::ComputeScratchKeyForDynamicBuffer(allocSize, intendedType, &key); uint32_t scratchFlags = 0; if (flags & kNoPendingIO_Flag) { scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; } else { scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; } GrBuffer* buffer = static_cast<GrBuffer*>( this->cache()->findAndRefScratchResource(key, allocSize, scratchFlags)); if (!buffer) { buffer = this->gpu()->createBuffer(allocSize, intendedType, kDynamic_GrAccessPattern); if (!buffer) { return nullptr; } } if (data) { buffer->updateData(data, size); } return buffer; }
GrIndexBuffer* GrResourceProvider::getIndexBuffer(size_t size, bool dynamic, bool calledDuringFlush) { if (this->isAbandoned()) { return NULL; } if (dynamic) { // bin by pow2 with a reasonable min static const uint32_t MIN_SIZE = 1 << 12; size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); GrScratchKey key; GrIndexBuffer::ComputeScratchKey(size, dynamic, &key); uint32_t scratchFlags = 0; if (calledDuringFlush) { scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; } else { scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; } GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, scratchFlags); if (resource) { return static_cast<GrIndexBuffer*>(resource); } } return this->gpu()->createIndexBuffer(size, dynamic); }
GrBuffer* GrResourceProvider::createBuffer(GrBufferType type, size_t size, GrAccessPattern accessPattern, uint32_t flags) { if (this->isAbandoned()) { return nullptr; } if (kDynamic_GrAccessPattern == accessPattern) { // bin by pow2 with a reasonable min static const uint32_t MIN_SIZE = 1 << 12; size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); GrScratchKey key; GrBuffer::ComputeScratchKeyForDynamicBuffer(type, size, &key); uint32_t scratchFlags = 0; if (flags & kNoPendingIO_Flag) { scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; } else { scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; } GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, size, scratchFlags); if (resource) { return static_cast<GrBuffer*>(resource); } } return this->gpu()->createBuffer(type, size, accessPattern); }
void SkRecorder::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkPaint& paint) { const int points = paint.countText(text, byteLength); APPEND(DrawPosTextH, paint, this->copy((const char*)text, byteLength), SkToUInt(byteLength), constY, this->copy(xpos, points)); }
void SkPipeCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) { size_t size = region.writeToMemory(nullptr); unsigned extra = 0; if (fits_in(size, 24)) { extra = SkToUInt(size); } SkPipeWriter writer(this); writer.write32(pack_verb(SkPipeVerb::kDrawRegion, extra)); if (0 == extra) { writer.write32(size); } SkAutoSMalloc<2048> storage(size); region.writeToMemory(storage.get()); write_pad(&writer, storage.get(), size); write_paint(writer, paint, kGeometry_PaintUsage); }
void SkRecorder::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) { APPEND(DrawPoints, paint, mode, SkToUInt(count), this->copy(pts, count)); }