OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
11 | 11 |
12 #include "GrBufferAllocPool.h" | 12 #include "GrBufferAllocPool.h" |
13 #include "GrContext.h" | 13 #include "GrContext.h" |
14 #include "GrDrawTargetCaps.h" | 14 #include "GrDrawTargetCaps.h" |
15 #include "GrGpuResourcePriv.h" | 15 #include "GrGpuResourcePriv.h" |
16 #include "GrIndexBuffer.h" | 16 #include "GrIndexBuffer.h" |
17 #include "GrResourceCache.h" | 17 #include "GrResourceCache.h" |
18 #include "GrRenderTargetPriv.h" | 18 #include "GrRenderTargetPriv.h" |
19 #include "GrStencilAttachment.h" | 19 #include "GrStencilAttachment.h" |
20 #include "GrVertexBuffer.h" | 20 #include "GrVertexBuffer.h" |
21 | 21 |
22 //////////////////////////////////////////////////////////////////////////////// | 22 //////////////////////////////////////////////////////////////////////////////// |
23 | 23 |
24 GrGpu::GrGpu(GrContext* context) | 24 GrGpu::GrGpu(GrContext* context) |
25 : fResetTimestamp(kExpiredTimestamp+1) | 25 : fResetTimestamp(kExpiredTimestamp+1) |
26 , fResetBits(kAll_GrBackendState) | 26 , fResetBits(kAll_GrBackendState) |
27 , fQuadIndexBuffer(NULL) | |
28 , fGpuTraceMarkerCount(0) | 27 , fGpuTraceMarkerCount(0) |
29 , fContext(context) { | 28 , fContext(context) { |
30 } | 29 } |
31 | 30 |
32 GrGpu::~GrGpu() { | 31 GrGpu::~GrGpu() {} |
33 SkSafeSetNull(fQuadIndexBuffer); | |
34 } | |
35 | 32 |
36 void GrGpu::contextAbandoned() {} | 33 void GrGpu::contextAbandoned() {} |
37 | 34 |
38 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
39 | 36 |
40 static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget)
{ | 37 static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget)
{ |
41 // By default, GrRenderTargets are GL's normal orientation so that they | 38 // By default, GrRenderTargets are GL's normal orientation so that they |
42 // can be drawn to by the outside world without the client having | 39 // can be drawn to by the outside world without the client having |
43 // to render upside down. | 40 // to render upside down. |
44 if (kDefault_GrSurfaceOrigin == origin) { | 41 if (kDefault_GrSurfaceOrigin == origin) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) { | 174 GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) { |
178 this->handleDirtyContext(); | 175 this->handleDirtyContext(); |
179 return this->onCreateVertexBuffer(size, dynamic); | 176 return this->onCreateVertexBuffer(size, dynamic); |
180 } | 177 } |
181 | 178 |
182 GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) { | 179 GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) { |
183 this->handleDirtyContext(); | 180 this->handleDirtyContext(); |
184 return this->onCreateIndexBuffer(size, dynamic); | 181 return this->onCreateIndexBuffer(size, dynamic); |
185 } | 182 } |
186 | 183 |
187 GrIndexBuffer* GrGpu::createInstancedIndexBuffer(const uint16_t* pattern, | |
188 int patternSize, | |
189 int reps, | |
190 int vertCount, | |
191 bool isDynamic) { | |
192 size_t bufferSize = patternSize * reps * sizeof(uint16_t); | |
193 GrGpu* me = const_cast<GrGpu*>(this); | |
194 GrIndexBuffer* buffer = me->createIndexBuffer(bufferSize, isDynamic); | |
195 if (buffer) { | |
196 uint16_t* data = (uint16_t*) buffer->map(); | |
197 bool useTempData = (NULL == data); | |
198 if (useTempData) { | |
199 data = SkNEW_ARRAY(uint16_t, reps * patternSize); | |
200 } | |
201 for (int i = 0; i < reps; ++i) { | |
202 int baseIdx = i * patternSize; | |
203 uint16_t baseVert = (uint16_t)(i * vertCount); | |
204 for (int j = 0; j < patternSize; ++j) { | |
205 data[baseIdx+j] = baseVert + pattern[j]; | |
206 } | |
207 } | |
208 if (useTempData) { | |
209 if (!buffer->updateData(data, bufferSize)) { | |
210 SkFAIL("Can't get indices into buffer!"); | |
211 } | |
212 SkDELETE_ARRAY(data); | |
213 } else { | |
214 buffer->unmap(); | |
215 } | |
216 } | |
217 return buffer; | |
218 } | |
219 | |
220 void GrGpu::clear(const SkIRect* rect, | 184 void GrGpu::clear(const SkIRect* rect, |
221 GrColor color, | 185 GrColor color, |
222 bool canIgnoreRect, | 186 bool canIgnoreRect, |
223 GrRenderTarget* renderTarget) { | 187 GrRenderTarget* renderTarget) { |
224 SkASSERT(renderTarget); | 188 SkASSERT(renderTarget); |
225 this->handleDirtyContext(); | 189 this->handleDirtyContext(); |
226 this->onClear(renderTarget, rect, color, canIgnoreRect); | 190 this->onClear(renderTarget, rect, color, canIgnoreRect); |
227 } | 191 } |
228 | 192 |
229 void GrGpu::clearStencilClip(const SkIRect& rect, | 193 void GrGpu::clearStencilClip(const SkIRect& rect, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 if (this->caps()->gpuTracingSupport()) { | 262 if (this->caps()->gpuTracingSupport()) { |
299 SkASSERT(fGpuTraceMarkerCount >= 1); | 263 SkASSERT(fGpuTraceMarkerCount >= 1); |
300 this->fActiveTraceMarkers.remove(*marker); | 264 this->fActiveTraceMarkers.remove(*marker); |
301 this->didRemoveGpuTraceMarker(); | 265 this->didRemoveGpuTraceMarker(); |
302 --fGpuTraceMarkerCount; | 266 --fGpuTraceMarkerCount; |
303 } | 267 } |
304 } | 268 } |
305 | 269 |
306 //////////////////////////////////////////////////////////////////////////////// | 270 //////////////////////////////////////////////////////////////////////////////// |
307 | 271 |
308 static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1; | |
309 | |
310 GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535); | |
311 | |
312 static const uint16_t gQuadIndexPattern[] = { | |
313 0, 1, 2, 0, 2, 3 | |
314 }; | |
315 | |
316 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { | |
317 if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) { | |
318 SkSafeUnref(fQuadIndexBuffer); | |
319 GrGpu* me = const_cast<GrGpu*>(this); | |
320 fQuadIndexBuffer = me->createInstancedIndexBuffer(gQuadIndexPattern, | |
321 6, | |
322 MAX_QUADS, | |
323 4); | |
324 } | |
325 | |
326 return fQuadIndexBuffer; | |
327 } | |
328 | |
329 //////////////////////////////////////////////////////////////////////////////// | |
330 | |
331 void GrGpu::draw(const DrawArgs& args, const GrDrawTarget::DrawInfo& info) { | 272 void GrGpu::draw(const DrawArgs& args, const GrDrawTarget::DrawInfo& info) { |
332 this->handleDirtyContext(); | 273 this->handleDirtyContext(); |
333 this->onDraw(args, info); | 274 this->onDraw(args, info); |
334 } | 275 } |
335 | 276 |
336 void GrGpu::stencilPath(const GrPath* path, const StencilPathState& state) { | 277 void GrGpu::stencilPath(const GrPath* path, const StencilPathState& state) { |
337 this->handleDirtyContext(); | 278 this->handleDirtyContext(); |
338 this->onStencilPath(path, state); | 279 this->onStencilPath(path, state); |
339 } | 280 } |
340 | 281 |
(...skipping 10 matching lines...) Expand all Loading... |
351 GrDrawTarget::PathIndexType indexType, | 292 GrDrawTarget::PathIndexType indexType, |
352 const float transformValues[], | 293 const float transformValues[], |
353 GrDrawTarget::PathTransformType transformType, | 294 GrDrawTarget::PathTransformType transformType, |
354 int count, | 295 int count, |
355 const GrStencilSettings& stencilSettings) { | 296 const GrStencilSettings& stencilSettings) { |
356 this->handleDirtyContext(); | 297 this->handleDirtyContext(); |
357 pathRange->willDrawPaths(indices, indexType, count); | 298 pathRange->willDrawPaths(indices, indexType, count); |
358 this->onDrawPaths(args, pathRange, indices, indexType, transformValues, | 299 this->onDrawPaths(args, pathRange, indices, indexType, transformValues, |
359 transformType, count, stencilSettings); | 300 transformType, count, stencilSettings); |
360 } | 301 } |
OLD | NEW |