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

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

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

Powered by Google App Engine
This is Rietveld 408576698