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