| 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 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 1908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1919 if (path && path->isEqualTo(inPath, stroke)) { | 1919 if (path && path->isEqualTo(inPath, stroke)) { |
| 1920 path->ref(); | 1920 path->ref(); |
| 1921 } else { | 1921 } else { |
| 1922 path = fGpu->createPath(inPath, stroke); | 1922 path = fGpu->createPath(inPath, stroke); |
| 1923 fResourceCache->purgeAsNeeded(1, path->gpuMemorySize()); | 1923 fResourceCache->purgeAsNeeded(1, path->gpuMemorySize()); |
| 1924 fResourceCache->addResource(resourceKey, path); | 1924 fResourceCache->addResource(resourceKey, path); |
| 1925 } | 1925 } |
| 1926 return path; | 1926 return path; |
| 1927 } | 1927 } |
| 1928 | 1928 |
| 1929 GrPathRange* GrContext::createGlyphs(const SkTypeface* typeface, |
| 1930 const SkDescriptor* desc, |
| 1931 const SkStrokeRec& stroke) { |
| 1932 static const GrCacheID::Domain gGlyphsDomain = GrCacheID::GenerateDomain(); |
| 1933 |
| 1934 SkASSERT(fGpu->caps()->pathRenderingSupport()); |
| 1935 |
| 1936 GrCacheID::Key key; |
| 1937 uint64_t* keyData = key.fData64; |
| 1938 keyData[0] = desc ? desc->getChecksum() : 0; |
| 1939 keyData[0] = (keyData[0] << 32) | (typeface ? typeface->uniqueID() : 0); |
| 1940 keyData[1] = GrPath::ComputeStrokeKey(stroke); |
| 1941 GrResourceKey resourceKey = GrResourceKey(GrCacheID(gGlyphsDomain, key), |
| 1942 GrPathRange::resourceType(), 0); |
| 1943 |
| 1944 GrPathRange* glyphs = static_cast<GrPathRange*>(fResourceCache->find(resourc
eKey)); |
| 1945 if (glyphs && (NULL == desc || glyphs->isEqualTo(*desc))) { |
| 1946 glyphs->ref(); |
| 1947 } else { |
| 1948 glyphs = fGpu->createGlyphs(typeface, desc, stroke); |
| 1949 fResourceCache->purgeAsNeeded(1, glyphs->gpuMemorySize()); |
| 1950 fResourceCache->addResource(resourceKey, glyphs); |
| 1951 } |
| 1952 return glyphs; |
| 1953 } |
| 1954 |
| 1929 void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResour
ce* resource) { | 1955 void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResour
ce* resource) { |
| 1930 fResourceCache->purgeAsNeeded(1, resource->gpuMemorySize()); | 1956 fResourceCache->purgeAsNeeded(1, resource->gpuMemorySize()); |
| 1931 fResourceCache->addResource(resourceKey, resource); | 1957 fResourceCache->addResource(resourceKey, resource); |
| 1932 } | 1958 } |
| 1933 | 1959 |
| 1934 GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resource
Key) { | 1960 GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resource
Key) { |
| 1935 GrGpuResource* resource = fResourceCache->find(resourceKey); | 1961 GrGpuResource* resource = fResourceCache->find(resourceKey); |
| 1936 SkSafeRef(resource); | 1962 SkSafeRef(resource); |
| 1937 return resource; | 1963 return resource; |
| 1938 } | 1964 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1950 fDrawBuffer->removeGpuTraceMarker(marker); | 1976 fDrawBuffer->removeGpuTraceMarker(marker); |
| 1951 } | 1977 } |
| 1952 } | 1978 } |
| 1953 | 1979 |
| 1954 /////////////////////////////////////////////////////////////////////////////// | 1980 /////////////////////////////////////////////////////////////////////////////// |
| 1955 #if GR_CACHE_STATS | 1981 #if GR_CACHE_STATS |
| 1956 void GrContext::printCacheStats() const { | 1982 void GrContext::printCacheStats() const { |
| 1957 fResourceCache->printStats(); | 1983 fResourceCache->printStats(); |
| 1958 } | 1984 } |
| 1959 #endif | 1985 #endif |
| OLD | NEW |