OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 #include "GrContext.h" | 9 #include "GrContext.h" |
10 | 10 |
11 #include "effects/GrConfigConversionEffect.h" | |
12 #include "effects/GrDashingEffect.h" | |
13 #include "effects/GrSingleTextureEffect.h" | |
14 | |
15 #include "GrAARectRenderer.h" | 11 #include "GrAARectRenderer.h" |
16 #include "GrBufferAllocPool.h" | 12 #include "GrBufferAllocPool.h" |
17 #include "GrGpu.h" | 13 #include "GrDefaultGeoProcFactory.h" |
18 #include "GrGpuResource.h" | 14 #include "GrGpuResource.h" |
19 #include "GrGpuResourceCacheAccess.h" | 15 #include "GrGpuResourceCacheAccess.h" |
20 #include "GrDistanceFieldTextContext.h" | 16 #include "GrDistanceFieldTextContext.h" |
21 #include "GrDrawTargetCaps.h" | 17 #include "GrDrawTargetCaps.h" |
| 18 #include "GrGpu.h" |
22 #include "GrIndexBuffer.h" | 19 #include "GrIndexBuffer.h" |
23 #include "GrInOrderDrawBuffer.h" | 20 #include "GrInOrderDrawBuffer.h" |
24 #include "GrLayerCache.h" | 21 #include "GrLayerCache.h" |
25 #include "GrOvalRenderer.h" | 22 #include "GrOvalRenderer.h" |
26 #include "GrPathRenderer.h" | 23 #include "GrPathRenderer.h" |
27 #include "GrPathUtils.h" | 24 #include "GrPathUtils.h" |
28 #include "GrResourceCache2.h" | 25 #include "GrResourceCache2.h" |
29 #include "GrSoftwarePathRenderer.h" | 26 #include "GrSoftwarePathRenderer.h" |
30 #include "GrStencilBuffer.h" | 27 #include "GrStencilBuffer.h" |
31 #include "GrStencilAndCoverTextContext.h" | 28 #include "GrStencilAndCoverTextContext.h" |
32 #include "GrStrokeInfo.h" | 29 #include "GrStrokeInfo.h" |
33 #include "GrSurfacePriv.h" | 30 #include "GrSurfacePriv.h" |
34 #include "GrTextStrike.h" | 31 #include "GrTextStrike.h" |
35 #include "GrTexturePriv.h" | 32 #include "GrTexturePriv.h" |
36 #include "GrTraceMarker.h" | 33 #include "GrTraceMarker.h" |
37 #include "GrTracing.h" | 34 #include "GrTracing.h" |
38 #include "SkDashPathPriv.h" | 35 #include "SkDashPathPriv.h" |
39 #include "SkConfig8888.h" | 36 #include "SkConfig8888.h" |
40 #include "SkGr.h" | 37 #include "SkGr.h" |
41 #include "SkRRect.h" | 38 #include "SkRRect.h" |
42 #include "SkStrokeRec.h" | 39 #include "SkStrokeRec.h" |
43 #include "SkTLazy.h" | 40 #include "SkTLazy.h" |
44 #include "SkTLS.h" | 41 #include "SkTLS.h" |
45 #include "SkTraceEvent.h" | 42 #include "SkTraceEvent.h" |
46 | 43 |
| 44 #include "effects/GrConfigConversionEffect.h" |
| 45 #include "effects/GrDashingEffect.h" |
| 46 #include "effects/GrSingleTextureEffect.h" |
| 47 |
47 #ifdef SK_DEBUG | 48 #ifdef SK_DEBUG |
48 // change this to a 1 to see notifications when partial coverage fails | 49 // change this to a 1 to see notifications when partial coverage fails |
49 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 | 50 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
50 #else | 51 #else |
51 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 | 52 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
52 #endif | 53 #endif |
53 | 54 |
54 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; | 55 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; |
55 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; | 56 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; |
56 | 57 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 const uint8_t* srcRow = reinterpret_cast<const uint8_t *>(src) + (y>>16)
*srcW*bpp; | 293 const uint8_t* srcRow = reinterpret_cast<const uint8_t *>(src) + (y>>16)
*srcW*bpp; |
293 uint8_t* dstRow = reinterpret_cast<uint8_t *>(dst) + j*dstW*bpp; | 294 uint8_t* dstRow = reinterpret_cast<uint8_t *>(dst) + j*dstW*bpp; |
294 for (size_t i = 0; i < dstXLimit; i += bpp) { | 295 for (size_t i = 0; i < dstXLimit; i += bpp) { |
295 memcpy(dstRow + i, srcRow + (x>>16)*bpp, bpp); | 296 memcpy(dstRow + i, srcRow + (x>>16)*bpp, bpp); |
296 x += dx; | 297 x += dx; |
297 } | 298 } |
298 y += dy; | 299 y += dy; |
299 } | 300 } |
300 } | 301 } |
301 | 302 |
302 namespace { | |
303 | |
304 // position + local coordinate | |
305 extern const GrVertexAttrib gVertexAttribs[] = { | |
306 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | |
307 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBindi
ng} | |
308 }; | |
309 | |
310 }; | |
311 | |
312 // The desired texture is NPOT and tiled but that isn't supported by | 303 // The desired texture is NPOT and tiled but that isn't supported by |
313 // the current hardware. Resize the texture to be a POT | 304 // the current hardware. Resize the texture to be a POT |
314 GrTexture* GrContext::createResizedTexture(const GrSurfaceDesc& desc, | 305 GrTexture* GrContext::createResizedTexture(const GrSurfaceDesc& desc, |
315 const GrCacheID& cacheID, | 306 const GrCacheID& cacheID, |
316 const void* srcData, | 307 const void* srcData, |
317 size_t rowBytes, | 308 size_t rowBytes, |
318 bool filter) { | 309 bool filter) { |
319 SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID
, NULL)); | 310 SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID
, NULL)); |
320 if (NULL == clampedTexture) { | 311 if (NULL == clampedTexture) { |
321 clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, r
owBytes)); | 312 clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, r
owBytes)); |
(...skipping 18 matching lines...) Expand all Loading... |
340 drawState->setRenderTarget(texture->asRenderTarget()); | 331 drawState->setRenderTarget(texture->asRenderTarget()); |
341 | 332 |
342 // if filtering is not desired then we want to ensure all | 333 // if filtering is not desired then we want to ensure all |
343 // texels in the resampled image are copies of texels from | 334 // texels in the resampled image are copies of texels from |
344 // the original. | 335 // the original. |
345 GrTextureParams params(SkShader::kClamp_TileMode, | 336 GrTextureParams params(SkShader::kClamp_TileMode, |
346 filter ? GrTextureParams::kBilerp_FilterMode : | 337 filter ? GrTextureParams::kBilerp_FilterMode : |
347 GrTextureParams::kNone_FilterMode); | 338 GrTextureParams::kNone_FilterMode); |
348 drawState->addColorTextureProcessor(clampedTexture, SkMatrix::I(), param
s); | 339 drawState->addColorTextureProcessor(clampedTexture, SkMatrix::I(), param
s); |
349 | 340 |
350 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib
s), | 341 drawState->setGeometryProcessor( |
351 2 * sizeof(SkPoint)); | 342 GrDefaultGeoProcFactory::CreateAndSetAttribs( |
| 343 drawState, |
| 344 GrDefaultGeoProcFactory::kPosition_GPType | |
| 345 GrDefaultGeoProcFactory::kLocalCoord_GPType))->unref(); |
352 | 346 |
353 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, 0); | 347 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, 0); |
354 | 348 |
355 if (arg.succeeded()) { | 349 if (arg.succeeded()) { |
356 SkPoint* verts = (SkPoint*) arg.vertices(); | 350 SkPoint* verts = (SkPoint*) arg.vertices(); |
357 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(SkPoint)); | 351 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(SkPoint)); |
358 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); | 352 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); |
359 fDrawBuffer->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); | 353 fDrawBuffer->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); |
360 } | 354 } |
361 } else { | 355 } else { |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 return; | 759 return; |
766 } | 760 } |
767 | 761 |
768 if (width >= 0) { | 762 if (width >= 0) { |
769 // TODO: consider making static vertex buffers for these cases. | 763 // TODO: consider making static vertex buffers for these cases. |
770 // Hairline could be done by just adding closing vertex to | 764 // Hairline could be done by just adding closing vertex to |
771 // unitSquareVertexBuffer() | 765 // unitSquareVertexBuffer() |
772 | 766 |
773 static const int worstCaseVertCount = 10; | 767 static const int worstCaseVertCount = 10; |
774 target->drawState()->setDefaultVertexAttribs(); | 768 target->drawState()->setDefaultVertexAttribs(); |
| 769 target->drawState()->setGeometryProcessor(GrDefaultGeoProcFactory::Creat
e(false))->unref(); |
775 GrDrawTarget::AutoReleaseGeometry geo(target, worstCaseVertCount, 0); | 770 GrDrawTarget::AutoReleaseGeometry geo(target, worstCaseVertCount, 0); |
776 | 771 |
777 if (!geo.succeeded()) { | 772 if (!geo.succeeded()) { |
778 SkDebugf("Failed to get space for vertices!\n"); | 773 SkDebugf("Failed to get space for vertices!\n"); |
779 return; | 774 return; |
780 } | 775 } |
781 | 776 |
782 GrPrimitiveType primType; | 777 GrPrimitiveType primType; |
783 int vertCount; | 778 int vertCount; |
784 SkPoint* vertex = geo.positions(); | 779 SkPoint* vertex = geo.positions(); |
(...skipping 29 matching lines...) Expand all Loading... |
814 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); | 809 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); |
815 if (NULL == target) { | 810 if (NULL == target) { |
816 return; | 811 return; |
817 } | 812 } |
818 | 813 |
819 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | 814 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
820 | 815 |
821 target->drawRect(dstRect, &localRect, localMatrix); | 816 target->drawRect(dstRect, &localRect, localMatrix); |
822 } | 817 } |
823 | 818 |
824 namespace { | |
825 | |
826 extern const GrVertexAttrib gPosUVColorAttribs[] = { | |
827 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, | |
828 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBind
ing }, | |
829 {kVec4ub_GrVertexAttribType, 2*sizeof(SkPoint), kColor_GrVertexAttribBinding
} | |
830 }; | |
831 | |
832 static const size_t kPosUVAttribsSize = 2 * sizeof(SkPoint); | |
833 static const size_t kPosUVColorAttribsSize = 2 * sizeof(SkPoint) + sizeof(GrColo
r); | |
834 | |
835 extern const GrVertexAttrib gPosColorAttribs[] = { | |
836 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, | |
837 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding}, | |
838 }; | |
839 | |
840 static const size_t kPosAttribsSize = sizeof(SkPoint); | |
841 static const size_t kPosColorAttribsSize = sizeof(SkPoint) + sizeof(GrColor); | |
842 | |
843 static void set_vertex_attributes(GrDrawState* drawState, | 819 static void set_vertex_attributes(GrDrawState* drawState, |
844 const SkPoint* texCoords, | 820 const SkPoint* texCoords, |
845 const GrColor* colors, | 821 const GrColor* colors, |
846 int* colorOffset, | 822 int* colorOffset, |
847 int* texOffset) { | 823 int* texOffset) { |
848 *texOffset = -1; | 824 *texOffset = -1; |
849 *colorOffset = -1; | 825 *colorOffset = -1; |
850 | 826 |
| 827 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; |
851 if (texCoords && colors) { | 828 if (texCoords && colors) { |
852 *texOffset = sizeof(SkPoint); | 829 *colorOffset = sizeof(SkPoint); |
853 *colorOffset = 2*sizeof(SkPoint); | 830 *texOffset = sizeof(SkPoint) + sizeof(GrColor); |
854 drawState->setVertexAttribs<gPosUVColorAttribs>(3, kPosUVColorAttribsSiz
e); | 831 flags |= GrDefaultGeoProcFactory::kColor_GPType | |
| 832 GrDefaultGeoProcFactory::kLocalCoord_GPType; |
855 } else if (texCoords) { | 833 } else if (texCoords) { |
856 *texOffset = sizeof(SkPoint); | 834 *texOffset = sizeof(SkPoint); |
857 drawState->setVertexAttribs<gPosUVColorAttribs>(2, kPosUVAttribsSize); | 835 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
858 } else if (colors) { | 836 } else if (colors) { |
859 *colorOffset = sizeof(SkPoint); | 837 *colorOffset = sizeof(SkPoint); |
860 drawState->setVertexAttribs<gPosColorAttribs>(2, kPosColorAttribsSize); | 838 flags |= GrDefaultGeoProcFactory::kColor_GPType; |
861 } else { | |
862 drawState->setVertexAttribs<gPosColorAttribs>(1, kPosAttribsSize); | |
863 } | 839 } |
| 840 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::CreateAndSetAttribs
(drawState, |
| 841
flags))->unref(); |
864 } | 842 } |
865 | 843 |
866 }; | |
867 | |
868 void GrContext::drawVertices(const GrPaint& paint, | 844 void GrContext::drawVertices(const GrPaint& paint, |
869 GrPrimitiveType primitiveType, | 845 GrPrimitiveType primitiveType, |
870 int vertexCount, | 846 int vertexCount, |
871 const SkPoint positions[], | 847 const SkPoint positions[], |
872 const SkPoint texCoords[], | 848 const SkPoint texCoords[], |
873 const GrColor colors[], | 849 const GrColor colors[], |
874 const uint16_t indices[], | 850 const uint16_t indices[], |
875 int indexCount) { | 851 int indexCount) { |
876 AutoRestoreEffects are; | 852 AutoRestoreEffects are; |
877 AutoCheckFlush acf(this); | 853 AutoCheckFlush acf(this); |
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1757 fResourceCache2->printStats(); | 1733 fResourceCache2->printStats(); |
1758 } | 1734 } |
1759 #endif | 1735 #endif |
1760 | 1736 |
1761 #if GR_GPU_STATS | 1737 #if GR_GPU_STATS |
1762 const GrContext::GPUStats* GrContext::gpuStats() const { | 1738 const GrContext::GPUStats* GrContext::gpuStats() const { |
1763 return fGpu->gpuStats(); | 1739 return fGpu->gpuStats(); |
1764 } | 1740 } |
1765 #endif | 1741 #endif |
1766 | 1742 |
OLD | NEW |