Sat, 03 Jan 2015 20:18:00 +0100
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 2010 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 | |
michael@0 | 10 | |
michael@0 | 11 | #include "GrRectanizer.h" |
michael@0 | 12 | #include "GrTBSearch.h" |
michael@0 | 13 | |
michael@0 | 14 | #define MIN_HEIGHT_POW2 2 |
michael@0 | 15 | |
michael@0 | 16 | class GrRectanizerPow2 : public GrRectanizer { |
michael@0 | 17 | public: |
michael@0 | 18 | GrRectanizerPow2(int w, int h) : GrRectanizer(w, h) { |
michael@0 | 19 | fNextStripY = 0; |
michael@0 | 20 | fAreaSoFar = 0; |
michael@0 | 21 | sk_bzero(fRows, sizeof(fRows)); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | virtual ~GrRectanizerPow2() { |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | virtual void reset() { |
michael@0 | 28 | fNextStripY = 0; |
michael@0 | 29 | fAreaSoFar = 0; |
michael@0 | 30 | sk_bzero(fRows, sizeof(fRows)); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | virtual bool addRect(int w, int h, GrIPoint16* loc); |
michael@0 | 34 | |
michael@0 | 35 | virtual float percentFull() const { |
michael@0 | 36 | return fAreaSoFar / ((float)this->width() * this->height()); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | virtual int stripToPurge(int height) const { return -1; } |
michael@0 | 40 | virtual void purgeStripAtY(int yCoord) { } |
michael@0 | 41 | |
michael@0 | 42 | /////////////////////////////////////////////////////////////////////////// |
michael@0 | 43 | |
michael@0 | 44 | struct Row { |
michael@0 | 45 | GrIPoint16 fLoc; |
michael@0 | 46 | int fRowHeight; |
michael@0 | 47 | |
michael@0 | 48 | bool canAddWidth(int width, int containerWidth) const { |
michael@0 | 49 | return fLoc.fX + width <= containerWidth; |
michael@0 | 50 | } |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | Row fRows[16]; |
michael@0 | 54 | |
michael@0 | 55 | static int HeightToRowIndex(int height) { |
michael@0 | 56 | SkASSERT(height >= MIN_HEIGHT_POW2); |
michael@0 | 57 | return 32 - SkCLZ(height - 1); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | int fNextStripY; |
michael@0 | 61 | int32_t fAreaSoFar; |
michael@0 | 62 | |
michael@0 | 63 | bool canAddStrip(int height) const { |
michael@0 | 64 | return fNextStripY + height <= this->height(); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | void initRow(Row* row, int rowHeight) { |
michael@0 | 68 | row->fLoc.set(0, fNextStripY); |
michael@0 | 69 | row->fRowHeight = rowHeight; |
michael@0 | 70 | fNextStripY += rowHeight; |
michael@0 | 71 | } |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | bool GrRectanizerPow2::addRect(int width, int height, GrIPoint16* loc) { |
michael@0 | 75 | if ((unsigned)width > (unsigned)this->width() || |
michael@0 | 76 | (unsigned)height > (unsigned)this->height()) { |
michael@0 | 77 | return false; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | int32_t area = width * height; |
michael@0 | 81 | |
michael@0 | 82 | /* |
michael@0 | 83 | We use bsearch, but there may be more than one row with the same height, |
michael@0 | 84 | so we actually search for height-1, which can only be a pow2 itself if |
michael@0 | 85 | height == 2. Thus we set a minimum height. |
michael@0 | 86 | */ |
michael@0 | 87 | height = GrNextPow2(height); |
michael@0 | 88 | if (height < MIN_HEIGHT_POW2) { |
michael@0 | 89 | height = MIN_HEIGHT_POW2; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | Row* row = &fRows[HeightToRowIndex(height)]; |
michael@0 | 93 | SkASSERT(row->fRowHeight == 0 || row->fRowHeight == height); |
michael@0 | 94 | |
michael@0 | 95 | if (0 == row->fRowHeight) { |
michael@0 | 96 | if (!this->canAddStrip(height)) { |
michael@0 | 97 | return false; |
michael@0 | 98 | } |
michael@0 | 99 | this->initRow(row, height); |
michael@0 | 100 | } else { |
michael@0 | 101 | if (!row->canAddWidth(width, this->width())) { |
michael@0 | 102 | if (!this->canAddStrip(height)) { |
michael@0 | 103 | return false; |
michael@0 | 104 | } |
michael@0 | 105 | // that row is now "full", so retarget our Row record for |
michael@0 | 106 | // another one |
michael@0 | 107 | this->initRow(row, height); |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | SkASSERT(row->fRowHeight == height); |
michael@0 | 112 | SkASSERT(row->canAddWidth(width, this->width())); |
michael@0 | 113 | *loc = row->fLoc; |
michael@0 | 114 | row->fLoc.fX += width; |
michael@0 | 115 | |
michael@0 | 116 | SkASSERT(row->fLoc.fX <= this->width()); |
michael@0 | 117 | SkASSERT(row->fLoc.fY <= this->height()); |
michael@0 | 118 | SkASSERT(fNextStripY <= this->height()); |
michael@0 | 119 | fAreaSoFar += area; |
michael@0 | 120 | return true; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 124 | |
michael@0 | 125 | // factory is now in GrRectanizer_skyline.cpp |
michael@0 | 126 | //GrRectanizer* GrRectanizer::Factory(int width, int height) { |
michael@0 | 127 | // return SkNEW_ARGS(GrRectanizerPow2, (width, height)); |
michael@0 | 128 | //} |