blob: 401ce222fbf54b4c28902d4f8d2fd6091cb235ed [file] [log] [blame]
bsalomon@google.com31ec7982013-03-27 18:14:57 +00001/*
2 * Copyright 2013 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#ifndef GrGLProgramDesc_DEFINED
9#define GrGLProgramDesc_DEFINED
10
joshualitt79f8fae2014-10-28 17:59:26 -070011#include "GrColor.h"
12#include "GrProgramDesc.h"
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +000013#include "GrGpu.h"
joshualitt79f8fae2014-10-28 17:59:26 -070014#include "GrTypesPriv.h"
bsalomon@google.com31ec7982013-03-27 18:14:57 +000015
bsalomon861e1032014-12-16 07:33:49 -080016class GrGLGpu;
bsalomon@google.com31ec7982013-03-27 18:14:57 +000017
joshualitt79f8fae2014-10-28 17:59:26 -070018/**
19 * This class can be used to build a GrProgramDesc. It also provides helpers for accessing
20 * GL specific info in the header.
21 */
22class GrGLProgramDescBuilder {
bsalomon@google.com31ec7982013-03-27 18:14:57 +000023public:
joshualitt79f8fae2014-10-28 17:59:26 -070024 struct GLKeyHeader : public GrProgramDesc::KeyHeader {
25 SkBool8 fUseNvpr;
bsalomon@google.com31ec7982013-03-27 18:14:57 +000026 };
bsalomon@google.com31ec7982013-03-27 18:14:57 +000027
joshualitt79f8fae2014-10-28 17:59:26 -070028 // The key, stored in fKey, is composed of five parts(first 2 are defined in the key itself):
bsalomon848faf02014-07-11 10:01:02 -070029 // 1. uint32_t for total key length.
30 // 2. uint32_t for a checksum.
31 // 3. Header struct defined above.
egdanielc67870c2014-11-26 08:50:50 -080032 // 4. Backend-specific information including per-processor keys and their key lengths.
33 // Each processor's key is a variable length array of uint32_t.
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000034 enum {
bsalomon929f29a2014-07-17 07:55:11 -070035 // Part 3.
joshualitt79f8fae2014-10-28 17:59:26 -070036 kHeaderOffset = GrProgramDesc::kHeaderOffset,
37 kHeaderSize = SkAlign4(sizeof(GLKeyHeader)),
bsalomon929f29a2014-07-17 07:55:11 -070038 // Part 4.
egdanielc67870c2014-11-26 08:50:50 -080039 // This is the offset into the backenend specific part of the key, which includes
40 // per-processor keys.
41 kProcessorKeysOffset = kHeaderOffset + kHeaderSize,
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000042 };
43
joshualitt79f8fae2014-10-28 17:59:26 -070044 /**
45 * Builds a GL specific program descriptor
46 *
47 * @param GrOptDrawState The optimized drawstate. The descriptor will represent a program
48 * which this optstate can use to draw with. The optstate contains
49 * general draw information, as well as the specific color, geometry,
50 * and coverage stages which will be used to generate the GL Program for
51 * this optstate.
52 * @param DescInfo A descriptor info struct, generated by the optstate, which contains a number
53 * of important facts about the program the built descriptor will represent
54 * @param DrawType
bsalomon861e1032014-12-16 07:33:49 -080055 * @param GrGLGpu A GL Gpu, the caps and Gpu object are used to output processor specific
joshualitt79f8fae2014-10-28 17:59:26 -070056 * parts of the descriptor.
57 * @param GrDeviceCoordTexture A dstCopy texture, which may be null if frame buffer fetch is
58 * supported
59 * @param GrProgramDesc The built and finalized descriptor
60 **/
61 static bool Build(const GrOptDrawState&,
62 const GrProgramDesc::DescInfo&,
63 GrGpu::DrawType,
bsalomon861e1032014-12-16 07:33:49 -080064 GrGLGpu*,
joshualitt79f8fae2014-10-28 17:59:26 -070065 GrProgramDesc*);
66
67 static const GLKeyHeader& GetHeader(const GrProgramDesc& desc) {
68 return *desc.atOffset<GLKeyHeader, kHeaderOffset>();
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000069 }
bsalomon@google.com31ec7982013-03-27 18:14:57 +000070};
71
72#endif