OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
4 * Copyright (C) 2010 Mozilla Corporation. All rights reserved. | 4 * Copyright (C) 2010 Mozilla Corporation. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "wtf/text/WTFString.h" | 47 #include "wtf/text/WTFString.h" |
48 | 48 |
49 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
50 #include "public/platform/WebGraphicsContext3D.h" | 50 #include "public/platform/WebGraphicsContext3D.h" |
51 #include "public/platform/WebGraphicsContext3DProvider.h" | 51 #include "public/platform/WebGraphicsContext3DProvider.h" |
52 | 52 |
53 namespace WebCore { | 53 namespace WebCore { |
54 | 54 |
55 namespace { | 55 namespace { |
56 | 56 |
57 void getDrawingParameters(DrawingBuffer* drawingBuffer, WebKit::WebGraphicsConte
xt3D* graphicsContext3D, | 57 void getDrawingParameters(DrawingBuffer* drawingBuffer, blink::WebGraphicsContex
t3D* graphicsContext3D, |
58 Platform3DObject* frameBufferId, int* width, int* heig
ht) | 58 Platform3DObject* frameBufferId, int* width, int* heig
ht) |
59 { | 59 { |
60 ASSERT(drawingBuffer); | 60 ASSERT(drawingBuffer); |
61 *frameBufferId = drawingBuffer->framebuffer(); | 61 *frameBufferId = drawingBuffer->framebuffer(); |
62 *width = drawingBuffer->size().width(); | 62 *width = drawingBuffer->size().width(); |
63 *height = drawingBuffer->size().height(); | 63 *height = drawingBuffer->size().height(); |
64 } | 64 } |
65 | 65 |
66 } // anonymous namespace | 66 } // anonymous namespace |
67 | 67 |
68 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<WebKit::WebGraphicsContext3D> we
bContext, bool preserveDrawingBuffer) | 68 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3D> web
Context, bool preserveDrawingBuffer) |
69 : m_impl(webContext.get()) | 69 : m_impl(webContext.get()) |
70 , m_ownedWebContext(webContext) | 70 , m_ownedWebContext(webContext) |
71 , m_initializedAvailableExtensions(false) | 71 , m_initializedAvailableExtensions(false) |
72 , m_layerComposited(false) | 72 , m_layerComposited(false) |
73 , m_preserveDrawingBuffer(preserveDrawingBuffer) | 73 , m_preserveDrawingBuffer(preserveDrawingBuffer) |
74 , m_packAlignment(4) | 74 , m_packAlignment(4) |
75 , m_resourceSafety(ResourceSafetyUnknown) | 75 , m_resourceSafety(ResourceSafetyUnknown) |
76 , m_grContext(0) | 76 , m_grContext(0) |
77 { | 77 { |
78 } | 78 } |
79 | 79 |
80 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<WebKit::WebGraphicsContext3DProv
ider> provider, bool preserveDrawingBuffer) | 80 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3DProvi
der> provider, bool preserveDrawingBuffer) |
81 : m_provider(provider) | 81 : m_provider(provider) |
82 , m_impl(m_provider->context3d()) | 82 , m_impl(m_provider->context3d()) |
83 , m_initializedAvailableExtensions(false) | 83 , m_initializedAvailableExtensions(false) |
84 , m_layerComposited(false) | 84 , m_layerComposited(false) |
85 , m_preserveDrawingBuffer(preserveDrawingBuffer) | 85 , m_preserveDrawingBuffer(preserveDrawingBuffer) |
86 , m_packAlignment(4) | 86 , m_packAlignment(4) |
87 , m_resourceSafety(ResourceSafetyUnknown) | 87 , m_resourceSafety(ResourceSafetyUnknown) |
88 , m_grContext(m_provider->grContext()) | 88 , m_grContext(m_provider->grContext()) |
89 { | 89 { |
90 } | 90 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 { \ | 199 { \ |
200 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ | 200 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ |
201 } | 201 } |
202 | 202 |
203 #define DELEGATE_TO_WEBCONTEXT_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt)
\ | 203 #define DELEGATE_TO_WEBCONTEXT_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt)
\ |
204 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a
8, t9 a9) \ | 204 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a
8, t9 a9) \ |
205 { \ | 205 { \ |
206 return m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ | 206 return m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ |
207 } | 207 } |
208 | 208 |
209 class GraphicsContext3DContextLostCallbackAdapter : public WebKit::WebGraphicsCo
ntext3D::WebGraphicsContextLostCallback { | 209 class GraphicsContext3DContextLostCallbackAdapter : public blink::WebGraphicsCon
text3D::WebGraphicsContextLostCallback { |
210 public: | 210 public: |
211 GraphicsContext3DContextLostCallbackAdapter(PassOwnPtr<GraphicsContext3D::Co
ntextLostCallback> callback) | 211 GraphicsContext3DContextLostCallbackAdapter(PassOwnPtr<GraphicsContext3D::Co
ntextLostCallback> callback) |
212 : m_contextLostCallback(callback) { } | 212 : m_contextLostCallback(callback) { } |
213 virtual ~GraphicsContext3DContextLostCallbackAdapter() { } | 213 virtual ~GraphicsContext3DContextLostCallbackAdapter() { } |
214 | 214 |
215 virtual void onContextLost() | 215 virtual void onContextLost() |
216 { | 216 { |
217 if (m_contextLostCallback) | 217 if (m_contextLostCallback) |
218 m_contextLostCallback->onContextLost(); | 218 m_contextLostCallback->onContextLost(); |
219 } | 219 } |
220 private: | 220 private: |
221 OwnPtr<GraphicsContext3D::ContextLostCallback> m_contextLostCallback; | 221 OwnPtr<GraphicsContext3D::ContextLostCallback> m_contextLostCallback; |
222 }; | 222 }; |
223 | 223 |
224 class GraphicsContext3DErrorMessageCallbackAdapter : public WebKit::WebGraphicsC
ontext3D::WebGraphicsErrorMessageCallback { | 224 class GraphicsContext3DErrorMessageCallbackAdapter : public blink::WebGraphicsCo
ntext3D::WebGraphicsErrorMessageCallback { |
225 public: | 225 public: |
226 GraphicsContext3DErrorMessageCallbackAdapter(PassOwnPtr<GraphicsContext3D::E
rrorMessageCallback> callback) | 226 GraphicsContext3DErrorMessageCallbackAdapter(PassOwnPtr<GraphicsContext3D::E
rrorMessageCallback> callback) |
227 : m_errorMessageCallback(callback) { } | 227 : m_errorMessageCallback(callback) { } |
228 virtual ~GraphicsContext3DErrorMessageCallbackAdapter() { } | 228 virtual ~GraphicsContext3DErrorMessageCallbackAdapter() { } |
229 | 229 |
230 virtual void onErrorMessage(const WebKit::WebString& message, WebKit::WGC3Di
nt id) | 230 virtual void onErrorMessage(const blink::WebString& message, blink::WGC3Dint
id) |
231 { | 231 { |
232 if (m_errorMessageCallback) | 232 if (m_errorMessageCallback) |
233 m_errorMessageCallback->onErrorMessage(message, id); | 233 m_errorMessageCallback->onErrorMessage(message, id); |
234 } | 234 } |
235 private: | 235 private: |
236 OwnPtr<GraphicsContext3D::ErrorMessageCallback> m_errorMessageCallback; | 236 OwnPtr<GraphicsContext3D::ErrorMessageCallback> m_errorMessageCallback; |
237 }; | 237 }; |
238 | 238 |
239 void GraphicsContext3D::setContextLostCallback(PassOwnPtr<GraphicsContext3D::Con
textLostCallback> callback) | 239 void GraphicsContext3D::setContextLostCallback(PassOwnPtr<GraphicsContext3D::Con
textLostCallback> callback) |
240 { | 240 { |
241 if (m_ownedWebContext) { | 241 if (m_ownedWebContext) { |
242 m_contextLostCallbackAdapter = adoptPtr(new GraphicsContext3DContextLost
CallbackAdapter(callback)); | 242 m_contextLostCallbackAdapter = adoptPtr(new GraphicsContext3DContextLost
CallbackAdapter(callback)); |
243 m_ownedWebContext->setContextLostCallback(m_contextLostCallbackAdapter.g
et()); | 243 m_ownedWebContext->setContextLostCallback(m_contextLostCallbackAdapter.g
et()); |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 void GraphicsContext3D::setErrorMessageCallback(PassOwnPtr<GraphicsContext3D::Er
rorMessageCallback> callback) | 247 void GraphicsContext3D::setErrorMessageCallback(PassOwnPtr<GraphicsContext3D::Er
rorMessageCallback> callback) |
248 { | 248 { |
249 if (m_ownedWebContext) { | 249 if (m_ownedWebContext) { |
250 m_errorMessageCallbackAdapter = adoptPtr(new GraphicsContext3DErrorMessa
geCallbackAdapter(callback)); | 250 m_errorMessageCallbackAdapter = adoptPtr(new GraphicsContext3DErrorMessa
geCallbackAdapter(callback)); |
251 m_ownedWebContext->setErrorMessageCallback(m_errorMessageCallbackAdapter
.get()); | 251 m_ownedWebContext->setErrorMessageCallback(m_errorMessageCallbackAdapter
.get()); |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attri
butes attrs) | 255 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attri
butes attrs) |
256 { | 256 { |
257 WebKit::WebGraphicsContext3D::Attributes webAttributes; | 257 blink::WebGraphicsContext3D::Attributes webAttributes; |
258 webAttributes.alpha = attrs.alpha; | 258 webAttributes.alpha = attrs.alpha; |
259 webAttributes.depth = attrs.depth; | 259 webAttributes.depth = attrs.depth; |
260 webAttributes.stencil = attrs.stencil; | 260 webAttributes.stencil = attrs.stencil; |
261 webAttributes.antialias = attrs.antialias; | 261 webAttributes.antialias = attrs.antialias; |
262 webAttributes.premultipliedAlpha = attrs.premultipliedAlpha; | 262 webAttributes.premultipliedAlpha = attrs.premultipliedAlpha; |
263 webAttributes.noExtensions = attrs.noExtensions; | 263 webAttributes.noExtensions = attrs.noExtensions; |
264 webAttributes.shareResources = attrs.shareResources; | 264 webAttributes.shareResources = attrs.shareResources; |
265 webAttributes.preferDiscreteGPU = attrs.preferDiscreteGPU; | 265 webAttributes.preferDiscreteGPU = attrs.preferDiscreteGPU; |
266 webAttributes.topDocumentURL = attrs.topDocumentURL.string(); | 266 webAttributes.topDocumentURL = attrs.topDocumentURL.string(); |
267 | 267 |
268 OwnPtr<WebKit::WebGraphicsContext3D> webContext = adoptPtr(WebKit::Platform:
:current()->createOffscreenGraphicsContext3D(webAttributes)); | 268 OwnPtr<blink::WebGraphicsContext3D> webContext = adoptPtr(blink::Platform::c
urrent()->createOffscreenGraphicsContext3D(webAttributes)); |
269 if (!webContext) | 269 if (!webContext) |
270 return 0; | 270 return 0; |
271 | 271 |
272 return GraphicsContext3D::createGraphicsContextFromWebContext(webContext.rel
ease(), attrs.preserveDrawingBuffer); | 272 return GraphicsContext3D::createGraphicsContextFromWebContext(webContext.rel
ease(), attrs.preserveDrawingBuffer); |
273 } | 273 } |
274 | 274 |
275 PassRefPtr<GraphicsContext3D> GraphicsContext3D::createGraphicsContextFromProvid
er(PassOwnPtr<WebKit::WebGraphicsContext3DProvider> provider, bool preserveDrawi
ngBuffer) | 275 PassRefPtr<GraphicsContext3D> GraphicsContext3D::createGraphicsContextFromProvid
er(PassOwnPtr<blink::WebGraphicsContext3DProvider> provider, bool preserveDrawin
gBuffer) |
276 { | 276 { |
277 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(provider,
preserveDrawingBuffer)); | 277 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(provider,
preserveDrawingBuffer)); |
278 return context.release(); | 278 return context.release(); |
279 } | 279 } |
280 | 280 |
281 PassRefPtr<GraphicsContext3D> GraphicsContext3D::createGraphicsContextFromWebCon
text(PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, bool preserveDrawingBu
ffer) | 281 PassRefPtr<GraphicsContext3D> GraphicsContext3D::createGraphicsContextFromWebCon
text(PassOwnPtr<blink::WebGraphicsContext3D> webContext, bool preserveDrawingBuf
fer) |
282 { | 282 { |
283 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(webContex
t, preserveDrawingBuffer)); | 283 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(webContex
t, preserveDrawingBuffer)); |
284 return context.release(); | 284 return context.release(); |
285 } | 285 } |
286 | 286 |
287 GrContext* GraphicsContext3D::grContext() | 287 GrContext* GraphicsContext3D::grContext() |
288 { | 288 { |
289 return m_grContext; | 289 return m_grContext; |
290 } | 290 } |
291 | 291 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 DELEGATE_TO_WEBCONTEXT_1(enableVertexAttribArray, GC3Duint) | 344 DELEGATE_TO_WEBCONTEXT_1(enableVertexAttribArray, GC3Duint) |
345 DELEGATE_TO_WEBCONTEXT(finish) | 345 DELEGATE_TO_WEBCONTEXT(finish) |
346 DELEGATE_TO_WEBCONTEXT(flush) | 346 DELEGATE_TO_WEBCONTEXT(flush) |
347 DELEGATE_TO_WEBCONTEXT_4(framebufferRenderbuffer, GC3Denum, GC3Denum, GC3Denum,
Platform3DObject) | 347 DELEGATE_TO_WEBCONTEXT_4(framebufferRenderbuffer, GC3Denum, GC3Denum, GC3Denum,
Platform3DObject) |
348 DELEGATE_TO_WEBCONTEXT_5(framebufferTexture2D, GC3Denum, GC3Denum, GC3Denum, Pla
tform3DObject, GC3Dint) | 348 DELEGATE_TO_WEBCONTEXT_5(framebufferTexture2D, GC3Denum, GC3Denum, GC3Denum, Pla
tform3DObject, GC3Dint) |
349 DELEGATE_TO_WEBCONTEXT_1(frontFace, GC3Denum) | 349 DELEGATE_TO_WEBCONTEXT_1(frontFace, GC3Denum) |
350 DELEGATE_TO_WEBCONTEXT_1(generateMipmap, GC3Denum) | 350 DELEGATE_TO_WEBCONTEXT_1(generateMipmap, GC3Denum) |
351 | 351 |
352 bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, GC3Duint index
, ActiveInfo& info) | 352 bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, GC3Duint index
, ActiveInfo& info) |
353 { | 353 { |
354 WebKit::WebGraphicsContext3D::ActiveInfo webInfo; | 354 blink::WebGraphicsContext3D::ActiveInfo webInfo; |
355 if (!m_impl->getActiveAttrib(program, index, webInfo)) | 355 if (!m_impl->getActiveAttrib(program, index, webInfo)) |
356 return false; | 356 return false; |
357 info.name = webInfo.name; | 357 info.name = webInfo.name; |
358 info.type = webInfo.type; | 358 info.type = webInfo.type; |
359 info.size = webInfo.size; | 359 info.size = webInfo.size; |
360 return true; | 360 return true; |
361 } | 361 } |
362 | 362 |
363 bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint inde
x, ActiveInfo& info) | 363 bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint inde
x, ActiveInfo& info) |
364 { | 364 { |
365 WebKit::WebGraphicsContext3D::ActiveInfo webInfo; | 365 blink::WebGraphicsContext3D::ActiveInfo webInfo; |
366 if (!m_impl->getActiveUniform(program, index, webInfo)) | 366 if (!m_impl->getActiveUniform(program, index, webInfo)) |
367 return false; | 367 return false; |
368 info.name = webInfo.name; | 368 info.name = webInfo.name; |
369 info.type = webInfo.type; | 369 info.type = webInfo.type; |
370 info.size = webInfo.size; | 370 info.size = webInfo.size; |
371 return true; | 371 return true; |
372 } | 372 } |
373 | 373 |
374 DELEGATE_TO_WEBCONTEXT_4(getAttachedShaders, Platform3DObject, GC3Dsizei, GC3Dsi
zei*, Platform3DObject*) | 374 DELEGATE_TO_WEBCONTEXT_4(getAttachedShaders, Platform3DObject, GC3Dsizei, GC3Dsi
zei*, Platform3DObject*) |
375 | 375 |
376 GC3Dint GraphicsContext3D::getAttribLocation(Platform3DObject program, const Str
ing& name) | 376 GC3Dint GraphicsContext3D::getAttribLocation(Platform3DObject program, const Str
ing& name) |
377 { | 377 { |
378 return m_impl->getAttribLocation(program, name.utf8().data()); | 378 return m_impl->getAttribLocation(program, name.utf8().data()); |
379 } | 379 } |
380 | 380 |
381 DELEGATE_TO_WEBCONTEXT_2(getBooleanv, GC3Denum, GC3Dboolean*) | 381 DELEGATE_TO_WEBCONTEXT_2(getBooleanv, GC3Denum, GC3Dboolean*) |
382 DELEGATE_TO_WEBCONTEXT_3(getBufferParameteriv, GC3Denum, GC3Denum, GC3Dint*) | 382 DELEGATE_TO_WEBCONTEXT_3(getBufferParameteriv, GC3Denum, GC3Denum, GC3Dint*) |
383 | 383 |
384 GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes() | 384 GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes() |
385 { | 385 { |
386 WebKit::WebGraphicsContext3D::Attributes webAttributes = m_impl->getContextA
ttributes(); | 386 blink::WebGraphicsContext3D::Attributes webAttributes = m_impl->getContextAt
tributes(); |
387 GraphicsContext3D::Attributes attributes; | 387 GraphicsContext3D::Attributes attributes; |
388 attributes.alpha = webAttributes.alpha; | 388 attributes.alpha = webAttributes.alpha; |
389 attributes.depth = webAttributes.depth; | 389 attributes.depth = webAttributes.depth; |
390 attributes.stencil = webAttributes.stencil; | 390 attributes.stencil = webAttributes.stencil; |
391 attributes.antialias = webAttributes.antialias; | 391 attributes.antialias = webAttributes.antialias; |
392 attributes.premultipliedAlpha = webAttributes.premultipliedAlpha; | 392 attributes.premultipliedAlpha = webAttributes.premultipliedAlpha; |
393 attributes.preserveDrawingBuffer = m_preserveDrawingBuffer; | 393 attributes.preserveDrawingBuffer = m_preserveDrawingBuffer; |
394 attributes.preferDiscreteGPU = webAttributes.preferDiscreteGPU; | 394 attributes.preferDiscreteGPU = webAttributes.preferDiscreteGPU; |
395 return attributes; | 395 return attributes; |
396 } | 396 } |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 for (unsigned i = 0; i < count; i++) { | 940 for (unsigned i = 0; i < count; i++) { |
941 uint8* rowA = framebuffer + i * rowBytes; | 941 uint8* rowA = framebuffer + i * rowBytes; |
942 uint8* rowB = framebuffer + (height - i - 1) * rowBytes; | 942 uint8* rowB = framebuffer + (height - i - 1) * rowBytes; |
943 memcpy(scanline, rowB, rowBytes); | 943 memcpy(scanline, rowB, rowBytes); |
944 memcpy(rowB, rowA, rowBytes); | 944 memcpy(rowB, rowA, rowBytes); |
945 memcpy(rowA, scanline, rowBytes); | 945 memcpy(rowA, scanline, rowBytes); |
946 } | 946 } |
947 } | 947 } |
948 | 948 |
949 } // namespace WebCore | 949 } // namespace WebCore |
OLD | NEW |