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 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 34 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 35 | |
Greg Daniel | a47ab49 | 2019-06-11 16:44:23 -0400 | [diff] [blame^] | 36 | return pool->allocate<GrCopySurfaceOp>(srcProxy, dstProxy, clippedSrcRect, clippedDstPoint); |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 37 | } |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 38 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 39 | void GrCopySurfaceOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) { |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 40 | SkASSERT(fSrc.get()->isInstantiated()); |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 41 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 42 | // If we are using approx surfaces we may need to adjust our srcRect or dstPoint if the origin |
| 43 | // is bottom left. |
| 44 | GrSurfaceProxy* src = fSrc.get(); |
| 45 | if (src->origin() == kBottomLeft_GrSurfaceOrigin) { |
| 46 | GrSurfaceProxy* dst = fDst.get(); |
| 47 | SkASSERT(dst->isInstantiated()); |
| 48 | if (src->height() != src->peekSurface()->height()) { |
| 49 | fSrcRect.offset(0, src->peekSurface()->height() - src->height()); |
| 50 | } |
| 51 | if (dst->height() != dst->peekSurface()->height()) { |
| 52 | fDstPoint.fY = fDstPoint.fY + (dst->peekSurface()->height() - dst->height()); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | state->commandBuffer()->copy(fSrc.get()->peekSurface(), fSrcRect, fDstPoint); |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 57 | } |