| 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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 368 |
| 369 return texture; | 369 return texture; |
| 370 } | 370 } |
| 371 | 371 |
| 372 GrTexture* GrContext::createTexture(const GrTextureParams* params, | 372 GrTexture* GrContext::createTexture(const GrTextureParams* params, |
| 373 const GrTextureDesc& desc, | 373 const GrTextureDesc& desc, |
| 374 const GrCacheID& cacheID, | 374 const GrCacheID& cacheID, |
| 375 void* srcData, | 375 void* srcData, |
| 376 size_t rowBytes, | 376 size_t rowBytes, |
| 377 GrResourceKey* cacheKey) { | 377 GrResourceKey* cacheKey) { |
| 378 SK_TRACE_EVENT0("GrContext::createTexture"); | |
| 379 | |
| 380 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI
D); | 378 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI
D); |
| 381 | 379 |
| 382 GrTexture* texture; | 380 GrTexture* texture; |
| 383 if (GrTexture::NeedsResizing(resourceKey)) { | 381 if (GrTexture::NeedsResizing(resourceKey)) { |
| 384 texture = this->createResizedTexture(desc, cacheID, | 382 texture = this->createResizedTexture(desc, cacheID, |
| 385 srcData, rowBytes, | 383 srcData, rowBytes, |
| 386 GrTexture::NeedsBilerp(resourceKey)
); | 384 GrTexture::NeedsBilerp(resourceKey)
); |
| 387 } else { | 385 } else { |
| 388 texture= fGpu->createTexture(desc, srcData, rowBytes); | 386 texture= fGpu->createTexture(desc, srcData, rowBytes); |
| 389 } | 387 } |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 | 759 |
| 762 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
int) { | 760 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
int) { |
| 763 return point.fX >= rect.fLeft && point.fX <= rect.fRight && | 761 return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 764 point.fY >= rect.fTop && point.fY <= rect.fBottom; | 762 point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 765 } | 763 } |
| 766 | 764 |
| 767 void GrContext::drawRect(const GrPaint& paint, | 765 void GrContext::drawRect(const GrPaint& paint, |
| 768 const SkRect& rect, | 766 const SkRect& rect, |
| 769 const SkStrokeRec* stroke, | 767 const SkStrokeRec* stroke, |
| 770 const SkMatrix* matrix) { | 768 const SkMatrix* matrix) { |
| 771 SK_TRACE_EVENT0("GrContext::drawRect"); | |
| 772 | |
| 773 AutoRestoreEffects are; | 769 AutoRestoreEffects are; |
| 774 AutoCheckFlush acf(this); | 770 AutoCheckFlush acf(this); |
| 775 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 771 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
| 776 | 772 |
| 777 SkScalar width = stroke == NULL ? -1 : stroke->getWidth(); | 773 SkScalar width = stroke == NULL ? -1 : stroke->getWidth(); |
| 778 SkMatrix combinedMatrix = target->drawState()->getViewMatrix(); | 774 SkMatrix combinedMatrix = target->drawState()->getViewMatrix(); |
| 779 if (NULL != matrix) { | 775 if (NULL != matrix) { |
| 780 combinedMatrix.preConcat(*matrix); | 776 combinedMatrix.preConcat(*matrix); |
| 781 } | 777 } |
| 782 | 778 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 // filled BW rect | 879 // filled BW rect |
| 884 target->drawSimpleRect(rect, matrix); | 880 target->drawSimpleRect(rect, matrix); |
| 885 } | 881 } |
| 886 } | 882 } |
| 887 | 883 |
| 888 void GrContext::drawRectToRect(const GrPaint& paint, | 884 void GrContext::drawRectToRect(const GrPaint& paint, |
| 889 const SkRect& dstRect, | 885 const SkRect& dstRect, |
| 890 const SkRect& localRect, | 886 const SkRect& localRect, |
| 891 const SkMatrix* dstMatrix, | 887 const SkMatrix* dstMatrix, |
| 892 const SkMatrix* localMatrix) { | 888 const SkMatrix* localMatrix) { |
| 893 SK_TRACE_EVENT0("GrContext::drawRectToRect"); | |
| 894 AutoRestoreEffects are; | 889 AutoRestoreEffects are; |
| 895 AutoCheckFlush acf(this); | 890 AutoCheckFlush acf(this); |
| 896 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 891 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
| 897 | 892 |
| 898 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); | 893 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); |
| 899 } | 894 } |
| 900 | 895 |
| 901 namespace { | 896 namespace { |
| 902 | 897 |
| 903 extern const GrVertexAttrib gPosUVColorAttribs[] = { | 898 extern const GrVertexAttrib gPosUVColorAttribs[] = { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 }; | 932 }; |
| 938 | 933 |
| 939 void GrContext::drawVertices(const GrPaint& paint, | 934 void GrContext::drawVertices(const GrPaint& paint, |
| 940 GrPrimitiveType primitiveType, | 935 GrPrimitiveType primitiveType, |
| 941 int vertexCount, | 936 int vertexCount, |
| 942 const GrPoint positions[], | 937 const GrPoint positions[], |
| 943 const GrPoint texCoords[], | 938 const GrPoint texCoords[], |
| 944 const GrColor colors[], | 939 const GrColor colors[], |
| 945 const uint16_t indices[], | 940 const uint16_t indices[], |
| 946 int indexCount) { | 941 int indexCount) { |
| 947 SK_TRACE_EVENT0("GrContext::drawVertices"); | |
| 948 | |
| 949 AutoRestoreEffects are; | 942 AutoRestoreEffects are; |
| 950 AutoCheckFlush acf(this); | 943 AutoCheckFlush acf(this); |
| 951 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e | 944 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e |
| 952 | 945 |
| 953 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 946 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
| 954 | 947 |
| 955 GrDrawState* drawState = target->drawState(); | 948 GrDrawState* drawState = target->drawState(); |
| 956 | 949 |
| 957 int colorOffset = -1, texOffset = -1; | 950 int colorOffset = -1, texOffset = -1; |
| 958 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset
); | 951 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset
); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 } else { | 1192 } else { |
| 1200 fDrawBuffer->flush(); | 1193 fDrawBuffer->flush(); |
| 1201 } | 1194 } |
| 1202 fFlushToReduceCacheSize = false; | 1195 fFlushToReduceCacheSize = false; |
| 1203 } | 1196 } |
| 1204 | 1197 |
| 1205 bool GrContext::writeTexturePixels(GrTexture* texture, | 1198 bool GrContext::writeTexturePixels(GrTexture* texture, |
| 1206 int left, int top, int width, int height, | 1199 int left, int top, int width, int height, |
| 1207 GrPixelConfig config, const void* buffer, siz
e_t rowBytes, | 1200 GrPixelConfig config, const void* buffer, siz
e_t rowBytes, |
| 1208 uint32_t flags) { | 1201 uint32_t flags) { |
| 1209 SK_TRACE_EVENT0("GrContext::writeTexturePixels"); | |
| 1210 ASSERT_OWNED_RESOURCE(texture); | 1202 ASSERT_OWNED_RESOURCE(texture); |
| 1211 | 1203 |
| 1212 if ((kUnpremul_PixelOpsFlag & flags) || !fGpu->canWriteTexturePixels(texture
, config)) { | 1204 if ((kUnpremul_PixelOpsFlag & flags) || !fGpu->canWriteTexturePixels(texture
, config)) { |
| 1213 if (NULL != texture->asRenderTarget()) { | 1205 if (NULL != texture->asRenderTarget()) { |
| 1214 return this->writeRenderTargetPixels(texture->asRenderTarget(), | 1206 return this->writeRenderTargetPixels(texture->asRenderTarget(), |
| 1215 left, top, width, height, | 1207 left, top, width, height, |
| 1216 config, buffer, rowBytes, flags
); | 1208 config, buffer, rowBytes, flags
); |
| 1217 } else { | 1209 } else { |
| 1218 return false; | 1210 return false; |
| 1219 } | 1211 } |
| 1220 } | 1212 } |
| 1221 | 1213 |
| 1222 if (!(kDontFlush_PixelOpsFlag & flags)) { | 1214 if (!(kDontFlush_PixelOpsFlag & flags)) { |
| 1223 this->flush(); | 1215 this->flush(); |
| 1224 } | 1216 } |
| 1225 | 1217 |
| 1226 return fGpu->writeTexturePixels(texture, left, top, width, height, | 1218 return fGpu->writeTexturePixels(texture, left, top, width, height, |
| 1227 config, buffer, rowBytes); | 1219 config, buffer, rowBytes); |
| 1228 } | 1220 } |
| 1229 | 1221 |
| 1230 bool GrContext::readTexturePixels(GrTexture* texture, | 1222 bool GrContext::readTexturePixels(GrTexture* texture, |
| 1231 int left, int top, int width, int height, | 1223 int left, int top, int width, int height, |
| 1232 GrPixelConfig config, void* buffer, size_t row
Bytes, | 1224 GrPixelConfig config, void* buffer, size_t row
Bytes, |
| 1233 uint32_t flags) { | 1225 uint32_t flags) { |
| 1234 SK_TRACE_EVENT0("GrContext::readTexturePixels"); | |
| 1235 ASSERT_OWNED_RESOURCE(texture); | 1226 ASSERT_OWNED_RESOURCE(texture); |
| 1236 | 1227 |
| 1237 GrRenderTarget* target = texture->asRenderTarget(); | 1228 GrRenderTarget* target = texture->asRenderTarget(); |
| 1238 if (NULL != target) { | 1229 if (NULL != target) { |
| 1239 return this->readRenderTargetPixels(target, | 1230 return this->readRenderTargetPixels(target, |
| 1240 left, top, width, height, | 1231 left, top, width, height, |
| 1241 config, buffer, rowBytes, | 1232 config, buffer, rowBytes, |
| 1242 flags); | 1233 flags); |
| 1243 } else { | 1234 } else { |
| 1244 // TODO: make this more efficient for cases where we're reading the enti
re | 1235 // 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... |
| 1314 GrCrash("Unexpected input"); | 1305 GrCrash("Unexpected input"); |
| 1315 return SkCanvas::kBGRA_Unpremul_Config8888;; | 1306 return SkCanvas::kBGRA_Unpremul_Config8888;; |
| 1316 } | 1307 } |
| 1317 } | 1308 } |
| 1318 } | 1309 } |
| 1319 | 1310 |
| 1320 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, | 1311 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, |
| 1321 int left, int top, int width, int height, | 1312 int left, int top, int width, int height, |
| 1322 GrPixelConfig dstConfig, void* buffer, si
ze_t rowBytes, | 1313 GrPixelConfig dstConfig, void* buffer, si
ze_t rowBytes, |
| 1323 uint32_t flags) { | 1314 uint32_t flags) { |
| 1324 SK_TRACE_EVENT0("GrContext::readRenderTargetPixels"); | |
| 1325 ASSERT_OWNED_RESOURCE(target); | 1315 ASSERT_OWNED_RESOURCE(target); |
| 1326 | 1316 |
| 1327 if (NULL == target) { | 1317 if (NULL == target) { |
| 1328 target = fRenderTarget.get(); | 1318 target = fRenderTarget.get(); |
| 1329 if (NULL == target) { | 1319 if (NULL == target) { |
| 1330 return false; | 1320 return false; |
| 1331 } | 1321 } |
| 1332 } | 1322 } |
| 1333 | 1323 |
| 1334 if (!(kDontFlush_PixelOpsFlag & flags)) { | 1324 if (!(kDontFlush_PixelOpsFlag & flags)) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 SkRect dstR = SkRect::MakeWH(SkIntToScalar(srcRect.width()), SkIntToScalar(s
rcRect.height())); | 1492 SkRect dstR = SkRect::MakeWH(SkIntToScalar(srcRect.width()), SkIntToScalar(s
rcRect.height())); |
| 1503 fGpu->drawSimpleRect(dstR, NULL); | 1493 fGpu->drawSimpleRect(dstR, NULL); |
| 1504 } | 1494 } |
| 1505 | 1495 |
| 1506 bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, | 1496 bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, |
| 1507 int left, int top, int width, int height
, | 1497 int left, int top, int width, int height
, |
| 1508 GrPixelConfig srcConfig, | 1498 GrPixelConfig srcConfig, |
| 1509 const void* buffer, | 1499 const void* buffer, |
| 1510 size_t rowBytes, | 1500 size_t rowBytes, |
| 1511 uint32_t flags) { | 1501 uint32_t flags) { |
| 1512 SK_TRACE_EVENT0("GrContext::writeRenderTargetPixels"); | |
| 1513 ASSERT_OWNED_RESOURCE(target); | 1502 ASSERT_OWNED_RESOURCE(target); |
| 1514 | 1503 |
| 1515 if (NULL == target) { | 1504 if (NULL == target) { |
| 1516 target = fRenderTarget.get(); | 1505 target = fRenderTarget.get(); |
| 1517 if (NULL == target) { | 1506 if (NULL == target) { |
| 1518 return false; | 1507 return false; |
| 1519 } | 1508 } |
| 1520 } | 1509 } |
| 1521 | 1510 |
| 1522 // TODO: when underlying api has a direct way to do this we should use it (e
.g. glDrawPixels on | 1511 // 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... |
| 1810 } | 1799 } |
| 1811 return path; | 1800 return path; |
| 1812 } | 1801 } |
| 1813 | 1802 |
| 1814 /////////////////////////////////////////////////////////////////////////////// | 1803 /////////////////////////////////////////////////////////////////////////////// |
| 1815 #if GR_CACHE_STATS | 1804 #if GR_CACHE_STATS |
| 1816 void GrContext::printCacheStats() const { | 1805 void GrContext::printCacheStats() const { |
| 1817 fTextureCache->printStats(); | 1806 fTextureCache->printStats(); |
| 1818 } | 1807 } |
| 1819 #endif | 1808 #endif |
| OLD | NEW |