GrSurface.h revision 0342a85091fd430c90a142d155dc9642aa729d9e
17d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com/*
27d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * Copyright 2012 Google Inc.
37d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com *
47d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * Use of this source code is governed by a BSD-style license that can be
57d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * found in the LICENSE file.
67d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com */
77d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
87d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
97d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com#ifndef GrSurface_DEFINED
107d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com#define GrSurface_DEFINED
117d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
127d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com#include "GrTypes.h"
137d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com#include "GrResource.h"
147d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
157d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.comclass GrTexture;
167d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.comclass GrRenderTarget;
177d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
187d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.comclass GrSurface : public GrResource {
197d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.compublic:
207d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    SK_DECLARE_INST_COUNT(GrSurface);
217d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
227d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    /**
237d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * Retrieves the width of the surface.
247d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     *
257d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @return the width in texels
267d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     */
277d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    int width() const { return fDesc.fWidth; }
287d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
297d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    /**
307d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * Retrieves the height of the surface.
317d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     *
327d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @return the height in texels
337d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     */
347d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    int height() const { return fDesc.fHeight; }
357d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
367d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    /**
377d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * Retrieves the pixel config specified when the surface was created.
387d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * For render targets this can be kUnknown_GrPixelConfig
397d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * if client asked us to render to a target that has a pixel
407d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * config that isn't equivalent with one of our configs.
417d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     */
427d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    GrPixelConfig config() const { return fDesc.fConfig; }
437d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
447d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    /**
457d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * Return the descriptor describing the surface
467d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     */
477d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    const GrTextureDesc& desc() const { return fDesc; }
487d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
497d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    /**
507d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @return the texture associated with the surface, may be NULL.
517d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     */
527d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    virtual GrTexture* asTexture() = 0;
537d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    virtual const GrTexture* asTexture() const = 0;
547d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
557d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    /**
567d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @return the render target underlying this surface, may be NULL.
577d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     */
587d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    virtual GrRenderTarget* asRenderTarget() = 0;
597d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    virtual const GrRenderTarget* asRenderTarget() const = 0;
607d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
617d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    /**
627d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * Reads a rectangle of pixels from the surface.
637d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param left          left edge of the rectangle to read (inclusive)
647d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param top           top edge of the rectangle to read (inclusive)
657d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param width         width of rectangle to read in pixels.
667d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param height        height of rectangle to read in pixels.
677d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param config        the pixel config of the destination buffer
687d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param buffer        memory to read the rectangle into.
690342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     * @param rowBytes      number of bytes bewtween consecutive rows. Zero means rows are tightly
700342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     *                      packed.
710342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum.
727d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     *
730342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     * @return true if the read succeeded, false if not. The read can fail because of an unsupported
740342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     *              pixel config.
757d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     */
767d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    virtual bool readPixels(int left, int top, int width, int height,
770342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com                            GrPixelConfig config,
780342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com                            void* buffer,
790342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com                            size_t rowBytes = 0,
800342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com                            uint32_t pixelOpsFlags = 0) = 0;
817d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
827d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    /**
830342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     * Copy the src pixels [buffer, rowbytes, pixelconfig] into the surface at the specified
840342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     * rectangle.
857d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param left          left edge of the rectangle to write (inclusive)
867d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param top           top edge of the rectangle to write (inclusive)
877d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param width         width of rectangle to write in pixels.
887d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param height        height of rectangle to write in pixels.
897d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param config        the pixel config of the source buffer
907d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     * @param buffer        memory to read the rectangle from.
910342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     * @param rowBytes      number of bytes bewtween consecutive rows. Zero means rows are tightly
920342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     *                      packed.
930342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum.
947d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com     */
957d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    virtual void writePixels(int left, int top, int width, int height,
960342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com                             GrPixelConfig config,
970342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com                             const void* buffer,
980342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com                             size_t rowBytes = 0,
990342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com                             uint32_t pixelOpsFlags = 0) = 0;
1007d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
1017d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.comprotected:
1020342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com    GrTextureDesc fDesc;
1037d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
1047d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    GrSurface(GrGpu* gpu, const GrTextureDesc& desc)
1057d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    : INHERITED(gpu)
1067d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    , fDesc(desc) {
1077d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    }
1087d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
1097d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.comprivate:
1107d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com    typedef GrResource INHERITED;
1117d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com};
1127d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com
1137d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com#endif // GrSurface_DEFINED
114