Chromium Code Reviews| 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 "GrBufferAllocPool.h" | 17 #include "GrBufferAllocPool.h" |
| 17 #include "GrDefaultGeoProcFactory.h" | 18 #include "GrDefaultGeoProcFactory.h" |
| 18 #include "GrGpuResource.h" | 19 #include "GrGpuResource.h" |
| 19 #include "GrGpuResourcePriv.h" | 20 #include "GrGpuResourcePriv.h" |
| 20 #include "GrDrawTargetCaps.h" | 21 #include "GrDrawTargetCaps.h" |
| 21 #include "GrGpu.h" | 22 #include "GrGpu.h" |
| 22 #include "GrIndexBuffer.h" | 23 #include "GrIndexBuffer.h" |
| 23 #include "GrInOrderDrawBuffer.h" | 24 #include "GrInOrderDrawBuffer.h" |
| 24 #include "GrLayerCache.h" | 25 #include "GrLayerCache.h" |
| 25 #include "GrOvalRenderer.h" | 26 #include "GrOvalRenderer.h" |
| (...skipping 1875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1901 fDrawBuffer->addGpuTraceMarker(marker); | 1902 fDrawBuffer->addGpuTraceMarker(marker); |
| 1902 } | 1903 } |
| 1903 } | 1904 } |
| 1904 | 1905 |
| 1905 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 1906 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 1906 fGpu->removeGpuTraceMarker(marker); | 1907 fGpu->removeGpuTraceMarker(marker); |
| 1907 if (fDrawBuffer) { | 1908 if (fDrawBuffer) { |
| 1908 fDrawBuffer->removeGpuTraceMarker(marker); | 1909 fDrawBuffer->removeGpuTraceMarker(marker); |
| 1909 } | 1910 } |
| 1910 } | 1911 } |
| 1912 | |
| 1913 //////////////////////////////////////////////////////////////////////////////// /////////////////// | |
| 1914 | |
| 1915 #ifdef GR_TEST_UTILS | |
| 1916 | |
| 1917 BATCH_TEST_DEFINE(StrokeRect) { | |
| 1918 StrokeRectBatch::Geometry geometry; | |
| 1919 geometry.fViewMatrix = GrTest::TestMatrix(random); | |
| 1920 geometry.fColor = GrRandomColor(random); | |
| 1921 geometry.fRect = GrTest::TestRect(random); | |
|
robertphillips
2015/05/08 18:32:17
A big one? 10?
| |
| 1922 geometry.fStrokeWidth = random->nextBool() ? 0.0f : 1.0f; | |
| 1923 | |
| 1924 return StrokeRectBatch::Create(geometry); | |
| 1925 } | |
| 1926 | |
| 1927 static int seed_vertices(GrPrimitiveType type) { | |
|
robertphillips
2015/05/08 18:40:13
space between 'h' and '(' ?
| |
| 1928 switch(type) { | |
|
robertphillips
2015/05/08 18:32:17
add // fall throughs
?
| |
| 1929 case kTriangles_GrPrimitiveType: | |
| 1930 case kTriangleStrip_GrPrimitiveType: | |
| 1931 case kTriangleFan_GrPrimitiveType: | |
| 1932 return 3; | |
| 1933 case kPoints_GrPrimitiveType: | |
| 1934 return 1; | |
| 1935 case kLines_GrPrimitiveType: | |
| 1936 case kLineStrip_GrPrimitiveType: | |
| 1937 return 2; | |
| 1938 } | |
| 1939 SkFAIL("Incomplete switch\n"); | |
| 1940 return 0; | |
| 1941 } | |
| 1942 | |
| 1943 static int primitive_vertices(GrPrimitiveType type) { | |
| 1944 switch(type) { | |
| 1945 case kTriangles_GrPrimitiveType: | |
| 1946 return 3; | |
| 1947 case kLines_GrPrimitiveType: | |
| 1948 return 2; | |
| 1949 case kTriangleStrip_GrPrimitiveType: | |
| 1950 case kTriangleFan_GrPrimitiveType: | |
| 1951 case kPoints_GrPrimitiveType: | |
| 1952 case kLineStrip_GrPrimitiveType: | |
| 1953 return 1; | |
| 1954 } | |
| 1955 SkFAIL("Incomplete switch\n"); | |
| 1956 return 0; | |
| 1957 } | |
| 1958 | |
| 1959 static SkPoint random_point(SkRandom* random, SkScalar min, SkScalar max) { | |
| 1960 SkPoint p; | |
| 1961 p.fX = random->nextRangeScalar(min, max); | |
| 1962 p.fY = random->nextRangeScalar(min, max); | |
| 1963 return p; | |
| 1964 } | |
| 1965 | |
|
robertphillips
2015/05/08 18:40:13
Actually use min & max ?
| |
| 1966 static void randomize_params(int count, int maxVertex, SkScalar min, SkScalar ma x, | |
| 1967 SkRandom* random, | |
| 1968 SkTArray<SkPoint>* positions, | |
| 1969 SkTArray<SkPoint>* texCoords, bool hasTexCoords, | |
| 1970 SkTArray<GrColor>* colors, bool hasColors, | |
| 1971 SkTArray<uint16_t>* indices, bool hasIndices) { | |
| 1972 for (int v = 0; v < count; v++) { | |
| 1973 positions->push_back(random_point(random, -100.f, 100.f)); | |
| 1974 if (hasTexCoords) { | |
| 1975 texCoords->push_back(random_point(random, -100.f, 100.f)); | |
| 1976 } | |
| 1977 if (hasColors) { | |
| 1978 colors->push_back(GrRandomColor(random)); | |
| 1979 } | |
| 1980 if (hasIndices) { | |
| 1981 indices->push_back(random->nextULessThan(maxVertex)); | |
| 1982 } | |
| 1983 } | |
| 1984 } | |
| 1985 | |
| 1986 BATCH_TEST_DEFINE(Vertices) { | |
| 1987 GrPrimitiveType type = GrPrimitiveType(random->nextULessThan(kLast_GrPrimiti veType + 1)); | |
| 1988 int primitiveCount = random->nextRangeU(1, 100); | |
| 1989 | |
| 1990 // TODO make 'sensible' indexbuffers | |
| 1991 SkTArray<SkPoint> positions; | |
| 1992 SkTArray<SkPoint> texCoords; | |
| 1993 SkTArray<GrColor> colors; | |
| 1994 SkTArray<uint16_t> indices; | |
| 1995 | |
| 1996 bool hasTexCoords = random->nextBool(); | |
| 1997 bool hasIndices = random->nextBool(); | |
| 1998 bool hasColors = random->nextBool(); | |
| 1999 | |
| 2000 int vertexCount = seed_vertices(type) + (primitiveCount - 1) * primitive_ver tices(type); | |
| 2001 | |
| 2002 int i = 1; | |
|
robertphillips
2015/05/08 18:40:13
Maybe kMinVertExtent, kMaxVertExtent instead of -1
| |
| 2003 randomize_params(seed_vertices(type), vertexCount, -100.f, 100.f, | |
| 2004 random, | |
| 2005 &positions, | |
| 2006 &texCoords, hasTexCoords, | |
| 2007 &colors, hasColors, | |
| 2008 &indices, hasIndices); | |
| 2009 | |
|
robertphillips
2015/05/08 18:32:17
I, personally, would do "for (int i = 1; ..." but
| |
| 2010 for (; i < primitiveCount; i++) { | |
| 2011 randomize_params(primitive_vertices(type), vertexCount, -100.f, 100.f, | |
| 2012 random, | |
| 2013 &positions, | |
| 2014 &texCoords, hasTexCoords, | |
| 2015 &colors, hasColors, | |
| 2016 &indices, hasIndices); | |
| 2017 } | |
| 2018 | |
| 2019 SkMatrix viewMatrix = GrTest::TestMatrix(random); | |
| 2020 SkRect bounds; | |
|
robertphillips
2015/05/08 18:40:13
Don't we want to assert that the bound is finite ?
| |
| 2021 SkDEBUGCODE(bool result = ) !bounds.setBoundsCheck(positions.begin(), vertex Count); | |
| 2022 SkASSERT(result); | |
| 2023 | |
| 2024 viewMatrix.mapRect(&bounds); | |
| 2025 | |
| 2026 DrawVerticesBatch::Geometry geometry; | |
| 2027 geometry.fColor = GrRandomColor(random); | |
| 2028 return DrawVerticesBatch::Create(geometry, type, viewMatrix, | |
| 2029 positions.begin(), vertexCount, | |
| 2030 indices.begin(), hasIndices ? vertexCount : 0, | |
| 2031 colors.begin(), | |
| 2032 texCoords.begin(), | |
| 2033 bounds); | |
| 2034 } | |
| 2035 | |
| 2036 #endif | |
| OLD | NEW |