GrCopySurfaceOp.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #include "src/gpu/ops/GrCopySurfaceOp.h"
  8. #include "include/private/GrRecordingContext.h"
  9. #include "src/gpu/GrGpu.h"
  10. #include "src/gpu/GrMemoryPool.h"
  11. #include "src/gpu/GrRecordingContextPriv.h"
  12. #include "src/gpu/geometry/GrRect.h"
  13. std::unique_ptr<GrOp> GrCopySurfaceOp::Make(GrRecordingContext* context,
  14. GrSurfaceProxy* dstProxy,
  15. GrSurfaceProxy* srcProxy,
  16. const SkIRect& srcRect,
  17. const SkIPoint& dstPoint) {
  18. SkASSERT(dstProxy);
  19. SkASSERT(srcProxy);
  20. SkIRect clippedSrcRect;
  21. SkIPoint clippedDstPoint;
  22. // If the rect is outside the srcProxy or dstProxy then we've already succeeded.
  23. if (!GrClipSrcRectAndDstPoint(dstProxy->isize(), srcProxy->isize(), srcRect, dstPoint,
  24. &clippedSrcRect, &clippedDstPoint)) {
  25. return nullptr;
  26. }
  27. if (GrPixelConfigIsCompressed(dstProxy->config())) {
  28. return nullptr;
  29. }
  30. GrOpMemoryPool* pool = context->priv().opMemoryPool();
  31. return pool->allocate<GrCopySurfaceOp>(srcProxy, dstProxy, clippedSrcRect, clippedDstPoint);
  32. }
  33. void GrCopySurfaceOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
  34. SkASSERT(fSrc.get()->isInstantiated());
  35. // If we are using approx surfaces we may need to adjust our srcRect or dstPoint if the origin
  36. // is bottom left.
  37. GrSurfaceProxy* src = fSrc.get();
  38. if (src->origin() == kBottomLeft_GrSurfaceOrigin) {
  39. GrSurfaceProxy* dst = fDst.get();
  40. SkASSERT(dst->isInstantiated());
  41. if (src->height() != src->peekSurface()->height()) {
  42. fSrcRect.offset(0, src->peekSurface()->height() - src->height());
  43. }
  44. if (dst->height() != dst->peekSurface()->height()) {
  45. fDstPoint.fY = fDstPoint.fY + (dst->peekSurface()->height() - dst->height());
  46. }
  47. }
  48. state->commandBuffer()->copy(fSrc.get()->peekSurface(), fSrcRect, fDstPoint);
  49. }