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

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

Issue 583043002: remove RenderTargetFlags -- NewRenderTargetDirect will never clear (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
« no previous file with comments | « src/gpu/GrLayerHoister.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, TextRenderMode trm, 17 SkSurface_Gpu(GrRenderTarget*, bool cached, TextRenderMode trm, bool doClear );
18 SkSurface::RenderTargetFlags flags);
19 virtual ~SkSurface_Gpu(); 18 virtual ~SkSurface_Gpu();
20 19
21 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; 20 virtual SkCanvas* onNewCanvas() SK_OVERRIDE;
22 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; 21 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
23 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; 22 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE;
24 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, 23 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
25 const SkPaint*) SK_OVERRIDE; 24 const SkPaint*) SK_OVERRIDE;
26 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; 25 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE;
27 virtual void onDiscard() SK_OVERRIDE; 26 virtual void onDiscard() SK_OVERRIDE;
28 27
29 private: 28 private:
30 SkGpuDevice* fDevice; 29 SkGpuDevice* fDevice;
31 30
32 typedef SkSurface_Base INHERITED; 31 typedef SkSurface_Base INHERITED;
33 }; 32 };
34 33
35 /////////////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////////////
36 35
37 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached, TextRend erMode trm, 36 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached, TextRend erMode trm,
38 SkSurface::RenderTargetFlags flags) 37 bool doClear)
39 : INHERITED(renderTarget->width(), renderTarget->height()) { 38 : INHERITED(renderTarget->width(), renderTarget->height()) {
40 int deviceFlags = 0; 39 int deviceFlags = 0;
41 deviceFlags |= cached ? SkGpuDevice::kCached_Flag : 0; 40 deviceFlags |= cached ? SkGpuDevice::kCached_Flag : 0;
42 deviceFlags |= (kDistanceField_TextRenderMode == trm) ? SkGpuDevice::kDFFont s_Flag : 0; 41 deviceFlags |= (kDistanceField_TextRenderMode == trm) ? SkGpuDevice::kDFFont s_Flag : 0;
43 fDevice = SkGpuDevice::Create(renderTarget, deviceFlags); 42 fDevice = SkGpuDevice::Create(renderTarget, deviceFlags);
44 43
45 if (kRGB_565_GrPixelConfig != renderTarget->config() && 44 if (kRGB_565_GrPixelConfig != renderTarget->config() && doClear) {
46 !(flags & kDontClear_RenderTargetFlag)) {
47 fDevice->clear(0x0); 45 fDevice->clear(0x0);
48 } 46 }
49 } 47 }
50 48
51 SkSurface_Gpu::~SkSurface_Gpu() { 49 SkSurface_Gpu::~SkSurface_Gpu() {
52 SkSafeUnref(fDevice); 50 SkSafeUnref(fDevice);
53 } 51 }
54 52
55 SkCanvas* SkSurface_Gpu::onNewCanvas() { 53 SkCanvas* SkSurface_Gpu::onNewCanvas() {
56 return SkNEW_ARGS(SkCanvas, (fDevice)); 54 return SkNEW_ARGS(SkCanvas, (fDevice));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 this->SkSurface_Gpu::onDiscard(); 95 this->SkSurface_Gpu::onDiscard();
98 } 96 }
99 } 97 }
100 98
101 void SkSurface_Gpu::onDiscard() { 99 void SkSurface_Gpu::onDiscard() {
102 fDevice->accessRenderTarget()->discard(); 100 fDevice->accessRenderTarget()->discard();
103 } 101 }
104 102
105 /////////////////////////////////////////////////////////////////////////////// 103 ///////////////////////////////////////////////////////////////////////////////
106 104
107 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMo de trm, 105 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMo de trm) {
108 RenderTargetFlags flags) {
109 if (NULL == target) { 106 if (NULL == target) {
110 return NULL; 107 return NULL;
111 } 108 }
112 return SkNEW_ARGS(SkSurface_Gpu, (target, false, trm, flags)); 109 return SkNEW_ARGS(SkSurface_Gpu, (target, false, trm, false));
113 } 110 }
114 111
115 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i nt sampleCount, 112 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i nt sampleCount,
116 TextRenderMode trm, RenderTargetFlags flag s) { 113 TextRenderMode trm) {
117 if (NULL == ctx) { 114 if (NULL == ctx) {
118 return NULL; 115 return NULL;
119 } 116 }
120 117
121 GrTextureDesc desc; 118 GrTextureDesc desc;
122 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit; 119 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit;
123 desc.fWidth = info.width(); 120 desc.fWidth = info.width();
124 desc.fHeight = info.height(); 121 desc.fHeight = info.height();
125 desc.fConfig = SkImageInfo2GrPixelConfig(info); 122 desc.fConfig = SkImageInfo2GrPixelConfig(info);
126 desc.fSampleCnt = sampleCount; 123 desc.fSampleCnt = sampleCount;
127 124
128 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); 125 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0));
129 if (NULL == tex) { 126 if (NULL == tex) {
130 return NULL; 127 return NULL;
131 } 128 }
132 129
133 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, trm, flags)) ; 130 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, trm, true));
134 } 131 }
135 132
136 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& info, 133 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& info,
137 int sampleCount, TextRenderMode trm , 134 int sampleCount, TextRenderMode trm ) {
138 RenderTargetFlags flags) {
139 if (NULL == ctx) { 135 if (NULL == ctx) {
140 return NULL; 136 return NULL;
141 } 137 }
142 138
143 GrTextureDesc desc; 139 GrTextureDesc desc;
144 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit; 140 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit;
145 desc.fWidth = info.width(); 141 desc.fWidth = info.width();
146 desc.fHeight = info.height(); 142 desc.fHeight = info.height();
147 desc.fConfig = SkImageInfo2GrPixelConfig(info); 143 desc.fConfig = SkImageInfo2GrPixelConfig(info);
148 desc.fSampleCnt = sampleCount; 144 desc.fSampleCnt = sampleCount;
149 145
150 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k Exact_ScratchTexMatch)); 146 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k Exact_ScratchTexMatch));
151 147
152 if (NULL == tex) { 148 if (NULL == tex) {
153 return NULL; 149 return NULL;
154 } 150 }
155 151
156 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm, flags)); 152 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm, true));
157 } 153 }
OLDNEW
« no previous file with comments | « src/gpu/GrLayerHoister.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698