Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: src/gpu/GrContext.cpp

Issue 929243004: adding preabandon flag to DM (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: feedback incorporated Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | src/gpu/GrTextContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "effects/GrDashingEffect.h" 45 #include "effects/GrDashingEffect.h"
46 #include "effects/GrSingleTextureEffect.h" 46 #include "effects/GrSingleTextureEffect.h"
47 47
48 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; 48 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15;
49 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; 49 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4;
50 50
51 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; 51 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11;
52 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; 52 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4;
53 53
54 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) 54 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
55 #define RETURN_IF_ABANDONED if (!fDrawBuffer) { return; }
56 #define RETURN_FALSE_IF_ABANDONED if (!fDrawBuffer) { return false; }
57 #define RETURN_NULL_IF_ABANDONED if (!fDrawBuffer) { return NULL; }
55 58
56 class GrContext::AutoCheckFlush { 59 class GrContext::AutoCheckFlush {
57 public: 60 public:
58 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); } 61 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); }
59 62
60 ~AutoCheckFlush() { 63 ~AutoCheckFlush() {
61 if (fContext->fFlushToReduceCacheSize) { 64 if (fContext->fFlushToReduceCacheSize) {
62 fContext->flush(); 65 fContext->flush();
63 } 66 }
64 } 67 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 bool GrContext::isConfigTexturable(GrPixelConfig config) const { 236 bool GrContext::isConfigTexturable(GrPixelConfig config) const {
234 return fGpu->caps()->isConfigTexturable(config); 237 return fGpu->caps()->isConfigTexturable(config);
235 } 238 }
236 239
237 bool GrContext::npotTextureTileSupport() const { 240 bool GrContext::npotTextureTileSupport() const {
238 return fGpu->caps()->npotTextureTileSupport(); 241 return fGpu->caps()->npotTextureTileSupport();
239 } 242 }
240 243
241 GrTexture* GrContext::createTexture(const GrSurfaceDesc& desc, bool budgeted, co nst void* srcData, 244 GrTexture* GrContext::createTexture(const GrSurfaceDesc& desc, bool budgeted, co nst void* srcData,
242 size_t rowBytes) { 245 size_t rowBytes) {
246 RETURN_NULL_IF_ABANDONED
243 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && 247 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
244 !this->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 248 !this->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
245 return NULL; 249 return NULL;
246 } 250 }
247 if (!GrPixelConfigIsCompressed(desc.fConfig)) { 251 if (!GrPixelConfigIsCompressed(desc.fConfig)) {
248 static const uint32_t kFlags = kExact_ScratchTextureFlag | 252 static const uint32_t kFlags = kExact_ScratchTextureFlag |
249 kNoCreate_ScratchTextureFlag; 253 kNoCreate_ScratchTextureFlag;
250 if (GrTexture* texture = this->internalRefScratchTexture(desc, kFlags)) { 254 if (GrTexture* texture = this->internalRefScratchTexture(desc, kFlags)) {
251 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight , desc.fConfig, 255 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight , desc.fConfig,
252 srcData, rowBytes)) { 256 srcData, rowBytes)) {
253 if (!budgeted) { 257 if (!budgeted) {
254 texture->resourcePriv().makeUnbudgeted(); 258 texture->resourcePriv().makeUnbudgeted();
255 } 259 }
256 return texture; 260 return texture;
257 } 261 }
258 texture->unref(); 262 texture->unref();
259 } 263 }
260 } 264 }
261 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); 265 return fGpu->createTexture(desc, budgeted, srcData, rowBytes);
262 } 266 }
263 267
264 GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMat ch match, 268 GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMat ch match,
265 bool calledDuringFlush) { 269 bool calledDuringFlush) {
270 RETURN_NULL_IF_ABANDONED
266 // Currently we don't recycle compressed textures as scratch. 271 // Currently we don't recycle compressed textures as scratch.
267 if (GrPixelConfigIsCompressed(desc.fConfig)) { 272 if (GrPixelConfigIsCompressed(desc.fConfig)) {
268 return NULL; 273 return NULL;
269 } else { 274 } else {
270 uint32_t flags = 0; 275 uint32_t flags = 0;
271 if (kExact_ScratchTexMatch == match) { 276 if (kExact_ScratchTexMatch == match) {
272 flags |= kExact_ScratchTextureFlag; 277 flags |= kExact_ScratchTextureFlag;
273 } 278 }
274 if (calledDuringFlush) { 279 if (calledDuringFlush) {
275 flags |= kNoPendingIO_ScratchTextureFlag; 280 flags |= kNoPendingIO_ScratchTextureFlag;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 return fGpu->caps()->maxRenderTargetSize(); 342 return fGpu->caps()->maxRenderTargetSize();
338 } 343 }
339 344
340 int GrContext::getMaxSampleCount() const { 345 int GrContext::getMaxSampleCount() const {
341 return fGpu->caps()->maxSampleCount(); 346 return fGpu->caps()->maxSampleCount();
342 } 347 }
343 348
344 /////////////////////////////////////////////////////////////////////////////// 349 ///////////////////////////////////////////////////////////////////////////////
345 350
346 GrTexture* GrContext::wrapBackendTexture(const GrBackendTextureDesc& desc) { 351 GrTexture* GrContext::wrapBackendTexture(const GrBackendTextureDesc& desc) {
352 RETURN_NULL_IF_ABANDONED
347 return fGpu->wrapBackendTexture(desc); 353 return fGpu->wrapBackendTexture(desc);
348 } 354 }
349 355
350 GrRenderTarget* GrContext::wrapBackendRenderTarget(const GrBackendRenderTargetDe sc& desc) { 356 GrRenderTarget* GrContext::wrapBackendRenderTarget(const GrBackendRenderTargetDe sc& desc) {
357 RETURN_NULL_IF_ABANDONED
351 return fGpu->wrapBackendRenderTarget(desc); 358 return fGpu->wrapBackendRenderTarget(desc);
352 } 359 }
353 360
354 //////////////////////////////////////////////////////////////////////////////// 361 ////////////////////////////////////////////////////////////////////////////////
355 362
356 void GrContext::clear(const SkIRect* rect, 363 void GrContext::clear(const SkIRect* rect,
357 const GrColor color, 364 const GrColor color,
358 bool canIgnoreRect, 365 bool canIgnoreRect,
359 GrRenderTarget* renderTarget) { 366 GrRenderTarget* renderTarget) {
367 RETURN_IF_ABANDONED
360 ASSERT_OWNED_RESOURCE(renderTarget); 368 ASSERT_OWNED_RESOURCE(renderTarget);
361 SkASSERT(renderTarget); 369 SkASSERT(renderTarget);
362 370
363 AutoCheckFlush acf(this); 371 AutoCheckFlush acf(this);
364 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); 372 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this);
365 GrDrawTarget* target = this->prepareToDraw(); 373 GrDrawTarget* target = this->prepareToDraw();
366 if (NULL == target) { 374 if (NULL == target) {
367 return; 375 return;
368 } 376 }
369 target->clear(rect, color, canIgnoreRect, renderTarget); 377 target->clear(rect, color, canIgnoreRect, renderTarget);
370 } 378 }
371 379
372 void GrContext::drawPaint(GrRenderTarget* rt, 380 void GrContext::drawPaint(GrRenderTarget* rt,
373 const GrClip& clip, 381 const GrClip& clip,
374 const GrPaint& origPaint, 382 const GrPaint& origPaint,
375 const SkMatrix& viewMatrix) { 383 const SkMatrix& viewMatrix) {
384 RETURN_IF_ABANDONED
376 // set rect to be big enough to fill the space, but not super-huge, so we 385 // set rect to be big enough to fill the space, but not super-huge, so we
377 // don't overflow fixed-point implementations 386 // don't overflow fixed-point implementations
378 SkRect r; 387 SkRect r;
379 r.setLTRB(0, 0, 388 r.setLTRB(0, 0,
380 SkIntToScalar(rt->width()), 389 SkIntToScalar(rt->width()),
381 SkIntToScalar(rt->height())); 390 SkIntToScalar(rt->height()));
382 SkTCopyOnFirstWrite<GrPaint> paint(origPaint); 391 SkTCopyOnFirstWrite<GrPaint> paint(origPaint);
383 392
384 // by definition this fills the entire clip, no need for AA 393 // by definition this fills the entire clip, no need for AA
385 if (paint->isAntiAlias()) { 394 if (paint->isAntiAlias()) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 return point.fX >= rect.fLeft && point.fX <= rect.fRight && 509 return point.fX >= rect.fLeft && point.fX <= rect.fRight &&
501 point.fY >= rect.fTop && point.fY <= rect.fBottom; 510 point.fY >= rect.fTop && point.fY <= rect.fBottom;
502 } 511 }
503 512
504 void GrContext::drawRect(GrRenderTarget* rt, 513 void GrContext::drawRect(GrRenderTarget* rt,
505 const GrClip& clip, 514 const GrClip& clip,
506 const GrPaint& paint, 515 const GrPaint& paint,
507 const SkMatrix& viewMatrix, 516 const SkMatrix& viewMatrix,
508 const SkRect& rect, 517 const SkRect& rect,
509 const GrStrokeInfo* strokeInfo) { 518 const GrStrokeInfo* strokeInfo) {
519 RETURN_IF_ABANDONED
510 if (strokeInfo && strokeInfo->isDashed()) { 520 if (strokeInfo && strokeInfo->isDashed()) {
511 SkPath path; 521 SkPath path;
512 path.addRect(rect); 522 path.addRect(rect);
513 this->drawPath(rt, clip, paint, viewMatrix, path, *strokeInfo); 523 this->drawPath(rt, clip, paint, viewMatrix, path, *strokeInfo);
514 return; 524 return;
515 } 525 }
516 526
517 AutoCheckFlush acf(this); 527 AutoCheckFlush acf(this);
518 GrPipelineBuilder pipelineBuilder; 528 GrPipelineBuilder pipelineBuilder;
519 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain t, &acf); 529 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain t, &acf);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 } 644 }
635 } 645 }
636 646
637 void GrContext::drawNonAARectToRect(GrRenderTarget* rt, 647 void GrContext::drawNonAARectToRect(GrRenderTarget* rt,
638 const GrClip& clip, 648 const GrClip& clip,
639 const GrPaint& paint, 649 const GrPaint& paint,
640 const SkMatrix& viewMatrix, 650 const SkMatrix& viewMatrix,
641 const SkRect& rectToDraw, 651 const SkRect& rectToDraw,
642 const SkRect& localRect, 652 const SkRect& localRect,
643 const SkMatrix* localMatrix) { 653 const SkMatrix* localMatrix) {
654 RETURN_IF_ABANDONED
644 AutoCheckFlush acf(this); 655 AutoCheckFlush acf(this);
645 GrPipelineBuilder pipelineBuilder; 656 GrPipelineBuilder pipelineBuilder;
646 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain t, &acf); 657 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain t, &acf);
647 if (NULL == target) { 658 if (NULL == target) {
648 return; 659 return;
649 } 660 }
650 661
651 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); 662 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target);
652 663
653 target->drawRect(&pipelineBuilder, 664 target->drawRect(&pipelineBuilder,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 const GrClip& clip, 697 const GrClip& clip,
687 const GrPaint& paint, 698 const GrPaint& paint,
688 const SkMatrix& viewMatrix, 699 const SkMatrix& viewMatrix,
689 GrPrimitiveType primitiveType, 700 GrPrimitiveType primitiveType,
690 int vertexCount, 701 int vertexCount,
691 const SkPoint positions[], 702 const SkPoint positions[],
692 const SkPoint texCoords[], 703 const SkPoint texCoords[],
693 const GrColor colors[], 704 const GrColor colors[],
694 const uint16_t indices[], 705 const uint16_t indices[],
695 int indexCount) { 706 int indexCount) {
707 RETURN_IF_ABANDONED
696 AutoCheckFlush acf(this); 708 AutoCheckFlush acf(this);
697 GrPipelineBuilder pipelineBuilder; 709 GrPipelineBuilder pipelineBuilder;
698 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e 710 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e
699 711
700 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain t, &acf); 712 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain t, &acf);
701 if (NULL == target) { 713 if (NULL == target) {
702 return; 714 return;
703 } 715 }
704 716
705 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); 717 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 } 756 }
745 757
746 /////////////////////////////////////////////////////////////////////////////// 758 ///////////////////////////////////////////////////////////////////////////////
747 759
748 void GrContext::drawRRect(GrRenderTarget*rt, 760 void GrContext::drawRRect(GrRenderTarget*rt,
749 const GrClip& clip, 761 const GrClip& clip,
750 const GrPaint& paint, 762 const GrPaint& paint,
751 const SkMatrix& viewMatrix, 763 const SkMatrix& viewMatrix,
752 const SkRRect& rrect, 764 const SkRRect& rrect,
753 const GrStrokeInfo& strokeInfo) { 765 const GrStrokeInfo& strokeInfo) {
766 RETURN_IF_ABANDONED
754 if (rrect.isEmpty()) { 767 if (rrect.isEmpty()) {
755 return; 768 return;
756 } 769 }
757 770
758 if (strokeInfo.isDashed()) { 771 if (strokeInfo.isDashed()) {
759 SkPath path; 772 SkPath path;
760 path.addRRect(rrect); 773 path.addRRect(rrect);
761 this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo); 774 this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo);
762 return; 775 return;
763 } 776 }
(...skipping 25 matching lines...) Expand all
789 } 802 }
790 803
791 /////////////////////////////////////////////////////////////////////////////// 804 ///////////////////////////////////////////////////////////////////////////////
792 805
793 void GrContext::drawDRRect(GrRenderTarget* rt, 806 void GrContext::drawDRRect(GrRenderTarget* rt,
794 const GrClip& clip, 807 const GrClip& clip,
795 const GrPaint& paint, 808 const GrPaint& paint,
796 const SkMatrix& viewMatrix, 809 const SkMatrix& viewMatrix,
797 const SkRRect& outer, 810 const SkRRect& outer,
798 const SkRRect& inner) { 811 const SkRRect& inner) {
812 RETURN_IF_ABANDONED
799 if (outer.isEmpty()) { 813 if (outer.isEmpty()) {
800 return; 814 return;
801 } 815 }
802 816
803 AutoCheckFlush acf(this); 817 AutoCheckFlush acf(this);
804 GrPipelineBuilder pipelineBuilder; 818 GrPipelineBuilder pipelineBuilder;
805 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain t, &acf); 819 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain t, &acf);
806 820
807 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); 821 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target);
808 822
(...skipping 17 matching lines...) Expand all
826 } 840 }
827 841
828 /////////////////////////////////////////////////////////////////////////////// 842 ///////////////////////////////////////////////////////////////////////////////
829 843
830 void GrContext::drawOval(GrRenderTarget* rt, 844 void GrContext::drawOval(GrRenderTarget* rt,
831 const GrClip& clip, 845 const GrClip& clip,
832 const GrPaint& paint, 846 const GrPaint& paint,
833 const SkMatrix& viewMatrix, 847 const SkMatrix& viewMatrix,
834 const SkRect& oval, 848 const SkRect& oval,
835 const GrStrokeInfo& strokeInfo) { 849 const GrStrokeInfo& strokeInfo) {
850 RETURN_IF_ABANDONED
836 if (oval.isEmpty()) { 851 if (oval.isEmpty()) {
837 return; 852 return;
838 } 853 }
839 854
840 if (strokeInfo.isDashed()) { 855 if (strokeInfo.isDashed()) {
841 SkPath path; 856 SkPath path;
842 path.addOval(oval); 857 path.addOval(oval);
843 this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo); 858 this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo);
844 return; 859 return;
845 } 860 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 937
923 return allEq || allGoE1; 938 return allEq || allGoE1;
924 } 939 }
925 940
926 void GrContext::drawPath(GrRenderTarget* rt, 941 void GrContext::drawPath(GrRenderTarget* rt,
927 const GrClip& clip, 942 const GrClip& clip,
928 const GrPaint& paint, 943 const GrPaint& paint,
929 const SkMatrix& viewMatrix, 944 const SkMatrix& viewMatrix,
930 const SkPath& path, 945 const SkPath& path,
931 const GrStrokeInfo& strokeInfo) { 946 const GrStrokeInfo& strokeInfo) {
932 947 RETURN_IF_ABANDONED
933 if (path.isEmpty()) { 948 if (path.isEmpty()) {
934 if (path.isInverseFillType()) { 949 if (path.isInverseFillType()) {
935 this->drawPaint(rt, clip, paint, viewMatrix); 950 this->drawPaint(rt, clip, paint, viewMatrix);
936 } 951 }
937 return; 952 return;
938 } 953 }
939 954
940 GrColor color = paint.getColor(); 955 GrColor color = paint.getColor();
941 if (strokeInfo.isDashed()) { 956 if (strokeInfo.isDashed()) {
942 SkPoint pts[2]; 957 SkPoint pts[2];
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 } 1028 }
1014 } 1029 }
1015 1030
1016 void GrContext::internalDrawPath(GrDrawTarget* target, 1031 void GrContext::internalDrawPath(GrDrawTarget* target,
1017 GrPipelineBuilder* pipelineBuilder, 1032 GrPipelineBuilder* pipelineBuilder,
1018 const SkMatrix& viewMatrix, 1033 const SkMatrix& viewMatrix,
1019 GrColor color, 1034 GrColor color,
1020 bool useAA, 1035 bool useAA,
1021 const SkPath& path, 1036 const SkPath& path,
1022 const GrStrokeInfo& strokeInfo) { 1037 const GrStrokeInfo& strokeInfo) {
1038 RETURN_IF_ABANDONED
1023 SkASSERT(!path.isEmpty()); 1039 SkASSERT(!path.isEmpty());
1024 1040
1025 GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target); 1041 GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target);
1026 1042
1027 1043
1028 // An Assumption here is that path renderer would use some form of tweaking 1044 // An Assumption here is that path renderer would use some form of tweaking
1029 // the src color (either the input alpha or in the frag shader) to implement 1045 // the src color (either the input alpha or in the frag shader) to implement
1030 // aa. If we have some future driver-mojo path AA that can do the right 1046 // aa. If we have some future driver-mojo path AA that can do the right
1031 // thing WRT to the blend then we'll need some query on the PR. 1047 // thing WRT to the blend then we'll need some query on the PR.
1032 bool useCoverageAA = useAA && 1048 bool useCoverageAA = useAA &&
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 dstPI.fPixels = outPixels; 1119 dstPI.fPixels = outPixels;
1104 dstPI.fRowBytes = outRowBytes; 1120 dstPI.fRowBytes = outRowBytes;
1105 1121
1106 return srcPI.convertPixelsTo(&dstPI, width, height); 1122 return srcPI.convertPixelsTo(&dstPI, width, height);
1107 } 1123 }
1108 1124
1109 bool GrContext::writeSurfacePixels(GrSurface* surface, 1125 bool GrContext::writeSurfacePixels(GrSurface* surface,
1110 int left, int top, int width, int height, 1126 int left, int top, int width, int height,
1111 GrPixelConfig srcConfig, const void* buffer, size_t rowBytes, 1127 GrPixelConfig srcConfig, const void* buffer, size_t rowBytes,
1112 uint32_t pixelOpsFlags) { 1128 uint32_t pixelOpsFlags) {
1113 1129 RETURN_FALSE_IF_ABANDONED
1114 { 1130 {
1115 GrTexture* texture = NULL; 1131 GrTexture* texture = NULL;
1116 if (!(kUnpremul_PixelOpsFlag & pixelOpsFlags) && (texture = surface->asT exture()) && 1132 if (!(kUnpremul_PixelOpsFlag & pixelOpsFlags) && (texture = surface->asT exture()) &&
1117 fGpu->canWriteTexturePixels(texture, srcConfig)) { 1133 fGpu->canWriteTexturePixels(texture, srcConfig)) {
1118 1134
1119 if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && 1135 if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) &&
1120 surface->surfacePriv().hasPendingIO()) { 1136 surface->surfacePriv().hasPendingIO()) {
1121 this->flush(); 1137 this->flush();
1122 } 1138 }
1123 return fGpu->writeTexturePixels(texture, left, top, width, height, 1139 return fGpu->writeTexturePixels(texture, left, top, width, height,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 } else { 1249 } else {
1234 SkASSERT(kBGRA_8888_SkColorType == ct); 1250 SkASSERT(kBGRA_8888_SkColorType == ct);
1235 return kRGBA_8888_SkColorType; 1251 return kRGBA_8888_SkColorType;
1236 } 1252 }
1237 } 1253 }
1238 1254
1239 bool GrContext::readRenderTargetPixels(GrRenderTarget* target, 1255 bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
1240 int left, int top, int width, int height, 1256 int left, int top, int width, int height,
1241 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes, 1257 GrPixelConfig dstConfig, void* buffer, si ze_t rowBytes,
1242 uint32_t flags) { 1258 uint32_t flags) {
1259 RETURN_FALSE_IF_ABANDONED
1243 ASSERT_OWNED_RESOURCE(target); 1260 ASSERT_OWNED_RESOURCE(target);
1244 SkASSERT(target); 1261 SkASSERT(target);
1245 1262
1246 if (!(kDontFlush_PixelOpsFlag & flags) && target->surfacePriv().hasPendingWr ite()) { 1263 if (!(kDontFlush_PixelOpsFlag & flags) && target->surfacePriv().hasPendingWr ite()) {
1247 this->flush(); 1264 this->flush();
1248 } 1265 }
1249 1266
1250 // Determine which conversions have to be applied: flipY, swapRAnd, and/or u npremul. 1267 // Determine which conversions have to be applied: flipY, swapRAnd, and/or u npremul.
1251 1268
1252 // If fGpu->readPixels would incur a y-flip cost then we will read the pixel s upside down. We'll 1269 // If fGpu->readPixels would incur a y-flip cost then we will read the pixel s upside down. We'll
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 srcPI.fAlphaType = kPremul_SkAlphaType; 1388 srcPI.fAlphaType = kPremul_SkAlphaType;
1372 srcPI.fPixels = buffer; 1389 srcPI.fPixels = buffer;
1373 srcPI.fRowBytes = rowBytes; 1390 srcPI.fRowBytes = rowBytes;
1374 1391
1375 return srcPI.convertPixelsTo(&dstPI, width, height); 1392 return srcPI.convertPixelsTo(&dstPI, width, height);
1376 } 1393 }
1377 return true; 1394 return true;
1378 } 1395 }
1379 1396
1380 void GrContext::prepareSurfaceForExternalRead(GrSurface* surface) { 1397 void GrContext::prepareSurfaceForExternalRead(GrSurface* surface) {
1398 RETURN_IF_ABANDONED
1381 SkASSERT(surface); 1399 SkASSERT(surface);
1382 ASSERT_OWNED_RESOURCE(surface); 1400 ASSERT_OWNED_RESOURCE(surface);
1383 if (surface->surfacePriv().hasPendingIO()) { 1401 if (surface->surfacePriv().hasPendingIO()) {
1384 this->flush(); 1402 this->flush();
1385 } 1403 }
1386 GrRenderTarget* rt = surface->asRenderTarget(); 1404 GrRenderTarget* rt = surface->asRenderTarget();
1387 if (fGpu && rt) { 1405 if (fGpu && rt) {
1388 fGpu->resolveRenderTarget(rt); 1406 fGpu->resolveRenderTarget(rt);
1389 } 1407 }
1390 } 1408 }
1391 1409
1392 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { 1410 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) {
1411 RETURN_IF_ABANDONED
1393 SkASSERT(renderTarget); 1412 SkASSERT(renderTarget);
1394 ASSERT_OWNED_RESOURCE(renderTarget); 1413 ASSERT_OWNED_RESOURCE(renderTarget);
1395 AutoCheckFlush acf(this); 1414 AutoCheckFlush acf(this);
1396 GrDrawTarget* target = this->prepareToDraw(); 1415 GrDrawTarget* target = this->prepareToDraw();
1397 if (NULL == target) { 1416 if (NULL == target) {
1398 return; 1417 return;
1399 } 1418 }
1400 target->discard(renderTarget); 1419 target->discard(renderTarget);
1401 } 1420 }
1402 1421
1403 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct, 1422 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct,
1404 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { 1423 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) {
1424 RETURN_IF_ABANDONED
1405 if (NULL == src || NULL == dst) { 1425 if (NULL == src || NULL == dst) {
1406 return; 1426 return;
1407 } 1427 }
1408 ASSERT_OWNED_RESOURCE(src); 1428 ASSERT_OWNED_RESOURCE(src);
1409 ASSERT_OWNED_RESOURCE(dst); 1429 ASSERT_OWNED_RESOURCE(dst);
1410 1430
1411 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh 1431 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh
1412 // here. 1432 // here.
1413 1433
1414 GrDrawTarget* target = this->prepareToDraw(); 1434 GrDrawTarget* target = this->prepareToDraw();
1415 if (NULL == target) { 1435 if (NULL == target) {
1416 return; 1436 return;
1417 } 1437 }
1418 target->copySurface(dst, src, srcRect, dstPoint); 1438 target->copySurface(dst, src, srcRect, dstPoint);
1419 1439
1420 if (kFlushWrites_PixelOp & pixelOpsFlags) { 1440 if (kFlushWrites_PixelOp & pixelOpsFlags) {
1421 this->flush(); 1441 this->flush();
1422 } 1442 }
1423 } 1443 }
1424 1444
1425 void GrContext::flushSurfaceWrites(GrSurface* surface) { 1445 void GrContext::flushSurfaceWrites(GrSurface* surface) {
1446 RETURN_IF_ABANDONED
1426 if (surface->surfacePriv().hasPendingWrite()) { 1447 if (surface->surfacePriv().hasPendingWrite()) {
1427 this->flush(); 1448 this->flush();
1428 } 1449 }
1429 } 1450 }
1430 1451
1431 GrDrawTarget* GrContext::prepareToDraw(GrPipelineBuilder* pipelineBuilder, 1452 GrDrawTarget* GrContext::prepareToDraw(GrPipelineBuilder* pipelineBuilder,
1432 GrRenderTarget* rt, 1453 GrRenderTarget* rt,
1433 const GrClip& clip, 1454 const GrClip& clip,
1434 const GrPaint* paint, 1455 const GrPaint* paint,
1435 const AutoCheckFlush* acf) { 1456 const AutoCheckFlush* acf) {
1436 if (NULL == fGpu) { 1457 if (NULL == fGpu || NULL == fDrawBuffer) {
1437 return NULL; 1458 return NULL;
1438 } 1459 }
1439 1460
1440 ASSERT_OWNED_RESOURCE(rt); 1461 ASSERT_OWNED_RESOURCE(rt);
1441 SkASSERT(rt && paint && acf); 1462 SkASSERT(rt && paint && acf);
1442 pipelineBuilder->setFromPaint(*paint, rt, clip); 1463 pipelineBuilder->setFromPaint(*paint, rt, clip);
1443 return fDrawBuffer; 1464 return fDrawBuffer;
1444 } 1465 }
1445 1466
1446 GrDrawTarget* GrContext::prepareToDraw() { 1467 GrDrawTarget* GrContext::prepareToDraw() {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 } 1639 }
1619 } 1640 }
1620 1641
1621 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 1642 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
1622 fGpu->removeGpuTraceMarker(marker); 1643 fGpu->removeGpuTraceMarker(marker);
1623 if (fDrawBuffer) { 1644 if (fDrawBuffer) {
1624 fDrawBuffer->removeGpuTraceMarker(marker); 1645 fDrawBuffer->removeGpuTraceMarker(marker);
1625 } 1646 }
1626 } 1647 }
1627 1648
OLDNEW
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | src/gpu/GrTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698