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

Side by Side Diff: src/gpu/GrGpu.h

Issue 1249543003: Creating functions for uploading a mipmapped texture. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Fixing incorrect rebase. Created 5 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 GrGpu_DEFINED 8 #ifndef GrGpu_DEFINED
9 #define GrGpu_DEFINED 9 #define GrGpu_DEFINED
10 10
11 #include "GrPipelineBuilder.h" 11 #include "GrPipelineBuilder.h"
12 #include "GrProgramDesc.h" 12 #include "GrProgramDesc.h"
13 #include "GrStencil.h" 13 #include "GrStencil.h"
14 #include "GrXferProcessor.h" 14 #include "GrXferProcessor.h"
15 #include "SkMipMapLevel.h"
15 #include "SkPath.h" 16 #include "SkPath.h"
17 #include "SkTArray.h"
16 18
17 class GrBatchTracker; 19 class GrBatchTracker;
18 class GrContext; 20 class GrContext;
19 class GrGLContext; 21 class GrGLContext;
20 class GrIndexBuffer; 22 class GrIndexBuffer;
21 class GrNonInstancedVertices; 23 class GrNonInstancedVertices;
22 class GrPath; 24 class GrPath;
23 class GrPathRange; 25 class GrPathRange;
24 class GrPathRenderer; 26 class GrPathRenderer;
25 class GrPathRendererChain; 27 class GrPathRendererChain;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; } 74 void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; }
73 75
74 /** 76 /**
75 * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can 77 * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can
76 * be used as a render target by calling GrTexture::asRenderTarget(). Not al l 78 * be used as a render target by calling GrTexture::asRenderTarget(). Not al l
77 * pixel configs can be used as render targets. Support for configs as textu res 79 * pixel configs can be used as render targets. Support for configs as textu res
78 * or render targets can be checked using GrCaps. 80 * or render targets can be checked using GrCaps.
79 * 81 *
80 * @param desc describes the texture to be created. 82 * @param desc describes the texture to be created.
81 * @param budgeted does this texture count against the resource cache bud get? 83 * @param budgeted does this texture count against the resource cache bud get?
82 * @param srcData texel data to load texture. Begins with full-size 84 * @param texels array of mipmap levels containing texel data to load.
83 * palette data for paletted textures. For compressed 85 * Begins with full-size palette data for paletted textur es.
84 * formats it contains the compressed pixel data. Otherwi se, 86 * For compressed formats it contains the compressed pixe l data.
85 * it contains width*height texels. If nullptr texture da ta 87 * Otherwise, it contains width*height texels. If there i s only one
86 * is uninitialized. 88 * element and it contains nullptr fTexels, texture data is
87 * @param rowBytes the number of bytes between consecutive rows. Zero 89 * uninitialized.
88 * means rows are tightly packed. This field is ignored 90 * @return The texture object if successful, otherwise nullptr.
89 * for compressed formats. 91 */
92 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted,
93 const SkTArray<SkMipMapLevel>& texels);
94
95 /**
96 * This function is a shim which creates a SkTArray<SkMipMapLevel> of size 1 .
97 * It then calls createTexture with that SkTArray.
90 * 98 *
91 * @return The texture object if successful, otherwise nullptr. 99 * @param srcData Pointer to the pixel values (optional).
100 * @param rowBytes The number of bytes between rows for the texture. Zero
101 * implies tightly packed rows. For compressed pixel configs , this
102 * field is ignored.
92 */ 103 */
93 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, 104 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted,
94 const void* srcData, size_t rowBytes); 105 const void* srcData, size_t rowBytes);
95 106
96 /** 107 /**
97 * Implements GrContext::wrapBackendTexture 108 * Implements GrContext::wrapBackendTexture
98 */ 109 */
99 GrTexture* wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership); 110 GrTexture* wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership);
100 111
101 /** 112 /**
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 185
175 /** 186 /**
176 * Used to negotiate whether and how an intermediate draw should or must be performed before 187 * Used to negotiate whether and how an intermediate draw should or must be performed before
177 * a readPixels call. If this returns false then GrGpu could not deduce an i ntermediate draw 188 * a readPixels call. If this returns false then GrGpu could not deduce an i ntermediate draw
178 * that would allow a successful readPixels call. The passed width, height, and rowBytes, 189 * that would allow a successful readPixels call. The passed width, height, and rowBytes,
179 * must be non-zero and already reflect clipping to the src bounds. 190 * must be non-zero and already reflect clipping to the src bounds.
180 */ 191 */
181 bool getReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes, 192 bool getReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
182 GrPixelConfig readConfig, DrawPreference*, ReadPixelT empDrawInfo*); 193 GrPixelConfig readConfig, DrawPreference*, ReadPixelT empDrawInfo*);
183 194
184 /** Info struct returned by getWritePixelsInfo about performing an intermedi ate draw in order 195 /** Info struct returned by getWritePixelsInfo about performing an intermedi ate draw in order
185 to write pixels to a GrSurface for either performance or correctness rea sons. */ 196 to write pixels to a GrSurface for either performance or correctness rea sons. */
186 struct WritePixelTempDrawInfo { 197 struct WritePixelTempDrawInfo {
187 /** If the GrGpu is requesting that the caller upload to an intermediate surface and draw 198 /** If the GrGpu is requesting that the caller upload to an intermediate surface and draw
188 that to the dst then this is the descriptor for the intermediate sur face. The caller 199 that to the dst then this is the descriptor for the intermediate sur face. The caller
189 should upload the pixels such that the upper left pixel of the uploa d rect is at 0,0 in 200 should upload the pixels such that the upper left pixel of the uploa d rect is at 0,0 in
190 the intermediate surface.*/ 201 the intermediate surface.*/
191 GrSurfaceDesc fTempSurfaceDesc; 202 GrSurfaceDesc fTempSurfaceDesc;
192 /** If set, fTempSurfaceDesc's config will be a R/B swap of the src pixe l config. The caller 203 /** If set, fTempSurfaceDesc's config will be a R/B swap of the src pixe l config. The caller
193 should upload the pixels as is such that R and B will be swapped in the intermediate 204 should upload the pixels as is such that R and B will be swapped in the intermediate
194 surface. When the intermediate is drawn to the dst the shader should swap R/B again 205 surface. When the intermediate is drawn to the dst the shader should swap R/B again
195 such that the correct swizzle results in the dst. This is done to wo rk around either 206 such that the correct swizzle results in the dst. This is done to wo rk around either
196 performance or API restrictions in the backend 3D API implementation . */ 207 performance or API restrictions in the backend 3D API implementation . */
197 bool fSwapRAndB; 208 bool fSwapRAndB;
198 }; 209 };
199 210
200 /** 211 /**
201 * Used to negotiate whether and how an intermediate surface should be used to write pixels to 212 * Used to negotiate whether and how an intermediate surface should be used to write pixels to
202 * a GrSurface. If this returns false then GrGpu could not deduce an interme diate draw 213 * a GrSurface. If this returns false then GrGpu could not deduce an interme diate draw
203 * that would allow a successful transfer of the src pixels to the dst. The passed width, 214 * that would allow a successful transfer of the src pixels to the dst. The passed width,
204 * height, and rowBytes, must be non-zero and already reflect clipping to th e dst bounds. 215 * height, and rowBytes, must be non-zero and already reflect clipping to th e dst bounds.
205 */ 216 */
206 bool getWritePixelsInfo(GrSurface* dstSurface, int width, int height, size_t rowBytes, 217 bool getWritePixelsInfo(GrSurface* dstSurface, int width, int height,
207 GrPixelConfig srcConfig, DrawPreference*, WritePixel TempDrawInfo*); 218 GrPixelConfig srcConfig, DrawPreference*, WritePixel TempDrawInfo*);
208 219
209 /** 220 /**
210 * Reads a rectangle of pixels from a render target. 221 * Reads a rectangle of pixels from a render target.
211 * 222 *
212 * @param surface The surface to read from 223 * @param surface The surface to read from
213 * @param left left edge of the rectangle to read (inclusive) 224 * @param left left edge of the rectangle to read (inclusive)
214 * @param top top edge of the rectangle to read (inclusive) 225 * @param top top edge of the rectangle to read (inclusive)
215 * @param width width of rectangle to read in pixels. 226 * @param width width of rectangle to read in pixels.
216 * @param height height of rectangle to read in pixels. 227 * @param height height of rectangle to read in pixels.
(...skipping 14 matching lines...) Expand all
231 242
232 /** 243 /**
233 * Updates the pixels in a rectangle of a surface. 244 * Updates the pixels in a rectangle of a surface.
234 * 245 *
235 * @param surface The surface to write to. 246 * @param surface The surface to write to.
236 * @param left left edge of the rectangle to write (inclusive) 247 * @param left left edge of the rectangle to write (inclusive)
237 * @param top top edge of the rectangle to write (inclusive) 248 * @param top top edge of the rectangle to write (inclusive)
238 * @param width width of rectangle to write in pixels. 249 * @param width width of rectangle to write in pixels.
239 * @param height height of rectangle to write in pixels. 250 * @param height height of rectangle to write in pixels.
240 * @param config the pixel config of the source buffer 251 * @param config the pixel config of the source buffer
241 * @param buffer memory to read pixels from 252 * @param texels array of mipmap levels containing texture data
242 * @param rowBytes number of bytes between consecutive rows. Zero
243 * means rows are tightly packed.
244 */ 253 */
245 bool writePixels(GrSurface* surface, 254 bool writePixels(GrSurface* surface,
246 int left, int top, int width, int height, 255 int left, int top, int width, int height,
256 GrPixelConfig config,
257 const SkTArray<SkMipMapLevel>& texels);
258
259 /**
260 * This function is a shim which creates a SkTArray<SkMipMapLevel> of size 1 .
261 * It then calls writePixels with that SkTArray.
262 *
263 * @param buffer Pointer to the pixel values (optional).
264 * @param rowBytes The number of bytes between rows of the texture. Zero
265 * implies tightly packed rows. For compressed pixel configs , this
266 * field is ignored.
267 */
268 bool writePixels(GrSurface* surface,
269 int left, int top, int width, int height,
247 GrPixelConfig config, const void* buffer, 270 GrPixelConfig config, const void* buffer,
248 size_t rowBytes); 271 size_t rowBytes);
249 272
250 /** 273 /**
251 * Clear the passed in render target. Ignores the draw state and clip. 274 * Clear the passed in render target. Ignores the draw state and clip.
252 */ 275 */
253 void clear(const SkIRect& rect, GrColor color, GrRenderTarget* renderTarget) ; 276 void clear(const SkIRect& rect, GrColor color, GrRenderTarget* renderTarget) ;
254 277
255 278
256 void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* renderTarget); 279 void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* renderTarget);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 virtual void onResetContext(uint32_t resetBits) = 0; 437 virtual void onResetContext(uint32_t resetBits) = 0;
415 438
416 // Called before certain draws in order to guarantee coherent results from d st reads. 439 // Called before certain draws in order to guarantee coherent results from d st reads.
417 virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0; 440 virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0;
418 441
419 // overridden by backend-specific derived class to create objects. 442 // overridden by backend-specific derived class to create objects.
420 // Texture size and sample size will have already been validated in base cla ss before 443 // Texture size and sample size will have already been validated in base cla ss before
421 // onCreateTexture/CompressedTexture are called. 444 // onCreateTexture/CompressedTexture are called.
422 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, 445 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc,
423 GrGpuResource::LifeCycle lifeCycle, 446 GrGpuResource::LifeCycle lifeCycle,
424 const void* srcData, size_t rowBytes) = 0 ; 447 const SkTArray<SkMipMapLevel>& texels) = 0;
425 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, 448 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
426 GrGpuResource::LifeCycle lifeCy cle, 449 GrGpuResource::LifeCycle lifeCy cle,
427 const void* srcData) = 0; 450 const SkTArray<SkMipMapLevel>& texels) = 0;
451
428 virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapO wnership) = 0; 452 virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapO wnership) = 0;
429 virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTarge tDesc&, 453 virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTarge tDesc&,
430 GrWrapOwnership) = 0; 454 GrWrapOwnership) = 0;
431 virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0; 455 virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0;
432 virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0; 456 virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0;
433 457
434 // overridden by backend-specific derived class to perform the clear. 458 // overridden by backend-specific derived class to perform the clear.
435 virtual void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) = 0; 459 virtual void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) = 0;
436 460
437 461
438 // Overridden by backend specific classes to perform a clear of the stencil clip bits. This is 462 // Overridden by backend specific classes to perform a clear of the stencil clip bits. This is
439 // ONLY used by the the clip target 463 // ONLY used by the the clip target
440 virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool i nsideClip) = 0; 464 virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool i nsideClip) = 0;
441 465
442 // overridden by backend-specific derived class to perform the draw call. 466 // overridden by backend-specific derived class to perform the draw call.
443 virtual void onDraw(const DrawArgs&, const GrNonInstancedVertices&) = 0; 467 virtual void onDraw(const DrawArgs&, const GrNonInstancedVertices&) = 0;
444 468
445 virtual bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int r eadHeight, 469 virtual bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int r eadHeight,
446 size_t rowBytes, GrPixelConfig readConfig, DrawPreference*, 470 size_t rowBytes, GrPixelConfig readConfig, DrawPreference*,
447 ReadPixelTempDrawInfo*) = 0; 471 ReadPixelTempDrawInfo*) = 0;
448 virtual bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int heig ht, size_t rowBytes, 472 virtual bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int heig ht,
449 GrPixelConfig srcConfig, DrawPreference*, 473 GrPixelConfig srcConfig, DrawPreference*,
450 WritePixelTempDrawInfo*) = 0; 474 WritePixelTempDrawInfo*) = 0;
451 475
452 // overridden by backend-specific derived class to perform the surface read 476 // overridden by backend-specific derived class to perform the surface read
453 virtual bool onReadPixels(GrSurface*, 477 virtual bool onReadPixels(GrSurface*,
454 int left, int top, 478 int left, int top,
455 int width, int height, 479 int width, int height,
456 GrPixelConfig, 480 GrPixelConfig,
457 void* buffer, 481 void* buffer,
458 size_t rowBytes) = 0; 482 size_t rowBytes) = 0;
459 483
460 // overridden by backend-specific derived class to perform the surface write 484 // overridden by backend-specific derived class to perform the surface write
461 virtual bool onWritePixels(GrSurface*, 485 virtual bool onWritePixels(GrSurface*,
462 int left, int top, int width, int height, 486 int left, int top, int width, int height,
463 GrPixelConfig config, const void* buffer, 487 GrPixelConfig config,
464 size_t rowBytes) = 0; 488 const SkTArray<SkMipMapLevel>& texels) = 0;
465 489
466 // overridden by backend-specific derived class to perform the resolve 490 // overridden by backend-specific derived class to perform the resolve
467 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; 491 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0;
468 492
469 // overridden by backend specific derived class to perform the copy surface 493 // overridden by backend specific derived class to perform the copy surface
470 virtual bool onCopySurface(GrSurface* dst, 494 virtual bool onCopySurface(GrSurface* dst,
471 GrSurface* src, 495 GrSurface* src,
472 const SkIRect& srcRect, 496 const SkIRect& srcRect,
473 const SkIPoint& dstPoint) = 0; 497 const SkIPoint& dstPoint) = 0;
474 498
(...skipping 12 matching lines...) Expand all
487 ResetTimestamp fResetTi mestamp; 511 ResetTimestamp fResetTi mestamp;
488 uint32_t fResetBi ts; 512 uint32_t fResetBi ts;
489 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. 513 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu.
490 GrContext* fContext ; 514 GrContext* fContext ;
491 515
492 friend class GrPathRendering; 516 friend class GrPathRendering;
493 typedef SkRefCnt INHERITED; 517 typedef SkRefCnt INHERITED;
494 }; 518 };
495 519
496 #endif 520 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698