Change GR_COMPRESS_ALPHA_MASK from compile-time flag to run-time. We do this by introducing an Options struct to be passed to a GrContext on creation.

R=robertphillips@google.com, bsalomon@google.com

Author: krajcevski@google.com

Review URL: https://codereview.chromium.org/459033002
This commit is contained in:
krajcevski 2014-08-12 07:26:25 -07:00 committed by Commit bot
parent 03bde3e6fa
commit 9c6d4d744a
4 changed files with 31 additions and 13 deletions

View File

@ -74,9 +74,6 @@
'../include/gpu',
],
},
'defines': [
'GR_COMPRESS_ALPHA_MASK=0',
],
},
'targets': [
{

View File

@ -49,10 +49,19 @@ class SK_API GrContext : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(GrContext)
struct Options {
Options() : fDrawPathToCompressedTexture(false) { }
// EXPERIMENTAL
// May be removed in the future, or may become standard depending
// on the outcomes of a variety of internal tests.
bool fDrawPathToCompressedTexture;
};
/**
* Creates a GrContext for a backend context.
*/
static GrContext* Create(GrBackend, GrBackendContext);
static GrContext* Create(GrBackend, GrBackendContext, const Options* opts = NULL);
virtual ~GrContext();
@ -939,6 +948,12 @@ public:
GrPathRendererChain::DrawType drawType = GrPathRendererChain::kColor_DrawType,
GrPathRendererChain::StencilSupport* stencilSupport = NULL);
/**
* This returns a copy of the the GrContext::Options that was passed to the
* constructor of this class.
*/
const Options& getOptions() const { return fOptions; }
#if GR_CACHE_STATS
void printCacheStats() const;
#endif
@ -987,7 +1002,9 @@ private:
int fMaxTextureSizeOverride;
GrContext(); // init must be called after the constructor.
const Options fOptions;
GrContext(const Options&); // init must be called after the constructor.
bool init(GrBackend, GrBackendContext);
void setupDrawBuffer();

View File

@ -84,8 +84,15 @@ private:
GrContext* fContext;
};
GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) {
GrContext* context = SkNEW(GrContext);
GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext,
const Options* opts) {
GrContext* context;
if (NULL == opts) {
context = SkNEW_ARGS(GrContext, (Options()));
} else {
context = SkNEW_ARGS(GrContext, (*opts));
}
if (context->init(backend, backendContext)) {
return context;
} else {
@ -94,7 +101,7 @@ GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
}
}
GrContext::GrContext() {
GrContext::GrContext(const Options& opts) : fOptions(opts) {
fDrawState = NULL;
fGpu = NULL;
fClip = NULL;

View File

@ -66,7 +66,6 @@ static inline GrPixelConfig fmt_to_config(SkTextureCompressor::Format fmt) {
return config;
}
#if GR_COMPRESS_ALPHA_MASK
static bool choose_compressed_fmt(const GrDrawTargetCaps* caps,
SkTextureCompressor::Format *fmt) {
if (NULL == fmt) {
@ -95,7 +94,6 @@ static bool choose_compressed_fmt(const GrDrawTargetCaps* caps,
return false;
}
#endif
}
@ -171,11 +169,10 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds,
SkIRect bounds = SkIRect::MakeWH(resultBounds.width(),
resultBounds.height());
#if GR_COMPRESS_ALPHA_MASK
if (choose_compressed_fmt(fContext->getGpu()->caps(), &fCompressedFormat)) {
if (fContext->getOptions().fDrawPathToCompressedTexture &&
choose_compressed_fmt(fContext->getGpu()->caps(), &fCompressedFormat)) {
fCompressionMode = kCompress_CompressionMode;
}
#endif
// Make sure that the width is a multiple of the desired block dimensions
// to allow for specialized SIMD instructions that compress multiple blocks at a time.