• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "src/gpu/ops/GrCopySurfaceOp.h"
9 
10 #include "include/private/GrRecordingContext.h"
11 #include "src/gpu/GrGpu.h"
12 #include "src/gpu/GrMemoryPool.h"
13 #include "src/gpu/GrRecordingContextPriv.h"
14 #include "src/gpu/geometry/GrRect.h"
15 
Make(GrRecordingContext * context,GrSurfaceProxy * dstProxy,GrSurfaceProxy * srcProxy,const SkIRect & srcRect,const SkIPoint & dstPoint)16 std::unique_ptr<GrOp> GrCopySurfaceOp::Make(GrRecordingContext* context,
17                                             GrSurfaceProxy* dstProxy,
18                                             GrSurfaceProxy* srcProxy,
19                                             const SkIRect& srcRect,
20                                             const SkIPoint& dstPoint) {
21     SkASSERT(dstProxy);
22     SkASSERT(srcProxy);
23     SkIRect clippedSrcRect;
24     SkIPoint clippedDstPoint;
25     // If the rect is outside the srcProxy or dstProxy then we've already succeeded.
26     if (!GrClipSrcRectAndDstPoint(dstProxy->isize(), srcProxy->isize(), srcRect, dstPoint,
27                                   &clippedSrcRect, &clippedDstPoint)) {
28         return nullptr;
29     }
30     if (GrPixelConfigIsCompressed(dstProxy->config())) {
31         return nullptr;
32     }
33 
34     GrOpMemoryPool* pool = context->priv().opMemoryPool();
35 
36     return pool->allocate<GrCopySurfaceOp>(srcProxy, dstProxy, clippedSrcRect, clippedDstPoint);
37 }
38 
onExecute(GrOpFlushState * state,const SkRect & chainBounds)39 void GrCopySurfaceOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
40     SkASSERT(fSrc.get()->isInstantiated());
41 
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);
57 }
58