epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrIndexBuffer_DEFINED |
| 12 | #define GrIndexBuffer_DEFINED |
| 13 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 14 | #include "GrGeometryBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 16 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 17 | class GrIndexBuffer : public GrGeometryBuffer { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 18 | public: |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 19 | 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.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 28 | /** |
| 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.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 34 | return static_cast<int>(this->gpuMemorySize() / (sizeof(uint16_t) * 6)); |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 35 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 36 | protected: |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 37 | GrIndexBuffer(GrGpu* gpu, size_t gpuMemorySize, bool dynamic, bool cpuBacked) |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 38 | : INHERITED(gpu, gpuMemorySize, dynamic, cpuBacked) { |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 39 | // 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 | } |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 45 | } |
| 46 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | private: |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 48 | typedef GrGeometryBuffer INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | #endif |