bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/ops/GrCopySurfaceOp.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/private/GrRecordingContext.h" |
| 11 | #include "src/gpu/GrGpu.h" |
| 12 | #include "src/gpu/GrMemoryPool.h" |
| 13 | #include "src/gpu/GrRecordingContextPriv.h" |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame^] | 14 | #include "src/gpu/geometry/GrRect.h" |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 15 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 16 | std::unique_ptr<GrOp> GrCopySurfaceOp::Make(GrRecordingContext* context, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 17 | GrSurfaceProxy* dstProxy, |
| 18 | GrSurfaceProxy* srcProxy, |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 19 | const SkIRect& srcRect, |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 20 | const SkIPoint& dstPoint) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 21 | SkASSERT(dstProxy); |
| 22 | SkASSERT(srcProxy); |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 23 | SkIRect clippedSrcRect; |
| 24 | SkIPoint clippedDstPoint; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 25 | // If the rect is outside the srcProxy or dstProxy then we've already succeeded. |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame^] | 26 | if (!GrClipSrcRectAndDstPoint(dstProxy->isize(), srcProxy->isize(), srcRect, dstPoint, |
| 27 | &clippedSrcRect, &clippedDstPoint)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 28 | return nullptr; |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 29 | } |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 30 | if (GrPixelConfigIsCompressed(dstProxy->config())) { |
| 31 | return nullptr; |
| 32 | } |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 33 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame^] | 34 | SkASSERT(dstProxy->origin() == srcProxy->origin()); |
| 35 | SkIRect adjSrcRect; |
| 36 | adjSrcRect.fLeft = clippedSrcRect.fLeft; |
| 37 | adjSrcRect.fRight = clippedSrcRect.fRight; |
| 38 | SkIPoint adjDstPoint; |
| 39 | adjDstPoint.fX = clippedDstPoint.fX; |
| 40 | |
| 41 | // If it is bottom left origin we must flip the rects. |
| 42 | SkASSERT(dstProxy->origin() == srcProxy->origin()); |
| 43 | if (kBottomLeft_GrSurfaceOrigin == srcProxy->origin()) { |
| 44 | adjSrcRect.fTop = srcProxy->height() - clippedSrcRect.fBottom; |
| 45 | adjSrcRect.fBottom = srcProxy->height() - clippedSrcRect.fTop; |
| 46 | adjDstPoint.fY = dstProxy->height() - clippedDstPoint.fY - clippedSrcRect.height(); |
| 47 | } else { |
| 48 | adjSrcRect.fTop = clippedSrcRect.fTop; |
| 49 | adjSrcRect.fBottom = clippedSrcRect.fBottom; |
| 50 | adjDstPoint.fY = clippedDstPoint.fY; |
| 51 | } |
| 52 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 53 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 54 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame^] | 55 | return pool->allocate<GrCopySurfaceOp>(srcProxy, dstProxy, adjSrcRect, adjDstPoint); |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 56 | } |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 57 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 58 | void GrCopySurfaceOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) { |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 59 | SkASSERT(fSrc.get()->isInstantiated()); |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 60 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame^] | 61 | // If we are using approx surfaces we may need to adjust our srcRect or dstPoint if the origin |
| 62 | // is bottom left. |
| 63 | GrSurfaceProxy* src = fSrc.get(); |
| 64 | if (src->origin() == kBottomLeft_GrSurfaceOrigin) { |
| 65 | GrSurfaceProxy* dst = fDst.get(); |
| 66 | SkASSERT(dst->isInstantiated()); |
| 67 | if (src->height() != src->peekSurface()->height()) { |
| 68 | fSrcRect.offset(0, src->peekSurface()->height() - src->height()); |
| 69 | } |
| 70 | if (dst->height() != dst->peekSurface()->height()) { |
| 71 | fDstPoint.fY = fDstPoint.fY + (dst->peekSurface()->height() - dst->height()); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | state->commandBuffer()->copy(fSrc.get()->peekSurface(), fSrcRect, fDstPoint); |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 76 | } |