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