1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_GL_RENDERER_DRAW_CACHE_H_
6 #define COMPONENTS_VIZ_SERVICE_DISPLAY_GL_RENDERER_DRAW_CACHE_H_
7 
8 #include <vector>
9 
10 #include "base/macros.h"
11 #include "components/viz/service/display/program_binding.h"
12 #include "third_party/skia/include/core/SkColor.h"
13 #include "ui/gfx/rrect_f.h"
14 
15 namespace viz {
16 
17 // Collects 4 floats at a time for easy upload to GL.
18 struct Float4 {
19   float data[4];
20 };
21 
22 // Collects 16 floats at a time for easy upload to GL.
23 struct Float16 {
24   float data[16];
25 };
26 
27 // A cache for storing textured quads to be drawn.  Stores the minimum required
28 // data to tell if two back to back draws only differ in their transform. Quads
29 // that only differ by transform may be coalesced into a single draw call.
30 struct TexturedQuadDrawCache {
31   TexturedQuadDrawCache();
32   ~TexturedQuadDrawCache();
33 
34   bool is_empty = true;
35 
36   // Values tracked to determine if textured quads may be coalesced.
37   ProgramKey program_key;
38   int resource_id = -1;
39   bool needs_blending = false;
40   bool nearest_neighbor = false;
41   SkColor background_color = 0;
42   gfx::RRectF rounded_corner_bounds;
43 
44   // A cache for the coalesced quad data.
45   std::vector<Float4> uv_xform_data;
46   std::vector<float> vertex_opacity_data;
47   std::vector<Float16> matrix_data;
48 
49   // Don't batch if tex clamp rect is given.
50   Float4 tex_clamp_rect_data;
51 
52  private:
53   DISALLOW_COPY_AND_ASSIGN(TexturedQuadDrawCache);
54 };
55 
56 }  // namespace viz
57 
58 #endif  // COMPONENTS_VIZ_SERVICE_DISPLAY_GL_RENDERER_DRAW_CACHE_H_
59