gfx/skia/trunk/src/utils/SkMeshUtils.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.

     2 /*
     3  * Copyright 2011 Google Inc.
     4  *
     5  * Use of this source code is governed by a BSD-style license that can be
     6  * found in the LICENSE file.
     7  */
     8 #include "SkMeshUtils.h"
     9 #include "SkCanvas.h"
    10 #include "SkPaint.h"
    12 SkMeshIndices::SkMeshIndices() {
    13     sk_bzero(this, sizeof(*this));
    14 }
    16 SkMeshIndices::~SkMeshIndices() {
    17     sk_free(fStorage);
    18 }
    20 bool SkMeshIndices::init(SkPoint tex[], uint16_t indices[],
    21                          int texW, int texH, int rows, int cols) {
    22     if (rows < 2 || cols < 2) {
    23         sk_free(fStorage);
    24         fStorage = NULL;
    25         fTex = NULL;
    26         fIndices = NULL;
    27         fTexCount = fIndexCount = 0;
    28         return false;
    29     }
    31     sk_free(fStorage);
    32     fStorage = NULL;
    34     fTexCount = rows * cols;
    35     rows -= 1;
    36     cols -= 1;
    37     fIndexCount = rows * cols * 6;
    39     if (tex) {
    40         fTex = tex;
    41         fIndices = indices;
    42     } else {
    43         fStorage = sk_malloc_throw(fTexCount * sizeof(SkPoint) +
    44                                    fIndexCount * sizeof(uint16_t));
    45         fTex = (SkPoint*)fStorage;
    46         fIndices = (uint16_t*)(fTex + fTexCount);
    47     }
    49     // compute the indices
    50     {
    51         uint16_t* idx = fIndices;
    52         int index = 0;
    53         for (int y = 0; y < cols; y++) {
    54             for (int x = 0; x < rows; x++) {
    55                 *idx++ = index;
    56                 *idx++ = index + rows + 1;
    57                 *idx++ = index + 1;
    59                 *idx++ = index + 1;
    60                 *idx++ = index + rows + 1;
    61                 *idx++ = index + rows + 2;
    63                 index += 1;
    64             }
    65             index += 1;
    66         }
    67     }
    69     // compute texture coordinates
    70     {
    71         SkPoint* tex = fTex;
    72         const SkScalar dx = SkIntToScalar(texW) / rows;
    73         const SkScalar dy = SkIntToScalar(texH) / cols;
    74         for (int y = 0; y <= cols; y++) {
    75             for (int x = 0; x <= rows; x++) {
    76                 tex->set(x*dx, y*dy);
    77                 tex += 1;
    78             }
    79         }
    80     }
    81     return true;
    82 }
    84 ///////////////////////////////////////////////////////////////////////////////
    86 #include "SkShader.h"
    88 void SkMeshUtils::Draw(SkCanvas* canvas, const SkBitmap& bitmap,
    89                        int rows, int cols, const SkPoint verts[],
    90                        const SkColor colors[], const SkPaint& paint) {
    91     SkMeshIndices idx;
    93     if (idx.init(bitmap.width(), bitmap.height(), rows, cols)) {
    94         SkPaint p(paint);
    95         p.setShader(SkShader::CreateBitmapShader(bitmap,
    96                                          SkShader::kClamp_TileMode,
    97                                          SkShader::kClamp_TileMode))->unref();
    98         canvas->drawVertices(SkCanvas::kTriangles_VertexMode,
    99                              rows * cols, verts, idx.tex(), colors, NULL,
   100                              idx.indices(), idx.indexCount(), p);
   101     }
   102 }

mercurial