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

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: rebase (nasty) 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, InitType)
42 : fFlags(flags)
43 , fPixelGeometry(compute_default_geometry())
44 {}
45
46 SkSurfaceProps::SkSurfaceProps(uint32_t flags, SkPixelGeometry pg)
47 : fFlags(flags), fPixelGeometry(pg)
48 {}
49
12 /////////////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////////////
13 51
14 SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height) { 52 SkSurface_Base::SkSurface_Base(int width, int height, const SkSurfaceProps* prop s)
53 : INHERITED(width, height, props)
54 {
15 fCachedCanvas = NULL; 55 fCachedCanvas = NULL;
16 fCachedImage = NULL; 56 fCachedImage = NULL;
17 } 57 }
18 58
19 SkSurface_Base::SkSurface_Base(const SkImageInfo& info) : INHERITED(info) { 59 SkSurface_Base::SkSurface_Base(const SkImageInfo& info, const SkSurfaceProps* pr ops)
60 : INHERITED(info, props)
61 {
20 fCachedCanvas = NULL; 62 fCachedCanvas = NULL;
21 fCachedImage = NULL; 63 fCachedImage = NULL;
22 } 64 }
23 65
24 SkSurface_Base::~SkSurface_Base() { 66 SkSurface_Base::~SkSurface_Base() {
25 // in case the canvas outsurvives us, we null the callback 67 // in case the canvas outsurvives us, we null the callback
26 if (fCachedCanvas) { 68 if (fCachedCanvas) {
27 fCachedCanvas->setSurfaceBase(NULL); 69 fCachedCanvas->setSurfaceBase(NULL);
28 } 70 }
29 71
30 SkSafeUnref(fCachedImage); 72 SkSafeUnref(fCachedImage);
31 SkSafeUnref(fCachedCanvas); 73 SkSafeUnref(fCachedCanvas);
32 } 74 }
33 75
34 void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 76 void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa int* paint) {
35 const SkPaint* paint) {
36 SkImage* image = this->newImageSnapshot(); 77 SkImage* image = this->newImageSnapshot();
37 if (image) { 78 if (image) {
38 image->draw(canvas, x, y, paint); 79 image->draw(canvas, x, y, paint);
39 image->unref(); 80 image->unref();
40 } 81 }
41 } 82 }
42 83
43 void SkSurface_Base::aboutToDraw(ContentChangeMode mode) { 84 void SkSurface_Base::aboutToDraw(ContentChangeMode mode) {
44 this->dirtyGenerationID(); 85 this->dirtyGenerationID();
45 86
(...skipping 20 matching lines...) Expand all
66 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); 107 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this);
67 static int32_t gID; 108 static int32_t gID;
68 return sk_atomic_inc(&gID) + 1; 109 return sk_atomic_inc(&gID) + 1;
69 } 110 }
70 111
71 static SkSurface_Base* asSB(SkSurface* surface) { 112 static SkSurface_Base* asSB(SkSurface* surface) {
72 return static_cast<SkSurface_Base*>(surface); 113 return static_cast<SkSurface_Base*>(surface);
73 } 114 }
74 115
75 /////////////////////////////////////////////////////////////////////////////// 116 ///////////////////////////////////////////////////////////////////////////////
76 117
robertphillips 2014/09/19 18:25:37 Use CopyOrLegacy?
reed1 2014/09/19 19:16:34 Done.
77 SkSurface::SkSurface(int width, int height) : fWidth(width), fHeight(height) { 118 static SkSurfaceProps props_or_default(const SkSurfaceProps* props) {
119 if (props) {
120 return *props;
121 } else {
122 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
123 }
124 }
125
126 SkSurface::SkSurface(int width, int height, const SkSurfaceProps* props)
127 : fProps(props_or_default(props)), fWidth(width), fHeight(height)
128 {
78 SkASSERT(fWidth >= 0); 129 SkASSERT(fWidth >= 0);
79 SkASSERT(fHeight >= 0); 130 SkASSERT(fHeight >= 0);
80 fGenerationID = 0; 131 fGenerationID = 0;
81 } 132 }
82 133
83 SkSurface::SkSurface(const SkImageInfo& info) : fWidth(info.width()), fHeight(in fo.height()) { 134 SkSurface::SkSurface(const SkImageInfo& info, const SkSurfaceProps* props)
135 : fProps(props_or_default(props)), fWidth(info.width()), fHeight(info.height ())
136 {
84 SkASSERT(fWidth >= 0); 137 SkASSERT(fWidth >= 0);
85 SkASSERT(fHeight >= 0); 138 SkASSERT(fHeight >= 0);
86 fGenerationID = 0; 139 fGenerationID = 0;
87 } 140 }
88 141
89 uint32_t SkSurface::generationID() { 142 uint32_t SkSurface::generationID() {
90 if (0 == fGenerationID) { 143 if (0 == fGenerationID) {
91 fGenerationID = asSB(this)->newGenerationID(); 144 fGenerationID = asSB(this)->newGenerationID();
92 } 145 }
93 return fGenerationID; 146 return fGenerationID;
(...skipping 18 matching lines...) Expand all
112 } 165 }
113 166
114 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, 167 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y,
115 const SkPaint* paint) { 168 const SkPaint* paint) {
116 return asSB(this)->onDraw(canvas, x, y, paint); 169 return asSB(this)->onDraw(canvas, x, y, paint);
117 } 170 }
118 171
119 const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) { 172 const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) {
120 return this->getCanvas()->peekPixels(info, rowBytes); 173 return this->getCanvas()->peekPixels(info, rowBytes);
121 } 174 }
175
176 //////////////////////////////////////////////////////////////////////////////// //////
177 #ifdef SK_SUPPORT_LEGACY_TEXTRENDERMODE
178
179 static SkSurfaceProps make_props(SkSurface::TextRenderMode trm) {
180 uint32_t propsFlags = 0;
181 if (SkSurface::kDistanceField_TextRenderMode == trm) {
182 propsFlags |= SkSurfaceProps::kUseDistanceFieldFonts_Flag;
183 }
184 return SkSurfaceProps(propsFlags, SkSurfaceProps::kLegacyFontHost_InitType);
185 }
186
187 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMo de trm,
188 RenderTargetFlags flags) {
189 SkSurfaceProps props = make_props(trm);
190 return NewRenderTargetDirect(target, &props, flags);
191 }
192
193 SkSurface* SkSurface::NewRenderTarget(GrContext* gr, const SkImageInfo& info, in t sampleCount,
194 TextRenderMode trm, RenderTargetFlags flag s) {
195 SkSurfaceProps props = make_props(trm);
196 return NewRenderTarget(gr, info, sampleCount, &props, flags);
197 }
198
robertphillips 2014/09/19 18:25:37 overlength
199 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* gr, const SkImageInfo& i nfo, int sampleCount,
200 TextRenderMode trm, RenderTargetFla gs flags) {
201 SkSurfaceProps props = make_props(trm);
202 return NewScratchRenderTarget(gr, info, sampleCount, &props, flags);
203 }
204
205 #endif
206
207 #if !SK_SUPPORT_GPU
208
209 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget*, const SkSurfaceProp s*,
210 RenderTargetFlags) {
211 return NULL;
212 }
213
214 SkSurface* SkSurface::NewRenderTarget(GrContext*, const SkImageInfo&, int, const SkSurfaceProps*,
215 RenderTargetFlags) {
216 return NULL;
217 }
218
219 SkSurface* SkSurface::NewScratchRenderTarget(GrContext*, const SkImageInfo&, int ,
220 const SkSurfaceProps*, RenderTarget Flags) {
221 return NULL;
222 }
223
224 #endif
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