OLD | NEW |
---|---|
1 | |
2 /* | 1 /* |
3 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 | 8 |
10 #include "GrGpu.h" | 9 #include "GrGpu.h" |
11 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 // By default, GrRenderTargets are GL's normal orientation so that they | 56 // By default, GrRenderTargets are GL's normal orientation so that they |
58 // can be drawn to by the outside world without the client having | 57 // can be drawn to by the outside world without the client having |
59 // to render upside down. | 58 // to render upside down. |
60 if (kDefault_GrSurfaceOrigin == origin) { | 59 if (kDefault_GrSurfaceOrigin == origin) { |
61 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin; | 60 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin; |
62 } else { | 61 } else { |
63 return origin; | 62 return origin; |
64 } | 63 } |
65 } | 64 } |
66 | 65 |
66 /** | |
67 * Prior to creating a texture, make sure the type of texture being created is | |
68 * supported by calling check_texture_creation_params. | |
69 * | |
70 * @param caps The capabilities of the GL device. | |
71 * @param desc The descriptor of the texture to create. | |
72 * @param isRT Indicates if the texture be a render target. | |
73 */ | |
74 static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDes c& desc, | |
75 bool* isRT) { | |
76 if (!caps.isConfigTexturable(desc.fConfig)) { | |
77 return false; | |
78 } | |
79 | |
80 *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | |
81 if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | |
82 return false; | |
83 } | |
84 | |
85 // We currently do not support multisampled textures | |
86 if (!*isRT && desc.fSampleCnt > 0) { | |
87 return false; | |
88 } | |
89 | |
90 if (*isRT) { | |
91 int maxRTSize = caps.maxRenderTargetSize(); | |
92 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { | |
93 return false; | |
94 } | |
95 } else { | |
96 int maxSize = caps.maxTextureSize(); | |
97 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { | |
98 return false; | |
99 } | |
100 } | |
101 return true; | |
102 } | |
103 | |
67 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, | 104 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, |
68 const void* srcData, size_t rowBytes) { | 105 SkTArray<SkMipMapLevel>& texels) { |
69 GrSurfaceDesc desc = origDesc; | 106 GrSurfaceDesc desc = origDesc; |
70 | 107 |
71 if (!this->caps()->isConfigTexturable(desc.fConfig)) { | 108 const GrCaps* caps = this->caps(); |
109 if (!caps) { | |
72 return NULL; | 110 return NULL; |
73 } | |
74 | |
75 bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | |
76 if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | |
77 return NULL; | |
78 } | |
79 | |
80 // We currently not support multisampled textures | |
81 if (!isRT && desc.fSampleCnt > 0) { | |
82 return NULL; | |
83 } | |
84 | |
85 GrTexture *tex = NULL; | |
86 | |
87 if (isRT) { | |
88 int maxRTSize = this->caps()->maxRenderTargetSize(); | |
89 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { | |
90 return NULL; | |
91 } | |
92 } else { | 111 } else { |
93 int maxSize = this->caps()->maxTextureSize(); | 112 bool isRT = false; |
94 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { | 113 bool textureCreationParamsValid = check_texture_creation_params(*caps, d esc, &isRT); |
95 return NULL; | 114 if (!textureCreationParamsValid) { |
96 } | |
97 } | |
98 | |
99 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC ycle : | |
100 GrGpuResource::kUncached_Lif eCycle; | |
101 | |
102 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); | |
103 // Attempt to catch un- or wrongly initialized sample counts; | |
104 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); | |
105 | |
106 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); | |
107 | |
108 if (GrPixelConfigIsCompressed(desc.fConfig)) { | |
109 // We shouldn't be rendering into this | |
110 SkASSERT(!isRT); | |
111 SkASSERT(0 == desc.fSampleCnt); | |
112 | |
113 if (!this->caps()->npotTextureTileSupport() && | |
114 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { | |
115 return NULL; | 115 return NULL; |
116 } | 116 } |
117 | 117 |
118 this->handleDirtyContext(); | 118 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); |
119 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); | 119 // Attempt to catch un- or wrongly initialized sample counts; |
120 } else { | 120 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
121 this->handleDirtyContext(); | 121 |
122 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); | 122 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
123 | |
124 GrTexture *tex = NULL; | |
125 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_L ifeCycle : | |
126 GrGpuResource::kUncached _LifeCycle; | |
127 | |
128 if (GrPixelConfigIsCompressed(desc.fConfig)) { | |
129 // We shouldn't be rendering into this | |
130 SkASSERT(!isRT); | |
131 SkASSERT(0 == desc.fSampleCnt); | |
132 | |
133 if (!caps->npotTextureTileSupport() && | |
134 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { | |
135 return NULL; | |
136 } | |
137 | |
138 this->handleDirtyContext(); | |
139 tex = this->onCreateCompressedTexture(desc, lifeCycle, texels); | |
140 } else { | |
141 this->handleDirtyContext(); | |
142 tex = this->onCreateTexture(desc, lifeCycle, texels); | |
143 } | |
144 if (tex) { | |
145 /* TODO: I am unsure how to use a scratch texture well with mipmaps | |
bsalomon
2015/08/26 18:30:11
I think we should just include mip status in the s
cblume
2015/08/26 18:58:00
Thinking out loud: A bool of "is mipmapped" may no
bsalomon
2015/08/27 13:22:49
Why don't we just require either just a base level
| |
146 if (!caps->reuseScratchTextures() && !isRT) { | |
147 tex->resourcePriv().removeScratchKey(); | |
148 } | |
149 */ | |
150 fStats.incTextureCreates(); | |
151 if (!texels.empty()) { | |
152 if (texels[0].fTexels) { | |
153 fStats.incTextureUploads(); | |
154 } | |
155 } | |
156 } | |
157 return tex; | |
123 } | 158 } |
124 if (!this->caps()->reuseScratchTextures() && !isRT) { | 159 } |
125 tex->resourcePriv().removeScratchKey(); | 160 |
126 } | 161 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted, |
127 if (tex) { | 162 const void* srcData, size_t rowBytes) { |
128 fStats.incTextureCreates(); | 163 SkMipMapLevel level(srcData, rowBytes); |
129 if (srcData) { | 164 |
130 fStats.incTextureUploads(); | 165 const int mipLevelCount = 1; |
131 } | 166 SkTArray<SkMipMapLevel> levels(mipLevelCount); |
132 } | 167 levels.push_back(level); |
133 return tex; | 168 |
169 return createTexture(desc, budgeted, levels); | |
134 } | 170 } |
135 | 171 |
136 bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) { | 172 bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) { |
137 SkASSERT(NULL == rt->renderTargetPriv().getStencilAttachment()); | 173 SkASSERT(NULL == rt->renderTargetPriv().getStencilAttachment()); |
138 GrUniqueKey sbKey; | 174 GrUniqueKey sbKey; |
139 | 175 |
140 int width = rt->width(); | 176 int width = rt->width(); |
141 int height = rt->height(); | 177 int height = rt->height(); |
142 #if 0 | 178 #if 0 |
143 if (this->caps()->oversizedStencilSupport()) { | 179 if (this->caps()->oversizedStencilSupport()) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 int left, int top, int width, int height, | 272 int left, int top, int width, int height, |
237 GrPixelConfig config, void* buffer, | 273 GrPixelConfig config, void* buffer, |
238 size_t rowBytes) { | 274 size_t rowBytes) { |
239 this->handleDirtyContext(); | 275 this->handleDirtyContext(); |
240 return this->onReadPixels(target, left, top, width, height, | 276 return this->onReadPixels(target, left, top, width, height, |
241 config, buffer, rowBytes); | 277 config, buffer, rowBytes); |
242 } | 278 } |
243 | 279 |
244 bool GrGpu::writeTexturePixels(GrTexture* texture, | 280 bool GrGpu::writeTexturePixels(GrTexture* texture, |
245 int left, int top, int width, int height, | 281 int left, int top, int width, int height, |
246 GrPixelConfig config, const void* buffer, | 282 GrPixelConfig config, |
247 size_t rowBytes) { | 283 SkTArray<SkMipMapLevel>& texels) { |
248 this->handleDirtyContext(); | 284 this->handleDirtyContext(); |
249 if (this->onWriteTexturePixels(texture, left, top, width, height, | 285 if (this->onWriteTexturePixels(texture, left, top, width, height, |
250 config, buffer, rowBytes)) { | 286 config, texels)) { |
251 fStats.incTextureUploads(); | 287 fStats.incTextureUploads(); |
252 return true; | 288 return true; |
253 } | 289 } |
254 return false; | 290 return false; |
255 } | 291 } |
256 | 292 |
293 bool GrGpu::writeTexturePixels(GrTexture* texture, | |
294 int left, int top, int width, int height, | |
295 GrPixelConfig config, const void* buffer, | |
296 size_t rowBytes) { | |
297 SkMipMapLevel mipLevel(buffer, rowBytes); | |
298 SkTArray<SkMipMapLevel> texels; | |
299 texels.push_back(mipLevel); | |
300 | |
301 writeTexturePixels(texture, left, top, width, height, config, texels); | |
302 } | |
303 | |
257 void GrGpu::resolveRenderTarget(GrRenderTarget* target) { | 304 void GrGpu::resolveRenderTarget(GrRenderTarget* target) { |
258 SkASSERT(target); | 305 SkASSERT(target); |
259 this->handleDirtyContext(); | 306 this->handleDirtyContext(); |
260 this->onResolveRenderTarget(target); | 307 this->onResolveRenderTarget(target); |
261 } | 308 } |
262 | 309 |
263 typedef GrTraceMarkerSet::Iter TMIter; | 310 typedef GrTraceMarkerSet::Iter TMIter; |
264 void GrGpu::saveActiveTraceMarkers() { | 311 void GrGpu::saveActiveTraceMarkers() { |
265 if (this->caps()->gpuTracingSupport()) { | 312 if (this->caps()->gpuTracingSupport()) { |
266 SkASSERT(0 == fStoredTraceMarkers.count()); | 313 SkASSERT(0 == fStoredTraceMarkers.count()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 //////////////////////////////////////////////////////////////////////////////// | 351 //////////////////////////////////////////////////////////////////////////////// |
305 | 352 |
306 void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) { | 353 void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) { |
307 this->handleDirtyContext(); | 354 this->handleDirtyContext(); |
308 GrVertices::Iterator iter; | 355 GrVertices::Iterator iter; |
309 const GrNonInstancedVertices* verts = iter.init(vertices); | 356 const GrNonInstancedVertices* verts = iter.init(vertices); |
310 do { | 357 do { |
311 this->onDraw(args, *verts); | 358 this->onDraw(args, *verts); |
312 } while ((verts = iter.next())); | 359 } while ((verts = iter.next())); |
313 } | 360 } |
OLD | NEW |