blob: a0e08e5a00b295e393e11835c5538c0155ba98dd [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
reed@google.comac10a2d2010-12-22 21:39:39 +00009#include "GrGpuGL.h"
cdalton51192342014-06-09 11:16:58 -070010#include "GrGLNameAllocator.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000011#include "GrGLStencilBuffer.h"
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000012#include "GrGLPath.h"
cdaltonb85a0aa2014-07-21 15:32:44 -070013#include "GrGLPathRange.h"
bsalomon@google.com6d003d12012-09-11 15:45:20 +000014#include "GrGLShaderBuilder.h"
bsalomon@google.coma3201942012-06-21 19:58:20 +000015#include "GrTemplates.h"
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +000016#include "GrTypes.h"
commit-bot@chromium.org32184d82013-10-09 15:14:18 +000017#include "SkStrokeRec.h"
bsalomon@google.com3582bf92011-06-30 21:32:31 +000018#include "SkTemplates.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000019
bsalomon@google.com0b77d682011-08-19 13:28:54 +000020#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +000021#define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X)
bsalomon@google.com0b77d682011-08-19 13:28:54 +000022
reed@google.comac10a2d2010-12-22 21:39:39 +000023#define SKIP_CACHE_CHECK true
24
bsalomon@google.com4f3c2532012-01-19 16:16:52 +000025#if GR_GL_CHECK_ALLOC_WITH_GET_ERROR
26 #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface)
27 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call)
28 #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface)
rmistry@google.comfbfcd562012-08-23 18:09:54 +000029#else
bsalomon@google.com4f3c2532012-01-19 16:16:52 +000030 #define CLEAR_ERROR_BEFORE_ALLOC(iface)
31 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call)
32 #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR
33#endif
34
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +000035
36///////////////////////////////////////////////////////////////////////////////
37
cdaltonb85a0aa2014-07-21 15:32:44 -070038static const GrGLenum gXformType2GLType[] = {
39 GR_GL_NONE,
40 GR_GL_TRANSLATE_X,
41 GR_GL_TRANSLATE_Y,
42 GR_GL_TRANSLATE_2D,
43 GR_GL_TRANSPOSE_AFFINE_2D
44};
45
46GR_STATIC_ASSERT(0 == GrDrawTarget::kNone_PathTransformType);
47GR_STATIC_ASSERT(1 == GrDrawTarget::kTranslateX_PathTransformType);
48GR_STATIC_ASSERT(2 == GrDrawTarget::kTranslateY_PathTransformType);
49GR_STATIC_ASSERT(3 == GrDrawTarget::kTranslate_PathTransformType);
50GR_STATIC_ASSERT(4 == GrDrawTarget::kAffine_PathTransformType);
51GR_STATIC_ASSERT(GrDrawTarget::kAffine_PathTransformType == GrDrawTarget::kLast_PathTransformType);
52
twiz@google.com0f31ca72011-03-18 17:38:11 +000053static const GrGLenum gXfermodeCoeff2Blend[] = {
54 GR_GL_ZERO,
55 GR_GL_ONE,
56 GR_GL_SRC_COLOR,
57 GR_GL_ONE_MINUS_SRC_COLOR,
58 GR_GL_DST_COLOR,
59 GR_GL_ONE_MINUS_DST_COLOR,
60 GR_GL_SRC_ALPHA,
61 GR_GL_ONE_MINUS_SRC_ALPHA,
62 GR_GL_DST_ALPHA,
63 GR_GL_ONE_MINUS_DST_ALPHA,
64 GR_GL_CONSTANT_COLOR,
65 GR_GL_ONE_MINUS_CONSTANT_COLOR,
66 GR_GL_CONSTANT_ALPHA,
67 GR_GL_ONE_MINUS_CONSTANT_ALPHA,
bsalomon@google.com271cffc2011-05-20 14:13:56 +000068
69 // extended blend coeffs
70 GR_GL_SRC1_COLOR,
71 GR_GL_ONE_MINUS_SRC1_COLOR,
72 GR_GL_SRC1_ALPHA,
73 GR_GL_ONE_MINUS_SRC1_ALPHA,
reed@google.comac10a2d2010-12-22 21:39:39 +000074};
75
bsalomon@google.com271cffc2011-05-20 14:13:56 +000076bool GrGpuGL::BlendCoeffReferencesConstant(GrBlendCoeff coeff) {
bsalomon@google.com080773c2011-03-15 19:09:25 +000077 static const bool gCoeffReferencesBlendConst[] = {
78 false,
79 false,
80 false,
81 false,
82 false,
83 false,
84 false,
85 false,
86 false,
87 false,
88 true,
89 true,
90 true,
91 true,
bsalomon@google.com271cffc2011-05-20 14:13:56 +000092
93 // extended blend coeffs
94 false,
95 false,
96 false,
97 false,
bsalomon@google.com080773c2011-03-15 19:09:25 +000098 };
99 return gCoeffReferencesBlendConst[coeff];
bsalomon@google.com47059542012-06-06 20:51:20 +0000100 GR_STATIC_ASSERT(kTotalGrBlendCoeffCount ==
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000101 SK_ARRAY_COUNT(gCoeffReferencesBlendConst));
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000102
bsalomon@google.com47059542012-06-06 20:51:20 +0000103 GR_STATIC_ASSERT(0 == kZero_GrBlendCoeff);
104 GR_STATIC_ASSERT(1 == kOne_GrBlendCoeff);
105 GR_STATIC_ASSERT(2 == kSC_GrBlendCoeff);
106 GR_STATIC_ASSERT(3 == kISC_GrBlendCoeff);
107 GR_STATIC_ASSERT(4 == kDC_GrBlendCoeff);
108 GR_STATIC_ASSERT(5 == kIDC_GrBlendCoeff);
109 GR_STATIC_ASSERT(6 == kSA_GrBlendCoeff);
110 GR_STATIC_ASSERT(7 == kISA_GrBlendCoeff);
111 GR_STATIC_ASSERT(8 == kDA_GrBlendCoeff);
112 GR_STATIC_ASSERT(9 == kIDA_GrBlendCoeff);
113 GR_STATIC_ASSERT(10 == kConstC_GrBlendCoeff);
114 GR_STATIC_ASSERT(11 == kIConstC_GrBlendCoeff);
115 GR_STATIC_ASSERT(12 == kConstA_GrBlendCoeff);
116 GR_STATIC_ASSERT(13 == kIConstA_GrBlendCoeff);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000117
bsalomon@google.com47059542012-06-06 20:51:20 +0000118 GR_STATIC_ASSERT(14 == kS2C_GrBlendCoeff);
119 GR_STATIC_ASSERT(15 == kIS2C_GrBlendCoeff);
120 GR_STATIC_ASSERT(16 == kS2A_GrBlendCoeff);
121 GR_STATIC_ASSERT(17 == kIS2A_GrBlendCoeff);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000122
123 // assertion for gXfermodeCoeff2Blend have to be in GrGpu scope
bsalomon@google.com47059542012-06-06 20:51:20 +0000124 GR_STATIC_ASSERT(kTotalGrBlendCoeffCount ==
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000125 SK_ARRAY_COUNT(gXfermodeCoeff2Blend));
bsalomon@google.com080773c2011-03-15 19:09:25 +0000126}
127
reed@google.comac10a2d2010-12-22 21:39:39 +0000128///////////////////////////////////////////////////////////////////////////////
129
rileya@google.come38160c2012-07-03 18:03:04 +0000130static bool gPrintStartupSpew;
bsalomon@google.com42ab7ea2011-01-19 17:19:40 +0000131
robertphillips@google.com6177e692013-02-28 20:16:25 +0000132GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context)
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000133 : GrGpu(context)
robertphillips@google.com6177e692013-02-28 20:16:25 +0000134 , fGLContext(ctx) {
bsalomon@google.com89ec61e2012-02-10 20:05:18 +0000135
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000136 SkASSERT(ctx.isInitialized());
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000137 fCaps.reset(SkRef(ctx.caps()));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000138
bsalomon1c63bf62014-07-22 13:09:46 -0700139 fHWBoundTextureUniqueIDs.reset(this->glCaps().maxFragmentTextureUnits());
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000140 fHWPathTexGenSettings.reset(this->glCaps().maxFixedFunctionTextureCoords());
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000141
robertphillips@google.com6177e692013-02-28 20:16:25 +0000142 GrGLClearErr(fGLContext.interface());
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000143 if (gPrintStartupSpew) {
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000144 const GrGLubyte* vendor;
145 const GrGLubyte* renderer;
146 const GrGLubyte* version;
147 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR));
148 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER));
149 GL_CALL_RET(version, GetString(GR_GL_VERSION));
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000150 GrPrintf("------------------------- create GrGpuGL %p --------------\n",
151 this);
152 GrPrintf("------ VENDOR %s\n", vendor);
153 GrPrintf("------ RENDERER %s\n", renderer);
154 GrPrintf("------ VERSION %s\n", version);
bsalomon@google.com00142c42013-05-02 19:42:54 +0000155 GrPrintf("------ EXTENSIONS\n");
bsalomone904c092014-07-17 10:50:59 -0700156 ctx.extensions().print();
bsalomon@google.com00142c42013-05-02 19:42:54 +0000157 GrPrintf("\n");
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000158 GrPrintf(this->glCaps().dump().c_str());
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000159 }
160
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000161 fProgramCache = SkNEW_ARGS(ProgramCache, (this));
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000162
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000163 SkASSERT(this->glCaps().maxVertexAttributes() >= GrDrawState::kMaxVertexAttribCnt);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000164
bsalomon@google.comfe676522011-06-17 18:12:21 +0000165 fLastSuccessfulStencilFmtIdx = 0;
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000166 fHWProgramID = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000167}
168
169GrGpuGL::~GrGpuGL() {
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000170 if (0 != fHWProgramID) {
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000171 // detach the current program so there is no confusion on OpenGL's part
172 // that we want it to be deleted
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000173 SkASSERT(fHWProgramID == fCurrentProgram->programID());
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000174 GL_CALL(UseProgram(0));
175 }
176
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000177 delete fProgramCache;
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000178
bsalomon@google.com4a018bb2011-10-28 19:50:21 +0000179 // This must be called by before the GrDrawTarget destructor
180 this->releaseGeometry();
bsalomon@google.com15b11df2011-09-16 21:18:29 +0000181 // This subclass must do this before the base class destructor runs
182 // since we will unref the GrGLInterface.
183 this->releaseResources();
reed@google.comac10a2d2010-12-22 21:39:39 +0000184}
185
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000186///////////////////////////////////////////////////////////////////////////////
bungemanc7af8122014-07-16 09:10:41 -0700187
188
commit-bot@chromium.org28621512013-08-07 19:43:45 +0000189GrPixelConfig GrGpuGL::preferredReadPixelsConfig(GrPixelConfig readConfig,
190 GrPixelConfig surfaceConfig) const {
191 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig) {
bsalomon@google.com9c680582013-02-06 18:17:50 +0000192 return kBGRA_8888_GrPixelConfig;
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000193 } else if (this->glContext().isMesa() &&
commit-bot@chromium.org28621512013-08-07 19:43:45 +0000194 GrBytesPerPixel(readConfig) == 4 &&
195 GrPixelConfigSwapRAndB(readConfig) == surfaceConfig) {
commit-bot@chromium.org5d1d79a2013-05-24 18:52:52 +0000196 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA surface and vice-versa.
197 // Perhaps this should be guarded by some compiletime or runtime check.
198 return surfaceConfig;
bungemanc7af8122014-07-16 09:10:41 -0700199 } else if (readConfig == kBGRA_8888_GrPixelConfig &&
200 !this->glCaps().readPixelsSupported(this->glInterface(),
201 GR_GL_BGRA, GR_GL_UNSIGNED_BYTE)) {
commit-bot@chromium.org28621512013-08-07 19:43:45 +0000202 return kRGBA_8888_GrPixelConfig;
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000203 } else {
commit-bot@chromium.org28621512013-08-07 19:43:45 +0000204 return readConfig;
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000205 }
206}
207
commit-bot@chromium.org5d1d79a2013-05-24 18:52:52 +0000208GrPixelConfig GrGpuGL::preferredWritePixelsConfig(GrPixelConfig writeConfig,
209 GrPixelConfig surfaceConfig) const {
commit-bot@chromium.org28621512013-08-07 19:43:45 +0000210 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == writeConfig) {
211 return kBGRA_8888_GrPixelConfig;
212 } else {
213 return writeConfig;
214 }
bsalomon@google.com9c680582013-02-06 18:17:50 +0000215}
216
217bool GrGpuGL::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcConfig) const {
krajcevski145d48c2014-06-11 16:07:50 -0700218 if (kIndex_8_GrPixelConfig == srcConfig || kIndex_8_GrPixelConfig == texture->config()) {
bsalomon@google.com9c680582013-02-06 18:17:50 +0000219 return false;
220 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000221 if (srcConfig != texture->config() && kGLES_GrGLStandard == this->glStandard()) {
bsalomon@google.com9c680582013-02-06 18:17:50 +0000222 // In general ES2 requires the internal format of the texture and the format of the src
223 // pixels to match. However, It may or may not be possible to upload BGRA data to a RGBA
224 // texture. It depends upon which extension added BGRA. The Apple extension allows it
225 // (BGRA's internal format is RGBA) while the EXT extension does not (BGRA is its own
226 // internal format).
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000227 if (this->glCaps().isConfigTexturable(kBGRA_8888_GrPixelConfig) &&
bsalomon@google.com9c680582013-02-06 18:17:50 +0000228 !this->glCaps().bgraIsInternalFormat() &&
229 kBGRA_8888_GrPixelConfig == srcConfig &&
230 kRGBA_8888_GrPixelConfig == texture->config()) {
231 return true;
232 } else {
233 return false;
234 }
bsalomon@google.com0a97be22011-11-08 19:20:57 +0000235 } else {
bsalomon@google.com9c680582013-02-06 18:17:50 +0000236 return true;
bsalomon@google.com0a97be22011-11-08 19:20:57 +0000237 }
238}
239
bsalomon@google.com56d11e02011-11-30 19:59:08 +0000240bool GrGpuGL::fullReadPixelsIsFasterThanPartial() const {
241 return SkToBool(GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL);
242}
243
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000244void GrGpuGL::onResetContext(uint32_t resetBits) {
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000245 // we don't use the zb at all
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000246 if (resetBits & kMisc_GrGLBackendState) {
247 GL_CALL(Disable(GR_GL_DEPTH_TEST));
248 GL_CALL(DepthMask(GR_GL_FALSE));
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000249
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000250 fHWDrawFace = GrDrawState::kInvalid_DrawFace;
251 fHWDitherEnabled = kUnknown_TriState;
reed@google.comac10a2d2010-12-22 21:39:39 +0000252
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000253 if (kGL_GrGLStandard == this->glStandard()) {
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000254 // Desktop-only state that we never change
255 if (!this->glCaps().isCoreProfile()) {
256 GL_CALL(Disable(GR_GL_POINT_SMOOTH));
257 GL_CALL(Disable(GR_GL_LINE_SMOOTH));
258 GL_CALL(Disable(GR_GL_POLYGON_SMOOTH));
259 GL_CALL(Disable(GR_GL_POLYGON_STIPPLE));
260 GL_CALL(Disable(GR_GL_COLOR_LOGIC_OP));
261 GL_CALL(Disable(GR_GL_INDEX_LOGIC_OP));
262 }
263 // The windows NVIDIA driver has GL_ARB_imaging in the extension string when using a
264 // core profile. This seems like a bug since the core spec removes any mention of
265 // GL_ARB_imaging.
266 if (this->glCaps().imagingSupport() && !this->glCaps().isCoreProfile()) {
267 GL_CALL(Disable(GR_GL_COLOR_TABLE));
268 }
269 GL_CALL(Disable(GR_GL_POLYGON_OFFSET_FILL));
270 // Since ES doesn't support glPointSize at all we always use the VS to
271 // set the point size
272 GL_CALL(Enable(GR_GL_VERTEX_PROGRAM_POINT_SIZE));
273
274 // We should set glPolygonMode(FRONT_AND_BACK,FILL) here, too. It isn't
275 // currently part of our gl interface. There are probably others as
276 // well.
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000277 }
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000278 fHWWriteToColor = kUnknown_TriState;
279 // we only ever use lines in hairline mode
280 GL_CALL(LineWidth(1));
bsalomon@google.comcad107b2013-06-28 14:32:08 +0000281 }
edisonn@google.comba669992013-06-28 16:03:21 +0000282
egdanielb09bdd62014-07-29 08:52:23 -0700283 if (resetBits & kAA_GrGLBackendState) {
284 fHWAAState.invalidate();
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000285 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000286
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000287 fHWActiveTextureUnitIdx = -1; // invalid
288
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000289 if (resetBits & kTextureBinding_GrGLBackendState) {
bsalomon1c63bf62014-07-22 13:09:46 -0700290 for (int s = 0; s < fHWBoundTextureUniqueIDs.count(); ++s) {
291 fHWBoundTextureUniqueIDs[s] = SK_InvalidUniqueID;
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000292 }
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000293 }
bsalomon@google.com316f99232011-01-13 21:28:12 +0000294
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000295 if (resetBits & kBlend_GrGLBackendState) {
296 fHWBlendState.invalidate();
297 }
robertphillips@google.com730ebe52012-04-16 16:33:13 +0000298
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000299 if (resetBits & kView_GrGLBackendState) {
300 fHWScissorSettings.invalidate();
301 fHWViewport.invalidate();
302 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000303
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000304 if (resetBits & kStencil_GrGLBackendState) {
305 fHWStencilSettings.invalidate();
306 fHWStencilTestEnabled = kUnknown_TriState;
307 }
robertphillips@google.com730ebe52012-04-16 16:33:13 +0000308
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000309 // Vertex
310 if (resetBits & kVertex_GrGLBackendState) {
311 fHWGeometryState.invalidate();
312 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000313
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000314 if (resetBits & kRenderTarget_GrGLBackendState) {
bsalomon1c63bf62014-07-22 13:09:46 -0700315 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000316 }
bsalomon@google.com8ef3fd02011-11-21 15:53:13 +0000317
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000318 if (resetBits & kPathRendering_GrGLBackendState) {
319 if (this->caps()->pathRenderingSupport()) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000320 fHWProjectionMatrixState.invalidate();
321 // we don't use the model view matrix.
commit-bot@chromium.orgf6696722014-04-25 06:21:30 +0000322 GL_CALL(MatrixLoadIdentity(GR_GL_MODELVIEW));
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000323
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000324 for (int i = 0; i < this->glCaps().maxFixedFunctionTextureCoords(); ++i) {
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000325 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL));
326 fHWPathTexGenSettings[i].fMode = GR_GL_NONE;
327 fHWPathTexGenSettings[i].fNumComponents = 0;
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000328 }
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000329 fHWActivePathTexGenSets = 0;
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000330 }
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000331 fHWPathStencilSettings.invalidate();
bsalomon@google.com05a718c2012-06-29 14:01:53 +0000332 }
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000333
bsalomon@google.com8ef3fd02011-11-21 15:53:13 +0000334 // we assume these values
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000335 if (resetBits & kPixelStore_GrGLBackendState) {
336 if (this->glCaps().unpackRowLengthSupport()) {
337 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
338 }
339 if (this->glCaps().packRowLengthSupport()) {
340 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0));
341 }
342 if (this->glCaps().unpackFlipYSupport()) {
343 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE));
344 }
345 if (this->glCaps().packFlipYSupport()) {
346 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, GR_GL_FALSE));
347 }
bsalomon@google.com56d11e02011-11-30 19:59:08 +0000348 }
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000349
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000350 if (resetBits & kProgram_GrGLBackendState) {
351 fHWProgramID = 0;
352 fSharedGLProgramState.invalidate();
353 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000354}
355
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000356namespace {
357
358GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) {
359 // By default, GrRenderTargets are GL's normal orientation so that they
360 // can be drawn to by the outside world without the client having
361 // to render upside down.
362 if (kDefault_GrSurfaceOrigin == origin) {
363 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
364 } else {
365 return origin;
366 }
367}
368
369}
370
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000371GrTexture* GrGpuGL::onWrapBackendTexture(const GrBackendTextureDesc& desc) {
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000372 if (!this->configToGLFormats(desc.fConfig, false, NULL, NULL, NULL)) {
bsalomon@google.come269f212011-11-07 13:29:52 +0000373 return NULL;
374 }
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000375
robertphillips@google.comb72e5d32012-10-30 15:18:10 +0000376 if (0 == desc.fTextureHandle) {
377 return NULL;
378 }
379
bsalomon@google.combcce8922013-03-25 15:38:39 +0000380 int maxSize = this->caps()->maxTextureSize();
robertphillips@google.comb72e5d32012-10-30 15:18:10 +0000381 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
382 return NULL;
383 }
384
385 GrGLTexture::Desc glTexDesc;
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000386 // next line relies on GrBackendTextureDesc's flags matching GrTexture's
robertphillips@google.com32716282012-06-04 12:48:45 +0000387 glTexDesc.fFlags = (GrTextureFlags) desc.fFlags;
bsalomon@google.com99621082011-11-15 16:47:16 +0000388 glTexDesc.fWidth = desc.fWidth;
389 glTexDesc.fHeight = desc.fHeight;
bsalomon@google.come269f212011-11-07 13:29:52 +0000390 glTexDesc.fConfig = desc.fConfig;
robertphillips@google.com32716282012-06-04 12:48:45 +0000391 glTexDesc.fSampleCnt = desc.fSampleCnt;
bsalomon@google.come269f212011-11-07 13:29:52 +0000392 glTexDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle);
bsalomon@google.com72830222013-01-23 20:25:22 +0000393 glTexDesc.fIsWrapped = true;
senorblanco@chromium.orgd0925242013-06-10 15:06:09 +0000394 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag);
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000395 // FIXME: this should be calling resolve_origin(), but Chrome code is currently
396 // assuming the old behaviour, which is that backend textures are always
397 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to:
398 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
399 if (kDefault_GrSurfaceOrigin == desc.fOrigin) {
400 glTexDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
401 } else {
402 glTexDesc.fOrigin = desc.fOrigin;
403 }
bsalomon@google.come269f212011-11-07 13:29:52 +0000404
405 GrGLTexture* texture = NULL;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000406 if (renderTarget) {
bsalomon@google.come269f212011-11-07 13:29:52 +0000407 GrGLRenderTarget::Desc glRTDesc;
408 glRTDesc.fRTFBOID = 0;
409 glRTDesc.fTexFBOID = 0;
410 glRTDesc.fMSColorRenderbufferID = 0;
bsalomon@google.come269f212011-11-07 13:29:52 +0000411 glRTDesc.fConfig = desc.fConfig;
412 glRTDesc.fSampleCnt = desc.fSampleCnt;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000413 glRTDesc.fOrigin = glTexDesc.fOrigin;
senorblanco@chromium.orgd0925242013-06-10 15:06:09 +0000414 glRTDesc.fCheckAllocation = false;
bsalomon@google.com99621082011-11-15 16:47:16 +0000415 if (!this->createRenderTargetObjects(glTexDesc.fWidth,
416 glTexDesc.fHeight,
bsalomon@google.come269f212011-11-07 13:29:52 +0000417 glTexDesc.fTextureID,
418 &glRTDesc)) {
419 return NULL;
420 }
tomhudson@google.comc377baf2012-07-09 20:17:56 +0000421 texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc));
bsalomon@google.come269f212011-11-07 13:29:52 +0000422 } else {
tomhudson@google.comc377baf2012-07-09 20:17:56 +0000423 texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc));
bsalomon@google.come269f212011-11-07 13:29:52 +0000424 }
425 if (NULL == texture) {
426 return NULL;
427 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000428
bsalomon@google.come269f212011-11-07 13:29:52 +0000429 return texture;
430}
431
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000432GrRenderTarget* GrGpuGL::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) {
bsalomon@google.come269f212011-11-07 13:29:52 +0000433 GrGLRenderTarget::Desc glDesc;
434 glDesc.fConfig = desc.fConfig;
435 glDesc.fRTFBOID = static_cast<GrGLuint>(desc.fRenderTargetHandle);
436 glDesc.fMSColorRenderbufferID = 0;
437 glDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
438 glDesc.fSampleCnt = desc.fSampleCnt;
bsalomon@google.com72830222013-01-23 20:25:22 +0000439 glDesc.fIsWrapped = true;
senorblanco@chromium.orgd0925242013-06-10 15:06:09 +0000440 glDesc.fCheckAllocation = false;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000441
442 glDesc.fOrigin = resolve_origin(desc.fOrigin, true);
bsalomon@google.come269f212011-11-07 13:29:52 +0000443 GrGLIRect viewport;
444 viewport.fLeft = 0;
445 viewport.fBottom = 0;
446 viewport.fWidth = desc.fWidth;
447 viewport.fHeight = desc.fHeight;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000448
tomhudson@google.comc377baf2012-07-09 20:17:56 +0000449 GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget,
450 (this, glDesc, viewport));
bsalomon@google.come269f212011-11-07 13:29:52 +0000451 if (desc.fStencilBits) {
452 GrGLStencilBuffer::Format format;
453 format.fInternalFormat = GrGLStencilBuffer::kUnknownInternalFormat;
454 format.fPacked = false;
455 format.fStencilBits = desc.fStencilBits;
456 format.fTotalBits = desc.fStencilBits;
bsalomon@google.com1f0f1a32013-01-23 21:32:32 +0000457 static const bool kIsSBWrapped = false;
tomhudson@google.comc377baf2012-07-09 20:17:56 +0000458 GrGLStencilBuffer* sb = SkNEW_ARGS(GrGLStencilBuffer,
459 (this,
bsalomon@google.com1f0f1a32013-01-23 21:32:32 +0000460 kIsSBWrapped,
tomhudson@google.comc377baf2012-07-09 20:17:56 +0000461 0,
462 desc.fWidth,
463 desc.fHeight,
464 desc.fSampleCnt,
465 format));
bsalomon@google.come269f212011-11-07 13:29:52 +0000466 tgt->setStencilBuffer(sb);
467 sb->unref();
468 }
469 return tgt;
470}
471
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000472////////////////////////////////////////////////////////////////////////////////
473
bsalomon@google.com9c680582013-02-06 18:17:50 +0000474bool GrGpuGL::onWriteTexturePixels(GrTexture* texture,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000475 int left, int top, int width, int height,
476 GrPixelConfig config, const void* buffer,
477 size_t rowBytes) {
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000478 if (NULL == buffer) {
bsalomon@google.com9c680582013-02-06 18:17:50 +0000479 return false;
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000480 }
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000481 GrGLTexture* glTex = static_cast<GrGLTexture*>(texture);
482
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000483 this->setScratchTextureUnit();
bsalomon@google.com6f379512011-11-16 20:36:03 +0000484 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID()));
485 GrGLTexture::Desc desc;
robertphillips@google.com32716282012-06-04 12:48:45 +0000486 desc.fFlags = glTex->desc().fFlags;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000487 desc.fWidth = glTex->width();
488 desc.fHeight = glTex->height();
robertphillips@google.com32716282012-06-04 12:48:45 +0000489 desc.fConfig = glTex->config();
490 desc.fSampleCnt = glTex->desc().fSampleCnt;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000491 desc.fTextureID = glTex->textureID();
bsalomon@google.com2d0bade2012-10-26 19:01:17 +0000492 desc.fOrigin = glTex->origin();
bsalomon@google.com9d6cfd82011-11-05 13:25:21 +0000493
krajcevski145d48c2014-06-11 16:07:50 -0700494 bool success = false;
495 if (GrPixelConfigIsCompressed(desc.fConfig)) {
496 // We check that config == desc.fConfig in GrGpuGL::canWriteTexturePixels()
497 SkASSERT(config == desc.fConfig);
498 success = this->uploadCompressedTexData(desc, buffer, false,
499 left, top, width, height);
500 } else {
501 success = this->uploadTexData(desc, false,
502 left, top, width, height,
503 config, buffer, rowBytes);
504 }
505
506 if (success) {
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +0000507 texture->impl()->dirtyMipMaps(true);
commit-bot@chromium.orgcffff792013-07-26 16:36:04 +0000508 return true;
commit-bot@chromium.orgcffff792013-07-26 16:36:04 +0000509 }
krajcevski145d48c2014-06-11 16:07:50 -0700510
511 return false;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000512}
513
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000514namespace {
515bool adjust_pixel_ops_params(int surfaceWidth,
516 int surfaceHeight,
517 size_t bpp,
518 int* left, int* top, int* width, int* height,
519 const void** data,
520 size_t* rowBytes) {
521 if (!*rowBytes) {
522 *rowBytes = *width * bpp;
523 }
524
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000525 SkIRect subRect = SkIRect::MakeXYWH(*left, *top, *width, *height);
526 SkIRect bounds = SkIRect::MakeWH(surfaceWidth, surfaceHeight);
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000527
528 if (!subRect.intersect(bounds)) {
529 return false;
530 }
531 *data = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>(*data) +
532 (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp);
533
534 *left = subRect.fLeft;
535 *top = subRect.fTop;
536 *width = subRect.width();
537 *height = subRect.height();
538 return true;
539}
senorblanco@chromium.orgd0925242013-06-10 15:06:09 +0000540
541GrGLenum check_alloc_error(const GrTextureDesc& desc, const GrGLInterface* interface) {
542 if (SkToBool(desc.fFlags & kCheckAllocation_GrTextureFlagBit)) {
543 return GR_GL_GET_ERROR(interface);
544 } else {
545 return CHECK_ALLOC_ERROR(interface);
546 }
547}
548
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000549}
550
bsalomon@google.com136f55b2011-11-28 18:34:44 +0000551bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
552 bool isNewTexture,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000553 int left, int top, int width, int height,
554 GrPixelConfig dataConfig,
555 const void* data,
556 size_t rowBytes) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000557 SkASSERT(NULL != data || isNewTexture);
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000558
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000559 // If we're uploading compressed data then we should be using uploadCompressedTexData
560 SkASSERT(!GrPixelConfigIsCompressed(dataConfig));
561
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000562 size_t bpp = GrBytesPerPixel(dataConfig);
563 if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top,
564 &width, &height, &data, &rowBytes)) {
bsalomon@google.com136f55b2011-11-28 18:34:44 +0000565 return false;
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000566 }
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000567 size_t trimRowBytes = width * bpp;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000568
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000569 // in case we need a temporary, trimmed copy of the src pixels
570 SkAutoSMalloc<128 * 128> tempStorage;
571
bsalomon@google.com313f0192012-07-10 17:21:02 +0000572 // paletted textures cannot be partially updated
commit-bot@chromium.orgcea9abb2013-12-09 19:15:37 +0000573 // We currently lazily create MIPMAPs when the we see a draw with
574 // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that the
575 // MIP levels are all created when the texture is created. So for now we don't use
576 // texture storage.
577 bool useTexStorage = false &&
578 isNewTexture &&
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000579 kIndex_8_GrPixelConfig != desc.fConfig &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000580 this->glCaps().texStorageSupport();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000581
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000582 if (useTexStorage && kGL_GrGLStandard == this->glStandard()) {
bsalomon@google.com313f0192012-07-10 17:21:02 +0000583 // 565 is not a sized internal format on desktop GL. So on desktop with
584 // 565 we always use an unsized internal format to let the system pick
585 // the best sized format to convert the 565 data to. Since TexStorage
586 // only allows sized internal formats we will instead use TexImage2D.
587 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig;
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000588 }
589
590 GrGLenum internalFormat;
bsalomone904c092014-07-17 10:50:59 -0700591 GrGLenum externalFormat = 0x0; // suprress warning
592 GrGLenum externalType = 0x0;// suprress warning
593
commit-bot@chromium.org87002952013-08-20 15:12:01 +0000594 // glTexStorage requires sized internal formats on both desktop and ES. ES2 requires an unsized
595 // format for glTexImage, unlike ES3 and desktop. However, we allow the driver to decide the
596 // size of the internal format whenever possible and so only use a sized internal format when
597 // using texture storage.
bsalomone904c092014-07-17 10:50:59 -0700598 bool useSizedFormat = useTexStorage;
599 // At least some versions of the desktop ES3 drivers for NVIDIA won't accept GL_RED in
600 // glTexImage2D for the internal format but will accept GL_R8.
601 if (!useSizedFormat && kNVIDIA_GrGLVendor == this->glContext().vendor() &&
602 kGLES_GrGLStandard == this->glStandard() && this->glVersion() >= GR_GL_VER(3, 0)) {
603 useSizedFormat = true;
604 }
605 if (!this->configToGLFormats(dataConfig, useSizedFormat, &internalFormat,
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000606 &externalFormat, &externalType)) {
bsalomon@google.com136f55b2011-11-28 18:34:44 +0000607 return false;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000608 }
609
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000610 if (!isNewTexture && GR_GL_PALETTE8_RGBA8 == internalFormat) {
bsalomon@google.com32e4d2a2011-12-09 16:14:25 +0000611 // paletted textures cannot be updated
612 return false;
613 }
614
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000615 /*
bsalomon@google.com6f379512011-11-16 20:36:03 +0000616 * check whether to allocate a temporary buffer for flipping y or
617 * because our srcData has extra bytes past each row. If so, we need
618 * to trim those off here, since GL ES may not let us specify
619 * GL_UNPACK_ROW_LENGTH.
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000620 */
bsalomon@google.com6f379512011-11-16 20:36:03 +0000621 bool restoreGLRowLength = false;
bsalomon@google.com8ef3fd02011-11-21 15:53:13 +0000622 bool swFlipY = false;
623 bool glFlipY = false;
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000624 if (NULL != data) {
senorblanco@chromium.orgef5dbe12013-01-28 16:42:38 +0000625 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000626 if (this->glCaps().unpackFlipYSupport()) {
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000627 glFlipY = true;
628 } else {
629 swFlipY = true;
630 }
631 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000632 if (this->glCaps().unpackRowLengthSupport() && !swFlipY) {
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000633 // can't use this for flipping, only non-neg values allowed. :(
634 if (rowBytes != trimRowBytes) {
635 GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp);
636 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowLength));
637 restoreGLRowLength = true;
638 }
bsalomon@google.com8ef3fd02011-11-21 15:53:13 +0000639 } else {
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000640 if (trimRowBytes != rowBytes || swFlipY) {
641 // copy data into our new storage, skipping the trailing bytes
642 size_t trimSize = height * trimRowBytes;
643 const char* src = (const char*)data;
bsalomon@google.com8ef3fd02011-11-21 15:53:13 +0000644 if (swFlipY) {
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000645 src += (height - 1) * rowBytes;
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000646 }
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000647 char* dst = (char*)tempStorage.reset(trimSize);
648 for (int y = 0; y < height; y++) {
649 memcpy(dst, src, trimRowBytes);
650 if (swFlipY) {
651 src -= rowBytes;
652 } else {
653 src += rowBytes;
654 }
655 dst += trimRowBytes;
656 }
657 // now point data to our copied version
658 data = tempStorage.get();
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000659 }
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000660 }
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000661 if (glFlipY) {
662 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE));
663 }
joshualittee5da552014-07-16 13:32:56 -0700664 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT,
665 static_cast<GrGLint>(GrUnpackAlignment(dataConfig))));
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000666 }
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000667 bool succeeded = true;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000668 if (isNewTexture &&
bsalomon@google.com136f55b2011-11-28 18:34:44 +0000669 0 == left && 0 == top &&
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000670 desc.fWidth == width && desc.fHeight == height) {
bsalomon@google.com4f3c2532012-01-19 16:16:52 +0000671 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000672 if (useTexStorage) {
commit-bot@chromium.orgcea9abb2013-12-09 19:15:37 +0000673 // We never resize or change formats of textures.
bsalomon@google.com4f3c2532012-01-19 16:16:52 +0000674 GL_ALLOC_CALL(this->glInterface(),
675 TexStorage2D(GR_GL_TEXTURE_2D,
676 1, // levels
677 internalFormat,
678 desc.fWidth, desc.fHeight));
bsalomon@google.com32e4d2a2011-12-09 16:14:25 +0000679 } else {
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000680 if (GR_GL_PALETTE8_RGBA8 == internalFormat) {
681 GrGLsizei imageSize = desc.fWidth * desc.fHeight +
682 kGrColorTableSize;
bsalomon@google.com4f3c2532012-01-19 16:16:52 +0000683 GL_ALLOC_CALL(this->glInterface(),
684 CompressedTexImage2D(GR_GL_TEXTURE_2D,
685 0, // level
686 internalFormat,
687 desc.fWidth, desc.fHeight,
688 0, // border
689 imageSize,
690 data));
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000691 } else {
bsalomon@google.com4f3c2532012-01-19 16:16:52 +0000692 GL_ALLOC_CALL(this->glInterface(),
693 TexImage2D(GR_GL_TEXTURE_2D,
694 0, // level
695 internalFormat,
696 desc.fWidth, desc.fHeight,
697 0, // border
698 externalFormat, externalType,
699 data));
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000700 }
bsalomon@google.com32e4d2a2011-12-09 16:14:25 +0000701 }
senorblanco@chromium.orgd0925242013-06-10 15:06:09 +0000702 GrGLenum error = check_alloc_error(desc, this->glInterface());
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000703 if (error != GR_GL_NO_ERROR) {
704 succeeded = false;
705 } else {
706 // if we have data and we used TexStorage to create the texture, we
707 // now upload with TexSubImage.
708 if (NULL != data && useTexStorage) {
709 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D,
710 0, // level
711 left, top,
712 width, height,
713 externalFormat, externalType,
714 data));
715 }
bsalomon@google.com136f55b2011-11-28 18:34:44 +0000716 }
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000717 } else {
bsalomon@google.com8ef3fd02011-11-21 15:53:13 +0000718 if (swFlipY || glFlipY) {
bsalomon@google.com6f379512011-11-16 20:36:03 +0000719 top = desc.fHeight - (top + height);
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000720 }
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000721 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D,
722 0, // level
723 left, top,
724 width, height,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000725 externalFormat, externalType, data));
726 }
727
728 if (restoreGLRowLength) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000729 SkASSERT(this->glCaps().unpackRowLengthSupport());
bsalomon@google.com6f379512011-11-16 20:36:03 +0000730 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000731 }
bsalomon@google.com8ef3fd02011-11-21 15:53:13 +0000732 if (glFlipY) {
733 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE));
734 }
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +0000735 return succeeded;
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000736}
737
krajcevski145d48c2014-06-11 16:07:50 -0700738// TODO: This function is using a lot of wonky semantics like, if width == -1
bungemanc7af8122014-07-16 09:10:41 -0700739// then set width = desc.fWdith ... blah. A better way to do it might be to
krajcevski145d48c2014-06-11 16:07:50 -0700740// create a CompressedTexData struct that takes a desc/ptr and figures out
741// the proper upload semantics. Then users can construct this function how they
742// see fit if they want to go against the "standard" way to do it.
krajcevski9c0e6292014-06-02 07:38:14 -0700743bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc,
krajcevski145d48c2014-06-11 16:07:50 -0700744 const void* data,
745 bool isNewTexture,
746 int left, int top, int width, int height) {
747 SkASSERT(NULL != data || isNewTexture);
krajcevski9c0e6292014-06-02 07:38:14 -0700748
749 // No support for software flip y, yet...
750 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin);
751
krajcevski145d48c2014-06-11 16:07:50 -0700752 if (-1 == width) {
753 width = desc.fWidth;
754 }
755#ifdef SK_DEBUG
756 else {
757 SkASSERT(width <= desc.fWidth);
758 }
759#endif
760
761 if (-1 == height) {
762 height = desc.fHeight;
763 }
764#ifdef SK_DEBUG
765 else {
766 SkASSERT(height <= desc.fHeight);
767 }
768#endif
769
krajcevski9c0e6292014-06-02 07:38:14 -0700770 // Make sure that the width and height that we pass to OpenGL
771 // is a multiple of the block size.
krajcevski145d48c2014-06-11 16:07:50 -0700772 int dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height);
krajcevski9c0e6292014-06-02 07:38:14 -0700773
774 // We only need the internal format for compressed 2D textures.
775 GrGLenum internalFormat = 0;
776 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NULL)) {
777 return false;
778 }
779
780 bool succeeded = true;
781 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
krajcevski145d48c2014-06-11 16:07:50 -0700782
783 if (isNewTexture) {
784 GL_ALLOC_CALL(this->glInterface(),
785 CompressedTexImage2D(GR_GL_TEXTURE_2D,
786 0, // level
787 internalFormat,
788 width, height,
789 0, // border
790 dataSize,
791 data));
792 } else {
793 GL_ALLOC_CALL(this->glInterface(),
794 CompressedTexSubImage2D(GR_GL_TEXTURE_2D,
795 0, // level
796 left, top,
797 width, height,
798 internalFormat,
799 dataSize,
800 data));
801 }
krajcevski9c0e6292014-06-02 07:38:14 -0700802
803 GrGLenum error = check_alloc_error(desc, this->glInterface());
804 if (error != GR_GL_NO_ERROR) {
805 succeeded = false;
806 }
807 return succeeded;
808}
809
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000810static bool renderbuffer_storage_msaa(GrGLContext& ctx,
811 int sampleCount,
812 GrGLenum format,
813 int width, int height) {
robertphillips@google.com6177e692013-02-28 20:16:25 +0000814 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface());
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000815 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType());
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000816 switch (ctx.caps()->msFBOType()) {
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000817 case GrGLCaps::kDesktop_ARB_MSFBOType:
818 case GrGLCaps::kDesktop_EXT_MSFBOType:
819 case GrGLCaps::kES_3_0_MSFBOType:
820 GL_ALLOC_CALL(ctx.interface(),
821 RenderbufferStorageMultisample(GR_GL_RENDERBUFFER,
822 sampleCount,
823 format,
824 width, height));
825 break;
826 case GrGLCaps::kES_Apple_MSFBOType:
827 GL_ALLOC_CALL(ctx.interface(),
828 RenderbufferStorageMultisampleES2APPLE(GR_GL_RENDERBUFFER,
829 sampleCount,
830 format,
831 width, height));
832 break;
833 case GrGLCaps::kES_EXT_MsToTexture_MSFBOType:
834 case GrGLCaps::kES_IMG_MsToTexture_MSFBOType:
835 GL_ALLOC_CALL(ctx.interface(),
836 RenderbufferStorageMultisampleES2EXT(GR_GL_RENDERBUFFER,
837 sampleCount,
838 format,
839 width, height));
840 break;
841 case GrGLCaps::kNone_MSFBOType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000842 SkFAIL("Shouldn't be here if we don't support multisampled renderbuffers.");
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000843 break;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000844 }
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000845 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000846}
847
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000848bool GrGpuGL::createRenderTargetObjects(int width, int height,
849 GrGLuint texID,
850 GrGLRenderTarget::Desc* desc) {
851 desc->fMSColorRenderbufferID = 0;
852 desc->fRTFBOID = 0;
853 desc->fTexFBOID = 0;
bsalomon@google.com72830222013-01-23 20:25:22 +0000854 desc->fIsWrapped = false;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000855
856 GrGLenum status;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000857
bsalomon@google.comab15d612011-08-09 12:57:56 +0000858 GrGLenum msColorFormat = 0; // suppress warning
859
bsalomon@google.com347c3822013-05-01 20:10:01 +0000860 if (desc->fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType()) {
861 goto FAILED;
862 }
863
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000864 GL_CALL(GenFramebuffers(1, &desc->fTexFBOID));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000865 if (!desc->fTexFBOID) {
866 goto FAILED;
867 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000868
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000869
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000870 // If we are using multisampling we will create two FBOS. We render to one and then resolve to
871 // the texture bound to the other. The exception is the IMG multisample extension. With this
872 // extension the texture is multisampled when rendered to and then auto-resolves it when it is
873 // rendered from.
bsalomon@google.com347c3822013-05-01 20:10:01 +0000874 if (desc->fSampleCnt > 0 && this->glCaps().usesMSAARenderBuffers()) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000875 GL_CALL(GenFramebuffers(1, &desc->fRTFBOID));
876 GL_CALL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000877 if (!desc->fRTFBOID ||
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000878 !desc->fMSColorRenderbufferID ||
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000879 !this->configToGLFormats(desc->fConfig,
commit-bot@chromium.org87002952013-08-20 15:12:01 +0000880 // ES2 and ES3 require sized internal formats for rb storage.
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000881 kGLES_GrGLStandard == this->glStandard(),
bsalomon@google.com347c3822013-05-01 20:10:01 +0000882 &msColorFormat,
883 NULL,
884 NULL)) {
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000885 goto FAILED;
886 }
887 } else {
888 desc->fRTFBOID = desc->fTexFBOID;
889 }
890
bsalomon@google.com0e9b41a2012-01-04 22:11:43 +0000891 // below here we may bind the FBO
bsalomon1c63bf62014-07-22 13:09:46 -0700892 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000893 if (desc->fRTFBOID != desc->fTexFBOID) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000894 SkASSERT(desc->fSampleCnt > 0);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000895 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER,
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000896 desc->fMSColorRenderbufferID));
robertphillips@google.com6177e692013-02-28 20:16:25 +0000897 if (!renderbuffer_storage_msaa(fGLContext,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000898 desc->fSampleCnt,
899 msColorFormat,
900 width, height)) {
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000901 goto FAILED;
902 }
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000903 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID));
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000904 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000905 GR_GL_COLOR_ATTACHMENT0,
906 GR_GL_RENDERBUFFER,
907 desc->fMSColorRenderbufferID));
senorblanco@chromium.orgd0925242013-06-10 15:06:09 +0000908 if (desc->fCheckAllocation ||
909 !this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) {
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000910 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
911 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
912 goto FAILED;
913 }
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000914 fGLContext.caps()->markConfigAsValidColorAttachment(desc->fConfig);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000915 }
916 }
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000917 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000918
bsalomon@google.com347c3822013-05-01 20:10:01 +0000919 if (this->glCaps().usesImplicitMSAAResolve() && desc->fSampleCnt > 0) {
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000920 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER,
921 GR_GL_COLOR_ATTACHMENT0,
922 GR_GL_TEXTURE_2D,
923 texID, 0, desc->fSampleCnt));
924 } else {
925 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER,
926 GR_GL_COLOR_ATTACHMENT0,
927 GR_GL_TEXTURE_2D,
928 texID, 0));
929 }
senorblanco@chromium.orgd0925242013-06-10 15:06:09 +0000930 if (desc->fCheckAllocation ||
931 !this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) {
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +0000932 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
933 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
934 goto FAILED;
935 }
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000936 fGLContext.caps()->markConfigAsValidColorAttachment(desc->fConfig);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000937 }
938
939 return true;
940
941FAILED:
942 if (desc->fMSColorRenderbufferID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000943 GL_CALL(DeleteRenderbuffers(1, &desc->fMSColorRenderbufferID));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000944 }
945 if (desc->fRTFBOID != desc->fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000946 GL_CALL(DeleteFramebuffers(1, &desc->fRTFBOID));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000947 }
948 if (desc->fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000949 GL_CALL(DeleteFramebuffers(1, &desc->fTexFBOID));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000950 }
951 return false;
952}
953
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000954// good to set a break-point here to know when createTexture fails
955static GrTexture* return_null_texture() {
mtklein@google.com330313a2013-08-22 15:37:26 +0000956// SkDEBUGFAIL("null texture");
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000957 return NULL;
958}
959
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000960#if 0 && defined(SK_DEBUG)
bsalomon@google.com3f3ffd62011-01-18 17:14:52 +0000961static size_t as_size_t(int x) {
962 return x;
963}
964#endif
965
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000966GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc,
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000967 const void* srcData,
968 size_t rowBytes) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000969
bsalomon@google.com5bfc2172011-07-29 20:29:05 +0000970 GrGLTexture::Desc glTexDesc;
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000971 GrGLRenderTarget::Desc glRTDesc;
reed@google.comac10a2d2010-12-22 21:39:39 +0000972
bsalomon@google.com78d6cf92012-01-30 18:09:31 +0000973 // Attempt to catch un- or wrongly initialized sample counts;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000974 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000975 // We fail if the MSAA was requested and is not available.
976 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleCnt) {
977 //GrPrintf("MSAA RT requested but not supported on this platform.");
978 return return_null_texture();
979 }
980 // If the sample count exceeds the max then we clamp it.
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000981 glTexDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
bsalomon@google.com78d6cf92012-01-30 18:09:31 +0000982
robertphillips@google.com32716282012-06-04 12:48:45 +0000983 glTexDesc.fFlags = desc.fFlags;
bsalomon@google.com99621082011-11-15 16:47:16 +0000984 glTexDesc.fWidth = desc.fWidth;
985 glTexDesc.fHeight = desc.fHeight;
bsalomon@google.com78d6cf92012-01-30 18:09:31 +0000986 glTexDesc.fConfig = desc.fConfig;
bsalomon@google.com72830222013-01-23 20:25:22 +0000987 glTexDesc.fIsWrapped = false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000988
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000989 glRTDesc.fMSColorRenderbufferID = 0;
990 glRTDesc.fRTFBOID = 0;
991 glRTDesc.fTexFBOID = 0;
bsalomon@google.com72830222013-01-23 20:25:22 +0000992 glRTDesc.fIsWrapped = false;
bsalomon@google.com64c4fe42011-11-05 14:51:01 +0000993 glRTDesc.fConfig = glTexDesc.fConfig;
senorblanco@chromium.orgd0925242013-06-10 15:06:09 +0000994 glRTDesc.fCheckAllocation = SkToBool(desc.fFlags & kCheckAllocation_GrTextureFlagBit);
bsalomon@google.com71f341a2011-08-01 13:36:00 +0000995
senorblanco@chromium.orgd0925242013-06-10 15:06:09 +0000996 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrTextureFlagBit);
reed@google.comac10a2d2010-12-22 21:39:39 +0000997
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000998 glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
999 glRTDesc.fOrigin = glTexDesc.fOrigin;
bsalomon@google.comd9f826c2011-07-18 15:25:04 +00001000
bsalomon@google.com8a70eef2013-03-19 13:58:55 +00001001 glRTDesc.fSampleCnt = glTexDesc.fSampleCnt;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001002 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() &&
bsalomon@google.com78d6cf92012-01-30 18:09:31 +00001003 desc.fSampleCnt) {
bsalomon@google.com945bbe12012-06-15 14:30:34 +00001004 //GrPrintf("MSAA RT requested but not supported on this platform.");
1005 return return_null_texture();
reed@google.comac10a2d2010-12-22 21:39:39 +00001006 }
1007
reed@google.comac10a2d2010-12-22 21:39:39 +00001008 if (renderTarget) {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001009 int maxRTSize = this->caps()->maxRenderTargetSize();
1010 if (glTexDesc.fWidth > maxRTSize || glTexDesc.fHeight > maxRTSize) {
bsalomon@google.com91958362011-06-13 17:58:13 +00001011 return return_null_texture();
1012 }
sugoi@google.com6ba0b0f2013-05-03 13:52:32 +00001013 } else {
1014 int maxSize = this->caps()->maxTextureSize();
1015 if (glTexDesc.fWidth > maxSize || glTexDesc.fHeight > maxSize) {
1016 return return_null_texture();
1017 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001018 }
1019
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001020 GL_CALL(GenTextures(1, &glTexDesc.fTextureID));
junov@chromium.org8b6b1c92013-08-29 16:22:09 +00001021
bsalomon@google.com5bfc2172011-07-29 20:29:05 +00001022 if (!glTexDesc.fTextureID) {
bsalomon@google.comd9f826c2011-07-18 15:25:04 +00001023 return return_null_texture();
1024 }
1025
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +00001026 this->setScratchTextureUnit();
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001027 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID));
bsalomon@google.come269f212011-11-07 13:29:52 +00001028
junov@chromium.org8b6b1c92013-08-29 16:22:09 +00001029 if (renderTarget && this->glCaps().textureUsageSupport()) {
1030 // provides a hint about how this texture will be used
1031 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
1032 GR_GL_TEXTURE_USAGE,
1033 GR_GL_FRAMEBUFFER_ATTACHMENT));
1034 }
1035
bsalomon@google.com0a97be22011-11-08 19:20:57 +00001036 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some
1037 // drivers have a bug where an FBO won't be complete if it includes a
1038 // texture that is not mipmap complete (considering the filter in use).
1039 GrGLTexture::TexParams initialTexParams;
1040 // we only set a subset here so invalidate first
1041 initialTexParams.invalidate();
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +00001042 initialTexParams.fMinFilter = GR_GL_NEAREST;
1043 initialTexParams.fMagFilter = GR_GL_NEAREST;
bsalomon@google.com0a97be22011-11-08 19:20:57 +00001044 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE;
1045 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE;
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001046 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
1047 GR_GL_TEXTURE_MAG_FILTER,
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +00001048 initialTexParams.fMagFilter));
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001049 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
1050 GR_GL_TEXTURE_MIN_FILTER,
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +00001051 initialTexParams.fMinFilter));
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001052 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
1053 GR_GL_TEXTURE_WRAP_S,
bsalomon@google.com0a97be22011-11-08 19:20:57 +00001054 initialTexParams.fWrapS));
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001055 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
1056 GR_GL_TEXTURE_WRAP_T,
bsalomon@google.com0a97be22011-11-08 19:20:57 +00001057 initialTexParams.fWrapT));
bsalomon@google.comb1d14fd2011-12-09 18:41:34 +00001058 if (!this->uploadTexData(glTexDesc, true, 0, 0,
1059 glTexDesc.fWidth, glTexDesc.fHeight,
1060 desc.fConfig, srcData, rowBytes)) {
1061 GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID));
1062 return return_null_texture();
bsalomon@google.com6f379512011-11-16 20:36:03 +00001063 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001064
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001065 GrGLTexture* tex;
reed@google.comac10a2d2010-12-22 21:39:39 +00001066 if (renderTarget) {
robertphillips@google.comba0cc3e2012-03-26 17:58:35 +00001067 // unbind the texture from the texture unit before binding it to the frame buffer
1068 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0));
1069
bsalomon@google.com99621082011-11-15 16:47:16 +00001070 if (!this->createRenderTargetObjects(glTexDesc.fWidth,
1071 glTexDesc.fHeight,
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001072 glTexDesc.fTextureID,
1073 &glRTDesc)) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001074 GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID));
reed@google.comac10a2d2010-12-22 21:39:39 +00001075 return return_null_texture();
1076 }
tomhudson@google.comc377baf2012-07-09 20:17:56 +00001077 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001078 } else {
tomhudson@google.comc377baf2012-07-09 20:17:56 +00001079 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc));
reed@google.comac10a2d2010-12-22 21:39:39 +00001080 }
bsalomon@google.com0a97be22011-11-08 19:20:57 +00001081 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
reed@google.comac10a2d2010-12-22 21:39:39 +00001082#ifdef TRACE_TEXTURE_CREATION
bsalomon@google.com64c4fe42011-11-05 14:51:01 +00001083 GrPrintf("--- new texture [%d] size=(%d %d) config=%d\n",
1084 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig);
reed@google.comac10a2d2010-12-22 21:39:39 +00001085#endif
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001086 return tex;
1087}
1088
krajcevski9c0e6292014-06-02 07:38:14 -07001089GrTexture* GrGpuGL::onCreateCompressedTexture(const GrTextureDesc& desc,
1090 const void* srcData) {
1091
1092 if(SkToBool(desc.fFlags & kRenderTarget_GrTextureFlagBit)) {
1093 return return_null_texture();
1094 }
1095
1096 // Make sure that we're not flipping Y.
1097 GrSurfaceOrigin texOrigin = resolve_origin(desc.fOrigin, false);
1098 if (kBottomLeft_GrSurfaceOrigin == texOrigin) {
1099 return return_null_texture();
1100 }
1101
1102 GrGLTexture::Desc glTexDesc;
1103
1104 glTexDesc.fFlags = desc.fFlags;
1105 glTexDesc.fWidth = desc.fWidth;
1106 glTexDesc.fHeight = desc.fHeight;
1107 glTexDesc.fConfig = desc.fConfig;
1108 glTexDesc.fIsWrapped = false;
1109 glTexDesc.fOrigin = texOrigin;
1110
1111 int maxSize = this->caps()->maxTextureSize();
1112 if (glTexDesc.fWidth > maxSize || glTexDesc.fHeight > maxSize) {
1113 return return_null_texture();
1114 }
1115
1116 GL_CALL(GenTextures(1, &glTexDesc.fTextureID));
1117
1118 if (!glTexDesc.fTextureID) {
1119 return return_null_texture();
1120 }
1121
1122 this->setScratchTextureUnit();
1123 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID));
1124
1125 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some
1126 // drivers have a bug where an FBO won't be complete if it includes a
1127 // texture that is not mipmap complete (considering the filter in use).
1128 GrGLTexture::TexParams initialTexParams;
1129 // we only set a subset here so invalidate first
1130 initialTexParams.invalidate();
1131 initialTexParams.fMinFilter = GR_GL_NEAREST;
1132 initialTexParams.fMagFilter = GR_GL_NEAREST;
1133 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE;
1134 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE;
1135 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
1136 GR_GL_TEXTURE_MAG_FILTER,
1137 initialTexParams.fMagFilter));
1138 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
1139 GR_GL_TEXTURE_MIN_FILTER,
1140 initialTexParams.fMinFilter));
1141 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
1142 GR_GL_TEXTURE_WRAP_S,
1143 initialTexParams.fWrapS));
1144 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
1145 GR_GL_TEXTURE_WRAP_T,
1146 initialTexParams.fWrapT));
1147
1148 if (!this->uploadCompressedTexData(glTexDesc, srcData)) {
1149 GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID));
1150 return return_null_texture();
1151 }
1152
1153 GrGLTexture* tex;
1154 tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc));
1155 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
1156#ifdef TRACE_TEXTURE_CREATION
1157 GrPrintf("--- new compressed texture [%d] size=(%d %d) config=%d\n",
1158 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig);
1159#endif
1160 return tex;
1161}
1162
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001163namespace {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001164
1165const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
1166
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001167void inline get_stencil_rb_sizes(const GrGLInterface* gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001168 GrGLStencilBuffer::Format* format) {
sugoi@google.com6ba0b0f2013-05-03 13:52:32 +00001169
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001170 // we shouldn't ever know one size and not the other
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001171 SkASSERT((kUnknownBitCount == format->fStencilBits) ==
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001172 (kUnknownBitCount == format->fTotalBits));
1173 if (kUnknownBitCount == format->fStencilBits) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001174 GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER,
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001175 GR_GL_RENDERBUFFER_STENCIL_SIZE,
1176 (GrGLint*)&format->fStencilBits);
1177 if (format->fPacked) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001178 GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER,
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001179 GR_GL_RENDERBUFFER_DEPTH_SIZE,
1180 (GrGLint*)&format->fTotalBits);
1181 format->fTotalBits += format->fStencilBits;
1182 } else {
1183 format->fTotalBits = format->fStencilBits;
1184 }
1185 }
1186}
1187}
1188
1189bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt,
1190 int width, int height) {
1191
1192 // All internally created RTs are also textures. We don't create
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +00001193 // SBs for a client's standalone RT (that is a RT that isn't also a texture).
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001194 SkASSERT(rt->asTexture());
1195 SkASSERT(width >= rt->width());
1196 SkASSERT(height >= rt->height());
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001197
1198 int samples = rt->numSamples();
1199 GrGLuint sbID;
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001200 GL_CALL(GenRenderbuffers(1, &sbID));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001201 if (!sbID) {
1202 return false;
1203 }
1204
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001205 int stencilFmtCnt = this->glCaps().stencilFormats().count();
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001206 for (int i = 0; i < stencilFmtCnt; ++i) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001207 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001208 // we start with the last stencil format that succeeded in hopes
1209 // that we won't go through this loop more than once after the
1210 // first (painful) stencil creation.
1211 int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001212 const GrGLCaps::StencilFormat& sFmt =
1213 this->glCaps().stencilFormats()[sIdx];
bsalomon@google.com4f3c2532012-01-19 16:16:52 +00001214 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
bsalomon@google.com558a75b2011-08-08 17:01:14 +00001215 // we do this "if" so that we don't call the multisample
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001216 // version on a GL that doesn't have an MSAA extension.
bsalomon@google.comc9668ec2012-04-11 18:16:41 +00001217 bool created;
1218 if (samples > 0) {
robertphillips@google.com6177e692013-02-28 20:16:25 +00001219 created = renderbuffer_storage_msaa(fGLContext,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +00001220 samples,
1221 sFmt.fInternalFormat,
1222 width, height);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001223 } else {
bsalomon@google.com4f3c2532012-01-19 16:16:52 +00001224 GL_ALLOC_CALL(this->glInterface(),
1225 RenderbufferStorage(GR_GL_RENDERBUFFER,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001226 sFmt.fInternalFormat,
bsalomon@google.com4f3c2532012-01-19 16:16:52 +00001227 width, height));
bsalomon@google.comc9668ec2012-04-11 18:16:41 +00001228 created =
senorblanco@chromium.orgd0925242013-06-10 15:06:09 +00001229 (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glInterface()));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001230 }
bsalomon@google.comc9668ec2012-04-11 18:16:41 +00001231 if (created) {
1232 // After sized formats we attempt an unsized format and take
1233 // whatever sizes GL gives us. In that case we query for the size.
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001234 GrGLStencilBuffer::Format format = sFmt;
sugoi@google.com6ba0b0f2013-05-03 13:52:32 +00001235 get_stencil_rb_sizes(this->glInterface(), &format);
bsalomon@google.com72830222013-01-23 20:25:22 +00001236 static const bool kIsWrapped = false;
robertphillips@google.comf2e93fc2012-09-05 19:44:18 +00001237 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer,
bsalomon@google.com72830222013-01-23 20:25:22 +00001238 (this, kIsWrapped, sbID, width, height,
robertphillips@google.comf2e93fc2012-09-05 19:44:18 +00001239 samples, format)));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001240 if (this->attachStencilBufferToRenderTarget(sb, rt)) {
1241 fLastSuccessfulStencilFmtIdx = sIdx;
robertphillips@google.com9fbcad02012-09-09 14:44:15 +00001242 sb->transferToCache();
bsalomon@google.com558a75b2011-08-08 17:01:14 +00001243 rt->setStencilBuffer(sb);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001244 return true;
1245 }
1246 sb->abandon(); // otherwise we lose sbID
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001247 }
1248 }
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001249 GL_CALL(DeleteRenderbuffers(1, &sbID));
bsalomon@google.com558a75b2011-08-08 17:01:14 +00001250 return false;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001251}
1252
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00001253bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTarget* rt) {
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001254 GrGLRenderTarget* glrt = (GrGLRenderTarget*) rt;
1255
1256 GrGLuint fbo = glrt->renderFBOID();
1257
1258 if (NULL == sb) {
1259 if (NULL != rt->getStencilBuffer()) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001260 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00001261 GR_GL_STENCIL_ATTACHMENT,
1262 GR_GL_RENDERBUFFER, 0));
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001263 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00001264 GR_GL_DEPTH_ATTACHMENT,
1265 GR_GL_RENDERBUFFER, 0));
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +00001266#ifdef SK_DEBUG
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001267 GrGLenum status;
1268 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001269 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001270#endif
1271 }
1272 return true;
1273 } else {
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00001274 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001275 GrGLuint rb = glsb->renderbufferID();
1276
bsalomon1c63bf62014-07-22 13:09:46 -07001277 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001278 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
1279 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00001280 GR_GL_STENCIL_ATTACHMENT,
1281 GR_GL_RENDERBUFFER, rb));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001282 if (glsb->format().fPacked) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001283 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00001284 GR_GL_DEPTH_ATTACHMENT,
1285 GR_GL_RENDERBUFFER, rb));
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001286 } else {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001287 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00001288 GR_GL_DEPTH_ATTACHMENT,
1289 GR_GL_RENDERBUFFER, 0));
reed@google.comac10a2d2010-12-22 21:39:39 +00001290 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001291
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001292 GrGLenum status;
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00001293 if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(), glsb->format())) {
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +00001294 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1295 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001296 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +00001297 GR_GL_STENCIL_ATTACHMENT,
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001298 GR_GL_RENDERBUFFER, 0));
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +00001299 if (glsb->format().fPacked) {
1300 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1301 GR_GL_DEPTH_ATTACHMENT,
1302 GR_GL_RENDERBUFFER, 0));
1303 }
1304 return false;
1305 } else {
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +00001306 fGLContext.caps()->markColorConfigAndStencilFormatAsVerified(
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +00001307 rt->config(),
1308 glsb->format());
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001309 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001310 }
bsalomon@google.com4bcb0c62012-02-07 16:06:47 +00001311 return true;
reed@google.comac10a2d2010-12-22 21:39:39 +00001312 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001313}
1314
bsalomon@google.com71f341a2011-08-01 13:36:00 +00001315////////////////////////////////////////////////////////////////////////////////
1316
robertphillips@google.comadacc702013-10-14 21:53:24 +00001317GrVertexBuffer* GrGpuGL::onCreateVertexBuffer(size_t size, bool dynamic) {
bsalomon@google.come49ad452013-02-20 19:33:20 +00001318 GrGLVertexBuffer::Desc desc;
1319 desc.fDynamic = dynamic;
1320 desc.fSizeInBytes = size;
1321 desc.fIsWrapped = false;
1322
bsalomon@google.com96966a52013-02-21 16:34:21 +00001323 if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) {
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +00001324 desc.fID = 0;
bsalomon@google.come49ad452013-02-20 19:33:20 +00001325 GrGLVertexBuffer* vertexBuffer = SkNEW_ARGS(GrGLVertexBuffer, (this, desc));
reed@google.comac10a2d2010-12-22 21:39:39 +00001326 return vertexBuffer;
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +00001327 } else {
1328 GL_CALL(GenBuffers(1, &desc.fID));
1329 if (desc.fID) {
bsalomon@google.com6918d482013-03-07 19:09:11 +00001330 fHWGeometryState.setVertexBufferID(this, desc.fID);
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +00001331 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
1332 // make sure driver can allocate memory for this buffer
1333 GL_ALLOC_CALL(this->glInterface(),
1334 BufferData(GR_GL_ARRAY_BUFFER,
robertphillips@google.come9cd27d2013-10-16 17:48:11 +00001335 (GrGLsizeiptr) desc.fSizeInBytes,
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +00001336 NULL, // data ptr
1337 desc.fDynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
1338 if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) {
1339 GL_CALL(DeleteBuffers(1, &desc.fID));
bsalomon@google.com6918d482013-03-07 19:09:11 +00001340 this->notifyVertexBufferDelete(desc.fID);
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +00001341 return NULL;
1342 }
1343 GrGLVertexBuffer* vertexBuffer = SkNEW_ARGS(GrGLVertexBuffer, (this, desc));
1344 return vertexBuffer;
1345 }
1346 return NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +00001347 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001348}
1349
robertphillips@google.comadacc702013-10-14 21:53:24 +00001350GrIndexBuffer* GrGpuGL::onCreateIndexBuffer(size_t size, bool dynamic) {
bsalomon@google.come49ad452013-02-20 19:33:20 +00001351 GrGLIndexBuffer::Desc desc;
1352 desc.fDynamic = dynamic;
1353 desc.fSizeInBytes = size;
1354 desc.fIsWrapped = false;
1355
bsalomon@google.com96966a52013-02-21 16:34:21 +00001356 if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) {
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +00001357 desc.fID = 0;
bsalomon@google.come49ad452013-02-20 19:33:20 +00001358 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc));
reed@google.comac10a2d2010-12-22 21:39:39 +00001359 return indexBuffer;
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +00001360 } else {
1361 GL_CALL(GenBuffers(1, &desc.fID));
1362 if (desc.fID) {
bsalomon@google.com6918d482013-03-07 19:09:11 +00001363 fHWGeometryState.setIndexBufferIDOnDefaultVertexArray(this, desc.fID);
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +00001364 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
1365 // make sure driver can allocate memory for this buffer
1366 GL_ALLOC_CALL(this->glInterface(),
1367 BufferData(GR_GL_ELEMENT_ARRAY_BUFFER,
robertphillips@google.come9cd27d2013-10-16 17:48:11 +00001368 (GrGLsizeiptr) desc.fSizeInBytes,
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +00001369 NULL, // data ptr
1370 desc.fDynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
1371 if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) {
1372 GL_CALL(DeleteBuffers(1, &desc.fID));
bsalomon@google.com6918d482013-03-07 19:09:11 +00001373 this->notifyIndexBufferDelete(desc.fID);
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +00001374 return NULL;
1375 }
1376 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc));
1377 return indexBuffer;
1378 }
1379 return NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +00001380 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001381}
1382
commit-bot@chromium.org32184d82013-10-09 15:14:18 +00001383GrPath* GrGpuGL::onCreatePath(const SkPath& inPath, const SkStrokeRec& stroke) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001384 SkASSERT(this->caps()->pathRenderingSupport());
commit-bot@chromium.org32184d82013-10-09 15:14:18 +00001385 return SkNEW_ARGS(GrGLPath, (this, inPath, stroke));
bsalomon@google.com64aef2b2012-06-11 15:36:13 +00001386}
1387
cdaltonb85a0aa2014-07-21 15:32:44 -07001388GrPathRange* GrGpuGL::onCreatePathRange(size_t size, const SkStrokeRec& stroke) {
1389 SkASSERT(this->caps()->pathRenderingSupport());
1390 return SkNEW_ARGS(GrGLPathRange, (this, size, stroke));
1391}
1392
bsalomon@google.coma3201942012-06-21 19:58:20 +00001393void GrGpuGL::flushScissor() {
bsalomon@google.coma3201942012-06-21 19:58:20 +00001394 if (fScissorState.fEnabled) {
commit-bot@chromium.org5c363642013-10-04 15:28:18 +00001395 // Only access the RT if scissoring is being enabled. We can call this before performing
1396 // a glBitframebuffer for a surface->surface copy, which requires no RT to be bound to the
1397 // GrDrawState.
1398 const GrDrawState& drawState = this->getDrawState();
1399 const GrGLRenderTarget* rt =
1400 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget());
1401
1402 SkASSERT(NULL != rt);
1403 const GrGLIRect& vp = rt->getViewport();
bsalomon@google.coma3201942012-06-21 19:58:20 +00001404 GrGLIRect scissor;
1405 scissor.setRelativeTo(vp,
1406 fScissorState.fRect.fLeft,
1407 fScissorState.fRect.fTop,
1408 fScissorState.fRect.width(),
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +00001409 fScissorState.fRect.height(),
1410 rt->origin());
bsalomon@google.coma3201942012-06-21 19:58:20 +00001411 // if the scissor fully contains the viewport then we fall through and
1412 // disable the scissor test.
1413 if (!scissor.contains(vp)) {
1414 if (fHWScissorSettings.fRect != scissor) {
1415 scissor.pushToGLScissor(this->glInterface());
1416 fHWScissorSettings.fRect = scissor;
1417 }
1418 if (kYes_TriState != fHWScissorSettings.fEnabled) {
1419 GL_CALL(Enable(GR_GL_SCISSOR_TEST));
1420 fHWScissorSettings.fEnabled = kYes_TriState;
1421 }
1422 return;
1423 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001424 }
bsalomon@google.coma3201942012-06-21 19:58:20 +00001425 if (kNo_TriState != fHWScissorSettings.fEnabled) {
robertphillips@google.com730ebe52012-04-16 16:33:13 +00001426 GL_CALL(Disable(GR_GL_SCISSOR_TEST));
bsalomon@google.coma3201942012-06-21 19:58:20 +00001427 fHWScissorSettings.fEnabled = kNo_TriState;
1428 return;
reed@google.comac10a2d2010-12-22 21:39:39 +00001429 }
1430}
1431
robertphillips@google.com56ce48a2013-10-31 21:44:25 +00001432void GrGpuGL::onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +00001433 const GrDrawState& drawState = this->getDrawState();
1434 const GrRenderTarget* rt = drawState.getRenderTarget();
bsalomon@google.com0ba52fc2011-11-10 22:16:06 +00001435 // parent class should never let us get here with no RT
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001436 SkASSERT(NULL != rt);
bsalomon@google.com0ba52fc2011-11-10 22:16:06 +00001437
robertphillips@google.com56ce48a2013-10-31 21:44:25 +00001438 if (canIgnoreRect && this->glCaps().fullClearIsFree()) {
1439 rect = NULL;
1440 }
1441
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +00001442 SkIRect clippedRect;
bsalomon@google.com6aa25c32011-04-27 19:55:29 +00001443 if (NULL != rect) {
1444 // flushScissor expects rect to be clipped to the target.
bsalomon@google.com74b98712011-11-11 19:46:16 +00001445 clippedRect = *rect;
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +00001446 SkIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height());
bsalomon@google.com74b98712011-11-11 19:46:16 +00001447 if (clippedRect.intersect(rtRect)) {
1448 rect = &clippedRect;
bsalomon@google.com6aa25c32011-04-27 19:55:29 +00001449 } else {
1450 return;
1451 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001452 }
rmistry@google.comd6bab022013-12-02 13:50:38 +00001453
bsalomon@google.com8295dc12011-05-02 12:53:34 +00001454 this->flushRenderTarget(rect);
bsalomon@google.coma3201942012-06-21 19:58:20 +00001455 GrAutoTRestore<ScissorState> asr(&fScissorState);
1456 fScissorState.fEnabled = (NULL != rect);
1457 if (fScissorState.fEnabled) {
1458 fScissorState.fRect = *rect;
1459 }
1460 this->flushScissor();
bsalomon@google.com74b98712011-11-11 19:46:16 +00001461
1462 GrGLfloat r, g, b, a;
1463 static const GrGLfloat scale255 = 1.f / 255.f;
1464 a = GrColorUnpackA(color) * scale255;
1465 GrGLfloat scaleRGB = scale255;
bsalomon@google.com74b98712011-11-11 19:46:16 +00001466 r = GrColorUnpackR(color) * scaleRGB;
1467 g = GrColorUnpackG(color) * scaleRGB;
1468 b = GrColorUnpackB(color) * scaleRGB;
1469
1470 GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
bsalomon@google.com978c8c62012-05-21 14:45:49 +00001471 fHWWriteToColor = kYes_TriState;
bsalomon@google.com74b98712011-11-11 19:46:16 +00001472 GL_CALL(ClearColor(r, g, b, a));
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001473 GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT));
reed@google.comac10a2d2010-12-22 21:39:39 +00001474}
1475
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001476void GrGpuGL::discard(GrRenderTarget* renderTarget) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001477 if (!this->caps()->discardRenderTargetSupport()) {
1478 return;
1479 }
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001480 if (NULL == renderTarget) {
1481 renderTarget = this->drawState()->getRenderTarget();
1482 if (NULL == renderTarget) {
1483 return;
1484 }
1485 }
1486
1487 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget);
bsalomon1c63bf62014-07-22 13:09:46 -07001488 if (renderTarget->getUniqueID() != fHWBoundRenderTargetUniqueID) {
1489 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001490 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID()));
1491 }
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001492 switch (this->glCaps().invalidateFBType()) {
1493 case GrGLCaps::kNone_FBFetchType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00001494 SkFAIL("Should never get here.");
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001495 break;
1496 case GrGLCaps::kInvalidate_InvalidateFBType:
1497 if (0 == glRT->renderFBOID()) {
1498 // When rendering to the default framebuffer the legal values for attachments
1499 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the various FBO attachment
1500 // types.
1501 static const GrGLenum attachments[] = { GR_GL_COLOR };
1502 GL_CALL(InvalidateFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(attachments),
1503 attachments));
1504 } else {
1505 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 };
1506 GL_CALL(InvalidateFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(attachments),
1507 attachments));
1508 }
1509 break;
1510 case GrGLCaps::kDiscard_InvalidateFBType: {
commit-bot@chromium.org4453e8b2014-04-16 14:33:27 +00001511 if (0 == glRT->renderFBOID()) {
1512 // When rendering to the default framebuffer the legal values for attachments
1513 // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the various FBO attachment
1514 // types. See glDiscardFramebuffer() spec.
1515 static const GrGLenum attachments[] = { GR_GL_COLOR };
1516 GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(attachments),
1517 attachments));
1518 } else {
1519 static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 };
1520 GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(attachments),
1521 attachments));
1522 }
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001523 break;
1524 }
1525 }
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001526 renderTarget->flagAsResolved();
1527}
1528
1529
bsalomon@google.comedc177d2011-08-05 15:46:40 +00001530void GrGpuGL::clearStencil() {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +00001531 if (NULL == this->getDrawState().getRenderTarget()) {
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +00001532 return;
1533 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001534
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +00001535 this->flushRenderTarget(&SkIRect::EmptyIRect());
bsalomon@google.com8295dc12011-05-02 12:53:34 +00001536
bsalomon@google.coma3201942012-06-21 19:58:20 +00001537 GrAutoTRestore<ScissorState> asr(&fScissorState);
1538 fScissorState.fEnabled = false;
1539 this->flushScissor();
robertphillips@google.com730ebe52012-04-16 16:33:13 +00001540
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001541 GL_CALL(StencilMask(0xffffffff));
1542 GL_CALL(ClearStencil(0));
1543 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
bsalomon@google.com457b8a32012-05-21 21:19:58 +00001544 fHWStencilSettings.invalidate();
reed@google.comac10a2d2010-12-22 21:39:39 +00001545}
1546
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +00001547void GrGpuGL::clearStencilClip(const SkIRect& rect, bool insideClip) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +00001548 const GrDrawState& drawState = this->getDrawState();
1549 const GrRenderTarget* rt = drawState.getRenderTarget();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001550 SkASSERT(NULL != rt);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001551
1552 // this should only be called internally when we know we have a
1553 // stencil buffer.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001554 SkASSERT(NULL != rt->getStencilBuffer());
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +00001555 GrGLint stencilBitCount = rt->getStencilBuffer()->bits();
bsalomon@google.comab3dee52011-08-29 15:18:41 +00001556#if 0
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001557 SkASSERT(stencilBitCount > 0);
twiz@google.com0f31ca72011-03-18 17:38:11 +00001558 GrGLint clipStencilMask = (1 << (stencilBitCount - 1));
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +00001559#else
1560 // we could just clear the clip bit but when we go through
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001561 // ANGLE a partial stencil mask will cause clears to be
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +00001562 // turned into draws. Our contract on GrDrawTarget says that
1563 // changing the clip between stencil passes may or may not
1564 // zero the client's clip bits. So we just clear the whole thing.
twiz@google.com0f31ca72011-03-18 17:38:11 +00001565 static const GrGLint clipStencilMask = ~0;
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +00001566#endif
bsalomon@google.comab3dee52011-08-29 15:18:41 +00001567 GrGLint value;
1568 if (insideClip) {
1569 value = (1 << (stencilBitCount - 1));
1570 } else {
1571 value = 0;
1572 }
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +00001573 this->flushRenderTarget(&SkIRect::EmptyIRect());
bsalomon@google.coma3201942012-06-21 19:58:20 +00001574
1575 GrAutoTRestore<ScissorState> asr(&fScissorState);
1576 fScissorState.fEnabled = true;
1577 fScissorState.fRect = rect;
1578 this->flushScissor();
1579
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001580 GL_CALL(StencilMask((uint32_t) clipStencilMask));
bsalomon@google.comab3dee52011-08-29 15:18:41 +00001581 GL_CALL(ClearStencil(value));
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001582 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
bsalomon@google.com457b8a32012-05-21 21:19:58 +00001583 fHWStencilSettings.invalidate();
reed@google.comac10a2d2010-12-22 21:39:39 +00001584}
1585
bsalomon@google.comc4364992011-11-07 15:54:49 +00001586bool GrGpuGL::readPixelsWillPayForYFlip(GrRenderTarget* renderTarget,
1587 int left, int top,
1588 int width, int height,
1589 GrPixelConfig config,
bsalomon@google.com56d11e02011-11-30 19:59:08 +00001590 size_t rowBytes) const {
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +00001591 // If this rendertarget is aready TopLeft, we don't need to flip.
1592 if (kTopLeft_GrSurfaceOrigin == renderTarget->origin()) {
1593 return false;
1594 }
1595
bsalomon@google.com56d11e02011-11-30 19:59:08 +00001596 // if GL can do the flip then we'll never pay for it.
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001597 if (this->glCaps().packFlipYSupport()) {
bsalomon@google.com56d11e02011-11-30 19:59:08 +00001598 return false;
1599 }
1600
1601 // If we have to do memcpy to handle non-trim rowBytes then we
bsalomon@google.com7107fa72011-11-10 14:54:14 +00001602 // get the flip for free. Otherwise it costs.
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001603 if (this->glCaps().packRowLengthSupport()) {
bsalomon@google.coma85449d2011-11-19 02:36:05 +00001604 return true;
1605 }
1606 // If we have to do memcpys to handle rowBytes then y-flip is free
1607 // Note the rowBytes might be tight to the passed in data, but if data
1608 // gets clipped in x to the target the rowBytes will no longer be tight.
1609 if (left >= 0 && (left + width) < renderTarget->width()) {
1610 return 0 == rowBytes ||
1611 GrBytesPerPixel(config) * width == rowBytes;
1612 } else {
1613 return false;
1614 }
bsalomon@google.comc4364992011-11-07 15:54:49 +00001615}
1616
bsalomon@google.com5877ffd2011-04-11 17:58:48 +00001617bool GrGpuGL::onReadPixels(GrRenderTarget* target,
bsalomon@google.comc6980972011-11-02 19:57:21 +00001618 int left, int top,
1619 int width, int height,
bsalomon@google.comc4364992011-11-07 15:54:49 +00001620 GrPixelConfig config,
1621 void* buffer,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +00001622 size_t rowBytes) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001623 // We cannot read pixels into a compressed buffer
1624 if (GrPixelConfigIsCompressed(config)) {
1625 return false;
1626 }
1627
1628 GrGLenum format = 0;
1629 GrGLenum type = 0;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +00001630 bool flipY = kBottomLeft_GrSurfaceOrigin == target->origin();
bsalomon@google.com280e99f2012-01-05 16:17:38 +00001631 if (!this->configToGLFormats(config, false, NULL, &format, &type)) {
reed@google.comac10a2d2010-12-22 21:39:39 +00001632 return false;
bsalomon@google.comc6980972011-11-02 19:57:21 +00001633 }
bsalomon@google.coma85449d2011-11-19 02:36:05 +00001634 size_t bpp = GrBytesPerPixel(config);
1635 if (!adjust_pixel_ops_params(target->width(), target->height(), bpp,
1636 &left, &top, &width, &height,
1637 const_cast<const void**>(&buffer),
1638 &rowBytes)) {
1639 return false;
1640 }
bsalomon@google.comc4364992011-11-07 15:54:49 +00001641
bsalomon@google.comc6980972011-11-02 19:57:21 +00001642 // resolve the render target if necessary
bsalomon@google.com5877ffd2011-04-11 17:58:48 +00001643 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target);
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +00001644 GrDrawState::AutoRenderTargetRestore artr;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +00001645 switch (tgt->getResolveType()) {
1646 case GrGLRenderTarget::kCantResolve_ResolveType:
1647 return false;
1648 case GrGLRenderTarget::kAutoResolves_ResolveType:
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +00001649 artr.set(this->drawState(), target);
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +00001650 this->flushRenderTarget(&SkIRect::EmptyIRect());
bsalomon@google.com5877ffd2011-04-11 17:58:48 +00001651 break;
1652 case GrGLRenderTarget::kCanResolve_ResolveType:
bsalomon@google.com75f9f252012-01-31 13:35:56 +00001653 this->onResolveRenderTarget(tgt);
bsalomon@google.com5877ffd2011-04-11 17:58:48 +00001654 // we don't track the state of the READ FBO ID.
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001655 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
1656 tgt->textureFBOID()));
bsalomon@google.com5877ffd2011-04-11 17:58:48 +00001657 break;
1658 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00001659 SkFAIL("Unknown resolve type");
reed@google.comac10a2d2010-12-22 21:39:39 +00001660 }
1661
bsalomon@google.com5877ffd2011-04-11 17:58:48 +00001662 const GrGLIRect& glvp = tgt->getViewport();
bsalomon@google.comd302f142011-03-03 13:54:13 +00001663
bsalomon@google.com8895a7a2011-02-18 16:09:55 +00001664 // the read rect is viewport-relative
1665 GrGLIRect readRect;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +00001666 readRect.setRelativeTo(glvp, left, top, width, height, target->origin());
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001667
bsalomon@google.coma85449d2011-11-19 02:36:05 +00001668 size_t tightRowBytes = bpp * width;
bsalomon@google.comc6980972011-11-02 19:57:21 +00001669 if (0 == rowBytes) {
1670 rowBytes = tightRowBytes;
1671 }
1672 size_t readDstRowBytes = tightRowBytes;
1673 void* readDst = buffer;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001674
bsalomon@google.comc6980972011-11-02 19:57:21 +00001675 // determine if GL can read using the passed rowBytes or if we need
1676 // a scratch buffer.
1677 SkAutoSMalloc<32 * sizeof(GrColor)> scratch;
1678 if (rowBytes != tightRowBytes) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001679 if (this->glCaps().packRowLengthSupport()) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001680 SkASSERT(!(rowBytes % sizeof(GrColor)));
skia.committer@gmail.com4677acc2013-10-17 07:02:33 +00001681 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH,
robertphillips@google.come9cd27d2013-10-16 17:48:11 +00001682 static_cast<GrGLint>(rowBytes / sizeof(GrColor))));
bsalomon@google.comc6980972011-11-02 19:57:21 +00001683 readDstRowBytes = rowBytes;
1684 } else {
1685 scratch.reset(tightRowBytes * height);
1686 readDst = scratch.get();
1687 }
1688 }
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +00001689 if (flipY && this->glCaps().packFlipYSupport()) {
bsalomon@google.com56d11e02011-11-30 19:59:08 +00001690 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1));
1691 }
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001692 GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom,
1693 readRect.fWidth, readRect.fHeight,
bsalomon@google.comc6980972011-11-02 19:57:21 +00001694 format, type, readDst));
1695 if (readDstRowBytes != tightRowBytes) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001696 SkASSERT(this->glCaps().packRowLengthSupport());
bsalomon@google.comc6980972011-11-02 19:57:21 +00001697 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0));
1698 }
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +00001699 if (flipY && this->glCaps().packFlipYSupport()) {
bsalomon@google.com56d11e02011-11-30 19:59:08 +00001700 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 0));
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +00001701 flipY = false;
bsalomon@google.com56d11e02011-11-30 19:59:08 +00001702 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001703
1704 // now reverse the order of the rows, since GL's are bottom-to-top, but our
bsalomon@google.comc6980972011-11-02 19:57:21 +00001705 // API presents top-to-bottom. We must preserve the padding contents. Note
1706 // that the above readPixels did not overwrite the padding.
1707 if (readDst == buffer) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001708 SkASSERT(rowBytes == readDstRowBytes);
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +00001709 if (flipY) {
bsalomon@google.comc4364992011-11-07 15:54:49 +00001710 scratch.reset(tightRowBytes);
1711 void* tmpRow = scratch.get();
1712 // flip y in-place by rows
1713 const int halfY = height >> 1;
1714 char* top = reinterpret_cast<char*>(buffer);
1715 char* bottom = top + (height - 1) * rowBytes;
1716 for (int y = 0; y < halfY; y++) {
1717 memcpy(tmpRow, top, tightRowBytes);
1718 memcpy(top, bottom, tightRowBytes);
1719 memcpy(bottom, tmpRow, tightRowBytes);
1720 top += rowBytes;
1721 bottom -= rowBytes;
1722 }
bsalomon@google.comc6980972011-11-02 19:57:21 +00001723 }
1724 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001725 SkASSERT(readDst != buffer); SkASSERT(rowBytes != tightRowBytes);
bsalomon@google.comc6980972011-11-02 19:57:21 +00001726 // copy from readDst to buffer while flipping y
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001727 // const int halfY = height >> 1;
bsalomon@google.comc6980972011-11-02 19:57:21 +00001728 const char* src = reinterpret_cast<const char*>(readDst);
bsalomon@google.comc4364992011-11-07 15:54:49 +00001729 char* dst = reinterpret_cast<char*>(buffer);
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +00001730 if (flipY) {
bsalomon@google.comc4364992011-11-07 15:54:49 +00001731 dst += (height-1) * rowBytes;
1732 }
bsalomon@google.comc6980972011-11-02 19:57:21 +00001733 for (int y = 0; y < height; y++) {
1734 memcpy(dst, src, tightRowBytes);
1735 src += readDstRowBytes;
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +00001736 if (!flipY) {
bsalomon@google.comc4364992011-11-07 15:54:49 +00001737 dst += rowBytes;
1738 } else {
1739 dst -= rowBytes;
1740 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001741 }
1742 }
1743 return true;
1744}
1745
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +00001746void GrGpuGL::flushRenderTarget(const SkIRect* bound) {
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001747
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +00001748 GrGLRenderTarget* rt =
1749 static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget());
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001750 SkASSERT(NULL != rt);
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00001751
bsalomon1c63bf62014-07-22 13:09:46 -07001752 uint32_t rtID = rt->getUniqueID();
1753 if (fHWBoundRenderTargetUniqueID != rtID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001754 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID()));
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +00001755#ifdef SK_DEBUG
rmistry@google.comd6bab022013-12-02 13:50:38 +00001756 // don't do this check in Chromium -- this is causing
1757 // lots of repeated command buffer flushes when the compositor is
1758 // rendering with Ganesh, which is really slow; even too slow for
1759 // Debug mode.
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +00001760 if (!this->glContext().isChromium()) {
rmistry@google.comd6bab022013-12-02 13:50:38 +00001761 GrGLenum status;
1762 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1763 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
1764 GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x\n", status);
1765 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001766 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +00001767#endif
bsalomon1c63bf62014-07-22 13:09:46 -07001768 fHWBoundRenderTargetUniqueID = rtID;
bsalomon@google.comd302f142011-03-03 13:54:13 +00001769 const GrGLIRect& vp = rt->getViewport();
bsalomon@google.coma3201942012-06-21 19:58:20 +00001770 if (fHWViewport != vp) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001771 vp.pushToGLViewport(this->glInterface());
bsalomon@google.coma3201942012-06-21 19:58:20 +00001772 fHWViewport = vp;
reed@google.comac10a2d2010-12-22 21:39:39 +00001773 }
1774 }
bsalomon@google.com8295dc12011-05-02 12:53:34 +00001775 if (NULL == bound || !bound->isEmpty()) {
1776 rt->flagAsNeedingResolve(bound);
1777 }
skia.committer@gmail.comaeefb2a2013-07-27 07:01:06 +00001778
commit-bot@chromium.orgcffff792013-07-26 16:36:04 +00001779 GrTexture *texture = rt->asTexture();
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +00001780 if (NULL != texture) {
1781 texture->impl()->dirtyMipMaps(true);
commit-bot@chromium.orgcffff792013-07-26 16:36:04 +00001782 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001783}
1784
twiz@google.com0f31ca72011-03-18 17:38:11 +00001785GrGLenum gPrimitiveType2GLMode[] = {
1786 GR_GL_TRIANGLES,
1787 GR_GL_TRIANGLE_STRIP,
1788 GR_GL_TRIANGLE_FAN,
1789 GR_GL_POINTS,
1790 GR_GL_LINES,
1791 GR_GL_LINE_STRIP
reed@google.comac10a2d2010-12-22 21:39:39 +00001792};
1793
bsalomon@google.comd302f142011-03-03 13:54:13 +00001794#define SWAP_PER_DRAW 0
1795
bsalomon@google.coma7f84e12011-03-10 14:13:19 +00001796#if SWAP_PER_DRAW
commit-bot@chromium.org43823302013-09-25 20:57:51 +00001797 #if defined(SK_BUILD_FOR_MAC)
bsalomon@google.comd302f142011-03-03 13:54:13 +00001798 #include <AGL/agl.h>
commit-bot@chromium.org43823302013-09-25 20:57:51 +00001799 #elif defined(SK_BUILD_FOR_WIN32)
bsalomon@google.comce7357d2012-06-25 17:49:25 +00001800 #include <gl/GL.h>
bsalomon@google.comd302f142011-03-03 13:54:13 +00001801 void SwapBuf() {
1802 DWORD procID = GetCurrentProcessId();
1803 HWND hwnd = GetTopWindow(GetDesktopWindow());
1804 while(hwnd) {
1805 DWORD wndProcID = 0;
1806 GetWindowThreadProcessId(hwnd, &wndProcID);
1807 if(wndProcID == procID) {
1808 SwapBuffers(GetDC(hwnd));
1809 }
1810 hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);
1811 }
1812 }
1813 #endif
1814#endif
1815
bsalomon@google.com74749cd2013-01-30 16:12:41 +00001816void GrGpuGL::onGpuDraw(const DrawInfo& info) {
bsalomon@google.com880b8fc2013-02-19 20:17:28 +00001817 size_t indexOffsetInBytes;
1818 this->setupGeometry(info, &indexOffsetInBytes);
reed@google.comac10a2d2010-12-22 21:39:39 +00001819
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001820 SkASSERT((size_t)info.primitiveType() < SK_ARRAY_COUNT(gPrimitiveType2GLMode));
bsalomon@google.com1c13c962011-02-14 16:51:21 +00001821
bsalomon@google.com74749cd2013-01-30 16:12:41 +00001822 if (info.isIndexed()) {
bsalomon@google.com880b8fc2013-02-19 20:17:28 +00001823 GrGLvoid* indices =
1824 reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) * info.startIndex());
bsalomon@google.com74749cd2013-01-30 16:12:41 +00001825 // info.startVertex() was accounted for by setupGeometry.
1826 GL_CALL(DrawElements(gPrimitiveType2GLMode[info.primitiveType()],
1827 info.indexCount(),
1828 GR_GL_UNSIGNED_SHORT,
1829 indices));
1830 } else {
1831 // Pass 0 for parameter first. We have to adjust glVertexAttribPointer() to account for
1832 // startVertex in the DrawElements case. So we always rely on setupGeometry to have
1833 // accounted for startVertex.
1834 GL_CALL(DrawArrays(gPrimitiveType2GLMode[info.primitiveType()], 0, info.vertexCount()));
1835 }
bsalomon@google.comd302f142011-03-03 13:54:13 +00001836#if SWAP_PER_DRAW
1837 glFlush();
commit-bot@chromium.org43823302013-09-25 20:57:51 +00001838 #if defined(SK_BUILD_FOR_MAC)
bsalomon@google.comd302f142011-03-03 13:54:13 +00001839 aglSwapBuffers(aglGetCurrentContext());
1840 int set_a_break_pt_here = 9;
1841 aglSwapBuffers(aglGetCurrentContext());
commit-bot@chromium.org43823302013-09-25 20:57:51 +00001842 #elif defined(SK_BUILD_FOR_WIN32)
bsalomon@google.comd302f142011-03-03 13:54:13 +00001843 SwapBuf();
1844 int set_a_break_pt_here = 9;
1845 SwapBuf();
1846 #endif
1847#endif
reed@google.comac10a2d2010-12-22 21:39:39 +00001848}
1849
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001850static GrGLenum gr_stencil_op_to_gl_path_rendering_fill_mode(GrStencilOp op) {
1851 switch (op) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00001852 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00001853 SkFAIL("Unexpected path fill.");
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001854 /* fallthrough */;
1855 case kIncClamp_StencilOp:
1856 return GR_GL_COUNT_UP;
1857 case kInvert_StencilOp:
1858 return GR_GL_INVERT;
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00001859 }
1860}
1861
sugoi@google.com12b4e272012-12-06 20:13:11 +00001862void GrGpuGL::onGpuStencilPath(const GrPath* path, SkPath::FillType fill) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001863 SkASSERT(this->caps()->pathRenderingSupport());
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00001864
1865 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID();
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001866 SkASSERT(NULL != this->drawState()->getRenderTarget());
1867 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer());
1868
1869 flushPathStencilSettings(fill);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00001870
1871 // Decide how to manipulate the stencil buffer based on the fill rule.
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001872 SkASSERT(!fHWPathStencilSettings.isTwoSided());
1873
1874 GrGLenum fillMode =
1875 gr_stencil_op_to_gl_path_rendering_fill_mode(fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face));
1876 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00001877 GL_CALL(StencilFillPath(id, fillMode, writeMask));
bsalomon@google.com64aef2b2012-06-11 15:36:13 +00001878}
1879
commit-bot@chromium.org32184d82013-10-09 15:14:18 +00001880void GrGpuGL::onGpuDrawPath(const GrPath* path, SkPath::FillType fill) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001881 SkASSERT(this->caps()->pathRenderingSupport());
1882
1883 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID();
1884 SkASSERT(NULL != this->drawState()->getRenderTarget());
1885 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer());
1886 SkASSERT(!fCurrentProgram->hasVertexShader());
1887
1888 flushPathStencilSettings(fill);
commit-bot@chromium.org32184d82013-10-09 15:14:18 +00001889 const SkStrokeRec& stroke = path->getStroke();
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001890
1891 SkPath::FillType nonInvertedFill = SkPath::ConvertToNonInverseFillType(fill);
1892 SkASSERT(!fHWPathStencilSettings.isTwoSided());
1893 GrGLenum fillMode =
1894 gr_stencil_op_to_gl_path_rendering_fill_mode(fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face));
1895 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face);
commit-bot@chromium.org32184d82013-10-09 15:14:18 +00001896
1897 if (stroke.isFillStyle() || SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) {
1898 GL_CALL(StencilFillPath(id, fillMode, writeMask));
1899 }
1900 if (stroke.needToApply()) {
1901 GL_CALL(StencilStrokePath(id, 0xffff, writeMask));
1902 }
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001903
1904 if (nonInvertedFill == fill) {
commit-bot@chromium.org32184d82013-10-09 15:14:18 +00001905 if (stroke.needToApply()) {
1906 GL_CALL(CoverStrokePath(id, GR_GL_BOUNDING_BOX));
1907 } else {
1908 GL_CALL(CoverFillPath(id, GR_GL_BOUNDING_BOX));
1909 }
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001910 } else {
1911 GrDrawState* drawState = this->drawState();
1912 GrDrawState::AutoViewMatrixRestore avmr;
1913 SkRect bounds = SkRect::MakeLTRB(0, 0,
1914 SkIntToScalar(drawState->getRenderTarget()->width()),
1915 SkIntToScalar(drawState->getRenderTarget()->height()));
1916 SkMatrix vmi;
1917 // mapRect through persp matrix may not be correct
1918 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewInverse(&vmi)) {
1919 vmi.mapRect(&bounds);
1920 // theoretically could set bloat = 0, instead leave it because of matrix inversion
1921 // precision.
commit-bot@chromium.org18786512014-05-20 14:53:45 +00001922 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_ScalarHalf;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001923 bounds.outset(bloat, bloat);
1924 } else {
1925 avmr.setIdentity(drawState);
1926 }
1927
1928 this->drawSimpleRect(bounds, NULL);
1929 }
1930}
1931
cdaltonb85a0aa2014-07-21 15:32:44 -07001932void GrGpuGL::onGpuDrawPaths(const GrPathRange* pathRange,
1933 const uint32_t indices[], int count,
1934 const float transforms[], PathTransformType transformsType,
1935 SkPath::FillType fill) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001936 SkASSERT(this->caps()->pathRenderingSupport());
1937 SkASSERT(NULL != this->drawState()->getRenderTarget());
1938 SkASSERT(NULL != this->drawState()->getRenderTarget()->getStencilBuffer());
1939 SkASSERT(!fCurrentProgram->hasVertexShader());
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001940
cdaltonb85a0aa2014-07-21 15:32:44 -07001941 GrGLuint baseID = static_cast<const GrGLPathRange*>(pathRange)->basePathID();
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001942
1943 flushPathStencilSettings(fill);
cdaltonb85a0aa2014-07-21 15:32:44 -07001944 const SkStrokeRec& stroke = pathRange->getStroke();
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001945
1946 SkPath::FillType nonInvertedFill =
1947 SkPath::ConvertToNonInverseFillType(fill);
1948
1949 SkASSERT(!fHWPathStencilSettings.isTwoSided());
1950 GrGLenum fillMode =
1951 gr_stencil_op_to_gl_path_rendering_fill_mode(
1952 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face));
1953 GrGLint writeMask =
1954 fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face);
1955
cdaltonb85a0aa2014-07-21 15:32:44 -07001956 if (stroke.isFillStyle() || SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) {
1957 GL_CALL(StencilFillPathInstanced(count, GR_GL_UNSIGNED_INT, indices, baseID, fillMode,
1958 writeMask, gXformType2GLType[transformsType],
1959 transforms));
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001960 }
cdaltonb85a0aa2014-07-21 15:32:44 -07001961 if (stroke.needToApply()) {
1962 GL_CALL(StencilStrokePathInstanced(count, GR_GL_UNSIGNED_INT, indices, baseID, 0xffff,
1963 writeMask, gXformType2GLType[transformsType],
1964 transforms));
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001965 }
1966
1967 if (nonInvertedFill == fill) {
cdaltonb85a0aa2014-07-21 15:32:44 -07001968 if (stroke.needToApply()) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001969 GL_CALL(CoverStrokePathInstanced(
cdaltonb85a0aa2014-07-21 15:32:44 -07001970 count, GR_GL_UNSIGNED_INT, indices, baseID,
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001971 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES,
cdaltonb85a0aa2014-07-21 15:32:44 -07001972 gXformType2GLType[transformsType], transforms));
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001973 } else {
1974 GL_CALL(CoverFillPathInstanced(
cdaltonb85a0aa2014-07-21 15:32:44 -07001975 count, GR_GL_UNSIGNED_INT, indices, baseID,
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001976 GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES,
cdaltonb85a0aa2014-07-21 15:32:44 -07001977 gXformType2GLType[transformsType], transforms));
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001978 }
1979 } else {
1980 GrDrawState* drawState = this->drawState();
1981 GrDrawState::AutoViewMatrixRestore avmr;
1982 SkRect bounds = SkRect::MakeLTRB(0, 0,
1983 SkIntToScalar(drawState->getRenderTarget()->width()),
1984 SkIntToScalar(drawState->getRenderTarget()->height()));
1985 SkMatrix vmi;
1986 // mapRect through persp matrix may not be correct
1987 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewInverse(&vmi)) {
1988 vmi.mapRect(&bounds);
1989 // theoretically could set bloat = 0, instead leave it because of matrix inversion
1990 // precision.
commit-bot@chromium.org18786512014-05-20 14:53:45 +00001991 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_ScalarHalf;
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +00001992 bounds.outset(bloat, bloat);
1993 } else {
1994 avmr.setIdentity(drawState);
1995 }
1996
1997 this->drawSimpleRect(bounds, NULL);
1998 }
1999}
2000
bsalomon@google.com75f9f252012-01-31 13:35:56 +00002001void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) {
bsalomon@google.com75f9f252012-01-31 13:35:56 +00002002 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target);
bsalomon@google.com5877ffd2011-04-11 17:58:48 +00002003 if (rt->needsResolve()) {
bsalomon@google.com347c3822013-05-01 20:10:01 +00002004 // Some extensions automatically resolves the texture when it is read.
2005 if (this->glCaps().usesMSAARenderBuffers()) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00002006 SkASSERT(rt->textureFBOID() != rt->renderFBOID());
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00002007 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID()));
2008 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()));
2009 // make sure we go through flushRenderTarget() since we've modified
2010 // the bound DRAW FBO ID.
bsalomon1c63bf62014-07-22 13:09:46 -07002011 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00002012 const GrGLIRect& vp = rt->getViewport();
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +00002013 const SkIRect dirtyRect = rt->getResolveRect();
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00002014 GrGLIRect r;
2015 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop,
2016 dirtyRect.width(), dirtyRect.height(), target->origin());
reed@google.comac10a2d2010-12-22 21:39:39 +00002017
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00002018 GrAutoTRestore<ScissorState> asr;
bsalomon@google.com347c3822013-05-01 20:10:01 +00002019 if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) {
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00002020 // Apple's extension uses the scissor as the blit bounds.
bsalomon@google.coma3201942012-06-21 19:58:20 +00002021 asr.reset(&fScissorState);
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00002022 fScissorState.fEnabled = true;
2023 fScissorState.fRect = dirtyRect;
bsalomon@google.coma3201942012-06-21 19:58:20 +00002024 this->flushScissor();
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00002025 GL_CALL(ResolveMultisampleFramebuffer());
2026 } else {
bsalomon@google.com347c3822013-05-01 20:10:01 +00002027 if (GrGLCaps::kDesktop_EXT_MSFBOType == this->glCaps().msFBOType()) {
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00002028 // this respects the scissor during the blit, so disable it.
bsalomon@google.comf3a60c02013-03-19 19:06:09 +00002029 asr.reset(&fScissorState);
2030 fScissorState.fEnabled = false;
2031 this->flushScissor();
2032 }
2033 int right = r.fLeft + r.fWidth;
2034 int top = r.fBottom + r.fHeight;
2035 GL_CALL(BlitFramebuffer(r.fLeft, r.fBottom, right, top,
2036 r.fLeft, r.fBottom, right, top,
2037 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
bsalomon@google.coma9ecdad2011-03-23 13:50:34 +00002038 }
reed@google.comac10a2d2010-12-22 21:39:39 +00002039 }
bsalomon@google.com5877ffd2011-04-11 17:58:48 +00002040 rt->flagAsResolved();
reed@google.comac10a2d2010-12-22 21:39:39 +00002041 }
2042}
2043
bsalomon@google.com411dad02012-06-05 20:24:20 +00002044namespace {
bsalomon@google.comd302f142011-03-03 13:54:13 +00002045
bsalomon@google.com411dad02012-06-05 20:24:20 +00002046GrGLenum gr_to_gl_stencil_func(GrStencilFunc basicFunc) {
2047 static const GrGLenum gTable[] = {
2048 GR_GL_ALWAYS, // kAlways_StencilFunc
2049 GR_GL_NEVER, // kNever_StencilFunc
2050 GR_GL_GREATER, // kGreater_StencilFunc
2051 GR_GL_GEQUAL, // kGEqual_StencilFunc
2052 GR_GL_LESS, // kLess_StencilFunc
2053 GR_GL_LEQUAL, // kLEqual_StencilFunc,
2054 GR_GL_EQUAL, // kEqual_StencilFunc,
2055 GR_GL_NOTEQUAL, // kNotEqual_StencilFunc,
2056 };
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00002057 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kBasicStencilFuncCount);
bsalomon@google.com411dad02012-06-05 20:24:20 +00002058 GR_STATIC_ASSERT(0 == kAlways_StencilFunc);
2059 GR_STATIC_ASSERT(1 == kNever_StencilFunc);
2060 GR_STATIC_ASSERT(2 == kGreater_StencilFunc);
2061 GR_STATIC_ASSERT(3 == kGEqual_StencilFunc);
2062 GR_STATIC_ASSERT(4 == kLess_StencilFunc);
2063 GR_STATIC_ASSERT(5 == kLEqual_StencilFunc);
2064 GR_STATIC_ASSERT(6 == kEqual_StencilFunc);
2065 GR_STATIC_ASSERT(7 == kNotEqual_StencilFunc);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00002066 SkASSERT((unsigned) basicFunc < kBasicStencilFuncCount);
bsalomon@google.com411dad02012-06-05 20:24:20 +00002067
2068 return gTable[basicFunc];
2069}
2070
2071GrGLenum gr_to_gl_stencil_op(GrStencilOp op) {
2072 static const GrGLenum gTable[] = {
2073 GR_GL_KEEP, // kKeep_StencilOp
2074 GR_GL_REPLACE, // kReplace_StencilOp
2075 GR_GL_INCR_WRAP, // kIncWrap_StencilOp
2076 GR_GL_INCR, // kIncClamp_StencilOp
2077 GR_GL_DECR_WRAP, // kDecWrap_StencilOp
2078 GR_GL_DECR, // kDecClamp_StencilOp
2079 GR_GL_ZERO, // kZero_StencilOp
2080 GR_GL_INVERT, // kInvert_StencilOp
2081 };
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00002082 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kStencilOpCount);
bsalomon@google.com411dad02012-06-05 20:24:20 +00002083 GR_STATIC_ASSERT(0 == kKeep_StencilOp);
2084 GR_STATIC_ASSERT(1 == kReplace_StencilOp);
2085 GR_STATIC_ASSERT(2 == kIncWrap_StencilOp);
2086 GR_STATIC_ASSERT(3 == kIncClamp_StencilOp);
2087 GR_STATIC_ASSERT(4 == kDecWrap_StencilOp);
2088 GR_STATIC_ASSERT(5 == kDecClamp_StencilOp);
2089 GR_STATIC_ASSERT(6 == kZero_StencilOp);
2090 GR_STATIC_ASSERT(7 == kInvert_StencilOp);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00002091 SkASSERT((unsigned) op < kStencilOpCount);
bsalomon@google.com411dad02012-06-05 20:24:20 +00002092 return gTable[op];
2093}
2094
2095void set_gl_stencil(const GrGLInterface* gl,
bsalomon@google.coma3201942012-06-21 19:58:20 +00002096 const GrStencilSettings& settings,
bsalomon@google.com411dad02012-06-05 20:24:20 +00002097 GrGLenum glFace,
bsalomon@google.coma3201942012-06-21 19:58:20 +00002098 GrStencilSettings::Face grFace) {
2099 GrGLenum glFunc = gr_to_gl_stencil_func(settings.func(grFace));
2100 GrGLenum glFailOp = gr_to_gl_stencil_op(settings.failOp(grFace));
2101 GrGLenum glPassOp = gr_to_gl_stencil_op(settings.passOp(grFace));
2102
2103 GrGLint ref = settings.funcRef(grFace);
2104 GrGLint mask = settings.funcMask(grFace);
2105 GrGLint writeMask = settings.writeMask(grFace);
bsalomon@google.com411dad02012-06-05 20:24:20 +00002106
2107 if (GR_GL_FRONT_AND_BACK == glFace) {
2108 // we call the combined func just in case separate stencil is not
2109 // supported.
2110 GR_GL_CALL(gl, StencilFunc(glFunc, ref, mask));
2111 GR_GL_CALL(gl, StencilMask(writeMask));
2112 GR_GL_CALL(gl, StencilOp(glFailOp, glPassOp, glPassOp));
2113 } else {
2114 GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask));
2115 GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask));
2116 GR_GL_CALL(gl, StencilOpSeparate(glFace, glFailOp, glPassOp, glPassOp));
2117 }
2118}
2119}
bsalomon@google.comd302f142011-03-03 13:54:13 +00002120
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00002121void GrGpuGL::flushStencil(DrawType type) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00002122 if (kStencilPath_DrawType != type && fHWStencilSettings != fStencilSettings) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00002123 if (fStencilSettings.isDisabled()) {
2124 if (kNo_TriState != fHWStencilTestEnabled) {
2125 GL_CALL(Disable(GR_GL_STENCIL_TEST));
2126 fHWStencilTestEnabled = kNo_TriState;
2127 }
2128 } else {
2129 if (kYes_TriState != fHWStencilTestEnabled) {
2130 GL_CALL(Enable(GR_GL_STENCIL_TEST));
2131 fHWStencilTestEnabled = kYes_TriState;
2132 }
bsalomon@google.coma3201942012-06-21 19:58:20 +00002133 }
bsalomon@google.coma3201942012-06-21 19:58:20 +00002134 if (!fStencilSettings.isDisabled()) {
bsalomon@google.combcce8922013-03-25 15:38:39 +00002135 if (this->caps()->twoSidedStencilSupport()) {
bsalomon@google.com411dad02012-06-05 20:24:20 +00002136 set_gl_stencil(this->glInterface(),
bsalomon@google.coma3201942012-06-21 19:58:20 +00002137 fStencilSettings,
bsalomon@google.com411dad02012-06-05 20:24:20 +00002138 GR_GL_FRONT,
bsalomon@google.coma3201942012-06-21 19:58:20 +00002139 GrStencilSettings::kFront_Face);
bsalomon@google.com411dad02012-06-05 20:24:20 +00002140 set_gl_stencil(this->glInterface(),
bsalomon@google.coma3201942012-06-21 19:58:20 +00002141 fStencilSettings,
bsalomon@google.com411dad02012-06-05 20:24:20 +00002142 GR_GL_BACK,
bsalomon@google.coma3201942012-06-21 19:58:20 +00002143 GrStencilSettings::kBack_Face);
bsalomon@google.comd302f142011-03-03 13:54:13 +00002144 } else {
bsalomon@google.com411dad02012-06-05 20:24:20 +00002145 set_gl_stencil(this->glInterface(),
bsalomon@google.coma3201942012-06-21 19:58:20 +00002146 fStencilSettings,
bsalomon@google.com411dad02012-06-05 20:24:20 +00002147 GR_GL_FRONT_AND_BACK,
bsalomon@google.coma3201942012-06-21 19:58:20 +00002148 GrStencilSettings::kFront_Face);
bsalomon@google.comd302f142011-03-03 13:54:13 +00002149 }
2150 }
bsalomon@google.coma3201942012-06-21 19:58:20 +00002151 fHWStencilSettings = fStencilSettings;
reed@google.comac10a2d2010-12-22 21:39:39 +00002152 }
2153}
2154
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00002155void GrGpuGL::flushAAState(DrawType type) {
bsalomon@google.com202d1392013-03-19 18:58:08 +00002156// At least some ATI linux drivers will render GL_LINES incorrectly when MSAA state is enabled but
2157// the target is not multisampled. Single pixel wide lines are rendered thicker than 1 pixel wide.
2158#if 0
2159 // Replace RT_HAS_MSAA with this definition once this driver bug is no longer a relevant concern
2160 #define RT_HAS_MSAA rt->isMultisampled()
2161#else
2162 #define RT_HAS_MSAA (rt->isMultisampled() || kDrawLines_DrawType == type)
2163#endif
2164
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +00002165 const GrRenderTarget* rt = this->getDrawState().getRenderTarget();
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00002166 if (kGL_GrGLStandard == this->glStandard()) {
egdanielb09bdd62014-07-29 08:52:23 -07002167 // ES doesn't support toggling GL_MULTISAMPLE and doesn't have
2168 // smooth lines.
2169 // we prefer smooth lines over multisampled lines
2170 bool smoothLines = false;
2171
2172 if (kDrawLines_DrawType == type) {
2173 smoothLines = this->willUseHWAALines();
2174 if (smoothLines) {
2175 if (kYes_TriState != fHWAAState.fSmoothLineEnabled) {
2176 GL_CALL(Enable(GR_GL_LINE_SMOOTH));
2177 fHWAAState.fSmoothLineEnabled = kYes_TriState;
2178 // must disable msaa to use line smoothing
2179 if (RT_HAS_MSAA &&
2180 kNo_TriState != fHWAAState.fMSAAEnabled) {
2181 GL_CALL(Disable(GR_GL_MULTISAMPLE));
2182 fHWAAState.fMSAAEnabled = kNo_TriState;
2183 }
2184 }
2185 } else {
2186 if (kNo_TriState != fHWAAState.fSmoothLineEnabled) {
2187 GL_CALL(Disable(GR_GL_LINE_SMOOTH));
2188 fHWAAState.fSmoothLineEnabled = kNo_TriState;
2189 }
2190 }
2191 }
2192 if (!smoothLines && RT_HAS_MSAA) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00002193 // FIXME: GL_NV_pr doesn't seem to like MSAA disabled. The paths
2194 // convex hulls of each segment appear to get filled.
2195 bool enableMSAA = kStencilPath_DrawType == type ||
2196 this->getDrawState().isHWAntialiasState();
2197 if (enableMSAA) {
egdanielb09bdd62014-07-29 08:52:23 -07002198 if (kYes_TriState != fHWAAState.fMSAAEnabled) {
bsalomon@google.com4d5f3fe2012-05-21 17:11:44 +00002199 GL_CALL(Enable(GR_GL_MULTISAMPLE));
egdanielb09bdd62014-07-29 08:52:23 -07002200 fHWAAState.fMSAAEnabled = kYes_TriState;
bsalomon@google.com4d5f3fe2012-05-21 17:11:44 +00002201 }
2202 } else {
egdanielb09bdd62014-07-29 08:52:23 -07002203 if (kNo_TriState != fHWAAState.fMSAAEnabled) {
bsalomon@google.com4d5f3fe2012-05-21 17:11:44 +00002204 GL_CALL(Disable(GR_GL_MULTISAMPLE));
egdanielb09bdd62014-07-29 08:52:23 -07002205 fHWAAState.fMSAAEnabled = kNo_TriState;
bsalomon@google.com4d5f3fe2012-05-21 17:11:44 +00002206 }
bsalomon@google.comf954d8d2011-04-06 17:50:02 +00002207 }
2208 }
2209 }
2210}
2211
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00002212void GrGpuGL::flushPathStencilSettings(SkPath::FillType fill) {
2213 GrStencilSettings pathStencilSettings;
2214 this->getPathStencilSettingsForFillType(fill, &pathStencilSettings);
2215 if (fHWPathStencilSettings != pathStencilSettings) {
2216 // Just the func, ref, and mask is set here. The op and write mask are params to the call
2217 // that draws the path to the SB (glStencilFillPath)
2218 GrGLenum func =
2219 gr_to_gl_stencil_func(pathStencilSettings.func(GrStencilSettings::kFront_Face));
2220 GL_CALL(PathStencilFunc(func,
2221 pathStencilSettings.funcRef(GrStencilSettings::kFront_Face),
2222 pathStencilSettings.funcMask(GrStencilSettings::kFront_Face)));
2223
2224 fHWPathStencilSettings = pathStencilSettings;
2225 }
2226}
2227
bsalomon@google.com64aef2b2012-06-11 15:36:13 +00002228void GrGpuGL::flushBlend(bool isLines,
bsalomon@google.com86c1f712011-10-12 14:54:26 +00002229 GrBlendCoeff srcCoeff,
bsalomon@google.com271cffc2011-05-20 14:13:56 +00002230 GrBlendCoeff dstCoeff) {
egdanielb09bdd62014-07-29 08:52:23 -07002231 if (isLines && this->willUseHWAALines()) {
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +00002232 if (kYes_TriState != fHWBlendState.fEnabled) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00002233 GL_CALL(Enable(GR_GL_BLEND));
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +00002234 fHWBlendState.fEnabled = kYes_TriState;
bsalomon@google.com0650e812011-04-08 18:07:53 +00002235 }
egdanielb09bdd62014-07-29 08:52:23 -07002236 if (kSA_GrBlendCoeff != fHWBlendState.fSrcCoeff ||
2237 kISA_GrBlendCoeff != fHWBlendState.fDstCoeff) {
2238 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[kSA_GrBlendCoeff],
2239 gXfermodeCoeff2Blend[kISA_GrBlendCoeff]));
2240 fHWBlendState.fSrcCoeff = kSA_GrBlendCoeff;
2241 fHWBlendState.fDstCoeff = kISA_GrBlendCoeff;
bsalomon@google.com0650e812011-04-08 18:07:53 +00002242 }
egdanielb09bdd62014-07-29 08:52:23 -07002243 } else {
2244 // any optimization to disable blending should
2245 // have already been applied and tweaked the coeffs
2246 // to (1, 0).
2247 bool blendOff = kOne_GrBlendCoeff == srcCoeff &&
2248 kZero_GrBlendCoeff == dstCoeff;
2249 if (blendOff) {
2250 if (kNo_TriState != fHWBlendState.fEnabled) {
2251 GL_CALL(Disable(GR_GL_BLEND));
2252 fHWBlendState.fEnabled = kNo_TriState;
2253 }
2254 } else {
2255 if (kYes_TriState != fHWBlendState.fEnabled) {
2256 GL_CALL(Enable(GR_GL_BLEND));
2257 fHWBlendState.fEnabled = kYes_TriState;
2258 }
2259 if (fHWBlendState.fSrcCoeff != srcCoeff ||
2260 fHWBlendState.fDstCoeff != dstCoeff) {
2261 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff],
2262 gXfermodeCoeff2Blend[dstCoeff]));
2263 fHWBlendState.fSrcCoeff = srcCoeff;
2264 fHWBlendState.fDstCoeff = dstCoeff;
2265 }
2266 GrColor blendConst = this->getDrawState().getBlendConstant();
2267 if ((BlendCoeffReferencesConstant(srcCoeff) ||
2268 BlendCoeffReferencesConstant(dstCoeff)) &&
2269 (!fHWBlendState.fConstColorValid ||
2270 fHWBlendState.fConstColor != blendConst)) {
2271 GrGLfloat c[4];
2272 GrColorToRGBAFloat(blendConst, c);
2273 GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
2274 fHWBlendState.fConstColor = blendConst;
2275 fHWBlendState.fConstColorValid = true;
2276 }
bsalomon@google.com0650e812011-04-08 18:07:53 +00002277 }
2278 }
2279}
bsalomon@google.com0a97be22011-11-08 19:20:57 +00002280
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +00002281static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) {
bsalomon@google.comb8670992012-07-25 21:27:09 +00002282 static const GrGLenum gWrapModes[] = {
2283 GR_GL_CLAMP_TO_EDGE,
2284 GR_GL_REPEAT,
2285 GR_GL_MIRRORED_REPEAT
2286 };
commit-bot@chromium.org5d7ca952013-04-22 20:26:44 +00002287 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes));
bsalomon@google.comb8670992012-07-25 21:27:09 +00002288 GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode);
2289 GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode);
2290 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode);
2291 return gWrapModes[tm];
2292}
2293
bsalomon@google.com34cccde2013-01-04 18:34:30 +00002294void GrGpuGL::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00002295 SkASSERT(NULL != texture);
tomhudson@google.comd0c1a062012-07-12 17:23:52 +00002296
bsalomon@google.comb8670992012-07-25 21:27:09 +00002297 // If we created a rt/tex and rendered to it without using a texture and now we're texturing
2298 // from the rt it will still be the last bound texture, but it needs resolving. So keep this
bsalomon@google.com4c883782012-06-04 19:05:11 +00002299 // out of the "last != next" check.
bsalomon@google.com34cccde2013-01-04 18:34:30 +00002300 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderTarget());
bsalomon@google.com4c883782012-06-04 19:05:11 +00002301 if (NULL != texRT) {
2302 this->onResolveRenderTarget(texRT);
2303 }
2304
bsalomon1c63bf62014-07-22 13:09:46 -07002305 uint32_t textureID = texture->getUniqueID();
2306 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) {
bsalomon@google.com34cccde2013-01-04 18:34:30 +00002307 this->setTextureUnit(unitIdx);
2308 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID()));
bsalomon1c63bf62014-07-22 13:09:46 -07002309 fHWBoundTextureUniqueIDs[unitIdx] = textureID;
bsalomon@google.com4c883782012-06-04 19:05:11 +00002310 }
2311
bsalomon@google.com4c883782012-06-04 19:05:11 +00002312 ResetTimestamp timestamp;
bsalomon@google.com34cccde2013-01-04 18:34:30 +00002313 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&timestamp);
bsalomon@google.com4c883782012-06-04 19:05:11 +00002314 bool setAll = timestamp < this->getResetTimestamp();
2315 GrGLTexture::TexParams newTexParams;
2316
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +00002317 static GrGLenum glMinFilterModes[] = {
commit-bot@chromium.orgcffff792013-07-26 16:36:04 +00002318 GR_GL_NEAREST,
2319 GR_GL_LINEAR,
2320 GR_GL_LINEAR_MIPMAP_LINEAR
2321 };
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +00002322 static GrGLenum glMagFilterModes[] = {
2323 GR_GL_NEAREST,
2324 GR_GL_LINEAR,
2325 GR_GL_LINEAR
2326 };
commit-bot@chromium.org47442312013-12-19 16:18:01 +00002327 GrTextureParams::FilterMode filterMode = params.filterMode();
2328 if (!this->caps()->mipMapSupport() && GrTextureParams::kMipMap_FilterMode == filterMode) {
2329 filterMode = GrTextureParams::kBilerp_FilterMode;
2330 }
2331 newTexParams.fMinFilter = glMinFilterModes[filterMode];
2332 newTexParams.fMagFilter = glMagFilterModes[filterMode];
skia.committer@gmail.comaeefb2a2013-07-27 07:01:06 +00002333
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00002334 if (GrTextureParams::kMipMap_FilterMode == filterMode &&
2335 texture->mipMapsAreDirty() && !GrPixelConfigIsCompressed(texture->config())) {
commit-bot@chromium.orgcffff792013-07-26 16:36:04 +00002336 GL_CALL(GenerateMipmap(GR_GL_TEXTURE_2D));
2337 texture->dirtyMipMaps(false);
2338 }
bsalomon@google.com4c883782012-06-04 19:05:11 +00002339
bsalomon@google.comb8670992012-07-25 21:27:09 +00002340 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX());
2341 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY());
bsalomon@google.com4c883782012-06-04 19:05:11 +00002342 memcpy(newTexParams.fSwizzleRGBA,
bsalomon@google.com34cccde2013-01-04 18:34:30 +00002343 GrGLShaderBuilder::GetTexParamSwizzle(texture->config(), this->glCaps()),
bsalomon@google.com4c883782012-06-04 19:05:11 +00002344 sizeof(newTexParams.fSwizzleRGBA));
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +00002345 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) {
bsalomon@google.com34cccde2013-01-04 18:34:30 +00002346 this->setTextureUnit(unitIdx);
bsalomon@google.com4c883782012-06-04 19:05:11 +00002347 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
2348 GR_GL_TEXTURE_MAG_FILTER,
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +00002349 newTexParams.fMagFilter));
2350 }
2351 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) {
2352 this->setTextureUnit(unitIdx);
bsalomon@google.com4c883782012-06-04 19:05:11 +00002353 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
2354 GR_GL_TEXTURE_MIN_FILTER,
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +00002355 newTexParams.fMinFilter));
bsalomon@google.com4c883782012-06-04 19:05:11 +00002356 }
2357 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) {
bsalomon@google.com34cccde2013-01-04 18:34:30 +00002358 this->setTextureUnit(unitIdx);
bsalomon@google.com4c883782012-06-04 19:05:11 +00002359 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
2360 GR_GL_TEXTURE_WRAP_S,
2361 newTexParams.fWrapS));
2362 }
2363 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) {
bsalomon@google.com34cccde2013-01-04 18:34:30 +00002364 this->setTextureUnit(unitIdx);
bsalomon@google.com4c883782012-06-04 19:05:11 +00002365 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
2366 GR_GL_TEXTURE_WRAP_T,
2367 newTexParams.fWrapT));
2368 }
2369 if (this->glCaps().textureSwizzleSupport() &&
2370 (setAll || memcmp(newTexParams.fSwizzleRGBA,
2371 oldTexParams.fSwizzleRGBA,
2372 sizeof(newTexParams.fSwizzleRGBA)))) {
bsalomon@google.com34cccde2013-01-04 18:34:30 +00002373 this->setTextureUnit(unitIdx);
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00002374 if (this->glStandard() == kGLES_GrGLStandard) {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +00002375 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA.
2376 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA;
2377 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0]));
2378 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1]));
2379 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2]));
2380 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swizzle[3]));
2381 } else {
2382 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGLint));
2383 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexParams.fSwizzleRGBA);
2384 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA, swizzle));
2385 }
bsalomon@google.com4c883782012-06-04 19:05:11 +00002386 }
bsalomon@google.com34cccde2013-01-04 18:34:30 +00002387 texture->setCachedTexParams(newTexParams, this->getResetTimestamp());
bsalomon@google.com4c883782012-06-04 19:05:11 +00002388}
2389
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002390void GrGpuGL::setProjectionMatrix(const SkMatrix& matrix,
2391 const SkISize& renderTargetSize,
2392 GrSurfaceOrigin renderTargetOrigin) {
2393
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002394 SkASSERT(this->glCaps().pathRenderingSupport());
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002395
2396 if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin &&
2397 renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize &&
2398 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) {
2399 return;
2400 }
2401
2402 fHWProjectionMatrixState.fViewMatrix = matrix;
2403 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize;
2404 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin;
2405
2406 GrGLfloat glMatrix[4 * 4];
commit-bot@chromium.org47c66dd2014-05-29 01:12:10 +00002407 fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix);
commit-bot@chromium.orgf6696722014-04-25 06:21:30 +00002408 GL_CALL(MatrixLoadf(GR_GL_PROJECTION, glMatrix));
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002409}
2410
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002411void GrGpuGL::enablePathTexGen(int unitIdx,
2412 PathTexGenComponents components,
2413 const GrGLfloat* coefficients) {
2414 SkASSERT(this->glCaps().pathRenderingSupport());
2415 SkASSERT(components >= kS_PathTexGenComponents &&
2416 components <= kSTR_PathTexGenComponents);
commit-bot@chromium.org8e919ad2013-10-21 14:48:23 +00002417 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= unitIdx);
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002418
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002419 if (GR_GL_OBJECT_LINEAR == fHWPathTexGenSettings[unitIdx].fMode &&
2420 components == fHWPathTexGenSettings[unitIdx].fNumComponents &&
2421 !memcmp(coefficients, fHWPathTexGenSettings[unitIdx].fCoefficients,
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002422 3 * components * sizeof(GrGLfloat))) {
2423 return;
2424 }
2425
2426 this->setTextureUnit(unitIdx);
2427
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002428 fHWPathTexGenSettings[unitIdx].fNumComponents = components;
2429 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + unitIdx,
2430 GR_GL_OBJECT_LINEAR,
2431 components,
2432 coefficients));
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002433
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002434 memcpy(fHWPathTexGenSettings[unitIdx].fCoefficients, coefficients,
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002435 3 * components * sizeof(GrGLfloat));
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002436}
2437
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002438void GrGpuGL::enablePathTexGen(int unitIdx, PathTexGenComponents components,
2439 const SkMatrix& matrix) {
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002440 GrGLfloat coefficients[3 * 3];
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002441 SkASSERT(this->glCaps().pathRenderingSupport());
2442 SkASSERT(components >= kS_PathTexGenComponents &&
2443 components <= kSTR_PathTexGenComponents);
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002444
2445 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]);
2446 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]);
2447 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]);
2448
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002449 if (components >= kST_PathTexGenComponents) {
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002450 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]);
2451 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]);
2452 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]);
2453 }
2454
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002455 if (components >= kSTR_PathTexGenComponents) {
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002456 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]);
2457 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]);
2458 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]);
2459 }
2460
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002461 enablePathTexGen(unitIdx, components, coefficients);
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002462}
2463
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002464void GrGpuGL::flushPathTexGenSettings(int numUsedTexCoordSets) {
2465 SkASSERT(this->glCaps().pathRenderingSupport());
commit-bot@chromium.org8e919ad2013-10-21 14:48:23 +00002466 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= numUsedTexCoordSets);
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002467
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002468 // Only write the inactive path tex gens, since active path tex gens were
2469 // written when they were enabled.
commit-bot@chromium.org20807222013-11-01 11:54:54 +00002470
2471 SkDEBUGCODE(
2472 for (int i = 0; i < numUsedTexCoordSets; i++) {
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002473 SkASSERT(0 != fHWPathTexGenSettings[i].fNumComponents);
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002474 }
commit-bot@chromium.org20807222013-11-01 11:54:54 +00002475 );
2476
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002477 for (int i = numUsedTexCoordSets; i < fHWActivePathTexGenSets; i++) {
2478 SkASSERT(0 != fHWPathTexGenSettings[i].fNumComponents);
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002479
2480 this->setTextureUnit(i);
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002481 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL));
2482 fHWPathTexGenSettings[i].fNumComponents = 0;
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002483 }
2484
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +00002485 fHWActivePathTexGenSets = numUsedTexCoordSets;
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +00002486}
2487
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +00002488void GrGpuGL::flushMiscFixedFunctionState() {
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +00002489
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +00002490 const GrDrawState& drawState = this->getDrawState();
reed@google.comac10a2d2010-12-22 21:39:39 +00002491
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +00002492 if (drawState.isDitherState()) {
bsalomon@google.com978c8c62012-05-21 14:45:49 +00002493 if (kYes_TriState != fHWDitherEnabled) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00002494 GL_CALL(Enable(GR_GL_DITHER));
bsalomon@google.com978c8c62012-05-21 14:45:49 +00002495 fHWDitherEnabled = kYes_TriState;
2496 }
2497 } else {
2498 if (kNo_TriState != fHWDitherEnabled) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00002499 GL_CALL(Disable(GR_GL_DITHER));
bsalomon@google.com978c8c62012-05-21 14:45:49 +00002500 fHWDitherEnabled = kNo_TriState;
reed@google.comac10a2d2010-12-22 21:39:39 +00002501 }
2502 }
2503
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +00002504 if (drawState.isColorWriteDisabled()) {
bsalomon@google.com978c8c62012-05-21 14:45:49 +00002505 if (kNo_TriState != fHWWriteToColor) {
2506 GL_CALL(ColorMask(GR_GL_FALSE, GR_GL_FALSE,
2507 GR_GL_FALSE, GR_GL_FALSE));
2508 fHWWriteToColor = kNo_TriState;
bsalomon@google.comd302f142011-03-03 13:54:13 +00002509 }
bsalomon@google.com978c8c62012-05-21 14:45:49 +00002510 } else {
2511 if (kYes_TriState != fHWWriteToColor) {
2512 GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
2513 fHWWriteToColor = kYes_TriState;
2514 }
bsalomon@google.comd302f142011-03-03 13:54:13 +00002515 }
2516
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +00002517 if (fHWDrawFace != drawState.getDrawFace()) {
bsalomon@google.coma5d056a2012-03-27 15:59:58 +00002518 switch (this->getDrawState().getDrawFace()) {
tomhudson@google.com93813632011-10-27 20:21:16 +00002519 case GrDrawState::kCCW_DrawFace:
bsalomon@google.com0b77d682011-08-19 13:28:54 +00002520 GL_CALL(Enable(GR_GL_CULL_FACE));
2521 GL_CALL(CullFace(GR_GL_BACK));
bsalomon@google.comd302f142011-03-03 13:54:13 +00002522 break;
tomhudson@google.com93813632011-10-27 20:21:16 +00002523 case GrDrawState::kCW_DrawFace:
bsalomon@google.com0b77d682011-08-19 13:28:54 +00002524 GL_CALL(Enable(GR_GL_CULL_FACE));
2525 GL_CALL(CullFace(GR_GL_FRONT));
bsalomon@google.comd302f142011-03-03 13:54:13 +00002526 break;
tomhudson@google.com93813632011-10-27 20:21:16 +00002527 case GrDrawState::kBoth_DrawFace:
bsalomon@google.com0b77d682011-08-19 13:28:54 +00002528 GL_CALL(Disable(GR_GL_CULL_FACE));
bsalomon@google.comd302f142011-03-03 13:54:13 +00002529 break;
2530 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00002531 SkFAIL("Unknown draw face.");
bsalomon@google.comd302f142011-03-03 13:54:13 +00002532 }
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +00002533 fHWDrawFace = drawState.getDrawFace();
bsalomon@google.comd302f142011-03-03 13:54:13 +00002534 }
reed@google.comac10a2d2010-12-22 21:39:39 +00002535}
2536
cdalton51192342014-06-09 11:16:58 -07002537GrGLuint GrGpuGL::createGLPathObject() {
2538 if (NULL == fPathNameAllocator.get()) {
2539 static const int range = 65536;
2540 GrGLuint firstName;
2541 GL_CALL_RET(firstName, GenPaths(range));
2542 fPathNameAllocator.reset(SkNEW_ARGS(GrGLNameAllocator, (firstName, firstName + range)));
2543 }
2544
2545 GrGLuint name = fPathNameAllocator->allocateName();
2546 if (0 == name) {
2547 // Our reserved path names are all in use. Fall back on GenPaths.
2548 GL_CALL_RET(name, GenPaths(1));
2549 }
2550
2551 return name;
2552}
2553
2554void GrGpuGL::deleteGLPathObject(GrGLuint name) {
2555 if (NULL == fPathNameAllocator.get() ||
2556 name < fPathNameAllocator->firstName() ||
2557 name >= fPathNameAllocator->endName()) {
2558 // If we aren't inside fPathNameAllocator's range then this name was
2559 // generated by the GenPaths fallback (or else the name is unallocated).
2560 GL_CALL(DeletePaths(name, 1));
2561 return;
2562 }
2563
2564 // Make the path empty to save memory, but don't free the name in the driver.
2565 GL_CALL(PathCommands(name, 0, NULL, 0, GR_GL_FLOAT, NULL));
2566 fPathNameAllocator->free(name);
2567}
2568
bsalomon@google.com280e99f2012-01-05 16:17:38 +00002569bool GrGpuGL::configToGLFormats(GrPixelConfig config,
2570 bool getSizedInternalFormat,
2571 GrGLenum* internalFormat,
2572 GrGLenum* externalFormat,
2573 GrGLenum* externalType) {
2574 GrGLenum dontCare;
2575 if (NULL == internalFormat) {
2576 internalFormat = &dontCare;
2577 }
2578 if (NULL == externalFormat) {
2579 externalFormat = &dontCare;
2580 }
2581 if (NULL == externalType) {
2582 externalType = &dontCare;
2583 }
2584
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00002585 if(!this->glCaps().isConfigTexturable(config)) {
2586 return false;
2587 }
2588
reed@google.comac10a2d2010-12-22 21:39:39 +00002589 switch (config) {
bsalomon@google.com0342a852012-08-20 19:22:38 +00002590 case kRGBA_8888_GrPixelConfig:
bsalomon@google.comc4364992011-11-07 15:54:49 +00002591 *internalFormat = GR_GL_RGBA;
bsalomon@google.com32e4d2a2011-12-09 16:14:25 +00002592 *externalFormat = GR_GL_RGBA;
bsalomon@google.com280e99f2012-01-05 16:17:38 +00002593 if (getSizedInternalFormat) {
2594 *internalFormat = GR_GL_RGBA8;
2595 } else {
2596 *internalFormat = GR_GL_RGBA;
2597 }
bsalomon@google.com6f379512011-11-16 20:36:03 +00002598 *externalType = GR_GL_UNSIGNED_BYTE;
bsalomon@google.comc4364992011-11-07 15:54:49 +00002599 break;
bsalomon@google.com0342a852012-08-20 19:22:38 +00002600 case kBGRA_8888_GrPixelConfig:
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00002601 if (this->glCaps().bgraIsInternalFormat()) {
bsalomon@google.com280e99f2012-01-05 16:17:38 +00002602 if (getSizedInternalFormat) {
2603 *internalFormat = GR_GL_BGRA8;
2604 } else {
2605 *internalFormat = GR_GL_BGRA;
2606 }
twiz@google.comb65e0cb2011-03-18 20:41:44 +00002607 } else {
bsalomon@google.com280e99f2012-01-05 16:17:38 +00002608 if (getSizedInternalFormat) {
2609 *internalFormat = GR_GL_RGBA8;
2610 } else {
2611 *internalFormat = GR_GL_RGBA;
2612 }
twiz@google.comb65e0cb2011-03-18 20:41:44 +00002613 }
bsalomon@google.com32e4d2a2011-12-09 16:14:25 +00002614 *externalFormat = GR_GL_BGRA;
bsalomon@google.com6f379512011-11-16 20:36:03 +00002615 *externalType = GR_GL_UNSIGNED_BYTE;
reed@google.comac10a2d2010-12-22 21:39:39 +00002616 break;
bsalomon@google.com669fdc42011-04-05 17:08:27 +00002617 case kRGB_565_GrPixelConfig:
twiz@google.com0f31ca72011-03-18 17:38:11 +00002618 *internalFormat = GR_GL_RGB;
bsalomon@google.com32e4d2a2011-12-09 16:14:25 +00002619 *externalFormat = GR_GL_RGB;
bsalomon@google.com280e99f2012-01-05 16:17:38 +00002620 if (getSizedInternalFormat) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00002621 if (this->glStandard() == kGL_GrGLStandard) {
bsalomon@google.com280e99f2012-01-05 16:17:38 +00002622 return false;
2623 } else {
2624 *internalFormat = GR_GL_RGB565;
2625 }
2626 } else {
2627 *internalFormat = GR_GL_RGB;
2628 }
bsalomon@google.com6f379512011-11-16 20:36:03 +00002629 *externalType = GR_GL_UNSIGNED_SHORT_5_6_5;
reed@google.comac10a2d2010-12-22 21:39:39 +00002630 break;
bsalomon@google.com669fdc42011-04-05 17:08:27 +00002631 case kRGBA_4444_GrPixelConfig:
twiz@google.com0f31ca72011-03-18 17:38:11 +00002632 *internalFormat = GR_GL_RGBA;
bsalomon@google.com32e4d2a2011-12-09 16:14:25 +00002633 *externalFormat = GR_GL_RGBA;
bsalomon@google.com280e99f2012-01-05 16:17:38 +00002634 if (getSizedInternalFormat) {
2635 *internalFormat = GR_GL_RGBA4;
2636 } else {
2637 *internalFormat = GR_GL_RGBA;
2638 }
bsalomon@google.com6f379512011-11-16 20:36:03 +00002639 *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
reed@google.comac10a2d2010-12-22 21:39:39 +00002640 break;
bsalomon@google.com669fdc42011-04-05 17:08:27 +00002641 case kIndex_8_GrPixelConfig:
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00002642 // glCompressedTexImage doesn't take external params
2643 *externalFormat = GR_GL_PALETTE8_RGBA8;
2644 // no sized/unsized internal format distinction here
2645 *internalFormat = GR_GL_PALETTE8_RGBA8;
2646 // unused with CompressedTexImage
2647 *externalType = GR_GL_UNSIGNED_BYTE;
reed@google.comac10a2d2010-12-22 21:39:39 +00002648 break;
bsalomon@google.com669fdc42011-04-05 17:08:27 +00002649 case kAlpha_8_GrPixelConfig:
robertphillips@google.com443e5a52012-04-30 20:01:21 +00002650 if (this->glCaps().textureRedSupport()) {
2651 *internalFormat = GR_GL_RED;
2652 *externalFormat = GR_GL_RED;
2653 if (getSizedInternalFormat) {
2654 *internalFormat = GR_GL_R8;
2655 } else {
2656 *internalFormat = GR_GL_RED;
2657 }
2658 *externalType = GR_GL_UNSIGNED_BYTE;
bsalomon@google.com280e99f2012-01-05 16:17:38 +00002659 } else {
2660 *internalFormat = GR_GL_ALPHA;
robertphillips@google.com443e5a52012-04-30 20:01:21 +00002661 *externalFormat = GR_GL_ALPHA;
2662 if (getSizedInternalFormat) {
2663 *internalFormat = GR_GL_ALPHA8;
2664 } else {
2665 *internalFormat = GR_GL_ALPHA;
2666 }
2667 *externalType = GR_GL_UNSIGNED_BYTE;
bsalomon@google.com280e99f2012-01-05 16:17:38 +00002668 }
reed@google.comac10a2d2010-12-22 21:39:39 +00002669 break;
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00002670 case kETC1_GrPixelConfig:
2671 *internalFormat = GR_GL_COMPRESSED_RGB8_ETC1;
2672 break;
2673 case kLATC_GrPixelConfig:
2674 switch(this->glCaps().latcAlias()) {
2675 case GrGLCaps::kLATC_LATCAlias:
2676 *internalFormat = GR_GL_COMPRESSED_LUMINANCE_LATC1;
2677 break;
2678 case GrGLCaps::kRGTC_LATCAlias:
2679 *internalFormat = GR_GL_COMPRESSED_RED_RGTC1;
2680 break;
2681 case GrGLCaps::k3DC_LATCAlias:
2682 *internalFormat = GR_GL_COMPRESSED_3DC_X;
2683 break;
2684 }
2685 break;
krajcevski238b4562014-06-30 09:09:22 -07002686 case kR11_EAC_GrPixelConfig:
2687 *internalFormat = GR_GL_COMPRESSED_R11;
2688 break;
krajcevski7ef21622014-07-16 15:21:13 -07002689
2690 case kASTC_12x12_GrPixelConfig:
2691 *internalFormat = GR_GL_COMPRESSED_RGBA_ASTC_12x12;
2692 break;
2693
joshualittee5da552014-07-16 13:32:56 -07002694 case kRGBA_float_GrPixelConfig:
2695 *internalFormat = GR_GL_RGBA32F;
2696 *externalFormat = GR_GL_RGBA;
2697 *externalType = GR_GL_FLOAT;
2698 break;
krajcevski7ef21622014-07-16 15:21:13 -07002699
reed@google.comac10a2d2010-12-22 21:39:39 +00002700 default:
2701 return false;
2702 }
2703 return true;
2704}
2705
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00002706void GrGpuGL::setTextureUnit(int unit) {
bsalomon1c63bf62014-07-22 13:09:46 -07002707 SkASSERT(unit >= 0 && unit < fHWBoundTextureUniqueIDs.count());
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +00002708 if (unit != fHWActiveTextureUnitIdx) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00002709 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit));
bsalomon@google.com49209392012-06-05 15:13:46 +00002710 fHWActiveTextureUnitIdx = unit;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00002711 }
2712}
bsalomon@google.com316f99232011-01-13 21:28:12 +00002713
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +00002714void GrGpuGL::setScratchTextureUnit() {
2715 // Bind the last texture unit since it is the least likely to be used by GrGLProgram.
bsalomon1c63bf62014-07-22 13:09:46 -07002716 int lastUnitIdx = fHWBoundTextureUniqueIDs.count() - 1;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +00002717 if (lastUnitIdx != fHWActiveTextureUnitIdx) {
2718 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + lastUnitIdx));
2719 fHWActiveTextureUnitIdx = lastUnitIdx;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00002720 }
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +00002721 // clear out the this field so that if a program does use this unit it will rebind the correct
2722 // texture.
bsalomon1c63bf62014-07-22 13:09:46 -07002723 fHWBoundTextureUniqueIDs[lastUnitIdx] = SK_InvalidUniqueID;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00002724}
2725
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002726namespace {
2727// Determines whether glBlitFramebuffer could be used between src and dst.
bsalomon@google.comeb851172013-04-15 13:51:00 +00002728inline bool can_blit_framebuffer(const GrSurface* dst,
2729 const GrSurface* src,
2730 const GrGpuGL* gpu,
2731 bool* wouldNeedTempFBO = NULL) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +00002732 if (gpu->glCaps().isConfigRenderable(dst->config(), dst->desc().fSampleCnt > 0) &&
2733 gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt > 0) &&
bsalomon@google.com347c3822013-05-01 20:10:01 +00002734 gpu->glCaps().usesMSAARenderBuffers()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00002735 // ES3 doesn't allow framebuffer blits when the src has MSAA and the configs don't match
2736 // or the rects are not the same (not just the same size but have the same edges).
2737 if (GrGLCaps::kES_3_0_MSFBOType == gpu->glCaps().msFBOType() &&
2738 (src->desc().fSampleCnt > 0 || src->config() != dst->config())) {
2739 return false;
2740 }
bsalomon@google.comeb851172013-04-15 13:51:00 +00002741 if (NULL != wouldNeedTempFBO) {
2742 *wouldNeedTempFBO = NULL == dst->asRenderTarget() || NULL == src->asRenderTarget();
2743 }
2744 return true;
2745 } else {
2746 return false;
2747 }
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002748}
bsalomon@google.comeb851172013-04-15 13:51:00 +00002749
2750inline bool can_copy_texsubimage(const GrSurface* dst,
2751 const GrSurface* src,
2752 const GrGpuGL* gpu,
2753 bool* wouldNeedTempFBO = NULL) {
2754 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2755 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2756 // many drivers would allow it to work, but ANGLE does not.
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00002757 if (kGLES_GrGLStandard == gpu->glStandard() && gpu->glCaps().bgraIsInternalFormat() &&
bsalomon@google.comeb851172013-04-15 13:51:00 +00002758 (kBGRA_8888_GrPixelConfig == dst->config() || kBGRA_8888_GrPixelConfig == src->config())) {
2759 return false;
2760 }
2761 const GrGLRenderTarget* dstRT = static_cast<const GrGLRenderTarget*>(dst->asRenderTarget());
2762 // If dst is multisampled (and uses an extension where there is a separate MSAA renderbuffer)
2763 // then we don't want to copy to the texture but to the MSAA buffer.
2764 if (NULL != dstRT && dstRT->renderFBOID() != dstRT->textureFBOID()) {
2765 return false;
2766 }
bsalomon@google.coma2719852013-04-17 14:25:27 +00002767 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->asRenderTarget());
2768 // If the src is multisampled (and uses an extension where there is a separate MSAA
2769 // renderbuffer) then it is an invalid operation to call CopyTexSubImage
2770 if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) {
2771 return false;
2772 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +00002773 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt > 0) &&
2774 NULL != dst->asTexture() &&
2775 dst->origin() == src->origin() &&
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00002776 kIndex_8_GrPixelConfig != src->config() &&
2777 !GrPixelConfigIsCompressed(src->config())) {
bsalomon@google.comeb851172013-04-15 13:51:00 +00002778 if (NULL != wouldNeedTempFBO) {
2779 *wouldNeedTempFBO = NULL == src->asRenderTarget();
2780 }
2781 return true;
2782 } else {
2783 return false;
2784 }
2785}
2786
2787// If a temporary FBO was created, its non-zero ID is returned. The viewport that the copy rect is
2788// relative to is output.
2789inline GrGLuint bind_surface_as_fbo(const GrGLInterface* gl,
2790 GrSurface* surface,
2791 GrGLenum fboTarget,
2792 GrGLIRect* viewport) {
2793 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarget());
2794 GrGLuint tempFBOID;
2795 if (NULL == rt) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00002796 SkASSERT(NULL != surface->asTexture());
bsalomon@google.comeb851172013-04-15 13:51:00 +00002797 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textureID();
2798 GR_GL_CALL(gl, GenFramebuffers(1, &tempFBOID));
2799 GR_GL_CALL(gl, BindFramebuffer(fboTarget, tempFBOID));
2800 GR_GL_CALL(gl, FramebufferTexture2D(fboTarget,
2801 GR_GL_COLOR_ATTACHMENT0,
2802 GR_GL_TEXTURE_2D,
2803 texID,
2804 0));
2805 viewport->fLeft = 0;
2806 viewport->fBottom = 0;
2807 viewport->fWidth = surface->width();
2808 viewport->fHeight = surface->height();
2809 } else {
2810 tempFBOID = 0;
2811 GR_GL_CALL(gl, BindFramebuffer(fboTarget, rt->renderFBOID()));
2812 *viewport = rt->getViewport();
2813 }
2814 return tempFBOID;
2815}
2816
2817}
2818
2819void GrGpuGL::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) {
2820 // Check for format issues with glCopyTexSubImage2D
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00002821 if (kGLES_GrGLStandard == this->glStandard() && this->glCaps().bgraIsInternalFormat() &&
bsalomon@google.comeb851172013-04-15 13:51:00 +00002822 kBGRA_8888_GrPixelConfig == src->config()) {
2823 // glCopyTexSubImage2D doesn't work with this config. We'll want to make it a render target
bsalomon@google.com31c4e892013-04-15 13:55:02 +00002824 // in order to call glBlitFramebuffer or to copy to it by rendering.
bsalomon@google.comeb851172013-04-15 13:51:00 +00002825 INHERITED::initCopySurfaceDstDesc(src, desc);
bsalomon@google.coma2719852013-04-17 14:25:27 +00002826 return;
bsalomon@google.comeb851172013-04-15 13:51:00 +00002827 } else if (NULL == src->asRenderTarget()) {
2828 // We don't want to have to create an FBO just to use glCopyTexSubImage2D. Let the base
2829 // class handle it by rendering.
2830 INHERITED::initCopySurfaceDstDesc(src, desc);
bsalomon@google.coma2719852013-04-17 14:25:27 +00002831 return;
2832 }
2833
2834 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->asRenderTarget());
2835 if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) {
2836 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer.
2837 INHERITED::initCopySurfaceDstDesc(src, desc);
bsalomon@google.comeb851172013-04-15 13:51:00 +00002838 } else {
2839 desc->fConfig = src->config();
2840 desc->fOrigin = src->origin();
2841 desc->fFlags = kNone_GrTextureFlags;
2842 }
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002843}
2844
2845bool GrGpuGL::onCopySurface(GrSurface* dst,
2846 GrSurface* src,
2847 const SkIRect& srcRect,
2848 const SkIPoint& dstPoint) {
bsalomon@google.comeb851172013-04-15 13:51:00 +00002849 bool inheritedCouldCopy = INHERITED::onCanCopySurface(dst, src, srcRect, dstPoint);
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002850 bool copied = false;
bsalomon@google.comeb851172013-04-15 13:51:00 +00002851 bool wouldNeedTempFBO = false;
2852 if (can_copy_texsubimage(dst, src, this, &wouldNeedTempFBO) &&
2853 (!wouldNeedTempFBO || !inheritedCouldCopy)) {
2854 GrGLuint srcFBO;
2855 GrGLIRect srcVP;
2856 srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_FRAMEBUFFER, &srcVP);
2857 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture());
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00002858 SkASSERT(NULL != dstTex);
bsalomon@google.comeb851172013-04-15 13:51:00 +00002859 // We modified the bound FBO
bsalomon1c63bf62014-07-22 13:09:46 -07002860 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
bsalomon@google.comeb851172013-04-15 13:51:00 +00002861 GrGLIRect srcGLRect;
2862 srcGLRect.setRelativeTo(srcVP,
2863 srcRect.fLeft,
2864 srcRect.fTop,
2865 srcRect.width(),
2866 srcRect.height(),
2867 src->origin());
2868
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +00002869 this->setScratchTextureUnit();
bsalomon@google.comeb851172013-04-15 13:51:00 +00002870 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID()));
2871 GrGLint dstY;
2872 if (kBottomLeft_GrSurfaceOrigin == dst->origin()) {
2873 dstY = dst->height() - (dstPoint.fY + srcGLRect.fHeight);
2874 } else {
2875 dstY = dstPoint.fY;
2876 }
2877 GL_CALL(CopyTexSubImage2D(GR_GL_TEXTURE_2D, 0,
2878 dstPoint.fX, dstY,
2879 srcGLRect.fLeft, srcGLRect.fBottom,
2880 srcGLRect.fWidth, srcGLRect.fHeight));
2881 copied = true;
2882 if (srcFBO) {
2883 GL_CALL(DeleteFramebuffers(1, &srcFBO));
2884 }
2885 } else if (can_blit_framebuffer(dst, src, this, &wouldNeedTempFBO) &&
2886 (!wouldNeedTempFBO || !inheritedCouldCopy)) {
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002887 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY,
2888 srcRect.width(), srcRect.height());
2889 bool selfOverlap = false;
2890 if (dst->isSameAs(src)) {
2891 selfOverlap = SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect);
2892 }
2893
2894 if (!selfOverlap) {
bsalomon@google.comeb851172013-04-15 13:51:00 +00002895 GrGLuint dstFBO;
2896 GrGLuint srcFBO;
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002897 GrGLIRect dstVP;
2898 GrGLIRect srcVP;
bsalomon@google.comeb851172013-04-15 13:51:00 +00002899 dstFBO = bind_surface_as_fbo(this->glInterface(), dst, GR_GL_DRAW_FRAMEBUFFER, &dstVP);
2900 srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_READ_FRAMEBUFFER, &srcVP);
2901 // We modified the bound FBO
bsalomon1c63bf62014-07-22 13:09:46 -07002902 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002903 GrGLIRect srcGLRect;
2904 GrGLIRect dstGLRect;
2905 srcGLRect.setRelativeTo(srcVP,
2906 srcRect.fLeft,
2907 srcRect.fTop,
2908 srcRect.width(),
2909 srcRect.height(),
2910 src->origin());
2911 dstGLRect.setRelativeTo(dstVP,
2912 dstRect.fLeft,
2913 dstRect.fTop,
2914 dstRect.width(),
2915 dstRect.height(),
2916 dst->origin());
2917
2918 GrAutoTRestore<ScissorState> asr;
bsalomon@google.com347c3822013-05-01 20:10:01 +00002919 if (GrGLCaps::kDesktop_EXT_MSFBOType == this->glCaps().msFBOType()) {
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002920 // The EXT version applies the scissor during the blit, so disable it.
2921 asr.reset(&fScissorState);
2922 fScissorState.fEnabled = false;
2923 this->flushScissor();
2924 }
2925 GrGLint srcY0;
2926 GrGLint srcY1;
2927 // Does the blit need to y-mirror or not?
2928 if (src->origin() == dst->origin()) {
2929 srcY0 = srcGLRect.fBottom;
2930 srcY1 = srcGLRect.fBottom + srcGLRect.fHeight;
2931 } else {
2932 srcY0 = srcGLRect.fBottom + srcGLRect.fHeight;
2933 srcY1 = srcGLRect.fBottom;
2934 }
2935 GL_CALL(BlitFramebuffer(srcGLRect.fLeft,
2936 srcY0,
2937 srcGLRect.fLeft + srcGLRect.fWidth,
2938 srcY1,
2939 dstGLRect.fLeft,
2940 dstGLRect.fBottom,
2941 dstGLRect.fLeft + dstGLRect.fWidth,
2942 dstGLRect.fBottom + dstGLRect.fHeight,
2943 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
2944 if (dstFBO) {
2945 GL_CALL(DeleteFramebuffers(1, &dstFBO));
2946 }
2947 if (srcFBO) {
2948 GL_CALL(DeleteFramebuffers(1, &srcFBO));
2949 }
2950 copied = true;
2951 }
2952 }
bsalomon@google.comeb851172013-04-15 13:51:00 +00002953 if (!copied && inheritedCouldCopy) {
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002954 copied = INHERITED::onCopySurface(dst, src, srcRect, dstPoint);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00002955 SkASSERT(copied);
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002956 }
2957 return copied;
2958}
2959
2960bool GrGpuGL::onCanCopySurface(GrSurface* dst,
2961 GrSurface* src,
2962 const SkIRect& srcRect,
2963 const SkIPoint& dstPoint) {
2964 // This mirrors the logic in onCopySurface.
bsalomon@google.comeb851172013-04-15 13:51:00 +00002965 if (can_copy_texsubimage(dst, src, this)) {
2966 return true;
2967 }
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002968 if (can_blit_framebuffer(dst, src, this)) {
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002969 if (dst->isSameAs(src)) {
bsalomon@google.comeb851172013-04-15 13:51:00 +00002970 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY,
2971 srcRect.width(), srcRect.height());
2972 if(!SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect)) {
2973 return true;
2974 }
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002975 } else {
bsalomon@google.comeb851172013-04-15 13:51:00 +00002976 return true;
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002977 }
2978 }
bsalomon@google.comeb851172013-04-15 13:51:00 +00002979 return INHERITED::onCanCopySurface(dst, src, srcRect, dstPoint);
commit-bot@chromium.org63150af2013-04-11 22:00:22 +00002980}
2981
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +00002982void GrGpuGL::didAddGpuTraceMarker() {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00002983 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +00002984 const GrTraceMarkerSet& markerArray = this->getActiveTraceMarkers();
egdanield78a1682014-07-09 10:41:26 -07002985 SkString markerString = markerArray.toStringLast();
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +00002986 GL_CALL(PushGroupMarker(0, markerString.c_str()));
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00002987 }
2988}
2989
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +00002990void GrGpuGL::didRemoveGpuTraceMarker() {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00002991 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +00002992 GL_CALL(PopGroupMarker());
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00002993 }
2994}
bsalomon@google.com880b8fc2013-02-19 20:17:28 +00002995///////////////////////////////////////////////////////////////////////////////
2996
bsalomon@google.com6918d482013-03-07 19:09:11 +00002997GrGLAttribArrayState* GrGpuGL::HWGeometryState::bindArrayAndBuffersToDraw(
2998 GrGpuGL* gpu,
2999 const GrGLVertexBuffer* vbuffer,
3000 const GrGLIndexBuffer* ibuffer) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00003001 SkASSERT(NULL != vbuffer);
robertphillips@google.com4f65a272013-03-26 19:40:46 +00003002 GrGLAttribArrayState* attribState;
3003
bsalomon@google.com6918d482013-03-07 19:09:11 +00003004 // We use a vertex array if we're on a core profile and the verts are in a VBO.
3005 if (gpu->glCaps().isCoreProfile() && !vbuffer->isCPUBacked()) {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +00003006 if (NULL == fVBOVertexArray || fVBOVertexArray->wasDestroyed()) {
bsalomon@google.com6918d482013-03-07 19:09:11 +00003007 SkSafeUnref(fVBOVertexArray);
3008 GrGLuint arrayID;
3009 GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID));
3010 int attrCount = gpu->glCaps().maxVertexAttributes();
3011 fVBOVertexArray = SkNEW_ARGS(GrGLVertexArray, (gpu, arrayID, attrCount));
bsalomon@google.com880b8fc2013-02-19 20:17:28 +00003012 }
bsalomon@google.com6918d482013-03-07 19:09:11 +00003013 attribState = fVBOVertexArray->bindWithIndexBuffer(ibuffer);
3014 } else {
3015 if (NULL != ibuffer) {
3016 this->setIndexBufferIDOnDefaultVertexArray(gpu, ibuffer->bufferID());
3017 } else {
3018 this->setVertexArrayID(gpu, 0);
3019 }
3020 int attrCount = gpu->glCaps().maxVertexAttributes();
3021 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3022 fDefaultVertexArrayAttribState.resize(attrCount);
3023 }
3024 attribState = &fDefaultVertexArrayAttribState;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +00003025 }
bsalomon@google.com6918d482013-03-07 19:09:11 +00003026 return attribState;
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +00003027}