blob: 1e1a367260216d01fe94f74c783aabd7d6c60716 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
bsalomon@google.com27847de2011-02-22 20:59:41 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 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.
bsalomon@google.com27847de2011-02-22 20:59:41 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
bsalomon@google.com27847de2011-02-22 20:59:41 +000010#ifndef GrGeometryBuffer_DEFINED
11#define GrGeometryBuffer_DEFINED
12
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000013#include "GrGpuObject.h"
bsalomon@google.com8fe72472011-03-30 21:26:44 +000014
15class GrGpu;
bsalomon@google.com27847de2011-02-22 20:59:41 +000016
17/**
18 * Parent class for vertex and index buffers
19 */
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000020class GrGeometryBuffer : public GrGpuObject {
bsalomon@google.com27847de2011-02-22 20:59:41 +000021public:
robertphillips@google.com7fa18762012-09-11 13:02:31 +000022 SK_DECLARE_INST_COUNT(GrGeometryBuffer);
bsalomon@google.com8fe72472011-03-30 21:26:44 +000023
bsalomon@google.com27847de2011-02-22 20:59:41 +000024 /**
25 *Retrieves whether the buffer was created with the dynamic flag
26 *
27 * @return true if the buffer was created with the dynamic flag
28 */
29 bool dynamic() const { return fDynamic; }
bsalomon@google.com8fe72472011-03-30 21:26:44 +000030
bsalomon@google.com27847de2011-02-22 20:59:41 +000031 /**
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000032 * Returns true if the buffer is a wrapper around a CPU array. If true it
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000033 * indicates that map will always succeed and will be free.
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000034 */
35 bool isCPUBacked() const { return fCPUBacked; }
36
37 /**
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000038 * Maps the buffer to be written by the CPU.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000039 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000040 * The previous content of the buffer is invalidated. It is an error
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000041 * to draw from the buffer while it is mapped. It is an error to call map
42 * on an already mapped buffer. It may fail if the backend doesn't support
43 * mapping the buffer. If the buffer is CPU backed then it will always
44 * succeed and is a free operation. Must be matched by an unmap() call.
45 * Currently only one map at a time is supported (no nesting of
46 * map/unmap).
bsalomon@google.com8fe72472011-03-30 21:26:44 +000047 *
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000048 * @return a pointer to the data or NULL if the map fails.
bsalomon@google.com27847de2011-02-22 20:59:41 +000049 */
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000050 virtual void* map() = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000051
bsalomon@google.com27847de2011-02-22 20:59:41 +000052 /**
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000053 * Returns the same ptr that map() returned at time of map or NULL if the
54 * is not mapped.
bsalomon@google.com27847de2011-02-22 20:59:41 +000055 *
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000056 * @return ptr to mapped buffer data or undefined if buffer is not mapped.
bsalomon@google.com27847de2011-02-22 20:59:41 +000057 */
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000058 virtual void* mapPtr() const = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000059
60 /**
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000061 * Unmaps the buffer.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000062 *
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000063 * The pointer returned by the previous map call will no longer be valid.
bsalomon@google.com27847de2011-02-22 20:59:41 +000064 */
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000065 virtual void unmap() = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000066
67 /**
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000068 Queries whether the buffer has been mapped.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000069
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000070 @return true if the buffer is mapped, false otherwise.
bsalomon@google.com27847de2011-02-22 20:59:41 +000071 */
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000072 virtual bool isMapped() const = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000073
bsalomon@google.com27847de2011-02-22 20:59:41 +000074 /**
bsalomon@google.com8fe72472011-03-30 21:26:44 +000075 * Updates the buffer data.
76 *
77 * The size of the buffer will be preserved. The src data will be
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000078 * placed at the beginning of the buffer and any remaining contents will
bsalomon@google.com27847de2011-02-22 20:59:41 +000079 * be undefined.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000080 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000081 * @return returns true if the update succeeds, false otherwise.
82 */
83 virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000084
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000085 // GrGpuObject overrides
86 virtual size_t gpuMemorySize() const { return fGpuMemorySize; }
bsalomon@google.comcee661a2011-07-26 12:32:36 +000087
bsalomon@google.com27847de2011-02-22 20:59:41 +000088protected:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000089 GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t gpuMemorySize, bool dynamic, bool cpuBacked)
bsalomon@google.com72830222013-01-23 20:25:22 +000090 : INHERITED(gpu, isWrapped)
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000091 , fGpuMemorySize(gpuMemorySize)
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000092 , fDynamic(dynamic)
93 , fCPUBacked(cpuBacked) {}
bsalomon@google.com27847de2011-02-22 20:59:41 +000094
95private:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000096 size_t fGpuMemorySize;
bsalomon@google.com27847de2011-02-22 20:59:41 +000097 bool fDynamic;
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000098 bool fCPUBacked;
bsalomon@google.com27847de2011-02-22 20:59:41 +000099
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000100 typedef GrGpuObject INHERITED;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000101};
102
103#endif