| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 | 10 |
| 11 #include "GrAARectRenderer.h" | 11 #include "GrAARectRenderer.h" |
| 12 #include "GrAtlasTextContext.h" | 12 #include "GrAtlasTextContext.h" |
| 13 #include "GrBatch.h" | 13 #include "GrBatch.h" |
| 14 #include "GrBatchFontCache.h" | 14 #include "GrBatchFontCache.h" |
| 15 #include "GrBatchTarget.h" | 15 #include "GrBatchTarget.h" |
| 16 #include "GrBatchTest.h" | 16 #include "GrBatchTest.h" |
| 17 #include "GrCaps.h" | 17 #include "GrCaps.h" |
| 18 #include "GrContextOptions.h" |
| 18 #include "GrDefaultGeoProcFactory.h" | 19 #include "GrDefaultGeoProcFactory.h" |
| 19 #include "GrGpuResource.h" | 20 #include "GrGpuResource.h" |
| 20 #include "GrGpuResourcePriv.h" | 21 #include "GrGpuResourcePriv.h" |
| 21 #include "GrGpu.h" | 22 #include "GrGpu.h" |
| 22 #include "GrImmediateDrawTarget.h" | 23 #include "GrImmediateDrawTarget.h" |
| 23 #include "GrIndexBuffer.h" | 24 #include "GrIndexBuffer.h" |
| 24 #include "GrInOrderDrawBuffer.h" | 25 #include "GrInOrderDrawBuffer.h" |
| 25 #include "GrLayerCache.h" | 26 #include "GrLayerCache.h" |
| 26 #include "GrOvalRenderer.h" | 27 #include "GrOvalRenderer.h" |
| 27 #include "GrPathRenderer.h" | 28 #include "GrPathRenderer.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 ~AutoCheckFlush() { | 64 ~AutoCheckFlush() { |
| 64 if (fContext->fFlushToReduceCacheSize) { | 65 if (fContext->fFlushToReduceCacheSize) { |
| 65 fContext->flush(); | 66 fContext->flush(); |
| 66 } | 67 } |
| 67 } | 68 } |
| 68 | 69 |
| 69 private: | 70 private: |
| 70 GrContext* fContext; | 71 GrContext* fContext; |
| 71 }; | 72 }; |
| 72 | 73 |
| 74 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ |
| 75 GrContextOptions defaultOptions; |
| 76 return Create(backend, backendContext, defaultOptions); |
| 77 } |
| 78 |
| 73 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, | 79 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, |
| 74 const Options* opts) { | 80 const GrContextOptions& options) { |
| 75 GrContext* context; | 81 GrContext* context = SkNEW(GrContext); |
| 76 if (NULL == opts) { | |
| 77 context = SkNEW_ARGS(GrContext, (Options())); | |
| 78 } else { | |
| 79 context = SkNEW_ARGS(GrContext, (*opts)); | |
| 80 } | |
| 81 | 82 |
| 82 if (context->init(backend, backendContext)) { | 83 if (context->init(backend, backendContext, options)) { |
| 83 return context; | 84 return context; |
| 84 } else { | 85 } else { |
| 85 context->unref(); | 86 context->unref(); |
| 86 return NULL; | 87 return NULL; |
| 87 } | 88 } |
| 88 } | 89 } |
| 89 | 90 |
| 90 static int32_t gNextID = 1; | 91 static int32_t gNextID = 1; |
| 91 static int32_t next_id() { | 92 static int32_t next_id() { |
| 92 int32_t id; | 93 int32_t id; |
| 93 do { | 94 do { |
| 94 id = sk_atomic_inc(&gNextID); | 95 id = sk_atomic_inc(&gNextID); |
| 95 } while (id == SK_InvalidGenID); | 96 } while (id == SK_InvalidGenID); |
| 96 return id; | 97 return id; |
| 97 } | 98 } |
| 98 | 99 |
| 99 GrContext::GrContext(const Options& opts) : fOptions(opts), fUniqueID(next_id())
{ | 100 GrContext::GrContext() : fUniqueID(next_id()) { |
| 100 fGpu = NULL; | 101 fGpu = NULL; |
| 101 fResourceCache = NULL; | 102 fResourceCache = NULL; |
| 102 fResourceProvider = NULL; | 103 fResourceProvider = NULL; |
| 103 fPathRendererChain = NULL; | 104 fPathRendererChain = NULL; |
| 104 fSoftwarePathRenderer = NULL; | 105 fSoftwarePathRenderer = NULL; |
| 105 fBatchFontCache = NULL; | 106 fBatchFontCache = NULL; |
| 106 fDrawBuffer = NULL; | 107 fDrawBuffer = NULL; |
| 107 fFlushToReduceCacheSize = false; | 108 fFlushToReduceCacheSize = false; |
| 108 fAARectRenderer = NULL; | 109 fAARectRenderer = NULL; |
| 109 fOvalRenderer = NULL; | 110 fOvalRenderer = NULL; |
| 110 fMaxTextureSizeOverride = 1 << 20; | 111 fMaxTextureSizeOverride = 1 << 20; |
| 111 } | 112 } |
| 112 | 113 |
| 113 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { | 114 bool GrContext::init(GrBackend backend, GrBackendContext backendContext, |
| 115 const GrContextOptions& options) { |
| 114 SkASSERT(NULL == fGpu); | 116 SkASSERT(NULL == fGpu); |
| 115 | 117 |
| 116 fGpu = GrGpu::Create(backend, backendContext, this); | 118 fGpu = GrGpu::Create(backend, backendContext, options, this); |
| 117 if (NULL == fGpu) { | 119 if (NULL == fGpu) { |
| 118 return false; | 120 return false; |
| 119 } | 121 } |
| 120 this->initCommon(); | 122 this->initCommon(); |
| 121 return true; | 123 return true; |
| 122 } | 124 } |
| 123 | 125 |
| 124 void GrContext::initCommon() { | 126 void GrContext::initCommon() { |
| 125 fResourceCache = SkNEW(GrResourceCache); | 127 fResourceCache = SkNEW(GrResourceCache); |
| 126 fResourceCache->setOverBudgetCallback(OverBudgetCB, this); | 128 fResourceCache->setOverBudgetCallback(OverBudgetCB, this); |
| (...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1990 geometry.fColor = GrRandomColor(random); | 1992 geometry.fColor = GrRandomColor(random); |
| 1991 return DrawVerticesBatch::Create(geometry, type, viewMatrix, | 1993 return DrawVerticesBatch::Create(geometry, type, viewMatrix, |
| 1992 positions.begin(), vertexCount, | 1994 positions.begin(), vertexCount, |
| 1993 indices.begin(), hasIndices ? vertexCount :
0, | 1995 indices.begin(), hasIndices ? vertexCount :
0, |
| 1994 colors.begin(), | 1996 colors.begin(), |
| 1995 texCoords.begin(), | 1997 texCoords.begin(), |
| 1996 bounds); | 1998 bounds); |
| 1997 } | 1999 } |
| 1998 | 2000 |
| 1999 #endif | 2001 #endif |
| OLD | NEW |