'<(skia_src_path)/gpu/GrGpu.cpp',
'<(skia_src_path)/gpu/GrGpu.h',
'<(skia_src_path)/gpu/GrGpuFactory.cpp',
- '<(skia_src_path)/gpu/GrGpuVertex.h',
'<(skia_src_path)/gpu/GrIndexBuffer.h',
'<(skia_src_path)/gpu/GrInOrderDrawBuffer.cpp',
'<(skia_src_path)/gpu/GrInOrderDrawBuffer.h',
#endif
#endif
-#if !defined(GR_TEXT_SCALAR_TYPE_IS_USHORT)
- #define GR_TEXT_SCALAR_TYPE_IS_USHORT 0
-#endif
-#if !defined(GR_TEXT_SCALAR_TYPE_IS_FLOAT)
- #define GR_TEXT_SCALAR_TYPE_IS_FLOAT 0
-#endif
-#if !defined(GR_TEXT_SCALAR_TYPE_IS_FIXED)
- #define GR_TEXT_SCALAR_TYPE_IS_FIXED 0
-#endif
-
/**
* GR_GEOM_BUFFER_LOCK_THRESHOLD gives a threshold (in bytes) for when Gr should
* lock a GrGeometryBuffer to update its contents. It will use lock() if the
#error "More than one GR_BUILD defined"
#endif
-
-#if !GR_TEXT_SCALAR_IS_FLOAT && \
- !GR_TEXT_SCALAR_IS_FIXED && \
- !GR_TEXT_SCALAR_IS_USHORT
- #undef GR_TEXT_SCALAR_IS_FLOAT
- #define GR_TEXT_SCALAR_IS_FLOAT 1
- #pragma message GR_WARN("Text scalar type not defined, defaulting to float")
-#endif
-
#if 0
#if GR_WIN32_BUILD
// #pragma message GR_WARN("GR_WIN32_BUILD")
#include "GrGlyph.h"
#include "GrPaint.h"
-struct GrGpuTextVertex;
class GrContext;
class GrTextStrike;
class GrFontScaler;
kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
};
- GrGpuTextVertex* fVertices;
-
+ SkPoint* fVertices;
int32_t fMaxVertices;
GrTexture* fCurrTexture;
int fCurrVertex;
*/
//#define GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT 96
-///////////////////////////////////////////////////////////////////////////////
-// Decide Ganesh types
-
-#define GR_TEXT_SCALAR_IS_USHORT 0
-#define GR_TEXT_SCALAR_IS_FIXED 0
-#define GR_TEXT_SCALAR_IS_FLOAT 1
-
#endif
*/
#include "GrDrawState.h"
-
-#include "GrGpuVertex.h"
#include "GrPaint.h"
void GrDrawState::setFromPaint(const GrPaint& paint) {
} //unnamed namespace
+static const size_t kVec2Size = sizeof(GrPoint);
+
size_t GrDrawState::VertexSize(GrVertexLayout vertexLayout) {
GrAssert(check_layout(vertexLayout));
- size_t vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
- sizeof(GrGpuTextVertex) :
- sizeof(GrPoint);
-
- size_t size = vecSize; // position
- size += num_tex_coords(vertexLayout) * vecSize;
+ size_t size = kVec2Size; // position
+ size += num_tex_coords(vertexLayout) * kVec2Size;
if (vertexLayout & kColor_VertexLayoutBit) {
size += sizeof(GrColor);
}
int tcIdx = VertexTexCoordsForStage(stageIdx, vertexLayout);
if (tcIdx >= 0) {
- int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
- sizeof(GrGpuTextVertex) :
- sizeof(GrPoint);
- int offset = vecSize; // position
+ int offset = kVec2Size; // position
// figure out how many tex coordinates are present and precede this one.
for (int t = 0; t < tcIdx; ++t) {
if (gTexCoordMasks[t] & vertexLayout) {
- offset += vecSize;
+ offset += kVec2Size;
}
}
return offset;
GrAssert(check_layout(vertexLayout));
if (vertexLayout & kColor_VertexLayoutBit) {
- int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
- sizeof(GrGpuTextVertex) :
- sizeof(GrPoint);
- return vecSize * (num_tex_coords(vertexLayout) + 1); //+1 for pos
+ return kVec2Size * (num_tex_coords(vertexLayout) + 1); //+1 for pos
}
return -1;
}
GrAssert(check_layout(vertexLayout));
if (vertexLayout & kCoverage_VertexLayoutBit) {
- int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
- sizeof(GrGpuTextVertex) :
- sizeof(GrPoint);
-
- int offset = vecSize * (num_tex_coords(vertexLayout) + 1);
+ int offset = kVec2Size * (num_tex_coords(vertexLayout) + 1);
if (vertexLayout & kColor_VertexLayoutBit) {
offset += sizeof(GrColor);
}
// edge pts are after the pos, tex coords, and color
if (vertexLayout & kEdge_VertexLayoutBit) {
- int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
- sizeof(GrGpuTextVertex) :
- sizeof(GrPoint);
- int offset = vecSize * (num_tex_coords(vertexLayout) + 1); //+1 for pos
+ int offset = kVec2Size * (num_tex_coords(vertexLayout) + 1); //+1 for pos
if (vertexLayout & kColor_VertexLayoutBit) {
offset += sizeof(GrColor);
}
int* edgeOffset) {
GrAssert(check_layout(vertexLayout));
- int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
- sizeof(GrGpuTextVertex) :
- sizeof(GrPoint);
- int size = vecSize; // position
+ int size = kVec2Size; // position
for (int t = 0; t < kMaxTexCoords; ++t) {
if (gTexCoordMasks[t] & vertexLayout) {
if (NULL != texCoordOffsetsByIdx) {
texCoordOffsetsByIdx[t] = size;
}
- size += vecSize;
+ size += kVec2Size;
} else {
if (NULL != texCoordOffsetsByIdx) {
texCoordOffsetsByIdx[t] = -1;
/* vertices have coverage (GrColor)
*/
kCoverage_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 1),
- /* Use text vertices. (Pos and tex coords may be a different type for
- * text [GrGpuTextVertex vs GrPoint].)
- */
- kTextFormat_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 2),
-
/* Each vertex specificies an edge. Distance to the edge is used to
* compute a coverage. See GrDrawState::setVertexEdgeType().
*/
- kEdge_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 3),
+ kEdge_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 2),
// for below assert
kDummyVertexLayoutBit,
kHighVertexLayoutBit = kDummyVertexLayoutBit - 1
+++ /dev/null
-
-/*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-
-#ifndef GrGpuVertex_DEFINED
-#define GrGpuVertex_DEFINED
-
-#include "gl/GrGLConfig.h"
-#include "GrPoint.h"
-
-#if GR_TEXT_SCALAR_IS_USHORT
- typedef uint16_t GrTextScalar;
- #define GrIntToTextScalar(x) ((uint16_t)x)
- #define GrFixedToTextScalar(x) (x)
-#elif GR_TEXT_SCALAR_IS_FIXED
- typedef GrFixed GrTextScalar;
- #define GrIntToTextScalar(x) SkIntToFixed(x)
- #define GrFixedToTextScalar(x) (x)
-#elif GR_TEXT_SCALAR_IS_FLOAT
- typedef float GrTextScalar;
- #define GrIntToTextScalar(x) ((GrTextScalar)x)
- #define GrFixedToTextScalar(x) SkFixedToFloat(x)
-#else
- #error "Text scalar type not defined"
-#endif
-
-// text has its own vertex class, since it may want to be in fixed point (given)
-// that it starts with all integers) even when the default vertices are floats
-struct GrGpuTextVertex {
- GrTextScalar fX;
- GrTextScalar fY;
-
- void set(GrTextScalar x, GrTextScalar y) {
- fX = x;
- fY = y;
- }
-
- void setI(int x, int y) {
- fX = GrIntToTextScalar(x);
- fY = GrIntToTextScalar(y);
- }
-
- void setX(GrFixed x, GrFixed y) {
- fX = GrFixedToTextScalar(x);
- fY = GrFixedToTextScalar(y);
- }
-
- // rect fan is counter-clockwise
-
- void setRectFan(GrTextScalar l, GrTextScalar t, GrTextScalar r,
- GrTextScalar b) {
- GrGpuTextVertex* v = this;
- v[0].set(l, t);
- v[1].set(l, b);
- v[2].set(r, b);
- v[3].set(r, t);
- }
-
- void setIRectFan(int l, int t, int r, int b) {
- this->setRectFan(GrIntToTextScalar(l), GrIntToTextScalar(t),
- GrIntToTextScalar(r), GrIntToTextScalar(b));
- }
-
- void setIRectFan(int l, int t, int r, int b, size_t stride) {
- GrAssert(stride > sizeof(GrGpuTextVertex));
- char* v = (char*)this;
- ((GrGpuTextVertex*)(v + 0*stride))->setI(l, t);
- ((GrGpuTextVertex*)(v + 1*stride))->setI(l, b);
- ((GrGpuTextVertex*)(v + 2*stride))->setI(r, b);
- ((GrGpuTextVertex*)(v + 3*stride))->setI(r, t);
- }
-
- // counter-clockwise fan
- void setXRectFan(GrFixed l, GrFixed t, GrFixed r, GrFixed b) {
- this->setRectFan(GrFixedToTextScalar(l), GrFixedToTextScalar(t),
- GrFixedToTextScalar(r), GrFixedToTextScalar(b));
- }
-
- void setXRectFan(GrFixed l, GrFixed t, GrFixed r, GrFixed b, size_t stride) {
- GrAssert(stride > sizeof(GrGpuTextVertex));
- char* v = (char*)this;
- ((GrGpuTextVertex*)(v + 0*stride))->setX(l, t);
- ((GrGpuTextVertex*)(v + 1*stride))->setX(l, b);
- ((GrGpuTextVertex*)(v + 2*stride))->setX(r, b);
- ((GrGpuTextVertex*)(v + 3*stride))->setX(r, t);
- }
-
-};
-
-#endif
#include "GrContext.h"
#include "GrDrawTarget.h"
#include "GrFontScaler.h"
-#include "GrGpuVertex.h"
#include "GrIndexBuffer.h"
#include "GrTextStrike.h"
#include "GrTextStrike_impl.h"
fVertices = NULL;
fMaxVertices = 0;
- fVertexLayout =
- GrDrawState::kTextFormat_VertexLayoutBit |
- GrDrawState::StageTexCoordVertexLayoutBit(kGlyphMaskStage, 0);
+ fVertexLayout = GrDrawState::StageTexCoordVertexLayoutBit(kGlyphMaskStage, 0);
}
GrTextContext::~GrTextContext() {
this->flushGlyphs();
}
-static inline void setRectFan(GrGpuTextVertex v[4], int l, int t, int r, int b,
- int stride) {
- v[0 * stride].setI(l, t);
- v[1 * stride].setI(l, b);
- v[2 * stride].setI(r, b);
- v[3 * stride].setI(r, t);
-}
-
void GrTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
GrFixed vx, GrFixed vy,
GrFontScaler* scaler) {
HAS_ATLAS:
GrAssert(glyph->fAtlas);
- // now promote them to fixed
+ // now promote them to fixed (TODO: Rethink using fixed pt).
width = SkIntToFixed(width);
height = SkIntToFixed(height);
GrFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX);
GrFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY);
-#if GR_TEXT_SCALAR_IS_USHORT
- int x = vx >> 16;
- int y = vy >> 16;
- int w = width >> 16;
- int h = height >> 16;
-
- setRectFan(&fVertices[2*fCurrVertex], x, y, x + w, y + h, 2);
- setRectFan(&fVertices[2*fCurrVertex+1],
- texture->normalizeFixedX(tx),
- texture->normalizeFixedY(ty),
- texture->normalizeFixedX(tx + width),
- texture->normalizeFixedY(ty + height),
- 2);
-#else
- fVertices[2*fCurrVertex].setXRectFan(vx, vy, vx + width, vy + height,
- 2 * sizeof(GrGpuTextVertex));
- fVertices[2*fCurrVertex+1].setXRectFan(texture->normalizeFixedX(tx),
- texture->normalizeFixedY(ty),
- texture->normalizeFixedX(tx + width),
- texture->normalizeFixedY(ty + height),
- 2 * sizeof(GrGpuTextVertex));
-#endif
+ fVertices[2*fCurrVertex].setRectFan(SkFixedToFloat(vx),
+ SkFixedToFloat(vy),
+ SkFixedToFloat(vx + width),
+ SkFixedToFloat(vy + height),
+ 2 * sizeof(SkPoint));
+ fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)),
+ SkFixedToFloat(texture->normalizeFixedY(ty)),
+ SkFixedToFloat(texture->normalizeFixedX(tx + width)),
+ SkFixedToFloat(texture->normalizeFixedY(ty + height)),
+ 2 * sizeof(SkPoint));
fCurrVertex += 4;
}
#include "GrEffect.h"
#include "GrGLEffect.h"
-#include "GrGpuVertex.h"
typedef GrGLUniformManager::UniformHandle UniformHandle;
static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle;
return true;
}
-#if GR_TEXT_SCALAR_IS_USHORT
- #define TEXT_COORDS_GL_TYPE GR_GL_UNSIGNED_SHORT
- #define TEXT_COORDS_ARE_NORMALIZED 1
-#elif GR_TEXT_SCALAR_IS_FLOAT
- #define TEXT_COORDS_GL_TYPE GR_GL_FLOAT
- #define TEXT_COORDS_ARE_NORMALIZED 0
-#elif GR_TEXT_SCALAR_IS_FIXED
- #define TEXT_COORDS_GL_TYPE GR_GL_FIXED
- #define TEXT_COORDS_ARE_NORMALIZED 0
-#else
- #error "unknown GR_TEXT_SCALAR type"
-#endif
-
void GrGpuGL::setupGeometry(const DrawInfo& info, int* startIndexOffset) {
int newColorOffset;
int extraVertexOffset;
this->setBuffers(info.isIndexed(), &extraVertexOffset, startIndexOffset);
- GrGLenum scalarType;
- bool texCoordNorm;
- if (currLayout & GrDrawState::kTextFormat_VertexLayoutBit) {
- scalarType = TEXT_COORDS_GL_TYPE;
- texCoordNorm = SkToBool(TEXT_COORDS_ARE_NORMALIZED);
- } else {
- scalarType = GR_GL_FLOAT;
- texCoordNorm = false;
- }
-
size_t vertexOffset = (info.startVertex() + extraVertexOffset) * newStride;
// all the Pointers must be set if any of these are true
vertexOffset != fHWGeometryState.fVertexOffset ||
newStride != oldStride;
- // position and tex coord offsets change if above conditions are true
- // or the type/normalization changed based on text vs nontext type coords.
- bool posAndTexChange = allOffsetsChange ||
- (((TEXT_COORDS_GL_TYPE != GR_GL_FLOAT) || TEXT_COORDS_ARE_NORMALIZED) &&
- (GrDrawState::kTextFormat_VertexLayoutBit &
- (fHWGeometryState.fVertexLayout ^ currLayout)));
-
- if (posAndTexChange) {
+ if (allOffsetsChange) {
int idx = GrGLProgram::PositionAttributeIdx();
- GL_CALL(VertexAttribPointer(idx, 2, scalarType, false, newStride,
- (GrGLvoid*)vertexOffset));
+ GL_CALL(VertexAttribPointer(idx, 2, GR_GL_FLOAT, false, newStride, (GrGLvoid*)vertexOffset));
fHWGeometryState.fVertexOffset = vertexOffset;
}
int idx = GrGLProgram::TexCoordAttributeIdx(t);
if (oldTexCoordOffsets[t] <= 0) {
GL_CALL(EnableVertexAttribArray(idx));
- GL_CALL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm,
- newStride, texCoordOffset));
- } else if (posAndTexChange ||
- newTexCoordOffsets[t] != oldTexCoordOffsets[t]) {
- GL_CALL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm,
- newStride, texCoordOffset));
+ GL_CALL(VertexAttribPointer(idx, 2, GR_GL_FLOAT, false, newStride, texCoordOffset));
+ } else if (allOffsetsChange || newTexCoordOffsets[t] != oldTexCoordOffsets[t]) {
+ GL_CALL(VertexAttribPointer(idx, 2, GR_GL_FLOAT, false, newStride, texCoordOffset));
}
} else if (oldTexCoordOffsets[t] > 0) {
GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t)));
int idx = GrGLProgram::ColorAttributeIdx();
if (oldColorOffset <= 0) {
GL_CALL(EnableVertexAttribArray(idx));
- GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE,
- true, newStride, colorOffset));
+ GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, true, newStride, colorOffset));
} else if (allOffsetsChange || newColorOffset != oldColorOffset) {
- GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE,
- true, newStride, colorOffset));
+ GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, true, newStride, colorOffset));
}
} else if (oldColorOffset > 0) {
GL_CALL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx()));
int idx = GrGLProgram::EdgeAttributeIdx();
if (oldEdgeOffset <= 0) {
GL_CALL(EnableVertexAttribArray(idx));
- GL_CALL(VertexAttribPointer(idx, 4, scalarType,
- false, newStride, edgeOffset));
+ GL_CALL(VertexAttribPointer(idx, 4, GR_GL_FLOAT, false, newStride, edgeOffset));
} else if (allOffsetsChange || newEdgeOffset != oldEdgeOffset) {
- GL_CALL(VertexAttribPointer(idx, 4, scalarType,
- false, newStride, edgeOffset));
+ GL_CALL(VertexAttribPointer(idx, 4, GR_GL_FLOAT, false, newStride, edgeOffset));
}
} else if (oldEdgeOffset > 0) {
GL_CALL(DisableVertexAttribArray(GrGLProgram::EdgeAttributeIdx()));
int t = random_int(&random, GrDrawState::kMaxTexCoords);
pdesc.fVertexLayout |= GrDrawState::StageTexCoordVertexLayoutBit(s, t);
}
- // use text-formatted verts?
- if (random_bool(&random)) {
- pdesc.fVertexLayout |= GrDrawState::kTextFormat_VertexLayoutBit;
- }
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
SkAutoTUnref<const GrEffectRef> effect(create_random_effect(&random,