Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: src/core/SkMipMap.h

Issue 2029373004: respect srgb gamma when building mips (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Need to know when we're in L32 compatibility mode !!!? Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkMipMap_DEFINED 8 #ifndef SkMipMap_DEFINED
9 #define SkMipMap_DEFINED 9 #define SkMipMap_DEFINED
10 10
11 #include "SkCachedData.h" 11 #include "SkCachedData.h"
12 #include "SkPixmap.h" 12 #include "SkPixmap.h"
13 #include "SkScalar.h" 13 #include "SkScalar.h"
14 #include "SkSize.h" 14 #include "SkSize.h"
15 #include "SkShader.h"
15 16
16 class SkBitmap; 17 class SkBitmap;
17 class SkDiscardableMemory; 18 class SkDiscardableMemory;
18 19
19 typedef SkDiscardableMemory* (*SkDiscardableFactoryProc)(size_t bytes); 20 typedef SkDiscardableMemory* (*SkDiscardableFactoryProc)(size_t bytes);
20 21
21 class SkMipMap : public SkCachedData { 22 class SkMipMap : public SkCachedData {
22 public: 23 public:
23 static SkMipMap* Build(const SkPixmap& src, SkDiscardableFactoryProc); 24 enum SrcGammaMode {
24 static SkMipMap* Build(const SkBitmap& src, SkDiscardableFactoryProc); 25 kIgnore_SrcGammaMode, // treat src as having linear gamma
26 kRespect_SrcGammaMode, // treat src as described by its SkColorSpace
27 };
28
29 static SkMipMap* Build(const SkPixmap& src, SrcGammaMode, SkDiscardableFacto ryProc);
30 static SkMipMap* Build(const SkBitmap& src, SrcGammaMode, SkDiscardableFacto ryProc);
31
32 static SrcGammaMode DeduceMode(const SkShader::ContextRec& rec) {
33 return (SkShader::ContextRec::kPMColor_DstType == rec.fPreferredDstType) ?
msarett 2016/06/03 16:54:17 We will never want to respect gamma with kPMColor_
reed1 2016/06/07 16:01:10 That is the policy I'm proposing: - if the target
34 kIgnore_SrcGammaMode : kRespect_SrcGammaMode;
35 }
25 36
26 // Determines how many levels a SkMipMap will have without creating that mip map. 37 // Determines how many levels a SkMipMap will have without creating that mip map.
27 static int ComputeLevelCount(int baseWidth, int baseHeight); 38 static int ComputeLevelCount(int baseWidth, int baseHeight);
28 39
29 // Determines the size of a given mipmap level. 40 // Determines the size of a given mipmap level.
30 static SkSize ComputeLevelSize(int baseWidth, int baseHeight, int level); 41 static SkSize ComputeLevelSize(int baseWidth, int baseHeight, int level);
31 42
32 struct Level { 43 struct Level {
33 SkPixmap fPixmap; 44 SkPixmap fPixmap;
34 SkSize fScale; // < 1.0 45 SkSize fScale; // < 1.0
35 }; 46 };
36 47
37 bool extractLevel(const SkSize& scale, Level*) const; 48 bool extractLevel(const SkSize& scale, Level*) const;
38 int countLevels() const; 49 int countLevels() const;
39 bool getLevel(int index, Level*) const; 50 bool getLevel(int index, Level*) const;
40 51
41 protected: 52 protected:
42 void onDataChange(void* oldData, void* newData) override { 53 void onDataChange(void* oldData, void* newData) override {
43 fLevels = (Level*)newData; // could be nullptr 54 fLevels = (Level*)newData; // could be nullptr
44 } 55 }
45 56
46 private: 57 private:
47 Level* fLevels; 58 sk_sp<SkColorSpace> fCS;
48 int fCount; 59 Level* fLevels; // managed by the baseclass, may be null due to onDataChanged.
60 int fCount;
49 61
50 // we take ownership of levels, and will free it with sk_free()
51 SkMipMap(void* malloc, size_t size) : INHERITED(malloc, size) {} 62 SkMipMap(void* malloc, size_t size) : INHERITED(malloc, size) {}
52 SkMipMap(size_t size, SkDiscardableMemory* dm) : INHERITED(size, dm) {} 63 SkMipMap(size_t size, SkDiscardableMemory* dm) : INHERITED(size, dm) {}
53 64
54 static size_t AllocLevelsSize(int levelCount, size_t pixelSize); 65 static size_t AllocLevelsSize(int levelCount, size_t pixelSize);
55 66
56 typedef SkCachedData INHERITED; 67 typedef SkCachedData INHERITED;
57 }; 68 };
58 69
59 #endif 70 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698