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 "src/gpu/ops/GrClearOp.h"
9
10#include "include/private/GrRecordingContext.h"
11#include "src/gpu/GrMemoryPool.h"
12#include "src/gpu/GrOpFlushState.h"
13#include "src/gpu/GrOpsRenderPass.h"
14#include "src/gpu/GrProxyProvider.h"
15#include "src/gpu/GrRecordingContextPriv.h"
16
17std::unique_ptr<GrClearOp> GrClearOp::Make(GrRecordingContext* context,
18 const GrFixedClip& clip,
19 const SkPMColor4f& color,
20 GrSurfaceProxy* dstProxy) {
21 const SkIRect rect = SkIRect::MakeSize(dstProxy->dimensions());
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
31std::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
42GrClearOp::GrClearOp(const GrFixedClip& clip, const SkPMColor4f& color, GrSurfaceProxy* proxy)
43 : INHERITED(ClassID())
44 , fClip(clip)
45 , fColor(color) {
46 const SkIRect rtRect = SkIRect::MakeSize(proxy->dimensions());
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 (proxy->isFunctionallyExact() && fClip.scissorRect() == rtRect) {
55 fClip.disableScissor();
56 }
57 }
58 this->setBounds(SkRect::Make(fClip.scissorEnabled() ? fClip.scissorRect() : rtRect),
59 HasAABloat::kNo, IsHairline::kNo);
60}
61
62void GrClearOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
63 SkASSERT(state->opsRenderPass());
64 state->opsRenderPass()->clear(fClip, fColor);
65}
66