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

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

Issue 261783004: Add flag for SkGpuSurface creation to enable distance fields. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 7 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
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "SkGpuDevice.h" 11 #include "SkGpuDevice.h"
12 12
13 class SkSurface_Gpu : public SkSurface_Base { 13 class SkSurface_Gpu : public SkSurface_Base {
14 public: 14 public:
15 SK_DECLARE_INST_COUNT(SkSurface_Gpu) 15 SK_DECLARE_INST_COUNT(SkSurface_Gpu)
16 16
17 SkSurface_Gpu(GrRenderTarget*, bool cached); 17 SkSurface_Gpu(GrRenderTarget*, bool cached, TextRenderMode trm);
18 virtual ~SkSurface_Gpu(); 18 virtual ~SkSurface_Gpu();
19 19
20 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; 20 virtual SkCanvas* onNewCanvas() SK_OVERRIDE;
21 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; 21 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
22 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; 22 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE;
23 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, 23 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
24 const SkPaint*) SK_OVERRIDE; 24 const SkPaint*) SK_OVERRIDE;
25 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; 25 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE;
26 virtual void onDiscard() SK_OVERRIDE; 26 virtual void onDiscard() SK_OVERRIDE;
27 27
28 private: 28 private:
29 SkGpuDevice* fDevice; 29 SkGpuDevice* fDevice;
30 30
31 typedef SkSurface_Base INHERITED; 31 typedef SkSurface_Base INHERITED;
32 }; 32 };
33 33
34 /////////////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////////////
35 35
36 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached) 36 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached, TextRend erMode trm)
37 : INHERITED(renderTarget->width(), renderTarget->height()) { 37 : INHERITED(renderTarget->width(), renderTarget->height()) {
38 fDevice = SkGpuDevice::Create(renderTarget, cached ? SkGpuDevice::kCached_Fl ag : 0); 38 int flags = 0;
39 flags |= cached ? SkGpuDevice::kCached_Flag : 0;
40 flags |= (kDistanceField_TextRenderMode == trm) ? SkGpuDevice::kDFFonts_Flag : 0;
41 fDevice = SkGpuDevice::Create(renderTarget, flags);
39 42
40 if (kRGB_565_GrPixelConfig != renderTarget->config()) { 43 if (kRGB_565_GrPixelConfig != renderTarget->config()) {
41 fDevice->clear(0x0); 44 fDevice->clear(0x0);
42 } 45 }
43 } 46 }
44 47
45 SkSurface_Gpu::~SkSurface_Gpu() { 48 SkSurface_Gpu::~SkSurface_Gpu() {
46 SkSafeUnref(fDevice); 49 SkSafeUnref(fDevice);
47 } 50 }
48 51
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 this->SkSurface_Gpu::onDiscard(); 94 this->SkSurface_Gpu::onDiscard();
92 } 95 }
93 } 96 }
94 97
95 void SkSurface_Gpu::onDiscard() { 98 void SkSurface_Gpu::onDiscard() {
96 fDevice->accessRenderTarget()->discard(); 99 fDevice->accessRenderTarget()->discard();
97 } 100 }
98 101
99 /////////////////////////////////////////////////////////////////////////////// 102 ///////////////////////////////////////////////////////////////////////////////
100 103
101 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target) { 104 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMo de trm) {
102 if (NULL == target) { 105 if (NULL == target) {
103 return NULL; 106 return NULL;
104 } 107 }
105 return SkNEW_ARGS(SkSurface_Gpu, (target, false)); 108 return SkNEW_ARGS(SkSurface_Gpu, (target, false, trm));
106 } 109 }
107 110
108 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i nt sampleCount) { 111 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i nt sampleCount,
112 TextRenderMode trm) {
109 if (NULL == ctx) { 113 if (NULL == ctx) {
110 return NULL; 114 return NULL;
111 } 115 }
112 116
113 GrTextureDesc desc; 117 GrTextureDesc desc;
114 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit; 118 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit;
115 desc.fWidth = info.width(); 119 desc.fWidth = info.width();
116 desc.fHeight = info.height(); 120 desc.fHeight = info.height();
117 desc.fConfig = SkImageInfo2GrPixelConfig(info); 121 desc.fConfig = SkImageInfo2GrPixelConfig(info);
118 desc.fSampleCnt = sampleCount; 122 desc.fSampleCnt = sampleCount;
119 123
120 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); 124 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0));
121 if (NULL == tex) { 125 if (NULL == tex) {
122 return NULL; 126 return NULL;
123 } 127 }
124 128
125 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false)); 129 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, trm));
126 } 130 }
127 131
128 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& info, int sampleCount) { 132 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& info,
133 int sampleCount, TextRenderMode trm ) {
129 if (NULL == ctx) { 134 if (NULL == ctx) {
130 return NULL; 135 return NULL;
131 } 136 }
132 137
133 GrTextureDesc desc; 138 GrTextureDesc desc;
134 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit; 139 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit;
135 desc.fWidth = info.width(); 140 desc.fWidth = info.width();
136 desc.fHeight = info.height(); 141 desc.fHeight = info.height();
137 desc.fConfig = SkImageInfo2GrPixelConfig(info); 142 desc.fConfig = SkImageInfo2GrPixelConfig(info);
138 desc.fSampleCnt = sampleCount; 143 desc.fSampleCnt = sampleCount;
139 144
140 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k Exact_ScratchTexMatch)); 145 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k Exact_ScratchTexMatch));
141 146
142 if (NULL == tex) { 147 if (NULL == tex) {
143 return NULL; 148 return NULL;
144 } 149 }
145 150
146 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true)); 151 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm));
147 } 152 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698