xref: /aosp_15_r20/external/skia/src/gpu/graphite/DrawList.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2021 Google LLC
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/graphite/DrawList.h"
9 
10 #include "src/gpu/BufferWriter.h"
11 #include "src/gpu/graphite/Renderer.h"
12 #include "src/gpu/graphite/geom/Shape.h"
13 
14 namespace skgpu::graphite {
15 
deduplicateTransform(const Transform & localToDevice)16 const Transform& DrawList::deduplicateTransform(const Transform& localToDevice) {
17     // TODO: This is a pretty simple deduplication strategy and doesn't take advantage of the stack
18     // knowledge that Device has.
19     if (fTransforms.empty() || fTransforms.back() != localToDevice) {
20         fTransforms.push_back(localToDevice);
21     }
22     return fTransforms.back();
23 }
24 
recordDraw(const Renderer * renderer,const Transform & localToDevice,const Geometry & geometry,const Clip & clip,DrawOrder ordering,const PaintParams * paint,const StrokeStyle * stroke)25 void DrawList::recordDraw(const Renderer* renderer,
26                           const Transform& localToDevice,
27                           const Geometry& geometry,
28                           const Clip& clip,
29                           DrawOrder ordering,
30                           const PaintParams* paint,
31                           const StrokeStyle* stroke) {
32     SkASSERT(localToDevice.valid());
33     SkASSERT(!geometry.isEmpty() && !clip.drawBounds().isEmptyNegativeOrNaN());
34     SkASSERT(!(renderer->depthStencilFlags() & DepthStencilFlags::kStencil) ||
35              ordering.stencilIndex() != DrawOrder::kUnassigned);
36 
37     // TODO: Add validation that the renderer's expected shape type and stroke params match provided
38 
39     fDraws.emplace_back(renderer, this->deduplicateTransform(localToDevice),
40                         geometry, clip, ordering, paint, stroke);
41     fRenderStepCount += renderer->numRenderSteps();
42 
43 #if defined(SK_DEBUG)
44     if (geometry.isCoverageMaskShape()) {
45         fCoverageMaskShapeDrawCount++;
46     }
47 #endif
48 
49     if (paint && paint->dstReadRequirement() == DstReadRequirement::kTextureCopy) {
50         fDstCopyBounds.join(clip.drawBounds());
51     }
52 }
53 
54 } // namespace skgpu::graphite
55