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

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

Powered by Google App Engine
This is Rietveld 408576698