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 "GrAARectRenderer.h" | 11 #include "GrAARectRenderer.h" |
12 #include "GrAtlasTextContext.h" | 12 #include "GrAtlasTextContext.h" |
13 #include "GrBatch.h" | 13 #include "GrBatch.h" |
14 #include "GrBatchFontCache.h" | 14 #include "GrBatchFontCache.h" |
15 #include "GrBatchTarget.h" | 15 #include "GrBatchTarget.h" |
| 16 #include "GrBatchTest.h" |
16 #include "GrDefaultGeoProcFactory.h" | 17 #include "GrDefaultGeoProcFactory.h" |
17 #include "GrGpuResource.h" | 18 #include "GrGpuResource.h" |
18 #include "GrGpuResourcePriv.h" | 19 #include "GrGpuResourcePriv.h" |
19 #include "GrDrawTargetCaps.h" | 20 #include "GrDrawTargetCaps.h" |
20 #include "GrGpu.h" | 21 #include "GrGpu.h" |
21 #include "GrIndexBuffer.h" | 22 #include "GrIndexBuffer.h" |
22 #include "GrInOrderDrawBuffer.h" | 23 #include "GrInOrderDrawBuffer.h" |
23 #include "GrLayerCache.h" | 24 #include "GrLayerCache.h" |
24 #include "GrOvalRenderer.h" | 25 #include "GrOvalRenderer.h" |
25 #include "GrPathRenderer.h" | 26 #include "GrPathRenderer.h" |
(...skipping 1833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 fDrawBuffer->addGpuTraceMarker(marker); | 1860 fDrawBuffer->addGpuTraceMarker(marker); |
1860 } | 1861 } |
1861 } | 1862 } |
1862 | 1863 |
1863 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 1864 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
1864 fGpu->removeGpuTraceMarker(marker); | 1865 fGpu->removeGpuTraceMarker(marker); |
1865 if (fDrawBuffer) { | 1866 if (fDrawBuffer) { |
1866 fDrawBuffer->removeGpuTraceMarker(marker); | 1867 fDrawBuffer->removeGpuTraceMarker(marker); |
1867 } | 1868 } |
1868 } | 1869 } |
| 1870 |
| 1871 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 1872 |
| 1873 #ifdef GR_TEST_UTILS |
| 1874 |
| 1875 BATCH_TEST_DEFINE(StrokeRect) { |
| 1876 StrokeRectBatch::Geometry geometry; |
| 1877 geometry.fViewMatrix = GrTest::TestMatrix(random); |
| 1878 geometry.fColor = GrRandomColor(random); |
| 1879 geometry.fRect = GrTest::TestRect(random); |
| 1880 geometry.fStrokeWidth = random->nextBool() ? 0.0f : 1.0f; |
| 1881 |
| 1882 return StrokeRectBatch::Create(geometry); |
| 1883 } |
| 1884 |
| 1885 static uint32_t seed_vertices(GrPrimitiveType type) { |
| 1886 switch (type) { |
| 1887 case kTriangles_GrPrimitiveType: |
| 1888 case kTriangleStrip_GrPrimitiveType: |
| 1889 case kTriangleFan_GrPrimitiveType: |
| 1890 return 3; |
| 1891 case kPoints_GrPrimitiveType: |
| 1892 return 1; |
| 1893 case kLines_GrPrimitiveType: |
| 1894 case kLineStrip_GrPrimitiveType: |
| 1895 return 2; |
| 1896 } |
| 1897 SkFAIL("Incomplete switch\n"); |
| 1898 return 0; |
| 1899 } |
| 1900 |
| 1901 static uint32_t primitive_vertices(GrPrimitiveType type) { |
| 1902 switch (type) { |
| 1903 case kTriangles_GrPrimitiveType: |
| 1904 return 3; |
| 1905 case kLines_GrPrimitiveType: |
| 1906 return 2; |
| 1907 case kTriangleStrip_GrPrimitiveType: |
| 1908 case kTriangleFan_GrPrimitiveType: |
| 1909 case kPoints_GrPrimitiveType: |
| 1910 case kLineStrip_GrPrimitiveType: |
| 1911 return 1; |
| 1912 } |
| 1913 SkFAIL("Incomplete switch\n"); |
| 1914 return 0; |
| 1915 } |
| 1916 |
| 1917 static SkPoint random_point(SkRandom* random, SkScalar min, SkScalar max) { |
| 1918 SkPoint p; |
| 1919 p.fX = random->nextRangeScalar(min, max); |
| 1920 p.fY = random->nextRangeScalar(min, max); |
| 1921 return p; |
| 1922 } |
| 1923 |
| 1924 static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkSca
lar max, |
| 1925 SkRandom* random, |
| 1926 SkTArray<SkPoint>* positions, |
| 1927 SkTArray<SkPoint>* texCoords, bool hasTexCoords, |
| 1928 SkTArray<GrColor>* colors, bool hasColors, |
| 1929 SkTArray<uint16_t>* indices, bool hasIndices) { |
| 1930 for (uint32_t v = 0; v < count; v++) { |
| 1931 positions->push_back(random_point(random, min, max)); |
| 1932 if (hasTexCoords) { |
| 1933 texCoords->push_back(random_point(random, min, max)); |
| 1934 } |
| 1935 if (hasColors) { |
| 1936 colors->push_back(GrRandomColor(random)); |
| 1937 } |
| 1938 if (hasIndices) { |
| 1939 SkASSERT(maxVertex <= SK_MaxU16); |
| 1940 indices->push_back(random->nextULessThan((uint16_t)maxVertex)); |
| 1941 } |
| 1942 } |
| 1943 } |
| 1944 |
| 1945 BATCH_TEST_DEFINE(Vertices) { |
| 1946 GrPrimitiveType type = GrPrimitiveType(random->nextULessThan(kLast_GrPrimiti
veType + 1)); |
| 1947 uint32_t primitiveCount = random->nextRangeU(1, 100); |
| 1948 |
| 1949 // TODO make 'sensible' indexbuffers |
| 1950 SkTArray<SkPoint> positions; |
| 1951 SkTArray<SkPoint> texCoords; |
| 1952 SkTArray<GrColor> colors; |
| 1953 SkTArray<uint16_t> indices; |
| 1954 |
| 1955 bool hasTexCoords = random->nextBool(); |
| 1956 bool hasIndices = random->nextBool(); |
| 1957 bool hasColors = random->nextBool(); |
| 1958 |
| 1959 uint32_t vertexCount = seed_vertices(type) + (primitiveCount - 1) * primitiv
e_vertices(type); |
| 1960 |
| 1961 static const SkScalar kMinVertExtent = -100.f; |
| 1962 static const SkScalar kMaxVertExtent = 100.f; |
| 1963 randomize_params(seed_vertices(type), vertexCount, kMinVertExtent, kMaxVertE
xtent, |
| 1964 random, |
| 1965 &positions, |
| 1966 &texCoords, hasTexCoords, |
| 1967 &colors, hasColors, |
| 1968 &indices, hasIndices); |
| 1969 |
| 1970 for (uint32_t i = 1; i < primitiveCount; i++) { |
| 1971 randomize_params(primitive_vertices(type), vertexCount, kMinVertExtent,
kMaxVertExtent, |
| 1972 random, |
| 1973 &positions, |
| 1974 &texCoords, hasTexCoords, |
| 1975 &colors, hasColors, |
| 1976 &indices, hasIndices); |
| 1977 } |
| 1978 |
| 1979 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 1980 SkRect bounds; |
| 1981 SkDEBUGCODE(bool result = ) bounds.setBoundsCheck(positions.begin(), vertexC
ount); |
| 1982 SkASSERT(result); |
| 1983 |
| 1984 viewMatrix.mapRect(&bounds); |
| 1985 |
| 1986 DrawVerticesBatch::Geometry geometry; |
| 1987 geometry.fColor = GrRandomColor(random); |
| 1988 return DrawVerticesBatch::Create(geometry, type, viewMatrix, |
| 1989 positions.begin(), vertexCount, |
| 1990 indices.begin(), hasIndices ? vertexCount :
0, |
| 1991 colors.begin(), |
| 1992 texCoords.begin(), |
| 1993 bounds); |
| 1994 } |
| 1995 |
| 1996 #endif |
OLD | NEW |