8 #ifndef GrContext_DEFINED
9 #define GrContext_DEFINED
15 #include "GrRenderTarget.h"
16 #include "GrTextureProvider.h"
18 #include "SkPathEffect.h"
20 #include "../private/GrAuditTrail.h"
21 #include "../private/GrSingleOwner.h"
22 #include "../private/SkMutex.h"
24 struct GrBatchAtlasConfig;
25 class GrBatchFontCache;
29 class GrDrawingManager;
36 class GrPipelineBuilder;
37 class GrResourceEntry;
38 class GrResourceCache;
39 class GrResourceProvider;
41 class GrTextBlobCache;
54 static GrContext* Create(GrBackend, GrBackendContext);
73 void resetContext(uint32_t state = kAll_GrBackendState);
79 typedef void (*PFCleanUpFunc)(
const GrContext* context,
void* info);
89 entry->fFunc = cleanUp;
104 void abandonContext();
115 void releaseResourcesAndAbandonContext();
128 void getResourceCacheLimits(
int* maxResources,
size_t* maxResourceBytes)
const;
138 void getResourceCacheUsage(
int* resourceCount,
size_t* resourceBytes)
const;
149 void setResourceCacheLimits(
int maxResources,
size_t maxResourceBytes);
158 void freeGpuResources();
165 void purgeAllUnlockedResources();
181 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi)
const;
189 int width,
int height,
190 GrPixelConfig config,
193 GrSurfaceOrigin origin = kDefault_GrSurfaceOrigin,
195 SkBudgeted = SkBudgeted::kYes);
210 kDiscard_FlushBit = 0x2,
219 void flush(
int flagsBitfield = 0);
221 void flushIfNecessary() {
222 if (fFlushToReduceCacheSize || this->caps()->immediateFlush()) {
233 kDontFlush_PixelOpsFlag = 0x1,
236 kFlushWrites_PixelOp = 0x2,
239 kUnpremul_PixelOpsFlag = 0x4,
258 bool readSurfacePixels(
GrSurface* surface,
259 int left,
int top,
int width,
int height,
260 GrPixelConfig config,
void* buffer,
262 uint32_t pixelOpsFlags = 0);
279 bool writeSurfacePixels(
GrSurface* surface,
280 int left,
int top,
int width,
int height,
281 GrPixelConfig config,
const void* buffer,
283 uint32_t pixelOpsFlags = 0);
300 return this->copySurface(dst, src, SkIRect::MakeWH(dst->
width(), dst->
height()),
301 SkIPoint::Make(0,0));
307 void flushSurfaceWrites(
GrSurface* surface);
323 void prepareSurfaceForExternalIO(
GrSurface*);
332 GrGpu* getGpu() {
return fGpu; }
333 const GrGpu* getGpu()
const {
return fGpu; }
334 GrBatchFontCache* getBatchFontCache() {
return fBatchFontCache; }
335 GrTextBlobCache* getTextBlobCache() {
return fTextBlobCache; }
336 bool abandoned()
const;
337 GrResourceProvider* resourceProvider() {
return fResourceProvider; }
338 const GrResourceProvider* resourceProvider()
const {
return fResourceProvider; }
339 GrResourceCache* getResourceCache() {
return fResourceCache; }
345 void resetGpuStats()
const ;
348 void dumpCacheStats(
SkString*)
const;
349 void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values)
const;
350 void printCacheStats()
const;
354 void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values)
const;
355 void printGpuStats()
const;
359 void setTextBlobCacheLimit_ForTesting(
size_t bytes);
363 void setTextContextAtlasSizes_ForTesting(
const GrBatchAtlasConfig* configs);
369 GrTexture* getFontAtlasTexture(GrMaskFormat format);
371 GrAuditTrail* getAuditTrail() {
return &fAuditTrail; }
374 SkDEBUGCODE(GrSingleOwner* debugSingleOwner()
const {
return &fSingleOwner; } )
377 GrContextPriv contextPriv();
378 const GrContextPriv contextPriv()
const;
383 GrResourceCache* fResourceCache;
387 GrResourceProvider* fResourceProvider;
393 GrBatchFontCache* fBatchFontCache;
394 SkAutoTDelete<GrTextBlobCache> fTextBlobCache;
397 bool fFlushToReduceCacheSize;
398 bool fDidTestPMConversions;
399 int fPMToUPMConversion;
400 int fUPMToPMConversion;
411 SkMutex fReadPixelsMutex;
412 SkMutex fTestPMConversionsMutex;
417 mutable GrSingleOwner fSingleOwner;
424 SkTDArray<CleanUpData> fCleanUpData;
426 const uint32_t fUniqueID;
428 SkAutoTDelete<GrDrawingManager> fDrawingManager;
430 GrAuditTrail fAuditTrail;
433 friend class GrClipStackClip;
434 friend class GrDrawingManager;
435 friend class GrContextPriv;
437 GrDrawingManager* drawingManager() {
return fDrawingManager; }
442 void initMockContext();
457 void testPMConversionsIfNecessary(uint32_t flags);
460 bool didFailPMUPMConversionTest()
const;
466 static void OverBudgetCB(
void* data);
472 static void TextBlobCacheOverBudgetCB(
void* data);
485 , fContextUniqueID(uniqueID) {}
488 uint32_t fContextUniqueID;
Definition: GrContextOptions.h:13
Provides custom fragment shader code.
Definition: GrFragmentProcessor.h:24
Represents the capabilities of a GrContext.
Definition: GrCaps.h:130
const GrCaps * caps() const
Access the context capabilities.
Definition: GrContext.h:168
Definition: GrTextureProvider.h:16
Describes properties and constraints of a given SkSurface.
Definition: SkSurfaceProps.h:51
Represents the filtering and tile modes used to access a texture.
Definition: GrTextureParams.h:17
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
Definition: SkRefCnt.h:135
uint32_t uniqueID()
An ID associated with this context, guaranteed to be unique.
Definition: GrContext.h:328
Definition: GrSurface.h:21
int width() const
Retrieves the width of the surface.
Definition: GrSurface.h:26
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:258
Definition: GrDrawContext.h:51
Definition: GrContext.h:48
int height() const
Retrieves the height of the surface.
Definition: GrSurface.h:31
void addCleanUp(PFCleanUpFunc cleanUp, void *info)
Add a function to be called from within GrContext's destructor.
Definition: GrContext.h:86
FlushBits
Flags that affect flush() behavior.
Definition: GrContext.h:203
Interface for memory tracing.
Definition: SkTraceMemoryDump.h:20
bool copySurface(GrSurface *dst, GrSurface *src)
Helper that copies the whole surface but fails when the two surfaces are not identically sized...
Definition: GrContext.h:299
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
Definition: GrTexture.h:19
SkImage is an abstraction for drawing a rectagle of pixels, though the particular type of image could...
Definition: SkImage.h:45
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40
Definition: GrContext.h:419
PixelOpsFlags
These flags can be used with the read/write pixels functions below.
Definition: GrContext.h:230
Light weight class for managing strings.
Definition: SkString.h:121
Can be used to perform actions related to the generating GrContext in a thread safe manner...
Definition: GrContext.h:481