GrClearOp.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2017 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/GrClearOp.h"
  8. #include "include/private/GrRecordingContext.h"
  9. #include "src/gpu/GrGpuCommandBuffer.h"
  10. #include "src/gpu/GrMemoryPool.h"
  11. #include "src/gpu/GrOpFlushState.h"
  12. #include "src/gpu/GrProxyProvider.h"
  13. #include "src/gpu/GrRecordingContextPriv.h"
  14. std::unique_ptr<GrClearOp> GrClearOp::Make(GrRecordingContext* context,
  15. const GrFixedClip& clip,
  16. const SkPMColor4f& color,
  17. GrSurfaceProxy* dstProxy) {
  18. const SkIRect rect = SkIRect::MakeWH(dstProxy->width(), dstProxy->height());
  19. if (clip.scissorEnabled() && !SkIRect::Intersects(clip.scissorRect(), rect)) {
  20. return nullptr;
  21. }
  22. GrOpMemoryPool* pool = context->priv().opMemoryPool();
  23. return pool->allocate<GrClearOp>(clip, color, dstProxy);
  24. }
  25. std::unique_ptr<GrClearOp> GrClearOp::Make(GrRecordingContext* context,
  26. const SkIRect& rect,
  27. const SkPMColor4f& color,
  28. bool fullScreen) {
  29. SkASSERT(fullScreen || !rect.isEmpty());
  30. GrOpMemoryPool* pool = context->priv().opMemoryPool();
  31. return pool->allocate<GrClearOp>(rect, color, fullScreen);
  32. }
  33. GrClearOp::GrClearOp(const GrFixedClip& clip, const SkPMColor4f& color, GrSurfaceProxy* proxy)
  34. : INHERITED(ClassID())
  35. , fClip(clip)
  36. , fColor(color) {
  37. const SkIRect rtRect = SkIRect::MakeWH(proxy->width(), proxy->height());
  38. if (fClip.scissorEnabled()) {
  39. // Don't let scissors extend outside the RT. This may improve op combining.
  40. if (!fClip.intersect(rtRect)) {
  41. SkASSERT(0); // should be caught upstream
  42. fClip = GrFixedClip(SkIRect::MakeEmpty());
  43. }
  44. if (GrProxyProvider::IsFunctionallyExact(proxy) && fClip.scissorRect() == rtRect) {
  45. fClip.disableScissor();
  46. }
  47. }
  48. this->setBounds(SkRect::Make(fClip.scissorEnabled() ? fClip.scissorRect() : rtRect),
  49. HasAABloat::kNo, IsZeroArea::kNo);
  50. }
  51. void GrClearOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
  52. SkASSERT(state->rtCommandBuffer());
  53. state->rtCommandBuffer()->clear(fClip, fColor);
  54. }