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 "GrDistanceFieldTextContext.h" | 14 #include "GrDistanceFieldTextContext.h" |
19 #include "GrDrawTargetCaps.h" | 15 #include "GrDrawTargetCaps.h" |
| 16 #include "GrGpu.h" |
20 #include "GrIndexBuffer.h" | 17 #include "GrIndexBuffer.h" |
21 #include "GrInOrderDrawBuffer.h" | 18 #include "GrInOrderDrawBuffer.h" |
22 #include "GrLayerCache.h" | 19 #include "GrLayerCache.h" |
23 #include "GrOvalRenderer.h" | 20 #include "GrOvalRenderer.h" |
24 #include "GrPathRenderer.h" | 21 #include "GrPathRenderer.h" |
25 #include "GrPathUtils.h" | 22 #include "GrPathUtils.h" |
26 #include "GrResourceCache.h" | 23 #include "GrResourceCache.h" |
27 #include "GrResourceCache2.h" | 24 #include "GrResourceCache2.h" |
28 #include "GrSoftwarePathRenderer.h" | 25 #include "GrSoftwarePathRenderer.h" |
29 #include "GrStencilBuffer.h" | 26 #include "GrStencilBuffer.h" |
30 #include "GrStencilAndCoverTextContext.h" | 27 #include "GrStencilAndCoverTextContext.h" |
31 #include "GrStrokeInfo.h" | 28 #include "GrStrokeInfo.h" |
32 #include "GrSurfacePriv.h" | 29 #include "GrSurfacePriv.h" |
33 #include "GrTextStrike.h" | 30 #include "GrTextStrike.h" |
34 #include "GrTexturePriv.h" | 31 #include "GrTexturePriv.h" |
35 #include "GrTraceMarker.h" | 32 #include "GrTraceMarker.h" |
36 #include "GrTracing.h" | 33 #include "GrTracing.h" |
37 #include "SkDashPathPriv.h" | 34 #include "SkDashPathPriv.h" |
38 #include "SkConfig8888.h" | 35 #include "SkConfig8888.h" |
39 #include "SkGr.h" | 36 #include "SkGr.h" |
40 #include "SkRRect.h" | 37 #include "SkRRect.h" |
41 #include "SkStrokeRec.h" | 38 #include "SkStrokeRec.h" |
42 #include "SkTLazy.h" | 39 #include "SkTLazy.h" |
43 #include "SkTLS.h" | 40 #include "SkTLS.h" |
44 #include "SkTraceEvent.h" | 41 #include "SkTraceEvent.h" |
45 | 42 |
| 43 #include "effects/GrConfigConversionEffect.h" |
| 44 #include "effects/GrDashingEffect.h" |
| 45 #include "effects/GrSingleTextureEffect.h" |
| 46 |
46 #ifdef SK_DEBUG | 47 #ifdef SK_DEBUG |
47 // change this to a 1 to see notifications when partial coverage fails | 48 // change this to a 1 to see notifications when partial coverage fails |
48 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 | 49 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
49 #else | 50 #else |
50 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 | 51 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
51 #endif | 52 #endif |
52 | 53 |
53 static const size_t MAX_RESOURCE_CACHE_COUNT = GR_DEFAULT_RESOURCE_CACHE_COUNT_L
IMIT; | 54 static const size_t MAX_RESOURCE_CACHE_COUNT = GR_DEFAULT_RESOURCE_CACHE_COUNT_L
IMIT; |
54 static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMI
T * 1024 * 1024; | 55 static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMI
T * 1024 * 1024; |
55 | 56 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 const uint8_t* srcRow = reinterpret_cast<const uint8_t *>(src) + (y>>16)
*srcW*bpp; | 304 const uint8_t* srcRow = reinterpret_cast<const uint8_t *>(src) + (y>>16)
*srcW*bpp; |
304 uint8_t* dstRow = reinterpret_cast<uint8_t *>(dst) + j*dstW*bpp; | 305 uint8_t* dstRow = reinterpret_cast<uint8_t *>(dst) + j*dstW*bpp; |
305 for (size_t i = 0; i < dstXLimit; i += bpp) { | 306 for (size_t i = 0; i < dstXLimit; i += bpp) { |
306 memcpy(dstRow + i, srcRow + (x>>16)*bpp, bpp); | 307 memcpy(dstRow + i, srcRow + (x>>16)*bpp, bpp); |
307 x += dx; | 308 x += dx; |
308 } | 309 } |
309 y += dy; | 310 y += dy; |
310 } | 311 } |
311 } | 312 } |
312 | 313 |
313 namespace { | |
314 | |
315 // position + local coordinate | |
316 extern const GrVertexAttrib gVertexAttribs[] = { | |
317 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | |
318 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBindi
ng} | |
319 }; | |
320 | |
321 }; | |
322 | |
323 // The desired texture is NPOT and tiled but that isn't supported by | 314 // The desired texture is NPOT and tiled but that isn't supported by |
324 // the current hardware. Resize the texture to be a POT | 315 // the current hardware. Resize the texture to be a POT |
325 GrTexture* GrContext::createResizedTexture(const GrSurfaceDesc& desc, | 316 GrTexture* GrContext::createResizedTexture(const GrSurfaceDesc& desc, |
326 const GrCacheID& cacheID, | 317 const GrCacheID& cacheID, |
327 const void* srcData, | 318 const void* srcData, |
328 size_t rowBytes, | 319 size_t rowBytes, |
329 bool filter) { | 320 bool filter) { |
330 SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID
, NULL)); | 321 SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID
, NULL)); |
331 if (NULL == clampedTexture) { | 322 if (NULL == clampedTexture) { |
332 clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, r
owBytes)); | 323 clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, r
owBytes)); |
(...skipping 18 matching lines...) Expand all Loading... |
351 drawState->setRenderTarget(texture->asRenderTarget()); | 342 drawState->setRenderTarget(texture->asRenderTarget()); |
352 | 343 |
353 // if filtering is not desired then we want to ensure all | 344 // if filtering is not desired then we want to ensure all |
354 // texels in the resampled image are copies of texels from | 345 // texels in the resampled image are copies of texels from |
355 // the original. | 346 // the original. |
356 GrTextureParams params(SkShader::kClamp_TileMode, | 347 GrTextureParams params(SkShader::kClamp_TileMode, |
357 filter ? GrTextureParams::kBilerp_FilterMode : | 348 filter ? GrTextureParams::kBilerp_FilterMode : |
358 GrTextureParams::kNone_FilterMode); | 349 GrTextureParams::kNone_FilterMode); |
359 drawState->addColorTextureProcessor(clampedTexture, SkMatrix::I(), param
s); | 350 drawState->addColorTextureProcessor(clampedTexture, SkMatrix::I(), param
s); |
360 | 351 |
361 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib
s), | 352 drawState->setGeometryProcessor( |
362 2 * sizeof(SkPoint)); | 353 GrDefaultGeoProcFactory::CreateAndSetAttribs( |
| 354 drawState, |
| 355 GrDefaultGeoProcFactory::kPosition_GPType | |
| 356 GrDefaultGeoProcFactory::kLocalCoord_GPType))->unref(); |
363 | 357 |
364 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, 0); | 358 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, 0); |
365 | 359 |
366 if (arg.succeeded()) { | 360 if (arg.succeeded()) { |
367 SkPoint* verts = (SkPoint*) arg.vertices(); | 361 SkPoint* verts = (SkPoint*) arg.vertices(); |
368 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(SkPoint)); | 362 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(SkPoint)); |
369 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); | 363 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); |
370 fDrawBuffer->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); | 364 fDrawBuffer->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); |
371 } | 365 } |
372 } else { | 366 } else { |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 return; | 777 return; |
784 } | 778 } |
785 | 779 |
786 if (width >= 0) { | 780 if (width >= 0) { |
787 // TODO: consider making static vertex buffers for these cases. | 781 // TODO: consider making static vertex buffers for these cases. |
788 // Hairline could be done by just adding closing vertex to | 782 // Hairline could be done by just adding closing vertex to |
789 // unitSquareVertexBuffer() | 783 // unitSquareVertexBuffer() |
790 | 784 |
791 static const int worstCaseVertCount = 10; | 785 static const int worstCaseVertCount = 10; |
792 target->drawState()->setDefaultVertexAttribs(); | 786 target->drawState()->setDefaultVertexAttribs(); |
| 787 target->drawState()->setGeometryProcessor(GrDefaultGeoProcFactory::Creat
e(false))->unref(); |
793 GrDrawTarget::AutoReleaseGeometry geo(target, worstCaseVertCount, 0); | 788 GrDrawTarget::AutoReleaseGeometry geo(target, worstCaseVertCount, 0); |
794 | 789 |
795 if (!geo.succeeded()) { | 790 if (!geo.succeeded()) { |
796 SkDebugf("Failed to get space for vertices!\n"); | 791 SkDebugf("Failed to get space for vertices!\n"); |
797 return; | 792 return; |
798 } | 793 } |
799 | 794 |
800 GrPrimitiveType primType; | 795 GrPrimitiveType primType; |
801 int vertCount; | 796 int vertCount; |
802 SkPoint* vertex = geo.positions(); | 797 SkPoint* vertex = geo.positions(); |
(...skipping 29 matching lines...) Expand all Loading... |
832 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); | 827 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); |
833 if (NULL == target) { | 828 if (NULL == target) { |
834 return; | 829 return; |
835 } | 830 } |
836 | 831 |
837 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | 832 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
838 | 833 |
839 target->drawRect(dstRect, &localRect, localMatrix); | 834 target->drawRect(dstRect, &localRect, localMatrix); |
840 } | 835 } |
841 | 836 |
842 namespace { | |
843 | |
844 extern const GrVertexAttrib gPosUVColorAttribs[] = { | |
845 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, | |
846 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBind
ing }, | |
847 {kVec4ub_GrVertexAttribType, 2*sizeof(SkPoint), kColor_GrVertexAttribBinding
} | |
848 }; | |
849 | |
850 static const size_t kPosUVAttribsSize = 2 * sizeof(SkPoint); | |
851 static const size_t kPosUVColorAttribsSize = 2 * sizeof(SkPoint) + sizeof(GrColo
r); | |
852 | |
853 extern const GrVertexAttrib gPosColorAttribs[] = { | |
854 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, | |
855 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding}, | |
856 }; | |
857 | |
858 static const size_t kPosAttribsSize = sizeof(SkPoint); | |
859 static const size_t kPosColorAttribsSize = sizeof(SkPoint) + sizeof(GrColor); | |
860 | |
861 static void set_vertex_attributes(GrDrawState* drawState, | 837 static void set_vertex_attributes(GrDrawState* drawState, |
862 const SkPoint* texCoords, | 838 const SkPoint* texCoords, |
863 const GrColor* colors, | 839 const GrColor* colors, |
864 int* colorOffset, | 840 int* colorOffset, |
865 int* texOffset) { | 841 int* texOffset) { |
866 *texOffset = -1; | 842 *texOffset = -1; |
867 *colorOffset = -1; | 843 *colorOffset = -1; |
868 | 844 |
| 845 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; |
869 if (texCoords && colors) { | 846 if (texCoords && colors) { |
870 *texOffset = sizeof(SkPoint); | 847 *colorOffset = sizeof(SkPoint); |
871 *colorOffset = 2*sizeof(SkPoint); | 848 *texOffset = sizeof(SkPoint) + sizeof(GrColor); |
872 drawState->setVertexAttribs<gPosUVColorAttribs>(3, kPosUVColorAttribsSiz
e); | 849 flags |= GrDefaultGeoProcFactory::kColor_GPType | |
| 850 GrDefaultGeoProcFactory::kLocalCoord_GPType; |
873 } else if (texCoords) { | 851 } else if (texCoords) { |
874 *texOffset = sizeof(SkPoint); | 852 *texOffset = sizeof(SkPoint); |
875 drawState->setVertexAttribs<gPosUVColorAttribs>(2, kPosUVAttribsSize); | 853 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
876 } else if (colors) { | 854 } else if (colors) { |
877 *colorOffset = sizeof(SkPoint); | 855 *colorOffset = sizeof(SkPoint); |
878 drawState->setVertexAttribs<gPosColorAttribs>(2, kPosColorAttribsSize); | 856 flags |= GrDefaultGeoProcFactory::kColor_GPType; |
879 } else { | |
880 drawState->setVertexAttribs<gPosColorAttribs>(1, kPosAttribsSize); | |
881 } | 857 } |
| 858 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::CreateAndSetAttribs
(drawState, |
| 859
flags))->unref(); |
882 } | 860 } |
883 | 861 |
884 }; | |
885 | |
886 void GrContext::drawVertices(const GrPaint& paint, | 862 void GrContext::drawVertices(const GrPaint& paint, |
887 GrPrimitiveType primitiveType, | 863 GrPrimitiveType primitiveType, |
888 int vertexCount, | 864 int vertexCount, |
889 const SkPoint positions[], | 865 const SkPoint positions[], |
890 const SkPoint texCoords[], | 866 const SkPoint texCoords[], |
891 const GrColor colors[], | 867 const GrColor colors[], |
892 const uint16_t indices[], | 868 const uint16_t indices[], |
893 int indexCount) { | 869 int indexCount) { |
894 AutoRestoreEffects are; | 870 AutoRestoreEffects are; |
895 AutoCheckFlush acf(this); | 871 AutoCheckFlush acf(this); |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1778 fResourceCache->printStats(); | 1754 fResourceCache->printStats(); |
1779 } | 1755 } |
1780 #endif | 1756 #endif |
1781 | 1757 |
1782 #if GR_GPU_STATS | 1758 #if GR_GPU_STATS |
1783 const GrContext::GPUStats* GrContext::gpuStats() const { | 1759 const GrContext::GPUStats* GrContext::gpuStats() const { |
1784 return fGpu->gpuStats(); | 1760 return fGpu->gpuStats(); |
1785 } | 1761 } |
1786 #endif | 1762 #endif |
1787 | 1763 |
OLD | NEW |