gfx/layers/ImageDataSerializer.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=8 et :
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #ifndef GFX_LAYERS_BLOBSURFACE_H
michael@0 9 #define GFX_LAYERS_BLOBSURFACE_H
michael@0 10
michael@0 11 #include <stdint.h> // for uint8_t, uint32_t
michael@0 12 #include "mozilla/Attributes.h" // for MOZ_STACK_CLASS
michael@0 13 #include "mozilla/RefPtr.h" // for TemporaryRef
michael@0 14 #include "mozilla/gfx/Point.h" // for IntSize
michael@0 15 #include "mozilla/gfx/Types.h" // for SurfaceFormat
michael@0 16
michael@0 17 class gfxImageSurface;
michael@0 18
michael@0 19 namespace mozilla {
michael@0 20 namespace gfx {
michael@0 21 class DataSourceSurface;
michael@0 22 class DrawTarget;
michael@0 23 } // namespace gfx
michael@0 24 } // namespace mozilla
michael@0 25
michael@0 26 namespace mozilla {
michael@0 27 namespace layers {
michael@0 28
michael@0 29 class ImageDataSerializerBase
michael@0 30 {
michael@0 31 public:
michael@0 32 bool IsValid() const { return mIsValid; }
michael@0 33
michael@0 34 uint8_t* GetData();
michael@0 35 uint32_t GetStride() const;
michael@0 36 gfx::IntSize GetSize() const;
michael@0 37 gfx::SurfaceFormat GetFormat() const;
michael@0 38 TemporaryRef<gfx::DataSourceSurface> GetAsSurface();
michael@0 39 TemporaryRef<gfxImageSurface> GetAsThebesSurface();
michael@0 40 TemporaryRef<gfx::DrawTarget> GetAsDrawTarget(gfx::BackendType aBackend);
michael@0 41
michael@0 42 static uint32_t ComputeMinBufferSize(gfx::IntSize aSize,
michael@0 43 gfx::SurfaceFormat aFormat);
michael@0 44
michael@0 45 protected:
michael@0 46
michael@0 47 ImageDataSerializerBase(uint8_t* aData, size_t aDataSize)
michael@0 48 : mData(aData)
michael@0 49 , mDataSize(aDataSize)
michael@0 50 , mIsValid(false)
michael@0 51 {}
michael@0 52
michael@0 53 void Validate();
michael@0 54
michael@0 55 uint8_t* mData;
michael@0 56 size_t mDataSize;
michael@0 57 bool mIsValid;
michael@0 58 };
michael@0 59
michael@0 60 /**
michael@0 61 * A facility to serialize an image into a buffer of memory.
michael@0 62 * This is intended for use with the IPC code, in order to copy image data
michael@0 63 * into shared memory.
michael@0 64 * Note that there is a separate serializer class for YCbCr images
michael@0 65 * (see YCbCrImageDataSerializer.h).
michael@0 66 */
michael@0 67 class MOZ_STACK_CLASS ImageDataSerializer : public ImageDataSerializerBase
michael@0 68 {
michael@0 69 public:
michael@0 70 ImageDataSerializer(uint8_t* aData, size_t aDataSize)
michael@0 71 : ImageDataSerializerBase(aData, aDataSize)
michael@0 72 {
michael@0 73 // a serializer needs to be usable before correct buffer info has been written to it
michael@0 74 mIsValid = !!mData;
michael@0 75 }
michael@0 76 void InitializeBufferInfo(gfx::IntSize aSize,
michael@0 77 gfx::SurfaceFormat aFormat);
michael@0 78 };
michael@0 79
michael@0 80 /**
michael@0 81 * A facility to deserialize image data that has been serialized by an
michael@0 82 * ImageDataSerializer.
michael@0 83 */
michael@0 84 class MOZ_STACK_CLASS ImageDataDeserializer : public ImageDataSerializerBase
michael@0 85 {
michael@0 86 public:
michael@0 87 ImageDataDeserializer(uint8_t* aData, size_t aDataSize)
michael@0 88 : ImageDataSerializerBase(aData, aDataSize)
michael@0 89 {
michael@0 90 Validate();
michael@0 91 }
michael@0 92
michael@0 93 };
michael@0 94
michael@0 95 } // namespace layers
michael@0 96 } // namespace mozilla
michael@0 97
michael@0 98 #endif

mercurial