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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 static const size_t MAX_TEXTURE_CACHE_BYTES = GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT * 1024 * 1024; | 59 static const size_t MAX_TEXTURE_CACHE_BYTES = GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT * 1024 * 1024; |
| 60 | 60 |
| 61 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; | 61 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; |
| 62 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; | 62 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; |
| 63 | 63 |
| 64 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; | 64 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; |
| 65 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; | 65 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; |
| 66 | 66 |
| 67 #define ASSERT_OWNED_RESOURCE(R) GrAssert(!(R) || (R)->getContext() == this) | 67 #define ASSERT_OWNED_RESOURCE(R) GrAssert(!(R) || (R)->getContext() == this) |
| 68 | 68 |
| 69 // Glorified typedef to avoid including GrDrawState.h in GrContext.h | |
| 70 class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {}; | |
| 71 | |
| 69 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { | 72 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { |
| 70 GrContext* context = SkNEW(GrContext); | 73 GrContext* context = SkNEW(GrContext); |
| 71 if (context->init(backend, backendContext)) { | 74 if (context->init(backend, backendContext)) { |
| 72 return context; | 75 return context; |
| 73 } else { | 76 } else { |
| 74 context->unref(); | 77 context->unref(); |
| 75 return NULL; | 78 return NULL; |
| 76 } | 79 } |
| 77 } | 80 } |
| 78 | 81 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 int radius, | 255 int radius, |
| 253 Gr1DKernelEffect::Direction direction) { | 256 Gr1DKernelEffect::Direction direction) { |
| 254 GrRenderTarget* rt = target->drawState()->getRenderTarget(); | 257 GrRenderTarget* rt = target->drawState()->getRenderTarget(); |
| 255 GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit); | 258 GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit); |
| 256 GrDrawState* drawState = target->drawState(); | 259 GrDrawState* drawState = target->drawState(); |
| 257 drawState->setRenderTarget(rt); | 260 drawState->setRenderTarget(rt); |
| 258 SkAutoTUnref<GrEffectRef> conv(GrConvolutionEffect::CreateGaussian(texture, | 261 SkAutoTUnref<GrEffectRef> conv(GrConvolutionEffect::CreateGaussian(texture, |
| 259 direction , | 262 direction , |
| 260 radius, | 263 radius, |
| 261 sigma)); | 264 sigma)); |
| 262 drawState->setEffect(0, conv); | 265 drawState->addColorEffect(conv); |
| 263 target->drawSimpleRect(rect, NULL); | 266 target->drawSimpleRect(rect, NULL); |
| 264 } | 267 } |
| 265 | 268 |
| 266 } | 269 } |
| 267 | 270 |
| 268 //////////////////////////////////////////////////////////////////////////////// | 271 //////////////////////////////////////////////////////////////////////////////// |
| 269 | 272 |
| 270 GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc, | 273 GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc, |
| 271 const GrCacheID& cacheID, | 274 const GrCacheID& cacheID, |
| 272 const GrTextureParams* params) { | 275 const GrTextureParams* params) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 | 368 |
| 366 if (NULL != texture) { | 369 if (NULL != texture) { |
| 367 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); | 370 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); |
| 368 GrDrawState* drawState = fGpu->drawState(); | 371 GrDrawState* drawState = fGpu->drawState(); |
| 369 drawState->setRenderTarget(texture->asRenderTarget()); | 372 drawState->setRenderTarget(texture->asRenderTarget()); |
| 370 | 373 |
| 371 // if filtering is not desired then we want to ensure all | 374 // if filtering is not desired then we want to ensure all |
| 372 // texels in the resampled image are copies of texels from | 375 // texels in the resampled image are copies of texels from |
| 373 // the original. | 376 // the original. |
| 374 GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering); | 377 GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering); |
| 375 drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params) ; | 378 drawState->addColorTextureEffect(clampedTexture, SkMatrix::I(), params); |
| 376 | 379 |
| 377 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib s)); | 380 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib s)); |
| 378 | 381 |
| 379 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); | 382 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); |
| 380 | 383 |
| 381 if (arg.succeeded()) { | 384 if (arg.succeeded()) { |
| 382 GrPoint* verts = (GrPoint*) arg.vertices(); | 385 GrPoint* verts = (GrPoint*) arg.vertices(); |
| 383 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(GrPoint)); | 386 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(GrPoint)); |
| 384 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint)); | 387 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint)); |
| 385 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); | 388 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 } | 598 } |
| 596 return true; | 599 return true; |
| 597 } | 600 } |
| 598 | 601 |
| 599 | 602 |
| 600 //////////////////////////////////////////////////////////////////////////////// | 603 //////////////////////////////////////////////////////////////////////////////// |
| 601 | 604 |
| 602 void GrContext::clear(const GrIRect* rect, | 605 void GrContext::clear(const GrIRect* rect, |
| 603 const GrColor color, | 606 const GrColor color, |
| 604 GrRenderTarget* target) { | 607 GrRenderTarget* target) { |
| 605 this->prepareToDraw(NULL, BUFFERED_DRAW)->clear(rect, color, target); | 608 AutoRestoreEffects are; |
| 609 this->prepareToDraw(NULL, BUFFERED_DRAW, &are)->clear(rect, color, target); | |
| 606 } | 610 } |
| 607 | 611 |
| 608 void GrContext::drawPaint(const GrPaint& origPaint) { | 612 void GrContext::drawPaint(const GrPaint& origPaint) { |
| 609 // set rect to be big enough to fill the space, but not super-huge, so we | 613 // set rect to be big enough to fill the space, but not super-huge, so we |
| 610 // don't overflow fixed-point implementations | 614 // don't overflow fixed-point implementations |
| 611 GrRect r; | 615 GrRect r; |
| 612 r.setLTRB(0, 0, | 616 r.setLTRB(0, 0, |
| 613 SkIntToScalar(getRenderTarget()->width()), | 617 SkIntToScalar(getRenderTarget()->width()), |
| 614 SkIntToScalar(getRenderTarget()->height())); | 618 SkIntToScalar(getRenderTarget()->height())); |
| 615 SkMatrix inverse; | 619 SkMatrix inverse; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 return true; | 762 return true; |
| 759 } | 763 } |
| 760 } | 764 } |
| 761 | 765 |
| 762 void GrContext::drawRect(const GrPaint& paint, | 766 void GrContext::drawRect(const GrPaint& paint, |
| 763 const GrRect& rect, | 767 const GrRect& rect, |
| 764 SkScalar width, | 768 SkScalar width, |
| 765 const SkMatrix* matrix) { | 769 const SkMatrix* matrix) { |
| 766 SK_TRACE_EVENT0("GrContext::drawRect"); | 770 SK_TRACE_EVENT0("GrContext::drawRect"); |
| 767 | 771 |
| 768 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 772 AutoRestoreEffects are; |
| 769 GrDrawState::AutoStageDisable atr(fDrawState); | 773 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); |
| 770 | 774 |
| 771 GrRect devRect; | 775 GrRect devRect; |
| 772 SkMatrix combinedMatrix; | 776 SkMatrix combinedMatrix; |
| 773 bool useVertexCoverage; | 777 bool useVertexCoverage; |
| 774 bool needAA = paint.isAntiAlias() && | 778 bool needAA = paint.isAntiAlias() && |
| 775 !target->getDrawState().getRenderTarget()->isMultisampled(); | 779 !target->getDrawState().getRenderTarget()->isMultisampled(); |
| 776 bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, | 780 bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, |
| 777 &combinedMatrix, &devRect, | 781 &combinedMatrix, &devRect, |
| 778 &useVertexCoverage); | 782 &useVertexCoverage); |
| 779 if (doAA) { | 783 if (doAA) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 target->drawSimpleRect(rect, matrix); | 843 target->drawSimpleRect(rect, matrix); |
| 840 } | 844 } |
| 841 } | 845 } |
| 842 | 846 |
| 843 void GrContext::drawRectToRect(const GrPaint& paint, | 847 void GrContext::drawRectToRect(const GrPaint& paint, |
| 844 const GrRect& dstRect, | 848 const GrRect& dstRect, |
| 845 const GrRect& localRect, | 849 const GrRect& localRect, |
| 846 const SkMatrix* dstMatrix, | 850 const SkMatrix* dstMatrix, |
| 847 const SkMatrix* localMatrix) { | 851 const SkMatrix* localMatrix) { |
| 848 SK_TRACE_EVENT0("GrContext::drawRectToRect"); | 852 SK_TRACE_EVENT0("GrContext::drawRectToRect"); |
| 849 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 853 AutoRestoreEffects are; |
| 850 GrDrawState::AutoStageDisable atr(fDrawState); | 854 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); |
| 851 | 855 |
| 852 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); | 856 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); |
| 853 } | 857 } |
| 854 | 858 |
| 855 namespace { | 859 namespace { |
| 856 | 860 |
| 857 extern const GrVertexAttrib gPosUVColorAttribs[] = { | 861 extern const GrVertexAttrib gPosUVColorAttribs[] = { |
| 858 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, | 862 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, |
| 859 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBind ing }, | 863 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBind ing }, |
| 860 {kVec4ub_GrVertexAttribType, 2*sizeof(GrPoint), kColor_GrVertexAttribBinding } | 864 {kVec4ub_GrVertexAttribType, 2*sizeof(GrPoint), kColor_GrVertexAttribBinding } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 int vertexCount, | 899 int vertexCount, |
| 896 const GrPoint positions[], | 900 const GrPoint positions[], |
| 897 const GrPoint texCoords[], | 901 const GrPoint texCoords[], |
| 898 const GrColor colors[], | 902 const GrColor colors[], |
| 899 const uint16_t indices[], | 903 const uint16_t indices[], |
| 900 int indexCount) { | 904 int indexCount) { |
| 901 SK_TRACE_EVENT0("GrContext::drawVertices"); | 905 SK_TRACE_EVENT0("GrContext::drawVertices"); |
| 902 | 906 |
| 903 GrDrawTarget::AutoReleaseGeometry geo; | 907 GrDrawTarget::AutoReleaseGeometry geo; |
| 904 | 908 |
| 905 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 909 AutoRestoreEffects are; |
| 906 GrDrawState::AutoStageDisable atr(fDrawState); | 910 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); |
| 907 | 911 |
| 908 GrDrawState* drawState = target->drawState(); | 912 GrDrawState* drawState = target->drawState(); |
| 909 | 913 |
| 910 int colorOffset = -1, texOffset = -1; | 914 int colorOffset = -1, texOffset = -1; |
| 911 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset ); | 915 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset ); |
| 912 | 916 |
| 913 size_t vertexSize = drawState->getVertexSize(); | 917 size_t vertexSize = drawState->getVertexSize(); |
| 914 if (sizeof(GrPoint) != vertexSize) { | 918 if (sizeof(GrPoint) != vertexSize) { |
| 915 if (!geo.set(target, vertexCount, 0)) { | 919 if (!geo.set(target, vertexCount, 0)) { |
| 916 GrPrintf("Failed to get space for vertices!\n"); | 920 GrPrintf("Failed to get space for vertices!\n"); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 944 target->drawNonIndexed(primitiveType, 0, vertexCount); | 948 target->drawNonIndexed(primitiveType, 0, vertexCount); |
| 945 } | 949 } |
| 946 } | 950 } |
| 947 | 951 |
| 948 /////////////////////////////////////////////////////////////////////////////// | 952 /////////////////////////////////////////////////////////////////////////////// |
| 949 | 953 |
| 950 void GrContext::drawRRect(const GrPaint& paint, | 954 void GrContext::drawRRect(const GrPaint& paint, |
| 951 const SkRRect& rect, | 955 const SkRRect& rect, |
| 952 const SkStrokeRec& stroke) { | 956 const SkStrokeRec& stroke) { |
| 953 | 957 |
| 954 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 958 AutoRestoreEffects are; |
| 955 GrDrawState::AutoStageDisable atr(fDrawState); | 959 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); |
| 956 | 960 |
| 957 bool useAA = paint.isAntiAlias() && | 961 bool useAA = paint.isAntiAlias() && |
| 958 !target->getDrawState().getRenderTarget()->isMultisampled() && | 962 !target->getDrawState().getRenderTarget()->isMultisampled() && |
| 959 !disable_coverage_aa_for_blend(target); | 963 !disable_coverage_aa_for_blend(target); |
| 960 | 964 |
| 961 if (!fOvalRenderer->drawSimpleRRect(target, this, useAA, rect, stroke)) { | 965 if (!fOvalRenderer->drawSimpleRRect(target, this, useAA, rect, stroke)) { |
| 962 SkPath path; | 966 SkPath path; |
| 963 path.addRRect(rect); | 967 path.addRRect(rect); |
| 964 this->internalDrawPath(target, useAA, path, stroke); | 968 this->internalDrawPath(target, useAA, path, stroke); |
| 965 } | 969 } |
| 966 } | 970 } |
| 967 | 971 |
| 968 /////////////////////////////////////////////////////////////////////////////// | 972 /////////////////////////////////////////////////////////////////////////////// |
| 969 | 973 |
| 970 void GrContext::drawOval(const GrPaint& paint, | 974 void GrContext::drawOval(const GrPaint& paint, |
| 971 const GrRect& oval, | 975 const GrRect& oval, |
| 972 const SkStrokeRec& stroke) { | 976 const SkStrokeRec& stroke) { |
| 973 | 977 |
| 974 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 978 AutoRestoreEffects are; |
| 975 GrDrawState::AutoStageDisable atr(fDrawState); | 979 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); |
| 976 | 980 |
| 977 bool useAA = paint.isAntiAlias() && | 981 bool useAA = paint.isAntiAlias() && |
| 978 !target->getDrawState().getRenderTarget()->isMultisampled() && | 982 !target->getDrawState().getRenderTarget()->isMultisampled() && |
| 979 !disable_coverage_aa_for_blend(target); | 983 !disable_coverage_aa_for_blend(target); |
| 980 | 984 |
| 981 if (!fOvalRenderer->drawOval(target, this, useAA, oval, stroke)) { | 985 if (!fOvalRenderer->drawOval(target, this, useAA, oval, stroke)) { |
| 982 SkPath path; | 986 SkPath path; |
| 983 path.addOval(oval); | 987 path.addOval(oval); |
| 984 this->internalDrawPath(target, useAA, path, stroke); | 988 this->internalDrawPath(target, useAA, path, stroke); |
| 985 } | 989 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1038 this->drawPaint(paint); | 1042 this->drawPaint(paint); |
| 1039 } | 1043 } |
| 1040 return; | 1044 return; |
| 1041 } | 1045 } |
| 1042 | 1046 |
| 1043 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. | 1047 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. |
| 1044 // Scratch textures can be recycled after they are returned to the texture | 1048 // Scratch textures can be recycled after they are returned to the texture |
| 1045 // cache. This presents a potential hazard for buffered drawing. However, | 1049 // cache. This presents a potential hazard for buffered drawing. However, |
| 1046 // the writePixels that uploads to the scratch will perform a flush so we're | 1050 // the writePixels that uploads to the scratch will perform a flush so we're |
| 1047 // OK. | 1051 // OK. |
| 1048 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 1052 AutoRestoreEffects are; |
| 1049 GrDrawState::AutoStageDisable atr(fDrawState); | 1053 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); |
| 1050 | 1054 |
| 1051 bool useAA = paint.isAntiAlias() && !target->getDrawState().getRenderTarget( )->isMultisampled(); | 1055 bool useAA = paint.isAntiAlias() && !target->getDrawState().getRenderTarget( )->isMultisampled(); |
| 1052 if (useAA && stroke.getWidth() < 0 && !path.isConvex()) { | 1056 if (useAA && stroke.getWidth() < 0 && !path.isConvex()) { |
| 1053 // Concave AA paths are expensive - try to avoid them for special cases | 1057 // Concave AA paths are expensive - try to avoid them for special cases |
| 1054 bool useVertexCoverage; | 1058 bool useVertexCoverage; |
| 1055 SkRect rects[2]; | 1059 SkRect rects[2]; |
| 1056 | 1060 |
| 1057 if (is_nested_rects(target, path, stroke, rects, &useVertexCoverage)) { | 1061 if (is_nested_rects(target, path, stroke, rects, &useVertexCoverage)) { |
| 1058 SkMatrix origViewMatrix = target->getDrawState().getViewMatrix(); | 1062 SkMatrix origViewMatrix = target->getDrawState().getViewMatrix(); |
| 1059 GrDrawState::AutoViewMatrixRestore avmr; | 1063 GrDrawState::AutoViewMatrixRestore avmr; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1339 textureMatrix)); | 1343 textureMatrix)); |
| 1340 } | 1344 } |
| 1341 swapRAndB = false; // we will handle the swap in the draw. | 1345 swapRAndB = false; // we will handle the swap in the draw. |
| 1342 | 1346 |
| 1343 // We protect the existing geometry here since it may not be | 1347 // We protect the existing geometry here since it may not be |
| 1344 // clear to the caller that a draw operation (i.e., drawSimpleRe ct) | 1348 // clear to the caller that a draw operation (i.e., drawSimpleRe ct) |
| 1345 // can be invoked in this method | 1349 // can be invoked in this method |
| 1346 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget: :kReset_ASRInit); | 1350 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget: :kReset_ASRInit); |
| 1347 GrDrawState* drawState = fGpu->drawState(); | 1351 GrDrawState* drawState = fGpu->drawState(); |
| 1348 GrAssert(effect); | 1352 GrAssert(effect); |
| 1349 drawState->setEffect(0, effect); | 1353 drawState->addColorEffect(effect); |
| 1350 | 1354 |
| 1351 drawState->setRenderTarget(texture->asRenderTarget()); | 1355 drawState->setRenderTarget(texture->asRenderTarget()); |
| 1352 GrRect rect = GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar (height)); | 1356 GrRect rect = GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar (height)); |
| 1353 fGpu->drawSimpleRect(rect, NULL); | 1357 fGpu->drawSimpleRect(rect, NULL); |
| 1354 // we want to read back from the scratch's origin | 1358 // we want to read back from the scratch's origin |
| 1355 left = 0; | 1359 left = 0; |
| 1356 top = 0; | 1360 top = 0; |
| 1357 target = texture->asRenderTarget(); | 1361 target = texture->asRenderTarget(); |
| 1358 } | 1362 } |
| 1359 } | 1363 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1414 sampleM.setIDiv(src->width(), src->height()); | 1418 sampleM.setIDiv(src->width(), src->height()); |
| 1415 SkIRect srcRect = SkIRect::MakeWH(dst->width(), dst->height()); | 1419 SkIRect srcRect = SkIRect::MakeWH(dst->width(), dst->height()); |
| 1416 if (NULL != topLeft) { | 1420 if (NULL != topLeft) { |
| 1417 srcRect.offset(*topLeft); | 1421 srcRect.offset(*topLeft); |
| 1418 } | 1422 } |
| 1419 SkIRect srcBounds = SkIRect::MakeWH(src->width(), src->height()); | 1423 SkIRect srcBounds = SkIRect::MakeWH(src->width(), src->height()); |
| 1420 if (!srcRect.intersect(srcBounds)) { | 1424 if (!srcRect.intersect(srcBounds)) { |
| 1421 return; | 1425 return; |
| 1422 } | 1426 } |
| 1423 sampleM.preTranslate(SkIntToScalar(srcRect.fLeft), SkIntToScalar(srcRect.fTo p)); | 1427 sampleM.preTranslate(SkIntToScalar(srcRect.fLeft), SkIntToScalar(srcRect.fTo p)); |
| 1424 drawState->createTextureEffect(0, src, sampleM); | 1428 drawState->addColorTextureEffect(src, sampleM); |
| 1425 SkRect dstR = SkRect::MakeWH(SkIntToScalar(srcRect.width()), SkIntToScalar(s rcRect.height())); | 1429 SkRect dstR = SkRect::MakeWH(SkIntToScalar(srcRect.width()), SkIntToScalar(s rcRect.height())); |
| 1426 fGpu->drawSimpleRect(dstR, NULL); | 1430 fGpu->drawSimpleRect(dstR, NULL); |
| 1427 } | 1431 } |
| 1428 | 1432 |
| 1429 bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, | 1433 bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, |
| 1430 int left, int top, int width, int height , | 1434 int left, int top, int width, int height , |
| 1431 GrPixelConfig srcConfig, | 1435 GrPixelConfig srcConfig, |
| 1432 const void* buffer, | 1436 const void* buffer, |
| 1433 size_t rowBytes, | 1437 size_t rowBytes, |
| 1434 uint32_t flags) { | 1438 uint32_t flags) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1532 } | 1536 } |
| 1533 | 1537 |
| 1534 // writeRenderTargetPixels can be called in the midst of drawing another | 1538 // writeRenderTargetPixels can be called in the midst of drawing another |
| 1535 // object (e.g., when uploading a SW path rendering to the gpu while | 1539 // object (e.g., when uploading a SW path rendering to the gpu while |
| 1536 // drawing a rect) so preserve the current geometry. | 1540 // drawing a rect) so preserve the current geometry. |
| 1537 SkMatrix matrix; | 1541 SkMatrix matrix; |
| 1538 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 1542 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 1539 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRI nit, &matrix); | 1543 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRI nit, &matrix); |
| 1540 GrDrawState* drawState = fGpu->drawState(); | 1544 GrDrawState* drawState = fGpu->drawState(); |
| 1541 GrAssert(effect); | 1545 GrAssert(effect); |
| 1542 drawState->setEffect(0, effect); | 1546 drawState->addColorEffect(effect); |
| 1543 | 1547 |
| 1544 drawState->setRenderTarget(target); | 1548 drawState->setRenderTarget(target); |
| 1545 | 1549 |
| 1546 fGpu->drawSimpleRect(GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heig ht)), NULL); | 1550 fGpu->drawSimpleRect(GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heig ht)), NULL); |
| 1547 return true; | 1551 return true; |
| 1548 } | 1552 } |
| 1549 //////////////////////////////////////////////////////////////////////////////// | 1553 //////////////////////////////////////////////////////////////////////////////// |
| 1550 | 1554 |
| 1551 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, BufferedDraw buffer ed) { | 1555 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, |
| 1556 BufferedDraw buffered, | |
| 1557 AutoRestoreEffects* are) { | |
|
robertphillips
2013/06/13 15:49:04
are should -> should
bsalomon
2013/06/13 19:36:12
Done.
| |
| 1558 // All users of this draw state are should be freeing up all effects when th ey're done. | |
| 1559 // Otherwise effects that own resources may keep those resources alive indef initely. | |
| 1560 GrAssert(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageSt ages()); | |
| 1561 | |
| 1552 if (kNo_BufferedDraw == buffered && kYes_BufferedDraw == fLastDrawWasBuffere d) { | 1562 if (kNo_BufferedDraw == buffered && kYes_BufferedDraw == fLastDrawWasBuffere d) { |
| 1553 this->flushDrawBuffer(); | 1563 this->flushDrawBuffer(); |
| 1554 fLastDrawWasBuffered = kNo_BufferedDraw; | 1564 fLastDrawWasBuffered = kNo_BufferedDraw; |
| 1555 } | 1565 } |
| 1556 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); | 1566 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); |
| 1557 if (NULL != paint) { | 1567 if (NULL != paint) { |
| 1558 GrAssert(fDrawState->stagesDisabled()); | 1568 GrAssert(NULL != are); |
| 1569 are->set(fDrawState); | |
| 1559 fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); | 1570 fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); |
| 1560 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK | 1571 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK |
| 1561 if ((paint->hasMask() || 0xff != paint->fCoverage) && | 1572 if ((paint->hasMask() || 0xff != paint->fCoverage) && |
| 1562 !fGpu->canApplyCoverage()) { | 1573 !fGpu->canApplyCoverage()) { |
| 1563 GrPrintf("Partial pixel coverage will be incorrectly blended.\n"); | 1574 GrPrintf("Partial pixel coverage will be incorrectly blended.\n"); |
| 1564 } | 1575 } |
| 1565 #endif | 1576 #endif |
| 1566 } else { | 1577 } else { |
| 1567 fDrawState->reset(fViewMatrix); | 1578 fDrawState->reset(fViewMatrix); |
| 1568 fDrawState->setRenderTarget(fRenderTarget.get()); | 1579 fDrawState->setRenderTarget(fRenderTarget.get()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1648 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); | 1659 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); |
| 1649 | 1660 |
| 1650 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, | 1661 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, |
| 1651 fDrawBufferVBAllocPool, | 1662 fDrawBufferVBAllocPool, |
| 1652 fDrawBufferIBAllocPool)); | 1663 fDrawBufferIBAllocPool)); |
| 1653 | 1664 |
| 1654 fDrawBuffer->setDrawState(fDrawState); | 1665 fDrawBuffer->setDrawState(fDrawState); |
| 1655 } | 1666 } |
| 1656 | 1667 |
| 1657 GrDrawTarget* GrContext::getTextTarget() { | 1668 GrDrawTarget* GrContext::getTextTarget() { |
| 1658 return this->prepareToDraw(NULL, BUFFERED_DRAW); | 1669 return this->prepareToDraw(NULL, BUFFERED_DRAW, NULL); |
| 1659 } | 1670 } |
| 1660 | 1671 |
| 1661 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { | 1672 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { |
| 1662 return fGpu->getQuadIndexBuffer(); | 1673 return fGpu->getQuadIndexBuffer(); |
| 1663 } | 1674 } |
| 1664 | 1675 |
| 1665 namespace { | 1676 namespace { |
| 1666 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { | 1677 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
| 1667 GrConfigConversionEffect::PMConversion pmToUPM; | 1678 GrConfigConversionEffect::PMConversion pmToUPM; |
| 1668 GrConfigConversionEffect::PMConversion upmToPM; | 1679 GrConfigConversionEffect::PMConversion upmToPM; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1772 if (sigmaX > 0.0f) { | 1783 if (sigmaX > 0.0f) { |
| 1773 if (scaleFactorX > 1) { | 1784 if (scaleFactorX > 1) { |
| 1774 // Clear out a radius to the right of the srcRect to prevent the | 1785 // Clear out a radius to the right of the srcRect to prevent the |
| 1775 // X convolution from reading garbage. | 1786 // X convolution from reading garbage. |
| 1776 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, | 1787 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, |
| 1777 radiusX, srcIRect.height()); | 1788 radiusX, srcIRect.height()); |
| 1778 this->clear(&clearRect, 0x0); | 1789 this->clear(&clearRect, 0x0); |
| 1779 } | 1790 } |
| 1780 | 1791 |
| 1781 this->setRenderTarget(dstTexture->asRenderTarget()); | 1792 this->setRenderTarget(dstTexture->asRenderTarget()); |
| 1782 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW); | 1793 AutoRestoreEffects are; |
| 1794 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); | |
| 1783 convolve_gaussian(target, srcTexture, srcRect, sigmaX, radiusX, | 1795 convolve_gaussian(target, srcTexture, srcRect, sigmaX, radiusX, |
| 1784 Gr1DKernelEffect::kX_Direction); | 1796 Gr1DKernelEffect::kX_Direction); |
| 1785 srcTexture = dstTexture; | 1797 srcTexture = dstTexture; |
| 1786 SkTSwap(dstTexture, tempTexture); | 1798 SkTSwap(dstTexture, tempTexture); |
| 1787 } | 1799 } |
| 1788 | 1800 |
| 1789 if (sigmaY > 0.0f) { | 1801 if (sigmaY > 0.0f) { |
| 1790 if (scaleFactorY > 1 || sigmaX > 0.0f) { | 1802 if (scaleFactorY > 1 || sigmaX > 0.0f) { |
| 1791 // Clear out a radius below the srcRect to prevent the Y | 1803 // Clear out a radius below the srcRect to prevent the Y |
| 1792 // convolution from reading garbage. | 1804 // convolution from reading garbage. |
| 1793 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, | 1805 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, |
| 1794 srcIRect.width(), radiusY); | 1806 srcIRect.width(), radiusY); |
| 1795 this->clear(&clearRect, 0x0); | 1807 this->clear(&clearRect, 0x0); |
| 1796 } | 1808 } |
| 1797 | 1809 |
| 1798 this->setRenderTarget(dstTexture->asRenderTarget()); | 1810 this->setRenderTarget(dstTexture->asRenderTarget()); |
| 1799 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW); | 1811 AutoRestoreEffects are; |
| 1812 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); | |
| 1800 convolve_gaussian(target, srcTexture, srcRect, sigmaY, radiusY, | 1813 convolve_gaussian(target, srcTexture, srcRect, sigmaY, radiusY, |
| 1801 Gr1DKernelEffect::kY_Direction); | 1814 Gr1DKernelEffect::kY_Direction); |
| 1802 srcTexture = dstTexture; | 1815 srcTexture = dstTexture; |
| 1803 SkTSwap(dstTexture, tempTexture); | 1816 SkTSwap(dstTexture, tempTexture); |
| 1804 } | 1817 } |
| 1805 | 1818 |
| 1806 if (scaleFactorX > 1 || scaleFactorY > 1) { | 1819 if (scaleFactorX > 1 || scaleFactorY > 1) { |
| 1807 // Clear one pixel to the right and below, to accommodate bilinear | 1820 // Clear one pixel to the right and below, to accommodate bilinear |
| 1808 // upsampling. | 1821 // upsampling. |
| 1809 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, | 1822 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1835 return srcTexture; | 1848 return srcTexture; |
| 1836 } | 1849 } |
| 1837 } | 1850 } |
| 1838 | 1851 |
| 1839 /////////////////////////////////////////////////////////////////////////////// | 1852 /////////////////////////////////////////////////////////////////////////////// |
| 1840 #if GR_CACHE_STATS | 1853 #if GR_CACHE_STATS |
| 1841 void GrContext::printCacheStats() const { | 1854 void GrContext::printCacheStats() const { |
| 1842 fTextureCache->printStats(); | 1855 fTextureCache->printStats(); |
| 1843 } | 1856 } |
| 1844 #endif | 1857 #endif |
| OLD | NEW |