gfx/skia/trunk/src/gpu/gl/GrGLPath.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2012 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9 #include "GrGLPath.h"
michael@0 10 #include "GrGpuGL.h"
michael@0 11
michael@0 12 #define GPUGL static_cast<GrGpuGL*>(this->getGpu())
michael@0 13
michael@0 14 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
michael@0 15 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(GPUGL->glInterface(), R, X)
michael@0 16
michael@0 17 namespace {
michael@0 18 inline GrGLubyte verb_to_gl_path_cmd(SkPath::Verb verb) {
michael@0 19 static const GrGLubyte gTable[] = {
michael@0 20 GR_GL_MOVE_TO,
michael@0 21 GR_GL_LINE_TO,
michael@0 22 GR_GL_QUADRATIC_CURVE_TO,
michael@0 23 0xFF, // conic
michael@0 24 GR_GL_CUBIC_CURVE_TO,
michael@0 25 GR_GL_CLOSE_PATH,
michael@0 26 };
michael@0 27 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb);
michael@0 28 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb);
michael@0 29 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb);
michael@0 30 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb);
michael@0 31 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb);
michael@0 32
michael@0 33 SkASSERT(verb >= 0 && (size_t)verb < GR_ARRAY_COUNT(gTable));
michael@0 34 return gTable[verb];
michael@0 35 }
michael@0 36
michael@0 37 #ifdef SK_DEBUG
michael@0 38 inline int num_pts(SkPath::Verb verb) {
michael@0 39 static const int gTable[] = {
michael@0 40 1, // move
michael@0 41 1, // line
michael@0 42 2, // quad
michael@0 43 2, // conic
michael@0 44 3, // cubic
michael@0 45 0, // close
michael@0 46 };
michael@0 47 GR_STATIC_ASSERT(0 == SkPath::kMove_Verb);
michael@0 48 GR_STATIC_ASSERT(1 == SkPath::kLine_Verb);
michael@0 49 GR_STATIC_ASSERT(2 == SkPath::kQuad_Verb);
michael@0 50 GR_STATIC_ASSERT(4 == SkPath::kCubic_Verb);
michael@0 51 GR_STATIC_ASSERT(5 == SkPath::kClose_Verb);
michael@0 52
michael@0 53 SkASSERT(verb >= 0 && (size_t)verb < GR_ARRAY_COUNT(gTable));
michael@0 54 return gTable[verb];
michael@0 55 }
michael@0 56 #endif
michael@0 57
michael@0 58 inline GrGLenum join_to_gl_join(SkPaint::Join join) {
michael@0 59 static GrGLenum gSkJoinsToGrGLJoins[] = {
michael@0 60 GR_GL_MITER_REVERT,
michael@0 61 GR_GL_ROUND,
michael@0 62 GR_GL_BEVEL
michael@0 63 };
michael@0 64 return gSkJoinsToGrGLJoins[join];
michael@0 65 GR_STATIC_ASSERT(0 == SkPaint::kMiter_Join);
michael@0 66 GR_STATIC_ASSERT(1 == SkPaint::kRound_Join);
michael@0 67 GR_STATIC_ASSERT(2 == SkPaint::kBevel_Join);
michael@0 68 GR_STATIC_ASSERT(GR_ARRAY_COUNT(gSkJoinsToGrGLJoins) == SkPaint::kJoinCount);
michael@0 69 }
michael@0 70
michael@0 71 inline GrGLenum cap_to_gl_cap(SkPaint::Cap cap) {
michael@0 72 static GrGLenum gSkCapsToGrGLCaps[] = {
michael@0 73 GR_GL_FLAT,
michael@0 74 GR_GL_ROUND,
michael@0 75 GR_GL_SQUARE
michael@0 76 };
michael@0 77 return gSkCapsToGrGLCaps[cap];
michael@0 78 GR_STATIC_ASSERT(0 == SkPaint::kButt_Cap);
michael@0 79 GR_STATIC_ASSERT(1 == SkPaint::kRound_Cap);
michael@0 80 GR_STATIC_ASSERT(2 == SkPaint::kSquare_Cap);
michael@0 81 GR_STATIC_ASSERT(GR_ARRAY_COUNT(gSkCapsToGrGLCaps) == SkPaint::kCapCount);
michael@0 82 }
michael@0 83
michael@0 84 }
michael@0 85
michael@0 86 static const bool kIsWrapped = false; // The constructor creates the GL path object.
michael@0 87
michael@0 88 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke)
michael@0 89 : INHERITED(gpu, kIsWrapped, path, stroke) {
michael@0 90 SkASSERT(!path.isEmpty());
michael@0 91
michael@0 92 GL_CALL_RET(fPathID, GenPaths(1));
michael@0 93
michael@0 94 SkSTArray<16, GrGLubyte, true> pathCommands;
michael@0 95 SkSTArray<16, SkPoint, true> pathPoints;
michael@0 96
michael@0 97 int verbCnt = fSkPath.countVerbs();
michael@0 98 int pointCnt = fSkPath.countPoints();
michael@0 99 pathCommands.resize_back(verbCnt);
michael@0 100 pathPoints.resize_back(pointCnt);
michael@0 101
michael@0 102 // TODO: Direct access to path points since we could pass them on directly.
michael@0 103 fSkPath.getPoints(&pathPoints[0], pointCnt);
michael@0 104 fSkPath.getVerbs(&pathCommands[0], verbCnt);
michael@0 105
michael@0 106 SkDEBUGCODE(int numPts = 0);
michael@0 107 for (int i = 0; i < verbCnt; ++i) {
michael@0 108 SkPath::Verb v = static_cast<SkPath::Verb>(pathCommands[i]);
michael@0 109 pathCommands[i] = verb_to_gl_path_cmd(v);
michael@0 110 SkDEBUGCODE(numPts += num_pts(v));
michael@0 111 }
michael@0 112 SkASSERT(pathPoints.count() == numPts);
michael@0 113
michael@0 114 GL_CALL(PathCommands(fPathID,
michael@0 115 verbCnt, &pathCommands[0],
michael@0 116 2 * pointCnt, GR_GL_FLOAT, &pathPoints[0]));
michael@0 117
michael@0 118 if (stroke.needToApply()) {
michael@0 119 GL_CALL(PathParameterf(fPathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stroke.getWidth())));
michael@0 120 GL_CALL(PathParameterf(fPathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(stroke.getMiter())));
michael@0 121 GrGLenum join = join_to_gl_join(stroke.getJoin());
michael@0 122 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_JOIN_STYLE, join));
michael@0 123 GrGLenum cap = cap_to_gl_cap(stroke.getCap());
michael@0 124 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_INITIAL_END_CAP, cap));
michael@0 125 GL_CALL(PathParameteri(fPathID, GR_GL_PATH_TERMINAL_END_CAP, cap));
michael@0 126
michael@0 127 // FIXME: try to account for stroking, without rasterizing the stroke.
michael@0 128 fBounds.outset(SkScalarToFloat(stroke.getWidth()), SkScalarToFloat(stroke.getWidth()));
michael@0 129 }
michael@0 130 }
michael@0 131
michael@0 132 GrGLPath::~GrGLPath() {
michael@0 133 this->release();
michael@0 134 }
michael@0 135
michael@0 136 void GrGLPath::onRelease() {
michael@0 137 if (0 != fPathID && !this->isWrapped()) {
michael@0 138 GL_CALL(DeletePaths(fPathID, 1));
michael@0 139 fPathID = 0;
michael@0 140 }
michael@0 141
michael@0 142 INHERITED::onRelease();
michael@0 143 }
michael@0 144
michael@0 145 void GrGLPath::onAbandon() {
michael@0 146 fPathID = 0;
michael@0 147
michael@0 148 INHERITED::onAbandon();
michael@0 149 }

mercurial