Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2010 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef GrBufferAllocPool_DEFINED |
michael@0 | 9 | #define GrBufferAllocPool_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkTArray.h" |
michael@0 | 12 | #include "SkTDArray.h" |
michael@0 | 13 | #include "SkTypes.h" |
michael@0 | 14 | |
michael@0 | 15 | class GrGeometryBuffer; |
michael@0 | 16 | class GrGpu; |
michael@0 | 17 | |
michael@0 | 18 | /** |
michael@0 | 19 | * A pool of geometry buffers tied to a GrGpu. |
michael@0 | 20 | * |
michael@0 | 21 | * The pool allows a client to make space for geometry and then put back excess |
michael@0 | 22 | * space if it over allocated. When a client is ready to draw from the pool |
michael@0 | 23 | * it calls unlock on the pool ensure buffers are ready for drawing. The pool |
michael@0 | 24 | * can be reset after drawing is completed to recycle space. |
michael@0 | 25 | * |
michael@0 | 26 | * At creation time a minimum per-buffer size can be specified. Additionally, |
michael@0 | 27 | * a number of buffers to preallocate can be specified. These will |
michael@0 | 28 | * be allocated at the min size and kept around until the pool is destroyed. |
michael@0 | 29 | */ |
michael@0 | 30 | class GrBufferAllocPool : public SkNoncopyable { |
michael@0 | 31 | public: |
michael@0 | 32 | /** |
michael@0 | 33 | * Ensures all buffers are unlocked and have all data written to them. |
michael@0 | 34 | * Call before drawing using buffers from the pool. |
michael@0 | 35 | */ |
michael@0 | 36 | void unlock(); |
michael@0 | 37 | |
michael@0 | 38 | /** |
michael@0 | 39 | * Invalidates all the data in the pool, unrefs non-preallocated buffers. |
michael@0 | 40 | */ |
michael@0 | 41 | void reset(); |
michael@0 | 42 | |
michael@0 | 43 | /** |
michael@0 | 44 | * Gets the number of preallocated buffers that are yet to be used. |
michael@0 | 45 | */ |
michael@0 | 46 | int preallocatedBuffersRemaining() const; |
michael@0 | 47 | |
michael@0 | 48 | /** |
michael@0 | 49 | * gets the number of preallocated buffers |
michael@0 | 50 | */ |
michael@0 | 51 | int preallocatedBufferCount() const; |
michael@0 | 52 | |
michael@0 | 53 | /** |
michael@0 | 54 | * Frees data from makeSpaces in LIFO order. |
michael@0 | 55 | */ |
michael@0 | 56 | void putBack(size_t bytes); |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * Gets the GrGpu that this pool is associated with. |
michael@0 | 60 | */ |
michael@0 | 61 | GrGpu* getGpu() { return fGpu; } |
michael@0 | 62 | |
michael@0 | 63 | protected: |
michael@0 | 64 | /** |
michael@0 | 65 | * Used to determine what type of buffers to create. We could make the |
michael@0 | 66 | * createBuffer a virtual except that we want to use it in the cons for |
michael@0 | 67 | * pre-allocated buffers. |
michael@0 | 68 | */ |
michael@0 | 69 | enum BufferType { |
michael@0 | 70 | kVertex_BufferType, |
michael@0 | 71 | kIndex_BufferType, |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | /** |
michael@0 | 75 | * Constructor |
michael@0 | 76 | * |
michael@0 | 77 | * @param gpu The GrGpu used to create the buffers. |
michael@0 | 78 | * @param bufferType The type of buffers to create. |
michael@0 | 79 | * @param frequentResetHint A hint that indicates that the pool |
michael@0 | 80 | * should expect frequent unlock() calls |
michael@0 | 81 | * (as opposed to many makeSpace / acquires |
michael@0 | 82 | * between resets). |
michael@0 | 83 | * @param bufferSize The minimum size of created buffers. |
michael@0 | 84 | * This value will be clamped to some |
michael@0 | 85 | * reasonable minimum. |
michael@0 | 86 | * @param preallocBufferCnt The pool will allocate this number of |
michael@0 | 87 | * buffers at bufferSize and keep them until it |
michael@0 | 88 | * is destroyed. |
michael@0 | 89 | */ |
michael@0 | 90 | GrBufferAllocPool(GrGpu* gpu, |
michael@0 | 91 | BufferType bufferType, |
michael@0 | 92 | bool frequentResetHint, |
michael@0 | 93 | size_t bufferSize = 0, |
michael@0 | 94 | int preallocBufferCnt = 0); |
michael@0 | 95 | |
michael@0 | 96 | virtual ~GrBufferAllocPool(); |
michael@0 | 97 | |
michael@0 | 98 | /** |
michael@0 | 99 | * Gets the size of the preallocated buffers. |
michael@0 | 100 | * |
michael@0 | 101 | * @return the size of preallocated buffers. |
michael@0 | 102 | */ |
michael@0 | 103 | size_t preallocatedBufferSize() const { |
michael@0 | 104 | return fPreallocBuffers.count() ? fMinBlockSize : 0; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * Returns a block of memory to hold data. A buffer designated to hold the |
michael@0 | 109 | * data is given to the caller. The buffer may or may not be locked. The |
michael@0 | 110 | * returned ptr remains valid until any of the following: |
michael@0 | 111 | * *makeSpace is called again. |
michael@0 | 112 | * *unlock is called. |
michael@0 | 113 | * *reset is called. |
michael@0 | 114 | * *this object is destroyed. |
michael@0 | 115 | * |
michael@0 | 116 | * Once unlock on the pool is called the data is guaranteed to be in the |
michael@0 | 117 | * buffer at the offset indicated by offset. Until that time it may be |
michael@0 | 118 | * in temporary storage and/or the buffer may be locked. |
michael@0 | 119 | * |
michael@0 | 120 | * @param size the amount of data to make space for |
michael@0 | 121 | * @param alignment alignment constraint from start of buffer |
michael@0 | 122 | * @param buffer returns the buffer that will hold the data. |
michael@0 | 123 | * @param offset returns the offset into buffer of the data. |
michael@0 | 124 | * @return pointer to where the client should write the data. |
michael@0 | 125 | */ |
michael@0 | 126 | void* makeSpace(size_t size, |
michael@0 | 127 | size_t alignment, |
michael@0 | 128 | const GrGeometryBuffer** buffer, |
michael@0 | 129 | size_t* offset); |
michael@0 | 130 | |
michael@0 | 131 | /** |
michael@0 | 132 | * Gets the number of items of a size that can be added to the current |
michael@0 | 133 | * buffer without spilling to another buffer. If the pool has been reset, or |
michael@0 | 134 | * the previous makeSpace completely exhausted a buffer then the returned |
michael@0 | 135 | * size will be the size of the next available preallocated buffer, or zero |
michael@0 | 136 | * if no preallocated buffer remains available. It is assumed that items |
michael@0 | 137 | * should be itemSize-aligned from the start of a buffer. |
michael@0 | 138 | * |
michael@0 | 139 | * @return the number of items that would fit in the current buffer. |
michael@0 | 140 | */ |
michael@0 | 141 | int currentBufferItems(size_t itemSize) const; |
michael@0 | 142 | |
michael@0 | 143 | GrGeometryBuffer* createBuffer(size_t size); |
michael@0 | 144 | |
michael@0 | 145 | private: |
michael@0 | 146 | |
michael@0 | 147 | // The GrGpu must be able to clear the ref of pools it creates as members |
michael@0 | 148 | friend class GrGpu; |
michael@0 | 149 | void releaseGpuRef(); |
michael@0 | 150 | |
michael@0 | 151 | struct BufferBlock { |
michael@0 | 152 | size_t fBytesFree; |
michael@0 | 153 | GrGeometryBuffer* fBuffer; |
michael@0 | 154 | }; |
michael@0 | 155 | |
michael@0 | 156 | bool createBlock(size_t requestSize); |
michael@0 | 157 | void destroyBlock(); |
michael@0 | 158 | void flushCpuData(GrGeometryBuffer* buffer, size_t flushSize); |
michael@0 | 159 | #ifdef SK_DEBUG |
michael@0 | 160 | void validate(bool unusedBlockAllowed = false) const; |
michael@0 | 161 | #endif |
michael@0 | 162 | |
michael@0 | 163 | size_t fBytesInUse; |
michael@0 | 164 | |
michael@0 | 165 | GrGpu* fGpu; |
michael@0 | 166 | bool fGpuIsReffed; |
michael@0 | 167 | bool fFrequentResetHint; |
michael@0 | 168 | SkTDArray<GrGeometryBuffer*> fPreallocBuffers; |
michael@0 | 169 | size_t fMinBlockSize; |
michael@0 | 170 | BufferType fBufferType; |
michael@0 | 171 | |
michael@0 | 172 | SkTArray<BufferBlock> fBlocks; |
michael@0 | 173 | int fPreallocBuffersInUse; |
michael@0 | 174 | // We attempt to cycle through the preallocated buffers rather than |
michael@0 | 175 | // always starting from the first. |
michael@0 | 176 | int fPreallocBufferStartIdx; |
michael@0 | 177 | SkAutoMalloc fCpuData; |
michael@0 | 178 | void* fBufferPtr; |
michael@0 | 179 | }; |
michael@0 | 180 | |
michael@0 | 181 | class GrVertexBuffer; |
michael@0 | 182 | |
michael@0 | 183 | /** |
michael@0 | 184 | * A GrBufferAllocPool of vertex buffers |
michael@0 | 185 | */ |
michael@0 | 186 | class GrVertexBufferAllocPool : public GrBufferAllocPool { |
michael@0 | 187 | public: |
michael@0 | 188 | /** |
michael@0 | 189 | * Constructor |
michael@0 | 190 | * |
michael@0 | 191 | * @param gpu The GrGpu used to create the vertex buffers. |
michael@0 | 192 | * @param frequentResetHint A hint that indicates that the pool |
michael@0 | 193 | * should expect frequent unlock() calls |
michael@0 | 194 | * (as opposed to many makeSpace / acquires |
michael@0 | 195 | * between resets). |
michael@0 | 196 | * @param bufferSize The minimum size of created VBs This value |
michael@0 | 197 | * will be clamped to some reasonable minimum. |
michael@0 | 198 | * @param preallocBufferCnt The pool will allocate this number of VBs at |
michael@0 | 199 | * bufferSize and keep them until it is |
michael@0 | 200 | * destroyed. |
michael@0 | 201 | */ |
michael@0 | 202 | GrVertexBufferAllocPool(GrGpu* gpu, |
michael@0 | 203 | bool frequentResetHint, |
michael@0 | 204 | size_t bufferSize = 0, |
michael@0 | 205 | int preallocBufferCnt = 0); |
michael@0 | 206 | |
michael@0 | 207 | /** |
michael@0 | 208 | * Returns a block of memory to hold vertices. A buffer designated to hold |
michael@0 | 209 | * the vertices given to the caller. The buffer may or may not be locked. |
michael@0 | 210 | * The returned ptr remains valid until any of the following: |
michael@0 | 211 | * *makeSpace is called again. |
michael@0 | 212 | * *unlock is called. |
michael@0 | 213 | * *reset is called. |
michael@0 | 214 | * *this object is destroyed. |
michael@0 | 215 | * |
michael@0 | 216 | * Once unlock on the pool is called the vertices are guaranteed to be in |
michael@0 | 217 | * the buffer at the offset indicated by startVertex. Until that time they |
michael@0 | 218 | * may be in temporary storage and/or the buffer may be locked. |
michael@0 | 219 | * |
michael@0 | 220 | * @param vertexSize specifies size of a vertex to allocate space for |
michael@0 | 221 | * @param vertexCount number of vertices to allocate space for |
michael@0 | 222 | * @param buffer returns the vertex buffer that will hold the |
michael@0 | 223 | * vertices. |
michael@0 | 224 | * @param startVertex returns the offset into buffer of the first vertex. |
michael@0 | 225 | * In units of the size of a vertex from layout param. |
michael@0 | 226 | * @return pointer to first vertex. |
michael@0 | 227 | */ |
michael@0 | 228 | void* makeSpace(size_t vertexSize, |
michael@0 | 229 | int vertexCount, |
michael@0 | 230 | const GrVertexBuffer** buffer, |
michael@0 | 231 | int* startVertex); |
michael@0 | 232 | |
michael@0 | 233 | /** |
michael@0 | 234 | * Shortcut to make space and then write verts into the made space. |
michael@0 | 235 | */ |
michael@0 | 236 | bool appendVertices(size_t vertexSize, |
michael@0 | 237 | int vertexCount, |
michael@0 | 238 | const void* vertices, |
michael@0 | 239 | const GrVertexBuffer** buffer, |
michael@0 | 240 | int* startVertex); |
michael@0 | 241 | |
michael@0 | 242 | /** |
michael@0 | 243 | * Gets the number of vertices that can be added to the current VB without |
michael@0 | 244 | * spilling to another VB. If the pool has been reset, or the previous |
michael@0 | 245 | * makeSpace completely exhausted a VB then the returned number of vertices |
michael@0 | 246 | * would fit in the next available preallocated buffer. If any makeSpace |
michael@0 | 247 | * would force a new VB to be created the return value will be zero. |
michael@0 | 248 | * |
michael@0 | 249 | * @param the size of a vertex to compute space for. |
michael@0 | 250 | * @return the number of vertices that would fit in the current buffer. |
michael@0 | 251 | */ |
michael@0 | 252 | int currentBufferVertices(size_t vertexSize) const; |
michael@0 | 253 | |
michael@0 | 254 | /** |
michael@0 | 255 | * Gets the number of vertices that can fit in a preallocated vertex buffer. |
michael@0 | 256 | * Zero if no preallocated buffers. |
michael@0 | 257 | * |
michael@0 | 258 | * @param the size of a vertex to compute space for. |
michael@0 | 259 | * |
michael@0 | 260 | * @return number of vertices that fit in one of the preallocated vertex |
michael@0 | 261 | * buffers. |
michael@0 | 262 | */ |
michael@0 | 263 | int preallocatedBufferVertices(size_t vertexSize) const; |
michael@0 | 264 | |
michael@0 | 265 | private: |
michael@0 | 266 | typedef GrBufferAllocPool INHERITED; |
michael@0 | 267 | }; |
michael@0 | 268 | |
michael@0 | 269 | class GrIndexBuffer; |
michael@0 | 270 | |
michael@0 | 271 | /** |
michael@0 | 272 | * A GrBufferAllocPool of index buffers |
michael@0 | 273 | */ |
michael@0 | 274 | class GrIndexBufferAllocPool : public GrBufferAllocPool { |
michael@0 | 275 | public: |
michael@0 | 276 | /** |
michael@0 | 277 | * Constructor |
michael@0 | 278 | * |
michael@0 | 279 | * @param gpu The GrGpu used to create the index buffers. |
michael@0 | 280 | * @param frequentResetHint A hint that indicates that the pool |
michael@0 | 281 | * should expect frequent unlock() calls |
michael@0 | 282 | * (as opposed to many makeSpace / acquires |
michael@0 | 283 | * between resets). |
michael@0 | 284 | * @param bufferSize The minimum size of created IBs This value |
michael@0 | 285 | * will be clamped to some reasonable minimum. |
michael@0 | 286 | * @param preallocBufferCnt The pool will allocate this number of VBs at |
michael@0 | 287 | * bufferSize and keep them until it is |
michael@0 | 288 | * destroyed. |
michael@0 | 289 | */ |
michael@0 | 290 | GrIndexBufferAllocPool(GrGpu* gpu, |
michael@0 | 291 | bool frequentResetHint, |
michael@0 | 292 | size_t bufferSize = 0, |
michael@0 | 293 | int preallocBufferCnt = 0); |
michael@0 | 294 | |
michael@0 | 295 | /** |
michael@0 | 296 | * Returns a block of memory to hold indices. A buffer designated to hold |
michael@0 | 297 | * the indices is given to the caller. The buffer may or may not be locked. |
michael@0 | 298 | * The returned ptr remains valid until any of the following: |
michael@0 | 299 | * *makeSpace is called again. |
michael@0 | 300 | * *unlock is called. |
michael@0 | 301 | * *reset is called. |
michael@0 | 302 | * *this object is destroyed. |
michael@0 | 303 | * |
michael@0 | 304 | * Once unlock on the pool is called the indices are guaranteed to be in the |
michael@0 | 305 | * buffer at the offset indicated by startIndex. Until that time they may be |
michael@0 | 306 | * in temporary storage and/or the buffer may be locked. |
michael@0 | 307 | * |
michael@0 | 308 | * @param indexCount number of indices to allocate space for |
michael@0 | 309 | * @param buffer returns the index buffer that will hold the indices. |
michael@0 | 310 | * @param startIndex returns the offset into buffer of the first index. |
michael@0 | 311 | * @return pointer to first index. |
michael@0 | 312 | */ |
michael@0 | 313 | void* makeSpace(int indexCount, |
michael@0 | 314 | const GrIndexBuffer** buffer, |
michael@0 | 315 | int* startIndex); |
michael@0 | 316 | |
michael@0 | 317 | /** |
michael@0 | 318 | * Shortcut to make space and then write indices into the made space. |
michael@0 | 319 | */ |
michael@0 | 320 | bool appendIndices(int indexCount, |
michael@0 | 321 | const void* indices, |
michael@0 | 322 | const GrIndexBuffer** buffer, |
michael@0 | 323 | int* startIndex); |
michael@0 | 324 | |
michael@0 | 325 | /** |
michael@0 | 326 | * Gets the number of indices that can be added to the current IB without |
michael@0 | 327 | * spilling to another IB. If the pool has been reset, or the previous |
michael@0 | 328 | * makeSpace completely exhausted a IB then the returned number of indices |
michael@0 | 329 | * would fit in the next available preallocated buffer. If any makeSpace |
michael@0 | 330 | * would force a new IB to be created the return value will be zero. |
michael@0 | 331 | */ |
michael@0 | 332 | int currentBufferIndices() const; |
michael@0 | 333 | |
michael@0 | 334 | /** |
michael@0 | 335 | * Gets the number of indices that can fit in a preallocated index buffer. |
michael@0 | 336 | * Zero if no preallocated buffers. |
michael@0 | 337 | * |
michael@0 | 338 | * @return number of indices that fit in one of the preallocated index |
michael@0 | 339 | * buffers. |
michael@0 | 340 | */ |
michael@0 | 341 | int preallocatedBufferIndices() const; |
michael@0 | 342 | |
michael@0 | 343 | private: |
michael@0 | 344 | typedef GrBufferAllocPool INHERITED; |
michael@0 | 345 | }; |
michael@0 | 346 | |
michael@0 | 347 | #endif |