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

Side by Side Diff: src/image/SkSurface.cpp

Issue 551463004: introduce Props to surface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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 2012 Google Inc. 2 * Copyright 2012 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 #include "SkSurface_Base.h" 8 #include "SkSurface_Base.h"
9 #include "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 11
12 #include "SkFontLCDConfig.h"
13 static SkPixelGeometry compute_default_geometry() {
14 SkFontLCDConfig::LCDOrder order = SkFontLCDConfig::GetSubpixelOrder();
15 if (SkFontLCDConfig::kNONE_LCDOrder == order) {
16 return kUnknown_SkPixelGeometry;
17 } else {
18 // Bit0 is RGB(0), BGR(1)
19 // Bit1 is H(0), V(1)
20 const SkPixelGeometry gGeo[] = {
21 kRGB_H_SkPixelGeometry,
22 kBGR_H_SkPixelGeometry,
23 kRGB_V_SkPixelGeometry,
24 kBGR_V_SkPixelGeometry,
25 };
26 int index = 0;
27 if (SkFontLCDConfig::kBGR_LCDOrder == order) {
28 index |= 1;
29 }
30 if (SkFontLCDConfig::kVertical_LCDOrientation == SkFontLCDConfig::GetSub pixelOrientation()){
31 index |= 2;
32 }
33 return gGeo[index];
34 }
35 }
36
37 SkSurfaceProps::SkSurfaceProps() : fFlags(0), fPixelGeometry(kUnknown_SkPixelGeo metry) {}
38
39 SkSurfaceProps::SkSurfaceProps(InitType) : fFlags(0), fPixelGeometry(compute_def ault_geometry()) {}
40
41 SkSurfaceProps::SkSurfaceProps(uint32_t flags, SkPixelGeometry pg)
42 : fFlags(flags), fPixelGeometry(pg)
43 {}
44
12 /////////////////////////////////////////////////////////////////////////////// 45 ///////////////////////////////////////////////////////////////////////////////
13 46
14 SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height) { 47 SkSurface_Base::SkSurface_Base(int width, int height, const Props* props)
48 : INHERITED(width, height, props)
49 {
15 fCachedCanvas = NULL; 50 fCachedCanvas = NULL;
16 fCachedImage = NULL; 51 fCachedImage = NULL;
17 } 52 }
18 53
19 SkSurface_Base::SkSurface_Base(const SkImageInfo& info) : INHERITED(info) { 54 SkSurface_Base::SkSurface_Base(const SkImageInfo& info, const Props* props)
55 : INHERITED(info, props)
56 {
20 fCachedCanvas = NULL; 57 fCachedCanvas = NULL;
21 fCachedImage = NULL; 58 fCachedImage = NULL;
22 } 59 }
23 60
24 SkSurface_Base::~SkSurface_Base() { 61 SkSurface_Base::~SkSurface_Base() {
25 // in case the canvas outsurvives us, we null the callback 62 // in case the canvas outsurvives us, we null the callback
26 if (fCachedCanvas) { 63 if (fCachedCanvas) {
27 fCachedCanvas->setSurfaceBase(NULL); 64 fCachedCanvas->setSurfaceBase(NULL);
28 } 65 }
29 66
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 static int32_t gID; 104 static int32_t gID;
68 return sk_atomic_inc(&gID) + 1; 105 return sk_atomic_inc(&gID) + 1;
69 } 106 }
70 107
71 static SkSurface_Base* asSB(SkSurface* surface) { 108 static SkSurface_Base* asSB(SkSurface* surface) {
72 return static_cast<SkSurface_Base*>(surface); 109 return static_cast<SkSurface_Base*>(surface);
73 } 110 }
74 111
75 /////////////////////////////////////////////////////////////////////////////// 112 ///////////////////////////////////////////////////////////////////////////////
76 113
77 SkSurface::SkSurface(int width, int height) : fWidth(width), fHeight(height) { 114 static SkSurfaceProps props_or_default(const SkSurfaceProps* props) {
115 if (props) {
116 return *props;
117 } else {
118 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
119 }
120 }
121
122 SkSurface::SkSurface(int width, int height, const Props* props)
123 : fProps(props_or_default(props)), fWidth(width), fHeight(height)
124 {
78 SkASSERT(fWidth >= 0); 125 SkASSERT(fWidth >= 0);
79 SkASSERT(fHeight >= 0); 126 SkASSERT(fHeight >= 0);
80 fGenerationID = 0; 127 fGenerationID = 0;
81 } 128 }
82 129
83 SkSurface::SkSurface(const SkImageInfo& info) : fWidth(info.width()), fHeight(in fo.height()) { 130 SkSurface::SkSurface(const SkImageInfo& info, const Props* props)
131 : fProps(props_or_default(props)), fWidth(info.width()), fHeight(info.height ())
132 {
84 SkASSERT(fWidth >= 0); 133 SkASSERT(fWidth >= 0);
85 SkASSERT(fHeight >= 0); 134 SkASSERT(fHeight >= 0);
86 fGenerationID = 0; 135 fGenerationID = 0;
87 } 136 }
88 137
89 uint32_t SkSurface::generationID() { 138 uint32_t SkSurface::generationID() {
90 if (0 == fGenerationID) { 139 if (0 == fGenerationID) {
91 fGenerationID = asSB(this)->newGenerationID(); 140 fGenerationID = asSB(this)->newGenerationID();
92 } 141 }
93 return fGenerationID; 142 return fGenerationID;
(...skipping 18 matching lines...) Expand all
112 } 161 }
113 162
114 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, 163 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y,
115 const SkPaint* paint) { 164 const SkPaint* paint) {
116 return asSB(this)->onDraw(canvas, x, y, paint); 165 return asSB(this)->onDraw(canvas, x, y, paint);
117 } 166 }
118 167
119 const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) { 168 const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) {
120 return this->getCanvas()->peekPixels(info, rowBytes); 169 return this->getCanvas()->peekPixels(info, rowBytes);
121 } 170 }
OLDNEW
« src/core/SkCanvas.cpp ('K') | « src/gpu/SkGpuDevice.cpp ('k') | src/image/SkSurface_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698