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

Side by Side Diff: src/gpu/gl/GrGLCaps.h

Issue 364193004: Reopened: Caching the result of readPixelsSupported (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Corrections 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 | « no previous file | src/gpu/gl/GrGLCaps.cpp » ('j') | src/gpu/gl/GrGLCaps.cpp » ('J')
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 8
9 #ifndef GrGLCaps_DEFINED 9 #ifndef GrGLCaps_DEFINED
10 #define GrGLCaps_DEFINED 10 #define GrGLCaps_DEFINED
11 11
12 #include "GrDrawTargetCaps.h" 12 #include "GrDrawTargetCaps.h"
13 #include "GrGLStencilBuffer.h" 13 #include "GrGLStencilBuffer.h"
14 #include "SkTArray.h" 14 #include "SkTArray.h"
15 #include "SkTDArray.h" 15 #include "SkTDArray.h"
16 #include "SkTDynamicHash.h"
16 17
17 class GrGLContextInfo; 18 class GrGLContextInfo;
18 19
19 /** 20 /**
20 * Stores some capabilities of a GL context. Most are determined by the GL 21 * Stores some capabilities of a GL context. Most are determined by the GL
21 * version and the extensions string. It also tracks formats that have passed 22 * version and the extensions string. It also tracks formats that have passed
22 * the FBO completeness test. 23 * the FBO completeness test.
23 */ 24 */
24 class GrGLCaps : public GrDrawTargetCaps { 25 class GrGLCaps : public GrDrawTargetCaps {
25 public: 26 public:
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; } 247 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
247 248
248 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic conte nt. 249 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic conte nt.
249 bool useNonVBOVertexAndIndexDynamicData() const { 250 bool useNonVBOVertexAndIndexDynamicData() const {
250 return fUseNonVBOVertexAndIndexDynamicData; 251 return fUseNonVBOVertexAndIndexDynamicData;
251 } 252 }
252 253
253 /// Does ReadPixels support the provided format/type combo? 254 /// Does ReadPixels support the provided format/type combo?
254 bool readPixelsSupported(const GrGLInterface* intf, 255 bool readPixelsSupported(const GrGLInterface* intf,
255 GrGLenum format, 256 GrGLenum format,
256 GrGLenum type) const; 257 GrGLenum type,
258 GrGLenum currFboFormat) const;
257 259
258 bool isCoreProfile() const { return fIsCoreProfile; } 260 bool isCoreProfile() const { return fIsCoreProfile; }
259 261
260 262
261 bool fullClearIsFree() const { return fFullClearIsFree; } 263 bool fullClearIsFree() const { return fFullClearIsFree; }
262 264
263 bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; } 265 bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; }
264 266
265 /** 267 /**
266 * Returns a string containing the caps info. 268 * Returns a string containing the caps info.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx)); 319 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
318 } 320 }
319 }; 321 };
320 322
321 void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*); 323 void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
322 void initStencilFormats(const GrGLContextInfo&); 324 void initStencilFormats(const GrGLContextInfo&);
323 // This must be called after initFSAASupport(). 325 // This must be called after initFSAASupport().
324 void initConfigRenderableTable(const GrGLContextInfo&); 326 void initConfigRenderableTable(const GrGLContextInfo&);
325 void initConfigTexturableTable(const GrGLContextInfo&, const GrGLInterface*) ; 327 void initConfigTexturableTable(const GrGLContextInfo&, const GrGLInterface*) ;
326 328
329 bool doReadPixelsSupported(const GrGLInterface* intf,
330 GrGLenum format,
331 GrGLenum type) const;
332
327 // tracks configs that have been verified to pass the FBO completeness when 333 // tracks configs that have been verified to pass the FBO completeness when
328 // used as a color attachment 334 // used as a color attachment
329 VerifiedColorConfigs fVerifiedColorConfigs; 335 VerifiedColorConfigs fVerifiedColorConfigs;
330 336
331 SkTArray<StencilFormat, true> fStencilFormats; 337 SkTArray<StencilFormat, true> fStencilFormats;
332 // tracks configs that have been verified to pass the FBO completeness when 338 // tracks configs that have been verified to pass the FBO completeness when
333 // used as a color attachment when a particular stencil format is used 339 // used as a color attachment when a particular stencil format is used
334 // as a stencil attachment. 340 // as a stencil attachment.
335 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs; 341 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
336 342
(...skipping 20 matching lines...) Expand all
357 bool fTextureRedSupport : 1; 363 bool fTextureRedSupport : 1;
358 bool fImagingSupport : 1; 364 bool fImagingSupport : 1;
359 bool fTwoFormatLimit : 1; 365 bool fTwoFormatLimit : 1;
360 bool fFragCoordsConventionSupport : 1; 366 bool fFragCoordsConventionSupport : 1;
361 bool fVertexArrayObjectSupport : 1; 367 bool fVertexArrayObjectSupport : 1;
362 bool fUseNonVBOVertexAndIndexDynamicData : 1; 368 bool fUseNonVBOVertexAndIndexDynamicData : 1;
363 bool fIsCoreProfile : 1; 369 bool fIsCoreProfile : 1;
364 bool fFullClearIsFree : 1; 370 bool fFullClearIsFree : 1;
365 bool fDropsTileOnZeroDivide : 1; 371 bool fDropsTileOnZeroDivide : 1;
366 372
373 struct ReadPixelsSupportedFormatsKey {
374 GrGLenum fFormat;
375 GrGLenum fType;
376 GrGLenum fFboFormat;
377
378 bool operator==(const ReadPixelsSupportedFormatsKey& rhs) const {
379 return fFormat == rhs.fFormat
380 && fType == rhs.fType
381 && fFboFormat == rhs.fFboFormat;
382 }
383 };
384
385 class ReadPixelsSupportedFormats {
386 public:
387 ReadPixelsSupportedFormats(ReadPixelsSupportedFormatsKey key,
388 bool value)
389 :fKey(key), fValue(value) {
390 }
391
392 static const ReadPixelsSupportedFormatsKey& GetKey(const ReadPixelsSuppo rtedFormats& element) {
393 return element.fKey;
394 }
395 static uint32_t Hash(const ReadPixelsSupportedFormatsKey&);
396
397 bool value() const { return fValue; }
398 private:
399 ReadPixelsSupportedFormatsKey fKey;
400 bool fValue;
401 };
402
403 template <typename T,
404 typename Key,
405 typename Traits = T,
406 int kGrowPercent = 75>
407 class DynamicHashCache {
Justin Novosad 2014/07/04 14:42:27 This seems like a generally useful wrapper for SkT
bsalomon 2014/07/07 13:31:10 Adding the other Mike WRT this comment.
mtklein 2014/07/07 13:44:30 Yup, does sound useful to me too. We seem to have
mtklein 2014/07/07 13:44:30 If possible, class DynamicHashCache : SkNoncopyabl
Rémi Piotaix 2014/07/07 18:10:17 Done.
Rémi Piotaix 2014/07/07 18:10:17 Done.
408 public:
409 DynamicHashCache() {
410 fDict = new SkTDynamicHash<T, Key, Traits, kGrowPercent>();
mtklein 2014/07/07 13:44:30 fDict = SkNEW(SkTDynamicHash<T, Key, Traits, kGrow
Rémi Piotaix 2014/07/07 18:10:16 Done.
411 }
412
413 virtual ~DynamicHashCache() {
mtklein 2014/07/07 13:44:30 Don't make this virtual? Nothing else is virtual.
Rémi Piotaix 2014/07/07 18:10:17 Done.
414 delete fDict;
415 }
416
417 bool has(Key& key) const {
mtklein 2014/07/07 13:44:30 Can any of these parameters be passed as const Key
Rémi Piotaix 2014/07/07 18:10:17 Done.
418 return NULL != find(key);
mtklein 2014/07/07 13:44:30 return NULL != this->find(key);
Rémi Piotaix 2014/07/07 18:10:17 Done.
419 }
420
421 T* find(Key& key) const {
422 return fDict->find(key);
423 }
424
425 // if element already in cache, return immediately the cached value
426 T& put(T& element) {
427 Key key = Traits::GetKey(element);
428 if(has(key))
mtklein 2014/07/07 13:44:30 if (this->has(key)) { return *this->find(key); }
Rémi Piotaix 2014/07/07 18:10:17 Done.
429 return *find(key);
mtklein 2014/07/07 13:44:30 Does this all optimize away into one call to find(
Rémi Piotaix 2014/07/07 18:10:17 Done.
430
431 T& e = fValues.push_back(element);
432
433 fDict->add(&e);
mtklein 2014/07/07 13:44:30 Aren't these pointers invalidated when fValues res
Rémi Piotaix 2014/07/07 18:10:17 Yes, you're right. I've corrected this in the new
434
435 return e;
436 }
437
438 int size() {
439 return fValues.count();
440 }
441
442 void clear() {
443 fValues.reset();
444 delete fDict;
445 fDict = new SkTDynamicHash<T, Key, Traits, kGrowPercent>();
mtklein 2014/07/07 13:44:30 Seems like we could make fDict a non-pointer membe
446 }
447 private:
448 SkTDynamicHash<T, Key, Traits, kGrowPercent>* fDict;
449 SkTArray<T, true> fValues;
450 };
451
452 mutable DynamicHashCache<ReadPixelsSupportedFormats, ReadPixelsSupportedForm atsKey> fReadPixelsSupportedCache;
453
367 typedef GrDrawTargetCaps INHERITED; 454 typedef GrDrawTargetCaps INHERITED;
368 }; 455 };
369 456
370 #endif 457 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/gl/GrGLCaps.cpp » ('j') | src/gpu/gl/GrGLCaps.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698