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