Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/gpu/GrGpu.cpp

Issue 709133003: Snap optdrawstate in inorder draw buffer and pass into gpu (Closed) Base URL: https://skia.googlesource.com/skia.git@remove_friends
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrInOrderDrawBuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrIndexBuffer.h" 15 #include "GrIndexBuffer.h"
16 #include "GrStencilBuffer.h" 16 #include "GrStencilBuffer.h"
17 #include "GrVertexBuffer.h" 17 #include "GrVertexBuffer.h"
18 18
19 //////////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////////
20 20
21 #define DEBUG_INVAL_BUFFER 0xdeadcafe 21 #define DEBUG_INVAL_BUFFER 0xdeadcafe
22 #define DEBUG_INVAL_START_IDX -1 22 #define DEBUG_INVAL_START_IDX -1
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) 27 , fQuadIndexBuffer(NULL)
28 , fContext(context) { 28 , fContext(context) {
29 fDrawState = &fDefaultDrawState;
30 // We assume that fDrawState always owns a ref to the object it points at.
31 fDefaultDrawState.ref();
32 } 29 }
33 30
34 GrGpu::~GrGpu() { 31 GrGpu::~GrGpu() {
35 SkSafeSetNull(fQuadIndexBuffer); 32 SkSafeSetNull(fQuadIndexBuffer);
36 SkSafeUnref(fDrawState);
37 SkSafeUnref(fGeoSrcState.fVertexBuffer); 33 SkSafeUnref(fGeoSrcState.fVertexBuffer);
38 SkSafeUnref(fGeoSrcState.fIndexBuffer); 34 SkSafeUnref(fGeoSrcState.fIndexBuffer);
39 } 35 }
40 36
41 void GrGpu::contextAbandoned() {} 37 void GrGpu::contextAbandoned() {}
42 38
43 //////////////////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////////////////
44 40
45 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, 41 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc,
46 const void* srcData, size_t rowBytes) { 42 const void* srcData, size_t rowBytes) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 bool canIgnoreRect, 179 bool canIgnoreRect,
184 GrRenderTarget* renderTarget) { 180 GrRenderTarget* renderTarget) {
185 SkASSERT(renderTarget); 181 SkASSERT(renderTarget);
186 this->handleDirtyContext(); 182 this->handleDirtyContext();
187 this->onClear(renderTarget, rect, color, canIgnoreRect); 183 this->onClear(renderTarget, rect, color, canIgnoreRect);
188 } 184 }
189 185
190 void GrGpu::clearStencilClip(const SkIRect& rect, 186 void GrGpu::clearStencilClip(const SkIRect& rect,
191 bool insideClip, 187 bool insideClip,
192 GrRenderTarget* renderTarget) { 188 GrRenderTarget* renderTarget) {
193 if (NULL == renderTarget) { 189 SkASSERT(renderTarget);
194 renderTarget = this->getDrawState().getRenderTarget();
195 }
196 if (NULL == renderTarget) {
197 SkASSERT(0);
198 return;
199 }
200 this->handleDirtyContext(); 190 this->handleDirtyContext();
201 this->onClearStencilClip(renderTarget, rect, insideClip); 191 this->onClearStencilClip(renderTarget, rect, insideClip);
202 } 192 }
203 193
204 bool GrGpu::readPixels(GrRenderTarget* target, 194 bool GrGpu::readPixels(GrRenderTarget* target,
205 int left, int top, int width, int height, 195 int left, int top, int width, int height,
206 GrPixelConfig config, void* buffer, 196 GrPixelConfig config, void* buffer,
207 size_t rowBytes) { 197 size_t rowBytes) {
208 this->handleDirtyContext(); 198 this->handleDirtyContext();
209 return this->onReadPixels(target, left, top, width, height, 199 return this->onReadPixels(target, left, top, width, height,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 256
267 void GrGpu::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 257 void GrGpu::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
268 if (this->caps()->gpuTracingSupport()) { 258 if (this->caps()->gpuTracingSupport()) {
269 SkASSERT(fGpuTraceMarkerCount >= 1); 259 SkASSERT(fGpuTraceMarkerCount >= 1);
270 this->fActiveTraceMarkers.remove(*marker); 260 this->fActiveTraceMarkers.remove(*marker);
271 this->didRemoveGpuTraceMarker(); 261 this->didRemoveGpuTraceMarker();
272 --fGpuTraceMarkerCount; 262 --fGpuTraceMarkerCount;
273 } 263 }
274 } 264 }
275 265
276 void GrGpu::setVertexSourceToBuffer(const GrVertexBuffer* buffer) { 266 void GrGpu::setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexS tride) {
277 SkSafeUnref(fGeoSrcState.fVertexBuffer); 267 SkSafeUnref(fGeoSrcState.fVertexBuffer);
278 fGeoSrcState.fVertexBuffer = buffer; 268 fGeoSrcState.fVertexBuffer = buffer;
279 buffer->ref(); 269 buffer->ref();
280 fGeoSrcState.fVertexSize = this->drawState()->getVertexStride(); 270 fGeoSrcState.fVertexSize = vertexStride;
281 } 271 }
282 272
283 void GrGpu::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { 273 void GrGpu::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
284 SkSafeUnref(fGeoSrcState.fIndexBuffer); 274 SkSafeUnref(fGeoSrcState.fIndexBuffer);
285 fGeoSrcState.fIndexBuffer = buffer; 275 fGeoSrcState.fIndexBuffer = buffer;
286 buffer->ref(); 276 buffer->ref();
287 } 277 }
288 278
289 void GrGpu::setDrawState(GrDrawState* drawState) {
290 SkASSERT(fDrawState);
291 if (NULL == drawState) {
292 drawState = &fDefaultDrawState;
293 }
294 if (fDrawState != drawState) {
295 fDrawState->unref();
296 drawState->ref();
297 fDrawState = drawState;
298 }
299 }
300
301 //////////////////////////////////////////////////////////////////////////////// 279 ////////////////////////////////////////////////////////////////////////////////
302 280
303 static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1; 281 static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1;
304 282
305 GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535); 283 GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535);
306 284
307 static const uint16_t gQuadIndexPattern[] = { 285 static const uint16_t gQuadIndexPattern[] = {
308 0, 1, 2, 0, 2, 3 286 0, 1, 2, 0, 2, 3
309 }; 287 };
310 288
311 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { 289 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const {
312 if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) { 290 if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) {
313 SkSafeUnref(fQuadIndexBuffer); 291 SkSafeUnref(fQuadIndexBuffer);
314 GrGpu* me = const_cast<GrGpu*>(this); 292 GrGpu* me = const_cast<GrGpu*>(this);
315 fQuadIndexBuffer = me->createInstancedIndexBuffer(gQuadIndexPattern, 293 fQuadIndexBuffer = me->createInstancedIndexBuffer(gQuadIndexPattern,
316 6, 294 6,
317 MAX_QUADS, 295 MAX_QUADS,
318 4); 296 4);
319 } 297 }
320 298
321 return fQuadIndexBuffer; 299 return fQuadIndexBuffer;
322 } 300 }
323 301
324 //////////////////////////////////////////////////////////////////////////////// 302 ////////////////////////////////////////////////////////////////////////////////
325 303
326 void GrGpu::draw(const GrDrawTarget::DrawInfo& info, 304 void GrGpu::draw(const GrOptDrawState& ds,
327 const GrClipMaskManager::ScissorState& scissorState) { 305 const GrDrawTarget::DrawInfo& info,
306 const GrClipMaskManager::ScissorState& scissorState) {
328 this->handleDirtyContext(); 307 this->handleDirtyContext();
329 if (!this->flushGraphicsState(PrimTypeToDrawType(info.primitiveType()), 308 if (!this->flushGraphicsState(ds,
309 PrimTypeToDrawType(info.primitiveType()),
330 scissorState, 310 scissorState,
331 info.getDstCopy())) { 311 info.getDstCopy())) {
332 return; 312 return;
333 } 313 }
334 this->onDraw(info); 314 this->onDraw(ds, info);
335 } 315 }
336 316
337 void GrGpu::stencilPath(const GrPath* path, 317 void GrGpu::stencilPath(const GrOptDrawState& ds,
338 const GrClipMaskManager::ScissorState& scissorState, 318 const GrPath* path,
339 const GrStencilSettings& stencilSettings) { 319 const GrClipMaskManager::ScissorState& scissorState,
320 const GrStencilSettings& stencilSettings) {
340 this->handleDirtyContext(); 321 this->handleDirtyContext();
341 322
342 if (!this->flushGraphicsState(kStencilPath_DrawType, scissorState, NULL)) { 323 if (!this->flushGraphicsState(ds, kStencilPath_DrawType, scissorState, NULL) ) {
343 return; 324 return;
344 } 325 }
345 326
346 this->pathRendering()->stencilPath(path, stencilSettings); 327 this->pathRendering()->stencilPath(path, stencilSettings);
347 } 328 }
348 329
349 330
350 void GrGpu::drawPath(const GrPath* path, 331 void GrGpu::drawPath(const GrOptDrawState& ds,
351 const GrClipMaskManager::ScissorState& scissorState, 332 const GrPath* path,
352 const GrStencilSettings& stencilSettings, 333 const GrClipMaskManager::ScissorState& scissorState,
353 const GrDeviceCoordTexture* dstCopy) { 334 const GrStencilSettings& stencilSettings,
335 const GrDeviceCoordTexture* dstCopy) {
354 this->handleDirtyContext(); 336 this->handleDirtyContext();
355 337
356 if (!this->flushGraphicsState(kDrawPath_DrawType, scissorState, dstCopy)) { 338 if (!this->flushGraphicsState(ds, kDrawPath_DrawType, scissorState, dstCopy) ) {
357 return; 339 return;
358 } 340 }
359 341
360 this->pathRendering()->drawPath(path, stencilSettings); 342 this->pathRendering()->drawPath(path, stencilSettings);
361 } 343 }
362 344
363 void GrGpu::drawPaths(const GrPathRange* pathRange, 345 void GrGpu::drawPaths(const GrOptDrawState& ds,
364 const uint32_t indices[], 346 const GrPathRange* pathRange,
365 int count, 347 const uint32_t indices[],
366 const float transforms[], 348 int count,
367 GrDrawTarget::PathTransformType transformsType, 349 const float transforms[],
368 const GrClipMaskManager::ScissorState& scissorState, 350 GrDrawTarget::PathTransformType transformsType,
369 const GrStencilSettings& stencilSettings, 351 const GrClipMaskManager::ScissorState& scissorState,
370 const GrDeviceCoordTexture* dstCopy) { 352 const GrStencilSettings& stencilSettings,
353 const GrDeviceCoordTexture* dstCopy) {
371 this->handleDirtyContext(); 354 this->handleDirtyContext();
372 355
373 if (!this->flushGraphicsState(kDrawPaths_DrawType, scissorState, dstCopy)) { 356 if (!this->flushGraphicsState(ds, kDrawPaths_DrawType, scissorState, dstCopy )) {
374 return; 357 return;
375 } 358 }
376 359
377 pathRange->willDrawPaths(indices, count); 360 pathRange->willDrawPaths(indices, count);
378 this->pathRendering()->drawPaths(pathRange, indices, count, transforms, tran sformsType, 361 this->pathRendering()->drawPaths(pathRange, indices, count, transforms, tran sformsType,
379 stencilSettings); 362 stencilSettings);
380 } 363 }
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrInOrderDrawBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698