GrGeometryBuffer.h revision 8341eb76fbc54593e873f5589961e02793e7f15f
18fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 1027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com#ifndef GrGeometryBuffer_DEFINED 1127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com#define GrGeometryBuffer_DEFINED 1227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 13089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org#include "GrGpuObject.h" 148fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 158fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.comclass GrGpu; 1627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 1727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com/** 1827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Parent class for vertex and index buffers 1927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 20089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.orgclass GrGeometryBuffer : public GrGpuObject { 2127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.compublic: 227fa18762e0ab64c3473df3aab0c2bfd6fabd8831robertphillips@google.com SK_DECLARE_INST_COUNT(GrGeometryBuffer); 238fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 2427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 2527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com *Retrieves whether the buffer was created with the dynamic flag 2627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * 2727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @return true if the buffer was created with the dynamic flag 2827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 2927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com bool dynamic() const { return fDynamic; } 308fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 3127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 32ee3bc3b26771a58a78075f11cde8801e0e79f723bsalomon@google.com * Returns true if the buffer is a wrapper around a CPU array. If true it 338341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * indicates that map will always succeed and will be free. 34ee3bc3b26771a58a78075f11cde8801e0e79f723bsalomon@google.com */ 35ee3bc3b26771a58a78075f11cde8801e0e79f723bsalomon@google.com bool isCPUBacked() const { return fCPUBacked; } 36ee3bc3b26771a58a78075f11cde8801e0e79f723bsalomon@google.com 37ee3bc3b26771a58a78075f11cde8801e0e79f723bsalomon@google.com /** 388341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * Maps the buffer to be written by the CPU. 398fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * 4027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * The previous content of the buffer is invalidated. It is an error 418341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * to draw from the buffer while it is mapped. It is an error to call map 428341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * on an already mapped buffer. It may fail if the backend doesn't support 438341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * mapping the buffer. If the buffer is CPU backed then it will always 448341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * succeed and is a free operation. Must be matched by an unmap() call. 458341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * Currently only one map at a time is supported (no nesting of 468341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * map/unmap). 478fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * 488341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * @return a pointer to the data or NULL if the map fails. 4927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 508341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org virtual void* map() = 0; 518fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 5227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 538341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * Returns the same ptr that map() returned at time of map or NULL if the 548341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * is not mapped. 5527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * 568341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * @return ptr to mapped buffer data or undefined if buffer is not mapped. 5727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 588341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org virtual void* mapPtr() const = 0; 598fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 608fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com /** 618341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * Unmaps the buffer. 628fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * 638341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org * The pointer returned by the previous map call will no longer be valid. 6427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 658341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org virtual void unmap() = 0; 668fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 678fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com /** 688341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org Queries whether the buffer has been mapped. 698fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 708341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org @return true if the buffer is mapped, false otherwise. 7127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 728341eb76fbc54593e873f5589961e02793e7f15fcommit-bot@chromium.org virtual bool isMapped() const = 0; 738fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 7427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com /** 758fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * Updates the buffer data. 768fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * 778fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * The size of the buffer will be preserved. The src data will be 78ee3bc3b26771a58a78075f11cde8801e0e79f723bsalomon@google.com * placed at the beginning of the buffer and any remaining contents will 7927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * be undefined. 808fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * 8127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * @return returns true if the update succeeds, false otherwise. 8227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */ 8327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0; 848fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 85089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org // GrGpuObject overrides 86089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org virtual size_t gpuMemorySize() const { return fGpuMemorySize; } 87cee661af926cc977addc6e039b7022975a448acebsalomon@google.com 8827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.comprotected: 89089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t gpuMemorySize, bool dynamic, bool cpuBacked) 90728302281920727b96e6cec0bfc7575900f34a8bbsalomon@google.com : INHERITED(gpu, isWrapped) 91089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org , fGpuMemorySize(gpuMemorySize) 92ee3bc3b26771a58a78075f11cde8801e0e79f723bsalomon@google.com , fDynamic(dynamic) 93ee3bc3b26771a58a78075f11cde8801e0e79f723bsalomon@google.com , fCPUBacked(cpuBacked) {} 9427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 9527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.comprivate: 96089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org size_t fGpuMemorySize; 9727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com bool fDynamic; 98ee3bc3b26771a58a78075f11cde8801e0e79f723bsalomon@google.com bool fCPUBacked; 9927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 100089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org typedef GrGpuObject INHERITED; 10127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com}; 10227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com 10327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com#endif 104