| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 #ifndef GrContext_DEFINED | 8 #ifndef GrContext_DEFINED |
| 9 #define GrContext_DEFINED | 9 #define GrContext_DEFINED |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 class GrTestTarget; | 39 class GrTestTarget; |
| 40 class GrTextBlobCache; | 40 class GrTextBlobCache; |
| 41 class GrTextContext; | 41 class GrTextContext; |
| 42 class GrTextureParams; | 42 class GrTextureParams; |
| 43 class GrVertexBuffer; | 43 class GrVertexBuffer; |
| 44 class GrStrokeInfo; | 44 class GrStrokeInfo; |
| 45 class GrSoftwarePathRenderer; | 45 class GrSoftwarePathRenderer; |
| 46 | 46 |
| 47 class SK_API GrContext : public SkRefCnt { | 47 class SK_API GrContext : public SkRefCnt { |
| 48 public: | 48 public: |
| 49 SK_DECLARE_INST_COUNT(GrContext) | |
| 50 | |
| 51 /** | 49 /** |
| 52 * Creates a GrContext for a backend context. | 50 * Creates a GrContext for a backend context. |
| 53 */ | 51 */ |
| 54 static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions
& options); | 52 static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions
& options); |
| 55 static GrContext* Create(GrBackend, GrBackendContext); | 53 static GrContext* Create(GrBackend, GrBackendContext); |
| 56 | 54 |
| 57 /** | 55 /** |
| 58 * Only defined in test apps. | 56 * Only defined in test apps. |
| 59 */ | 57 */ |
| 60 static GrContext* CreateMockContext(); | 58 static GrContext* CreateMockContext(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 83 * The 'info' parameter will be stored and passed to the callback function. | 81 * The 'info' parameter will be stored and passed to the callback function. |
| 84 */ | 82 */ |
| 85 void addCleanUp(PFCleanUpFunc cleanUp, void* info) { | 83 void addCleanUp(PFCleanUpFunc cleanUp, void* info) { |
| 86 CleanUpData* entry = fCleanUpData.push(); | 84 CleanUpData* entry = fCleanUpData.push(); |
| 87 | 85 |
| 88 entry->fFunc = cleanUp; | 86 entry->fFunc = cleanUp; |
| 89 entry->fInfo = info; | 87 entry->fInfo = info; |
| 90 } | 88 } |
| 91 | 89 |
| 92 /** | 90 /** |
| 93 * Abandons all GPU resources and assumes the underlying backend 3D API | 91 * Abandons all GPU resources and assumes the underlying backend 3D API |
| 94 * context is not longer usable. Call this if you have lost the associated | 92 * context is not longer usable. Call this if you have lost the associated |
| 95 * GPU context, and thus internal texture, buffer, etc. references/IDs are | 93 * GPU context, and thus internal texture, buffer, etc. references/IDs are |
| 96 * now invalid. Should be called even when GrContext is no longer going to | 94 * now invalid. Should be called even when GrContext is no longer going to |
| 97 * be used for two reasons: | 95 * be used for two reasons: |
| 98 * 1) ~GrContext will not try to free the objects in the 3D API. | 96 * 1) ~GrContext will not try to free the objects in the 3D API. |
| 99 * 2) Any GrGpuResources created by this GrContext that outlive | 97 * 2) Any GrGpuResources created by this GrContext that outlive |
| 100 * will be marked as invalid (GrGpuResource::wasDestroyed()) and | 98 * will be marked as invalid (GrGpuResource::wasDestroyed()) and |
| 101 * when they're destroyed no 3D API calls will be made. | 99 * when they're destroyed no 3D API calls will be made. |
| 102 * Content drawn since the last GrContext::flush() may be lost. After this | 100 * Content drawn since the last GrContext::flush() may be lost. After this |
| 103 * function is called the only valid action on the GrContext or | 101 * function is called the only valid action on the GrContext or |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 * @param config the configuration of the render target. | 163 * @param config the configuration of the render target. |
| 166 * @param dpi the display density in dots per inch. | 164 * @param dpi the display density in dots per inch. |
| 167 * | 165 * |
| 168 * @return sample count that should be perform well and have good enough | 166 * @return sample count that should be perform well and have good enough |
| 169 * rendering quality for the display. Alternatively returns 0 if | 167 * rendering quality for the display. Alternatively returns 0 if |
| 170 * MSAA is not supported or recommended to be used by default. | 168 * MSAA is not supported or recommended to be used by default. |
| 171 */ | 169 */ |
| 172 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; | 170 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; |
| 173 | 171 |
| 174 /** | 172 /** |
| 175 * Returns a helper object to orchestrate draws. | 173 * Returns a helper object to orchestrate draws. |
| 176 * Callers should take a ref if they rely on the GrDrawContext sticking arou
nd. | 174 * Callers should take a ref if they rely on the GrDrawContext sticking arou
nd. |
| 177 * NULL will be returned if the context has been abandoned. | 175 * NULL will be returned if the context has been abandoned. |
| 178 * | 176 * |
| 179 * @param devProps the device properties (mainly defines text drawing) | 177 * @param devProps the device properties (mainly defines text drawing) |
| 180 * | 178 * |
| 181 * @return a draw context | 179 * @return a draw context |
| 182 */ | 180 */ |
| 183 GrDrawContext* drawContext(const SkSurfaceProps* surfaceProps = NULL) { | 181 GrDrawContext* drawContext(const SkSurfaceProps* surfaceProps = NULL) { |
| 184 return fDrawingMgr.drawContext(surfaceProps); | 182 return fDrawingMgr.drawContext(surfaceProps); |
| 185 } | 183 } |
| 186 | 184 |
| 187 /////////////////////////////////////////////////////////////////////////// | 185 /////////////////////////////////////////////////////////////////////////// |
| 188 // Misc. | 186 // Misc. |
| 189 | 187 |
| 190 /** | 188 /** |
| 191 * Flags that affect flush() behavior. | 189 * Flags that affect flush() behavior. |
| 192 */ | 190 */ |
| 193 enum FlushBits { | 191 enum FlushBits { |
| 194 /** | 192 /** |
| 195 * A client may reach a point where it has partially rendered a frame | 193 * A client may reach a point where it has partially rendered a frame |
| 196 * through a GrContext that it knows the user will never see. This flag | 194 * through a GrContext that it knows the user will never see. This flag |
| 197 * causes the flush to skip submission of deferred content to the 3D API | 195 * causes the flush to skip submission of deferred content to the 3D API |
| 198 * during the flush. | 196 * during the flush. |
| 199 */ | 197 */ |
| 200 kDiscard_FlushBit = 0x2, | 198 kDiscard_FlushBit = 0x2, |
| 201 }; | 199 }; |
| 202 | 200 |
| 203 /** | 201 /** |
| 204 * Call to ensure all drawing to the context has been issued to the | 202 * Call to ensure all drawing to the context has been issued to the |
| 205 * underlying 3D API. | 203 * underlying 3D API. |
| 206 * @param flagsBitfield flags that control the flushing behavior. See | 204 * @param flagsBitfield flags that control the flushing behavior. See |
| 207 * FlushBits. | 205 * FlushBits. |
| 208 */ | 206 */ |
| 209 void flush(int flagsBitfield = 0); | 207 void flush(int flagsBitfield = 0); |
| 210 | 208 |
| 211 void flushIfNecessary() { | 209 void flushIfNecessary() { |
| 212 if (fFlushToReduceCacheSize) { | 210 if (fFlushToReduceCacheSize) { |
| 213 this->flush(); | 211 this->flush(); |
| 214 } | 212 } |
| 215 } | 213 } |
| 216 | 214 |
| 217 /** | 215 /** |
| 218 * These flags can be used with the read/write pixels functions below. | 216 * These flags can be used with the read/write pixels functions below. |
| 219 */ | 217 */ |
| 220 enum PixelOpsFlags { | 218 enum PixelOpsFlags { |
| 221 /** The GrContext will not be flushed before the surface read or write.
This means that | 219 /** The GrContext will not be flushed before the surface read or write.
This means that |
| 222 the read or write may occur before previous draws have executed. */ | 220 the read or write may occur before previous draws have executed. */ |
| 223 kDontFlush_PixelOpsFlag = 0x1, | 221 kDontFlush_PixelOpsFlag = 0x1, |
| 224 /** Any surface writes should be flushed to the backend 3D API after the
surface operation | 222 /** Any surface writes should be flushed to the backend 3D API after the
surface operation |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ | 354 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ |
| 357 void dumpGpuStats(SkString*) const; | 355 void dumpGpuStats(SkString*) const; |
| 358 void printGpuStats() const; | 356 void printGpuStats() const; |
| 359 | 357 |
| 360 private: | 358 private: |
| 361 GrGpu* fGpu; | 359 GrGpu* fGpu; |
| 362 const GrCaps* fCaps; | 360 const GrCaps* fCaps; |
| 363 GrResourceCache* fResourceCache; | 361 GrResourceCache* fResourceCache; |
| 364 // this union exists because the inheritance of GrTextureProvider->GrResourc
eProvider | 362 // this union exists because the inheritance of GrTextureProvider->GrResourc
eProvider |
| 365 // is in a private header. | 363 // is in a private header. |
| 366 union { | 364 union { |
| 367 GrResourceProvider* fResourceProvider; | 365 GrResourceProvider* fResourceProvider; |
| 368 GrTextureProvider* fTextureProvider; | 366 GrTextureProvider* fTextureProvider; |
| 369 }; | 367 }; |
| 370 | 368 |
| 371 GrBatchFontCache* fBatchFontCache; | 369 GrBatchFontCache* fBatchFontCache; |
| 372 SkAutoTDelete<GrLayerCache> fLayerCache; | 370 SkAutoTDelete<GrLayerCache> fLayerCache; |
| 373 SkAutoTDelete<GrTextBlobCache> fTextBlobCache; | 371 SkAutoTDelete<GrTextBlobCache> fTextBlobCache; |
| 374 | 372 |
| 375 GrPathRendererChain* fPathRendererChain; | 373 GrPathRendererChain* fPathRendererChain; |
| 376 GrSoftwarePathRenderer* fSoftwarePathRenderer; | 374 GrSoftwarePathRenderer* fSoftwarePathRenderer; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 391 const uint32_t fUniqueID; | 389 const uint32_t fUniqueID; |
| 392 | 390 |
| 393 GrContext(); // init must be called after the constructor. | 391 GrContext(); // init must be called after the constructor. |
| 394 bool init(GrBackend, GrBackendContext, const GrContextOptions& options); | 392 bool init(GrBackend, GrBackendContext, const GrContextOptions& options); |
| 395 | 393 |
| 396 // Currently the DrawingMgr stores a separate GrDrawContext for each | 394 // Currently the DrawingMgr stores a separate GrDrawContext for each |
| 397 // combination of text drawing options (pixel geometry x DFT use) | 395 // combination of text drawing options (pixel geometry x DFT use) |
| 398 // and hands the appropriate one back given the user's request. | 396 // and hands the appropriate one back given the user's request. |
| 399 // All of the GrDrawContexts still land in the same GrDrawTarget! | 397 // All of the GrDrawContexts still land in the same GrDrawTarget! |
| 400 // | 398 // |
| 401 // In the future this class will allocate a new GrDrawContext for | 399 // In the future this class will allocate a new GrDrawContext for |
| 402 // each GrRenderTarget/GrDrawTarget and manage the DAG. | 400 // each GrRenderTarget/GrDrawTarget and manage the DAG. |
| 403 class DrawingMgr { | 401 class DrawingMgr { |
| 404 public: | 402 public: |
| 405 DrawingMgr() : fDrawTarget(NULL) { | 403 DrawingMgr() : fDrawTarget(NULL) { |
| 406 sk_bzero(fDrawContext, sizeof(fDrawContext)); | 404 sk_bzero(fDrawContext, sizeof(fDrawContext)); |
| 407 } | 405 } |
| 408 | 406 |
| 409 ~DrawingMgr(); | 407 ~DrawingMgr(); |
| 410 | 408 |
| 411 void init(GrContext* context); | 409 void init(GrContext* context); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 /** | 455 /** |
| 458 * A callback similar to the above for use by the TextBlobCache | 456 * A callback similar to the above for use by the TextBlobCache |
| 459 * TODO move textblob draw calls below context so we can use the call above. | 457 * TODO move textblob draw calls below context so we can use the call above. |
| 460 */ | 458 */ |
| 461 static void TextBlobCacheOverBudgetCB(void* data); | 459 static void TextBlobCacheOverBudgetCB(void* data); |
| 462 | 460 |
| 463 typedef SkRefCnt INHERITED; | 461 typedef SkRefCnt INHERITED; |
| 464 }; | 462 }; |
| 465 | 463 |
| 466 #endif | 464 #endif |
| OLD | NEW |