blob: 3c62cd61ca7f3c7e7dff63149cecb97d52dd890d [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 GrVertexBuffer_DEFINED
12#define GrVertexBuffer_DEFINED
13
bsalomon@google.com1c13c962011-02-14 16:51:21 +000014#include "GrGeometryBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000015
bsalomon@google.com1c13c962011-02-14 16:51:21 +000016class GrVertexBuffer : public GrGeometryBuffer {
robertphillips1b8e1b52015-06-24 06:54:10 -070017public:
18 static void ComputeScratchKey(size_t size, bool dynamic, GrScratchKey* key) {
19 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType();
20
21 GrScratchKey::Builder builder(key, kType, 2);
22
23 builder[0] = SkToUInt(size);
24 builder[1] = dynamic ? 1 : 0;
25 }
26
reed@google.comac10a2d2010-12-22 21:39:39 +000027protected:
bsalomon5236cf42015-01-14 10:42:08 -080028 GrVertexBuffer(GrGpu* gpu, size_t gpuMemorySize, bool dynamic, bool cpuBacked)
robertphillips1b8e1b52015-06-24 06:54:10 -070029 : INHERITED(gpu, gpuMemorySize, dynamic, cpuBacked) {
bsalomoneae62002015-07-31 13:59:30 -070030 // We currently only make buffers scratch if they're both pow2 sized and not cpuBacked.
31 if (!cpuBacked && SkIsPow2(gpuMemorySize)) {
32 GrScratchKey key;
33 ComputeScratchKey(gpuMemorySize, dynamic, &key);
34 this->setScratchKey(key);
35 }
robertphillips1b8e1b52015-06-24 06:54:10 -070036 }
37
reed@google.comac10a2d2010-12-22 21:39:39 +000038private:
bsalomon@google.com1c13c962011-02-14 16:51:21 +000039 typedef GrGeometryBuffer INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000040};
41
42#endif