Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1404)

Side by Side Diff: Source/platform/graphics/GraphicsContext3D.h

Issue 127493002: Removed most calls to GraphicsContext3D from DrawingBuffer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Moved texImage2DSafe to DrawingBuffer, it's only caller. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 15 matching lines...) Expand all
26 #ifndef GraphicsContext3D_h 26 #ifndef GraphicsContext3D_h
27 #define GraphicsContext3D_h 27 #define GraphicsContext3D_h
28 28
29 #include "platform/PlatformExport.h" 29 #include "platform/PlatformExport.h"
30 #include "platform/geometry/IntRect.h" 30 #include "platform/geometry/IntRect.h"
31 #include "platform/graphics/GraphicsTypes3D.h" 31 #include "platform/graphics/GraphicsTypes3D.h"
32 #include "platform/graphics/Image.h" 32 #include "platform/graphics/Image.h"
33 #include "platform/weborigin/KURL.h" 33 #include "platform/weborigin/KURL.h"
34 #include "third_party/khronos/GLES2/gl2.h" 34 #include "third_party/khronos/GLES2/gl2.h"
35 #include "third_party/khronos/GLES2/gl2ext.h" 35 #include "third_party/khronos/GLES2/gl2ext.h"
36 #include "third_party/skia/include/core/SkBitmap.h"
37 #include "wtf/HashMap.h" 36 #include "wtf/HashMap.h"
38 #include "wtf/HashSet.h" 37 #include "wtf/HashSet.h"
39 #include "wtf/ListHashSet.h" 38 #include "wtf/ListHashSet.h"
40 #include "wtf/Noncopyable.h" 39 #include "wtf/Noncopyable.h"
41 #include "wtf/OwnPtr.h" 40 #include "wtf/OwnPtr.h"
42 #include "wtf/PassOwnPtr.h" 41 #include "wtf/PassOwnPtr.h"
43 #include "wtf/RefCounted.h" 42 #include "wtf/RefCounted.h"
44 #include "wtf/text/WTFString.h" 43 #include "wtf/text/WTFString.h"
45 44
46 // FIXME: Find a better way to avoid the name confliction for NO_ERROR. 45 // FIXME: Find a better way to avoid the name confliction for NO_ERROR.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 bool antialias; 93 bool antialias;
95 bool premultipliedAlpha; 94 bool premultipliedAlpha;
96 bool preserveDrawingBuffer; 95 bool preserveDrawingBuffer;
97 bool noExtensions; 96 bool noExtensions;
98 bool shareResources; 97 bool shareResources;
99 bool preferDiscreteGPU; 98 bool preferDiscreteGPU;
100 bool failIfMajorPerformanceCaveat; 99 bool failIfMajorPerformanceCaveat;
101 KURL topDocumentURL; 100 KURL topDocumentURL;
102 }; 101 };
103 102
104 class ContextLostCallback {
105 public:
106 virtual void onContextLost() = 0;
107 virtual ~ContextLostCallback() {}
108 };
109
110 class ErrorMessageCallback {
111 public:
112 virtual void onErrorMessage(const String& message, GLint id) = 0;
113 virtual ~ErrorMessageCallback() { }
114 };
115
116 void setContextLostCallback(PassOwnPtr<ContextLostCallback>);
117 void setErrorMessageCallback(PassOwnPtr<ErrorMessageCallback>);
118
119 // This is the preferred method for creating an instance of this class. When created this way the webContext 103 // This is the preferred method for creating an instance of this class. When created this way the webContext
120 // is not owned by the GraphicsContext3D 104 // is not owned by the GraphicsContext3D
121 static PassRefPtr<GraphicsContext3D> createContextSupport(blink::WebGraphics Context3D* webContext); 105 static PassRefPtr<GraphicsContext3D> createContextSupport(blink::WebGraphics Context3D* webContext);
122 106
123 // The following three creation methods are obsolete and should not be used by new code. They will be removed soon. 107 // The following three creation methods are obsolete and should not be used by new code. They will be removed soon.
124 108
125 // Callers must make the context current before using it AND check that the context was created successfully 109 // Callers must make the context current before using it AND check that the context was created successfully
126 // via ContextLost before using the context in any way. Once made current on a thread, the context cannot 110 // via ContextLost before using the context in any way. Once made current on a thread, the context cannot
127 // be used on any other thread. 111 // be used on any other thread.
128 static PassRefPtr<GraphicsContext3D> create(Attributes); 112 static PassRefPtr<GraphicsContext3D> create(Attributes);
129 static PassRefPtr<GraphicsContext3D> createGraphicsContextFromWebContext(Pas sOwnPtr<blink::WebGraphicsContext3D>, bool preserveDrawingBuffer = false); 113 static PassRefPtr<GraphicsContext3D> createGraphicsContextFromWebContext(Pas sOwnPtr<blink::WebGraphicsContext3D>, bool preserveDrawingBuffer = false);
130 static PassRefPtr<GraphicsContext3D> createGraphicsContextFromProvider(PassO wnPtr<blink::WebGraphicsContext3DProvider>, bool preserveDrawingBuffer = false); 114 static PassRefPtr<GraphicsContext3D> createGraphicsContextFromProvider(PassO wnPtr<blink::WebGraphicsContext3DProvider>, bool preserveDrawingBuffer = false);
131 115
132 116
133 ~GraphicsContext3D(); 117 ~GraphicsContext3D();
134 118
135 GrContext* grContext(); 119 GrContext* grContext();
136 blink::WebGraphicsContext3D* webContext() const { return m_impl; } 120 blink::WebGraphicsContext3D* webContext() const { return m_impl; }
137 121
138 bool makeContextCurrent(); 122 bool makeContextCurrent();
139 123
140 uint32_t lastFlushID();
141
142 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
143 // Return true if no GL error is synthesized.
144 // By default, alignment is 4, the OpenGL default setting.
145 bool texImage2DResourceSafe(GLenum target, GLint level, GLenum internalforma t, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLin t alignment = 4);
146
147 //---------------------------------------------------------------------- 124 //----------------------------------------------------------------------
148 // Helpers for texture uploading and pixel readback. 125 // Helpers for texture uploading and pixel readback.
149 // 126 //
150 127
151 // Computes the components per pixel and bytes per component 128 // Computes the components per pixel and bytes per component
152 // for the given format and type combination. Returns false if 129 // for the given format and type combination. Returns false if
153 // either was an invalid enum. 130 // either was an invalid enum.
154 static bool computeFormatAndTypeParameters(GLenum format, GLenum type, unsig ned* componentsPerPixel, unsigned* bytesPerComponent); 131 static bool computeFormatAndTypeParameters(GLenum format, GLenum type, unsig ned* componentsPerPixel, unsigned* bytesPerComponent);
155 132
156 // Computes the image size in bytes. If paddingInBytes is not null, padding 133 // Computes the image size in bytes. If paddingInBytes is not null, padding
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 void uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z); 240 void uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z);
264 void uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); 241 void uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
265 void uniformMatrix4fv(GLint location, GLsizei, GLboolean transpose, GLfloat* value); 242 void uniformMatrix4fv(GLint location, GLsizei, GLboolean transpose, GLfloat* value);
266 243
267 void useProgram(Platform3DObject); 244 void useProgram(Platform3DObject);
268 245
269 void vertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean no rmalized, GLsizei stride, GLintptr offset); 246 void vertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean no rmalized, GLsizei stride, GLintptr offset);
270 247
271 void viewport(GLint x, GLint y, GLsizei width, GLsizei height); 248 void viewport(GLint x, GLint y, GLsizei width, GLsizei height);
272 249
273 void markContextChanged();
274 void markLayerComposited();
275 bool layerComposited() const;
276
277 void paintRenderingResultsToCanvas(ImageBuffer*, DrawingBuffer*);
278 PassRefPtr<Uint8ClampedArray> paintRenderingResultsToImageData(DrawingBuffer *, int&, int&);
279
280 // Support for buffer creation and deletion 250 // Support for buffer creation and deletion
281 Platform3DObject createBuffer(); 251 Platform3DObject createBuffer();
282 Platform3DObject createFramebuffer(); 252 Platform3DObject createFramebuffer();
283 Platform3DObject createProgram(); 253 Platform3DObject createProgram();
284 Platform3DObject createRenderbuffer(); 254 Platform3DObject createRenderbuffer();
285 Platform3DObject createShader(GLenum); 255 Platform3DObject createShader(GLenum);
286 Platform3DObject createTexture(); 256 Platform3DObject createTexture();
287 257
288 void deleteBuffer(Platform3DObject); 258 void deleteBuffer(Platform3DObject);
289 void deleteFramebuffer(Platform3DObject); 259 void deleteFramebuffer(Platform3DObject);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 350
381 // Helper function which extracts the user-supplied texture 351 // Helper function which extracts the user-supplied texture
382 // data, applying the flipY and premultiplyAlpha parameters. 352 // data, applying the flipY and premultiplyAlpha parameters.
383 // If the data is not tightly packed according to the passed 353 // If the data is not tightly packed according to the passed
384 // unpackAlignment, the output data will be tightly packed. 354 // unpackAlignment, the output data will be tightly packed.
385 // Returns true if successful, false if any error occurred. 355 // Returns true if successful, false if any error occurred.
386 static bool extractTextureData(unsigned width, unsigned height, GLenum forma t, GLenum type, unsigned unpackAlignment, bool flipY, bool premultiplyAlpha, con st void* pixels, Vector<uint8_t>& data); 356 static bool extractTextureData(unsigned width, unsigned height, GLenum forma t, GLenum type, unsigned unpackAlignment, bool flipY, bool premultiplyAlpha, con st void* pixels, Vector<uint8_t>& data);
387 357
388 // End GraphicsContext3DImagePacking.cpp functions 358 // End GraphicsContext3DImagePacking.cpp functions
389 359
390 // This is the order of bytes to use when doing a readback.
391 enum ReadbackOrder {
392 ReadbackRGBA,
393 ReadbackSkia
394 };
395
396 // Helper function which does a readback from the currently-bound
397 // framebuffer into a buffer of a certain size with 4-byte pixels.
398 void readBackFramebuffer(unsigned char* pixels, int width, int height, Readb ackOrder, AlphaOp);
399
400 void setPackAlignment(GLint param);
401
402 // Extension support. 360 // Extension support.
403 bool supportsExtension(const String& name); 361 bool supportsExtension(const String& name);
404 bool ensureExtensionEnabled(const String& name); 362 bool ensureExtensionEnabled(const String& name);
405 bool isExtensionEnabled(const String& name); 363 bool isExtensionEnabled(const String& name);
406 bool canUseCopyTextureCHROMIUM(GLenum destFormat, GLenum destType, GLint lev el);
407 364
408 void paintFramebufferToCanvas(int framebuffer, int width, int height, bool p remultiplyAlpha, ImageBuffer*); 365 static bool canUseCopyTextureCHROMIUM(GLenum destFormat, GLenum destType, GL int level);
409 366
410 private: 367 private:
411 GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3D>, bool preserveDraw ingBuffer); 368 GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3D>, bool preserveDraw ingBuffer);
412 GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3DProvider>, bool pres erveDrawingBuffer); 369 GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3DProvider>, bool pres erveDrawingBuffer);
413 GraphicsContext3D(blink::WebGraphicsContext3D* webContext); 370 GraphicsContext3D(blink::WebGraphicsContext3D* webContext);
414 371
415 // Helper for packImageData/extractImageData/extractTextureData which implem ent packing of pixel 372 // Helper for packImageData/extractImageData/extractTextureData which implem ent packing of pixel
416 // data into the specified OpenGL destination format and type. 373 // data into the specified OpenGL destination format and type.
417 // A sourceUnpackAlignment of zero indicates that the source 374 // A sourceUnpackAlignment of zero indicates that the source
418 // data is tightly packed. Non-zero values may take a slow path. 375 // data is tightly packed. Non-zero values may take a slow path.
419 // Destination data will have no gaps between rows. 376 // Destination data will have no gaps between rows.
420 // Implemented in GraphicsContext3DImagePacking.cpp 377 // Implemented in GraphicsContext3DImagePacking.cpp
421 static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataForma t, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned des tinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool f lipY); 378 static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataForma t, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned des tinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool f lipY);
422 379
423 // Helper function to flip a bitmap vertically.
424 void flipVertically(uint8_t* data, int width, int height);
425
426 void initializeExtensions(); 380 void initializeExtensions();
427 381
428 bool preserveDrawingBuffer() const { return m_preserveDrawingBuffer; }
429
430 OwnPtr<blink::WebGraphicsContext3DProvider> m_provider; 382 OwnPtr<blink::WebGraphicsContext3DProvider> m_provider;
431 blink::WebGraphicsContext3D* m_impl; 383 blink::WebGraphicsContext3D* m_impl;
432 OwnPtr<GraphicsContext3DContextLostCallbackAdapter> m_contextLostCallbackAda pter;
433 OwnPtr<GraphicsContext3DErrorMessageCallbackAdapter> m_errorMessageCallbackA dapter;
434 OwnPtr<blink::WebGraphicsContext3D> m_ownedWebContext; 384 OwnPtr<blink::WebGraphicsContext3D> m_ownedWebContext;
435 bool m_initializedAvailableExtensions; 385 bool m_initializedAvailableExtensions;
436 HashSet<String> m_enabledExtensions; 386 HashSet<String> m_enabledExtensions;
437 HashSet<String> m_requestableExtensions; 387 HashSet<String> m_requestableExtensions;
438 bool m_layerComposited;
439 bool m_preserveDrawingBuffer; 388 bool m_preserveDrawingBuffer;
440 int m_packAlignment;
441
442 // If the width and height of the Canvas's backing store don't
443 // match those that we were given in the most recent call to
444 // reshape(), then we need an intermediate bitmap to read back the
445 // frame buffer into. This seems to happen when CSS styles are
446 // used to resize the Canvas.
447 SkBitmap m_resizingBitmap;
448
449 GrContext* m_grContext; 389 GrContext* m_grContext;
450
451 // Used to flip a bitmap vertically.
452 Vector<uint8_t> m_scanline;
453 }; 390 };
454 391
455 } // namespace WebCore 392 } // namespace WebCore
456 393
457 #endif // GraphicsContext3D_h 394 #endif // GraphicsContext3D_h
OLDNEW
« no previous file with comments | « Source/core/html/canvas/WebGLRenderingContext.cpp ('k') | Source/platform/graphics/GraphicsContext3D.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698