blob: 2e3b437adfc3712f5500cc62fe554fcf4f4ad961 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef GrIndexBuffer_DEFINED
12#define GrIndexBuffer_DEFINED
13
bsalomon@google.com1c13c962011-02-14 16:51:21 +000014#include "GrGeometryBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000015
robertphillips1b8e1b52015-06-24 06:54:10 -070016
bsalomon@google.com1c13c962011-02-14 16:51:21 +000017class GrIndexBuffer : public GrGeometryBuffer {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000018public:
robertphillips1b8e1b52015-06-24 06:54:10 -070019 static void ComputeScratchKey(size_t size, bool dynamic, GrScratchKey* key) {
20 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType();
21
22 GrScratchKey::Builder builder(key, kType, 2);
23
24 builder[0] = SkToUInt(size);
25 builder[1] = dynamic ? 1 : 0;
26 }
27
bsalomon@google.com72830222013-01-23 20:25:22 +000028 /**
29 * Retrieves the maximum number of quads that could be rendered
30 * from the index buffer (using kTriangles_GrPrimitiveType).
31 * @return the maximum number of quads using full size of index buffer.
32 */
33 int maxQuads() const {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000034 return static_cast<int>(this->gpuMemorySize() / (sizeof(uint16_t) * 6));
bsalomon@google.com72830222013-01-23 20:25:22 +000035 }
reed@google.comac10a2d2010-12-22 21:39:39 +000036protected:
bsalomon5236cf42015-01-14 10:42:08 -080037 GrIndexBuffer(GrGpu* gpu, size_t gpuMemorySize, bool dynamic, bool cpuBacked)
robertphillips1b8e1b52015-06-24 06:54:10 -070038 : INHERITED(gpu, gpuMemorySize, dynamic, cpuBacked) {
bsalomoneae62002015-07-31 13:59:30 -070039 // We currently only make buffers scratch if they're both pow2 sized and not cpuBacked.
40 if (!cpuBacked && SkIsPow2(gpuMemorySize)) {
41 GrScratchKey key;
42 ComputeScratchKey(gpuMemorySize, dynamic, &key);
43 this->setScratchKey(key);
44 }
robertphillips1b8e1b52015-06-24 06:54:10 -070045 }
46
reed@google.comac10a2d2010-12-22 21:39:39 +000047private:
bsalomon@google.com1c13c962011-02-14 16:51:21 +000048 typedef GrGeometryBuffer INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000049};
50
51#endif