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