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 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "GrPathUtils.h" | 23 #include "GrPathUtils.h" |
| 24 #include "GrResourceCache.h" | 24 #include "GrResourceCache.h" |
| 25 #include "GrSoftwarePathRenderer.h" | 25 #include "GrSoftwarePathRenderer.h" |
| 26 #include "GrStencilBuffer.h" | 26 #include "GrStencilBuffer.h" |
| 27 #include "GrTextStrike.h" | 27 #include "GrTextStrike.h" |
| 28 #include "SkRTConf.h" | 28 #include "SkRTConf.h" |
| 29 #include "SkRRect.h" | 29 #include "SkRRect.h" |
| 30 #include "SkStrokeRec.h" | 30 #include "SkStrokeRec.h" |
| 31 #include "SkTLazy.h" | 31 #include "SkTLazy.h" |
| 32 #include "SkTLS.h" | 32 #include "SkTLS.h" |
| 33 #include "SkTrace.h" | 33 #include "SkTraceEvent.h" |
| 34 | 34 |
| 35 // It can be useful to set this to false to test whether a bug is caused by usin g the | 35 // It can be useful to set this to false to test whether a bug is caused by usin g the |
| 36 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe r, or to make | 36 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe r, or to make |
| 37 // debugging simpler. | 37 // debugging simpler. |
| 38 SK_CONF_DECLARE(bool, c_Defer, "gpu.deferContext", true, | 38 SK_CONF_DECLARE(bool, c_Defer, "gpu.deferContext", true, |
| 39 "Defers rendering in GrContext via GrInOrderDrawBuffer."); | 39 "Defers rendering in GrContext via GrInOrderDrawBuffer."); |
| 40 | 40 |
| 41 #define BUFFERED_DRAW (c_Defer ? kYes_BufferedDraw : kNo_BufferedDraw) | 41 #define BUFFERED_DRAW (c_Defer ? kYes_BufferedDraw : kNo_BufferedDraw) |
| 42 | 42 |
| 43 #ifdef SK_DEBUG | 43 #ifdef SK_DEBUG |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 | 364 |
| 365 return texture; | 365 return texture; |
| 366 } | 366 } |
| 367 | 367 |
| 368 GrTexture* GrContext::createTexture(const GrTextureParams* params, | 368 GrTexture* GrContext::createTexture(const GrTextureParams* params, |
| 369 const GrTextureDesc& desc, | 369 const GrTextureDesc& desc, |
| 370 const GrCacheID& cacheID, | 370 const GrCacheID& cacheID, |
| 371 void* srcData, | 371 void* srcData, |
| 372 size_t rowBytes, | 372 size_t rowBytes, |
| 373 GrResourceKey* cacheKey) { | 373 GrResourceKey* cacheKey) { |
| 374 SK_TRACE_EVENT0("GrContext::createTexture"); | 374 TRACE_EVENT0("skia.ganesh","GrContext::createTexture"); |
|
epoger
2014/03/19 21:34:45
Should we use a macro or constant for the recurrin
| |
| 375 | 375 |
| 376 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI D); | 376 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI D); |
| 377 | 377 |
| 378 GrTexture* texture; | 378 GrTexture* texture; |
| 379 if (GrTexture::NeedsResizing(resourceKey)) { | 379 if (GrTexture::NeedsResizing(resourceKey)) { |
| 380 texture = this->createResizedTexture(desc, cacheID, | 380 texture = this->createResizedTexture(desc, cacheID, |
| 381 srcData, rowBytes, | 381 srcData, rowBytes, |
| 382 GrTexture::NeedsBilerp(resourceKey) ); | 382 GrTexture::NeedsBilerp(resourceKey) ); |
| 383 } else { | 383 } else { |
| 384 texture= fGpu->createTexture(desc, srcData, rowBytes); | 384 texture= fGpu->createTexture(desc, srcData, rowBytes); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 | 757 |
| 758 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) { | 758 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) { |
| 759 return point.fX >= rect.fLeft && point.fX <= rect.fRight && | 759 return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 760 point.fY >= rect.fTop && point.fY <= rect.fBottom; | 760 point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 761 } | 761 } |
| 762 | 762 |
| 763 void GrContext::drawRect(const GrPaint& paint, | 763 void GrContext::drawRect(const GrPaint& paint, |
| 764 const SkRect& rect, | 764 const SkRect& rect, |
| 765 const SkStrokeRec* stroke, | 765 const SkStrokeRec* stroke, |
| 766 const SkMatrix* matrix) { | 766 const SkMatrix* matrix) { |
| 767 SK_TRACE_EVENT0("GrContext::drawRect"); | 767 TRACE_EVENT0("skia.ganesh","GrContext::drawRect"); |
| 768 | 768 |
| 769 AutoRestoreEffects are; | 769 AutoRestoreEffects are; |
| 770 AutoCheckFlush acf(this); | 770 AutoCheckFlush acf(this); |
| 771 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); | 771 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); |
| 772 | 772 |
| 773 SkScalar width = stroke == NULL ? -1 : stroke->getWidth(); | 773 SkScalar width = stroke == NULL ? -1 : stroke->getWidth(); |
| 774 SkMatrix combinedMatrix = target->drawState()->getViewMatrix(); | 774 SkMatrix combinedMatrix = target->drawState()->getViewMatrix(); |
| 775 if (NULL != matrix) { | 775 if (NULL != matrix) { |
| 776 combinedMatrix.preConcat(*matrix); | 776 combinedMatrix.preConcat(*matrix); |
| 777 } | 777 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 879 // filled BW rect | 879 // filled BW rect |
| 880 target->drawSimpleRect(rect, matrix); | 880 target->drawSimpleRect(rect, matrix); |
| 881 } | 881 } |
| 882 } | 882 } |
| 883 | 883 |
| 884 void GrContext::drawRectToRect(const GrPaint& paint, | 884 void GrContext::drawRectToRect(const GrPaint& paint, |
| 885 const SkRect& dstRect, | 885 const SkRect& dstRect, |
| 886 const SkRect& localRect, | 886 const SkRect& localRect, |
| 887 const SkMatrix* dstMatrix, | 887 const SkMatrix* dstMatrix, |
| 888 const SkMatrix* localMatrix) { | 888 const SkMatrix* localMatrix) { |
| 889 SK_TRACE_EVENT0("GrContext::drawRectToRect"); | 889 TRACE_EVENT0("skia.ganesh","GrContext::drawRectToRect"); |
| 890 AutoRestoreEffects are; | 890 AutoRestoreEffects are; |
| 891 AutoCheckFlush acf(this); | 891 AutoCheckFlush acf(this); |
| 892 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); | 892 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); |
| 893 | 893 |
| 894 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); | 894 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); |
| 895 } | 895 } |
| 896 | 896 |
| 897 namespace { | 897 namespace { |
| 898 | 898 |
| 899 extern const GrVertexAttrib gPosUVColorAttribs[] = { | 899 extern const GrVertexAttrib gPosUVColorAttribs[] = { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 933 }; | 933 }; |
| 934 | 934 |
| 935 void GrContext::drawVertices(const GrPaint& paint, | 935 void GrContext::drawVertices(const GrPaint& paint, |
| 936 GrPrimitiveType primitiveType, | 936 GrPrimitiveType primitiveType, |
| 937 int vertexCount, | 937 int vertexCount, |
| 938 const GrPoint positions[], | 938 const GrPoint positions[], |
| 939 const GrPoint texCoords[], | 939 const GrPoint texCoords[], |
| 940 const GrColor colors[], | 940 const GrColor colors[], |
| 941 const uint16_t indices[], | 941 const uint16_t indices[], |
| 942 int indexCount) { | 942 int indexCount) { |
| 943 SK_TRACE_EVENT0("GrContext::drawVertices"); | 943 TRACE_EVENT0("skia.ganesh","GrContext::drawVertices"); |
| 944 | 944 |
| 945 AutoRestoreEffects are; | 945 AutoRestoreEffects are; |
| 946 AutoCheckFlush acf(this); | 946 AutoCheckFlush acf(this); |
| 947 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e | 947 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e |
| 948 | 948 |
| 949 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); | 949 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); |
| 950 | 950 |
| 951 GrDrawState* drawState = target->drawState(); | 951 GrDrawState* drawState = target->drawState(); |
| 952 | 952 |
| 953 int colorOffset = -1, texOffset = -1; | 953 int colorOffset = -1, texOffset = -1; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1195 } else { | 1195 } else { |
| 1196 fDrawBuffer->flush(); | 1196 fDrawBuffer->flush(); |
| 1197 } | 1197 } |
| 1198 fFlushToReduceCacheSize = false; | 1198 fFlushToReduceCacheSize = false; |
| 1199 } | 1199 } |
| 1200 | 1200 |
| 1201 bool GrContext::writeTexturePixels(GrTexture* texture, | 1201 bool GrContext::writeTexturePixels(GrTexture* texture, |
| 1202 int left, int top, int width, int height, | 1202 int left, int top, int width, int height, |
| 1203 GrPixelConfig config, const void* buffer, siz e_t rowBytes, | 1203 GrPixelConfig config, const void* buffer, siz e_t rowBytes, |
| 1204 uint32_t flags) { | 1204 uint32_t flags) { |
| 1205 SK_TRACE_EVENT0("GrContext::writeTexturePixels"); | 1205 TRACE_EVENT0("skia.ganesh","GrContext::writeTexturePixels"); |
| 1206 ASSERT_OWNED_RESOURCE(texture); | 1206 ASSERT_OWNED_RESOURCE(texture); |
| 1207 | 1207 |
| 1208 if ((kUnpremul_PixelOpsFlag & flags) || !fGpu->canWriteTexturePixels(texture , config)) { | 1208 if ((kUnpremul_PixelOpsFlag & flags) || !fGpu->canWriteTexturePixels(texture , config)) { |
| 1209 if (NULL != texture->asRenderTarget()) { | 1209 if (NULL != texture->asRenderTarget()) { |
| 1210 return this->writeRenderTargetPixels(texture->asRenderTarget(), | 1210 return this->writeRenderTargetPixels(texture->asRenderTarget(), |
| 1211 left, top, width, height, | 1211 left, top, width, height, |
| 1212 config, buffer, rowBytes, flags ); | 1212 config, buffer, rowBytes, flags ); |
| 1213 } else { | 1213 } else { |
| 1214 return false; | 1214 return false; |
| 1215 } | 1215 } |
| 1216 } | 1216 } |
| 1217 | 1217 |
| 1218 if (!(kDontFlush_PixelOpsFlag & flags)) { | 1218 if (!(kDontFlush_PixelOpsFlag & flags)) { |
| 1219 this->flush(); | 1219 this->flush(); |
| 1220 } | 1220 } |
| 1221 | 1221 |
| 1222 return fGpu->writeTexturePixels(texture, left, top, width, height, | 1222 return fGpu->writeTexturePixels(texture, left, top, width, height, |
| 1223 config, buffer, rowBytes); | 1223 config, buffer, rowBytes); |
| 1224 } | 1224 } |
| 1225 | 1225 |
| 1226 bool GrContext::readTexturePixels(GrTexture* texture, | 1226 bool GrContext::readTexturePixels(GrTexture* texture, |
| 1227 int left, int top, int width, int height, | 1227 int left, int top, int width, int height, |
| 1228 GrPixelConfig config, void* buffer, size_t row Bytes, | 1228 GrPixelConfig config, void* buffer, size_t row Bytes, |
| 1229 uint32_t flags) { | 1229 uint32_t flags) { |
| 1230 SK_TRACE_EVENT0("GrContext::readTexturePixels"); | 1230 TRACE_EVENT0("skia.ganesh","GrContext::readTexturePixels"); |
| 1231 ASSERT_OWNED_RESOURCE(texture); | 1231 ASSERT_OWNED_RESOURCE(texture); |
| 1232 | 1232 |
| 1233 GrRenderTarget* target = texture->asRenderTarget(); | 1233 GrRenderTarget* target = texture->asRenderTarget(); |
| 1234 if (NULL != target) { | 1234 if (NULL != target) { |
| 1235 return this->readRenderTargetPixels(target, | 1235 return this->readRenderTargetPixels(target, |
| 1236 left, top, width, height, | 1236 left, top, width, height, |
| 1237 config, buffer, rowBytes, | 1237 config, buffer, rowBytes, |
| 1238 flags); | 1238 flags); |
| 1239 } else { | 1239 } else { |
| 1240 // TODO: make this more efficient for cases where we're reading the enti re | 1240 // TODO: make this more efficient for cases where we're reading the enti re |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1310 GrCrash("Unexpected input"); | 1310 GrCrash("Unexpected input"); |
| 1311 return SkCanvas::kBGRA_Unpremul_Config8888;; | 1311 return SkCanvas::kBGRA_Unpremul_Config8888;; |
| 1312 } | 1312 } |
| 1313 } | 1313 } |
| 1314 } | 1314 } |
| 1315 | 1315 |
| 1316 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, | 1316 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, |
| 1317 int left, int top, int width, int height, | 1317 int left, int top, int width, int height, |
| 1318 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes, | 1318 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes, |
| 1319 uint32_t flags) { | 1319 uint32_t flags) { |
| 1320 SK_TRACE_EVENT0("GrContext::readRenderTargetPixels"); | 1320 TRACE_EVENT0("skia.ganesh","GrContext::readRenderTargetPixels"); |
| 1321 ASSERT_OWNED_RESOURCE(target); | 1321 ASSERT_OWNED_RESOURCE(target); |
| 1322 | 1322 |
| 1323 if (NULL == target) { | 1323 if (NULL == target) { |
| 1324 target = fRenderTarget.get(); | 1324 target = fRenderTarget.get(); |
| 1325 if (NULL == target) { | 1325 if (NULL == target) { |
| 1326 return false; | 1326 return false; |
| 1327 } | 1327 } |
| 1328 } | 1328 } |
| 1329 | 1329 |
| 1330 if (!(kDontFlush_PixelOpsFlag & flags)) { | 1330 if (!(kDontFlush_PixelOpsFlag & flags)) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1498 SkRect dstR = SkRect::MakeWH(SkIntToScalar(srcRect.width()), SkIntToScalar(s rcRect.height())); | 1498 SkRect dstR = SkRect::MakeWH(SkIntToScalar(srcRect.width()), SkIntToScalar(s rcRect.height())); |
| 1499 fGpu->drawSimpleRect(dstR, NULL); | 1499 fGpu->drawSimpleRect(dstR, NULL); |
| 1500 } | 1500 } |
| 1501 | 1501 |
| 1502 bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, | 1502 bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, |
| 1503 int left, int top, int width, int height , | 1503 int left, int top, int width, int height , |
| 1504 GrPixelConfig srcConfig, | 1504 GrPixelConfig srcConfig, |
| 1505 const void* buffer, | 1505 const void* buffer, |
| 1506 size_t rowBytes, | 1506 size_t rowBytes, |
| 1507 uint32_t flags) { | 1507 uint32_t flags) { |
| 1508 SK_TRACE_EVENT0("GrContext::writeRenderTargetPixels"); | 1508 TRACE_EVENT0("skia.ganesh","GrContext::writeRenderTargetPixels"); |
| 1509 ASSERT_OWNED_RESOURCE(target); | 1509 ASSERT_OWNED_RESOURCE(target); |
| 1510 | 1510 |
| 1511 if (NULL == target) { | 1511 if (NULL == target) { |
| 1512 target = fRenderTarget.get(); | 1512 target = fRenderTarget.get(); |
| 1513 if (NULL == target) { | 1513 if (NULL == target) { |
| 1514 return false; | 1514 return false; |
| 1515 } | 1515 } |
| 1516 } | 1516 } |
| 1517 | 1517 |
| 1518 // TODO: when underlying api has a direct way to do this we should use it (e .g. glDrawPixels on | 1518 // TODO: when underlying api has a direct way to do this we should use it (e .g. glDrawPixels on |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1806 } | 1806 } |
| 1807 return path; | 1807 return path; |
| 1808 } | 1808 } |
| 1809 | 1809 |
| 1810 /////////////////////////////////////////////////////////////////////////////// | 1810 /////////////////////////////////////////////////////////////////////////////// |
| 1811 #if GR_CACHE_STATS | 1811 #if GR_CACHE_STATS |
| 1812 void GrContext::printCacheStats() const { | 1812 void GrContext::printCacheStats() const { |
| 1813 fTextureCache->printStats(); | 1813 fTextureCache->printStats(); |
| 1814 } | 1814 } |
| 1815 #endif | 1815 #endif |
| OLD | NEW |