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

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

Issue 608883003: GrResourceCache2 manages scratch texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@surfimpl
Patch Set: remove todo Created 6 years, 2 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/effects/GrTextureStripAtlas.cpp ('k') | tests/ResourceCacheTest.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, const SkSurfaceProps*, bool doCl ear); 17 SkSurface_Gpu(GrRenderTarget*, const SkSurfaceProps*, bool doClear);
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, const Sk SurfaceProps* props, 36 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, const SkSurfaceProps* props,
37 bool doClear) 37 bool doClear)
38 : INHERITED(renderTarget->width(), renderTarget->height(), props) 38 : INHERITED(renderTarget->width(), renderTarget->height(), props) {
39 {
40 int deviceFlags = 0; 39 int deviceFlags = 0;
41 deviceFlags |= cached ? SkGpuDevice::kCached_Flag : 0;
42 deviceFlags |= this->props().isUseDistanceFieldFonts() ? SkGpuDevice::kDFFon ts_Flag : 0; 40 deviceFlags |= this->props().isUseDistanceFieldFonts() ? SkGpuDevice::kDFFon ts_Flag : 0;
43 fDevice = SkGpuDevice::Create(renderTarget, this->props(), deviceFlags); 41 fDevice = SkGpuDevice::Create(renderTarget, this->props(), deviceFlags);
44 42
45 if (kRGB_565_GrPixelConfig != renderTarget->config() && doClear) { 43 if (kRGB_565_GrPixelConfig != renderTarget->config() && doClear) {
46 fDevice->clear(0x0); 44 fDevice->clear(0x0);
47 } 45 }
48 } 46 }
49 47
50 SkSurface_Gpu::~SkSurface_Gpu() { 48 SkSurface_Gpu::~SkSurface_Gpu() {
51 SkSafeUnref(fDevice); 49 SkSafeUnref(fDevice);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 void SkSurface_Gpu::onDiscard() { 102 void SkSurface_Gpu::onDiscard() {
105 fDevice->accessRenderTarget()->discard(); 103 fDevice->accessRenderTarget()->discard();
106 } 104 }
107 105
108 /////////////////////////////////////////////////////////////////////////////// 106 ///////////////////////////////////////////////////////////////////////////////
109 107
110 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, const SkSurf aceProps* props) { 108 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, const SkSurf aceProps* props) {
111 if (NULL == target) { 109 if (NULL == target) {
112 return NULL; 110 return NULL;
113 } 111 }
114 return SkNEW_ARGS(SkSurface_Gpu, (target, false, props, false)); 112 return SkNEW_ARGS(SkSurface_Gpu, (target, props, false));
115 } 113 }
116 114
117 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i nt sampleCount, 115 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i nt sampleCount,
118 const SkSurfaceProps* props) { 116 const SkSurfaceProps* props) {
119 if (NULL == ctx) { 117 if (NULL == ctx) {
120 return NULL; 118 return NULL;
121 } 119 }
122 120
123 GrTextureDesc desc; 121 GrTextureDesc desc;
124 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit; 122 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit;
125 desc.fWidth = info.width(); 123 desc.fWidth = info.width();
126 desc.fHeight = info.height(); 124 desc.fHeight = info.height();
127 desc.fConfig = SkImageInfo2GrPixelConfig(info); 125 desc.fConfig = SkImageInfo2GrPixelConfig(info);
128 desc.fSampleCnt = sampleCount; 126 desc.fSampleCnt = sampleCount;
129 127
130 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); 128 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0));
131 if (NULL == tex) { 129 if (NULL == tex) {
132 return NULL; 130 return NULL;
133 } 131 }
134 132
135 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, props, true) ); 133 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), props, true));
136 } 134 }
137 135
138 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& info, 136 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& info,
139 int sampleCount, const SkSurfacePro ps* props) { 137 int sampleCount, const SkSurfacePro ps* props) {
140 if (NULL == ctx) { 138 if (NULL == ctx) {
141 return NULL; 139 return NULL;
142 } 140 }
143 141
144 GrTextureDesc desc; 142 GrTextureDesc desc;
145 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit; 143 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit;
146 desc.fWidth = info.width(); 144 desc.fWidth = info.width();
147 desc.fHeight = info.height(); 145 desc.fHeight = info.height();
148 desc.fConfig = SkImageInfo2GrPixelConfig(info); 146 desc.fConfig = SkImageInfo2GrPixelConfig(info);
149 desc.fSampleCnt = sampleCount; 147 desc.fSampleCnt = sampleCount;
150 148
151 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k Exact_ScratchTexMatch)); 149 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k Exact_ScratchTexMatch));
152 150
153 if (NULL == tex) { 151 if (NULL == tex) {
154 return NULL; 152 return NULL;
155 } 153 }
156 154
157 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, props, true)) ; 155 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), props, true));
158 } 156 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrTextureStripAtlas.cpp ('k') | tests/ResourceCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698